8495a0ecd96f85f06f2357947e3d8822a7bf4b2d.svn-base 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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. namespace BEMSDataGateway
  15. {
  16. public partial class Form1 : Form
  17. {
  18. IcosComm iCosSocket; //iCos 통신클래스
  19. LogFileCreate LFC = new LogFileCreate(); //로그 기록 파일
  20. My_TimerThread MTT = new My_TimerThread();
  21. System.Timers.Timer timer_NetStat = new System.Timers.Timer();
  22. Parsing PS = new Parsing();
  23. string szICOS_IP; //iCos server 주소
  24. string szICOS_ID; //iCos server ID
  25. string szICOS_PW; //iCos server Password
  26. string szDB_IP; //iCos 프로젝트 DB 주소
  27. string szDB_NAME; //iCos 프로젝트 DB 이름
  28. string szDB_ID; //iCos 프로젝트 DB 접속 ID
  29. string szDB_PW; //iCos 프로젝트 DB 접속 비밀번호
  30. int nDB_TYPE = 1; //iCos 프로젝트 DB 종류 (0:MDB, 1:MS-SQL)
  31. public bool bConnect;
  32. public void CommResponse(string userid, int nType, int nSubType, Object obj) //iCOS 응답처리를 위한 함수
  33. {
  34. if (nType == 6)
  35. {
  36. if (nSubType == 2)
  37. {
  38. iCosLogInResponse _packet = (iCosLogInResponse)obj;
  39. string errMsg;
  40. if (_packet.nResult == 3) //로그인 성공
  41. {
  42. LFC.Log("iCOS 4 서버에 로그인 성공" + Environment.NewLine);
  43. }
  44. else //로그인 실패
  45. {
  46. if (_packet.nResult == 0)
  47. errMsg = "DB Error";
  48. else if (_packet.nResult == 1)
  49. errMsg = "Password Error";
  50. else if (_packet.nResult == 2)
  51. errMsg = "ID Error";
  52. else
  53. errMsg = "Other Errors";
  54. LFC.Log("[Form] iCOS4 서버 연결실패 : " + errMsg + Environment.NewLine);
  55. }
  56. }
  57. }
  58. else if (nType == 4) //알람
  59. {
  60. if (nSubType == 11)
  61. {
  62. //알람이 발생하면 여기로 들어온다.
  63. }
  64. else if (nSubType == 9) //ALARM_ACK_FROM_SERVER
  65. {
  66. //서버로 부터 알람에 대한 인지가 발생하면 여기로 들어온다.
  67. }
  68. else if (nSubType == 16) //ALARM_CHACK_ALL_PROCESS_FROM_SERVER
  69. {
  70. //서버로 부터 모든 알람에 대한 인지가 발생하면 여기로 들어온다.
  71. }
  72. else
  73. {
  74. // 그외에 알람관련 정보를 받으면 여기로 들어온다.
  75. }
  76. }
  77. else if (nType == 99)
  78. {
  79. //iCos 서버와의 접속이 끊기고 연결오류 발생시 여기로 들어온다.
  80. LFC.Log("[Form]iCos4 서버에 의해서 소켓 연결이 끊어졌습니다" + Environment.NewLine); ;
  81. }
  82. }
  83. public bool iCos4ConnectandLogin(string address, string id, string password)// iCOS4 네트워크 상태 파악 함수, 0 : 연결 안됨, 1: 정상 상태
  84. {
  85. bool bRet = false;
  86. if (iCosSocket.Connect(address, 6000, id, password)) //iCOS 소켓 연결
  87. {
  88. iCosSocket.IcosLogin(id, password); //iCOS 로그인
  89. bRet = true;
  90. }
  91. else
  92. {
  93. iCosSocket.Disconnect(id); //iCOS 소켓 연결 해제
  94. }
  95. return bRet;
  96. }
  97. public string iCos4Connect() //iCOS 연결 함수
  98. {
  99. string strRet = "";
  100. string Result_Connect_iCos = "";
  101. Readini Ri = new Readini();
  102. Ri.ReadData(); // ini의 설정값을 불러옴.
  103. szICOS_IP = Ri.IP1;
  104. szICOS_ID = Ri.ICOS_ID;
  105. szICOS_PW = Ri.ICOS_PASSWORD;
  106. nDB_TYPE = Convert.ToInt32(Ri.ICOSDB_TYPE);
  107. szDB_IP = Ri.ICOSDB_LOC;
  108. szDB_NAME = Ri.ICOSDB_NAME;
  109. szDB_ID = Ri.ICOSDB_ID;
  110. szDB_PW = Ri.ICOSDB_PASSWORD;
  111. try
  112. {
  113. if (!iCosSocket.InitTagAddress(nDB_TYPE, szDB_IP, szDB_NAME, szDB_ID, szDB_PW)) // iCOS DB 정보 가져옴
  114. {
  115. if (!iCosSocket.InitTagAddress(nDB_TYPE, szDB_IP, szDB_NAME, szDB_ID, szDB_PW)) //1차 실패시, iCOS DB 정보 다시 가져옴
  116. {
  117. Result_Connect_iCos = "iCOS 관제점 DB정보 설정 최종실패";
  118. return Result_Connect_iCos;
  119. }
  120. }
  121. iCosSocket.InitThread(); // iCoS 연결관리
  122. bool bRet = iCos4ConnectandLogin(szICOS_IP, szICOS_ID, szICOS_PW);
  123. if (bRet == false)
  124. {
  125. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 실패" + Environment.NewLine);
  126. LFC.Log("iCOS 접속 실패");
  127. Result_Connect_iCos = "FAIL";
  128. }
  129. else
  130. {
  131. strRet = bRet.ToString();
  132. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 시작" + Environment.NewLine);
  133. LFC.Log("iCOS 접속 시작");
  134. Result_Connect_iCos = "SUCCESS";
  135. }
  136. }
  137. catch (Exception)
  138. {
  139. Result_Connect_iCos = "FAIL";
  140. }
  141. LogTxt.Select(LogTxt.Text.Length, 0);
  142. LogTxt.ScrollToCaret();
  143. return Result_Connect_iCos;
  144. }
  145. string[] ReturnTag = new string[2];
  146. public void ReadTag() //iCOS 태그 등록 함수
  147. {
  148. int i;
  149. Parsing Ps = new Parsing();
  150. Control_Point_Group CPG = new Control_Point_Group();
  151. ReturnTag = Ps.TagParsing();
  152. i = iCosSocket.IcosRegTag(szICOS_ID, Convert.ToInt32(ReturnTag[1]), ReturnTag[0]);//Tag 등록
  153. if (i == 1)
  154. {
  155. LFC.Log("관제점 등록 완료 " + Environment.NewLine);
  156. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 관제점 등록 완료" + Environment.NewLine);
  157. }
  158. else
  159. {
  160. LFC.Log("[Form] 관제점 등록 실패" + Environment.NewLine);
  161. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 관제점 등록 실패" + Environment.NewLine);
  162. }
  163. PS.setIcosSocket(iCosSocket);
  164. CPG.setIcosSocket(iCosSocket);
  165. LogTxt.Select(LogTxt.Text.Length, 0);
  166. LogTxt.ScrollToCaret();
  167. }
  168. System.Timers.Timer timer2 = new System.Timers.Timer();
  169. public int UnReg()//iCOS 태그 해제 함수
  170. {
  171. int i;
  172. ReturnTag = PS.TagParsing();
  173. Control_Point_Group CPG = new Control_Point_Group();
  174. i = iCosSocket.IcosUnregTag(szICOS_ID, Convert.ToInt32(ReturnTag[1]), ReturnTag[0]);//태그 등록 해제
  175. PS.setIcosSocket(iCosSocket);
  176. CPG.setIcosSocket(iCosSocket);
  177. if (i == 1)
  178. {
  179. LFC.Log("[Form] 관제점 해제 완료" + Environment.NewLine);
  180. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 관제점 해제 완료" + Environment.NewLine);
  181. LogTxt.Select(LogTxt.Text.Length, 0);
  182. LogTxt.ScrollToCaret();
  183. return 1;
  184. }
  185. else
  186. {
  187. LFC.Log("[Form] 관제점 해제 실패" + Environment.NewLine);
  188. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 관제점 해제 실패" + Environment.NewLine);
  189. LogTxt.Select(LogTxt.Text.Length, 0);
  190. LogTxt.ScrollToCaret();
  191. return 0;
  192. }
  193. }
  194. public Form1() //Form 함수
  195. {
  196. InitializeComponent(); //Form 초기화
  197. iCosSocket = new IcosComm();
  198. // iCos 통신클래스와 연동을 위한 딜리게이트 함수설정
  199. iCosSocket.iCosResponse += new IcosComm.iCosCallback(CommResponse);
  200. Timer_netStat(); //iCOS 네트워크 연결 확인 함수
  201. }
  202. private void Form1_Load(object sender, EventArgs e)
  203. {
  204. ProStopBtn.Enabled = false;
  205. PointSetBtn.Enabled = false;
  206. PointUnRegBtn.Enabled = false;
  207. ProStartBtn.Enabled = false;
  208. ProStopBtn.Enabled = false;
  209. AllValueCheck_btn.Enabled = false;
  210. RequestValue_btn.Enabled = false;
  211. Shown += Form_Shown;
  212. }
  213. public void Timer_netStat() //iCOS 연결 상태 확인 쓰레드 동작 함수
  214. {
  215. timer_NetStat.Interval = 3000;
  216. timer_NetStat.Elapsed += new ElapsedEventHandler(net_state_Thread);
  217. timer_NetStat.Start();
  218. }
  219. bool changed = false;
  220. public void net_state_Thread(object sender, ElapsedEventArgs e) //iCOS 연결 상태 확인 쓰레드 함수
  221. {
  222. int nNet;
  223. string strRet;
  224. string connectstate = "";
  225. try
  226. {
  227. nNet = Convert.ToInt32(iCosSocket.GetConnectionStatus(szICOS_ID));
  228. strRet = nNet.ToString();
  229. if (strRet == "1")
  230. {
  231. if (changed == false)
  232. {
  233. connectstate = "ICOS 통신중";
  234. }
  235. else
  236. {
  237. Wirte_logtxt(Convert.ToString(DateTime.Now) + " ICOS와 통신 연결" + Environment.NewLine);
  238. Wirte_btn(PointSetBtn);
  239. }
  240. changed = false;
  241. }
  242. else
  243. {
  244. connectstate = "ICOS 통신끊김";
  245. changed = true;
  246. Wirte_logtxt(Convert.ToString(DateTime.Now) + " ICOS와 통신 끊김" + Environment.NewLine);
  247. }
  248. Wirte_Net_Stat(connectstate); // 통신상태 체크, 딜리게이트 활용: 스레드를 통한 Form UI 변경시 필요
  249. }
  250. catch (Exception E)
  251. {
  252. LFC.Log("[Form] net_state_Thread 오류 : " + E + Environment.NewLine);
  253. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] net_state_Thread 오류 : " + E + Environment.NewLine);
  254. }
  255. }
  256. private delegate void myDelegate_button(Button btn);
  257. private void Wirte_btn(Button btn) //통신상태 변화 Form text box에 적용 함수
  258. {
  259. try
  260. {
  261. if (PointSetBtn.InvokeRequired)
  262. {
  263. myDelegate_button d = new myDelegate_button(Wirte_btn);
  264. this.Invoke(d, btn);
  265. }
  266. else
  267. {
  268. btn.PerformClick();
  269. }
  270. }
  271. catch (Exception E)
  272. {
  273. LFC.Log("[Form] Wirte_btn 오류 : " + E + Environment.NewLine);
  274. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] Wirte_btn 오류 : " + E + Environment.NewLine);
  275. LogTxt.Select(LogTxt.Text.Length, 0);
  276. LogTxt.ScrollToCaret();
  277. }
  278. }
  279. private delegate void myDelegate_error(string theValue);
  280. private void Wirte_logtxt(string theValue) //통신상태 변화 Form text box에 적용 함수
  281. {
  282. try
  283. {
  284. if (this.LogTxt.InvokeRequired)
  285. {
  286. myDelegate_error d = new myDelegate_error(Wirte_logtxt);
  287. this.Invoke(d, new object[] { theValue });
  288. }
  289. else
  290. {
  291. this.LogTxt.AppendText(theValue);
  292. LogTxt.Select(LogTxt.Text.Length, 0);
  293. LogTxt.ScrollToCaret();
  294. }
  295. }
  296. catch (Exception E)
  297. {
  298. LFC.Log("[Form] Wirte_logtxt 오류 : " + E + Environment.NewLine);
  299. }
  300. }
  301. private delegate void myDelegate_state(string theValue);
  302. private void Wirte_Net_Stat(string theValue) //통신상태 변화 Form text box에 적용 함수
  303. {
  304. try
  305. {
  306. if (this.Net_Stat.InvokeRequired)
  307. {
  308. myDelegate_state d = new myDelegate_state(Wirte_Net_Stat);
  309. this.Invoke(d, new object[] { theValue });
  310. }
  311. else
  312. {
  313. this.Net_Stat.Text = theValue;
  314. }
  315. }
  316. catch (Exception E)
  317. {
  318. LFC.Log("[Form] Wirte_Net_Stat 오류 : " + E + Environment.NewLine);
  319. }
  320. }
  321. private void Form_Shown(object sender, EventArgs e) //Form 나타날때, 동작 함수
  322. {
  323. string ReturnValue = iCos4Connect();
  324. if (ReturnValue == "SUCCESS")
  325. {
  326. LFC.Log("iCOS 접속 성공");
  327. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 성공" + Environment.NewLine);
  328. EndTxt.Clear();
  329. StartTxt.Text = Convert.ToString(DateTime.Now);
  330. Conn_iCos_Btn.Enabled = false;
  331. ProStartBtn.Enabled = false;
  332. ProStopBtn.Enabled = true;
  333. PointSetBtn.Enabled = true;
  334. PointUnRegBtn.Enabled = false;
  335. FileSettingBtn.Enabled = false;
  336. FileMatchBtn.Enabled = false;
  337. FileExpBtn.Enabled = false;
  338. }
  339. else
  340. {
  341. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 실패" + Environment.NewLine);
  342. LFC.Log("iCOS 접속 실패" + Environment.NewLine);
  343. }
  344. LogTxt.Select(LogTxt.Text.Length, 0);
  345. LogTxt.ScrollToCaret();
  346. }
  347. private void ProStartBtn_Click(object sender, EventArgs e) //시작 버튼 클릭 함수
  348. {
  349. FolderBrowserDialog();
  350. if (toolStripStatusLabel1.Text != "")
  351. {
  352. try
  353. {
  354. EndTxt.Clear();
  355. StartTxt.Text = Convert.ToString(DateTime.Now);
  356. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 프로그램 시작" + Environment.NewLine);
  357. LFC.Log("프로그램 시작" + Environment.NewLine);
  358. ProStartBtn.Enabled = false; // 시작버튼 비활성화.
  359. ProStopBtn.Enabled = true;
  360. FileSettingBtn.Enabled = false;
  361. FileMatchBtn.Enabled = false;
  362. FileExpBtn.Enabled = false;
  363. AllValueCheck_btn.Enabled = true;
  364. RequestValue_btn.Enabled = true;
  365. FirstCheck FC = new FirstCheck();
  366. FC.Check_DailyData(); // Hour, Daily 테이블 삽입 및 업데이트
  367. OneMinute_Insert OMI = new OneMinute_Insert();
  368. OMI.Today_PeakMinMax();
  369. OMI.Year_PeakMinMax();
  370. MTT.timer2start();
  371. }
  372. catch (Exception eProStart)
  373. {
  374. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 프로그램 DB 접속 오류 : " + eProStart + Environment.NewLine);
  375. LFC.Log("[Form] 프로그램 DB 접속 오류 : " + eProStart + Environment.NewLine);
  376. }
  377. }
  378. else
  379. {
  380. MessageBox.Show("경로를 설정해주세요");
  381. }
  382. LogTxt.Select(LogTxt.Text.Length, 0);
  383. LogTxt.ScrollToCaret();
  384. }
  385. private void ProStopBtn_Click(object sender, EventArgs e) //스탑 버튼 클릭 함수
  386. {
  387. try
  388. {
  389. ProStartBtn.Enabled = true;
  390. ProStopBtn.Enabled = false;
  391. AllValueCheck_btn.Enabled = false;
  392. RequestValue_btn.Enabled = false;
  393. FileSettingBtn.Enabled = true;
  394. FileMatchBtn.Enabled = true;
  395. FileExpBtn.Enabled = true;
  396. EndTxt.Text = Convert.ToString(DateTime.Now);
  397. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 프로그램 중단" + Environment.NewLine);
  398. LFC.Log("프로그램 중단" + Environment.NewLine);
  399. LogTxt.Select(LogTxt.Text.Length, 0);
  400. LogTxt.ScrollToCaret();
  401. MTT.timer2Stop();
  402. }
  403. catch (Exception ex)
  404. {
  405. LFC.Log("프로그램 중단 오류 : " + ex + Environment.NewLine);
  406. }
  407. }
  408. private void ProSetBtn_Click(object sender, EventArgs e) //접속 설정 클릭 함수
  409. {
  410. SettingForm SF = new SettingForm();
  411. SF.ShowDialog();
  412. }
  413. private void ProPathBtn_Click(object sender, EventArgs e)//프로젝트 설정 클릭 함수
  414. {
  415. System.Diagnostics.Process.Start("explorer.exe", Environment.CurrentDirectory);
  416. }
  417. /// <summary>
  418. /// 셋팅파일 불러오기 버튼
  419. /// </summary>
  420. /// <param name="sender"></param>
  421. /// <param name="e"></param>
  422. private void FileSettingBtn_Click(object sender, EventArgs e)
  423. {
  424. string FSBLocation = Environment.CurrentDirectory + "\\Login.ini";
  425. try
  426. {
  427. System.Diagnostics.Process.Start(FSBLocation);
  428. }
  429. catch
  430. {
  431. FileError(FSBLocation);
  432. }
  433. }
  434. /// <summary>
  435. /// 매칭파일 불러오기 버튼
  436. /// </summary>
  437. /// <param name="sender"></param>
  438. /// <param name="e"></param>
  439. private void FileMatchBtn_Click(object sender, EventArgs e)
  440. {
  441. string FSBLocation = Environment.CurrentDirectory + "\\SettingFile.csv";
  442. try
  443. {
  444. System.Diagnostics.Process.Start(FSBLocation);
  445. }
  446. catch
  447. {
  448. FileError(FSBLocation);
  449. }
  450. }
  451. /// <summary>
  452. /// 수식파일 불러오기 버튼
  453. /// </summary>
  454. /// <param name="sender"></param>
  455. /// <param name="e"></param>
  456. private void FileExpBtn_Click(object sender, EventArgs e)
  457. {
  458. string FSBLocation = Environment.CurrentDirectory + "\\Expression.csv";
  459. try
  460. {
  461. System.Diagnostics.Process.Start(FSBLocation);
  462. }
  463. catch
  464. {
  465. FileError(FSBLocation);
  466. }
  467. }
  468. public void FileError(string Error) // 파일 읽어오기 에러 확인 삼수
  469. {
  470. if ((!Error.Contains("Login.ini")) || (!Error.Contains("expression.csv")) || (!Error.Contains("Matching.csv")))
  471. {
  472. MessageBox.Show("파일을 찾을 수 없음");
  473. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 파일을 찾을 수 없음" + Environment.NewLine);
  474. LFC.Log("파일을 찾을 수 없음 : " + Environment.NewLine);
  475. LogTxt.Select(LogTxt.Text.Length, 0);
  476. LogTxt.ScrollToCaret();
  477. }
  478. }
  479. public void FolderBrowserDialog()
  480. {
  481. toolStripStatusLabel1.Text = Environment.CurrentDirectory;
  482. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 경로 설정 완료" + Environment.NewLine);
  483. LogTxt.AppendText(toolStripStatusLabel1 + Environment.NewLine);
  484. LFC.Log("경로설정완료");
  485. LFC.Log("경로 : " + toolStripStatusLabel1 + Environment.NewLine);
  486. LogTxt.Select(LogTxt.Text.Length, 0);
  487. LogTxt.ScrollToCaret();
  488. }
  489. private void EraseLog_Click(object sender, EventArgs e) // 로그 박스에 로그 기록 삭제 함수
  490. {
  491. LogTxt.Clear();
  492. LogTxt.Select(LogTxt.Text.Length, 0);
  493. LogTxt.ScrollToCaret();
  494. }
  495. private void Form_FormClosing(object sender, FormClosingEventArgs e)// 프로그램 종료 이벤트
  496. {
  497. if (MessageBox.Show("프로그램을 종료하시겠습니까?", "종료", MessageBoxButtons.YesNo) == DialogResult.Yes)
  498. {
  499. LFC.Log("사용자에 의해 프로그램이 종료되었습니다." + Environment.NewLine);
  500. MTT.timer2Stop();
  501. Dispose();
  502. }
  503. else
  504. {
  505. LFC.Log("사용자에 의해 프로그램 종료가 취소되었습니다.");
  506. e.Cancel = true;
  507. return;
  508. }
  509. }
  510. private void PointSetBtn_Click(object sender, EventArgs e) //관제점 등록 함수
  511. {
  512. int nNet;
  513. string strRet;
  514. nNet = Convert.ToInt32(iCosSocket.GetConnectionStatus(szICOS_ID));
  515. strRet = nNet.ToString();
  516. if (strRet == "1")
  517. {
  518. ReadTag(); //관제점 등록
  519. AllValueCheck_btn.Enabled = true;
  520. RequestValue_btn.Enabled = true;
  521. ProStartBtn.Enabled = true;
  522. PointUnRegBtn.Enabled = true;
  523. }
  524. else
  525. {
  526. LFC.Log("관제점 등록 실패!!" + Environment.NewLine);
  527. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 관제점 등록 실패!!" + Environment.NewLine);
  528. LogTxt.Select(LogTxt.Text.Length, 0);
  529. LogTxt.ScrollToCaret();
  530. }
  531. }
  532. private void Conn_iCos_Btn_Click(object sender, EventArgs e) //iCOS 연결 클릭 함수
  533. {
  534. string ReturnValue = iCos4Connect(); //iCOS 연결
  535. if (ReturnValue == "SUCCESS")
  536. {
  537. StartTxt.Text = Convert.ToString(DateTime.Now);
  538. EndTxt.Clear();
  539. Conn_iCos_Btn.Enabled = false;
  540. ProStartBtn.Enabled = false;
  541. ProStopBtn.Enabled = true;
  542. PointSetBtn.Enabled = true;
  543. PointUnRegBtn.Enabled = true;
  544. LFC.Log("iCOS 접속 성공" + Environment.NewLine);
  545. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 성공" + Environment.NewLine);
  546. }
  547. else
  548. {
  549. LFC.Log("iCOS 접속 실패" + Environment.NewLine);
  550. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 실패" + Environment.NewLine);
  551. }
  552. LogTxt.Select(LogTxt.Text.Length, 0);
  553. LogTxt.ScrollToCaret();
  554. }
  555. private void PointUnRegBtn_Click(object sender, EventArgs e) //관제점 해제 클릭 함수
  556. {
  557. int i;
  558. i = UnReg(); //관제점 해제
  559. if (i == 1)
  560. {
  561. PointUnRegBtn.Enabled = false;
  562. AllValueCheck_btn.Enabled = false;
  563. RequestValue_btn.Enabled = false;
  564. ProStartBtn.Enabled = false;
  565. }
  566. else
  567. {
  568. PointUnRegBtn.Enabled = true;
  569. }
  570. }
  571. private void Btn_TagSetFile_Click(object sender, EventArgs e) //TagSetFile 클릭 함수, TagSetFile 파일 생성
  572. {
  573. Creating_Setting_File CSF = new Creating_Setting_File();
  574. CSF.Create_Point_File();
  575. }
  576. private void Btn_SettingFile_Click(object sender, EventArgs e)//SettingFile 클릭 함수, SettingFile 파일 생성
  577. {
  578. Creating_Setting_File CSF = new Creating_Setting_File();
  579. CSF.Create_Setting_Point_File();
  580. }
  581. private void AllValueCheck_btn_Click(object sender, EventArgs e)//일괄 출력 클릭 함수
  582. {
  583. string[] sArray = File.ReadAllLines("TagSetFile.csv", Encoding.Default);
  584. LogTxt.AppendText("*** 현재 시간 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
  585. LFC.Log("*** 현재 시간 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
  586. try
  587. {
  588. for (int i = 0; i < sArray.Length; i++)
  589. {
  590. string[] tmp = sArray[i].Split(','); // tmp[0] = index, tmp[1] = Tag명.
  591. LogTxt.AppendText('"' + tmp[1] + '"' + " 의 값 : " + iCosSocket.IcosGetTagValue(tmp[1]) + Environment.NewLine);
  592. LFC.Log('"' + tmp[1] + '"' + " 의 값 : " + iCosSocket.IcosGetTagValue(tmp[1]));
  593. }
  594. LogTxt.AppendText("**********************************" + Environment.NewLine);
  595. LFC.Log("**********************************" + Environment.NewLine);
  596. }
  597. catch (Exception er)
  598. {
  599. MessageBox.Show("오류 발생");
  600. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 오류 발생 : " + er);
  601. LFC.Log("오류 발생 = " + er);
  602. }
  603. LogTxt.Select(LogTxt.Text.Length, 0);
  604. LogTxt.ScrollToCaret();
  605. }
  606. private void RequestValue_btn_Click(object sender, EventArgs e) //특정 값 출력 함수
  607. {
  608. if (RequestValue.Text != "")
  609. {
  610. LogTxt.AppendText("*** 현재 시간 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
  611. LFC.Log("*** 현재 시간 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
  612. try
  613. {
  614. string tmp = RequestValue.Text; //태그값
  615. LogTxt.AppendText('"' + tmp + '"' + " 의 값 : " + iCosSocket.IcosGetTagValue(tmp) + Environment.NewLine);
  616. LogTxt.AppendText("**********************************" + Environment.NewLine);
  617. LFC.Log(tmp + " 의 값 : " + iCosSocket.IcosGetTagValue(tmp) + Environment.NewLine);
  618. LFC.Log("**********************************" + Environment.NewLine);
  619. }
  620. catch (Exception er)
  621. {
  622. MessageBox.Show("오류 발생");
  623. LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 오류 발생 : " + er);
  624. LFC.Log("오류 발생 : " + er);
  625. }
  626. }
  627. else
  628. {
  629. MessageBox.Show("확인 값이 없습니다.");
  630. return;
  631. }
  632. LogTxt.Select(LogTxt.Text.Length, 0);
  633. LogTxt.ScrollToCaret();
  634. }
  635. private void RequestValue_KeyPress(object sender, KeyPressEventArgs e)
  636. {
  637. if (e.KeyChar == 8) //백스페이스할때, 데이터 삭제
  638. {
  639. if (RequestValue.Text.Length != 0)
  640. {
  641. RequestValue.Text = RequestValue.Text.Substring(0, RequestValue.Text.Length - 1);
  642. RequestValue.Select(RequestValue.Text.Length, 0);
  643. e.Handled = true;
  644. }
  645. else
  646. {
  647. e.Handled = true;
  648. }
  649. }
  650. else
  651. {
  652. RequestValue.Select(RequestValue.Text.Length, 0); //현재 데이터 뒤로 포커스 이동
  653. }
  654. }
  655. private void RequestValue_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
  656. {
  657. if (e.Control && e.KeyCode == Keys.A) //Ctrl + A 동작
  658. {
  659. ((TextBox)sender).SelectAll();
  660. }
  661. if (e.Control && e.KeyCode == Keys.C) //Ctrl + C 동작
  662. {
  663. ((TextBox)sender).Copy();
  664. }
  665. if (e.Control && e.KeyCode == Keys.V) //Ctrl + V 동작
  666. {
  667. ((TextBox)sender).Paste();
  668. }
  669. if (e.Control && e.KeyCode == Keys.X) //Ctrl + X 동작
  670. {
  671. ((TextBox)sender).Cut();
  672. }
  673. }
  674. private void DBAddressTxt_TextChanged(object sender, EventArgs e)
  675. {
  676. }
  677. private void DBNameTxt_TextChanged(object sender, EventArgs e)
  678. {
  679. }
  680. }
  681. }