private void Insert() { if (id != -1) { string queryz = $"DELETE FROM OrderData WHERE idOrderBuy = {id}"; OleDbCommand commandz = new OleDbCommand(queryz, Form5.myConnection); commandz.ExecuteNonQuery(); } int idOrderBuy = DBmanager.GetId("OrderBuy", "idOrderBuy"); string query = $"INSERT INTO OrderData (idOrderBuy,data) VALUES ({idOrderBuy},'{DateTime.Now}') "; OleDbCommand command = new OleDbCommand(query, Form5.myConnection); command.ExecuteNonQuery(); for (int i = 0; i < orders.Count; i++) { if (orders[i].count != 0) { query = $"INSERT INTO OrderBuy (idOrderBuy,idStock,colech) VALUES ({idOrderBuy},{orders[i].idStoock},{orders[i].count}) "; command = new OleDbCommand(query, Form5.myConnection); command.ExecuteNonQuery(); } } Export(); }
private void button1_Click(object sender, EventArgs e) { if (Form5.famClient != "") { int idOdrer = DBmanager.GetId("Orders", "idOrder"); string data = DateTime.Now.ToString(); string query = $"INSERT INTO Orders (idClient,data,idOrder,skidka) VALUES ({Form5.idClient},'{DateTime.Now}',{idOdrer},{Form5.skidka})"; OleDbCommand command = new OleDbCommand(query, Form5.myConnection); command.ExecuteNonQuery(); for (int i = 0; i < Form5.bascet.Count; i++) { query = $"SELECT idColor FROM Colors WHERE color = '{Form5.bascet[i].color}'"; command = new OleDbCommand(query, Form5.myConnection); int idColor = int.Parse(command.ExecuteScalar().ToString()); query = $"SELECT idStock FROM Stock WHERE idPhone = {Form5.bascet[i].idPhone} AND idFleshMem = {Form5.bascet[i].idFleshMem} AND idColor = {idColor}"; command = new OleDbCommand(query, Form5.myConnection); int idStock = int.Parse(command.ExecuteScalar().ToString()); //int idStock = query = $"INSERT INTO Histori (idOrder,idStock,colech,price) VALUES ({idOdrer},{idStock},{Form5.bascet[i].count},{summa})"; command = new OleDbCommand(query, Form5.myConnection); command.ExecuteNonQuery(); } if (checkBox1.Checked) { Export(idOdrer, data); Messege mes = new Messege(Messege.messegeType.done, "Готово"); mes.ShowDialog(); DeleteBas(); if (System.Windows.Forms.Application.OpenForms["Form5"] != null) { (System.Windows.Forms.Application.OpenForms["Form5"] as Form5).OpenPhones(); } Form5.famClient = null; Form5.skidka = 0; } else { DeleteBas(); if (System.Windows.Forms.Application.OpenForms["Form5"] != null) { (System.Windows.Forms.Application.OpenForms["Form5"] as Form5).OpenPhones(); } Form5.famClient = null; Form5.skidka = 0; Messege mes = new Messege(Messege.messegeType.done, "Готово"); mes.ShowDialog(); } } else { Messege mes = new Messege(Messege.messegeType.error, "Для оформления заказа необходимо выбрать покупателя"); mes.ShowDialog(); } }
private void button5_Click(object sender, EventArgs e) { string query; OleDbCommand command; //if (Operation.update == oper) //{ // query = $"DELETE FROM Stock WHERE idPhone={idPhone}"; // command = new OleDbCommand(query, Form5.myConnection); // command.ExecuteNonQuery(); //} bool filledTextBox = this.Controls.OfType <TextBox>().All(textBox => textBox.Text != ""); bool filledComboBox = this.Controls.OfType <ComboBox>().All(comboBox => comboBox.Text != ""); //Task.Run(() => { while (true) CheckErrors(); }); //DestroiAllErPoints(); if (!filledComboBox || !filledTextBox) { Messege mes = new Messege(Messege.messegeType.error, $"Не все поля заполнены"); mes.ShowDialog(); timer1.Enabled = true; } else if (!CheckModel("Phons", textBox2.Text) && oper == Operation.insert) { CreatErrorPoint(textBox2); error = true; Messege mes = new Messege(Messege.messegeType.error, $"Телефон с моделью {textBox2.Text} уже зарегистрирован"); mes.ShowDialog(); } else { data = comboBox14.Text; model = textBox2.Text; os = comboBox1.Text; //scrinSize = double.Parse(textBox8.Text); razScrin = comboBox16.Text; ram = int.Parse(comboBox4.Text); //mamori = int.Parse(comboBox5.Text); fSim = comboBox6.Text; cSim = int.Parse(comboBox7.Text); batari = int.Parse(textBox19.Text); compani = comboBox13.Text; if (comboBox2.Text == "Новый") { proc = textBox12.Text; speed = int.Parse(textBox11.Text); countCors = int.Parse(comboBox8.Text); razProс = int.Parse(comboBox9.Text); sGPU = int.Parse(textBox16.Text); GAccelModl = comboBox15.Text; idCors = DBmanager.GetId("Cors", "idProc"); query = $"INSERT INTO Cors (idProc,model,speed,nCors,razProc,sGPU,GAccelModl) VALUES ({idCors},'{proc}',{speed},{countCors},{razProс},{sGPU},'{GAccelModl}')"; command = new OleDbCommand(query, Form5.myConnection); command.ExecuteNonQuery(); } if (oper == Operation.insert) { idPhone = DBmanager.GetId("Phons", "idPhone"); } idProcInPhone = idCors; hDis = comboBox10.Text; mDis = comboBox11.Text.Replace(",", "."); List <int> idFlethMam = new List <int>(); texScren = comboBox12.Text; soatnoshStor = comboBox3.Text; //inStock =int.Parse(textBox4.Text); image = pictureBox1.Image; if (oper == Operation.insert) { query = $"INSERT INTO Phons (idPhone, model, data, os, ram, sizeSc, fsim,Csim, hDesign, mDesign, scrin, sizeBat," + $" componi, idProc, texScren, soatnoshStor, cam) VALUES ({idPhone}, '{model}', {data}, '{os}', {ram}, {textBox8.Text.Replace(",",".")}," + $" '{fSim}', {cSim}, '{hDis}', '{mDis}', '{razScrin}', {batari}, '{compani}', {idCors}, '{texScren}', '{soatnoshStor}', {textBox1.Text})"; } else { query = $"UPDATE Phons SET idPhone={idPhone}, model='{model}', data={data}, os='{os}', ram={ram}, sizeSc={textBox8.Text.Replace(",", ".")}, fsim='{fSim}',Csim={cSim}, hDesign='{hDis}', mDesign='{mDis}', scrin='{razScrin}', sizeBat={batari}," + $" componi='{compani}', idProc={idCors}, texScren='{texScren}', soatnoshStor='{soatnoshStor}', cam={textBox1.Text} WHERE idPhone={idPhone}"; } //else // query = $"UPDATE Phons SET idPhone={idPhone}, model={model}, data={data}, os={os}, ram={ram}, sizeSc={textBox8.Text}, fsim={fSim},Csim={cSim}, hDesign={hDis}, mDesign={mDis}, scrin={razScrin}, sizeBat={batari}, componi={compani}, idProc={idCors}, texScren={texScren}, soatnoshStor={soatnoshStor}, minPrise={strMinPrise}"; command = new OleDbCommand(query, Form5.myConnection); command.ExecuteNonQuery(); DBmanager.SetImage(image, idPhone); int idFleshMam = 0; int idColor = 0; List <int> idStocs = new List <int>(); for (int i = 0; i < MemComboBoxes.Count; i++) { while (true) { query = $"SELECT idFleshMam FROM FleshMem WHERE FleshMamari = {MemComboBoxes[i].Text}"; command = new OleDbCommand(query, Form5.myConnection); try { idFleshMam = int.Parse(command.ExecuteScalar().ToString()); break; } catch (Exception) { query = $"INSERT INTO FleshMem (FleshMamari) VALUES ({MemComboBoxes[i].Text})"; command = new OleDbCommand(query, Form5.myConnection); command.ExecuteNonQuery(); } } while (true) { query = $"SELECT idColor FROM Colors WHERE color = '{ColorComboBoxes[i].Text}'"; command = new OleDbCommand(query, Form5.myConnection); try { idColor = int.Parse(command.ExecuteScalar().ToString()); break; } catch (Exception) { //query = $"INSERT INTO FleshMem (FleshMamari) VALUES ({MemComboBoxes[i].Text})"; query = $"INSERT INTO Colors (color) VALUES ('{ColorComboBoxes[i].Text}')"; command = new OleDbCommand(query, Form5.myConnection); command.ExecuteNonQuery(); } } if (oper == Operation.insert) { int idStoock = DBmanager.GetId("Stock", "idStock"); query = $"INSERT INTO Stock (idStock,idPhone,idFleshMem,idColor,colech,prise) VALUES ({idStoock},{idPhone},{idFleshMam},{idColor},{NumericUpDowns[i].Value},{TextBoxes[i].Text.Replace(",",".")})"; command = new OleDbCommand(query, Form5.myConnection); command.ExecuteNonQuery(); } else { try { query = $"UPDATE Stock SET idPhone = {idPhone},idFleshMem = {idFleshMam},idColor = {idColor},colech = {NumericUpDowns[i].Value}, prise = {TextBoxes[i].Text.Replace(",", ".")} WHERE idStock = {Form6.idStocks[i]}"; command = new OleDbCommand(query, Form5.myConnection); command.ExecuteNonQuery(); } catch (Exception) { int idStock = -1; idStock = DBmanager.GetId("Stock", "idStock"); query = $"INSERT INTO Stock (idStock,idPhone,idFleshMem,idColor,colech,prise) VALUES ({idStock},{idPhone},{idFleshMam},{idColor},{NumericUpDowns[i].Value},{TextBoxes[i].Text.Replace(",", ".")})"; command = new OleDbCommand(query, Form5.myConnection); command.ExecuteNonQuery(); //idStocs.Add(idStock); } } for (int t = 0; t < Form6.idDeleteStocks.Count; t++) { query = $"UPDATE Stock SET chatged = TRUE WHERE idStock = {Form6.idDeleteStocks[t]}"; command = new OleDbCommand(query, Form5.myConnection); command.ExecuteNonQuery(); } } if (oper == Operation.update) { Messege mes = new Messege(Messege.messegeType.done, $"Характеристики {textBox2.Text} успешно изменены."); mes.ShowDialog(); if (System.Windows.Forms.Application.OpenForms["Form5"] != null) { (System.Windows.Forms.Application.OpenForms["Form5"] as Form5).OpenPhones(); } } else { Messege mes = new Messege(Messege.messegeType.done, $"Телефон {textBox2.Text} успешно добавлен."); mes.ShowDialog(); if (System.Windows.Forms.Application.OpenForms["Form5"] != null) { (System.Windows.Forms.Application.OpenForms["Form5"] as Form5).OpenPhones(); } } } }