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();
-
-
-
- public Form1()
- {
- InitializeComponent();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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;
-
- }
- 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;
- 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);
- }
-
-
-
-
-
- private void FileSettingBtn_Click(object sender, EventArgs e)
- {
- string FSBLocation = Environment.CurrentDirectory + "\\Login.ini";
- try
- {
- System.Diagnostics.Process.Start(FSBLocation);
- }
- catch
- {
- FileError(FSBLocation);
- }
- }
-
-
-
-
-
- private void FileMatchBtn_Click(object sender, EventArgs e)
- {
- string FSBLocation = Environment.CurrentDirectory + "\\SettingFile.csv";
- try
- {
- System.Diagnostics.Process.Start(FSBLocation);
- }
- catch
- {
- FileError(FSBLocation);
- }
- }
-
-
-
-
-
- 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) + " 파일을 찾을 수 없음 : " + 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();
-
- 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)
- {
- 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();
- }
-
-
-
- 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(',');
- 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();
- }
- }
- }
|