private void glassButton5_Click(object sender, EventArgs e) { int supr = 0; bool chngeoccur = false; decimal cashamount = 0; decimal cashamount2 = 0; for (int ii = 0; ii < dataGridView1.Rows.Count; ii++) { if (dataGridView1.Rows[ii].Cells[2].Value.ToString() != "0") { chngeoccur = true; } } if (chngeoccur==true) { if (MessageBox.Show("Are you sure you want to void selected Item(s)?", "Void Transaction", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //try { for (int ii = 0; ii < dataGridView1.Rows.Count; ii++) { // MessageBox.Show(dataGridView1.Rows[ii].Cells[0].Value.ToString()); if (dataGridView1.Rows[ii].Cells[4].Value.ToString().Contains("Void")) { MessageBox.Show(dataGridView1.Rows[ii].Cells[1].Value.ToString() + " is already void"); } else { if (dataGridView1.Rows[ii].Cells[2].Value.ToString() != "0") { int quandif = 0; int quandif2 = 0; decimal newamount = Convert.ToDecimal(dataGridView1.Rows[ii].Cells[5].Value.ToString()); decimal newamount2 = 0; { string query; StreamReader sr = new StreamReader(Application.StartupPath.ToString() + "//data.txt"); line = sr.ReadLine(); StreamReader sr3 = new StreamReader(Application.StartupPath.ToString() + "//dataP.txt"); dbP = sr3.ReadLine(); StreamReader sr4 = new StreamReader(Application.StartupPath.ToString() + "//dataU.txt"); dbU = sr4.ReadLine(); string sConnection = "SERVER=" + line + ";" + "DATABASE=lamolinventory;" + "UID=" + dbU + ";" + "PASSWORD='******';"; MySqlConnection sqlConnection = new MySqlConnection(sConnection); query = "Select * from trans_items WHERE trans_item_id = '" + dataGridView1.CurrentRow.Cells[3].Value.ToString() + "' "; dbFill(query); while (dbReader.Read()) { quandif2 = Convert.ToInt32(dbReader["quan"].ToString()); quandif = quandif2 - Convert.ToInt32(dataGridView1.Rows[ii].Cells[2].Value.ToString()); newamount2 = newamount * quandif; } dbReader.Close(); dbConn.Close(); } { string query33; StreamReader sr33 = new StreamReader(Application.StartupPath.ToString() + "//data.txt"); line = sr33.ReadLine(); StreamReader sr34 = new StreamReader(Application.StartupPath.ToString() + "//dataP.txt"); dbP = sr34.ReadLine(); StreamReader sr35 = new StreamReader(Application.StartupPath.ToString() + "//dataU.txt"); dbU = sr35.ReadLine(); string sConnection33 = "SERVER=" + line + ";" + "DATABASE=lamolinventory;" + "UID=" + dbU + ";" + "PASSWORD='******';"; MySqlConnection sqlConnection33 = new MySqlConnection(sConnection33); { // query33 = " Update trans_items Set sum_amount = '" + dataGridView1.Rows[ii].Cells[6].Value.ToString() + "',quan = '" + quandif + "', notes = '" + "Void " + "(" + System.DateTime.Now.ToShortDateString() + ")" + "' Where trans_item_id = '" + dataGridView1.Rows[ii].Cells[3].Value.ToString() + "'"; query33 = " Update trans_items Set sum_amount = '" + dataGridView1.Rows[ii].Cells[6].Value.ToString() + "',quan = '" + quandif + "' Where trans_item_id = '" + dataGridView1.Rows[ii].Cells[3].Value.ToString() + "'"; } dbQuery(query33); if (supr == 0) { MessageBox.Show("Item(s) are now void."); } supr++; } { { decimal qq1 = 0; decimal qq2 = 0; int qq3 = 0; int qq4 = 0; string query; string newdate = dateparser(Convert.ToDateTime(dataGridView1.Rows[ii].Cells[7].Value)).ToString(); // MessageBox.Show(newdate); StreamReader sr = new StreamReader(Application.StartupPath.ToString() + "//data.txt"); line = sr.ReadLine(); StreamReader sr3 = new StreamReader(Application.StartupPath.ToString() + "//dataP.txt"); dbP = sr3.ReadLine(); StreamReader sr4 = new StreamReader(Application.StartupPath.ToString() + "//dataU.txt"); dbU = sr4.ReadLine(); string sConnection = "SERVER=" + line + ";" + "DATABASE=lamolinventory;" + "UID=" + dbU + ";" + "PASSWORD='******';"; MySqlConnection sqlConnection = new MySqlConnection(sConnection); query = "Select * from totaltrans Where time_sum LIKE '" + newdate + "%' AND item_name = '" + dataGridView1.Rows[ii].Cells[1].Value.ToString() + "'"; dbFill(query); while (dbReader.Read()) { qq1 = Convert.ToDecimal(dbReader["sum_amount"].ToString()); qq2 = qq1 - (Convert.ToDecimal(dataGridView1.Rows[ii].Cells[2].Value.ToString()) * (Convert.ToDecimal(dataGridView1.Rows[ii].Cells[5].Value.ToString()))); qq3 = Convert.ToInt32(dbReader["quan"].ToString()); qq4 = qq3 - (Convert.ToInt32(dataGridView1.Rows[ii].Cells[2].Value.ToString())); // MessageBox.Show(qq2.ToString() + qq4.ToString()); { string query33; StreamReader sr33 = new StreamReader(Application.StartupPath.ToString() + "//data.txt"); line = sr33.ReadLine(); StreamReader sr34 = new StreamReader(Application.StartupPath.ToString() + "//dataP.txt"); dbP = sr34.ReadLine(); StreamReader sr35 = new StreamReader(Application.StartupPath.ToString() + "//dataU.txt"); dbU = sr35.ReadLine(); string sConnection33 = "SERVER=" + line + ";" + "DATABASE=lamolinventory;" + "UID=" + dbU + ";" + "PASSWORD='******';"; MySqlConnection sqlConnection33 = new MySqlConnection(sConnection33); { query33 = " Update totaltrans Set sum_amount = '" + qq2.ToString() + "',quan = '" + qq4.ToString() + "'WHERE time_sum LIKE '" + newdate + "%' AND item_name = '" + dataGridView1.Rows[ii].Cells[1].Value.ToString() + "'"; } dbQuery(query33); } } dbReader.Close(); dbConn.Close(); } } { { int qq3 = 0; int qq4 = 0; string query; string newdate = dateparser(Convert.ToDateTime(dataGridView1.Rows[ii].Cells[7].Value)).ToString(); // MessageBox.Show(newdate); StreamReader sr = new StreamReader(Application.StartupPath.ToString() + "//data.txt"); line = sr.ReadLine(); StreamReader sr3 = new StreamReader(Application.StartupPath.ToString() + "//dataP.txt"); dbP = sr3.ReadLine(); StreamReader sr4 = new StreamReader(Application.StartupPath.ToString() + "//dataU.txt"); dbU = sr4.ReadLine(); string sConnection = "SERVER=" + line + ";" + "DATABASE=lamolinventory;" + "UID=" + dbU + ";" + "PASSWORD='******';"; MySqlConnection sqlConnection = new MySqlConnection(sConnection); query = "Select * from itemlist Where item_name = '" + dataGridView1.Rows[ii].Cells[1].Value.ToString() + "'"; dbFill(query); while (dbReader.Read()) { qq3 = Convert.ToInt32(dbReader["quan"].ToString()); qq4 = qq3 + (Convert.ToInt32(dataGridView1.Rows[ii].Cells[2].Value.ToString())); // MessageBox.Show(qq2.ToString() + qq4.ToString()); { string query33; StreamReader sr33 = new StreamReader(Application.StartupPath.ToString() + "//data.txt"); line = sr33.ReadLine(); StreamReader sr34 = new StreamReader(Application.StartupPath.ToString() + "//dataP.txt"); dbP = sr34.ReadLine(); StreamReader sr35 = new StreamReader(Application.StartupPath.ToString() + "//dataU.txt"); dbU = sr35.ReadLine(); string sConnection33 = "SERVER=" + line + ";" + "DATABASE=lamolinventory;" + "UID=" + dbU + ";" + "PASSWORD='******';"; MySqlConnection sqlConnection33 = new MySqlConnection(sConnection33); { query33 = " Update itemlist Set quan = '" + qq4.ToString() + "'WHERE item_name = '" + dataGridView1.Rows[ii].Cells[1].Value.ToString() + "'"; } dbQuery(query33); } } dbReader.Close(); dbConn.Close(); } } { string query33; StreamReader sr33 = new StreamReader(Application.StartupPath.ToString() + "//data.txt"); line = sr33.ReadLine(); StreamReader sr34 = new StreamReader(Application.StartupPath.ToString() + "//dataP.txt"); dbP = sr34.ReadLine(); StreamReader sr35 = new StreamReader(Application.StartupPath.ToString() + "//dataU.txt"); dbU = sr35.ReadLine(); string sConnection33 = "SERVER=" + line + ";" + "DATABASE=lamolinventory;" + "UID=" + dbU + ";" + "PASSWORD='******';"; MySqlConnection sqlConnection33 = new MySqlConnection(sConnection33); try { query33 = "Insert Into voidtable Values('" + "VOID" + idcomponent() + ":" + textBox1.Text + "','" + dataGridView1.Rows[ii].Cells[3].Value.ToString() + "','" + dataGridView1.Rows[ii].Cells[1].Value.ToString() + "','" + dataGridView1.Rows[ii].Cells[2].Value.ToString() + "','" + datecomponent() + "','" + "Void" + "')"; dbQuery(query33); } catch { upvoidtable(dataGridView1.Rows[ii].Cells[3].Value.ToString(), Convert.ToInt32(dataGridView1.Rows[ii].Cells[2].Value.ToString())); } } { { string query; StreamReader sr = new StreamReader(Application.StartupPath.ToString() + "//data.txt"); line = sr.ReadLine(); StreamReader sr3 = new StreamReader(Application.StartupPath.ToString() + "//dataP.txt"); dbP = sr3.ReadLine(); StreamReader sr4 = new StreamReader(Application.StartupPath.ToString() + "//dataU.txt"); dbU = sr4.ReadLine(); string sConnection = "SERVER=" + line + ";" + "DATABASE=lamolinventory;" + "UID=" + dbU + ";" + "PASSWORD='******';"; MySqlConnection sqlConnection = new MySqlConnection(sConnection); query = "Select * from trans_items Where trans_id = '" + textBox1.Text + "'"; dbFill(query); while (dbReader.Read()) { cashamount = (Convert.ToDecimal(dbReader["sum_amount"].ToString())) + cashamount; } dbReader.Close(); dbConn.Close(); } { string query; StreamReader sr = new StreamReader(Application.StartupPath.ToString() + "//data.txt"); line = sr.ReadLine(); StreamReader sr3 = new StreamReader(Application.StartupPath.ToString() + "//dataP.txt"); dbP = sr3.ReadLine(); StreamReader sr4 = new StreamReader(Application.StartupPath.ToString() + "//dataU.txt"); dbU = sr4.ReadLine(); string sConnection = "SERVER=" + line + ";" + "DATABASE=lamolinventory;" + "UID=" + dbU + ";" + "PASSWORD='******';"; MySqlConnection sqlConnection = new MySqlConnection(sConnection); query = "Select * from trans_misc Where trans_id = '" + textBox1.Text + "'"; dbFill(query); while (dbReader.Read()) { cashamount2 = (Convert.ToDecimal(dbReader["payment"].ToString())) - cashamount; } dbReader.Close(); dbConn.Close(); } { string query33; StreamReader sr33 = new StreamReader(Application.StartupPath.ToString() + "//data.txt"); line = sr33.ReadLine(); StreamReader sr34 = new StreamReader(Application.StartupPath.ToString() + "//dataP.txt"); dbP = sr34.ReadLine(); StreamReader sr35 = new StreamReader(Application.StartupPath.ToString() + "//dataU.txt"); dbU = sr35.ReadLine(); string sConnection33 = "SERVER=" + line + ";" + "DATABASE=lamolinventory;" + "UID=" + dbU + ";" + "PASSWORD='******';"; MySqlConnection sqlConnection33 = new MySqlConnection(sConnection33); { query33 = "Update trans_misc Set trans_misc.change = '" + cashamount2 + "'Where trans_id = '" + textBox1.Text + "'"; // query33 = " Update totaltrans Set sum_amount = '" + qq2.ToString() + "',quan = '" + qq4.ToString() + "'WHERE time_sum LIKE '" + newdate + "%' AND item_name = '" + dataGridView1.Rows[ii].Cells[1].Value.ToString() + "'"; } dbQuery(query33); } string name = ""; { string query; StreamReader sr = new StreamReader(Application.StartupPath.ToString() + "//data.txt"); line = sr.ReadLine(); StreamReader sr3 = new StreamReader(Application.StartupPath.ToString() + "//dataP.txt"); dbP = sr3.ReadLine(); StreamReader sr4 = new StreamReader(Application.StartupPath.ToString() + "//dataU.txt"); dbU = sr4.ReadLine(); string sConnection = "SERVER=" + line + ";" + "DATABASE=lamolinventory;" + "UID=" + dbU + ";" + "PASSWORD='******';"; MySqlConnection sqlConnection = new MySqlConnection(sConnection); query = "Select * from logs WHERE userna = '" + user + "'"; dbFill(query); while (dbReader.Read()) { name = dbReader["names"].ToString(); } dbReader.Close(); dbConn.Close(); } { string query33; StreamReader sr33 = new StreamReader(Application.StartupPath.ToString() + "//data.txt"); line = sr33.ReadLine(); StreamReader sr34 = new StreamReader(Application.StartupPath.ToString() + "//dataP.txt"); dbP = sr34.ReadLine(); StreamReader sr35 = new StreamReader(Application.StartupPath.ToString() + "//dataU.txt"); dbU = sr35.ReadLine(); string sConnection33 = "SERVER=" + line + ";" + "DATABASE=lamolinventory;" + "UID=" + dbU + ";" + "PASSWORD='******';"; MySqlConnection sqlConnection33 = new MySqlConnection(sConnection33); query33 = "Insert Into security Values('" + System.DateTime.Now.ToString() + "(" + System.DateTime.Now.Millisecond.ToString() + ")_" + name + "','" + "Voided Transaction ID: " + textBox1.Text + "','" + System.DateTime.Now.ToString() + "','" + name + "','" + terms() + "')"; dbQuery(query33); } } ReceiptForm rc = new ReceiptForm(textBox1.Text, user, "void"); rc.Show(); { dataGridView1.Rows.Clear(); glassButton2.Enabled = false; glassButton5.Enabled = false; glassButton3.Enabled = false; textBox1.Text = ""; } } } } } } // catch { } } }