Beispiel #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("please input a number");
                return;
            }
            else if (change < 0)
            {
                MessageBox.Show("kulang pa po");
                return;
            }
            string fooditem = "";

            int    quantity = 0, totalprice = 0;
            string datenum    = DateTime.Now.ToShortTimeString();
            string datestring = DateTime.Now.ToShortDateString();
            string date       = datestring + " " + datenum;

            for (int i = 0; i < listView1.Items.Count; i++)
            {
                string          myConn = "Server=127.0.0.1;Database=munchlab;Uid=root;Pwd=root;";
                MySqlConnection Conn   = new MySqlConnection(myConn);

                ordernum   = listView1.Items[i].SubItems[0].Text;
                quantity   = Convert.ToInt32(listView1.Items[i].SubItems[1].Text);
                totalprice = Convert.ToInt32(listView1.Items[i].SubItems[3].Text);
                fooditem   = listView1.Items[i].SubItems[2].Text;
                MySqlCommand getUP = new MySqlCommand();
                Conn.Open();
                getUP.Connection  = Conn;
                getUP.CommandText = "select price from menu where fooditem=@fooditem";
                getUP.Parameters.AddWithValue("@fooditem", fooditem);
                MySqlDataReader rdr = getUP.ExecuteReader();
                while (rdr.Read())
                {
                    unitprice = rdr.GetString("price").ToString();
                }
                rdr.Close();
                MySqlCommand insertSR = new MySqlCommand();
                insertSR.Connection  = Conn;
                insertSR.CommandText = "insert into salesreport(transactionnum, quantity, totalprice, fooditem, date, crewlog, unitprice, ordernum)values(@transactionnum, @quantity, @totalprice, @fooditem, @date, @crewlog, @unitprice, @ordernum)";
                insertSR.Parameters.AddWithValue("@totalprice", totalprice);
                insertSR.Parameters.AddWithValue("@quantity", quantity);
                insertSR.Parameters.AddWithValue("@fooditem", fooditem);
                insertSR.Parameters.AddWithValue("@date", date);
                insertSR.Parameters.AddWithValue("@transactionnum", transactionnum);
                insertSR.Parameters.AddWithValue("@crewlog", crewname);
                insertSR.Parameters.AddWithValue("@unitprice", unitprice);
                insertSR.Parameters.AddWithValue("@ordernum", ordernum);
                insertSR.ExecuteNonQuery();
            }
            transactionnum++;
            string          myConn2  = "Server=127.0.0.1;Database=munchlab;Uid=root;Pwd=root;";
            MySqlConnection Conn2    = new MySqlConnection(myConn2);
            MySqlCommand    updateTN = new MySqlCommand();

            updateTN.Connection = Conn2;
            Conn2.Open();
            updateTN.CommandText = "update transactionnumber set transactionnum=@transactionnum";
            updateTN.Parameters.AddWithValue("@transactionnum", transactionnum);
            updateTN.ExecuteNonQuery();
            updateTN.CommandText = "TRUNCATE TABLE salesinvoice";
            updateTN.ExecuteNonQuery();
            MessageBox.Show("Transaction complete");
            MENU men = new MENU();

            this.Hide();
            men.ShowDialog();
        }