| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- using ivf_tl_Manage.Converts;
- using ivf_tl_Manage.ViewModels;
- using ivf_tl_Manage.Win;
- using QuestPDF.Fluent;
- using System;
- using System.Collections.Generic;
- 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.Effects;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace ivf_tl_Manage.Views
- {
- /// <summary>
- /// PdfView.xaml 的交互逻辑
- /// </summary>
- public partial class PdfView : UserControl
- {
- private PdfViewModel vm;
- public PdfView()
- {
- InitializeComponent();
- Loaded += PdfView_Loaded;
- Unloaded += PdfView_Unloaded;
- }
- private void PdfView_Unloaded(object sender, RoutedEventArgs e)
- {
- Canvas_Root.Children.Clear();
- vm = null;
- DataContext = null;
- }
- private void PdfView_Loaded(object sender, RoutedEventArgs e)
- {
- vm = (PdfViewModel)this.DataContext;
- if (vm == null) return;
- InitNav();
- ImageTransformGroup();
- if (vm.IsUpdateAi)
- {
- Task.Factory.StartNew(() =>
- {
- var reportData = vm.dishProvider.GetCultureRecordDetailByIdApi(vm.Dish.id);
- if (reportData == null)
- {
- //Dispatcher.Invoke(() => MessageShow("没有可以导出的数据"));
- Dispatcher.Invoke(() => MessageShow(KeyToStringConvert.GetLanguageStringByKey("0614")));
- return;
- }
- vm.Document = vm.GenerateReportEN(reportData);
- vm.PdfImageList = vm.Document.GenerateImages().ToList();
- Dispatcher.Invoke(() => PdfShow());
- });
- }
- else
- {
- PdfShow();
- }
- }
- private void PdfShow()
- {
- try
- {
- DropShadowEffect dropShadowEffect = new DropShadowEffect();
- dropShadowEffect.BlurRadius = 15;
- dropShadowEffect.Direction = 0;
- dropShadowEffect.ShadowDepth = 0;
- dropShadowEffect.Opacity = 0.5;
- this.image.Children.Clear();
- foreach (var item in vm.PdfImageList)
- {
- //Rectangle pdfImage = new Rectangle();
- //pdfImage.Fill = new SolidColorBrush(Colors.LightBlue);
- Image pdfImage = new Image();
- pdfImage.Source = AppData.Instance.ByteToBitmapImage(item);
- if (pdfImage.Source == null) continue;
- this.image.Children.Add(pdfImage);
- if (item == vm.PdfImageList.Last())
- {
- pdfImage.Width = 1560;
- pdfImage.Height = 1102;
- }
- else
- {
- pdfImage.Width = 1200;
- pdfImage.Height = 1698;
- }
- pdfImage.Margin = new Thickness(5);
- pdfImage.Effect = dropShadowEffect;
- }
- }
- catch (Exception ex)
- {
- return;
- }
- }
- private void ImageTransformGroup()
- {
- 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) =>
- {
- if (Keyboard.Modifiers != ModifierKeys.Control) return;
- Point centerPoint = arg.GetPosition(image);
- var delta = arg.Delta * 0.001;
- if (sfr.ScaleX + delta < 0.5 || sfr.ScaleX + delta > 4.0)
- {
- arg.Handled = true;
- return;
- }
- if (true)
- {
- //Point pointNew = transformGroup.Inverse.Transform(centerPoint);
- sfr.CenterX = centerPoint.X;
- sfr.CenterY = centerPoint.Y;
- sfr.ScaleX += delta;
- sfr.ScaleY += delta;
- }
- else
- {
- Point pointNew = transformGroup.Inverse.Transform(centerPoint);
- sfr.ScaleX += delta;
- sfr.ScaleY += delta;
- ttf.X = -1 * ((pointNew.X * sfr.ScaleX) - centerPoint.X);
- ttf.Y = -1 * ((pointNew.Y * sfr.ScaleY) - centerPoint.Y);
- }
- arg.Handled = true;
- };
- Point StartPosition = new Point();
- Point EndPosition = new Point();
- Point ControlPoint = new Point();
- bool isStart = false;
- image.MouseDown += (s, arg) =>
- {
- Mouse.Capture((IInputElement)s);
- StartPosition = arg.GetPosition(parent);
- ControlPoint = new Point(ttf.X, ttf.Y);
- isStart = true;
- };
- image.MouseMove += (s, arg) =>
- {
- if (!isStart) return;
- if (arg.LeftButton != MouseButtonState.Pressed) return;
- EndPosition = arg.GetPosition(parent);
- var X = (EndPosition.X - StartPosition.X);
- var Y = EndPosition.Y - StartPosition.Y;
- ttf.X = ControlPoint.X + X;
- ttf.Y = ControlPoint.Y + Y;
- };
- image.MouseUp += (s, arg) =>
- {
- Mouse.Capture(null);
- isStart = false;
- };
- image.MouseLeave += (s, arg) =>
- {
- isStart = false;
- };
- }
- private void InitNav()
- {
- _nav_StackPanel.Children.Clear();
- for (int i = 0; i < vm.NavList.Count; i++)
- {
- var item = vm.NavList[i];
- if (i == vm.NavList.Count - 1)
- {
- TextBlock textBlock1 = new TextBlock();
- textBlock1.Margin = new Thickness(8, 0, 0, 0);
- textBlock1.FontWeight = FontWeights.Bold;
- textBlock1.Foreground = new SolidColorBrush(Colors.Black);
- textBlock1.FontSize = 32d;
- textBlock1.VerticalAlignment = VerticalAlignment.Center;
- textBlock1.Text = item.NavName;
- _nav_StackPanel.Children.Add(textBlock1);
- return;
- }
- Button button = new Button();
- button.Content = item.NavName;
- button.FontWeight = FontWeights.Bold;
- button.FontSize = 28d;
- button.BorderThickness = new Thickness(0);
- button.Background = new SolidColorBrush(Colors.Transparent);
- button.Style = App.Current.FindResource("ButtonStyle1") as Style;
- if (i == 0)
- {
- button.Margin = new Thickness(0, 0, 0, 0);
- }
- else
- {
- button.Margin = new Thickness(8, 0, 0, 0);
- }
- button.Click += (s, e) =>
- {
- if (vm != null)
- {
- vm.NavList.Clear();
- vm.LogoBytes = null;
- vm.Document = null;
- vm.PdfImageList.Clear();
- vm.Dish = null;
- vm.dishProvider = null;
- vm.QuickButtons.Clear();
- vm.DishPicAndVideoList.Clear();
- }
- AppData.Instance.MainWindowViewModel.CurrentViewModle = item;
- };
- TextBlock textBlock = new TextBlock();
- textBlock.Margin = new Thickness(8, 0, 0, 0);
- textBlock.VerticalAlignment = VerticalAlignment.Center;
- textBlock.FontWeight = FontWeights.Bold;
- textBlock.FontSize = 28d;
- textBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9B9B9B"));
- textBlock.Text = ">";
- _nav_StackPanel.Children.Add(button);
- _nav_StackPanel.Children.Add(textBlock);
- }
- }
- public void MessageShow(string message)
- {
- new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, message).Show();
- }
- private void Toast(bool success)
- {
- new ToastWindow(AppData.Instance.MainWindow, 1920, 65, success).Show();
- }
- private void Export_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (vm == null || vm.Document == null || vm.Dish == null)
- {
- //MessageShow("没有可以导出的数据")
- MessageShow(KeyToStringConvert.GetLanguageStringByKey("0614"));
- return;
- }
- string fileName = AppData.Instance.SaveFileName(vm.Dish.wife);
- if (fileName == null) return;
- vm.Document.GeneratePdf(fileName);
- MessageShow(KeyToStringConvert.GetLanguageStringByKey("0585"));
- //MessageShow("AI报告导出成功");
- }
- catch (Exception ex)
- {
- Toast(false);
- }
- }
- private void Mark_Click(object sender, RoutedEventArgs e)
- {
- vm.MarkEmbryo();
- }
- private void ScrollViewer_ManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
- {
- e.Handled = true;
- }
- private void ZoomMax_Click(object sender, RoutedEventArgs e)
- {
- double viewportCenterX = parent.HorizontalOffset + parent.ViewportWidth / 2;
- double viewportCenterY = parent.VerticalOffset + parent.ViewportHeight / 2;
- Point centerInImage = parent.TranslatePoint(new Point(viewportCenterX, viewportCenterY), image);
- TransformGroup transformGroup = this.image.RenderTransform as TransformGroup;
- ScaleTransform scaleTransform = transformGroup.Children[0] as ScaleTransform;
- scaleTransform.CenterX = centerInImage.X;
- scaleTransform.CenterY = centerInImage.Y;
- scaleTransform.ScaleX += 0.1;
- scaleTransform.ScaleY += 0.1;
- }
- private void ZoomMin_Click(object sender, RoutedEventArgs e)
- {
- double viewportCenterX = parent.HorizontalOffset + parent.ViewportWidth / 2;
- double viewportCenterY = parent.VerticalOffset + parent.ViewportHeight / 2;
- Point centerInImage = parent.TranslatePoint(new Point(viewportCenterX, viewportCenterY), image);
- TransformGroup transformGroup = this.image.RenderTransform as TransformGroup;
- ScaleTransform scaleTransform = transformGroup.Children[0] as ScaleTransform;
- scaleTransform.CenterX = centerInImage.X;
- scaleTransform.CenterY = centerInImage.Y;
- if (scaleTransform.ScaleX > 0.1)
- {
- scaleTransform.ScaleX -= 0.1;
- scaleTransform.ScaleY -= 0.1;
- }
- }
- }
- }
|