PhotoWindowNew.xaml.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. using ivf_tl_Entity.Entity;
  2. using ivf_tl_Entity.Entity.balance;
  3. using ivf_tl_Entity.Entity.Result;
  4. using ivf_tl_Entity.Enums;
  5. using ivf_tl_Entity.Pic;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. namespace ivf_tl_Manage.Win
  21. {
  22. /// <summary>
  23. /// PhotoWindowNew.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class PhotoWindowNew : Window
  26. {
  27. //public int CurrentNum;
  28. //public int AllPicNum;
  29. private string wifeName;
  30. private int wellsn;
  31. private string tlSn;
  32. private int houseSn;
  33. List<BigImageEntity> Photos = new List<BigImageEntity>();
  34. public PhotoWindowNew(Window w, List<PictureView> listPic, long picId, string tlsn1, int housesn1, string wifeName1, int wellsn1)
  35. {
  36. InitializeComponent();
  37. this.Owner = w;
  38. tlSn = tlsn1;
  39. houseSn = housesn1;
  40. wifeName = wifeName1;
  41. wellsn = wellsn1;
  42. foreach (var item in listPic)
  43. {
  44. Photos.Add(new BigImageEntity()
  45. {
  46. id = item.id,
  47. imageUrl = item.imageUrl,
  48. Url = $"{AppData.Instance.BaseUrl}{item.imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}",
  49. AllUrl = $"{AppData.Instance.BaseUrl}{item.imageUrl.Replace(AppData.Instance.PicSuf, $"_140x140{AppData.Instance.PicSuf}")}?token={AppData.Instance.HttpServiceCall.GetToken()}",
  50. CreationTime = item.imageTime,
  51. });
  52. }
  53. double windwoWidth = 0;
  54. switch (Photos.Count)
  55. {
  56. case 0:
  57. case 1:
  58. case 2:
  59. case 3:
  60. case 4:
  61. windwoWidth = 808d;
  62. break;
  63. case 5:
  64. windwoWidth = 896d;
  65. break;
  66. case 6:
  67. windwoWidth = 1060d;
  68. break;
  69. case 7:
  70. windwoWidth = 1224d;
  71. break;
  72. default:
  73. windwoWidth = 1388d;
  74. break;
  75. }
  76. this.Width = windwoWidth;
  77. TransformGroup transformGroup = this.image.RenderTransform as TransformGroup;
  78. ScaleTransform sfr = transformGroup.Children[0] as ScaleTransform;
  79. TranslateTransform ttf = transformGroup.Children[1] as TranslateTransform;
  80. image.MouseWheel += (s, arg) =>
  81. {
  82. Point centerPoint = arg.GetPosition(image);
  83. sfr.CenterX = centerPoint.X;
  84. sfr.CenterY = centerPoint.Y;
  85. var delta = arg.Delta * 0.001;
  86. if (sfr.ScaleX + delta < 0.1) return;
  87. if (sfr.ScaleX + delta > 4.0) return;
  88. sfr.ScaleX += arg.Delta * 0.001;
  89. sfr.ScaleY += arg.Delta * 0.001;
  90. };
  91. Point StartPosition = new Point();
  92. Point EndPosition = new Point();
  93. bool isStart = false;
  94. image.MouseDown += (s, arg) =>
  95. {
  96. StartPosition = arg.GetPosition(image);
  97. isStart = true;
  98. };
  99. image.MouseMove += (s, arg) =>
  100. {
  101. if (!isStart) return;
  102. if (arg.LeftButton != MouseButtonState.Pressed) return;
  103. EndPosition = arg.GetPosition(image);
  104. var X = EndPosition.X - StartPosition.X;
  105. var Y = EndPosition.Y - StartPosition.Y;
  106. ttf.X += X;
  107. ttf.Y += Y;
  108. };
  109. image.MouseUp += (s, arg) =>
  110. {
  111. isStart = false;
  112. };
  113. image.MouseLeave += (s, arg) =>
  114. {
  115. isStart = false;
  116. };
  117. Loaded += (s, e) =>
  118. {
  119. Task.Run(() =>
  120. {
  121. Dispatcher.Invoke(() =>
  122. {
  123. this.listBox.ItemsSource = Photos;
  124. CurrentPhoto = Photos.FirstOrDefault(x => x.id == picId);
  125. });
  126. });
  127. };
  128. this.Closed += (a, b) => w.Activate();
  129. //if (a == null) return;
  130. //CurrentPhoto = a;
  131. //CurrentNum = Photos.IndexOf(currentPhoto);
  132. //InitPic();
  133. //if (CurrentNum > 0) this._prePic_Button.IsEnabled = true;
  134. //else this._prePic_Button.IsEnabled = false;
  135. //if (CurrentNum < (listPic.Count - 1)) this._nextPic_Button.IsEnabled = true;
  136. //else this._nextPic_Button.IsEnabled = false;
  137. }
  138. public void InitPic()
  139. {
  140. //if (currentPhoto == null) return;
  141. //TransformGroup transformGroup = new TransformGroup();
  142. //ScaleTransform sfr = new ScaleTransform();//缩放
  143. //transformGroup.Children.Add(sfr);
  144. //TranslateTransform ttf = new TranslateTransform();//平移
  145. //transformGroup.Children.Add(ttf);
  146. //if (currentPhoto.BitmapImage == null)
  147. //{
  148. // currentPhoto.BitmapImage = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{currentPhoto.imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  149. //}
  150. //Image currentImage = new Image
  151. //{
  152. // Source = currentPhoto.BitmapImage,
  153. // Cursor = Cursors.Hand,
  154. // RenderTransform = transformGroup,
  155. //};
  156. //if (currentImage.Source == null) return;
  157. //currentImage.MouseWheel += (s, arg) =>
  158. //{
  159. // Point centerPoint = arg.GetPosition(_container);
  160. // sfr.CenterX = centerPoint.X;
  161. // sfr.CenterY = centerPoint.Y;
  162. // var delta = arg.Delta * 0.001;
  163. // if (sfr.ScaleX + delta < 0.1) return;
  164. // if (sfr.ScaleX + delta > 4.0) return;
  165. // sfr.ScaleX += arg.Delta * 0.001;
  166. // sfr.ScaleY += arg.Delta * 0.001;
  167. //};
  168. //Point StartPosition = new Point();
  169. //Point EndPosition = new Point();
  170. //currentImage.MouseDown += (s, arg) =>
  171. //{
  172. // StartPosition = arg.GetPosition(currentImage);
  173. //};
  174. //currentImage.MouseMove += (s, arg) =>
  175. //{
  176. // if (arg.LeftButton != MouseButtonState.Pressed) return;
  177. // EndPosition = arg.GetPosition(currentImage);
  178. // var X = EndPosition.X - StartPosition.X;
  179. // var Y = EndPosition.Y - StartPosition.Y;
  180. // ttf.X += X;
  181. // ttf.Y += Y;
  182. //};
  183. //this._container.Child = currentImage;
  184. }
  185. private void ZoomMin_Click(object sender, RoutedEventArgs e)
  186. {
  187. TransformGroup transformGroup = this.image.RenderTransform as TransformGroup;
  188. ScaleTransform scaleTransform = transformGroup.Children[0] as ScaleTransform;
  189. scaleTransform.CenterX = 290;
  190. scaleTransform.CenterY = 290;
  191. if (scaleTransform.ScaleX > 0.1)
  192. {
  193. scaleTransform.ScaleX -= 0.1;
  194. scaleTransform.ScaleY -= 0.1;
  195. }
  196. }
  197. private void ZoomMax_Click(object sender, RoutedEventArgs e)
  198. {
  199. TransformGroup transformGroup = this.image.RenderTransform as TransformGroup;
  200. ScaleTransform scaleTransform = transformGroup.Children[0] as ScaleTransform;
  201. scaleTransform.CenterX = 290;
  202. scaleTransform.CenterY = 290;
  203. scaleTransform.ScaleX += 0.1;
  204. scaleTransform.ScaleY += 0.1;
  205. }
  206. private void Pre_Click(object sender, RoutedEventArgs e)
  207. {
  208. //if (CurrentNum == -1)
  209. //{
  210. // CurrentNum = Photos.IndexOf(currentPhoto);
  211. // if (CurrentNum > 0)
  212. // {
  213. // currentPhoto = Photos[--CurrentNum];
  214. // InitPic();
  215. // }
  216. //}
  217. //else
  218. //{
  219. // if (CurrentNum > 0)
  220. // {
  221. // currentPhoto = Photos[--CurrentNum];
  222. // InitPic();
  223. // }
  224. //}
  225. //if (CurrentNum > 0) this._prePic_Button.IsEnabled = true;
  226. //else this._prePic_Button.IsEnabled = false;
  227. //if (CurrentNum < (Photos.Count - 1)) this._nextPic_Button.IsEnabled = true;
  228. //else this._nextPic_Button.IsEnabled = false;
  229. }
  230. private void Next_Click(object sender, RoutedEventArgs e)
  231. {
  232. //if (CurrentNum == -1)
  233. //{
  234. // CurrentNum = Photos.IndexOf(currentPhoto);
  235. // if (CurrentNum != -1 && CurrentNum < (Photos.Count - 1))
  236. // {
  237. // currentPhoto = Photos[++CurrentNum];
  238. // InitPic();
  239. // }
  240. //}
  241. //else
  242. //{
  243. // if (CurrentNum < (Photos.Count - 1))
  244. // {
  245. // currentPhoto = Photos[++CurrentNum];
  246. // InitPic();
  247. // }
  248. //}
  249. //if (CurrentNum > 0) this._prePic_Button.IsEnabled = true;
  250. //else this._prePic_Button.IsEnabled = false;
  251. //if (CurrentNum < (Photos.Count - 1)) this._nextPic_Button.IsEnabled = true;
  252. //else this._nextPic_Button.IsEnabled = false;
  253. }
  254. private void Ok_Click(object sender, RoutedEventArgs e)
  255. {
  256. this.DialogResult = false;
  257. }
  258. private void ListBox_ManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
  259. {
  260. e.Handled = true;
  261. }
  262. public BigImageEntity CurrentPhoto
  263. {
  264. get { return (BigImageEntity)GetValue(CurrentPhotoProperty); }
  265. set { SetValue(CurrentPhotoProperty, value); }
  266. }
  267. // Using a DependencyProperty as the backing store for CurrentPhoto. This enables animation, styling, binding, etc...
  268. public static readonly DependencyProperty CurrentPhotoProperty =
  269. DependencyProperty.Register("CurrentPhoto", typeof(BigImageEntity), typeof(PhotoWindowNew), new PropertyMetadata(null, new PropertyChangedCallback(CurrentPhotoPropertyChangedCallback)));
  270. private static void CurrentPhotoPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  271. {
  272. }
  273. private void Close_Click(object sender, RoutedEventArgs e)
  274. {
  275. this.DialogResult = false;
  276. return;
  277. }
  278. private void Export_Click(object sender, RoutedEventArgs e)
  279. {
  280. string url = $"/api/businessManage/pc/resource/downloadPicture?tlSn={tlSn}&houseSn={houseSn}&ids={CurrentPhoto.id}";
  281. string oldName = AppData.Instance.HttpServiceCall.GetDownLoadFileName(url);
  282. string fileName = SaveFileName(oldName);
  283. if (string.IsNullOrEmpty(fileName)) return;
  284. AppData.Instance.MainWindowViewModel.DownLoadStart(new ivf_tl_Entity.Entity.DownLoad.DownLoadEntity
  285. {
  286. DownLoadUrl = url,
  287. NewFileFullName = fileName,
  288. FileName = Path.GetFileName(fileName),
  289. });
  290. //var pro = AppData.Instance.GetPicProvider();
  291. //if(pro.DownloadFileApi(tlSn,houseSn,CurrentPhoto.id, fileName))
  292. //{
  293. // new ToastWindow(this, 1920,65, true).Show();
  294. //}
  295. //else
  296. //{
  297. // new ToastWindow(this, 1920,65, false).Show();
  298. //}
  299. //try
  300. //{
  301. // CommonOpenFileDialog open = new CommonOpenFileDialog();
  302. // open.IsFolderPicker = true;
  303. // open.EnsureReadOnly = true;
  304. // open.Multiselect = false;
  305. // open.Title = "请选择图片保存文件夹";
  306. // if (open.ShowDialog() == CommonFileDialogResult.Ok)
  307. // {
  308. // var newFullName = System.IO.Path.Combine(open.FileName, $"{CurrentEmbryo.Dish.Wife}-Well{CurrentEmbryo.Location}-{currentPhoto.CreationTime.ToString("yyyy-MM--dd-HH-mm-ss")}.jpg");
  309. // File.Copy(currentPhoto.FullName, newFullName, true);
  310. // //_mask.Visibility= Visibility.Visible;
  311. // //new MessageWindow("导出完成",true).ShowDialog();
  312. // //_mask.Visibility = Visibility.Hidden;
  313. // //System.Diagnostics.Process.Start(open.FileName);
  314. // new MessagePrompt().ShowCenterOwnerSuccess(this, $"导出成功");
  315. // return;
  316. // //this.Close();
  317. // }
  318. //}
  319. //catch (Exception ex)
  320. //{
  321. // UtilLogHelper.UtilLogHelper.EnqueueLogModel(ex, $"单张图片导出", null, LogEnum.RunException);
  322. //}
  323. }
  324. Embryo CurrentEmbryo = null;
  325. public string SaveFileName(string filename)
  326. {
  327. var dialog = new Microsoft.Win32.SaveFileDialog();
  328. if (string.IsNullOrEmpty(filename)) dialog.FileName = $"{wifeName}_{CurrentPhoto.CreationTime.ToString("yy-MM--dd-HH-mm-ss")}.jpg";
  329. else dialog.FileName = filename;
  330. dialog.DefaultExt = ".jpg";
  331. dialog.Filter = $"jpg|*.jpg";
  332. dialog.AddExtension = true;
  333. if (dialog.ShowDialog() != true)
  334. {
  335. return null;
  336. }
  337. return dialog.FileName;
  338. }
  339. private void listBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
  340. {
  341. if (sender is ListBox list)
  342. {
  343. var scrollViewer = (ScrollViewer)list.Template.FindName("_ScrollViewer", list);
  344. if (scrollViewer != null)
  345. {
  346. if (e.Delta > 0)
  347. {
  348. scrollViewer.LineLeft();
  349. scrollViewer.LineLeft();
  350. }
  351. else
  352. {
  353. scrollViewer.LineRight();
  354. scrollViewer.LineRight();
  355. }
  356. e.Handled = true;
  357. }
  358. }
  359. }
  360. private void PreButton_Click(object sender, RoutedEventArgs e)
  361. {
  362. if (this.listBox.SelectedIndex > 0) this.listBox.SelectedIndex--;
  363. }
  364. private void NextButton_Click(object sender, RoutedEventArgs e)
  365. {
  366. if (this.listBox.SelectedIndex < (Photos.Count - 1)) this.listBox.SelectedIndex++;
  367. }
  368. private void image_MouseWheel(object sender, MouseWheelEventArgs e)
  369. {
  370. }
  371. private void image_MouseDown(object sender, MouseButtonEventArgs e)
  372. {
  373. }
  374. int scrNum = 3;
  375. private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  376. {
  377. if (!(this.image.RenderTransform is TransformGroup transformGroup)) return;
  378. ScaleTransform scaleTransform = transformGroup.Children[0] as ScaleTransform;
  379. TranslateTransform ttf = transformGroup.Children[1] as TranslateTransform;
  380. scaleTransform.CenterX = 200;
  381. scaleTransform.CenterY = 200;
  382. scaleTransform.ScaleX = 1;
  383. scaleTransform.ScaleY = 1;
  384. ttf.X = 0;
  385. ttf.Y = 0;
  386. if (!(sender is ListBox listBox)) return;
  387. if (listBox.SelectedIndex == -1)
  388. {
  389. this._prePic_Button.IsEnabled = false;
  390. this._nextPic_Button.IsEnabled = false;
  391. return;
  392. }
  393. if (listBox.SelectedIndex > 0) this._prePic_Button.IsEnabled = true;
  394. else this._prePic_Button.IsEnabled = false;
  395. if (listBox.SelectedIndex < (Photos.Count - 1)) this._nextPic_Button.IsEnabled = true;
  396. else this._nextPic_Button.IsEnabled = false;
  397. if (listBox.SelectedIndex < scrNum || listBox.Items.Count - listBox.SelectedIndex - 1 < scrNum)
  398. {
  399. listBox.ScrollIntoView(listBox.Items[listBox.SelectedIndex]);
  400. return;
  401. }
  402. var scr = listBox.Template.FindName("_ScrollViewer", listBox) as ScrollViewer;
  403. if (scr == null)
  404. {
  405. listBox.ScrollIntoView(listBox.Items[listBox.SelectedIndex]);
  406. return;
  407. }
  408. scr.ScrollToHorizontalOffset(listBox.SelectedIndex - scrNum);
  409. }
  410. }
  411. }