private void label12_Click(object sender, EventArgs e) { if (ProName.Text == "" || ProPrice.Text == "" || ProQty.Text == "" || ProQty.Text == "0" || Convert.ToInt32(ProQty.Text) < 1) { MessageBox.Show("Please select the Valid entries"); } else { int remainingitems; SqlCommand command = new SqlCommand("select ProductQty from ProductTable WHERE Productid= " + Productid.Text + "", Con); Con.Open(); SqlDataReader read = command.ExecuteReader(); read.Read(); dbproqty = (read["ProductQty"].ToString()); Con.Close(); remainingitems = Convert.ToInt32(dbproqty) + Convert.ToInt32(ProQty.Text); String query = "update ProductTable set ProductQty='" + remainingitems + "'where Productid = " + Productid.Text + ""; SqlCommand cmd = new SqlCommand(query, Con); Con.Open(); cmd.ExecuteNonQuery(); //MessageBox.Show("Category is Updated Successfully"); Con.Close(); DataGridViewRow newrow = new DataGridViewRow(); newrow.CreateCells(Orderdgv); newrow.Cells[0].Value = Productid.Text; newrow.Cells[1].Value = ProName.Text; newrow.Cells[2].Value = ProPrice.Text; newrow.Cells[3].Value = ProQty.Text; newrow.Cells[4].Value = -(Convert.ToInt32(ProPrice.Text) * Convert.ToInt32(ProQty.Text)); int totalprice = Convert.ToInt32(ProPrice.Text) * Convert.ToInt32(ProQty.Text); Orderdgv.Rows.Add(newrow); //gridtotal = (gridtotal + totalprice); //TotalPrice.Text = gridtotal.ToString(); int sum = 0; for (int i = 0; i < Orderdgv.Rows.Count; ++i) { sum += Convert.ToInt32(Orderdgv.Rows[i].Cells[4].Value); } TotalPrice.Text = sum.ToString(); ProQty.Clear(); ProName.Clear(); ProPrice.Clear(); Productid.Clear(); populate(); read.Close(); } }
private void label1_Click(object sender, EventArgs e) { if (ProName.Text == "" || ProPrice.Text == "" || ProQty.Text == "" || ProQty.Text == "0" || Convert.ToInt32(ProQty.Text) < 1) { MessageBox.Show("Please select the Valid entries"); } else { int remainingitems; SqlCommand command = new SqlCommand("select ProductQty from ProductTable WHERE Productid= " + Productid.Text + "", Con); Con.Open(); SqlDataReader read = command.ExecuteReader(); read.Read(); dbproqty = (read["ProductQty"].ToString()); if (Convert.ToInt32(ProQty.Text) > Convert.ToInt32(dbproqty)) { MessageBox.Show("Number of items are low so please enter valid quantity\n Current Quantity = " + dbproqty + ""); Con.Close(); } else { Con.Close(); remainingitems = Convert.ToInt32(dbproqty) - Convert.ToInt32(ProQty.Text); String query = "update ProductTable set ProductQty='" + remainingitems + "'where Productid = " + Productid.Text + ""; SqlCommand cmd = new SqlCommand(query, Con); Con.Open(); cmd.ExecuteNonQuery(); MessageBox.Show("Category is Updated Successfully"); Con.Close(); DataGridViewRow newrow = new DataGridViewRow(); newrow.CreateCells(Orderdgv); newrow.Cells[0].Value = Productid.Text; newrow.Cells[1].Value = ProName.Text; newrow.Cells[2].Value = ProPrice.Text; newrow.Cells[3].Value = ProQty.Text; newrow.Cells[4].Value = Convert.ToInt32(ProPrice.Text) * Convert.ToInt32(ProQty.Text); int totalprice = Convert.ToInt32(ProPrice.Text) * Convert.ToInt32(ProQty.Text); Orderdgv.Rows.Add(newrow); gridtotal = gridtotal + totalprice; TotalPrice.Text = gridtotal.ToString(); ProQty.Clear(); ProName.Clear(); ProPrice.Clear(); Productid.Clear(); populate(); } read.Close(); } }