if (DB_Reader.HasRows)
{
//Boolean to check if he has row has been
bool Found = false;
if (dataGridView1.Rows.Count > 0)
{
//Check if the product Id exists
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (Convert.ToString(row.Cells[0].Value) == textBox1.Text && txtqty + Convert.ToInt16(row.Cells[2].Value) <= Convert.ToInt32(DB_Reader.GetString("stock")))
{
//Update the Quantity of the found row
row.Cells[2].Value = Convert.ToString(txtqty + Convert.ToInt16(row.Cells[2].Value));
row.Cells[3].Value = Convert.ToInt16(row.Cells[2].Value) * Convert.ToDecimal(DB_Reader.GetString("sale_price"));
Found = true;
this.textBox1.Text = "";
this.textEdit4.Text = "1";
}
}
if (!Found && txtqty <= Convert.ToInt32(DB_Reader.GetString("stock")))
{
//Add the row to grid view
dataGridView1.Rows.Add(DB_Reader.GetString("product_barcode"), DB_Reader.GetString("product_name"), txtqty, txtSum);
this.textBox1.Text = "";
this.textEdit4.Text = "1";
}
}
else
{
if (txtqty <= Convert.ToInt32(DB_Reader.GetString("stock")))
{
//Add the row to grid view for the first time
dataGridView1.Rows.Add(DB_Reader.GetString("product_barcode"), DB_Reader.GetString("product_name"), txtqty, txtSum);
this.textBox1.Text = "";
this.textEdit4.Text = "1";
}
}
if (DB_Reader.HasRows)
{
//Boolean to check if he has row has been
bool Found = false;
if (dataGridView1.Rows.Count > 0)
{
//Check if the product Id exists
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (Convert.ToString(row.Cells[0].Value) == textBox1.Text && txtqty + Convert.ToInt16(row.Cells[2].Value) <= Convert.ToInt32(DB_Reader.GetString("stock")))
{
//Update the Quantity of the found row
row.Cells[2].Value = Convert.ToString(txtqty + Convert.ToInt16(row.Cells[2].Value));
row.Cells[3].Value = Convert.ToInt16(row.Cells[2].Value) * Convert.ToDecimal(DB_Reader.GetString("sale_price"));
Found = true;
this.textBox1.Text = "";
this.textEdit4.Text = "1";
}
}
if (!Found && txtqty <= Convert.ToInt32(DB_Reader.GetString("stock")))
{
//Add the row to grid view
dataGridView1.Rows.Add(DB_Reader.GetString("product_barcode"), DB_Reader.GetString("product_name"), txtqty, txtSum);
this.textBox1.Text = "";
this.textEdit4.Text = "1";
}
}
else
{
if (txtqty <= Convert.ToInt32(DB_Reader.GetString("stock")))
{
//Add the row to grid view for the first time
dataGridView1.Rows.Add(DB_Reader.GetString("product_barcode"), DB_Reader.GetString("product_name"), txtqty, txtSum);
this.textBox1.Text = "";
this.textEdit4.Text = "1";
}
}