강기헌 강기헌 2022-11-14
..
@69d2887d85978e635cf859f8ec92de1083f3e37a
ModbusTest/FormModbus.cs
--- ModbusTest/FormModbus.cs
+++ ModbusTest/FormModbus.cs
@@ -42,7 +42,7 @@
             SerialConnectionSingleton.Instance().DataBits = 8;
             SerialConnectionSingleton.Instance().SlaveNo = 1;
 
-            UpdateBaseoilSwitch();
+            //UpdateBaseoilSwitch();
         }
 
 
@@ -1239,15 +1239,30 @@
             Dictionary<string, string> oldDic = new Dictionary<string, string>();
             strSQL = "select * from T_HT_REAL_BASEOIL";
             DataTable dtOld = db.OpenSQL(strSQL);
-            foreach(DataRow drOld in dtOld.Rows)
+            foreach (DataRow drOld in dtOld.Rows)
             {
                 string strKey = U3Util.toStr(drOld["BASEOIL_CD"]);
                 string strVal = U3Util.toStr(drOld["HBT_CD"]);
-                oldDic.Add(strKey, strVal);
+                if (oldDic.ContainsKey(strKey) == false)
+                    oldDic.Add(strKey, strVal);
+            }
+
+            Dictionary<string, float> pvDic = new Dictionary<string, float>();
+            strSQL = "";
+            strSQL += " SELECT a.MACH_CD, (REAL_DATA * VALUE_RATIO) as PV_VAL, MACH_NM, REMARK04";
+            strSQL += " FROM T_HT_REAL_DATA a";
+            strSQL += " left join T_STD_MACH b on a.MACH_CD = b.MACH_CD";
+            strSQL += " where b.REMARK04 is not null";
+            DataTable dtPv = db.OpenSQL(strSQL);
+            foreach (DataRow drPv in dtPv.Rows)
+            {
+                string strKey = U3Util.toStr(drPv["REMARK04"]);
+                float fVal = U3Util.toFloat(drPv["PV_VAL"]);
+                if (pvDic.ContainsKey(strKey) == false)
+                    pvDic.Add(strKey, fVal);
             }
 
             Dictionary<string, string> myDictionary = new Dictionary<string, string>();
-
             strSQL = "select isnull(REMARK02, '') as REMARK02 from T_STD_MACH where MACH_TYPE = '05' group by REMARK02";
             DataTable dt = db.OpenSQL(strSQL);
             foreach (DataRow dr in dt.Rows)
@@ -1283,14 +1298,22 @@
 
                 if (oldDic.ContainsKey(item.Key))
                 {
+                    float pvVal = 0;
+                    if (pvDic.ContainsKey(item.Key))
+                    {
+                        pvVal = pvDic[item.Key];
+                    }
+
                     string oldValue = oldDic[item.Key];
-                    if (item.Value.Length > 0 && item.Value != oldValue)
+                    if (item.Value != oldValue)
                     {
                         string sql3 = "";
-                        sql3 += " insert into T_HT_HIST_BASEOIL (COMP_CD,BASEOIL_CD,HBT_CD,REG_DT) values (";
+                        sql3 += " insert into T_HT_HIST_BASEOIL (COMP_CD,BASEOIL_CD,HBT_CD,ONOFF_YN,PV_VAL,REG_DT) values (";
                         sql3 += " '0001', ";
                         sql3 += " '" + item.Key + "', ";
-                        sql3 += " '" + item.Value + "', ";
+                        sql3 += " '" + ((item.Value.Length > 0) ? item.Value : oldValue) + "', ";
+                        sql3 += " '" + ((item.Value.Length > 0) ? "Y" : "N") + "', ";
+                        sql3 += " " + pvVal.ToString() + ", ";
                         sql3 += " getdate() ";
                         sql3 += " )";
                         sql3 += " ";
ModbusTest/U3Config.cs
--- ModbusTest/U3Config.cs
+++ ModbusTest/U3Config.cs
@@ -45,7 +45,7 @@
         {
             Load();
 
-            // 테스트용 서버
+            // 테스트용 개발 서버
             //m_SqlConnStr = "Provider=SQLOLEDB.1;Password=tlrmsjtm~1@3;Persist Security Info=False;User ID=sa;Initial Catalog=U3SMES;Data Source=signus-sf1.koreacentral.cloudapp.azure.com,14443";
 
             // 한국하우톤 현장 서버
Add a comment
List