eaf35dcf484985af52edbe85b97691e5eae54877.svn-base 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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.Threading;
  10. using System.Collections;
  11. namespace IControls_FireManager
  12. {
  13. public partial class Form_OperSetMapProcessFile : Form
  14. {
  15. // 대화 팝업용
  16. Form DialogPopup = new Form();
  17. // 크로스 스레드 해결
  18. delegate void Cross_Thread();
  19. // 수신기 ID를 저장하기 위해서
  20. string Receiver_ID = null;
  21. // 데이타 저장
  22. DataRowCollection DB_TABLE_MAPPROCESS = null;
  23. // 프로그레스바
  24. public delegate void ProgressBarWorking_SendMessage_Handler();
  25. public event ProgressBarWorking_SendMessage_Handler ProgressBarWorking_SendMessage_Event;
  26. // 생성자
  27. public Form_OperSetMapProcessFile(_RECEIVER RECEIVER)
  28. {
  29. InitializeComponent();
  30. ///
  31. /// 폼이 생성되는 위치
  32. ///
  33. this.StartPosition = FormStartPosition.Manual;
  34. this.Location = new System.Drawing.Point(MousePosition.X, MousePosition.Y);
  35. ///
  36. /// 폴더생성 및 기본경로 지정
  37. ///
  38. // 수신기 ID 저장
  39. Receiver_ID = RECEIVER.ID;
  40. // 수신기 폴더명
  41. string ReiceiverFolderName = _Text.DEFAULT_FOLDER_RECEIVER_PREFIX + Receiver_ID;
  42. // 폴더를 따로 두는 루틴은 제외함 -> 설정이 헷갈릴수 있으므로 제외 2014-01-24
  43. // MapProcessFile 을 생성하여 저장하는 기본 폴더는 자동으로 생성합니다.
  44. //_File.Create_Folder(_Data.Project_Path + "\\" + _Data.Project_Name + "\\" + ReiceiverFolderName + "\\", _Text.DEFAULT_FOLDER_MAPPROCESS);
  45. // 경로 지정
  46. this.editBox_ProjectPath.Text = _Data.Project_Path + "\\" + _Data.Project_Name + "\\" + ReiceiverFolderName; //+ "\\" + _Text.DEFAULT_FOLDER_MAPPROCESS;
  47. ///
  48. /// 이벤트
  49. ///
  50. // 폼닫기 이벤트를 등록 (이벤트 핸들러 해제용)
  51. this.FormClosing += new FormClosingEventHandler(CreateForm_FormClosing);
  52. ProgressBarWorking_SendMessage_Event += new ProgressBarWorking_SendMessage_Handler(Form_OperSetMapProcessFile_ProgressBarWorking_SendMessage_Event);
  53. }
  54. // 폼닫기 이벤트를 등록 (이벤트 핸들러 해제용)
  55. public void CreateForm_FormClosing(object sender, FormClosingEventArgs e)
  56. {
  57. // 이벤트 핸들러 해제
  58. ProgressBarWorking_SendMessage_Event -= new ProgressBarWorking_SendMessage_Handler(Form_OperSetMapProcessFile_ProgressBarWorking_SendMessage_Event);
  59. }
  60. public void Form_OperSetMapProcessFile_ProgressBarWorking_SendMessage_Event()
  61. {
  62. if (UiProgressBar_MapProcess.Value <= UiProgressBar_MapProcess.Maximum)
  63. Delegate_UiProgressBar();
  64. }
  65. // 파일 경로 지정
  66. private void uiButton_ProjectPath_Click(object sender, EventArgs e)
  67. {
  68. // 다이얼로그 생성
  69. FolderBrowserDialog pFolderBrowserDialog = new FolderBrowserDialog();
  70. // 수신기 폴더명
  71. string ReiceiverFolderName = _Text.DEFAULT_FOLDER_RECEIVER_PREFIX + Receiver_ID;
  72. // 엑셀파일 연동시에 다이얼로그창은 프로젝트 경로에 따라서 Field 폴더에 곧바로 접근할 수있도록 함
  73. pFolderBrowserDialog.SelectedPath = _Data.Project_Path + "\\" + _Data.Project_Name + "\\" + ReiceiverFolderName;// +"\\" + _Text.DEFAULT_FOLDER_MAPPROCESS;
  74. // 필터 처리 안함 (사용자가 xml
  75. //openFileDialog.Filter = "(*.xls)|*.xls|(*.xlsx)|*.xlsx";
  76. //openFileDialog.Filter = "(*.xls*)|*.xls*";
  77. if (pFolderBrowserDialog.ShowDialog() == DialogResult.OK)
  78. {
  79. this.editBox_ProjectPath.Text = pFolderBrowserDialog.SelectedPath;
  80. }
  81. }
  82. // UiProgressBar 크로스 스레드 해결
  83. private void Delegate_UiProgressBar()
  84. {
  85. if (UiProgressBar_MapProcess.InvokeRequired)
  86. {
  87. Cross_Thread d = new Cross_Thread(Delegate_UiProgressBar);
  88. UiProgressBar_MapProcess.Invoke(d, new object[] { });
  89. }
  90. else
  91. {
  92. UiProgressBar_MapProcess.Value++;
  93. }
  94. }
  95. // UiButton 크로스 스레드 해결
  96. private void Delegate_UiButton()
  97. {
  98. if (this.InvokeRequired)
  99. {
  100. Cross_Thread d = new Cross_Thread(Delegate_UiButton);
  101. this.Invoke(d, new object[] { });
  102. }
  103. else
  104. {
  105. label1.Text = "※ 완료되었습니다.";
  106. UiButton_Apply.Enabled = true;
  107. UiButton_Close.Enabled = true;
  108. }
  109. }
  110. // 닫기 버튼
  111. private void UiButton_Close_Click(object sender, EventArgs e)
  112. {
  113. // 폼을 닫음
  114. this.Close();
  115. }
  116. // 저장 버튼
  117. private void UiButton_Apply_Click(object sender, EventArgs e)
  118. {
  119. // 폴더를 아무것도 선택하지 않았을 경우
  120. if (editBox_ProjectPath.Text.Length == 0)
  121. {
  122. // 폴더를 선택해 주세요
  123. _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.Warnning, 250, 150, _Text.NotFolderChoice, 0);
  124. return;
  125. }
  126. //
  127. // 데이타베이스 접근 경로 지정부
  128. //
  129. _Data.DataBaseFilePath_Set(null);//(Receiver_ID);
  130. // 맵연동 파일 생성용 전용 쿼리
  131. DB_TABLE_MAPPROCESS = _Db.ExecuteRead_SqlDataAdapter(_Sql.MapProcessFile_Create(Receiver_ID));
  132. if (DB_TABLE_MAPPROCESS == null || DB_TABLE_MAPPROCESS.Count == 0)
  133. {
  134. _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.Warnning, 250, 150, _Text.FailDataInform, 0);
  135. return;
  136. }
  137. else
  138. {
  139. // MapProcess 데이타를 파일로 생성합니다. 계속 진행하시겠습니까?
  140. DialogPopup = _Popup.Create(Popup_Type.Dialog, Popup_Style.Normal, _Text.OK, 500, 150, _Text.MapProcessFileCreate_Continue, 0);
  141. // 대화 팝업은 특별처리
  142. _Event.PopupClose_SendMessage_Event += new _Event.PopupClose_SendMessage_Handler(_Event_PopupClose_SendMessage_Event);
  143. }
  144. }
  145. // 스레드
  146. public void MapProcess_DataCreate()
  147. {
  148. // 맵연동설정파일 포맷
  149. // - 한개의 레코드 길이 : 40 Byte (개행문자 포함)
  150. // - 구분자 는 |
  151. // - 마지막에 개행문자 (CR/LF)
  152. // - 순서 : A.MAP_NO,A.MAP_TYPE (ASC)
  153. // 1. RECEIVER ID : 3 Bytes (3자리가 아닐 경우 왼쪽 0으로 채움)
  154. // 2. MAP NO. : 7 Bytes (7자리가 아닐 경우 왼쪽 0으로 채움) // cyim 2015.10.30 : 포맷변경 포함 5->7, 즉 2번째 Map no 가 7자리로 변경
  155. // 3. MAP TYPE : 1 Bytes (NULL일 경우 공백으로 채움)
  156. // 4. PROCESS TYPE : 1 Bytes (NULL일 경우 공백으로 채움)
  157. // 5. COMM. ID : 3 Bytes (3자리가 아닐 경우 왼쪽 0으로 채움)
  158. // 6. BOARD ID : 3 Bytes (3자리가 아닐 경우 왼쪽 0으로 채움)
  159. // 7. LOOP NO. : 3 Bytes (3자리가 아닐 경우 왼쪽 0으로 채움)
  160. // 8. REPEATER ID : 3 Bytes (3자리가 아닐 경우 왼쪽 0으로 채움)
  161. // 9. DEVICE ID : 3 Bytes (3자리가 아닐 경우 왼쪽 0으로 채움)
  162. // 10. IN/OUT TYPE : 1 Bytes (NULL일 경우 공백으로 채움)
  163. // 11. USE FLAG : 1 Bytes (NULL일 경우 공백으로 채움)
  164. // 12. CR/LF : 2 Bytes
  165. // ex) C 소스코드
  166. // // MAP DATA 구성
  167. // sprintf (szMapData,"%03d|%07d|%c|%c|%03d|%03d|%03d|%03d|%03d|%c|%c|\r\n", // cyim 2015.10.30 : 포맷변경 포함 5->7, 즉 2번째 Map no 가 7자리로 변경
  168. // nReceiverID,nMapNo,
  169. // (szMapType[0]!='\0'?szMapType[0]:' '),
  170. // (szProcessType[0]!='\0'?szProcessType[0]:' '),
  171. // nCommID,nBoardID,nLoopNo,nRepeaterID,nDeviceID,
  172. // (szInoutType[0]!='\0'?szInoutType[0]:' '),
  173. // (szUseFlag[0]!='\0'?szUseFlag[0]:' '));
  174. // ex) 001|0000001|I|D|001|001|000|002|001|I|Y| // cyim 2015.10.30 : 포맷변경 포함 5->7, 즉 2번째 Map no 가 7자리로 변경
  175. StringBuilder Contents = new StringBuilder();
  176. // 프로그레스바 Value값 1증가
  177. ProgressBarWorking_SendMessage_Event();
  178. foreach (DataRow dr in DB_TABLE_MAPPROCESS)
  179. {
  180. if (dr[0].ToString().Length != 0 && dr[1].ToString().Length != 0 && dr[2].ToString().Length != 0 && dr[3].ToString().Length != 0
  181. && dr[4].ToString().Length != 0 && dr[5].ToString().Length != 0 && dr[6].ToString().Length != 0 && dr[7].ToString().Length != 0
  182. && dr[8].ToString().Length != 0 && dr[9].ToString().Length != 0 && dr[10].ToString().Length != 0)
  183. {
  184. // 데이타 추출 및 포맷 적용
  185. string RECEIVER_ID = Int32.Parse(dr["RECEIVER_ID"].ToString()).ToString("D3");
  186. // cyim 2016.04.01 : 6자리 혹은 4자리로 맵아이디와 그룹아이디 지정할수 있도록함
  187. string MAP_NO = "";
  188. if (_Data.Project_MapGroupIDTypeNumber == "6")
  189. MAP_NO = Int32.Parse(dr["MAP_NO"].ToString()).ToString("D7"); // cyim 2015.10.30 : 포맷변경 포함 5->7, 즉 2번째 Map no 가 7자리로 변경
  190. else
  191. MAP_NO = Int32.Parse(dr["MAP_NO"].ToString()).ToString("D5");
  192. string MAP_TYPE = dr["MAP_TYPE"].ToString();
  193. string PROCESS_TYPE = dr["PROCESS_TYPE"].ToString();
  194. string COMM_ID = Int32.Parse(dr["COMM_ID"].ToString()).ToString("D3");
  195. string BOARD_ID = Int32.Parse(dr["BOARD_ID"].ToString()).ToString("D3");
  196. string LOOP_NO = Int32.Parse(dr["LOOP_NO"].ToString()).ToString("D3");
  197. string REPEATER_ID = Int32.Parse(dr["REPEATER_ID"].ToString()).ToString("D3");
  198. string DEVICE_ID = Int32.Parse(dr["DEVICE_ID"].ToString()).ToString("D3");
  199. string INOUT_TYPE = dr["INOUT_TYPE"].ToString();
  200. string USE_FLAG = dr["USE_FLAG"].ToString();
  201. // 구분자 포함하여 레코드 단위 생성
  202. Contents.Append(
  203. RECEIVER_ID + "|" +
  204. MAP_NO + "|" +
  205. MAP_TYPE + "|" +
  206. PROCESS_TYPE + "|" +
  207. COMM_ID + "|" +
  208. BOARD_ID + "|" +
  209. LOOP_NO + "|" +
  210. REPEATER_ID + "|" +
  211. DEVICE_ID + "|" +
  212. INOUT_TYPE + "|" +
  213. USE_FLAG + "|"
  214. //+ _Text.CarrageReturn // cyim 2016.03.29 : 통신데몬과 마차가지로 개행문자 삭제
  215. );
  216. }
  217. }
  218. // 프로그레스바 Value값 1증가
  219. ProgressBarWorking_SendMessage_Event();
  220. //
  221. // 파일생성
  222. //
  223. _Cfg.Create_Cfg(Contents.ToString(), this.editBox_ProjectPath.Text + "\\" + _Text.DEFALUT_MAPPROCESS_FILENAME);
  224. // 프로그레스바 Value값 1증가
  225. ProgressBarWorking_SendMessage_Event();
  226. // 저장버튼 및 닫기버튼 사용하게...
  227. Delegate_UiButton();
  228. }
  229. // 팝업에서 Yes, NO 에서 받은 이벤트 처리
  230. public void _Event_PopupClose_SendMessage_Event(object sender, object etc)
  231. {
  232. // 대화 팝업 주체
  233. Form popup = (Form)sender;
  234. if (DialogPopup.Name == popup.Name && etc.ToString() == _Text.OK)
  235. {
  236. // 저장버튼 및 닫기버튼 실행 중에는 사용 못하게
  237. UiButton_Apply.Enabled = false;
  238. UiButton_Close.Enabled = false;
  239. // ProgressBar Total 카운트 (3으로 고정시킨다 카운터를 세기위해 프로그레스바가 너무 부하가 걸리므로)
  240. int ProgressBar_TotalCount = 3;
  241. // ProgressBar의 Maximum값을 구하기 위해서
  242. // ProgressBar_TotalCount = ProgressBar_TotalCount;
  243. // ProgressBar의 Maximum값 저장
  244. UiProgressBar_MapProcess.Maximum = ProgressBar_TotalCount;
  245. // UiProgressBar 초기값 셋팅
  246. UiProgressBar_MapProcess.Value = 0;
  247. // 스레드 생성
  248. Thread WorkingThread = new Thread(new ThreadStart(MapProcess_DataCreate));
  249. // 스레드시작
  250. WorkingThread.Start();
  251. }
  252. // 대화 팝업은 특별처리(이벤트 해제)
  253. _Event.PopupClose_SendMessage_Event -= new _Event.PopupClose_SendMessage_Handler(_Event_PopupClose_SendMessage_Event);
  254. }
  255. }
  256. }