123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886 |
- using SXLibrary;
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Data;
- using System.Data.Common;
- using System.Data.SQLite;
- namespace MOKA_Factory_Tools
- {
- class SQLiteHelper
- {
- /// <summary>
- /// 新建数据库文件
- /// </summary>
- /// <param name="dbPath">数据库文件路径及名称</param>
- /// <returns>新建成功,返回true,否则返回false</returns>
- static public Boolean NewDbFile(string dbPath)
- {
- try
- {
- SQLiteConnection.CreateFile(dbPath);
- return true;
- }
- catch (Exception ex)
- {
- throw new Exception("Create DB" + dbPath + "fail:" + ex.Message);
- }
- }
- /// <summary>
- /// 创建表
- /// </summary>
- /// <param name="dbPath">指定数据库文件</param>
- /// <param name="tableName">表名称</param>
- static public void NewTable(string dbPath, string tableName,string ColumnMessage)
- {
- SQLiteConnection sqliteConn = new SQLiteConnection("data source=" + dbPath);
- if (sqliteConn.State != System.Data.ConnectionState.Open)
- {
- sqliteConn.Open();
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = "CREATE TABLE " + tableName + ColumnMessage;
- cmd.ExecuteNonQuery();
- }
- sqliteConn.Close();
- sqliteConn.Dispose();
- }
- /// <summary>
- /// mid表插入一行
- /// </summary>
- /// <param name="dbPath"></param>
- /// <param name="param"></param>
- static public void AddOneLine(string dbPath,object[] param)
- {
- SQLiteConnection sqliteConn = new SQLiteConnection("data source=" + dbPath);
- if (sqliteConn.State != System.Data.ConnectionState.Open)
- {
- sqliteConn.Open();
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("insert into mid(bid,number,pid,ctype,version,host,purl,psize,pmd5,status) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')", param[0], param[1], param[2], param[3], param[4], param[5], param[6], param[7], param[8], param[9]);
- cmd.ExecuteNonQuery();
- }
- sqliteConn.Close();
- sqliteConn.Dispose();
- }
- /// <summary>
- /// roku表插入一行
- /// </summary>
- /// <param name="dbPath"></param>
- /// <param name="param"></param>
- static public void AddRokuOneLine(string dbPath, object[] param)
- {
- SQLiteConnection sqliteConn = new SQLiteConnection("data source=" + dbPath);
- if (sqliteConn.State != System.Data.ConnectionState.Open)
- {
- sqliteConn.Open();
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("insert into rokuCustomer(ordernum,region,brand,oemmodel,supporturl,supportphone,productiondate,remotetype) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", param[0], param[1], param[2], param[3], param[4], param[5], param[6], param[7]);
- cmd.ExecuteNonQuery();
- }
- sqliteConn.Close();
- sqliteConn.Dispose();
- }
- /// <summary>
- /// whitebalance表插入一行
- /// </summary>
- /// <param name="dbPath"></param>
- /// <param name="param"></param>
- static public void AddwbOneLine(string dbPath, object[] param)
- {
- SQLiteConnection sqliteConn = new SQLiteConnection("data source=" + dbPath);
- if (sqliteConn.State != System.Data.ConnectionState.Open)
- {
- sqliteConn.Open();
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("insert into whitebalance(ordernum,hdmirgain,hdmiggain,hdmibgain,nrgain,nggain,nbgain,lrgain,lggain,lbgain) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')", param[0], param[1], param[2], param[3], param[4], param[5], param[6], param[7], param[8], param[9]);
- cmd.ExecuteNonQuery();
- }
- sqliteConn.Close();
- sqliteConn.Dispose();
- }
- /// <summary>
- /// dsn表插入一行
- /// </summary>
- /// <param name="dbPath"></param>
- /// <param name="param"></param>
- static public void AdddsnOneLine(string dbPath, object[] param)
- {
- SQLiteConnection sqliteConn = new SQLiteConnection("data source=" + dbPath);
- if (sqliteConn.State != System.Data.ConnectionState.Open)
- {
- sqliteConn.Open();
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("insert into dsn(ordernum,dsn) values('{0}','{1}')", param[0], param[1]);
- cmd.ExecuteNonQuery();
- }
- sqliteConn.Close();
- sqliteConn.Dispose();
- }
- static public void UpdateTime(string dbPath, string bid)
- {
- SQLiteConnection sqliteConn = new SQLiteConnection("data source=" + dbPath);
- if (sqliteConn.State != System.Data.ConnectionState.Open)
- {
- sqliteConn.Open();
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("update mid set finish_date=datetime(CURRENT_TIMESTAMP,'localtime') where bid='{0}'",bid);
- cmd.ExecuteNonQuery();
- }
- sqliteConn.Close();
- sqliteConn.Dispose();
- }
- static public void UpdateStatus(string dbPath, string str)
- {
- SQLiteConnection sqliteConn = new SQLiteConnection("data source=" + dbPath);
- if (sqliteConn.State != System.Data.ConnectionState.Open)
- {
- sqliteConn.Open();
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("update mid set status='{0}'", str);
- cmd.ExecuteNonQuery();
- }
- sqliteConn.Close();
- sqliteConn.Dispose();
- }
- /// <summary>
- /// 使用事务批量插入sn,key行
- /// </summary>
- /// <param name="dbPath"></param>
- /// <param name="keys"></param>
- /// <returns></returns>
- static public bool InsertKeys(string dbPath, List<object[]> keys)
- {
- DbTransaction trans = null;
- try
- {
- SQLiteConnection sqliteConn = new SQLiteConnection("data source=" + dbPath);
- if (sqliteConn.State != System.Data.ConnectionState.Open)
- {
- sqliteConn.Open();
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- trans = sqliteConn.BeginTransaction();
- foreach (var key in keys)
- {
- cmd.CommandText = string.Format("insert into keys(sn,keys) values('{0}','{1}')", key[0], key[1]);
- cmd.ExecuteNonQuery();
- }
- trans.Commit();
- }
- sqliteConn.Close();
- sqliteConn.Dispose();
- return true;
- }
- catch(Exception ex)
- {
- if (trans != null)
- trans.Rollback();
- Log.WriteErrorLog("\r\nFail to transfer key to DB:\r\n" + ex.Message);
- return false;
- }
-
- }
- /// <summary>
- /// 插入一条sn/key数据
- /// </summary>
- /// <param name="sqliteConn"></param>
- /// <param name="sn"></param>
- /// <param name="keydata"></param>
- /// <returns></returns>
- static public bool Insertonekey(SQLiteConnection sqliteConn,string sn,string keydata)
- {
- DbTransaction trans = null;
- try
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- trans = sqliteConn.BeginTransaction();
- cmd.CommandText = string.Format("insert into keys(sn,keys,copy_date) values('{0}','{1}','{2}')", sn, keydata, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- cmd.ExecuteNonQuery();
- trans.Commit();
- return true;
- }
- catch (Exception ex)
- {
- if (trans != null)
- trans.Rollback();
- Log.WriteErrorLog("\r\nFail to transfer key to DB:\r\n" + ex.Message);
- return false;
- }
- }
- static public bool CheckDownloadStatus(string dbPath,string bid)
- {
- SQLiteConnection sqliteConn = new SQLiteConnection("data source=" + dbPath);
- if (sqliteConn.State != System.Data.ConnectionState.Open)
- {
- sqliteConn.Open();
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("select * from mid where bid='{0}'and status='1'", bid);
- using (SQLiteDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
- {
- if(dr.Read())
- {
- return true;
- }
- }
- }
- sqliteConn.Close();
- sqliteConn.Dispose();
- return false;
- }
- static public bool WholeCheckDownloadStatus(SQLiteConnection sqliteConn, string bid)
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("select * from mid where bid='{0}'and status='1'", bid);
- SQLiteDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- dr.Close();
- return true;
- }
- dr.Close();
- return false;
- }
- /// <summary>
- /// 获取DB文件内的key数据(json格式)
- /// </summary>
- /// <param name="sqliteConn"></param>
- /// <param name="SN"></param>
- /// <param name="copydone"></param>
- /// <returns></returns>
- static public string Getkeys(SQLiteConnection sqliteConn, string SN,out bool copydone)
- {
- copydone = false;
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("select * from keys where sn='{0}'", SN);
- SQLiteDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- NameValueCollection user = dr.GetValues();
- string values = user.Get("keys");
- if (user.Get("copy_date").Length>0)
- copydone = true;
- dr.Close();
- return values;
- }
- dr.Close();
- Log.WriteErrorLog("\r\nFail to Get keys to DB:\r\n" + cmd.CommandText);
- return "";
- }
- /// <summary>
- /// 获取DB文件内的roku抄写数据
- /// </summary>
- /// <param name="sqliteConn"></param>
- /// <param name="order"></param>
- /// <param name="rokuCustomer"></param>
- /// <returns></returns>
- static public bool GetrokuCustomer(SQLiteConnection sqliteConn, string order, out RokuCustomer rokuCustomer)
- {
- rokuCustomer = null;
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("select * from rokuCustomer where ordernum='{0}'", order);
- SQLiteDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- NameValueCollection user = dr.GetValues();
- rokuCustomer = new RokuCustomer()
- {
- ordernum = user.Get("ordernum"),
- brand = user.Get("brand"),
- region = user.Get("region"),
- oemmodel = user.Get("oemmodel"),
- supporturl = user.Get("supporturl"),
- supportphone = user.Get("supportphone"),
- productiondate = user.Get("productiondate"),
- remotetype= user.Get("remotetype")
- };
- dr.Close();
- return true;
- }
- dr.Close();
- return false;
- }
- /// <summary>
- /// 获取DB文件内的dsn数据
- /// </summary>
- /// <param name="sqliteConn"></param>
- /// <param name="order"></param>
- /// <param name="rokuCustomer"></param>
- /// <returns></returns>
- static public bool Getdsn(SQLiteConnection sqliteConn, string order, out string dsn)
- {
- dsn = null;
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("select * from dsn where ordernum='{0}'", order);
- SQLiteDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- NameValueCollection user = dr.GetValues();
- dsn = user.Get("dsn");
- dr.Close();
- return true;
- }
- dr.Close();
- return false;
- }
- /// <summary>
- /// 获取DB文件内的白平衡数据
- /// </summary>
- /// <param name="sqliteConn"></param>
- /// <param name="order"></param>
- /// <param name="whiteBalanceInfo"></param>
- /// <returns></returns>
- static public bool Getwhitebalance(SQLiteConnection sqliteConn, string order, out WhiteBalanceInfo whiteBalanceInfo)
- {
- whiteBalanceInfo = null;
- try
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("select * from whitebalance where ordernum='{0}'", order);
- SQLiteDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- NameValueCollection user = dr.GetValues();
- whiteBalanceInfo = new WhiteBalanceInfo()
- {
- ordernum = user.Get("ordernum"),
- hdmirgain = user.Get("hdmirgain"),
- hdmiggain = user.Get("hdmiggain"),
- hdmibgain = user.Get("hdmibgain"),
- nrgain = user.Get("nrgain"),
- nggain = user.Get("nggain"),
- nbgain = user.Get("nbgain"),
- lrgain = user.Get("lrgain"),
- lggain = user.Get("lggain"),
- lbgain = user.Get("lbgain")
- };
- dr.Close();
- return true;
- }
- dr.Close();
- return false;
- }
- catch(Exception ex)
- {
- Log.WriteErrorLog(ex.Message);
- return false;
- }
- }
- static public bool GetDBMidInfo(SQLiteConnection sqliteConn, string bid,out MidAddress MidAddress1)
- {
- MidAddress1 = new MidAddress();
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("select * from mid where bid='{0}'", bid);
- SQLiteDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- NameValueCollection user = dr.GetValues();
- MidAddress1.order = user.Get("bid");
- MidAddress1.pid= user.Get("pid");
- MidAddress1.des = user.Get("des");
- MidAddress1.number = user.Get("number");
- MidAddress1.ctype = user.Get("ctype");
- MidAddress1.purl = user.Get("purl");
- MidAddress1.psize = user.Get("psize");
- MidAddress1.pmd5 = user.Get("pmd5");
- MidAddress1.version = user.Get("version");
- MidAddress1.host = user.Get("host");
- dr.Close();
- return true;
- }
- dr.Close();
- return false;
- }
- static public bool UpdateCopyStatus(SQLiteConnection sqliteConn,string SN,out string copydate)
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = "select datetime(CURRENT_TIMESTAMP,'localtime')";
- SQLiteDataReader dr = cmd.ExecuteReader();
- copydate = "";
- if (dr.Read())
- {
- NameValueCollection user = dr.GetValues();
- copydate = user.Get("datetime(CURRENT_TIMESTAMP,'localtime')");
- }
- dr.Close();
- cmd.CommandText = string.Format("update keys set copy_date='"+ copydate+ "'where sn='{0}'", SN);
- int result = cmd.ExecuteNonQuery();
- cmd.Dispose();
- if (result > 0 && copydate.Length > 0)
- return true;
- else
- return false;
- }
- static public bool UpdateReportStatus(SQLiteConnection sqliteConn, string SN)
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("update keys set report_date=datetime(CURRENT_TIMESTAMP,'localtime') where sn='{0}'", SN);
- int result = cmd.ExecuteNonQuery();
- cmd.Dispose();
- if (result > 0)
- return true;
- else
- return false;
- }
- static public bool UpdateReportListStatus(SQLiteConnection sqliteConn, List<string> SNs)
- {
- DbTransaction trans = null;
- try
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- trans = sqliteConn.BeginTransaction();
- foreach (var SN in SNs)
- {
- cmd.CommandText = string.Format("update keys set report_date=datetime(CURRENT_TIMESTAMP,'localtime') where sn='{0}'", SN);
- cmd.ExecuteNonQuery();
- }
- trans.Commit();
- cmd.Dispose();
- return true;
- }
- catch(Exception ex)
- {
- return false;
- }
- }
- static public bool InsertDelayCopyReport(SQLiteConnection sqliteConn, object[] param)
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("insert into CopyDelayReport(bid,url,content) values('{0}','{1}','{2}')", param[0], param[1], param[2]);
- int result = cmd.ExecuteNonQuery();
- cmd.Dispose();
- if (result > 0)
- return true;
- else
- return false;
- }
- static public bool DeleteDelayCopyReport(SQLiteConnection sqliteConn, string ID)
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("Delete from CopyDelayReport where ID='{0}'",ID);
- int result = cmd.ExecuteNonQuery();
- cmd.Dispose();
- if (result > 0)
- return true;
- else
- return false;
- }
- static public bool IsErrorReportExist(SQLiteConnection sqliteConn, string url, string content)
- {
- try
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("select count from ErrorReport where url='{0}' and content='{1}'", url, content);
- SQLiteDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- NameValueCollection user = dr.GetValues();
- string values = user.Get("count");
- int count = Convert.ToInt32(values);
- dr.Close();
- if (count > 0)
- return true;
- cmd.Dispose();
- return false;
- }
- dr.Close();
- cmd.Dispose();
- return false;
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nGet Report Count Error:" + ex.Message);
- return false;
- }
- }
- static public bool InsertDelayErrorReport(SQLiteConnection sqliteConn, object[] param)
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- if (param[0].ToString().EndsWith("smes/RecordKey"))
- {
- if (IsErrorReportExist(sqliteConn, param[0].ToString(), param[1].ToString()))
- {
- // 记录存在,退出;
- return true;
- }
- }
- cmd.CommandText = string.Format("insert into ErrorReport(url,content) values('{0}','{1}')", param[0], param[1]);
- int result = cmd.ExecuteNonQuery();
- cmd.Dispose();
- if (result > 0)
- return true;
- else
- return false;
- }
- public static bool CheckProductionNum(SQLiteConnection sqliteConn, string order)
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("select * from ProductionCount where bid='{0}'", order);
- SQLiteDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- dr.Close();
- return true;
- }
- dr.Close();
- cmd.CommandText = string.Format("insert into ProductionCount(bid,count) values('{0}','{1}')", order, "0");
- int result = cmd.ExecuteNonQuery();
- cmd.Dispose();
- if (result > 0)
- return true;
- else
- return false;
- }
- public static bool UpdateProductionNum(SQLiteConnection sqliteConn, string order)
- {
- try
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("select count from ProductionCount where bid='{0}'", order);
- SQLiteDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- NameValueCollection user = dr.GetValues();
- string values = user.Get("count");
- string count = (Convert.ToInt32(values) + 1).ToString();
- dr.Close();
- cmd.CommandText = string.Format("update ProductionCount set count ='{0}' where bid='{1}'", count, order);
- int result = cmd.ExecuteNonQuery();
-
- if (result > 0)
- return true;
- else
- Log.WriteErrorLog("\r\nFail to update ProductionCount from db:\r\n" + cmd.CommandText);
- cmd.Dispose();
- return false;
- }
- dr.Close();
- Log.WriteErrorLog("\r\nFail to get ProductionCount from db:\r\n" + cmd.CommandText);
- cmd.Dispose();
- return false;
- }
- catch(Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to UpdateProductionNum:" + ex.Message);
- return false;
- }
-
- }
- /// <summary>
- /// 获取本地DB对应订单已经抄写的数量(包含重复抄写)
- /// </summary>
- /// <param name="sqliteConn"></param>
- /// <param name="order"></param>
- /// <returns></returns>
- public static string GetProductionNum(SQLiteConnection sqliteConn, string order)
- {
- try
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("select count from ProductionCount where bid='{0}'", order);
- SQLiteDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- NameValueCollection user = dr.GetValues();
- string values = user.Get("count");
- dr.Close();
- cmd.Dispose();
- return values;
- }
- dr.Close();
- cmd.Dispose();
- return "";
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to GetProductionNum:" + ex.Message);
- return "";
- }
- }
- /// <summary>
- /// 删除30天之前已经上报的数据
- /// </summary>
- /// <param name="sqliteConn"></param>
- /// <returns></returns>
- public static bool DeleteOldData(SQLiteConnection sqliteConn)
- {
- try
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = "Delete from ErrorReport where report_date is not null and date('now', '-30 day') >= date(report_date)";
- cmd.ExecuteNonQuery();
- cmd.CommandText = "Delete from CopyDelayReport where report_date is not null and date('now', '-30 day') >= date(report_date)";
- cmd.ExecuteNonQuery();
- cmd.Dispose();
- return true;
- }
- catch(Exception ex)
- {
- GC.Collect();
- Log.WriteErrorLog("\r\nFail to DeleteOldData:" + ex.Message);
- return false;
- }
- }
- /// <summary>
- /// 获取本地DB记录的未上报异常数据
- /// </summary>
- /// <param name="sqliteConn"></param>
- /// <param name="url"></param>
- /// <param name="content"></param>
- /// <returns></returns>
- public static bool GetErrorReportData(SQLiteConnection sqliteConn,out string url,out string content,out string id)
- {
- url = "";
- content = "";
- id = "";
- try
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = "select url,content,ID from ErrorReport where report_date is null LIMIT 1";
- SQLiteDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- NameValueCollection user = dr.GetValues();
- url = user.Get("url");
- content = user.Get("content");
- id = user.Get("ID");
- dr.Close();
- return true;
- }
- dr.Close();
- return false;
- }
- catch(Exception ex)
- {
- GC.Collect();
- Log.WriteErrorLog("\r\nFail to GetErrorReportData:" + ex.Message);
- return false;
- }
-
- }
- /// <summary>
- /// 获取本地DB记录的未上报烧录数据
- /// </summary>
- /// <param name="sqliteConn"></param>
- /// <param name="url"></param>
- /// <param name="content"></param>
- /// <returns></returns>
- public static bool GetDelayReportData(SQLiteConnection sqliteConn, out string url, out string content,out string id)
- {
- url = "";
- content = "";
- id = "";
- try
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = "select url,content,ID from CopyDelayReport where report_date is null LIMIT 1";
- SQLiteDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- NameValueCollection user = dr.GetValues();
- url = user.Get("url");
- content = user.Get("content");
- id = user.Get("ID");
- dr.Close();
- return true;
- }
- dr.Close();
- return false;
- }
- catch (Exception ex)
- {
- GC.Collect();
- Log.WriteErrorLog("\r\nFail to GetDelayReportData:" + ex.Message);
- return false;
- }
- }
- public static bool GetEppormDataList(SQLiteConnection sqliteConn, out List<PostDateClass> postList,out List<string> SNs)
- {
- postList = new List<PostDateClass>();
- try
- {
-
- SQLiteCommand cmd = new SQLiteCommand();
- SNs = new List<string>();
- cmd.Connection = sqliteConn;
- cmd.CommandText = "select sn from keys where report_date is null LIMIT 200";
- SQLiteDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- NameValueCollection user = dr.GetValues();
- string sn = user.Get("sn");
- SNs.Add(sn);
- postList.Add(new PostDateClass("sn", sn));
- postList.Add(new PostDateClass("date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
- }
- dr.Close();
- return true;
- }
- catch (Exception ex)
- {
- GC.Collect();
- SNs = null;
- Log.WriteErrorLog("\r\nFail to GetEppormData:" + ex.Message);
- return false;
- }
- }
- public static bool GetEppormDataList2(SQLiteConnection sqliteConn, out List<PostDateClass> postList, out List<string> SNs)
- {
- postList = new List<PostDateClass>();
- try
- {
- SQLiteCommand cmd = new SQLiteCommand();
- SNs = new List<string>();
- cmd.Connection = sqliteConn;
- cmd.CommandText = "select sn,copy_date from keys where report_date is null and copy_date is not null LIMIT 20";
- SQLiteDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- NameValueCollection user = dr.GetValues();
- string sn = user.Get("sn");
- string copy_date = user.Get("copy_date");
- SNs.Add(sn);
- postList.Add(new PostDateClass("sn", sn));
- postList.Add(new PostDateClass("date", copy_date));
- }
- dr.Close();
- return true;
- }
- catch (Exception ex)
- {
- GC.Collect();
- SNs = null;
- Log.WriteErrorLog("\r\nFail to GetEppormData:" + ex.Message);
- return false;
- }
- }
- public static bool GetEppormDataCount(SQLiteConnection sqliteConn, out string count)
- {
- count = "";
- try
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = "select count(*) from keys";
- SQLiteDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- NameValueCollection user = dr.GetValues();
- count = user.Get("count(*)");
- dr.Close();
- return true;
- }
- dr.Close();
- return false;
- }
- catch (Exception ex)
- {
- GC.Collect();
- Log.WriteErrorLog("\r\nFail to GetEppormDataCount:" + ex.Message);
- return false;
- }
- }
- public static bool GetEppormUploadedDataCount(SQLiteConnection sqliteConn, out string count)
- {
- count = "";
- try
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = "select count(*) from keys where report_date is not null";
- SQLiteDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- NameValueCollection user = dr.GetValues();
- count = user.Get("count(*)");
- dr.Close();
- return true;
- }
- dr.Close();
- return false;
- }
- catch (Exception ex)
- {
- GC.Collect();
- Log.WriteErrorLog("\r\nFail to GetEppormDataCount:" + ex.Message);
- return false;
- }
- }
- /// <summary>
- /// 更新本地DB记录的未上报数据
- /// </summary>
- public static bool UpdateReportData(SQLiteConnection sqliteConn,string table,string column,string data)
- {
- SQLiteCommand cmd = new SQLiteCommand();
- cmd.Connection = sqliteConn;
- cmd.CommandText = string.Format("update {0} set report_date = datetime(CURRENT_TIMESTAMP,'localtime') where {1}= '{2}'", table, column, data);
- int result = cmd.ExecuteNonQuery();
- cmd.Dispose();
- if (result > 0)
- return true;
- else
- return false;
- }
- }
- }
|