| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215 |
- 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;
- 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);
- 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;
- 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);
- 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;
- 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);
- 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;
- 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);
- 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;
- string tag = KeyToStringConvert.GetLanguageStringByKey("C0313");
- string messInfo = KeyToStringConvert.GetLanguageStringByKey("C0314");
- if (vm.ExDish.state == 0)
- {
- messInfo = KeyToStringConvert.GetLanguageStringByKey("C0315");
- tag = "完成";
- }
- EmbryoOp(tag, messInfo, 5);
- return;
- }
- 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;
- }
- }
- }
- }
|