DishRecordView.xaml.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. using ivf_tl_CustomControls;
  2. using ivf_tl_Entity.Entity.balance;
  3. using ivf_tl_Entity.Entity.DownLoad;
  4. using ivf_tl_Entity.Response;
  5. using ivf_tl_Manage.Converts;
  6. using ivf_tl_Manage.ViewModels;
  7. using ivf_tl_Manage.Win;
  8. using Newtonsoft.Json;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Diagnostics;
  12. using System.Drawing;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Security.Policy;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using System.Windows;
  19. using System.Windows.Controls;
  20. using System.Windows.Data;
  21. using System.Windows.Documents;
  22. using System.Windows.Input;
  23. using System.Windows.Media;
  24. using System.Windows.Media.Imaging;
  25. using System.Windows.Navigation;
  26. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
  27. namespace ivf_tl_Manage.Views
  28. {
  29. /// <summary>
  30. /// DishRecordView.xaml 的交互逻辑
  31. /// </summary>
  32. public partial class DishRecordView : UserControl
  33. {
  34. private DishRecordViewModel vm;
  35. public DishRecordView()
  36. {
  37. InitializeComponent();
  38. var a = this.ItemsControl_ShowData.Items;
  39. Loaded += (s, e) =>
  40. {
  41. vm = (DishRecordViewModel)this.DataContext;
  42. if (vm == null) return;
  43. this._tlName_ComBox.SelectedItem = vm.CurrentTlInfo;
  44. this._caseId_TextBox.Text = vm.CasedId;
  45. this._cycle_TextBox.Text = vm.Cycle;
  46. this._name_TextBox.Text = vm.SearchName;
  47. this._time_TextBox.Text = vm.SearchTime;
  48. this._HouseSn_ComBox.SelectedItem = vm.CurrentHouse;
  49. Task.Run(() =>
  50. {
  51. Dispatcher.Invoke(() =>
  52. {
  53. vm.UpdataCount();
  54. });
  55. });
  56. };
  57. }
  58. private void Oper_Click(object sender, RoutedEventArgs e)
  59. {
  60. }
  61. private void UserControl_KeyDown(object sender, KeyEventArgs e)
  62. {
  63. if (this._name_TextBox.IsFocused || this._time_TextBox.IsFocused)
  64. {
  65. if (e.Key == Key.Enter)
  66. {
  67. string newTime = this._time_TextBox.Text.Trim();
  68. string newName = this._name_TextBox.Text.Trim();
  69. if (!string.IsNullOrEmpty(newTime))
  70. {
  71. if (!DateTime.TryParse(newTime, out DateTime time))
  72. {
  73. //new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, "受精时间输入错误").Show();
  74. new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, KeyToStringConvert.GetLanguageStringByKey("0317")).Show();
  75. return;
  76. }
  77. }
  78. vm.SetSearchNameAndTime(newName, newTime);
  79. e.Handled = true;
  80. }
  81. }
  82. }
  83. private void RadioButtonMarkSetting_Checked(object sender, RoutedEventArgs e)
  84. {
  85. if (vm == null) return;
  86. if (!(sender is RadioButtonMarkSetting source)) return;
  87. if (!source.IsLoaded) return;
  88. vm.SetSelectedType(source.Tag.ToString());
  89. }
  90. private void PaginationUserControl_PageChangedEvent(UserControls.PaginationUserControl arg1, int arg2)
  91. {
  92. if (vm == null) return;
  93. if (!arg1.IsLoaded) return;
  94. NoUp = true;
  95. this._all_CheckBox1.IsChecked = false;
  96. NoUp = false;
  97. //this._exportDish.IsEnabled = false;
  98. vm.SetPageCurrent(arg2);
  99. }
  100. private void House_DropDownClosed(object sender, EventArgs e)
  101. {
  102. if (vm == null) return;
  103. if (!(sender is ComBoxCustom2 source)) return;
  104. if (!source.IsLoaded) return;
  105. string newTime = this._time_TextBox.Text.Trim();
  106. string newName = this._name_TextBox.Text.Trim();
  107. if (!string.IsNullOrEmpty(newTime))
  108. {
  109. if (!DateTime.TryParse(newTime, out DateTime time))
  110. {
  111. //new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, "受精时间输入错误").Show();
  112. new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, KeyToStringConvert.GetLanguageStringByKey("0317")).Show();
  113. return;
  114. }
  115. }
  116. if (source.SelectedItem == null)
  117. {
  118. vm.SetCurrentHouse(-1, newName, newTime);
  119. return;
  120. }
  121. vm.SetCurrentHouse((int)source.SelectedItem, newName, newTime);
  122. }
  123. private void TLSN_DropDownClosed(object sender, EventArgs e)
  124. {
  125. if (vm == null) return;
  126. if (!(sender is ComBoxCustom2 source)) return;
  127. if (!source.IsLoaded) return;
  128. string newTime = this._time_TextBox.Text.Trim();
  129. string newName = this._name_TextBox.Text.Trim();
  130. if (!string.IsNullOrEmpty(newTime))
  131. {
  132. if (!DateTime.TryParse(newTime, out DateTime time))
  133. {
  134. //new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, "受精时间输入错误").Show();
  135. new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, KeyToStringConvert.GetLanguageStringByKey("0317")).Show();
  136. return;
  137. }
  138. }
  139. if (source.SelectedItem == null)
  140. {
  141. vm.SetCurrentTlInfo(null, newName, newTime);
  142. return;
  143. }
  144. vm.SetCurrentTlInfo((TLInfo)source.SelectedItem, newName, newTime);
  145. }
  146. private void TextBoxButtonCustom_TestEvent(TextBoxButtonCustom source, string newName)
  147. {
  148. if (vm == null || source == null) return;
  149. if (!source.IsLoaded) return;
  150. vm.SetSearchName(newName);
  151. }
  152. private void TextBoxButtonCustom_TestEvent1(TextBoxButtonCustom source, string newTime)
  153. {
  154. if (vm == null || source == null) return;
  155. if (!source.IsLoaded) return;
  156. if (!string.IsNullOrEmpty(newTime))
  157. {
  158. if (!DateTime.TryParse(newTime, out DateTime time))
  159. {
  160. //new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, "受精时间输入错误").Show();
  161. new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, KeyToStringConvert.GetLanguageStringByKey("0317")).Show();
  162. return;
  163. }
  164. }
  165. vm.SetSearchTime(newTime);
  166. }
  167. private void DishRecordOper_CanvasMouseDown(object sender, MouseButtonEventArgs e)
  168. {
  169. try
  170. {
  171. if (vm == null) return;
  172. if (!(sender is Border source)) return;
  173. if (!source.IsLoaded) return;
  174. if (!(source.Tag is DishRecordEntity dishRecordEntity)) return;
  175. vm.OpenDishDetail(dishRecordEntity);
  176. //vm.OpenPdfView(dishRecordEntity);
  177. }
  178. finally
  179. {
  180. e.Handled = true;
  181. }
  182. }
  183. private void DishRecordOper_CanvasMouseDown1(object sender, MouseButtonEventArgs e)
  184. {
  185. try
  186. {
  187. if (vm == null) return;
  188. if (!(sender is StackPanel source)) return;
  189. if (!source.IsLoaded) return;
  190. if (!(source.Tag is DishRecordEntity dishRecordEntity)) return;
  191. vm.OpenDishDetail(dishRecordEntity);
  192. }
  193. finally
  194. {
  195. e.Handled = true;
  196. }
  197. }
  198. private void DishRecordOper_MouseDown(object sender, MouseButtonEventArgs e)
  199. {
  200. try
  201. {
  202. if (!this.IsLoaded) return;
  203. if (vm == null) return;
  204. if (!(sender is ImageCustom source)) return;
  205. if (!source.IsLoaded) return;
  206. if (!(source.Tag is DishRecordEntity dishRecordEntity)) return;
  207. vm.OpenDishDetail(dishRecordEntity);
  208. }
  209. finally
  210. {
  211. e.Handled = true;
  212. }
  213. }
  214. private void DishRecordDel_MouseDown(object sender, MouseButtonEventArgs e)
  215. {
  216. try
  217. {
  218. if (!this.IsLoaded) return;
  219. if (vm == null) return;
  220. if (!(sender is ImageCustom source)) return;
  221. if (!source.IsLoaded) return;
  222. if (!(source.Tag is DishRecordEntity dishRecordEntity)) return;
  223. vm.DeletDishRecord(dishRecordEntity);
  224. }
  225. finally
  226. {
  227. e.Handled = true;
  228. }
  229. }
  230. private void ScrollViewer_ManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
  231. {
  232. e.Handled = true;
  233. }
  234. private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
  235. {
  236. if (sender is ScrollViewer scrollViewer)
  237. {
  238. if (e.Delta > 0)
  239. {
  240. scrollViewer.LineLeft();
  241. scrollViewer.LineLeft();
  242. }
  243. else
  244. {
  245. scrollViewer.LineRight();
  246. scrollViewer.LineRight();
  247. }
  248. e.Handled = true;
  249. }
  250. //290 0
  251. //Debug.WriteLine($"{this.ScrollViewer_CenterData.HorizontalOffset} {this.ScrollViewer_CenterData.ViewportWidth} {this.ScrollViewer_CenterData.HorizontalOffset + this.ScrollViewer_CenterData.ViewportWidth} -> {this.ScrollViewer_CenterData.ExtentWidth}");
  252. }
  253. private void TextBoxButtonCustom_CasedIdEvent(TextBoxButtonCustom arg1, string arg2)
  254. {
  255. if (vm == null || arg1 == null) return;
  256. if (!arg1.IsLoaded) return;
  257. vm.SetCaseId(arg2);
  258. }
  259. private void TextBoxButtonCustom_CycleEvent(TextBoxButtonCustom arg1, string arg2)
  260. {
  261. if (vm == null || arg1 == null) return;
  262. if (!arg1.IsLoaded) return;
  263. vm.SetCycle(arg2);
  264. }
  265. private void HouesChart_Click(object sender, RoutedEventArgs e)
  266. {
  267. if (this.Canvas_OpenSearch.Visibility == Visibility.Visible)
  268. {
  269. this.Canvas_OpenSearch.Visibility = Visibility.Hidden;
  270. this.ButtonLeftImage_Search.Content = KeyToStringConvert.GetLanguageStringByKey("0269");
  271. this.ButtonLeftImage_Search.IconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DishOpenStateIcon.png", UriKind.Absolute));
  272. this.ButtonLeftImage_Search.MouseOverIconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DishOpenStateMouseOverIcon.png", UriKind.Absolute));
  273. }
  274. else
  275. {
  276. this.Canvas_OpenSearch.Visibility = Visibility.Visible;
  277. //this.ButtonLeftImage_Search.Content = "收起";
  278. this.ButtonLeftImage_Search.Content = KeyToStringConvert.GetLanguageStringByKey("0270");
  279. this.ButtonLeftImage_Search.IconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DishCloseStateIcon.png", UriKind.Absolute));
  280. this.ButtonLeftImage_Search.MouseOverIconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DishCloseStateMouseOverIcon.png", UriKind.Absolute));
  281. }
  282. }
  283. private void _itemsBorder_MouseEnter(object sender, MouseEventArgs e)
  284. {
  285. if (vm == null) return;
  286. if (!(sender is Border source)) return;
  287. if (!source.IsLoaded) return;
  288. if (!(source.Tag is DishRecordEntity dishRecordEntity)) return;
  289. dishRecordEntity.IsMouseOver = true;
  290. }
  291. private void _itemsBorder_MouseLeave(object sender, MouseEventArgs e)
  292. {
  293. if (vm == null) return;
  294. if (!(sender is Border source)) return;
  295. if (!source.IsLoaded) return;
  296. if (!(source.Tag is DishRecordEntity dishRecordEntity)) return;
  297. dishRecordEntity.IsMouseOver = false;
  298. }
  299. private void AI_MouseDown(object sender, MouseButtonEventArgs e)
  300. {
  301. try
  302. {
  303. if (!this.IsLoaded) return;
  304. if (vm == null) return;
  305. if (!(sender is ImageCustom source)) return;
  306. if (!source.IsLoaded) return;
  307. if (!(source.Tag is DishRecordEntity dishRecordEntity)) return;
  308. vm.OpenPdfView(dishRecordEntity);
  309. return;
  310. }
  311. finally
  312. {
  313. e.Handled = true;
  314. }
  315. }
  316. private void ItemsControl_MouseEnter(object sender, MouseEventArgs e)
  317. {
  318. }
  319. protected void ToastMessageShow(string mess)
  320. {
  321. new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, mess).Show();
  322. }
  323. private void ExportDish_Click(object sender, RoutedEventArgs e)
  324. {
  325. try
  326. {
  327. if (vm == null) return;
  328. if (vm.DishRecordList != null && vm.DishRecordList.Any())
  329. {
  330. var dishList = vm.DishRecordList.Where(x => x.IsCheck).ToList();
  331. if (dishList.Any())
  332. {
  333. ExportDishResponse exportDishResponse = new ExportDishResponse();
  334. AppData.Instance.MainWindowViewModel.MaskVisibility = true;
  335. ExportDishWindow exportDishWindow = new ExportDishWindow(exportDishResponse);
  336. if (exportDishWindow.ShowDialog() == true)
  337. {
  338. if (new MessageBoxWindow(KeyToStringConvert.GetLanguageStringByKey("0304"), KeyToStringConvert.GetLanguageStringByKey("0619"), AppData.Instance.MainWindow).ShowDialog() == true)
  339. {
  340. DownLoadFile(exportDishResponse, dishList);
  341. }
  342. }
  343. AppData.Instance.MainWindowViewModel.MaskVisibility = false;
  344. return;
  345. }
  346. }
  347. ExportDishResponse exportDishResponse1 = new ExportDishResponse();
  348. AppData.Instance.MainWindowViewModel.MaskVisibility = true;
  349. ExportDishWindow exportDishWindow1 = new ExportDishWindow(exportDishResponse1);
  350. if (exportDishWindow1.ShowDialog() == true)
  351. {
  352. if (new MessageBoxWindow(KeyToStringConvert.GetLanguageStringByKey("0304"), KeyToStringConvert.GetLanguageStringByKey("0628"), AppData.Instance.MainWindow).ShowDialog() == true)
  353. {
  354. var allDish = vm.GetAllDishRecord();
  355. if (allDish == null || !allDish.Any())
  356. {
  357. ToastMessageShow(KeyToStringConvert.GetLanguageStringByKey("0629"));
  358. return;
  359. }
  360. DownLoadFile(exportDishResponse1, allDish);
  361. }
  362. }
  363. AppData.Instance.MainWindowViewModel.MaskVisibility = false;
  364. }
  365. finally
  366. {
  367. AppData.Instance.MainWindowViewModel.MaskVisibility = false;
  368. }
  369. }
  370. private void DownLoadFile(ExportDishResponse exportDishResponse, List<DishRecordEntity> dishList)
  371. {
  372. AppData.Instance.MainWindowViewModel.MaskVisibility = false;
  373. string timeString = DateTime.Now.ToString("yyyy-MM-dd-HH-mm");
  374. string fileName;
  375. foreach (var item in dishList)
  376. {
  377. if (string.IsNullOrEmpty(item.husband))
  378. {
  379. fileName = $"{timeString}{item.wife}_{item.id}.zip";
  380. }
  381. else
  382. {
  383. fileName = $"{timeString}{item.wife}_{item.husband}_{item.id}.zip";
  384. }
  385. Dictionary<string, string> KeyBody = new Dictionary<string, string>();
  386. KeyBody.Add("houseSn", item.houseSn.ToString());
  387. KeyBody.Add("tlSn", item.tlSn);
  388. KeyBody.Add("freezing", exportDishResponse.freezing.ToString());
  389. KeyBody.Add("invalid", exportDishResponse.invalid.ToString());
  390. KeyBody.Add("transplant", exportDishResponse.transplant.ToString());
  391. KeyBody.Add("deleted", exportDishResponse.deleted.ToString());
  392. KeyBody.Add("unmark", exportDishResponse.unmark.ToString());
  393. KeyBody.Add("ids", item.id.ToString());
  394. DownLoadEntity downLoad = new ivf_tl_Entity.Entity.DownLoad.DownLoadEntity
  395. {
  396. DownLoadUrl = $"/api/businessManage/pc/resource/exportPictures?{string.Join("&", KeyBody.Select(kv => $"{Uri.EscapeDataString(kv.Key)}={Uri.EscapeDataString(kv.Value)}"))}",
  397. NewFileFullName = Path.Combine(exportDishResponse.tlSn, fileName),
  398. FileName = fileName,
  399. };
  400. AppData.Instance.MainWindowViewModel.DownLoadStart(downLoad);
  401. }
  402. ToastMessageShow(KeyToStringConvert.GetLanguageStringByKey("0299"));
  403. return;
  404. }
  405. private void Item_Unchecked(object sender, RoutedEventArgs e)
  406. {
  407. if (vm == null || !this.IsLoaded) return;
  408. //if (vm.DishRecordList.FirstOrDefault(x => x.IsCheck) == null)
  409. //{
  410. // this._exportDish.IsEnabled = false;
  411. //}
  412. //else
  413. //{
  414. // this._exportDish.IsEnabled = true;
  415. //}
  416. NoUp = true;
  417. this._all_CheckBox1.IsChecked = false;
  418. NoUp = false;
  419. }
  420. private void Item_Checked(object sender, RoutedEventArgs e)
  421. {
  422. if (vm == null || !this.IsLoaded) return;
  423. //if (vm.DishRecordList.FirstOrDefault(x => x.IsCheck) == null)
  424. //{
  425. // this._exportDish.IsEnabled = false;
  426. //}
  427. //else
  428. //{
  429. // this._exportDish.IsEnabled = true;
  430. //}
  431. if (vm.DishRecordList.FirstOrDefault(x => !x.IsCheck) == null)
  432. {
  433. NoUp = true;
  434. this._all_CheckBox1.IsChecked = true;
  435. NoUp = false;
  436. }
  437. }
  438. bool NoUp = false;
  439. private void All_Checked(object sender, RoutedEventArgs e)
  440. {
  441. if (vm == null || NoUp || !this.IsLoaded) return;
  442. foreach (var item in vm.DishRecordList)
  443. {
  444. item.IsCheck = true;
  445. }
  446. }
  447. private void All_UnChecked(object sender, RoutedEventArgs e)
  448. {
  449. if (vm == null || NoUp || !this.IsLoaded) return;
  450. foreach (var item in vm.DishRecordList)
  451. {
  452. item.IsCheck = false;
  453. }
  454. }
  455. }
  456. }