//login button private void button1_Click(object sender, EventArgs e) { try { MySqlConnection myConn = new MySqlConnection(Connection.myConnection); MySqlCommand SelectCommand = new MySqlCommand("Select * from cashier where username='******'and password='******';", myConn); MySqlDataReader myReader; myConn.Open(); myReader = SelectCommand.ExecuteReader(); int count = 0; while (myReader.Read()) { count = count + 1; } if (count == 1) { this.Hide(); cashier Cashier = new cashier(); Cashier.Show(); } else { MessageBox.Show("Your Username Password is incorrect"); } myConn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//payment button private void button1_Click(object sender, EventArgs e) { if (textBox3.Text == "") { MessageBox.Show("You have not calculated the balance"); textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; } else { try { DialogResult dialog = MessageBox.Show("Confirm the Payment?", "Payment Confirm", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { MySqlConnection myConn = new MySqlConnection(Connection.myConnection); MySqlCommand SelectCom = new MySqlCommand("insert into sales_invoice (invoiceNum,date,time,details,totalBill,discount,cashPaid,balance) values ('" + label7.Text + "','" + label1.Text + "','" + DateTime.Now.ToLongTimeString() + "','" + richTextBox1.Text + "','" + textBox1.Text + "','" + label9.Text + "','" + label10.Text + "','" + textBox3.Text + "') ", myConn); MySqlCommand SelectCom1 = new MySqlCommand("insert into cash_received_from_sales (invoiceNum,date,time,cashPaid) values ('" + label7.Text + "','" + label1.Text + "','" + DateTime.Now.ToLongTimeString() + "','" + label10.Text + "')", myConn); MySqlDataReader myReader; MySqlDataReader myReader1; myConn.Open(); myReader = SelectCom.ExecuteReader(); myConn.Close(); if (label10.Text != "0.00") { myConn.Open(); myReader1 = SelectCom1.ExecuteReader(); } MessageBox.Show("Payment has been completed"); this.Close(); foreach (Form s in Application.OpenForms) { if (s.Text == "Cashier") { s.Close(); break; } } cashier c = new cashier(); c.Show(); } else if (dialog == DialogResult.No) { textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
//close the form private void button6_Click(object sender, EventArgs e) { try { DialogResult dialog = MessageBox.Show("Do you really want to clear the bill?", "Clear", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { MySqlConnection myConn = new MySqlConnection(Connection.myConnection); MySqlCommand SelectCom = new MySqlCommand("delete from sales where invoiceNum = '" + label7.Text + "'", myConn); MySqlDataReader myReader; myConn.Open(); myReader = SelectCom.ExecuteReader(); this.Close(); cashier c = new cashier(); c.Show(); } else if (dialog == DialogResult.No) { } } catch (Exception ex) { MessageBox.Show(ex.Message); } }