| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- using ivf_tl_Entity.GlobalEnums;
- using ivf_tl_Operate.CustomUserControls;
- using ivf_tl_Operate.ViewModel;
- using ivf_tl_Operate.Windows;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Diagnostics;
- using System.IO;
- 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.Imaging;
- using System.Windows.Navigation;
- using System.Xml;
- namespace ivf_tl_Operate.View
- {
- /// <summary>
- /// MainPageView.xaml 的交互逻辑
- /// </summary>
- public partial class MainPageView : UserControl
- {
- private MainPageViewModel vm { get { return (MainPageViewModel)this.DataContext; } }
- public MainPageView()
- {
- InitializeComponent();
- AppData.Instance.CustomHouseInfoList.Add(this._HouseInfo1);
- AppData.Instance.CustomHouseInfoList.Add(this._HouseInfo2);
- AppData.Instance.CustomHouseInfoList.Add(this._HouseInfo3);
- AppData.Instance.CustomHouseInfoList.Add(this._HouseInfo4);
- AppData.Instance.CustomHouseInfoList.Add(this._HouseInfo5);
- AppData.Instance.CustomHouseInfoList.Add(this._HouseInfo6);
- AppData.Instance.CustomHouseInfoList.Add(this._HouseInfo7);
- AppData.Instance.CustomHouseInfoList.Add(this._HouseInfo8);
- AppData.Instance.CustomHouseInfoList.Add(this._HouseInfo9);
- AppData.Instance.CustomHouseInfoList.Add(this._HouseInfo10);
- var houseEnabled = ConfigurationManager.AppSettings["houseEnabled"].ToString();
- if (!string.IsNullOrEmpty(houseEnabled))
- {
- var houseEnabledList = houseEnabled.Split(",");
- int enableHouse;
- foreach (var item in houseEnabledList)
- {
- if (int.TryParse(item, out enableHouse))
- {
- SerEn(enableHouse);
- }
- }
- }
- #if DEBUG
- this.lanQie.Visibility = Visibility.Visible;
- List<int> items = new List<int>();
- for (int i = 0; i < 100; i++)
- {
- items.Add(i);
- }
- this._timingAutoFocus_ComboBox.ItemsSource = items;
- #endif
- }
- public void SerEn(int houseen)
- {
- switch (houseen)
- {
- case 1:
- this._HouseInfo1.IsEnabled = false;
- break;
- case 2:
- this._HouseInfo2.IsEnabled = false;
- break;
- case 3:
- this._HouseInfo3.IsEnabled = false;
- break;
- case 4:
- this._HouseInfo4.IsEnabled = false;
- break;
- case 5:
- this._HouseInfo5.IsEnabled = false;
- break;
- case 6:
- this._HouseInfo6.IsEnabled = false;
- break;
- case 7:
- this._HouseInfo7.IsEnabled = false;
- break;
- case 8:
- this._HouseInfo8.IsEnabled = false;
- break;
- case 9:
- this._HouseInfo9.IsEnabled = false;
- break;
- case 10:
- this._HouseInfo10.IsEnabled = false;
- break;
- }
- }
- private void ExLog(Exception ex, string name)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"MainPageView.{name}", LogEnum.RunException);
- }
- private void ErrorLog(string mess, LogEnum logEnum)
- {
- AppData.Instance.LogHelper.TLLog(mess, logEnum);
- }
- /// <summary>
- /// 设置按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Setting_Click(object sender, RoutedEventArgs e)
- {
- SettingPageView settingPageView = new SettingPageView();
- AppData.Instance.MainWindow.LoadPage(settingPageView);
- }
- /// <summary>
- /// 用户按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void User_Click(object sender, RoutedEventArgs e)
- {
- AppData.Instance.MainWindow.Mark(true);
- var a = new LoginWindow(AppData.Instance.MainWindow).ShowDialog();
- AppData.Instance.MainWindow.Mark(false);
- if (a != true) return;
- //vm.StartMqtt();
- }
- public void SetAlarmMute(long id, int mute)
- {
- if (vm == null) return;
- vm.SetAlarmMute(id, mute);
- AppData.Instance.HttpHelper.MuteAlarmApi(id, mute);
- }
- /// <summary>
- /// 点击舱室
- /// </summary>
- /// <param name="obj"></param>
- private void CustomHouseInfo_ClickHouseEvent(CustomHouseInfo customHouseInfo)
- {
- if (!this.IsLoaded || !this.IsLoaded) return;
- var currentDish = customHouseInfo.ExDishSource;
- if (currentDish != null && currentDish.id > 0)
- {
- DetailPageViewModel detailPageViewModel = new DetailPageViewModel(customHouseInfo.ExHouseSource, currentDish);
- DetailPageView detailPageView = new DetailPageView()
- {
- DataContext = detailPageViewModel,
- };
- AppData.Instance.MainWindow.LoadPage(detailPageView);
- }
- else
- {
- var isBalacne = false;
- long balanceId = 0;
- var currentExbalance = vm.HouseSnToExBalance(customHouseInfo.HouseSn);
- if (currentExbalance != null)
- {
- isBalacne = true;
- balanceId = currentExbalance.id;
- }
- //Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Input, () =>
- //{
-
- //});
- AddDishWindowView addDishWindowView = new AddDishWindowView(customHouseInfo.HouseSn, isBalacne, balanceId);
- AppData.Instance.MainWindow.Mark(true);
- var a = addDishWindowView.ShowDialog();
- AppData.Instance.MainWindow.Mark(false);
- if (a == true)
- {
- vm.Init();
- }
- }
- }
- private CustomHouseInfo GetHouseInfoControl(int houseSn)
- {
- CustomHouseInfo customHouseInfo = null;
- switch (houseSn)
- {
- case 1:
- customHouseInfo = this._HouseInfo1;
- break;
- case 2:
- customHouseInfo = this._HouseInfo2;
- break;
- case 3:
- customHouseInfo = this._HouseInfo3;
- break;
- case 4:
- customHouseInfo = this._HouseInfo4;
- break;
- case 5:
- customHouseInfo = this._HouseInfo5;
- break;
- case 6:
- customHouseInfo = this._HouseInfo6;
- break;
- case 7:
- customHouseInfo = this._HouseInfo7;
- break;
- case 8:
- customHouseInfo = this._HouseInfo8;
- break;
- case 9:
- customHouseInfo = this._HouseInfo9;
- break;
- case 10:
- customHouseInfo = this._HouseInfo10;
- break;
- }
- return customHouseInfo;
- }
- /// <summary>
- /// 设置胚胎状态
- /// </summary>
- /// <param name="houseSn"></param>
- /// <param name="well"></param>
- /// <param name="embryoState"></param>
- public void SetMainEmbryoState(int houseSn, int well, int embryoState)
- {
- try
- {
- CustomHouseInfo customHouseInfo = GetHouseInfoControl(houseSn);
- if (customHouseInfo == null) return;
- customHouseInfo.SetEmbryoState(well, embryoState);
- }
- catch (Exception ex)
- {
- ExLog(ex, "SetMainEmbryoState");
- }
- }
- /// <summary>
- /// 结束培养
- /// </summary>
- /// <param name="housesn"></param>
- public void EndDish(int housesn)
- {
- vm.EndDish(housesn);
- }
- public void UpdateInfo()
- {
- vm.Init();
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- AppData.Instance.MainWindow.WindowState = WindowState.Minimized;
- }
- private void DishRecord_Click(object sender, RoutedEventArgs e)
- {
- DishRecordViewModel dishRecordViewModel = new DishRecordViewModel() { TLSn = vm.tlsn, ParentViewModel = vm };
- DishRecordView dishRecordView = new DishRecordView()
- {
- DataContext = dishRecordViewModel,
- };
- AppData.Instance.MainWindow.LoadPage(dishRecordView);
- }
- private void Chart_Click(object sender, RoutedEventArgs e)
- {
- ChartPageViewModel dishRecordViewModel = new ChartPageViewModel(1, vm) { tlSn = vm.tlsn };
- ChartPageView dishRecordView = new ChartPageView(1)
- {
- DataContext = dishRecordViewModel,
- };
- AppData.Instance.MainWindow.LoadPage(dishRecordView);
- }
- private void _status_MouseUp(object sender, MouseButtonEventArgs e)
- {
- }
- private void _status_MouseDown(object sender, MouseButtonEventArgs e)
- {
- AlarmPageViewModel alarmPageViewModel = new AlarmPageViewModel();
- AlarmPageView alarmPageView = new AlarmPageView() { DataContext = alarmPageViewModel };
- AppData.Instance.MainWindow.LoadPage(alarmPageView);
- }
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- GetDateWindow getDate = new GetDateWindow(AppData.Instance.MainWindow);
- getDate.ShowDialog();
- return;
- ChangeLanguage("Chinese.xaml");
- }
- private void Button_Click_2(object sender, RoutedEventArgs e)
- {
- ChangeLanguage("English.xaml");
- }
- private void Button_Click_5(object sender, RoutedEventArgs e)
- {
- if (vm.ExHouse6.pressureAlarm == 0)
- {
- vm.ExHouse6.pressureAlarm = 1;
- }
- else
- {
- vm.ExHouse6.pressureAlarm = 0;
- }
- }
- private void Button_Click_4(object sender, RoutedEventArgs e)
- {
- if (vm.ExHouse6.temperatureAlarm == 0)
- {
- vm.ExHouse6.temperatureAlarm = 1;
- }
- else
- {
- vm.ExHouse6.temperatureAlarm = 0;
- }
- }
- public void ChangeLanguage(string languageName)
- {
- try
- {
- ResourceDictionary langRd = null;
- #if DEBUG
- string xamlFilePath = @"C:\PersonalSpace\work\1 VisualWorkSpace\SurfaceLan\" + languageName;
- #else
- string xamlFilePath = $"{System.AppDomain.CurrentDomain.BaseDirectory}Resources\\Language\\{languageName}";
- #endif
- if (!File.Exists(xamlFilePath))
- {
- new MessageWindow(AppData.Instance.MainWindow, $"切换语言失败,配置文件不存在:{xamlFilePath}", "消息提示").ShowDialog();
- return;
- }
- using (var stream = new FileStream(xamlFilePath, FileMode.Open))
- {
- langRd = System.Windows.Markup.XamlReader.Load(stream) as ResourceDictionary;
- }
- if (langRd != null)
- {
- int count = Application.Current.Resources.MergedDictionaries.Count;
- if (count >= 1)
- {
- Application.Current.Resources.MergedDictionaries.RemoveAt(count - 1);
- }
- Application.Current.Resources.MergedDictionaries.Add(langRd);
- setAppConfig(languageName);
- //Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- //config.AppSettings.Settings["Language"].Value = languageName;
- //config.Save(ConfigurationSaveMode.Modified);
- //System.Configuration.ConfigurationManager.RefreshSection("appSettings");
- }
- else
- {
- new MessageWindow(AppData.Instance.MainWindow, $"切换语言失败,文件转ResourceDictionary失败;{xamlFilePath}", "消息提示").ShowDialog();
- }
- }
- catch (Exception ex)
- {
- new MessageWindow(AppData.Instance.MainWindow, $"切换语言异常,{JsonConvert.SerializeObject(ex)}", "消息提示").ShowDialog();
- return;
- }
- }
- public void setAppConfig(string languageName)
- {
- try
- {
- string fileName = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "ivf_tl_Operate.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)
- {
- if (addNode.Attributes["key"].Value == "Language")
- {
- addNode.Attributes["value"].Value = languageName;
- }
- }
- }
- xmlDoc.Save(fileName);
- System.Configuration.ConfigurationManager.RefreshSection("appSettings");
- xmlDoc = null;
- }
- catch (Exception ex)
- {
- return;
- }
- }
- private void Button_Click_3(object sender, RoutedEventArgs e)
- {
- if (AppData.Instance.OutInterString != "1")
- {
- MessageBox.Show("在配置文件切换外网使用");
- return;
- }
- Task.Run(async () =>
- {
- #if DEBUG
- string fileName = @"C:\PersonalSpace\work\1 VisualWorkSpace\SurfaceLan\";
- # else
- string fileName = $"{System.AppDomain.CurrentDomain.BaseDirectory}Resources\\Language\\";
- #endif
- if (!Directory.Exists(fileName)) Directory.CreateDirectory(fileName);
- string Body = JsonConvert.SerializeObject(new { clientType = 3, region = 1 });
- await AppData.Instance.HttpHelper.DownLoadFileAsync("/api/tl/control/data/downloadLanguageConf", $"{fileName}Chinese.xaml", Body);
- Body = JsonConvert.SerializeObject(new { clientType = 3, region = 2 });
- #if DEBUG
- fileName = @"C:\PersonalSpace\work\1 VisualWorkSpace\SurfaceLan\";
- #else
- fileName = $"{System.AppDomain.CurrentDomain.BaseDirectory}Resources\\Language\\";
- #endif
- if (!Directory.Exists(fileName)) Directory.CreateDirectory(fileName);
- await AppData.Instance.HttpHelper.DownLoadFileAsync("/api/tl/control/data/downloadLanguageConf", $"{fileName}English.xaml", Body);
- Dispatcher.Invoke(() =>
- {
- MessageBox.Show("多语言模板更新完成");
- });
- });
- }
- }
- }
|