private void transactionSave_Click(object sender, EventArgs e) { db = new Database.DatabaseHandler(); db.openConnection(); String dates = dateTimePicker1.Value.ToString("yyyy-MM-dd"); for (int i = 0; i < salesman_gridview.RowCount - 1; i++) { string P_ID = salesman_gridview.Rows[i].Cells[0].Value.ToString(); string Quantity = salesman_gridview.Rows[i].Cells[3].Value.ToString(); string Total_Price = salesman_gridview.Rows[i].Cells[2].Value.ToString(); //for (int i = 0; i < salesman_gridview.RowCount; i++) double total_Cost = Convert.ToDouble(Total_Price); if (m_ID == 1) { total_Cost = total_Cost - (total_Cost * 0.05); } if (m_ID == 2) { total_Cost = total_Cost - (total_Cost * 0.1); } if (m_ID == 3) { total_Cost = total_Cost - (total_Cost * 0.2); } if (m_ID == 4) { total_Cost = total_Cost - (total_Cost * 0.25); } if (i == 0) { query = "INSERT INTO transaction(P_ID , Quantity , Total_Price , Date) VALUES('" + (P_ID) + "','" + (Quantity) + "','" + total_Cost + "','" + dates + "')"; } else { query = "INSERT INTO transaction " + "SELECT transaction.T_ID, " + "'" + (P_ID) + "','" + (Quantity) + "','" + total_Cost + "','" + dates + "' " + "FROM transaction ORDER BY transaction.T_ID DESC LIMIT 1"; } try { MySqlCommand cmd = new MySqlCommand(query, db.getmyConn()); cmd.ExecuteNonQuery(); } catch (Exception ev) { MessageBox.Show(ev.ToString()); } } if (id != 0) { try { query = "INSERT INTO proceed " + "SELECT transaction.T_ID, " + "'" + id + "'" + " FROM transaction ORDER BY transaction.T_ID DESC LIMIT 1"; MySqlCommand cmd = new MySqlCommand(query, db.getmyConn()); cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } MessageBox.Show("Saved"); db.closeConnection(); }