private void Button3_Click(object sender, EventArgs e) { if (listBox1.Items.Count != 0) { ///////////Add price foreach (var item in listBox1.Items) { DetailParse.Add(item.ToString()); } forMessage += "Components: + <br>"; for (int i = 0; i < DetailParse.Count; i++) { for (int j = 0; j < DetailName.Count; j++) { if (DetailName[j] == DetailParse[i].Substring(0, DetailParse[i].IndexOf('-'))) { int uno = Convert.ToInt32(DetailParse[i].Substring(DetailParse[i].IndexOf('-') + 1)); int dos = Convert.ToInt32(DetailPrice[j]); Price += uno * dos; } } forMessage += DetailParse[i] + "<br>"; } forMessage += "<br> General component price: " + Price + "<br>"; /////////Create new model try { string sql = "insert into Model(Model_id, M_price) values (null, " + Price + ")"; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.ExecuteNonQuery(); cmd = new MySqlCommand { Connection = conn, CommandText = string.Format("SELECT MAX(Model_id) FROM Model;") }; MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { model_id = reader.GetInt32(0); } reader.Close(); ///////////////////////add info into consist for (int i = 0; i < DetailParse.Count; i++) { for (int j = 0; j < DetailName.Count; j++) { if (DetailName[j] == DetailParse[i].Substring(0, DetailParse[i].IndexOf('-'))) { int count = Convert.ToInt32(DetailParse[i].Substring(DetailParse[i].IndexOf('-') + 1)); sql = "insert into consists(Detail_id, Model_id, count) values (" + DetailId[j] + "," + model_id + "," + count + ")"; cmd = new MySqlCommand(sql, conn); cmd.ExecuteNonQuery(); } } } } catch (Exception ex) { } int current_price = 0; /////////////////Orders block try { MySqlCommand cmd = new MySqlCommand { Connection = conn, CommandText = string.Format("SELECT Price FROM orders WHERE Order_id=" + OrderId + ";") }; MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { current_price = reader.GetInt32(0); } reader.Close(); string sql = "UPDATE Orders SET Price=" + (current_price + Price) + " WHERE Order_id=" + OrderId + ";"; cmd = new MySqlCommand(sql, conn); cmd.ExecuteNonQuery(); sql = "UPDATE Orders SET Model_id=" + model_id + " WHERE Order_id=" + OrderId + ";"; cmd = new MySqlCommand(sql, conn); cmd.ExecuteNonQuery(); sql = "UPDATE Orders SET Status_id=" + 2 + " WHERE Order_id=" + OrderId + ";"; cmd = new MySqlCommand(sql, conn); cmd.ExecuteNonQuery(); Send(forMessage); CreateModel model = new CreateModel(Id); model.Show(); conn.Close(); this.Dispose(); } catch (Exception ex) { } } else { MessageBox.Show("Parts List is empty, add at least one piece!"); } }