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 viewCheckBoxImageList = new ObservableCollection(); public int PicPageSize { get; set; } = 36; public List EmbryoPicViewList { get; set; } = new List(); public EmbryoPicView CurrentEmbryoPicView { get; set; } = null; public LayerPictureView CurrentLayerPicView { get; set; } = null; public List ShowPictureList { get; set; } = new List(); public List ButtonRightImageList = new List(); public List CheckBoxNoFrameCustomList = new List(); 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> currentEmbryoPic = new Dictionary>(); //List newList = new List(); //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 settings = new List(); 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 { CurrentEmbryo.wellSn }, new List { focal }); // var aa = focalList.FirstOrDefault(x => x.pictureLayer == focal); // if (aa != null) CurrentEmbryoAllPicDic.Add(focal, aa.pictureList); // else CurrentEmbryoAllPicDic.Add(focal, new List()); // } // else // { // CurrentEmbryoAllPicDic.Add(focal, new List()); // } //} //List allList = CurrentEmbryoAllPicDic[focal]; //if (CheckBoxNoFrameCustomList.Any()) //{ // List settings = new List(); // 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 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 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 }), }); } } }