Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            cmd = new MySqlCommand("insert into bill values(?a,?b,?c,?d,?e,?f)", con);
            cmd.Parameters.AddWithValue("?a", textBox1.Text);
            cmd.Parameters.AddWithValue("?b", comboBox2.Text);
            cmd.Parameters.AddWithValue("?c", dateTimePicker1.Text);
            cmd.Parameters.AddWithValue("?d", textBox2.Text);
            cmd.Parameters.AddWithValue("?e", textBox4.Text);
            cmd.Parameters.AddWithValue("?f", comboBox1.Text);

            cmd.ExecuteNonQuery();
            int pcode = 0;
            int count = Convert.ToInt32(textBox2.Text);

            for (i = 0; i < count; i++)
            {
                cmd1 = new MySqlCommand("insert into bill_order values(?in,?rt,?qt,?ta,?bn)", con);
                cmd1.Parameters.AddWithValue("?in", item[i].Text);
                cmd1.Parameters.AddWithValue("?rt", rate[i].Text);
                cmd1.Parameters.AddWithValue("?qt", qty[i].Text);
                cmd1.Parameters.AddWithValue("?ta", textBox4.Text);
                cmd1.Parameters.AddWithValue("?bn", textBox1.Text);
                cmd1.ExecuteNonQuery();


                cmd2 = new MySqlCommand("select * from packing_product where prod_name=?pc", con);
                cmd2.Parameters.AddWithValue("?pc", item[i].Text);
                dr = cmd2.ExecuteReader();
                if (dr.Read())
                {
                    pcode = Convert.ToInt32(dr["prod_code"]);
                }
                dr.Close();
                cmd2 = new MySqlCommand("update stock set total_qty=total_qty-?qt where  typeofproduct='packing product' and prod_code=?pc", con);
                cmd2.Parameters.AddWithValue("?qt", qty[i].Text);

                cmd2.Parameters.AddWithValue("?pc", pcode);
                cmd2.ExecuteNonQuery();
                cmd2 = new MySqlCommand("select total_qty from stock where prod_code=?pc", con);
                cmd2.Parameters.AddWithValue("?pc", pcode);
                dr = cmd2.ExecuteReader();
                if (dr.Read())
                {
                    if (Convert.ToInt32(dr["total_qty"]) <= 3)
                    {
                        MessageBox.Show(item[i].Text + " remaining only " + dr[0]);
                    }
                }
                dr.Close();

                // updating stock as per product
            }
            if (comboBox2.Text == "Cash")
            {
                MessageBox.Show("Payment Successful...!");
            }
            else
            {
                toa = Convert.ToInt32(textBox4.Text);
                bno = Convert.ToInt32(textBox1.Text);
                Form7 f7 = new Form7(bno, toa);
                f7.Show();
            }
            Hide();
        }