Sfoglia il codice sorgente

完成后台上报数据的功能。

jianfeng1.wang 2 anni fa
parent
commit
126e9b3d84

+ 1 - 1
FactoryTool_CShare/Business/V2Method.cs

@@ -648,7 +648,7 @@ namespace MOKA_Factory_Tools
         {
             if ( background )
             {
-                return SQLiteHelper.AddReportOnlineData(sqliteConn, url + "/reportData/report", order, postData);
+                return SQLiteHelper.AddReportOnlineData(sqliteConn, url + "/reportData/report", postData);
             }
 
             if (timeout < 5000)

+ 33 - 2
FactoryTool_CShare/Database/SQLiteHelper.cs

@@ -871,18 +871,49 @@ namespace MOKA_Factory_Tools
                 return false;
         }
 
-        public static bool AddReportOnlineData(SQLiteConnection connection, string url, string order, string content)
+        public static bool AddReportOnlineData(SQLiteConnection connection, string url, string content)
         {
             if (connection == null)
                 return false;
 
             SQLiteCommand cmd = new SQLiteCommand();
             cmd.Connection = connection;
-            cmd.CommandText = string.Format("insert into ReportData(order,url,content) values('{0}','{1}','{2}')", order, url, content);
+            cmd.CommandText = string.Format("insert into ReportData(url,content) values('{0}','{1}')", url, content);
             int result = cmd.ExecuteNonQuery();
             cmd.Dispose();
 
             return result > 0 ? true : false;
         }
+
+        public static bool GetReportData(SQLiteConnection sqliteConn, out string id, out string url, out string content)
+        {
+            url = "";
+            content = "";
+            id = "";
+            try
+            {
+                SQLiteCommand cmd = new SQLiteCommand();
+                cmd.Connection = sqliteConn;
+                cmd.CommandText = "select id, url, content from ReportData Order by random() 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 GetReportData:" + ex.Message);
+                return false;
+            }
+        }
     }
 }

+ 1 - 1
FactoryTool_CShare/Program.cs

@@ -34,7 +34,7 @@ namespace MOKA_Factory_Tools
             {
                 if (SQLiteHelper.NewDbFile(reportFolder + "\\ReportData.db"))
                 {
-                    SQLiteHelper.NewTable(reportFolder + "\\ReportData.db", "ReportData", "([order] text,url text,content text)");
+                    SQLiteHelper.NewTable(reportFolder + "\\ReportData.db", "ReportData", "(id text,url text,content text)");
                 }
             }
             #endregion

+ 30 - 0
FactoryTool_CShare/Views/Main.cs

@@ -31,6 +31,7 @@ namespace MOKA_Factory_Tools
         FunctionSetting functionSetting1 = new FunctionSetting();
         SQLiteConnection LocalDB = null;
         SQLiteConnection ErrorDB = null;
+        SQLiteConnection ReportDB = null;
 
         Dictionary<string, string> ChannelMapList = new Dictionary<string, string>();
         Dictionary<string, string> LanguageMapList = new Dictionary<string, string>();
@@ -38,6 +39,7 @@ namespace MOKA_Factory_Tools
         string Custom_ProjectID = "";
         ArrayList formlocationmsg = new ArrayList();
         string ErrorDBPath = AppDomain.CurrentDomain.BaseDirectory + "\\Error.db";
+        string ReportDBPath = AppDomain.CurrentDomain.BaseDirectory + "\\DB\\ReportData.db";
         Thread uploadbackground;
 
         bool LocalWrite = false;//离线抄写开关
@@ -78,6 +80,12 @@ namespace MOKA_Factory_Tools
                 ErrorDB.Open();
             }
 
+            if (ReportDB == null)
+            {
+                ReportDB = new SQLiteConnection("data source=" + ReportDBPath);
+                ReportDB.Open();
+            }
+
             #region 研发账号
             if (CommonMethod.GetLoginAccout().Equals("RD", StringComparison.OrdinalIgnoreCase))
             {
@@ -1448,6 +1456,28 @@ namespace MOKA_Factory_Tools
                     Log.WriteErrorLog(ex.Message);
                 }
 
+                try
+                {
+                    string url;
+                    string content;
+                    string id;
+                    if (SQLiteHelper.GetReportData(ReportDB, out id, out url, out content))
+                    {
+                        if ( V2Method.ReportOnlineDataSQL(url, content, 5000) )
+                        {
+                            // 删除该记录;
+                            SQLiteCommand cmd = new SQLiteCommand();
+                            cmd.Connection = ReportDB;
+                            cmd.CommandText = string.Format("delete from ReportData where id = {0}", id);
+                            cmd.Dispose();
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    Log.WriteErrorLog(ex.Message);
+                }
+
                 // 频率5秒一次;
                 Thread.Sleep(5000);
             }