123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444 |
- 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.Net.Sockets;
- using System.Net;
- using System.Threading;
- using System.Timers;
- using System.Diagnostics;
- namespace DataGateWayProject
- {
- public partial class Form1 : Form
- {
- LogFileCreate LFC = new LogFileCreate();
- My_TimerThread MTT = new My_TimerThread();
- //System.Threading.Timer timer_NetStat;
- //private Object iCosCommObj = new Object();
- //Stopwatch sw = new Stopwatch();
- public Form1()
- {
- InitializeComponent();
- }
- //public void Timer_netStat() //iCOS 연결 상태 확인 쓰레드 동작 함수
- //{
- // timer_NetStat = new System.Threading.Timer(net_state_Thread,null,1,9000);
- //}
- //bool changed = false;
- //public void net_state_Thread(object status)//(object sender, ElapsedEventArgs e) //iCOS 연결 상태 확인 쓰레드 함수
- //{
- // GetData_From_iCos GFI = new GetData_From_iCos();
- // string connectstate = "";
- // //lock (iCosCommObj)
- // //{
- // try
- // {
- // connectstate = GFI.GetConnectionStatus();
- // if (connectstate == "iCOS 통신 중")
- // {
- // if (changed == true)
- // {
- // Wirte_logbox_State(Convert.ToString(DateTime.Now) + " iCOS 통신 연결" + Environment.NewLine);
- // LFC.Log("iCOS 통신 연결" + Environment.NewLine);
- // }
- // changed = false;
- // }
- // else
- // {
- // Wirte_logbox_State(Convert.ToString(DateTime.Now) + " iCOS 통신 끊김" + Environment.NewLine);
- // LFC.Log("iCOS 통신 끊김" + Environment.NewLine);
- // changed = true;
- // }
- // Wirte_Textbox_State(connectstate);
- // }
- // 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 DelegateTextbox(string theValue);
- //private void Wirte_Textbox_State(string theValue) //통신상태 변화 Form text box에 적용 함수
- //{
- // try
- // {
- // if (this.Net_Stat.InvokeRequired)
- // {
- // DelegateTextbox d = new DelegateTextbox(Wirte_Textbox_State);
- // this.Invoke(d, new object[] { theValue });
- // }
- // else
- // {
- // this.Net_Stat.Text = theValue;
- // }
- // }
- // catch (Exception E)
- // {
- // LFC.Log("[Form] DelegateTextbox 오류 : " + E + Environment.NewLine);
- // }
- //}
- //private delegate void DelegateLogbox(string theValue);
- //private void Wirte_logbox_State(string theValue) //통신상태 변화 Form text box에 적용 함수
- //{
- // try
- // {
- // if (this.LogTxt.InvokeRequired)
- // {
- // DelegateLogbox d = new DelegateLogbox(Wirte_logbox_State);
- // 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] DelegateLogbox 오류 : " + E + Environment.NewLine);
- // }
- //}
- private void Form1_Load(object sender, EventArgs e)
- {
- ProStartBtn.Enabled = false; //시작 버튼 비활성화
- ProStopBtn.Enabled = false; //중단 버튼 비활성화
- PointSetBtn.Enabled = false; //관제점 등록 버튼 비활성화
- PointUnRegBtn.Enabled = false; //관제점 해제 버튼 비활성화
- AllValueCheck_btn.Enabled = false; // 일관 확인 버튼 비활성화
- RequestValue_btn.Enabled = false; //특정 값 확인 버튼 비활성화
- //Timer_netStat(); //iCOS 네트워크 연결 확인 함수
- }
- private void ProStartBtn_Click(object sender, EventArgs e) //시작버튼 함수
- {
- FolderBrowserDialog();
- if (toolStripStatusLabel1.Text != "")//경로 설정 확인
- {
- try
- {
- EndTxt.Clear(); //모니터링 종료시간 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; //성능분석시 버튼 비활성화
- FirstCheck FC = new FirstCheck();
- FC.Check_DailyData();
- OneMinute_Insert OMI = new OneMinute_Insert();
- OMI.Today_PeakMinMax();
- OMI.Year_PeakMinMax();
- MTT.timer2start();
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- catch (Exception eProStart)
- {
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 프로그램 오류 : " + eProStart + Environment.NewLine);
- LFC.Log("프로그램 오류 : " + eProStart + Environment.NewLine);
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- }
- else
- MessageBox.Show("경로를 설정해주세요");
- }
- private void ProStopBtn_Click(object sender, EventArgs e) //중단
- {
- GetData_From_iCos GFi = new GetData_From_iCos();
- GFi.StopTimer();
- MTT.timer2Stop();
- FileSettingBtn.Enabled = true; //프로젝트 설정 버튼 활성화
- FileMatchBtn.Enabled = true; //관제점설정 버튼 활성화
- FileExpBtn.Enabled = true; //성는분석식 버튼 활성화
- ProStartBtn.Enabled = true;
- EndTxt.Text = Convert.ToString(DateTime.Now);
- LFC.Log("프로그램 중단" + Environment.NewLine);
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 프로그램 중단 " + Environment.NewLine);
- ProStopBtn.Enabled = false;
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- private void ProSetBtn_Click(object sender, EventArgs e) //접속 설정
- {
- SettingForm SF = new SettingForm();
- SF.ShowDialog();
- }
- private void ProPathBtn_Click_1(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);// Login 파일에 접근
- }
- 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)// 오류 같음[Matching.csv => SettingFile.csv]
- {
- if ((!Error.Contains("Login.ini")) || (!Error.Contains("expression.csv")) || (!Error.Contains("Matching.csv")))
- {
- MessageBox.Show("파일을 찾을 수 없음");
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 파일을 찾을 수 없음 : " + Error + Environment.NewLine);
- LFC.Log("파일을 찾을 수 없음 : " + Error + 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 Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (MessageBox.Show("프로그램을 종료하시겠습니까?", "종료", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- MTT.timer2Stop();
- // 스레드 종료
- Application.ExitThread();
- for (int i = 0; i < 1000000; i++) {; }
- // 프로세스 종료
- Application.Exit();
- // 프로세스가 남아있다면 최종 종료 (2개의 프로젝트가 공존하고 Application.ProductName 값이 2개다
- System.Diagnostics.Process[] mProcess = System.Diagnostics.Process.GetProcessesByName(Application.ProductName);
- foreach (System.Diagnostics.Process p in mProcess)
- p.Kill();
- // 최종 정리 (보완코드 : 크로스 스레드 문제 발생 여지가 있으므로 사용주의)
- Environment.Exit(0);
- LFC.Log("사용자에 의해 프로그램이 종료되었습니다.");
- }
- else
- {
- LFC.Log("사용자에 의해 프로그램 종료가 취소되었습니다.");
- e.Cancel = true;
- return;
- }
- }
- private void PointSetBtn_Click(object sender, EventArgs e) //관제점 등록
- {
- bool ReadTag_Result;
- GetData_From_iCos GFi = new GetData_From_iCos();
- ReadTag_Result = GFi.ReadTag();
- if (ReadTag_Result == true)
- {
- LFC.Log("관제점 등록 완료 " + Environment.NewLine);
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " 관제점 등록 완료" + Environment.NewLine);
- ProStartBtn.Enabled = true;
- PointUnRegBtn.Enabled = true;
- GFi.GetValueTimer();
- Thread.Sleep(4500);
- RequestValue_btn.Enabled = true;
- AllValueCheck_btn.Enabled = true;
- }
- else
- {
- LFC.Log("관제점 등록 실패 " + Convert.ToString(DateTime.Now));
- 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 접속
- {
- GetData_From_iCos GetData = new GetData_From_iCos();
- string ReturnValue = GetData.iCos3_Conn();
- if (ReturnValue == "SUCCESS")
- {
- EndTxt.Clear();
- LFC.Log("iCOS 접속 성공" + Environment.NewLine);
- LogTxt.AppendText(Convert.ToString(DateTime.Now) + " iCOS 접속 성공" + Environment.NewLine);
- PointSetBtn.Enabled = true;
- }
- 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 Btn_SettingFile_Click(object sender, EventArgs e) //설정파일 생성 버튼
- {
- Creating_Setting_File CSF = new Creating_Setting_File();
- CSF.Create_Setting_Point_File();
- }
- private void Btn_TagSetFile_Click(object sender, EventArgs e) //태그등록파일 생성 버튼
- {
- Creating_Setting_File CSF = new Creating_Setting_File();
- CSF.Create_Point_File();
- }
- 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") + " ***");
- try
- {
- string tag = RequestValue.Text; //태그값
- string temp = GetData_From_iCos.Key_Value_Dic[RequestValue.Text];
- LogTxt.AppendText('"' + tag + '"' + " 의 값 : " + temp + Environment.NewLine);
- LogTxt.AppendText("***********************************" + Environment.NewLine);
- LFC.Log('"' + tag + '"' + " 의 값 : " + temp);
- LFC.Log("***************************************" + Environment.NewLine);
- }
- catch (Exception er)
- {
- MessageBox.Show("오류 발생");
- LogTxt.AppendText("오류 발생 : " + er);
- LFC.Log("오류 발생 : " + er);
- }
- }
- else
- {
- MessageBox.Show("확인 값이 없습니다.");
- return;
- }
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- /// <summary>
- /// 패킷분석 기능 추가
- /// </summary>
- private void AllValueCheck_btn_Click(object sender, EventArgs e) //값 일괄 확인 버튼
- {
- string[] sArray = File.ReadAllLines("TagSetFile.csv", Encoding.Default);
- GetData_From_iCos GFi = new GetData_From_iCos();
- LogTxt.AppendText("*** 현재 시간 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***" + Environment.NewLine);
- LFC.Log("****** 현재 시간 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " *****");
- try
- {
- for (int i = 0; i < sArray.Length; i++)
- {
- string[] tmp = sArray[i].Split(','); // tmp[0] = index, tmp[1] = Tag명.
- string a = GFi.GetTagValue(tmp[1]);
- LogTxt.AppendText('"' + tmp[1] + '"' + " 의 값 : " + GetData_From_iCos.Key_Value_Dic[tmp[1]] + Environment.NewLine);
- LFC.Log('"' + tmp[1] + '"' + " 의 값 : " + GetData_From_iCos.Key_Value_Dic[tmp[1]]);
- }
- LogTxt.AppendText("***********************************" + Environment.NewLine);
- LFC.Log("********************************************" + Environment.NewLine);
- }
- catch (Exception er)
- {
- LogTxt.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 오류 발생 : " + er + Environment.NewLine);
- LFC.Log("오류 발생 : " + er + Environment.NewLine);
- MessageBox.Show("오류 발생 : " + er);
- }
- LogTxt.Select(LogTxt.Text.Length, 0);
- LogTxt.ScrollToCaret();
- }
- }
- }
|