| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454 |
- using ivf_tl_Entity.Entity;
- using ivf_tl_Entity.Entity.balance;
- using ivf_tl_Entity.Entity.Result;
- using ivf_tl_Entity.Enums;
- using ivf_tl_Entity.Pic;
- 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;
- 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;
- namespace ivf_tl_Manage.Win
- {
- /// <summary>
- /// PhotoWindowNew.xaml 的交互逻辑
- /// </summary>
- public partial class PhotoWindowNew : Window
- {
- //public int CurrentNum;
- //public int AllPicNum;
- private string wifeName;
- private int wellsn;
- private string tlSn;
- private int houseSn;
- List<BigImageEntity> Photos = new List<BigImageEntity>();
- public PhotoWindowNew(Window w, List<PictureView> listPic, long picId, string tlsn1, int housesn1, string wifeName1, int wellsn1)
- {
- InitializeComponent();
- this.Owner = w;
- tlSn = tlsn1;
- houseSn = housesn1;
- wifeName = wifeName1;
- wellsn = wellsn1;
- foreach (var item in listPic)
- {
- Photos.Add(new BigImageEntity()
- {
- id = item.id,
- imageUrl = item.imageUrl,
- Url = $"{AppData.Instance.BaseUrl}{item.imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}",
- AllUrl = $"{AppData.Instance.BaseUrl}{item.imageUrl.Replace(AppData.Instance.PicSuf, $"_140x140{AppData.Instance.PicSuf}")}?token={AppData.Instance.HttpServiceCall.GetToken()}",
- CreationTime = item.imageTime,
- });
- }
- double windwoWidth = 0;
- switch (Photos.Count)
- {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- windwoWidth = 808d;
- break;
- case 5:
- windwoWidth = 896d;
- break;
- case 6:
- windwoWidth = 1060d;
- break;
- case 7:
- windwoWidth = 1224d;
- break;
- default:
- windwoWidth = 1388d;
- break;
- }
- this.Width = windwoWidth;
- TransformGroup transformGroup = this.image.RenderTransform as TransformGroup;
- ScaleTransform sfr = transformGroup.Children[0] as ScaleTransform;
- TranslateTransform ttf = transformGroup.Children[1] as TranslateTransform;
- image.MouseWheel += (s, arg) =>
- {
- Point centerPoint = arg.GetPosition(image);
- sfr.CenterX = centerPoint.X;
- sfr.CenterY = centerPoint.Y;
- var delta = arg.Delta * 0.001;
- if (sfr.ScaleX + delta < 0.1) return;
- if (sfr.ScaleX + delta > 4.0) return;
- sfr.ScaleX += arg.Delta * 0.001;
- sfr.ScaleY += arg.Delta * 0.001;
- };
- Point StartPosition = new Point();
- Point EndPosition = new Point();
- bool isStart = false;
- image.MouseDown += (s, arg) =>
- {
- StartPosition = arg.GetPosition(image);
- isStart = true;
- };
- image.MouseMove += (s, arg) =>
- {
- if (!isStart) return;
- if (arg.LeftButton != MouseButtonState.Pressed) return;
- EndPosition = arg.GetPosition(image);
- var X = EndPosition.X - StartPosition.X;
- var Y = EndPosition.Y - StartPosition.Y;
- ttf.X += X;
- ttf.Y += Y;
- };
- image.MouseUp += (s, arg) =>
- {
- isStart = false;
- };
- image.MouseLeave += (s, arg) =>
- {
- isStart = false;
- };
- Loaded += (s, e) =>
- {
- Task.Run(() =>
- {
- Dispatcher.Invoke(() =>
- {
- this.listBox.ItemsSource = Photos;
- CurrentPhoto = Photos.FirstOrDefault(x => x.id == picId);
- });
- });
- };
- this.Closed += (a, b) => w.Activate();
- //if (a == null) return;
- //CurrentPhoto = a;
- //CurrentNum = Photos.IndexOf(currentPhoto);
- //InitPic();
- //if (CurrentNum > 0) this._prePic_Button.IsEnabled = true;
- //else this._prePic_Button.IsEnabled = false;
- //if (CurrentNum < (listPic.Count - 1)) this._nextPic_Button.IsEnabled = true;
- //else this._nextPic_Button.IsEnabled = false;
- }
- public void InitPic()
- {
- //if (currentPhoto == null) return;
- //TransformGroup transformGroup = new TransformGroup();
- //ScaleTransform sfr = new ScaleTransform();//缩放
- //transformGroup.Children.Add(sfr);
- //TranslateTransform ttf = new TranslateTransform();//平移
- //transformGroup.Children.Add(ttf);
- //if (currentPhoto.BitmapImage == null)
- //{
- // currentPhoto.BitmapImage = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{currentPhoto.imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}");
- //}
- //Image currentImage = new Image
- //{
- // Source = currentPhoto.BitmapImage,
- // Cursor = Cursors.Hand,
- // RenderTransform = transformGroup,
- //};
- //if (currentImage.Source == null) return;
- //currentImage.MouseWheel += (s, arg) =>
- //{
- // Point centerPoint = arg.GetPosition(_container);
- // sfr.CenterX = centerPoint.X;
- // sfr.CenterY = centerPoint.Y;
- // var delta = arg.Delta * 0.001;
- // if (sfr.ScaleX + delta < 0.1) return;
- // if (sfr.ScaleX + delta > 4.0) return;
- // sfr.ScaleX += arg.Delta * 0.001;
- // sfr.ScaleY += arg.Delta * 0.001;
- //};
- //Point StartPosition = new Point();
- //Point EndPosition = new Point();
- //currentImage.MouseDown += (s, arg) =>
- //{
- // StartPosition = arg.GetPosition(currentImage);
- //};
- //currentImage.MouseMove += (s, arg) =>
- //{
- // if (arg.LeftButton != MouseButtonState.Pressed) return;
- // EndPosition = arg.GetPosition(currentImage);
- // var X = EndPosition.X - StartPosition.X;
- // var Y = EndPosition.Y - StartPosition.Y;
- // ttf.X += X;
- // ttf.Y += Y;
- //};
- //this._container.Child = currentImage;
- }
- private void ZoomMin_Click(object sender, RoutedEventArgs e)
- {
- TransformGroup transformGroup = this.image.RenderTransform as TransformGroup;
- ScaleTransform scaleTransform = transformGroup.Children[0] as ScaleTransform;
- scaleTransform.CenterX = 290;
- scaleTransform.CenterY = 290;
- if (scaleTransform.ScaleX > 0.1)
- {
- scaleTransform.ScaleX -= 0.1;
- scaleTransform.ScaleY -= 0.1;
- }
- }
- private void ZoomMax_Click(object sender, RoutedEventArgs e)
- {
- TransformGroup transformGroup = this.image.RenderTransform as TransformGroup;
- ScaleTransform scaleTransform = transformGroup.Children[0] as ScaleTransform;
- scaleTransform.CenterX = 290;
- scaleTransform.CenterY = 290;
- scaleTransform.ScaleX += 0.1;
- scaleTransform.ScaleY += 0.1;
- }
- private void Pre_Click(object sender, RoutedEventArgs e)
- {
- //if (CurrentNum == -1)
- //{
- // CurrentNum = Photos.IndexOf(currentPhoto);
- // if (CurrentNum > 0)
- // {
- // currentPhoto = Photos[--CurrentNum];
- // InitPic();
- // }
- //}
- //else
- //{
- // if (CurrentNum > 0)
- // {
- // currentPhoto = Photos[--CurrentNum];
- // InitPic();
- // }
- //}
- //if (CurrentNum > 0) this._prePic_Button.IsEnabled = true;
- //else this._prePic_Button.IsEnabled = false;
- //if (CurrentNum < (Photos.Count - 1)) this._nextPic_Button.IsEnabled = true;
- //else this._nextPic_Button.IsEnabled = false;
- }
- private void Next_Click(object sender, RoutedEventArgs e)
- {
- //if (CurrentNum == -1)
- //{
- // CurrentNum = Photos.IndexOf(currentPhoto);
- // if (CurrentNum != -1 && CurrentNum < (Photos.Count - 1))
- // {
- // currentPhoto = Photos[++CurrentNum];
- // InitPic();
- // }
- //}
- //else
- //{
- // if (CurrentNum < (Photos.Count - 1))
- // {
- // currentPhoto = Photos[++CurrentNum];
- // InitPic();
- // }
- //}
- //if (CurrentNum > 0) this._prePic_Button.IsEnabled = true;
- //else this._prePic_Button.IsEnabled = false;
- //if (CurrentNum < (Photos.Count - 1)) this._nextPic_Button.IsEnabled = true;
- //else this._nextPic_Button.IsEnabled = false;
- }
- private void Ok_Click(object sender, RoutedEventArgs e)
- {
- this.DialogResult = false;
- }
- private void ListBox_ManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
- {
- e.Handled = true;
- }
- public BigImageEntity CurrentPhoto
- {
- get { return (BigImageEntity)GetValue(CurrentPhotoProperty); }
- set { SetValue(CurrentPhotoProperty, value); }
- }
- // Using a DependencyProperty as the backing store for CurrentPhoto. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty CurrentPhotoProperty =
- DependencyProperty.Register("CurrentPhoto", typeof(BigImageEntity), typeof(PhotoWindowNew), new PropertyMetadata(null, new PropertyChangedCallback(CurrentPhotoPropertyChangedCallback)));
- private static void CurrentPhotoPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- }
- private void Close_Click(object sender, RoutedEventArgs e)
- {
- this.DialogResult = false;
- return;
- }
- private void Export_Click(object sender, RoutedEventArgs e)
- {
- string url = $"/api/businessManage/pc/resource/downloadPicture?tlSn={tlSn}&houseSn={houseSn}&ids={CurrentPhoto.id}";
- 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 = Path.GetFileName(fileName),
- });
- //var pro = AppData.Instance.GetPicProvider();
- //if(pro.DownloadFileApi(tlSn,houseSn,CurrentPhoto.id, fileName))
- //{
- // new ToastWindow(this, 1920,65, true).Show();
- //}
- //else
- //{
- // new ToastWindow(this, 1920,65, false).Show();
- //}
- //try
- //{
- // CommonOpenFileDialog open = new CommonOpenFileDialog();
- // open.IsFolderPicker = true;
- // open.EnsureReadOnly = true;
- // open.Multiselect = false;
- // open.Title = "请选择图片保存文件夹";
- // if (open.ShowDialog() == CommonFileDialogResult.Ok)
- // {
- // var newFullName = System.IO.Path.Combine(open.FileName, $"{CurrentEmbryo.Dish.Wife}-Well{CurrentEmbryo.Location}-{currentPhoto.CreationTime.ToString("yyyy-MM--dd-HH-mm-ss")}.jpg");
- // File.Copy(currentPhoto.FullName, newFullName, true);
- // //_mask.Visibility= Visibility.Visible;
- // //new MessageWindow("导出完成",true).ShowDialog();
- // //_mask.Visibility = Visibility.Hidden;
- // //System.Diagnostics.Process.Start(open.FileName);
- // new MessagePrompt().ShowCenterOwnerSuccess(this, $"导出成功");
- // return;
- // //this.Close();
- // }
- //}
- //catch (Exception ex)
- //{
- // UtilLogHelper.UtilLogHelper.EnqueueLogModel(ex, $"单张图片导出", null, LogEnum.RunException);
- //}
- }
- Embryo CurrentEmbryo = null;
- public string SaveFileName(string filename)
- {
- var dialog = new Microsoft.Win32.SaveFileDialog();
- if (string.IsNullOrEmpty(filename)) dialog.FileName = $"{wifeName}_{CurrentPhoto.CreationTime.ToString("yy-MM--dd-HH-mm-ss")}.jpg";
- else dialog.FileName = filename;
- dialog.DefaultExt = ".jpg";
- dialog.Filter = $"jpg|*.jpg";
- dialog.AddExtension = true;
- if (dialog.ShowDialog() != true)
- {
- return null;
- }
- return dialog.FileName;
- }
- private void listBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
- {
- if (sender is ListBox list)
- {
- var scrollViewer = (ScrollViewer)list.Template.FindName("_ScrollViewer", list);
- if (scrollViewer != null)
- {
- if (e.Delta > 0)
- {
- scrollViewer.LineLeft();
- scrollViewer.LineLeft();
- }
- else
- {
- scrollViewer.LineRight();
- scrollViewer.LineRight();
- }
- e.Handled = true;
- }
- }
- }
- private void PreButton_Click(object sender, RoutedEventArgs e)
- {
- if (this.listBox.SelectedIndex > 0) this.listBox.SelectedIndex--;
- }
- private void NextButton_Click(object sender, RoutedEventArgs e)
- {
- if (this.listBox.SelectedIndex < (Photos.Count - 1)) this.listBox.SelectedIndex++;
- }
- private void image_MouseWheel(object sender, MouseWheelEventArgs e)
- {
- }
- private void image_MouseDown(object sender, MouseButtonEventArgs e)
- {
- }
- int scrNum = 3;
- private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (!(this.image.RenderTransform is TransformGroup transformGroup)) return;
- ScaleTransform scaleTransform = transformGroup.Children[0] as ScaleTransform;
- TranslateTransform ttf = transformGroup.Children[1] as TranslateTransform;
- scaleTransform.CenterX = 200;
- scaleTransform.CenterY = 200;
- scaleTransform.ScaleX = 1;
- scaleTransform.ScaleY = 1;
- ttf.X = 0;
- ttf.Y = 0;
- if (!(sender is ListBox listBox)) return;
- if (listBox.SelectedIndex == -1)
- {
- this._prePic_Button.IsEnabled = false;
- this._nextPic_Button.IsEnabled = false;
- return;
- }
- if (listBox.SelectedIndex > 0) this._prePic_Button.IsEnabled = true;
- else this._prePic_Button.IsEnabled = false;
- if (listBox.SelectedIndex < (Photos.Count - 1)) this._nextPic_Button.IsEnabled = true;
- else this._nextPic_Button.IsEnabled = false;
- if (listBox.SelectedIndex < scrNum || listBox.Items.Count - listBox.SelectedIndex - 1 < scrNum)
- {
- listBox.ScrollIntoView(listBox.Items[listBox.SelectedIndex]);
- return;
- }
- var scr = listBox.Template.FindName("_ScrollViewer", listBox) as ScrollViewer;
- if (scr == null)
- {
- listBox.ScrollIntoView(listBox.Items[listBox.SelectedIndex]);
- return;
- }
- scr.ScrollToHorizontalOffset(listBox.SelectedIndex - scrNum);
- }
- }
- }
|