123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data;
- using System.Net.NetworkInformation;
- using System.Collections;
- using System.Runtime.InteropServices;
- using System.Drawing;
- using Microsoft.Win32;
- using System.Net.Sockets;
- using System.Threading;
- using System.Net; // cyim 2016.12.26 : UI 이탈방지 코드 추가 (후킹)
- namespace FPER
- {
- // cyim 2015.6.24 소스 정리
- // 공용으로 사용하는 클래스와 변수를 _Data.cs 에서 사용한다
- // 기존에 Static 으로 구성된 것은 어쩔수없지만, 기존 개발자가 만든 파일들을 모두 정리하는 것은 불가능하다
- // 공용 변수
- public static class _Data
- {
- // cyim 2016.12.26 : UI 이탈방지 코드 추가 (후킹)
- public static string Hook_Enable = null;
- // cyim 2016.12.20 : 현장명 사용자 지정
- public static string Site_Name = null;
- // cyim 2015.7.29 수신반 모드
- // 수신반 모드 여부 (0:평상시모드, 1:수신반모드)
- // 수신반 모드에서는 레지스트리 값을 이용하지 않고 데이터베이스에서 읽은 값을 토대로 셋팅된다
- public static bool FireDeskMode = false;
- // 수신기 아이디 해쉬테이블 (key : id, data : class type - FireDeskReceiver)
- public static Hashtable Hash_Receiver = new Hashtable();
- // 수신기 아이디 배열
- public static string[] Hash_Receiver_keys = null;
- // cyim 2015.7.29 수신반 루틴을 위해 외부 파라미터로 동작하도록 수정 : 레지스트리값을 여기서 다 읽고 처리함 (1회만 읽으면 된다)
- public static int Registry_ReceiverID = 0;
- public static string Registry_DATABASE_NAME = null; // IP + PATH
- public static string Registry_DATABASE_NAME_IP = null; // IP
- public static string Registry_DATABASE_NAME_PATH = null; // PATH
- public static bool Registry_MonitorDaemon_Enable = false; // 모니터데몬 상태 (1이면 네트워크 수신기)
- public static string Registry_MonitorDaemon_IP = null; // 모니터데몬 아이피
- public static string Registry_Project_Directory = null; // 프로젝트 폴더 경로 : 예) D:\FireTest
- // cyim 2015.8.3 수신반 연동기능 추가 : 수신반 운영모드 팝업창
- public static bool FireDesk_Operation_Enable = false;
- // cyim 2015.9.1 통합조회창기능 추가
- public static bool FireDesk_FormLogView_Enable = false;
- // cyim 2015.9.11 : 과거내역 통합조회창에서 사용할 DB 에서 미리 읽은값을 사용하도록 수정함
- public static DataTable dtBoardList = null;
- public static DataTable dtRepeaterList2 = null;
- public static DataTable dtAnalogDetecterLevel = null;
- public static DataTable dtDeviceDBList2 = null;
- // cyim 2016.12.16 : 모바일앱 연동
- public static string MOBILE_ENABLE = null;
- // cyim 2016.12.20 : 푸시메세지 연동 기능 추가
- public static string GCM_ENABLE = null;
- public static string GCM_API_KEY = null;
- public static string GCM_TEST_MODE = null;
- public static string GCM_INFO_FIRE = null; //; 화재
- public static string GCM_INFO_FACILITY = null; //; 설비
- public static string GCM_INFO_COMERROR = null; //; 통신에러
- public static string GCM_INFO_BLOCK = null; //; 단선
- public static string GCM_INFO_CUT = null; //; 차단
- public static string GCM_INFO_CHECK = null; //; 점검
- // 디버깅 창 열림 확인
- public static bool Enable_Form_Debug = false;
- // 로그 표시
- public static bool Enable_Log = false;
- }
- //
- // 추가 클래스는 아래에 정리된다
- //
- // cyim 2015.8.4 수신반을 위한 static 클래스 정리
- ////
- //// cyim 2014.5.7 : 수신기설정정보 변경 (하단 주석처리하고 변수는 전역으로 처리한다)
- ////
- ////public static class _frmReceiverConfig_Data
- ////{
- //// // cyim 2014.5.7 : 수신기설정정보 변경
- //// //public static Boolean receiverConfig_Change_Flag = false;
- ////}
- //
- // cyim 2014.5.8 : 프로세스 관리 클래스 추가
- //
- public static class _Diagnostics
- {
- public static void Process_Kill(string ProcessName)
- {
- try
- {
- if (ProcessName != null)
- {
- System.Diagnostics.Process[] mProcess = System.Diagnostics.Process.GetProcessesByName(ProcessName);
- foreach (System.Diagnostics.Process p in mProcess)
- p.Kill();
- }
- }
- catch (Exception ex)
- {
- Util.UErrorMessage(ex, 0, 0);
- }
- }
-
- //
- // cyim 2017.01.23 : Explorer 프로세스 제어 루틴 추가
- //
- public static bool Process_Status(string ProcessName)
- {
- try
- {
- if (ProcessName != null)
- {
- System.Diagnostics.Process[] mProcess = System.Diagnostics.Process.GetProcessesByName(ProcessName);
- foreach (System.Diagnostics.Process p in mProcess)
- return true;
- }
- return false;
- }
- catch (Exception ex)
- {
- Util.UErrorMessage(ex, 0, 0);
- return false;
- }
- }
-
- public static void taskkill_explorer()
- {
- string Explorer_Path = null;
- Explorer_Path = "C:\\Windows\\explorer.exe";
- if (_Diagnostics.Process_Status("explorer") == true)
- {
- if (System.IO.File.Exists(Explorer_Path) == true)
- {
- System.Diagnostics.Process proc = new System.Diagnostics.Process();
- proc.EnableRaisingEvents = false;
- proc.StartInfo.FileName = "taskkill.exe";
- proc.StartInfo.Arguments = "/f /im explorer.exe";
- proc.Start();
- proc.Close();
- }
- }
- }
- public static void start_explorer()
- {
- string Explorer_Path = null; Explorer_Path = "C:\\Windows\\explorer.exe";
- if (_Diagnostics.Process_Status("explorer") == false)
- {
- if (System.IO.File.Exists(Explorer_Path) == true)
- {
- System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
- myProcess.StartInfo.FileName = Explorer_Path;
- myProcess.StartInfo.CreateNoWindow = false;
- myProcess.Start();
- myProcess.Close();
- }
- }
- }
- }
- //
- // cyim 2015.7.22 : 통신데몬 연결 핑테스트
- //
- public class _Ethernet
- {
- public PingOptions options = new PingOptions(); // cyim 2017.01.02 : Memory leak
- public bool Ping_SyncCheck(string DestIP)
- {
- try
- {
- if (DestIP == null || DestIP.Trim().Length == 0) return false;
- using (Ping pingSender = new Ping()) // cyim 2017.01.02 : Memory leak
- {
- options.DontFragment = true;
- string data = "0";
- byte[] buffer = Encoding.ASCII.GetBytes(data);
- PingReply reply = pingSender.Send(DestIP, 400, buffer, options); // cyim 2016.12.29 : 화면 멈춤 문제 수정
- if (reply.Status == IPStatus.Success)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- catch
- {
- return false;
- }
- }
-
- // 비동기 코드 테스트
- public void Ping_Async(string DestIP)
- {
- AutoResetEvent waiter = new AutoResetEvent(false);
- Ping pingSender = new Ping();
- pingSender.PingCompleted += new PingCompletedEventHandler(PingCompletedCallback);
- IPAddress address = IPAddress.Parse(DestIP);
- string data = "0";
- byte[] buffer = Encoding.ASCII.GetBytes(data);
- int timeout = 1000;
- PingOptions options = new PingOptions(64, true);
- pingSender.SendAsync(address, timeout, buffer, options, waiter);
- waiter.WaitOne();
- Console.WriteLine("Ping example completed.");
- }
- public void PingCompletedCallback(object sender, PingCompletedEventArgs e)
- {
- if (e.Cancelled)
- {
- Console.WriteLine("Ping canceled.");
- // 주 스레드가 진행되게 한다.
- // 유저토큰은 주 스레드가 대기하고 있는 AutoResetEvent 객체이다.
- ((AutoResetEvent)e.UserState).Set();
- }
- // 에러가 발생하면 메세지가 표시된다.
- if (e.Error != null)
- {
- Console.WriteLine("Ping failed:");
- Console.WriteLine(e.Error.ToString());
- // 주 스레드가 진행되게 한다.
- ((AutoResetEvent)e.UserState).Set();
- }
- PingReply reply = e.Reply;
- DisplayReply(reply);
- // 주 스레드가 진행되게 한다.
- ((AutoResetEvent)e.UserState).Set();
- }
- public void DisplayReply(PingReply reply)
- {
- if (reply == null)
- return;
- Console.WriteLine("ping status: {0}", reply.Status);
- if (reply.Status == IPStatus.Success)
- {
- //Console.WriteLine("Address: {0}", reply.Address.ToString());
- //Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
- //Console.WriteLine("Time to live: {0}", reply.Options.Ttl);
- //Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment);
- //Console.WriteLine("Buffer size: {0}", reply.Buffer.Length);
- }
- }
- }
- //
- // 공용 변환 함수
- //
- public static class _Convert
- {
- // 코딩 방식
- public enum Coding
- {
- Default, UTF8, ASCII
- }
- // 인코딩
- public static byte[] EncodingData(Coding coding, string Data)
- {
- byte[] data = null;
- switch (coding)
- {
- case Coding.Default:
- data = Encoding.Default.GetBytes(Data);
- break;
- case Coding.UTF8:
- data = Encoding.UTF8.GetBytes(Data);
- break;
- case Coding.ASCII:
- data = Encoding.ASCII.GetBytes(Data);
- break;
- }
- return data;
- }
- // 디코딩
- public static string DecodingData(Coding coding, byte[] Data)
- {
- string data = null;
- switch (coding)
- {
- case Coding.Default:
- data = Encoding.Default.GetString(Data);
- break;
- case Coding.UTF8:
- data = Encoding.UTF8.GetString(Data);
- break;
- case Coding.ASCII:
- data = Encoding.ASCII.GetString(Data);
- break;
- }
- return data;
- }
- // 어레이리스트를 구분자로 삽입하여 표시
- public static string ArrayList_to_String(ArrayList Datas, string spilt)
- {
- if (Datas == null || Datas.Count == 0) return "";
- string Temp = null;
- foreach (string Data in Datas)
- {
- Temp = Temp + Data + spilt;
- }
- Temp = Temp.TrimEnd(Convert.ToChar(spilt));
- return Temp;
- }
- }
- // cyim 2014.7.23 마우스 이벤트 강제로 발생
- public static class _MouseEvent
- {
- private const uint LBUTTONDOWN = 0x00000002; // 왼쪽 마우스 버튼 누름
- private const uint LBUTTONUP = 0x00000004; // 왼쪽 마우스 버튼 땜
- [DllImport("user32.dll")]
- static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo);
- [DllImport("user32.dll")]
- static extern int SetCursorPos(int x, int y);
- // 특정 좌표에 클릭을 발생시킨다
- public static void Click(int x, int y)
- {
- Point pt = new Point(x, y);
- SetCursorPos(pt.X, pt.Y);
- mouse_event(LBUTTONDOWN, (uint)pt.X, (uint)pt.Y, 0, 0);
- mouse_event(LBUTTONUP, (uint)pt.X, (uint)pt.Y, 0, 0);
- }
- }
- // cyim 2016.12.26 : UI 이탈방지 코드 추가 (후킹)
- public static class _Hook
- {
- public static void Enable_TaskMgr()
- {
- try
- {
- string subKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
- RegistryKey rk = Registry.CurrentUser;
- RegistryKey sk1 = rk.OpenSubKey(subKey);
- if (sk1 != null)
- rk.DeleteSubKeyTree(subKey);
- rk.Close();
- }
- catch
- {
- ;
- }
- }
- public static void Disable_TaskMgr()
- {
- RegistryKey rk;
- string keyValueInt = "1";
- string subKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
- try
- {
- rk = Registry.CurrentUser.CreateSubKey(subKey);
- rk.SetValue("DisableTaskMgr", keyValueInt);
- rk.Close();
- }
- catch
- {
- ;
- }
- }
- // cyim 2017.01.24 : Alt+Ctrl+Del 화면 변경
- public static void Enable_NoClose()
- {
- try
- {
- RegistryKey rk = null;
- RegistryKey sk1 = null;
- rk = Registry.LocalMachine;
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", true);
- if (sk1 != null) sk1.SetValue("NoClose", 0, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("HideFastUserSwitching", 0, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("DisableChangePassword", 0, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("DisableLockWorkstation", 0, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("DisableTaskMgr", 0, RegistryValueKind.DWord);
- rk = Registry.CurrentUser;
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", true);
- if (sk1 != null) sk1.SetValue("NoClose", 0, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("HideFastUserSwitching", 0, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("DisableChangePassword", 0, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("DisableLockWorkstation", 0, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("DisableTaskMgr", 0, RegistryValueKind.DWord);
- sk1.Close();
- rk.Close();
- }
- catch
- {
- ;
- }
- }
- public static void Disable_NoClose()
- {
- try
- {
- RegistryKey rk = null;
- RegistryKey sk1 = null;
- rk = Registry.LocalMachine;
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", true);
- if (sk1 != null) sk1.SetValue("NoClose", 1, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("HideFastUserSwitching", 1, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("DisableChangePassword", 1, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("DisableLockWorkstation", 1, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("DisableTaskMgr", 1, RegistryValueKind.DWord);
- rk = Registry.CurrentUser;
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", true);
- if (sk1 != null) sk1.SetValue("NoClose", 1, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("HideFastUserSwitching", 1, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("DisableChangePassword", 1, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("DisableLockWorkstation", 1, RegistryValueKind.DWord);
- sk1 = rk.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
- if (sk1 != null) sk1.SetValue("DisableTaskMgr", 1, RegistryValueKind.DWord);
- sk1.Close();
- rk.Close();
- }
- catch
- {
- ;
- }
- }
- }
- //
- // 수신반 전용 클래스
- // 이 클래스는 범용으로 수신반에서 다른 수신기간의 데이터를 쉽게 공유할수 있게 만든 클래스이다.
- // 실제로 사용하는 데이터만 추가하도록 한다
- // 자세한 정보는 결국 직접 접속해서 볼수 있는 화면으로 구성한다
- public class _FireDesk_Receiver
- {
- // 수신기 기본정보
- public string RECEIVER_ID = "1";
- public string MASTER_FLAG = "N";
- public string PROJECT_DIRECTORY;
- public string DATABASE_NAME; // IP + PATH
- public string DATABASE_NAME_IP; // PATH
- public string DATABASE_NAME_PATH; // PATH
- // 카운터 정보
- public int FireDetect = 0; // 화재
- public int DeviceInput = 0; // 설비
- public int RepeaterError = 0; // 통신
- public int DeviceCut = 0; // 단선
- public int DeviceNotuse = 0; // 차단
- // 클래스 정보
- public bool LoadingOk = false;
- public MDIParent mdi = null;
- }
-
- // cyim 2016.12.29 : 화면 멈춤 문제 수정 : 스레드 처리
- public class _ConnectThread
- {
- public TcpClient socket = null;
- public int port = 0;
- public TimeSpan timeout = new TimeSpan();
- }
-
- // cyim 2017.01.03 : 연동기능 보완
- public class _Sort
- {
- // 일반 서브포트용
- public class ID : IComparer
- {
- int IComparer.Compare(object a, object b)
- {
- // 첫번째 데이타 검사
- int data1 = Int32.Parse(a.ToString());
- int data2 = Int32.Parse(b.ToString());
- // 비교
- if (data1 > data2)
- return 1;
- else if (data1 < data2)
- return -1;
- else
- return 0;
- }
- }
- }
- }
|