 |
|
สอบถามเรื่องการ Check ค่าก่อน Add row datagridview ครับ |
|
 |
|
|
 |
 |
|
ไม่ Debug ดูละครับ ว่ามันเข้า เคสตรงไหน มี Tools มี่สุดยอดอย่าง Visual Studio อยู่แล้ว
|
 |
 |
 |
 |
Date :
2016-08-19 09:59:10 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเอา อันใดอันหนึ่งจาก 2 อันนี้ออกนะครับ
Code (C#)
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";
}
|
 |
 |
 |
 |
Date :
2016-08-21 06:55:09 |
By :
bigsuntat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาออกเเล้วครับลองทั้งสองอัน ยังไม่ได้ ครับ
|
 |
 |
 |
 |
Date :
2016-08-22 23:20:45 |
By :
mtts10448 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองออกแบบโค๊ดดีๆครับ
ไหนๆก็ไหนๆ ลองอธิบายโค๊ดหน่อยซิครับว่าที่เขียนมามันตรงแล้วจริงๆรึ
เหมือนมันจะขัดกับความเป็นจริงอยู่นา
Code (C#)
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";
}
}
|
 |
 |
 |
 |
Date :
2016-08-23 08:14:43 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นะ่นละครับ ผมขียนเป็นแบบอื่นไม่รู้จะเขียนยังไงครับ
|
 |
 |
 |
 |
Date :
2016-08-23 09:20:26 |
By :
mtts10448 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|