private void button2_Click(object sender, EventArgs e) { //LoadData(); //comboBox4.SelectedIndex= CombSetValue(comboBox4,"8"); //form6 = new Form6(222); //form6.ShowDialog(); DBmanager.SetImage(textBox20.Text, 504); }
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(); } } } }