DetailView.xaml.cs 133 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087
  1. using ivf_tl_CustomControls;
  2. using ivf_tl_Entity.Entity;
  3. using ivf_tl_Entity.Entity.balance;
  4. using ivf_tl_Entity.Entity.Result;
  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 ivf_tl_Service;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Diagnostics;
  14. using System.Linq;
  15. using System.Numerics;
  16. using System.Reflection;
  17. using System.Reflection.Metadata;
  18. using System.Text;
  19. using System.Threading;
  20. using System.Threading.Tasks;
  21. using System.Timers;
  22. using System.Windows;
  23. using System.Windows.Controls;
  24. using System.Windows.Data;
  25. using System.Windows.Documents;
  26. using System.Windows.Input;
  27. using System.Windows.Media;
  28. using System.Windows.Media.Imaging;
  29. using System.Windows.Navigation;
  30. using System.Windows.Shapes;
  31. namespace ivf_tl_Manage.Views
  32. {
  33. /// <summary>
  34. /// DetailView.xaml 的交互逻辑
  35. /// </summary>
  36. public partial class DetailView : UserControl
  37. {
  38. string paiShe, peitai, shiping;
  39. private DetailViewModel vm;
  40. private Brush deaeatForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D75AC"));
  41. private Brush noEmbryoForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9B9B9B"));
  42. private Brush noPicForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D4D4D"));
  43. private double centerX, centerY;
  44. private double angle;
  45. private double angleOffset = 90;
  46. private int ellipseCount = 16;
  47. private int backImageRadius = 50;
  48. private int backImageBigRadius = 248;
  49. private int imageRadius = 40;
  50. private int imageBigRadius = 248;
  51. private int textBigRadius = 193;
  52. private int operRaius = 13;
  53. private int operBigRadius = 288;
  54. private int selectedIndex;
  55. private List<TextBlock> TextBlockList = new List<TextBlock>();
  56. private List<Image> ImageList = new List<Image>();
  57. private List<Image> PicImageList = new List<Image>();
  58. private List<Image> OperImageList = new List<Image>();
  59. public bool IsCleanVideo = false;
  60. public DetailView()
  61. {
  62. //DebugLog($"详情界面初始化开始:{DateTime.Now}");
  63. InitializeComponent();
  64. //paiShe = "拍摄中,请耐心等待";
  65. //shiping = "暂无视频,请耐心等待";
  66. //peitai = "暂无胚胎";
  67. paiShe = KeyToStringConvert.GetLanguageStringByKey("0509");
  68. shiping = KeyToStringConvert.GetLanguageStringByKey("0510");
  69. peitai = KeyToStringConvert.GetLanguageStringByKey("0511");
  70. object value = App.Current.TryFindResource("0511");
  71. centerX = 710 / 2.0;
  72. centerY = 710 / 2.0;
  73. angle = 360.00 / 16;
  74. Loaded += DetailView_Loaded;
  75. Unloaded += (s, e) =>
  76. {
  77. CloseCeLiang();
  78. PlayerDispose();
  79. Canvas_Root.Children.Clear();
  80. TextBlockList.Clear();
  81. ImageList.Clear();
  82. PicImageList.Clear();
  83. OperImageList.Clear();
  84. if (vm != null)
  85. {
  86. foreach (var item in vm.CurrentDish.embryoList)
  87. {
  88. item.AlarmChangedEvent -= EmbryoAlarmEvent;
  89. }
  90. }
  91. vm = null;
  92. DataContext = null;
  93. };
  94. //DebugLog($"详情界面初始化完成:{DateTime.Now}");
  95. }
  96. private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
  97. {
  98. string ss = "";
  99. }
  100. private void DetailView_Loaded(object sender, RoutedEventArgs e)
  101. {
  102. vm = (DetailViewModel)this.DataContext;
  103. if (vm == null) return;
  104. InitNav();
  105. InitCustomNew();
  106. foreach (var item in vm.CurrentDish.embryoList)
  107. {
  108. item.AlarmChangedEvent -= EmbryoAlarmEvent;
  109. item.AlarmChangedEvent += EmbryoAlarmEvent;
  110. }
  111. InitAlarm();
  112. Task.Run(() =>
  113. {
  114. vm.Init();
  115. if (vm == null) return;
  116. Dispatcher.InvokeAsync(() =>
  117. {
  118. //Stopwatch stopwatch = Stopwatch.StartNew();
  119. //DebugLog($"开始设置详情界面默认值:{DateTime.Now}");
  120. //var time1 = stopwatch.Elapsed;
  121. IsCleanVideo = false;
  122. if (vm == null) return;
  123. if (vm.DishPicAndVideoList.Any())
  124. {
  125. var a = vm.DishPicAndVideoList.First();
  126. if (a.videos != null && a.videos.Any())
  127. {
  128. var b = a.videos.FirstOrDefault(x => x.pictureLayer == 0);
  129. if (b != null && b.videoUrl == AppData.Instance.CleanVideoString)
  130. {
  131. IsCleanVideo = true;
  132. }
  133. }
  134. }
  135. InitQuickButton();
  136. SetEmbryoPic();
  137. PlayerEvent(this.mediaElementPlayer);
  138. //var time2 = stopwatch.Elapsed;
  139. //DebugLog($"详情界面默认值设置完成,开始设置视频:{DateTime.Now},耗时:{(time2 - time1).TotalMilliseconds}");
  140. ChangeEmbryo(1);
  141. //time1 = stopwatch.Elapsed;
  142. //DebugLog($"所有设置完成:{DateTime.Now},耗时:{(time1 - time2).TotalMilliseconds},总耗时:{stopwatch.Elapsed.TotalMilliseconds}");
  143. //stopwatch.Stop();
  144. });
  145. while (true)
  146. {
  147. Thread.Sleep(10000);
  148. if (vm == null || vm.CurrentDish == null || AppData.Instance.CurrentTlInfo == null) return;
  149. //foreach (var item in vm.CurrentDish.embryoList)
  150. //{
  151. // if (item.alarm == 0) item.alarm = 1;
  152. // else item.alarm = 0;
  153. //}
  154. InitAlarm();
  155. }
  156. });
  157. }
  158. private void InitAlarm()
  159. {
  160. if (vm == null || vm.CurrentDish == null || AppData.Instance.CurrentTlInfo == null) return;
  161. HouseCropAlarmResponse houseCropAlarmResponse = new HouseCropAlarmResponse();
  162. HouseCropAlarmResult CurrentHouseCropAlarmResult;
  163. houseCropAlarmResponse.tlSn = AppData.Instance.CurrentTlInfo.tlSn;
  164. if (!houseCropAlarmResponse.houseList.Any())
  165. {
  166. houseCropAlarmResponse.houseList.Add(new HouseCropAlarmHouseResponse
  167. {
  168. houseSn = vm.CurrentDish.houseSn,
  169. startTime = vm.CurrentDish.startTime,
  170. });
  171. }
  172. CurrentHouseCropAlarmResult = vm.detailProvider.GetHouseCropAlarmApi(houseCropAlarmResponse).FirstOrDefault(x => x.houseSn == vm.CurrentDish.houseSn);
  173. if (vm == null || vm.CurrentDish == null || AppData.Instance.CurrentTlInfo == null) return;
  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.SetResourceReference(Button.ContentProperty, "0002");
  216. button.Content = item.NavName;
  217. button.FontWeight = FontWeights.Bold;
  218. button.FontSize = 28d;
  219. button.BorderThickness = new Thickness(0);
  220. button.Background = new SolidColorBrush(Colors.Transparent);
  221. button.Style = App.Current.FindResource("ButtonStyle1") as Style;
  222. if (i == 0)
  223. {
  224. button.Margin = new Thickness(0, 0, 0, 0);
  225. }
  226. else
  227. {
  228. button.Margin = new Thickness(8, 0, 0, 0);
  229. }
  230. button.Click += (s, e) =>
  231. {
  232. PlayerDispose();
  233. if (vm != null) vm.NavList.Clear();
  234. if (item is PatientManageViewModel patient)
  235. {
  236. patient.SetTLInfo(AppData.Instance.CurrentTlInfo);
  237. AppData.Instance.MainWindowViewModel.CurrentViewModle = patient;
  238. return;
  239. }
  240. AppData.Instance.MainWindowViewModel.CurrentViewModle = item;
  241. };
  242. TextBlock textBlock = new TextBlock();
  243. textBlock.Margin = new Thickness(8, 0, 0, 0);
  244. textBlock.VerticalAlignment = VerticalAlignment.Center;
  245. textBlock.FontWeight = FontWeights.Bold;
  246. textBlock.FontSize = 28d;
  247. textBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9B9B9B"));
  248. textBlock.Text = ">";
  249. _nav_StackPanel.Children.Add(button);
  250. _nav_StackPanel.Children.Add(textBlock);
  251. }
  252. }
  253. private void ExLog(Exception ex, string name)
  254. {
  255. AppData.Instance.LogService.ExceptionLog(ex, $"DetailView.{name}", LogEnum.RunException);
  256. }
  257. private void ErrorLog(string message, LogEnum logType)
  258. {
  259. AppData.Instance.LogService.TLLog($"DetailView.{message}", logType);
  260. }
  261. private void TimeLog(string message)
  262. {
  263. AppData.Instance.LogService.TLLog($"DetailView.{message}", LogEnum.TakeTime);
  264. }
  265. private void MessageShow(string message)
  266. {
  267. new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, message).Show();
  268. }
  269. private void Toast(bool success)
  270. {
  271. new ToastWindow(AppData.Instance.MainWindow, 1920, 65, success).Show();
  272. }
  273. /// <summary>
  274. /// 设备管理界面
  275. /// </summary>
  276. /// <param name="sender"></param>
  277. /// <param name="e"></param>
  278. private void Button_Click(object sender, RoutedEventArgs e)
  279. {
  280. AppData.Instance.MainWindowViewModel.CurrentViewModle = AppData.Instance.MainWindowViewModel.devManageViewModel;
  281. }
  282. /// <summary>
  283. /// 患者管理界面
  284. /// </summary>
  285. /// <param name="sender"></param>
  286. /// <param name="e"></param>
  287. private void Parien_Click(object sender, RoutedEventArgs e)
  288. {
  289. //AppData.Instance.MainWindowViewModel.patientManageViewModel.SetTLInfo(vm.tLInfo);
  290. //AppData.Instance.MainWindowViewModel.CurrentViewModle = AppData.Instance.MainWindowViewModel.patientManageViewModel;
  291. }
  292. /// <summary>
  293. /// 培养记录界面
  294. /// </summary>
  295. /// <param name="sender"></param>
  296. /// <param name="e"></param>
  297. private void Record_Click(object sender, RoutedEventArgs e)
  298. {
  299. AppData.Instance.MainWindowViewModel.CurrentViewModle = vm.ParentViewModel;
  300. }
  301. private void Mark_Click(object sender, RoutedEventArgs e)
  302. {
  303. vm.MarkEmbryo();
  304. }
  305. /// <summary>
  306. /// 图片查看界面
  307. /// </summary>
  308. /// <param name="sender"></param>
  309. /// <param name="e"></param>
  310. private void EmbryoPicClick(object sender, RoutedEventArgs e)
  311. {
  312. if (vm == null) return;
  313. if (vm.CurrentEmbryo != null)
  314. {
  315. AppData.Instance.MainWindowViewModel.CurrentViewModle = new DetailPicViewModel(vm, vm.MaxTotalLayer, vm.CurrentEmbryo.wellSn);
  316. }
  317. else
  318. {
  319. AppData.Instance.MainWindowViewModel.CurrentViewModle = new DetailPicViewModel(vm, vm.MaxTotalLayer, 1);
  320. }
  321. return;
  322. }
  323. /// <summary>
  324. /// 标记明细
  325. /// </summary>
  326. /// <param name="sender"></param>
  327. /// <param name="e"></param>
  328. private void ButtonBottomImage_Click(object sender, RoutedEventArgs e)
  329. {
  330. AppData.Instance.MainWindowViewModel.CurrentViewModle = new MarkDetailViewModel(vm, vm.CurrentDish.id);
  331. }
  332. private void Export_Click(object sender, RoutedEventArgs e)
  333. {
  334. AppData.Instance.MainWindowViewModel.MaskVisibility = true;
  335. new ExportBulkWindow(vm.CurrentDish, vm.DishPicAndVideoList, IsCleanVideo).ShowDialog();
  336. AppData.Instance.MainWindowViewModel.MaskVisibility = false;
  337. }
  338. /// <summary>
  339. /// 移植按钮
  340. /// </summary>
  341. /// <param name="sender"></param>
  342. /// <param name="e"></param>
  343. //private void EmbryoMove_Click(object sender, RoutedEventArgs e)
  344. //{
  345. // CloseCeLiang();
  346. // PlayerPause();
  347. // if (vm.CurrentEmbryo == null) return;
  348. // string tag = "移植";
  349. // string messInfo = $"是否确定对{vm.CurrentEmbryo.wellSn}号胚胎进行移植?";
  350. // int iconType = 2;
  351. // if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  352. // {
  353. // tag = "完成";
  354. // switch (vm.CurrentEmbryo.state)
  355. // {
  356. // case (int)EmbryoState.Freezing:
  357. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已冷冻";
  358. // iconType = 1;
  359. // break;
  360. // case (int)EmbryoState.Transplant:
  361. // messInfo = $"是否取消{vm.CurrentEmbryo.wellSn}号胚胎的移植标记?";
  362. // tag = "取消";
  363. // break;
  364. // case (int)EmbryoState.Cancellation:
  365. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已作废";
  366. // iconType = 3;
  367. // break;
  368. // case (int)EmbryoState.Delete:
  369. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已删除";
  370. // iconType = 4;
  371. // break;
  372. // }
  373. // }
  374. // EmbryoOp(tag, messInfo, iconType);
  375. // return;
  376. //}
  377. //string s1 = "Whether or not to";
  378. //string s2 = "embryo No.";
  379. //string s3 = "Whether or not to cancel the";
  380. //string s4 = "mark of embryo No.";
  381. //string s5 = "Embryo No.";
  382. //string s6 = "has been";
  383. string s1 = KeyToStringConvert.GetLanguageStringByKey("0521");
  384. string s2 = KeyToStringConvert.GetLanguageStringByKey("0522");
  385. string s3 = KeyToStringConvert.GetLanguageStringByKey("0523");
  386. string s4 = KeyToStringConvert.GetLanguageStringByKey("0524");
  387. string s5 = KeyToStringConvert.GetLanguageStringByKey("0525");
  388. string s6 = KeyToStringConvert.GetLanguageStringByKey("0526");
  389. string spaceString = KeyToStringConvert.GetLanguageStringByKey("0636");
  390. string haoString = KeyToStringConvert.GetLanguageStringByKey("0635");
  391. private void EmbryoMove_Click(object sender, RoutedEventArgs e)
  392. {
  393. CloseCeLiang();
  394. PlayerPause();
  395. if (vm.CurrentEmbryo == null) return;
  396. string tag = KeyToStringConvert.GetLanguageStringByKey("0041");
  397. string messInfo = GetMessageInfo(tag);
  398. int iconType = 2;
  399. if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  400. {
  401. tag = "完成";
  402. switch (vm.CurrentEmbryo.state)
  403. {
  404. case (int)EmbryoState.Freezing:
  405. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0040"));
  406. iconType = 1;
  407. break;
  408. case (int)EmbryoState.Transplant:
  409. messInfo = GetCancelMarkMessage();
  410. tag = "取消";
  411. break;
  412. case (int)EmbryoState.Cancellation:
  413. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0042"));
  414. iconType = 3;
  415. break;
  416. case (int)EmbryoState.Delete:
  417. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0043"));
  418. iconType = 4;
  419. break;
  420. }
  421. }
  422. EmbryoOp(tag, messInfo, iconType);
  423. return;
  424. }
  425. /// <summary>
  426. /// 冷冻按钮
  427. /// </summary>
  428. /// <param name="sender"></param>
  429. /// <param name="e"></param>
  430. private void EmbryoFree_Click(object sender, RoutedEventArgs e)
  431. {
  432. CloseCeLiang();
  433. PlayerPause();
  434. if (vm.CurrentEmbryo == null) return;
  435. int iconType = 1;
  436. string tag = KeyToStringConvert.GetLanguageStringByKey("0040");
  437. string messInfo = GetMessageInfo(tag);
  438. if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  439. {
  440. tag = "完成";
  441. switch (vm.CurrentEmbryo.state)
  442. {
  443. case (int)EmbryoState.Freezing:
  444. messInfo = GetCancelMarkMessage();
  445. tag = "取消";
  446. break;
  447. case (int)EmbryoState.Transplant:
  448. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0041"));
  449. iconType = 2;
  450. break;
  451. case (int)EmbryoState.Cancellation:
  452. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0042"));
  453. iconType = 3;
  454. break;
  455. case (int)EmbryoState.Delete:
  456. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0043"));
  457. iconType = 4;
  458. break;
  459. }
  460. }
  461. EmbryoOp(tag, messInfo, iconType);
  462. return;
  463. }
  464. //private void EmbryoFree_Click(object sender, RoutedEventArgs e)
  465. //{
  466. // CloseCeLiang();
  467. // PlayerPause();
  468. // if (vm.CurrentEmbryo == null) return;
  469. // int iconType = 1;
  470. // string tag = "冷冻";
  471. // string messInfo = $"是否确定对{vm.CurrentEmbryo.wellSn}号胚胎进行冷冻?";
  472. // if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  473. // {
  474. // tag = "完成";
  475. // switch (vm.CurrentEmbryo.state)
  476. // {
  477. // case (int)EmbryoState.Freezing:
  478. // messInfo = $"是否取消{vm.CurrentEmbryo.wellSn}号胚胎的冷冻标记?";
  479. // tag = "取消";
  480. // break;
  481. // case (int)EmbryoState.Transplant:
  482. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已移植";
  483. // iconType = 2;
  484. // break;
  485. // case (int)EmbryoState.Cancellation:
  486. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已作废";
  487. // iconType = 3;
  488. // break;
  489. // case (int)EmbryoState.Delete:
  490. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已删除";
  491. // iconType = 4;
  492. // break;
  493. // }
  494. // }
  495. // EmbryoOp(tag, messInfo, iconType);
  496. // return;
  497. //}
  498. /// <summary>
  499. /// 作废按钮
  500. /// </summary>
  501. /// <param name="sender"></param>
  502. /// <param name="e"></param>
  503. private void EmbryoInv_Click(object sender, RoutedEventArgs e)
  504. {
  505. CloseCeLiang();
  506. PlayerPause();
  507. if (vm.CurrentEmbryo == null) return;
  508. int iconType = 3;
  509. string tag = KeyToStringConvert.GetLanguageStringByKey("0042");
  510. string messInfo = GetMessageInfo(tag);
  511. if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  512. {
  513. tag = "完成";
  514. switch (vm.CurrentEmbryo.state)
  515. {
  516. case (int)EmbryoState.Freezing:
  517. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0040"));
  518. iconType = 1;
  519. break;
  520. case (int)EmbryoState.Transplant:
  521. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0041"));
  522. iconType = 2;
  523. break;
  524. case (int)EmbryoState.Cancellation:
  525. messInfo = GetCancelMarkMessage();
  526. tag = "取消";
  527. break;
  528. case (int)EmbryoState.Delete:
  529. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0043"));
  530. iconType = 4;
  531. break;
  532. }
  533. }
  534. EmbryoOp(tag, messInfo, iconType);
  535. return;
  536. }
  537. //private void EmbryoInv_Click(object sender, RoutedEventArgs e)
  538. //{
  539. // CloseCeLiang();
  540. // PlayerPause();
  541. // if (vm.CurrentEmbryo == null) return;
  542. // int iconType = 3;
  543. // string tag = "作废";
  544. // string messInfo = $"是否确定对{vm.CurrentEmbryo.wellSn}号胚胎进行作废?";
  545. // if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  546. // {
  547. // tag = "完成";
  548. // switch (vm.CurrentEmbryo.state)
  549. // {
  550. // case (int)EmbryoState.Freezing:
  551. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已冷冻";
  552. // iconType = 1;
  553. // break;
  554. // case (int)EmbryoState.Transplant:
  555. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已移植";
  556. // iconType = 2;
  557. // break;
  558. // case (int)EmbryoState.Cancellation:
  559. // messInfo = $"是否取消{vm.CurrentEmbryo.wellSn}号胚胎的作废标记?";
  560. // tag = "取消";
  561. // break;
  562. // case (int)EmbryoState.Delete:
  563. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已删除";
  564. // iconType = 4;
  565. // break;
  566. // }
  567. // }
  568. // EmbryoOp(tag, messInfo, iconType);
  569. // return;
  570. //}
  571. /// <summary>
  572. /// 删除按钮
  573. /// </summary>
  574. /// <param name="sender"></param>
  575. /// <param name="e"></param>
  576. private void EmbryoDel_Click(object sender, RoutedEventArgs e)
  577. {
  578. CloseCeLiang();
  579. PlayerPause();
  580. if (vm.CurrentEmbryo == null) return;
  581. int iconType = 4;
  582. string tag = KeyToStringConvert.GetLanguageStringByKey("0043");
  583. string messInfo = GetMessageInfo(tag);
  584. if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  585. {
  586. tag = "完成";
  587. switch (vm.CurrentEmbryo.state)
  588. {
  589. case (int)EmbryoState.Freezing:
  590. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0040"));
  591. iconType = 1;
  592. break;
  593. case (int)EmbryoState.Transplant:
  594. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0041"));
  595. iconType = 2;
  596. break;
  597. case (int)EmbryoState.Cancellation:
  598. messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0042"));
  599. iconType = 3;
  600. break;
  601. case (int)EmbryoState.Delete:
  602. messInfo = GetCancelMarkMessage();
  603. tag = "取消";
  604. break;
  605. }
  606. }
  607. EmbryoOp(tag, messInfo, iconType);
  608. return;
  609. }
  610. //private void EmbryoDel_Click(object sender, RoutedEventArgs e)
  611. //{
  612. // CloseCeLiang();
  613. // PlayerPause();
  614. // if (vm.CurrentEmbryo == null) return;
  615. // int iconType = 4;
  616. // string tag = "删除";
  617. // string messInfo = $"是否确定对{vm.CurrentEmbryo.wellSn}号胚胎进行删除?";
  618. // if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
  619. // {
  620. // tag = "完成";
  621. // switch (vm.CurrentEmbryo.state)
  622. // {
  623. // case (int)EmbryoState.Freezing:
  624. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已冷冻";
  625. // iconType = 1;
  626. // break;
  627. // case (int)EmbryoState.Transplant:
  628. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已移植";
  629. // iconType = 2;
  630. // break;
  631. // case (int)EmbryoState.Cancellation:
  632. // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已作废";
  633. // iconType = 3;
  634. // break;
  635. // case (int)EmbryoState.Delete:
  636. // messInfo = $"是否取消{vm.CurrentEmbryo.wellSn}号胚胎的删除标记?";
  637. // tag = "取消";
  638. // break;
  639. // }
  640. // }
  641. // EmbryoOp(tag, messInfo, iconType);
  642. // return;
  643. //}
  644. /// <summary>
  645. /// 结束按钮
  646. /// </summary>
  647. /// <param name="sender"></param>
  648. /// <param name="e"></param>
  649. private void EmbryoOver_Click(object sender, RoutedEventArgs e)
  650. {
  651. try
  652. {
  653. CloseCeLiang();
  654. PlayerPause();
  655. if (vm.CurrentDish == null || vm.CurrentDish.id == 0) return;
  656. string tag = KeyToStringConvert.GetLanguageStringByKey("0518");
  657. string messInfo = $"{KeyToStringConvert.GetLanguageStringByKey("0519")}?";
  658. if (vm.CurrentDish.state == 0)
  659. {
  660. messInfo = KeyToStringConvert.GetLanguageStringByKey("0520");
  661. tag = "完成";
  662. }
  663. EmbryoOp(tag, messInfo, 5);
  664. return;
  665. }
  666. catch (Exception ex)
  667. {
  668. ExLog(ex, "EmbryoOver_Click");
  669. }
  670. //try
  671. //{
  672. // CloseCeLiang();
  673. // PlayerPause();
  674. // if (vm.CurrentDish == null || vm.CurrentDish.id == 0) return;
  675. // string tag = "结束";
  676. // string messInfo = $"是否结束培养所有胚胎?";
  677. // if (vm.CurrentDish.state == 0)
  678. // {
  679. // messInfo = "当前舱室已结束培养";
  680. // tag = "完成";
  681. // }
  682. // EmbryoOp(tag, messInfo, 5);
  683. // return;
  684. //}
  685. //catch (Exception ex)
  686. //{
  687. // ExLog(ex, "EmbryoOver_Click");
  688. //}
  689. }
  690. private string GetMessageInfo(string stateString)
  691. {
  692. return $"{s1}{spaceString}{stateString}{spaceString}{s2}{vm.CurrentEmbryo.wellSn}{haoString}?";
  693. }
  694. private string GetMarkMessage(string stateString)
  695. {
  696. return $"{s5}{vm.CurrentEmbryo.wellSn}{spaceString}{s6}{spaceString}{stateString}";
  697. }
  698. private string GetCancelMarkMessage()
  699. {
  700. return $"{s3}{spaceString}{vm.CurrentEmbryo.wellSn}{haoString}?";
  701. }
  702. /// <summary>
  703. /// 胚胎操作
  704. /// </summary>
  705. private void EmbryoOp(string tag, string infoString, int type)
  706. {
  707. if (tag == "完成")
  708. {
  709. AppData.Instance.MainWindowViewModel.MaskVisibility = true;
  710. new MessagePrompt().ShowEmbryoOper(tag, infoString, type);
  711. AppData.Instance.MainWindowViewModel.MaskVisibility = false;
  712. return;
  713. }
  714. AppData.Instance.MainWindowViewModel.MaskVisibility = true;
  715. var rs = new MessagePrompt().ShowEmbryoOper(tag, infoString, type);
  716. AppData.Instance.MainWindowViewModel.MaskVisibility = false;
  717. if (rs != true) return;
  718. if (tag == "取消")
  719. {
  720. EmbryoMark((int)EmbryoState.None);
  721. return;
  722. }
  723. switch (type)
  724. {
  725. case 1:
  726. EmbryoMark((int)EmbryoState.Freezing);
  727. break;
  728. case 3:
  729. EmbryoMark((int)EmbryoState.Cancellation);
  730. break;
  731. case 2:
  732. EmbryoMark((int)EmbryoState.Transplant);
  733. break;
  734. case 4:
  735. EmbryoMark((int)EmbryoState.Delete);
  736. break;
  737. case 5:
  738. Finish();
  739. break;
  740. default:
  741. break;
  742. }
  743. }
  744. //private void EmbryoOp(string tag, string infoString, int type)
  745. //{
  746. // if (tag == "完成")
  747. // {
  748. // AppData.Instance.MainWindowViewModel.MaskVisibility = true;
  749. // new MessagePrompt().ShowEmbryoOper(tag, infoString, type);
  750. // AppData.Instance.MainWindowViewModel.MaskVisibility = false;
  751. // return;
  752. // }
  753. // AppData.Instance.MainWindowViewModel.MaskVisibility = true;
  754. // var rs = new MessagePrompt().ShowEmbryoOper(tag, infoString, type);
  755. // AppData.Instance.MainWindowViewModel.MaskVisibility = false;
  756. // if (rs == true)
  757. // {
  758. // switch (tag)
  759. // {
  760. // case "冷冻":
  761. // EmbryoMark((int)EmbryoState.Freezing);
  762. // break;
  763. // case "作废":
  764. // EmbryoMark((int)EmbryoState.Cancellation);
  765. // break;
  766. // case "移植":
  767. // EmbryoMark((int)EmbryoState.Transplant);
  768. // break;
  769. // case "删除":
  770. // EmbryoMark((int)EmbryoState.Delete);
  771. // break;
  772. // case "结束":
  773. // Finish();
  774. // break;
  775. // case "取消":
  776. // EmbryoMark((int)EmbryoState.None);
  777. // break;
  778. // default:
  779. // break;
  780. // }
  781. // }
  782. //}
  783. /// <summary>
  784. /// 结束培养
  785. /// </summary>
  786. /// <exception cref="NotImplementedException"></exception>
  787. private void Finish()
  788. {
  789. try
  790. {
  791. if (!vm.EndDish())
  792. {
  793. //MessageShow("结束培养失败");
  794. MessageShow(KeyToStringConvert.GetLanguageStringByKey("0318"));
  795. return;
  796. }
  797. vm.Back();
  798. //vm.CurrentDish = new Dish();
  799. //AppData.Instance.BackMainPage();
  800. }
  801. catch (Exception ex)
  802. {
  803. ExLog(ex, "Finish");
  804. }
  805. }
  806. private void EmbryoMark(int embryoState)
  807. {
  808. try
  809. {
  810. if (!vm.MarkEmbryo(embryoState))
  811. {
  812. //MessageShow("胚胎标记失败");
  813. MessageShow(KeyToStringConvert.GetLanguageStringByKey("0319"));
  814. return;
  815. }
  816. DateTime ct = DateTime.Now;
  817. vm.CurrentEmbryo.state = embryoState;
  818. vm.CurrentEmbryo.stateTime = ct.ToString("yyyy-MM-dd HH:mm:ss");
  819. SetEmbryoState(vm.CurrentEmbryo.wellSn, vm.CurrentEmbryo.state);
  820. Toast(true);
  821. //AppData.Instance.MainPageView.SetMainEmbryoState(vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.wellSn, vm.CurrentEmbryo.state);
  822. }
  823. catch (Exception ex)
  824. {
  825. ExLog(ex, "EmbryoMark");
  826. }
  827. }
  828. /// <summary>
  829. /// 播放暂停
  830. /// </summary>
  831. /// <param name="sender"></param>
  832. /// <param name="e"></param>
  833. private void Video_Click(object sender, RoutedEventArgs e)
  834. {
  835. CloseCeLiang();
  836. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  837. {
  838. if (PlayerState == PlayerStateEnum.Playing)
  839. {
  840. PlayerPause();
  841. }
  842. else
  843. {
  844. newCurrentTime = -1;
  845. if (PlayerPlay())
  846. {
  847. //this._preview.Visibility = Visibility.Hidden;
  848. this.Canvas_preview.Visibility = Visibility.Hidden;
  849. vm.CurrentFocal = 0;
  850. }
  851. else
  852. {
  853. SetPreviewNoVideo();
  854. }
  855. }
  856. }
  857. else
  858. {
  859. SetPreviewNoVideo();
  860. }
  861. }
  862. /// <summary>
  863. /// 上一帧
  864. /// </summary>
  865. /// <param name="sender"></param>
  866. /// <param name="e"></param>
  867. private void PreviousFrame_Click(object sender, RoutedEventArgs e)
  868. {
  869. CloseCeLiang();
  870. if (vm == null || vm.CurrentWellLayerPicAndVideo == null) return;
  871. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  872. {
  873. PlayerPause();
  874. PlayerLastFrame(vm.CurrentWellLayerPicAndVideo.fps);
  875. //this._preview.Visibility = Visibility.Hidden;
  876. this.Canvas_preview.Visibility = Visibility.Hidden;
  877. }
  878. }
  879. /// <summary>
  880. /// 下一帧
  881. /// </summary>
  882. /// <param name="sender"></param>
  883. /// <param name="e"></param>
  884. private void NextFrame_Click(object sender, RoutedEventArgs e)
  885. {
  886. CloseCeLiang();
  887. if (vm == null || vm.CurrentWellLayerPicAndVideo == null) return;
  888. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  889. {
  890. PlayerPause();
  891. PlayerNextFrame(vm.CurrentWellLayerPicAndVideo.fps);
  892. //this._preview.Visibility = Visibility.Hidden;
  893. this.Canvas_preview.Visibility = Visibility.Hidden;
  894. }
  895. }
  896. /// <summary>
  897. /// 上一层
  898. /// </summary>
  899. /// <param name="sender"></param>
  900. /// <param name="e"></param>
  901. private void BigFocus_Click(object sender, RoutedEventArgs e)
  902. {
  903. PlayerPause();
  904. CloseCeLiang();
  905. if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return;
  906. if (vm.CurrentEmbryo == null) return;
  907. if (vm.CurrentWellLayerPicAndVideo != null) ChangeFocalNoVideo(true);
  908. //if (vm.CurrentWellLayerPicAndVideo != null) if (!string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl)) ChangeFocalNoVideo(true);
  909. // else ChangeImageFocal(true);
  910. }
  911. /// <summary>
  912. /// 下一层
  913. /// </summary>
  914. /// <param name="sender"></param>
  915. /// <param name="e"></param>
  916. private void SmallFocus_Click(object sender, RoutedEventArgs e)
  917. {
  918. PlayerPause();
  919. CloseCeLiang();
  920. if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return;
  921. if (vm.CurrentEmbryo == null) return;
  922. if (vm.CurrentWellLayerPicAndVideo != null) ChangeFocalNoVideo(false);
  923. //if (vm.CurrentWellLayerPicAndVideo != null) if (!string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl)) ChangeFocalNoVideo(false);
  924. // else ChangeImageFocal(false);
  925. }
  926. /// <summary>
  927. /// 设置倍率
  928. /// </summary>
  929. /// <param name="sender"></param>
  930. /// <param name="e"></param>
  931. private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  932. {
  933. if (vm == null) return;
  934. PlayerSetSpeedRatio(vm.SelectedFps.Key);
  935. if (this._fps_Popup.IsOpen)
  936. this._fps_Popup.IsOpen = false;
  937. }
  938. /// <summary>
  939. /// 快捷定位
  940. /// </summary>
  941. /// <param name="minHour"></param>
  942. /// <param name="maxHour"></param>
  943. /// <param name="quickName"></param>
  944. private void QuickButton_Click(int minHour, int maxHour, string quickName)
  945. {
  946. try
  947. {
  948. CloseCeLiang();
  949. PlayerPause();
  950. if (vm.CurrentWellLayerPicAndVideo == null || vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
  951. {
  952. //MessageShow($"当前胚胎还未发育到{quickName}阶段");
  953. MessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0316")} {quickName}");
  954. return;
  955. }
  956. var lastPic = vm.CurrentWellLayerPicAndVideo.videoPictures.Last();
  957. if (minHour > lastPic.developTime)
  958. {
  959. //MessageShow($"当前胚胎还未发育到{quickName}阶段");
  960. MessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0316")} {quickName}");
  961. return;
  962. }
  963. int picCount = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
  964. for (int i = 0; i < picCount; i++)
  965. {
  966. var item = vm.CurrentWellLayerPicAndVideo.videoPictures[i];
  967. if (item.developTime >= minHour)
  968. {
  969. if (IsCleanVideo)
  970. {
  971. this._preview.Visibility = Visibility.Visible;
  972. vm.VideoCurrentTime = i + 1;
  973. this._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{item.imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  974. }
  975. else
  976. {
  977. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  978. {
  979. this._preview.Visibility = Visibility.Hidden;
  980. double pro = (i * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps));
  981. SetTimeProgressbarProgressValue(pro);
  982. SetPlayerPosition(pro);
  983. }
  984. else
  985. {
  986. this._preview.Visibility = Visibility.Visible;
  987. vm.VideoCurrentTime = i + 1;
  988. this._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{item.imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  989. }
  990. }
  991. break;
  992. }
  993. }
  994. }
  995. catch (Exception ex)
  996. {
  997. ExLog(ex, $"QuickButton_Click");
  998. }
  999. }
  1000. /// <summary>
  1001. /// 播放速率调整
  1002. /// </summary>
  1003. /// <param name="sender"></param>
  1004. /// <param name="e"></param>
  1005. private void Fps_MouseUp(object sender, MouseButtonEventArgs e)
  1006. {
  1007. CloseCeLiang();
  1008. if (this._fps_Popup.IsOpen) this._fps_Popup.IsOpen = false;
  1009. else this._fps_Popup.IsOpen = true;
  1010. }
  1011. private void CeLiang_Click(object sender, RoutedEventArgs e)
  1012. {
  1013. PlayerPause();
  1014. if (vm.CurrentEmbryo == null)
  1015. {
  1016. //MessageBox.Show("embryo为空");
  1017. return;
  1018. }
  1019. int developTime = 0;
  1020. if (vm.CurrentPic == null)
  1021. {
  1022. if (vm.CurrentWellDishPicAndVideo != null && vm.CurrentWellDishPicAndVideo.focus)
  1023. {
  1024. developTime = vm.CurrentWellDishPicAndVideo.developTime;
  1025. }
  1026. else
  1027. {
  1028. //MessageBox.Show("CurrentPic为空");
  1029. return;
  1030. }
  1031. }
  1032. else
  1033. {
  1034. developTime = vm.CurrentPic.developTime;
  1035. }
  1036. if (isCeLiang)
  1037. {
  1038. count = 0;
  1039. this._ceLiang_Border.Visibility = Visibility.Hidden;
  1040. this.b1.Text = "";
  1041. this.canvas1.Children.Remove(myLine);
  1042. this.canvas1.Children.Remove(starEllipse);
  1043. this.canvas1.Children.Remove(endEllipse);
  1044. isCeLiang = false;
  1045. MeaUIShow(false);
  1046. }
  1047. else
  1048. {
  1049. isCeLiang = true;
  1050. MeaUIShow(true);
  1051. }
  1052. DetailPicInfo detailPicInfo = null;
  1053. if (vm.CurrentPic == null)
  1054. {
  1055. detailPicInfo = vm.detailProvider.GetDetailPicInfoApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, 9999, developTime);
  1056. }
  1057. else
  1058. {
  1059. detailPicInfo = vm.detailProvider.GetDetailPicInfoApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, vm.CurrentFocal, developTime);
  1060. }
  1061. if (detailPicInfo != null) PicRadius = detailPicInfo.radius;
  1062. Log4netHelper.WriteLog($"{vm.CurrentEmbryo.id}:{PicRadius}");
  1063. e.Handled = true;
  1064. }
  1065. private void Button_Click_1(object sender, RoutedEventArgs e)
  1066. {
  1067. if (vm == null || vm.CurrentWellLayerPicAndVideo == null || string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) || vm.CurrentWellLayerPicAndVideo.videoUrl == AppData.Instance.CleanVideoString) return;
  1068. string url = $"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}";
  1069. TimeLog($"开始下载:{url}");
  1070. Stopwatch stopwatch = Stopwatch.StartNew();
  1071. AppData.Instance.HttpServiceCall.DownLoadFileAsync(url, $"C:\\TLData\\ivf_tl_Manage_logs\\{DateTime.Now.ToString("HH_mm")}.mp4").GetAwaiter().GetResult();
  1072. TimeLog($"下载耗时:{stopwatch.ElapsedMilliseconds}毫秒、{stopwatch.Elapsed.TotalSeconds}秒");
  1073. }
  1074. int PicRadius = 0;
  1075. bool isMax = false;
  1076. double maxWidth = 610;
  1077. double maxLeft = 50;
  1078. double minWidth = 330;
  1079. double minLeft = 190;
  1080. int count = 0;
  1081. bool isCeLiang = false;
  1082. Line myLine = null;
  1083. Ellipse starEllipse = null;
  1084. Ellipse endEllipse = null;
  1085. private void PreviewMouseDownEvent(object sender, MouseButtonEventArgs e)
  1086. {
  1087. if (!this.IsLoaded) return;
  1088. if (!isCeLiang)
  1089. {
  1090. if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
  1091. {
  1092. if (isMax == false)
  1093. {
  1094. this.nextEmbryoButton.Visibility = Visibility.Visible;
  1095. this.lastEmbryoButton.Visibility = Visibility.Visible;
  1096. //_preview.Width = maxWidth;
  1097. //_preview.Height = maxWidth;
  1098. _mask.Width = maxWidth;
  1099. _mask.Height = maxWidth;
  1100. mediaElementPlayer.Width = maxWidth;
  1101. mediaElementPlayer.Height = maxWidth;
  1102. canvas1.Width = maxWidth;
  1103. canvas1.Height = maxWidth;
  1104. isMax = true;
  1105. //Canvas.SetLeft(_preview, maxLeft);
  1106. //Canvas.SetTop(_preview, maxLeft);
  1107. Canvas.SetLeft(mediaElementPlayer, maxLeft);
  1108. Canvas.SetTop(mediaElementPlayer, maxLeft);
  1109. Canvas.SetLeft(_mask, maxLeft);
  1110. Canvas.SetTop(_mask, maxLeft);
  1111. Canvas.SetLeft(canvas1, maxLeft);
  1112. Canvas.SetTop(canvas1, maxLeft);
  1113. Panel.SetZIndex(mediaElementPlayer, 16);
  1114. //Panel.SetZIndex(_preview, 17);
  1115. Panel.SetZIndex(canvas1, 18);
  1116. }
  1117. else
  1118. {
  1119. this.nextEmbryoButton.Visibility = Visibility.Hidden;
  1120. this.lastEmbryoButton.Visibility = Visibility.Hidden;
  1121. //_preview.Width = minWidth;
  1122. //_preview.Height = minWidth;
  1123. _mask.Width = minWidth;
  1124. _mask.Height = minWidth;
  1125. mediaElementPlayer.Width = minWidth;
  1126. mediaElementPlayer.Height = minWidth;
  1127. canvas1.Width = minWidth;
  1128. canvas1.Height = minWidth;
  1129. isMax = false;
  1130. //Canvas.SetLeft(_preview, minLeft);
  1131. //Canvas.SetTop(_preview, minLeft);
  1132. Canvas.SetLeft(mediaElementPlayer, minLeft);
  1133. Canvas.SetTop(mediaElementPlayer, minLeft);
  1134. Canvas.SetLeft(_mask, minLeft);
  1135. Canvas.SetTop(_mask, minLeft);
  1136. Canvas.SetLeft(canvas1, minLeft);
  1137. Canvas.SetTop(canvas1, minLeft);
  1138. Panel.SetZIndex(mediaElementPlayer, 8);
  1139. //Panel.SetZIndex(_preview, 9);
  1140. Panel.SetZIndex(canvas1, 10);
  1141. }
  1142. SetLoad(isMax);
  1143. SetPreView(isMax);
  1144. }
  1145. e.Handled = true;
  1146. return;
  1147. }
  1148. else
  1149. {
  1150. switch (count)
  1151. {
  1152. case 0:
  1153. myLine = new Line();
  1154. myLine.X1 = e.GetPosition(this.canvas1).X;
  1155. myLine.Y1 = e.GetPosition(this.canvas1).Y;
  1156. starEllipse = CreateEllipse(myLine.X1, myLine.Y1);
  1157. this.canvas1.Children.Add(starEllipse);
  1158. count++;
  1159. break;
  1160. case 1:
  1161. myLine.X2 = e.GetPosition(canvas1).X;
  1162. myLine.Y2 = e.GetPosition(canvas1).Y;
  1163. endEllipse = CreateEllipse(myLine.X2, myLine.Y2);
  1164. this.canvas1.Children.Add(endEllipse);
  1165. myLine.HorizontalAlignment = HorizontalAlignment.Left;
  1166. myLine.VerticalAlignment = VerticalAlignment.Center;
  1167. myLine.StrokeDashArray = new DoubleCollection(new List<double> { 8d, 4d });
  1168. myLine.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFB000"));
  1169. this.canvas1.Children.Add(myLine);
  1170. double offsetX = myLine.X2 - myLine.X1;
  1171. double offsetY = myLine.Y2 - myLine.Y1;
  1172. _ceLiang_Border.SetValue(Canvas.LeftProperty, myLine.X1 + offsetX / 2 - 46.5);
  1173. _ceLiang_Border.SetValue(Canvas.TopProperty, myLine.Y1 + offsetY / 2 - 50);
  1174. RotateTransform rotateTransform = new RotateTransform();
  1175. rotateTransform.Angle = GetAngle(myLine.X1, myLine.Y1, myLine.X2, myLine.Y2);
  1176. _ceLiang_Border.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5);
  1177. _ceLiang_Border.RenderTransform = rotateTransform;
  1178. double fangDaBeiShu = 8.5778;//放大倍数
  1179. double xiangYuan = 2.2;
  1180. double picWidth = isMax ? 610d : 330d;
  1181. //if (vm != null && vm.CurrentPicZhen != null) picWidth = (double)(vm.CurrentPicZhen.radius * 2);
  1182. if (PicRadius != 0) picWidth = (double)(PicRadius * 2.0);
  1183. int meaValue = (int)(((Math.Sqrt(Math.Pow(offsetX, 2.0) + Math.Pow(offsetY, 2.0)) * xiangYuan) / fangDaBeiShu) / ((isMax ? 610.00 : 330.00) / picWidth)) + AppData.Instance.Measurement;
  1184. b1.Text = $"{meaValue}µm";
  1185. foreach (var item in vm.MeasurementList)
  1186. {
  1187. if (item.MeasurementValue == -1)
  1188. {
  1189. item.MeasurementValue = meaValue;
  1190. break;
  1191. }
  1192. }
  1193. //var 线条长度 = Math.Sqrt(Math.Pow(offsetX, 2.0) + Math.Pow(offsetY, 2.0));
  1194. //var 线条长度经过像元 = (线条长度 * xiangYuan);
  1195. //var 控件放大倍数 = ((isMax ? 610d : 330d) / picWidth);
  1196. //var aaaa = 线条长度经过像元 / fangDaBeiShu/ 控件放大倍数;
  1197. this._ceLiang_Border.Visibility = Visibility.Visible;
  1198. count++;
  1199. break;
  1200. case 2:
  1201. count = 0;
  1202. this._ceLiang_Border.Visibility = Visibility.Hidden;
  1203. this.canvas1.Children.Remove(myLine);
  1204. this.canvas1.Children.Remove(starEllipse);
  1205. this.canvas1.Children.Remove(endEllipse);
  1206. myLine = new Line();
  1207. myLine.X1 = e.GetPosition(canvas1).X;
  1208. myLine.Y1 = e.GetPosition(canvas1).Y;
  1209. starEllipse = CreateEllipse(myLine.X1, myLine.Y1);
  1210. this.canvas1.Children.Add(starEllipse);
  1211. count++;
  1212. break;
  1213. default:
  1214. break;
  1215. }
  1216. e.Handled = true;
  1217. return;
  1218. }
  1219. e.Handled = true;
  1220. }
  1221. private void SetLoad(bool isMax)
  1222. {
  1223. if (isMax)
  1224. {
  1225. Image_Load.Width = maxWidth;
  1226. Image_Load.Height = maxWidth;
  1227. Canvas_Load.Width = maxWidth;
  1228. Canvas_Load.Height = maxWidth;
  1229. TextBlock_Load.Width = maxWidth;
  1230. TextBlock_Load.FontSize = 38;
  1231. Canvas.SetTop(TextBlock_Load, 361);
  1232. Canvas.SetLeft(Canvas_Load, maxLeft);
  1233. Canvas.SetTop(Canvas_Load, maxLeft);
  1234. Panel.SetZIndex(Canvas_Load, 15);
  1235. }
  1236. else
  1237. {
  1238. Image_Load.Width = minWidth;
  1239. Image_Load.Height = minWidth;
  1240. Canvas_Load.Width = minWidth;
  1241. Canvas_Load.Height = minWidth;
  1242. TextBlock_Load.Width = minWidth;
  1243. TextBlock_Load.FontSize = 20;
  1244. Canvas.SetTop(TextBlock_Load, 198);
  1245. Canvas.SetLeft(Canvas_Load, minLeft);
  1246. Canvas.SetTop(Canvas_Load, minLeft);
  1247. Panel.SetZIndex(Canvas_Load, 7);
  1248. }
  1249. }
  1250. private void SetPreView(bool isMax)
  1251. {
  1252. if (isMax)
  1253. {
  1254. _preview.Width = maxWidth;
  1255. _preview.Height = maxWidth;
  1256. Canvas_preview.Width = maxWidth;
  1257. Canvas_preview.Height = maxWidth;
  1258. TextBlock_preview.Width = maxWidth;
  1259. TextBlock_preview.FontSize = 38;
  1260. Canvas.SetTop(TextBlock_preview, 361);
  1261. Canvas.SetLeft(Canvas_preview, maxLeft);
  1262. Canvas.SetTop(Canvas_preview, maxLeft);
  1263. Panel.SetZIndex(Canvas_preview, 17);
  1264. }
  1265. else
  1266. {
  1267. _preview.Width = minWidth;
  1268. _preview.Height = minWidth;
  1269. Canvas_preview.Width = minWidth;
  1270. Canvas_preview.Height = minWidth;
  1271. TextBlock_preview.Width = minWidth;
  1272. TextBlock_preview.FontSize = 20;
  1273. Canvas.SetTop(TextBlock_preview, 198);
  1274. Canvas.SetLeft(Canvas_preview, minLeft);
  1275. Canvas.SetTop(Canvas_preview, minLeft);
  1276. Panel.SetZIndex(Canvas_preview, 9);
  1277. }
  1278. }
  1279. private void Canvas_PreviewMouseDown(object sender, MouseButtonEventArgs e)
  1280. {
  1281. if (e.Source is ButtonBottomImage bottomImage && bottomImage.Name == "_celiang_ButtonBottomImage")
  1282. {
  1283. e.Handled = true;
  1284. return;
  1285. }
  1286. if (e.Source is Canvas canvas && canvas.Name == "canvas1")
  1287. {
  1288. e.Handled = true;
  1289. return;
  1290. }
  1291. CloseCeLiang();
  1292. }
  1293. private Ellipse CreateEllipse(double x, double y)
  1294. {
  1295. Ellipse ellipse = new Ellipse();
  1296. ellipse.Width = 10;
  1297. ellipse.Height = 10;
  1298. ellipse.Fill = new SolidColorBrush(Colors.Red);
  1299. ellipse.SetValue(Canvas.LeftProperty, x - (10 / 2));
  1300. ellipse.SetValue(Canvas.TopProperty, y - (10 / 2));
  1301. ellipse.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFB000"));
  1302. return ellipse;
  1303. }
  1304. private double GetAngle(double x1, double y1, double x2, double y2)
  1305. {
  1306. double angle = Math.Atan2(y2 - y1, x2 - x1);
  1307. double degrees = angle * 180 / Math.PI;
  1308. double normalizedAngle = degrees % 180;
  1309. if (normalizedAngle > 90)
  1310. {
  1311. normalizedAngle -= 180;
  1312. }
  1313. else if (normalizedAngle < -90)
  1314. {
  1315. normalizedAngle += 180;
  1316. }
  1317. return normalizedAngle;
  1318. }
  1319. private void CloseCeLiang()
  1320. {
  1321. if (isCeLiang)
  1322. {
  1323. PicRadius = 0;
  1324. count = 0;
  1325. this._ceLiang_Border.Visibility = Visibility.Hidden;
  1326. this.b1.Text = "";
  1327. this.canvas1.Children.Remove(myLine);
  1328. this.canvas1.Children.Remove(starEllipse);
  1329. this.canvas1.Children.Remove(endEllipse);
  1330. isCeLiang = false;
  1331. MeaUIShow(false);
  1332. }
  1333. }
  1334. private void LastEmbryo_Click(object sender, RoutedEventArgs e)
  1335. {
  1336. int index = selectedIndex;
  1337. if (index == 0)
  1338. {
  1339. index = 15;
  1340. }
  1341. else
  1342. {
  1343. index--;
  1344. }
  1345. SelectIndex(index);
  1346. CloseCeLiang();
  1347. PlayerPause();
  1348. ChangeEmbryo(index + 1);
  1349. }
  1350. private void NextEmbryo_Click(object sender, RoutedEventArgs e)
  1351. {
  1352. int index = selectedIndex;
  1353. if (index == 15)
  1354. {
  1355. index = 0;
  1356. }
  1357. else
  1358. {
  1359. index++;
  1360. }
  1361. SelectIndex(index);
  1362. CloseCeLiang();
  1363. PlayerPause();
  1364. ChangeEmbryo(index + 1);
  1365. }
  1366. private void ListBox_ManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
  1367. {
  1368. e.Handled = true;
  1369. }
  1370. private void Auto_Click(object sender, RoutedEventArgs e)
  1371. {
  1372. if (vm == null) return;
  1373. var list = vm.CurrentDish.embryoList.Where(x => x.state == (int)EmbryoState.None).ToList();
  1374. //var list = vm.CurrentDish.embryoList.ToList();
  1375. if (!list.Any())
  1376. {
  1377. //new ToastMessageWindow(AppData.Instance.MainWindow, $"暂无胚胎需要对焦预览").Show();
  1378. new ToastMessageWindow(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("0320")).Show();
  1379. return;
  1380. }
  1381. AppData.Instance.MainWindowViewModel.MaskVisibility = true;
  1382. new AutoFocusWindow(vm.CurrentDish.tlSn, vm.CurrentDish.houseSn, list, vm.CurrentEmbryo).ShowDialog();
  1383. AppData.Instance.MainWindowViewModel.MaskVisibility = false;
  1384. return;
  1385. }
  1386. private void AverageValue_Click(object sender, RoutedEventArgs e)
  1387. {
  1388. int allValue = 0;
  1389. int count = 0;
  1390. foreach (var item in vm.MeasurementList)
  1391. {
  1392. if (item.MeasurementValue != -1)
  1393. {
  1394. allValue += item.MeasurementValue;
  1395. count++;
  1396. }
  1397. }
  1398. if (count == 0)
  1399. {
  1400. MessageShow("至少满足一次测量");
  1401. return;
  1402. }
  1403. this.averageValueText.Text = $"{((double)allValue / count).ToString("f2")}";
  1404. }
  1405. private void ClearMea_Click(object sender, RoutedEventArgs e)
  1406. {
  1407. if (this.meaListBox.SelectedItem == null) return;
  1408. if (this.meaListBox.SelectedItem is MeasurementEntity mea)
  1409. {
  1410. mea.MeasurementValue = -1;
  1411. }
  1412. }
  1413. private void MeaUIShow(bool b)
  1414. {
  1415. if (b)
  1416. {
  1417. this.meaUI1.Visibility = Visibility.Visible;
  1418. //this.meaUI2.Visibility = Visibility.Visible;
  1419. //this.meaUI3.Visibility = Visibility.Visible;
  1420. }
  1421. else
  1422. {
  1423. this.meaUI1.Visibility = Visibility.Hidden;
  1424. //this.meaUI2.Visibility = Visibility.Hidden;
  1425. //this.meaUI3.Visibility = Visibility.Hidden;
  1426. }
  1427. }
  1428. private void ClearMeasurementList()
  1429. {
  1430. this.averageValueText.Text = "";
  1431. if (vm == null || vm.MeasurementList == null) return;
  1432. foreach (var item in vm.MeasurementList)
  1433. {
  1434. item.MeasurementValue = -1;
  1435. }
  1436. }
  1437. #region 初始化
  1438. private void InitQuickButton()
  1439. {
  1440. this._quick_StackPanel.Children.Clear();
  1441. if (vm == null || vm.QuickButtons == null || !vm.QuickButtons.Any())
  1442. {
  1443. //this._quick_TextBlock.Visibility = Visibility.Hidden;
  1444. return;
  1445. }
  1446. bool isFirst = true;
  1447. var newList = vm.QuickButtons.OrderBy(x => x.orderNum).Take(7);
  1448. foreach (var item in newList)
  1449. {
  1450. ButtonLeftImage buttonLeftImage = new ButtonLeftImage()
  1451. {
  1452. IconWidth = 40,
  1453. IconHeight = 40,
  1454. IconMargin = new Thickness(0, 0, 5, 0),
  1455. Content = item.buttonName,
  1456. FontWeight = FontWeights.Medium,
  1457. FontSize = 24,
  1458. Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9B9B9B")),
  1459. MouseOverForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D4D4D")),
  1460. IconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailQuickIcon.png", UriKind.Absolute)),
  1461. MouseOverIconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailQuickMouseOverIcon.png", UriKind.Absolute)),
  1462. };
  1463. if (!isFirst) buttonLeftImage.Margin = new Thickness(20, 0, 0, 0);
  1464. if (isFirst) isFirst = false;
  1465. buttonLeftImage.Click += (sender, args) =>
  1466. {
  1467. QuickButton_Click(item.minHour * 60, item.maxHour * 60, item.buttonName);
  1468. };
  1469. this._quick_StackPanel.Children.Add(buttonLeftImage);
  1470. }
  1471. }
  1472. private void InitCustom()
  1473. {
  1474. try
  1475. {
  1476. EllipseGeometry ellipseGeometry = new EllipseGeometry(new Point(imageRadius, imageRadius), imageRadius, imageRadius);
  1477. Embryo itemEmbryo = null;
  1478. for (int i = 0; i < ellipseCount; i++)
  1479. {
  1480. TextBlock textBlock = new TextBlock();
  1481. Image border = new Image();
  1482. Image image = new Image();
  1483. Image opImage = new Image();
  1484. this._canvas.Children.Add(textBlock);
  1485. this._canvas.Children.Add(border);
  1486. this._canvas.Children.Add(image);
  1487. this._canvas.Children.Add(opImage);
  1488. Panel.SetZIndex(textBlock, 11);
  1489. Panel.SetZIndex(border, 12);
  1490. Panel.SetZIndex(image, 13);
  1491. Panel.SetZIndex(opImage, 14);
  1492. textBlock.FontWeight = FontWeights.Medium;
  1493. textBlock.Foreground = deaeatForeground;
  1494. textBlock.FontSize = 14;
  1495. textBlock.Width = 16;
  1496. textBlock.Height = 22;
  1497. textBlock.Text = $"{i + 1}";
  1498. textBlock.TextAlignment = TextAlignment.Center;
  1499. textBlock.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - 7);
  1500. textBlock.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - 11);
  1501. TextBlockList.Add(textBlock);
  1502. ImageList.Add(border);
  1503. PicImageList.Add(image);
  1504. border.Width = backImageRadius * 2;
  1505. border.Height = backImageRadius * 2;
  1506. border.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * backImageBigRadius - backImageRadius);
  1507. border.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * backImageBigRadius - backImageRadius);
  1508. opImage.Width = operRaius * 2;
  1509. opImage.Height = operRaius * 2;
  1510. opImage.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * operBigRadius - operRaius);
  1511. opImage.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * operBigRadius - operRaius);
  1512. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState1Icon.png", UriKind.Absolute));
  1513. OperImageList.Add(opImage);
  1514. image.Width = imageRadius * 2;
  1515. image.Height = imageRadius * 2;
  1516. image.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius);
  1517. image.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius);
  1518. image.SetValue(Image.ClipProperty, ellipseGeometry);
  1519. image.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryo.png", UriKind.Absolute));
  1520. image.Tag = i;
  1521. image.MouseUp += (s, e) =>
  1522. {
  1523. if (!this.IsLoaded) return;
  1524. if (!(s is Image source)) return;
  1525. int index = (int)source.Tag;
  1526. if (selectedIndex == index) return;
  1527. SelectIndex(index);
  1528. CloseCeLiang();
  1529. PlayerPause();
  1530. ChangeEmbryo(index + 1);
  1531. };
  1532. var aa = vm.CurrentDish;
  1533. itemEmbryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == i + 1);
  1534. if (itemEmbryo == null)//无胚胎
  1535. {
  1536. opImage.Visibility = Visibility.Hidden;
  1537. textBlock.Tag = 0;
  1538. textBlock.Foreground = noEmbryoForeground;
  1539. border.Tag = 0;
  1540. border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryoBackground.png", UriKind.Absolute));
  1541. continue;
  1542. }
  1543. image.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryo1.png", UriKind.Absolute));
  1544. switch ((EmbryoState)itemEmbryo.state)
  1545. {
  1546. case EmbryoState.Freezing: //冷冻
  1547. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState1Icon.png", UriKind.Absolute));
  1548. break;
  1549. case EmbryoState.Transplant://移植
  1550. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState2Icon.png", UriKind.Absolute));
  1551. break;
  1552. case EmbryoState.Cancellation://作废
  1553. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState3Icon.png", UriKind.Absolute));
  1554. break;
  1555. case EmbryoState.Delete://删除
  1556. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState4Icon.png", UriKind.Absolute));
  1557. break;
  1558. default:
  1559. opImage.Visibility = Visibility.Hidden;
  1560. break;
  1561. }
  1562. var currentData = vm.DishPicAndVideoList.FirstOrDefault(x => x.wellSn == itemEmbryo.wellSn);
  1563. if (currentData == null || string.IsNullOrEmpty(currentData.lastPicture))//无图片
  1564. {
  1565. textBlock.Tag = 1;
  1566. textBlock.Foreground = noPicForeground;
  1567. border.Tag = 1;
  1568. border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png", UriKind.Absolute));
  1569. continue;
  1570. }
  1571. string borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png";
  1572. int borderTag = 3;
  1573. switch ((EmbryoState)itemEmbryo.state)
  1574. {
  1575. case EmbryoState.End:
  1576. case EmbryoState.None:
  1577. borderTag = 2;
  1578. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png";
  1579. break;
  1580. case EmbryoState.Freezing: //冷冻
  1581. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState1Icon.png";
  1582. break;
  1583. case EmbryoState.Transplant://移植
  1584. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState2Icon.png";
  1585. break;
  1586. case EmbryoState.Cancellation://作废
  1587. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState3Icon.png";
  1588. break;
  1589. case EmbryoState.Delete://删除
  1590. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState4Icon.png";
  1591. break;
  1592. }
  1593. textBlock.Tag = 2;
  1594. textBlock.Foreground = deaeatForeground;
  1595. border.Tag = borderTag;
  1596. border.Source = new BitmapImage(new Uri(borderSource, UriKind.Absolute));
  1597. }
  1598. SelectIndex(0);
  1599. }
  1600. catch (Exception)
  1601. {
  1602. throw;
  1603. }
  1604. }
  1605. private void EmbryoAlarmEvent(int wellsn, int stateAlarm)
  1606. {
  1607. try
  1608. {
  1609. Dispatcher.Invoke(() => { SetWellImage(wellsn - 1, selectedIndex); });
  1610. }
  1611. catch (Exception ex)
  1612. {
  1613. }
  1614. }
  1615. private void InitCustomNew()
  1616. {
  1617. try
  1618. {
  1619. EllipseGeometry ellipseGeometry = new EllipseGeometry(new Point(imageRadius, imageRadius), imageRadius, imageRadius);
  1620. Embryo itemEmbryo = null;
  1621. for (int i = 0; i < ellipseCount; i++)
  1622. {
  1623. TextBlock textBlock = new TextBlock();
  1624. Image border = new Image();
  1625. Image image = new Image();
  1626. Image opImage = new Image();
  1627. this._canvas.Children.Add(textBlock);
  1628. this._canvas.Children.Add(border);
  1629. this._canvas.Children.Add(image);
  1630. this._canvas.Children.Add(opImage);
  1631. TextBlockList.Add(textBlock);
  1632. ImageList.Add(border);
  1633. PicImageList.Add(image);
  1634. OperImageList.Add(opImage);
  1635. Panel.SetZIndex(textBlock, 11);
  1636. Panel.SetZIndex(border, 12);
  1637. Panel.SetZIndex(image, 13);
  1638. Panel.SetZIndex(opImage, 14);
  1639. textBlock.FontWeight = FontWeights.Medium;
  1640. textBlock.FontSize = 14;
  1641. textBlock.Width = 16;
  1642. textBlock.Height = 22;
  1643. textBlock.Text = $"{i + 1}";
  1644. textBlock.TextAlignment = TextAlignment.Center;
  1645. textBlock.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - 7);
  1646. textBlock.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - 11);
  1647. border.Width = backImageRadius * 2;
  1648. border.Height = backImageRadius * 2;
  1649. border.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * backImageBigRadius - backImageRadius);
  1650. border.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * backImageBigRadius - backImageRadius);
  1651. opImage.Width = operRaius * 2;
  1652. opImage.Height = operRaius * 2;
  1653. opImage.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * operBigRadius - operRaius);
  1654. opImage.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * operBigRadius - operRaius);
  1655. image.Width = imageRadius * 2;
  1656. image.Height = imageRadius * 2;
  1657. image.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius);
  1658. image.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius);
  1659. image.SetValue(Image.ClipProperty, ellipseGeometry);
  1660. if (vm.CurrentDish == null)
  1661. {
  1662. border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryoBackground.png", UriKind.Absolute));
  1663. }
  1664. else
  1665. {
  1666. itemEmbryo = SetWellImage(i, 0);
  1667. if (itemEmbryo == null)
  1668. {
  1669. textBlock.Tag = 0;
  1670. textBlock.Foreground = noEmbryoForeground;
  1671. image.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryo.png", UriKind.Absolute));
  1672. }
  1673. else
  1674. {
  1675. textBlock.Tag = 2;
  1676. textBlock.Foreground = deaeatForeground;
  1677. image.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryo1.png", UriKind.Absolute));
  1678. switch ((EmbryoState)itemEmbryo.state)
  1679. {
  1680. case EmbryoState.Freezing: //冷冻
  1681. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState1Icon.png", UriKind.Absolute));
  1682. break;
  1683. case EmbryoState.Transplant://移植
  1684. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState2Icon.png", UriKind.Absolute));
  1685. break;
  1686. case EmbryoState.Cancellation://作废
  1687. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState3Icon.png", UriKind.Absolute));
  1688. break;
  1689. case EmbryoState.Delete://删除
  1690. opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState4Icon.png", UriKind.Absolute));
  1691. break;
  1692. default:
  1693. opImage.Visibility = Visibility.Hidden;
  1694. break;
  1695. }
  1696. }
  1697. }
  1698. if (i == 0) textBlock.Foreground = new SolidColorBrush(Colors.White);
  1699. int index = i;
  1700. image.MouseUp += (s, e) =>
  1701. {
  1702. if (!this.IsLoaded) return;
  1703. if (selectedIndex == index) return;
  1704. SelectIndex(index);
  1705. CloseCeLiang();
  1706. PlayerPause();
  1707. ChangeEmbryo(index + 1);
  1708. };
  1709. }
  1710. //SelectIndex(0);
  1711. }
  1712. catch (Exception ex)
  1713. {
  1714. ExLog(ex, "InitCustomNew");
  1715. }
  1716. }
  1717. private object lock1 = new object();
  1718. private Embryo SetWellImage(int index, int oldIndex)
  1719. {
  1720. lock (lock1)
  1721. {
  1722. if (vm == null || vm.CurrentDish == null) return null;
  1723. Image imageBorder = ImageList[index];
  1724. var itemEmbryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == index + 1);
  1725. if (itemEmbryo == null)
  1726. {
  1727. if (index == oldIndex)
  1728. {
  1729. imageBorder.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute));
  1730. }
  1731. else
  1732. {
  1733. imageBorder.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryoBackground.png", UriKind.Absolute));
  1734. }
  1735. return itemEmbryo;
  1736. }
  1737. string borderSource = null;
  1738. switch ((EmbryoState)itemEmbryo.state)
  1739. {
  1740. case EmbryoState.End:
  1741. case EmbryoState.None:
  1742. if (itemEmbryo.alarm == 1)
  1743. {
  1744. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState3Icon.png";
  1745. }
  1746. else
  1747. {
  1748. if (index == oldIndex)
  1749. {
  1750. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png";
  1751. }
  1752. else
  1753. {
  1754. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png";
  1755. }
  1756. }
  1757. break;
  1758. case EmbryoState.Freezing: //冷冻
  1759. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState1Icon.png";
  1760. break;
  1761. case EmbryoState.Transplant://移植
  1762. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState2Icon.png";
  1763. break;
  1764. case EmbryoState.Cancellation://作废
  1765. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState3Icon.png";
  1766. break;
  1767. case EmbryoState.Delete://删除
  1768. borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState4Icon.png";
  1769. break;
  1770. }
  1771. imageBorder.Source = new BitmapImage(new Uri(borderSource, UriKind.Absolute));
  1772. return itemEmbryo;
  1773. }
  1774. }
  1775. /// <summary>
  1776. /// 设置选中状态
  1777. /// </summary>
  1778. /// <param name="index"></param>
  1779. private void SelectIndex(int index)
  1780. {
  1781. switch (TextBlockList[selectedIndex].Tag.ToString())
  1782. {
  1783. case "0":
  1784. TextBlockList[selectedIndex].Foreground = noEmbryoForeground;
  1785. break;
  1786. case "1":
  1787. TextBlockList[selectedIndex].Foreground = noPicForeground;
  1788. break;
  1789. case "2":
  1790. TextBlockList[selectedIndex].Foreground = deaeatForeground;
  1791. break;
  1792. }
  1793. SetWellImage(selectedIndex, -1);
  1794. selectedIndex = index;
  1795. TextBlockList[selectedIndex].Foreground = new SolidColorBrush(Colors.White);
  1796. var itemEmbryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == selectedIndex + 1);
  1797. if (itemEmbryo == null)
  1798. {
  1799. ImageList[selectedIndex].Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute));
  1800. }
  1801. else
  1802. {
  1803. if ((itemEmbryo.state == (int)EmbryoState.End || itemEmbryo.state == (int)EmbryoState.None) && itemEmbryo.alarm == 0)
  1804. {
  1805. ImageList[selectedIndex].Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute));
  1806. }
  1807. }
  1808. RotateTransform rotateTransform = this._sx.RenderTransform as RotateTransform;
  1809. rotateTransform.Angle = angle * selectedIndex;
  1810. }
  1811. private void SelectIndexold(int index)
  1812. {
  1813. switch (TextBlockList[selectedIndex].Tag.ToString())
  1814. {
  1815. case "0":
  1816. TextBlockList[selectedIndex].Foreground = noEmbryoForeground;
  1817. break;
  1818. case "1":
  1819. TextBlockList[selectedIndex].Foreground = noPicForeground;
  1820. break;
  1821. case "2":
  1822. TextBlockList[selectedIndex].Foreground = deaeatForeground;
  1823. break;
  1824. }
  1825. switch (ImageList[selectedIndex].Tag.ToString())
  1826. {
  1827. case "0":
  1828. ImageList[selectedIndex].Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryoBackground.png", UriKind.Absolute));
  1829. break;
  1830. case "1":
  1831. case "2":
  1832. ImageList[selectedIndex].Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png", UriKind.Absolute));
  1833. break;
  1834. }
  1835. selectedIndex = index;
  1836. TextBlockList[selectedIndex].Foreground = new SolidColorBrush(Colors.White);
  1837. switch (ImageList[selectedIndex].Tag.ToString())
  1838. {
  1839. case "0":
  1840. case "1":
  1841. case "2":
  1842. ImageList[selectedIndex].Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute));
  1843. break;
  1844. }
  1845. RotateTransform rotateTransform = this._sx.RenderTransform as RotateTransform;
  1846. rotateTransform.Angle = angle * selectedIndex;
  1847. }
  1848. /// <summary>
  1849. /// 切换well
  1850. /// </summary>
  1851. /// <param name="well"></param>
  1852. public void ChangeEmbryo(int well)
  1853. {
  1854. try
  1855. {
  1856. PlayerDispose();
  1857. ClearMeasurementList();
  1858. if (vm == null) return;
  1859. vm.CurrentEmbryo = null;
  1860. vm.CurrentWellDishPicAndVideo = null;
  1861. vm.CurrentWellLayerPicAndVideo = null;
  1862. vm.CurrentPic = null;
  1863. SetVideoButtonState(false);
  1864. vm.CurrentFocal = 0;
  1865. this._bigFocal_Button.IsEnabled = true;
  1866. this._smallFocal_Button.IsEnabled = true;
  1867. if (vm.CurrentDish != null && vm.CurrentDish.id > 0) vm.CurrentEmbryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == well);
  1868. if (vm.CurrentEmbryo == null)
  1869. {
  1870. vm.VideoAllTime = 1;
  1871. vm.VideoCurrentTime = 0;
  1872. }
  1873. if (vm.CurrentEmbryo != null) vm.CurrentWellDishPicAndVideo = vm.DishPicAndVideoList.FirstOrDefault(x => x.wellSn == vm.CurrentEmbryo.wellSn);
  1874. if (vm.CurrentWellDishPicAndVideo != null) vm.CurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == 0);
  1875. if (vm.MaxTotalLayer == -1) if (vm.CurrentWellLayerPicAndVideo != null) vm.MaxTotalLayer = vm.CurrentWellLayerPicAndVideo.videoPictures.Max(x => x.totalLayer);
  1876. SetPreview(well);
  1877. SetVideo(vm.CurrentFocal, true);
  1878. if (vm.CurrentWellLayerPicAndVideo != null && vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
  1879. {
  1880. this._bigFocal_Button.IsEnabled = true;
  1881. this._smallFocal_Button.IsEnabled = true;
  1882. if (string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) || vm.CurrentWellLayerPicAndVideo.videoUrl == AppData.Instance.CleanVideoString)
  1883. {
  1884. var aaa = this.te.VideoCurrentTime;
  1885. var aaa1 = this.te.VideoAllTime;
  1886. vm.VideoAllTime = 1;
  1887. vm.VideoCurrentTime = 0;
  1888. vm.VideoAllTime = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
  1889. vm.VideoCurrentTime = vm.VideoAllTime;
  1890. }
  1891. }
  1892. else
  1893. {
  1894. this._bigFocal_Button.IsEnabled = false;
  1895. this._smallFocal_Button.IsEnabled = false;
  1896. }
  1897. }
  1898. catch (Exception ex)
  1899. {
  1900. ExLog(ex, "ChangeEmbryo");
  1901. }
  1902. }
  1903. /// <summary>
  1904. /// 设置视频
  1905. /// </summary>
  1906. private bool SetVideo(int focal, bool isUpdate)
  1907. {
  1908. if (vm.CurrentWellLayerPicAndVideo != null && !string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) && vm.CurrentWellLayerPicAndVideo.videoUrl != AppData.Instance.CleanVideoString)
  1909. {
  1910. TimeLog($"视频设置完成");
  1911. if (PlayerSetSource($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}")) return true;
  1912. }
  1913. if (!isUpdate) return false;
  1914. vm.VideoAllTime = 1;
  1915. vm.VideoCurrentTime = 0;
  1916. return true;
  1917. }
  1918. /// <summary>
  1919. /// 设置缩略图
  1920. /// </summary>
  1921. /// <param name="datas"></param>
  1922. private void SetEmbryoPic()
  1923. {
  1924. Image item = null;
  1925. for (int i = 0; i < 16; i++)
  1926. {
  1927. if (!PicImageList.Any()) return;
  1928. item = PicImageList[i];
  1929. var embryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == i + 1);
  1930. if (embryo == null)
  1931. {
  1932. item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryo.png", UriKind.Absolute));
  1933. continue;
  1934. }
  1935. var currentData = vm.DishPicAndVideoList.FirstOrDefault(x => x.wellSn == embryo.wellSn);
  1936. if (currentData == null || currentData.lastPicture == null)
  1937. {
  1938. item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoNoPic.png", UriKind.Absolute));
  1939. }
  1940. else
  1941. {
  1942. item.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{currentData.lastPicture.Replace(AppData.Instance.PicSuf, $"_80x80{AppData.Instance.PicSuf}")}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  1943. }
  1944. }
  1945. }
  1946. /// <summary>
  1947. /// 设置封面
  1948. /// </summary>
  1949. /// <param name="well"></param>
  1950. private void SetPreview(int well)
  1951. {
  1952. vm.SelectedFps = new KeyValuePair<double, string>(1d, "1.0x");
  1953. currentMediaElement.SpeedRatio = 1d;
  1954. //this._preview.Visibility = Visibility.Visible;
  1955. this.Canvas_preview.Visibility = Visibility.Visible;
  1956. if (vm.CurrentEmbryo == null)
  1957. {
  1958. //this._preview.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryoBigPic.png", UriKind.Absolute));
  1959. AppData.Instance.SetImageSource(this._preview, LogoEnum.Circle);
  1960. this.TextBlock_preview.Text = peitai;
  1961. return;
  1962. }
  1963. if (vm.CurrentWellDishPicAndVideo == null || string.IsNullOrEmpty(vm.CurrentWellDishPicAndVideo.lastPicture))
  1964. {
  1965. this._preview.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoPicBigPic.png", UriKind.Absolute));
  1966. this.TextBlock_preview.Text = paiShe;
  1967. return;
  1968. }
  1969. //var bb = PicImageList[(well - 1)];
  1970. //var cc = ((BitmapImage)bb.Source).UriSource.AbsolutePath.Replace("_80x80.jpg", ".jpg").Substring(1);
  1971. this._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.CurrentWellDishPicAndVideo.lastPicture}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  1972. this.TextBlock_preview.Text = "";
  1973. }
  1974. /// <summary>
  1975. /// 设置封面为无视频
  1976. /// </summary>
  1977. /// <param name="well"></param>
  1978. private void SetPreviewNoVideo()
  1979. {
  1980. this.Canvas_preview.Visibility = Visibility.Visible;
  1981. //this._preview.Visibility = Visibility.Visible;
  1982. this._preview.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoVideoPic.png", UriKind.Absolute));
  1983. this.TextBlock_preview.Text = shiping;
  1984. }
  1985. /// <summary>
  1986. /// 设置胚胎状态
  1987. /// </summary>
  1988. /// <param name="well"></param>
  1989. /// <param name="embryoState"></param>
  1990. private void SetEmbryoState(int well, int embryoState)
  1991. {
  1992. var item = OperImageList[(well - 1)];
  1993. var backItme = ImageList[(well - 1)];
  1994. EmbryoState state = (EmbryoState)embryoState;
  1995. item.Visibility = Visibility.Visible;
  1996. backItme.Tag = 3;
  1997. switch (state)
  1998. {
  1999. case EmbryoState.Freezing://冷冻
  2000. item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState1Icon.png", UriKind.Absolute));
  2001. backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState1Icon.png", UriKind.Absolute));
  2002. break;
  2003. case EmbryoState.Transplant://移植
  2004. item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState2Icon.png", UriKind.Absolute));
  2005. backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState2Icon.png", UriKind.Absolute));
  2006. break;
  2007. case EmbryoState.Cancellation://作废
  2008. item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState3Icon.png", UriKind.Absolute));
  2009. backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState3Icon.png", UriKind.Absolute));
  2010. break;
  2011. case EmbryoState.Delete://删除
  2012. item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState4Icon.png", UriKind.Absolute));
  2013. backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState4Icon.png", UriKind.Absolute));
  2014. break;
  2015. default:
  2016. item.Visibility = Visibility.Hidden;
  2017. backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute));
  2018. backItme.Tag = 2;
  2019. break;
  2020. }
  2021. }
  2022. /// <summary>
  2023. /// 切换图层
  2024. /// </summary>
  2025. /// <param name="isMax"></param>
  2026. private void ChangeFocal(bool isMax)
  2027. {
  2028. try
  2029. {
  2030. //DebugLog($"开始切换图层:{DateTime.Now}");
  2031. int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2;
  2032. int minFocal = -maxFocal;
  2033. int newCurrentFocal = vm.CurrentFocal;
  2034. if (isMax) newCurrentFocal++;
  2035. else newCurrentFocal--;
  2036. if (newCurrentFocal < maxFocal) this._bigFocal_Button.IsEnabled = true;
  2037. else this._bigFocal_Button.IsEnabled = false;
  2038. if (newCurrentFocal > minFocal) this._smallFocal_Button.IsEnabled = true;
  2039. else this._smallFocal_Button.IsEnabled = false;
  2040. if (newCurrentFocal < minFocal || newCurrentFocal > maxFocal) return;
  2041. //this._preview.Visibility = Visibility.Hidden;
  2042. this.Canvas_preview.Visibility = Visibility.Hidden;
  2043. Task.Run(() =>
  2044. {
  2045. Dispatcher.Invoke(() =>
  2046. {
  2047. 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()}");
  2048. if (a != null)
  2049. {
  2050. //this._preview.Visibility = Visibility.Visible;
  2051. this.Canvas_preview.Visibility = Visibility.Visible;
  2052. this.TextBlock_preview.Text = "";
  2053. this._preview.Source = a;
  2054. }
  2055. });
  2056. });
  2057. newCurrentTime = 0;
  2058. vm.CurrentFocal = newCurrentFocal;
  2059. SetVideoButtonState(false);
  2060. //var time1 = stopwatch.Elapsed;
  2061. //DebugLog($"切换图层确定新图层:{DateTime.Now},耗时:{time1.TotalMilliseconds}");
  2062. if (vm.CurrentWellDishPicAndVideo == null) return;
  2063. vm.CurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == vm.CurrentFocal);
  2064. SetVideo(vm.CurrentFocal, false);
  2065. if (vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
  2066. {
  2067. vm.CurrentWellLayerPicAndVideo.videoPictures = vm.detailProvider.GetVideoTimeLineApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, vm.CurrentFocal);
  2068. }
  2069. if (vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any() || vm.CurrentPic == null) return;
  2070. int i = 0;
  2071. foreach (var item in vm.CurrentWellLayerPicAndVideo.videoPictures)
  2072. {
  2073. if (item.developTime >= vm.CurrentPic.developTime) break;
  2074. i++;
  2075. }
  2076. newCurrentTime = i * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps);
  2077. //if (i == 0) newCurrentTime = 0;
  2078. //else newCurrentTime = (i + 1) * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps);
  2079. //var time2 = stopwatch.Elapsed;
  2080. //DebugLog($"切换图层确定新图层:{DateTime.Now},耗时:{(time2 - time1).TotalMilliseconds},切换图层以及设置视频源总耗时:{time2.TotalMilliseconds}");
  2081. }
  2082. catch (Exception ex)
  2083. {
  2084. ExLog(ex, "ChangeFocal");
  2085. }
  2086. //finally
  2087. //{
  2088. // stopwatch.Stop();
  2089. //}
  2090. }
  2091. /// <summary>
  2092. /// 切换图层
  2093. /// </summary>
  2094. /// <param name="isMax"></param>
  2095. private void ChangeImageFocal(bool isMax)
  2096. {
  2097. try
  2098. {
  2099. int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2;
  2100. int minFocal = -maxFocal;
  2101. int newCurrentFocal = vm.CurrentFocal;
  2102. if (isMax) newCurrentFocal++;
  2103. else newCurrentFocal--;
  2104. if (newCurrentFocal < maxFocal) this._bigFocal_Button.IsEnabled = true;
  2105. else this._bigFocal_Button.IsEnabled = false;
  2106. if (newCurrentFocal > minFocal) this._smallFocal_Button.IsEnabled = true;
  2107. else this._smallFocal_Button.IsEnabled = false;
  2108. if (newCurrentFocal < minFocal || newCurrentFocal > maxFocal) return;
  2109. var newCurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == newCurrentFocal);
  2110. newCurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == newCurrentFocal);
  2111. if (newCurrentWellLayerPicAndVideo == null) return;
  2112. if (!newCurrentWellLayerPicAndVideo.videoPictures.Any()) return;
  2113. vm.CurrentWellLayerPicAndVideo = newCurrentWellLayerPicAndVideo;
  2114. //this._preview.Visibility = Visibility.Visible;
  2115. this.Canvas_preview.Visibility = Visibility.Visible;
  2116. var oldDevelopTime = vm.CurrentPic.developTime;
  2117. vm.CurrentFocal = newCurrentFocal;
  2118. vm.VideoAllTime = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
  2119. int i = 0;
  2120. foreach (var item in vm.CurrentWellLayerPicAndVideo.videoPictures)
  2121. {
  2122. if (item.developTime >= oldDevelopTime) break;
  2123. i++;
  2124. }
  2125. //Debug.WriteLine($"{vm.CurrentWellLayerPicAndVideo.videoPictures[163].developTime} -> {oldDevelopTime}");
  2126. //Debug.WriteLine($"focal:{i} -》 {vm.CurrentWellLayerPicAndVideo.videoPictures.Count}");
  2127. //vm.VideoCurrentTime = vm.VideoAllTime;
  2128. this._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoPictures[i].imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  2129. this.TextBlock_preview.Text = "";
  2130. vm.VideoCurrentTime = 0;
  2131. vm.VideoCurrentTime = i + 1;
  2132. return;
  2133. Task.Run(() =>
  2134. {
  2135. Dispatcher.Invoke(() =>
  2136. {
  2137. 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()}");
  2138. if (a != null)
  2139. {
  2140. this._preview.Visibility = Visibility.Visible;
  2141. this._preview.Source = a;
  2142. }
  2143. });
  2144. });
  2145. newCurrentTime = 0;
  2146. vm.CurrentFocal = newCurrentFocal;
  2147. SetVideoButtonState(false);
  2148. //var time1 = stopwatch.Elapsed;
  2149. //DebugLog($"切换图层确定新图层:{DateTime.Now},耗时:{time1.TotalMilliseconds}");
  2150. if (vm.CurrentWellDishPicAndVideo == null) return;
  2151. vm.CurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == vm.CurrentFocal);
  2152. SetVideo(vm.CurrentFocal, false);
  2153. if (vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
  2154. {
  2155. vm.CurrentWellLayerPicAndVideo.videoPictures = vm.detailProvider.GetVideoTimeLineApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, vm.CurrentFocal);
  2156. }
  2157. if (vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any() || vm.CurrentPic == null) return;
  2158. newCurrentTime = i * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps);
  2159. //if (i == 0) newCurrentTime = 0;
  2160. //else newCurrentTime = (i + 1) * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps);
  2161. //var time2 = stopwatch.Elapsed;
  2162. //DebugLog($"切换图层确定新图层:{DateTime.Now},耗时:{(time2 - time1).TotalMilliseconds},切换图层以及设置视频源总耗时:{time2.TotalMilliseconds}");
  2163. }
  2164. catch (Exception ex)
  2165. {
  2166. ExLog(ex, "ChangeImageFocal");
  2167. }
  2168. //finally
  2169. //{
  2170. // stopwatch.Stop();
  2171. //}
  2172. }
  2173. private void ChangeFocalNoVideo(bool isMax)
  2174. {
  2175. try
  2176. {
  2177. //DebugLog($"开始切换图层:{DateTime.Now}");
  2178. int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2;
  2179. int minFocal = -maxFocal;
  2180. int newCurrentFocal = vm.CurrentFocal;
  2181. CC:
  2182. Debug.WriteLine($"{newCurrentFocal}、{vm.CurrentPic.developTime}");
  2183. if (isMax) newCurrentFocal++;
  2184. else newCurrentFocal--;
  2185. if (newCurrentFocal < maxFocal) this._bigFocal_Button.IsEnabled = true;
  2186. else this._bigFocal_Button.IsEnabled = false;
  2187. if (newCurrentFocal > minFocal) this._smallFocal_Button.IsEnabled = true;
  2188. else this._smallFocal_Button.IsEnabled = false;
  2189. if (newCurrentFocal < minFocal || newCurrentFocal > maxFocal) return;
  2190. //totalLayer返回11,但是视频图片数据只有7层
  2191. var aa = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == newCurrentFocal);
  2192. if (aa == null) goto CC;
  2193. if (aa.videoPictures == null || !aa.videoPictures.Any())
  2194. {
  2195. aa.videoPictures = vm.detailProvider.GetVideoTimeLineApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal);
  2196. }
  2197. if (aa.videoPictures == null || !aa.videoPictures.Any()) goto CC;
  2198. bool b = false;
  2199. string imageUrl = null;
  2200. foreach (var item in aa.videoPictures)
  2201. {
  2202. if (item.developTime == vm.CurrentPic.developTime)
  2203. {
  2204. b = true;
  2205. imageUrl = item.imageUrl;
  2206. break;
  2207. }
  2208. }
  2209. if (!b) goto CC;
  2210. Task.Run(() =>
  2211. {
  2212. if (string.IsNullOrEmpty(imageUrl)) imageUrl = vm.detailProvider.GetImageUrlApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal, vm.CurrentPic.developTime);
  2213. Dispatcher.Invoke(() =>
  2214. {
  2215. var a = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  2216. if (a != null)
  2217. {
  2218. this.Canvas_preview.Visibility = Visibility.Visible;
  2219. //this._preview.Visibility = Visibility.Visible;
  2220. this._preview.Source = a;
  2221. }
  2222. });
  2223. });
  2224. vm.CurrentFocal = newCurrentFocal;
  2225. }
  2226. catch (Exception ex)
  2227. {
  2228. ExLog(ex, "ChangeFocalNoVideo");
  2229. }
  2230. }
  2231. private void SetVideoButtonState(bool IsEnabledVideo)
  2232. {
  2233. Task.Run(() =>
  2234. {
  2235. Dispatcher.Invoke(() =>
  2236. {
  2237. this._lastButton.IsEnabled = IsEnabledVideo;
  2238. this._playButton.IsEnabled = IsEnabledVideo;
  2239. this._nextButton.IsEnabled = IsEnabledVideo;
  2240. });
  2241. });
  2242. }
  2243. #endregion
  2244. #region 进度条事件
  2245. private void ProgressbarUserControl_BeforeInteractionEvent()
  2246. {
  2247. CloseCeLiang();
  2248. PlayerPause();
  2249. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  2250. {
  2251. //this._preview.Visibility = Visibility.Hidden;
  2252. this.Canvas_preview.Visibility = Visibility.Hidden;
  2253. }
  2254. else
  2255. {
  2256. }
  2257. }
  2258. private void ProgressbarUserControl_AfterInteractionEvent(double obj)
  2259. {
  2260. //Debug.WriteLine($"After:{obj}->{ProToImageIndex()} ->{vm.CurrentWellLayerPicAndVideo.videoPictures.Count}");
  2261. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  2262. {
  2263. currentMediaElement.LoadedBehavior = MediaState.Manual;
  2264. SetPlayerPosition(obj);
  2265. }
  2266. else
  2267. {
  2268. if (vm.CurrentWellLayerPicAndVideo != null && vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
  2269. {
  2270. this._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoPictures[ProToImageIndex()].imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  2271. this.TextBlock_preview.Text = "";
  2272. }
  2273. }
  2274. }
  2275. private void ProgressbarUserControl_ProChangendEvent(double obj)
  2276. {
  2277. //Debug.WriteLine($"ProChangend:{obj}->{ProToImageIndex()}");
  2278. if (PlayerState != PlayerStateEnum.Nothing || PlayerState != PlayerStateEnum.Error)
  2279. {
  2280. SetPlayerPosition(obj);
  2281. }
  2282. else
  2283. {
  2284. //this._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoPictures[ProToImageIndex()].imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}");
  2285. }
  2286. }
  2287. int picCount = 0;
  2288. int picIndex = 0;
  2289. private string ProgressbarUserControl_LengthDevelopmentEvent(double arg)
  2290. {
  2291. try
  2292. {
  2293. if (vm == null || vm.CurrentWellLayerPicAndVideo == null)
  2294. {
  2295. vm.CurrentPic = null;
  2296. return "00h:00m";
  2297. }
  2298. if (vm.CurrentWellLayerPicAndVideo == null || vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
  2299. {
  2300. vm.CurrentPic = null;
  2301. return "00h:00m";
  2302. }
  2303. if (string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) || vm.CurrentWellLayerPicAndVideo.videoUrl == AppData.Instance.CleanVideoString)
  2304. {
  2305. picIndex = ProToImageIndex();
  2306. vm.CurrentPic = vm.CurrentWellLayerPicAndVideo.videoPictures[picIndex];
  2307. //Debug.WriteLine($"proLength {picIndex} ->{vm.CurrentWellLayerPicAndVideo.videoPictures.Count}");
  2308. return $"{(vm.CurrentPic.developTime / 60).ToString("D2")}h:{(vm.CurrentPic.developTime % 60).ToString("D2")}m";
  2309. }
  2310. else
  2311. {
  2312. picCount = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
  2313. picIndex = VideoProToImageIndex();
  2314. if (picIndex < 0) picIndex = 0;
  2315. if (picIndex > (picCount - 1)) picIndex = picCount - 1;
  2316. vm.CurrentPic = vm.CurrentWellLayerPicAndVideo.videoPictures[picIndex];
  2317. return $"{(vm.CurrentPic.developTime / 60).ToString("D2")}h:{(vm.CurrentPic.developTime % 60).ToString("D2")}m";
  2318. }
  2319. }
  2320. catch (Exception ex)
  2321. {
  2322. vm.CurrentPic = null;
  2323. ExLog(ex, "获取当前帧发育时长");
  2324. return "00h:00m";
  2325. }
  2326. }
  2327. /// <summary>
  2328. /// 0- count-1
  2329. /// </summary>
  2330. /// <returns></returns>
  2331. public int VideoProToImageIndex()
  2332. {
  2333. try
  2334. {
  2335. if (vm == null || vm.CurrentWellLayerPicAndVideo == null) return 0;
  2336. return (int)(vm.VideoCurrentTime / (1000.00 / vm.CurrentWellLayerPicAndVideo.fps));
  2337. }
  2338. catch (Exception ex)
  2339. {
  2340. ExLog(ex, "VideoProToImageIndex");
  2341. return 0;
  2342. }
  2343. }
  2344. /// <summary>
  2345. /// 进度条换算图片下标
  2346. /// </summary>
  2347. /// <returns></returns>
  2348. public int ProToImageIndex()
  2349. {
  2350. try
  2351. {
  2352. if (vm == null || vm.CurrentWellLayerPicAndVideo == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any()) return 0;
  2353. var imageIndex = ((int)vm.VideoCurrentTime - 1);
  2354. if (imageIndex < 0) imageIndex = 0;
  2355. if (imageIndex >= vm.CurrentWellLayerPicAndVideo.videoPictures.Count) imageIndex = vm.CurrentWellLayerPicAndVideo.videoPictures.Count - 1;
  2356. return imageIndex;
  2357. }
  2358. catch (Exception ex)
  2359. {
  2360. ExLog(ex, "ProToImageIndex");
  2361. return 0;
  2362. }
  2363. }
  2364. #endregion
  2365. #region 视频基础操作
  2366. double newCurrentTime = -1;
  2367. double beilv = 1;
  2368. MediaElement currentMediaElement = null;
  2369. /// <summary>
  2370. /// 定时器
  2371. /// </summary>
  2372. public System.Timers.Timer dispatcherTimer = new System.Timers.Timer();
  2373. /// <summary>
  2374. /// 视频状态
  2375. /// </summary>
  2376. public PlayerStateEnum PlayerState { get; set; } = PlayerStateEnum.Nothing;
  2377. /// <summary>
  2378. /// 播放器事件初始化
  2379. /// </summary>
  2380. public void PlayerEvent(MediaElement mediaElement)
  2381. {
  2382. try
  2383. {
  2384. currentMediaElement = mediaElement;
  2385. currentMediaElement.MediaEnded -= MediaEndedEvent;
  2386. currentMediaElement.MediaOpened -= MediaOpenedEvent;
  2387. currentMediaElement.MediaFailed -= MediaFailedEvent; currentMediaElement.BufferingEnded -= CurrentMediaElement_BufferingEnded;
  2388. currentMediaElement.MediaEnded += MediaEndedEvent;
  2389. currentMediaElement.MediaOpened += MediaOpenedEvent;
  2390. currentMediaElement.MediaFailed += MediaFailedEvent;
  2391. //currentMediaElement.BufferingEnded += CurrentMediaElement_BufferingEnded;
  2392. dispatcherTimer.Interval = 25;
  2393. dispatcherTimer.Elapsed -= dispatcherTimer_Elapsed;
  2394. dispatcherTimer.Elapsed += dispatcherTimer_Elapsed;
  2395. }
  2396. catch (Exception ex)
  2397. {
  2398. ExLog(ex, $"播放器事件初始化");
  2399. }
  2400. }
  2401. private void CurrentMediaElement_BufferingEnded(object sender, RoutedEventArgs e)
  2402. {
  2403. TimeLog($"媒体缓冲结束时");
  2404. }
  2405. private string LocalVideo()
  2406. {
  2407. switch (vm.CurrentEmbryo.wellSn)
  2408. {
  2409. case 1:
  2410. return @"C:\Users\20552\Desktop\t-修改_24-01-23-17-35-08\t-修改_well_1.mp4";
  2411. case 2:
  2412. return @"C:\Users\20552\Desktop\t-修改_24-01-23-17-35-08\t-修改_well_2.mp4";
  2413. case 3:
  2414. return @"C:\Users\20552\Desktop\t-修改_24-01-23-17-35-08\t-修改_well_3.mp4";
  2415. case 4:
  2416. return @"C:\Users\20552\Desktop\t-修改_24-01-23-17-35-08\t-修改_well_4.mp4";
  2417. case 5:
  2418. return @"C:\Users\20552\Desktop\t-修改_24-01-23-17-35-08\t-修改_well_5.mp4";
  2419. case 6:
  2420. return @"C:\Users\20552\Desktop\t-修改_24-01-23-17-35-08\t-修改_well_6.mp4";
  2421. case 7:
  2422. return @"C:\Users\20552\Desktop\t-修改_24-01-23-17-35-08\t-修改_well_7.mp4";
  2423. }
  2424. return "";
  2425. }
  2426. private string LocalVideo1()
  2427. {
  2428. switch (vm.CurrentEmbryo.wellSn)
  2429. {
  2430. case 1:
  2431. return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_1.mp4";
  2432. case 2:
  2433. return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_2.mp4";
  2434. case 3:
  2435. return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_3.mp4";
  2436. case 4:
  2437. return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_4.mp4";
  2438. case 5:
  2439. return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_5.mp4";
  2440. case 6:
  2441. return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_6.mp4";
  2442. case 7:
  2443. return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_7.mp4";
  2444. }
  2445. return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_1.mp4";
  2446. }
  2447. /// <summary>
  2448. /// 设置播放源
  2449. /// </summary>
  2450. /// <param name="FileName"></param>
  2451. public bool PlayerSetSource(string FileName)
  2452. {
  2453. try
  2454. {
  2455. //FileName = "http://192.168.0.218:8300/vod/index.m3u8";
  2456. //FileName = LocalVideo1();
  2457. PlayerDispose();
  2458. currentMediaElement.Source = new Uri(FileName, UriKind.RelativeOrAbsolute);
  2459. currentMediaElement.LoadedBehavior = MediaState.Manual;
  2460. currentMediaElement.SpeedRatio = 1;
  2461. currentMediaElement.Play();
  2462. currentMediaElement.Pause();
  2463. return true;
  2464. }
  2465. catch (Exception ex)
  2466. {
  2467. ExLog(ex, $"设置播放源");
  2468. return false;
  2469. }
  2470. }
  2471. /// <summary>
  2472. /// 播放器加载视频完成事件
  2473. /// </summary>
  2474. /// <param name="sender"></param>
  2475. /// <param name="e"></param>
  2476. private void MediaOpenedEvent(object sender, RoutedEventArgs e)
  2477. {
  2478. try
  2479. {
  2480. if (!this.IsLoaded) return;
  2481. if (vm == null) return;
  2482. //Stopwatch stopwatch = Stopwatch.StartNew();
  2483. TimeLog($"视频加载完成");
  2484. //bool isWhile = true;
  2485. //while (isWhile)
  2486. //{
  2487. // DebugLog($"视频下载进度:{currentMediaElement.DownloadProgress}");
  2488. // isWhile = !(currentMediaElement.DownloadProgress == 1);
  2489. // Thread.Sleep(20);
  2490. //}
  2491. //isWhile = true;
  2492. //while (isWhile)
  2493. //{
  2494. // DebugLog($"视频加载进度:{currentMediaElement.BufferingProgress}");
  2495. // isWhile = !(currentMediaElement.BufferingProgress == 1);
  2496. // Thread.Sleep(20);
  2497. //}
  2498. //ErrorLog($"视频加载完成,开始设置属性", LogEnum.RunRecord);
  2499. currentMediaElement.ScrubbingEnabled = false;
  2500. vm.VideoAllTime = 1;
  2501. vm.VideoCurrentTime = 0;
  2502. if (currentMediaElement.NaturalDuration.HasTimeSpan)
  2503. {
  2504. currentMediaElement.LoadedBehavior = MediaState.Manual;
  2505. PlayerState = PlayerStateEnum.Paused;
  2506. vm.VideoAllTime = currentMediaElement.NaturalDuration.TimeSpan.TotalMilliseconds;
  2507. //Debug.WriteLine($"{vm.CurrentFocal}:{vm.VideoAllTime}:{currentMediaElement.Source}");
  2508. currentMediaElement.ScrubbingEnabled = true;
  2509. //currentMediaElement.SpeedRatio = vm.SelectedFps.Key;
  2510. currentMediaElement.Play();
  2511. currentMediaElement.Pause();
  2512. if (newCurrentTime != -1)
  2513. {
  2514. if (newCurrentTime < 0) newCurrentTime = 0;
  2515. if (newCurrentTime > vm.VideoAllTime) newCurrentTime = vm.VideoAllTime;
  2516. SetTimeProgressbarProgressValue(newCurrentTime);
  2517. SetPlayerPosition(vm.VideoCurrentTime);
  2518. newCurrentTime = -1;
  2519. }
  2520. else
  2521. {
  2522. SetTimeProgressbarProgressValue(vm.VideoAllTime);
  2523. SetPlayerPosition(vm.VideoCurrentTime);
  2524. }
  2525. SetVideoButtonState(true);
  2526. }
  2527. else
  2528. {
  2529. PlayerState = PlayerStateEnum.Nothing;
  2530. }
  2531. //ErrorLog($"视频属性设置完成:{DateTime.Now},总耗时:{stopwatch.Elapsed.TotalMilliseconds}", LogEnum.RunRecord);
  2532. //stopwatch.Stop();
  2533. }
  2534. catch (Exception ex)
  2535. {
  2536. PlayerState = PlayerStateEnum.Error;
  2537. ExLog(ex, $"播放器加载视频完成事件");
  2538. }
  2539. }
  2540. /// <summary>
  2541. /// 播放完成事件
  2542. /// </summary>
  2543. /// <param name="sender"></param>
  2544. /// <param name="e"></param>
  2545. private void MediaEndedEvent(object sender, RoutedEventArgs e)
  2546. {
  2547. //bool isCan = currentMediaElement.CanPause;
  2548. try
  2549. {
  2550. PlayerState = PlayerStateEnum.Paused;
  2551. dispatcherTimer_Stop();
  2552. //currentMediaElement.LoadedBehavior = MediaState.Stop;
  2553. //currentMediaElement.LoadedBehavior = MediaState.Play;
  2554. //currentMediaElement.LoadedBehavior = MediaState.Pause;
  2555. //currentMediaElement.SpeedRatio = 1;
  2556. currentMediaElement.Play();
  2557. currentMediaElement.Pause();
  2558. SetTimeProgressbarProgressValue(vm.VideoAllTime);
  2559. SetPlayerPosition(vm.VideoAllTime);
  2560. SetPlayButton(false);
  2561. }
  2562. catch (Exception ex)
  2563. {
  2564. ExLog(ex, $"播放完成事件");
  2565. }
  2566. }
  2567. /// <summary>
  2568. /// 播放器错误事件
  2569. /// </summary>
  2570. /// <param name="sender"></param>
  2571. /// <param name="e"></param>
  2572. /// <exception cref="NotImplementedException"></exception>
  2573. private void MediaFailedEvent(object? sender, ExceptionRoutedEventArgs e)
  2574. {
  2575. try
  2576. {
  2577. PlayerState = PlayerStateEnum.Error;
  2578. if (vm != null)
  2579. {
  2580. vm.VideoAllTime = 1;
  2581. vm.VideoCurrentTime = 0;
  2582. }
  2583. SetPlayButton(false);
  2584. string ss = "";
  2585. MediaElement med = sender as MediaElement;
  2586. if (med != null)
  2587. {
  2588. ss = med.Source.ToString();
  2589. ErrorLog($"{ss},视频遇到错误", LogEnum.RunError);
  2590. }
  2591. dispatcherTimer_Stop();
  2592. ExLog(e.ErrorException, $"MediaFailedEvent:{ss}");
  2593. }
  2594. catch (Exception ex)
  2595. {
  2596. ExLog(ex, $"播放器错误事件");
  2597. }
  2598. }
  2599. /// <summary>
  2600. /// 播放按钮图标设置
  2601. /// </summary>
  2602. private void SetPlayButton(bool isPlaying)
  2603. {
  2604. if (isPlaying)//正在播放,设置为暂停按钮
  2605. {
  2606. this._playButton.IconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailPauseVideoButtonIcon.png", UriKind.Absolute));
  2607. this._playButton.MouseOverIconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailPauseVideoButtonMouseIcon.png", UriKind.Absolute));
  2608. }
  2609. else//未播放,设置为播放按钮
  2610. {
  2611. this._playButton.IconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailStartVideoButtonIcon.png", UriKind.Absolute));
  2612. this._playButton.MouseOverIconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailStartVideoButtonMouseIcon.png", UriKind.Absolute));
  2613. }
  2614. }
  2615. /// <summary>
  2616. /// 定时器事件
  2617. /// </summary>
  2618. /// <param name="sender"></param>
  2619. /// <param name="e"></param>
  2620. private void dispatcherTimer_Elapsed(object? sender, ElapsedEventArgs e)
  2621. {
  2622. try
  2623. {
  2624. Dispatcher.Invoke(() =>
  2625. {
  2626. SetTimeProgressbarProgressValue(currentMediaElement.Position.TotalMilliseconds);
  2627. });
  2628. if (PlayerState != PlayerStateEnum.Playing)
  2629. {
  2630. dispatcherTimer_Stop();
  2631. }
  2632. }
  2633. catch (Exception ex)
  2634. {
  2635. ExLog(ex, $"定时器事件");
  2636. }
  2637. }
  2638. /// <summary>
  2639. /// 停止定时器
  2640. /// </summary>
  2641. public void dispatcherTimer_Stop()
  2642. {
  2643. try
  2644. {
  2645. if (dispatcherTimer.Enabled)
  2646. {
  2647. dispatcherTimer.Enabled = false;
  2648. dispatcherTimer.Stop();
  2649. }
  2650. }
  2651. catch (Exception ex)
  2652. {
  2653. ExLog(ex, $"停止定时器");
  2654. }
  2655. }
  2656. /// <summary>
  2657. ///设置视频进度
  2658. /// </summary>
  2659. /// <param name="progressValue"></param>
  2660. public void SetPlayerPosition(double currentTime)
  2661. {
  2662. try
  2663. {
  2664. if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
  2665. {
  2666. currentMediaElement.Position = TimeSpan.FromMilliseconds(currentTime);
  2667. }
  2668. }
  2669. catch (Exception ex)
  2670. {
  2671. ExLog(ex, $"设置视频进度");
  2672. }
  2673. }
  2674. /// <summary>
  2675. /// 设置进度条进度
  2676. /// </summary>
  2677. public void SetTimeProgressbarProgressValue(double newTime)
  2678. {
  2679. try
  2680. {
  2681. if (vm == null) return;
  2682. vm.VideoCurrentTime = newTime;
  2683. }
  2684. catch (Exception ex)
  2685. {
  2686. ExLog(ex, $"设置进度条进度");
  2687. }
  2688. }
  2689. /// <summary>
  2690. /// 释放播放器
  2691. /// </summary>
  2692. public void PlayerDispose()
  2693. {
  2694. try
  2695. {
  2696. dispatcherTimer_Stop();
  2697. if (PlayerState != PlayerStateEnum.Nothing)
  2698. {
  2699. if (currentMediaElement != null)
  2700. {
  2701. currentMediaElement.Close();
  2702. currentMediaElement.LoadedBehavior = MediaState.Close;
  2703. }
  2704. PlayerState = PlayerStateEnum.Nothing;
  2705. }
  2706. }
  2707. catch (Exception ex)
  2708. {
  2709. PlayerState = PlayerStateEnum.Nothing;
  2710. ExLog(ex, $"释放播放器");
  2711. }
  2712. }
  2713. /// <summary>
  2714. /// 设置倍率
  2715. /// </summary>
  2716. /// <param name="newSpeedRatio"></param>
  2717. public void PlayerSetSpeedRatio(double newSpeedRatio)
  2718. {
  2719. try
  2720. {
  2721. beilv = newSpeedRatio;
  2722. if (PlayerState == PlayerStateEnum.Playing)
  2723. {
  2724. currentMediaElement.LoadedBehavior = MediaState.Manual;
  2725. currentMediaElement.SpeedRatio = newSpeedRatio;
  2726. }
  2727. }
  2728. catch (Exception ex)
  2729. {
  2730. ExLog(ex, $"设置倍率");
  2731. }
  2732. }
  2733. /// <summary>
  2734. /// 播放操作
  2735. /// </summary>
  2736. public bool PlayerPlay()
  2737. {
  2738. try
  2739. {
  2740. bool isPlay = false;
  2741. switch (PlayerState)
  2742. {
  2743. case PlayerStateEnum.Error:
  2744. break;
  2745. case PlayerStateEnum.Nothing:
  2746. break;
  2747. case PlayerStateEnum.Opened:
  2748. isPlay = true;
  2749. break;
  2750. case PlayerStateEnum.Paused:
  2751. isPlay = true;
  2752. break;
  2753. case PlayerStateEnum.Playing:
  2754. break;
  2755. case PlayerStateEnum.Stopped:
  2756. currentMediaElement.Stop();
  2757. isPlay = true;
  2758. break;
  2759. }
  2760. if (isPlay)
  2761. {
  2762. PlayerState = PlayerStateEnum.Playing;
  2763. if (vm.VideoCurrentTime == vm.VideoAllTime)
  2764. {
  2765. SetPlayerPosition(0);
  2766. }
  2767. if (!dispatcherTimer.Enabled)
  2768. {
  2769. dispatcherTimer.Start();
  2770. }
  2771. PlayerSetSpeedRatio(beilv);
  2772. currentMediaElement.Play();
  2773. //currentMediaElement.LoadedBehavior = MediaState.Play;
  2774. SetPlayButton(true);
  2775. return true;
  2776. }
  2777. return false;
  2778. }
  2779. catch (Exception ex)
  2780. {
  2781. ExLog(ex, $"播放操作");
  2782. return false;
  2783. }
  2784. }
  2785. /// <summary>
  2786. /// 暂停操作
  2787. /// </summary>
  2788. /// <param name="isSetState"></param>
  2789. public bool PlayerPause()
  2790. {
  2791. try
  2792. {
  2793. bool isPause = false;
  2794. switch (PlayerState)
  2795. {
  2796. case PlayerStateEnum.Error:
  2797. break;
  2798. case PlayerStateEnum.Nothing:
  2799. break;
  2800. case PlayerStateEnum.Opened:
  2801. break;
  2802. case PlayerStateEnum.Paused:
  2803. break;
  2804. case PlayerStateEnum.Playing:
  2805. isPause = true;
  2806. break;
  2807. case PlayerStateEnum.Stopped:
  2808. break;
  2809. }
  2810. if (isPause)
  2811. {
  2812. PlayerState = PlayerStateEnum.Paused;
  2813. //currentMediaElement.LoadedBehavior = MediaState.Pause;
  2814. currentMediaElement.Pause();
  2815. dispatcherTimer_Stop();
  2816. SetPlayButton(false);
  2817. return true;
  2818. }
  2819. return false;
  2820. }
  2821. catch (Exception ex)
  2822. {
  2823. ExLog(ex, $"暂停操作");
  2824. return false;
  2825. }
  2826. }
  2827. /// <summary>
  2828. /// 上一帧
  2829. /// </summary>
  2830. public void PlayerLastFrame(int zhenshu)
  2831. {
  2832. try
  2833. {
  2834. bool isOK = false;
  2835. bool isStop = false;
  2836. switch (PlayerState)
  2837. {
  2838. case PlayerStateEnum.Error:
  2839. break;
  2840. case PlayerStateEnum.Nothing:
  2841. break;
  2842. case PlayerStateEnum.Opened:
  2843. isOK = true;
  2844. break;
  2845. case PlayerStateEnum.Paused:
  2846. isOK = true;
  2847. break;
  2848. case PlayerStateEnum.Playing:
  2849. break;
  2850. case PlayerStateEnum.Stopped:
  2851. isOK = true;
  2852. break;
  2853. }
  2854. if (!isOK) return;
  2855. //var currentPositionTime = currentMediaElement.Position.TotalMilliseconds;
  2856. if (vm.VideoCurrentTime == 0) return;
  2857. var c = vm.VideoCurrentTime - (1000.00 / zhenshu);
  2858. if (c < 0) c = 0;
  2859. SetPlayerPosition(c);
  2860. SetTimeProgressbarProgressValue(c);
  2861. return;
  2862. }
  2863. catch (Exception ex)
  2864. {
  2865. ExLog(ex, $"上一帧");
  2866. }
  2867. }
  2868. /// <summary>
  2869. /// 下一帧
  2870. /// </summary>
  2871. public void PlayerNextFrame(int zhenshu)
  2872. {
  2873. try
  2874. {
  2875. bool isOK = false;
  2876. switch (PlayerState)
  2877. {
  2878. case PlayerStateEnum.Error:
  2879. break;
  2880. case PlayerStateEnum.Nothing:
  2881. break;
  2882. case PlayerStateEnum.Opened:
  2883. isOK = true;
  2884. break;
  2885. case PlayerStateEnum.Paused:
  2886. isOK = true;
  2887. break;
  2888. case PlayerStateEnum.Playing:
  2889. break;
  2890. case PlayerStateEnum.Stopped:
  2891. isOK = true;
  2892. break;
  2893. }
  2894. if (!isOK) return;
  2895. if (vm.VideoCurrentTime == vm.VideoAllTime) return;
  2896. var newpos = vm.VideoCurrentTime + (1000d / zhenshu);
  2897. if (newpos > vm.VideoAllTime) newpos = vm.VideoAllTime;
  2898. SetPlayerPosition(newpos);
  2899. SetTimeProgressbarProgressValue(newpos);
  2900. return;
  2901. }
  2902. catch (Exception ex)
  2903. {
  2904. ExLog(ex, $"下一帧");
  2905. }
  2906. }
  2907. #endregion
  2908. }
  2909. }