MainWindow.xaml.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. using ivf_tl_Entity.Entity;
  2. using ivf_tl_Manage.ViewModels;
  3. using System;
  4. using System.Threading.Tasks;
  5. using System.Windows;
  6. using System.Windows.Input;
  7. using System.Windows.Media;
  8. using System.Windows.Media.Imaging;
  9. using ivf_tl_CustomControls;
  10. using ivf_tl_Manage.Win;
  11. using System.Windows.Threading;
  12. using System.Configuration;
  13. using Newtonsoft.Json;
  14. using System.Windows.Controls;
  15. using ivf_tl_Service;
  16. using log4net.Appender;
  17. using log4net.Repository.Hierarchy;
  18. using log4net;
  19. using System.Linq;
  20. using ivf_tl_Entity.Entity.DownLoad;
  21. namespace ivf_tl_Manage
  22. {
  23. /// <summary>
  24. /// Interaction logic for MainWindow.xaml
  25. /// </summary>
  26. public partial class MainWindow : Window
  27. {
  28. MainWindowViewModel vm = new MainWindowViewModel();
  29. DispatcherTimer ShowTimer;
  30. public MainWindow()
  31. {
  32. InitializeComponent();
  33. this.DataContext = vm;
  34. QuestPDF.Settings.License = QuestPDF.Infrastructure.LicenseType.Community;
  35. ShowTime();
  36. AppData.Instance.SetImageSource(this.MainLogoImg, ivf_tl_Entity.Enums.LogoEnum.Rectangle);
  37. Loaded += MainWindow_Loaded;
  38. #if DEBUG
  39. this.chLan.Visibility = Visibility.Visible;
  40. this.enLan.Visibility = Visibility.Visible;
  41. this.upLan.Visibility = Visibility.Visible;
  42. Canvas originalCanvas = MainCanvas;
  43. this.Content = null;
  44. Viewbox viewbox = new Viewbox
  45. {
  46. Child = originalCanvas,
  47. Stretch = Stretch.Uniform
  48. };
  49. this.Content = viewbox;
  50. #endif
  51. }
  52. private UserInfo currentUserInfo = new UserInfo();
  53. private void MainWindow_Loaded(object sender, RoutedEventArgs e)
  54. {
  55. if (new LoginWindow(this, currentUserInfo).ShowDialog() != true)
  56. {
  57. Application.Current.Shutdown();
  58. return;
  59. }
  60. AppData.Instance.MainWindow = this;
  61. if (int.TryParse(ConfigurationManager.AppSettings["DownLoadMaxNum"].ToString(), out int downNum))
  62. {
  63. vm = new MainWindowViewModel(currentUserInfo, downNum);
  64. }
  65. else
  66. {
  67. vm = new MainWindowViewModel(currentUserInfo, 3);
  68. }
  69. if (int.TryParse(ConfigurationManager.AppSettings["ClearLogDay"].ToString(), out int newLogDay)) vm.ClearLogDay = newLogDay;
  70. //AppData.Instance.GetHouseProvider().GetSettingCommonApi();;
  71. this.DataContext = vm;
  72. AppData.Instance.MainWindowViewModel = vm;
  73. vm.CurrentViewModle = vm.devManageViewModel;
  74. ShowTimer = new DispatcherTimer();
  75. ShowTimer.Tick += new EventHandler(ShowCurTimer);//起个Timer一直获取当前时间
  76. ShowTimer.Interval = new TimeSpan(0, 0, 5);
  77. ShowTimer.Start();
  78. //Debug.WriteLine(DateTime.Now);
  79. }
  80. private void ShowCurTimer(object? sender, EventArgs e)
  81. {
  82. ShowTime();
  83. }
  84. private void ShowTime()
  85. {
  86. this.TextBlock_CurrentTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  87. }
  88. private void Exit_Click(object sender, RoutedEventArgs e)
  89. {
  90. Application.Current.Shutdown();
  91. //Environment.Exit(0);
  92. return;
  93. }
  94. private void DevManage_PreviewMouseDown(object sender, MouseButtonEventArgs e)
  95. {
  96. if (!this.IsLoaded) return;
  97. if (vm == null) return;
  98. if (!(sender is RadioButtonNoFrame source)) return;
  99. if (!source.IsLoaded) return;
  100. if (source.IsChecked == true && vm.CurrentViewModle != vm.devManageViewModel) vm.CurrentViewModle = vm.devManageViewModel;
  101. }
  102. /// <summary>
  103. /// 设备管理
  104. /// </summary>
  105. /// <param name="sender"></param>
  106. /// <param name="e"></param>
  107. private void DevManage_Checked(object sender, RoutedEventArgs e)
  108. {
  109. if (!this.IsLoaded) return;
  110. if (vm == null) return;
  111. vm.CurrentViewModle = vm.devManageViewModel;
  112. foreach (var item in vm.devManageViewModel.TlInfoList)
  113. {
  114. foreach (var houseItem in item.houses)
  115. {
  116. houseItem.IsUpdate = true;
  117. }
  118. }
  119. }
  120. /// <summary>
  121. /// 培养记录
  122. /// </summary>
  123. /// <param name="sender"></param>
  124. /// <param name="e"></param>
  125. private void DishRecord_Checked(object sender, RoutedEventArgs e)
  126. {
  127. if (!this.IsLoaded) return;
  128. if (AppData.Instance.MainWindowViewModel.IsClick) vm.CurrentTlSN = null;
  129. vm.CurrentViewModle = new DishRecordViewModel(vm.CurrentTlSN);
  130. }
  131. /// <summary>
  132. /// 系统异常
  133. /// </summary>
  134. /// <param name="sender"></param>
  135. /// <param name="e"></param>
  136. private void AlarmHistory_Checked(object sender, RoutedEventArgs e)
  137. {
  138. if (!this.IsLoaded) return;
  139. if (AppData.Instance.MainWindowViewModel.IsClick) vm.CurrentTlSN = null;
  140. vm.CurrentViewModle = new AlarmHistoryViewModel(vm.CurrentTlSN);
  141. }
  142. /// <summary>
  143. /// 远程报警
  144. /// </summary>
  145. /// <param name="sender"></param>
  146. /// <param name="e"></param>
  147. private void AlarmSetting_Checked(object sender, RoutedEventArgs e)
  148. {
  149. if (!this.IsLoaded) return;
  150. vm.CurrentViewModle = new AlarmSettingViewModel();
  151. }
  152. /// <summary>
  153. /// 模型配置
  154. /// </summary>
  155. /// <param name="sender"></param>
  156. /// <param name="e"></param>
  157. private void MarkSetting_Checked(object sender, RoutedEventArgs e)
  158. {
  159. if (!this.IsLoaded) return;
  160. vm.CurrentViewModle = new MarkSettingViewModel();
  161. }
  162. /// <summary>
  163. /// 舱室环境
  164. /// </summary>
  165. /// <param name="sender"></param>
  166. /// <param name="e"></param>
  167. private void BinSetting_Checked(object sender, RoutedEventArgs e)
  168. {
  169. if (!this.IsLoaded) return;
  170. if (AppData.Instance.MainWindowViewModel.IsClick) vm.CurrentTlSN = null;
  171. vm.CurrentViewModle = new BinSettingViewModel(vm.CurrentTlSN);
  172. }
  173. /// <summary>
  174. /// 系统管理
  175. /// </summary>
  176. /// <param name="sender"></param>
  177. /// <param name="e"></param>
  178. private void RadioButtonNoFrame_Checked(object sender, RoutedEventArgs e)
  179. {
  180. if (!this.IsLoaded) return;
  181. vm.CurrentViewModle = new AppSettingViewModel();
  182. }
  183. private void Canvas_User_MouseEnter(object sender, MouseEventArgs e)
  184. {
  185. if (!this.IsLoaded) return;
  186. this.Popup_EditPassWord.IsOpen = true;
  187. this.TextBlock_User.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#0053C4"));
  188. this.Canvas_User.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/UserNameBoxMouseOver.png", UriKind.Absolute)));
  189. this.Image_User.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/UserHeadshotMouseOver.png", UriKind.Absolute));
  190. }
  191. private async void Canvas_User_MouseLeave(object sender, MouseEventArgs e)
  192. {
  193. if (!this.IsLoaded) return;
  194. await Task.Delay(200);
  195. if (!this.Popup_EditPassWord.IsMouseOver)
  196. {
  197. this.Popup_EditPassWord.IsOpen = false;
  198. this.TextBlock_User.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#003177"));
  199. this.Canvas_User.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/UserNameBox.png", UriKind.Absolute)));
  200. this.Image_User.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/UserHeadshot.png", UriKind.Absolute));
  201. }
  202. }
  203. private async void Popup_EditPassWord_MouseLeave(object sender, MouseEventArgs e)
  204. {
  205. if (!this.IsLoaded) return;
  206. await Task.Delay(200);
  207. if (!this.Canvas_User.IsMouseOver)
  208. {
  209. this.Popup_EditPassWord.IsOpen = false;
  210. this.TextBlock_User.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#003177"));
  211. this.Canvas_User.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/UserNameBox.png", UriKind.Absolute)));
  212. this.Image_User.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/UserHeadshot.png", UriKind.Absolute));
  213. }
  214. }
  215. private void Password_Click(object sender, RoutedEventArgs e)
  216. {
  217. //vm.devManageViewModel.View._root_Canvas.Children.Clear();
  218. //return;
  219. if (!this.IsLoaded) return;
  220. this.Popup_EditPassWord.IsOpen = false;
  221. this.TextBlock_User.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#003177"));
  222. this.Canvas_User.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/UserNameBox.png", UriKind.Absolute)));
  223. this.Image_User.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/UserHeadshot.png", UriKind.Absolute));
  224. vm.MaskVisibility = true;
  225. new PasswordWindow().ShowDialog();
  226. vm.MaskVisibility = false;
  227. }
  228. private void Min_Click(object sender, RoutedEventArgs e)
  229. {
  230. this.WindowState = WindowState.Minimized;
  231. }
  232. private void Button_Click(object sender, RoutedEventArgs e)
  233. {
  234. AppData.Instance.ChangeLanguage("Chinese.xaml");
  235. }
  236. private void Button_Click1(object sender, RoutedEventArgs e)
  237. {
  238. AppData.Instance.ChangeLanguage("English.xaml");
  239. }
  240. private void Button_Click2(object sender, RoutedEventArgs e)
  241. {
  242. //for (int i = 0; i < 30; i++)
  243. //{
  244. // AppData.Instance.MainWindowViewModel.DownLoadStart(new ivf_tl_Entity.Entity.DownLoad.DownLoadEntity
  245. // {
  246. // NewFileFullName = @"C:\PersonalSpace\work\1 VisualWorkSpace\Personal\Git\ivf_tl_Manage_2.0\ivf_tl_Manage\Resources\1.ico",
  247. // FileName = i.ToString()
  248. // });
  249. //}
  250. //vm.DownLoadFileCount = 5;
  251. //return;
  252. //clientType 1PC、2App、3Surafce
  253. #if DEBUG
  254. string fileDir = @"C:\PersonalSpace\work\1 VisualWorkSpace\PCLan\";
  255. #else
  256. string fileDir = $"{System.AppDomain.CurrentDomain.BaseDirectory}Language\\";
  257. #endif
  258. if (true)
  259. {
  260. AppData.Instance.MainWindowViewModel.DownLoadStart(new ivf_tl_Entity.Entity.DownLoad.DownLoadEntity
  261. {
  262. DownLoadUrl = $"/api/tl/control/data/downloadLanguageConf",
  263. NewFileFullName = $"{fileDir}Chinese.xaml",
  264. FileName = "Chinese.xaml",
  265. Body = JsonConvert.SerializeObject(new { clientType = 1, region = 1 }),
  266. });
  267. AppData.Instance.MainWindowViewModel.DownLoadStart(new ivf_tl_Entity.Entity.DownLoad.DownLoadEntity
  268. {
  269. DownLoadUrl = $"/api/tl/control/data/downloadLanguageConf",
  270. NewFileFullName = $"{fileDir}English.xaml",
  271. FileName = "English.xaml",
  272. Body = JsonConvert.SerializeObject(new { clientType = 1, region = 2 }),
  273. });
  274. AppData.Instance.MainWindowViewModel.DownLoadStart(new ivf_tl_Entity.Entity.DownLoad.DownLoadEntity
  275. {
  276. DownLoadUrl = $"/api/tl/control/data/downloadLanguageConf",
  277. NewFileFullName = @"C:\PersonalSpace\work\1 VisualWorkSpace\SurfaceLan\Chinese.xaml",
  278. FileName = "Chinese.xaml",
  279. Body = JsonConvert.SerializeObject(new { clientType = 3, region = 1 }),
  280. });
  281. AppData.Instance.MainWindowViewModel.DownLoadStart(new ivf_tl_Entity.Entity.DownLoad.DownLoadEntity
  282. {
  283. DownLoadUrl = $"/api/tl/control/data/downloadLanguageConf",
  284. NewFileFullName = @"C:\PersonalSpace\work\1 VisualWorkSpace\SurfaceLan\English.xaml",
  285. FileName = "English.xaml",
  286. Body = JsonConvert.SerializeObject(new { clientType = 3, region = 2 }),
  287. });
  288. }
  289. else
  290. {
  291. }
  292. }
  293. private void Carousel_LogEvent(string obj)
  294. {
  295. //Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")}:{obj}----------------------------------------------");
  296. }
  297. private void AlarmSetting_CheckedNew(object sender, RoutedEventArgs e)
  298. {
  299. if (!this.IsLoaded) return;
  300. vm.CurrentViewModle = new AlarmSettingNewViewModel();
  301. }
  302. private void StackPanel_MouseDown(object sender, MouseButtonEventArgs e)
  303. {
  304. try
  305. {
  306. if (!this.IsLoaded || vm == null) return;
  307. vm.MaskVisibility = true;
  308. //vm.DownLoadFileList.Clear();
  309. //for (int i = 0; i < 100; i++)
  310. //{
  311. // vm.DownLoadFileList.Add(new DownLoadEntity
  312. // {
  313. // DownLoadUrl = "123",
  314. // FileName = $"filename{i}",
  315. // NewFileFullName = "newfileName"
  316. // });
  317. //}
  318. DownLoadDetailWindow downLoadDetailWindow = new DownLoadDetailWindow(vm);
  319. downLoadDetailWindow.ShowDialog();
  320. }
  321. finally
  322. {
  323. vm.MaskVisibility = false;
  324. }
  325. }
  326. }
  327. }