コード例 #1
0
        private void SaveSettings(CancelEventArgs e)
        {
            DateTime dtBegin = new DateTime(dtpBegin.Value.Year, dtpBegin.Value.Month, dtpBegin.Value.Day, 0, 0, 0);
            DateTime dtEnd   = new DateTime(dtpEnd.Value.Year, dtpEnd.Value.Month, dtpEnd.Value.Day, 23, 59, 59);

            // 加载日志
            SendLogList = ProductSendLogStorage.ReadSendLogList(dtBegin, dtEnd);

            lvLog.BeginUpdate();
            int idx = 0;    // 计数器

            foreach (ProductSendLog sendLog in SendLogList)
            {
                ListViewItem lvi = new ListViewItem((++idx).ToString());
                lvi.SubItems.Add(sendLog.ProductName);
                lvi.SubItems.Add(sendLog.ProductDate.ToString("yyyy-MM-dd"));
                lvi.SubItems.Add(sendLog.IsSendOK ? "√" : "×");
                lvi.SubItems.Add(sendLog.Note);
                lvi.SubItems.Add(sendLog.OpTime.ToString("yyyy-MM-dd HH:mm:ss"));


                lvi.Tag = sendLog;
                lvLog.Items.Add(lvi);
            }

            lvLog.EndUpdate();


            e.Cancel = true;
        }
コード例 #2
0
        public static ProductSendLogList ReadSendLogList(DateTime dtBegin, DateTime dtEnd)
        {
            ProductSendLogList sendLogList = new ProductSendLogList();

            // 临时键值对,存放产品id-产品名称
            Dictionary <int, string> dicProduct = new Dictionary <int, string>();

            try
            {
                using (SQLiteConnection cn = new SQLiteConnection(ConfigurationManager.AppSettings["conn"]))
                {
                    cn.Open();

                    using (SQLiteCommand cmd = new SQLiteCommand(cn))
                    {
                        cmd.CommandText = "select * from ProductSendLog where ProductDate between @Begin and @End";
                        cmd.Parameters.Add(new SQLiteParameter("@Begin", dtBegin));
                        cmd.Parameters.Add(new SQLiteParameter("@End", dtEnd));

                        using (SQLiteDataReader dr = cmd.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                // 获取产品基本信息
                                int id        = int.Parse(dr["ID"].ToString());
                                int productID = int.Parse(dr["ProductID"].ToString());

                                // 获取产品名称
                                string productName = string.Empty;
                                if (dicProduct.ContainsKey(productID))
                                {
                                    productName = dicProduct[productID];
                                }
                                else
                                {
                                    productName = ProductStorage.GetProductNameById(productID, cn);
                                    dicProduct.Add(productID, productName);
                                }
                                DateTime productDate = DateTime.Parse(dr["ProductDate"].ToString());
                                bool     isSendOK    = bool.Parse(dr["IsSendOK"].ToString());
                                string   note        = dr["Note"].ToString();
                                DateTime opTime      = DateTime.Parse(dr["OpTime"].ToString());


                                ProductSendLog sendLog = new ProductSendLog(
                                    id,
                                    productID,
                                    productName,
                                    productDate,
                                    isSendOK,
                                    note,
                                    opTime
                                    );

                                sendLogList.Add(sendLog);
                            } //eof while
                        }     //eof dr
                    }         //eof cmd
                }             //eof conn
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                dicProduct.Clear();
            }

            return(sendLogList);
        }