123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Threading;
- using System.Collections;
- namespace IControls_FireManager
- {
- public partial class Form_PointOpcData : Form
- {
- // 대화 팝업용
- Form DialogPopup = new Form();
- // 크로스 스레드 해결
- delegate void Cross_Thread();
- // 수신기 ID를 저장하기 위해서
- string Receiver_ID = null;
- // 데이타 저장
- DataRowCollection DB_TABLE_DEVICE = null;
- // 생성자
- public Form_PointOpcData(_RECEIVER RECEIVER)
- {
- InitializeComponent();
- ///
- /// 폼이 생성되는 위치
- ///
- this.StartPosition = FormStartPosition.Manual;
- this.Location = new System.Drawing.Point(MousePosition.X, MousePosition.Y);
- ///
- /// 폴더생성 및 기본경로 지정
- ///
- // 수신기 ID 저장
- Receiver_ID = RECEIVER.ID;
- // 수신기 폴더명
- string ReiceiverFolderName = _Text.DEFAULT_FOLDER_RECEIVER_PREFIX + Receiver_ID;
- // OPC 파일을 생성하여 저장하는 기본 폴더는 자동으로 생성합니다.
- _File.Create_Folder(_Data.Project_Path + "\\" + _Data.Project_Name + "\\" + ReiceiverFolderName + "\\", _Text.DEFAULT_FOLDER_OPC);
- // 경로 지정
- this.editBox_ProjectPath.Text = _Data.Project_Path + "\\" + _Data.Project_Name + "\\" + ReiceiverFolderName + "\\" + _Text.DEFAULT_FOLDER_OPC;
- ///
- /// 이벤트
- ///
- // 폼닫기 이벤트를 등록 (이벤트 핸들러 해제용)
- this.FormClosing += new FormClosingEventHandler(CreateForm_FormClosing);
- }
- // 폼닫기 이벤트를 등록 (이벤트 핸들러 해제용)
- public void CreateForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- }
- // 파일 경로 지정
- private void uiButton_ProjectPath_Click(object sender, EventArgs e)
- {
- // 다이얼로그 생성
- FolderBrowserDialog pFolderBrowserDialog = new FolderBrowserDialog();
- // 수신기 폴더명
- string ReiceiverFolderName = _Text.DEFAULT_FOLDER_RECEIVER_PREFIX + Receiver_ID;
- // 엑셀파일 연동시에 다이얼로그창은 프로젝트 경로에 따라서 Field 폴더에 곧바로 접근할 수있도록 함
- pFolderBrowserDialog.SelectedPath = _Data.Project_Path + "\\" + _Data.Project_Name + "\\" + ReiceiverFolderName + "\\" + _Text.DEFAULT_FOLDER_OPC;
- // 필터 처리 안함 (사용자가 xml
- //openFileDialog.Filter = "(*.xls)|*.xls|(*.xlsx)|*.xlsx";
- //openFileDialog.Filter = "(*.xls*)|*.xls*";
- if (pFolderBrowserDialog.ShowDialog() == DialogResult.OK)
- {
- this.editBox_ProjectPath.Text = pFolderBrowserDialog.SelectedPath;
- }
- }
- // UiProgressBar 크로스 스레드 해결
- private void Delegate_UiProgressBar()
- {
- if (this.InvokeRequired)
- {
- Cross_Thread d = new Cross_Thread(Delegate_UiProgressBar);
- this.Invoke(d, new object[] { });
- }
- else
- {
- UiProgressBar_OpcData.Value++;
- }
- }
- // UiButton 크로스 스레드 해결
- private void Delegate_UiButton()
- {
- if (this.InvokeRequired)
- {
- Cross_Thread d = new Cross_Thread(Delegate_UiButton);
- this.Invoke(d, new object[] { });
- }
- else
- {
- label1.Text = "※ 완료되었습니다.";
- UiButton_Apply.Enabled = true;
- UiButton_Close.Enabled = true;
- }
- }
- // 닫기 버튼
- private void UiButton_Close_Click(object sender, EventArgs e)
- {
- // 폼을 닫음
- this.Close();
- }
- // 저장 버튼
- private void UiButton_Apply_Click(object sender, EventArgs e)
- {
- // 폴더를 아무것도 선택하지 않았을 경우
- if (editBox_ProjectPath.Text.Length == 0)
- {
- // 폴더를 선택해 주세요
- _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.Warnning, 250, 150, _Text.NotFolderChoice, 0);
- return;
- }
- // 버튼 연속으로 입력은 안됨
- if (_Data.Enable_Button == false)
- return;
- else
- _Data.Enable_Button = false;
- //
- // 데이타베이스 접근 경로 지정부
- //
- _Data.DataBaseFilePath_Set(null);//(Receiver_ID);
- // cyim 2016.12.05 : 수신기 모델별 내부 로직 변경
- if (((_RECEIVER)_Data.HASH_RECEIVER[Receiver_ID]).MODEL == "IFC3300")
- {
- // 매개변수 순서 => COMM_ID, INOUT_TYPE, BOARD_ID, LOOP_NO, REPEATER_ID, POSITION_CODE, DEVICE_TYPE_NAME, DEVICE_NAME
- DB_TABLE_DEVICE = _Db.ExecuteRead_SqlDataAdapter(_Sql.Search_DEVICETable_NoneBoardID_BigReceiver("1", "I", "", "", "", "", "", Receiver_ID));
- }
- else
- {
- // 매개변수 순서 => COMM_ID, INOUT_TYPE, BOARD_ID, LOOP_NO, REPEATER_ID, POSITION_CODE, DEVICE_TYPE_NAME, DEVICE_NAME
- DB_TABLE_DEVICE = _Db.ExecuteRead_SqlDataAdapter(_Sql.Search_DEVICETable("1", "I", "15", "", "", "", "", "", Receiver_ID));
- }
- if (DB_TABLE_DEVICE == null || DB_TABLE_DEVICE.Count == 0)
- {
- _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.Warnning, 250, 150, _Text.FailDataInform, 0);
- return;
- }
- else
- {
- // OPC 연동 데이타를 파일로 생성합니다. 계속 진행하시겠습니까?"
- DialogPopup = _Popup.Create(Popup_Type.Dialog, Popup_Style.Normal, _Text.OK, 500, 150, _Text.OpcInfoCreate_Continue, 0);
- // 대화 팝업은 특별처리
- _Event.PopupClose_SendMessage_Event += new _Event.PopupClose_SendMessage_Handler(_Event_PopupClose_SendMessage_Event);
- }
- }
- // 스레드
- public void OPC_DataCreate()
- {
- //
- // FirePoint.cfg
- //
- // M MI1100021=1,1,I,0,2,1
- string FirePoint = "# Code Name = ReceiverID BoardID,Loop,Repeater,Port" + _Text.CarrageReturn;
- ArrayList CommBoardIDCount = new ArrayList();
- foreach (DataRow dr in DB_TABLE_DEVICE)
- {
- string BoardID = dr["BOARD_ID"].ToString();
- string Loop = dr["LOOP_NO"].ToString();
- string Repeater = _Convert.String_to_Int_ThreeType(dr["REPEATER_ID"].ToString());
- string Repeater_No = dr["REPEATER_ID"].ToString();
- string Port = dr["DEVICE_ID"].ToString();
- FirePoint = FirePoint + "M MI" + Receiver_ID + BoardID + Loop + Repeater + Port +
- "=" + Receiver_ID + "," + BoardID + ",I," + Loop + "," + Repeater_No + "," + Port + _Text.CarrageReturn;
- //FireUnit.cfg
- if (CommBoardIDCount.Contains(BoardID) == false)
- CommBoardIDCount.Add(BoardID);
- // 프로그레스바 Value값 1증가
- if (UiProgressBar_OpcData.Value <= UiProgressBar_OpcData.Maximum)
- Delegate_UiProgressBar(); //크로스 스레드 해결
- }
- //
- // FirePoint.cfg
- //
- string FireUnit = null;
- foreach (string CommBoardID in CommBoardIDCount)
- FireUnit = FireUnit + "M " + CommBoardID + _Text.CarrageReturn;
- //
- // config.ini
- //
- string config = "[RECEIVER]" + _Text.CarrageReturn;
- DataRowCollection DB_TABLE_TB_RECEIVER = _Db.ExecuteRead_SqlDataAdapter(_Sql.SearchAll_Table_Value("TB_RECEIVER", Receiver_ID));
- if (DB_TABLE_TB_RECEIVER != null && DB_TABLE_TB_RECEIVER.Count != 0) // 데이터가 DB에 있다.
- {
- DataRow dr = DB_TABLE_TB_RECEIVER[0];
- config = config + "IP = " + dr["IP_ADDRESS"].ToString() + _Text.CarrageReturn;
- config = config + "EVENT_PORT = " + Util.StrToInt(dr["EVENT_PORT_NO"], 0) + _Text.CarrageReturn;
- config = config + "COMMAND_PORT = " + Util.StrToInt(dr["COMMAND_PORT_NO"], 0);
- }
- //
- // 파일생성
- //
- _Cfg.Create_Cfg(FirePoint, this.editBox_ProjectPath.Text + "\\" + _Text.DEFAULT_OPC_POINT);
- // 그리드에 출력이 끝나면 Value값을 1 증가시킴
- if (UiProgressBar_OpcData.Value <= UiProgressBar_OpcData.Maximum)
- Delegate_UiProgressBar(); //크로스 스레드 해결
- _Cfg.Create_Cfg(FireUnit, this.editBox_ProjectPath.Text + "\\" + _Text.DEFAULT_OPC_UNIT);
- // 그리드에 출력이 끝나면 Value값을 1 증가시킴
- if (UiProgressBar_OpcData.Value <= UiProgressBar_OpcData.Maximum)
- Delegate_UiProgressBar(); //크로스 스레드 해결
- _Ini.Create_Ini(config, this.editBox_ProjectPath.Text + "\\" + _Text.DEFAULT_OPC_CONFIG);
- // 그리드에 출력이 끝나면 Value값을 1 증가시킴
- if (UiProgressBar_OpcData.Value <= UiProgressBar_OpcData.Maximum)
- Delegate_UiProgressBar(); //크로스 스레드 해결
- // 저장버튼 및 닫기버튼 사용하게...
- Delegate_UiButton();
- // 버튼은 사용가능함
- _Data.Enable_Button = true;
- }
- // 팝업에서 Yes, NO 에서 받은 이벤트 처리
- public void _Event_PopupClose_SendMessage_Event(object sender, object etc)
- {
- // 대화 팝업 주체
- Form popup = (Form)sender;
- if (DialogPopup.Name == popup.Name && etc.ToString() == _Text.OK)
- {
- // 저장버튼 및 닫기버튼 실행 중에는 사용 못하게
- UiButton_Apply.Enabled = false;
- UiButton_Close.Enabled = false;
- // ProgressBar Total 카운트(추가로 3을 주는 이유는 FirePoint.cfg 이 생성될때 1 증가, FireUnit.cfg 생성될때 1 증가, config.ini 생성될때 1 증가)
- int ProgressBar_TotalCount = 3;
- // ProgressBar의 Maximum값을 구하기 위해서
- ProgressBar_TotalCount = ProgressBar_TotalCount + DB_TABLE_DEVICE.Count;
- // ProgressBar의 Maximum값 저장
- UiProgressBar_OpcData.Maximum = ProgressBar_TotalCount;
- // UiProgressBar 초기값 셋팅
- UiProgressBar_OpcData.Value = 0;
- // 스레드 생성
- Thread WorkingThread = new Thread(new ThreadStart(OPC_DataCreate));
- // 스레드시작
- WorkingThread.Start();
- }
- else
- _Data.Enable_Button = true;
- // 대화 팝업은 특별처리(이벤트 해제)
- _Event.PopupClose_SendMessage_Event -= new _Event.PopupClose_SendMessage_Handler(_Event_PopupClose_SendMessage_Event);
- }
- }
- }
|