如何在库存系统中扫描和显示过期产品

本文关键字:显示 过期 扫描 系统 | 更新日期: 2023-09-27 17:50:21

我们正在制作一个库存系统,该系统应该显示5天内到期的产品列表。我不知道如何解释清楚,但我会尽力的。我的想法是它应该扫描所有的记录,那些在5天内到期的记录将被显示出来。我应该用什么来做呢,我应该用for循环吗,还是if else。谢谢你!我使用的语言是c#。

这是我到目前为止所做的。

public void all()
    {
        SqlConnection MySqlConnection;
        DataTable p_table = new DataTable();
        MySqlConnection = new SqlConnection("Data Source=christina''sqlexpress;Initial Catalog=cafe_inventory;User ID=sa;Password=tina;");
        MySqlConnection.Open();
        SqlCommand command1 = new SqlCommand("Select * from inventory", MySqlConnection);
        //Clear the datatable to prevent duplicate generation of data in gridview.
        p_table.Clear();
        SqlDataAdapter m_da = new SqlDataAdapter("Select * from inventory", MySqlConnection);
        //DataSet ds = new DataSet();
        //DataTable dtable = ds.Tables["empinfo1"];
        m_da.Fill(p_table);
        // Clear the ListView control
        //listView3.Items.Clear();

        // Display items in the ListView control
        for (int i = 0; i < p_table.Rows.Count; i++)
        {
            DataRow drow = p_table.Rows[i];
            // Only row that have not been deleted
            if (drow.RowState != DataRowState.Deleted)
            {
                // Define the list items
                ListViewItem lvi = new ListViewItem(drow["bnum"].ToString());
                lvi.SubItems.Add(drow["pnum"].ToString());
                lvi.SubItems.Add(drow["pname"].ToString());
                lvi.SubItems.Add(drow["descr"].ToString());
                lvi.SubItems.Add(((DateTime)drow["dater"]).ToShortDateString());
                //lvi.SubItems.Add(drow["exp"].ToString());
                lvi.SubItems.Add(((DateTime)drow["exp"]).ToShortDateString());
                lvi.SubItems.Add(drow["qt"].ToString());
                // Add the list items to the ListView
                listView2.Items.Add(lvi);
            }
        }
    }

->这将显示所有的产品

如何在库存系统中扫描和显示过期产品

Try This:

DateTime CurrentDate = DateTime.Now;
string query = "select * from inventory where Exp
                       < (Select DATEADD(day,5,@CurrentDate))";
SqlCommand command = new SqlCommand(query);
command.Parameters.AddWithValue(@CurrentDate ,CurrentDate);
SqlDataAdapter m_da = new SqlDataAdapter(command , MySqlConnection);