private void button2_Click(object sender, EventArgs e) { int pcode = 0; int count = Convert.ToInt32(textBox2.Text); for (int i = 0; i < count; i++) { cmd2 = new MySqlCommand("insert into purchase_new values(?a,?b,?c,?d,?e,?f,?g,?h,?i,?j,?k,?l,?m,?n)", con); cmd2.Parameters.AddWithValue("?a", textBox1.Text); cmd2.Parameters.AddWithValue("?b", comboBox1.Text); if (radioButton1.Checked == true) { cmd2.Parameters.AddWithValue("?c", "packing product"); } else { cmd2.Parameters.AddWithValue("?c", "Raw Material"); } cmd2.Parameters.AddWithValue("?d", comboBox2.Text); cmd2.Parameters.AddWithValue("?e", prod[i].Text); cmd2.Parameters.AddWithValue("?f", rate[i].Text); cmd2.Parameters.AddWithValue("?g", qty[i].Text); cmd2.Parameters.AddWithValue("?h", tot_amt[i].Text); cmd2.Parameters.AddWithValue("?i", textBox3.Text); cmd2.Parameters.AddWithValue("?j", comboBox3.Text); cmd2.Parameters.AddWithValue("?k", textBox5.Text); cmd2.Parameters.AddWithValue("?l", date[i].Text); cmd2.Parameters.AddWithValue("?m", dateTimePicker1.Text); // cmd2.Parameters.AddWithValue("?j", textBox5.Text); cmd2.Parameters.AddWithValue("?n", pcode); cmd2.ExecuteNonQuery(); // MessageBox.Show("Value added"); if (radioButton1.Checked == true) { cmd2 = new MySqlCommand("select * from packing_product where prod_name=?pc", con); cmd2.Parameters.AddWithValue("?pc", prod[i].Text); dr = cmd2.ExecuteReader(); if (dr.Read()) { pcode = Convert.ToInt32(dr["prod_code"]); // MessageBox.Show(pcode.ToString()); } dr.Close(); } else { cmd2 = new MySqlCommand("select * from raw_material where prod_name=?pc", con); cmd2.Parameters.AddWithValue("?pc", prod[i].Text); dr = cmd2.ExecuteReader(); if (dr.Read()) { pcode = Convert.ToInt32(dr["prod_code"]); } dr.Close(); } cmd3 = new MySqlCommand("select * from stock where typeofproduct=?a and prod_code=?b", con); if (radioButton1.Checked == true) { cmd3.Parameters.AddWithValue("?a", "packing product"); } else { cmd3.Parameters.AddWithValue("?a", "Raw Material"); } cmd3.Parameters.AddWithValue("?b", pcode); dr2 = cmd3.ExecuteReader(); if (dr2.Read()) { dr2.Close(); cmd4 = new MySqlCommand("update stock set total_qty=total_qty+ ?tq where prod_code=?pc and typeofproduct=?tp", con); cmd4.Parameters.AddWithValue("?tq", qty[i].Text); cmd4.Parameters.AddWithValue("?pc", pcode); if (radioButton1.Checked == true) { cmd4.Parameters.AddWithValue("?tp", "packing product"); } else { cmd4.Parameters.AddWithValue("?tp", "Raw Material"); } cmd4.ExecuteNonQuery(); // MessageBox.Show("Value updated"); //textBox1.Clear(); //textBox2.Clear(); } else { dr2.Close(); cmd4 = new MySqlCommand("insert into stock(total_qty,prod_code,typeofproduct) values(?tq,?pc,?tp)", con); cmd4.Parameters.AddWithValue("?tq", qty[i].Text); cmd4.Parameters.AddWithValue("?pc", pcode); if (radioButton1.Checked == true) { cmd4.Parameters.AddWithValue("?tp", "packing product"); } else { cmd4.Parameters.AddWithValue("?tp", "Raw Material"); } cmd4.ExecuteNonQuery(); // MessageBox.Show("Value added into stock"); //textBox1.Clear(); //textBox2.Clear(); } } if (comboBox2.Text == "Cash") { MessageBox.Show("Payment successful"); } else { cmd5 = new MySqlCommand("insert into supplier_credit values(?bn,?sn,?na)", con); cmd5.Parameters.AddWithValue("?bn", textBox1.Text); cmd5.Parameters.AddWithValue("?sn", comboBox1.Text); cmd5.Parameters.AddWithValue("?na", textBox5.Text); cmd5.ExecuteNonQuery(); Form28 f28 = new Form28(); f28.Show(); // updating stock as per product } Hide(); }
private void supplierCreditToolStripMenuItem_Click(object sender, EventArgs e) { Form28 f28 = new Form28(); f28.Show(); }