using ivf_tl_CustomControls; using ivf_tl_Entity.Entity; using ivf_tl_Entity.Entity.balance; using ivf_tl_Entity.Entity.Mark; using ivf_tl_Entity.Enums; using ivf_tl_Entity.Response; using ivf_tl_Manage.Converts; using ivf_tl_Manage.ViewModels; using ivf_tl_Manage.Win; using System; using System.Collections.Generic; 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.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace ivf_tl_Manage.Views { /// /// MarkUseView.xaml 的交互逻辑 /// public partial class MarkUseView : UserControl { string paiShe, peitai, shiping; private MarkUseViewModel vm = null; private Brush deaeatForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D75AC")); private Brush noEmbryoForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9B9B9B")); private Brush noPicForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D4D4D")); private double centerX, centerY; private double angle; private double angleOffset = 90; private int ellipseCount = 16; private int backImageRadius = 50; private int backImageBigRadius = 248; private int imageRadius = 40; private int imageBigRadius = 248; private int textBigRadius = 193; private int operRaius = 13; private int operBigRadius = 288; private int selectedIndex; private List TextBlockList = new List(); private List ImageList = new List(); private List PicImageList = new List(); private List OperImageList = new List(); private bool IsCleanVideo = false; public MarkUseView() { InitializeComponent(); paiShe = KeyToStringConvert.GetLanguageStringByKey("0509"); shiping = KeyToStringConvert.GetLanguageStringByKey("0510"); peitai = KeyToStringConvert.GetLanguageStringByKey("0511"); //paiShe = "拍摄中,请耐心等待"; //shiping = "暂无视频,请耐心等待"; //peitai = "暂无胚胎"; centerX = 710 / 2.0; centerY = 710 / 2.0; angle = 360.00 / 16; Loaded += MarkUseView_Loaded; Unloaded += (s, e) => { PlayerDispose(); Canvas_Root.Children.Clear(); TextBlockList.Clear(); ImageList.Clear(); PicImageList.Clear(); OperImageList.Clear(); if (vm != null) { vm.DingWeiEvent -= QuickButton_Click; foreach (var item in vm.CurrentDish.embryoList) { item.AlarmChangedEvent -= EmbryoAlarmEvent; } } vm = null; DataContext = null; }; } private async void MarkUseView_Loaded(object sender, RoutedEventArgs e) { vm = (MarkUseViewModel)this.DataContext; if (vm != null) InitNav(); InitCustomNew(); PlayerEvent(this.mediaElementPlayer); Task task = null; if (vm.isPdf) { task = Task.Factory.StartNew(() => vm.Initnew()); } if (task != null) await task.WaitAsync(new TimeSpan(0, 0, 30)); InitQuickButton(); SetEmbryoPic(); if (vm == null) { ChangeEmbryo(1); return; } else { if (vm.DishPicAndVideoList.Any()) { var a = vm.DishPicAndVideoList.First(); if (a.videos != null && a.videos.Any()) { var b = a.videos.FirstOrDefault(x => x.pictureLayer == 0); if (b != null && b.videoUrl == AppData.Instance.CleanVideoString) { IsCleanVideo = true; } } } if (vm.DetailViewModel != null && vm.DetailViewModel.CurrentEmbryo != null) { ChangeEmbryo(vm.DetailViewModel.CurrentEmbryo.wellSn); SelectIndex(vm.DetailViewModel.CurrentEmbryo.wellSn - 1); } else { ChangeEmbryo(1); } vm.CurrentMarkModelType = null; if (vm.MarkModelTypeList != null) { vm.CurrentMarkModelType = vm.MarkModelTypeList.First(); } } vm.DingWeiEvent -= QuickButton_Click; vm.DingWeiEvent += QuickButton_Click; foreach (var item in vm.CurrentDish.embryoList) { item.AlarmChangedEvent -= EmbryoAlarmEvent; item.AlarmChangedEvent += EmbryoAlarmEvent; } InitAlarm(); Task.Run(async () => { while (true) { await Task.Delay(10000); if (vm == null || vm.CurrentDish == null || AppData.Instance.CurrentTlInfo == null) return; //foreach (var item in vm.CurrentDish.embryoList) //{ // if (item.alarm == 0) item.alarm = 1; // else item.alarm = 0; //} InitAlarm(); } }); } private void InitAlarm() { if (vm == null || vm.CurrentDish == null || AppData.Instance.CurrentTlInfo == null) return; HouseCropAlarmResponse houseCropAlarmResponse = new HouseCropAlarmResponse(); HouseCropAlarmResult CurrentHouseCropAlarmResult = null; houseCropAlarmResponse.tlSn = AppData.Instance.CurrentTlInfo.tlSn; if (!houseCropAlarmResponse.houseList.Any()) { houseCropAlarmResponse.houseList.Add(new HouseCropAlarmHouseResponse { houseSn = vm.CurrentDish.houseSn, startTime = vm.CurrentDish.startTime, }); } CurrentHouseCropAlarmResult = vm.detailProvider.GetHouseCropAlarmApi(houseCropAlarmResponse).FirstOrDefault(x => x.houseSn == vm.CurrentDish.houseSn); foreach (var item in vm.CurrentDish.embryoList) { if (CurrentHouseCropAlarmResult == null) { item.alarm = 0; continue; } if (CurrentHouseCropAlarmResult.wellSn == null) { item.alarm = 0; continue; } if (CurrentHouseCropAlarmResult.wellSn.Contains(item.wellSn)) { item.alarm = 1; } else { item.alarm = 0; } } } private void InitNav() { _nav_StackPanel.Children.Clear(); for (int i = 0; i < vm.NavList.Count; i++) { var item = vm.NavList[i]; if (i == vm.NavList.Count - 1) { TextBlock textBlock1 = new TextBlock(); textBlock1.Margin = new Thickness(8, 0, 0, 0); textBlock1.FontWeight = FontWeights.Bold; textBlock1.Foreground = new SolidColorBrush(Colors.Black); textBlock1.FontSize = 32d; textBlock1.VerticalAlignment = VerticalAlignment.Center; textBlock1.Text = item.NavName; _nav_StackPanel.Children.Add(textBlock1); return; } Button button = new Button(); button.Content = item.NavName; button.FontWeight = FontWeights.Bold; button.FontSize = 28d; button.BorderThickness = new Thickness(0); button.Background = new SolidColorBrush(Colors.Transparent); button.Style = App.Current.FindResource("ButtonStyle1") as Style; if (i == 0) { button.Margin = new Thickness(0, 0, 0, 0); } else { button.Margin = new Thickness(8, 0, 0, 0); } button.Click += (s, e) => { PlayerDispose(); if (vm != null) vm.NavList.Clear(); if (item is PatientManageViewModel patient) { patient.SetTLInfo(AppData.Instance.CurrentTlInfo); AppData.Instance.MainWindowViewModel.CurrentViewModle = patient; return; } AppData.Instance.MainWindowViewModel.CurrentViewModle = item; }; TextBlock textBlock = new TextBlock(); textBlock.Margin = new Thickness(8, 0, 0, 0); textBlock.VerticalAlignment = VerticalAlignment.Center; textBlock.FontWeight = FontWeights.Bold; textBlock.FontSize = 28d; textBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9B9B9B")); textBlock.Text = ">"; _nav_StackPanel.Children.Add(button); _nav_StackPanel.Children.Add(textBlock); } } public void MessageShow(string message) { new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, message).Show(); } private void Toast(bool success) { new ToastWindow(AppData.Instance.MainWindow, 1920, 65, success).Show(); } private void ExLog(Exception ex, string name) { AppData.Instance.LogService.ExceptionLog(ex, $"MarkUseView.{name}", LogEnum.RunException); } private void ErrorLog(string message, LogEnum logType) { AppData.Instance.LogService.TLLog($"MarkUseView.{message}", logType); } #region 界面按钮 private void Button_Click(object sender, RoutedEventArgs e) { PlayerDispose(); AppData.Instance.MainWindowViewModel.CurrentViewModle = AppData.Instance.MainWindowViewModel.devManageViewModel; } private void Parien_Click(object sender, RoutedEventArgs e) { //PlayerDispose(); //AppData.Instance.MainWindowViewModel.patientManageViewModel.SetTLInfo(vm.tLInfo); //AppData.Instance.MainWindowViewModel.CurrentViewModle = AppData.Instance.MainWindowViewModel.patientManageViewModel; } private void Parien1_Click(object sender, RoutedEventArgs e) { //AppData.Instance.MainWindowViewModel.detailViewModel.Init(null, vm.tLInfo, vm.CurrentDish); AppData.Instance.MainWindowViewModel.CurrentViewModle = vm.DetailViewModel; } private void RecordParien_Click(object sender, RoutedEventArgs e) { AppData.Instance.MainWindowViewModel.CurrentViewModle = vm.RecordViewModel; } private void RecordParien1_Click(object sender, RoutedEventArgs e) { AppData.Instance.MainWindowViewModel.CurrentViewModle = vm.DetailViewModel; } private void BigFocus_Click(object sender, RoutedEventArgs e) { PlayerPause(); if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return; if (vm.CurrentEmbryo == null) return; if (vm.CurrentWellLayerPicAndVideo != null) ChangeFocalNoVideo(true); //if (vm.CurrentWellLayerPicAndVideo != null) if (!string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl)) ChangeFocalNoVideo(true); // else ChangeImageFocal(true); } private void SmallFocus_Click(object sender, RoutedEventArgs e) { PlayerPause(); if (vm == null || vm.CurrentPic == null || vm.CurrentWellDishPicAndVideo == null) return; if (vm.CurrentEmbryo == null) return; if (vm.CurrentWellLayerPicAndVideo != null) ChangeFocalNoVideo(false); //if (vm.CurrentWellLayerPicAndVideo != null) if (!string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl)) ChangeFocalNoVideo(false); // else ChangeImageFocal(false); } private void PreviousFrame_Click(object sender, RoutedEventArgs e) { if (vm == null || vm.CurrentWellLayerPicAndVideo == null) return; if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error) { PlayerPause(); PlayerLastFrame(vm.CurrentWellLayerPicAndVideo.fps); //this._preview.Visibility = Visibility.Hidden; this.Canvas_preview.Visibility = Visibility.Hidden; } } private void Video_Click(object sender, RoutedEventArgs e) { if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error) { if (PlayerState == PlayerStateEnum.Playing) { PlayerPause(); } else { newCurrentTime = -1; if (PlayerPlay()) { //this._preview.Visibility = Visibility.Hidden; this.Canvas_preview.Visibility = Visibility.Hidden; vm.CurrentFocal = 0; } else { SetPreviewNoVideo(); } } } else { SetPreviewNoVideo(); } } private void NextFrame_Click(object sender, RoutedEventArgs e) { if (vm == null || vm.CurrentWellLayerPicAndVideo == null) return; if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error) { PlayerPause(); PlayerNextFrame(vm.CurrentWellLayerPicAndVideo.fps); //PlayerNextFrame(vm.CurrentVideoFps); //this._preview.Visibility = Visibility.Hidden; this.Canvas_preview.Visibility = Visibility.Hidden; } } private void Fps_MouseUp(object sender, MouseButtonEventArgs e) { if (this._fps_Popup.IsOpen) this._fps_Popup.IsOpen = false; else this._fps_Popup.IsOpen = true; } private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (vm == null) return; PlayerSetSpeedRatio(vm.SelectedFps.Key); if (this._fps_Popup.IsOpen) this._fps_Popup.IsOpen = false; } private void QuickButton_Click(int minHour, int maxHour, string quickName) { try { PlayerPause(); if (vm.CurrentWellLayerPicAndVideo == null || vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any()) { //MessageShow($"当前胚胎还未发育到{quickName}阶段"); //MessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0316")}{quickName}{KeyToStringConvert.GetLanguageStringByKey("0264")}"); MessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0316")} {quickName}"); return; } var lastPic = vm.CurrentWellLayerPicAndVideo.videoPictures.Last(); if (minHour > lastPic.developTime) { //MessageShow($"当前胚胎还未发育到{quickName}阶段"); //MessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0316")}{quickName}{KeyToStringConvert.GetLanguageStringByKey("0264")}"); MessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0316")} {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 (IsCleanVideo) { this.Canvas_preview.Visibility = Visibility.Visible; vm.VideoCurrentTime = i + 1; this._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{item.imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}"); } else { if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error) { this.Canvas_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.Canvas_preview.Visibility = Visibility.Visible; vm.VideoCurrentTime = i + 1; this._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{item.imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}"); } } break; } } } catch (Exception ex) { ExLog(ex, $"QuickButton_Click"); } //try //{ // PlayerPause(); // if (vm.CurrentVideoData == null || vm.CurrentVideoData.videoPictures == null || !vm.CurrentVideoData.videoPictures.Any()) // { // MessageShow($"当前胚胎还未发育到{quickName}阶段"); // return; // } // var lastPic = vm.CurrentVideoData.videoPictures.Last(); // if (minHour > lastPic.developTime) // { // MessageShow($"当前胚胎还未发育到{quickName}阶段"); // return; // } // int picCount = vm.CurrentVideoData.videoPictures.Count; // for (int i = 0; i < picCount; i++) // { // var item = vm.CurrentVideoData.videoPictures[i]; // if (item.developTime > minHour) // { // this._preview.Visibility = Visibility.Hidden; // double pro = ((i + 1) / (double)picCount) * vm.VideoAllTime; // SetTimeProgressbarProgressValue(pro); // SetPlayerPosition(pro); // break; // } // } //} //catch (Exception ex) //{ // ExLog(ex, $"QuickButton_Click"); //} } private void Ok_Click(object sender, RoutedEventArgs e) { } private void Cancel_Click(object sender, RoutedEventArgs e) { } private void ListBox_ManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e) { e.Handled = true; } private void MarkDetailUserControl_SaveMarkEvent(ivf_tl_Entity.Entity.Mark.MarkEntity obj) { vm.SaveMark(obj); } #endregion #region 标记 string s1 = KeyToStringConvert.GetLanguageStringByKey("0521"); string s2 = KeyToStringConvert.GetLanguageStringByKey("0522"); string s3 = KeyToStringConvert.GetLanguageStringByKey("0523"); string s4 = KeyToStringConvert.GetLanguageStringByKey("0524"); string s5 = KeyToStringConvert.GetLanguageStringByKey("0525"); string s6 = KeyToStringConvert.GetLanguageStringByKey("0526"); string spaceString = KeyToStringConvert.GetLanguageStringByKey("0636"); string haoString = KeyToStringConvert.GetLanguageStringByKey("0635"); private void EmbryoMove_Click(object sender, RoutedEventArgs e) { PlayerPause(); if (vm.CurrentEmbryo == null) return; string tag = KeyToStringConvert.GetLanguageStringByKey("0041"); string messInfo = GetMessageInfo(tag); int iconType = 2; 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("0040")); iconType = 1; break; case (int)EmbryoState.Transplant: messInfo = GetCancelMarkMessage(); tag = "取消"; break; case (int)EmbryoState.Cancellation: messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0042")); iconType = 3; break; case (int)EmbryoState.Delete: messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0043")); iconType = 4; break; } } EmbryoOp(tag, messInfo, iconType); return; } private void EmbryoFree_Click(object sender, RoutedEventArgs e) { PlayerPause(); if (vm.CurrentEmbryo == null) return; int iconType = 1; string tag = KeyToStringConvert.GetLanguageStringByKey("0040"); string messInfo = GetMessageInfo(tag); if (vm.CurrentEmbryo.state != (int)EmbryoState.None && vm.CurrentEmbryo.state != (int)EmbryoState.End) { tag = "完成"; switch (vm.CurrentEmbryo.state) { case (int)EmbryoState.Freezing: messInfo = GetCancelMarkMessage(); tag = "取消"; break; case (int)EmbryoState.Transplant: messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0041")); iconType = 2; break; case (int)EmbryoState.Cancellation: messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0042")); iconType = 3; break; case (int)EmbryoState.Delete: messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0043")); iconType = 4; break; } } EmbryoOp(tag, messInfo, iconType); return; } private void EmbryoInv_Click(object sender, RoutedEventArgs e) { PlayerPause(); if (vm.CurrentEmbryo == null) return; int iconType = 3; string tag = KeyToStringConvert.GetLanguageStringByKey("0042"); string messInfo = GetMessageInfo(tag); 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("0040")); iconType = 1; break; case (int)EmbryoState.Transplant: messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0041")); iconType = 2; break; case (int)EmbryoState.Cancellation: messInfo = GetCancelMarkMessage(); tag = "取消"; break; case (int)EmbryoState.Delete: messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0043")); iconType = 4; break; } } EmbryoOp(tag, messInfo, iconType); return; } private void EmbryoDel_Click(object sender, RoutedEventArgs e) { PlayerPause(); if (vm.CurrentEmbryo == null) return; int iconType = 4; string tag = KeyToStringConvert.GetLanguageStringByKey("0043"); string messInfo = GetMessageInfo(tag); 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("0040")); iconType = 1; break; case (int)EmbryoState.Transplant: messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0041")); iconType = 2; break; case (int)EmbryoState.Cancellation: messInfo = GetMarkMessage(KeyToStringConvert.GetLanguageStringByKey("0042")); iconType = 3; break; case (int)EmbryoState.Delete: messInfo = GetCancelMarkMessage(); tag = "取消"; break; } } EmbryoOp(tag, messInfo, iconType); return; } private void EmbryoOp(string tag, string infoString, int type) { if (tag == "完成") { AppData.Instance.MainWindowViewModel.MaskVisibility = true; new MessagePrompt().ShowEmbryoOper(tag, infoString, type); AppData.Instance.MainWindowViewModel.MaskVisibility = false; return; } AppData.Instance.MainWindowViewModel.MaskVisibility = true; var rs = new MessagePrompt().ShowEmbryoOper(tag, infoString, type); AppData.Instance.MainWindowViewModel.MaskVisibility = false; if (rs != true) return; if (vm != null && vm.PdfParentViewModel != null) vm.PdfParentViewModel.IsUpdateAi = true; if (tag == "取消") { EmbryoMark((int)EmbryoState.None); return; } switch (type) { case 1: EmbryoMark((int)EmbryoState.Freezing); break; case 3: EmbryoMark((int)EmbryoState.Cancellation); break; case 2: EmbryoMark((int)EmbryoState.Transplant); break; case 4: EmbryoMark((int)EmbryoState.Delete); break; default: break; } } private void EmbryoMark(int embryoState) { try { //SetEmbryoState(vm.CurrentEmbryo.wellSn, embryoState, vm.CurrentEmbryo.alarm); //return; if (!vm.MarkEmbryo(embryoState)) { MessageShow(KeyToStringConvert.GetLanguageStringByKey("0319")); return; } DateTime ct = DateTime.Now; vm.CurrentEmbryo.state = embryoState; vm.CurrentEmbryo.stateTime = ct.ToString("yyyy-MM-dd HH:mm:ss"); SetEmbryoState(vm.CurrentEmbryo.wellSn, vm.CurrentEmbryo.state, vm.CurrentEmbryo.alarm); Toast(true); } 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}?"; } private void SetEmbryoState(int well, int embryoState, int alarm) { var item = OperImageList[(well - 1)]; var backItme = ImageList[(well - 1)]; EmbryoState state = (EmbryoState)embryoState; item.Visibility = Visibility.Visible; backItme.Tag = 3; switch (state) { case EmbryoState.Freezing://冷冻 item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState1Icon.png", UriKind.Absolute)); backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState1Icon.png", UriKind.Absolute)); break; case EmbryoState.Transplant://移植 item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState2Icon.png", UriKind.Absolute)); backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState2Icon.png", UriKind.Absolute)); break; case EmbryoState.Cancellation://作废 item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState3Icon.png", UriKind.Absolute)); backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState3Icon.png", UriKind.Absolute)); break; case EmbryoState.Delete://删除 item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState4Icon.png", UriKind.Absolute)); backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState4Icon.png", UriKind.Absolute)); break; default: item.Visibility = Visibility.Hidden; if (alarm == 0) { backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute)); } else { backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState3Icon.png", UriKind.Absolute)); } backItme.Tag = 2; break; } } private void ButtonBottomImage_Click(object sender, RoutedEventArgs e) { AppData.Instance.MainWindowViewModel.CurrentViewModle = new MarkDetailViewModel(vm, vm.CurrentDish.id); } bool isMax = false; double maxWidth = 610; double maxLeft = 50; double minWidth = 330; double minLeft = 190; private void PreviewMouseDownEvent(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2) { if (isMax == false) { _mask.Width = maxWidth; _mask.Height = maxWidth; mediaElementPlayer.Width = maxWidth; mediaElementPlayer.Height = maxWidth; canvas1.Width = maxWidth; canvas1.Height = maxWidth; isMax = true; Canvas.SetLeft(mediaElementPlayer, maxLeft); Canvas.SetTop(mediaElementPlayer, maxLeft); Canvas.SetLeft(_mask, maxLeft); Canvas.SetTop(_mask, maxLeft); Canvas.SetLeft(canvas1, maxLeft); Canvas.SetTop(canvas1, maxLeft); Panel.SetZIndex(mediaElementPlayer, 16); Panel.SetZIndex(canvas1, 18); } else { _mask.Width = minWidth; _mask.Height = minWidth; mediaElementPlayer.Width = minWidth; mediaElementPlayer.Height = minWidth; canvas1.Width = minWidth; canvas1.Height = minWidth; isMax = false; Canvas.SetLeft(mediaElementPlayer, minLeft); Canvas.SetTop(mediaElementPlayer, minLeft); Canvas.SetLeft(_mask, minLeft); Canvas.SetTop(_mask, minLeft); Canvas.SetLeft(canvas1, minLeft); Canvas.SetTop(canvas1, minLeft); Panel.SetZIndex(mediaElementPlayer, 8); Panel.SetZIndex(canvas1, 10); } SetLoad(isMax); SetPreView(isMax); } e.Handled = true; return; } private void SetLoad(bool isMax) { if (isMax) { Image_Load.Width = maxWidth; Image_Load.Height = maxWidth; Canvas_Load.Width = maxWidth; Canvas_Load.Height = maxWidth; TextBlock_Load.Width = maxWidth; TextBlock_Load.FontSize = 38; Canvas.SetTop(TextBlock_Load, 361); Canvas.SetLeft(Canvas_Load, maxLeft); Canvas.SetTop(Canvas_Load, maxLeft); Panel.SetZIndex(Canvas_Load, 15); } else { Image_Load.Width = minWidth; Image_Load.Height = minWidth; Canvas_Load.Width = minWidth; Canvas_Load.Height = minWidth; TextBlock_Load.Width = minWidth; TextBlock_Load.FontSize = 20; Canvas.SetTop(TextBlock_Load, 198); Canvas.SetLeft(Canvas_Load, minLeft); Canvas.SetTop(Canvas_Load, minLeft); Panel.SetZIndex(Canvas_Load, 7); } } private void SetPreView(bool isMax) { if (isMax) { _preview.Width = maxWidth; _preview.Height = maxWidth; Canvas_preview.Width = maxWidth; Canvas_preview.Height = maxWidth; TextBlock_preview.Width = maxWidth; TextBlock_preview.FontSize = 38; Canvas.SetTop(TextBlock_preview, 361); Canvas.SetLeft(Canvas_preview, maxLeft); Canvas.SetTop(Canvas_preview, maxLeft); Panel.SetZIndex(Canvas_preview, 17); } else { _preview.Width = minWidth; _preview.Height = minWidth; Canvas_preview.Width = minWidth; Canvas_preview.Height = minWidth; TextBlock_preview.Width = minWidth; TextBlock_preview.FontSize = 20; Canvas.SetTop(TextBlock_preview, 198); Canvas.SetLeft(Canvas_preview, minLeft); Canvas.SetTop(Canvas_preview, minLeft); Panel.SetZIndex(Canvas_preview, 9); } } #endregion #region 进度条事件 private void ProgressbarUserControl_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._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoPictures[ProToImageIndex()].imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}"); this.TextBlock_preview.Text = ""; } } } private void ProgressbarUserControl_BeforeInteractionEvent() { PlayerPause(); if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error) { //this._preview.Visibility = Visibility.Hidden; this.Canvas_preview.Visibility = Visibility.Hidden; } } List PicList = null; int picCount = 0; int picIndex = 0; private string ProgressbarUserControl_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 == AppData.Instance.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"; } //try //{ // if (vm == null || vm.CurrentVideoData == null) return "00h:00m"; // PicList = vm.CurrentVideoData.videoPictures; // if (PicList == null || !PicList.Any()) return "00h:00m"; // picCount = PicList.Count; // picIndex = VideoProToImageIndex(); // if (picIndex < 0) picIndex = 0; // if (picIndex > (picCount - 1)) picIndex = picCount - 1; // vm.CurrentPicZhen = PicList[picIndex]; // return $"{(vm.CurrentPicZhen.developTime / 60).ToString("D2")}h:{(vm.CurrentPicZhen.developTime % 60).ToString("D2")}m"; //} //catch (Exception ex) //{ // if (vm != null) vm.CurrentPicZhen = null; // ExLog(ex, "获取当前帧发育时长"); // return "00h:00m"; //} } private void ProgressbarUserControl_ProChangendEvent(double obj) { if (PlayerState != PlayerStateEnum.Nothing || PlayerState != PlayerStateEnum.Error) SetPlayerPosition(obj); } 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; //} } /// /// 进度条换算图片下标 /// /// 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 初始化 private void InitQuickButton() { this._quick_StackPanel.Children.Clear(); //if (vm == null || vm.QuickButtons == null || !vm.QuickButtons.Any()) //{ // this._quickT.Visibility = Visibility.Hidden; // return; //} //this._quickT.Visibility = Visibility.Visible; bool isFirst = true; var newList = vm.QuickButtons.OrderBy(x => x.orderNum).Take(7); foreach (var item in newList) { ButtonLeftImage buttonLeftImage = new ButtonLeftImage() { IconWidth = 40, IconHeight = 40, IconMargin = new Thickness(0, 0, 5, 0), Content = item.buttonName, FontWeight = FontWeights.Medium, FontSize = 24, Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9B9B9B")), MouseOverForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D4D4D")), IconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailQuickIcon.png", UriKind.Absolute)), MouseOverIconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailQuickMouseOverIcon.png", UriKind.Absolute)), }; if (!isFirst) buttonLeftImage.Margin = new Thickness(20, 0, 0, 0); if (isFirst) isFirst = false; buttonLeftImage.Click += (sender, args) => { QuickButton_Click(item.minHour * 60, item.maxHour * 60, item.buttonName); }; this._quick_StackPanel.Children.Add(buttonLeftImage); } } private void InitMark() { } private void InitCustom() { try { EllipseGeometry ellipseGeometry = new EllipseGeometry(new Point(imageRadius, imageRadius), imageRadius, imageRadius); Embryo itemEmbryo = null; for (int i = 0; i < ellipseCount; i++) { TextBlock textBlock = new TextBlock(); Image border = new Image(); Image image = new Image(); Image opImage = new Image(); this._canvas.Children.Add(textBlock); this._canvas.Children.Add(border); this._canvas.Children.Add(image); this._canvas.Children.Add(opImage); Panel.SetZIndex(textBlock, 11); Panel.SetZIndex(border, 12); Panel.SetZIndex(image, 13); Panel.SetZIndex(opImage, 14); textBlock.FontWeight = FontWeights.Medium; textBlock.Foreground = deaeatForeground; textBlock.FontSize = 14; textBlock.Width = 16; textBlock.Height = 22; textBlock.Text = $"{i + 1}"; textBlock.TextAlignment = TextAlignment.Center; textBlock.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - 7); textBlock.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - 11); TextBlockList.Add(textBlock); ImageList.Add(border); PicImageList.Add(image); border.Width = backImageRadius * 2; border.Height = backImageRadius * 2; border.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * backImageBigRadius - backImageRadius); border.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * backImageBigRadius - backImageRadius); opImage.Width = operRaius * 2; opImage.Height = operRaius * 2; opImage.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * operBigRadius - operRaius); opImage.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * operBigRadius - operRaius); opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState1Icon.png", UriKind.Absolute)); OperImageList.Add(opImage); image.Width = imageRadius * 2; image.Height = imageRadius * 2; image.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius); image.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius); image.SetValue(Image.ClipProperty, ellipseGeometry); image.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png", UriKind.Absolute)); image.Tag = i; image.MouseUp += (s, e) => { if (!(s is Image source)) return; int index = (int)source.Tag; if (selectedIndex == index) return; SelectIndex(index); PlayerPause(); ChangeEmbryo(index + 1); }; var aa = vm.CurrentDish; itemEmbryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == i + 1); if (itemEmbryo == null)//无胚胎 { opImage.Visibility = Visibility.Hidden; textBlock.Tag = 0; textBlock.Foreground = noEmbryoForeground; border.Tag = 0; border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryoBackground.png", UriKind.Absolute)); continue; } switch ((EmbryoState)itemEmbryo.state) { case EmbryoState.Freezing: //冷冻 opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState1Icon.png", UriKind.Absolute)); break; case EmbryoState.Transplant://移植 opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState2Icon.png", UriKind.Absolute)); break; case EmbryoState.Cancellation://作废 opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState3Icon.png", UriKind.Absolute)); break; case EmbryoState.Delete://删除 opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState4Icon.png", UriKind.Absolute)); break; default: opImage.Visibility = Visibility.Hidden; break; } var currentData = vm.DishPicAndVideoList.FirstOrDefault(x => x.wellSn == itemEmbryo.wellSn); if (currentData == null || string.IsNullOrEmpty(currentData.lastPicture))//无图片 { textBlock.Tag = 1; textBlock.Foreground = noPicForeground; border.Tag = 1; border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png", UriKind.Absolute)); continue; } string borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png"; int borderTag = 3; switch ((EmbryoState)itemEmbryo.state) { case EmbryoState.None: borderTag = 2; borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png"; break; case EmbryoState.Freezing: //冷冻 borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState1Icon.png"; break; case EmbryoState.Transplant://移植 borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState2Icon.png"; break; case EmbryoState.Cancellation://作废 borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState3Icon.png"; break; case EmbryoState.Delete://删除 borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState4Icon.png"; break; } textBlock.Tag = 2; textBlock.Foreground = deaeatForeground; border.Tag = borderTag; border.Source = new BitmapImage(new Uri(borderSource, UriKind.Absolute)); } SelectIndex(0); } catch (Exception) { throw; } } private void InitCustomNew() { try { EllipseGeometry ellipseGeometry = new EllipseGeometry(new Point(imageRadius, imageRadius), imageRadius, imageRadius); Embryo itemEmbryo = null; for (int i = 0; i < ellipseCount; i++) { TextBlock textBlock = new TextBlock(); Image border = new Image(); Image image = new Image(); Image opImage = new Image(); this._canvas.Children.Add(textBlock); this._canvas.Children.Add(border); this._canvas.Children.Add(image); this._canvas.Children.Add(opImage); Panel.SetZIndex(textBlock, 11); Panel.SetZIndex(border, 12); Panel.SetZIndex(image, 13); Panel.SetZIndex(opImage, 14); textBlock.FontWeight = FontWeights.Medium; textBlock.Foreground = deaeatForeground; textBlock.FontSize = 14; textBlock.Width = 16; textBlock.Height = 22; textBlock.Text = $"{i + 1}"; textBlock.TextAlignment = TextAlignment.Center; textBlock.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - 7); textBlock.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - 11); TextBlockList.Add(textBlock); ImageList.Add(border); PicImageList.Add(image); border.Width = backImageRadius * 2; border.Height = backImageRadius * 2; border.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * backImageBigRadius - backImageRadius); border.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * backImageBigRadius - backImageRadius); opImage.Width = operRaius * 2; opImage.Height = operRaius * 2; opImage.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * operBigRadius - operRaius); opImage.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * operBigRadius - operRaius); //opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState1Icon.png", UriKind.Absolute)); OperImageList.Add(opImage); image.Width = imageRadius * 2; image.Height = imageRadius * 2; image.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius); image.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius); image.SetValue(Image.ClipProperty, ellipseGeometry); if (vm.CurrentDish == null) { border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryoBackground.png", UriKind.Absolute)); } else { itemEmbryo = SetWellImage(i, 0); if (itemEmbryo == null) { textBlock.Tag = 0; textBlock.Foreground = noEmbryoForeground; image.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryo.png", UriKind.Absolute)); } else { textBlock.Tag = 2; textBlock.Foreground = deaeatForeground; image.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryo1.png", UriKind.Absolute)); switch ((EmbryoState)itemEmbryo.state) { case EmbryoState.Freezing: //冷冻 opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState1Icon.png", UriKind.Absolute)); break; case EmbryoState.Transplant://移植 opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState2Icon.png", UriKind.Absolute)); break; case EmbryoState.Cancellation://作废 opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState3Icon.png", UriKind.Absolute)); break; case EmbryoState.Delete://删除 opImage.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoState4Icon.png", UriKind.Absolute)); break; default: opImage.Visibility = Visibility.Hidden; break; } } } if (i == 0) textBlock.Foreground = new SolidColorBrush(Colors.White); int index = i; image.MouseUp += (s, e) => { if (!this.IsLoaded) return; if (selectedIndex == index) return; SelectIndex(index); PlayerPause(); ChangeEmbryo(index + 1); }; } } catch (Exception ex) { ExLog(ex, "InitCustomNew"); } } private object lock1 = new object(); private Embryo SetWellImage(int index, int oldIndex) { lock (lock1) { if (vm == null || vm.CurrentDish == null) return null; Image imageBorder = ImageList[index]; var itemEmbryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == index + 1); if (itemEmbryo == null) { if (index == oldIndex) { imageBorder.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute)); } else { imageBorder.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryoBackground.png", UriKind.Absolute)); } return itemEmbryo; } string borderSource = null; switch ((EmbryoState)itemEmbryo.state) { case EmbryoState.End: case EmbryoState.None: if (itemEmbryo.alarm == 1) { borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState3Icon.png"; } else { if (index == oldIndex) { borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png"; } else { borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png"; } } break; case EmbryoState.Freezing: //冷冻 borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState1Icon.png"; break; case EmbryoState.Transplant://移植 borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState2Icon.png"; break; case EmbryoState.Cancellation://作废 borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState3Icon.png"; break; case EmbryoState.Delete://删除 borderSource = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoState4Icon.png"; break; } imageBorder.Source = new BitmapImage(new Uri(borderSource, UriKind.Absolute)); return itemEmbryo; } } private void EmbryoAlarmEvent(int wellsn, int stateAlarm) { try { Dispatcher.Invoke(() => { SetWellImage(wellsn - 1, selectedIndex); }); } catch (Exception) { } } /// /// 切换well /// /// public void ChangeEmbryo(int well) { //try //{ // this._bigFocal_Button.IsEnabled = true; // this._smallFocal_Button.IsEnabled = true; // SetVideoButtonState(false); // vm.CurrentFocal = 0; // vm.CurrentPicZhen = null; // vm.CurrentEmbryo = null; // vm.CurrentVideoData = null; // vm.VideoAllTime = 1; // vm.VideoCurrentTime = 0; // if (vm.CurrentDish != null && vm.CurrentDish.id > 0) vm.CurrentEmbryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == well); // vm.CurrentVideoData = vm.AllEmbryoPicAndVideo.FirstOrDefault(x => x.wellSn == well); // SetPreview(well); // SetVideo(vm.CurrentFocal, true); //} //catch (Exception ex) //{ // ExLog(ex, "ChangeEmbryo"); //} try { PlayerDispose(); if (vm == null) return; vm.CurrentEmbryo = null; vm.CurrentWellDishPicAndVideo = null; vm.CurrentWellLayerPicAndVideo = null; SetVideoButtonState(false); vm.CurrentFocal = 0; this._bigFocal_Button.IsEnabled = true; this._smallFocal_Button.IsEnabled = true; if (vm.CurrentDish != null && vm.CurrentDish.id > 0) vm.CurrentEmbryo = vm.CurrentDish.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); SetPreview(well); SetVideo(vm.CurrentFocal, true); if (vm.CurrentWellLayerPicAndVideo != null && vm.CurrentWellLayerPicAndVideo.videoPictures.Any()) { this._bigFocal_Button.IsEnabled = true; this._smallFocal_Button.IsEnabled = true; if (string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) || vm.CurrentWellLayerPicAndVideo.videoUrl == AppData.Instance.CleanVideoString) { vm.VideoAllTime = 1; vm.VideoCurrentTime = 0; vm.VideoAllTime = vm.CurrentWellLayerPicAndVideo.videoPictures.Count; vm.VideoCurrentTime = vm.VideoAllTime; } } else { this._bigFocal_Button.IsEnabled = false; this._smallFocal_Button.IsEnabled = false; } } catch (Exception ex) { ExLog(ex, "ChangeEmbryo"); } } /// /// 设置视频 /// private bool SetVideo(int focal, bool isUpdate) { PlayerDispose(); if (vm.CurrentWellLayerPicAndVideo != null && !string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) && vm.CurrentWellLayerPicAndVideo.videoUrl != AppData.Instance.CleanVideoString) if (PlayerSetSource($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}")) return true; if (!isUpdate) return false; vm.VideoAllTime = 1; vm.VideoCurrentTime = 0; return true; } /// /// 设置选中状态 /// /// private void SelectIndex(int index) { switch (TextBlockList[selectedIndex].Tag.ToString()) { case "0": TextBlockList[selectedIndex].Foreground = noEmbryoForeground; break; case "1": TextBlockList[selectedIndex].Foreground = noPicForeground; break; case "2": TextBlockList[selectedIndex].Foreground = deaeatForeground; break; } SetWellImage(selectedIndex, -1); selectedIndex = index; TextBlockList[selectedIndex].Foreground = new SolidColorBrush(Colors.White); var itemEmbryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == selectedIndex + 1); if (itemEmbryo == null) { ImageList[selectedIndex].Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute)); } else { if ((itemEmbryo.state == (int)EmbryoState.End || itemEmbryo.state == (int)EmbryoState.None) && itemEmbryo.alarm == 0) { ImageList[selectedIndex].Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute)); } } RotateTransform rotateTransform = this._sx.RenderTransform as RotateTransform; rotateTransform.Angle = angle * selectedIndex; } private void SelectIndexold(int index) { switch (TextBlockList[selectedIndex].Tag.ToString()) { case "0": TextBlockList[selectedIndex].Foreground = noEmbryoForeground; break; case "1": TextBlockList[selectedIndex].Foreground = noPicForeground; break; case "2": TextBlockList[selectedIndex].Foreground = deaeatForeground; break; } switch (ImageList[selectedIndex].Tag.ToString()) { case "0": ImageList[selectedIndex].Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryoBackground.png", UriKind.Absolute)); break; case "1": case "2": ImageList[selectedIndex].Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoBackground.png", UriKind.Absolute)); break; } selectedIndex = index; TextBlockList[selectedIndex].Foreground = new SolidColorBrush(Colors.White); switch (ImageList[selectedIndex].Tag.ToString()) { case "0": case "1": case "2": ImageList[selectedIndex].Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute)); break; } RotateTransform rotateTransform = this._sx.RenderTransform as RotateTransform; rotateTransform.Angle = angle * selectedIndex; } /// /// 设置封面 /// /// private void SetPreview(int well) { vm.SelectedFps = new KeyValuePair(1d, "1.0x"); currentMediaElement.SpeedRatio = 1d; //this._preview.Visibility = Visibility.Visible; this.Canvas_preview.Visibility = Visibility.Visible; if (vm.CurrentEmbryo == null) { //this._preview.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryoBigPic.png", UriKind.Absolute)); AppData.Instance.SetImageSource(this._preview, LogoEnum.Circle); this.TextBlock_preview.Text = peitai; return; } if (vm.CurrentWellDishPicAndVideo == null || string.IsNullOrEmpty(vm.CurrentWellDishPicAndVideo.lastPicture)) { this._preview.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoPicBigPic.png", UriKind.Absolute)); this.TextBlock_preview.Text = paiShe; return; } this._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.CurrentWellDishPicAndVideo.lastPicture}?token={AppData.Instance.HttpServiceCall.GetToken()}"); this.TextBlock_preview.Text = ""; } /// /// 设置封面为无视频 /// /// private void SetPreviewNoVideo() { //this._preview.Visibility = Visibility.Visible; this.Canvas_preview.Visibility = Visibility.Visible; this._preview.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoVideoPic.png", UriKind.Absolute)); this.TextBlock_preview.Text = shiping; } /// /// 设置缩略图 /// /// private void SetEmbryoPic() { Image item = null; for (int i = 0; i < 16; i++) { item = PicImageList[i]; var embryo = vm.CurrentDish.embryoList.FirstOrDefault(x => x.wellSn == i + 1); if (embryo == null) { item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailNoEmbryo.png", UriKind.Absolute)); continue; } //var currentData = vm.AllEmbryoPicAndVideo.FirstOrDefault(x => x.wellSn == embryo.wellSn); var currentData = vm.DishPicAndVideoList.FirstOrDefault(x => x.wellSn == embryo.wellSn); if (currentData == null || currentData.lastPicture == null) { item.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoNoPic.png", UriKind.Absolute)); } else { item.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{currentData.lastPicture.Replace(AppData.Instance.PicSuf, $"_80x80{AppData.Instance.PicSuf}")}?token={AppData.Instance.HttpServiceCall.GetToken()}"); } } } /// /// 切换图层 /// /// private void ChangeFocal(bool isMax) { try { PlayerPause(); int newCurrentFocal = vm.CurrentFocal; int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2; int minFocal = -maxFocal; if (isMax) newCurrentFocal++; else newCurrentFocal--; if (newCurrentFocal < maxFocal) this._bigFocal_Button.IsEnabled = true; else this._bigFocal_Button.IsEnabled = false; if (newCurrentFocal > minFocal) this._smallFocal_Button.IsEnabled = true; else this._smallFocal_Button.IsEnabled = false; if (newCurrentFocal < minFocal || newCurrentFocal > maxFocal) return; //this._preview.Visibility = Visibility.Hidden; this.Canvas_preview.Visibility = Visibility.Hidden; Task.Run(() => { Dispatcher.Invoke(() => { var a = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.detailProvider.GetImageUrlApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal, vm.CurrentPic.developTime)}?token={AppData.Instance.HttpServiceCall.GetToken()}"); if (a != null) { //this._preview.Visibility = Visibility.Visible; this.Canvas_preview.Visibility = Visibility.Visible; this._preview.Source = a; this.TextBlock_preview.Text = ""; } }); }); newCurrentTime = 0; vm.CurrentFocal = newCurrentFocal; SetVideoButtonState(false); 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 = vm.detailProvider.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); } catch (Exception ex) { ExLog(ex, "ChangeFocal"); } } /// /// 切换图层 /// /// private void ChangeImageFocal(bool isMax) { try { int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2; int minFocal = -maxFocal; int newCurrentFocal = vm.CurrentFocal; if (isMax) newCurrentFocal++; else newCurrentFocal--; if (newCurrentFocal < maxFocal) this._bigFocal_Button.IsEnabled = true; else this._bigFocal_Button.IsEnabled = false; if (newCurrentFocal > minFocal) this._smallFocal_Button.IsEnabled = true; else this._smallFocal_Button.IsEnabled = 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) return; if (!newCurrentWellLayerPicAndVideo.videoPictures.Any()) return; vm.CurrentWellLayerPicAndVideo = newCurrentWellLayerPicAndVideo; //this._preview.Visibility = Visibility.Visible; this.Canvas_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._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoPictures[i].imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}"); this.TextBlock_preview.Text = ""; vm.VideoCurrentTime = 0; vm.VideoCurrentTime = i + 1; return; } catch (Exception ex) { ExLog(ex, "ChangeImageFocal"); } } private void ChangeFocalNoVideo(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) this._bigFocal_Button.IsEnabled = true; else this._bigFocal_Button.IsEnabled = false; if (newCurrentFocal > minFocal) this._smallFocal_Button.IsEnabled = true; else this._smallFocal_Button.IsEnabled = 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 = vm.detailProvider.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 = vm.detailProvider.GetImageUrlApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal, vm.CurrentPic.developTime); Dispatcher.Invoke(() => { var a = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}"); if (a != null) { this.Canvas_preview.Visibility = Visibility.Visible; this._preview.Source = a; } }); }); vm.CurrentFocal = newCurrentFocal; } catch (Exception ex) { ExLog(ex, "ChangeFocalNoVideo"); } } private void SetFocal(int newFocal, int newDevelopTime) { try { int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2; int minFocal = -maxFocal; int newCurrentFocal = newFocal; if (newCurrentFocal < maxFocal) this._bigFocal_Button.IsEnabled = true; else this._bigFocal_Button.IsEnabled = false; if (newCurrentFocal > minFocal) this._smallFocal_Button.IsEnabled = true; else this._smallFocal_Button.IsEnabled = false; if (newCurrentFocal < minFocal || newCurrentFocal > maxFocal) { MessageShow($"标记图层{newCurrentFocal}超出范围{minFocal}-{maxFocal}"); return; } var aa = vm.CurrentWellDishPicAndVideo.videos.FirstOrDefault(x => x.pictureLayer == newCurrentFocal); if (aa == null) { MessageShow($"没有对应图层:{newCurrentFocal}"); return; } if (aa.videoPictures == null || !aa.videoPictures.Any()) { aa.videoPictures = vm.detailProvider.GetVideoTimeLineApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal); } if (aa.videoPictures == null || !aa.videoPictures.Any()) { MessageShow($"目标图层没有图片:{newCurrentFocal}"); return; } bool b = false; string imageUrl = null; foreach (var item in aa.videoPictures) { if (item.developTime == newDevelopTime) { b = true; imageUrl = item.imageUrl; break; } } if (!b) { MessageShow($"{newCurrentFocal}层没有发育时长为{newDevelopTime}分钟的图片"); return; } Task.Run(() => { if (string.IsNullOrEmpty(imageUrl)) imageUrl = vm.detailProvider.GetImageUrlApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, newCurrentFocal, newDevelopTime); Dispatcher.Invoke(() => { var a = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}"); if (a != null) { this.Canvas_preview.Visibility = Visibility.Visible; this._preview.Source = a; } }); }); vm.CurrentFocal = newCurrentFocal; } catch (Exception ex) { ExLog(ex, "SetFocal"); } } #endregion #region 视频基础操作 double newCurrentTime = -1; double beilv = 1; MediaElement currentMediaElement = null; /// /// 定时器 /// public System.Timers.Timer dispatcherTimer = new System.Timers.Timer(); /// /// 视频状态 /// public PlayerStateEnum PlayerState { get; set; } = PlayerStateEnum.Nothing; /// /// 播放器事件初始化 /// 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) { ExLog(ex, $"播放器事件初始化"); } } /// /// 设置播放源 /// /// public bool PlayerSetSource(string FileName) { try { PlayerDispose(); currentMediaElement.LoadedBehavior = MediaState.Manual; //指定媒体文件地址 currentMediaElement.Source = new Uri(FileName, UriKind.RelativeOrAbsolute); currentMediaElement.ScrubbingEnabled = true; currentMediaElement.SpeedRatio = 1; currentMediaElement.Play(); currentMediaElement.Pause(); return true; } catch (Exception ex) { ExLog(ex, $"设置播放源"); return false; } } /// /// 播放器加载视频完成事件 /// /// /// private void MediaOpenedEvent(object sender, RoutedEventArgs e) { try { //bool isWhile = true; //while (isWhile) //{ // isWhile = !(currentMediaElement.DownloadProgress == 1); // Thread.Sleep(20); //} //isWhile = true; //while (isWhile) //{ // isWhile = !(currentMediaElement.BufferingProgress == 1); // Thread.Sleep(20); //} currentMediaElement.ScrubbingEnabled = false; vm.VideoAllTime = 1; vm.VideoCurrentTime = 0; if (currentMediaElement.NaturalDuration.HasTimeSpan) { currentMediaElement.LoadedBehavior = MediaState.Manual; PlayerState = PlayerStateEnum.Paused; vm.VideoAllTime = currentMediaElement.NaturalDuration.TimeSpan.TotalMilliseconds; currentMediaElement.ScrubbingEnabled = true; currentMediaElement.Play(); currentMediaElement.Pause(); 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); } SetVideoButtonState(true); } else { PlayerState = PlayerStateEnum.Nothing; } } catch (Exception ex) { PlayerState = PlayerStateEnum.Error; ExLog(ex, $"播放器加载视频完成事件"); } } /// /// 播放完成事件 /// /// /// 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); } catch (Exception ex) { ExLog(ex, $"播放完成事件"); } } /// /// 播放器错误事件 /// /// /// /// private void MediaFailedEvent(object? sender, ExceptionRoutedEventArgs e) { try { PlayerState = PlayerStateEnum.Error; vm.VideoAllTime = 1; vm.VideoCurrentTime = 0; SetPlayButton(false); string ss = ""; MediaElement med = sender as MediaElement; if (med != null) { ss = med.Source.ToString(); ErrorLog($"{ss},视频遇到错误", LogEnum.RunError); } dispatcherTimer_Stop(); ExLog(e.ErrorException, $"MediaFailedEvent:{ss}"); } catch (Exception ex) { ExLog(ex, $"播放器错误事件"); } } /// /// 播放按钮图标设置 /// private void SetPlayButton(bool isPlaying) { if (isPlaying)//正在播放,设置为暂停按钮 { this._playButton.IconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailPauseVideoButtonIcon.png", UriKind.Absolute)); this._playButton.MouseOverIconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailPauseVideoButtonMouseIcon.png", UriKind.Absolute)); } else//未播放,设置为播放按钮 { this._playButton.IconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailStartVideoButtonIcon.png", UriKind.Absolute)); this._playButton.MouseOverIconSource = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailStartVideoButtonMouseIcon.png", UriKind.Absolute)); } } /// /// 定时器事件 /// /// /// private void dispatcherTimer_Elapsed(object? sender, ElapsedEventArgs e) { try { Dispatcher.Invoke(() => { SetTimeProgressbarProgressValue(currentMediaElement.Position.TotalMilliseconds); }); if (PlayerState != PlayerStateEnum.Playing) { dispatcherTimer_Stop(); } } catch (Exception ex) { ExLog(ex, $"定时器事件"); } } /// /// 停止定时器 /// public void dispatcherTimer_Stop() { try { if (dispatcherTimer.Enabled) { dispatcherTimer.Enabled = false; dispatcherTimer.Stop(); } } catch (Exception ex) { ExLog(ex, $"停止定时器"); } } /// ///设置视频进度 /// /// public void SetPlayerPosition(double currentTime) { try { if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error) { currentMediaElement.Position = TimeSpan.FromMilliseconds(currentTime); } } catch (Exception ex) { ExLog(ex, $"进度条变换以后设置视频进度"); } } /// /// 设置进度条 /// public void SetTimeProgressbarProgressValue(double newTime) { try { vm.VideoCurrentTime = newTime; } catch (Exception ex) { ExLog(ex, $"视频进度变换以后设置进度条"); } } /// /// 释放播放器 /// public void PlayerDispose() { try { dispatcherTimer_Stop(); if (PlayerState != PlayerStateEnum.Nothing) { currentMediaElement.LoadedBehavior = MediaState.Close; PlayerState = PlayerStateEnum.Nothing; } } catch (Exception ex) { ExLog(ex, $"释放播放器"); } } /// /// 设置倍率 /// /// public void PlayerSetSpeedRatio(double newSpeedRatio) { try { beilv = newSpeedRatio; if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error) { currentMediaElement.LoadedBehavior = MediaState.Manual; currentMediaElement.SpeedRatio = newSpeedRatio; } } catch (Exception ex) { ExLog(ex, $"设置倍率"); } } /// /// 播放操作 /// 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; } if (isPlay) { PlayerState = PlayerStateEnum.Playing; if (vm.VideoCurrentTime == vm.VideoAllTime) { SetPlayerPosition(0); } if (!dispatcherTimer.Enabled) { dispatcherTimer.Start(); } PlayerSetSpeedRatio(beilv); currentMediaElement.Play(); SetPlayButton(true); return true; } return false; } catch (Exception ex) { ExLog(ex, $"播放操作"); return false; } } /// /// 暂停操作 /// /// 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) { ExLog(ex, $"暂停操作"); return false; } } /// /// 上一帧 /// 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) { var zhen = (1000d / 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); return; } else { } } catch (Exception ex) { ExLog(ex, $"上一帧"); } } /// /// 下一帧 /// 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) { var newpos = currentMediaElement.Position.TotalMilliseconds + (1000d / zhenshu); if (newpos > vm.VideoAllTime) { newpos = vm.VideoAllTime; } SetPlayerPosition(newpos); SetTimeProgressbarProgressValue(newpos); return; } else { } if (isStop) { return; } } catch (Exception ex) { ExLog(ex, $"下一帧"); } } private void Canvas_MouseDown(object sender, MouseButtonEventArgs e) { if (vm == null) return; if (!(sender is Canvas canvas)) return; if (!(canvas.Tag is MarkEntity value)) return; if (value.maxTime != 0) { QuickButton_Click(value.maxTime, value.maxTime, value.name); if (value.pictureLayer != vm.CurrentFocal) SetFocal(value.pictureLayer, value.maxTime); } } private void SetVideoButtonState(bool IsEnabledVideo) { Task.Run(() => { Dispatcher.Invoke(() => { this._lastButton.IsEnabled = IsEnabledVideo; this._playButton.IsEnabled = IsEnabledVideo; this._nextButton.IsEnabled = IsEnabledVideo; }); }); } #endregion } }