bfd324c63df4638aa2083c448259464d0c5b5134.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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_PointOpcData : 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_DEVICE = null;
  23. // 생성자
  24. public Form_PointOpcData(_RECEIVER RECEIVER)
  25. {
  26. InitializeComponent();
  27. ///
  28. /// 폼이 생성되는 위치
  29. ///
  30. this.StartPosition = FormStartPosition.Manual;
  31. this.Location = new System.Drawing.Point(MousePosition.X, MousePosition.Y);
  32. ///
  33. /// 폴더생성 및 기본경로 지정
  34. ///
  35. // 수신기 ID 저장
  36. Receiver_ID = RECEIVER.ID;
  37. // 수신기 폴더명
  38. string ReiceiverFolderName = _Text.DEFAULT_FOLDER_RECEIVER_PREFIX + Receiver_ID;
  39. // OPC 파일을 생성하여 저장하는 기본 폴더는 자동으로 생성합니다.
  40. _File.Create_Folder(_Data.Project_Path + "\\" + _Data.Project_Name + "\\" + ReiceiverFolderName + "\\", _Text.DEFAULT_FOLDER_OPC);
  41. // 경로 지정
  42. this.editBox_ProjectPath.Text = _Data.Project_Path + "\\" + _Data.Project_Name + "\\" + ReiceiverFolderName + "\\" + _Text.DEFAULT_FOLDER_OPC;
  43. ///
  44. /// 이벤트
  45. ///
  46. // 폼닫기 이벤트를 등록 (이벤트 핸들러 해제용)
  47. this.FormClosing += new FormClosingEventHandler(CreateForm_FormClosing);
  48. }
  49. // 폼닫기 이벤트를 등록 (이벤트 핸들러 해제용)
  50. public void CreateForm_FormClosing(object sender, FormClosingEventArgs e)
  51. {
  52. }
  53. // 파일 경로 지정
  54. private void uiButton_ProjectPath_Click(object sender, EventArgs e)
  55. {
  56. // 다이얼로그 생성
  57. FolderBrowserDialog pFolderBrowserDialog = new FolderBrowserDialog();
  58. // 수신기 폴더명
  59. string ReiceiverFolderName = _Text.DEFAULT_FOLDER_RECEIVER_PREFIX + Receiver_ID;
  60. // 엑셀파일 연동시에 다이얼로그창은 프로젝트 경로에 따라서 Field 폴더에 곧바로 접근할 수있도록 함
  61. pFolderBrowserDialog.SelectedPath = _Data.Project_Path + "\\" + _Data.Project_Name + "\\" + ReiceiverFolderName + "\\" + _Text.DEFAULT_FOLDER_OPC;
  62. // 필터 처리 안함 (사용자가 xml
  63. //openFileDialog.Filter = "(*.xls)|*.xls|(*.xlsx)|*.xlsx";
  64. //openFileDialog.Filter = "(*.xls*)|*.xls*";
  65. if (pFolderBrowserDialog.ShowDialog() == DialogResult.OK)
  66. {
  67. this.editBox_ProjectPath.Text = pFolderBrowserDialog.SelectedPath;
  68. }
  69. }
  70. // UiProgressBar 크로스 스레드 해결
  71. private void Delegate_UiProgressBar()
  72. {
  73. if (this.InvokeRequired)
  74. {
  75. Cross_Thread d = new Cross_Thread(Delegate_UiProgressBar);
  76. this.Invoke(d, new object[] { });
  77. }
  78. else
  79. {
  80. UiProgressBar_OpcData.Value++;
  81. }
  82. }
  83. // UiButton 크로스 스레드 해결
  84. private void Delegate_UiButton()
  85. {
  86. if (this.InvokeRequired)
  87. {
  88. Cross_Thread d = new Cross_Thread(Delegate_UiButton);
  89. this.Invoke(d, new object[] { });
  90. }
  91. else
  92. {
  93. label1.Text = "※ 완료되었습니다.";
  94. UiButton_Apply.Enabled = true;
  95. UiButton_Close.Enabled = true;
  96. }
  97. }
  98. // 닫기 버튼
  99. private void UiButton_Close_Click(object sender, EventArgs e)
  100. {
  101. // 폼을 닫음
  102. this.Close();
  103. }
  104. // 저장 버튼
  105. private void UiButton_Apply_Click(object sender, EventArgs e)
  106. {
  107. // 폴더를 아무것도 선택하지 않았을 경우
  108. if (editBox_ProjectPath.Text.Length == 0)
  109. {
  110. // 폴더를 선택해 주세요
  111. _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.Warnning, 250, 150, _Text.NotFolderChoice, 0);
  112. return;
  113. }
  114. // 버튼 연속으로 입력은 안됨
  115. if (_Data.Enable_Button == false)
  116. return;
  117. else
  118. _Data.Enable_Button = false;
  119. //
  120. // 데이타베이스 접근 경로 지정부
  121. //
  122. _Data.DataBaseFilePath_Set(null);//(Receiver_ID);
  123. // cyim 2016.12.05 : 수신기 모델별 내부 로직 변경
  124. if (((_RECEIVER)_Data.HASH_RECEIVER[Receiver_ID]).MODEL == "IFC3300")
  125. {
  126. // 매개변수 순서 => COMM_ID, INOUT_TYPE, BOARD_ID, LOOP_NO, REPEATER_ID, POSITION_CODE, DEVICE_TYPE_NAME, DEVICE_NAME
  127. DB_TABLE_DEVICE = _Db.ExecuteRead_SqlDataAdapter(_Sql.Search_DEVICETable_NoneBoardID_BigReceiver("1", "I", "", "", "", "", "", Receiver_ID));
  128. }
  129. else
  130. {
  131. // 매개변수 순서 => COMM_ID, INOUT_TYPE, BOARD_ID, LOOP_NO, REPEATER_ID, POSITION_CODE, DEVICE_TYPE_NAME, DEVICE_NAME
  132. DB_TABLE_DEVICE = _Db.ExecuteRead_SqlDataAdapter(_Sql.Search_DEVICETable("1", "I", "15", "", "", "", "", "", Receiver_ID));
  133. }
  134. if (DB_TABLE_DEVICE == null || DB_TABLE_DEVICE.Count == 0)
  135. {
  136. _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.Warnning, 250, 150, _Text.FailDataInform, 0);
  137. return;
  138. }
  139. else
  140. {
  141. // OPC 연동 데이타를 파일로 생성합니다. 계속 진행하시겠습니까?"
  142. DialogPopup = _Popup.Create(Popup_Type.Dialog, Popup_Style.Normal, _Text.OK, 500, 150, _Text.OpcInfoCreate_Continue, 0);
  143. // 대화 팝업은 특별처리
  144. _Event.PopupClose_SendMessage_Event += new _Event.PopupClose_SendMessage_Handler(_Event_PopupClose_SendMessage_Event);
  145. }
  146. }
  147. // 스레드
  148. public void OPC_DataCreate()
  149. {
  150. //
  151. // FirePoint.cfg
  152. //
  153. // M MI1100021=1,1,I,0,2,1
  154. string FirePoint = "# Code Name = ReceiverID BoardID,Loop,Repeater,Port" + _Text.CarrageReturn;
  155. ArrayList CommBoardIDCount = new ArrayList();
  156. foreach (DataRow dr in DB_TABLE_DEVICE)
  157. {
  158. string BoardID = dr["BOARD_ID"].ToString();
  159. string Loop = dr["LOOP_NO"].ToString();
  160. string Repeater = _Convert.String_to_Int_ThreeType(dr["REPEATER_ID"].ToString());
  161. string Repeater_No = dr["REPEATER_ID"].ToString();
  162. string Port = dr["DEVICE_ID"].ToString();
  163. FirePoint = FirePoint + "M MI" + Receiver_ID + BoardID + Loop + Repeater + Port +
  164. "=" + Receiver_ID + "," + BoardID + ",I," + Loop + "," + Repeater_No + "," + Port + _Text.CarrageReturn;
  165. //FireUnit.cfg
  166. if (CommBoardIDCount.Contains(BoardID) == false)
  167. CommBoardIDCount.Add(BoardID);
  168. // 프로그레스바 Value값 1증가
  169. if (UiProgressBar_OpcData.Value <= UiProgressBar_OpcData.Maximum)
  170. Delegate_UiProgressBar(); //크로스 스레드 해결
  171. }
  172. //
  173. // FirePoint.cfg
  174. //
  175. string FireUnit = null;
  176. foreach (string CommBoardID in CommBoardIDCount)
  177. FireUnit = FireUnit + "M " + CommBoardID + _Text.CarrageReturn;
  178. //
  179. // config.ini
  180. //
  181. string config = "[RECEIVER]" + _Text.CarrageReturn;
  182. DataRowCollection DB_TABLE_TB_RECEIVER = _Db.ExecuteRead_SqlDataAdapter(_Sql.SearchAll_Table_Value("TB_RECEIVER", Receiver_ID));
  183. if (DB_TABLE_TB_RECEIVER != null && DB_TABLE_TB_RECEIVER.Count != 0) // 데이터가 DB에 있다.
  184. {
  185. DataRow dr = DB_TABLE_TB_RECEIVER[0];
  186. config = config + "IP = " + dr["IP_ADDRESS"].ToString() + _Text.CarrageReturn;
  187. config = config + "EVENT_PORT = " + Util.StrToInt(dr["EVENT_PORT_NO"], 0) + _Text.CarrageReturn;
  188. config = config + "COMMAND_PORT = " + Util.StrToInt(dr["COMMAND_PORT_NO"], 0);
  189. }
  190. //
  191. // 파일생성
  192. //
  193. _Cfg.Create_Cfg(FirePoint, this.editBox_ProjectPath.Text + "\\" + _Text.DEFAULT_OPC_POINT);
  194. // 그리드에 출력이 끝나면 Value값을 1 증가시킴
  195. if (UiProgressBar_OpcData.Value <= UiProgressBar_OpcData.Maximum)
  196. Delegate_UiProgressBar(); //크로스 스레드 해결
  197. _Cfg.Create_Cfg(FireUnit, this.editBox_ProjectPath.Text + "\\" + _Text.DEFAULT_OPC_UNIT);
  198. // 그리드에 출력이 끝나면 Value값을 1 증가시킴
  199. if (UiProgressBar_OpcData.Value <= UiProgressBar_OpcData.Maximum)
  200. Delegate_UiProgressBar(); //크로스 스레드 해결
  201. _Ini.Create_Ini(config, this.editBox_ProjectPath.Text + "\\" + _Text.DEFAULT_OPC_CONFIG);
  202. // 그리드에 출력이 끝나면 Value값을 1 증가시킴
  203. if (UiProgressBar_OpcData.Value <= UiProgressBar_OpcData.Maximum)
  204. Delegate_UiProgressBar(); //크로스 스레드 해결
  205. // 저장버튼 및 닫기버튼 사용하게...
  206. Delegate_UiButton();
  207. // 버튼은 사용가능함
  208. _Data.Enable_Button = true;
  209. }
  210. // 팝업에서 Yes, NO 에서 받은 이벤트 처리
  211. public void _Event_PopupClose_SendMessage_Event(object sender, object etc)
  212. {
  213. // 대화 팝업 주체
  214. Form popup = (Form)sender;
  215. if (DialogPopup.Name == popup.Name && etc.ToString() == _Text.OK)
  216. {
  217. // 저장버튼 및 닫기버튼 실행 중에는 사용 못하게
  218. UiButton_Apply.Enabled = false;
  219. UiButton_Close.Enabled = false;
  220. // ProgressBar Total 카운트(추가로 3을 주는 이유는 FirePoint.cfg 이 생성될때 1 증가, FireUnit.cfg 생성될때 1 증가, config.ini 생성될때 1 증가)
  221. int ProgressBar_TotalCount = 3;
  222. // ProgressBar의 Maximum값을 구하기 위해서
  223. ProgressBar_TotalCount = ProgressBar_TotalCount + DB_TABLE_DEVICE.Count;
  224. // ProgressBar의 Maximum값 저장
  225. UiProgressBar_OpcData.Maximum = ProgressBar_TotalCount;
  226. // UiProgressBar 초기값 셋팅
  227. UiProgressBar_OpcData.Value = 0;
  228. // 스레드 생성
  229. Thread WorkingThread = new Thread(new ThreadStart(OPC_DataCreate));
  230. // 스레드시작
  231. WorkingThread.Start();
  232. }
  233. else
  234. _Data.Enable_Button = true;
  235. // 대화 팝업은 특별처리(이벤트 해제)
  236. _Event.PopupClose_SendMessage_Event -= new _Event.PopupClose_SendMessage_Handler(_Event_PopupClose_SendMessage_Event);
  237. }
  238. }
  239. }