我创建了一个pos payform,但是当检测到相同的产品时,它将自动检测到它,并且它在增加数量行而不是最终价格行。这是我的代码:
private void Dodadivotabela()
{
bool Found = false;
if (dataGridView1.Rows.Count > 0)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (Convert.ToString(row.Cells[0].Value) == txtBarajKod.Text)
{
row.Cells[3].Value =
Convert.ToString(1 + Convert.ToInt64(row.Cells[3].Value));
Found = true;
break;
}
}
}
if (!Found)
{
price = float.Parse(txtCena.Text);
quantity = float.Parse(txtKolicina.Text);
finalprice = price * quantity;
var firstrow = txtBarajKod.Text;
var secrow = txtNaziv.Text;
var thirdrow = price;
var forthrow = quantity;
var fifthrow = finalprice;
dataGridView1.Rows.Add(prvred, vtorred, tretred, cetvrtred, pettired);
}
}
这是我对总行的计算:
public void PresmetajTotal()
{
var vkp = 0;
for (var i = 0; i < dataGridView1.Rows.Count; i++)
{
vkp += Convert.ToInt32(dataGridView1.Rows[i].Cells[4].Value);
txtTotal.Text = vkp.ToString();
}
}
问题在于DGV中有4行,数量行已更新,但最终价格行保持不变。
答案 0 :(得分:0)
当“ Found”为true时,如果“发现”为false,则似乎正在运行计算
If(Found){...}
而不是
If(!Found){...}