FormField.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Xml;
  9. using System.IO;
  10. using System.Collections;
  11. namespace FPER {
  12. public partial class FormField : Form
  13. { // field form class
  14. public XMLReader xmlR = null;
  15. public List<XMLField> xField = null;
  16. public Dev_Type_Set DataType_Set = null;
  17. List<Button> LButton = new List<Button>();
  18. public ArrayList lActLoop = new ArrayList();
  19. Graphics g;
  20. int iGetDataIndex = 0;
  21. // cyim 2013.7.31 타화면전환시 화면갱신이 늦게 되는 문제
  22. // 현장도면에서 곧바로 설비연동 화면으로 진입시 화면갱신이 늦게되는 문제
  23. // 근본적인 문제는 현장도면에서 정보를 요청하는것이 있는 경우에 (버튼 연타도 마찬가지) 데몬이 늦게 응답해주어서 발생되는 문제이다.
  24. // 즉, 응답오기전까지는 누르지 못하게 막음. 단, 화면전환이후 화면갱신이 느리게 될수있는 여지가 있다
  25. bool CommDaemonAck_Received = false;
  26. public FormField(List<XMLField> xField, Dev_Type_Set DataType_Set)
  27. {
  28. InitializeComponent();
  29. this.xField = xField;
  30. this.DataType_Set = DataType_Set;
  31. // this.SetLTypeImage();
  32. g = panel1.CreateGraphics();
  33. g.Clear(SystemColors.ControlLight);
  34. }
  35. MDIParent mdi = null;
  36. private void FormField_Load(object sender, EventArgs e)
  37. {
  38. // cyim 2013.8.1 : 더블버퍼링 적용
  39. SetStyle(ControlStyles.UserPaint, true);
  40. //this.UpdateStyles();
  41. SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  42. //this.UpdateStyles();
  43. SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  44. this.UpdateStyles();
  45. // form load event
  46. this.mdi = (MDIParent)this.MdiParent;
  47. this.mdi.SelectMenuIndex = 7;
  48. this.init();
  49. }
  50. private void init()
  51. { // init form data
  52. if (xField != null)
  53. {
  54. // //Util.UDebugMessage("xField.Length = " + xField.Count.ToString(), 0, 0);
  55. this.comboBox1.Items.Clear();
  56. foreach (XMLField field in xField)
  57. {
  58. this.comboBox1.Items.Add(field.Name);
  59. }
  60. if (xField.Count > 0)
  61. {
  62. this.comboBox1.SelectedIndex = 0;
  63. }
  64. }
  65. }
  66. void GetAllDataListForce()
  67. { // ActiveLoop 리스트의 데이터를 읽는다. (에러 체크 하지 않음.)
  68. //foreach (Loop loop in this.LActiveLoop) {
  69. // this.getData(loop.boardID, loop.loopNo);
  70. // System.Threading.Thread.Sleep(50);
  71. //}
  72. int iBoardID = 0;
  73. int iLoopNo = 0;
  74. for (int iLoop = 0; iLoop < lActLoop.Count; iLoop++)
  75. {
  76. iBoardID = Convert.ToInt16(lActLoop[iLoop]) / 10;
  77. iLoopNo = Convert.ToInt16(lActLoop[iLoop]) % 10;
  78. this.getData(iBoardID, iLoopNo);
  79. System.Threading.Thread.Sleep(200);
  80. }
  81. // iGetDataIndex = 0;
  82. }
  83. void GetDataList()
  84. {
  85. if (lActLoop.Count > 0)
  86. {
  87. int iBoardID = Convert.ToInt16(lActLoop[iGetDataIndex]) / 10;
  88. int iLoopNo = Convert.ToInt16(lActLoop[iGetDataIndex]) % 10;
  89. this.getData(iBoardID, iLoopNo);
  90. System.Threading.Thread.Sleep(200);
  91. iGetDataIndex++;
  92. if (iGetDataIndex >= lActLoop.Count)
  93. {
  94. iGetDataIndex = 0;
  95. }
  96. }
  97. }
  98. void GetAllDataList()
  99. { // ActiveLoop 리스트의 데이터를 통신상 에러를 체크 하면서 읽음.
  100. /*
  101. foreach(Loop loop in this.LActiveLoop){
  102. if (loop.calltime > 0 && Environment.TickCount - loop.calltime > 5000) {
  103. this.SetComunicationError(loop.boardID,loop.loopNo,-4);// time out
  104. }
  105. bool get = this.getData(loop.boardID, loop.loopNo);
  106. if (get == false) {
  107. this.SetComunicationError(loop.boardID, loop.loopNo, -3);// deamon error
  108. }
  109. if (loop.calltime < 0) {
  110. loop.calltime = Environment.TickCount;
  111. }
  112. System.Threading.Thread.Sleep(200);
  113. }
  114. */
  115. int iBoardID = 0;
  116. int iLoopNo = 0;
  117. for (int iLoop = 0; iLoop < lActLoop.Count; iLoop++)
  118. {
  119. iBoardID = Convert.ToInt16(lActLoop[iLoop]) / 10;
  120. iLoopNo = Convert.ToInt16(lActLoop[iLoop]) % 10;
  121. //if (loop.calltime > 0 && Environment.TickCount - loop.calltime > 5000)
  122. //{
  123. // this.SetComunicationError(iBoardID, iLoopNo, -4);// time out
  124. //}
  125. bool get = this.getData(iBoardID, iLoopNo);
  126. if (get == false)
  127. {
  128. this.SetComunicationError(iBoardID, iLoopNo, -3);// deamon error
  129. }
  130. //if (loop.calltime < 0)
  131. //{
  132. // loop.calltime = Environment.TickCount;
  133. //}
  134. System.Threading.Thread.Sleep(200);
  135. }
  136. }
  137. void SetComunicationError(int boardID, int loopNo, int errorCode)
  138. {// set error image
  139. // int index = 0;
  140. foreach (XMLDevice dev in this.xField[this.comboBox1.SelectedIndex].LDevice)
  141. {
  142. if (dev.Board_ID == boardID && dev.Loop_No == loopNo)
  143. {
  144. UpdateDev(dev, errorCode);
  145. }
  146. // index++;
  147. }
  148. }
  149. /*
  150. Loop GetLoop(int boardID, int loopNo) { // set upload loop
  151. Loop ret = null;
  152. foreach (Loop loop in this.LActiveLoop) {
  153. if (loop.Match(boardID, loopNo)) {
  154. ret = loop;
  155. break;
  156. }
  157. }
  158. return ret;
  159. }
  160. */
  161. bool getData(int BoardID, int Loop)
  162. {
  163. // cyim 2013.7.31 타화면전환시 화면갱신이 늦게 되는 문제
  164. if (CommDaemonAck_Received == true)
  165. {
  166. return false;
  167. }
  168. else
  169. {
  170. CommDaemonAck_Received = true;
  171. // loop data upload function
  172. bool ret = false;
  173. MDIParent mdi = (MDIParent)this.MdiParent;
  174. dCommandResponse d = new dCommandResponse(UpdateData);
  175. CmdInfo cmd = new CmdInfo(prt_cmd_define.read_repeater_all, mdi.myReceiverID, 1, Loop, BoardID, d);
  176. ret = mdi.ui.runCommand(cmd);
  177. return ret;
  178. }
  179. }
  180. // 현장도면에서도 차단표시를 합니다.
  181. // frmControlMode.cs 에서 사용하는 함수명은 동일하지만 파라미터가 틀립니다.
  182. // frmControlMode.cs 에서는 중계기 단위로 체크하지만 , FormField.cs 에서는 디바이스별로 체크해야 합니다
  183. // cyim 2013.10.2 : 차단 표시
  184. private bool Repeater_GetData_Circuit_CutInfo(RepeaterDeviceTypeInfo repinfo, XMLDevice dev)
  185. {
  186. if (dev == null) return false;
  187. // 입력인지 출력인지 구분
  188. if (dev.Inout_Type == "I")
  189. {
  190. if (repinfo.inDeviceTypeInfos[dev.Device_ID - 1] == null)
  191. return false;
  192. else
  193. return repinfo.inDeviceTypeInfos[dev.Device_ID - 1].CutFlag;
  194. }
  195. else
  196. {
  197. if (repinfo.outDeviceTypeInfos[dev.Device_ID - 1] == null)
  198. return false;
  199. else
  200. return repinfo.outDeviceTypeInfos[dev.Device_ID - 1].CutFlag;
  201. }
  202. }
  203. public void UpdateData(CmdInfo cmd)
  204. {// device data update
  205. try
  206. {
  207. // MDIParent mdi = (MDIParent)this.MdiParent;
  208. //Loop loop = this.GetLoop(cmd.boardNo, cmd.loopNo);
  209. //if (loop != null) {
  210. // loop.calltime = -1;
  211. //}
  212. // cyim 2013.7.31 타화면전환시 화면갱신이 늦게 되는 문제
  213. CommDaemonAck_Received = false;
  214. //try {
  215. if (cmd.ResponseData is RCVData_NACK)
  216. {
  217. #if _DEBUG
  218. //Util.UDebugMessage("UpdateData RCVData_NACK", 0, 0);
  219. #endif
  220. this.SetComunicationError(cmd.boardNo, cmd.loopNo, -2);// nack error : board error
  221. }
  222. if (cmd.ResponseData is RCVData_ReadRepeaterPointAll)
  223. {
  224. RCVData_ReadRepeaterPointAll ResponseData = (RCVData_ReadRepeaterPointAll)cmd.ResponseData;
  225. RepeaterData[] data = ResponseData.Data;
  226. if (cmd.Command == prt_cmd_define.read_repeater_all || cmd.ResCommand == prt_res_define.read_repeater_all)
  227. {
  228. /*if (savBoardID == cmd.boardNo && savLoop == cmd.loopNo) */
  229. {
  230. ReceiverTypeInfo Receiverinfo = mdi.ui.MyReceiverTypeInfo; //수신기설정
  231. BoardTypeInfo brdinfo = Receiverinfo.Get_RepeaterType(ResponseData.TBD_ID); //통신보드savBoardID의 loop0의 설정값
  232. RepeaterDeviceTypeInfo[] repinfo;
  233. RepeaterPointUnit[] repdata;
  234. // cyim 2016.10.31 : 계통정보는 0,1,2,3 으로 변경
  235. if (ResponseData.Repeater_loop == 0)
  236. {
  237. repinfo = brdinfo.Loop0_RepeaterType; //통신보드 + Loop0 + 127개 중계기 설정값
  238. repdata = brdinfo.Loop0_RepeaterUnit_Data; //127개 중계기 데이터
  239. }
  240. else if (ResponseData.Repeater_loop == 1)
  241. {
  242. repinfo = brdinfo.Loop1_RepeaterType; //통신보드 + Loop1 + 127개 중계기 설정값
  243. repdata = brdinfo.Loop1_RepeaterUnit_Data; //127개 중계기 데이터
  244. }
  245. else if (ResponseData.Repeater_loop == 2)
  246. {
  247. repinfo = brdinfo.Loop2_RepeaterType; //통신보드 + Loop2 + 127개 중계기 설정값
  248. repdata = brdinfo.Loop2_RepeaterUnit_Data; //127개 중계기 데이터
  249. }
  250. else if (ResponseData.Repeater_loop == 3)
  251. {
  252. repinfo = brdinfo.Loop3_RepeaterType; //통신보드 + Loop3 + 127개 중계기 설정값
  253. repdata = brdinfo.Loop3_RepeaterUnit_Data; //127개 중계기 데이터
  254. }
  255. else
  256. {
  257. repinfo = null;
  258. repdata = null;
  259. }
  260. // int index = 0;
  261. foreach (XMLDevice dev in this.xField[this.comboBox1.SelectedIndex].LDevice)
  262. {
  263. if (dev.DevID != "")
  264. {
  265. int a = dev.Device_ID;
  266. if (dev.Board_ID == cmd.boardNo && dev.Loop_No == cmd.loopNo)
  267. {
  268. int status = -100;// unkonun error
  269. if (repdata[dev.Repeater_ID - 1].RepeaterErr)
  270. {
  271. status = -1;// repeater comm error
  272. }
  273. // cyim 2013.10.2 : 차단 표시 (중계기 차단)
  274. else if (repinfo[dev.Repeater_ID - 1].CutFlag == true)
  275. {
  276. status = 4; // 차단 상태값
  277. }
  278. // cyim 2013.10.2 : 차단 표시 (회로 차단)
  279. else if (Repeater_GetData_Circuit_CutInfo(repinfo[dev.Repeater_ID - 1], dev) == true)
  280. {
  281. status = 4; // 차단 상태값
  282. }
  283. else if (dev.Inout_Type == "I")
  284. {
  285. switch (dev.Device_ID)
  286. {
  287. case 1:
  288. status = data[dev.Repeater_ID - 1].Repeater_state_1;
  289. break;
  290. case 2:
  291. status = data[dev.Repeater_ID - 1].Repeater_state_2;
  292. break;
  293. case 3:
  294. status = data[dev.Repeater_ID - 1].Repeater_state_3;
  295. break;
  296. case 4:
  297. status = data[dev.Repeater_ID - 1].Repeater_state_4;
  298. break;
  299. }
  300. }
  301. else
  302. {
  303. switch (dev.Device_ID)
  304. {
  305. case 1:
  306. status = data[dev.Repeater_ID - 1].Repeater_output_1_W ? 0 : 1;
  307. break;
  308. case 2:
  309. status = data[dev.Repeater_ID - 1].Repeater_output_2_W ? 0 : 1;
  310. break;
  311. case 3:
  312. status = data[dev.Repeater_ID - 1].Repeater_output_3_W ? 0 : 1;
  313. break;
  314. case 4:
  315. status = data[dev.Repeater_ID - 1].Repeater_output_4_W ? 0 : 1;
  316. break;
  317. }
  318. }
  319. //if(status != -1) {
  320. //this.UpdateDevImage(index, status, dev.Device_Type);
  321. UpdateDev(dev, status);
  322. //}
  323. }
  324. }
  325. // index++;
  326. }
  327. //for (int repeaterNo = 0; repeaterNo < data.Length; repeaterNo++) {
  328. // RepeaterPointUnit newdata = new RepeaterPointUnit(repeaterNo + 1, data[repeaterNo]);
  329. // //데이터저장
  330. // repdata[repeaterNo] = newdata;
  331. // //각 셀에 중계기 데이터 표시
  332. // //GRIDCELL[repeaterNo].Set_DeviceUnit(newdata);
  333. //}
  334. //선택된 셀의 데이터를 dataGridView2에 표시한다..
  335. //dataGridView1_SelectionChanged(dataGridView1, System.EventArgs.Empty);
  336. }
  337. }
  338. }
  339. //}
  340. //catch (Exception ex) {
  341. // MessageBox.Show(string.Format("[{0}]\r\n{1}", ex.Message, ex.Source), Application.ProductName);
  342. //}
  343. //finally {
  344. // //버튼 비활성 해제
  345. // //button_end(true);
  346. //}
  347. ////정상응답처리-------------------------------------------끝
  348. }
  349. catch (Exception ex)
  350. {
  351. Util.UErrorMessage(ex, 0, 0);
  352. }
  353. }
  354. void ClearActiveLoop()
  355. {
  356. lActLoop.Clear();
  357. }
  358. void AddActiveLoop(int iBoardID, int iLoopNo)
  359. {
  360. // cyim 2013.7.3 아이콘깜빡임 문제 수정
  361. // 디버깅 결과, NACK 가 들어오면서 화면이 물음표로 전환되는 것이 문제로 판단됩니다.
  362. // NACK 를 받는 이유는 FieldSetting.xml 에 회로번호가 널값이라면 통신보드 0으로 인식하여 이에 해당하는 패킷을 생성 및 요청하게 되므로
  363. // NACK 가 들어올 수 밖에 없습니다. (당연히 물리적으로 통신보드 아이디값 0 은 존재하지 않습니다)
  364. // 즉, 다시 물음표로 보였다가 다시 정상동작 아이콘으로 반복 표시되는 현상이 발생하는 것입니다.
  365. // 회로번호 널값에 의한 통신보드 0 값은 통신요청하지 않도록 수정합니다
  366. if (iBoardID == 0) return;
  367. int iConvert = iBoardID * 10 + iLoopNo;
  368. if (lActLoop.Contains(iConvert) == false)
  369. {
  370. lActLoop.Add(iConvert);
  371. }
  372. }
  373. /*
  374. List<Loop> LActiveLoop = new List<Loop>();
  375. void ClearLActiveLoop() {// clear update loop
  376. this.LActiveLoop.Clear();
  377. }
  378. void AddLActiveLoop(int boardID, int loopNo) { // add update loop
  379. bool add = true;
  380. foreach (Loop loop in LActiveLoop) {
  381. if (loop.Match(boardID, loopNo)) {
  382. add = false;
  383. break;
  384. }
  385. }
  386. if (add) {
  387. this.LActiveLoop.Add(new Loop(boardID, loopNo));
  388. }
  389. }
  390. class Loop { // loop class
  391. public int boardID = -1;
  392. public int loopNo = -1;
  393. public int calltime = -1;
  394. public Loop(int boardID , int loopNo) {
  395. this.boardID = boardID;
  396. this.loopNo = loopNo;
  397. }
  398. public bool Match(int boardID, int loopNo) { // check same loop
  399. bool ret = false;
  400. if (this.boardID == boardID && this.loopNo == loopNo) {
  401. ret = true;
  402. }
  403. return ret;
  404. }
  405. }
  406. */
  407. Image GetTypeImage(string imgType)
  408. { // get base type image form list
  409. Image ret = null;
  410. ret = DataType_Set.GetDevImage(imgType);
  411. return ret;
  412. }
  413. int selectedFieldIndex = -1;
  414. private void SetField(int fieldIndex)
  415. {// set base filed image
  416. try
  417. {
  418. // cyim 2013.3.15 화면깜빡임 문제 수정 -> cyim 2013.7.3 원복함 : 다른페이지 전환시 팝업창이 남아있다
  419. // 아래의 코드가 제일 문제이다. 아래 코드가 적용되면 당연히 디바이스 팝업창이 사라지면서 Paint 함수를 중복 호출이 되어버린다..
  420. if (formDevice != null && formDevice.Created)
  421. {
  422. this.formDevice.Visible = false;
  423. }
  424. if (this.selectedFieldIndex != fieldIndex && xField != null)
  425. // if (xField != null)
  426. {
  427. #if _DEBUG
  428. //Util.UDebugMessage(string.Format("SetField fieldIndex = {0} , xField.Count= {1}, TickCount = {2}", fieldIndex, xField.Count, Environment.TickCount), 0, 100);
  429. #endif
  430. this.selectedFieldIndex = fieldIndex;
  431. if (xField.Count > fieldIndex && xField[fieldIndex] != null)
  432. { // XML Field 가 생성되었고, XML Field의 수가 FieldIndex보다 큰 경우 수행..
  433. this.timer1.Stop();
  434. // 통신을 수행할 통신보드/루프 리스트를 초기화 한다.
  435. //this.ClearLActiveLoop();
  436. ClearActiveLoop();
  437. // cyim 2013.3.15 화면깜빡임 문제 수정
  438. // 그래픽 화면을 지운다.
  439. //g.Clear(SystemColors.Control);
  440. #if _DEBUG
  441. //Util.UDebugMessage(string.Format("+SetField SetBaseImage TickCount = {0}", Environment.TickCount), 0, 100);
  442. #endif
  443. XMLField field = xField[fieldIndex]; // XML Field 재 생성
  444. this.SetBaseImage(field.imagePath); // 배경 이미지를 그린다.
  445. #if _DEBUG
  446. //Util.UDebugMessage(string.Format("-SetField UpdateXMLFieldData TickCount = {0}", Environment.TickCount), 0, 100);
  447. #endif
  448. try
  449. {
  450. for (int i = 0; i < field.Count_Dev; i++)
  451. { // FieldIndex에 해당하는 포인트 데이터갯수만큼 루프를 돈다.
  452. XMLDevice dev = field.LDevice[i]; //
  453. //this.AddLActiveLoop(dev.Board_ID, dev.Loop_No); // 현재 화면에 해당하는 BoardID와 LoopNO를 리스트로 구성한다.
  454. AddActiveLoop(dev.Board_ID, dev.Loop_No);
  455. this.xField[fieldIndex].LDevice[i].Image = DataType_Set.GetDevImagePath(xField[fieldIndex].LDevice[i].DevIconID);
  456. this.SetDevImage(xField[fieldIndex].LDevice[i]); // 디바이스 이미지를 화면에 표출한다.
  457. }
  458. for (int i = 0; i < xField[fieldIndex].LButton.Count; i++)
  459. {
  460. SetBtnImage(xField[fieldIndex].LButton[i]);
  461. }
  462. this.GetAllDataListForce(); // Active Loop 내의 데이터를 (에러체크 하지 않고) 읽는다.
  463. // 화면의 초기 업데이트를 위해서 읽는 것 같다.
  464. // 데이터 읽기 Index를 0 으로 리셋한다.
  465. iGetDataIndex = 0;
  466. #if _DEBUG
  467. //Util.UDebugMessage(string.Format("-SetField XMLDevice TickCount = {0}", Environment.TickCount), 0, 100);
  468. #endif
  469. }
  470. catch (Exception ex)
  471. {
  472. Util.UErrorMessage(ex, 0, 0);
  473. }
  474. #if _DEBUG
  475. //Util.UDebugMessage(string.Format("+SetField SetButtonImage TickCount = {0}", Environment.TickCount), 0, 100);
  476. #endif
  477. // foreach (XMLButton button in xField[fieldIndex].LButton) {
  478. // this.SetButtonImage(button);
  479. // }
  480. #if _DEBUG
  481. //Util.UDebugMessage(string.Format("+SetField SetButtonImage TickCount = {0}", Environment.TickCount), 0, 100);
  482. #endif
  483. this.timer1.Start();
  484. } // if (xField.Count > fieldIndex && xField[fieldIndex] != null)
  485. } // if (xField != null)
  486. }
  487. catch (Exception ex)
  488. {
  489. Util.UErrorMessage(ex, 0, 0);
  490. }
  491. }
  492. public void SetBaseImage(string img_path)
  493. {// set filed base image
  494. //panel1.BackgroundImage = Image.FromFile(img_path);
  495. //g.DrawImage(Image.FromFile(img_path), 0, 0);
  496. // cyim 2013.7.3 해상도에 따른 이미지 크기가 변경되는 문제 수정 (상위 주석처리함)
  497. Image Temp = Image.FromFile(img_path);
  498. g.DrawImage(Temp, 0, 0, Temp.Width, Temp.Height);
  499. }
  500. public void UpdateDev(XMLDevice device, int status)
  501. {
  502. if (device.Image == "")
  503. {
  504. #if _DEBUG
  505. //Util.UDebugMessage(string.Format("SetDevImage icon_path == null "), 0, 0);
  506. #endif
  507. }
  508. else
  509. {
  510. // Graphics g = panel1.CreateGraphics();
  511. Bitmap m_Dev = new Bitmap(GetTypeImage(device.DevIconID));
  512. g.DrawImage(m_Dev, device.Xposition, device.Yposition, m_Dev.Width, m_Dev.Height); // cyim 2013.7.3 해상도에 따른 이미지 크기가 변경되는 문제 수정
  513. string sPath = System.IO.Path.GetDirectoryName(device.Image);
  514. switch (status)
  515. {
  516. case 0: // 감지
  517. if (device.dev_type == "IC") // 설비 입력
  518. {
  519. Bitmap m_Detect = new Bitmap(Path.Combine(sPath, "설비동작.png")); // 파랑 ㅁ
  520. g.DrawImage(m_Detect, device.Xposition, device.Yposition, m_Detect.Width, m_Detect.Height); // cyim 2013.7.3 해상도에 따른 이미지 크기가 변경되는 문제 수정
  521. }
  522. else if ((device.dev_type == "IA") || (device.dev_type == "IB"))
  523. {
  524. Bitmap m_Detect = new Bitmap(Path.Combine(sPath, "화재감지.png")); // 빨강 ㅁ
  525. g.DrawImage(m_Detect, device.Xposition, device.Yposition, m_Detect.Width, m_Detect.Height);// cyim 2013.7.3 해상도에 따른 이미지 크기가 변경되는 문제 수정
  526. }
  527. break;
  528. case 1: // 정상
  529. break;
  530. case 3: // 단선
  531. Bitmap m_Broken = new Bitmap(Path.Combine(sPath, "Error.png"));// X
  532. g.DrawImage(m_Broken, device.Xposition, device.Yposition, m_Broken.Width, m_Broken.Height); // cyim 2013.7.3 해상도에 따른 이미지 크기가 변경되는 문제 수정
  533. break;
  534. // cyim 2013.10.2 : 차단 표시 (회로 차단)
  535. case 4:
  536. Bitmap m_Cut = new Bitmap(Path.Combine(sPath, "차단.png")); // =
  537. g.DrawImage(m_Cut, device.Xposition, device.Yposition, m_Cut.Width, m_Cut.Height);
  538. break;
  539. default: // 중계기 이상 (status = -1)
  540. Bitmap m_Odd = new Bitmap(Path.Combine(sPath, "중계기이상.png")); // ?
  541. g.DrawImage(m_Odd, device.Xposition, device.Yposition, m_Odd.Width, m_Odd.Height); // cyim 2013.7.3 해상도에 따른 이미지 크기가 변경되는 문제 수정
  542. break;
  543. }
  544. device.status = status;
  545. // g.Dispose();
  546. }
  547. }
  548. public void SetBtnImage(XMLButton button)
  549. {
  550. // Graphics g = panel1.CreateGraphics();
  551. Bitmap m_Dev = new Bitmap(button.ImagePath);
  552. g.DrawImage(m_Dev, button.Xposition, button.Yposition, m_Dev.Width, m_Dev.Height);// cyim 2013.7.3 해상도에 따른 이미지 크기가 변경되는 문제 수정
  553. // g.Dispose();
  554. }
  555. /*
  556. public void SetButtonImage(XMLButton button) { // set button image to field
  557. #if _DEBUG
  558. //Util.UDebugMessage(string.Format("+SetButtonImage "), 0, 0);
  559. #endif
  560. Button btnMove = new Button();
  561. this.LButton.Add(btnMove);
  562. btnMove.Parent = this.panel1;
  563. btnMove.Location = new Point(button.xposition, button.yposition);
  564. btnMove.FlatStyle = FlatStyle.Flat;
  565. if (button.imagePath == "") {
  566. #if _DEBUG
  567. //Util.UDebugMessage(string.Format("SetButtonImage imgPath == null "), 0, 0);
  568. #endif
  569. }
  570. else {
  571. //btnMove.Width = loadicon.Width;
  572. if (button.name != "") {
  573. //Image loadicon = new Bitmap(new Bitmap(button.imagePath), button.width, button.height - 20);
  574. //btnMove.Image = loadicon;
  575. btnMove.Image = new Bitmap(button.imagePath);
  576. //btnMove.ImageAlign = ContentAlignment.TopCenter;
  577. //btnMove.TextAlign = ContentAlignment.BottomCenter;
  578. }
  579. else {
  580. //Image loadicon = new Bitmap(new Bitmap(button.imagePath), button.width, button.height);
  581. //btnMove.Image = loadicon;
  582. btnMove.Image = new Bitmap(button.imagePath);
  583. //btnMove.ImageAlign = ContentAlignment.MiddleCenter;
  584. }
  585. }
  586. //btnMove.Name = button.name;
  587. //btnMove.Padding = new Padding(3);
  588. //btnMove.BackColor = Color.Transparent;
  589. btnMove.Tag = button;
  590. //btnMove.Text = button.name;
  591. btnMove.Width = button.width + 5;
  592. btnMove.Height = button.height + 5;
  593. btnMove.MouseDown += new MouseEventHandler(BtnMouseClick);
  594. }
  595. */
  596. /*
  597. void BtnMouseClick(object sender, MouseEventArgs e) { // field button click event
  598. #if _DEBUG
  599. //Util.UDebugMessage("BtnMouseClick", 0, 0);
  600. #endif
  601. if (e.Button == MouseButtons.Left) {
  602. Button btnM = (Button)sender;
  603. XMLButton button = (XMLButton)btnM.Tag;
  604. this.comboBox1.SelectedIndex = button.jumpField;
  605. }
  606. }
  607. */
  608. public void SetDevImage(XMLDevice device)
  609. { // set one device image to filed
  610. if (device.DevIconID == "")
  611. {
  612. #if _DEBUG
  613. //Util.UDebugMessage(string.Format("SetDevImage icon_path == null "), 0, 0);
  614. #endif
  615. }
  616. else
  617. {
  618. // Graphics g = panel1.CreateGraphics();
  619. Bitmap m_Dev = new Bitmap(GetTypeImage(device.DevIconID));
  620. g.DrawImage(m_Dev, device.Xposition, device.Yposition, m_Dev.Width, m_Dev.Height); // cyim 2013.7.3 해상도에 따른 이미지 크기가 변경되는 문제 수정
  621. // g.Dispose();
  622. }
  623. }
  624. FormDevice formDevice = null;
  625. private void btnWinClose_Click(object sender, EventArgs e)
  626. { // filed close event
  627. try
  628. {
  629. this.Close();
  630. }
  631. catch (Exception ex)
  632. {
  633. Util.UErrorMessage(ex, 0, 0);
  634. }
  635. }
  636. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  637. { // set select list
  638. this.SetField(this.comboBox1.SelectedIndex);
  639. }
  640. public void JumpField(int id)
  641. {
  642. // cyim 2015.7.30 화재발생시 점프할 페이지 지정 루틴에 예외처리 추가
  643. if (this.comboBox1.Items.Count <= 0)
  644. return;
  645. // filed change using index
  646. // lch 13.07.19 - 속도개선 작업
  647. if (this.comboBox1.InvokeRequired)
  648. {
  649. dCommandFuctionCall d = new dCommandFuctionCall(JumpField);
  650. this.comboBox1.Invoke(d, new object[] { id });
  651. }
  652. else
  653. {
  654. #if _DEBUG
  655. //Util.UDebugMessage(string.Format("JumpField JUMP_FIELD_ID = {0}", id), 0, 0);
  656. #endif
  657. for (int i = 0; i < this.xField.Count; i++)
  658. {
  659. if (id == this.xField[i].FieldID)
  660. {
  661. this.comboBox1.SelectedIndex = i;
  662. //this.SetField(i);
  663. break;
  664. }
  665. }
  666. }
  667. }
  668. private void timer1_Tick(object sender, EventArgs e)
  669. { // data update tmer
  670. //this.GetAllDataList();
  671. GetDataList();
  672. }
  673. private void FormField_Activated(object sender, EventArgs e)
  674. { // form active event
  675. try
  676. {
  677. this.mdi.SelectMenuIndex = 7;
  678. }
  679. catch (Exception ex)
  680. {
  681. Util.UErrorMessage(ex, 0, 0);
  682. }
  683. }
  684. void FormField_Disposed(object sender, System.EventArgs e)
  685. { // form dispose event
  686. try
  687. {
  688. this.mdi.SelectMenuIndex = 0;
  689. g.Dispose();
  690. }
  691. catch (Exception ex)
  692. {
  693. Util.UErrorMessage(ex, 0, 0);
  694. }
  695. }
  696. private void FormField_FormClosing(object sender, FormClosingEventArgs e)
  697. { // form close event
  698. try
  699. {
  700. if (formDevice != null && formDevice.Created)
  701. {
  702. this.formDevice.Close();
  703. }
  704. }
  705. catch (Exception ex)
  706. {
  707. Util.UErrorMessage(ex, 0, 0);
  708. }
  709. }
  710. // 특정 상황에서, 화면을 다시 그린다.
  711. private void panel1_Paint(object sender, PaintEventArgs e)
  712. {
  713. selectedFieldIndex = -1;
  714. SetField(comboBox1.SelectedIndex);
  715. }
  716. // 화면에서 디바이스 아이콘을 선택하면 상태정보를 출력한다
  717. private void panel1_MouseDown(object sender, MouseEventArgs e)
  718. {
  719. // 판넬 마우스 다운 이벤트
  720. // 위치 확인하여, 해당 디바이스 메시지를 띄운다.
  721. int i;
  722. // 마우스 위치를 확인.
  723. int iX = e.Location.X;
  724. int iY = e.Location.Y;
  725. // 디바이스의 위치
  726. int iXX;
  727. int iYY;
  728. // cyim
  729. // 배경 화면에는 2가지 타입의 아이콘이 존재한다
  730. // XMLButton : 버튼 아이콘으로서 페이지간 이동하도록 링크가 설정되어 있다.
  731. // XMLDevice : 디바이스 아이콘으로서 장치 정보를 나타낸다.
  732. // 마우스 포인트 정보를 이용하여 버튼을 추출하고, 그 버튼의 점프 페이지 정보를 확인한다.
  733. for (i = 0; i < xField[this.comboBox1.SelectedIndex].LButton.Count; i++)
  734. {
  735. iXX = xField[this.comboBox1.SelectedIndex].LButton[i].Xposition;
  736. iYY = xField[this.comboBox1.SelectedIndex].LButton[i].Yposition;
  737. if ((iX >= iXX) && (iX <= (iXX + xField[this.comboBox1.SelectedIndex].LButton[i].width)))
  738. {
  739. if ((iY >= iYY) && (iY <= (iYY + xField[this.comboBox1.SelectedIndex].LButton[i].height)))
  740. {
  741. // 화면 상단의 콤보박스 셋팅
  742. // 인덱스가 변경되는 순간 해당 페이지로 이동한다 -> comboBox1_SelectedIndexChanged
  743. comboBox1.SelectedIndex = xField[this.comboBox1.SelectedIndex].LButton[i].jumpField;
  744. // cyim 2013.3.15 화면깜빡임 문제 수정
  745. // 루프문 최소화
  746. break;
  747. }
  748. }
  749. }
  750. // 마우스 포인트 정보를 이용하여 디바이스를 추출하고, 그 디바이스의 정보를 확인한다.
  751. for (i = 0; i < xField[this.comboBox1.SelectedIndex].Count_Dev; i++)
  752. {
  753. iXX = xField[this.comboBox1.SelectedIndex].LDevice[i].Xposition;
  754. iYY = xField[this.comboBox1.SelectedIndex].LDevice[i].Yposition;
  755. if ((iX >= iXX) && (iX <= (iXX + 24)))
  756. {
  757. if ((iY >= iYY) && (iY <= (iYY + 24)))
  758. {
  759. // DeviceForm 의 내용을 표시한다.
  760. // 이미 할당되면 적용안됨, 새로운 폼이라면 메모리 할당
  761. if (formDevice == null)
  762. {
  763. formDevice = new FormDevice(this.mdi);
  764. formDevice.Owner = this;
  765. formDevice.Visible = false;
  766. formDevice.Show();// 데이타를 아직 표시하지 않았으므로 표시는 하지 않는다.
  767. }
  768. // 표시 불가
  769. formDevice.Visible = false;
  770. // 아이디
  771. formDevice.devID = this.xField[this.comboBox1.SelectedIndex].LDevice[i].DevID;
  772. // 폼헤더 상단 문구
  773. formDevice.Text = this.xField[this.comboBox1.SelectedIndex].LDevice[i].dev_name;
  774. // 디바이스 정보
  775. formDevice.SetDeviceInformText(string.Format(
  776. "장치 번호 : " + this.xField[this.comboBox1.SelectedIndex].LDevice[i].Device_ViewID +
  777. "\r\n장치 이름 : " + this.xField[this.comboBox1.SelectedIndex].LDevice[i].dev_name +
  778. "\r\n위 치 : " + this.xField[this.comboBox1.SelectedIndex].LDevice[i].position));
  779. // 이미지
  780. formDevice.SetDeviceImage(GetTypeImage(this.xField[this.comboBox1.SelectedIndex].LDevice[i].DevIconID));
  781. // 디바이스 상태
  782. formDevice.SetDeciceStatusText("상 태 : " + this.xField[this.comboBox1.SelectedIndex].LDevice[i].StatusStr);
  783. // 위치
  784. formDevice.Location = new Point(Control.MousePosition.X + 5, Control.MousePosition.Y + 5);
  785. // 표시
  786. formDevice.Visible = true;
  787. // cyim 2013.3.15 화면깜빡임 문제 수정
  788. // 루프문 최소화
  789. break;
  790. }
  791. }
  792. }
  793. }
  794. }
  795. }