123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745 |
- 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.Runtime.InteropServices;
- using System.IO;
- using System.Collections.Concurrent;
- using System.Threading;
- using System.Timers;
- namespace BEMSDataGateway
- {
- public partial class Form1 : Form
- {
- IcosComm iCosSocket; //iCos 통신클래스
- LogFileCreate LFC = new LogFileCreate(); //로그 기록 파일
- My_TimerThread MTT = new My_TimerThread();
- System.Timers.Timer timer_NetStat = new System.Timers.Timer();
- Parsing PS = new Parsing();
- string szICOS_IP; //iCos server 주소
- string szICOS_ID; //iCos server ID
- string szICOS_PW; //iCos server Password
- string szDB_IP; //iCos 프로젝트 DB 주소
- string szDB_NAME; //iCos 프로젝트 DB 이름
- string szDB_ID; //iCos 프로젝트 DB 접속 ID
- string szDB_PW; //iCos 프로젝트 DB 접속 비밀번호
- int nDB_TYPE = 1; //iCos 프로젝트 DB 종류 (0:MDB, 1:MS-SQL)
- public bool bConnect;
- public void CommResponse(string userid, int nType, int nSubType, Object obj) //iCOS 응답처리를 위한 함수
- {
- if (nType == 6)
- {
- if (nSubType == 2)
- {
- iCosLogInResponse _packet = (iCosLogInResponse)obj;
- string errMsg;
- if (_packet.nResult == 3) //로그인 성공
- {
- LFC.Log("iCOS 4 서버에 로그인 성공" + Environment.NewLine);
- }
- else //로그인 실패
- {
- if (_packet.nResult == 0)
- errMsg = "DB Error";
- else if (_packet.nResult == 1)
- errMsg = "Password Error";
- else if (_packet.nResult == 2)
- errMsg = "ID Error";
- else
- errMsg = "Other Errors";
- LFC.Log("[Form] iCOS4 서버 연결실패 : " + errMsg + Environment.NewLine);
- }
- }
- }
- else if (nType == 4) //알람
- {
- if (nSubType == 11)
- {
- //알람이 발생하면 여기로 들어온다.
- }
- else if (nSubType == 9) //ALARM_ACK_FROM_SERVER
- {
- //서버로 부터 알람에 대한 인지가 발생하면 여기로 들어온다.
- }
- else if (nSubType == 16) //ALARM_CHACK_ALL_PROCESS_FROM_SERVER
- {
- //서버로 부터 모든 알람에 대한 인지가 발생하면 여기로 들어온다.
- }
- else
- {
- // 그외에 알람관련 정보를 받으면 여기로 들어온다.
- }
- }
- else if (nType == 99)
- {
- //iCos 서버와의 접속이 끊기고 연결오류 발생시 여기로 들어온다.
- LFC.Log("[Form]iCos4 서버에 의해서 소켓 연결이 끊어졌습니다" + Environment.NewLine); ;
- }
- }
- public bool iCos4ConnectandLogin(string address, string id, string password)// iCOS4 네트워크 상태 파악 함수, 0 : 연결 안됨, 1: 정상 상태
- {
- bool bRet = false;
- if (iCosSocket.Connect(address, 6000, id, password)) //iCOS 소켓 연결
- {
- iCosSocket.IcosLogin(id, password); //iCOS 로그인
- bRet = true;
- }
- else
- {
- iCosSocket.Disconnect(id); //iCOS 소켓 연결 해제
- }
- return bRet;
- }
- public string iCos4Connect() //iCOS 연결 함수
- {
- string strRet = "";
- string Result_Connect_iCos = "";
- Readini Ri = new Readini();
- Ri.ReadData(); // ini의 설정값을 불러옴.
- szICOS_IP = Ri.IP1;
- szICOS_ID = Ri.ICOS_ID;
- szICOS_PW = Ri.ICOS_PASSWORD;
- nDB_TYPE = Convert.ToInt32(Ri.ICOSDB_TYPE);
- szDB_IP = Ri.ICOSDB_LOC;
- szDB_NAME = Ri.ICOSDB_NAME;
- szDB_ID = Ri.ICOSDB_ID;
- szDB_PW = Ri.ICOSDB_PASSWORD;
- try
- {
- if (!iCosSocket.InitTagAddress(nDB_TYPE, szDB_IP, szDB_NAME, szDB_ID, szDB_PW)) // iCOS DB 정보 가져옴
- {
- if (!iCosSocket.InitTagAddress(nDB_TYPE, szDB_IP, szDB_NAME, szDB_ID, szDB_PW)) //1차 실패시, iCOS DB 정보 다시 가져옴
- {
- Result_Connect_iCos = "iCOS 관제점 DB정보 설정 최종실패";
- return Result_Connect_iCos;
- }
- }
- iCosSocket.InitThread(); // iCoS 연결관리
- bool bRet = iCos4ConnectandLogin(szICOS_IP, szICOS_ID, szICOS_PW);
- if (bRet == false)
- {
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 실패" + Environment.NewLine);
- LFC.Log("iCOS 접속 실패");
- Result_Connect_iCos = "FAIL";
- }
- else
- {
- strRet = bRet.ToString();
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 시작" + Environment.NewLine);
- LFC.Log("iCOS 접속 시작");
- Result_Connect_iCos = "SUCCESS";
- }
- }
- catch (Exception)
- {
- Result_Connect_iCos = "FAIL";
- }
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- return Result_Connect_iCos;
- }
- string[] ReturnTag = new string[2];
- public void ReadTag() //iCOS 태그 등록 함수
- {
- int i;
- Parsing Ps = new Parsing();
- Control_Point_Group CPG = new Control_Point_Group();
- ReturnTag = Ps.TagParsing();
- i = iCosSocket.IcosRegTag(szICOS_ID, Convert.ToInt32(ReturnTag[1]), ReturnTag[0]);//Tag 등록
- if (i == 1)
- {
- LFC.Log("관제점 등록 완료 " + Environment.NewLine);
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 관제점 등록 완료" + Environment.NewLine);
- }
- else
- {
- LFC.Log("[Form] 관제점 등록 실패" + Environment.NewLine);
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 관제점 등록 실패" + Environment.NewLine);
- }
- PS.setIcosSocket(iCosSocket);
- CPG.setIcosSocket(iCosSocket);
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- System.Timers.Timer timer2 = new System.Timers.Timer();
- public int UnReg()//iCOS 태그 해제 함수
- {
- int i;
- ReturnTag = PS.TagParsing();
- Control_Point_Group CPG = new Control_Point_Group();
- i = iCosSocket.IcosUnregTag(szICOS_ID, Convert.ToInt32(ReturnTag[1]), ReturnTag[0]);//태그 등록 해제
- PS.setIcosSocket(iCosSocket);
- CPG.setIcosSocket(iCosSocket);
- if (i == 1)
- {
- LFC.Log("[Form] 관제점 해제 완료" + Environment.NewLine);
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 관제점 해제 완료" + Environment.NewLine);
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- return 1;
- }
- else
- {
- LFC.Log("[Form] 관제점 해제 실패" + Environment.NewLine);
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 관제점 해제 실패" + Environment.NewLine);
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- return 0;
- }
- }
- public Form1() //Form 함수
- {
- InitializeComponent(); //Form 초기화
- iCosSocket = new IcosComm();
- // iCos 통신클래스와 연동을 위한 딜리게이트 함수설정
- iCosSocket.iCosResponse += new IcosComm.iCosCallback(CommResponse);
- Timer_netStat(); //iCOS 네트워크 연결 확인 함수
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- ProStopBtn.Enabled = false;
- PointSetBtn.Enabled = false;
- PointUnRegBtn.Enabled = false;
- ProStartBtn.Enabled = false;
- ProStopBtn.Enabled = false;
- AllValueCheck_btn.Enabled = false;
- RequestValue_btn.Enabled = false;
- Shown += Form_Shown;
- }
- public void Timer_netStat() //iCOS 연결 상태 확인 쓰레드 동작 함수
- {
- timer_NetStat.Interval = 3000;
- timer_NetStat.Elapsed += new ElapsedEventHandler(net_state_Thread);
- timer_NetStat.Start();
- }
- bool changed = false;
- public void net_state_Thread(object sender, ElapsedEventArgs e) //iCOS 연결 상태 확인 쓰레드 함수
- {
- int nNet;
- string strRet;
- string connectstate = "";
- try
- {
- nNet = Convert.ToInt32(iCosSocket.GetConnectionStatus(szICOS_ID));
- strRet = nNet.ToString();
- if (strRet == "1")
- {
- if (changed == false)
- {
- connectstate = "ICOS 통신중";
- }
- else
- {
- Wirte_logtxt(Convert.ToString(DateTime.Now) + " ICOS와 통신 연결" + Environment.NewLine);
- Wirte_btn(PointSetBtn);
- }
- changed = false;
- }
- else
- {
- connectstate = "ICOS 통신끊김";
- changed = true;
- Wirte_logtxt(Convert.ToString(DateTime.Now) + " ICOS와 통신 끊김" + Environment.NewLine);
- }
- Wirte_Net_Stat(connectstate); // 통신상태 체크, 딜리게이트 활용: 스레드를 통한 Form UI 변경시 필요
- }
- catch (Exception E)
- {
- LFC.Log("[Form] net_state_Thread 오류 : " + E + Environment.NewLine);
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] net_state_Thread 오류 : " + E + Environment.NewLine);
- }
- }
- private delegate void myDelegate_button(Button btn);
- private void Wirte_btn(Button btn) //통신상태 변화 Form text box에 적용 함수
- {
- try
- {
- if (PointSetBtn.InvokeRequired)
- {
- myDelegate_button d = new myDelegate_button(Wirte_btn);
- this.Invoke(d, btn);
- }
- else
- {
- btn.PerformClick();
- }
- }
- catch (Exception E)
- {
- LFC.Log("[Form] Wirte_btn 오류 : " + E + Environment.NewLine);
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " [Form] Wirte_btn 오류 : " + E + Environment.NewLine);
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- }
- private delegate void myDelegate_error(string theValue);
- private void Wirte_logtxt(string theValue) //통신상태 변화 Form text box에 적용 함수
- {
- try
- {
- if (this.LogTxt.InvokeRequired)
- {
- myDelegate_error d = new myDelegate_error(Wirte_logtxt);
- this.Invoke(d, new object[] { theValue });
- }
- else
- {
- this.LogTxt.AppendText(theValue);
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- }
- catch (Exception E)
- {
- LFC.Log("[Form] Wirte_logtxt 오류 : " + E + Environment.NewLine);
- }
- }
- private delegate void myDelegate_state(string theValue);
- private void Wirte_Net_Stat(string theValue) //통신상태 변화 Form text box에 적용 함수
- {
- try
- {
- if (this.Net_Stat.InvokeRequired)
- {
- myDelegate_state d = new myDelegate_state(Wirte_Net_Stat);
- this.Invoke(d, new object[] { theValue });
- }
- else
- {
- this.Net_Stat.Text = theValue;
- }
- }
- catch (Exception E)
- {
- LFC.Log("[Form] Wirte_Net_Stat 오류 : " + E + Environment.NewLine);
- }
- }
- private void Form_Shown(object sender, EventArgs e) //Form 나타날때, 동작 함수
- {
- string ReturnValue = iCos4Connect();
- if (ReturnValue == "SUCCESS")
- {
- LFC.Log("iCOS 접속 성공");
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 성공" + Environment.NewLine);
- EndTxt.Clear();
- StartTxt.Text = Convert.ToString(DateTime.Now);
- Conn_iCos_Btn.Enabled = false;
- ProStartBtn.Enabled = false;
- ProStopBtn.Enabled = true;
- PointSetBtn.Enabled = true;
- PointUnRegBtn.Enabled = false;
- FileSettingBtn.Enabled = false;
- FileMatchBtn.Enabled = false;
- FileExpBtn.Enabled = false;
- }
- else
- {
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 실패" + Environment.NewLine);
- LFC.Log("iCOS 접속 실패" + Environment.NewLine);
- }
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- private void ProStartBtn_Click(object sender, EventArgs e) //시작 버튼 클릭 함수
- {
- FolderBrowserDialog();
- if (toolStripStatusLabel1.Text != "")
- {
- try
- {
- EndTxt.Clear();
- StartTxt.Text = Convert.ToString(DateTime.Now);
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 프로그램 시작" + Environment.NewLine);
- LFC.Log("프로그램 시작" + Environment.NewLine);
- ProStartBtn.Enabled = false; // 시작버튼 비활성화.
- ProStopBtn.Enabled = true;
- FileSettingBtn.Enabled = false;
- FileMatchBtn.Enabled = false;
- FileExpBtn.Enabled = false;
- AllValueCheck_btn.Enabled = true;
- RequestValue_btn.Enabled = true;
- FirstCheck FC = new FirstCheck();
- FC.Check_DailyData(); // Hour, Daily 테이블 삽입 및 업데이트
- OneMinute_Insert OMI = new OneMinute_Insert();
- OMI.Today_PeakMinMax();
- OMI.Year_PeakMinMax();
- MTT.timer2start();
- }
- catch (Exception eProStart)
- {
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 프로그램 DB 접속 오류 : " + eProStart + Environment.NewLine);
- LFC.Log("[Form] 프로그램 DB 접속 오류 : " + eProStart + Environment.NewLine);
- }
- }
- else
- {
- MessageBox.Show("경로를 설정해주세요");
- }
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- private void ProStopBtn_Click(object sender, EventArgs e) //스탑 버튼 클릭 함수
- {
- try
- {
- ProStartBtn.Enabled = true;
- ProStopBtn.Enabled = false;
- AllValueCheck_btn.Enabled = false;
- RequestValue_btn.Enabled = false;
- FileSettingBtn.Enabled = true;
- FileMatchBtn.Enabled = true;
- FileExpBtn.Enabled = true;
- EndTxt.Text = Convert.ToString(DateTime.Now);
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 프로그램 중단" + Environment.NewLine);
- LFC.Log("프로그램 중단" + Environment.NewLine);
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- MTT.timer2Stop();
- }
- catch (Exception ex)
- {
- LFC.Log("프로그램 중단 오류 : " + ex + Environment.NewLine);
- }
- }
- private void ProSetBtn_Click(object sender, EventArgs e) //접속 설정 클릭 함수
- {
- SettingForm SF = new SettingForm();
- SF.ShowDialog();
- }
- private void ProPathBtn_Click(object sender, EventArgs e)//프로젝트 설정 클릭 함수
- {
- System.Diagnostics.Process.Start("explorer.exe", Environment.CurrentDirectory);
- }
- /// <summary>
- /// 셋팅파일 불러오기 버튼
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void FileSettingBtn_Click(object sender, EventArgs e)
- {
- string FSBLocation = Environment.CurrentDirectory + "\\Login.ini";
- try
- {
- System.Diagnostics.Process.Start(FSBLocation);
- }
- catch
- {
- FileError(FSBLocation);
- }
- }
- /// <summary>
- /// 매칭파일 불러오기 버튼
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void FileMatchBtn_Click(object sender, EventArgs e)
- {
- string FSBLocation = Environment.CurrentDirectory + "\\SettingFile.csv";
- try
- {
- System.Diagnostics.Process.Start(FSBLocation);
- }
- catch
- {
- FileError(FSBLocation);
- }
- }
- /// <summary>
- /// 수식파일 불러오기 버튼
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void FileExpBtn_Click(object sender, EventArgs e)
- {
- string FSBLocation = Environment.CurrentDirectory + "\\Expression.csv";
- try
- {
- System.Diagnostics.Process.Start(FSBLocation);
- }
- catch
- {
- FileError(FSBLocation);
- }
- }
- public void FileError(string Error) // 파일 읽어오기 에러 확인 삼수
- {
- if ((!Error.Contains("Login.ini")) || (!Error.Contains("expression.csv")) || (!Error.Contains("Matching.csv")))
- {
- MessageBox.Show("파일을 찾을 수 없음");
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 파일을 찾을 수 없음" + Environment.NewLine);
- LFC.Log("파일을 찾을 수 없음 : " + Environment.NewLine);
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- }
- public void FolderBrowserDialog()
- {
- toolStripStatusLabel1.Text = Environment.CurrentDirectory;
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 경로 설정 완료" + Environment.NewLine);
- LogTxt.AppendText(toolStripStatusLabel1 + Environment.NewLine);
- LFC.Log("경로설정완료");
- LFC.Log("경로 : " + toolStripStatusLabel1 + Environment.NewLine);
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- private void EraseLog_Click(object sender, EventArgs e) // 로그 박스에 로그 기록 삭제 함수
- {
- LogTxt.Clear();
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- private void Form_FormClosing(object sender, FormClosingEventArgs e)// 프로그램 종료 이벤트
- {
- if (MessageBox.Show("프로그램을 종료하시겠습니까?", "종료", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- LFC.Log("사용자에 의해 프로그램이 종료되었습니다." + Environment.NewLine);
- MTT.timer2Stop();
- Dispose();
- }
- else
- {
- LFC.Log("사용자에 의해 프로그램 종료가 취소되었습니다.");
- e.Cancel = true;
- return;
- }
- }
- private void PointSetBtn_Click(object sender, EventArgs e) //관제점 등록 함수
- {
- int nNet;
- string strRet;
- nNet = Convert.ToInt32(iCosSocket.GetConnectionStatus(szICOS_ID));
- strRet = nNet.ToString();
- if (strRet == "1")
- {
- ReadTag(); //관제점 등록
- AllValueCheck_btn.Enabled = true;
- RequestValue_btn.Enabled = true;
- ProStartBtn.Enabled = true;
- PointUnRegBtn.Enabled = true;
- }
- else
- {
- LFC.Log("관제점 등록 실패!!" + Environment.NewLine);
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 관제점 등록 실패!!" + Environment.NewLine);
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- }
- private void Conn_iCos_Btn_Click(object sender, EventArgs e) //iCOS 연결 클릭 함수
- {
- string ReturnValue = iCos4Connect(); //iCOS 연결
- if (ReturnValue == "SUCCESS")
- {
- StartTxt.Text = Convert.ToString(DateTime.Now);
- EndTxt.Clear();
- Conn_iCos_Btn.Enabled = false;
- ProStartBtn.Enabled = false;
- ProStopBtn.Enabled = true;
- PointSetBtn.Enabled = true;
- PointUnRegBtn.Enabled = true;
- LFC.Log("iCOS 접속 성공" + Environment.NewLine);
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 성공" + Environment.NewLine);
- }
- else
- {
- LFC.Log("iCOS 접속 실패" + Environment.NewLine);
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 실패" + Environment.NewLine);
- }
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- private void PointUnRegBtn_Click(object sender, EventArgs e) //관제점 해제 클릭 함수
- {
- int i;
- i = UnReg(); //관제점 해제
- if (i == 1)
- {
- PointUnRegBtn.Enabled = false;
- AllValueCheck_btn.Enabled = false;
- RequestValue_btn.Enabled = false;
- ProStartBtn.Enabled = false;
- }
- else
- {
- PointUnRegBtn.Enabled = true;
- }
- }
- private void Btn_TagSetFile_Click(object sender, EventArgs e) //TagSetFile 클릭 함수, TagSetFile 파일 생성
- {
- Creating_Setting_File CSF = new Creating_Setting_File();
- CSF.Create_Point_File();
- }
- private void Btn_SettingFile_Click(object sender, EventArgs e)//SettingFile 클릭 함수, SettingFile 파일 생성
- {
- Creating_Setting_File CSF = new Creating_Setting_File();
- CSF.Create_Setting_Point_File();
- }
- private void AllValueCheck_btn_Click(object sender, EventArgs e)//일괄 출력 클릭 함수
- {
- string[] sArray = File.ReadAllLines("TagSetFile.csv", Encoding.Default);
- LogTxt.AppendText("*** 현재 시간 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
- LFC.Log("*** 현재 시간 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
- try
- {
- for (int i = 0; i < sArray.Length; i++)
- {
- string[] tmp = sArray[i].Split(','); // tmp[0] = index, tmp[1] = Tag명.
- LogTxt.AppendText('"' + tmp[1] + '"' + " 의 값 : " + iCosSocket.IcosGetTagValue(tmp[1]) + Environment.NewLine);
- LFC.Log('"' + tmp[1] + '"' + " 의 값 : " + iCosSocket.IcosGetTagValue(tmp[1]));
- }
- LogTxt.AppendText("**********************************" + Environment.NewLine);
- LFC.Log("**********************************" + Environment.NewLine);
- }
- catch (Exception er)
- {
- MessageBox.Show("오류 발생");
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 오류 발생 : " + er);
- LFC.Log("오류 발생 = " + er);
- }
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- private void RequestValue_btn_Click(object sender, EventArgs e) //특정 값 출력 함수
- {
- if (RequestValue.Text != "")
- {
- LogTxt.AppendText("*** 현재 시간 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
- LFC.Log("*** 현재 시간 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
- try
- {
- string tmp = RequestValue.Text; //태그값
- LogTxt.AppendText('"' + tmp + '"' + " 의 값 : " + iCosSocket.IcosGetTagValue(tmp) + Environment.NewLine);
- LogTxt.AppendText("**********************************" + Environment.NewLine);
- LFC.Log(tmp + " 의 값 : " + iCosSocket.IcosGetTagValue(tmp) + Environment.NewLine);
- LFC.Log("**********************************" + Environment.NewLine);
- }
- catch (Exception er)
- {
- MessageBox.Show("오류 발생");
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 오류 발생 : " + er);
- LFC.Log("오류 발생 : " + er);
- }
- }
- else
- {
- MessageBox.Show("확인 값이 없습니다.");
- return;
- }
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- private void RequestValue_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == 8) //백스페이스할때, 데이터 삭제
- {
- if (RequestValue.Text.Length != 0)
- {
- RequestValue.Text = RequestValue.Text.Substring(0, RequestValue.Text.Length - 1);
- RequestValue.Select(RequestValue.Text.Length, 0);
- e.Handled = true;
- }
- else
- {
- e.Handled = true;
- }
- }
- else
- {
- RequestValue.Select(RequestValue.Text.Length, 0); //현재 데이터 뒤로 포커스 이동
- }
- }
- private void RequestValue_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
- {
- if (e.Control && e.KeyCode == Keys.A) //Ctrl + A 동작
- {
- ((TextBox)sender).SelectAll();
- }
- if (e.Control && e.KeyCode == Keys.C) //Ctrl + C 동작
- {
- ((TextBox)sender).Copy();
- }
- if (e.Control && e.KeyCode == Keys.V) //Ctrl + V 동작
- {
- ((TextBox)sender).Paste();
- }
- if (e.Control && e.KeyCode == Keys.X) //Ctrl + X 동작
- {
- ((TextBox)sender).Cut();
- }
- }
- private void DBAddressTxt_TextChanged(object sender, EventArgs e)
- {
- }
- private void DBNameTxt_TextChanged(object sender, EventArgs e)
- {
- }
- }
- }
|