|
|
@@ -1,328 +0,0 @@
|
|
|
-using ivf_tl_Control;
|
|
|
-using ivf_tl_ControlMain;
|
|
|
-using IvfTl.Control.Entity.GlobalEnums;
|
|
|
-using IvfTl.Control.Services;
|
|
|
-using ivf_tl_UtilHelper;
|
|
|
-using System;
|
|
|
-using System.ComponentModel;
|
|
|
-using System.Configuration;
|
|
|
-using System.IO;
|
|
|
-using System.Threading.Tasks;
|
|
|
-using System.Windows;
|
|
|
-using System.Windows.Controls;
|
|
|
-using System.Windows.Media.Imaging;
|
|
|
-using System.Xml;
|
|
|
-
|
|
|
-namespace ivf_tl_ControlTest
|
|
|
-{
|
|
|
- /// <summary>
|
|
|
- /// Window1.xaml 的交互逻辑
|
|
|
- /// </summary>
|
|
|
- public partial class Window1 : Window
|
|
|
- {
|
|
|
- bool stop = false;
|
|
|
- int stopPro = 15;
|
|
|
- public Window1()
|
|
|
- {
|
|
|
- InitializeComponent();
|
|
|
-
|
|
|
- if (int.TryParse(ConfigurationManager.AppSettings["StopPro"].ToString(), out int newTime12)) stopPro = newTime12;
|
|
|
-
|
|
|
- AppData.Instance.StopProEvent += Instance_StopProEvent;
|
|
|
-
|
|
|
- string mvcFileName = @"C:\Windows\System32\MVCCamera.ini";
|
|
|
- if (File.Exists(mvcFileName)) File.Delete(mvcFileName);
|
|
|
- Loaded += Window1_Loaded1;
|
|
|
- //Closed += Window1_Closed;
|
|
|
- //Closing += Window1_Closing;
|
|
|
- }
|
|
|
-
|
|
|
- private void Window1_Closing(object? sender, CancelEventArgs e)
|
|
|
- {
|
|
|
- Log4netHelper.WriteLog("Window1_Closing");
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private void Window1_Closed(object? sender, EventArgs e)
|
|
|
- {
|
|
|
- Log4netHelper.WriteLog("窗口关闭");
|
|
|
- }
|
|
|
-
|
|
|
- private void Window1_Loaded1(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- string account = ConfigurationManager.AppSettings["userName"].ToString();
|
|
|
- string password = ConfigurationManager.AppSettings["passWord"].ToString();
|
|
|
- string cacheDisk = ConfigurationManager.AppSettings["cacheDisk"].ToString();
|
|
|
- this._account_TextBox.Text = account;
|
|
|
- this._password_TextBox.Password = password;
|
|
|
- this._button.IsEnabled = false;
|
|
|
- this._button1.IsEnabled = true;
|
|
|
- Task.Run(() =>
|
|
|
- {
|
|
|
- if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
|
|
|
- {
|
|
|
- AppData.Instance.LogService.TLLog($"请输入账号或密码", LogEnum.RunRecord);
|
|
|
- Environment.Exit(0);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!AppData.Instance.Login(account, password))
|
|
|
- {
|
|
|
- AppData.Instance.LogService.TLLog($"登录失败", LogEnum.RunRecord);
|
|
|
- Environment.Exit(0);
|
|
|
- return;
|
|
|
- }
|
|
|
- PathHelper.pan = cacheDisk;
|
|
|
- AppData.Instance.LogService.Pan = cacheDisk;
|
|
|
- SetApp1(account, password);
|
|
|
- StartMain startMain = new StartMain();
|
|
|
- string ss = startMain.StartRun();
|
|
|
- if (!string.IsNullOrEmpty(ss))
|
|
|
- {
|
|
|
- AppData.Instance.LogService.TLLog($"启动失败:{ss}", LogEnum.RunRecord);
|
|
|
- Environment.Exit(0);
|
|
|
- return;
|
|
|
- }
|
|
|
- SetApp1(AppData.Instance.TLSetting.tmpDir);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private void Window1_Loaded(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- this._account_TextBox.Text = ConfigurationManager.AppSettings["userName"].ToString();
|
|
|
- this._password_TextBox.Password = ConfigurationManager.AppSettings["passWord"].ToString();
|
|
|
- }
|
|
|
-
|
|
|
- //[DllImport("user32.dll", SetLastError = true)]
|
|
|
- //static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
|
|
-
|
|
|
- //[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
|
|
- //static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
|
|
|
-
|
|
|
- //delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
|
|
|
- //[DllImport("user32.dll")]
|
|
|
- //static extern bool EnumChildWindows(IntPtr hWndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam);
|
|
|
- //[DllImport("user32.dll")]
|
|
|
- //static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
|
|
|
- //[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
|
|
- //static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
|
|
|
-
|
|
|
- //const uint WM_CLOSE = 0x0010;
|
|
|
- //const uint BM_CLICK = 0x00F5;
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 开始按钮
|
|
|
- /// </summary>
|
|
|
- /// <param name="sender"></param>
|
|
|
- /// <param name="e"></param>
|
|
|
- private void Button_Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- //AppData.Instance.TestEvent();
|
|
|
- //return;
|
|
|
-
|
|
|
- //var aaa = MessageBoxResult.Cancel;
|
|
|
- //var dialogTask = Task.Run(() =>
|
|
|
- //{
|
|
|
- // aaa = MessageBox.Show("messageinfo", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly);
|
|
|
- // Debug.WriteLine(1);
|
|
|
- //});
|
|
|
-
|
|
|
- //Task.Delay(3000).ContinueWith(t =>
|
|
|
- //{
|
|
|
- // if (!dialogTask.IsCompleted)
|
|
|
- // {
|
|
|
- // IntPtr hWnd = FindWindow("#32770", "提示");
|
|
|
- // if (hWnd != IntPtr.Zero)
|
|
|
- // {
|
|
|
- // EnumChildWindows(hWnd, (childHwnd, lParam) =>
|
|
|
- // {
|
|
|
- // StringBuilder className = new StringBuilder(256);
|
|
|
- // GetClassName(childHwnd, className, className.Capacity);
|
|
|
- // if (className.ToString() == "Button")
|
|
|
- // {
|
|
|
- // StringBuilder text = new StringBuilder(256);
|
|
|
- // GetWindowText(childHwnd, text, text.Capacity);
|
|
|
- // if (text.ToString().Contains("Y"))
|
|
|
- // {
|
|
|
- // SendMessage(childHwnd, BM_CLICK, IntPtr.Zero, IntPtr.Zero);
|
|
|
- // return false;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // return true;
|
|
|
- // }, IntPtr.Zero);
|
|
|
- // }
|
|
|
- // Debug.WriteLine(2);
|
|
|
- // }
|
|
|
- //});
|
|
|
- //dialogTask.Wait();
|
|
|
- //Debug.WriteLine(aaa);
|
|
|
- //return;
|
|
|
- string account = this._account_TextBox.Text.Trim();
|
|
|
- string password = this._password_TextBox.Password.Trim();
|
|
|
- if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
|
|
|
- {
|
|
|
- MessageBox.Show("请输入账号或密码");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!AppData.Instance.Login(account, password))
|
|
|
- {
|
|
|
- MessageBox.Show("登录失败");
|
|
|
- return;
|
|
|
- }
|
|
|
- SetApp1(account, password);
|
|
|
- //var aa = AppData.Instance.SerialBinController.SearchPictureController("3_1_7_69_2023-09-28-22-41-41_71900_75000.jpg", "NEO-1-20230107");
|
|
|
- StartMain startMain = new StartMain();
|
|
|
- MessageBox.Show(startMain.StartRun());
|
|
|
- this._button.IsEnabled = false;
|
|
|
- this._button1.IsEnabled = true;
|
|
|
- }
|
|
|
- private object lockObject = new object();
|
|
|
- private void Instance_StopProEvent()
|
|
|
- {
|
|
|
- return;
|
|
|
- AppData.Instance.LogService.TLLog($"拍照异常退出软件", LogEnum.RunError);
|
|
|
- lock (lockObject)
|
|
|
- {
|
|
|
- if (stop) return;
|
|
|
- stop = true;
|
|
|
- }
|
|
|
- Dispatcher.Invoke(() =>
|
|
|
- {
|
|
|
- StopWindow stopWindow = new StopWindow(this, stopPro);
|
|
|
- stopWindow.Show();
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private void SetApp(string name, string pass)
|
|
|
- {
|
|
|
- Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
|
|
- config.AppSettings.Settings["userName"].Value = name;
|
|
|
- config.AppSettings.Settings["passWord"].Value = pass;
|
|
|
- config.Save(ConfigurationSaveMode.Modified);
|
|
|
- System.Configuration.ConfigurationManager.RefreshSection("appSettings");
|
|
|
- }
|
|
|
- public void SetApp1(string name, string pass)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- string fileName = $"{System.AppDomain.CurrentDomain.BaseDirectory}ivf_tl_ControlMain.dll.config";
|
|
|
- if (!File.Exists(fileName)) return;
|
|
|
- var xmlDoc = new XmlDocument();
|
|
|
- xmlDoc.Load(fileName);
|
|
|
- var tags = xmlDoc.GetElementsByTagName("appSettings");
|
|
|
- XmlNode appSettingsNode = xmlDoc.SelectSingleNode("configuration/appSettings");
|
|
|
- if (appSettingsNode != null)
|
|
|
- {
|
|
|
- XmlNodeList addNodes = appSettingsNode.SelectNodes("add");
|
|
|
- foreach (XmlNode addNode in addNodes)
|
|
|
- {
|
|
|
- //string key = addNode.Attributes["key"].Value;
|
|
|
- //string value = addNode.Attributes["value"].Value;
|
|
|
- //Debug.WriteLine("键: " + key + ", 值: " + value);
|
|
|
- if (addNode.Attributes["key"].Value == "userName")
|
|
|
- {
|
|
|
- addNode.Attributes["value"].Value = name;
|
|
|
- }
|
|
|
- if (addNode.Attributes["key"].Value == "passWord")
|
|
|
- {
|
|
|
- addNode.Attributes["value"].Value = pass;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- xmlDoc.Save(fileName);
|
|
|
- System.Configuration.ConfigurationManager.RefreshSection("appSettings");
|
|
|
- xmlDoc = null;
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- private void SetApp(string newDisk)
|
|
|
- {
|
|
|
- Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
|
|
- config.AppSettings.Settings["cacheDisk"].Value = newDisk;
|
|
|
- config.Save(ConfigurationSaveMode.Modified);
|
|
|
- System.Configuration.ConfigurationManager.RefreshSection("appSettings");
|
|
|
- }
|
|
|
- public void SetApp1(string newDisk)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- string fileName = $"{System.AppDomain.CurrentDomain.BaseDirectory}ivf_tl_ControlMain.dll.config";
|
|
|
- if (!File.Exists(fileName)) return;
|
|
|
- var xmlDoc = new XmlDocument();
|
|
|
- xmlDoc.Load(fileName);
|
|
|
- var tags = xmlDoc.GetElementsByTagName("appSettings");
|
|
|
- XmlNode appSettingsNode = xmlDoc.SelectSingleNode("configuration/appSettings");
|
|
|
- if (appSettingsNode != null)
|
|
|
- {
|
|
|
- XmlNodeList addNodes = appSettingsNode.SelectNodes("add");
|
|
|
- foreach (XmlNode addNode in addNodes)
|
|
|
- {
|
|
|
- //string key = addNode.Attributes["key"].Value;
|
|
|
- //string value = addNode.Attributes["value"].Value;
|
|
|
- //Debug.WriteLine("键: " + key + ", 值: " + value);
|
|
|
- if (addNode.Attributes["key"].Value == "cacheDisk")
|
|
|
- {
|
|
|
- addNode.Attributes["value"].Value = newDisk;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- xmlDoc.Save(fileName);
|
|
|
- System.Configuration.ConfigurationManager.RefreshSection("appSettings");
|
|
|
- xmlDoc = null;
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void End_Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- //Log4netHelper.WriteLog("点击退出按钮");
|
|
|
- //Application.Current.Shutdown();
|
|
|
- //e.Handled = true;
|
|
|
- //return;
|
|
|
-
|
|
|
- Log4netHelper.WriteLog("点击退出按钮");
|
|
|
- AppData.Instance.SerialBinController.PushMessageController(AppData.Instance.TLSetting.tlSn, 0, null);
|
|
|
- Application.Current.Shutdown();
|
|
|
- e.Handled = true;
|
|
|
- }
|
|
|
-
|
|
|
- private void Button1_Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- if (AppData.Instance.MqttService != null)
|
|
|
- {
|
|
|
- AppData.Instance.MqttService.DisconnectAsync();
|
|
|
- }
|
|
|
- //string account = this._account_TextBox.Text.Trim();
|
|
|
- //string password = this._password_TextBox.Password.Trim();
|
|
|
- //if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
|
|
|
- //{
|
|
|
- // MessageBox.Show("请输入账号或密码");
|
|
|
- // return;
|
|
|
- //}
|
|
|
- //if (!AppData.Instance.Login(account, password))
|
|
|
- //{
|
|
|
- // MessageBox.Show("登录失败");
|
|
|
- // return;
|
|
|
- //}
|
|
|
- //AppData.Instance.UpdateSetting("NEO-1-20230107");
|
|
|
- }
|
|
|
- private void Button2_Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- if (AppData.Instance.MqttService != null)
|
|
|
- {
|
|
|
- AppData.Instance.MqttService.ClientMqtt();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void End_1Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- System.Diagnostics.Process.Start("shutdown", " /r /t 0");
|
|
|
- }
|
|
|
- }
|
|
|
-}
|