DetailPicViewModel.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using CommunityToolkit.Mvvm.ComponentModel;
  2. using ivf_tl_CustomControls;
  3. using ivf_tl_Entity.Entity;
  4. using ivf_tl_Entity.Entity.balance;
  5. using ivf_tl_Entity.Entity.Result;
  6. using ivf_tl_Entity.Pic;
  7. using ivf_tl_Manage.Converts;
  8. using ivf_tl_Manage.UserControls;
  9. using ivf_tl_Service.HttpProvider;
  10. using Newtonsoft.Json;
  11. using Newtonsoft.Json.Linq;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Collections.ObjectModel;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Windows;
  20. namespace ivf_tl_Manage.ViewModels
  21. {
  22. public partial class DetailPicViewModel : BaseViewModel
  23. {
  24. [ObservableProperty]
  25. private Dish currentDish;
  26. [ObservableProperty]
  27. private Embryo currentEmbryo = null;
  28. [ObservableProperty]
  29. private int currentFocal = 0;
  30. [ObservableProperty]
  31. private int picDataCount = 0;
  32. [ObservableProperty]
  33. private int currentPage = 1;
  34. [ObservableProperty]
  35. private ObservableCollection<PicUserControl> viewCheckBoxImageList = new ObservableCollection<PicUserControl>();
  36. public int PicPageSize { get; set; } = 36;
  37. public List<EmbryoPicView> EmbryoPicViewList { get; set; } = new List<EmbryoPicView>();
  38. public EmbryoPicView CurrentEmbryoPicView { get; set; } = null;
  39. public LayerPictureView CurrentLayerPicView { get; set; } = null;
  40. public List<PictureView> ShowPictureList { get; set; } = new List<PictureView>();
  41. public List<ButtonRightImage> ButtonRightImageList = new List<ButtonRightImage>();
  42. public List<CheckBoxNoFrameCustom> CheckBoxNoFrameCustomList = new List<CheckBoxNoFrameCustom>();
  43. public int MaxFocal = 0;
  44. public int MinFocal = 0;
  45. private PicProvider picProvider = null;
  46. public TLInfo tLInfo = null;
  47. public DetailPicViewModel(DetailViewModel detailViewModel, int MaxTotalLayer, int wellSn)
  48. {
  49. base.NavName = KeyToStringConvert.GetLanguageStringByKey("0161");
  50. base.NavList.Clear();
  51. foreach (var item in detailViewModel.NavList)
  52. {
  53. base.NavList.Add(item);
  54. }
  55. base.NavList.Add(this);
  56. base.ViewModelName = nameof(DetailPicViewModel);
  57. picProvider = AppData.Instance.GetPicProvider();
  58. CurrentDish = detailViewModel.CurrentDish;
  59. GetMaxAndMinFocal(MaxTotalLayer);
  60. if (CurrentDish.embryoList != null && CurrentDish.embryoList.Any())
  61. {
  62. CurrentDish.embryoList = CurrentDish.embryoList.OrderBy(x => x.wellSn).ToList();
  63. CurrentEmbryo = CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == wellSn);
  64. if (CurrentEmbryo == null) CurrentEmbryo = CurrentDish.embryoList.First();
  65. }
  66. }
  67. partial void OnCurrentEmbryoChanged(Embryo value)
  68. {
  69. CurrentEmbryoPicView = null;
  70. CurrentLayerPicView = null;
  71. if (value == null) return;
  72. CurrentEmbryoPicView = EmbryoPicViewList.FirstOrDefault(x => x.WellSn == value.wellSn);
  73. if (CurrentEmbryoPicView == null)
  74. {
  75. CurrentEmbryoPicView = new EmbryoPicView { WellSn = value.wellSn };
  76. EmbryoPicViewList.Add(CurrentEmbryoPicView);
  77. }
  78. CurrentFocal = 0;
  79. //GetCurrentEmbryoAllPic(value.wellSn);
  80. RefPic(CurrentFocal);
  81. }
  82. public void GetCurrentEmbryoAllPic(int wellsn)
  83. {
  84. //if (AllPicDic.ContainsKey(wellsn))
  85. //{
  86. // CurrentEmbryoAllPicDic = AllPicDic[wellsn];
  87. // GetMaxAndMinFocal();
  88. // return;
  89. //}
  90. //Dictionary<int, List<PictureEntity>> currentEmbryoPic = new Dictionary<int, List<PictureEntity>>();
  91. //List<PictureEntity> newList = new List<PictureEntity>();
  92. //var picAndVideo = AllEmbryoPicAndVideo.FirstOrDefault(x => x.wellSn == wellsn);
  93. //if (picAndVideo != null && picAndVideo.videoPictures != null)
  94. //{
  95. // foreach (var item in picAndVideo.videoPictures)
  96. // {
  97. // newList.Add(item);
  98. // }
  99. //}
  100. //currentEmbryoPic.Add(0, newList);
  101. //CurrentEmbryoAllPicDic = currentEmbryoPic;
  102. //AllPicDic.Add(wellsn, CurrentEmbryoAllPicDic);
  103. //GetMaxAndMinFocal();
  104. }
  105. public void GetMaxAndMinFocal(int MaxTotalLayer)
  106. {
  107. if (MaxTotalLayer <= 0)
  108. {
  109. MaxFocal = 0;
  110. MinFocal = 0;
  111. return;
  112. }
  113. MaxFocal = (MaxTotalLayer - 1) / 2;
  114. MinFocal = -MaxFocal;
  115. }
  116. public void RefPic(int focal)
  117. {
  118. ShowPictureList.Clear();
  119. if (CurrentEmbryoPicView == null) return;
  120. CurrentLayerPicView = CurrentEmbryoPicView.pictureViews.FirstOrDefault(x => x.pictureLayer == focal);
  121. if (CurrentLayerPicView == null)
  122. {
  123. CurrentLayerPicView = new LayerPictureView { pictureLayer = focal };
  124. CurrentEmbryoPicView.pictureViews.Add(CurrentLayerPicView);
  125. }
  126. if (CurrentLayerPicView.PictureViews == null || !CurrentLayerPicView.PictureViews.Any())
  127. {
  128. CurrentLayerPicView.PictureViews = picProvider.GetPictureViewApi(CurrentEmbryo.tlSn, CurrentEmbryo.houseSn, CurrentEmbryo.id, focal);
  129. }
  130. if (CheckBoxNoFrameCustomList.Any())
  131. {
  132. List<PhotoBoxSetting> settings = new List<PhotoBoxSetting>();
  133. foreach (var item in CheckBoxNoFrameCustomList) if (item.Tag is PhotoBoxSetting itemsetting) settings.Add(itemsetting);
  134. foreach (var photo in CurrentLayerPicView.PictureViews)
  135. {
  136. for (int i = 0; i < settings.Count; i++)
  137. {
  138. PhotoBoxSetting setting = settings[i];
  139. if (photo.developTime >= setting.MinHour && photo.developTime <= setting.MaxHour)
  140. {
  141. ShowPictureList.Add(photo);
  142. break;
  143. }
  144. }
  145. }
  146. }
  147. else
  148. {
  149. foreach (var item in CurrentLayerPicView.PictureViews) ShowPictureList.Add(item);
  150. }
  151. PicDataCount = -1;
  152. PicDataCount = ShowPictureList.Count;
  153. return;
  154. //ShowPicList.Clear();
  155. //if (!CurrentEmbryoAllPicDic.ContainsKey(focal))
  156. //{
  157. // if (CurrentEmbryo != null)
  158. // {
  159. // var focalList = picProvider.SwitchVideoPictureLayersApi(CurrentEmbryo.tlSn, CurrentEmbryo.houseSn, CurrentEmbryo.embryoCultureRecordId, new List<int> { CurrentEmbryo.wellSn }, new List<int> { focal });
  160. // var aa = focalList.FirstOrDefault(x => x.pictureLayer == focal);
  161. // if (aa != null) CurrentEmbryoAllPicDic.Add(focal, aa.pictureList);
  162. // else CurrentEmbryoAllPicDic.Add(focal, new List<PictureEntity>());
  163. // }
  164. // else
  165. // {
  166. // CurrentEmbryoAllPicDic.Add(focal, new List<PictureEntity>());
  167. // }
  168. //}
  169. //List<PictureEntity> allList = CurrentEmbryoAllPicDic[focal];
  170. //if (CheckBoxNoFrameCustomList.Any())
  171. //{
  172. // List<PhotoBoxSetting> settings = new List<PhotoBoxSetting>();
  173. // foreach (var item in CheckBoxNoFrameCustomList) if (item.Tag is PhotoBoxSetting itemsetting) settings.Add(itemsetting);
  174. // foreach (var photo in allList)
  175. // {
  176. // for (int i = 0; i < settings.Count; i++)
  177. // {
  178. // PhotoBoxSetting setting = settings[i];
  179. // if (photo.developTime >= setting.MinHour && photo.developTime <= setting.MaxHour)
  180. // {
  181. // ShowPicList.Add(photo);
  182. // break;
  183. // }
  184. // }
  185. // }
  186. //}
  187. //else
  188. //{
  189. // foreach (var item in allList) ShowPicList.Add(item);
  190. //}
  191. //PicDataCount = -1;
  192. //PicDataCount = ShowPicList.Count;
  193. }
  194. public void DowloadPic(List<long> ids, string fileName)
  195. {
  196. AppData.Instance.MainWindowViewModel.DownLoadStart(new ivf_tl_Entity.Entity.DownLoad.DownLoadEntity
  197. {
  198. DownLoadUrl = $"/api/businessManage/pc/resource/downloadSelectPictures?tlSn={CurrentEmbryo.tlSn}&houseSn={CurrentEmbryo.houseSn}&ids={string.Join(",", ids)}",
  199. NewFileFullName = fileName,
  200. FileName = Path.GetFileName(fileName),
  201. });
  202. }
  203. public void DowLoadPic(List<long> ids, string fileName)
  204. {
  205. AppData.Instance.MainWindowViewModel.DownLoadStart(new ivf_tl_Entity.Entity.DownLoad.DownLoadEntity
  206. {
  207. DownLoadUrl = $"/api/businessManage/pc/resource/downloadSelectPictures",
  208. NewFileFullName = fileName,
  209. FileName = Path.GetFileName(fileName),
  210. Body = JsonConvert.SerializeObject(new { tlSn = CurrentEmbryo.tlSn, houseSn = CurrentEmbryo.houseSn, ids = ids }),
  211. });
  212. }
  213. }
  214. }