示例#1
0
        /*找出庫存報警的設備*/

        public static ArrayList GetStockWarningDevices()
        {
            ArrayList devices       = new ArrayList();
            string    queryString   = "select * from [t_device_using]";
            DataBase  db            = new DataBase();
            DataSet   usingDeviceDs = db.GetDataSet(queryString);

            for (int i = 0; i < usingDeviceDs.Tables[0].Rows.Count; i++)
            {
                DataRow dr = usingDeviceDs.Tables[0].Rows[i];
                /*設備名稱*/
                string deviceName = dr["deviceName"].ToString();
                /*使用開始時間*/
                DateTime useDate = Convert.ToDateTime(dr["useDate"]);
                /*使用壽命*/
                int deviceLife = Convert.ToInt32(dr["deviceLife"]);
                /*當前時間*/
                DateTime nowDate = DateTime.Now;
                /*計算已經使用的天數*/
                TimeSpan ts           = nowDate - useDate;
                int      haveUsedDays = Convert.ToInt32(ts.TotalDays);
                /*計算剩餘可以使用的天數*/
                int leftDays = deviceLife - haveUsedDays;
                if (leftDays < Constant.WARNING_DAYS)
                {
                    /*如果在用設備壽命即將到期,查詢備用備件中該設備是否存在*/
                    queryString = "select * from [t_device_backup] where deviceName=" + SqlString.GetQuotedString(deviceName);
                    DataSet backupDeviceDs = db.GetDataSet(queryString);
                    if (backupDeviceDs.Tables[0].Rows.Count == 0)
                    {
                        /*如果備用設備不存在,則將該設備名稱加入到庫存報警資訊中*/
                        devices.Add(deviceName);
                    }
                }
            }

            return(devices);
        }