PhotoPageView.xaml.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. using ivf_tl_Entity;
  2. using ivf_tl_Entity.GlobalEntitys;
  3. using ivf_tl_Entity.GlobalEnums;
  4. using ivf_tl_Operate.Converts;
  5. using ivf_tl_Operate.CustomUserControls;
  6. using ivf_tl_Operate.ViewModel;
  7. using ivf_tl_Operate.Windows;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Navigation;
  21. using System.Windows.Shapes;
  22. namespace ivf_tl_Operate.View
  23. {
  24. /// <summary>
  25. /// PhotoPageView.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class PhotoPageView : UserControl
  28. {
  29. private PhotoPageViewModel vm;
  30. public DetailPageViewModel parentVm;
  31. public List<PhotoBox> PhotoBoxes { get; set; } = new List<PhotoBox>();
  32. //private List<PhotoButton> photoButtons = new List<PhotoButton>();
  33. public int WellSn = 0;
  34. public PhotoPageView(DetailPageViewModel parentVm1, int wellSn)
  35. {
  36. InitializeComponent();
  37. WellSn = wellSn;
  38. //this._well_textbolock.Text = $"well{wellSn}原图";
  39. this._well_textbolock.Text = $"well{wellSn}{Environment.NewLine}{KeyToStringConvert.GetLanguageStringByKey("C0236")}";
  40. parentVm = parentVm1;
  41. for (int i = 1; i < 17; i++)
  42. {
  43. PhotoBox photoBox = new PhotoBox();
  44. photoBox.ID = i;
  45. photoBox.Tag = i;
  46. photoBox.Visibility = Visibility.Hidden;
  47. photoBox.MouseUp += PhotoBox_MouseUp;
  48. this.PhotoBoxes.Add(photoBox);
  49. _container.Children.Add(photoBox);
  50. }
  51. this._photoButton1.PhotoBoxSetting = new PhotoBoxSetting() { MinHour = 0, MaxHour = 24 * 60, MinHour1 = 16 * 60, MaxHour1 = 18 * 60, name = "0-24", name1 = "16-18" };
  52. this._photoButton2.PhotoBoxSetting = new PhotoBoxSetting() { MinHour = 24 * 60, MaxHour = 48 * 60, MinHour1 = 26 * 60, MaxHour1 = 28 * 60, name = "24-48", name1 = "26-28" };
  53. this._photoButton3.PhotoBoxSetting = new PhotoBoxSetting() { MinHour = 48 * 60, MaxHour = 72 * 60, MinHour1 = 36 * 60, MaxHour1 = 38 * 60, name = "48-72", name1 = "36-38" };
  54. this._photoButton4.PhotoBoxSetting = new PhotoBoxSetting() { MinHour = 72 * 60, MaxHour = 96 * 60, MinHour1 = 46 * 60, MaxHour1 = 48 * 60, name = "72-96", name1 = "46-48" };
  55. this._photoButton5.PhotoBoxSetting = new PhotoBoxSetting() { MinHour = 96 * 60, MaxHour = 120 * 60, MinHour1 = 56 * 60, MaxHour1 = 58 * 60, name = "96-120", name1 = "56-68" };
  56. this._photoButton6.PhotoBoxSetting = new PhotoBoxSetting() { MinHour = 120 * 60, MaxHour = 144 * 60, MinHour1 = 66 * 60, MaxHour1 = 68 * 60, name = "120-144", name1 = "66-68" };
  57. this._photoButton7.PhotoBoxSetting = new PhotoBoxSetting() { MinHour = 144 * 60, MaxHour = 0, MinHour1 = 76 * 60, MaxHour1 = 78 * 60, name = "144+", name1 = "76-78" };
  58. var b11 = AppData.Instance.HttpHelper.GetTimeButtonsApi();
  59. PhotoBoxSetting pho = null;
  60. List<ButtonEntity> b = new List<ButtonEntity>();
  61. foreach (var item in b11)
  62. {
  63. if (item.type == "COMMON_BUTTON")
  64. {
  65. b = item.button.Take(7).OrderBy(x => x.minHour).ToList();
  66. for (int i = 0; i < b.Count; i++)
  67. {
  68. var item1 = b[i];
  69. switch (i)
  70. {
  71. case 0:
  72. pho = this._photoButton1.PhotoBoxSetting;
  73. if (pho == null) pho = new PhotoBoxSetting();
  74. pho.MinHour = item1.minHour * 60;
  75. pho.MaxHour = item1.maxHour * 60;
  76. pho.name = item1.buttonName;
  77. break;
  78. case 1:
  79. pho = this._photoButton2.PhotoBoxSetting;
  80. if (pho == null) pho = new PhotoBoxSetting();
  81. pho.MinHour = item1.minHour * 60;
  82. pho.MaxHour = item1.maxHour * 60;
  83. pho.name = item1.buttonName;
  84. break;
  85. case 2:
  86. pho = this._photoButton3.PhotoBoxSetting;
  87. if (pho == null) pho = new PhotoBoxSetting();
  88. pho.MinHour = item1.minHour * 60;
  89. pho.MaxHour = item1.maxHour * 60;
  90. pho.name = item1.buttonName;
  91. break;
  92. case 3:
  93. pho = this._photoButton4.PhotoBoxSetting;
  94. if (pho == null) pho = new PhotoBoxSetting();
  95. pho.MinHour = item1.minHour * 60;
  96. pho.MaxHour = item1.maxHour * 60;
  97. pho.name = item1.buttonName;
  98. break;
  99. case 4:
  100. pho = this._photoButton5.PhotoBoxSetting;
  101. if (pho == null) pho = new PhotoBoxSetting();
  102. pho.MinHour = item1.minHour * 60;
  103. pho.MaxHour = item1.maxHour * 60;
  104. pho.name = item1.buttonName;
  105. break;
  106. case 5:
  107. pho = this._photoButton6.PhotoBoxSetting;
  108. if (pho == null) pho = new PhotoBoxSetting();
  109. pho.MinHour = item1.minHour * 60;
  110. pho.MaxHour = item1.maxHour * 60;
  111. pho.name = item1.buttonName;
  112. break;
  113. case 6:
  114. pho = this._photoButton7.PhotoBoxSetting;
  115. if (pho == null) pho = new PhotoBoxSetting();
  116. pho.MinHour = item1.minHour * 60;
  117. pho.MaxHour = item1.maxHour * 60;
  118. pho.name = item1.buttonName;
  119. break;
  120. }
  121. }
  122. }
  123. else if (item.type == "KEY_BUTTON")
  124. {
  125. b = item.button.Take(7).OrderBy(x => x.minHour).ToList();
  126. for (int i = 0; i < b.Count; i++)
  127. {
  128. var item1 = b[i];
  129. switch (i)
  130. {
  131. case 0:
  132. pho = this._photoButton1.PhotoBoxSetting;
  133. if (pho == null) pho = new PhotoBoxSetting();
  134. pho.MinHour1 = item1.minHour * 60;
  135. pho.MaxHour1 = item1.maxHour * 60;
  136. pho.name1 = item1.buttonName;
  137. break;
  138. case 1:
  139. pho = this._photoButton2.PhotoBoxSetting;
  140. if (pho == null) pho = new PhotoBoxSetting();
  141. pho.MinHour1 = item1.minHour * 60;
  142. pho.MaxHour1 = item1.maxHour * 60;
  143. pho.name1 = item1.buttonName;
  144. break;
  145. case 2:
  146. pho = this._photoButton3.PhotoBoxSetting;
  147. if (pho == null) pho = new PhotoBoxSetting();
  148. pho.MinHour1 = item1.minHour * 60;
  149. pho.MaxHour1 = item1.maxHour * 60;
  150. pho.name1 = item1.buttonName;
  151. break;
  152. case 3:
  153. pho = this._photoButton4.PhotoBoxSetting;
  154. if (pho == null) pho = new PhotoBoxSetting();
  155. pho.MinHour1 = item1.minHour * 60;
  156. pho.MaxHour1 = item1.maxHour * 60;
  157. pho.name1 = item1.buttonName;
  158. break;
  159. case 4:
  160. pho = this._photoButton5.PhotoBoxSetting;
  161. if (pho == null) pho = new PhotoBoxSetting();
  162. pho.MinHour1 = item1.minHour * 60;
  163. pho.MaxHour1 = item1.maxHour * 60;
  164. pho.name1 = item1.buttonName;
  165. break;
  166. case 5:
  167. pho = this._photoButton6.PhotoBoxSetting;
  168. if (pho == null) pho = new PhotoBoxSetting();
  169. pho.MinHour1 = item1.minHour * 60;
  170. pho.MaxHour1 = item1.maxHour * 60;
  171. pho.name1 = item1.buttonName;
  172. break;
  173. case 6:
  174. pho = this._photoButton7.PhotoBoxSetting;
  175. if (pho == null)
  176. {
  177. pho = new PhotoBoxSetting();
  178. }
  179. pho.MinHour1 = item1.minHour * 60;
  180. pho.MaxHour1 = item1.maxHour * 60;
  181. pho.name1 = item1.buttonName;
  182. break;
  183. }
  184. }
  185. }
  186. }
  187. Loaded += (s, e) =>
  188. {
  189. vm = this.DataContext as PhotoPageViewModel;
  190. if (vm == null) return;
  191. vm.PhotoButtonList.Add(_photoButton1);
  192. vm.PhotoButtonList.Add(_photoButton2);
  193. vm.PhotoButtonList.Add(_photoButton3);
  194. vm.PhotoButtonList.Add(_photoButton4);
  195. vm.PhotoButtonList.Add(_photoButton5);
  196. vm.PhotoButtonList.Add(_photoButton6);
  197. vm.PhotoButtonList.Add(_photoButton7);
  198. vm.PhotoToggle = false;
  199. InitializeToggle(false, false);
  200. //_box.Children.Clear();
  201. //for (int i = vm.MinFocal; i <= vm.MaxFocal; i++)
  202. //{
  203. // int k = i;
  204. // Border itembor = new Border();
  205. // itembor.Width = 178;
  206. // itembor.Height = 80;
  207. // itembor.Margin = new Thickness(10);
  208. // itembor.BorderThickness = new Thickness(0, 0, 0, 1);
  209. // itembor.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#DDDEE0"));
  210. // itembor.Background = new SolidColorBrush(Colors.Transparent);
  211. // itembor.Tag = i;
  212. // itembor.VerticalAlignment = VerticalAlignment.Center;
  213. // itembor.HorizontalAlignment = HorizontalAlignment.Center;
  214. // TextBlock itemText = new TextBlock();
  215. // itemText.FontSize = 44;
  216. // itemText.VerticalAlignment = VerticalAlignment.Center;
  217. // itemText.HorizontalAlignment = HorizontalAlignment.Center;
  218. // itemText.Text = i.ToString();
  219. // itemText.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3A5F91"));
  220. // itemText.TextAlignment = TextAlignment.Center;
  221. // //itemText.Background = new SolidColorBrush(Colors.LightBlue);
  222. // itembor.Child = itemText;
  223. // itembor.MouseUp += (s, e) =>
  224. // {
  225. // _popupLiquid.IsOpen = false;
  226. // if (k.ToString() == this._picNum_TextBlock.Text)
  227. // {
  228. // return;
  229. // }
  230. // this._picNum_TextBlock.Text = k.ToString();
  231. // vm.CurrentPicLayer = k;
  232. // vm.SetCurrentPicViewList();
  233. // vm.SetShowPicViewList();
  234. // //var temp = s as Border;
  235. // //string newpicnum = temp.Tag.ToString();
  236. // //string oldpicnum = this._picNum_TextBlock.Text;
  237. // //if (newpicnum != oldpicnum)
  238. // //{
  239. // // this._picNum_TextBlock.Text = temp.Tag.ToString();
  240. // // // GetAllPhotos((int)temp.Tag);
  241. // //}
  242. // };
  243. // _box.Children.Add(itembor);
  244. //}
  245. vm.SetShowPicViewList();
  246. };
  247. Unloaded += (s, e) =>
  248. {
  249. this.Grid_Root.Children.Clear();
  250. if (vm != null) vm = null;
  251. this.DataContext = null;
  252. };
  253. }
  254. private void PhotoBox_MouseUp(object sender, MouseButtonEventArgs e)
  255. {
  256. if (AppData.Instance.MainWindow == null) return;
  257. if (!(sender is PhotoBox box)) return;
  258. if (vm == null) return;
  259. AppData.Instance.MainWindow.Mark(true);
  260. //PhotoWindow win = new PhotoWindow(uri);
  261. //win.ShowDialog();
  262. new PhotoWindowNew(vm.ShowPicViewList, box.ID, vm.IsSourcePic).ShowDialog();
  263. AppData.Instance.MainWindow.Mark(false);
  264. }
  265. private void InitializeToggle(bool photoToggle, bool isRefresh)
  266. {
  267. if (vm == null) return;
  268. bool b = false;
  269. if (isRefresh)
  270. {
  271. if (vm.PhotoButtonList.FirstOrDefault(x => x.IsSelected) != null)
  272. {
  273. b = true;
  274. }
  275. }
  276. foreach (var button in vm.PhotoButtonList)
  277. {
  278. button.IsSelected = false;
  279. if (photoToggle)
  280. {
  281. button.Content = button.PhotoBoxSetting.name1;
  282. }
  283. else
  284. {
  285. button.Content = button.PhotoBoxSetting.name;
  286. }
  287. }
  288. if (b)
  289. {
  290. vm.SetShowPicViewList();
  291. }
  292. }
  293. private void Return_Click(object sender, RoutedEventArgs e)
  294. {
  295. DetailPageView detailPageView = new DetailPageView()
  296. {
  297. DataContext = parentVm,
  298. };
  299. AppData.Instance.MainWindow.LoadPage(detailPageView);
  300. }
  301. private void Image_MouseUp_PhotoToggle(object sender, MouseButtonEventArgs e)
  302. {
  303. if (!(sender is PhotoToggle photoToggle)) return;
  304. vm.PhotoToggle = photoToggle.IsOpen;
  305. InitializeToggle(photoToggle.IsOpen, true);
  306. }
  307. private void CustomControlPagination_PageChangedEvent(int obj)
  308. {
  309. if (vm == null) return;
  310. foreach (var item in PhotoBoxes)
  311. {
  312. item.Visibility = Visibility.Hidden;
  313. }
  314. vm.PageIndex = obj;
  315. var list = vm.ShowPicViewList.Skip(vm.PageSize * (obj - 1)).Take(vm.PageSize).ToList();
  316. for (int i = 0; i < list.Count; i++)
  317. {
  318. this.PhotoBoxes[i].ID = list[i].Num;
  319. if (vm.IsSourcePic)
  320. {
  321. this.PhotoBoxes[i].ImageSource = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{list[i].sourceImageUrl.Replace(AppData.Instance.PicSuf, $"_240x240{AppData.Instance.PicSuf}")}?token={AppData.Instance.HttpHelper.GetToken()}");
  322. }
  323. else
  324. {
  325. this.PhotoBoxes[i].ImageSource = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{list[i].imageUrl.Replace(AppData.Instance.PicSuf, $"_240x240{AppData.Instance.PicSuf}")}?token={AppData.Instance.HttpHelper.GetToken()}");
  326. }
  327. this.PhotoBoxes[i].peiYangShiChang = list[i].imageTime.ToString("MM-dd HH:mm");
  328. this.PhotoBoxes[i].Visibility = Visibility.Visible;
  329. }
  330. }
  331. private void _BorderLiquid_MouseUp(object sender, MouseButtonEventArgs e)
  332. {
  333. //if (_popupLiquid.IsOpen) _popupLiquid.IsOpen = false;
  334. //else _popupLiquid.IsOpen = true;
  335. }
  336. private void TextBlock_MouseUp(object sender, MouseButtonEventArgs e)
  337. {
  338. if (vm == null) return;
  339. if (vm.IsSourcePic)
  340. {
  341. vm.IsSourcePic = false;
  342. //this._well_textbolock.Text = $"well{WellSn}原图";
  343. this._well_textbolock.Text = $"well{WellSn}{Environment.NewLine}{KeyToStringConvert.GetLanguageStringByKey("C0236")}";
  344. vm.SetCurrentPicViewList();
  345. vm.SetShowPicViewList();
  346. }
  347. else
  348. {
  349. vm.IsSourcePic = true;
  350. //this._well_textbolock.Text = $"well{WellSn}抠图";
  351. this._well_textbolock.Text = $"well{WellSn}{Environment.NewLine}{KeyToStringConvert.GetLanguageStringByKey("C0236")}";
  352. vm.SetCurrentPicViewList();
  353. vm.SetShowPicViewList();
  354. }
  355. }
  356. private void Image_MouseUp_Output(object sender, MouseButtonEventArgs e)
  357. {
  358. }
  359. private void ChangePicNum_MouseUp(object sender, MouseButtonEventArgs e)
  360. {
  361. }
  362. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  363. {
  364. }
  365. private void PhotoButton_MouseUp(object sender, MouseButtonEventArgs e)
  366. {
  367. if (vm == null) return;
  368. if (!(sender is PhotoButton button)) return;
  369. button.IsSelected = !button.IsSelected;
  370. vm.SetShowPicViewList();
  371. }
  372. private void BigFocus_Click(object sender, MouseButtonEventArgs e)
  373. {
  374. ChangeFocal(true);
  375. }
  376. private void SmallFocus_Click(object sender, MouseButtonEventArgs e)
  377. {
  378. ChangeFocal(false);
  379. }
  380. /// <summary>
  381. /// 切换图层
  382. /// </summary>
  383. /// <param name="isMax"></param>
  384. private void ChangeFocal(bool isMax)
  385. {
  386. try
  387. {
  388. if (vm == null) return;
  389. int newCurrentFocal = vm.CurrentPicLayer;
  390. if (isMax) newCurrentFocal++;
  391. else newCurrentFocal--;
  392. if (newCurrentFocal < vm.MaxFocal)
  393. {
  394. this._bigFocal_Button.IsEnabled = true;
  395. this._bigFocal_Button.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/DetailBigFocusIcon.png", UriKind.Relative));
  396. }
  397. else
  398. {
  399. this._bigFocal_Button.IsEnabled = false;
  400. this._bigFocal_Button.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/DetailBigFocusEnableIcon.png", UriKind.Relative));
  401. }
  402. if (newCurrentFocal > vm.MinFocal)
  403. {
  404. this._smallFocal_Button.IsEnabled = true;
  405. this._smallFocal_Button.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/DetailSmallFocusIcon.png", UriKind.Relative));
  406. }
  407. else
  408. {
  409. this._smallFocal_Button.IsEnabled = false;
  410. this._smallFocal_Button.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/DetailSmallFocusEnableIcon.png", UriKind.Relative));
  411. }
  412. if (newCurrentFocal < vm.MinFocal || newCurrentFocal > vm.MaxFocal) return;
  413. vm.CurrentPicLayer = newCurrentFocal;
  414. vm.SetCurrentPicViewList();
  415. vm.SetShowPicViewList();
  416. }
  417. catch (Exception ex)
  418. {
  419. AppData.Instance.LogHelper.TLLog($"PhotoPageView.{ChangeFocal}", LogEnum.RunException);
  420. }
  421. }
  422. }
  423. }