我正在尝试使用sql
和C#
为医疗商店创建库存系统,我在
private void cmbProductID_SelectedIndexChanged_2(object sender, EventArgs e)
{
string query = @"SELECT [ProductName],[Total_Product],[Pro_Instock] ,[ProductSold] FROM [vwSalesTracking] Where ProductId=@idd";
cmd = new SqlCommand(query);
cmd.Parameters.AddWithValue("@idd", cmbProductID.Text);
dt = db.SelectRecord(cmd);
if (dt.Rows[0]["Pro_Instock"]==null)
{
grdtractsold1.Tag = dt.Rows[0]["Total_Product"];
}
else
{
grdtractsold1.Tag = dt.Rows[0]["Pro_Instock"];
}
grdtractsold1.DataSource = dt;
}
}
在上面的代码我正在尝试当Pro_Instock“== null然后做grdtractsold1.Tag = dt.Rows [0] [”Total_Product“] 其他 do grdtractsold1.Tag = dt.Rows [0] [“Pro_Instock”]; 但问题是,当没有出售任何东西时,我尝试销售的数量少于总数量(总数量为100,我想销售30件商品,它也会向我们显示错误,或者我试图销售更多然后总量)它也显示消息,所以如果卖出的数量少于那么它应该显示消息的总数量我应该怎么做呢?否则它不应该
private void txtQty_Validating(object sender, CancelEventArgs e)
{
int val1 = 0;
int val2 = 0;
if (grdtractsold1.Tag != null)
{
int.TryParse(grdtractsold1.Tag.ToString(), out val1);
int.TryParse(txtQty.Text, out val2);
if (val2 > val1)
{
MessageBox.Show("Selling quantities are more than available quantities", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtQty.Text = "";
// txtTotalAmount.Text = "";
//cmbProductID.Focus();
//txtQty.Focus();
return;
}
}
else
{
MessageBox.Show("Product Quantity Not Found!", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
谢谢