实际上我想在其中发出包含特定数据的提醒消息,例如 '产品1已达到其级别' 。 我不能这样做,所以我尝试了另一种方式来显示警报消息,但没有显示特定的pid。
这是我的代码:
SqlConnection connection = new SqlConnection("Data Source=aaaVAIO;InitialCatalog=System;Integrated Security=True");
SqlCommand abc = new SqlCommand("select pid, case when (Pamount <= SafetyStock) then 'has reached its limit!' end as Alert from Product ", connection);
try
{
connection.Open();
SqlDataReader rdr = abc.ExecuteReader();
while (rdr.Read())
{
ListBox1.Items.Add(rdr["alert"].ToString());
foreach (ListItem li in ListBox1.Items)
{
if (li.Text.Equals("Limit stock has been reached"))
{
ClientScriptManager def= Page.ClientScript;
{
string strconfirm = "<script>if(window.confirm('Limit Stock has been reached!')){window.location.href='/Inventory system/Manager/Updateproductdetails.aspx'}</script>";
def.RegisterClientScriptBlock(this.GetType(), "Confirm", strconfirm, false);
}
}
}
}
rdr.Close();
}
在上面的代码中,我将sqlcommand
输出存储在list box
中,然后警报消息将根据列表内容显示警报消息。如果列表框中有限制库存消息,则会发出警告消息。
实际上我想让它更具体地显示达到极限的特定pid。例如,警告消息将显示消息 '产品1已达到其限制' 。
请建议我解决这个问题。
我应该先将值gridview
存储吗?或者其他任何方式吗?
先谢谢你。
答案 0 :(得分:0)
您可以更改您的SQL查询以显示金额&lt; =到安全股票的项目:
SqlCommand abc = new SqlCommand("select pid from Product where Pamount <= SafetyStock", connection);
然后你的循环改变它是这样的:
while (rdr.Read())
{
ClientScriptManager def = Page.ClientScript;
{
string strconfirm = "<script>if(window.confirm('Product " + rdr["pid"] + " has reached its limit')){window.location.href='/Inventory system/Manager/Updateproductdetails.aspx'}</script>";
def.RegisterClientScriptBlock(this.GetType(), "Confirm", strconfirm, false);
}
}