MarkUseView.xaml.cs 105 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415
  1. using ivf_tl_CustomControls;
  2. using ivf_tl_Entity.Entity;
  3. using ivf_tl_Entity.Entity.balance;
  4. using ivf_tl_Entity.Entity.Mark;
  5. using ivf_tl_Entity.Enums;
  6. using ivf_tl_Entity.Response;
  7. using ivf_tl_Manage.Converts;
  8. using ivf_tl_Manage.ViewModels;
  9. using ivf_tl_Manage.Win;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. using System.Timers;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Data;
  20. using System.Windows.Documents;
  21. using System.Windows.Input;
  22. using System.Windows.Media;
  23. using System.Windows.Media.Imaging;
  24. using System.Windows.Navigation;
  25. using System.Windows.Shapes;
  26. namespace ivf_tl_Manage.Views
  27. {
  28. /// <summary>
  29. /// MarkUseView.xaml 的交互逻辑
  30. /// </summary>
  31. public partial class MarkUseView : UserControl
  32. {
  33. string paiShe, peitai, shiping;
  34. private MarkUseViewModel vm = null;
  35. private Brush deaeatForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D75AC"));
  36. private Brush noEmbryoForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9B9B9B"));
  37. private Brush noPicForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D4D4D"));
  38. private double centerX, centerY;
  39. private double angle;
  40. private double angleOffset = 90;
  41. private int ellipseCount = 16;
  42. private int backImageRadius = 50;
  43. private int backImageBigRadius = 248;
  44. private int imageRadius = 40;
  45. private int imageBigRadius = 248;
  46. private int textBigRadius = 193;
  47. private int operRaius = 13;
  48. private int operBigRadius = 288;
  49. private int selectedIndex;
  50. private List<TextBlock> TextBlockList = new List<TextBlock>();
  51. private List<Image> ImageList = new List<Image>();
  52. private List<Image> PicImageList = new List<Image>();
  53. private List<Image> OperImageList = new List<Image>();
  54. private bool IsCleanVideo = false;
  55. public MarkUseView()
  56. {
  57. InitializeComponent();
  58. paiShe = KeyToStringConvert.GetLanguageStringByKey("0509");
  59. shiping = KeyToStringConvert.GetLanguageStringByKey("0510");
  60. peitai = KeyToStringConvert.GetLanguageStringByKey("0511");
  61. //paiShe = "拍摄中,请耐心等待";
  62. //shiping = "暂无视频,请耐心等待";
  63. //peitai = "暂无胚胎";
  64. centerX = 710 / 2.0;
  65. centerY = 710 / 2.0;
  66. angle = 360.00 / 16;
  67. Loaded += MarkUseView_Loaded;
  68. Unloaded += (s, e) =>
  69. {
  70. PlayerDispose();
  71. Canvas_Root.Children.Clear();
  72. TextBlockList.Clear();
  73. ImageList.Clear();
  74. PicImageList.Clear();
  75. OperImageList.Clear();
  76. if (vm != null)
  77. {
  78. vm.DingWeiEvent -= QuickButton_Click;
  79. foreach (var item in vm.CurrentDish.embryoList)
  80. {
  81. item.AlarmChangedEvent -= EmbryoAlarmEvent;
  82. }
  83. }
  84. vm = null;
  85. DataContext = null;
  86. };
  87. }
  88. private async void MarkUseView_Loaded(object sender, RoutedEventArgs e)
  89. {
  90. vm = (MarkUseViewModel)this.DataContext;
  91. if (vm != null) InitNav();
  92. InitCustomNew();
  93. PlayerEvent(this.mediaElementPlayer);
  94. Task task = null;
  95. if (vm.isPdf)
  96. {
  97. task = Task.Factory.StartNew(() => vm.Initnew());
  98. }
  99. if (task != null) await task.WaitAsync(new TimeSpan(0, 0, 30));
  100. InitQuickButton();
  101. SetEmbryoPic();
  102. if (vm == null)
  103. {
  104. ChangeEmbryo(1);
  105. return;
  106. }
  107. else
  108. {
  109. if (vm.DishPicAndVideoList.Any())
  110. {
  111. var a = vm.DishPicAndVideoList.First();
  112. if (a.videos != null && a.videos.Any())
  113. {
  114. var b = a.videos.FirstOrDefault(x => x.pictureLayer == 0);
  115. if (b != null && b.videoUrl == AppData.Instance.CleanVideoString)
  116. {
  117. IsCleanVideo = true;
  118. }
  119. }
  120. }
  121. if (vm.DetailViewModel != null && vm.DetailViewModel.CurrentEmbryo != null)
  122. {
  123. ChangeEmbryo(vm.DetailViewModel.CurrentEmbryo.wellSn);
  124. SelectIndex(vm.DetailViewModel.CurrentEmbryo.wellSn - 1);
  125. }
  126. else
  127. {
  128. ChangeEmbryo(1);
  129. }
  130. vm.CurrentMarkModelType = null;
  131. if (vm.MarkModelTypeList != null)
  132. {
  133. vm.CurrentMarkModelType = vm.MarkModelTypeList.First();
  134. }
  135. }
  136. vm.DingWeiEvent -= QuickButton_Click;
  137. vm.DingWeiEvent += QuickButton_Click;
  138. foreach (var item in vm.CurrentDish.embryoList)
  139. {
  140. item.AlarmChangedEvent -= EmbryoAlarmEvent;
  141. item.AlarmChangedEvent += EmbryoAlarmEvent;
  142. }
  143. InitAlarm();
  144. Task.Run(async () =>
  145. {
  146. while (true)
  147. {
  148. await Task.Delay(10000);
  149. if (vm == null || vm.CurrentDish == null || AppData.Instance.CurrentTlInfo == null) return;
  150. //foreach (var item in vm.CurrentDish.embryoList)
  151. //{
  152. // if (item.alarm == 0) item.alarm = 1;
  153. // else item.alarm = 0;
  154. //}
  155. InitAlarm();
  156. }
  157. });
  158. }
  159. private void InitAlarm()
  160. {
  161. if (vm == null || vm.CurrentDish == null || AppData.Instance.CurrentTlInfo == null) return;
  162. HouseCropAlarmResponse houseCropAlarmResponse = new HouseCropAlarmResponse();
  163. HouseCropAlarmResult CurrentHouseCropAlarmResult = null;
  164. houseCropAlarmResponse.tlSn = AppData.Instance.CurrentTlInfo.tlSn;
  165. if (!houseCropAlarmResponse.houseList.Any())
  166. {
  167. houseCropAlarmResponse.houseList.Add(new HouseCropAlarmHouseResponse
  168. {
  169. houseSn = vm.CurrentDish.houseSn,
  170. startTime = vm.CurrentDish.startTime,
  171. });
  172. }
  173. CurrentHouseCropAlarmResult = vm.detailProvider.GetHouseCropAlarmApi(houseCropAlarmResponse).FirstOrDefault(x => x.houseSn == vm.CurrentDish.houseSn);
  174. foreach (var item in vm.CurrentDish.embryoList)
  175. {
  176. if (CurrentHouseCropAlarmResult == null)
  177. {
  178. item.alarm = 0;
  179. continue;
  180. }
  181. if (CurrentHouseCropAlarmResult.wellSn == null)
  182. {
  183. item.alarm = 0;
  184. continue;
  185. }
  186. if (CurrentHouseCropAlarmResult.wellSn.Contains(item.wellSn))
  187. {
  188. item.alarm = 1;
  189. }
  190. else
  191. {
  192. item.alarm = 0;
  193. }
  194. }
  195. }
  196. private void InitNav()
  197. {
  198. _nav_StackPanel.Children.Clear();
  199. for (int i = 0; i < vm.NavList.Count; i++)
  200. {
  201. var item = vm.NavList[i];
  202. if (i == vm.NavList.Count - 1)
  203. {
  204. TextBlock textBlock1 = new TextBlock();
  205. textBlock1.Margin = new Thickness(8, 0, 0, 0);
  206. textBlock1.FontWeight = FontWeights.Bold;
  207. textBlock1.Foreground = new SolidColorBrush(Colors.Black);
  208. textBlock1.FontSize = 32d;
  209. textBlock1.VerticalAlignment = VerticalAlignment.Center;
  210. textBlock1.Text = item.NavName;
  211. _nav_StackPanel.Children.Add(textBlock1);
  212. return;
  213. }
  214. Button button = new Button();
  215. button.Content = item.NavName;
  216. button.FontWeight = FontWeights.Bold;
  217. button.FontSize = 28d;
  218. button.BorderThickness = new Thickness(0);
  219. button.Background = new SolidColorBrush(Colors.Transparent);
  220. button.Style = App.Current.FindResource("ButtonStyle1") as Style;
  221. if (i == 0)
  222. {
  223. button.Margin = new Thickness(0, 0, 0, 0);
  224. }
  225. else
  226. {
  227. button.Margin = new Thickness(8, 0, 0, 0);
  228. }
  229. button.Click += (s, e) =>
  230. {
  231. PlayerDispose();
  232. if (vm != null) vm.NavList.Clear();
  233. if (item is PatientManageViewModel patient)
  234. {
  235. patient.SetTLInfo(AppData.Instance.CurrentTlInfo);
  236. AppData.Instance.MainWindowViewModel.CurrentViewModle = patient;
  237. return;
  238. }
  239. AppData.Instance.MainWindowViewModel.CurrentViewModle = item;
  240. };
  241. TextBlock textBlock = new TextBlock();
  242. textBlock.Margin = new Thickness(8, 0, 0, 0);
  243. textBlock.VerticalAlignment = VerticalAlignment.Center;
  244. textBlock.FontWeight = FontWeights.Bold;
  245. textBlock.FontSize = 28d;
  246. textBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9B9B9B"));
  247. textBlock.Text = ">";
  248. _nav_StackPanel.Children.Add(button);
  249. _nav_StackPanel.Children.Add(textBlock);
  250. }
  251. }
  252. public void MessageShow(string message)
  253. {
  254. new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, message).Show();
  255. }
  256. private void Toast(bool success)
  257. {
  258. new ToastWindow(AppData.Instance.MainWindow, 1920, 65, success).Show();
  259. }
  260. private void ExLog(Exception ex, string name)
  261. {
  262. AppData.Instance.LogService.ExceptionLog(ex, $"MarkUseView.{name}", LogEnum.RunException);
  263. }
  264. private void ErrorLog(string message, LogEnum logType)
  265. {
  266. AppData.Instance.LogService.TLLog($"MarkUseView.{message}", logType);
  267. }
  268. #region 界面按钮
  269. private void Button_Click(object sender, RoutedEventArgs e)
  270. {
  271. PlayerDispose();
  272. AppData.Instance.MainWindowViewModel.CurrentViewModle = AppData.Instance.MainWindowViewModel.devManageViewModel;
  273. }
  274. private void Parien_Click(object sender, RoutedEventArgs e)
  275. {
  276. //PlayerDispose();
  277. //AppData.Instance.MainWindowViewModel.patientManageViewModel.SetTLInfo(vm.tLInfo);
  278. //AppData.Instance.MainWindowViewModel.CurrentViewModle = AppData.Instance.MainWindowViewModel.patientManageViewModel;
  279. }
  280. private void Parien1_Click(object sender, RoutedEventArgs e)
  281. {
  282. //AppData.Instance.MainWindowViewModel.detailViewModel.Init(null, vm.tLInfo, vm.CurrentDish);
  283. AppData.Instance.MainWindowViewModel.CurrentViewModle = vm.DetailViewModel;
  284. }
  285. private void RecordParien_Click(object sender, RoutedEventArgs e)
  286. {
  287. AppData.Instance.MainWindowViewModel.CurrentViewModle = vm.RecordViewModel;
  288. }
  289. private void RecordParien1_Click(object sender, RoutedEventArgs e)
  290. {
  291. AppData.Instance.MainWindowViewModel.CurrentViewModle = vm.DetailViewModel;
  292. }
  293. private void BigFocus_Click(object sender, RoutedEventArgs e)
  294. {
  295. PlayerPause();
  296. if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return;
  297. if (vm.CurrentEmbryo == null) return;
  298. if (vm.CurrentWellLayerPicAndVideo != null) ChangeFocalNoVideo(true);
  299. //if (vm.CurrentWellLayerPicAndVideo != null) if (!string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl)) ChangeFocalNoVideo(true);
  300. // else ChangeImageFocal(true);
  301. }
  302. private void SmallFocus_Click(object sender, RoutedEventArgs e)
  303. {
  304. PlayerPause();
  305. if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return;
  306. if (vm.CurrentEmbryo == null) return;
  307. if (vm.CurrentWellLayerPicAndVideo != null) ChangeFocalNoVideo(false);
  308. //if (vm.CurrentWellLayerPicAndVideo != null) if (!string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl)) ChangeFocalNoVideo(false);
  309. // else ChangeImageFocal(false);
  310. }
  311. private void PreviousFrame_Click(object sender, RoutedEventArgs e)
  312. {
  313. if (vm == null || vm.CurrentWellLayerPicAndVideo == null) return;
  314. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  315. {
  316. PlayerPause();
  317. PlayerLastFrame(vm.CurrentWellLayerPicAndVideo.fps);
  318. //this._preview.Visibility = Visibility.Hidden;
  319. this.Canvas_preview.Visibility = Visibility.Hidden;
  320. }
  321. }
  322. private void Video_Click(object sender, RoutedEventArgs e)
  323. {
  324. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  325. {
  326. if (PlayerState == PlayerStateEnum.Playing)
  327. {
  328. PlayerPause();
  329. }
  330. else
  331. {
  332. newCurrentTime = -1;
  333. if (PlayerPlay())
  334. {
  335. //this._preview.Visibility = Visibility.Hidden;
  336. this.Canvas_preview.Visibility = Visibility.Hidden;
  337. vm.CurrentFocal = 0;
  338. }
  339. else
  340. {
  341. SetPreviewNoVideo();
  342. }
  343. }
  344. }
  345. else
  346. {
  347. SetPreviewNoVideo();
  348. }
  349. }
  350. private void NextFrame_Click(object sender, RoutedEventArgs e)
  351. {
  352. if (vm == null || vm.CurrentWellLayerPicAndVideo == null) return;
  353. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  354. {
  355. PlayerPause();
  356. PlayerNextFrame(vm.CurrentWellLayerPicAndVideo.fps);
  357. //PlayerNextFrame(vm.CurrentVideoFps);
  358. //this._preview.Visibility = Visibility.Hidden;
  359. this.Canvas_preview.Visibility = Visibility.Hidden;
  360. }
  361. }
  362. private void Fps_MouseUp(object sender, MouseButtonEventArgs e)
  363. {
  364. if (this._fps_Popup.IsOpen) this._fps_Popup.IsOpen = false;
  365. else this._fps_Popup.IsOpen = true;
  366. }
  367. private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  368. {
  369. if (vm == null) return;
  370. PlayerSetSpeedRatio(vm.SelectedFps.Key);
  371. if (this._fps_Popup.IsOpen) this._fps_Popup.IsOpen = false;
  372. }
  373. private void QuickButton_Click(int minHour, int maxHour, string quickName)
  374. {
  375. try
  376. {
  377. PlayerPause();
  378. if (vm.CurrentWellLayerPicAndVideo == null || vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
  379. {
  380. //MessageShow($"当前胚胎还未发育到{quickName}阶段");
  381. //MessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0316")}{quickName}{KeyToStringConvert.GetLanguageStringByKey("0264")}");
  382. MessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0316")} {quickName}");
  383. return;
  384. }
  385. var lastPic = vm.CurrentWellLayerPicAndVideo.videoPictures.Last();
  386. if (minHour > lastPic.developTime)
  387. {
  388. //MessageShow($"当前胚胎还未发育到{quickName}阶段");
  389. //MessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0316")}{quickName}{KeyToStringConvert.GetLanguageStringByKey("0264")}");
  390. MessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0316")} {quickName}");
  391. return;
  392. }
  393. int picCount = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
  394. for (int i = 0; i < picCount; i++)
  395. {
  396. var item = vm.CurrentWellLayerPicAndVideo.videoPictures[i];
  397. if (item.developTime >= minHour)
  398. {
  399. if (IsCleanVideo)
  400. {
  401. this.Canvas_preview.Visibility = Visibility.Visible;
  402. vm.VideoCurrentTime = i + 1;
  403. this._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{item.imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  404. }
  405. else
  406. {
  407. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  408. {
  409. this.Canvas_preview.Visibility = Visibility.Hidden;
  410. //double pro = ((i + 1) / (double)picCount) * vm.VideoAllTime;
  411. double pro = (i * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps));
  412. SetTimeProgressbarProgressValue(pro);
  413. SetPlayerPosition(pro);
  414. }
  415. else
  416. {
  417. this.Canvas_preview.Visibility = Visibility.Visible;
  418. vm.VideoCurrentTime = i + 1;
  419. this._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{item.imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  420. }
  421. }
  422. break;
  423. }
  424. }
  425. }
  426. catch (Exception ex)
  427. {
  428. ExLog(ex, $"QuickButton_Click");
  429. }
  430. //try
  431. //{
  432. // PlayerPause();
  433. // if (vm.CurrentVideoData == null || vm.CurrentVideoData.videoPictures == null || !vm.CurrentVideoData.videoPictures.Any())
  434. // {
  435. // MessageShow($"当前胚胎还未发育到{quickName}阶段");
  436. // return;
  437. // }
  438. // var lastPic = vm.CurrentVideoData.videoPictures.Last();
  439. // if (minHour > lastPic.developTime)
  440. // {
  441. // MessageShow($"当前胚胎还未发育到{quickName}阶段");
  442. // return;
  443. // }
  444. // int picCount = vm.CurrentVideoData.videoPictures.Count;
  445. // for (int i = 0; i < picCount; i++)
  446. // {
  447. // var item = vm.CurrentVideoData.videoPictures[i];
  448. // if (item.developTime > minHour)
  449. // {
  450. // this._preview.Visibility = Visibility.Hidden;
  451. // double pro = ((i + 1) / (double)picCount) * vm.VideoAllTime;
  452. // SetTimeProgressbarProgressValue(pro);
  453. // SetPlayerPosition(pro);
  454. // break;
  455. // }
  456. // }
  457. //}
  458. //catch (Exception ex)
  459. //{
  460. // ExLog(ex, $"QuickButton_Click");
  461. //}
  462. }
  463. private void Ok_Click(object sender, RoutedEventArgs e)
  464. {
  465. }
  466. private void Cancel_Click(object sender, RoutedEventArgs e)
  467. {
  468. }
  469. private void ListBox_ManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
  470. {
  471. e.Handled = true;
  472. }
  473. private void MarkDetailUserControl_SaveMarkEvent(ivf_tl_Entity.Entity.Mark.MarkEntity obj)
  474. {
  475. vm.SaveMark(obj);
  476. }
  477. #endregion
  478. #region 标记
  479. string s1 = KeyToStringConvert.GetLanguageStringByKey("0521");
  480. string s2 = KeyToStringConvert.GetLanguageStringByKey("0522");
  481. string s3 = KeyToStringConvert.GetLanguageStringByKey("0523");
  482. string s4 = KeyToStringConvert.GetLanguageStringByKey("0524");
  483. string s5 = KeyToStringConvert.GetLanguageStringByKey("0525");
  484. string s6 = KeyToStringConvert.GetLanguageStringByKey("0526");
  485. string spaceString = KeyToStringConvert.GetLanguageStringByKey("0636");
  486. string haoString = KeyToStringConvert.GetLanguageStringByKey("0635");
  487. private void EmbryoMove_Click(object sender, RoutedEventArgs e)
  488. {
  489. PlayerPause();
  490. if (vm.CurrentEmbryo == null) return;
  491. string tag = KeyToStringConvert.GetLanguageStringByKey("0041");
  492. string messInfo = GetMessageInfo(tag);
  493. int iconType = 2;
  494. if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  495. {
  496. tag = "完成";
  497. switch (vm.CurrentEmbryo.state)
  498. {
  499. case (int)EmbryoState.Freezing:
  500. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0040"));
  501. iconType = 1;
  502. break;
  503. case (int)EmbryoState.Transplant:
  504. messInfo = GetCancelMarkMessage();
  505. tag = "取消";
  506. break;
  507. case (int)EmbryoState.Cancellation:
  508. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0042"));
  509. iconType = 3;
  510. break;
  511. case (int)EmbryoState.Delete:
  512. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0043"));
  513. iconType = 4;
  514. break;
  515. }
  516. }
  517. EmbryoOp(tag, messInfo, iconType);
  518. return;
  519. }
  520. private void EmbryoFree_Click(object sender, RoutedEventArgs e)
  521. {
  522. PlayerPause();
  523. if (vm.CurrentEmbryo == null) return;
  524. int iconType = 1;
  525. string tag = KeyToStringConvert.GetLanguageStringByKey("0040");
  526. string messInfo = GetMessageInfo(tag);
  527. if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  528. {
  529. tag = "完成";
  530. switch (vm.CurrentEmbryo.state)
  531. {
  532. case (int)EmbryoState.Freezing:
  533. messInfo = GetCancelMarkMessage();
  534. tag = "取消";
  535. break;
  536. case (int)EmbryoState.Transplant:
  537. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0041"));
  538. iconType = 2;
  539. break;
  540. case (int)EmbryoState.Cancellation:
  541. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0042"));
  542. iconType = 3;
  543. break;
  544. case (int)EmbryoState.Delete:
  545. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0043"));
  546. iconType = 4;
  547. break;
  548. }
  549. }
  550. EmbryoOp(tag, messInfo, iconType);
  551. return;
  552. }
  553. private void EmbryoInv_Click(object sender, RoutedEventArgs e)
  554. {
  555. PlayerPause();
  556. if (vm.CurrentEmbryo == null) return;
  557. int iconType = 3;
  558. string tag = KeyToStringConvert.GetLanguageStringByKey("0042");
  559. string messInfo = GetMessageInfo(tag);
  560. if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  561. {
  562. tag = "完成";
  563. switch (vm.CurrentEmbryo.state)
  564. {
  565. case (int)EmbryoState.Freezing:
  566. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0040"));
  567. iconType = 1;
  568. break;
  569. case (int)EmbryoState.Transplant:
  570. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0041"));
  571. iconType = 2;
  572. break;
  573. case (int)EmbryoState.Cancellation:
  574. messInfo = GetCancelMarkMessage();
  575. tag = "取消";
  576. break;
  577. case (int)EmbryoState.Delete:
  578. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0043"));
  579. iconType = 4;
  580. break;
  581. }
  582. }
  583. EmbryoOp(tag, messInfo, iconType);
  584. return;
  585. }
  586. private void EmbryoDel_Click(object sender, RoutedEventArgs e)
  587. {
  588. PlayerPause();
  589. if (vm.CurrentEmbryo == null) return;
  590. int iconType = 4;
  591. string tag = KeyToStringConvert.GetLanguageStringByKey("0043");
  592. string messInfo = GetMessageInfo(tag);
  593. if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  594. {
  595. tag = "完成";
  596. switch (vm.CurrentEmbryo.state)
  597. {
  598. case (int)EmbryoState.Freezing:
  599. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0040"));
  600. iconType = 1;
  601. break;
  602. case (int)EmbryoState.Transplant:
  603. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0041"));
  604. iconType = 2;
  605. break;
  606. case (int)EmbryoState.Cancellation:
  607. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0042"));
  608. iconType = 3;
  609. break;
  610. case (int)EmbryoState.Delete:
  611. messInfo = GetCancelMarkMessage();
  612. tag = "取消";
  613. break;
  614. }
  615. }
  616. EmbryoOp(tag, messInfo, iconType);
  617. return;
  618. }
  619. private void EmbryoOp(string tag, string infoString, int type)
  620. {
  621. if (tag == "完成")
  622. {
  623. AppData.Instance.MainWindowViewModel.MaskVisibility = true;
  624. new MessagePrompt().ShowEmbryoOper(tag, infoString, type);
  625. AppData.Instance.MainWindowViewModel.MaskVisibility = false;
  626. return;
  627. }
  628. AppData.Instance.MainWindowViewModel.MaskVisibility = true;
  629. var rs = new MessagePrompt().ShowEmbryoOper(tag, infoString, type);
  630. AppData.Instance.MainWindowViewModel.MaskVisibility = false;
  631. if (rs != true) return;
  632. if (vm != null && vm.PdfParentViewModel != null) vm.PdfParentViewModel.IsUpdateAi = true;
  633. if (tag == "取消")
  634. {
  635. EmbryoMark((int)EmbryoState.None);
  636. return;
  637. }
  638. switch (type)
  639. {
  640. case 1:
  641. EmbryoMark((int)EmbryoState.Freezing);
  642. break;
  643. case 3:
  644. EmbryoMark((int)EmbryoState.Cancellation);
  645. break;
  646. case 2:
  647. EmbryoMark((int)EmbryoState.Transplant);
  648. break;
  649. case 4:
  650. EmbryoMark((int)EmbryoState.Delete);
  651. break;
  652. default:
  653. break;
  654. }
  655. }
  656. private void EmbryoMark(int embryoState)
  657. {
  658. try
  659. {
  660. //SetEmbryoState(vm.CurrentEmbryo.wellSn, embryoState, vm.CurrentEmbryo.alarm);
  661. //return;
  662. if (!vm.MarkEmbryo(embryoState))
  663. {
  664. MessageShow(KeyToStringConvert.GetLanguageStringByKey("0319"));
  665. return;
  666. }
  667. DateTime ct = DateTime.Now;
  668. vm.CurrentEmbryo.state = embryoState;
  669. vm.CurrentEmbryo.stateTime = ct.ToString("yyyy-MM-dd HH:mm:ss");
  670. SetEmbryoState(vm.CurrentEmbryo.wellSn, vm.CurrentEmbryo.state, vm.CurrentEmbryo.alarm);
  671. Toast(true);
  672. }
  673. catch (Exception ex)
  674. {
  675. ExLog(ex, "EmbryoMark");
  676. }
  677. }
  678. private string GetMessageInfo(string stateString)
  679. {
  680. return $"{s1}{spaceString}{stateString}{spaceString}{s2}{vm.CurrentEmbryo.wellSn}{haoString}?";
  681. }
  682. private string GetMarkMessage(string stateString)
  683. {
  684. return $"{s5}{vm.CurrentEmbryo.wellSn}{spaceString}{s6}{spaceString}{stateString}";
  685. }
  686. private string GetCancelMarkMessage()
  687. {
  688. return $"{s3}{spaceString}{vm.CurrentEmbryo.wellSn}{haoString}?";
  689. }
  690. private void SetEmbryoState(int well, int embryoState, int alarm)
  691. {
  692. var item = OperImageList[(well - 1)];
  693. var backItme = ImageList[(well - 1)];
  694. EmbryoState state = (EmbryoState)embryoState;
  695. item.Visibility = Visibility.Visible;
  696. backItme.Tag = 3;
  697. switch (state)
  698. {
  699. case EmbryoState.Freezing://冷冻
  700. item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState1Icon.png", UriKind.Absolute));
  701. backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState1Icon.png", UriKind.Absolute));
  702. break;
  703. case EmbryoState.Transplant://移植
  704. item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState2Icon.png", UriKind.Absolute));
  705. backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState2Icon.png", UriKind.Absolute));
  706. break;
  707. case EmbryoState.Cancellation://作废
  708. item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState3Icon.png", UriKind.Absolute));
  709. backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState3Icon.png", UriKind.Absolute));
  710. break;
  711. case EmbryoState.Delete://删除
  712. item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState4Icon.png", UriKind.Absolute));
  713. backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState4Icon.png", UriKind.Absolute));
  714. break;
  715. default:
  716. item.Visibility = Visibility.Hidden;
  717. if (alarm == 0)
  718. {
  719. backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute));
  720. }
  721. else
  722. {
  723. backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState3Icon.png", UriKind.Absolute));
  724. }
  725. backItme.Tag = 2;
  726. break;
  727. }
  728. }
  729. private void ButtonBottomImage_Click(object sender, RoutedEventArgs e)
  730. {
  731. AppData.Instance.MainWindowViewModel.CurrentViewModle = new MarkDetailViewModel(vm, vm.CurrentDish.id);
  732. }
  733. bool isMax = false;
  734. double maxWidth = 610;
  735. double maxLeft = 50;
  736. double minWidth = 330;
  737. double minLeft = 190;
  738. private void PreviewMouseDownEvent(object sender, MouseButtonEventArgs e)
  739. {
  740. if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
  741. {
  742. if (isMax == false)
  743. {
  744. _mask.Width = maxWidth;
  745. _mask.Height = maxWidth;
  746. mediaElementPlayer.Width = maxWidth;
  747. mediaElementPlayer.Height = maxWidth;
  748. canvas1.Width = maxWidth;
  749. canvas1.Height = maxWidth;
  750. isMax = true;
  751. Canvas.SetLeft(mediaElementPlayer, maxLeft);
  752. Canvas.SetTop(mediaElementPlayer, maxLeft);
  753. Canvas.SetLeft(_mask, maxLeft);
  754. Canvas.SetTop(_mask, maxLeft);
  755. Canvas.SetLeft(canvas1, maxLeft);
  756. Canvas.SetTop(canvas1, maxLeft);
  757. Panel.SetZIndex(mediaElementPlayer, 16);
  758. Panel.SetZIndex(canvas1, 18);
  759. }
  760. else
  761. {
  762. _mask.Width = minWidth;
  763. _mask.Height = minWidth;
  764. mediaElementPlayer.Width = minWidth;
  765. mediaElementPlayer.Height = minWidth;
  766. canvas1.Width = minWidth;
  767. canvas1.Height = minWidth;
  768. isMax = false;
  769. Canvas.SetLeft(mediaElementPlayer, minLeft);
  770. Canvas.SetTop(mediaElementPlayer, minLeft);
  771. Canvas.SetLeft(_mask, minLeft);
  772. Canvas.SetTop(_mask, minLeft);
  773. Canvas.SetLeft(canvas1, minLeft);
  774. Canvas.SetTop(canvas1, minLeft);
  775. Panel.SetZIndex(mediaElementPlayer, 8);
  776. Panel.SetZIndex(canvas1, 10);
  777. }
  778. SetLoad(isMax);
  779. SetPreView(isMax);
  780. }
  781. e.Handled = true;
  782. return;
  783. }
  784. private void SetLoad(bool isMax)
  785. {
  786. if (isMax)
  787. {
  788. Image_Load.Width = maxWidth;
  789. Image_Load.Height = maxWidth;
  790. Canvas_Load.Width = maxWidth;
  791. Canvas_Load.Height = maxWidth;
  792. TextBlock_Load.Width = maxWidth;
  793. TextBlock_Load.FontSize = 38;
  794. Canvas.SetTop(TextBlock_Load, 361);
  795. Canvas.SetLeft(Canvas_Load, maxLeft);
  796. Canvas.SetTop(Canvas_Load, maxLeft);
  797. Panel.SetZIndex(Canvas_Load, 15);
  798. }
  799. else
  800. {
  801. Image_Load.Width = minWidth;
  802. Image_Load.Height = minWidth;
  803. Canvas_Load.Width = minWidth;
  804. Canvas_Load.Height = minWidth;
  805. TextBlock_Load.Width = minWidth;
  806. TextBlock_Load.FontSize = 20;
  807. Canvas.SetTop(TextBlock_Load, 198);
  808. Canvas.SetLeft(Canvas_Load, minLeft);
  809. Canvas.SetTop(Canvas_Load, minLeft);
  810. Panel.SetZIndex(Canvas_Load, 7);
  811. }
  812. }
  813. private void SetPreView(bool isMax)
  814. {
  815. if (isMax)
  816. {
  817. _preview.Width = maxWidth;
  818. _preview.Height = maxWidth;
  819. Canvas_preview.Width = maxWidth;
  820. Canvas_preview.Height = maxWidth;
  821. TextBlock_preview.Width = maxWidth;
  822. TextBlock_preview.FontSize = 38;
  823. Canvas.SetTop(TextBlock_preview, 361);
  824. Canvas.SetLeft(Canvas_preview, maxLeft);
  825. Canvas.SetTop(Canvas_preview, maxLeft);
  826. Panel.SetZIndex(Canvas_preview, 17);
  827. }
  828. else
  829. {
  830. _preview.Width = minWidth;
  831. _preview.Height = minWidth;
  832. Canvas_preview.Width = minWidth;
  833. Canvas_preview.Height = minWidth;
  834. TextBlock_preview.Width = minWidth;
  835. TextBlock_preview.FontSize = 20;
  836. Canvas.SetTop(TextBlock_preview, 198);
  837. Canvas.SetLeft(Canvas_preview, minLeft);
  838. Canvas.SetTop(Canvas_preview, minLeft);
  839. Panel.SetZIndex(Canvas_preview, 9);
  840. }
  841. }
  842. #endregion
  843. #region 进度条事件
  844. private void ProgressbarUserControl_AfterInteractionEvent(double obj)
  845. {
  846. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  847. {
  848. currentMediaElement.LoadedBehavior = MediaState.Manual;
  849. SetPlayerPosition(obj);
  850. }
  851. else
  852. {
  853. if (vm.CurrentWellLayerPicAndVideo != null && vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
  854. {
  855. this._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoPictures[ProToImageIndex()].imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  856. this.TextBlock_preview.Text = "";
  857. }
  858. }
  859. }
  860. private void ProgressbarUserControl_BeforeInteractionEvent()
  861. {
  862. PlayerPause();
  863. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  864. {
  865. //this._preview.Visibility = Visibility.Hidden;
  866. this.Canvas_preview.Visibility = Visibility.Hidden;
  867. }
  868. }
  869. List<PictureEntity> PicList = null;
  870. int picCount = 0;
  871. int picIndex = 0;
  872. private string ProgressbarUserControl_LengthDevelopmentEvent(double arg)
  873. {
  874. try
  875. {
  876. if (vm == null || vm.CurrentWellLayerPicAndVideo == null)
  877. {
  878. vm.CurrentPic = null;
  879. return "00h:00m";
  880. }
  881. if (vm.CurrentWellLayerPicAndVideo == null || vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
  882. {
  883. vm.CurrentPic = null;
  884. return "00h:00m";
  885. }
  886. if (string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) || vm.CurrentWellLayerPicAndVideo.videoUrl == AppData.Instance.CleanVideoString)
  887. {
  888. picIndex = ProToImageIndex();
  889. vm.CurrentPic = vm.CurrentWellLayerPicAndVideo.videoPictures[picIndex];
  890. //Debug.WriteLine($"proLength {picIndex} ->{vm.CurrentWellLayerPicAndVideo.videoPictures.Count}");
  891. return $"{(vm.CurrentPic.developTime / 60).ToString("D2")}h:{(vm.CurrentPic.developTime % 60).ToString("D2")}m";
  892. }
  893. else
  894. {
  895. picCount = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
  896. picIndex = VideoProToImageIndex();
  897. if (picIndex < 0) picIndex = 0;
  898. if (picIndex > (picCount - 1)) picIndex = picCount - 1;
  899. vm.CurrentPic = vm.CurrentWellLayerPicAndVideo.videoPictures[picIndex];
  900. return $"{(vm.CurrentPic.developTime / 60).ToString("D2")}h:{(vm.CurrentPic.developTime % 60).ToString("D2")}m";
  901. }
  902. }
  903. catch (Exception ex)
  904. {
  905. vm.CurrentPic = null;
  906. ExLog(ex, "获取当前帧发育时长");
  907. return "00h:00m";
  908. }
  909. //try
  910. //{
  911. // if (vm == null || vm.CurrentVideoData == null) return "00h:00m";
  912. // PicList = vm.CurrentVideoData.videoPictures;
  913. // if (PicList == null || !PicList.Any()) return "00h:00m";
  914. // picCount = PicList.Count;
  915. // picIndex = VideoProToImageIndex();
  916. // if (picIndex < 0) picIndex = 0;
  917. // if (picIndex > (picCount - 1)) picIndex = picCount - 1;
  918. // vm.CurrentPicZhen = PicList[picIndex];
  919. // return $"{(vm.CurrentPicZhen.developTime / 60).ToString("D2")}h:{(vm.CurrentPicZhen.developTime % 60).ToString("D2")}m";
  920. //}
  921. //catch (Exception ex)
  922. //{
  923. // if (vm != null) vm.CurrentPicZhen = null;
  924. // ExLog(ex, "获取当前帧发育时长");
  925. // return "00h:00m";
  926. //}
  927. }
  928. private void ProgressbarUserControl_ProChangendEvent(double obj)
  929. {
  930. if (PlayerState != PlayerStateEnum.Nothing || PlayerState != PlayerStateEnum.Error) SetPlayerPosition(obj);
  931. }
  932. public int VideoProToImageIndex()
  933. {
  934. try
  935. {
  936. if (vm == null || vm.CurrentWellLayerPicAndVideo == null) return 0;
  937. return (int)(vm.VideoCurrentTime / (1000.00 / vm.CurrentWellLayerPicAndVideo.fps));
  938. }
  939. catch (Exception ex)
  940. {
  941. ExLog(ex, "VideoProToImageIndex");
  942. return 0;
  943. }
  944. //try
  945. //{
  946. // return (int)(vm.VideoCurrentTime / (1000.00 / vm.CurrentVideoFps));
  947. //}
  948. //catch (Exception ex)
  949. //{
  950. // ExLog(ex, "VideoProToImageIndex");
  951. // return 0;
  952. //}
  953. }
  954. /// <summary>
  955. /// 进度条换算图片下标
  956. /// </summary>
  957. /// <returns></returns>
  958. public int ProToImageIndex()
  959. {
  960. try
  961. {
  962. if (vm == null || vm.CurrentWellLayerPicAndVideo == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any()) return 0;
  963. var imageIndex = ((int)vm.VideoCurrentTime - 1);
  964. if (imageIndex < 0) imageIndex = 0;
  965. if (imageIndex >= vm.CurrentWellLayerPicAndVideo.videoPictures.Count) imageIndex = vm.CurrentWellLayerPicAndVideo.videoPictures.Count - 1;
  966. return imageIndex;
  967. }
  968. catch (Exception ex)
  969. {
  970. ExLog(ex, "ProToImageIndex");
  971. return 0;
  972. }
  973. }
  974. #endregion
  975. #region 初始化
  976. private void InitQuickButton()
  977. {
  978. this._quick_StackPanel.Children.Clear();
  979. //if (vm == null || vm.QuickButtons == null || !vm.QuickButtons.Any())
  980. //{
  981. // this._quickT.Visibility = Visibility.Hidden;
  982. // return;
  983. //}
  984. //this._quickT.Visibility = Visibility.Visible;
  985. bool isFirst = true;
  986. var newList = vm.QuickButtons.OrderBy(x => x.orderNum).Take(7);
  987. foreach (var item in newList)
  988. {
  989. ButtonLeftImage buttonLeftImage = new ButtonLeftImage()
  990. {
  991. IconWidth = 40,
  992. IconHeight = 40,
  993. IconMargin = new Thickness(0, 0, 5, 0),
  994. Content = item.buttonName,
  995. FontWeight = FontWeights.Medium,
  996. FontSize = 24,
  997. Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9B9B9B")),
  998. MouseOverForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D4D4D")),
  999. IconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailQuickIcon.png", UriKind.Absolute)),
  1000. MouseOverIconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailQuickMouseOverIcon.png", UriKind.Absolute)),
  1001. };
  1002. if (!isFirst) buttonLeftImage.Margin = new Thickness(20, 0, 0, 0);
  1003. if (isFirst) isFirst = false;
  1004. buttonLeftImage.Click += (sender, args) =>
  1005. {
  1006. QuickButton_Click(item.minHour * 60, item.maxHour * 60, item.buttonName);
  1007. };
  1008. this._quick_StackPanel.Children.Add(buttonLeftImage);
  1009. }
  1010. }
  1011. private void InitMark()
  1012. {
  1013. }
  1014. private void InitCustom()
  1015. {
  1016. try
  1017. {
  1018. EllipseGeometry ellipseGeometry = new EllipseGeometry(new Point(imageRadius, imageRadius), imageRadius, imageRadius);
  1019. Embryo itemEmbryo = null;
  1020. for (int i = 0; i < ellipseCount; i++)
  1021. {
  1022. TextBlock textBlock = new TextBlock();
  1023. Image border = new Image();
  1024. Image image = new Image();
  1025. Image opImage = new Image();
  1026. this._canvas.Children.Add(textBlock);
  1027. this._canvas.Children.Add(border);
  1028. this._canvas.Children.Add(image);
  1029. this._canvas.Children.Add(opImage);
  1030. Panel.SetZIndex(textBlock, 11);
  1031. Panel.SetZIndex(border, 12);
  1032. Panel.SetZIndex(image, 13);
  1033. Panel.SetZIndex(opImage, 14);
  1034. textBlock.FontWeight = FontWeights.Medium;
  1035. textBlock.Foreground = deaeatForeground;
  1036. textBlock.FontSize = 14;
  1037. textBlock.Width = 16;
  1038. textBlock.Height = 22;
  1039. textBlock.Text = $"{i + 1}";
  1040. textBlock.TextAlignment = TextAlignment.Center;
  1041. textBlock.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - 7);
  1042. textBlock.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - 11);
  1043. TextBlockList.Add(textBlock);
  1044. ImageList.Add(border);
  1045. PicImageList.Add(image);
  1046. border.Width = backImageRadius * 2;
  1047. border.Height = backImageRadius * 2;
  1048. border.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * backImageBigRadius - backImageRadius);
  1049. border.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * backImageBigRadius - backImageRadius);
  1050. opImage.Width = operRaius * 2;
  1051. opImage.Height = operRaius * 2;
  1052. opImage.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * operBigRadius - operRaius);
  1053. opImage.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * operBigRadius - operRaius);
  1054. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState1Icon.png", UriKind.Absolute));
  1055. OperImageList.Add(opImage);
  1056. image.Width = imageRadius * 2;
  1057. image.Height = imageRadius * 2;
  1058. image.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius);
  1059. image.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius);
  1060. image.SetValue(Image.ClipProperty, ellipseGeometry);
  1061. image.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png", UriKind.Absolute));
  1062. image.Tag = i;
  1063. image.MouseUp += (s, e) =>
  1064. {
  1065. if (!(s is Image source)) return;
  1066. int index = (int)source.Tag;
  1067. if (selectedIndex == index) return;
  1068. SelectIndex(index);
  1069. PlayerPause();
  1070. ChangeEmbryo(index + 1);
  1071. };
  1072. var aa = vm.CurrentDish;
  1073. itemEmbryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == i + 1);
  1074. if (itemEmbryo == null)//无胚胎
  1075. {
  1076. opImage.Visibility = Visibility.Hidden;
  1077. textBlock.Tag = 0;
  1078. textBlock.Foreground = noEmbryoForeground;
  1079. border.Tag = 0;
  1080. border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryoBackground.png", UriKind.Absolute));
  1081. continue;
  1082. }
  1083. switch ((EmbryoState)itemEmbryo.state)
  1084. {
  1085. case EmbryoState.Freezing: //冷冻
  1086. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState1Icon.png", UriKind.Absolute));
  1087. break;
  1088. case EmbryoState.Transplant://移植
  1089. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState2Icon.png", UriKind.Absolute));
  1090. break;
  1091. case EmbryoState.Cancellation://作废
  1092. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState3Icon.png", UriKind.Absolute));
  1093. break;
  1094. case EmbryoState.Delete://删除
  1095. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState4Icon.png", UriKind.Absolute));
  1096. break;
  1097. default:
  1098. opImage.Visibility = Visibility.Hidden;
  1099. break;
  1100. }
  1101. var currentData = vm.DishPicAndVideoList.FirstOrDefault(x => x.wellSn == itemEmbryo.wellSn);
  1102. if (currentData == null || string.IsNullOrEmpty(currentData.lastPicture))//无图片
  1103. {
  1104. textBlock.Tag = 1;
  1105. textBlock.Foreground = noPicForeground;
  1106. border.Tag = 1;
  1107. border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png", UriKind.Absolute));
  1108. continue;
  1109. }
  1110. string borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png";
  1111. int borderTag = 3;
  1112. switch ((EmbryoState)itemEmbryo.state)
  1113. {
  1114. case EmbryoState.None:
  1115. borderTag = 2;
  1116. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png";
  1117. break;
  1118. case EmbryoState.Freezing: //冷冻
  1119. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState1Icon.png";
  1120. break;
  1121. case EmbryoState.Transplant://移植
  1122. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState2Icon.png";
  1123. break;
  1124. case EmbryoState.Cancellation://作废
  1125. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState3Icon.png";
  1126. break;
  1127. case EmbryoState.Delete://删除
  1128. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState4Icon.png";
  1129. break;
  1130. }
  1131. textBlock.Tag = 2;
  1132. textBlock.Foreground = deaeatForeground;
  1133. border.Tag = borderTag;
  1134. border.Source = new BitmapImage(new Uri(borderSource, UriKind.Absolute));
  1135. }
  1136. SelectIndex(0);
  1137. }
  1138. catch (Exception)
  1139. {
  1140. throw;
  1141. }
  1142. }
  1143. private void InitCustomNew()
  1144. {
  1145. try
  1146. {
  1147. EllipseGeometry ellipseGeometry = new EllipseGeometry(new Point(imageRadius, imageRadius), imageRadius, imageRadius);
  1148. Embryo itemEmbryo = null;
  1149. for (int i = 0; i < ellipseCount; i++)
  1150. {
  1151. TextBlock textBlock = new TextBlock();
  1152. Image border = new Image();
  1153. Image image = new Image();
  1154. Image opImage = new Image();
  1155. this._canvas.Children.Add(textBlock);
  1156. this._canvas.Children.Add(border);
  1157. this._canvas.Children.Add(image);
  1158. this._canvas.Children.Add(opImage);
  1159. Panel.SetZIndex(textBlock, 11);
  1160. Panel.SetZIndex(border, 12);
  1161. Panel.SetZIndex(image, 13);
  1162. Panel.SetZIndex(opImage, 14);
  1163. textBlock.FontWeight = FontWeights.Medium;
  1164. textBlock.Foreground = deaeatForeground;
  1165. textBlock.FontSize = 14;
  1166. textBlock.Width = 16;
  1167. textBlock.Height = 22;
  1168. textBlock.Text = $"{i + 1}";
  1169. textBlock.TextAlignment = TextAlignment.Center;
  1170. textBlock.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - 7);
  1171. textBlock.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - 11);
  1172. TextBlockList.Add(textBlock);
  1173. ImageList.Add(border);
  1174. PicImageList.Add(image);
  1175. border.Width = backImageRadius * 2;
  1176. border.Height = backImageRadius * 2;
  1177. border.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * backImageBigRadius - backImageRadius);
  1178. border.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * backImageBigRadius - backImageRadius);
  1179. opImage.Width = operRaius * 2;
  1180. opImage.Height = operRaius * 2;
  1181. opImage.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * operBigRadius - operRaius);
  1182. opImage.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * operBigRadius - operRaius);
  1183. //opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState1Icon.png", UriKind.Absolute));
  1184. OperImageList.Add(opImage);
  1185. image.Width = imageRadius * 2;
  1186. image.Height = imageRadius * 2;
  1187. image.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius);
  1188. image.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius);
  1189. image.SetValue(Image.ClipProperty, ellipseGeometry);
  1190. if (vm.CurrentDish == null)
  1191. {
  1192. border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryoBackground.png", UriKind.Absolute));
  1193. }
  1194. else
  1195. {
  1196. itemEmbryo = SetWellImage(i, 0);
  1197. if (itemEmbryo == null)
  1198. {
  1199. textBlock.Tag = 0;
  1200. textBlock.Foreground = noEmbryoForeground;
  1201. image.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryo.png", UriKind.Absolute));
  1202. }
  1203. else
  1204. {
  1205. textBlock.Tag = 2;
  1206. textBlock.Foreground = deaeatForeground;
  1207. image.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryo1.png", UriKind.Absolute));
  1208. switch ((EmbryoState)itemEmbryo.state)
  1209. {
  1210. case EmbryoState.Freezing: //冷冻
  1211. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState1Icon.png", UriKind.Absolute));
  1212. break;
  1213. case EmbryoState.Transplant://移植
  1214. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState2Icon.png", UriKind.Absolute));
  1215. break;
  1216. case EmbryoState.Cancellation://作废
  1217. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState3Icon.png", UriKind.Absolute));
  1218. break;
  1219. case EmbryoState.Delete://删除
  1220. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState4Icon.png", UriKind.Absolute));
  1221. break;
  1222. default:
  1223. opImage.Visibility = Visibility.Hidden;
  1224. break;
  1225. }
  1226. }
  1227. }
  1228. if (i == 0) textBlock.Foreground = new SolidColorBrush(Colors.White);
  1229. int index = i;
  1230. image.MouseUp += (s, e) =>
  1231. {
  1232. if (!this.IsLoaded) return;
  1233. if (selectedIndex == index) return;
  1234. SelectIndex(index);
  1235. PlayerPause();
  1236. ChangeEmbryo(index + 1);
  1237. };
  1238. }
  1239. }
  1240. catch (Exception ex)
  1241. {
  1242. ExLog(ex, "InitCustomNew");
  1243. }
  1244. }
  1245. private object lock1 = new object();
  1246. private Embryo SetWellImage(int index, int oldIndex)
  1247. {
  1248. lock (lock1)
  1249. {
  1250. if (vm == null || vm.CurrentDish == null) return null;
  1251. Image imageBorder = ImageList[index];
  1252. var itemEmbryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == index + 1);
  1253. if (itemEmbryo == null)
  1254. {
  1255. if (index == oldIndex)
  1256. {
  1257. imageBorder.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute));
  1258. }
  1259. else
  1260. {
  1261. imageBorder.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryoBackground.png", UriKind.Absolute));
  1262. }
  1263. return itemEmbryo;
  1264. }
  1265. string borderSource = null;
  1266. switch ((EmbryoState)itemEmbryo.state)
  1267. {
  1268. case EmbryoState.End:
  1269. case EmbryoState.None:
  1270. if (itemEmbryo.alarm == 1)
  1271. {
  1272. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState3Icon.png";
  1273. }
  1274. else
  1275. {
  1276. if (index == oldIndex)
  1277. {
  1278. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png";
  1279. }
  1280. else
  1281. {
  1282. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png";
  1283. }
  1284. }
  1285. break;
  1286. case EmbryoState.Freezing: //冷冻
  1287. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState1Icon.png";
  1288. break;
  1289. case EmbryoState.Transplant://移植
  1290. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState2Icon.png";
  1291. break;
  1292. case EmbryoState.Cancellation://作废
  1293. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState3Icon.png";
  1294. break;
  1295. case EmbryoState.Delete://删除
  1296. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState4Icon.png";
  1297. break;
  1298. }
  1299. imageBorder.Source = new BitmapImage(new Uri(borderSource, UriKind.Absolute));
  1300. return itemEmbryo;
  1301. }
  1302. }
  1303. private void EmbryoAlarmEvent(int wellsn, int stateAlarm)
  1304. {
  1305. try
  1306. {
  1307. Dispatcher.Invoke(() => { SetWellImage(wellsn - 1, selectedIndex); });
  1308. }
  1309. catch (Exception)
  1310. {
  1311. }
  1312. }
  1313. /// <summary>
  1314. /// 切换well
  1315. /// </summary>
  1316. /// <param name="well"></param>
  1317. public void ChangeEmbryo(int well)
  1318. {
  1319. //try
  1320. //{
  1321. // this._bigFocal_Button.IsEnabled = true;
  1322. // this._smallFocal_Button.IsEnabled = true;
  1323. // SetVideoButtonState(false);
  1324. // vm.CurrentFocal = 0;
  1325. // vm.CurrentPicZhen = null;
  1326. // vm.CurrentEmbryo = null;
  1327. // vm.CurrentVideoData = null;
  1328. // vm.VideoAllTime = 1;
  1329. // vm.VideoCurrentTime = 0;
  1330. // if (vm.CurrentDish != null && vm.CurrentDish.id > 0) vm.CurrentEmbryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == well);
  1331. // vm.CurrentVideoData = vm.AllEmbryoPicAndVideo.FirstOrDefault(x => x.wellSn == well);
  1332. // SetPreview(well);
  1333. // SetVideo(vm.CurrentFocal, true);
  1334. //}
  1335. //catch (Exception ex)
  1336. //{
  1337. // ExLog(ex, "ChangeEmbryo");
  1338. //}
  1339. try
  1340. {
  1341. PlayerDispose();
  1342. if (vm == null) return;
  1343. vm.CurrentEmbryo = null;
  1344. vm.CurrentWellDishPicAndVideo = null;
  1345. vm.CurrentWellLayerPicAndVideo = null;
  1346. SetVideoButtonState(false);
  1347. vm.CurrentFocal = 0;
  1348. this._bigFocal_Button.IsEnabled = true;
  1349. this._smallFocal_Button.IsEnabled = true;
  1350. if (vm.CurrentDish != null && vm.CurrentDish.id > 0) vm.CurrentEmbryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == well);
  1351. if (vm.CurrentEmbryo == null)
  1352. {
  1353. vm.VideoAllTime = 1;
  1354. vm.VideoCurrentTime = 0;
  1355. }
  1356. if (vm.CurrentEmbryo != null) vm.CurrentWellDishPicAndVideo = vm.DishPicAndVideoList.FirstOrDefault(x => x.wellSn == vm.CurrentEmbryo.wellSn);
  1357. if (vm.CurrentWellDishPicAndVideo != null) vm.CurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == 0);
  1358. SetPreview(well);
  1359. SetVideo(vm.CurrentFocal, true);
  1360. if (vm.CurrentWellLayerPicAndVideo != null && vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
  1361. {
  1362. this._bigFocal_Button.IsEnabled = true;
  1363. this._smallFocal_Button.IsEnabled = true;
  1364. if (string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) || vm.CurrentWellLayerPicAndVideo.videoUrl == AppData.Instance.CleanVideoString)
  1365. {
  1366. vm.VideoAllTime = 1;
  1367. vm.VideoCurrentTime = 0;
  1368. vm.VideoAllTime = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
  1369. vm.VideoCurrentTime = vm.VideoAllTime;
  1370. }
  1371. }
  1372. else
  1373. {
  1374. this._bigFocal_Button.IsEnabled = false;
  1375. this._smallFocal_Button.IsEnabled = false;
  1376. }
  1377. }
  1378. catch (Exception ex)
  1379. {
  1380. ExLog(ex, "ChangeEmbryo");
  1381. }
  1382. }
  1383. /// <summary>
  1384. /// 设置视频
  1385. /// </summary>
  1386. private bool SetVideo(int focal, bool isUpdate)
  1387. {
  1388. PlayerDispose();
  1389. if (vm.CurrentWellLayerPicAndVideo != null && !string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) && vm.CurrentWellLayerPicAndVideo.videoUrl != AppData.Instance.CleanVideoString)
  1390. if (PlayerSetSource($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}")) return true;
  1391. if (!isUpdate) return false;
  1392. vm.VideoAllTime = 1;
  1393. vm.VideoCurrentTime = 0;
  1394. return true;
  1395. }
  1396. /// <summary>
  1397. /// 设置选中状态
  1398. /// </summary>
  1399. /// <param name="index"></param>
  1400. private void SelectIndex(int index)
  1401. {
  1402. switch (TextBlockList[selectedIndex].Tag.ToString())
  1403. {
  1404. case "0":
  1405. TextBlockList[selectedIndex].Foreground = noEmbryoForeground;
  1406. break;
  1407. case "1":
  1408. TextBlockList[selectedIndex].Foreground = noPicForeground;
  1409. break;
  1410. case "2":
  1411. TextBlockList[selectedIndex].Foreground = deaeatForeground;
  1412. break;
  1413. }
  1414. SetWellImage(selectedIndex, -1);
  1415. selectedIndex = index;
  1416. TextBlockList[selectedIndex].Foreground = new SolidColorBrush(Colors.White);
  1417. var itemEmbryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == selectedIndex + 1);
  1418. if (itemEmbryo == null)
  1419. {
  1420. ImageList[selectedIndex].Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute));
  1421. }
  1422. else
  1423. {
  1424. if ((itemEmbryo.state == (int)EmbryoState.End || itemEmbryo.state == (int)EmbryoState.None) && itemEmbryo.alarm == 0)
  1425. {
  1426. ImageList[selectedIndex].Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute));
  1427. }
  1428. }
  1429. RotateTransform rotateTransform = this._sx.RenderTransform as RotateTransform;
  1430. rotateTransform.Angle = angle * selectedIndex;
  1431. }
  1432. private void SelectIndexold(int index)
  1433. {
  1434. switch (TextBlockList[selectedIndex].Tag.ToString())
  1435. {
  1436. case "0":
  1437. TextBlockList[selectedIndex].Foreground = noEmbryoForeground;
  1438. break;
  1439. case "1":
  1440. TextBlockList[selectedIndex].Foreground = noPicForeground;
  1441. break;
  1442. case "2":
  1443. TextBlockList[selectedIndex].Foreground = deaeatForeground;
  1444. break;
  1445. }
  1446. switch (ImageList[selectedIndex].Tag.ToString())
  1447. {
  1448. case "0":
  1449. ImageList[selectedIndex].Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryoBackground.png", UriKind.Absolute));
  1450. break;
  1451. case "1":
  1452. case "2":
  1453. ImageList[selectedIndex].Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png", UriKind.Absolute));
  1454. break;
  1455. }
  1456. selectedIndex = index;
  1457. TextBlockList[selectedIndex].Foreground = new SolidColorBrush(Colors.White);
  1458. switch (ImageList[selectedIndex].Tag.ToString())
  1459. {
  1460. case "0":
  1461. case "1":
  1462. case "2":
  1463. ImageList[selectedIndex].Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute));
  1464. break;
  1465. }
  1466. RotateTransform rotateTransform = this._sx.RenderTransform as RotateTransform;
  1467. rotateTransform.Angle = angle * selectedIndex;
  1468. }
  1469. /// <summary>
  1470. /// 设置封面
  1471. /// </summary>
  1472. /// <param name="well"></param>
  1473. private void SetPreview(int well)
  1474. {
  1475. vm.SelectedFps = new KeyValuePair<double, string>(1d, "1.0x");
  1476. currentMediaElement.SpeedRatio = 1d;
  1477. //this._preview.Visibility = Visibility.Visible;
  1478. this.Canvas_preview.Visibility = Visibility.Visible;
  1479. if (vm.CurrentEmbryo == null)
  1480. {
  1481. //this._preview.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryoBigPic.png", UriKind.Absolute));
  1482. AppData.Instance.SetImageSource(this._preview, LogoEnum.Circle);
  1483. this.TextBlock_preview.Text = peitai;
  1484. return;
  1485. }
  1486. if (vm.CurrentWellDishPicAndVideo == null || string.IsNullOrEmpty(vm.CurrentWellDishPicAndVideo.lastPicture))
  1487. {
  1488. this._preview.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoPicBigPic.png", UriKind.Absolute));
  1489. this.TextBlock_preview.Text = paiShe;
  1490. return;
  1491. }
  1492. this._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.CurrentWellDishPicAndVideo.lastPicture}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  1493. this.TextBlock_preview.Text = "";
  1494. }
  1495. /// <summary>
  1496. /// 设置封面为无视频
  1497. /// </summary>
  1498. /// <param name="well"></param>
  1499. private void SetPreviewNoVideo()
  1500. {
  1501. //this._preview.Visibility = Visibility.Visible;
  1502. this.Canvas_preview.Visibility = Visibility.Visible;
  1503. this._preview.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoVideoPic.png", UriKind.Absolute));
  1504. this.TextBlock_preview.Text = shiping;
  1505. }
  1506. /// <summary>
  1507. /// 设置缩略图
  1508. /// </summary>
  1509. /// <param name="datas"></param>
  1510. private void SetEmbryoPic()
  1511. {
  1512. Image item = null;
  1513. for (int i = 0; i < 16; i++)
  1514. {
  1515. item = PicImageList[i];
  1516. var embryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == i + 1);
  1517. if (embryo == null)
  1518. {
  1519. item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryo.png", UriKind.Absolute));
  1520. continue;
  1521. }
  1522. //var currentData = vm.AllEmbryoPicAndVideo.FirstOrDefault(x => x.wellSn == embryo.wellSn);
  1523. var currentData = vm.DishPicAndVideoList.FirstOrDefault(x => x.wellSn == embryo.wellSn);
  1524. if (currentData == null || currentData.lastPicture == null)
  1525. {
  1526. item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoNoPic.png", UriKind.Absolute));
  1527. }
  1528. else
  1529. {
  1530. item.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{currentData.lastPicture.Replace(AppData.Instance.PicSuf, $"_80x80{AppData.Instance.PicSuf}")}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  1531. }
  1532. }
  1533. }
  1534. /// <summary>
  1535. /// 切换图层
  1536. /// </summary>
  1537. /// <param name="isMax"></param>
  1538. private void ChangeFocal(bool isMax)
  1539. {
  1540. try
  1541. {
  1542. PlayerPause();
  1543. int newCurrentFocal = vm.CurrentFocal;
  1544. int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2;
  1545. int minFocal = -maxFocal;
  1546. if (isMax) newCurrentFocal++;
  1547. else newCurrentFocal--;
  1548. if (newCurrentFocal < maxFocal) this._bigFocal_Button.IsEnabled = true;
  1549. else this._bigFocal_Button.IsEnabled = false;
  1550. if (newCurrentFocal > minFocal) this._smallFocal_Button.IsEnabled = true;
  1551. else this._smallFocal_Button.IsEnabled = false;
  1552. if (newCurrentFocal < minFocal || newCurrentFocal > maxFocal) return;
  1553. //this._preview.Visibility = Visibility.Hidden;
  1554. this.Canvas_preview.Visibility = Visibility.Hidden;
  1555. Task.Run(() =>
  1556. {
  1557. Dispatcher.Invoke(() =>
  1558. {
  1559. var a = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.detailProvider.GetImageUrlApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal, vm.CurrentPic.developTime)}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  1560. if (a != null)
  1561. {
  1562. //this._preview.Visibility = Visibility.Visible;
  1563. this.Canvas_preview.Visibility = Visibility.Visible;
  1564. this._preview.Source = a;
  1565. this.TextBlock_preview.Text = "";
  1566. }
  1567. });
  1568. });
  1569. newCurrentTime = 0;
  1570. vm.CurrentFocal = newCurrentFocal;
  1571. SetVideoButtonState(false);
  1572. if (vm.CurrentWellDishPicAndVideo == null) return;
  1573. vm.CurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == vm.CurrentFocal);
  1574. SetVideo(vm.CurrentFocal, false);
  1575. if (vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
  1576. {
  1577. vm.CurrentWellLayerPicAndVideo.videoPictures = vm.detailProvider.GetVideoTimeLineApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, vm.CurrentFocal);
  1578. }
  1579. if (vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any() || vm.CurrentPic == null) return;
  1580. int i = 0;
  1581. foreach (var item in vm.CurrentWellLayerPicAndVideo.videoPictures)
  1582. {
  1583. if (item.developTime >= vm.CurrentPic.developTime) break;
  1584. i++;
  1585. }
  1586. newCurrentTime = i * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps);
  1587. //if (i == 0) newCurrentTime = 0;
  1588. //else newCurrentTime = (i + 1) * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps);
  1589. }
  1590. catch (Exception ex)
  1591. {
  1592. ExLog(ex, "ChangeFocal");
  1593. }
  1594. }
  1595. /// <summary>
  1596. /// 切换图层
  1597. /// </summary>
  1598. /// <param name="isMax"></param>
  1599. private void ChangeImageFocal(bool isMax)
  1600. {
  1601. try
  1602. {
  1603. int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2;
  1604. int minFocal = -maxFocal;
  1605. int newCurrentFocal = vm.CurrentFocal;
  1606. if (isMax) newCurrentFocal++;
  1607. else newCurrentFocal--;
  1608. if (newCurrentFocal < maxFocal) this._bigFocal_Button.IsEnabled = true;
  1609. else this._bigFocal_Button.IsEnabled = false;
  1610. if (newCurrentFocal > minFocal) this._smallFocal_Button.IsEnabled = true;
  1611. else this._smallFocal_Button.IsEnabled = false;
  1612. if (newCurrentFocal < minFocal || newCurrentFocal > maxFocal) return;
  1613. var newCurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == newCurrentFocal);
  1614. newCurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == newCurrentFocal);
  1615. if (newCurrentWellLayerPicAndVideo == null) return;
  1616. if (!newCurrentWellLayerPicAndVideo.videoPictures.Any()) return;
  1617. vm.CurrentWellLayerPicAndVideo = newCurrentWellLayerPicAndVideo;
  1618. //this._preview.Visibility = Visibility.Visible;
  1619. this.Canvas_preview.Visibility = Visibility.Visible;
  1620. var oldDevelopTime = vm.CurrentPic.developTime;
  1621. vm.CurrentFocal = newCurrentFocal;
  1622. vm.VideoAllTime = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
  1623. int i = 0;
  1624. foreach (var item in vm.CurrentWellLayerPicAndVideo.videoPictures)
  1625. {
  1626. if (item.developTime >= oldDevelopTime) break;
  1627. i++;
  1628. }
  1629. //Debug.WriteLine($"{vm.CurrentWellLayerPicAndVideo.videoPictures[163].developTime} -> {oldDevelopTime}");
  1630. //Debug.WriteLine($"focal:{i} -》 {vm.CurrentWellLayerPicAndVideo.videoPictures.Count}");
  1631. //vm.VideoCurrentTime = vm.VideoAllTime;
  1632. this._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoPictures[i].imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  1633. this.TextBlock_preview.Text = "";
  1634. vm.VideoCurrentTime = 0;
  1635. vm.VideoCurrentTime = i + 1;
  1636. return;
  1637. }
  1638. catch (Exception ex)
  1639. {
  1640. ExLog(ex, "ChangeImageFocal");
  1641. }
  1642. }
  1643. private void ChangeFocalNoVideo(bool isMax)
  1644. {
  1645. try
  1646. {
  1647. int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2;
  1648. int minFocal = -maxFocal;
  1649. int newCurrentFocal = vm.CurrentFocal;
  1650. CC:
  1651. if (isMax) newCurrentFocal++;
  1652. else newCurrentFocal--;
  1653. if (newCurrentFocal < maxFocal) this._bigFocal_Button.IsEnabled = true;
  1654. else this._bigFocal_Button.IsEnabled = false;
  1655. if (newCurrentFocal > minFocal) this._smallFocal_Button.IsEnabled = true;
  1656. else this._smallFocal_Button.IsEnabled = false;
  1657. if (newCurrentFocal < minFocal || newCurrentFocal > maxFocal) return;
  1658. var aa = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == newCurrentFocal);
  1659. if (aa == null) goto CC;
  1660. if (aa.videoPictures == null || !aa.videoPictures.Any())
  1661. {
  1662. aa.videoPictures = vm.detailProvider.GetVideoTimeLineApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal);
  1663. }
  1664. if (aa.videoPictures == null || !aa.videoPictures.Any()) goto CC;
  1665. bool b = false;
  1666. string imageUrl = null;
  1667. foreach (var item in aa.videoPictures)
  1668. {
  1669. if (item.developTime == vm.CurrentPic.developTime)
  1670. {
  1671. b = true;
  1672. imageUrl = item.imageUrl;
  1673. break;
  1674. }
  1675. }
  1676. if (!b) goto CC;
  1677. Task.Run(() =>
  1678. {
  1679. if (string.IsNullOrEmpty(imageUrl)) imageUrl = vm.detailProvider.GetImageUrlApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal, vm.CurrentPic.developTime);
  1680. Dispatcher.Invoke(() =>
  1681. {
  1682. var a = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  1683. if (a != null)
  1684. {
  1685. this.Canvas_preview.Visibility = Visibility.Visible;
  1686. this._preview.Source = a;
  1687. }
  1688. });
  1689. });
  1690. vm.CurrentFocal = newCurrentFocal;
  1691. }
  1692. catch (Exception ex)
  1693. {
  1694. ExLog(ex, "ChangeFocalNoVideo");
  1695. }
  1696. }
  1697. private void SetFocal(int newFocal, int newDevelopTime)
  1698. {
  1699. try
  1700. {
  1701. int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2;
  1702. int minFocal = -maxFocal;
  1703. int newCurrentFocal = newFocal;
  1704. if (newCurrentFocal < maxFocal) this._bigFocal_Button.IsEnabled = true;
  1705. else this._bigFocal_Button.IsEnabled = false;
  1706. if (newCurrentFocal > minFocal) this._smallFocal_Button.IsEnabled = true;
  1707. else this._smallFocal_Button.IsEnabled = false;
  1708. if (newCurrentFocal < minFocal || newCurrentFocal > maxFocal)
  1709. {
  1710. MessageShow($"标记图层{newCurrentFocal}超出范围{minFocal}-{maxFocal}");
  1711. return;
  1712. }
  1713. var aa = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == newCurrentFocal);
  1714. if (aa == null)
  1715. {
  1716. MessageShow($"没有对应图层:{newCurrentFocal}");
  1717. return;
  1718. }
  1719. if (aa.videoPictures == null || !aa.videoPictures.Any())
  1720. {
  1721. aa.videoPictures = vm.detailProvider.GetVideoTimeLineApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal);
  1722. }
  1723. if (aa.videoPictures == null || !aa.videoPictures.Any())
  1724. {
  1725. MessageShow($"目标图层没有图片:{newCurrentFocal}");
  1726. return;
  1727. }
  1728. bool b = false;
  1729. string imageUrl = null;
  1730. foreach (var item in aa.videoPictures)
  1731. {
  1732. if (item.developTime == newDevelopTime)
  1733. {
  1734. b = true;
  1735. imageUrl = item.imageUrl;
  1736. break;
  1737. }
  1738. }
  1739. if (!b)
  1740. {
  1741. MessageShow($"{newCurrentFocal}层没有发育时长为{newDevelopTime}分钟的图片");
  1742. return;
  1743. }
  1744. Task.Run(() =>
  1745. {
  1746. if (string.IsNullOrEmpty(imageUrl)) imageUrl = vm.detailProvider.GetImageUrlApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal, newDevelopTime);
  1747. Dispatcher.Invoke(() =>
  1748. {
  1749. var a = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  1750. if (a != null)
  1751. {
  1752. this.Canvas_preview.Visibility = Visibility.Visible;
  1753. this._preview.Source = a;
  1754. }
  1755. });
  1756. });
  1757. vm.CurrentFocal = newCurrentFocal;
  1758. }
  1759. catch (Exception ex)
  1760. {
  1761. ExLog(ex, "SetFocal");
  1762. }
  1763. }
  1764. #endregion
  1765. #region 视频基础操作
  1766. double newCurrentTime = -1;
  1767. double beilv = 1;
  1768. MediaElement currentMediaElement = null;
  1769. /// <summary>
  1770. /// 定时器
  1771. /// </summary>
  1772. public System.Timers.Timer dispatcherTimer = new System.Timers.Timer();
  1773. /// <summary>
  1774. /// 视频状态
  1775. /// </summary>
  1776. public PlayerStateEnum PlayerState { get; set; } = PlayerStateEnum.Nothing;
  1777. /// <summary>
  1778. /// 播放器事件初始化
  1779. /// </summary>
  1780. public void PlayerEvent(MediaElement mediaElement)
  1781. {
  1782. try
  1783. {
  1784. currentMediaElement = mediaElement;
  1785. currentMediaElement.MediaEnded -= MediaEndedEvent;
  1786. currentMediaElement.MediaOpened -= MediaOpenedEvent;
  1787. currentMediaElement.MediaFailed -= MediaFailedEvent;
  1788. currentMediaElement.MediaEnded += MediaEndedEvent;
  1789. currentMediaElement.MediaOpened += MediaOpenedEvent;
  1790. currentMediaElement.MediaFailed += MediaFailedEvent;
  1791. dispatcherTimer.Interval = 25;
  1792. dispatcherTimer.Elapsed -= dispatcherTimer_Elapsed;
  1793. dispatcherTimer.Elapsed += dispatcherTimer_Elapsed;
  1794. }
  1795. catch (Exception ex)
  1796. {
  1797. ExLog(ex, $"播放器事件初始化");
  1798. }
  1799. }
  1800. /// <summary>
  1801. /// 设置播放源
  1802. /// </summary>
  1803. /// <param name="FileName"></param>
  1804. public bool PlayerSetSource(string FileName)
  1805. {
  1806. try
  1807. {
  1808. PlayerDispose();
  1809. currentMediaElement.LoadedBehavior = MediaState.Manual;
  1810. //指定媒体文件地址
  1811. currentMediaElement.Source = new Uri(FileName, UriKind.RelativeOrAbsolute);
  1812. currentMediaElement.ScrubbingEnabled = true;
  1813. currentMediaElement.SpeedRatio = 1;
  1814. currentMediaElement.Play();
  1815. currentMediaElement.Pause();
  1816. return true;
  1817. }
  1818. catch (Exception ex)
  1819. {
  1820. ExLog(ex, $"设置播放源");
  1821. return false;
  1822. }
  1823. }
  1824. /// <summary>
  1825. /// 播放器加载视频完成事件
  1826. /// </summary>
  1827. /// <param name="sender"></param>
  1828. /// <param name="e"></param>
  1829. private void MediaOpenedEvent(object sender, RoutedEventArgs e)
  1830. {
  1831. try
  1832. {
  1833. //bool isWhile = true;
  1834. //while (isWhile)
  1835. //{
  1836. // isWhile = !(currentMediaElement.DownloadProgress == 1);
  1837. // Thread.Sleep(20);
  1838. //}
  1839. //isWhile = true;
  1840. //while (isWhile)
  1841. //{
  1842. // isWhile = !(currentMediaElement.BufferingProgress == 1);
  1843. // Thread.Sleep(20);
  1844. //}
  1845. currentMediaElement.ScrubbingEnabled = false;
  1846. vm.VideoAllTime = 1;
  1847. vm.VideoCurrentTime = 0;
  1848. if (currentMediaElement.NaturalDuration.HasTimeSpan)
  1849. {
  1850. currentMediaElement.LoadedBehavior = MediaState.Manual;
  1851. PlayerState = PlayerStateEnum.Paused;
  1852. vm.VideoAllTime = currentMediaElement.NaturalDuration.TimeSpan.TotalMilliseconds;
  1853. currentMediaElement.ScrubbingEnabled = true;
  1854. currentMediaElement.Play();
  1855. currentMediaElement.Pause();
  1856. if (newCurrentTime != -1)
  1857. {
  1858. if (newCurrentTime < 0) newCurrentTime = 0;
  1859. if (newCurrentTime > vm.VideoAllTime) newCurrentTime = vm.VideoAllTime;
  1860. SetTimeProgressbarProgressValue(newCurrentTime);
  1861. SetPlayerPosition(vm.VideoCurrentTime);
  1862. newCurrentTime = -1;
  1863. }
  1864. else
  1865. {
  1866. SetTimeProgressbarProgressValue(vm.VideoAllTime);
  1867. SetPlayerPosition(vm.VideoCurrentTime);
  1868. }
  1869. SetVideoButtonState(true);
  1870. }
  1871. else
  1872. {
  1873. PlayerState = PlayerStateEnum.Nothing;
  1874. }
  1875. }
  1876. catch (Exception ex)
  1877. {
  1878. PlayerState = PlayerStateEnum.Error;
  1879. ExLog(ex, $"播放器加载视频完成事件");
  1880. }
  1881. }
  1882. /// <summary>
  1883. /// 播放完成事件
  1884. /// </summary>
  1885. /// <param name="sender"></param>
  1886. /// <param name="e"></param>
  1887. private void MediaEndedEvent(object sender, RoutedEventArgs e)
  1888. {
  1889. try
  1890. {
  1891. PlayerState = PlayerStateEnum.Paused;
  1892. dispatcherTimer_Stop();
  1893. //currentMediaElement.Stop();
  1894. currentMediaElement.Play();
  1895. currentMediaElement.Pause();
  1896. SetTimeProgressbarProgressValue(vm.VideoAllTime);
  1897. SetPlayerPosition(vm.VideoAllTime);
  1898. SetPlayButton(false);
  1899. }
  1900. catch (Exception ex)
  1901. {
  1902. ExLog(ex, $"播放完成事件");
  1903. }
  1904. }
  1905. /// <summary>
  1906. /// 播放器错误事件
  1907. /// </summary>
  1908. /// <param name="sender"></param>
  1909. /// <param name="e"></param>
  1910. /// <exception cref="NotImplementedException"></exception>
  1911. private void MediaFailedEvent(object? sender, ExceptionRoutedEventArgs e)
  1912. {
  1913. try
  1914. {
  1915. PlayerState = PlayerStateEnum.Error;
  1916. vm.VideoAllTime = 1;
  1917. vm.VideoCurrentTime = 0;
  1918. SetPlayButton(false);
  1919. string ss = "";
  1920. MediaElement med = sender as MediaElement;
  1921. if (med != null)
  1922. {
  1923. ss = med.Source.ToString();
  1924. ErrorLog($"{ss},视频遇到错误", LogEnum.RunError);
  1925. }
  1926. dispatcherTimer_Stop();
  1927. ExLog(e.ErrorException, $"MediaFailedEvent:{ss}");
  1928. }
  1929. catch (Exception ex)
  1930. {
  1931. ExLog(ex, $"播放器错误事件");
  1932. }
  1933. }
  1934. /// <summary>
  1935. /// 播放按钮图标设置
  1936. /// </summary>
  1937. private void SetPlayButton(bool isPlaying)
  1938. {
  1939. if (isPlaying)//正在播放,设置为暂停按钮
  1940. {
  1941. this._playButton.IconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailPauseVideoButtonIcon.png", UriKind.Absolute));
  1942. this._playButton.MouseOverIconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailPauseVideoButtonMouseIcon.png", UriKind.Absolute));
  1943. }
  1944. else//未播放,设置为播放按钮
  1945. {
  1946. this._playButton.IconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailStartVideoButtonIcon.png", UriKind.Absolute));
  1947. this._playButton.MouseOverIconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailStartVideoButtonMouseIcon.png", UriKind.Absolute));
  1948. }
  1949. }
  1950. /// <summary>
  1951. /// 定时器事件
  1952. /// </summary>
  1953. /// <param name="sender"></param>
  1954. /// <param name="e"></param>
  1955. private void dispatcherTimer_Elapsed(object? sender, ElapsedEventArgs e)
  1956. {
  1957. try
  1958. {
  1959. Dispatcher.Invoke(() =>
  1960. {
  1961. SetTimeProgressbarProgressValue(currentMediaElement.Position.TotalMilliseconds);
  1962. });
  1963. if (PlayerState != PlayerStateEnum.Playing)
  1964. {
  1965. dispatcherTimer_Stop();
  1966. }
  1967. }
  1968. catch (Exception ex)
  1969. {
  1970. ExLog(ex, $"定时器事件");
  1971. }
  1972. }
  1973. /// <summary>
  1974. /// 停止定时器
  1975. /// </summary>
  1976. public void dispatcherTimer_Stop()
  1977. {
  1978. try
  1979. {
  1980. if (dispatcherTimer.Enabled)
  1981. {
  1982. dispatcherTimer.Enabled = false;
  1983. dispatcherTimer.Stop();
  1984. }
  1985. }
  1986. catch (Exception ex)
  1987. {
  1988. ExLog(ex, $"停止定时器");
  1989. }
  1990. }
  1991. /// <summary>
  1992. ///设置视频进度
  1993. /// </summary>
  1994. /// <param name="progressValue"></param>
  1995. public void SetPlayerPosition(double currentTime)
  1996. {
  1997. try
  1998. {
  1999. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  2000. {
  2001. currentMediaElement.Position = TimeSpan.FromMilliseconds(currentTime);
  2002. }
  2003. }
  2004. catch (Exception ex)
  2005. {
  2006. ExLog(ex, $"进度条变换以后设置视频进度");
  2007. }
  2008. }
  2009. /// <summary>
  2010. /// 设置进度条
  2011. /// </summary>
  2012. public void SetTimeProgressbarProgressValue(double newTime)
  2013. {
  2014. try
  2015. {
  2016. vm.VideoCurrentTime = newTime;
  2017. }
  2018. catch (Exception ex)
  2019. {
  2020. ExLog(ex, $"视频进度变换以后设置进度条");
  2021. }
  2022. }
  2023. /// <summary>
  2024. /// 释放播放器
  2025. /// </summary>
  2026. public void PlayerDispose()
  2027. {
  2028. try
  2029. {
  2030. dispatcherTimer_Stop();
  2031. if (PlayerState != PlayerStateEnum.Nothing)
  2032. {
  2033. currentMediaElement.LoadedBehavior = MediaState.Close;
  2034. PlayerState = PlayerStateEnum.Nothing;
  2035. }
  2036. }
  2037. catch (Exception ex)
  2038. {
  2039. ExLog(ex, $"释放播放器");
  2040. }
  2041. }
  2042. /// <summary>
  2043. /// 设置倍率
  2044. /// </summary>
  2045. /// <param name="newSpeedRatio"></param>
  2046. public void PlayerSetSpeedRatio(double newSpeedRatio)
  2047. {
  2048. try
  2049. {
  2050. beilv = newSpeedRatio;
  2051. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  2052. {
  2053. currentMediaElement.LoadedBehavior = MediaState.Manual;
  2054. currentMediaElement.SpeedRatio = newSpeedRatio;
  2055. }
  2056. }
  2057. catch (Exception ex)
  2058. {
  2059. ExLog(ex, $"设置倍率");
  2060. }
  2061. }
  2062. /// <summary>
  2063. /// 播放操作
  2064. /// </summary>
  2065. public bool PlayerPlay()
  2066. {
  2067. try
  2068. {
  2069. bool isPlay = false;
  2070. switch (PlayerState)
  2071. {
  2072. case PlayerStateEnum.Error:
  2073. break;
  2074. case PlayerStateEnum.Nothing:
  2075. break;
  2076. case PlayerStateEnum.Opened:
  2077. isPlay = true;
  2078. break;
  2079. case PlayerStateEnum.Paused:
  2080. isPlay = true;
  2081. break;
  2082. case PlayerStateEnum.Playing:
  2083. break;
  2084. case PlayerStateEnum.Stopped:
  2085. currentMediaElement.Stop();
  2086. isPlay = true;
  2087. break;
  2088. }
  2089. if (isPlay)
  2090. {
  2091. PlayerState = PlayerStateEnum.Playing;
  2092. if (vm.VideoCurrentTime == vm.VideoAllTime)
  2093. {
  2094. SetPlayerPosition(0);
  2095. }
  2096. if (!dispatcherTimer.Enabled)
  2097. {
  2098. dispatcherTimer.Start();
  2099. }
  2100. PlayerSetSpeedRatio(beilv);
  2101. currentMediaElement.Play();
  2102. SetPlayButton(true);
  2103. return true;
  2104. }
  2105. return false;
  2106. }
  2107. catch (Exception ex)
  2108. {
  2109. ExLog(ex, $"播放操作");
  2110. return false;
  2111. }
  2112. }
  2113. /// <summary>
  2114. /// 暂停操作
  2115. /// </summary>
  2116. /// <param name="isSetState"></param>
  2117. public bool PlayerPause()
  2118. {
  2119. try
  2120. {
  2121. bool isPause = false;
  2122. switch (PlayerState)
  2123. {
  2124. case PlayerStateEnum.Error:
  2125. break;
  2126. case PlayerStateEnum.Nothing:
  2127. break;
  2128. case PlayerStateEnum.Opened:
  2129. break;
  2130. case PlayerStateEnum.Paused:
  2131. break;
  2132. case PlayerStateEnum.Playing:
  2133. isPause = true;
  2134. break;
  2135. case PlayerStateEnum.Stopped:
  2136. break;
  2137. }
  2138. if (isPause)
  2139. {
  2140. PlayerState = PlayerStateEnum.Paused;
  2141. currentMediaElement.Pause();
  2142. dispatcherTimer_Stop();
  2143. SetPlayButton(false);
  2144. return true;
  2145. }
  2146. return false;
  2147. }
  2148. catch (Exception ex)
  2149. {
  2150. ExLog(ex, $"暂停操作");
  2151. return false;
  2152. }
  2153. }
  2154. /// <summary>
  2155. /// 上一帧
  2156. /// </summary>
  2157. public void PlayerLastFrame(int zhenshu)
  2158. {
  2159. try
  2160. {
  2161. bool isOK = false;
  2162. bool isStop = false;
  2163. switch (PlayerState)
  2164. {
  2165. case PlayerStateEnum.Error:
  2166. break;
  2167. case PlayerStateEnum.Nothing:
  2168. break;
  2169. case PlayerStateEnum.Opened:
  2170. isOK = true;
  2171. break;
  2172. case PlayerStateEnum.Paused:
  2173. isOK = true;
  2174. break;
  2175. case PlayerStateEnum.Playing:
  2176. break;
  2177. case PlayerStateEnum.Stopped:
  2178. isOK = true;
  2179. break;
  2180. }
  2181. if (isOK)
  2182. {
  2183. var zhen = (1000d / zhenshu);
  2184. var currentPositionTime = currentMediaElement.Position.TotalMilliseconds;
  2185. if (currentPositionTime == 0)
  2186. {
  2187. return;
  2188. }
  2189. if (currentPositionTime < zhen)
  2190. {
  2191. SetPlayerPosition(0);
  2192. SetTimeProgressbarProgressValue(0);
  2193. return;
  2194. }
  2195. var c = currentPositionTime - zhen;
  2196. SetPlayerPosition(c);
  2197. SetTimeProgressbarProgressValue(c);
  2198. return;
  2199. }
  2200. else
  2201. {
  2202. }
  2203. }
  2204. catch (Exception ex)
  2205. {
  2206. ExLog(ex, $"上一帧");
  2207. }
  2208. }
  2209. /// <summary>
  2210. /// 下一帧
  2211. /// </summary>
  2212. public void PlayerNextFrame(int zhenshu)
  2213. {
  2214. try
  2215. {
  2216. bool isOK = false;
  2217. bool isStop = false;
  2218. switch (PlayerState)
  2219. {
  2220. case PlayerStateEnum.Error:
  2221. break;
  2222. case PlayerStateEnum.Nothing:
  2223. break;
  2224. case PlayerStateEnum.Opened:
  2225. isOK = true;
  2226. break;
  2227. case PlayerStateEnum.Paused:
  2228. isOK = true;
  2229. break;
  2230. case PlayerStateEnum.Playing:
  2231. break;
  2232. case PlayerStateEnum.Stopped:
  2233. isOK = true;
  2234. break;
  2235. }
  2236. if (isOK)
  2237. {
  2238. var newpos = currentMediaElement.Position.TotalMilliseconds + (1000d / zhenshu);
  2239. if (newpos > vm.VideoAllTime)
  2240. {
  2241. newpos = vm.VideoAllTime;
  2242. }
  2243. SetPlayerPosition(newpos);
  2244. SetTimeProgressbarProgressValue(newpos);
  2245. return;
  2246. }
  2247. else
  2248. {
  2249. }
  2250. if (isStop)
  2251. {
  2252. return;
  2253. }
  2254. }
  2255. catch (Exception ex)
  2256. {
  2257. ExLog(ex, $"下一帧");
  2258. }
  2259. }
  2260. private void Canvas_MouseDown(object sender, MouseButtonEventArgs e)
  2261. {
  2262. if (vm == null) return;
  2263. if (!(sender is Canvas canvas)) return;
  2264. if (!(canvas.Tag is MarkEntity value)) return;
  2265. if (value.maxTime != 0)
  2266. {
  2267. QuickButton_Click(value.maxTime, value.maxTime, value.name);
  2268. if (value.pictureLayer != vm.CurrentFocal) SetFocal(value.pictureLayer, value.maxTime);
  2269. }
  2270. }
  2271. private void SetVideoButtonState(bool IsEnabledVideo)
  2272. {
  2273. Task.Run(() =>
  2274. {
  2275. Dispatcher.Invoke(() =>
  2276. {
  2277. this._lastButton.IsEnabled = IsEnabledVideo;
  2278. this._playButton.IsEnabled = IsEnabledVideo;
  2279. this._nextButton.IsEnabled = IsEnabledVideo;
  2280. });
  2281. });
  2282. }
  2283. #endregion
  2284. }
  2285. }