using ivf_tl_Entity.DebugEntitys; using ivf_tl_Operate.Converts; using ivf_tl_Operate.ViewModel; using ivf_tl_Operate.Windows; using ivf_tl_Services; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace ivf_tl_Operate.View { /// /// SettingPageView.xaml 的交互逻辑 /// public partial class SettingPageView : UserControl { string guanbi; public TLSettingCommon tLSettingCommon = null; public SettingPageView() { InitializeComponent(); List autoTimeList = new List(); for (int i = 0; i < 24; i++) autoTimeList.Add(i); List zhenList = new List(); for (int i = 1; i <= 30; i++) zhenList.Add(i); guanbi = KeyToStringConvert.GetLanguageStringByKey("C0305"); List cropList = new List() { guanbi, "1", "3", "5", "7", "9", "11", "13", "15", "17", "19", "21", "23", "25" }; //for (int i = 1; i <= 11; i++) cropList.Add(i); this._timingAutoFocus_ComboBox.ItemsSource = autoTimeList; this._videoFps_ComboBox.ItemsSource = zhenList; this._cropNum_ComboBox.ItemsSource = cropList; Loaded += SettingPageView_Loaded; } private void SettingPageView_Loaded(object sender, RoutedEventArgs e) { if (AppData.Instance.TLSettingCommon != null && AppData.Instance.TLSettingCommon.id == 0) { AppData.Instance.TLSettingCommon = AppData.Instance.HttpHelper.SettingCommonApi(AppData.Instance.TLSettingCommon.tlSn); if (AppData.Instance.TLSettingCommon != null && AppData.Instance.TLSettingCommon.id == 0) { new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "获取设置失败"); } } tLSettingCommon = AppData.Instance.TLSettingCommon; SetPageInfo(); } private string GetDataTime() { try { AppData.Instance.MainWindow.Mark(true); GetDateWindow getDate = new GetDateWindow(AppData.Instance.MainWindow); //getDate._dateControl.SetNYR(false); getDate.SetSelectWeiLai(); getDate.isClos = true; var result = getDate.ShowDialog(); if (result.Value == true) { return $"{getDate.Date} 00:00:00"; } return null; } catch (Exception ex) { return null; } finally { AppData.Instance.MainWindow.Mark(false); } } private void SetPageInfo() { //this._timingAutoFocus_TextBlock.Text = $"{tLSettingCommon.autoFocusTime} >"; //this._videoFps_TextBlock.Text = $"{tLSettingCommon.videoFps} >"; //this._hepaTime_TextBlock.Text = $"{tLSettingCommon.heapDate} >"; //this._keepTime_TextBlock.Text = $"{tLSettingCommon.keepDate} >"; this._timingAutoFocus_ComboBox.SelectedItem = tLSettingCommon.autoFocusTime; this._videoFps_ComboBox.SelectedItem = tLSettingCommon.videoFps; if (tLSettingCommon.cropNum == -1) { this._cropNum_ComboBox.SelectedItem = guanbi; } else { this._cropNum_ComboBox.SelectedItem = tLSettingCommon.cropNum.ToString(); } } private bool MiMa(PasswordBox textBox) { bool rs = false; // M5-02-3:工程师口令改读加密存储的 engineerPwd(首次无值回退默认 tl13579,迁移已在 App_Startup 加密回写)。 // 方法签名与 7 处调用点不变(00-需求总览.md §8),仅换口令来源。[D8] 权限分级(普通运维 vs 工程师)待确认。 string engineerPwd = ivf_tl_Operate.Helpers.AppConfigHelper.GetEngineerPwd(); if (textBox.Password.Trim() == engineerPwd) rs = true; textBox.Password = ""; return rs; } private bool UpdataTlSetting() { if (AppData.Instance.HttpHelper.CommonUpdateApi(tLSettingCommon)) { new MessagePrompt().ShowCenterOwnerSuccess(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0232")); return true; } else { //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "更新失败"); new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0233")); return false; } } private void Return_Click(object sender, RoutedEventArgs e) { AppData.Instance.BackMainPage(); } private void TimingAutoFocus_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this._timingAutoFocus_ComboBox.SelectedItem is int newValue) { if (newValue != tLSettingCommon.autoFocusTime) { int oldValue = tLSettingCommon.autoFocusTime; tLSettingCommon.autoFocusTime = newValue; if (!UpdataTlSetting()) tLSettingCommon.autoFocusTime = oldValue; } } } private void VideoFps_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this._videoFps_ComboBox.SelectedItem is int newValue) { if (newValue != tLSettingCommon.videoFps) { int oldValue = tLSettingCommon.videoFps; tLSettingCommon.videoFps = newValue; if (!UpdataTlSetting()) tLSettingCommon.videoFps = oldValue; } } } /// /// HEPA下次更换时间 /// /// /// private void HepaTime_MouseUp(object sender, MouseButtonEventArgs e) { if (!MiMa(this._hepaTime_PasswordBox)) { //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "密码输入错误"); new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234")); return; } string newTime = GetDataTime(); if (string.IsNullOrEmpty(newTime)) { return; } string oldValue = tLSettingCommon.heapDate; tLSettingCommon.heapDate = newTime; if (!UpdataTlSetting()) tLSettingCommon.heapDate = oldValue; } /// /// 设备下次保养时间 /// /// /// private void KeepTime_MouseUp(object sender, MouseButtonEventArgs e) { if (!MiMa(this.KeepTime_PasswordBox)) { //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "密码输入错误"); new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234")); return; } string newTime = GetDataTime(); if (string.IsNullOrEmpty(newTime)) { return; } string oldValue = tLSettingCommon.keepDate; tLSettingCommon.keepDate = newTime; if (!UpdataTlSetting()) tLSettingCommon.keepDate = oldValue; } /// /// 系统参数设置 /// /// /// private void HouseSetting_MouseUp(object sender, MouseButtonEventArgs e) { if (!MiMa(this.HouseSetting_PasswordBox)) { //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "密码输入错误"); new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234")); return; } HouseSettingPageViewModel houseSettingPageViewModel = new HouseSettingPageViewModel(); HouseSettingPageView houseSettingPageView = new HouseSettingPageView() { DataContext = houseSettingPageViewModel, }; //houseSettingPageView.TestData(); AppData.Instance.MainWindow.LoadPage(houseSettingPageView); } /// /// 对焦参数设置 /// /// /// private void AutoFocusSetting_MouseUp(object sender, MouseButtonEventArgs e) { if (!MiMa(this.AutoFocusSetting_PasswordBox)) { //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "密码输入错误"); new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234")); return; } AutoFocusSettingViewModel autoFocusSettingViewModel = new AutoFocusSettingViewModel(); AutoFocusSettingView autoFocusSettingView = new AutoFocusSettingView(autoFocusSettingViewModel); AppData.Instance.MainWindow.LoadPage(autoFocusSettingView); } /// /// 舱室调试 /// /// /// private void HouseDebug_MouseUp(object sender, MouseButtonEventArgs e) { if (!MiMa(this.HouseDebug_PasswordBox)) { //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "密码输入错误"); new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234")); return; } if (!IsClose()) { //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "请先关闭下位机控制软件"); new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0235")); return; } HouseDebugPageViewModel houseDebugPageViewModel = new HouseDebugPageViewModel(); string err = null; houseDebugPageViewModel.Start(ref err); if (!string.IsNullOrEmpty(err)) { if (err == "结束") return; MessageBox.Show(err); return; } HouseDebugPageView houseDebugPageView = new HouseDebugPageView(houseDebugPageViewModel); AppData.Instance.MainWindow.LoadPage(houseDebugPageView); } /// /// 缓冲瓶调试 /// /// /// private void BufferDebug_MouseUp(object sender, MouseButtonEventArgs e) { if (!MiMa(this.BufferDebug_PasswordBox)) { //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "密码输入错误"); new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234")); return; } if (!IsClose()) { //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "请先关闭下位机控制软件"); new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0235")); return; } BufferDebugViewModel bufferDebugViewModel = new BufferDebugViewModel(); string err = null; bufferDebugViewModel.Start(ref err); if (!string.IsNullOrEmpty(err)) { if (err == "结束") return; MessageBox.Show(err); return; } BufferDebugView houseDebugPageView = new BufferDebugView(bufferDebugViewModel); AppData.Instance.MainWindow.LoadPage(houseDebugPageView); } /// /// 退出系统 /// /// /// private void Exit_MouseUp(object sender, MouseButtonEventArgs e) { if (!MiMa(this.Exit_PasswordBox)) { //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "密码输入错误"); new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234")); return; } App.Current.Shutdown(); } /// /// 关于我们 /// /// /// private void About_MouseUp(object sender, MouseButtonEventArgs e) { AboutView houseDebugPageView = new AboutView(); AppData.Instance.MainWindow.LoadPage(houseDebugPageView); } /// /// M5-02-4:统一配置(本地层配置界面化)。工程师口令保护,仿 HouseSetting_MouseUp。既有入口不变。 /// private void UnifiedConfig_MouseUp(object sender, MouseButtonEventArgs e) { if (!MiMa(this.UnifiedConfig_PasswordBox)) { new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0234")); return; } UnifiedConfigView unifiedConfigView = new UnifiedConfigView(); AppData.Instance.MainWindow.LoadPage(unifiedConfigView); } /// /// M5-03-5:服务监控(只读)。仿 About_MouseUp(无口令、直接进入)。 /// 监控页纯只读、无任何控制/写控件。[D8] 是否需口令/权限分级待确认。既有入口不变。 /// private void ServiceMonitor_MouseUp(object sender, MouseButtonEventArgs e) { ServiceMonitorView serviceMonitorView = new ServiceMonitorView(); AppData.Instance.MainWindow.LoadPage(serviceMonitorView); } private void _exitPass_PasswordBox_PasswordChanged(object sender, RoutedEventArgs e) { PasswordBox passwordBox = sender as PasswordBox; if (passwordBox == null) return; string ss = passwordBox.Password.Trim(); if (string.IsNullOrEmpty(ss)) { passwordBox.Background = (VisualBrush)this.FindResource("HelpBrush"); } else { passwordBox.Background = new SolidColorBrush(Colors.White); } } private void Min_MouseUp(object sender, MouseButtonEventArgs e) { AppData.Instance.MainWindow.WindowState = WindowState.Minimized; } private bool IsClose() { Process[] processes = Process.GetProcessesByName("ivf_tl_ControlMain"); if (processes.Length == 0) return true; return false; } private void CropNum_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this._cropNum_ComboBox.SelectedItem is string newValue) { int newValueInt; if (!int.TryParse(newValue, out newValueInt) && newValue == guanbi) newValueInt = -1; if (newValueInt != tLSettingCommon.cropNum) { int oldValue = tLSettingCommon.cropNum; tLSettingCommon.cropNum = newValueInt; if (!UpdataTlSetting()) { tLSettingCommon.cropNum = oldValue; if (tLSettingCommon.cropNum == -1) { this._cropNum_ComboBox.SelectedItem = guanbi; } else { this._cropNum_ComboBox.SelectedItem = tLSettingCommon.cropNum.ToString(); } } } } } } }