123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- 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_OperSetMapProcessFile : Form
- {
- // 대화 팝업용
- Form DialogPopup = new Form();
- // 크로스 스레드 해결
- delegate void Cross_Thread();
- // 수신기 ID를 저장하기 위해서
- string Receiver_ID = null;
- // 데이타 저장
- DataRowCollection DB_TABLE_MAPPROCESS = null;
- // 프로그레스바
- public delegate void ProgressBarWorking_SendMessage_Handler();
- public event ProgressBarWorking_SendMessage_Handler ProgressBarWorking_SendMessage_Event;
- // 생성자
- public Form_OperSetMapProcessFile(_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;
- // 폴더를 따로 두는 루틴은 제외함 -> 설정이 헷갈릴수 있으므로 제외 2014-01-24
- // MapProcessFile 을 생성하여 저장하는 기본 폴더는 자동으로 생성합니다.
- //_File.Create_Folder(_Data.Project_Path + "\\" + _Data.Project_Name + "\\" + ReiceiverFolderName + "\\", _Text.DEFAULT_FOLDER_MAPPROCESS);
- // 경로 지정
- this.editBox_ProjectPath.Text = _Data.Project_Path + "\\" + _Data.Project_Name + "\\" + ReiceiverFolderName; //+ "\\" + _Text.DEFAULT_FOLDER_MAPPROCESS;
- ///
- /// 이벤트
- ///
- // 폼닫기 이벤트를 등록 (이벤트 핸들러 해제용)
- this.FormClosing += new FormClosingEventHandler(CreateForm_FormClosing);
- ProgressBarWorking_SendMessage_Event += new ProgressBarWorking_SendMessage_Handler(Form_OperSetMapProcessFile_ProgressBarWorking_SendMessage_Event);
- }
- // 폼닫기 이벤트를 등록 (이벤트 핸들러 해제용)
- public void CreateForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- // 이벤트 핸들러 해제
- ProgressBarWorking_SendMessage_Event -= new ProgressBarWorking_SendMessage_Handler(Form_OperSetMapProcessFile_ProgressBarWorking_SendMessage_Event);
- }
- public void Form_OperSetMapProcessFile_ProgressBarWorking_SendMessage_Event()
- {
- if (UiProgressBar_MapProcess.Value <= UiProgressBar_MapProcess.Maximum)
- Delegate_UiProgressBar();
- }
- // 파일 경로 지정
- 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_MAPPROCESS;
- // 필터 처리 안함 (사용자가 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 (UiProgressBar_MapProcess.InvokeRequired)
- {
- Cross_Thread d = new Cross_Thread(Delegate_UiProgressBar);
- UiProgressBar_MapProcess.Invoke(d, new object[] { });
- }
- else
- {
- UiProgressBar_MapProcess.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;
- }
- //
- // 데이타베이스 접근 경로 지정부
- //
- _Data.DataBaseFilePath_Set(null);//(Receiver_ID);
- // 맵연동 파일 생성용 전용 쿼리
- DB_TABLE_MAPPROCESS = _Db.ExecuteRead_SqlDataAdapter(_Sql.MapProcessFile_Create(Receiver_ID));
- if (DB_TABLE_MAPPROCESS == null || DB_TABLE_MAPPROCESS.Count == 0)
- {
- _Popup.Create(Popup_Type.Confirm, Popup_Style.Normal, _Text.Warnning, 250, 150, _Text.FailDataInform, 0);
- return;
- }
- else
- {
- // MapProcess 데이타를 파일로 생성합니다. 계속 진행하시겠습니까?
- DialogPopup = _Popup.Create(Popup_Type.Dialog, Popup_Style.Normal, _Text.OK, 500, 150, _Text.MapProcessFileCreate_Continue, 0);
- // 대화 팝업은 특별처리
- _Event.PopupClose_SendMessage_Event += new _Event.PopupClose_SendMessage_Handler(_Event_PopupClose_SendMessage_Event);
- }
- }
- // 스레드
- public void MapProcess_DataCreate()
- {
- // 맵연동설정파일 포맷
- // - 한개의 레코드 길이 : 40 Byte (개행문자 포함)
- // - 구분자 는 |
- // - 마지막에 개행문자 (CR/LF)
- // - 순서 : A.MAP_NO,A.MAP_TYPE (ASC)
- // 1. RECEIVER ID : 3 Bytes (3자리가 아닐 경우 왼쪽 0으로 채움)
- // 2. MAP NO. : 7 Bytes (7자리가 아닐 경우 왼쪽 0으로 채움) // cyim 2015.10.30 : 포맷변경 포함 5->7, 즉 2번째 Map no 가 7자리로 변경
- // 3. MAP TYPE : 1 Bytes (NULL일 경우 공백으로 채움)
- // 4. PROCESS TYPE : 1 Bytes (NULL일 경우 공백으로 채움)
- // 5. COMM. ID : 3 Bytes (3자리가 아닐 경우 왼쪽 0으로 채움)
- // 6. BOARD ID : 3 Bytes (3자리가 아닐 경우 왼쪽 0으로 채움)
- // 7. LOOP NO. : 3 Bytes (3자리가 아닐 경우 왼쪽 0으로 채움)
- // 8. REPEATER ID : 3 Bytes (3자리가 아닐 경우 왼쪽 0으로 채움)
- // 9. DEVICE ID : 3 Bytes (3자리가 아닐 경우 왼쪽 0으로 채움)
- // 10. IN/OUT TYPE : 1 Bytes (NULL일 경우 공백으로 채움)
- // 11. USE FLAG : 1 Bytes (NULL일 경우 공백으로 채움)
- // 12. CR/LF : 2 Bytes
- // ex) C 소스코드
- // // MAP DATA 구성
- // 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자리로 변경
- // nReceiverID,nMapNo,
- // (szMapType[0]!='\0'?szMapType[0]:' '),
- // (szProcessType[0]!='\0'?szProcessType[0]:' '),
- // nCommID,nBoardID,nLoopNo,nRepeaterID,nDeviceID,
- // (szInoutType[0]!='\0'?szInoutType[0]:' '),
- // (szUseFlag[0]!='\0'?szUseFlag[0]:' '));
- // ex) 001|0000001|I|D|001|001|000|002|001|I|Y| // cyim 2015.10.30 : 포맷변경 포함 5->7, 즉 2번째 Map no 가 7자리로 변경
- StringBuilder Contents = new StringBuilder();
- // 프로그레스바 Value값 1증가
- ProgressBarWorking_SendMessage_Event();
- foreach (DataRow dr in DB_TABLE_MAPPROCESS)
- {
- if (dr[0].ToString().Length != 0 && dr[1].ToString().Length != 0 && dr[2].ToString().Length != 0 && dr[3].ToString().Length != 0
- && dr[4].ToString().Length != 0 && dr[5].ToString().Length != 0 && dr[6].ToString().Length != 0 && dr[7].ToString().Length != 0
- && dr[8].ToString().Length != 0 && dr[9].ToString().Length != 0 && dr[10].ToString().Length != 0)
- {
- // 데이타 추출 및 포맷 적용
- string RECEIVER_ID = Int32.Parse(dr["RECEIVER_ID"].ToString()).ToString("D3");
- // cyim 2016.04.01 : 6자리 혹은 4자리로 맵아이디와 그룹아이디 지정할수 있도록함
- string MAP_NO = "";
- if (_Data.Project_MapGroupIDTypeNumber == "6")
- MAP_NO = Int32.Parse(dr["MAP_NO"].ToString()).ToString("D7"); // cyim 2015.10.30 : 포맷변경 포함 5->7, 즉 2번째 Map no 가 7자리로 변경
- else
- MAP_NO = Int32.Parse(dr["MAP_NO"].ToString()).ToString("D5");
- string MAP_TYPE = dr["MAP_TYPE"].ToString();
- string PROCESS_TYPE = dr["PROCESS_TYPE"].ToString();
- string COMM_ID = Int32.Parse(dr["COMM_ID"].ToString()).ToString("D3");
- string BOARD_ID = Int32.Parse(dr["BOARD_ID"].ToString()).ToString("D3");
- string LOOP_NO = Int32.Parse(dr["LOOP_NO"].ToString()).ToString("D3");
- string REPEATER_ID = Int32.Parse(dr["REPEATER_ID"].ToString()).ToString("D3");
- string DEVICE_ID = Int32.Parse(dr["DEVICE_ID"].ToString()).ToString("D3");
- string INOUT_TYPE = dr["INOUT_TYPE"].ToString();
- string USE_FLAG = dr["USE_FLAG"].ToString();
- // 구분자 포함하여 레코드 단위 생성
- Contents.Append(
- RECEIVER_ID + "|" +
- MAP_NO + "|" +
- MAP_TYPE + "|" +
- PROCESS_TYPE + "|" +
- COMM_ID + "|" +
- BOARD_ID + "|" +
- LOOP_NO + "|" +
- REPEATER_ID + "|" +
- DEVICE_ID + "|" +
- INOUT_TYPE + "|" +
- USE_FLAG + "|"
- //+ _Text.CarrageReturn // cyim 2016.03.29 : 통신데몬과 마차가지로 개행문자 삭제
- );
- }
- }
- // 프로그레스바 Value값 1증가
- ProgressBarWorking_SendMessage_Event();
- //
- // 파일생성
- //
- _Cfg.Create_Cfg(Contents.ToString(), this.editBox_ProjectPath.Text + "\\" + _Text.DEFALUT_MAPPROCESS_FILENAME);
- // 프로그레스바 Value값 1증가
- ProgressBarWorking_SendMessage_Event();
- // 저장버튼 및 닫기버튼 사용하게...
- Delegate_UiButton();
- }
- // 팝업에서 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으로 고정시킨다 카운터를 세기위해 프로그레스바가 너무 부하가 걸리므로)
- int ProgressBar_TotalCount = 3;
- // ProgressBar의 Maximum값을 구하기 위해서
- // ProgressBar_TotalCount = ProgressBar_TotalCount;
- // ProgressBar의 Maximum값 저장
- UiProgressBar_MapProcess.Maximum = ProgressBar_TotalCount;
- // UiProgressBar 초기값 셋팅
- UiProgressBar_MapProcess.Value = 0;
- // 스레드 생성
- Thread WorkingThread = new Thread(new ThreadStart(MapProcess_DataCreate));
- // 스레드시작
- WorkingThread.Start();
- }
- // 대화 팝업은 특별처리(이벤트 해제)
- _Event.PopupClose_SendMessage_Event -= new _Event.PopupClose_SendMessage_Handler(_Event_PopupClose_SendMessage_Event);
- }
- }
- }
|