Form1.cs 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10. using System.IO;
  11. using System.Collections.Concurrent;
  12. using System.Threading;
  13. using System.Timers;
  14. using System.Net.NetworkInformation;
  15. namespace BEMSDataGateway
  16. {
  17. public partial class Form1 : Form
  18. {
  19. IcosComm iCosSocket; //iCos 통신클래스
  20. LogFileCreate LFC = new LogFileCreate(); //로그 기록 파일
  21. My_TimerThread MTT = new My_TimerThread();
  22. System.Timers.Timer timer_NetStat = new System.Timers.Timer();
  23. public static bool Enable_EnglishMode;
  24. Parsing PS = new Parsing();
  25. string szICOS_IP; //iCos server 주소
  26. string szICOS_ID; //iCos server ID
  27. string szICOS_PW; //iCos server Password
  28. string szDB_IP; //iCos 프로젝트 DB 주소
  29. string szDB_NAME; //iCos 프로젝트 DB 이름
  30. string szDB_ID; //iCos 프로젝트 DB 접속 ID
  31. string szDB_PW; //iCos 프로젝트 DB 접속 비밀번호
  32. int nDB_TYPE = 1; //iCos 프로젝트 DB 종류 (0:MDB, 1:MS-SQL)
  33. public bool bConnect;
  34. public void CommResponse(string userid, int nType, int nSubType, Object obj) //iCOS 응답처리를 위한 함수
  35. {
  36. if (nType == 6)
  37. {
  38. if (nSubType == 2)
  39. {
  40. iCosLogInResponse _packet = (iCosLogInResponse)obj;
  41. string errMsg;
  42. if (_packet.nResult == 3) //로그인 성공
  43. {
  44. if (Enable_EnglishMode)//영어
  45. {
  46. LFC.Log("Successfully logged in to the iCOS 4 server" + Environment.NewLine);
  47. }
  48. else//한글
  49. {
  50. LFC.Log("iCOS 4 서버에 로그인 성공" + Environment.NewLine);
  51. }
  52. Wirte_state_PointSetBtn(PointSetBtn);
  53. Wirte_PointSetBtn(PointSetBtn);
  54. }
  55. else //로그인 실패
  56. {
  57. if (_packet.nResult == 0)
  58. errMsg = "DB Error";
  59. else if (_packet.nResult == 1)
  60. errMsg = "Password Error";
  61. else if (_packet.nResult == 2)
  62. errMsg = "ID Error";
  63. else
  64. errMsg = "Other Errors";
  65. if (Enable_EnglishMode)//영어
  66. {
  67. LFC.Log("[Form] iCOS4 server Login failure : " + errMsg + Environment.NewLine);
  68. Wirte_logtxt(Convert.ToString(DateTime.Now) + "[Form] iCOS4 server Login failure : " + errMsg + Environment.NewLine);
  69. }
  70. else//한글
  71. {
  72. LFC.Log("[Form] iCOS4 로그인 실패 : " + errMsg + Environment.NewLine);
  73. Wirte_logtxt(Convert.ToString(DateTime.Now) + "[Form] iCOS4 로그인 실패 : " + errMsg + Environment.NewLine);
  74. }
  75. //Wirte_ProStopBtn(ProStopBtn);
  76. LFC.Log("[Form] iCOS4 서버 연결실패 : 3분후 재 로그인을 진행합니다." + Environment.NewLine);
  77. Wirte_logtxt(Convert.ToString(DateTime.Now) + "[Form] iCOS4 로그인 실패 : 3분후 재 로그인을 진행합니다" + Environment.NewLine);
  78. Delay(180000);
  79. iCosSocket.IcosLogin(szICOS_ID, szICOS_PW);
  80. }
  81. }
  82. }
  83. else if (nType == 4) //알람
  84. {
  85. if (nSubType == 11)
  86. {
  87. //알람이 발생하면 여기로 들어온다.
  88. }
  89. else if (nSubType == 9) //ALARM_ACK_FROM_SERVER
  90. {
  91. //서버로 부터 알람에 대한 인지가 발생하면 여기로 들어온다.
  92. }
  93. else if (nSubType == 16) //ALARM_CHACK_ALL_PROCESS_FROM_SERVER
  94. {
  95. //서버로 부터 모든 알람에 대한 인지가 발생하면 여기로 들어온다.
  96. }
  97. else
  98. {
  99. // 그외에 알람관련 정보를 받으면 여기로 들어온다.
  100. }
  101. }
  102. else if (nType == 99)
  103. {
  104. //iCos 서버와의 접속이 끊기고 연결오류 발생시 여기로 들어온다.
  105. if (Enable_EnglishMode)//영어
  106. {
  107. LFC.Log("[Form]The socket connection was broken by the iCos4 server" + Environment.NewLine);
  108. }
  109. else//한글
  110. {
  111. LFC.Log("[Form]iCos4 서버에 의해서 소켓 연결이 끊어졌습니다" + Environment.NewLine);
  112. }
  113. }
  114. }
  115. public static DateTime Delay(int MS)
  116. {
  117. DateTime ThisMoment = DateTime.Now;
  118. TimeSpan duration = new TimeSpan(0, 0, 0, 0, MS);
  119. DateTime AfterWards = ThisMoment.Add(duration);
  120. while (AfterWards >= ThisMoment)
  121. {
  122. System.Windows.Forms.Application.DoEvents();
  123. ThisMoment = DateTime.Now;
  124. }
  125. return DateTime.Now;
  126. }
  127. public bool iCos4ConnectandLogin(string address, string id, string password)// iCOS4 네트워크 상태 파악 함수, 0 : 연결 안됨, 1: 정상 상태
  128. {
  129. bool bRet = false;
  130. var state = iCosSocket.GetConnectionStatus(id);
  131. if (state)
  132. {
  133. iCosSocket.reDisconnect(id);
  134. }
  135. if (iCosSocket.Connect(address, 6000, id, password)) //iCOS 소켓 연결
  136. {
  137. iCosSocket.IcosLogin(id, password); //iCOS 로그인
  138. bRet = true;
  139. }
  140. else
  141. {
  142. iCosSocket.Disconnect(id); //iCOS 소켓 연결 해제
  143. }
  144. return bRet;
  145. }
  146. public string iCos4Connect() //iCOS 연결 함수
  147. {
  148. string strRet = "";
  149. string Result_Connect_iCos = "";
  150. Readini Ri = new Readini();
  151. Ri.ReadData(); // ini의 설정값을 불러옴.
  152. szICOS_IP = Ri.IP1;
  153. szICOS_ID = Ri.ICOS_ID;
  154. szICOS_PW = Ri.ICOS_PASSWORD;
  155. nDB_TYPE = Convert.ToInt32(Ri.ICOSDB_TYPE);
  156. szDB_IP = Ri.ICOSDB_LOC;
  157. szDB_NAME = Ri.ICOSDB_NAME;
  158. szDB_ID = Ri.ICOSDB_ID;
  159. szDB_PW = Ri.ICOSDB_PASSWORD;
  160. Enable_EnglishMode = Ri.Enable_EnglishMode;
  161. this.ProSetBtn.Text = (Enable_EnglishMode ? "Connection setup" : "접속 설정");
  162. this.ProPathBtn.Text = (Enable_EnglishMode ? "Open project folder" : "프로젝트 폴더 열기");
  163. this.Conn_iCos_Btn.Text = (Enable_EnglishMode ? "iCos \r\nconnect" : "iCos \r\n접속");
  164. this.PointSetBtn.Text = (Enable_EnglishMode ? "Registration of control point" : "관제점 등록");
  165. this.PointUnRegBtn.Text = (Enable_EnglishMode ? "Disable control point" : "관제점 해제");
  166. this.ProStartBtn.Text = (Enable_EnglishMode ? "Start" : "시작");
  167. this.ProStopBtn.Text = (Enable_EnglishMode ? "Stop" : "중단");
  168. this.EraseLog.Text = (Enable_EnglishMode ? "Log\r\nClear" : "로그\r\n지우기");
  169. this.groupBox1.Text = (Enable_EnglishMode ? "Preferences" : "환경설정");
  170. this.groupBox5.Text = (Enable_EnglishMode ? "Monitoring" : "모니터링");
  171. this.label6.Text = (Enable_EnglishMode ? "Start \r\nTime" : "시작시간");
  172. this.label4.Text = (Enable_EnglishMode ? "End \r\nTime" : "종료시간");
  173. this.label10.Text = (Enable_EnglishMode ? "Communication status" : "통신상태");
  174. this.label11.Text = (Enable_EnglishMode ? "Verify the value" : "값 확인");
  175. this.AllValueCheck_btn.Text = (Enable_EnglishMode ? "Batch verification of values" : "값 일괄 확인");
  176. this.RequestValue_btn.Text = (Enable_EnglishMode ? "Identify specific values" : "특정 값 확인");
  177. this.groupBox4.Text = (Enable_EnglishMode ? "Log message" : "로그 메시지");
  178. try
  179. {
  180. if (!iCosSocket.InitTagAddress(nDB_TYPE, szDB_IP, szDB_NAME, szDB_ID, szDB_PW)) // iCOS DB 정보 가져옴
  181. {
  182. if (!iCosSocket.InitTagAddress(nDB_TYPE, szDB_IP, szDB_NAME, szDB_ID, szDB_PW)) //1차 실패시, iCOS DB 정보 다시 가져옴
  183. {
  184. if (Enable_EnglishMode)//영어
  185. {
  186. Result_Connect_iCos = "Final failure of iCOS control point DB information setting";
  187. }
  188. else//한글
  189. {
  190. Result_Connect_iCos = "iCOS 관제점 DB정보 설정 최종실패";
  191. }
  192. return Result_Connect_iCos;
  193. }
  194. }
  195. iCosSocket.InitThread(); // iCoS 연결관리
  196. bool bRet = iCos4ConnectandLogin(szICOS_IP, szICOS_ID, szICOS_PW);
  197. if (bRet == false)
  198. {
  199. Result_Connect_iCos = "FAIL";
  200. }
  201. else
  202. {
  203. strRet = bRet.ToString();
  204. Result_Connect_iCos = "SUCCESS";
  205. }
  206. }
  207. catch (Exception)
  208. {
  209. Result_Connect_iCos = "FAIL";
  210. }
  211. LogTxt.Select(LogTxt.Text.Length, 0);
  212. LogTxt.ScrollToCaret();
  213. return Result_Connect_iCos;
  214. }
  215. string[] ReturnTag = new string[2];
  216. public void ReadTag() //iCOS 태그 등록 함수
  217. {
  218. int i;
  219. Parsing Ps = new Parsing();
  220. Control_Point_Group CPG = new Control_Point_Group();
  221. ReturnTag = Ps.TagParsing();
  222. i = iCosSocket.IcosRegTag(szICOS_ID, Convert.ToInt32(ReturnTag[1]), ReturnTag[0]);//Tag 등록
  223. if (i == 1)
  224. {
  225. if (Enable_EnglishMode)//영어
  226. {
  227. LFC.Log("Completion of control point registration " + Environment.NewLine);
  228. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Completion of control point registration" + Environment.NewLine);
  229. }
  230. else//한글
  231. {
  232. LFC.Log("관제점 등록 완료 " + Environment.NewLine);
  233. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 관제점 등록 완료" + Environment.NewLine);
  234. }
  235. }
  236. else
  237. {
  238. if (Enable_EnglishMode)//영어
  239. {
  240. LFC.Log("[Form] Point entry failed" + Environment.NewLine);
  241. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Point entry failed" + Environment.NewLine);
  242. }
  243. else//한글
  244. {
  245. LFC.Log("[Form] 관제점 등록 실패" + Environment.NewLine);
  246. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 관제점 등록 실패" + Environment.NewLine);
  247. }
  248. return;
  249. }
  250. PS.setIcosSocket(iCosSocket);
  251. CPG.setIcosSocket(iCosSocket);
  252. LogTxt.Select(LogTxt.Text.Length, 0);
  253. LogTxt.ScrollToCaret();
  254. }
  255. System.Timers.Timer timer2 = new System.Timers.Timer();
  256. public int UnReg()//iCOS 태그 해제 함수
  257. {
  258. int i;
  259. ReturnTag = PS.TagParsing();
  260. Control_Point_Group CPG = new Control_Point_Group();
  261. i = iCosSocket.IcosUnregTag(szICOS_ID, Convert.ToInt32(ReturnTag[1]), ReturnTag[0]);//태그 등록 해제
  262. PS.setIcosSocket(iCosSocket);
  263. CPG.setIcosSocket(iCosSocket);
  264. if (i == 1)
  265. {
  266. if (Enable_EnglishMode)//영어
  267. {
  268. LFC.Log("[Form] Completion of control point" + Environment.NewLine);
  269. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Completion of control point" + Environment.NewLine);
  270. LogTxt.Select(LogTxt.Text.Length, 0);
  271. LogTxt.ScrollToCaret();
  272. }
  273. else//한글
  274. {
  275. LFC.Log("[Form] 관제점 해제 완료" + Environment.NewLine);
  276. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 관제점 해제 완료" + Environment.NewLine);
  277. LogTxt.Select(LogTxt.Text.Length, 0);
  278. LogTxt.ScrollToCaret();
  279. }
  280. return 1;
  281. }
  282. else
  283. {
  284. if (Enable_EnglishMode)//영어
  285. {
  286. LFC.Log("[Form] Failure to control point" + Environment.NewLine);
  287. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Failure to control point" + Environment.NewLine);
  288. LogTxt.Select(LogTxt.Text.Length, 0);
  289. LogTxt.ScrollToCaret();
  290. }
  291. else//한글
  292. {
  293. LFC.Log("[Form] 관제점 해제 실패" + Environment.NewLine);
  294. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 관제점 해제 실패" + Environment.NewLine);
  295. LogTxt.Select(LogTxt.Text.Length, 0);
  296. LogTxt.ScrollToCaret();
  297. }
  298. return 0;
  299. }
  300. }
  301. public static bool Ping_SyncCheck(string DestIP)
  302. {
  303. try
  304. {
  305. if (DestIP == null || DestIP.Trim().Length == 0) return false;
  306. Ping pingSender = new Ping();
  307. PingOptions options = new PingOptions();
  308. options.DontFragment = true;
  309. string data = "0123456789";
  310. byte[] buffer = Encoding.ASCII.GetBytes(data);
  311. PingReply reply = pingSender.Send(DestIP, 1000, buffer, options);
  312. if (reply.Status == IPStatus.Success)
  313. {
  314. return true;
  315. }
  316. else
  317. {
  318. return false;
  319. }
  320. }
  321. catch
  322. {
  323. return false;
  324. }
  325. }
  326. public Form1() //Form 함수
  327. {
  328. InitializeComponent(); //Form 초기화
  329. iCosSocket = new IcosComm();
  330. // iCos 통신클래스와 연동을 위한 딜리게이트 함수설정
  331. iCosSocket.iCosResponse += new IcosComm.iCosCallback(CommResponse);
  332. Timer_netStat(); //iCOS 네트워크 연결 확인 함수
  333. }
  334. private void Form1_Load(object sender, EventArgs e)
  335. {
  336. ProStopBtn.Enabled = false;
  337. PointSetBtn.Enabled = false;
  338. PointUnRegBtn.Enabled = false;
  339. ProStartBtn.Enabled = false;
  340. ProStopBtn.Enabled = false;
  341. AllValueCheck_btn.Enabled = false;
  342. RequestValue_btn.Enabled = false;
  343. Shown += Form_Shown;
  344. }
  345. public void Timer_netStat() //iCOS 연결 상태 확인 쓰레드 동작 함수
  346. {
  347. timer_NetStat.Interval = 10 * 1000;
  348. timer_NetStat.Elapsed += new ElapsedEventHandler(net_state_Thread);
  349. timer_NetStat.Start();
  350. }
  351. string prevconnectstate = "";
  352. string prevpingstate = "";
  353. public void net_state_Thread(object sender, ElapsedEventArgs e) //iCOS 연결 상태 확인 쓰레드 함수
  354. {
  355. int nNet;
  356. string strRet;
  357. string connectstate = "";
  358. try
  359. {
  360. if (Ping_SyncCheck(szICOS_IP) == true) // Ping 성공
  361. {
  362. nNet = Convert.ToInt32(iCosSocket.GetConnectionStatus(szICOS_ID));
  363. strRet = nNet.ToString();
  364. if (strRet == "1")
  365. {
  366. if (prevconnectstate == "ICOS Communication") // O->O
  367. {
  368. connectstate = "ICOS Communication";
  369. }
  370. else if (prevconnectstate == "ICOS Communication lost") //X -> O / ping onoff시
  371. {
  372. if (prevpingstate == "pingerror")
  373. {
  374. Wirte_state_Conn_iCos_Btn(Conn_iCos_Btn);
  375. Wirte_Conn_iCos_Btn(Conn_iCos_Btn);
  376. prevpingstate = "";
  377. }
  378. else
  379. {
  380. if (Enable_EnglishMode)//영어
  381. {
  382. Wirte_logtxt(Convert.ToString(DateTime.Now) + " ICOS Communication" + Environment.NewLine);
  383. }
  384. else//한글
  385. {
  386. Wirte_logtxt(Convert.ToString(DateTime.Now) + " ICOS 연결" + Environment.NewLine);
  387. }
  388. }
  389. connectstate = "ICOS Communication";
  390. Wirte_Net_Stat(connectstate);
  391. }
  392. else //시작
  393. {
  394. connectstate = "ICOS Communication";
  395. Wirte_Net_Stat(connectstate);
  396. }
  397. }
  398. else
  399. {
  400. if (prevconnectstate == "ICOS Communication") // O->X
  401. {
  402. Wirte_state_ProStartBtn(ProStartBtn);
  403. Wirte_state_PointSetBtn(PointSetBtn);
  404. Wirte_state_Conn_iCos_Btn(Conn_iCos_Btn);
  405. connectstate = "ICOS Communication lost";
  406. Wirte_Net_Stat(connectstate);
  407. if (Enable_EnglishMode)//영어
  408. {
  409. Wirte_logtxt(Convert.ToString(DateTime.Now) + " ICOS Communication lost" + Environment.NewLine);
  410. }
  411. else//한글
  412. {
  413. Wirte_logtxt(Convert.ToString(DateTime.Now) + " ICOS 연결 실패" + Environment.NewLine);
  414. }
  415. }
  416. else if (prevconnectstate == "ICOS Communication lost") //X->X
  417. {
  418. connectstate = "ICOS Communication lost";
  419. }
  420. else //시작
  421. {
  422. connectstate = "ICOS Communication lost";
  423. Wirte_Net_Stat(connectstate);
  424. if (Enable_EnglishMode)//영어
  425. {
  426. Wirte_logtxt(Convert.ToString(DateTime.Now) + " ICOS Communication lost" + Environment.NewLine);
  427. }
  428. else//한글
  429. {
  430. Wirte_logtxt(Convert.ToString(DateTime.Now) + " ICOS 연결 실패" + Environment.NewLine);
  431. }
  432. }
  433. }
  434. prevconnectstate = connectstate;
  435. }
  436. else // Ping 실패
  437. {
  438. if (Enable_EnglishMode)//영어
  439. {
  440. LFC.Log("[Form] ICOS Communication lost(Ping) Error" + Environment.NewLine);
  441. Wirte_logtxt(Convert.ToString(DateTime.Now) + " ICOS Communication lost(Ping) Error" + Environment.NewLine);
  442. }
  443. else//한글
  444. {
  445. LFC.Log("[Form] ICOS 연결 실패(Ping) 오류" + Environment.NewLine);
  446. Wirte_logtxt(Convert.ToString(DateTime.Now) + " ICOS 연결 실패(Ping) 오류" + Environment.NewLine);
  447. }
  448. connectstate = "ICOS Communication lost";
  449. prevconnectstate = connectstate;
  450. Wirte_Net_Stat(connectstate);
  451. prevpingstate = "pingerror";
  452. }
  453. }
  454. catch (Exception E)
  455. {
  456. if (Enable_EnglishMode)//영어
  457. {
  458. LFC.Log("[Form] net_state_Thread Error : " + E + Environment.NewLine);
  459. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] net_state_Thread Error : " + E + Environment.NewLine);
  460. }
  461. else//한글
  462. {
  463. LFC.Log("[Form] net_state_Thread 오류 : " + E + Environment.NewLine);
  464. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] net_state_Thread 오류 : " + E + Environment.NewLine);
  465. }
  466. }
  467. }
  468. private delegate void myDelegate_button(Button btn);
  469. private void Wirte_PointSetBtn(Button btn) ////관제점 재 등록
  470. {
  471. try
  472. {
  473. if (this.PointSetBtn.InvokeRequired)
  474. {
  475. myDelegate_button d = new myDelegate_button(Wirte_PointSetBtn);
  476. this.Invoke(d, btn);
  477. }
  478. else
  479. {
  480. this.PointSetBtn.PerformClick();
  481. }
  482. }
  483. catch (Exception E)
  484. {
  485. if (Enable_EnglishMode)//영어
  486. {
  487. LFC.Log("[Form] Wirte_PointSetBtn Error : " + E + Environment.NewLine);
  488. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] Wirte_PointSetBtn Error : " + E + Environment.NewLine);
  489. }
  490. else//한글
  491. {
  492. LFC.Log("[Form] Wirte_PointSetBtn 오류 : " + E + Environment.NewLine);
  493. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] Wirte_PointSetBtn 오류 : " + E + Environment.NewLine);
  494. }
  495. LogTxt.Select(LogTxt.Text.Length, 0);
  496. LogTxt.ScrollToCaret();
  497. }
  498. }
  499. private void Wirte_Conn_iCos_Btn(Button btn) ////관제점 재 등록
  500. {
  501. try
  502. {
  503. if (this.Conn_iCos_Btn.InvokeRequired)
  504. {
  505. myDelegate_button d = new myDelegate_button(Wirte_Conn_iCos_Btn);
  506. this.Invoke(d, btn);
  507. }
  508. else
  509. {
  510. this.Conn_iCos_Btn.PerformClick();
  511. }
  512. }
  513. catch (Exception E)
  514. {
  515. if (Enable_EnglishMode)//영어
  516. {
  517. LFC.Log("[Form] Wirte_Conn_iCos_Btn Error : " + E + Environment.NewLine);
  518. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] Wirte_Conn_iCos_Btn Error : " + E + Environment.NewLine);
  519. }
  520. else//한글
  521. {
  522. LFC.Log("[Form] Wirte_Conn_iCos_Btn 오류 : " + E + Environment.NewLine);
  523. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] Wirte_Conn_iCos_Btn 오류 : " + E + Environment.NewLine);
  524. }
  525. LogTxt.Select(LogTxt.Text.Length, 0);
  526. LogTxt.ScrollToCaret();
  527. }
  528. }
  529. private void Wirte_state_ProStartBtn(Button btn) //시작버튼 초기화
  530. {
  531. try
  532. {
  533. if (this.ProStartBtn.InvokeRequired)
  534. {
  535. myDelegate_button d = new myDelegate_button(Wirte_state_ProStartBtn);
  536. this.Invoke(d, btn);
  537. }
  538. else
  539. {
  540. this.ProStartBtn.Enabled = true;
  541. }
  542. }
  543. catch (Exception E)
  544. {
  545. if (Enable_EnglishMode)//영어
  546. {
  547. LFC.Log("[Form] Wirte_state_ProStartBtn Error : " + E + Environment.NewLine);
  548. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] Wirte_state_ProStartBtn Error : " + E + Environment.NewLine);
  549. }
  550. else//한글
  551. {
  552. LFC.Log("[Form] Wirte_state_ProStartBtn 오류 : " + E + Environment.NewLine);
  553. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] Wirte_state_ProStartBtn 오류 : " + E + Environment.NewLine);
  554. }
  555. LogTxt.Select(LogTxt.Text.Length, 0);
  556. LogTxt.ScrollToCaret();
  557. }
  558. }
  559. private void Wirte_state_PointSetBtn(Button btn) //관제점 버튼 초기화
  560. {
  561. try
  562. {
  563. if (this.PointSetBtn.InvokeRequired)
  564. {
  565. myDelegate_button d = new myDelegate_button(Wirte_state_PointSetBtn);
  566. this.Invoke(d, btn);
  567. }
  568. else
  569. {
  570. this.PointSetBtn.Enabled = true;
  571. }
  572. }
  573. catch (Exception E)
  574. {
  575. if (Enable_EnglishMode)//영어
  576. {
  577. LFC.Log("[Form] Wirte_state_PointSetBtn Error : " + E + Environment.NewLine);
  578. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] Wirte_state_PointSetBtn Error : " + E + Environment.NewLine);
  579. }
  580. else//한글
  581. {
  582. LFC.Log("[Form] Wirte_state_PointSetBtn 오류 : " + E + Environment.NewLine);
  583. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] Wirte_state_PointSetBtn 오류 : " + E + Environment.NewLine);
  584. }
  585. LogTxt.Select(LogTxt.Text.Length, 0);
  586. LogTxt.ScrollToCaret();
  587. }
  588. }
  589. private void Wirte_state_Conn_iCos_Btn(Button btn) //ICOS 연결 버튼 초기화
  590. {
  591. try
  592. {
  593. if (this.Conn_iCos_Btn.InvokeRequired)
  594. {
  595. myDelegate_button d = new myDelegate_button(Wirte_state_Conn_iCos_Btn);
  596. this.Invoke(d, btn);
  597. }
  598. else
  599. {
  600. this.Conn_iCos_Btn.Enabled = true;
  601. }
  602. }
  603. catch (Exception E)
  604. {
  605. LFC.Log("[Form] Wirte_state_Conn_iCos_Btn 오류 : " + E + Environment.NewLine);
  606. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] Wirte_state_Conn_iCos_Btn 오류 : " + E + Environment.NewLine);
  607. LogTxt.Select(LogTxt.Text.Length, 0);
  608. LogTxt.ScrollToCaret();
  609. }
  610. }
  611. private void Wirte_ProStopBtn(Button btn) //ICOS 연결 버튼 초기화
  612. {
  613. try
  614. {
  615. if (this.ProStopBtn.InvokeRequired)
  616. {
  617. myDelegate_button d = new myDelegate_button(Wirte_ProStopBtn);
  618. this.Invoke(d, btn);
  619. }
  620. else
  621. {
  622. this.ProStopBtn.PerformClick();
  623. }
  624. }
  625. catch (Exception E)
  626. {
  627. if (Enable_EnglishMode)//영어
  628. {
  629. LFC.Log("[Form] Wirte_ProStopBtn Error : " + E + Environment.NewLine);
  630. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] Wirte_ProStopBtn Error : " + E + Environment.NewLine);
  631. }
  632. else//한글
  633. {
  634. LFC.Log("[Form] Wirte_ProStopBtn 오류 : " + E + Environment.NewLine);
  635. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] Wirte_ProStopBtn 오류 : " + E + Environment.NewLine);
  636. }
  637. LogTxt.Select(LogTxt.Text.Length, 0);
  638. LogTxt.ScrollToCaret();
  639. }
  640. }
  641. private delegate void myDelegate_error(string theValue);
  642. private void Wirte_logtxt(string theValue) //통신상태 변화 Form text box에 적용 함수
  643. {
  644. try
  645. {
  646. if (this.LogTxt.InvokeRequired)
  647. {
  648. myDelegate_error d = new myDelegate_error(Wirte_logtxt);
  649. this.Invoke(d, new object[] { theValue });
  650. }
  651. else
  652. {
  653. this.LogTxt.AppendText(theValue);
  654. LogTxt.Select(LogTxt.Text.Length, 0);
  655. LogTxt.ScrollToCaret();
  656. }
  657. }
  658. catch (Exception E)
  659. {
  660. if (Enable_EnglishMode)//영어
  661. {
  662. LFC.Log("[Form] Wirte_logtxt Error : " + E + Environment.NewLine);
  663. }
  664. else//한글
  665. {
  666. LFC.Log("[Form] Wirte_logtxt 오류 : " + E + Environment.NewLine);
  667. }
  668. }
  669. }
  670. private delegate void myDelegate_state(string theValue);
  671. private void Wirte_Net_Stat(string theValue) //통신상태 변화 Form text box에 적용 함수
  672. {
  673. try
  674. {
  675. if (this.Net_Stat.InvokeRequired)
  676. {
  677. myDelegate_state d = new myDelegate_state(Wirte_Net_Stat);
  678. this.Invoke(d, new object[] { theValue });
  679. }
  680. else
  681. {
  682. this.Net_Stat.Text = theValue;
  683. }
  684. }
  685. catch (Exception E)
  686. {
  687. if (Enable_EnglishMode)//영어
  688. {
  689. LFC.Log("[Form] Wirte_Net_Stat Error : " + E + Environment.NewLine);
  690. }
  691. else//한글
  692. {
  693. LFC.Log("[Form] Wirte_Net_Stat 오류 : " + E + Environment.NewLine);
  694. }
  695. }
  696. }
  697. private void Form_Shown(object sender, EventArgs e) //Form 나타날때, 동작 함수
  698. {
  699. string ReturnValue = iCos4Connect();
  700. if (ReturnValue == "SUCCESS")
  701. {
  702. if (Enable_EnglishMode)//영어
  703. {
  704. LFC.Log("Successful iCOS connection");
  705. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Successful iCOS connection" + Environment.NewLine);
  706. }
  707. else//한글
  708. {
  709. LFC.Log("iCOS 접속 성공");
  710. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 성공" + Environment.NewLine);
  711. }
  712. EndTxt.Clear();
  713. StartTxt.Text = Convert.ToString(DateTime.Now);
  714. Conn_iCos_Btn.Enabled = false;
  715. ProStartBtn.Enabled = false;
  716. ProStopBtn.Enabled = true;
  717. PointSetBtn.Enabled = true;
  718. PointUnRegBtn.Enabled = false;
  719. FileSettingBtn.Enabled = false;
  720. FileMatchBtn.Enabled = false;
  721. FileExpBtn.Enabled = false;
  722. //PointSetBtn.PerformClick();
  723. }
  724. else
  725. {
  726. if (Enable_EnglishMode)//영어
  727. {
  728. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS connection failed" + Environment.NewLine);
  729. LFC.Log("iCOS connection failed" + Environment.NewLine);
  730. }
  731. else//한글
  732. {
  733. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 실패" + Environment.NewLine);
  734. LFC.Log("iCOS 접속 실패" + Environment.NewLine);
  735. }
  736. }
  737. LogTxt.Select(LogTxt.Text.Length, 0);
  738. LogTxt.ScrollToCaret();
  739. }
  740. public void ProStartBtn_Click(object sender, EventArgs e) //시작 버튼 클릭 함수
  741. {
  742. int nNet = Convert.ToInt32(iCosSocket.GetConnectionStatus(szICOS_ID));
  743. string strRet = nNet.ToString();
  744. if (strRet == "1")
  745. {
  746. //FolderBrowserDialog();
  747. //if (toolStripStatusLabel1.Text != "")
  748. //{
  749. try
  750. {
  751. FirstCheck FC = new FirstCheck();
  752. string returnvalue = FC.Check_DailyData(); // Hour, Daily 테이블 삽입 및 업데이트
  753. if (returnvalue == "error")
  754. {
  755. if (Enable_EnglishMode)//영어
  756. {
  757. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Program DB connection error" + Environment.NewLine);
  758. LFC.Log("[Form] Program DB connection error" + Environment.NewLine);
  759. }
  760. else//한글
  761. {
  762. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 프로그램 DB 접속 오류" + Environment.NewLine);
  763. LFC.Log("[Form] 프로그램 DB 접속 오류" + Environment.NewLine);
  764. }
  765. return;
  766. }
  767. EndTxt.Clear();
  768. StartTxt.Text = Convert.ToString(DateTime.Now);
  769. ProStartBtn.Enabled = false; // 시작버튼 비활성화.
  770. ProStopBtn.Enabled = true;
  771. FileSettingBtn.Enabled = false;
  772. FileMatchBtn.Enabled = false;
  773. FileExpBtn.Enabled = false;
  774. AllValueCheck_btn.Enabled = true;
  775. RequestValue_btn.Enabled = true;
  776. OneMinute_Insert OMI = new OneMinute_Insert();
  777. OMI.Today_PeakMinMax();
  778. OMI.Year_PeakMinMax();
  779. MTT.timer2start();
  780. if (Enable_EnglishMode)//영어
  781. {
  782. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Start DGW operation" + Environment.NewLine);
  783. LFC.Log("[Form] Start DGW operation" + Environment.NewLine);
  784. }
  785. else//한글
  786. {
  787. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " DGW 작동 시작" + Environment.NewLine);
  788. LFC.Log("[Form] DGW 작동 시작" + Environment.NewLine);
  789. }
  790. }
  791. catch (Exception eProStart)
  792. {
  793. if (Enable_EnglishMode)//영어
  794. {
  795. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Program DB connection error" + Environment.NewLine);
  796. LFC.Log("[Form] Program DB connection error" + Environment.NewLine);
  797. }
  798. else//한글
  799. {
  800. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 프로그램 DB 접속 오류 : " + eProStart + Environment.NewLine);
  801. LFC.Log("[Form] 프로그램 DB 접속 오류 : " + eProStart + Environment.NewLine);
  802. }
  803. }
  804. LogTxt.Select(LogTxt.Text.Length, 0);
  805. LogTxt.ScrollToCaret();
  806. }
  807. else
  808. {
  809. if (Enable_EnglishMode)//영어
  810. {
  811. LFC.Log("Not connected to ICOS" + Environment.NewLine);
  812. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Not connected to ICOS" + Environment.NewLine);
  813. }
  814. else//한글
  815. {
  816. LFC.Log("ICOS와 연결 되지 않았습니다." + Environment.NewLine);
  817. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " ICOS와 연결 되지 않았습니다." + Environment.NewLine);
  818. }
  819. LogTxt.Select(LogTxt.Text.Length, 0);
  820. LogTxt.ScrollToCaret();
  821. }
  822. }
  823. private void ProStopBtn_Click(object sender, EventArgs e) //스탑 버튼 클릭 함수
  824. {
  825. try
  826. {
  827. ProStartBtn.Enabled = true;
  828. ProStopBtn.Enabled = false;
  829. FileSettingBtn.Enabled = true;
  830. FileMatchBtn.Enabled = true;
  831. FileExpBtn.Enabled = true;
  832. EndTxt.Text = Convert.ToString(DateTime.Now);
  833. if (Enable_EnglishMode)//영어
  834. {
  835. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Abort the program" + Environment.NewLine);
  836. LFC.Log("Abort the program" + Environment.NewLine);
  837. }
  838. else//한글
  839. {
  840. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 프로그램 중단" + Environment.NewLine);
  841. LFC.Log("프로그램 중단" + Environment.NewLine);
  842. }
  843. LogTxt.Select(LogTxt.Text.Length, 0);
  844. LogTxt.ScrollToCaret();
  845. MTT.timer2Stop();
  846. }
  847. catch (Exception ex)
  848. {
  849. if (Enable_EnglishMode)//영어
  850. {
  851. LFC.Log("Program interruption error : " + ex + Environment.NewLine);
  852. }
  853. else//한글
  854. {
  855. LFC.Log("프로그램 중단 오류 : " + ex + Environment.NewLine);
  856. }
  857. }
  858. }
  859. private void ProSetBtn_Click(object sender, EventArgs e) //접속 설정 클릭 함수
  860. {
  861. SettingForm SF = new SettingForm();
  862. SF.Text = (Enable_EnglishMode ? "setup" : "설정");
  863. SF.label11.Text = (Enable_EnglishMode ? "BEMS database" : "BEMS 데이타베이스");
  864. SF.label12.Text = (Enable_EnglishMode ? "MMI connect" : "MMI 접속");
  865. SF.label9.Text = (Enable_EnglishMode ? "Air conditioning period" : "냉방기간");
  866. SF.label16.Text = (Enable_EnglishMode ? "Heating period" : "난방기간");
  867. SF.SettingFormSave.Text = (Enable_EnglishMode ? "Save" : "저장");
  868. SF.SettingFormExit.Text = (Enable_EnglishMode ? "Close" : "닫기");
  869. SF.ShowDialog();
  870. }
  871. private void ProPathBtn_Click(object sender, EventArgs e)//프로젝트 설정 클릭 함수
  872. {
  873. System.Diagnostics.Process.Start("explorer.exe", Environment.CurrentDirectory);
  874. }
  875. /// <summary>
  876. /// 셋팅파일 불러오기 버튼
  877. /// </summary>
  878. /// <param name="sender"></param>
  879. /// <param name="e"></param>
  880. private void FileSettingBtn_Click(object sender, EventArgs e)
  881. {
  882. string FSBLocation = Environment.CurrentDirectory + "\\Login.ini";
  883. try
  884. {
  885. System.Diagnostics.Process.Start(FSBLocation);
  886. }
  887. catch
  888. {
  889. FileError(FSBLocation);
  890. }
  891. }
  892. /// <summary>
  893. /// 매칭파일 불러오기 버튼
  894. /// </summary>
  895. /// <param name="sender"></param>
  896. /// <param name="e"></param>
  897. private void FileMatchBtn_Click(object sender, EventArgs e)
  898. {
  899. string FSBLocation = Environment.CurrentDirectory + "\\SettingFile.csv";
  900. try
  901. {
  902. System.Diagnostics.Process.Start(FSBLocation);
  903. }
  904. catch
  905. {
  906. FileError(FSBLocation);
  907. }
  908. }
  909. /// <summary>
  910. /// 수식파일 불러오기 버튼
  911. /// </summary>
  912. /// <param name="sender"></param>
  913. /// <param name="e"></param>
  914. private void FileExpBtn_Click(object sender, EventArgs e)
  915. {
  916. string FSBLocation = Environment.CurrentDirectory + "\\Expression.csv";
  917. try
  918. {
  919. System.Diagnostics.Process.Start(FSBLocation);
  920. }
  921. catch
  922. {
  923. FileError(FSBLocation);
  924. }
  925. }
  926. public void FileError(string Error) // 파일 읽어오기 에러 확인 삼수
  927. {
  928. if ((!Error.Contains("Login.ini")) || (!Error.Contains("expression.csv")) || (!Error.Contains("Matching.csv")))
  929. {
  930. if (Enable_EnglishMode)//영어
  931. {
  932. MessageBox.Show("File not found");
  933. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " File not found" + Environment.NewLine);
  934. LFC.Log("File not found : " + Environment.NewLine);
  935. }
  936. else//한글
  937. {
  938. MessageBox.Show("파일을 찾을 수 없음");
  939. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 파일을 찾을 수 없음" + Environment.NewLine);
  940. LFC.Log("파일을 찾을 수 없음 : " + Environment.NewLine);
  941. }
  942. LogTxt.Select(LogTxt.Text.Length, 0);
  943. LogTxt.ScrollToCaret();
  944. }
  945. }
  946. public void FolderBrowserDialog()
  947. {
  948. toolStripStatusLabel1.Text = Environment.CurrentDirectory;
  949. if (Enable_EnglishMode)//영어
  950. {
  951. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Routing complete" + Environment.NewLine);
  952. LogTxt.AppendText(toolStripStatusLabel1 + Environment.NewLine);
  953. LFC.Log("Routing complete : " + toolStripStatusLabel1 + Environment.NewLine);
  954. }
  955. else//한글
  956. {
  957. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 경로 설정 완료" + Environment.NewLine);
  958. LogTxt.AppendText(toolStripStatusLabel1 + Environment.NewLine);
  959. LFC.Log("경로 설정 완료 : " + toolStripStatusLabel1 + Environment.NewLine);
  960. }
  961. LogTxt.Select(LogTxt.Text.Length, 0);
  962. LogTxt.ScrollToCaret();
  963. }
  964. private void EraseLog_Click(object sender, EventArgs e) // 로그 박스에 로그 기록 삭제 함수
  965. {
  966. LogTxt.Clear();
  967. LogTxt.Select(LogTxt.Text.Length, 0);
  968. LogTxt.ScrollToCaret();
  969. }
  970. private void Form_FormClosing(object sender, FormClosingEventArgs e)// 프로그램 종료 이벤트
  971. {
  972. if (MessageBox.Show((Enable_EnglishMode ? "Do you want to exit the program?" : "프로그램을 종료하시겠습니까?"), (Enable_EnglishMode ? "End" : "종료"), MessageBoxButtons.YesNo) == DialogResult.Yes)
  973. {
  974. if (MTT.timer2 != null)
  975. MTT.timer2Stop();
  976. Application.ExitThread();
  977. for (int i = 0; i < 1000000; i++) {; }
  978. // 프로세스 종료
  979. Application.Exit();
  980. // 프로세스가 남아있다면 최종 종료 (2개의 프로젝트가 공존하고 Application.ProductName 값이 2개다
  981. System.Diagnostics.Process[] mProcess = System.Diagnostics.Process.GetProcessesByName(Application.ProductName);
  982. foreach (System.Diagnostics.Process p in mProcess)
  983. p.Kill();
  984. if (Enable_EnglishMode)//영어
  985. {
  986. LFC.Log("The program has been terminated by the user." + Environment.NewLine);
  987. }
  988. else//한글
  989. {
  990. LFC.Log("사용자에 의해 프로그램이 종료되었습니다." + Environment.NewLine);
  991. }
  992. // 최종 정리 (보완코드 : 크로스 스레드 문제 발생 여지가 있으므로 사용주의)
  993. Environment.Exit(0);
  994. }
  995. else
  996. {
  997. if (Enable_EnglishMode)//영어
  998. {
  999. LFC.Log("Program termination canceled by user.");
  1000. }
  1001. else//한글
  1002. {
  1003. LFC.Log("사용자에 의해 프로그램 종료가 취소되었습니다.");
  1004. }
  1005. e.Cancel = true;
  1006. return;
  1007. }
  1008. }
  1009. private void PointSetBtn_Click(object sender, EventArgs e) //관제점 등록 함수
  1010. {
  1011. int nNet = Convert.ToInt32(iCosSocket.GetConnectionStatus(szICOS_ID));
  1012. string strRet = nNet.ToString();
  1013. if (strRet == "1")
  1014. {
  1015. ReadTag(); //관제점 등록
  1016. Conn_iCos_Btn.Enabled = false;
  1017. AllValueCheck_btn.Enabled = true;
  1018. RequestValue_btn.Enabled = true;
  1019. ProStartBtn.Enabled = true;
  1020. PointUnRegBtn.Enabled = true;
  1021. PointSetBtn.Enabled = false;
  1022. ProStartBtn.PerformClick();
  1023. }
  1024. else
  1025. {
  1026. if (Enable_EnglishMode)//영어
  1027. {
  1028. LFC.Log("Not connected to ICOS." + Environment.NewLine);
  1029. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Not connected to ICOS." + Environment.NewLine);
  1030. }
  1031. else//한글
  1032. {
  1033. LFC.Log("ICOS와 연결 되지 않았습니다." + Environment.NewLine);
  1034. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " ICOS와 연결 되지 않았습니다." + Environment.NewLine);
  1035. }
  1036. LogTxt.Select(LogTxt.Text.Length, 0);
  1037. LogTxt.ScrollToCaret();
  1038. }
  1039. }
  1040. private void Conn_iCos_Btn_Click(object sender, EventArgs e) //iCOS 연결 클릭 함수
  1041. {
  1042. string ReturnValue = iCos4Connect(); //iCOS 연결
  1043. if (ReturnValue == "SUCCESS")
  1044. {
  1045. StartTxt.Text = Convert.ToString(DateTime.Now);
  1046. EndTxt.Clear();
  1047. Conn_iCos_Btn.Enabled = false;
  1048. ProStartBtn.Enabled = false;
  1049. ProStopBtn.Enabled = true;
  1050. PointSetBtn.Enabled = true;
  1051. PointUnRegBtn.Enabled = true;
  1052. //PointSetBtn.PerformClick();
  1053. if (Enable_EnglishMode)//영어
  1054. {
  1055. LFC.Log("Successful iCOS connection" + Environment.NewLine);
  1056. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Successful iCOS connection" + Environment.NewLine);
  1057. }
  1058. else//한글
  1059. {
  1060. LFC.Log("iCOS 접속 성공" + Environment.NewLine);
  1061. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 성공" + Environment.NewLine);
  1062. }
  1063. }
  1064. else
  1065. {
  1066. if (Enable_EnglishMode)//영어
  1067. {
  1068. LFC.Log("iCOS connection failed" + Environment.NewLine);
  1069. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS connection failed" + Environment.NewLine);
  1070. }
  1071. else//한글
  1072. {
  1073. LFC.Log("iCOS 접속 실패" + Environment.NewLine);
  1074. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 실패" + Environment.NewLine);
  1075. }
  1076. }
  1077. LogTxt.Select(LogTxt.Text.Length, 0);
  1078. LogTxt.ScrollToCaret();
  1079. }
  1080. private void PointUnRegBtn_Click(object sender, EventArgs e) //관제점 해제 클릭 함수
  1081. {
  1082. int nNet = Convert.ToInt32(iCosSocket.GetConnectionStatus(szICOS_ID));
  1083. string strRet = nNet.ToString();
  1084. if (strRet == "1")
  1085. {
  1086. int i = UnReg(); //관제점 해제
  1087. if (i == 1)
  1088. {
  1089. PointUnRegBtn.Enabled = false;
  1090. AllValueCheck_btn.Enabled = false;
  1091. RequestValue_btn.Enabled = false;
  1092. ProStartBtn.Enabled = false;
  1093. PointSetBtn.Enabled = true;
  1094. ProStopBtn.PerformClick();
  1095. }
  1096. else
  1097. {
  1098. PointUnRegBtn.Enabled = true;
  1099. }
  1100. }
  1101. else
  1102. {
  1103. if (Enable_EnglishMode)//영어
  1104. {
  1105. LFC.Log("Not connected to ICOS." + Environment.NewLine);
  1106. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Not connected to ICOS." + Environment.NewLine);
  1107. }
  1108. else//한글
  1109. {
  1110. LFC.Log("ICOS와 연결 되지 않았습니다." + Environment.NewLine);
  1111. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " ICOS와 연결 되지 않았습니다." + Environment.NewLine);
  1112. }
  1113. LogTxt.Select(LogTxt.Text.Length, 0);
  1114. LogTxt.ScrollToCaret();
  1115. }
  1116. }
  1117. private void Btn_TagSetFile_Click(object sender, EventArgs e) //TagSetFile 클릭 함수, TagSetFile 파일 생성
  1118. {
  1119. Creating_Setting_File CSF = new Creating_Setting_File();
  1120. CSF.Create_Point_File();
  1121. }
  1122. private void Btn_SettingFile_Click(object sender, EventArgs e)//SettingFile 클릭 함수, SettingFile 파일 생성
  1123. {
  1124. Creating_Setting_File CSF = new Creating_Setting_File();
  1125. CSF.Create_Setting_Point_File();
  1126. }
  1127. private void AllValueCheck_btn_Click(object sender, EventArgs e)//일괄 출력 클릭 함수
  1128. {
  1129. string[] sArray = File.ReadAllLines("TagSetFile.csv", Encoding.Default);
  1130. if (Enable_EnglishMode)//영어
  1131. {
  1132. LogTxt.AppendText("*** current time : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
  1133. LFC.Log("*** current time : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
  1134. }
  1135. else//한글
  1136. {
  1137. LogTxt.AppendText("*** 현재 시간 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
  1138. LFC.Log("*** 현재 시간 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
  1139. }
  1140. try
  1141. {
  1142. for (int i = 0; i < sArray.Length; i++)
  1143. {
  1144. string[] tmp = sArray[i].Split(','); // tmp[0] = index, tmp[1] = Tag명.
  1145. if (Enable_EnglishMode)//영어
  1146. {
  1147. LogTxt.AppendText('"' + tmp[1] + '"' + " value : " + iCosSocket.IcosGetTagValue(tmp[1]) + Environment.NewLine);
  1148. LFC.Log('"' + tmp[1] + '"' + " value : " + iCosSocket.IcosGetTagValue(tmp[1]));
  1149. }
  1150. else//한글
  1151. {
  1152. LogTxt.AppendText('"' + tmp[1] + '"' + " 의 값 : " + iCosSocket.IcosGetTagValue(tmp[1]) + Environment.NewLine);
  1153. LFC.Log('"' + tmp[1] + '"' + " 의 값 : " + iCosSocket.IcosGetTagValue(tmp[1]));
  1154. }
  1155. }
  1156. LogTxt.AppendText("**********************************" + Environment.NewLine);
  1157. LFC.Log("**********************************" + Environment.NewLine);
  1158. }
  1159. catch (Exception er)
  1160. {
  1161. if (Enable_EnglishMode)//영어
  1162. {
  1163. MessageBox.Show("Error occurred");
  1164. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Error occurred : " + er);
  1165. LFC.Log("Error occurred = " + er);
  1166. }
  1167. else//한글
  1168. {
  1169. MessageBox.Show("오류 발생");
  1170. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 오류 발생 : " + er);
  1171. LFC.Log("오류 발생 = " + er);
  1172. }
  1173. }
  1174. LogTxt.Select(LogTxt.Text.Length, 0);
  1175. LogTxt.ScrollToCaret();
  1176. }
  1177. private void RequestValue_btn_Click(object sender, EventArgs e) //특정 값 출력 함수
  1178. {
  1179. if (RequestValue.Text != "")
  1180. {
  1181. if (Enable_EnglishMode)//영어
  1182. {
  1183. LogTxt.AppendText("*** current time : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
  1184. LFC.Log("*** current time : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
  1185. }
  1186. else//한글
  1187. {
  1188. LogTxt.AppendText("*** 현재 시간 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
  1189. LFC.Log("*** 현재 시간 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
  1190. }
  1191. try
  1192. {
  1193. string tmp = RequestValue.Text; //태그값
  1194. if (Enable_EnglishMode)//영어
  1195. {
  1196. LogTxt.AppendText('"' + tmp + '"' + " value : " + iCosSocket.IcosGetTagValue(tmp) + Environment.NewLine);
  1197. LFC.Log(tmp + " value : " + iCosSocket.IcosGetTagValue(tmp) + Environment.NewLine);
  1198. }
  1199. else//한글
  1200. {
  1201. LogTxt.AppendText('"' + tmp + '"' + " 의 값 : " + iCosSocket.IcosGetTagValue(tmp) + Environment.NewLine);
  1202. LFC.Log(tmp + " 의 값 : " + iCosSocket.IcosGetTagValue(tmp) + Environment.NewLine);
  1203. }
  1204. LogTxt.AppendText("**********************************" + Environment.NewLine);
  1205. LFC.Log("**********************************" + Environment.NewLine);
  1206. }
  1207. catch (Exception er)
  1208. {
  1209. if (Enable_EnglishMode)//영어
  1210. {
  1211. MessageBox.Show("Error occurred");
  1212. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " Error occurred : " + er);
  1213. LFC.Log("Error occurred : " + er);
  1214. }
  1215. else//한글
  1216. {
  1217. MessageBox.Show("오류 발생");
  1218. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 오류 발생 : " + er);
  1219. LFC.Log("오류 발생 : " + er);
  1220. }
  1221. }
  1222. }
  1223. else
  1224. {
  1225. if (Enable_EnglishMode)//영어
  1226. {
  1227. MessageBox.Show("No confirmation value.");
  1228. }
  1229. else//한글
  1230. {
  1231. MessageBox.Show("확인 값이 없습니다.");
  1232. }
  1233. return;
  1234. }
  1235. LogTxt.Select(LogTxt.Text.Length, 0);
  1236. LogTxt.ScrollToCaret();
  1237. }
  1238. private void RequestValue_KeyPress(object sender, KeyPressEventArgs e)
  1239. {
  1240. if (e.KeyChar == 8) //백스페이스할때, 데이터 삭제
  1241. {
  1242. if (RequestValue.Text.Length != 0)
  1243. {
  1244. RequestValue.Text = RequestValue.Text.Substring(0, RequestValue.Text.Length - 1);
  1245. RequestValue.Select(RequestValue.Text.Length, 0);
  1246. e.Handled = true;
  1247. }
  1248. else
  1249. {
  1250. e.Handled = true;
  1251. }
  1252. }
  1253. else
  1254. {
  1255. RequestValue.Select(RequestValue.Text.Length, 0); //현재 데이터 뒤로 포커스 이동
  1256. }
  1257. }
  1258. private void RequestValue_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
  1259. {
  1260. if (e.Control && e.KeyCode == Keys.A) //Ctrl + A 동작
  1261. {
  1262. ((TextBox)sender).SelectAll();
  1263. }
  1264. if (e.Control && e.KeyCode == Keys.C) //Ctrl + C 동작
  1265. {
  1266. ((TextBox)sender).Copy();
  1267. }
  1268. if (e.Control && e.KeyCode == Keys.V) //Ctrl + V 동작
  1269. {
  1270. ((TextBox)sender).Paste();
  1271. }
  1272. if (e.Control && e.KeyCode == Keys.X) //Ctrl + X 동작
  1273. {
  1274. ((TextBox)sender).Cut();
  1275. }
  1276. }
  1277. private void LogTxt_TextChanged(object sender, EventArgs e)
  1278. {
  1279. if (LogTxt.Lines.Length >= 5000)
  1280. {
  1281. LogTxt.Clear();
  1282. LogTxt.Select(LogTxt.Text.Length, 0);
  1283. LogTxt.ScrollToCaret();
  1284. }
  1285. }
  1286. }
  1287. }