--- KHSCALE_TP/FormScale.cs
+++ KHSCALE_TP/FormScale.cs
... | ... | @@ -35,7 +35,7 @@ |
35 | 35 |
m_strip = ip.ToString(); |
36 | 36 |
} |
37 | 37 |
|
38 |
- m_strip = "192.168.1.121"; |
|
38 |
+ //m_strip = "192.168.1.121"; |
|
39 | 39 |
|
40 | 40 |
U3Database db = new U3Database(); |
41 | 41 |
try |
--- KHSCALE_TP/U3Config.cs
+++ KHSCALE_TP/U3Config.cs
... | ... | @@ -46,10 +46,10 @@ |
46 | 46 |
Load(); |
47 | 47 |
|
48 | 48 |
// 테스트용 서버 |
49 |
- 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"; |
|
49 |
+ //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"; |
|
50 | 50 |
|
51 | 51 |
// 한국하우톤 현장 서버 |
52 |
- //m_SqlConnStr = "Provider=SQLOLEDB.1;Password=signus1!;Persist Security Info=False;User ID=sa;Initial Catalog=U3SMES;Data Source=192.168.1.17,1433"; |
|
52 |
+ m_SqlConnStr = "Provider=SQLOLEDB.1;Password=signus1!;Persist Security Info=False;User ID=sa;Initial Catalog=U3SMES;Data Source=192.168.1.17,1433"; |
|
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
public void Save() |
--- ModbusTest/FormModbus.cs
+++ ModbusTest/FormModbus.cs
... | ... | @@ -20,6 +20,7 @@ |
20 | 20 |
{ |
21 | 21 |
public partial class FormModbus : Form |
22 | 22 |
{ |
23 |
+ // PLC 주소 |
|
23 | 24 |
string mipAddr = "192.168.1.200"; |
24 | 25 |
//string mipAddr = "127.0.0.1"; |
25 | 26 |
int mPortNumber = 502; |
... | ... | @@ -41,10 +42,10 @@ |
41 | 42 |
SerialConnectionSingleton.Instance().DataBits = 8; |
42 | 43 |
SerialConnectionSingleton.Instance().SlaveNo = 1; |
43 | 44 |
|
44 |
- //UpdateBaseoilSwitch(); |
|
45 |
+ UpdateBaseoilSwitch(); |
|
45 | 46 |
} |
46 | 47 |
|
47 |
- |
|
48 |
+ |
|
48 | 49 |
|
49 | 50 |
|
50 | 51 |
|
... | ... | @@ -307,6 +308,9 @@ |
307 | 308 |
|
308 | 309 |
textBox_State.Select(textBox_State.Text.Length, 0); |
309 | 310 |
textBox_State.ScrollToCaret(); |
311 |
+ |
|
312 |
+ UpdateHbtOnOff(); |
|
313 |
+ UpdateBaseoilSwitch(); |
|
310 | 314 |
} |
311 | 315 |
|
312 | 316 |
public int RunState = 0; |
... | ... | @@ -317,7 +321,7 @@ |
317 | 321 |
switch(RunState) |
318 | 322 |
{ |
319 | 323 |
case 0: |
320 |
- U3Util.ErrorLog(textBox_State.Text); |
|
324 |
+ //U3Util.ErrorLog(textBox_State.Text); |
|
321 | 325 |
textBox_State.Text = ""; |
322 | 326 |
lst = new List<string[,]>(); |
323 | 327 |
break; |
... | ... | @@ -1072,14 +1076,176 @@ |
1072 | 1076 |
textBox_State.Text += "DBInsert Complete : " + input_RealData + "\r\n"; |
1073 | 1077 |
} |
1074 | 1078 |
|
1079 |
+ UpdateHbtOnOff(); |
|
1075 | 1080 |
UpdateBaseoilSwitch(); |
1076 | 1081 |
} |
1077 | 1082 |
|
1083 |
+ private Dictionary<string, int> m_dicHbtOnOff = new Dictionary<string, int>(); |
|
1084 |
+ |
|
1085 |
+ private void UpdateHbtOnOff() |
|
1086 |
+ { |
|
1087 |
+ U3Util.ErrorLog("UpdateHbtOnOff"); |
|
1088 |
+ U3Database db = new U3Database(); |
|
1089 |
+ string strSQL = ""; |
|
1090 |
+ |
|
1091 |
+ strSQL = ""; |
|
1092 |
+ strSQL += " select *"; |
|
1093 |
+ strSQL += " from T_HT_REAL_DATA a"; |
|
1094 |
+ strSQL += " left join T_STD_MACH b on a.MACH_CD = b.MACH_CD"; |
|
1095 |
+ strSQL += " where b.REMARK03 = 'TEMP'"; |
|
1096 |
+ strSQL += ""; |
|
1097 |
+ |
|
1098 |
+ DataTable dtTemp = db.OpenSQL(strSQL); |
|
1099 |
+ |
|
1100 |
+ strSQL = ""; |
|
1101 |
+ strSQL += " select *"; |
|
1102 |
+ strSQL += " from T_HT_REAL_DATA a"; |
|
1103 |
+ strSQL += " left join T_STD_MACH b on a.MACH_CD = b.MACH_CD"; |
|
1104 |
+ strSQL += " where b.REMARK03 = 'TIME'"; |
|
1105 |
+ strSQL += ""; |
|
1106 |
+ |
|
1107 |
+ DataTable dtTime = db.OpenSQL(strSQL); |
|
1108 |
+ |
|
1109 |
+ |
|
1110 |
+ |
|
1111 |
+ strSQL = ""; |
|
1112 |
+ strSQL += " select *"; |
|
1113 |
+ strSQL += " from T_HT_REAL_DATA a"; |
|
1114 |
+ strSQL += " left join T_STD_MACH b on a.MACH_CD = b.MACH_CD"; |
|
1115 |
+ strSQL += " where b.REMARK03 = 'ONOFF'"; |
|
1116 |
+ strSQL += ""; |
|
1117 |
+ |
|
1118 |
+ DataTable dtOnoff = db.OpenSQL(strSQL); |
|
1119 |
+ |
|
1120 |
+ foreach (DataRow dr in dtOnoff.Rows) |
|
1121 |
+ { |
|
1122 |
+ string strHbt = U3Util.toStr(dr["REMARK01"]); |
|
1123 |
+ if (strHbt == "") continue; |
|
1124 |
+ |
|
1125 |
+ int val = U3Util.toInt(dr["REAL_DATA"]); |
|
1126 |
+ |
|
1127 |
+ if (m_dicHbtOnOff.ContainsKey(strHbt)) |
|
1128 |
+ { |
|
1129 |
+ int prev = m_dicHbtOnOff[strHbt]; |
|
1130 |
+ |
|
1131 |
+ // 값이 이전과 달라졌는가? |
|
1132 |
+ if (val != prev) |
|
1133 |
+ { |
|
1134 |
+ U3Util.ErrorLog(String.Format("UpdateHbtOnOff {0}, {1}, {2}", strHbt, val, prev)); |
|
1135 |
+ float fTemp = 0; |
|
1136 |
+ int nTime = 0; |
|
1137 |
+ |
|
1138 |
+ foreach (DataRow drTemp in dtTemp.Rows) |
|
1139 |
+ { |
|
1140 |
+ string s = U3Util.toStr(drTemp["REMARK01"]); |
|
1141 |
+ if (s == strHbt) |
|
1142 |
+ { |
|
1143 |
+ float f1 = U3Util.toFloat(drTemp["REAL_DATA"]); |
|
1144 |
+ float f2 = U3Util.toFloat(drTemp["VALUE_RATIO"]); |
|
1145 |
+ fTemp = f1 * f2; |
|
1146 |
+ break; |
|
1147 |
+ } |
|
1148 |
+ } |
|
1149 |
+ |
|
1150 |
+ foreach (DataRow drTime in dtTime.Rows) |
|
1151 |
+ { |
|
1152 |
+ string s = U3Util.toStr(drTime["REMARK01"]); |
|
1153 |
+ if (s == strHbt) |
|
1154 |
+ { |
|
1155 |
+ nTime = U3Util.toInt(drTime["REAL_DATA"]); |
|
1156 |
+ break; |
|
1157 |
+ } |
|
1158 |
+ } |
|
1159 |
+ |
|
1160 |
+ string sql2 = ""; |
|
1161 |
+ sql2 += " insert into T_HT_HIST_HBT (COMP_CD,HBT_CD,ONOFF_YN,MINUTE_VAL,TEMP_VAL,REG_DT) values ("; |
|
1162 |
+ sql2 += " '0001', "; |
|
1163 |
+ sql2 += " '" + strHbt + "', "; |
|
1164 |
+ sql2 += " '" + (val == 1 ? "Y" : "N") + "', "; |
|
1165 |
+ sql2 += " " + nTime.ToString() + ", "; |
|
1166 |
+ sql2 += " " + fTemp.ToString() + ", "; |
|
1167 |
+ sql2 += " getdate() "; |
|
1168 |
+ sql2 += " )"; |
|
1169 |
+ sql2 += " "; |
|
1170 |
+ |
|
1171 |
+ db.ExcuteSql(sql2); |
|
1172 |
+ } |
|
1173 |
+ } |
|
1174 |
+ |
|
1175 |
+ // 새로운 값을 Dictionary에 저장 |
|
1176 |
+ m_dicHbtOnOff[strHbt] = val; |
|
1177 |
+ } |
|
1178 |
+ |
|
1179 |
+ |
|
1180 |
+ |
|
1181 |
+ /* |
|
1182 |
+ strSQL = "select isnull(REMARK02, '') as REMARK02 from T_STD_MACH where MACH_TYPE = '05' group by REMARK02"; |
|
1183 |
+ DataTable dt = db.OpenSQL(strSQL); |
|
1184 |
+ foreach (DataRow dr in dt.Rows) |
|
1185 |
+ { |
|
1186 |
+ string s = U3Util.toStr(dr["REMARK02"]); |
|
1187 |
+ if (s.Length > 0) |
|
1188 |
+ { |
|
1189 |
+ myDictionary.Add(s, ""); |
|
1190 |
+ } |
|
1191 |
+ } |
|
1192 |
+ |
|
1193 |
+ strSQL = ""; |
|
1194 |
+ strSQL += " select a.MACH_CD, a.MACH_NM, isnull(b.REAL_DATA, 0) as REAL_DATA, a.REMARK01, a.REMARK02"; |
|
1195 |
+ strSQL += " from T_STD_MACH a"; |
|
1196 |
+ strSQL += " left join T_HT_REAL_DATA b on a.MACH_CD = b.MACH_CD"; |
|
1197 |
+ strSQL += " where a.MACH_TYPE = '05'"; |
|
1198 |
+ strSQL += " and isnull(b.REAL_DATA, 0) = 1"; |
|
1199 |
+ dt = db.OpenSQL(strSQL); |
|
1200 |
+ |
|
1201 |
+ foreach (DataRow dr in dt.Rows) |
|
1202 |
+ { |
|
1203 |
+ string s1 = U3Util.toStr(dr["REMARK01"]); |
|
1204 |
+ string s2 = U3Util.toStr(dr["REMARK02"]); |
|
1205 |
+ if (s1.Length > 0 && s2.Length > 0) |
|
1206 |
+ { |
|
1207 |
+ myDictionary[s2] = s1; |
|
1208 |
+ } |
|
1209 |
+ } |
|
1210 |
+ |
|
1211 |
+ foreach (KeyValuePair<string, string> item in myDictionary) |
|
1212 |
+ { |
|
1213 |
+ string sql1 = ""; |
|
1214 |
+ sql1 += " update T_HT_REAL_BASEOIL set"; |
|
1215 |
+ sql1 += " HBT_CD = '" + item.Value + "', "; |
|
1216 |
+ sql1 += " REG_DT = getdate()"; |
|
1217 |
+ sql1 += " where COMP_CD = '0001' and BASEOIL_CD = '" + item.Key + "'"; |
|
1218 |
+ string sql2 = ""; |
|
1219 |
+ sql2 += " insert into T_HT_REAL_BASEOIL (COMP_CD, BASEOIL_CD) values"; |
|
1220 |
+ sql2 += " ('0001', '" + item.Key + "') "; |
|
1221 |
+ |
|
1222 |
+ int nResult = db.ExcuteSql(sql1); |
|
1223 |
+ if (nResult == 0) |
|
1224 |
+ { |
|
1225 |
+ db.ExcuteSql(sql2); |
|
1226 |
+ db.ExcuteSql(sql1); |
|
1227 |
+ } |
|
1228 |
+ } |
|
1229 |
+ */ |
|
1230 |
+ } |
|
1078 | 1231 |
|
1079 | 1232 |
private void UpdateBaseoilSwitch() |
1080 | 1233 |
{ |
1234 |
+ U3Util.ErrorLog("UpdateBaseoilSwitch"); |
|
1081 | 1235 |
U3Database db = new U3Database(); |
1236 |
+ |
|
1082 | 1237 |
string strSQL = ""; |
1238 |
+ |
|
1239 |
+ Dictionary<string, string> oldDic = new Dictionary<string, string>(); |
|
1240 |
+ strSQL = "select * from T_HT_REAL_BASEOIL"; |
|
1241 |
+ DataTable dtOld = db.OpenSQL(strSQL); |
|
1242 |
+ foreach(DataRow drOld in dtOld.Rows) |
|
1243 |
+ { |
|
1244 |
+ string strKey = U3Util.toStr(drOld["BASEOIL_CD"]); |
|
1245 |
+ string strVal = U3Util.toStr(drOld["HBT_CD"]); |
|
1246 |
+ oldDic.Add(strKey, strVal); |
|
1247 |
+ } |
|
1248 |
+ |
|
1083 | 1249 |
Dictionary<string, string> myDictionary = new Dictionary<string, string>(); |
1084 | 1250 |
|
1085 | 1251 |
strSQL = "select isnull(REMARK02, '') as REMARK02 from T_STD_MACH where MACH_TYPE = '05' group by REMARK02"; |
... | ... | @@ -1113,6 +1279,26 @@ |
1113 | 1279 |
|
1114 | 1280 |
foreach (KeyValuePair<string, string> item in myDictionary) |
1115 | 1281 |
{ |
1282 |
+ U3Util.ErrorLog(String.Format("UpdateBaseoilSwitch {0}, {1}", item.Key, item.Value)); |
|
1283 |
+ |
|
1284 |
+ if (oldDic.ContainsKey(item.Key)) |
|
1285 |
+ { |
|
1286 |
+ string oldValue = oldDic[item.Key]; |
|
1287 |
+ if (item.Value.Length > 0 && item.Value != oldValue) |
|
1288 |
+ { |
|
1289 |
+ string sql3 = ""; |
|
1290 |
+ sql3 += " insert into T_HT_HIST_BASEOIL (COMP_CD,BASEOIL_CD,HBT_CD,REG_DT) values ("; |
|
1291 |
+ sql3 += " '0001', "; |
|
1292 |
+ sql3 += " '" + item.Key + "', "; |
|
1293 |
+ sql3 += " '" + item.Value + "', "; |
|
1294 |
+ sql3 += " getdate() "; |
|
1295 |
+ sql3 += " )"; |
|
1296 |
+ sql3 += " "; |
|
1297 |
+ |
|
1298 |
+ db.ExcuteSql(sql3); |
|
1299 |
+ } |
|
1300 |
+ } |
|
1301 |
+ |
|
1116 | 1302 |
string sql1 = ""; |
1117 | 1303 |
sql1 += " update T_HT_REAL_BASEOIL set"; |
1118 | 1304 |
sql1 += " HBT_CD = '" + item.Value + "', "; |
--- ModbusTest/U3Config.cs
+++ ModbusTest/U3Config.cs
... | ... | @@ -46,10 +46,10 @@ |
46 | 46 |
Load(); |
47 | 47 |
|
48 | 48 |
// 테스트용 서버 |
49 |
- 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"; |
|
49 |
+ //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"; |
|
50 | 50 |
|
51 | 51 |
// 한국하우톤 현장 서버 |
52 |
- //m_SqlConnStr = "Provider=SQLOLEDB.1;Password=signus1!;Persist Security Info=False;User ID=sa;Initial Catalog=U3SMES;Data Source=192.168.1.17,1433"; |
|
52 |
+ m_SqlConnStr = "Provider=SQLOLEDB.1;Password=signus1!;Persist Security Info=False;User ID=sa;Initial Catalog=U3SMES;Data Source=192.168.1.17,1433"; |
|
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
public void Save() |
--- ModbusTest/U3Util.cs
+++ ModbusTest/U3Util.cs
... | ... | @@ -209,6 +209,8 @@ |
209 | 209 |
|
210 | 210 |
public static string toStr(object obj, string def = "") |
211 | 211 |
{ |
212 |
+ if (obj == null) return def; |
|
213 |
+ |
|
212 | 214 |
try |
213 | 215 |
{ |
214 | 216 |
return obj.ToString().Trim(); |
... | ... | @@ -221,6 +223,8 @@ |
221 | 223 |
|
222 | 224 |
public static bool toBoolean(object obj, bool def = false) |
223 | 225 |
{ |
226 |
+ if (obj == null) return def; |
|
227 |
+ |
|
224 | 228 |
try |
225 | 229 |
{ |
226 | 230 |
return (bool)obj; |
... | ... | @@ -245,6 +249,7 @@ |
245 | 249 |
|
246 | 250 |
public static Decimal toDecimal(object obj, Decimal def = 0M) |
247 | 251 |
{ |
252 |
+ if (obj == null) return def; |
|
248 | 253 |
try |
249 | 254 |
{ |
250 | 255 |
return Convert.ToDecimal(obj); |
... | ... | @@ -257,6 +262,7 @@ |
257 | 262 |
|
258 | 263 |
public static int toInt(object A, int def = 0) |
259 | 264 |
{ |
265 |
+ if (A == null) return def; |
|
260 | 266 |
try |
261 | 267 |
{ |
262 | 268 |
return Convert.ToInt32(Math.Round(Convert.ToDouble(U3Util.toStr(A, "")), 0)); |
... | ... | @@ -269,6 +275,7 @@ |
269 | 275 |
|
270 | 276 |
public static double toDouble(object A, double def = 0.0) |
271 | 277 |
{ |
278 |
+ if (A == null) return def; |
|
272 | 279 |
try |
273 | 280 |
{ |
274 | 281 |
return double.Parse(U3Util.toStr(A, "")); |
... | ... | @@ -281,6 +288,7 @@ |
281 | 288 |
|
282 | 289 |
public static float toFloat(object A, float def = 0.0f) |
283 | 290 |
{ |
291 |
+ if (A == null) return def; |
|
284 | 292 |
try |
285 | 293 |
{ |
286 | 294 |
return float.Parse(U3Util.toStr(A, "")); |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?