| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- using CommunityToolkit.Mvvm.ComponentModel;
- using ivf_tl_CustomControls;
- using ivf_tl_Entity.Entity;
- using ivf_tl_Entity.Entity.balance;
- using ivf_tl_Entity.Entity.Result;
- using ivf_tl_Entity.Pic;
- using ivf_tl_Manage.Converts;
- using ivf_tl_Manage.UserControls;
- using ivf_tl_Service.HttpProvider;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace ivf_tl_Manage.ViewModels
- {
- public partial class DetailPicViewModel : BaseViewModel
- {
- [ObservableProperty]
- private Dish currentDish;
- [ObservableProperty]
- private Embryo currentEmbryo = null;
- [ObservableProperty]
- private int currentFocal = 0;
- [ObservableProperty]
- private int picDataCount = 0;
- [ObservableProperty]
- private int currentPage = 1;
- [ObservableProperty]
- private ObservableCollection<PicUserControl> viewCheckBoxImageList = new ObservableCollection<PicUserControl>();
- public int PicPageSize { get; set; } = 36;
- public List<EmbryoPicView> EmbryoPicViewList { get; set; } = new List<EmbryoPicView>();
- public EmbryoPicView CurrentEmbryoPicView { get; set; } = null;
- public LayerPictureView CurrentLayerPicView { get; set; } = null;
- public List<PictureView> ShowPictureList { get; set; } = new List<PictureView>();
- public List<ButtonRightImage> ButtonRightImageList = new List<ButtonRightImage>();
- public List<CheckBoxNoFrameCustom> CheckBoxNoFrameCustomList = new List<CheckBoxNoFrameCustom>();
- public int MaxFocal = 0;
- public int MinFocal = 0;
- private PicProvider picProvider = null;
- public TLInfo tLInfo = null;
- public DetailPicViewModel(DetailViewModel detailViewModel, int MaxTotalLayer, int wellSn)
- {
- base.NavName = KeyToStringConvert.GetLanguageStringByKey("0161");
- base.NavList.Clear();
- foreach (var item in detailViewModel.NavList)
- {
- base.NavList.Add(item);
- }
- base.NavList.Add(this);
- base.ViewModelName = nameof(DetailPicViewModel);
- picProvider = AppData.Instance.GetPicProvider();
- CurrentDish = detailViewModel.CurrentDish;
- GetMaxAndMinFocal(MaxTotalLayer);
- if (CurrentDish.embryoList != null && CurrentDish.embryoList.Any())
- {
- CurrentDish.embryoList = CurrentDish.embryoList.OrderBy(x => x.wellSn).ToList();
- CurrentEmbryo = CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == wellSn);
- if (CurrentEmbryo == null) CurrentEmbryo = CurrentDish.embryoList.First();
- }
- }
- partial void OnCurrentEmbryoChanged(Embryo value)
- {
- CurrentEmbryoPicView = null;
- CurrentLayerPicView = null;
- if (value == null) return;
- CurrentEmbryoPicView = EmbryoPicViewList.FirstOrDefault(x => x.WellSn == value.wellSn);
- if (CurrentEmbryoPicView == null)
- {
- CurrentEmbryoPicView = new EmbryoPicView { WellSn = value.wellSn };
- EmbryoPicViewList.Add(CurrentEmbryoPicView);
- }
- CurrentFocal = 0;
- //GetCurrentEmbryoAllPic(value.wellSn);
- RefPic(CurrentFocal);
- }
- public void GetCurrentEmbryoAllPic(int wellsn)
- {
- //if (AllPicDic.ContainsKey(wellsn))
- //{
- // CurrentEmbryoAllPicDic = AllPicDic[wellsn];
- // GetMaxAndMinFocal();
- // return;
- //}
- //Dictionary<int, List<PictureEntity>> currentEmbryoPic = new Dictionary<int, List<PictureEntity>>();
- //List<PictureEntity> newList = new List<PictureEntity>();
- //var picAndVideo = AllEmbryoPicAndVideo.FirstOrDefault(x => x.wellSn == wellsn);
- //if (picAndVideo != null && picAndVideo.videoPictures != null)
- //{
- // foreach (var item in picAndVideo.videoPictures)
- // {
- // newList.Add(item);
- // }
- //}
- //currentEmbryoPic.Add(0, newList);
- //CurrentEmbryoAllPicDic = currentEmbryoPic;
- //AllPicDic.Add(wellsn, CurrentEmbryoAllPicDic);
- //GetMaxAndMinFocal();
- }
- public void GetMaxAndMinFocal(int MaxTotalLayer)
- {
- if (MaxTotalLayer <= 0)
- {
- MaxFocal = 0;
- MinFocal = 0;
- return;
- }
- MaxFocal = (MaxTotalLayer - 1) / 2;
- MinFocal = -MaxFocal;
- }
- public void RefPic(int focal)
- {
- ShowPictureList.Clear();
- if (CurrentEmbryoPicView == null) return;
- CurrentLayerPicView = CurrentEmbryoPicView.pictureViews.FirstOrDefault(x => x.pictureLayer == focal);
- if (CurrentLayerPicView == null)
- {
- CurrentLayerPicView = new LayerPictureView { pictureLayer = focal };
- CurrentEmbryoPicView.pictureViews.Add(CurrentLayerPicView);
- }
- if (CurrentLayerPicView.PictureViews == null || !CurrentLayerPicView.PictureViews.Any())
- {
- CurrentLayerPicView.PictureViews = picProvider.GetPictureViewApi(CurrentEmbryo.tlSn, CurrentEmbryo.houseSn, CurrentEmbryo.id, focal);
- }
- if (CheckBoxNoFrameCustomList.Any())
- {
- List<PhotoBoxSetting> settings = new List<PhotoBoxSetting>();
- foreach (var item in CheckBoxNoFrameCustomList) if (item.Tag is PhotoBoxSetting itemsetting) settings.Add(itemsetting);
- foreach (var photo in CurrentLayerPicView.PictureViews)
- {
- for (int i = 0; i < settings.Count; i++)
- {
- PhotoBoxSetting setting = settings[i];
- if (photo.developTime >= setting.MinHour && photo.developTime <= setting.MaxHour)
- {
- ShowPictureList.Add(photo);
- break;
- }
- }
- }
- }
- else
- {
- foreach (var item in CurrentLayerPicView.PictureViews) ShowPictureList.Add(item);
- }
- PicDataCount = -1;
- PicDataCount = ShowPictureList.Count;
- return;
- //ShowPicList.Clear();
- //if (!CurrentEmbryoAllPicDic.ContainsKey(focal))
- //{
- // if (CurrentEmbryo != null)
- // {
- // var focalList = picProvider.SwitchVideoPictureLayersApi(CurrentEmbryo.tlSn, CurrentEmbryo.houseSn, CurrentEmbryo.embryoCultureRecordId, new List<int> { CurrentEmbryo.wellSn }, new List<int> { focal });
- // var aa = focalList.FirstOrDefault(x => x.pictureLayer == focal);
- // if (aa != null) CurrentEmbryoAllPicDic.Add(focal, aa.pictureList);
- // else CurrentEmbryoAllPicDic.Add(focal, new List<PictureEntity>());
- // }
- // else
- // {
- // CurrentEmbryoAllPicDic.Add(focal, new List<PictureEntity>());
- // }
- //}
- //List<PictureEntity> allList = CurrentEmbryoAllPicDic[focal];
- //if (CheckBoxNoFrameCustomList.Any())
- //{
- // List<PhotoBoxSetting> settings = new List<PhotoBoxSetting>();
- // foreach (var item in CheckBoxNoFrameCustomList) if (item.Tag is PhotoBoxSetting itemsetting) settings.Add(itemsetting);
- // foreach (var photo in allList)
- // {
- // for (int i = 0; i < settings.Count; i++)
- // {
- // PhotoBoxSetting setting = settings[i];
- // if (photo.developTime >= setting.MinHour && photo.developTime <= setting.MaxHour)
- // {
- // ShowPicList.Add(photo);
- // break;
- // }
- // }
- // }
- //}
- //else
- //{
- // foreach (var item in allList) ShowPicList.Add(item);
- //}
- //PicDataCount = -1;
- //PicDataCount = ShowPicList.Count;
- }
- public void DowloadPic(List<long> ids, string fileName)
- {
- AppData.Instance.MainWindowViewModel.DownLoadStart(new ivf_tl_Entity.Entity.DownLoad.DownLoadEntity
- {
- DownLoadUrl = $"/api/businessManage/pc/resource/downloadSelectPictures?tlSn={CurrentEmbryo.tlSn}&houseSn={CurrentEmbryo.houseSn}&ids={string.Join(",", ids)}",
- NewFileFullName = fileName,
- FileName = Path.GetFileName(fileName),
- });
- }
- public void DowLoadPic(List<long> ids, string fileName)
- {
- AppData.Instance.MainWindowViewModel.DownLoadStart(new ivf_tl_Entity.Entity.DownLoad.DownLoadEntity
- {
- DownLoadUrl = $"/api/businessManage/pc/resource/downloadSelectPictures",
- NewFileFullName = fileName,
- FileName = Path.GetFileName(fileName),
- Body = JsonConvert.SerializeObject(new { tlSn = CurrentEmbryo.tlSn, houseSn = CurrentEmbryo.houseSn, ids = ids }),
- });
- }
- }
- }
|