| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243 |
- using ivf_tl_Entity.GlobalEntitys;
- using ivf_tl_Entity.GlobalEnums;
- using ivf_tl_Operate.Converts;
- using ivf_tl_Operate.CustomUserControls;
- using ivf_tl_Operate.ViewModel;
- using ivf_tl_Operate.Windows;
- using Newtonsoft.Json;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Timers;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using static System.Net.Mime.MediaTypeNames;
- namespace ivf_tl_Operate.View
- {
- /// <summary>
- /// DetailPageView.xaml 的交互逻辑
- /// </summary>
- public partial class DetailPageView : UserControl
- {
- DetailPageViewModel vm;
- string CleanVideoString { get; set; } = "-";
- private double newCurrentTime = -1;
- double beilv { get; set; } = 1;
- public DetailPageView()
- {
- InitializeComponent();
- Loaded += DetailPageView_Loaded;
- Unloaded += DetailPageView_Unloaded;
- }
- private void DetailPageView_Unloaded(object sender, RoutedEventArgs e)
- {
- this.Grid_Root.Children.Clear();
- if (vm != null) vm = null;
- this.DataContext = null;
- }
- int NoMarkTime = 48;
- private void DetailPageView_Loaded(object sender, RoutedEventArgs e)
- {
- var TLSettingModel = AppData.Instance.HttpHelper.SettingSystemApi(AppData.Instance.TlSn);
- if(TLSettingModel!=null) NoMarkTime = TLSettingModel.operableEmbryoTime * 24;
- vm = (DetailPageViewModel)this.DataContext;
- if (vm == null) return;
- if (vm.ExDish != null && vm.ExDish.id > 0)
- {
- if (vm.ExDish.state == 0 && !string.IsNullOrEmpty(vm.ExDish.endTime) && DateTime.TryParse(vm.ExDish.endTime, out DateTime endtime))
- {
- var cultivateDuration = DateTime.Now.Subtract(endtime);
- if (cultivateDuration.TotalHours > NoMarkTime)
- {
- disableButton(false);
- }
- else
- {
- disableButton(true);
- }
- this.Button_js.IsEnabled = false;
- }
- else
- {
- disableButton(true);
- this.Button_js.IsEnabled = true;
- }
- }
- else
- {
- disableButton(true);
- this.Button_js.IsEnabled = true;
- }
- Task.Run(() =>
- {
- vm.Init();
- if (vm == null) return;
- Dispatcher.InvokeAsync(() =>
- {
- _dishInfo.SetEmbryoPic(vm.DishPicAndVideoList);
- PlayerEvent(this._dishInfo.mediaElementPlayer);
- ChangeEmbryo(1);
- });
- InitAlarm();
- while (true)
- {
- Thread.Sleep(10000);
- //Thread.Sleep(3000);
- if (vm == null || vm.ExDish == null) return;
- //foreach (var item in vm.ExDish.embryoList)
- //{
- // if (item.alarm == 0)
- // {
- // item.alarm = 1;
- // }
- // else
- // {
- // item.alarm = 0;
- // }
- //}
- InitAlarm();
- }
- });
- }
- private void InitAlarm()
- {
- if (vm == null || vm.ExDish == null) return;
- HouseCropAlarmResponse houseCropAlarmResponse = new HouseCropAlarmResponse();
- HouseCropAlarmResult CurrentHouseCropAlarmResult;
- houseCropAlarmResponse.tlSn = AppData.Instance.TlSn;
- if (!houseCropAlarmResponse.houseList.Any())
- {
- houseCropAlarmResponse.houseList.Add(new HouseCropAlarmHouseResponse
- {
- houseSn = vm.ExDish.houseSn,
- startTime = vm.ExDish.startTime,
- });
- }
- CurrentHouseCropAlarmResult = AppData.Instance.HttpHelper.GetHouseCropAlarmApi(houseCropAlarmResponse).FirstOrDefault(x => x.houseSn == vm.ExDish.houseSn);
- foreach (var item in vm.ExDish.embryoList)
- {
- if (CurrentHouseCropAlarmResult == null)
- {
- item.alarm = 0;
- continue;
- }
- if (CurrentHouseCropAlarmResult.wellSn.Contains(item.wellSn))
- {
- item.alarm = 1;
- }
- else
- {
- item.alarm = 0;
- }
- }
- }
- public void disableButton(bool disable)
- {
- this.Button_yz.IsEnabled = disable;
- this.Button_ld.IsEnabled = disable;
- this.Button_sc.IsEnabled = disable;
- this.Button_zf.IsEnabled = disable;
- }
- private void ExLog(Exception ex, string name)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"DetailPageView.{name}", LogEnum.RunException);
- }
- private void ErrorLog(string mess, LogEnum logEnum)
- {
- AppData.Instance.LogHelper.TLLog($"DetailPageView.{mess}", logEnum);
- }
- public void ShowMessage(string mess)
- {
- new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, mess);
- }
- private void WellChangeEvent(int obj)
- {
- PlayerPause();
- ChangeEmbryo(obj);
- }
- public void ChangeEmbryo(int well)
- {
- try
- {
- PlayerDispose();
- if (vm == null) return;
- vm.CurrentEmbryo = null;
- vm.CurrentWellDishPicAndVideo = null;
- vm.CurrentWellLayerPicAndVideo = null;
- vm.CurrentPic = null;
- SetVideoButtonState(false);
- vm.CurrentFocal = 0;
- BigFocusIsEnabled(true);
- SmallFocusIsEnabled(true);
- if (vm.ExDish != null && vm.ExDish.id > 0) vm.CurrentEmbryo = vm.ExDish.embryoList.FirstOrDefault(x => x.wellSn == well);
- if (vm.CurrentEmbryo == null)
- {
- vm.VideoAllTime = 1;
- vm.VideoCurrentTime = 0;
- }
- if (vm.CurrentEmbryo != null) vm.CurrentWellDishPicAndVideo = vm.DishPicAndVideoList.FirstOrDefault(x => x.wellSn == vm.CurrentEmbryo.wellSn);
- if (vm.CurrentWellDishPicAndVideo != null) vm.CurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == 0);
- this._dishInfo.SetPreview(vm.CurrentWellDishPicAndVideo);
- if (vm.MaxTotalLayer == -1) if (vm.CurrentWellLayerPicAndVideo != null) vm.MaxTotalLayer = vm.CurrentWellLayerPicAndVideo.videoPictures.Max(x => x.totalLayer);
- SetVideo(vm.CurrentFocal, true);
- if (vm.CurrentWellLayerPicAndVideo != null && vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
- {
- BigFocusIsEnabled(true);
- SmallFocusIsEnabled(true);
- if (string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) || vm.CurrentWellLayerPicAndVideo.videoUrl == CleanVideoString)
- {
- vm.VideoAllTime = 1;
- vm.VideoCurrentTime = 0;
- vm.VideoAllTime = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
- vm.VideoCurrentTime = vm.VideoAllTime;
- }
- }
- else
- {
- BigFocusIsEnabled(false);
- SmallFocusIsEnabled(false);
- }
- }
- catch (Exception ex)
- {
- ExLog(ex, "ChangeEmbryo");
- }
- }
- private void LastEmbryo_Click(object sender, RoutedEventArgs e)
- {
- if (!this._dishInfo.IsLoaded) return;
- this._dishInfo.LastEmbryo();
- }
- private void NextEmbryo_Click(object sender, RoutedEventArgs e)
- {
- if (!this._dishInfo.IsLoaded) return;
- this._dishInfo.NextEmbryo();
- }
- /// <summary>
- /// 返回按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Return_Click(object sender, RoutedEventArgs e)
- {
- PlayerPause();
- PlayerDispose();
- if (vm != null && vm.ParentViewModel != null)
- {
- DishRecordView dishRecordView = new DishRecordView()
- {
- DataContext = vm.ParentViewModel,
- };
- AppData.Instance.MainWindow.LoadPage(dishRecordView);
- return;
- }
- AppData.Instance.BackMainPage();
- }
- #region 标记菜单
- //string s1 = "Whether or not to";
- //string s2 = "embryo No.";
- //string s3 = "Whether or not to cancel the";
- //string s4 = "mark of embryo No.";
- //string s5 = "Embryo No.";
- //string s6 = "has been";
- string s1 = KeyToStringConvert.GetLanguageStringByKey("C0307");
- string s2 = KeyToStringConvert.GetLanguageStringByKey("C0308");
- string s3 = KeyToStringConvert.GetLanguageStringByKey("C0309");
- string s4 = KeyToStringConvert.GetLanguageStringByKey("C0310");
- string s5 = KeyToStringConvert.GetLanguageStringByKey("C0311");
- string s6 = KeyToStringConvert.GetLanguageStringByKey("C0312");
- string spaceString = KeyToStringConvert.GetLanguageStringByKey("C0328");
- string haoString = KeyToStringConvert.GetLanguageStringByKey("C0327");
- /// <summary>
- /// 移植按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void EmbryoMove_Click(object sender, RoutedEventArgs e)
- {
- PlayerPause();
- if (vm.CurrentEmbryo == null) return;
- // M8-G3-1:胚胎操作命令入口埋点。
- using var _op = Aivfo.OperationLog.OperationLogger.Begin("胚胎操作", "移动胚胎");
- _op.Input(new { embryoId = vm.CurrentEmbryo.id, wellSn = vm.CurrentEmbryo.wellSn, houseSn = vm.CurrentEmbryo.houseSn, state = vm.CurrentEmbryo.state });
- string tag = KeyToStringConvert.GetLanguageStringByKey("C0136");
- string messInfo = GetMessageInfo(tag);
- int stateTag = 1;
- if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
- {
- tag = "完成";
- switch (vm.CurrentEmbryo.state)
- {
- case (int)EmbryoState.Freezing:
- messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0135"));
- stateTag = 2;
- break;
- case (int)EmbryoState.Transplant:
- messInfo = GetCancelMarkMessage();
- tag = "取消";
- break;
- case (int)EmbryoState.Cancellation:
- messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0138"));
- stateTag = 4;
- break;
- case (int)EmbryoState.Delete:
- messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0137"));
- stateTag = 3;
- break;
- }
- }
- EmbryoOp(tag, messInfo, stateTag);
- _op.Success();
- return;
- }
- //private void EmbryoMove_Click(object sender, RoutedEventArgs e)
- //{
- // PlayerPause();
- // if (vm.CurrentEmbryo == null) return;
- // string tag = "移植";
- // string messInfo = $"是否确定对{vm.CurrentEmbryo.wellSn}号胚胎进行移植?";
- // if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
- // {
- // tag = "完成";
- // switch (vm.CurrentEmbryo.state)
- // {
- // case (int)EmbryoState.Freezing:
- // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已冷冻";
- // break;
- // case (int)EmbryoState.Transplant:
- // messInfo = $"是否取消{vm.CurrentEmbryo.wellSn}号胚胎的移植标记";
- // tag = "取消";
- // break;
- // case (int)EmbryoState.Cancellation:
- // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已作废";
- // break;
- // case (int)EmbryoState.Delete:
- // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已删除";
- // break;
- // }
- // }
- // EmbryoOp(tag, messInfo);
- // return;
- //}
- /// <summary>
- /// 冷冻按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void EmbryoFree_Click(object sender, RoutedEventArgs e)
- {
- PlayerPause();
- if (vm.CurrentEmbryo == null) return;
- // M8-G3-1:胚胎操作命令入口埋点。
- using var _op = Aivfo.OperationLog.OperationLogger.Begin("胚胎操作", "释放胚胎");
- _op.Input(new { embryoId = vm.CurrentEmbryo.id, wellSn = vm.CurrentEmbryo.wellSn, houseSn = vm.CurrentEmbryo.houseSn, state = vm.CurrentEmbryo.state });
- string tag = KeyToStringConvert.GetLanguageStringByKey("C0135");
- string messInfo = GetMessageInfo(tag);
- int stateTag = 2;
- if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
- {
- tag = "完成";
- switch (vm.CurrentEmbryo.state)
- {
- case (int)EmbryoState.Transplant:
- messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0136"));
- stateTag = 1;
- break;
- case (int)EmbryoState.Freezing:
- messInfo = GetCancelMarkMessage();
- tag = "取消";
- break;
- case (int)EmbryoState.Cancellation:
- messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0138"));
- stateTag = 4;
- break;
- case (int)EmbryoState.Delete:
- messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0137"));
- stateTag = 3;
- break;
- }
- }
- EmbryoOp(tag, messInfo, stateTag);
- _op.Success();
- return;
- }
- //private void EmbryoFree_Click(object sender, RoutedEventArgs e)
- //{
- // PlayerPause();
- // if (vm.CurrentEmbryo == null) return;
- // string tag = "冷冻";
- // string messInfo = $"是否确定对{vm.CurrentEmbryo.wellSn}号胚胎进行冷冻?";
- // if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
- // {
- // tag = "完成";
- // switch (vm.CurrentEmbryo.state)
- // {
- // case (int)EmbryoState.Transplant:
- // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已移植";
- // break;
- // case (int)EmbryoState.Freezing:
- // messInfo = $"是否取消{vm.CurrentEmbryo.wellSn}号胚胎的冷冻标记";
- // tag = "取消";
- // break;
- // case (int)EmbryoState.Cancellation:
- // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已作废";
- // break;
- // case (int)EmbryoState.Delete:
- // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已删除";
- // break;
- // }
- // }
- // EmbryoOp(tag, messInfo);
- // return;
- //}
- /// <summary>
- /// 删除按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void EmbryoDel_Click(object sender, RoutedEventArgs e)
- {
- PlayerPause();
- if (vm.CurrentEmbryo == null) return;
- // M8-G3-1:胚胎操作命令入口埋点。
- using var _op = Aivfo.OperationLog.OperationLogger.Begin("胚胎操作", "删除胚胎");
- _op.Input(new { embryoId = vm.CurrentEmbryo.id, wellSn = vm.CurrentEmbryo.wellSn, houseSn = vm.CurrentEmbryo.houseSn, state = vm.CurrentEmbryo.state });
- string tag = KeyToStringConvert.GetLanguageStringByKey("C0137");
- string messInfo = GetMessageInfo(tag);
- int stateTag = 3;
- if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
- {
- tag = "完成";
- switch (vm.CurrentEmbryo.state)
- {
- case (int)EmbryoState.Transplant:
- messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0136"));
- stateTag = 1;
- break;
- case (int)EmbryoState.Freezing:
- messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0135"));
- stateTag = 2;
- break;
- case (int)EmbryoState.Cancellation:
- messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0138"));
- stateTag = 4;
- break;
- case (int)EmbryoState.Delete:
- messInfo = GetCancelMarkMessage();
- tag = "取消";
- break;
- }
- }
- EmbryoOp(tag, messInfo, stateTag);
- _op.Success();
- return;
- }
- //private void EmbryoDel_Click(object sender, RoutedEventArgs e)
- //{
- // PlayerPause();
- // if (vm.CurrentEmbryo == null) return;
- // string tag = "删除";
- // string messInfo = $"是否确定对{vm.CurrentEmbryo.wellSn}号胚胎进行删除?";
- // if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
- // {
- // tag = "完成";
- // switch (vm.CurrentEmbryo.state)
- // {
- // case (int)EmbryoState.Transplant:
- // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已移植";
- // break;
- // case (int)EmbryoState.Freezing:
- // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已冷冻";
- // break;
- // case (int)EmbryoState.Cancellation:
- // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已作废";
- // break;
- // case (int)EmbryoState.Delete:
- // messInfo = $"是否取消{vm.CurrentEmbryo.wellSn}号胚胎的删除标记";
- // tag = "取消";
- // break;
- // }
- // }
- // EmbryoOp(tag, messInfo);
- // return;
- //}
- /// <summary>
- /// 作废按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void EmbryoInv_Click(object sender, RoutedEventArgs e)
- {
- PlayerPause();
- if (vm.CurrentEmbryo == null) return;
- // M8-G3-1:胚胎操作命令入口埋点。
- using var _op = Aivfo.OperationLog.OperationLogger.Begin("胚胎操作", "作废胚胎");
- _op.Input(new { embryoId = vm.CurrentEmbryo.id, wellSn = vm.CurrentEmbryo.wellSn, houseSn = vm.CurrentEmbryo.houseSn, state = vm.CurrentEmbryo.state });
- string tag = KeyToStringConvert.GetLanguageStringByKey("C0138");
- string messInfo = GetMessageInfo(tag);
- int stateTag = 4;
- if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
- {
- tag = "完成";
- switch (vm.CurrentEmbryo.state)
- {
- case (int)EmbryoState.Transplant:
- messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0136"));
- stateTag = 1;
- break;
- case (int)EmbryoState.Freezing:
- messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0135"));
- stateTag = 2;
- break;
- case (int)EmbryoState.Cancellation:
- messInfo = GetCancelMarkMessage();
- tag = "取消";
- break;
- case (int)EmbryoState.Delete:
- messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("C0137"));
- stateTag = 3;
- break;
- }
- }
- EmbryoOp(tag, messInfo, stateTag);
- _op.Success();
- return;
- }
- //private void EmbryoInv_Click(object sender, RoutedEventArgs e)
- //{
- // PlayerPause();
- // if (vm.CurrentEmbryo == null) return;
- // string tag = "作废";
- // string messInfo = $"是否确定对{vm.CurrentEmbryo.wellSn}号胚胎进行作废?";
- // if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End)
- // {
- // tag = "完成";
- // switch (vm.CurrentEmbryo.state)
- // {
- // case (int)EmbryoState.Transplant:
- // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已移植";
- // break;
- // case (int)EmbryoState.Freezing:
- // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已冷冻";
- // break;
- // case (int)EmbryoState.Cancellation:
- // messInfo = $"是否取消{vm.CurrentEmbryo.wellSn}号胚胎的作废标记";
- // tag = "取消";
- // break;
- // case (int)EmbryoState.Delete:
- // messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已删除";
- // break;
- // }
- // }
- // EmbryoOp(tag, messInfo);
- // return;
- //}
- /// <summary>
- /// 结束按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void EmbryoOver_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- PlayerPause();
- if (vm.ExDish == null || vm.ExDish.id == 0) return;
- // M8-G3-1:胚胎操作命令入口埋点。
- using var _op = Aivfo.OperationLog.OperationLogger.Begin("胚胎操作", "结束胚胎培养");
- _op.Input(new { dishId = vm.ExDish.id, houseSn = vm.ExDish.houseSn, state = vm.ExDish.state });
- try
- {
- string tag = KeyToStringConvert.GetLanguageStringByKey("C0313");
- string messInfo = KeyToStringConvert.GetLanguageStringByKey("C0314");
- if (vm.ExDish.state == 0)
- {
- messInfo = KeyToStringConvert.GetLanguageStringByKey("C0315");
- tag = "完成";
- }
- EmbryoOp(tag, messInfo, 5);
- _op.Success();
- return;
- }
- catch (Exception)
- {
- _op.Fail("EmbryoOver_Click exception");
- throw;
- }
- }
- catch (Exception ex)
- {
- ExLog(ex, "EmbryoOver_Click");
- }
- //try
- //{
- // PlayerPause();
- // if (vm.ExDish == null || vm.ExDish.id == 0) return;
- // string tag = "结束";
- // string messInfo = $"是否结束培养所有胚胎?";
- // if (vm.ExDish.state == 0)
- // {
- // messInfo = "当前舱室已结束培养";
- // tag = "完成";
- // }
- // EmbryoOp(tag, messInfo,5);
- // return;
- //}
- //catch (Exception ex)
- //{
- // ExLog(ex, "EmbryoOver_Click");
- //}
- }
- /// <summary>
- /// 胚胎操作
- /// </summary>
- private void EmbryoOp(string tag, string infoString, int opType)
- {
- if (tag == "完成")
- {
- switch (opType)
- {
- case 1:
- tag = KeyToStringConvert.GetLanguageStringByKey("C0136");
- break;
- case 2:
- tag = KeyToStringConvert.GetLanguageStringByKey("C0135");
- break;
- case 3:
- tag = KeyToStringConvert.GetLanguageStringByKey("C0137");
- break;
- case 4:
- tag = KeyToStringConvert.GetLanguageStringByKey("C0138");
- break;
- }
- new MessageWindow(AppData.Instance.MainWindow, infoString, tag).ShowDialog();
- //new MessageWindow(AppData.Instance.MainWindow, infoString, KeyToStringConvert.GetLanguageStringByKey("C0171")).ShowDialog();
- return;
- }
- if (tag == "取消")
- {
- switch (opType)
- {
- case 1:
- tag = KeyToStringConvert.GetLanguageStringByKey("C0136");
- break;
- case 2:
- tag = KeyToStringConvert.GetLanguageStringByKey("C0135");
- break;
- case 3:
- tag = KeyToStringConvert.GetLanguageStringByKey("C0137");
- break;
- case 4:
- tag = KeyToStringConvert.GetLanguageStringByKey("C0138");
- break;
- }
- //tag = KeyToStringConvert.GetLanguageStringByKey("C0031");
- opType = 6;
- }
- if (tag == "结束")
- {
- tag = KeyToStringConvert.GetLanguageStringByKey("C0313");
- }
- // case "取消": EmbryoMark((int)EmbryoState.None); break;
- var rs = new MessageWindow(AppData.Instance.MainWindow, infoString, tag).ShowDialog();
- if (rs == true)
- {
- switch (opType)
- {
- case 2:
- EmbryoMark((int)EmbryoState.Freezing);
- break;
- case 4:
- EmbryoMark((int)EmbryoState.Cancellation);
- break;
- case 1:
- EmbryoMark((int)EmbryoState.Transplant);
- break;
- case 3:
- EmbryoMark((int)EmbryoState.Delete);
- break;
- case 5:
- Finish();
- break;
- case 6:
- EmbryoMark((int)EmbryoState.None);
- break;
- default:
- break;
- }
- }
- }
- //private void EmbryoOp(string tag, string infoString,int opType)
- //{
- // if (tag == "完成")
- // {
- // //new MessageWindow(AppData.Instance.MainWindow, infoString, "消息提示").ShowDialog();
- // new MessageWindow(AppData.Instance.MainWindow, infoString, KeyToStringConvert.GetLanguageStringByKey("C0171")).ShowDialog();
- // return;
- // }
- // var rs = new MessageWindow(AppData.Instance.MainWindow, infoString, tag).ShowDialog();
- // if (rs == true)
- // {
- // switch (tag)
- // {
- // case "冷冻":
- // EmbryoMark((int)EmbryoState.Freezing);
- // break;
- // case "作废":
- // EmbryoMark((int)EmbryoState.Cancellation);
- // break;
- // case "移植":
- // EmbryoMark((int)EmbryoState.Transplant);
- // break;
- // case "删除":
- // EmbryoMark((int)EmbryoState.Delete);
- // break;
- // case "结束":
- // Finish();
- // break;
- // case "取消":
- // EmbryoMark((int)EmbryoState.None);
- // break;
- // default:
- // break;
- // }
- // }
- //}
- /// <summary>
- /// 结束培养
- /// </summary>
- /// <exception cref="NotImplementedException"></exception>
- private void Finish()
- {
- try
- {
- if (!AppData.Instance.HttpHelper.EndCultureRecordApi(vm.ExDish.id))
- {
- //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "结束培养失败");
- new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0252"));
- return;
- }
- AppData.Instance.MainPageView.EndDish(vm.ExDish.houseSn);
- vm.ExDish = new ExDish();
- PlayerPause();
- PlayerDispose();
- if (vm != null && vm.ParentViewModel != null)
- {
- DishRecordView dishRecordView = new DishRecordView()
- {
- DataContext = vm.ParentViewModel,
- };
- AppData.Instance.MainWindow.LoadPage(dishRecordView);
- return;
- }
- AppData.Instance.BackMainPage();
- }
- catch (Exception ex)
- {
- ExLog(ex, "Finish");
- }
- }
- private void EmbryoMark(int embryoState)
- {
- try
- {
- if (!AppData.Instance.HttpHelper.MarkEmbryoDestinationApi(vm.CurrentEmbryo.id, embryoState))
- {
- //new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, "胚胎标记失败");
- new MessagePrompt().ShowCenterOwnerDefeat(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0253"));
- return;
- }
- DateTime ct = DateTime.Now;
- vm.CurrentEmbryo.state = embryoState;
- vm.CurrentEmbryo.stateTime = ct;
- this._dishInfo.SetEmbryoState(vm.CurrentEmbryo.wellSn, vm.CurrentEmbryo.state, vm.CurrentEmbryo.alarm);
- if(string.IsNullOrEmpty(vm.ExDish.endTime)) AppData.Instance.MainPageView.SetMainEmbryoState(vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.wellSn, vm.CurrentEmbryo.state);
- }
- catch (Exception ex)
- {
- ExLog(ex, "EmbryoMark");
- }
- }
- private string GetMessageInfo(string stateString)
- {
- return $"{s1}{spaceString}{stateString}{spaceString}{s2}{vm.CurrentEmbryo.wellSn}{haoString}?";
- }
- private string GetMarkMessage(string stateString)
- {
- return $"{s5}{vm.CurrentEmbryo.wellSn}{spaceString}{s6}{spaceString}{stateString}";
- }
- private string GetCancelMarkMessage()
- {
- return $"{s3}{spaceString}{vm.CurrentEmbryo.wellSn}{haoString}?";
- }
- #endregion
- #region 视频操作
- /// <summary>
- /// 播放暂停按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Image_MouseUp_Play(object sender, MouseButtonEventArgs e)
- {
- if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
- {
- if (PlayerState == PlayerStateEnum.Playing)
- {
- PlayerPause();
- }
- else
- {
- newCurrentTime = -1;
- //this._dishInfo._preview.Visibility = Visibility.Hidden;
- this._dishInfo.Cancas_Preview.Visibility = Visibility.Hidden;
- if (!PlayerPlay())
- {
- this._dishInfo.SetPreviewNoVideo();
- }
- }
- }
- else
- {
- this._dishInfo.SetPreviewNoVideo();
- }
- }
- /// <summary>
- /// 上一帧按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Image_MouseUp_PreviousFrame(object sender, MouseButtonEventArgs e)
- {
- if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
- {
- PlayerPause();
- PlayerLastFrame(AppData.Instance.TLSettingCommon.videoFps);
- //this._dishInfo._preview.Visibility = Visibility.Hidden;
- this._dishInfo.Cancas_Preview.Visibility = Visibility.Hidden;
- }
- }
- /// <summary>
- /// 下一帧按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Image_MouseUp_NextFrame(object sender, MouseButtonEventArgs e)
- {
- if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
- {
- PlayerPause();
- PlayerNextFrame(AppData.Instance.TLSettingCommon.videoFps);
- this._dishInfo.Cancas_Preview.Visibility = Visibility.Hidden;
- //this._dishInfo._preview.Visibility = Visibility.Hidden;
- }
- }
- /// <summary>
- /// 播放倍速按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void SpeedRatio_Click(object sender, RoutedEventArgs e)
- {
- PlayerPause();
- if (this._beilvwindow_Border.Height == 324)
- {
- CloseBeiLvWindow();
- }
- else
- {
- OpenBeiLvWindow();
- }
- }
- /// <summary>
- /// 关闭倍率设置按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BeiLvClose_MouseUp(object sender, MouseButtonEventArgs e)
- {
- CloseBeiLvWindow();
- }
- /// <summary>
- /// 设置倍率
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BeiLv_MouseUp(object sender, MouseButtonEventArgs e)
- {
- try
- {
- PlayerPause();
- if (sender is TextBlock text)
- {
- int k = int.Parse(text.Tag.ToString());
- //var v = 362.5 * k;
- var v = 290 * k;
- this._beilv_Rectangle.Width = v;
- this._beilv_Ellipse.Margin = new Thickness((v - 42), 0, 0, 0);
- double fps = -1;
- switch (k)
- {
- case 0:
- fps = 0.25;
- break;
- case 1:
- fps = 0.5;
- break;
- case 2:
- fps = 1.0;
- break;
- case 3:
- fps = 1.25;
- break;
- case 4:
- fps = 1.5;
- break;
- case 5:
- fps = 2.0;
- break;
- }
- if (fps != -1)
- {
- beilv = fps;
- this._radius_Button.Content = text.Text;
- }
- }
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}设置倍率", LogEnum.RunException);
- }
- }
- /// <summary>
- /// 上一层
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Image_MouseDown_BigFocus(object sender, MouseButtonEventArgs e)
- {
- PlayerPause();
- if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return;
- if (vm.CurrentEmbryo == null) return;
- if (vm.CurrentWellLayerPicAndVideo != null) ChangeFocalNoVideo(true);
- //PlayerPause();
- //if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return;
- //if (vm.CurrentEmbryo == null) return;
- //if (vm.CurrentWellLayerPicAndVideo != null) if (!string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl)) ChangeFocal(true);
- // else ChangeImageFocal(true);
- }
- /// <summary>
- /// 下一层
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Image_MouseDown_SmallFocus(object sender, MouseButtonEventArgs e)
- {
- PlayerPause();
- if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return;
- if (vm.CurrentEmbryo == null) return;
- if (vm.CurrentWellLayerPicAndVideo != null) ChangeFocalNoVideo(false);
- //PlayerPause();
- //ChangeFocal(false);
- //PlayerPause();
- //if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return;
- //if (vm.CurrentEmbryo == null) return;
- //if (vm.CurrentWellLayerPicAndVideo != null) if (!string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl)) ChangeFocal(false);
- // else ChangeImageFocal(false);
- }
- private void CustomQuickButton_ClickQuickPositionEvent(ButtonEntity obj)
- {
- try
- {
- PlayerPause();
- string quickName = obj.buttonName;
- int minHour = obj.minHour * 60;
- if (vm.CurrentWellLayerPicAndVideo == null || vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
- {
- //ShowMessage($"当前胚胎还未发育到{quickName}阶段");
- ShowMessage($"{KeyToStringConvert.GetLanguageStringByKey("C0320")} {quickName}");
- return;
- }
- var lastPic = vm.CurrentWellLayerPicAndVideo.videoPictures.Last();
- if (minHour > lastPic.developTime)
- {
- ShowMessage($"{KeyToStringConvert.GetLanguageStringByKey("C0320")} {quickName}");
- return;
- }
- int picCount = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
- for (int i = 0; i < picCount; i++)
- {
- var item = vm.CurrentWellLayerPicAndVideo.videoPictures[i];
- if (item.developTime > minHour)
- {
- if (string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) || vm.CurrentWellLayerPicAndVideo.videoUrl == CleanVideoString)
- {
- this._dishInfo.Cancas_Preview.Visibility = Visibility.Visible;
- vm.VideoCurrentTime = i + 1;
- this._dishInfo._preview.Source = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{item.imageUrl}?token={AppData.Instance.HttpHelper.GetToken()}");
- }
- else
- {
- if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
- {
- this._dishInfo.Cancas_Preview.Visibility = Visibility.Hidden;
- //double pro = ((i + 1) / (double)picCount) * vm.VideoAllTime;
- double pro = i * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps);
- SetTimeProgressbarProgressValue(pro);
- SetPlayerPosition(pro);
- }
- else
- {
- this._dishInfo.Cancas_Preview.Visibility = Visibility.Visible;
- vm.VideoCurrentTime = i + 1;
- this._dishInfo._preview.Source = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{item.imageUrl}?token={AppData.Instance.HttpHelper.GetToken()}");
- }
- }
- break;
- }
- //if (item.developTime > minHour)
- //{
- // this._dishInfo.Cancas_Preview.Visibility = Visibility.Hidden;
- // double pro = i * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps);
- // SetTimeProgressbarProgressValue(pro);
- // SetPlayerPosition(pro);
- // break;
- //}
- }
- }
- catch (Exception ex)
- {
- ExLog(ex, $"CustomQuickButton_ClickQuickPositionEvent");
- }
- }
- private void BeforeInteractionEvent()
- {
- PlayerPause();
- if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
- {
- //this._dishInfo._preview.Visibility = Visibility.Hidden;
- this._dishInfo.Cancas_Preview.Visibility = Visibility.Hidden;
- }
- }
- private void AfterInteractionEvent(double obj)
- {
- if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
- {
- currentMediaElement.LoadedBehavior = MediaState.Manual;
- SetPlayerPosition(obj);
- }
- else
- {
- if (vm.CurrentWellLayerPicAndVideo != null && vm.CurrentWellLayerPicAndVideo.videoPictures.Any()) this._dishInfo._preview.Source = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoPictures[ProToImageIndex()].imageUrl}?token={AppData.Instance.HttpHelper.GetToken()}");
- }
- }
- private void ProChangendEvent(double obj)
- {
- if (PlayerState != PlayerStateEnum.Nothing || PlayerState != PlayerStateEnum.Error) SetPlayerPosition(obj);
- }
- List<PictureEntity> PicList = null;
- int picCount = 0;
- int picIndex = 0;
- private string CustomProgressbar_LengthDevelopmentEvent(double arg)
- {
- try
- {
- if (vm == null || vm.CurrentWellLayerPicAndVideo == null)
- {
- vm.CurrentPic = null;
- return "00h:00m";
- }
- if (vm.CurrentWellLayerPicAndVideo == null || vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
- {
- vm.CurrentPic = null;
- return "00h:00m";
- }
- if (string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) || vm.CurrentWellLayerPicAndVideo.videoUrl == CleanVideoString)
- {
- picIndex = ProToImageIndex();
- vm.CurrentPic = vm.CurrentWellLayerPicAndVideo.videoPictures[picIndex];
- //Debug.WriteLine($"proLength {picIndex} ->{vm.CurrentWellLayerPicAndVideo.videoPictures.Count}");
- return $"{(vm.CurrentPic.developTime / 60).ToString("D2")}h:{(vm.CurrentPic.developTime % 60).ToString("D2")}m";
- }
- else
- {
- picCount = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
- picIndex = VideoProToImageIndex();
- if (picIndex < 0) picIndex = 0;
- if (picIndex > (picCount - 1)) picIndex = picCount - 1;
- vm.CurrentPic = vm.CurrentWellLayerPicAndVideo.videoPictures[picIndex];
- return $"{(vm.CurrentPic.developTime / 60).ToString("D2")}h:{(vm.CurrentPic.developTime % 60).ToString("D2")}m";
- }
- }
- catch (Exception ex)
- {
- vm.CurrentPic = null;
- ExLog(ex, "获取当前帧发育时长");
- return "00h:00m";
- }
- }
- /// <summary>
- /// 0- count-1
- /// </summary>
- /// <returns></returns>
- public int VideoProToImageIndex()
- {
- try
- {
- if (vm == null || vm.CurrentWellLayerPicAndVideo == null) return 0;
- return (int)(vm.VideoCurrentTime / (1000.00 / vm.CurrentWellLayerPicAndVideo.fps));
- }
- catch (Exception ex)
- {
- ExLog(ex, "VideoProToImageIndex");
- return 0;
- }
- //try
- //{
- // return (int)(vm.VideoCurrentTime / (1000.00 / vm.CurrentVideoFps));
- //}
- //catch (Exception ex)
- //{
- // ExLog(ex, "VideoProToImageIndex");
- // return 0;
- //}
- }
- /// <summary>
- /// 进度条换算图片下标
- /// </summary>
- /// <returns></returns>
- public int ProToImageIndex()
- {
- try
- {
- if (vm == null || vm.CurrentWellLayerPicAndVideo == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any()) return 0;
- var imageIndex = ((int)vm.VideoCurrentTime - 1);
- if (imageIndex < 0) imageIndex = 0;
- if (imageIndex >= vm.CurrentWellLayerPicAndVideo.videoPictures.Count) imageIndex = vm.CurrentWellLayerPicAndVideo.videoPictures.Count - 1;
- return imageIndex;
- }
- catch (Exception ex)
- {
- ExLog(ex, "ProToImageIndex");
- return 0;
- }
- }
- #endregion
- #region
- /// <summary>
- /// 切换图层
- /// </summary>
- /// <param name="isMax"></param>
- private void ChangeFocal(bool isMax)
- {
- try
- {
- if (vm.CurrentEmbryo == null) return;
- if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return;
- int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2;
- int minFocal = -maxFocal;
- int newCurrentFocal = vm.CurrentFocal;
- if (isMax) newCurrentFocal++;
- else newCurrentFocal--;
- if (newCurrentFocal < maxFocal) BigFocusIsEnabled(true);
- else BigFocusIsEnabled(false);
- if (newCurrentFocal > minFocal) SmallFocusIsEnabled(true);
- else SmallFocusIsEnabled(false);
- if (newCurrentFocal < minFocal || newCurrentFocal > maxFocal) return;
- //this._dishInfo._preview.Visibility = Visibility.Hidden;
- Task.Run(() =>
- {
- Dispatcher.Invoke(() =>
- {
- var a = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{AppData.Instance.HttpHelper.GetImageUrlApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal, vm.CurrentPic.developTime)}?token={AppData.Instance.HttpHelper.GetToken()}");
- if (a != null)
- {
- this._dishInfo.Cancas_Preview.Visibility = Visibility.Visible;
- //this._dishInfo._preview.Visibility = Visibility.Visible;
- this._dishInfo._preview.Source = a;
- }
- });
- });
- newCurrentTime = 0;
- vm.CurrentFocal = newCurrentFocal;
- //SetVideoButtonState(false);
- //var time1 = stopwatch.Elapsed;
- //DebugLog($"切换图层确定新图层:{DateTime.Now},耗时:{time1.TotalMilliseconds}");
- if (vm.CurrentWellDishPicAndVideo == null) return;
- vm.CurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == vm.CurrentFocal);
- SetVideo(vm.CurrentFocal, false);
- if (vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
- {
- vm.CurrentWellLayerPicAndVideo.videoPictures = AppData.Instance.HttpHelper.GetVideoTimeLineApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, vm.CurrentFocal);
- }
- if (vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any() || vm.CurrentPic == null) return;
- int i = 0;
- foreach (var item in vm.CurrentWellLayerPicAndVideo.videoPictures)
- {
- if (item.developTime >= vm.CurrentPic.developTime) break;
- i++;
- }
- newCurrentTime = i * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps);
- //if (i == 0) newCurrentTime = 0;
- //else newCurrentTime = (i + 1) * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps);
- //var time2 = stopwatch.Elapsed;
- //DebugLog($"切换图层确定新图层:{DateTime.Now},耗时:{(time2 - time1).TotalMilliseconds},切换图层以及设置视频源总耗时:{time2.TotalMilliseconds}");
- }
- catch (Exception ex)
- {
- ExLog(ex, "ChangeFocal");
- }
- }
- private void ChangeFocalNoVideo(bool isMax)
- {
- try
- {
- //DebugLog($"开始切换图层:{DateTime.Now}");
- int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2;
- int minFocal = -maxFocal;
- int newCurrentFocal = vm.CurrentFocal;
- CC:
- if (isMax) newCurrentFocal++;
- else newCurrentFocal--;
- if (newCurrentFocal < maxFocal) BigFocusIsEnabled(true);
- else BigFocusIsEnabled(false);
- if (newCurrentFocal > minFocal) SmallFocusIsEnabled(true);
- else SmallFocusIsEnabled(false);
- if (newCurrentFocal < minFocal || newCurrentFocal > maxFocal) return;
- var aa = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == newCurrentFocal);
- if (aa == null) goto CC;
- if (aa.videoPictures == null || !aa.videoPictures.Any())
- {
- aa.videoPictures = AppData.Instance.HttpHelper.GetVideoTimeLineApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal);
- }
- if (aa.videoPictures == null || !aa.videoPictures.Any()) goto CC;
- bool b = false;
- string imageUrl = null;
- foreach (var item in aa.videoPictures)
- {
- if (item.developTime == vm.CurrentPic.developTime)
- {
- b = true;
- imageUrl = item.imageUrl;
- break;
- }
- }
- if (!b) goto CC;
- Task.Run(() =>
- {
- if (string.IsNullOrEmpty(imageUrl)) imageUrl = AppData.Instance.HttpHelper.GetImageUrlApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal, vm.CurrentPic.developTime);
- Dispatcher.Invoke(() =>
- {
- var a = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{imageUrl}?token={AppData.Instance.HttpHelper.GetToken()}");
- if (a != null)
- {
- //this._dishInfo._preview.Visibility = Visibility.Visible;
- this._dishInfo.Cancas_Preview.Visibility = Visibility.Visible;
- this._dishInfo._preview.Source = a;
- }
- });
- });
- vm.CurrentFocal = newCurrentFocal;
- }
- catch (Exception ex)
- {
- ExLog(ex, "ChangeFocalNoVideo");
- }
- }
- /// <summary>
- /// 切换图层
- /// </summary>
- /// <param name="isMax"></param>
- private void ChangeImageFocal(bool isMax)
- {
- try
- {
- int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2;
- int minFocal = -maxFocal;
- int newCurrentFocal = vm.CurrentFocal;
- CC:
- if (isMax) newCurrentFocal++;
- else newCurrentFocal--;
- if (newCurrentFocal < maxFocal) BigFocusIsEnabled(true);
- else BigFocusIsEnabled(false);
- if (newCurrentFocal > minFocal) SmallFocusIsEnabled(true);
- else SmallFocusIsEnabled(false);
- if (newCurrentFocal < minFocal || newCurrentFocal > maxFocal) return;
- var newCurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == newCurrentFocal);
- newCurrentWellLayerPicAndVideo = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == newCurrentFocal);
- if (newCurrentWellLayerPicAndVideo == null)
- {
- goto CC;
- return;
- }
- if (!newCurrentWellLayerPicAndVideo.videoPictures.Any())
- {
- goto CC;
- return;
- }
- vm.CurrentWellLayerPicAndVideo = newCurrentWellLayerPicAndVideo;
- //this._dishInfo._preview.Visibility = Visibility.Visible;
- this._dishInfo.Cancas_Preview.Visibility = Visibility.Visible;
- var oldDevelopTime = vm.CurrentPic.developTime;
- vm.CurrentFocal = newCurrentFocal;
- vm.VideoAllTime = vm.CurrentWellLayerPicAndVideo.videoPictures.Count;
- int i = 0;
- foreach (var item in vm.CurrentWellLayerPicAndVideo.videoPictures)
- {
- if (item.developTime >= oldDevelopTime) break;
- i++;
- }
- //Debug.WriteLine($"{vm.CurrentWellLayerPicAndVideo.videoPictures[163].developTime} -> {oldDevelopTime}");
- //Debug.WriteLine($"focal:{i} -》 {vm.CurrentWellLayerPicAndVideo.videoPictures.Count}");
- //vm.VideoCurrentTime = vm.VideoAllTime;
- this._dishInfo._preview.Source = AppData.Instance.ConvertHelper.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoPictures[i].imageUrl}?token={AppData.Instance.HttpHelper.GetToken()}");
- vm.VideoCurrentTime = 0;
- vm.VideoCurrentTime = i + 1;
- return;
- }
- catch (Exception ex)
- {
- ExLog(ex, "ChangeImageFocal");
- }
- }
- /// <summary>
- /// 设置视频
- /// </summary>
- private bool SetVideo(int focal, bool isUpdate)
- {
- if (vm.CurrentWellLayerPicAndVideo != null && !string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) && vm.CurrentWellLayerPicAndVideo.videoUrl != CleanVideoString)
- {
- if (PlayerSetSource($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoUrl}?token={AppData.Instance.HttpHelper.GetToken()}")) return true;
- }
- if (!isUpdate) return false;
- vm.VideoAllTime = 1;
- vm.VideoCurrentTime = 0;
- return true;
- }
- private void BigFocusIsEnabled(bool isEn)
- {
- if (this._bigFocus_Border.IsEnabled == isEn) return;
- this._bigFocus_Border.IsEnabled = isEn;
- if (isEn)
- {
- this._bigFocus_Border.Background = (LinearGradientBrush)this.FindResource("BuleLinear");
- this._bigFocus_Image.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/prePicNum.png", UriKind.RelativeOrAbsolute));
- }
- else
- {
- this._bigFocus_Border.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#8B8B8B"));
- this._bigFocus_Image.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/prePicNumEnabled.png", UriKind.RelativeOrAbsolute));
- }
- }
- private void SmallFocusIsEnabled(bool isEn)
- {
- if (this._smallFocus_Border.IsEnabled == isEn) return;
- this._smallFocus_Border.IsEnabled = isEn;
- if (isEn)
- {
- this._smallFocus_Border.Background = (LinearGradientBrush)this.FindResource("BuleLinear");
- this._smallFocus_Image.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/nextPicNum.png", UriKind.RelativeOrAbsolute));
- }
- else
- {
- this._smallFocus_Border.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#8B8B8B"));
- this._smallFocus_Image.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/nextPicNumEnabled.png", UriKind.RelativeOrAbsolute));
- }
- }
- #endregion
- #region 视频基础操作
- MediaElement currentMediaElement = null;
- string currentViewName = "详情页面";
- /// <summary>
- /// 定时器
- /// </summary>
- public System.Timers.Timer dispatcherTimer = new System.Timers.Timer();
- /// <summary>
- /// 视频状态
- /// </summary>
- public PlayerStateEnum PlayerState { get; set; } = PlayerStateEnum.Nothing;
- /// <summary>
- /// 播放器事件初始化
- /// </summary>
- public void PlayerEvent(MediaElement mediaElement)
- {
- try
- {
- currentMediaElement = mediaElement;
- currentMediaElement.MediaEnded -= MediaEndedEvent;
- currentMediaElement.MediaOpened -= MediaOpenedEvent;
- currentMediaElement.MediaFailed -= MediaFailedEvent;
- currentMediaElement.MediaEnded += MediaEndedEvent;
- currentMediaElement.MediaOpened += MediaOpenedEvent;
- currentMediaElement.MediaFailed += MediaFailedEvent;
- dispatcherTimer.Interval = 25;
- dispatcherTimer.Elapsed -= dispatcherTimer_Elapsed;
- dispatcherTimer.Elapsed += dispatcherTimer_Elapsed;
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}播放器事件初始化", LogEnum.RunException);
- }
- }
- /// <summary>
- /// 设置播放源
- /// </summary>
- /// <param name="FileName"></param>
- public bool PlayerSetSource(string FileName)
- {
- try
- {
- ErrorLog($"开始加载视频,{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}", LogEnum.TakeTime);
- PlayerDispose();
- //指定媒体文件地址
- currentMediaElement.LoadedBehavior = MediaState.Manual;
- currentMediaElement.SpeedRatio = 1;
- beilv = 1;
- ChangeBeiLvUi();
- this._radius_Button.Content = "1.0x";
- this._radius_Button.Tag = 1.0;
- currentMediaElement.Source = new Uri(FileName, UriKind.RelativeOrAbsolute);
- currentMediaElement.ScrubbingEnabled = true;
- currentMediaElement.Play();
- currentMediaElement.Pause();
- return true;
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}设置播放源", LogEnum.RunException);
- return false;
- }
- }
- /// <summary>
- /// 播放器加载视频完成事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MediaOpenedEvent(object sender, RoutedEventArgs e)
- {
- try
- {
- if (vm == null) return;
- //ErrorLog($"视频加载完成,开始设置属性,{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")},[{currentMediaElement.Source}]", LogEnum.TakeTime);
- ErrorLog($"视频加载完成", LogEnum.TakeTime);
- currentMediaElement.ScrubbingEnabled = false;
- vm.VideoAllTime = 1;
- vm.VideoCurrentTime = 0;
- if (currentMediaElement.NaturalDuration.HasTimeSpan)
- {
- currentMediaElement.LoadedBehavior = MediaState.Manual;
- PlayerState = PlayerStateEnum.Paused;
- currentMediaElement.Play();
- currentMediaElement.Pause();
- vm.VideoAllTime = currentMediaElement.NaturalDuration.TimeSpan.TotalMilliseconds;
- if (newCurrentTime != -1)
- {
- if (newCurrentTime < 0) newCurrentTime = 0;
- if (newCurrentTime > vm.VideoAllTime) newCurrentTime = vm.VideoAllTime;
- SetTimeProgressbarProgressValue(newCurrentTime);
- SetPlayerPosition(vm.VideoCurrentTime);
- newCurrentTime = -1;
- }
- else
- {
- SetTimeProgressbarProgressValue(vm.VideoAllTime);
- SetPlayerPosition(vm.VideoCurrentTime);
- }
- currentMediaElement.ScrubbingEnabled = true;
- SetVideoButtonState(true);
- }
- else
- {
- PlayerState = PlayerStateEnum.Nothing;
- }
- ErrorLog($"视频加载完成,{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}", LogEnum.TakeTime);
- }
- catch (Exception ex)
- {
- PlayerState = PlayerStateEnum.Error;
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}播放器加载视频完成事件", LogEnum.RunException);
- }
- }
- /// <summary>
- /// 播放完成事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MediaEndedEvent(object sender, RoutedEventArgs e)
- {
- try
- {
- PlayerState = PlayerStateEnum.Paused;
- dispatcherTimer_Stop();
- // currentMediaElement.Stop();
- currentMediaElement.Play();
- currentMediaElement.Pause();
- SetTimeProgressbarProgressValue(vm.VideoAllTime);
- SetPlayerPosition(vm.VideoAllTime);
- SetPlayButton(false);
- //currentMediaElement.Position = currentMediaElement.NaturalDuration.TimeSpan;
- //currentMediaElement.Play();
- //currentMediaElement.Pause();
- //PlayerSetPosition(1);
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}播放完成事件", LogEnum.RunException);
- }
- }
- /// <summary>
- /// 播放器错误事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- /// <exception cref="NotImplementedException"></exception>
- private void MediaFailedEvent(object? sender, ExceptionRoutedEventArgs e)
- {
- try
- {
- PlayerState = PlayerStateEnum.Error;
- vm.VideoAllTime = 1;
- vm.VideoCurrentTime = 0;
- string ss = "";
- MediaElement med = sender as MediaElement;
- if (med != null)
- {
- ss = med.Source.ToString();
- AppData.Instance.LogHelper.TLLog($"{ss},{currentViewName}视频遇到错误", LogEnum.RunError);
- }
- dispatcherTimer_Stop();
- AppData.Instance.LogHelper.ExceptionLog(e.ErrorException, $"{currentViewName}.MediaFailedEvent:{ss}", LogEnum.RunException);
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"播放器错误事件:{JsonConvert.SerializeObject(ex)}", LogEnum.RunException);
- }
- }
- /// <summary>
- /// 播放按钮图标设置
- /// </summary>
- private void SetPlayButton(bool isPlaying)
- {
- if (isPlaying)//正在播放,设置为暂停按钮
- {
- _playButton.Source = new BitmapImage(new Uri("/Resources/Image/video_Pause.png", UriKind.RelativeOrAbsolute));
- }
- else//未播放,设置为播放按钮
- {
- _playButton.Source = new BitmapImage(new Uri("/Resources/Image/video_play.png", UriKind.RelativeOrAbsolute));//重置播放按钮
- }
- }
- /// <summary>
- /// 定时器事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dispatcherTimer_Elapsed(object? sender, ElapsedEventArgs e)
- {
- try
- {
- Dispatcher.Invoke(() =>
- {
- SetTimeProgressbarProgressValue(currentMediaElement.Position.TotalMilliseconds);
- });
- if (PlayerState != PlayerStateEnum.Playing)
- {
- dispatcherTimer_Stop();
- }
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}定时器事件", LogEnum.RunException);
- }
- }
- /// <summary>
- /// 停止定时器
- /// </summary>
- public void dispatcherTimer_Stop()
- {
- try
- {
- if (dispatcherTimer.Enabled)
- {
- dispatcherTimer.Enabled = false;
- dispatcherTimer.Stop();
- }
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}停止定时器", LogEnum.RunException);
- }
- }
- public bool isMediaOpened = true;
- /// <summary>
- ///设置视频进度
- /// </summary>
- /// <param name="progressValue"></param>
- public void SetPlayerPosition(double currentTime)
- {
- try
- {
- if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
- {
- //var a = currentMediaElement.NaturalDuration.TimeSpan.TotalMilliseconds;
- currentMediaElement.Position = TimeSpan.FromMilliseconds(currentTime);
- //var a = currentMediaElement.NaturalDuration.TimeSpan.TotalMilliseconds * progressValue;
- //int k = (int)(PlayerAllTime - a);
- //if (k < 0)
- //{
- // k = 0;
- //}
- //vm.PlayTimeString = RevertToTime(b);
- //vm.AllTimeString = RevertToTime(TimeSpan.FromMilliseconds(k));
- }
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}进度条变换以后设置视频进度", LogEnum.RunException);
- }
- }
- /// <summary>
- /// 设置进度条
- /// </summary>
- public void SetTimeProgressbarProgressValue(double newTime)
- {
- try
- {
- if (vm == null) return;
- vm.VideoCurrentTime = newTime;
- //var currentPosition = currentMediaElement.Position.TotalMilliseconds;
- //var b = (currentPosition) / PlayerAllTime;
- //if (b == 0 && PlayerState == PlayerStateEnum.Playing)
- //{
- // return;
- //}
- //vm.PlayTimeString = RevertToTime(currentMediaElement.Position);
- //SetProValue(b);
- //int k = (int)(PlayerAllTime - currentPosition);
- //if (k < 0)
- //{
- // k = 0;
- //}
- //vm.AllTimeString = RevertToTime(TimeSpan.FromMilliseconds(k));
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}视频进度变换以后设置进度条", LogEnum.RunException);
- }
- }
- /// <summary>
- /// 设置进度条进度
- /// </summary>
- /// <param name="newValue"></param>
- public void SetProValue(double newValue)
- {
- //if (vm.ProgressValue == newValue)
- //{
- // var maxNewValue = newValue + 0.01;
- // if (maxNewValue > 1)
- // {
- // var minNewValue = newValue - 0.01;
- // vm.ProgressValue = minNewValue;
- // }
- // else
- // {
- // vm.ProgressValue = maxNewValue;
- // }
- //}
- //vm.ProgressValue = newValue;
- }
- /// <summary>
- /// 释放播放器
- /// </summary>
- public void PlayerDispose()
- {
- try
- {
- dispatcherTimer_Stop();
- if (PlayerState != PlayerStateEnum.Nothing)
- {
- currentMediaElement.Close();
- currentMediaElement.LoadedBehavior = MediaState.Close;
- PlayerState = PlayerStateEnum.Nothing;
- }
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}释放播放器", LogEnum.RunException);
- }
- }
- /// <summary>
- /// 设置倍率
- /// </summary>
- /// <param name="newSpeedRatio"></param>
- public void PlayerSetSpeedRatio(double newSpeedRatio)
- {
- try
- {
- if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
- {
- currentMediaElement.SpeedRatio = newSpeedRatio;
- }
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}设置倍率", LogEnum.RunException);
- }
- }
- /// <summary>
- /// 播放操作
- /// </summary>
- public bool PlayerPlay()
- {
- try
- {
- bool isPlay = false;
- switch (PlayerState)
- {
- case PlayerStateEnum.Error:
- break;
- case PlayerStateEnum.Nothing:
- break;
- case PlayerStateEnum.Opened:
- isPlay = true;
- break;
- case PlayerStateEnum.Paused:
- isPlay = true;
- break;
- case PlayerStateEnum.Playing:
- break;
- case PlayerStateEnum.Stopped:
- currentMediaElement.Stop();
- isPlay = true;
- break;
- default:
- AppData.Instance.LogHelper.TLLog($"{currentViewName}.PlayerPlay,未知的视频状态:{PlayerState.ToString()}", LogEnum.RunError);
- break;
- }
- if (isPlay)
- {
- PlayerState = PlayerStateEnum.Playing;
- if (!dispatcherTimer.Enabled)
- {
- dispatcherTimer.Start();
- }
- if (vm.VideoCurrentTime == vm.VideoAllTime)
- {
- SetPlayerPosition(0);
- }
- //var a = currentMediaElement.Position.TotalMilliseconds;
- PlayerSetSpeedRatio(beilv);
- currentMediaElement.Play();
- SetPlayButton(true);
- return true;
- }
- return false;
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}播放操作", LogEnum.RunException);
- return false;
- }
- }
- /// <summary>
- /// 暂停操作
- /// </summary>
- /// <param name="isSetState"></param>
- public bool PlayerPause()
- {
- try
- {
- bool isPause = false;
- switch (PlayerState)
- {
- case PlayerStateEnum.Error:
- break;
- case PlayerStateEnum.Nothing:
- break;
- case PlayerStateEnum.Opened:
- break;
- case PlayerStateEnum.Paused:
- break;
- case PlayerStateEnum.Playing:
- isPause = true;
- break;
- case PlayerStateEnum.Stopped:
- break;
- }
- if (isPause)
- {
- PlayerState = PlayerStateEnum.Paused;
- currentMediaElement.Pause();
- dispatcherTimer_Stop();
- SetPlayButton(false);
- return true;
- }
- return false;
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}暂停操作", LogEnum.RunException);
- return false;
- }
- }
- /// <summary>
- /// 上一帧
- /// </summary>
- public void PlayerLastFrame(int zhenshu)
- {
- try
- {
- bool isOK = false;
- bool isStop = false;
- switch (PlayerState)
- {
- case PlayerStateEnum.Error:
- break;
- case PlayerStateEnum.Nothing:
- break;
- case PlayerStateEnum.Opened:
- isOK = true;
- break;
- case PlayerStateEnum.Paused:
- isOK = true;
- break;
- case PlayerStateEnum.Playing:
- break;
- case PlayerStateEnum.Stopped:
- isOK = true;
- break;
- }
- if (isOK)
- {
- if (vm.VideoCurrentTime == 0) return;
- var c = vm.VideoCurrentTime - (1000.00 / zhenshu);
- if (c < 0) c = 0;
- SetPlayerPosition(c);
- SetTimeProgressbarProgressValue(c);
- //var zhen = (1000 / zhenshu);
- //var currentPositionTime = currentMediaElement.Position.TotalMilliseconds;
- //if (currentPositionTime == 0)
- //{
- // return;
- //}
- //if (currentPositionTime < zhen)
- //{
- // SetPlayerPosition(0);
- // SetTimeProgressbarProgressValue(0);
- // return;
- //}
- //var c = currentPositionTime - zhen;
- //SetPlayerPosition(c);
- //SetTimeProgressbarProgressValue(c);
- //currentMediaElement.Position = c;
- //SetTimeProgressbarProgressValue(1);
- return;
- }
- else
- {
- }
- //if (isStop)
- //{
- // currentMediaElement.Position = TimeSpan.FromMilliseconds(currentMediaElement.NaturalDuration.TimeSpan.TotalMilliseconds - (1000 / zhenshu));
- // SetTimeProgressbarProgressValue(1);
- // return;
- //}
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}上一帧", LogEnum.RunException);
- }
- }
- /// <summary>
- /// 下一帧
- /// </summary>
- public void PlayerNextFrame(int zhenshu)
- {
- try
- {
- bool isOK = false;
- bool isStop = false;
- switch (PlayerState)
- {
- case PlayerStateEnum.Error:
- break;
- case PlayerStateEnum.Nothing:
- break;
- case PlayerStateEnum.Opened:
- isOK = true;
- break;
- case PlayerStateEnum.Paused:
- isOK = true;
- break;
- case PlayerStateEnum.Playing:
- break;
- case PlayerStateEnum.Stopped:
- isOK = true;
- break;
- }
- if (!isOK) return;
- if (vm.VideoCurrentTime == vm.VideoAllTime) return;
- var newpos = vm.VideoCurrentTime + (1000d / zhenshu);
- if (newpos > vm.VideoAllTime) newpos = vm.VideoAllTime;
- SetPlayerPosition(newpos);
- SetTimeProgressbarProgressValue(newpos);
- return;
- //if (isOK)
- //{
- // var newpos = currentMediaElement.Position.TotalMilliseconds + (1000 / zhenshu);
- // if (newpos > vm.VideoAllTime)
- // {
- // newpos = vm.VideoAllTime;
- // }
- // SetPlayerPosition(newpos);
- // SetTimeProgressbarProgressValue(newpos);
- // return;
- //}
- //else
- //{
- //}
- //if (isStop)
- //{
- // return;
- //}
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}下一帧", LogEnum.RunException);
- }
- }
- #endregion
- /// <summary>
- /// 转换为时分秒格式
- /// </summary>
- /// <param name="timespan"></param>
- /// <returns></returns>
- public string RevertToTime(TimeSpan timespan)
- {
- return $"{(timespan.Days * 24 + timespan.Hours).ToString("D2")}:{timespan.Minutes.ToString("D2")}:{(timespan.Seconds + ((int)Math.Round(timespan.Milliseconds / 1000.00))).ToString("D2")}";
- }
- public void ChangeBeiLvUi()
- {
- int k = 1;
- switch (beilv)
- {
- case 0.5:
- k = 0;
- break;
- case 0.75:
- k = 1;
- break;
- case 1.0:
- k = 2;
- break;
- case 1.25:
- k = 3;
- break;
- case 1.5:
- k = 4;
- break;
- }
- var v = 362.5 * k;
- this._beilv_Rectangle.Width = v;
- this._beilv_Ellipse.Margin = new Thickness((v - 42), 0, 0, 0);
- }
- /// <summary>
- /// 打开倍率窗口
- /// </summary>
- public void OpenBeiLvWindow()
- {
- try
- {
- if (this._beilvwindow_Border.Height == 324)
- {
- return;
- }
- double width = 0;
- double to = 324;
- DoubleAnimation doubleAnimation = new DoubleAnimation();
- doubleAnimation.From = width;
- doubleAnimation.To = to;
- doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.1));
- this._beilvwindow_Border.BeginAnimation(FrameworkElement.HeightProperty, doubleAnimation);
- int k = 1;
- switch (beilv)
- {
- case 0.25:
- k = 0;
- break;
- case 0.5:
- k = 1;
- break;
- case 1.0:
- k = 2;
- break;
- case 1.25:
- k = 3;
- break;
- case 1.5:
- k = 4;
- break;
- case 2.0:
- k = 5;
- break;
- }
- //var v = 362.5 * k;
- var v = 290 * k;
- this._beilv_Rectangle.Width = v;
- this._beilv_Ellipse.Margin = new Thickness((v - 42), 0, 0, 0);
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}打开倍率窗口", LogEnum.RunException);
- }
- }
- /// <summary>
- /// 关闭倍率窗口
- /// </summary>
- public void CloseBeiLvWindow()
- {
- try
- {
- if (this._beilvwindow_Border.Height == 0)
- {
- return;
- }
- double width = 324;
- double to = 0;
- DoubleAnimation doubleAnimation = new DoubleAnimation();
- doubleAnimation.From = width;
- doubleAnimation.To = to;
- doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.1));
- this._beilvwindow_Border.BeginAnimation(FrameworkElement.HeightProperty, doubleAnimation);
- }
- catch (Exception ex)
- {
- AppData.Instance.LogHelper.ExceptionLog(ex, $"{currentViewName}关闭倍率窗口", LogEnum.RunException);
- }
- }
- private void Sure_Click(object sender, RoutedEventArgs e)
- {
- }
- private void Cancel_Click(object sender, RoutedEventArgs e)
- {
- }
- private void Grid_PreviewMouseUp(object sender, MouseButtonEventArgs e)
- {
- PlayerPause();
- AddDishWindowView addDishWindowView = new AddDishWindowView(vm.ExDish, vm.DishPicAndVideoList);
- AppData.Instance.MainWindow.Mark(true);
- var a = addDishWindowView.ShowDialog();
- AppData.Instance.MainWindow.Mark(false);
- if (a == true)
- {
- //new MessagePrompt().ShowCenterOwnerSuccess(AppData.Instance.MainWindow, "保存成功");
- new MessagePrompt().ShowCenterOwnerSuccess(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0242"));
- AppData.Instance.MainPageView.UpdateInfo();
- }
- e.Handled = true;
- }
- private void Pic_Click(object sender, RoutedEventArgs e)
- {
- if (vm == null || vm.CurrentEmbryo == null) return;
- PhotoPageViewModel photoPageViewModel = new PhotoPageViewModel(vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, vm.MaxTotalLayer);
- PhotoPageView dishRecordView = new PhotoPageView(vm, vm.CurrentEmbryo.wellSn)
- {
- DataContext = photoPageViewModel,
- };
- AppData.Instance.MainWindow.LoadPage(dishRecordView);
- }
- private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
- {
- PlayerPause();
- AddDishWindowView addDishWindowView = new AddDishWindowView(vm.ExDish, vm.DishPicAndVideoList);
- AppData.Instance.MainWindow.Mark(true);
- var a = addDishWindowView.ShowDialog();
- AppData.Instance.MainWindow.Mark(false);
- if (a == true)
- {
- //new MessagePrompt().ShowCenterOwnerSuccess(AppData.Instance.MainWindow, "保存成功");
- new MessagePrompt().ShowCenterOwnerSuccess(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("C0242"));
- AppData.Instance.MainPageView.UpdateInfo();
- }
- e.Handled = true;
- }
- private void SetVideoButtonState(bool IsEnabledVideo)
- {
- Task.Run(() =>
- {
- Dispatcher.Invoke(() =>
- {
- this.playButton.IsEnabled = IsEnabledVideo;
- if (IsEnabledVideo)
- {
- this.playButton.Background = (LinearGradientBrush)this.FindResource("BuleLinear");
- this.preZhenImage.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/preZhen.png", UriKind.RelativeOrAbsolute));
- this._playButton.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/video_play.png", UriKind.RelativeOrAbsolute));
- this.nextZhenImage.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/nextZhen.png", UriKind.RelativeOrAbsolute));
- }
- else
- {
- this.playButton.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#8B8B8B"));
- this.preZhenImage.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/preZhen1.png", UriKind.RelativeOrAbsolute));
- this._playButton.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/video_play1.png", UriKind.RelativeOrAbsolute));
- this.nextZhenImage.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/nextZhen1.png", UriKind.RelativeOrAbsolute));
- }
- //this._lastButton.IsEnabled = IsEnabledVideo;
- //this._playButton.IsEnabled = IsEnabledVideo;
- //this._nextButton.IsEnabled = IsEnabledVideo;
- });
- });
- }
- private void _dishInfo_IsMaxChangedEvent(bool obj)
- {
- if (obj)
- {
- this.lastBu.Visibility = Visibility.Visible;
- this.nextBu.Visibility = Visibility.Visible;
- }
- else
- {
- this.lastBu.Visibility = Visibility.Hidden;
- this.nextBu.Visibility = Visibility.Hidden;
- }
- }
- }
- }
|