Ejemplo n.º 1
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            string appPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            string file    = Path.Combine(appPath, "Record.txt");

            try
            {
                using (FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write))
                {
                    using (StreamWriter writer = new StreamWriter(fs))
                    {
                        foreach (CardPaymentInfo payment in _Records)
                        {
                            writer.WriteLine(CardPaymentInfoSerializer.Serialize(payment));
                        }
                    }
                }
                MessageBox.Show(string.Format("成功导出 {0} 条收费记录", _Records.Count));
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex);
            }
            btnExport.Enabled = false;
        }
Ejemplo n.º 2
0
        public bool Add(CardPaymentInfo info)
        {
            string sql = "insert into CardPaymentRecord values ('" +
                         info.ChargeDateTime.ToString("yyyy-MM-dd HH:mm:ss") + "','" + info.CardID + "','" +
                         CardPaymentInfoSerializer.Serialize(info) + "')";

            return(ExcuteCmd(sql) == 1);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 收费记录保存到文件
 /// </summary>
 /// <param name="info"></param>
 /// <param name="file"></param>
 /// <returns></returns>
 public bool SaveToFile(CardPaymentInfo info, string file)
 {
     try
     {
         using (FileStream fs = new FileStream(file, FileMode.Append, FileAccess.Write))
         {
             using (StreamWriter writer = new StreamWriter(fs))
             {
                 writer.WriteLine(CardPaymentInfoSerializer.Serialize(info));
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         ExceptionPolicy.HandleException(ex);
     }
     return(false);
 }
Ejemplo n.º 4
0
        public List <CardPaymentInfo> GetRecords(DateTime dtBegin, DateTime dtEnd)
        {
            List <CardPaymentInfo> items = null;
            string sql = "select Record from CardPaymentRecord where ChargeDateTime>='" + dtBegin.ToString("yyyy-MM-dd HH:mm:ss") +
                         "' and ChargeDateTime<='" + dtEnd.ToString("yyyy-MM-dd HH:mm:ss") + "'";

            try
            {
                using (SQLiteConnection con = new SQLiteConnection(_RepoUri))
                {
                    con.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(con))
                    {
                        cmd.CommandText = sql;
                        SQLiteDataReader reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            string record = reader.GetString(0);
                            if (!string.IsNullOrEmpty(record))
                            {
                                CardPaymentInfo payment = CardPaymentInfoSerializer.Deserialize(record);
                                if (payment != null)
                                {
                                    if (items == null)
                                    {
                                        items = new List <CardPaymentInfo>();
                                    }
                                    items.Add(payment);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex);
            }
            return(items);
        }