using ivf_tl_Entity.Entity.balance; using ivf_tl_Entity.Enums; using ivf_tl_Entity.Pic; using ivf_tl_Manage.Converts; using ivf_tl_Manage.UserControls; using ivf_tl_Service.HttpProvider; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace ivf_tl_Manage.Win { /// /// ImageSourceNewWindow.xaml 的交互逻辑 /// public partial class ImageSourceNewWindow : Window { PicProvider picProvider = null; int houseSn; int pictureLayer; long embryoId; string tlSn; Dish dish; List FocalList = new List(); List PhotoBoxSettings = new List(); public ImageSourceNewWindow(Embryo embryo, int houseSn, int pictureLayer, string tlSn, Dish dish, int max, int min, List photoBoxSetting1s) { try { InitializeComponent(); this.Owner = AppData.Instance.MainWindow; PhotoBoxSettings = photoBoxSetting1s; this.houseSn = houseSn; this.pictureLayer = pictureLayer; this.tlSn = tlSn; picProvider = AppData.Instance.GetPicProvider(); GetMaxAndMinFocal(picProvider.GetSourcePicturesTotalLayerApi(tlSn, houseSn, dish.embryoList.First().id)); this.dish = dish; PicPageSize = 42; for (int i = MinFocal; i <= MaxFocal; i++) { FocalList.Add(i); } this.ComBox_Focal.ItemsSource = FocalList; this.ComBox_Focal.SelectedItem = pictureLayer; this.ComBox_Well.ItemsSource = this.dish.embryoList; if (embryo == null) { this.ComBox_Well.SelectedIndex = 0; } else { this.ComBox_Well.SelectedItem = embryo; } Loaded += (s, e) => { if (!this.dish.embryoList.Any()) return; long embryoIdC = this.dish.embryoList.First().id; if (embryo != null) embryoIdC = embryo.id; this.embryoId = embryoIdC; var aa = picProvider.GetImageSourcePageApi(embryoIdC, houseSn, pictureLayer, tlSn, 1, PicPageSize, PhotoBoxSettings); PicDataCount = aa.total; return; }; this.Closed += (a, b) => AppData.Instance.MainWindow.Activate(); Unloaded += (s, e) => { _root_Canvas.Children.Clear(); }; } catch (Exception ex) { ExLog(ex, "ImageSourceWindow"); } } int MaxFocal, MinFocal; public void GetMaxAndMinFocal(int MaxTotalLayer) { if (MaxTotalLayer <= 0) { MaxFocal = 0; MinFocal = 0; return; } MaxFocal = (MaxTotalLayer - 1) / 2; MinFocal = -MaxFocal; } public int PicPageSize { get { return (int)GetValue(PicPageSizeProperty); } set { SetValue(PicPageSizeProperty, value); } } // Using a DependencyProperty as the backing store for PicPageSize. This enables animation, styling, binding, etc... public static readonly DependencyProperty PicPageSizeProperty = DependencyProperty.Register("PicPageSize", typeof(int), typeof(ImageSourceNewWindow), new PropertyMetadata(-1)); public int PicDataCount { get { return (int)GetValue(PicDataCountProperty); } set { SetValue(PicDataCountProperty, value); } } // Using a DependencyProperty as the backing store for PicDataCount. This enables animation, styling, binding, etc... public static readonly DependencyProperty PicDataCountProperty = DependencyProperty.Register("PicDataCount", typeof(int), typeof(ImageSourceNewWindow), new PropertyMetadata(-1)); public int CurrentPage { get { return (int)GetValue(CurrentPageProperty); } set { SetValue(CurrentPageProperty, value); } } // Using a DependencyProperty as the backing store for CurrentPage. This enables animation, styling, binding, etc... public static readonly DependencyProperty CurrentPageProperty = DependencyProperty.Register("CurrentPage", typeof(int), typeof(ImageSourceNewWindow), new PropertyMetadata(1)); private int CheckBoxImageNum = 1; private void init(long embryoId, int houseSn, int pictureLayer, string tlSn) { return; var list = picProvider.GetImageSourceApi(embryoId, houseSn, pictureLayer, tlSn); Task.Run(() => { Dispatcher.Invoke(() => { foreach (var item in list) { if (string.IsNullOrEmpty(item.sourceImageUrl)) continue; PicSourceUserControl checkBoxImage = new PicSourceUserControl() { ImageSourceUrl = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{item.sourceImageUrl.Replace(AppData.Instance.PicSuf, $"_180x180{AppData.Instance.PicSuf}")}?token={AppData.Instance.HttpServiceCall.GetToken()}"), ImageInfoString = $"{item.imageTime.ToString("MM-dd HH:mm")}", }; if (checkBoxImage.ImageSourceUrl == null) continue; if (CheckBoxImageNum > 7) { if ((CheckBoxImageNum - 1) % 7 == 0) checkBoxImage.Margin = new Thickness(0, 10, 0, 0); else checkBoxImage.Margin = new Thickness(10, 10, 0, 0); } else { if (CheckBoxImageNum == 1) checkBoxImage.Margin = new Thickness(0); else checkBoxImage.Margin = new Thickness(10, 0, 0, 0); } CheckBoxImageNum++; WrapPanel_Image.Children.Add(checkBoxImage); } }); }); } private void ExLog(Exception ex, string name) { AppData.Instance.LogService.ExceptionLog(ex, $"ImageSourceNewWindow.{name}", LogEnum.RunException); } private void ErrorLog(string message, LogEnum logType) { AppData.Instance.LogService.TLLog($"ImageSourceNewWindow.{message}", logType); } private void Cancel_Click(object sender, RoutedEventArgs e) { this.DialogResult = false; return; } private void ScrollViewer_ManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e) { e.Handled = true; } private void PaginationUserControl_PageChangedEvent(PaginationUserControl arg1, int arg2) { if (!arg1.IsLoaded) return; if (!this.IsLoaded) return; WrapPanel_Image.Children.Clear(); var a = picProvider.GetImageSourcePageApi(embryoId, houseSn, pictureLayer, tlSn, arg2, PicPageSize, PhotoBoxSettings); Task.Run(() => { Dispatcher.Invoke(() => { //this.Canvas_Big.Visibility = Visibility.Collapsed; PicSourceUserControl aa = null; int newK = 0; int ImageIndex = 1; CurrentPage = arg2; ListPic.Clear(); foreach (var item in a.records) { if (string.IsNullOrEmpty(item.sourceImageUrl)) continue; PicSourceUserControl checkBoxImage = new PicSourceUserControl() { ImageSourceUrl = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{item.sourceImageUrl.Replace(AppData.Instance.PicSuf, $"_180x180{AppData.Instance.PicSuf}")}?token={AppData.Instance.HttpServiceCall.GetToken()}"), ImageInfoString = $"{item.imageTime.ToString("MM-dd HH:mm")}-{item.shootingPosition}", ImageUrl = item.sourceImageUrl, ImageId = item.id, developTime = item.developTime, }; if (checkBoxImage.ImageSourceUrl == null) continue; if (CheckBoxImageNum > 7) { if ((CheckBoxImageNum - 1) % 7 == 0) checkBoxImage.Margin = new Thickness(0, 10, 0, 0); else checkBoxImage.Margin = new Thickness(10, 10, 0, 0); } else { if (CheckBoxImageNum == 1) checkBoxImage.Margin = new Thickness(0); else checkBoxImage.Margin = new Thickness(10, 0, 0, 0); } var k = ImageIndex; checkBoxImage.MouseDown += (s, e) => { this.Text_Big.Text = checkBoxImage.ImageInfoString; CurrentImageId = checkBoxImage.ImageId; CurrentDevelopTime = checkBoxImage.developTime; this.Image_Big.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{checkBoxImage.ImageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}"); this.Canvas_Big.Visibility = Visibility.Visible; this.Image_Big.Tag = k; if (k < ListPic.Last().Key) { this._nextPic_Button.Visibility = Visibility.Visible; } else { this._nextPic_Button.Visibility = Visibility.Hidden; } if (k > 1) { this._prePic_Button.Visibility = Visibility.Visible; } else { this._prePic_Button.Visibility = Visibility.Hidden; } }; ListPic.Add(k, checkBoxImage); ImageIndex++; CheckBoxImageNum++; WrapPanel_Image.Children.Add(checkBoxImage); if (this.Canvas_Big.Visibility == Visibility.Visible && CurrentDevelopTime != -1) { if (aa == null && item.developTime >= CurrentDevelopTime) { aa = checkBoxImage; newK = k; } } } if (this.Canvas_Big.Visibility == Visibility.Visible) { if (CurrentDevelopTime != -1 && aa != null) { this.Text_Big.Text = aa.ImageInfoString; CurrentImageId = aa.ImageId; CurrentDevelopTime = aa.developTime; this.Image_Big.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{aa.ImageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}"); this.Canvas_Big.Visibility = Visibility.Visible; this.Image_Big.Tag = newK; if (newK < ListPic.Last().Key) { this._nextPic_Button.Visibility = Visibility.Visible; } else { this._nextPic_Button.Visibility = Visibility.Hidden; } if (newK > 1) { this._prePic_Button.Visibility = Visibility.Visible; } else { this._prePic_Button.Visibility = Visibility.Hidden; } } else { this.Canvas_Big.Visibility = Visibility.Collapsed; } } }); }); return; } private void ComBox_Well_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!this.ComBox_Well.IsLoaded) return; if (this.ComBox_Well.SelectedItem != null && this.ComBox_Well.SelectedItem is Embryo currentEmbryo) { CurrentPage = 1; this.embryoId = currentEmbryo.id; var aa = picProvider.GetImageSourcePageApi(embryoId, houseSn, pictureLayer, tlSn, 1, PicPageSize, PhotoBoxSettings); PicDataCount = -1; PicDataCount = aa.total; this.Canvas_Big.Visibility = Visibility.Collapsed; CurrentDevelopTime = -1; } } private void ComBox_Focal_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!this.ComBox_Focal.IsLoaded) return; if (this.ComBox_Focal.SelectedItem != null && this.ComBox_Focal.SelectedItem is int currentFocal) { pictureLayer = currentFocal; var aa = picProvider.GetImageSourcePageApi(embryoId, houseSn, pictureLayer, tlSn, 1, PicPageSize, PhotoBoxSettings); PicDataCount = -1; PicDataCount = aa.total; } } Dictionary ListPic = new Dictionary(); private void Close_Click(object sender, RoutedEventArgs e) { this.Canvas_Big.Visibility = Visibility.Collapsed; } private void PreButton_Click(object sender, RoutedEventArgs e) { if (!int.TryParse(this.Image_Big.Tag.ToString(), out int newValue)) { return; } newValue--; if (!ListPic.ContainsKey(newValue)) return; var checkBoxImage = ListPic[newValue]; this.Text_Big.Text = checkBoxImage.ImageInfoString; this.Image_Big.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{checkBoxImage.ImageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}"); this.Canvas_Big.Visibility = Visibility.Visible; this.Image_Big.Tag = newValue; CurrentImageId = checkBoxImage.ImageId; CurrentDevelopTime = checkBoxImage.developTime; if (newValue > 1) { this._prePic_Button.Visibility = Visibility.Visible; } else { this._prePic_Button.Visibility = Visibility.Hidden; } if (newValue < ListPic.Last().Key) { this._nextPic_Button.Visibility = Visibility.Visible; } else { this._nextPic_Button.Visibility = Visibility.Hidden; } } private void NextButton_Click(object sender, RoutedEventArgs e) { if (!int.TryParse(this.Image_Big.Tag.ToString(), out int newValue)) { return; } newValue++; if (!ListPic.ContainsKey(newValue)) return; var checkBoxImage = ListPic[newValue]; this.Text_Big.Text = checkBoxImage.ImageInfoString; this.Image_Big.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{checkBoxImage.ImageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}"); this.Canvas_Big.Visibility = Visibility.Visible; this.Image_Big.Tag = newValue; CurrentImageId = checkBoxImage.ImageId; CurrentDevelopTime = checkBoxImage.developTime; if (newValue < ListPic.Last().Key) { this._nextPic_Button.Visibility = Visibility.Visible; } else { this._nextPic_Button.Visibility = Visibility.Hidden; } if (newValue > 1) { this._prePic_Button.Visibility = Visibility.Visible; } else { this._prePic_Button.Visibility = Visibility.Hidden; } } private void ExportCurrentWellPic_Click(object sender, RoutedEventArgs e) { try { string name = $"{dish.wife}_{DateTime.Now.ToString("yy-MM-dd-HH-mm-ss")}.zip"; string fileName = SaveFileName(name); if (string.IsNullOrEmpty(fileName)) return; string body = null; if (PhotoBoxSettings.Any()) { body = JsonConvert.SerializeObject(new { houseSn = dish.houseSn, ids = new List { embryoId }, pictureLayer = pictureLayer, tlSn = tlSn, searchButtons = PhotoBoxSettings }); } else { body = JsonConvert.SerializeObject(new { houseSn = dish.houseSn, ids = new List { embryoId }, pictureLayer = pictureLayer, tlSn = tlSn }); } AppData.Instance.MainWindowViewModel.DownLoadStart(new ivf_tl_Entity.Entity.DownLoad.DownLoadEntity { DownLoadUrl = $"/api/businessManage/pc/resource/downloadSourcePictures", NewFileFullName = fileName, FileName = name, Body = body, }); //ToastMessage("开始下载"); ToastMessage(KeyToStringConvert.GetLanguageStringByKey("0299")); } catch (Exception ex) { ExLog(ex, "ExportCurrentWellPic_Click"); } } private void ExportAllWellPic_Click(object sender, RoutedEventArgs e) { try { string name = $"{dish.wife}_{DateTime.Now.ToString("yy-MM-dd-HH-mm-ss")}.zip"; string fileName = SaveFileName(name); if (string.IsNullOrEmpty(fileName)) return; string body = null; if (PhotoBoxSettings.Any()) { body = JsonConvert.SerializeObject(new { houseSn = dish.houseSn, ids = dish.embryoList.Select(x => x.id).ToList(), pictureLayer = pictureLayer, tlSn = tlSn, searchButtons = PhotoBoxSettings }); } else { body = JsonConvert.SerializeObject(new { houseSn = dish.houseSn, ids = dish.embryoList.Select(x => x.id).ToList(), pictureLayer = pictureLayer, tlSn = tlSn }); } AppData.Instance.MainWindowViewModel.DownLoadStart(new ivf_tl_Entity.Entity.DownLoad.DownLoadEntity { DownLoadUrl = $"/api/businessManage/pc/resource/downloadSourcePictures", NewFileFullName = fileName, FileName = name, Body = body, }); //ToastMessage("开始下载"); ToastMessage(KeyToStringConvert.GetLanguageStringByKey("0299")); } catch (Exception ex) { ExLog(ex, "ExportAllWellPic_Click"); } } public string SaveFileName(string fileName) { var dialog = new Microsoft.Win32.SaveFileDialog(); dialog.FileName = fileName; dialog.DefaultExt = ".zip"; dialog.Filter = "zip|*.zip"; if (dialog.ShowDialog() != true) { return null; } return dialog.FileName; } private void ToastMessage(string mess) { new ToastMessageWindow(this, mess).Show(); } private void ExportPic_Click(object sender, RoutedEventArgs e) { try { string url = $"/api/businessManage/pc/resource/downloadSourcePicture?tlSn={tlSn}&houseSn={houseSn}&ids={CurrentImageId}"; string oldName = AppData.Instance.HttpServiceCall.GetDownLoadFileName(url); string fileName = SaveFileName(oldName); if (string.IsNullOrEmpty(fileName)) return; AppData.Instance.MainWindowViewModel.DownLoadStart(new ivf_tl_Entity.Entity.DownLoad.DownLoadEntity { DownLoadUrl = url, NewFileFullName = fileName, FileName = System.IO.Path.GetFileName(fileName), }); } catch (Exception ex) { ExLog(ex, "ExportPic_Click"); } } public long CurrentImageId { get; set; } public int CurrentDevelopTime { get; set; } = -1; private void PaginationUserControl_ClickPageEvent() { this.Canvas_Big.Visibility = Visibility.Collapsed; } } }