Hello Team,
When I Add item to the list by entring product barcode into the Search textbox and the same item is added again it appears on a new row means while I want the quantity and total sales to increase when the sames item is selected again but in this case it appears on a new rows.
public void ADDToLIST() { try {
// int i = 0; using (SqlConnection cn = new SqlConnection(dbcon.MyConnection())) { cn.Open(); using (SqlCommand cm = new SqlCommand("select ProductId, PCode, ProductDate, ProductName, Category, CostPrice, Profit, SalesPrice, Tax, TotalPrice,StockIn, Barcode from tblProduct where Barcode like @searchBarcode", cn)) { cm.Parameters.AddWithValue("@searchBarcode", "%" + txt_Search_Product_Barcode.Text + "%"); using (SqlDataReader dr = cm.ExecuteReader()) { while (dr.Read()) if (txt_Search_Product_Barcode.Text == String.Empty) { return; } else {
string productId; string pcode; string productname; string category; decimal saleprice; decimal tax; string totalprice; decimal totalqtyprice;
productId = dr["ProductId"].ToString(); pcode = dr["PCode"].ToString(); productname = dr["ProductName"].ToString(); category = dr["Category"].ToString(); saleprice = Convert.ToDecimal(dr["SalesPrice"].ToString()); tax = Convert.ToDecimal(dr["Tax"].ToString()); totalprice = dr["TotalPrice"].ToString();
totalqtyprice =Convert.ToDecimal(saleprice * (tax) / 100) + saleprice; dataGridView1.Rows.Add(productId, pcode, productname, category, saleprice, tax, totalprice, 1, totalqtyprice.ToString("#,##0.00")); txt_Search_Product_Barcode.Clear(); txt_Search_Product_Barcode.Focus(); }
} } } } catch (Exception ex) { if (dr != null && !dr.IsClosed) { dr.Close(); } if (cn.State == ConnectionState.Open) { cn.Close();
} MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } dataGridView1.Rows[numrows].Cells[7].Value = int.Parse("1") + numtext; dataGridView1.Rows[numrows].Cells[8].Value = dataGridView1.Rows[numrows].Cells[6].Value * dataGridView1.Rows[numrows].Cells[7].Value; }