강기헌 강기헌 2023-01-06
..
@73f720d4b3b8dcb7605f721047b3d11d5ef74590
ModbusTest/FormModbus.cs
--- ModbusTest/FormModbus.cs
+++ ModbusTest/FormModbus.cs
@@ -1359,13 +1359,31 @@
                     string oldValue = oldDic[item.Key];
                     if (item.Value != oldValue)
                     {
+                        float pvVal2 = 0;
+                        if (item.Value.Length == 0)
+                        {
+                            // N인 경우 PV_VAL2 에 차이값을 저장한다
+                            string sql4 = "";
+                            sql4 += " select* from T_HT_HIST_BASEOiL";
+                            sql4 += " where BASEOIL_CD = '" + item.Key + "' and HBT_CD = '" + oldValue + "'";
+                            sql4 += " order by idx desc";
+
+                            DataTable dt4 = db.OpenSQL(sql4);
+                            if (dt4 != null && dt4.Rows.Count > 0)
+                            {
+                                float fPrev = U3Util.toFloat(dt4.Rows[0]["PV_VAL"]);
+                                pvVal2 = fPrev - pvVal;
+                            }
+                        }
+
                         string sql3 = "";
-                        sql3 += " insert into T_HT_HIST_BASEOIL (COMP_CD,BASEOIL_CD,HBT_CD,ONOFF_YN,PV_VAL,MACH_NM,REG_DT) values (";
+                        sql3 += " insert into T_HT_HIST_BASEOIL (COMP_CD,BASEOIL_CD,HBT_CD,ONOFF_YN,PV_VAL,PV_VAL2,MACH_NM,REG_DT) values (";
                         sql3 += " '0001', ";
                         sql3 += " '" + item.Key + "', ";
                         sql3 += " '" + ((item.Value.Length > 0) ? item.Value : oldValue) + "', ";
                         sql3 += " '" + ((item.Value.Length > 0) ? "Y" : "N") + "', ";
                         sql3 += " " + pvVal.ToString() + ", ";
+                        sql3 += " " + pvVal2.ToString() + ", ";
                         sql3 += " '" + mach_nm + "', ";
                         sql3 += " getdate() ";
                         sql3 += " )";
SignusKHSVR/Form1.cs
--- SignusKHSVR/Form1.cs
+++ SignusKHSVR/Form1.cs
@@ -74,11 +74,109 @@
             if (m_nPrevSec == dtNow.Second) return;
             m_nPrevSec = dtNow.Second;
 
+            if (m_nPrevSec % 10 == 0)
+            {
+                SaveLog();
+                SaveScaleLog();
+            }
+
             UpdateProgram(m_nPrevSec % 10);
 
             //Program.MoveFiles("C:\\EDIM\\Edge Advance 16P\\CSV", "C:\\EDIM\\Edge Advance 16P\\CSV1");
         }
 
+        private void SaveLog()
+        {
+            U3Database db = new U3Database();
+            string strSQL = "";
+            strSQL += " SELECT a.MACH_CD, (a.REAL_DATA * b.VALUE_RATIO) as PV_VAL";
+            strSQL += " FROM T_HT_REAL_DATA a";
+            strSQL += " left join T_STD_MACH b on a.MACH_CD = b.MACH_CD";
+            strSQL += " where a.MACH_CD >= 'M0001' and a.MACH_CD <= 'M0030'";
+            DataTable dt = db.OpenSQL(strSQL);
+
+            Dictionary<string, float> m_dic = new Dictionary<string, float>();
+
+            foreach (DataRow dr in dt.Rows)
+            {
+                string s = U3Util.toStr(dr["MACH_CD"]);
+                float f = U3Util.toFloat(dr["PV_VAL"]);
+                m_dic[s] = f;
+            }
+
+            strSQL = "";
+            strSQL += " insert into T_TEMP_REAL_DATA_LOG (COMP_CD, REG_DT, M0001, M0002, M0003, M0004, M0005, M0006, M0007, M0008, M0009, M0010, M0011, M0012, M0013, M0014, M0015, M0016, M0017, M0018, M0019, M0020, M0021, M0022, M0023, M0024, M0025, M0026, M0027, M0028, M0029, M0030) values (";
+            strSQL += " '0001', ";
+            strSQL += " getdate(), ";
+            strSQL += " " + (m_dic.ContainsKey("M0001") ? m_dic["M0001"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0002") ? m_dic["M0002"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0003") ? m_dic["M0003"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0004") ? m_dic["M0004"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0005") ? m_dic["M0005"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0006") ? m_dic["M0006"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0007") ? m_dic["M0007"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0008") ? m_dic["M0008"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0009") ? m_dic["M0009"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0010") ? m_dic["M0010"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0011") ? m_dic["M0011"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0012") ? m_dic["M0012"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0013") ? m_dic["M0013"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0014") ? m_dic["M0014"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0015") ? m_dic["M0015"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0016") ? m_dic["M0016"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0017") ? m_dic["M0017"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0018") ? m_dic["M0018"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0019") ? m_dic["M0019"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0020") ? m_dic["M0020"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0021") ? m_dic["M0021"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0022") ? m_dic["M0022"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0023") ? m_dic["M0023"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0024") ? m_dic["M0024"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0025") ? m_dic["M0025"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0026") ? m_dic["M0026"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0027") ? m_dic["M0027"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0028") ? m_dic["M0028"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0029") ? m_dic["M0029"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("M0030") ? m_dic["M0030"].ToString() : "0") + ") ";
+
+            db.ExcuteSql(strSQL);
+        }
+
+        private void SaveScaleLog()
+        {
+            U3Database db = new U3Database();
+            string strSQL = "";
+            strSQL += " SELECT * FROM T_HT_REAL_SCALE ";
+            DataTable dt = db.OpenSQL(strSQL);
+
+            Dictionary<string, float> m_dic = new Dictionary<string, float>();
+
+            foreach (DataRow dr in dt.Rows)
+            {
+                string s = U3Util.toStr(dr["TOUCH_CD"]);
+                float f = U3Util.toFloat(dr["SCALE_VALUE"]);
+                if (s.Length == 0) continue;
+                m_dic[s] = f;
+            }
+
+            strSQL = "";
+            strSQL += " insert into T_TEMP_REAL_SCALE_LOG (COMP_CD, REG_DT, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10) values (";
+            strSQL += " '0001', ";
+            strSQL += " getdate(), ";
+            strSQL += " " + (m_dic.ContainsKey("TP-01") ? m_dic["TP-01"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("TP-02") ? m_dic["TP-02"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("TP-03") ? m_dic["TP-03"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("TP-04") ? m_dic["TP-04"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("TP-05") ? m_dic["TP-05"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("TP-06") ? m_dic["TP-06"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("TP-07") ? m_dic["TP-07"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("TP-08") ? m_dic["TP-08"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("TP-09") ? m_dic["TP-09"].ToString() : "0") + ", ";
+            strSQL += " " + (m_dic.ContainsKey("TP-10") ? m_dic["TP-10"].ToString() : "0") + ") ";
+
+            db.ExcuteSql(strSQL);
+        }
+
         public void UpdateProgram(int index)
         {
             if (index < 0) return;
Add a comment
List