123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using Microsoft.Win32;
- using System.Diagnostics;
- namespace IControls_FireManager
- {
- public partial class Main : Form
- {
-
- int MainTimerTick_Cnt = 0;
-
-
- string User = null;
-
- string Receiver_Project_Path = null;
- string Usb_Update_Path = Environment.CurrentDirectory + "\\Update";
-
- string txt = null;
- public Main(string UserID)
- {
- InitializeComponent();
- User = UserID;
-
-
- this.radioButton_EventLogDel_All.Checked = true;
- try
- {
-
- RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\I_FPER_COMM_DAEMON", false);
- string Temp_DATABASE_NAME = rk.GetValue("DATABASE_NAME").ToString();
- string Registry_DATABASE_NAME = Temp_DATABASE_NAME;
- string Registry_DATABASE_NAME_IP = Temp_DATABASE_NAME.Substring(0, Temp_DATABASE_NAME.IndexOf(":"));
- string Registry_DATABASE_NAME_PATH = Temp_DATABASE_NAME.Substring(Temp_DATABASE_NAME.IndexOf(":") + 1);
- string Registry_Project_Directory = rk.GetValue("PROJECT_DIR").ToString();
- _Db.DB_FullPath = Registry_DATABASE_NAME_PATH;
- }
- catch
- {
- ;
- }
- }
-
- private void checkBox_EventLogDel_CheckedChanged(object sender, EventArgs e)
- {
- this.radioButton_EventLogDel_All.Enabled = this.radioButton_EventLogDel_Day.Enabled = this.checkBox_EventLogDel.Checked;
- this.dateTimePicker1.Enabled = this.dateTimePicker2.Enabled = this.radioButton_EventLogDel_Day.Checked;
- }
-
- private void radioButton_EventLogDel_Day_CheckedChanged(object sender, EventArgs e)
- {
- this.dateTimePicker1.Enabled = this.dateTimePicker2.Enabled = this.radioButton_EventLogDel_Day.Checked;
- }
-
- private void button_Start_Click(object sender, EventArgs e)
- {
-
- txt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " [" + User + "] \r\n";
-
- if (this.textBox_Comment.Text.Trim().Length == 0)
- {
- MessageBox.Show("반드시 사유를 입력 하셔야됩니다");
- return;
- }
-
- if (this.checkBox_FileUpdate.Checked == false && this.checkBox_EventLogDel.Checked == false)
- {
- MessageBox.Show("최소한 하나 이상은 선택하셔야됩니다");
- return;
- }
- txt = txt + string.Format(" 사유 : {0}\r\n", this.textBox_Comment.Text);
-
- if (this.checkBox_FileUpdate.Checked == true)
- {
- string[] files = Directory.GetFiles(Usb_Update_Path);
- string[] folders = Directory.GetDirectories(Usb_Update_Path);
-
- if (files.Length == 0 && folders.Length == 0)
- { MessageBox.Show("업데이트 파일이 존재하지 않습니다"); return; }
- }
-
- MainTimerTick_Cnt = 0;
- _Timer_WindowBase.Delete("Main_Timer");
- _Timer_WindowBase.Create("Main_Timer", 1000, Main_Timer_Tick, true);
- }
-
-
- private void Main_Timer_Tick(object sender, EventArgs e)
- {
- try
- {
-
- this.label_Status.Text = string.Format("진행상황 : {0} 초 남았습니다.", 35 - MainTimerTick_Cnt);
-
- MainTimerTick_Cnt++;
-
- switch (MainTimerTick_Cnt)
- {
-
- case 1:
- this.checkBox_EventLogDel.Enabled = false;
- this.checkBox_FileUpdate.Enabled = false;
- this.checkBox_restart.Enabled = false;
- this.textBox_Comment.Enabled = false;
- this.button_Start.Enabled = false;
- break;
-
- case 2:
- if (_Diagnostics.Process_Excute("FLauncher") == true)
- _Diagnostics.Process_Delete("FLauncher", false);
- break;
-
- case 4:
- if (_Diagnostics.Process_Excute("FPER") == true)
- _Diagnostics.Process_Delete("FPER", false);
- break;
-
- case 7:
- if (_Diagnostics.Process_Excute("CommDaemon") == true)
- _Diagnostics.Process_Delete("CommDaemon", false);
- break;
-
- case 10:
- string FireBirdLogPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
- FireBirdLogPath += "\\Firebird\\Firebird_2_5\\firebird.log";
- if (File.Exists(FireBirdLogPath) == true)
- File.Delete(FireBirdLogPath);
- break;
-
- case 13:
-
- if (this.checkBox_EventLogDel.Checked == true)
- {
- txt = txt + " EventLogDel ";
- if (this.radioButton_EventLogDel_All.Checked == true)
- _Db.Execute(_Sql.Delete_Table("TB_EVENT_LOG", null));
- else
- {
-
- string start = this.dateTimePicker1.Value.ToShortDateString().Replace("-", "") + "00000000000";
- string end = this.dateTimePicker2.Value.ToShortDateString().Replace("-", "") + "99999999999";
-
- _Db.Execute(_Sql.DeleteEventLogDataTime(start, end));
-
- _Db.Execute(_Sql.DeleteCommandLogData(start, end));
- }
- }
- break;
-
- case 16:
- string folder = _Db.DB_FullPath.Replace("FPER.FDB", "");
-
- string[] files = Directory.GetFiles(folder);
- foreach (string file in files)
- {
- if (_Db.DB_FullPath != file)
- {
- File.Delete(file);
- }
- }
- break;
-
- case 19:
- {
-
- Receiver_Project_Path = _Db.DB_FullPath.Replace("DB\\FPER.FDB", "");
-
- string[] files_temp = Directory.GetFiles(Usb_Update_Path);
- if (files_temp.Length != 0)
- {
- Copy_Folder(Usb_Update_Path, Receiver_Project_Path);
- }
-
- string[] folders_temp = Directory.GetDirectories(Usb_Update_Path);
- if (folders_temp.Length != 0)
- {
- foreach (string folders in folders_temp)
- {
- string temp = Get_Folder(folders);
- if (temp == "DB")
- {
- string[] files_temp_db = Directory.GetFiles(Usb_Update_Path + "\\" + temp);
- if (files_temp_db.Length != 0)
- {
- Copy_Folder(Usb_Update_Path + "\\" + temp, Receiver_Project_Path + "\\" + temp);
- }
- }
- else if (temp == "mapview")
- {
- string[] folders_temp_mapview = Directory.GetDirectories(Usb_Update_Path + "\\" + temp);
-
- if (folders_temp_mapview.Length != 0)
- {
- foreach (string folders_temp_mapviews in folders_temp_mapview)
- {
- string folder_name = Get_Folder(folders_temp_mapviews);
- Copy_Folder(Usb_Update_Path + "\\" + temp + "\\" + folder_name, Receiver_Project_Path + "\\" + temp + "\\" + folder_name);
- }
- }
- }
- }
- }
- }
- break;
-
- case 35:
- try
- {
- if (this.checkBox_EventLogDel.Checked == true)
- {
- txt += " EventLogDel ";
- if (this.radioButton_EventLogDel_All.Checked == true)
- txt += "LogDel:All";
- else
- txt += "LogDel:Day[" + this.dateTimePicker1.Value.ToShortDateString() + "~" + this.dateTimePicker2.Value.ToShortDateString() + "]";
- }
-
- string history = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " >> Excute ";
- RegistryKey Set_Rk = Registry.LocalMachine.CreateSubKey("SOFTWARE").CreateSubKey("I_FPER_COMM_DAEMON");
- Set_Rk.SetValue("FireOperator", history);
-
- Write_Log("\r\n" + txt);
- }
- catch
- {
-
- Write_Log("\r\n" + "레지스트리접근권한 실패");
- }
-
- if (this.checkBox_restart.Checked == true)
- {
- Process myProcess = new Process();
- myProcess.StartInfo.WorkingDirectory = Receiver_Project_Path;
- myProcess.StartInfo.FileName = "FLauncher.exe";
-
- myProcess.Start();
- }
-
- this.label_Status.Text = string.Format("진행상황 : 처리완료되었습니다.");
-
- _Timer_WindowBase.Delete("Main_Timer");
-
- this.checkBox_EventLogDel.Enabled = true;
- this.checkBox_FileUpdate.Enabled = true;
- this.checkBox_restart.Enabled = true;
- this.textBox_Comment.Enabled = true;
- this.button_Start.Enabled = true;
- break;
- default:
- if (MainTimerTick_Cnt < 0)
- {
-
- if (this.checkBox_restart.Checked == true)
- {
- Process myProcess = new Process();
- myProcess.StartInfo.WorkingDirectory = Receiver_Project_Path;
- myProcess.StartInfo.FileName = "FLauncher.exe";
-
- myProcess.Start();
- }
-
- this.label_Status.Text = string.Format("진행상황 : 처리완료되었습니다.");
-
- _Timer_WindowBase.Delete("Main_Timer");
-
- this.checkBox_EventLogDel.Enabled = true;
- this.checkBox_FileUpdate.Enabled = true;
- this.checkBox_restart.Enabled = true;
- this.textBox_Comment.Enabled = true;
- this.button_Start.Enabled = true;
- }
- break;
- }
- }
- catch
- {
- ;
- }
- }
- public static void Write_Log(string txt)
- {
- try
- {
- string path = "C:\\fireguard\\Log.txt";
- if (!File.Exists(path))
- {
-
- string createText = txt;
- File.WriteAllText(path, createText);
- }
- else
- {
-
-
- string appendText = txt;
- File.AppendAllText(path, appendText);
- }
- }
- catch
- {
- ;
- }
- }
-
- private void Main_FormClosed(object sender, FormClosedEventArgs e)
- {
-
- 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);
- }
-
- public string Get_Folder(string path)
- {
- try
- {
- string[] foldernames = path.Split('\\');
- if (foldernames.Length != 0)
- {
- return foldernames[foldernames.Length - 1];
- }
- else
- return "";
- }
- catch
- {
- return null;
- }
- }
-
- public void Copy_Folder(string sourcePath, string targetPath)
- {
-
- string[] files = System.IO.Directory.GetFiles(sourcePath);
-
- foreach (string file in files)
- {
-
- if (!System.IO.Directory.Exists(targetPath))
- System.IO.Directory.CreateDirectory(targetPath);
- string fileName = System.IO.Path.GetFileName(file);
- string destfile = System.IO.Path.Combine(targetPath, fileName);
-
- System.IO.File.Copy(file, destfile, true);
- if (fileName == "FPER.FDB")
- {
- txt += string.Format("FDB Upate : {0} -> {1}\r\n",
- File.GetCreationTime(file),
- File.GetCreationTime(destfile)
- );
- }
- else if (fileName == "CommDaemon.exe")
- {
- txt += string.Format("CommDaemon Upate : {0} -> {1}\r\n",
- FileVersionInfo.GetVersionInfo(file).FileVersion,
- FileVersionInfo.GetVersionInfo(destfile).FileVersion
- );
- }
- else if (fileName == "FPER.exe")
- {
- txt += string.Format("FPER Upate : {0} -> {1}\r\n",
- FileVersionInfo.GetVersionInfo(file).FileVersion,
- FileVersionInfo.GetVersionInfo(destfile).FileVersion
- );
- }
- else if (fileName == "FLauncher.exe")
- {
- txt += string.Format("FLauncher Upate : {0} -> {1}\r\n",
- FileVersionInfo.GetVersionInfo(file).FileVersion,
- FileVersionInfo.GetVersionInfo(destfile).FileVersion
- );
- }
- txt += string.Format("File Upate : {0}\r\n", destfile);
- }
- }
- }
- }
|