예제 #1
0
        public Form10(MySqlConnection conn, string user)
        {
            InitializeComponent();

            this.conn = conn;
            this.user = user;
            string name = "";

            //设置label1的值
            conn.Open();
            string          sql_tip = $"SELECT TName FROM tradesman WHERE TNo = '{user}'";
            MySqlCommand    cmd     = new MySqlCommand(sql_tip, conn);
            MySqlDataReader reader  = cmd.ExecuteReader();

            reader.Read();
            name = reader.GetString("TName");
            reader.Close();
            label1.Text = "欢迎" + name + "~";

            //保鲜期到期/库存提醒
            richTextBox1.AppendText("保鲜期到期/库存不足提醒(低于原保质期天数的0.2倍/库存少于100kg):\n");
            richTextBox1.AppendText("农产品\t\t\t库存(kg)\t\t库存提醒\t\t保质期(day)\t\t剩余保质期(day)\n");
            DateTime timeNow = System.DateTime.Now;

            Tradesman[] freshGroup = new Tradesman[30];
            Tradesman   tradesFre  = null;
            int         i          = -1;
            //获取pno数组
            string sql_deal = $"SELECT PNo,TStock FROM deal WHERE TNo = '{user}'";

            cmd = new MySqlCommand(sql_deal, conn);
            MySqlDataReader reader1 = cmd.ExecuteReader();

            while (reader1.Read())
            {
                tradesFre       = new Tradesman();
                tradesFre.pno   = reader1.GetString("PNo");
                tradesFre.stock = reader1.GetInt32("TStock");

                freshGroup[++i] = tradesFre;
            }
            reader1.Close();

            //获取cno在通过全局常量crops获得cname和fresh信息
            i = 0;
            int             j;
            MySqlDataReader reader2    = null;
            string          sql_getcno = "";

            while (freshGroup[i] != null)
            {
                sql_getcno = $"SELECT CNo,ProdDate FROM plante WHERE PNo = '{freshGroup[i].pno}'";
                cmd        = new MySqlCommand(sql_getcno, conn);
                reader2    = cmd.ExecuteReader();
                reader2.Read();
                freshGroup[i].cno     = reader2.GetString("CNo");
                freshGroup[i].timePro = reader2.GetDateTime("ProdDate");

                //获取commom.crops中值
                j = 0;
                while (Common.crops[j] != null)
                {
                    if (Common.crops[j].cno.Equals(freshGroup[i].cno))
                    {
                        freshGroup[i].cname     = Common.crops[j].cname;              //get cname
                        freshGroup[i].freshness = Common.crops[j].freshness;          // get freshness
                        sd = new SubDate(freshGroup[i].timePro, timeNow);
                        freshGroup[i].leave = freshGroup[i].freshness - sd.dateSub(); //get剩余保质期
                        break;
                    }
                    j++;
                }
                if (freshGroup[i].leave <= 0)
                {
                    if (freshGroup[i].stock < 100)
                    {
                        richTextBox1.AppendText(freshGroup[i].cname + "\t\t\t" + freshGroup[i].stock + "\t\t\t不足\t\t\t" +
                                                freshGroup[i].freshness + "\t\t\t\t已过期\n");
                    }
                    else
                    {
                        richTextBox1.AppendText(freshGroup[i].cname + "\t\t\t" + freshGroup[i].stock + "\t\t\t充足\t\t\t" +
                                                freshGroup[i].freshness + "\t\t\t\t已过期\n");
                    }
                    freshGroup[i].isFresh = 1;//过期
                }
                else if (freshGroup[i].leave < freshGroup[i].freshness * 0.2)
                {
                    if (freshGroup[i].stock < 100)
                    {
                        richTextBox1.AppendText(freshGroup[i].cname + "\t\t\t" + freshGroup[i].stock + "\t\t\t不足\t\t\t" +
                                                freshGroup[i].freshness + "\t\t\t\t" + freshGroup[i].leave + "\n");
                    }
                    else
                    {
                        richTextBox1.AppendText(freshGroup[i].cname + "\t\t\t" + freshGroup[i].stock + "\t\t\t充足\t\t\t" +
                                                freshGroup[i].freshness + "\t\t\t\t" + freshGroup[i].leave + "\n");
                    }
                }
                else
                {
                }
                i++;
                reader2.Dispose();
            }
            reader2.Close();

            //UPDATE plante - IsFresh
            string sql_update = "";

            i = 0;
            while (freshGroup[i] != null)
            {
                sql_update = $"UPDATE plante SET IsFresh = '{freshGroup[i].isFresh}' WHERE PNo = '{freshGroup[i].pno}'";
                cmd        = new MySqlCommand(sql_update, conn);
                cmd.ExecuteNonQuery();
                i++;
            }

            conn.Close();
        }
예제 #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = "";
            richTextBox1.AppendText("仓库:\n");
            richTextBox1.AppendText("生产编号\t\t农产品\t\t库存(kg)\t\t保质期(天)\t\t生产日期\n");

            Tradesman[]  freshGroup = new Tradesman[30];
            Tradesman    tradesFre  = null;
            MySqlCommand cmd        = null;
            int          i          = -1;

            conn.Open();
            //获取pno数组
            string sql_deal = $"SELECT PNo,TStock FROM deal WHERE TNo = '{user}'";

            cmd = new MySqlCommand(sql_deal, conn);
            MySqlDataReader reader1 = cmd.ExecuteReader();

            while (reader1.Read())
            {
                tradesFre       = new Tradesman();
                tradesFre.pno   = reader1.GetString("PNo");
                tradesFre.stock = reader1.GetInt32("TStock");

                freshGroup[++i] = tradesFre;
            }
            reader1.Close();

            //获取cno在通过全局常量crops获得cname和fresh信息
            i = 0;
            int             j;
            MySqlDataReader reader2    = null;
            string          sql_getcno = "";

            while (freshGroup[i] != null)
            {
                sql_getcno = $"SELECT CNo,ProdDate FROM plante WHERE PNo = '{freshGroup[i].pno}'";
                cmd        = new MySqlCommand(sql_getcno, conn);
                reader2    = cmd.ExecuteReader();
                reader2.Read();
                freshGroup[i].cno     = reader2.GetString("CNo");
                freshGroup[i].timePro = reader2.GetDateTime("ProdDate");

                //获取commom.crops中值
                j = 0;
                while (Common.crops[j] != null)
                {
                    if (Common.crops[j].cno.Equals(freshGroup[i].cno))
                    {
                        freshGroup[i].cname     = Common.crops[j].cname;     //get cname
                        freshGroup[i].freshness = Common.crops[j].freshness; // get freshness
                        richTextBox1.AppendText(freshGroup[i].pno + "\t\t" + freshGroup[i].cname + "\t\t" + freshGroup[i].stock + "\t\t\t" +
                                                freshGroup[i].freshness + "\t\t\t\t" + freshGroup[i].timePro.ToLongDateString() + "\n");
                        break;
                    }
                    j++;
                }
                i++;
                reader2.Dispose();
            }
            conn.Close();
            reader2.Close();
        }
예제 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = "";
            conn.Open();
            MySqlCommand cmd = null;

            //保鲜期到期/库存提醒
            richTextBox1.AppendText("保鲜期到期/库存不足提醒(低于原保质期天数的0.2倍/库存少于100kg):\n");
            richTextBox1.AppendText("农产品\t\t\t库存(kg)\t\t库存提醒\t\t保质期(day)\t\t剩余保质期(day)\n");
            DateTime timeNow = System.DateTime.Now;

            Tradesman[] freshGroup = new Tradesman[30];
            Tradesman   tradesFre  = null;
            int         i          = -1;
            //获取pno数组
            string sql_deal = $"SELECT PNo,TStock FROM deal WHERE TNo = '{user}'";

            cmd = new MySqlCommand(sql_deal, conn);
            MySqlDataReader reader1 = cmd.ExecuteReader();

            while (reader1.Read())
            {
                tradesFre       = new Tradesman();
                tradesFre.pno   = reader1.GetString("PNo");
                tradesFre.stock = reader1.GetInt32("TStock");

                freshGroup[++i] = tradesFre;
            }
            reader1.Close();

            //获取cno在通过全局常量crops获得cname和fresh信息
            i = 0;
            int             j;
            MySqlDataReader reader2    = null;
            string          sql_getcno = "";

            while (freshGroup[i] != null)
            {
                sql_getcno = $"SELECT CNo,ProdDate FROM plante WHERE PNo = '{freshGroup[i].pno}'";
                cmd        = new MySqlCommand(sql_getcno, conn);
                reader2    = cmd.ExecuteReader();
                reader2.Read();
                freshGroup[i].cno     = reader2.GetString("CNo");
                freshGroup[i].timePro = reader2.GetDateTime("ProdDate");

                //获取commom.crops中值
                j = 0;
                while (Common.crops[j] != null)
                {
                    if (Common.crops[j].cno.Equals(freshGroup[i].cno))
                    {
                        freshGroup[i].cname     = Common.crops[j].cname;              //get cname
                        freshGroup[i].freshness = Common.crops[j].freshness;          // get freshness
                        sd = new SubDate(freshGroup[i].timePro, timeNow);
                        freshGroup[i].leave = freshGroup[i].freshness - sd.dateSub(); //get剩余保质期
                        break;
                    }
                    j++;
                }
                if (freshGroup[i].leave <= 0)
                {
                    if (freshGroup[i].stock < 100)
                    {
                        richTextBox1.AppendText(freshGroup[i].cname + "\t\t\t" + freshGroup[i].stock + "\t\t\t不足\t\t\t" +
                                                freshGroup[i].freshness + "\t\t\t\t已过期\n");
                    }
                    else
                    {
                        richTextBox1.AppendText(freshGroup[i].cname + "\t\t\t" + freshGroup[i].stock + "\t\t\t充足\t\t\t" +
                                                freshGroup[i].freshness + "\t\t\t\t已过期\n");
                    }
                    freshGroup[i].isFresh = 1;//过期
                }
                else if (freshGroup[i].leave < freshGroup[i].freshness * 0.2)
                {
                    if (freshGroup[i].stock < 100)
                    {
                        richTextBox1.AppendText(freshGroup[i].cname + "\t\t\t" + freshGroup[i].stock + "\t\t\t不足\t\t\t" +
                                                freshGroup[i].freshness + "\t\t\t\t" + freshGroup[i].leave + "\n");
                    }
                    else
                    {
                        richTextBox1.AppendText(freshGroup[i].cname + "\t\t\t" + freshGroup[i].stock + "\t\t\t充足\t\t\t" +
                                                freshGroup[i].freshness + "\t\t\t\t" + freshGroup[i].leave + "\n");
                    }
                }
                else
                {
                }
                i++;
                reader2.Dispose();
            }
            reader2.Close();
            conn.Close();
        }