我正在设置一个功能来计算销售账单中的数量并比较我的存储中的数量。
当我从一个项目中获取数量时,该功能会将获取的数量与网格中的总量进行比较。
示例: 项目x = 10,项目y = 5,项目z = 6
当我从y项中拿5,然后从x项中拿5时,它发出异议:“数量不可用,您只有10个”
int Qte;
string sumQte;
//Calculate item quantity
void sum_Quantity()
{
try
{
if (dgvSale.Rows.Count < 1)
{
sumQte = "0";
}
else
{
for (int i = 0; i < dgvSale.Rows.Count; i++)
{
sumQte = (from DataGridViewRow row in dgvSale.Rows
where row.Cells[3].FormattedValue.ToString()
!= string.Empty &&
dgvSale.Rows[i].Cells[0].Value.ToString() ==
row.Cells[0].FormattedValue.
ToString()
select
Convert.ToDouble(row.Cells[3].FormattedValue)).Sum().ToString();
txtSumQte.Text = sumQte;
txtQte.Text = Convert.ToString(Qte);
}
}
}
catch
{
return;
}
}
if(Convert.ToInt32(txtQuantity.Text) > Qte)
{
MessageBox.Show("This Quantity is not available" +
Environment.NewLine + "You have : "
+ Qte.ToString(),"",
MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
txtQuantity.Clear();
txtQuantity.Focus();
return;
}
if(dgvSale.Rows.Count > 0)
{
if (Convert.ToInt32(txtQuantity.Text) +
Convert.ToInt32(sumQte.ToString()) > Qte)
{
MessageBox.Show("This Quantity is not available" +
Environment.NewLine + "You have : "
+ Qte.ToString(), "", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
txtQuantity.Clear();
txtQuantity.Focus();
return;
}
}