using Servise.Classes; using System; using System.Data; using System.Data.SqlClient; using System.Windows.Forms; namespace Servise.Forms { public partial class AddZac : Form { string tp = ""; string ie = ""; string ic = ""; DataBase conect = new DataBase(); public AddZac() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (0 >= Convert.ToInt32(textColvo.Text)) { MessageBox.Show("Попытка добавить пустое значение"); return; } if (tp != "" && ie != "" && ic != "") { conect.openConect(); SqlCommand sql = new SqlCommand("Select quantity From repository_spare where id_spare =" + comboShare.SelectedValue.ToString() + " ", conect.getConect()); int i1 = Convert.ToInt32(sql.ExecuteScalar().ToString()); if (i1 >= Convert.ToInt32(textColvo.Text)) { string nb = textColvo.Text; string nm = comboShare.SelectedValue.ToString(); sql = new SqlCommand("Select id_poch From poch where id_employ='" + ie + "' and id_client = '" + ic + "' and time_poch = '" + tp + "'", conect.getConect()); string nm2 = sql.ExecuteScalar().ToString(); var indert = "INSERT INTO zakaz (stoim,col_vo, id_spare,id_poch) VALUES (" + Math.Round(podschet(Convert.ToInt32(comboShare.SelectedValue.ToString()), Convert.ToInt32(textColvo.Text)), 3) + "," + nb + "," + nm + "," + nm2 + ");"; conect.openConect(); var command = new SqlCommand(indert, conect.getConect()); command.ExecuteNonQuery(); indert = "update repository_spare set quantity = quantity - " + nb + " where id_spare =" + nm + " "; command = new SqlCommand(indert, conect.getConect()); command.ExecuteNonQuery(); } else { MessageBox.Show("На складе недостаточно запчастей"); } conect.closeConect(); } else { MessageBox.Show("Починка еще не задана"); } } private void AddZac_Load(object sender, EventArgs e) { Main.upd("SELECT id_spare as 'Код детали',name_spare as 'Название детали',name_type_spare as 'Тип детали',name_brand + ' ' + name_model + ' ' + year_of_release as 'Автомобиль' FROM spare,type_spare,brand where spare.id_brand =brand.id_brand and type_spare.id_type_spare = spare.id_type_spare", dataShare, ""); Main.addVariant(Client, "client", "name_client + ' ' + phone_client", "id_client"); Main.addVariant(comboShare, "spare", "name_spare", "id_spare"); } public double podschet(int c, int col) { conect.openConect(); SqlCommand sql = new SqlCommand("Select cost From repository_spare where id_spare =" + c + " ", conect.getConect()); double i1 = Convert.ToDouble(sql.ExecuteScalar().ToString()); conect.closeConect(); return (i1 * col); } private void textColvo_Leave(object sender, EventArgs e) { if (textColvo.Text != "") { textBox1.Text = Convert.ToString(podschet(Convert.ToInt32(comboShare.SelectedValue.ToString()), Convert.ToInt32(textColvo.Text))); } } private void button2_Click(object sender, EventArgs e) { conect.openConect(); SqlCommand sql = new SqlCommand("Select id_employee From employees where login='" + UserInform.Login + "'", conect.getConect()); ic = Client.SelectedValue.ToString(); ie = sql.ExecuteScalar().ToString(); tp = DateTime.Now.ToString(); var indert = "INSERT INTO poch (id_employ,id_client,time_poch) VALUES (" + ie + "," + ic + ",'" + tp + "');"; var command = new SqlCommand(indert, conect.getConect()); command.ExecuteNonQuery(); conect.closeConect(); } private void button3_Click(object sender, EventArgs e) { this.Hide(); Users goUser = new Users(); goUser.Show(); } private void label15_Click(object sender, EventArgs e) { } private void dataShare_CellContentClick(object sender, DataGridViewCellEventArgs e) { } } }