DetailPageView.xaml.cs 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215
  1. using ivf_tl_Entity.GlobalEntitys;
  2. using ivf_tl_Entity.GlobalEnums;
  3. using ivf_tl_Operate.Converts;
  4. using ivf_tl_Operate.CustomUserControls;
  5. using ivf_tl_Operate.ViewModel;
  6. using ivf_tl_Operate.Windows;
  7. using Newtonsoft.Json;
  8. using System;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using System.Diagnostics;
  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.Animation;
  24. using System.Windows.Media.Imaging;
  25. using System.Windows.Navigation;
  26. using System.Windows.Shapes;
  27. using static System.Net.Mime.MediaTypeNames;
  28. namespace ivf_tl_Operate.View
  29. {
  30. /// <summary>
  31. /// DetailPageView.xaml 的交互逻辑
  32. /// </summary>
  33. public partial class DetailPageView : UserControl
  34. {
  35. DetailPageViewModel vm;
  36. string CleanVideoString { get; set; } = "-";
  37. private double newCurrentTime = -1;
  38. double beilv { get; set; } = 1;
  39. public DetailPageView()
  40. {
  41. InitializeComponent();
  42. Loaded += DetailPageView_Loaded;
  43. Unloaded += DetailPageView_Unloaded;
  44. }
  45. private void DetailPageView_Unloaded(object sender, RoutedEventArgs e)
  46. {
  47. this.Grid_Root.Children.Clear();
  48. if (vm != null) vm = null;
  49. this.DataContext = null;
  50. }
  51. int NoMarkTime = 48;
  52. private void DetailPageView_Loaded(object sender, RoutedEventArgs e)
  53. {
  54. var TLSettingModel = AppData.Instance.HttpHelper.SettingSystemApi(AppData.Instance.TlSn);
  55. if(TLSettingModel!=null) NoMarkTime = TLSettingModel.operableEmbryoTime * 24;
  56. vm = (DetailPageViewModel)this.DataContext;
  57. if (vm == null) return;
  58. if (vm.ExDish != null && vm.ExDish.id > 0)
  59. {
  60. if (vm.ExDish.state == 0 && !string.IsNullOrEmpty(vm.ExDish.endTime) && DateTime.TryParse(vm.ExDish.endTime, out DateTime endtime))
  61. {
  62. var cultivateDuration = DateTime.Now.Subtract(endtime);
  63. if (cultivateDuration.TotalHours > NoMarkTime)
  64. {
  65. disableButton(false);
  66. }
  67. else
  68. {
  69. disableButton(true);
  70. }
  71. this.Button_js.IsEnabled = false;
  72. }
  73. else
  74. {
  75. disableButton(true);
  76. this.Button_js.IsEnabled = true;
  77. }
  78. }
  79. else
  80. {
  81. disableButton(true);
  82. this.Button_js.IsEnabled = true;
  83. }
  84. Task.Run(() =>
  85. {
  86. vm.Init();
  87. if (vm == null) return;
  88. Dispatcher.InvokeAsync(() =>
  89. {
  90. _dishInfo.SetEmbryoPic(vm.DishPicAndVideoList);
  91. PlayerEvent(this._dishInfo.mediaElementPlayer);
  92. ChangeEmbryo(1);
  93. });
  94. InitAlarm();
  95. while (true)
  96. {
  97. Thread.Sleep(10000);
  98. //Thread.Sleep(3000);
  99. if (vm == null || vm.ExDish == null) return;
  100. //foreach (var item in vm.ExDish.embryoList)
  101. //{
  102. // if (item.alarm == 0)
  103. // {
  104. // item.alarm = 1;
  105. // }
  106. // else
  107. // {
  108. // item.alarm = 0;
  109. // }
  110. //}
  111. InitAlarm();
  112. }
  113. });
  114. }
  115. private void InitAlarm()
  116. {
  117. if (vm == null || vm.ExDish == null) return;
  118. HouseCropAlarmResponse houseCropAlarmResponse = new HouseCropAlarmResponse();
  119. HouseCropAlarmResult CurrentHouseCropAlarmResult;
  120. houseCropAlarmResponse.tlSn = AppData.Instance.TlSn;
  121. if (!houseCropAlarmResponse.houseList.Any())
  122. {
  123. houseCropAlarmResponse.houseList.Add(new HouseCropAlarmHouseResponse
  124. {
  125. houseSn = vm.ExDish.houseSn,
  126. startTime = vm.ExDish.startTime,
  127. });
  128. }
  129. CurrentHouseCropAlarmResult = AppData.Instance.HttpHelper.GetHouseCropAlarmApi(houseCropAlarmResponse).FirstOrDefault(x => x.houseSn == vm.ExDish.houseSn);
  130. foreach (var item in vm.ExDish.embryoList)
  131. {
  132. if (CurrentHouseCropAlarmResult == null)
  133. {
  134. item.alarm = 0;
  135. continue;
  136. }
  137. if (CurrentHouseCropAlarmResult.wellSn.Contains(item.wellSn))
  138. {
  139. item.alarm = 1;
  140. }
  141. else
  142. {
  143. item.alarm = 0;
  144. }
  145. }
  146. }
  147. public void disableButton(bool disable)
  148. {
  149. this.Button_yz.IsEnabled = disable;
  150. this.Button_ld.IsEnabled = disable;
  151. this.Button_sc.IsEnabled = disable;
  152. this.Button_zf.IsEnabled = disable;
  153. }
  154. private void ExLog(Exception ex, string name)
  155. {
  156. AppData.Instance.LogHelper.ExceptionLog(ex, $"DetailPageView.{name}", LogEnum.RunException);
  157. }
  158. private void ErrorLog(string mess, LogEnum logEnum)
  159. {
  160. AppData.Instance.LogHelper.TLLog($"DetailPageView.{mess}", logEnum);
  161. }
  162. public void ShowMessage(string mess)
  163. {
  164. new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, mess);
  165. }
  166. private void WellChangeEvent(int obj)
  167. {
  168. PlayerPause();
  169. ChangeEmbryo(obj);
  170. }
  171. public void ChangeEmbryo(int well)
  172. {
  173. try
  174. {
  175. PlayerDispose();
  176. if (vm == null) return;
  177. vm.CurrentEmbryo = null;
  178. vm.CurrentWellDishPicAndVideo = null;
  179. vm.CurrentWellLayerPicAndVideo = null;
  180. vm.CurrentPic = null;
  181. SetVideoButtonState(false);
  182. vm.CurrentFocal = 0;
  183. BigFocusIsEnabled(true);
  184. SmallFocusIsEnabled(true);
  185. if (vm.ExDish != null && vm.ExDish.id > 0) vm.CurrentEmbryo = vm.ExDish.embryoList.FirstOrDefault(x => x.wellSn == well);
  186. if (vm.CurrentEmbryo == null)
  187. {
  188. vm.VideoAllTime = 1;
  189. vm.VideoCurrentTime = 0;
  190. }
  191. if (vm.CurrentEmbryo != null) vm.CurrentWellDishPicAndVideo = vm.DishPicAndVideoList.FirstOrDefault(x => x.wellSn == vm.CurrentEmbryo.wellSn);
  192. if (vm.CurrentWellDishPicAndVideo != null) vm.CurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == 0);
  193. this._dishInfo.SetPreview(vm.CurrentWellDishPicAndVideo);
  194. if (vm.MaxTotalLayer == -1) if (vm.CurrentWellLayerPicAndVideo != null) vm.MaxTotalLayer = vm.CurrentWellLayerPicAndVideo.videoPictures.Max(x => x.totalLayer);
  195. SetVideo(vm.CurrentFocal, true);
  196. if (vm.CurrentWellLayerPicAndVideo != null && vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
  197. {
  198. BigFocusIsEnabled(true);
  199. SmallFocusIsEnabled(true);
  200. if (string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) || vm.CurrentWellLayerPicAndVideo.videoUrl == CleanVideoString)
  201. {
  202. vm.VideoAllTime = 1;
  203. vm.VideoCurrentTime = 0;
  204. vm.VideoAllTime = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
  205. vm.VideoCurrentTime = vm.VideoAllTime;
  206. }
  207. }
  208. else
  209. {
  210. BigFocusIsEnabled(false);
  211. SmallFocusIsEnabled(false);
  212. }
  213. }
  214. catch (Exception ex)
  215. {
  216. ExLog(ex, "ChangeEmbryo");
  217. }
  218. }
  219. private void LastEmbryo_Click(object sender, RoutedEventArgs e)
  220. {
  221. if (!this._dishInfo.IsLoaded) return;
  222. this._dishInfo.LastEmbryo();
  223. }
  224. private void NextEmbryo_Click(object sender, RoutedEventArgs e)
  225. {
  226. if (!this._dishInfo.IsLoaded) return;
  227. this._dishInfo.NextEmbryo();
  228. }
  229. /// <summary>
  230. /// 返回按钮
  231. /// </summary>
  232. /// <param name="sender"></param>
  233. /// <param name="e"></param>
  234. private void Return_Click(object sender, RoutedEventArgs e)
  235. {
  236. PlayerPause();
  237. PlayerDispose();
  238. if (vm != null && vm.ParentViewModel != null)
  239. {
  240. DishRecordView dishRecordView = new DishRecordView()
  241. {
  242. DataContext = vm.ParentViewModel,
  243. };
  244. AppData.Instance.MainWindow.LoadPage(dishRecordView);
  245. return;
  246. }
  247. AppData.Instance.BackMainPage();
  248. }
  249. #region 标记菜单
  250. //string s1 = "Whether or not to";
  251. //string s2 = "embryo No.";
  252. //string s3 = "Whether or not to cancel the";
  253. //string s4 = "mark of embryo No.";
  254. //string s5 = "Embryo No.";
  255. //string s6 = "has been";
  256. string s1 = KeyToStringConvert.GetLanguageStringByKey("C0307");
  257. string s2 = KeyToStringConvert.GetLanguageStringByKey("C0308");
  258. string s3 = KeyToStringConvert.GetLanguageStringByKey("C0309");
  259. string s4 = KeyToStringConvert.GetLanguageStringByKey("C0310");
  260. string s5 = KeyToStringConvert.GetLanguageStringByKey("C0311");
  261. string s6 = KeyToStringConvert.GetLanguageStringByKey("C0312");
  262. string spaceString = KeyToStringConvert.GetLanguageStringByKey("C0328");
  263. string haoString = KeyToStringConvert.GetLanguageStringByKey("C0327");
  264. /// <summary>
  265. /// 移植按钮
  266. /// </summary>
  267. /// <param name="sender"></param>
  268. /// <param name="e"></param>
  269. private void EmbryoMove_Click(object sender, RoutedEventArgs e)
  270. {
  271. PlayerPause();
  272. if (vm.CurrentEmbryo == null) return;
  273. string tag = KeyToStringConvert.GetLanguageStringByKey("C0136");
  274. string messInfo = GetMessageInfo(tag);
  275. int stateTag = 1;
  276. if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  277. {
  278. tag = "完成";
  279. switch (vm.CurrentEmbryo.state)
  280. {
  281. case (int)EmbryoState.Freezing:
  282. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0135"));
  283. stateTag = 2;
  284. break;
  285. case (int)EmbryoState.Transplant:
  286. messInfo = GetCancelMarkMessage();
  287. tag = "取消";
  288. break;
  289. case (int)EmbryoState.Cancellation:
  290. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0138"));
  291. stateTag = 4;
  292. break;
  293. case (int)EmbryoState.Delete:
  294. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0137"));
  295. stateTag = 3;
  296. break;
  297. }
  298. }
  299. EmbryoOp(tag, messInfo, stateTag);
  300. return;
  301. }
  302. //private void EmbryoMove_Click(object sender, RoutedEventArgs e)
  303. //{
  304. // PlayerPause();
  305. // if (vm.CurrentEmbryo == null) return;
  306. // string tag = "移植";
  307. // string messInfo = $"是否确定对{vm.CurrentEmbryo.wellSn}号胚胎进行移植?";
  308. // if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  309. // {
  310. // tag = "完成";
  311. // switch (vm.CurrentEmbryo.state)
  312. // {
  313. // case (int)EmbryoState.Freezing:
  314. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已冷冻";
  315. // break;
  316. // case (int)EmbryoState.Transplant:
  317. // messInfo = $"是否取消{vm.CurrentEmbryo.wellSn}号胚胎的移植标记";
  318. // tag = "取消";
  319. // break;
  320. // case (int)EmbryoState.Cancellation:
  321. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已作废";
  322. // break;
  323. // case (int)EmbryoState.Delete:
  324. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已删除";
  325. // break;
  326. // }
  327. // }
  328. // EmbryoOp(tag, messInfo);
  329. // return;
  330. //}
  331. /// <summary>
  332. /// 冷冻按钮
  333. /// </summary>
  334. /// <param name="sender"></param>
  335. /// <param name="e"></param>
  336. private void EmbryoFree_Click(object sender, RoutedEventArgs e)
  337. {
  338. PlayerPause();
  339. if (vm.CurrentEmbryo == null) return;
  340. string tag = KeyToStringConvert.GetLanguageStringByKey("C0135");
  341. string messInfo = GetMessageInfo(tag);
  342. int stateTag = 2;
  343. if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  344. {
  345. tag = "完成";
  346. switch (vm.CurrentEmbryo.state)
  347. {
  348. case (int)EmbryoState.Transplant:
  349. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0136"));
  350. stateTag = 1;
  351. break;
  352. case (int)EmbryoState.Freezing:
  353. messInfo = GetCancelMarkMessage();
  354. tag = "取消";
  355. break;
  356. case (int)EmbryoState.Cancellation:
  357. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0138"));
  358. stateTag = 4;
  359. break;
  360. case (int)EmbryoState.Delete:
  361. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0137"));
  362. stateTag = 3;
  363. break;
  364. }
  365. }
  366. EmbryoOp(tag, messInfo, stateTag);
  367. return;
  368. }
  369. //private void EmbryoFree_Click(object sender, RoutedEventArgs e)
  370. //{
  371. // PlayerPause();
  372. // if (vm.CurrentEmbryo == null) return;
  373. // string tag = "冷冻";
  374. // string messInfo = $"是否确定对{vm.CurrentEmbryo.wellSn}号胚胎进行冷冻?";
  375. // if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  376. // {
  377. // tag = "完成";
  378. // switch (vm.CurrentEmbryo.state)
  379. // {
  380. // case (int)EmbryoState.Transplant:
  381. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已移植";
  382. // break;
  383. // case (int)EmbryoState.Freezing:
  384. // messInfo = $"是否取消{vm.CurrentEmbryo.wellSn}号胚胎的冷冻标记";
  385. // tag = "取消";
  386. // break;
  387. // case (int)EmbryoState.Cancellation:
  388. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已作废";
  389. // break;
  390. // case (int)EmbryoState.Delete:
  391. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已删除";
  392. // break;
  393. // }
  394. // }
  395. // EmbryoOp(tag, messInfo);
  396. // return;
  397. //}
  398. /// <summary>
  399. /// 删除按钮
  400. /// </summary>
  401. /// <param name="sender"></param>
  402. /// <param name="e"></param>
  403. private void EmbryoDel_Click(object sender, RoutedEventArgs e)
  404. {
  405. PlayerPause();
  406. if (vm.CurrentEmbryo == null) return;
  407. string tag = KeyToStringConvert.GetLanguageStringByKey("C0137");
  408. string messInfo = GetMessageInfo(tag);
  409. int stateTag = 3;
  410. if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  411. {
  412. tag = "完成";
  413. switch (vm.CurrentEmbryo.state)
  414. {
  415. case (int)EmbryoState.Transplant:
  416. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0136"));
  417. stateTag = 1;
  418. break;
  419. case (int)EmbryoState.Freezing:
  420. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0135"));
  421. stateTag = 2;
  422. break;
  423. case (int)EmbryoState.Cancellation:
  424. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0138"));
  425. stateTag = 4;
  426. break;
  427. case (int)EmbryoState.Delete:
  428. messInfo = GetCancelMarkMessage();
  429. tag = "取消";
  430. break;
  431. }
  432. }
  433. EmbryoOp(tag, messInfo, stateTag);
  434. return;
  435. }
  436. //private void EmbryoDel_Click(object sender, RoutedEventArgs e)
  437. //{
  438. // PlayerPause();
  439. // if (vm.CurrentEmbryo == null) return;
  440. // string tag = "删除";
  441. // string messInfo = $"是否确定对{vm.CurrentEmbryo.wellSn}号胚胎进行删除?";
  442. // if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  443. // {
  444. // tag = "完成";
  445. // switch (vm.CurrentEmbryo.state)
  446. // {
  447. // case (int)EmbryoState.Transplant:
  448. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已移植";
  449. // break;
  450. // case (int)EmbryoState.Freezing:
  451. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已冷冻";
  452. // break;
  453. // case (int)EmbryoState.Cancellation:
  454. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已作废";
  455. // break;
  456. // case (int)EmbryoState.Delete:
  457. // messInfo = $"是否取消{vm.CurrentEmbryo.wellSn}号胚胎的删除标记";
  458. // tag = "取消";
  459. // break;
  460. // }
  461. // }
  462. // EmbryoOp(tag, messInfo);
  463. // return;
  464. //}
  465. /// <summary>
  466. /// 作废按钮
  467. /// </summary>
  468. /// <param name="sender"></param>
  469. /// <param name="e"></param>
  470. private void EmbryoInv_Click(object sender, RoutedEventArgs e)
  471. {
  472. PlayerPause();
  473. if (vm.CurrentEmbryo == null) return;
  474. string tag = KeyToStringConvert.GetLanguageStringByKey("C0138");
  475. string messInfo = GetMessageInfo(tag);
  476. int stateTag = 4;
  477. if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  478. {
  479. tag = "完成";
  480. switch (vm.CurrentEmbryo.state)
  481. {
  482. case (int)EmbryoState.Transplant:
  483. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0136"));
  484. stateTag = 1;
  485. break;
  486. case (int)EmbryoState.Freezing:
  487. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0135"));
  488. stateTag = 2;
  489. break;
  490. case (int)EmbryoState.Cancellation:
  491. messInfo = GetCancelMarkMessage();
  492. tag = "取消";
  493. break;
  494. case (int)EmbryoState.Delete:
  495. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0137"));
  496. stateTag = 3;
  497. break;
  498. }
  499. }
  500. EmbryoOp(tag, messInfo, stateTag);
  501. return;
  502. }
  503. //private void EmbryoInv_Click(object sender, RoutedEventArgs e)
  504. //{
  505. // PlayerPause();
  506. // if (vm.CurrentEmbryo == null) return;
  507. // string tag = "作废";
  508. // string messInfo = $"是否确定对{vm.CurrentEmbryo.wellSn}号胚胎进行作废?";
  509. // if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  510. // {
  511. // tag = "完成";
  512. // switch (vm.CurrentEmbryo.state)
  513. // {
  514. // case (int)EmbryoState.Transplant:
  515. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已移植";
  516. // break;
  517. // case (int)EmbryoState.Freezing:
  518. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已冷冻";
  519. // break;
  520. // case (int)EmbryoState.Cancellation:
  521. // messInfo = $"是否取消{vm.CurrentEmbryo.wellSn}号胚胎的作废标记";
  522. // tag = "取消";
  523. // break;
  524. // case (int)EmbryoState.Delete:
  525. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已删除";
  526. // break;
  527. // }
  528. // }
  529. // EmbryoOp(tag, messInfo);
  530. // return;
  531. //}
  532. /// <summary>
  533. /// 结束按钮
  534. /// </summary>
  535. /// <param name="sender"></param>
  536. /// <param name="e"></param>
  537. private void EmbryoOver_Click(object sender, RoutedEventArgs e)
  538. {
  539. try
  540. {
  541. PlayerPause();
  542. if (vm.ExDish == null || vm.ExDish.id == 0) return;
  543. string tag = KeyToStringConvert.GetLanguageStringByKey("C0313");
  544. string messInfo = KeyToStringConvert.GetLanguageStringByKey("C0314");
  545. if (vm.ExDish.state == 0)
  546. {
  547. messInfo = KeyToStringConvert.GetLanguageStringByKey("C0315");
  548. tag = "完成";
  549. }
  550. EmbryoOp(tag, messInfo, 5);
  551. return;
  552. }
  553. catch (Exception ex)
  554. {
  555. ExLog(ex, "EmbryoOver_Click");
  556. }
  557. //try
  558. //{
  559. // PlayerPause();
  560. // if (vm.ExDish == null || vm.ExDish.id == 0) return;
  561. // string tag = "结束";
  562. // string messInfo = $"是否结束培养所有胚胎?";
  563. // if (vm.ExDish.state == 0)
  564. // {
  565. // messInfo = "当前舱室已结束培养";
  566. // tag = "完成";
  567. // }
  568. // EmbryoOp(tag, messInfo,5);
  569. // return;
  570. //}
  571. //catch (Exception ex)
  572. //{
  573. // ExLog(ex, "EmbryoOver_Click");
  574. //}
  575. }
  576. /// <summary>
  577. /// 胚胎操作
  578. /// </summary>
  579. private void EmbryoOp(string tag, string infoString, int opType)
  580. {
  581. if (tag == "完成")
  582. {
  583. switch (opType)
  584. {
  585. case 1:
  586. tag = KeyToStringConvert.GetLanguageStringByKey("C0136");
  587. break;
  588. case 2:
  589. tag = KeyToStringConvert.GetLanguageStringByKey("C0135");
  590. break;
  591. case 3:
  592. tag = KeyToStringConvert.GetLanguageStringByKey("C0137");
  593. break;
  594. case 4:
  595. tag = KeyToStringConvert.GetLanguageStringByKey("C0138");
  596. break;
  597. }
  598. new MessageWindow(AppData.Instance.MainWindow, infoString, tag).ShowDialog();
  599. //new MessageWindow(AppData.Instance.MainWindow, infoString, KeyToStringConvert.GetLanguageStringByKey("C0171")).ShowDialog();
  600. return;
  601. }
  602. if (tag == "取消")
  603. {
  604. switch (opType)
  605. {
  606. case 1:
  607. tag = KeyToStringConvert.GetLanguageStringByKey("C0136");
  608. break;
  609. case 2:
  610. tag = KeyToStringConvert.GetLanguageStringByKey("C0135");
  611. break;
  612. case 3:
  613. tag = KeyToStringConvert.GetLanguageStringByKey("C0137");
  614. break;
  615. case 4:
  616. tag = KeyToStringConvert.GetLanguageStringByKey("C0138");
  617. break;
  618. }
  619. //tag = KeyToStringConvert.GetLanguageStringByKey("C0031");
  620. opType = 6;
  621. }
  622. if (tag == "结束")
  623. {
  624. tag = KeyToStringConvert.GetLanguageStringByKey("C0313");
  625. }
  626. // case "取消": EmbryoMark((int)EmbryoState.None); break;
  627. var rs = new MessageWindow(AppData.Instance.MainWindow, infoString, tag).ShowDialog();
  628. if (rs == true)
  629. {
  630. switch (opType)
  631. {
  632. case 2:
  633. EmbryoMark((int)EmbryoState.Freezing);
  634. break;
  635. case 4:
  636. EmbryoMark((int)EmbryoState.Cancellation);
  637. break;
  638. case 1:
  639. EmbryoMark((int)EmbryoState.Transplant);
  640. break;
  641. case 3:
  642. EmbryoMark((int)EmbryoState.Delete);
  643. break;
  644. case 5:
  645. Finish();
  646. break;
  647. case 6:
  648. EmbryoMark((int)EmbryoState.None);
  649. break;
  650. default:
  651. break;
  652. }
  653. }
  654. }
  655. //private void EmbryoOp(string tag, string infoString,int opType)
  656. //{
  657. // if (tag == "完成")
  658. // {
  659. // //new MessageWindow(AppData.Instance.MainWindow, infoString, "消息提示").ShowDialog();
  660. // new MessageWindow(AppData.Instance.MainWindow, infoString, KeyToStringConvert.GetLanguageStringByKey("C0171")).ShowDialog();
  661. // return;
  662. // }
  663. // var rs = new MessageWindow(AppData.Instance.MainWindow, infoString, tag).ShowDialog();
  664. // if (rs == true)
  665. // {
  666. // switch (tag)
  667. // {
  668. // case "冷冻":
  669. // EmbryoMark((int)EmbryoState.Freezing);
  670. // break;
  671. // case "作废":
  672. // EmbryoMark((int)EmbryoState.Cancellation);
  673. // break;
  674. // case "移植":
  675. // EmbryoMark((int)EmbryoState.Transplant);
  676. // break;
  677. // case "删除":
  678. // EmbryoMark((int)EmbryoState.Delete);
  679. // break;
  680. // case "结束":
  681. // Finish();
  682. // break;
  683. // case "取消":
  684. // EmbryoMark((int)EmbryoState.None);
  685. // break;
  686. // default:
  687. // break;
  688. // }
  689. // }
  690. //}
  691. /// <summary>
  692. /// 结束培养
  693. /// </summary>
  694. /// <exception cref="NotImplementedException"></exception>
  695. private void Finish()
  696. {
  697. try
  698. {
  699. if (!AppData.Instance.HttpHelper.EndCultureRecordApi(vm.ExDish.id))
  700. {
  701. //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "结束培养失败");
  702. new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0252"));
  703. return;
  704. }
  705. AppData.Instance.MainPageView.EndDish(vm.ExDish.houseSn);
  706. vm.ExDish = new ExDish();
  707. PlayerPause();
  708. PlayerDispose();
  709. if (vm != null && vm.ParentViewModel != null)
  710. {
  711. DishRecordView dishRecordView = new DishRecordView()
  712. {
  713. DataContext = vm.ParentViewModel,
  714. };
  715. AppData.Instance.MainWindow.LoadPage(dishRecordView);
  716. return;
  717. }
  718. AppData.Instance.BackMainPage();
  719. }
  720. catch (Exception ex)
  721. {
  722. ExLog(ex, "Finish");
  723. }
  724. }
  725. private void EmbryoMark(int embryoState)
  726. {
  727. try
  728. {
  729. if (!AppData.Instance.HttpHelper.MarkEmbryoDestinationApi(vm.CurrentEmbryo.id, embryoState))
  730. {
  731. //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "胚胎标记失败");
  732. new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0253"));
  733. return;
  734. }
  735. DateTime ct = DateTime.Now;
  736. vm.CurrentEmbryo.state = embryoState;
  737. vm.CurrentEmbryo.stateTime = ct;
  738. this._dishInfo.SetEmbryoState(vm.CurrentEmbryo.wellSn, vm.CurrentEmbryo.state, vm.CurrentEmbryo.alarm);
  739. if(string.IsNullOrEmpty(vm.ExDish.endTime)) AppData.Instance.MainPageView.SetMainEmbryoState(vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.wellSn, vm.CurrentEmbryo.state);
  740. }
  741. catch (Exception ex)
  742. {
  743. ExLog(ex, "EmbryoMark");
  744. }
  745. }
  746. private string GetMessageInfo(string stateString)
  747. {
  748. return $"{s1}{spaceString}{stateString}{spaceString}{s2}{vm.CurrentEmbryo.wellSn}{haoString}?";
  749. }
  750. private string GetMarkMessage(string stateString)
  751. {
  752. return $"{s5}{vm.CurrentEmbryo.wellSn}{spaceString}{s6}{spaceString}{stateString}";
  753. }
  754. private string GetCancelMarkMessage()
  755. {
  756. return $"{s3}{spaceString}{vm.CurrentEmbryo.wellSn}{haoString}?";
  757. }
  758. #endregion
  759. #region 视频操作
  760. /// <summary>
  761. /// 播放暂停按钮
  762. /// </summary>
  763. /// <param name="sender"></param>
  764. /// <param name="e"></param>
  765. private void Image_MouseUp_Play(object sender, MouseButtonEventArgs e)
  766. {
  767. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  768. {
  769. if (PlayerState == PlayerStateEnum.Playing)
  770. {
  771. PlayerPause();
  772. }
  773. else
  774. {
  775. newCurrentTime = -1;
  776. //this._dishInfo._preview.Visibility = Visibility.Hidden;
  777. this._dishInfo.Cancas_Preview.Visibility = Visibility.Hidden;
  778. if (!PlayerPlay())
  779. {
  780. this._dishInfo.SetPreviewNoVideo();
  781. }
  782. }
  783. }
  784. else
  785. {
  786. this._dishInfo.SetPreviewNoVideo();
  787. }
  788. }
  789. /// <summary>
  790. /// 上一帧按钮
  791. /// </summary>
  792. /// <param name="sender"></param>
  793. /// <param name="e"></param>
  794. private void Image_MouseUp_PreviousFrame(object sender, MouseButtonEventArgs e)
  795. {
  796. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  797. {
  798. PlayerPause();
  799. PlayerLastFrame(AppData.Instance.TLSettingCommon.videoFps);
  800. //this._dishInfo._preview.Visibility = Visibility.Hidden;
  801. this._dishInfo.Cancas_Preview.Visibility = Visibility.Hidden;
  802. }
  803. }
  804. /// <summary>
  805. /// 下一帧按钮
  806. /// </summary>
  807. /// <param name="sender"></param>
  808. /// <param name="e"></param>
  809. private void Image_MouseUp_NextFrame(object sender, MouseButtonEventArgs e)
  810. {
  811. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  812. {
  813. PlayerPause();
  814. PlayerNextFrame(AppData.Instance.TLSettingCommon.videoFps);
  815. this._dishInfo.Cancas_Preview.Visibility = Visibility.Hidden;
  816. //this._dishInfo._preview.Visibility = Visibility.Hidden;
  817. }
  818. }
  819. /// <summary>
  820. /// 播放倍速按钮
  821. /// </summary>
  822. /// <param name="sender"></param>
  823. /// <param name="e"></param>
  824. private void SpeedRatio_Click(object sender, RoutedEventArgs e)
  825. {
  826. PlayerPause();
  827. if (this._beilvwindow_Border.Height == 324)
  828. {
  829. CloseBeiLvWindow();
  830. }
  831. else
  832. {
  833. OpenBeiLvWindow();
  834. }
  835. }
  836. /// <summary>
  837. /// 关闭倍率设置按钮
  838. /// </summary>
  839. /// <param name="sender"></param>
  840. /// <param name="e"></param>
  841. private void BeiLvClose_MouseUp(object sender, MouseButtonEventArgs e)
  842. {
  843. CloseBeiLvWindow();
  844. }
  845. /// <summary>
  846. /// 设置倍率
  847. /// </summary>
  848. /// <param name="sender"></param>
  849. /// <param name="e"></param>
  850. private void BeiLv_MouseUp(object sender, MouseButtonEventArgs e)
  851. {
  852. try
  853. {
  854. PlayerPause();
  855. if (sender is TextBlock text)
  856. {
  857. int k = int.Parse(text.Tag.ToString());
  858. //var v = 362.5 * k;
  859. var v = 290 * k;
  860. this._beilv_Rectangle.Width = v;
  861. this._beilv_Ellipse.Margin = new Thickness((v - 42), 0, 0, 0);
  862. double fps = -1;
  863. switch (k)
  864. {
  865. case 0:
  866. fps = 0.25;
  867. break;
  868. case 1:
  869. fps = 0.5;
  870. break;
  871. case 2:
  872. fps = 1.0;
  873. break;
  874. case 3:
  875. fps = 1.25;
  876. break;
  877. case 4:
  878. fps = 1.5;
  879. break;
  880. case 5:
  881. fps = 2.0;
  882. break;
  883. }
  884. if (fps != -1)
  885. {
  886. beilv = fps;
  887. this._radius_Button.Content = text.Text;
  888. }
  889. }
  890. }
  891. catch (Exception ex)
  892. {
  893. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}设置倍率", LogEnum.RunException);
  894. }
  895. }
  896. /// <summary>
  897. /// 上一层
  898. /// </summary>
  899. /// <param name="sender"></param>
  900. /// <param name="e"></param>
  901. private void Image_MouseDown_BigFocus(object sender, MouseButtonEventArgs e)
  902. {
  903. PlayerPause();
  904. if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return;
  905. if (vm.CurrentEmbryo == null) return;
  906. if (vm.CurrentWellLayerPicAndVideo != null) ChangeFocalNoVideo(true);
  907. //PlayerPause();
  908. //if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return;
  909. //if (vm.CurrentEmbryo == null) return;
  910. //if (vm.CurrentWellLayerPicAndVideo != null) if (!string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl)) ChangeFocal(true);
  911. // else ChangeImageFocal(true);
  912. }
  913. /// <summary>
  914. /// 下一层
  915. /// </summary>
  916. /// <param name="sender"></param>
  917. /// <param name="e"></param>
  918. private void Image_MouseDown_SmallFocus(object sender, MouseButtonEventArgs e)
  919. {
  920. PlayerPause();
  921. if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return;
  922. if (vm.CurrentEmbryo == null) return;
  923. if (vm.CurrentWellLayerPicAndVideo != null) ChangeFocalNoVideo(false);
  924. //PlayerPause();
  925. //ChangeFocal(false);
  926. //PlayerPause();
  927. //if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return;
  928. //if (vm.CurrentEmbryo == null) return;
  929. //if (vm.CurrentWellLayerPicAndVideo != null) if (!string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl)) ChangeFocal(false);
  930. // else ChangeImageFocal(false);
  931. }
  932. private void CustomQuickButton_ClickQuickPositionEvent(ButtonEntity obj)
  933. {
  934. try
  935. {
  936. PlayerPause();
  937. string quickName = obj.buttonName;
  938. int minHour = obj.minHour * 60;
  939. if (vm.CurrentWellLayerPicAndVideo == null || vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
  940. {
  941. //ShowMessage($"当前胚胎还未发育到{quickName}阶段");
  942. ShowMessage($"{KeyToStringConvert.GetLanguageStringByKey("C0320")} {quickName}");
  943. return;
  944. }
  945. var lastPic = vm.CurrentWellLayerPicAndVideo.videoPictures.Last();
  946. if (minHour > lastPic.developTime)
  947. {
  948. ShowMessage($"{KeyToStringConvert.GetLanguageStringByKey("C0320")} {quickName}");
  949. return;
  950. }
  951. int picCount = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
  952. for (int i = 0; i < picCount; i++)
  953. {
  954. var item = vm.CurrentWellLayerPicAndVideo.videoPictures[i];
  955. if (item.developTime > minHour)
  956. {
  957. if (string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) || vm.CurrentWellLayerPicAndVideo.videoUrl == CleanVideoString)
  958. {
  959. this._dishInfo.Cancas_Preview.Visibility = Visibility.Visible;
  960. vm.VideoCurrentTime = i + 1;
  961. this._dishInfo._preview.Source = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{item.imageUrl}?token={AppData.Instance.HttpHelper.GetToken()}");
  962. }
  963. else
  964. {
  965. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  966. {
  967. this._dishInfo.Cancas_Preview.Visibility = Visibility.Hidden;
  968. //double pro = ((i + 1) / (double)picCount) * vm.VideoAllTime;
  969. double pro = i * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps);
  970. SetTimeProgressbarProgressValue(pro);
  971. SetPlayerPosition(pro);
  972. }
  973. else
  974. {
  975. this._dishInfo.Cancas_Preview.Visibility = Visibility.Visible;
  976. vm.VideoCurrentTime = i + 1;
  977. this._dishInfo._preview.Source = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{item.imageUrl}?token={AppData.Instance.HttpHelper.GetToken()}");
  978. }
  979. }
  980. break;
  981. }
  982. //if (item.developTime > minHour)
  983. //{
  984. // this._dishInfo.Cancas_Preview.Visibility = Visibility.Hidden;
  985. // double pro = i * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps);
  986. // SetTimeProgressbarProgressValue(pro);
  987. // SetPlayerPosition(pro);
  988. // break;
  989. //}
  990. }
  991. }
  992. catch (Exception ex)
  993. {
  994. ExLog(ex, $"CustomQuickButton_ClickQuickPositionEvent");
  995. }
  996. }
  997. private void BeforeInteractionEvent()
  998. {
  999. PlayerPause();
  1000. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  1001. {
  1002. //this._dishInfo._preview.Visibility = Visibility.Hidden;
  1003. this._dishInfo.Cancas_Preview.Visibility = Visibility.Hidden;
  1004. }
  1005. }
  1006. private void AfterInteractionEvent(double obj)
  1007. {
  1008. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  1009. {
  1010. currentMediaElement.LoadedBehavior = MediaState.Manual;
  1011. SetPlayerPosition(obj);
  1012. }
  1013. else
  1014. {
  1015. if (vm.CurrentWellLayerPicAndVideo != null && vm.CurrentWellLayerPicAndVideo.videoPictures.Any()) this._dishInfo._preview.Source = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoPictures[ProToImageIndex()].imageUrl}?token={AppData.Instance.HttpHelper.GetToken()}");
  1016. }
  1017. }
  1018. private void ProChangendEvent(double obj)
  1019. {
  1020. if (PlayerState != PlayerStateEnum.Nothing || PlayerState != PlayerStateEnum.Error) SetPlayerPosition(obj);
  1021. }
  1022. List<PictureEntity> PicList = null;
  1023. int picCount = 0;
  1024. int picIndex = 0;
  1025. private string CustomProgressbar_LengthDevelopmentEvent(double arg)
  1026. {
  1027. try
  1028. {
  1029. if (vm == null || vm.CurrentWellLayerPicAndVideo == null)
  1030. {
  1031. vm.CurrentPic = null;
  1032. return "00h:00m";
  1033. }
  1034. if (vm.CurrentWellLayerPicAndVideo == null || vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
  1035. {
  1036. vm.CurrentPic = null;
  1037. return "00h:00m";
  1038. }
  1039. if (string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) || vm.CurrentWellLayerPicAndVideo.videoUrl == CleanVideoString)
  1040. {
  1041. picIndex = ProToImageIndex();
  1042. vm.CurrentPic = vm.CurrentWellLayerPicAndVideo.videoPictures[picIndex];
  1043. //Debug.WriteLine($"proLength {picIndex} ->{vm.CurrentWellLayerPicAndVideo.videoPictures.Count}");
  1044. return $"{(vm.CurrentPic.developTime / 60).ToString("D2")}h:{(vm.CurrentPic.developTime % 60).ToString("D2")}m";
  1045. }
  1046. else
  1047. {
  1048. picCount = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
  1049. picIndex = VideoProToImageIndex();
  1050. if (picIndex < 0) picIndex = 0;
  1051. if (picIndex > (picCount - 1)) picIndex = picCount - 1;
  1052. vm.CurrentPic = vm.CurrentWellLayerPicAndVideo.videoPictures[picIndex];
  1053. return $"{(vm.CurrentPic.developTime / 60).ToString("D2")}h:{(vm.CurrentPic.developTime % 60).ToString("D2")}m";
  1054. }
  1055. }
  1056. catch (Exception ex)
  1057. {
  1058. vm.CurrentPic = null;
  1059. ExLog(ex, "获取当前帧发育时长");
  1060. return "00h:00m";
  1061. }
  1062. }
  1063. /// <summary>
  1064. /// 0- count-1
  1065. /// </summary>
  1066. /// <returns></returns>
  1067. public int VideoProToImageIndex()
  1068. {
  1069. try
  1070. {
  1071. if (vm == null || vm.CurrentWellLayerPicAndVideo == null) return 0;
  1072. return (int)(vm.VideoCurrentTime / (1000.00 / vm.CurrentWellLayerPicAndVideo.fps));
  1073. }
  1074. catch (Exception ex)
  1075. {
  1076. ExLog(ex, "VideoProToImageIndex");
  1077. return 0;
  1078. }
  1079. //try
  1080. //{
  1081. // return (int)(vm.VideoCurrentTime / (1000.00 / vm.CurrentVideoFps));
  1082. //}
  1083. //catch (Exception ex)
  1084. //{
  1085. // ExLog(ex, "VideoProToImageIndex");
  1086. // return 0;
  1087. //}
  1088. }
  1089. /// <summary>
  1090. /// 进度条换算图片下标
  1091. /// </summary>
  1092. /// <returns></returns>
  1093. public int ProToImageIndex()
  1094. {
  1095. try
  1096. {
  1097. if (vm == null || vm.CurrentWellLayerPicAndVideo == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any()) return 0;
  1098. var imageIndex = ((int)vm.VideoCurrentTime - 1);
  1099. if (imageIndex < 0) imageIndex = 0;
  1100. if (imageIndex >= vm.CurrentWellLayerPicAndVideo.videoPictures.Count) imageIndex = vm.CurrentWellLayerPicAndVideo.videoPictures.Count - 1;
  1101. return imageIndex;
  1102. }
  1103. catch (Exception ex)
  1104. {
  1105. ExLog(ex, "ProToImageIndex");
  1106. return 0;
  1107. }
  1108. }
  1109. #endregion
  1110. #region
  1111. /// <summary>
  1112. /// 切换图层
  1113. /// </summary>
  1114. /// <param name="isMax"></param>
  1115. private void ChangeFocal(bool isMax)
  1116. {
  1117. try
  1118. {
  1119. if (vm.CurrentEmbryo == null) return;
  1120. if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return;
  1121. int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2;
  1122. int minFocal = -maxFocal;
  1123. int newCurrentFocal = vm.CurrentFocal;
  1124. if (isMax) newCurrentFocal++;
  1125. else newCurrentFocal--;
  1126. if (newCurrentFocal < maxFocal) BigFocusIsEnabled(true);
  1127. else BigFocusIsEnabled(false);
  1128. if (newCurrentFocal > minFocal) SmallFocusIsEnabled(true);
  1129. else SmallFocusIsEnabled(false);
  1130. if (newCurrentFocal < minFocal || newCurrentFocal > maxFocal) return;
  1131. //this._dishInfo._preview.Visibility = Visibility.Hidden;
  1132. Task.Run(() =>
  1133. {
  1134. Dispatcher.Invoke(() =>
  1135. {
  1136. var a = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{AppData.Instance.HttpHelper.GetImageUrlApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal, vm.CurrentPic.developTime)}?token={AppData.Instance.HttpHelper.GetToken()}");
  1137. if (a != null)
  1138. {
  1139. this._dishInfo.Cancas_Preview.Visibility = Visibility.Visible;
  1140. //this._dishInfo._preview.Visibility = Visibility.Visible;
  1141. this._dishInfo._preview.Source = a;
  1142. }
  1143. });
  1144. });
  1145. newCurrentTime = 0;
  1146. vm.CurrentFocal = newCurrentFocal;
  1147. //SetVideoButtonState(false);
  1148. //var time1 = stopwatch.Elapsed;
  1149. //DebugLog($"切换图层确定新图层:{DateTime.Now},耗时:{time1.TotalMilliseconds}");
  1150. if (vm.CurrentWellDishPicAndVideo == null) return;
  1151. vm.CurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == vm.CurrentFocal);
  1152. SetVideo(vm.CurrentFocal, false);
  1153. if (vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
  1154. {
  1155. vm.CurrentWellLayerPicAndVideo.videoPictures = AppData.Instance.HttpHelper.GetVideoTimeLineApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, vm.CurrentFocal);
  1156. }
  1157. if (vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any() || vm.CurrentPic == null) return;
  1158. int i = 0;
  1159. foreach (var item in vm.CurrentWellLayerPicAndVideo.videoPictures)
  1160. {
  1161. if (item.developTime >= vm.CurrentPic.developTime) break;
  1162. i++;
  1163. }
  1164. newCurrentTime = i * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps);
  1165. //if (i == 0) newCurrentTime = 0;
  1166. //else newCurrentTime = (i + 1) * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps);
  1167. //var time2 = stopwatch.Elapsed;
  1168. //DebugLog($"切换图层确定新图层:{DateTime.Now},耗时:{(time2 - time1).TotalMilliseconds},切换图层以及设置视频源总耗时:{time2.TotalMilliseconds}");
  1169. }
  1170. catch (Exception ex)
  1171. {
  1172. ExLog(ex, "ChangeFocal");
  1173. }
  1174. }
  1175. private void ChangeFocalNoVideo(bool isMax)
  1176. {
  1177. try
  1178. {
  1179. //DebugLog($"开始切换图层:{DateTime.Now}");
  1180. int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2;
  1181. int minFocal = -maxFocal;
  1182. int newCurrentFocal = vm.CurrentFocal;
  1183. CC:
  1184. if (isMax) newCurrentFocal++;
  1185. else newCurrentFocal--;
  1186. if (newCurrentFocal < maxFocal) BigFocusIsEnabled(true);
  1187. else BigFocusIsEnabled(false);
  1188. if (newCurrentFocal > minFocal) SmallFocusIsEnabled(true);
  1189. else SmallFocusIsEnabled(false);
  1190. if (newCurrentFocal < minFocal || newCurrentFocal > maxFocal) return;
  1191. var aa = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == newCurrentFocal);
  1192. if (aa == null) goto CC;
  1193. if (aa.videoPictures == null || !aa.videoPictures.Any())
  1194. {
  1195. aa.videoPictures = AppData.Instance.HttpHelper.GetVideoTimeLineApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal);
  1196. }
  1197. if (aa.videoPictures == null || !aa.videoPictures.Any()) goto CC;
  1198. bool b = false;
  1199. string imageUrl = null;
  1200. foreach (var item in aa.videoPictures)
  1201. {
  1202. if (item.developTime == vm.CurrentPic.developTime)
  1203. {
  1204. b = true;
  1205. imageUrl = item.imageUrl;
  1206. break;
  1207. }
  1208. }
  1209. if (!b) goto CC;
  1210. Task.Run(() =>
  1211. {
  1212. if (string.IsNullOrEmpty(imageUrl)) imageUrl = AppData.Instance.HttpHelper.GetImageUrlApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal, vm.CurrentPic.developTime);
  1213. Dispatcher.Invoke(() =>
  1214. {
  1215. var a = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{imageUrl}?token={AppData.Instance.HttpHelper.GetToken()}");
  1216. if (a != null)
  1217. {
  1218. //this._dishInfo._preview.Visibility = Visibility.Visible;
  1219. this._dishInfo.Cancas_Preview.Visibility = Visibility.Visible;
  1220. this._dishInfo._preview.Source = a;
  1221. }
  1222. });
  1223. });
  1224. vm.CurrentFocal = newCurrentFocal;
  1225. }
  1226. catch (Exception ex)
  1227. {
  1228. ExLog(ex, "ChangeFocalNoVideo");
  1229. }
  1230. }
  1231. /// <summary>
  1232. /// 切换图层
  1233. /// </summary>
  1234. /// <param name="isMax"></param>
  1235. private void ChangeImageFocal(bool isMax)
  1236. {
  1237. try
  1238. {
  1239. int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2;
  1240. int minFocal = -maxFocal;
  1241. int newCurrentFocal = vm.CurrentFocal;
  1242. CC:
  1243. if (isMax) newCurrentFocal++;
  1244. else newCurrentFocal--;
  1245. if (newCurrentFocal < maxFocal) BigFocusIsEnabled(true);
  1246. else BigFocusIsEnabled(false);
  1247. if (newCurrentFocal > minFocal) SmallFocusIsEnabled(true);
  1248. else SmallFocusIsEnabled(false);
  1249. if (newCurrentFocal < minFocal || newCurrentFocal > maxFocal) return;
  1250. var newCurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == newCurrentFocal);
  1251. newCurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == newCurrentFocal);
  1252. if (newCurrentWellLayerPicAndVideo == null)
  1253. {
  1254. goto CC;
  1255. return;
  1256. }
  1257. if (!newCurrentWellLayerPicAndVideo.videoPictures.Any())
  1258. {
  1259. goto CC;
  1260. return;
  1261. }
  1262. vm.CurrentWellLayerPicAndVideo = newCurrentWellLayerPicAndVideo;
  1263. //this._dishInfo._preview.Visibility = Visibility.Visible;
  1264. this._dishInfo.Cancas_Preview.Visibility = Visibility.Visible;
  1265. var oldDevelopTime = vm.CurrentPic.developTime;
  1266. vm.CurrentFocal = newCurrentFocal;
  1267. vm.VideoAllTime = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
  1268. int i = 0;
  1269. foreach (var item in vm.CurrentWellLayerPicAndVideo.videoPictures)
  1270. {
  1271. if (item.developTime >= oldDevelopTime) break;
  1272. i++;
  1273. }
  1274. //Debug.WriteLine($"{vm.CurrentWellLayerPicAndVideo.videoPictures[163].developTime} -> {oldDevelopTime}");
  1275. //Debug.WriteLine($"focal:{i} -》 {vm.CurrentWellLayerPicAndVideo.videoPictures.Count}");
  1276. //vm.VideoCurrentTime = vm.VideoAllTime;
  1277. this._dishInfo._preview.Source = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoPictures[i].imageUrl}?token={AppData.Instance.HttpHelper.GetToken()}");
  1278. vm.VideoCurrentTime = 0;
  1279. vm.VideoCurrentTime = i + 1;
  1280. return;
  1281. }
  1282. catch (Exception ex)
  1283. {
  1284. ExLog(ex, "ChangeImageFocal");
  1285. }
  1286. }
  1287. /// <summary>
  1288. /// 设置视频
  1289. /// </summary>
  1290. private bool SetVideo(int focal, bool isUpdate)
  1291. {
  1292. if (vm.CurrentWellLayerPicAndVideo != null && !string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) && vm.CurrentWellLayerPicAndVideo.videoUrl != CleanVideoString)
  1293. {
  1294. if (PlayerSetSource($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoUrl}?token={AppData.Instance.HttpHelper.GetToken()}")) return true;
  1295. }
  1296. if (!isUpdate) return false;
  1297. vm.VideoAllTime = 1;
  1298. vm.VideoCurrentTime = 0;
  1299. return true;
  1300. }
  1301. private void BigFocusIsEnabled(bool isEn)
  1302. {
  1303. if (this._bigFocus_Border.IsEnabled == isEn) return;
  1304. this._bigFocus_Border.IsEnabled = isEn;
  1305. if (isEn)
  1306. {
  1307. this._bigFocus_Border.Background = (LinearGradientBrush)this.FindResource("BuleLinear");
  1308. this._bigFocus_Image.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/prePicNum.png", UriKind.RelativeOrAbsolute));
  1309. }
  1310. else
  1311. {
  1312. this._bigFocus_Border.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#8B8B8B"));
  1313. this._bigFocus_Image.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/prePicNumEnabled.png", UriKind.RelativeOrAbsolute));
  1314. }
  1315. }
  1316. private void SmallFocusIsEnabled(bool isEn)
  1317. {
  1318. if (this._smallFocus_Border.IsEnabled == isEn) return;
  1319. this._smallFocus_Border.IsEnabled = isEn;
  1320. if (isEn)
  1321. {
  1322. this._smallFocus_Border.Background = (LinearGradientBrush)this.FindResource("BuleLinear");
  1323. this._smallFocus_Image.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/nextPicNum.png", UriKind.RelativeOrAbsolute));
  1324. }
  1325. else
  1326. {
  1327. this._smallFocus_Border.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#8B8B8B"));
  1328. this._smallFocus_Image.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/nextPicNumEnabled.png", UriKind.RelativeOrAbsolute));
  1329. }
  1330. }
  1331. #endregion
  1332. #region 视频基础操作
  1333. MediaElement currentMediaElement = null;
  1334. string currentViewName = "详情页面";
  1335. /// <summary>
  1336. /// 定时器
  1337. /// </summary>
  1338. public System.Timers.Timer dispatcherTimer = new System.Timers.Timer();
  1339. /// <summary>
  1340. /// 视频状态
  1341. /// </summary>
  1342. public PlayerStateEnum PlayerState { get; set; } = PlayerStateEnum.Nothing;
  1343. /// <summary>
  1344. /// 播放器事件初始化
  1345. /// </summary>
  1346. public void PlayerEvent(MediaElement mediaElement)
  1347. {
  1348. try
  1349. {
  1350. currentMediaElement = mediaElement;
  1351. currentMediaElement.MediaEnded -= MediaEndedEvent;
  1352. currentMediaElement.MediaOpened -= MediaOpenedEvent;
  1353. currentMediaElement.MediaFailed -= MediaFailedEvent;
  1354. currentMediaElement.MediaEnded += MediaEndedEvent;
  1355. currentMediaElement.MediaOpened += MediaOpenedEvent;
  1356. currentMediaElement.MediaFailed += MediaFailedEvent;
  1357. dispatcherTimer.Interval = 25;
  1358. dispatcherTimer.Elapsed -= dispatcherTimer_Elapsed;
  1359. dispatcherTimer.Elapsed += dispatcherTimer_Elapsed;
  1360. }
  1361. catch (Exception ex)
  1362. {
  1363. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}播放器事件初始化", LogEnum.RunException);
  1364. }
  1365. }
  1366. /// <summary>
  1367. /// 设置播放源
  1368. /// </summary>
  1369. /// <param name="FileName"></param>
  1370. public bool PlayerSetSource(string FileName)
  1371. {
  1372. try
  1373. {
  1374. ErrorLog($"开始加载视频,{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}", LogEnum.TakeTime);
  1375. PlayerDispose();
  1376. //指定媒体文件地址
  1377. currentMediaElement.LoadedBehavior = MediaState.Manual;
  1378. currentMediaElement.SpeedRatio = 1;
  1379. beilv = 1;
  1380. ChangeBeiLvUi();
  1381. this._radius_Button.Content = "1.0x";
  1382. this._radius_Button.Tag = 1.0;
  1383. currentMediaElement.Source = new Uri(FileName, UriKind.RelativeOrAbsolute);
  1384. currentMediaElement.ScrubbingEnabled = true;
  1385. currentMediaElement.Play();
  1386. currentMediaElement.Pause();
  1387. return true;
  1388. }
  1389. catch (Exception ex)
  1390. {
  1391. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}设置播放源", LogEnum.RunException);
  1392. return false;
  1393. }
  1394. }
  1395. /// <summary>
  1396. /// 播放器加载视频完成事件
  1397. /// </summary>
  1398. /// <param name="sender"></param>
  1399. /// <param name="e"></param>
  1400. private void MediaOpenedEvent(object sender, RoutedEventArgs e)
  1401. {
  1402. try
  1403. {
  1404. if (vm == null) return;
  1405. //ErrorLog($"视频加载完成,开始设置属性,{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")},[{currentMediaElement.Source}]", LogEnum.TakeTime);
  1406. ErrorLog($"视频加载完成", LogEnum.TakeTime);
  1407. currentMediaElement.ScrubbingEnabled = false;
  1408. vm.VideoAllTime = 1;
  1409. vm.VideoCurrentTime = 0;
  1410. if (currentMediaElement.NaturalDuration.HasTimeSpan)
  1411. {
  1412. currentMediaElement.LoadedBehavior = MediaState.Manual;
  1413. PlayerState = PlayerStateEnum.Paused;
  1414. currentMediaElement.Play();
  1415. currentMediaElement.Pause();
  1416. vm.VideoAllTime = currentMediaElement.NaturalDuration.TimeSpan.TotalMilliseconds;
  1417. if (newCurrentTime != -1)
  1418. {
  1419. if (newCurrentTime < 0) newCurrentTime = 0;
  1420. if (newCurrentTime > vm.VideoAllTime) newCurrentTime = vm.VideoAllTime;
  1421. SetTimeProgressbarProgressValue(newCurrentTime);
  1422. SetPlayerPosition(vm.VideoCurrentTime);
  1423. newCurrentTime = -1;
  1424. }
  1425. else
  1426. {
  1427. SetTimeProgressbarProgressValue(vm.VideoAllTime);
  1428. SetPlayerPosition(vm.VideoCurrentTime);
  1429. }
  1430. currentMediaElement.ScrubbingEnabled = true;
  1431. SetVideoButtonState(true);
  1432. }
  1433. else
  1434. {
  1435. PlayerState = PlayerStateEnum.Nothing;
  1436. }
  1437. ErrorLog($"视频加载完成,{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}", LogEnum.TakeTime);
  1438. }
  1439. catch (Exception ex)
  1440. {
  1441. PlayerState = PlayerStateEnum.Error;
  1442. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}播放器加载视频完成事件", LogEnum.RunException);
  1443. }
  1444. }
  1445. /// <summary>
  1446. /// 播放完成事件
  1447. /// </summary>
  1448. /// <param name="sender"></param>
  1449. /// <param name="e"></param>
  1450. private void MediaEndedEvent(object sender, RoutedEventArgs e)
  1451. {
  1452. try
  1453. {
  1454. PlayerState = PlayerStateEnum.Paused;
  1455. dispatcherTimer_Stop();
  1456. // currentMediaElement.Stop();
  1457. currentMediaElement.Play();
  1458. currentMediaElement.Pause();
  1459. SetTimeProgressbarProgressValue(vm.VideoAllTime);
  1460. SetPlayerPosition(vm.VideoAllTime);
  1461. SetPlayButton(false);
  1462. //currentMediaElement.Position = currentMediaElement.NaturalDuration.TimeSpan;
  1463. //currentMediaElement.Play();
  1464. //currentMediaElement.Pause();
  1465. //PlayerSetPosition(1);
  1466. }
  1467. catch (Exception ex)
  1468. {
  1469. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}播放完成事件", LogEnum.RunException);
  1470. }
  1471. }
  1472. /// <summary>
  1473. /// 播放器错误事件
  1474. /// </summary>
  1475. /// <param name="sender"></param>
  1476. /// <param name="e"></param>
  1477. /// <exception cref="NotImplementedException"></exception>
  1478. private void MediaFailedEvent(object? sender, ExceptionRoutedEventArgs e)
  1479. {
  1480. try
  1481. {
  1482. PlayerState = PlayerStateEnum.Error;
  1483. vm.VideoAllTime = 1;
  1484. vm.VideoCurrentTime = 0;
  1485. string ss = "";
  1486. MediaElement med = sender as MediaElement;
  1487. if (med != null)
  1488. {
  1489. ss = med.Source.ToString();
  1490. AppData.Instance.LogHelper.TLLog($"{ss},{currentViewName}视频遇到错误", LogEnum.RunError);
  1491. }
  1492. dispatcherTimer_Stop();
  1493. AppData.Instance.LogHelper.ExceptionLog(e.ErrorException, $"{currentViewName}.MediaFailedEvent:{ss}", LogEnum.RunException);
  1494. }
  1495. catch (Exception ex)
  1496. {
  1497. AppData.Instance.LogHelper.ExceptionLog(ex, $"播放器错误事件:{JsonConvert.SerializeObject(ex)}", LogEnum.RunException);
  1498. }
  1499. }
  1500. /// <summary>
  1501. /// 播放按钮图标设置
  1502. /// </summary>
  1503. private void SetPlayButton(bool isPlaying)
  1504. {
  1505. if (isPlaying)//正在播放,设置为暂停按钮
  1506. {
  1507. _playButton.Source = new BitmapImage(new Uri("/Resources/Image/video_Pause.png", UriKind.RelativeOrAbsolute));
  1508. }
  1509. else//未播放,设置为播放按钮
  1510. {
  1511. _playButton.Source = new BitmapImage(new Uri("/Resources/Image/video_play.png", UriKind.RelativeOrAbsolute));//重置播放按钮
  1512. }
  1513. }
  1514. /// <summary>
  1515. /// 定时器事件
  1516. /// </summary>
  1517. /// <param name="sender"></param>
  1518. /// <param name="e"></param>
  1519. private void dispatcherTimer_Elapsed(object? sender, ElapsedEventArgs e)
  1520. {
  1521. try
  1522. {
  1523. Dispatcher.Invoke(() =>
  1524. {
  1525. SetTimeProgressbarProgressValue(currentMediaElement.Position.TotalMilliseconds);
  1526. });
  1527. if (PlayerState != PlayerStateEnum.Playing)
  1528. {
  1529. dispatcherTimer_Stop();
  1530. }
  1531. }
  1532. catch (Exception ex)
  1533. {
  1534. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}定时器事件", LogEnum.RunException);
  1535. }
  1536. }
  1537. /// <summary>
  1538. /// 停止定时器
  1539. /// </summary>
  1540. public void dispatcherTimer_Stop()
  1541. {
  1542. try
  1543. {
  1544. if (dispatcherTimer.Enabled)
  1545. {
  1546. dispatcherTimer.Enabled = false;
  1547. dispatcherTimer.Stop();
  1548. }
  1549. }
  1550. catch (Exception ex)
  1551. {
  1552. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}停止定时器", LogEnum.RunException);
  1553. }
  1554. }
  1555. public bool isMediaOpened = true;
  1556. /// <summary>
  1557. ///设置视频进度
  1558. /// </summary>
  1559. /// <param name="progressValue"></param>
  1560. public void SetPlayerPosition(double currentTime)
  1561. {
  1562. try
  1563. {
  1564. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  1565. {
  1566. //var a = currentMediaElement.NaturalDuration.TimeSpan.TotalMilliseconds;
  1567. currentMediaElement.Position = TimeSpan.FromMilliseconds(currentTime);
  1568. //var a = currentMediaElement.NaturalDuration.TimeSpan.TotalMilliseconds * progressValue;
  1569. //int k = (int)(PlayerAllTime - a);
  1570. //if (k < 0)
  1571. //{
  1572. // k = 0;
  1573. //}
  1574. //vm.PlayTimeString = RevertToTime(b);
  1575. //vm.AllTimeString = RevertToTime(TimeSpan.FromMilliseconds(k));
  1576. }
  1577. }
  1578. catch (Exception ex)
  1579. {
  1580. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}进度条变换以后设置视频进度", LogEnum.RunException);
  1581. }
  1582. }
  1583. /// <summary>
  1584. /// 设置进度条
  1585. /// </summary>
  1586. public void SetTimeProgressbarProgressValue(double newTime)
  1587. {
  1588. try
  1589. {
  1590. if (vm == null) return;
  1591. vm.VideoCurrentTime = newTime;
  1592. //var currentPosition = currentMediaElement.Position.TotalMilliseconds;
  1593. //var b = (currentPosition) / PlayerAllTime;
  1594. //if (b == 0 && PlayerState == PlayerStateEnum.Playing)
  1595. //{
  1596. // return;
  1597. //}
  1598. //vm.PlayTimeString = RevertToTime(currentMediaElement.Position);
  1599. //SetProValue(b);
  1600. //int k = (int)(PlayerAllTime - currentPosition);
  1601. //if (k < 0)
  1602. //{
  1603. // k = 0;
  1604. //}
  1605. //vm.AllTimeString = RevertToTime(TimeSpan.FromMilliseconds(k));
  1606. }
  1607. catch (Exception ex)
  1608. {
  1609. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}视频进度变换以后设置进度条", LogEnum.RunException);
  1610. }
  1611. }
  1612. /// <summary>
  1613. /// 设置进度条进度
  1614. /// </summary>
  1615. /// <param name="newValue"></param>
  1616. public void SetProValue(double newValue)
  1617. {
  1618. //if (vm.ProgressValue == newValue)
  1619. //{
  1620. // var maxNewValue = newValue + 0.01;
  1621. // if (maxNewValue > 1)
  1622. // {
  1623. // var minNewValue = newValue - 0.01;
  1624. // vm.ProgressValue = minNewValue;
  1625. // }
  1626. // else
  1627. // {
  1628. // vm.ProgressValue = maxNewValue;
  1629. // }
  1630. //}
  1631. //vm.ProgressValue = newValue;
  1632. }
  1633. /// <summary>
  1634. /// 释放播放器
  1635. /// </summary>
  1636. public void PlayerDispose()
  1637. {
  1638. try
  1639. {
  1640. dispatcherTimer_Stop();
  1641. if (PlayerState != PlayerStateEnum.Nothing)
  1642. {
  1643. currentMediaElement.Close();
  1644. currentMediaElement.LoadedBehavior = MediaState.Close;
  1645. PlayerState = PlayerStateEnum.Nothing;
  1646. }
  1647. }
  1648. catch (Exception ex)
  1649. {
  1650. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}释放播放器", LogEnum.RunException);
  1651. }
  1652. }
  1653. /// <summary>
  1654. /// 设置倍率
  1655. /// </summary>
  1656. /// <param name="newSpeedRatio"></param>
  1657. public void PlayerSetSpeedRatio(double newSpeedRatio)
  1658. {
  1659. try
  1660. {
  1661. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  1662. {
  1663. currentMediaElement.SpeedRatio = newSpeedRatio;
  1664. }
  1665. }
  1666. catch (Exception ex)
  1667. {
  1668. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}设置倍率", LogEnum.RunException);
  1669. }
  1670. }
  1671. /// <summary>
  1672. /// 播放操作
  1673. /// </summary>
  1674. public bool PlayerPlay()
  1675. {
  1676. try
  1677. {
  1678. bool isPlay = false;
  1679. switch (PlayerState)
  1680. {
  1681. case PlayerStateEnum.Error:
  1682. break;
  1683. case PlayerStateEnum.Nothing:
  1684. break;
  1685. case PlayerStateEnum.Opened:
  1686. isPlay = true;
  1687. break;
  1688. case PlayerStateEnum.Paused:
  1689. isPlay = true;
  1690. break;
  1691. case PlayerStateEnum.Playing:
  1692. break;
  1693. case PlayerStateEnum.Stopped:
  1694. currentMediaElement.Stop();
  1695. isPlay = true;
  1696. break;
  1697. default:
  1698. AppData.Instance.LogHelper.TLLog($"{currentViewName}.PlayerPlay,未知的视频状态:{PlayerState.ToString()}", LogEnum.RunError);
  1699. break;
  1700. }
  1701. if (isPlay)
  1702. {
  1703. PlayerState = PlayerStateEnum.Playing;
  1704. if (!dispatcherTimer.Enabled)
  1705. {
  1706. dispatcherTimer.Start();
  1707. }
  1708. if (vm.VideoCurrentTime == vm.VideoAllTime)
  1709. {
  1710. SetPlayerPosition(0);
  1711. }
  1712. //var a = currentMediaElement.Position.TotalMilliseconds;
  1713. PlayerSetSpeedRatio(beilv);
  1714. currentMediaElement.Play();
  1715. SetPlayButton(true);
  1716. return true;
  1717. }
  1718. return false;
  1719. }
  1720. catch (Exception ex)
  1721. {
  1722. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}播放操作", LogEnum.RunException);
  1723. return false;
  1724. }
  1725. }
  1726. /// <summary>
  1727. /// 暂停操作
  1728. /// </summary>
  1729. /// <param name="isSetState"></param>
  1730. public bool PlayerPause()
  1731. {
  1732. try
  1733. {
  1734. bool isPause = false;
  1735. switch (PlayerState)
  1736. {
  1737. case PlayerStateEnum.Error:
  1738. break;
  1739. case PlayerStateEnum.Nothing:
  1740. break;
  1741. case PlayerStateEnum.Opened:
  1742. break;
  1743. case PlayerStateEnum.Paused:
  1744. break;
  1745. case PlayerStateEnum.Playing:
  1746. isPause = true;
  1747. break;
  1748. case PlayerStateEnum.Stopped:
  1749. break;
  1750. }
  1751. if (isPause)
  1752. {
  1753. PlayerState = PlayerStateEnum.Paused;
  1754. currentMediaElement.Pause();
  1755. dispatcherTimer_Stop();
  1756. SetPlayButton(false);
  1757. return true;
  1758. }
  1759. return false;
  1760. }
  1761. catch (Exception ex)
  1762. {
  1763. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}暂停操作", LogEnum.RunException);
  1764. return false;
  1765. }
  1766. }
  1767. /// <summary>
  1768. /// 上一帧
  1769. /// </summary>
  1770. public void PlayerLastFrame(int zhenshu)
  1771. {
  1772. try
  1773. {
  1774. bool isOK = false;
  1775. bool isStop = false;
  1776. switch (PlayerState)
  1777. {
  1778. case PlayerStateEnum.Error:
  1779. break;
  1780. case PlayerStateEnum.Nothing:
  1781. break;
  1782. case PlayerStateEnum.Opened:
  1783. isOK = true;
  1784. break;
  1785. case PlayerStateEnum.Paused:
  1786. isOK = true;
  1787. break;
  1788. case PlayerStateEnum.Playing:
  1789. break;
  1790. case PlayerStateEnum.Stopped:
  1791. isOK = true;
  1792. break;
  1793. }
  1794. if (isOK)
  1795. {
  1796. if (vm.VideoCurrentTime == 0) return;
  1797. var c = vm.VideoCurrentTime - (1000.00 / zhenshu);
  1798. if (c < 0) c = 0;
  1799. SetPlayerPosition(c);
  1800. SetTimeProgressbarProgressValue(c);
  1801. //var zhen = (1000 / zhenshu);
  1802. //var currentPositionTime = currentMediaElement.Position.TotalMilliseconds;
  1803. //if (currentPositionTime == 0)
  1804. //{
  1805. // return;
  1806. //}
  1807. //if (currentPositionTime < zhen)
  1808. //{
  1809. // SetPlayerPosition(0);
  1810. // SetTimeProgressbarProgressValue(0);
  1811. // return;
  1812. //}
  1813. //var c = currentPositionTime - zhen;
  1814. //SetPlayerPosition(c);
  1815. //SetTimeProgressbarProgressValue(c);
  1816. //currentMediaElement.Position = c;
  1817. //SetTimeProgressbarProgressValue(1);
  1818. return;
  1819. }
  1820. else
  1821. {
  1822. }
  1823. //if (isStop)
  1824. //{
  1825. // currentMediaElement.Position = TimeSpan.FromMilliseconds(currentMediaElement.NaturalDuration.TimeSpan.TotalMilliseconds - (1000 / zhenshu));
  1826. // SetTimeProgressbarProgressValue(1);
  1827. // return;
  1828. //}
  1829. }
  1830. catch (Exception ex)
  1831. {
  1832. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}上一帧", LogEnum.RunException);
  1833. }
  1834. }
  1835. /// <summary>
  1836. /// 下一帧
  1837. /// </summary>
  1838. public void PlayerNextFrame(int zhenshu)
  1839. {
  1840. try
  1841. {
  1842. bool isOK = false;
  1843. bool isStop = false;
  1844. switch (PlayerState)
  1845. {
  1846. case PlayerStateEnum.Error:
  1847. break;
  1848. case PlayerStateEnum.Nothing:
  1849. break;
  1850. case PlayerStateEnum.Opened:
  1851. isOK = true;
  1852. break;
  1853. case PlayerStateEnum.Paused:
  1854. isOK = true;
  1855. break;
  1856. case PlayerStateEnum.Playing:
  1857. break;
  1858. case PlayerStateEnum.Stopped:
  1859. isOK = true;
  1860. break;
  1861. }
  1862. if (!isOK) return;
  1863. if (vm.VideoCurrentTime == vm.VideoAllTime) return;
  1864. var newpos = vm.VideoCurrentTime + (1000d / zhenshu);
  1865. if (newpos > vm.VideoAllTime) newpos = vm.VideoAllTime;
  1866. SetPlayerPosition(newpos);
  1867. SetTimeProgressbarProgressValue(newpos);
  1868. return;
  1869. //if (isOK)
  1870. //{
  1871. // var newpos = currentMediaElement.Position.TotalMilliseconds + (1000 / zhenshu);
  1872. // if (newpos > vm.VideoAllTime)
  1873. // {
  1874. // newpos = vm.VideoAllTime;
  1875. // }
  1876. // SetPlayerPosition(newpos);
  1877. // SetTimeProgressbarProgressValue(newpos);
  1878. // return;
  1879. //}
  1880. //else
  1881. //{
  1882. //}
  1883. //if (isStop)
  1884. //{
  1885. // return;
  1886. //}
  1887. }
  1888. catch (Exception ex)
  1889. {
  1890. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}下一帧", LogEnum.RunException);
  1891. }
  1892. }
  1893. #endregion
  1894. /// <summary>
  1895. /// 转换为时分秒格式
  1896. /// </summary>
  1897. /// <param name="timespan"></param>
  1898. /// <returns></returns>
  1899. public string RevertToTime(TimeSpan timespan)
  1900. {
  1901. return $"{(timespan.Days * 24 + timespan.Hours).ToString("D2")}:{timespan.Minutes.ToString("D2")}:{(timespan.Seconds + ((int)Math.Round(timespan.Milliseconds / 1000.00))).ToString("D2")}";
  1902. }
  1903. public void ChangeBeiLvUi()
  1904. {
  1905. int k = 1;
  1906. switch (beilv)
  1907. {
  1908. case 0.5:
  1909. k = 0;
  1910. break;
  1911. case 0.75:
  1912. k = 1;
  1913. break;
  1914. case 1.0:
  1915. k = 2;
  1916. break;
  1917. case 1.25:
  1918. k = 3;
  1919. break;
  1920. case 1.5:
  1921. k = 4;
  1922. break;
  1923. }
  1924. var v = 362.5 * k;
  1925. this._beilv_Rectangle.Width = v;
  1926. this._beilv_Ellipse.Margin = new Thickness((v - 42), 0, 0, 0);
  1927. }
  1928. /// <summary>
  1929. /// 打开倍率窗口
  1930. /// </summary>
  1931. public void OpenBeiLvWindow()
  1932. {
  1933. try
  1934. {
  1935. if (this._beilvwindow_Border.Height == 324)
  1936. {
  1937. return;
  1938. }
  1939. double width = 0;
  1940. double to = 324;
  1941. DoubleAnimation doubleAnimation = new DoubleAnimation();
  1942. doubleAnimation.From = width;
  1943. doubleAnimation.To = to;
  1944. doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.1));
  1945. this._beilvwindow_Border.BeginAnimation(FrameworkElement.HeightProperty, doubleAnimation);
  1946. int k = 1;
  1947. switch (beilv)
  1948. {
  1949. case 0.25:
  1950. k = 0;
  1951. break;
  1952. case 0.5:
  1953. k = 1;
  1954. break;
  1955. case 1.0:
  1956. k = 2;
  1957. break;
  1958. case 1.25:
  1959. k = 3;
  1960. break;
  1961. case 1.5:
  1962. k = 4;
  1963. break;
  1964. case 2.0:
  1965. k = 5;
  1966. break;
  1967. }
  1968. //var v = 362.5 * k;
  1969. var v = 290 * k;
  1970. this._beilv_Rectangle.Width = v;
  1971. this._beilv_Ellipse.Margin = new Thickness((v - 42), 0, 0, 0);
  1972. }
  1973. catch (Exception ex)
  1974. {
  1975. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}打开倍率窗口", LogEnum.RunException);
  1976. }
  1977. }
  1978. /// <summary>
  1979. /// 关闭倍率窗口
  1980. /// </summary>
  1981. public void CloseBeiLvWindow()
  1982. {
  1983. try
  1984. {
  1985. if (this._beilvwindow_Border.Height == 0)
  1986. {
  1987. return;
  1988. }
  1989. double width = 324;
  1990. double to = 0;
  1991. DoubleAnimation doubleAnimation = new DoubleAnimation();
  1992. doubleAnimation.From = width;
  1993. doubleAnimation.To = to;
  1994. doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.1));
  1995. this._beilvwindow_Border.BeginAnimation(FrameworkElement.HeightProperty, doubleAnimation);
  1996. }
  1997. catch (Exception ex)
  1998. {
  1999. AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}关闭倍率窗口", LogEnum.RunException);
  2000. }
  2001. }
  2002. private void Sure_Click(object sender, RoutedEventArgs e)
  2003. {
  2004. }
  2005. private void Cancel_Click(object sender, RoutedEventArgs e)
  2006. {
  2007. }
  2008. private void Grid_PreviewMouseUp(object sender, MouseButtonEventArgs e)
  2009. {
  2010. PlayerPause();
  2011. AddDishWindowView addDishWindowView = new AddDishWindowView(vm.ExDish, vm.DishPicAndVideoList);
  2012. AppData.Instance.MainWindow.Mark(true);
  2013. var a = addDishWindowView.ShowDialog();
  2014. AppData.Instance.MainWindow.Mark(false);
  2015. if (a == true)
  2016. {
  2017. //new MessagePrompt().ShowCenterOwnerSuccess(AppData.Instance.MainWindow, "保存成功");
  2018. new MessagePrompt().ShowCenterOwnerSuccess(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0242"));
  2019. AppData.Instance.MainPageView.UpdateInfo();
  2020. }
  2021. e.Handled = true;
  2022. }
  2023. private void Pic_Click(object sender, RoutedEventArgs e)
  2024. {
  2025. if (vm == null || vm.CurrentEmbryo == null) return;
  2026. PhotoPageViewModel photoPageViewModel = new PhotoPageViewModel(vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, vm.MaxTotalLayer);
  2027. PhotoPageView dishRecordView = new PhotoPageView(vm, vm.CurrentEmbryo.wellSn)
  2028. {
  2029. DataContext = photoPageViewModel,
  2030. };
  2031. AppData.Instance.MainWindow.LoadPage(dishRecordView);
  2032. }
  2033. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  2034. {
  2035. PlayerPause();
  2036. AddDishWindowView addDishWindowView = new AddDishWindowView(vm.ExDish, vm.DishPicAndVideoList);
  2037. AppData.Instance.MainWindow.Mark(true);
  2038. var a = addDishWindowView.ShowDialog();
  2039. AppData.Instance.MainWindow.Mark(false);
  2040. if (a == true)
  2041. {
  2042. //new MessagePrompt().ShowCenterOwnerSuccess(AppData.Instance.MainWindow, "保存成功");
  2043. new MessagePrompt().ShowCenterOwnerSuccess(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0242"));
  2044. AppData.Instance.MainPageView.UpdateInfo();
  2045. }
  2046. e.Handled = true;
  2047. }
  2048. private void SetVideoButtonState(bool IsEnabledVideo)
  2049. {
  2050. Task.Run(() =>
  2051. {
  2052. Dispatcher.Invoke(() =>
  2053. {
  2054. this.playButton.IsEnabled = IsEnabledVideo;
  2055. if (IsEnabledVideo)
  2056. {
  2057. this.playButton.Background = (LinearGradientBrush)this.FindResource("BuleLinear");
  2058. this.preZhenImage.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/preZhen.png", UriKind.RelativeOrAbsolute));
  2059. this._playButton.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/video_play.png", UriKind.RelativeOrAbsolute));
  2060. this.nextZhenImage.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/nextZhen.png", UriKind.RelativeOrAbsolute));
  2061. }
  2062. else
  2063. {
  2064. this.playButton.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#8B8B8B"));
  2065. this.preZhenImage.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/preZhen1.png", UriKind.RelativeOrAbsolute));
  2066. this._playButton.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/video_play1.png", UriKind.RelativeOrAbsolute));
  2067. this.nextZhenImage.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/nextZhen1.png", UriKind.RelativeOrAbsolute));
  2068. }
  2069. //this._lastButton.IsEnabled = IsEnabledVideo;
  2070. //this._playButton.IsEnabled = IsEnabledVideo;
  2071. //this._nextButton.IsEnabled = IsEnabledVideo;
  2072. });
  2073. });
  2074. }
  2075. private void _dishInfo_IsMaxChangedEvent(bool obj)
  2076. {
  2077. if (obj)
  2078. {
  2079. this.lastBu.Visibility = Visibility.Visible;
  2080. this.nextBu.Visibility = Visibility.Visible;
  2081. }
  2082. else
  2083. {
  2084. this.lastBu.Visibility = Visibility.Hidden;
  2085. this.nextBu.Visibility = Visibility.Hidden;
  2086. }
  2087. }
  2088. }
  2089. }