当库存达到严重时显示警报面板

时间:2015-10-08 16:02:03

标签: c# asp.net

我试图显示库存低于关键时间。我调试系统时似乎没有到达那里

这是我背后的代码

protected void Page_Load(object sender, EventArgs e)
{
      GetInventory();
      TotalCount();
      CriticalItem();
      Panel1.Visible = false;
}

void TotalCount()
{
    con.Open();
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = con;
    cmd.CommandText = "SELECT 'Total Count of Inventory ' + '(' + convert(nvarchar,SUM(Quantity)) + ')' AS TotalCount from Inventory";
    SqlDataReader data = cmd.ExecuteReader();
    if (data.HasRows)
    {
        while (data.Read())
        {
            lblTotalCount.Text = data["TotalCount"].ToString();

        }
        con.Close();
    }
    else
    {
        con.Close();
        Response.Redirect("Default.aspx");
    }
}

void GetInventory()
{


    con.Open();
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = con;
    cmd.CommandText = "SELECT Inventory.InventoryID, Products.ProductName, " +
        "Supplier.SupplierName, Inventory.Quantity, Users.LastName + ', ' + Users.FirstName AS UserAccount, " +
        "SupplierProducts.CriticalLevel, Inventory.Status, Inventory.DateAdded, Inventory.DateModified, SupplierProducts.Price FROM Inventory " +
        "INNER JOIN SupplierProducts ON Inventory.ProductID = SupplierProducts.SupplierProductID " + 
        "INNER JOIN Products ON SupplierProducts.ProductID = Products.ProductID " +
        "INNER JOIN Supplier ON Inventory.SupplierID = Supplier.SupplierID " + 
        "INNER JOIN Users ON Inventory.UserID = Users.UserID";

    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds, "Inventory");
    lvInventory.DataSource = ds;
    lvInventory.DataBind();
    con.Close();
}

void CriticalItem()
{
    var intcheck = new DataTable();
    using (var da = new SqlDataAdapter("SELECT * FROM Inventory", con))
    {
        da.Fill(intcheck);
    }

    var critcheck = new DataTable();
    using (var da = new SqlDataAdapter("SELECT * FROM SupplierProducts", con))
    {
        da.Fill(critcheck);
    }

    int finalQuantity = Convert.ToInt32(intcheck.Rows[0]["Quantity"]);
    int criticalLevel = Convert.ToInt32(critcheck.Rows[0]["CriticalLevel"]);


    if (finalQuantity > criticalLevel)
    {
        Panel1.Visible = true;
        criticalItem.Text = "Available";
    }
}

我想通过criticalItem.text来告诉库存低于其临界水平。

0 个答案:

没有答案