using ivf_tl_CustomControls;
using ivf_tl_Entity.Entity;
using ivf_tl_Entity.Entity.balance;
using ivf_tl_Entity.Entity.Result;
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 ivf_tl_Service;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Reflection.Metadata;
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
{
///
/// DetailView.xaml 的交互逻辑
///
public partial class DetailView : UserControl
{
string paiShe, peitai, shiping;
private DetailViewModel vm;
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();
public bool IsCleanVideo = false;
public DetailView()
{
//DebugLog($"详情界面初始化开始:{DateTime.Now}");
InitializeComponent();
//paiShe = "拍摄中,请耐心等待";
//shiping = "暂无视频,请耐心等待";
//peitai = "暂无胚胎";
paiShe = KeyToStringConvert.GetLanguageStringByKey("0509");
shiping = KeyToStringConvert.GetLanguageStringByKey("0510");
peitai = KeyToStringConvert.GetLanguageStringByKey("0511");
object value = App.Current.TryFindResource("0511");
centerX = 710 / 2.0;
centerY = 710 / 2.0;
angle = 360.00 / 16;
Loaded += DetailView_Loaded;
Unloaded += (s, e) =>
{
CloseCeLiang();
PlayerDispose();
Canvas_Root.Children.Clear();
TextBlockList.Clear();
ImageList.Clear();
PicImageList.Clear();
OperImageList.Clear();
if (vm != null)
{
foreach (var item in vm.CurrentDish.embryoList)
{
item.AlarmChangedEvent -= EmbryoAlarmEvent;
}
}
vm = null;
DataContext = null;
};
//DebugLog($"详情界面初始化完成:{DateTime.Now}");
}
private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
string ss = "";
}
private void DetailView_Loaded(object sender, RoutedEventArgs e)
{
vm = (DetailViewModel)this.DataContext;
if (vm == null) return;
InitNav();
InitCustomNew();
foreach (var item in vm.CurrentDish.embryoList)
{
item.AlarmChangedEvent -= EmbryoAlarmEvent;
item.AlarmChangedEvent += EmbryoAlarmEvent;
}
InitAlarm();
Task.Run(() =>
{
vm.Init();
if (vm == null) return;
Dispatcher.InvokeAsync(() =>
{
//Stopwatch stopwatch = Stopwatch.StartNew();
//DebugLog($"开始设置详情界面默认值:{DateTime.Now}");
//var time1 = stopwatch.Elapsed;
IsCleanVideo = false;
if (vm == null) return;
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;
}
}
}
InitQuickButton();
SetEmbryoPic();
PlayerEvent(this.mediaElementPlayer);
//var time2 = stopwatch.Elapsed;
//DebugLog($"详情界面默认值设置完成,开始设置视频:{DateTime.Now},耗时:{(time2 - time1).TotalMilliseconds}");
ChangeEmbryo(1);
//time1 = stopwatch.Elapsed;
//DebugLog($"所有设置完成:{DateTime.Now},耗时:{(time1 - time2).TotalMilliseconds},总耗时:{stopwatch.Elapsed.TotalMilliseconds}");
//stopwatch.Stop();
});
while (true)
{
Thread.Sleep(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;
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);
if (vm == null || vm.CurrentDish == null || AppData.Instance.CurrentTlInfo == null) return;
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.SetResourceReference(Button.ContentProperty, "0002");
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);
}
}
private void ExLog(Exception ex, string name)
{
AppData.Instance.LogService.ExceptionLog(ex, $"DetailView.{name}", LogEnum.RunException);
}
private void ErrorLog(string message, LogEnum logType)
{
AppData.Instance.LogService.TLLog($"DetailView.{message}", logType);
}
private void TimeLog(string message)
{
AppData.Instance.LogService.TLLog($"DetailView.{message}", LogEnum.TakeTime);
}
private 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 Button_Click(object sender, RoutedEventArgs e)
{
AppData.Instance.MainWindowViewModel.CurrentViewModle = AppData.Instance.MainWindowViewModel.devManageViewModel;
}
///
/// 患者管理界面
///
///
///
private void Parien_Click(object sender, RoutedEventArgs e)
{
//AppData.Instance.MainWindowViewModel.patientManageViewModel.SetTLInfo(vm.tLInfo);
//AppData.Instance.MainWindowViewModel.CurrentViewModle = AppData.Instance.MainWindowViewModel.patientManageViewModel;
}
///
/// 培养记录界面
///
///
///
private void Record_Click(object sender, RoutedEventArgs e)
{
AppData.Instance.MainWindowViewModel.CurrentViewModle = vm.ParentViewModel;
}
private void Mark_Click(object sender, RoutedEventArgs e)
{
vm.MarkEmbryo();
}
///
/// 图片查看界面
///
///
///
private void EmbryoPicClick(object sender, RoutedEventArgs e)
{
if (vm == null) return;
if (vm.CurrentEmbryo != null)
{
AppData.Instance.MainWindowViewModel.CurrentViewModle = new DetailPicViewModel(vm, vm.MaxTotalLayer, vm.CurrentEmbryo.wellSn);
}
else
{
AppData.Instance.MainWindowViewModel.CurrentViewModle = new DetailPicViewModel(vm, vm.MaxTotalLayer, 1);
}
return;
}
///
/// 标记明细
///
///
///
private void ButtonBottomImage_Click(object sender, RoutedEventArgs e)
{
AppData.Instance.MainWindowViewModel.CurrentViewModle = new MarkDetailViewModel(vm, vm.CurrentDish.id);
}
private void Export_Click(object sender, RoutedEventArgs e)
{
AppData.Instance.MainWindowViewModel.MaskVisibility = true;
new ExportBulkWindow(vm.CurrentDish, vm.DishPicAndVideoList, IsCleanVideo).ShowDialog();
AppData.Instance.MainWindowViewModel.MaskVisibility = false;
}
///
/// 移植按钮
///
///
///
//private void EmbryoMove_Click(object sender, RoutedEventArgs e)
//{
// CloseCeLiang();
// PlayerPause();
// if (vm.CurrentEmbryo == null) return;
// string tag = "移植";
// string messInfo = $"是否确定对{vm.CurrentEmbryo.wellSn}号胚胎进行移植?";
// 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 = $"{vm.CurrentEmbryo.wellSn}号胚胎已冷冻";
// iconType = 1;
// break;
// case (int)EmbryoState.Transplant:
// messInfo = $"是否取消{vm.CurrentEmbryo.wellSn}号胚胎的移植标记?";
// tag = "取消";
// break;
// case (int)EmbryoState.Cancellation:
// messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已作废";
// iconType = 3;
// break;
// case (int)EmbryoState.Delete:
// messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已删除";
// iconType = 4;
// break;
// }
// }
// EmbryoOp(tag, messInfo, iconType);
// return;
//}
//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("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)
{
CloseCeLiang();
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)
{
CloseCeLiang();
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 EmbryoFree_Click(object sender, RoutedEventArgs e)
//{
// CloseCeLiang();
// PlayerPause();
// if (vm.CurrentEmbryo == null) return;
// int iconType = 1;
// 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}号胚胎的冷冻标记?";
// tag = "取消";
// break;
// case (int)EmbryoState.Transplant:
// messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已移植";
// iconType = 2;
// break;
// case (int)EmbryoState.Cancellation:
// messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已作废";
// iconType = 3;
// break;
// case (int)EmbryoState.Delete:
// messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已删除";
// iconType = 4;
// break;
// }
// }
// EmbryoOp(tag, messInfo, iconType);
// return;
//}
///
/// 作废按钮
///
///
///
private void EmbryoInv_Click(object sender, RoutedEventArgs e)
{
CloseCeLiang();
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 EmbryoInv_Click(object sender, RoutedEventArgs e)
//{
// CloseCeLiang();
// PlayerPause();
// if (vm.CurrentEmbryo == null) return;
// int iconType = 3;
// 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}号胚胎已冷冻";
// iconType = 1;
// break;
// case (int)EmbryoState.Transplant:
// messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已移植";
// iconType = 2;
// break;
// case (int)EmbryoState.Cancellation:
// messInfo = $"是否取消{vm.CurrentEmbryo.wellSn}号胚胎的作废标记?";
// tag = "取消";
// break;
// case (int)EmbryoState.Delete:
// messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已删除";
// iconType = 4;
// break;
// }
// }
// EmbryoOp(tag, messInfo, iconType);
// return;
//}
///
/// 删除按钮
///
///
///
private void EmbryoDel_Click(object sender, RoutedEventArgs e)
{
CloseCeLiang();
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 EmbryoDel_Click(object sender, RoutedEventArgs e)
//{
// CloseCeLiang();
// PlayerPause();
// if (vm.CurrentEmbryo == null) return;
// int iconType = 4;
// 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}号胚胎已冷冻";
// iconType = 1;
// break;
// case (int)EmbryoState.Transplant:
// messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已移植";
// iconType = 2;
// break;
// case (int)EmbryoState.Cancellation:
// messInfo = $"{vm.CurrentEmbryo.wellSn}号胚胎已作废";
// iconType = 3;
// break;
// case (int)EmbryoState.Delete:
// messInfo = $"是否取消{vm.CurrentEmbryo.wellSn}号胚胎的删除标记?";
// tag = "取消";
// break;
// }
// }
// EmbryoOp(tag, messInfo, iconType);
// return;
//}
///
/// 结束按钮
///
///
///
private void EmbryoOver_Click(object sender, RoutedEventArgs e)
{
try
{
CloseCeLiang();
PlayerPause();
if (vm.CurrentDish == null || vm.CurrentDish.id == 0) return;
string tag = KeyToStringConvert.GetLanguageStringByKey("0518");
string messInfo = $"{KeyToStringConvert.GetLanguageStringByKey("0519")}?";
if (vm.CurrentDish.state == 0)
{
messInfo = KeyToStringConvert.GetLanguageStringByKey("0520");
tag = "完成";
}
EmbryoOp(tag, messInfo, 5);
return;
}
catch (Exception ex)
{
ExLog(ex, "EmbryoOver_Click");
}
//try
//{
// CloseCeLiang();
// PlayerPause();
// if (vm.CurrentDish == null || vm.CurrentDish.id == 0) return;
// string tag = "结束";
// string messInfo = $"是否结束培养所有胚胎?";
// if (vm.CurrentDish.state == 0)
// {
// messInfo = "当前舱室已结束培养";
// tag = "完成";
// }
// EmbryoOp(tag, messInfo, 5);
// return;
//}
//catch (Exception ex)
//{
// ExLog(ex, "EmbryoOver_Click");
//}
}
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 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 (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;
case 5:
Finish();
break;
default:
break;
}
}
//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)
// {
// 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;
// }
// }
//}
///
/// 结束培养
///
///
private void Finish()
{
try
{
if (!vm.EndDish())
{
//MessageShow("结束培养失败");
MessageShow(KeyToStringConvert.GetLanguageStringByKey("0318"));
return;
}
vm.Back();
//vm.CurrentDish = new Dish();
//AppData.Instance.BackMainPage();
}
catch (Exception ex)
{
ExLog(ex, "Finish");
}
}
private void EmbryoMark(int embryoState)
{
try
{
if (!vm.MarkEmbryo(embryoState))
{
//MessageShow("胚胎标记失败");
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);
Toast(true);
//AppData.Instance.MainPageView.SetMainEmbryoState(vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.wellSn, vm.CurrentEmbryo.state);
}
catch (Exception ex)
{
ExLog(ex, "EmbryoMark");
}
}
///
/// 播放暂停
///
///
///
private void Video_Click(object sender, RoutedEventArgs e)
{
CloseCeLiang();
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 PreviousFrame_Click(object sender, RoutedEventArgs e)
{
CloseCeLiang();
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 NextFrame_Click(object sender, RoutedEventArgs e)
{
CloseCeLiang();
if (vm == null || vm.CurrentWellLayerPicAndVideo == null) return;
if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
{
PlayerPause();
PlayerNextFrame(vm.CurrentWellLayerPicAndVideo.fps);
//this._preview.Visibility = Visibility.Hidden;
this.Canvas_preview.Visibility = Visibility.Hidden;
}
}
///
/// 上一层
///
///
///
private void BigFocus_Click(object sender, RoutedEventArgs e)
{
PlayerPause();
CloseCeLiang();
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();
CloseCeLiang();
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 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
{
CloseCeLiang();
PlayerPause();
if (vm.CurrentWellLayerPicAndVideo == null || vm.CurrentWellLayerPicAndVideo.videoPictures == null || !vm.CurrentWellLayerPicAndVideo.videoPictures.Any())
{
//MessageShow($"当前胚胎还未发育到{quickName}阶段");
MessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0316")} {quickName}");
return;
}
var lastPic = vm.CurrentWellLayerPicAndVideo.videoPictures.Last();
if (minHour > lastPic.developTime)
{
//MessageShow($"当前胚胎还未发育到{quickName}阶段");
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._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._preview.Visibility = Visibility.Hidden;
double pro = (i * (1000.00 / vm.CurrentWellLayerPicAndVideo.fps));
SetTimeProgressbarProgressValue(pro);
SetPlayerPosition(pro);
}
else
{
this._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");
}
}
///
/// 播放速率调整
///
///
///
private void Fps_MouseUp(object sender, MouseButtonEventArgs e)
{
CloseCeLiang();
if (this._fps_Popup.IsOpen) this._fps_Popup.IsOpen = false;
else this._fps_Popup.IsOpen = true;
}
private void CeLiang_Click(object sender, RoutedEventArgs e)
{
PlayerPause();
if (vm.CurrentEmbryo == null)
{
//MessageBox.Show("embryo为空");
return;
}
int developTime = 0;
if (vm.CurrentPic == null)
{
if (vm.CurrentWellDishPicAndVideo != null && vm.CurrentWellDishPicAndVideo.focus)
{
developTime = vm.CurrentWellDishPicAndVideo.developTime;
}
else
{
//MessageBox.Show("CurrentPic为空");
return;
}
}
else
{
developTime = vm.CurrentPic.developTime;
}
if (isCeLiang)
{
count = 0;
this._ceLiang_Border.Visibility = Visibility.Hidden;
this.b1.Text = "";
this.canvas1.Children.Remove(myLine);
this.canvas1.Children.Remove(starEllipse);
this.canvas1.Children.Remove(endEllipse);
isCeLiang = false;
MeaUIShow(false);
}
else
{
isCeLiang = true;
MeaUIShow(true);
}
DetailPicInfo detailPicInfo = null;
if (vm.CurrentPic == null)
{
detailPicInfo = vm.detailProvider.GetDetailPicInfoApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, 9999, developTime);
}
else
{
detailPicInfo = vm.detailProvider.GetDetailPicInfoApi(vm.CurrentEmbryo.tlSn, vm.CurrentEmbryo.houseSn, vm.CurrentEmbryo.id, vm.CurrentFocal, developTime);
}
if (detailPicInfo != null) PicRadius = detailPicInfo.radius;
Log4netHelper.WriteLog($"{vm.CurrentEmbryo.id}:{PicRadius}");
e.Handled = true;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (vm == null || vm.CurrentWellLayerPicAndVideo == null || string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) || vm.CurrentWellLayerPicAndVideo.videoUrl == AppData.Instance.CleanVideoString) return;
string url = $"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}";
TimeLog($"开始下载:{url}");
Stopwatch stopwatch = Stopwatch.StartNew();
AppData.Instance.HttpServiceCall.DownLoadFileAsync(url, $"C:\\TLData\\ivf_tl_Manage_logs\\{DateTime.Now.ToString("HH_mm")}.mp4").GetAwaiter().GetResult();
TimeLog($"下载耗时:{stopwatch.ElapsedMilliseconds}毫秒、{stopwatch.Elapsed.TotalSeconds}秒");
}
int PicRadius = 0;
bool isMax = false;
double maxWidth = 610;
double maxLeft = 50;
double minWidth = 330;
double minLeft = 190;
int count = 0;
bool isCeLiang = false;
Line myLine = null;
Ellipse starEllipse = null;
Ellipse endEllipse = null;
private void PreviewMouseDownEvent(object sender, MouseButtonEventArgs e)
{
if (!this.IsLoaded) return;
if (!isCeLiang)
{
if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
{
if (isMax == false)
{
this.nextEmbryoButton.Visibility = Visibility.Visible;
this.lastEmbryoButton.Visibility = Visibility.Visible;
//_preview.Width = maxWidth;
//_preview.Height = maxWidth;
_mask.Width = maxWidth;
_mask.Height = maxWidth;
mediaElementPlayer.Width = maxWidth;
mediaElementPlayer.Height = maxWidth;
canvas1.Width = maxWidth;
canvas1.Height = maxWidth;
isMax = true;
//Canvas.SetLeft(_preview, maxLeft);
//Canvas.SetTop(_preview, maxLeft);
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(_preview, 17);
Panel.SetZIndex(canvas1, 18);
}
else
{
this.nextEmbryoButton.Visibility = Visibility.Hidden;
this.lastEmbryoButton.Visibility = Visibility.Hidden;
//_preview.Width = minWidth;
//_preview.Height = minWidth;
_mask.Width = minWidth;
_mask.Height = minWidth;
mediaElementPlayer.Width = minWidth;
mediaElementPlayer.Height = minWidth;
canvas1.Width = minWidth;
canvas1.Height = minWidth;
isMax = false;
//Canvas.SetLeft(_preview, minLeft);
//Canvas.SetTop(_preview, minLeft);
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(_preview, 9);
Panel.SetZIndex(canvas1, 10);
}
SetLoad(isMax);
SetPreView(isMax);
}
e.Handled = true;
return;
}
else
{
switch (count)
{
case 0:
myLine = new Line();
myLine.X1 = e.GetPosition(this.canvas1).X;
myLine.Y1 = e.GetPosition(this.canvas1).Y;
starEllipse = CreateEllipse(myLine.X1, myLine.Y1);
this.canvas1.Children.Add(starEllipse);
count++;
break;
case 1:
myLine.X2 = e.GetPosition(canvas1).X;
myLine.Y2 = e.GetPosition(canvas1).Y;
endEllipse = CreateEllipse(myLine.X2, myLine.Y2);
this.canvas1.Children.Add(endEllipse);
myLine.HorizontalAlignment = HorizontalAlignment.Left;
myLine.VerticalAlignment = VerticalAlignment.Center;
myLine.StrokeDashArray = new DoubleCollection(new List { 8d, 4d });
myLine.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFB000"));
this.canvas1.Children.Add(myLine);
double offsetX = myLine.X2 - myLine.X1;
double offsetY = myLine.Y2 - myLine.Y1;
_ceLiang_Border.SetValue(Canvas.LeftProperty, myLine.X1 + offsetX / 2 - 46.5);
_ceLiang_Border.SetValue(Canvas.TopProperty, myLine.Y1 + offsetY / 2 - 50);
RotateTransform rotateTransform = new RotateTransform();
rotateTransform.Angle = GetAngle(myLine.X1, myLine.Y1, myLine.X2, myLine.Y2);
_ceLiang_Border.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5);
_ceLiang_Border.RenderTransform = rotateTransform;
double fangDaBeiShu = 8.5778;//放大倍数
double xiangYuan = 2.2;
double picWidth = isMax ? 610d : 330d;
//if (vm != null && vm.CurrentPicZhen != null) picWidth = (double)(vm.CurrentPicZhen.radius * 2);
if (PicRadius != 0) picWidth = (double)(PicRadius * 2.0);
int meaValue = (int)(((Math.Sqrt(Math.Pow(offsetX, 2.0) + Math.Pow(offsetY, 2.0)) * xiangYuan) / fangDaBeiShu) / ((isMax ? 610.00 : 330.00) / picWidth)) + AppData.Instance.Measurement;
b1.Text = $"{meaValue}µm";
foreach (var item in vm.MeasurementList)
{
if (item.MeasurementValue == -1)
{
item.MeasurementValue = meaValue;
break;
}
}
//var 线条长度 = Math.Sqrt(Math.Pow(offsetX, 2.0) + Math.Pow(offsetY, 2.0));
//var 线条长度经过像元 = (线条长度 * xiangYuan);
//var 控件放大倍数 = ((isMax ? 610d : 330d) / picWidth);
//var aaaa = 线条长度经过像元 / fangDaBeiShu/ 控件放大倍数;
this._ceLiang_Border.Visibility = Visibility.Visible;
count++;
break;
case 2:
count = 0;
this._ceLiang_Border.Visibility = Visibility.Hidden;
this.canvas1.Children.Remove(myLine);
this.canvas1.Children.Remove(starEllipse);
this.canvas1.Children.Remove(endEllipse);
myLine = new Line();
myLine.X1 = e.GetPosition(canvas1).X;
myLine.Y1 = e.GetPosition(canvas1).Y;
starEllipse = CreateEllipse(myLine.X1, myLine.Y1);
this.canvas1.Children.Add(starEllipse);
count++;
break;
default:
break;
}
e.Handled = true;
return;
}
e.Handled = true;
}
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);
}
}
private void Canvas_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.Source is ButtonBottomImage bottomImage && bottomImage.Name == "_celiang_ButtonBottomImage")
{
e.Handled = true;
return;
}
if (e.Source is Canvas canvas && canvas.Name == "canvas1")
{
e.Handled = true;
return;
}
CloseCeLiang();
}
private Ellipse CreateEllipse(double x, double y)
{
Ellipse ellipse = new Ellipse();
ellipse.Width = 10;
ellipse.Height = 10;
ellipse.Fill = new SolidColorBrush(Colors.Red);
ellipse.SetValue(Canvas.LeftProperty, x - (10 / 2));
ellipse.SetValue(Canvas.TopProperty, y - (10 / 2));
ellipse.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFB000"));
return ellipse;
}
private double GetAngle(double x1, double y1, double x2, double y2)
{
double angle = Math.Atan2(y2 - y1, x2 - x1);
double degrees = angle * 180 / Math.PI;
double normalizedAngle = degrees % 180;
if (normalizedAngle > 90)
{
normalizedAngle -= 180;
}
else if (normalizedAngle < -90)
{
normalizedAngle += 180;
}
return normalizedAngle;
}
private void CloseCeLiang()
{
if (isCeLiang)
{
PicRadius = 0;
count = 0;
this._ceLiang_Border.Visibility = Visibility.Hidden;
this.b1.Text = "";
this.canvas1.Children.Remove(myLine);
this.canvas1.Children.Remove(starEllipse);
this.canvas1.Children.Remove(endEllipse);
isCeLiang = false;
MeaUIShow(false);
}
}
private void LastEmbryo_Click(object sender, RoutedEventArgs e)
{
int index = selectedIndex;
if (index == 0)
{
index = 15;
}
else
{
index--;
}
SelectIndex(index);
CloseCeLiang();
PlayerPause();
ChangeEmbryo(index + 1);
}
private void NextEmbryo_Click(object sender, RoutedEventArgs e)
{
int index = selectedIndex;
if (index == 15)
{
index = 0;
}
else
{
index++;
}
SelectIndex(index);
CloseCeLiang();
PlayerPause();
ChangeEmbryo(index + 1);
}
private void ListBox_ManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
{
e.Handled = true;
}
private void Auto_Click(object sender, RoutedEventArgs e)
{
if (vm == null) return;
var list = vm.CurrentDish.embryoList.Where(x => x.state == (int)EmbryoState.None).ToList();
//var list = vm.CurrentDish.embryoList.ToList();
if (!list.Any())
{
//new ToastMessageWindow(AppData.Instance.MainWindow, $"暂无胚胎需要对焦预览").Show();
new ToastMessageWindow(AppData.Instance.MainWindow, KeyToStringConvert.GetLanguageStringByKey("0320")).Show();
return;
}
AppData.Instance.MainWindowViewModel.MaskVisibility = true;
new AutoFocusWindow(vm.CurrentDish.tlSn, vm.CurrentDish.houseSn, list, vm.CurrentEmbryo).ShowDialog();
AppData.Instance.MainWindowViewModel.MaskVisibility = false;
return;
}
private void AverageValue_Click(object sender, RoutedEventArgs e)
{
int allValue = 0;
int count = 0;
foreach (var item in vm.MeasurementList)
{
if (item.MeasurementValue != -1)
{
allValue += item.MeasurementValue;
count++;
}
}
if (count == 0)
{
MessageShow("至少满足一次测量");
return;
}
this.averageValueText.Text = $"{((double)allValue / count).ToString("f2")}";
}
private void ClearMea_Click(object sender, RoutedEventArgs e)
{
if (this.meaListBox.SelectedItem == null) return;
if (this.meaListBox.SelectedItem is MeasurementEntity mea)
{
mea.MeasurementValue = -1;
}
}
private void MeaUIShow(bool b)
{
if (b)
{
this.meaUI1.Visibility = Visibility.Visible;
//this.meaUI2.Visibility = Visibility.Visible;
//this.meaUI3.Visibility = Visibility.Visible;
}
else
{
this.meaUI1.Visibility = Visibility.Hidden;
//this.meaUI2.Visibility = Visibility.Hidden;
//this.meaUI3.Visibility = Visibility.Hidden;
}
}
private void ClearMeasurementList()
{
this.averageValueText.Text = "";
if (vm == null || vm.MeasurementList == null) return;
foreach (var item in vm.MeasurementList)
{
item.MeasurementValue = -1;
}
}
#region 初始化
private void InitQuickButton()
{
this._quick_StackPanel.Children.Clear();
if (vm == null || vm.QuickButtons == null || !vm.QuickButtons.Any())
{
//this._quick_TextBlock.Visibility = Visibility.Hidden;
return;
}
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 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/DetailNoEmbryo.png", UriKind.Absolute));
image.Tag = i;
image.MouseUp += (s, e) =>
{
if (!this.IsLoaded) return;
if (!(s is Image source)) return;
int index = (int)source.Tag;
if (selectedIndex == index) return;
SelectIndex(index);
CloseCeLiang();
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;
}
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;
}
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.End:
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 EmbryoAlarmEvent(int wellsn, int stateAlarm)
{
try
{
Dispatcher.Invoke(() => { SetWellImage(wellsn - 1, selectedIndex); });
}
catch (Exception ex)
{
}
}
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);
TextBlockList.Add(textBlock);
ImageList.Add(border);
PicImageList.Add(image);
OperImageList.Add(opImage);
Panel.SetZIndex(textBlock, 11);
Panel.SetZIndex(border, 12);
Panel.SetZIndex(image, 13);
Panel.SetZIndex(opImage, 14);
textBlock.FontWeight = FontWeights.Medium;
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);
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);
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);
CloseCeLiang();
PlayerPause();
ChangeEmbryo(index + 1);
};
}
//SelectIndex(0);
}
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 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;
}
///
/// 切换well
///
///
public void ChangeEmbryo(int well)
{
try
{
PlayerDispose();
ClearMeasurementList();
if (vm == null) return;
vm.CurrentEmbryo = null;
vm.CurrentWellDishPicAndVideo = null;
vm.CurrentWellLayerPicAndVideo = null;
vm.CurrentPic = 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);
if (vm.MaxTotalLayer == -1) if (vm.CurrentWellLayerPicAndVideo != null) vm.MaxTotalLayer = vm.CurrentWellLayerPicAndVideo.videoPictures.Max(x => x.totalLayer);
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)
{
var aaa = this.te.VideoCurrentTime;
var aaa1 = this.te.VideoAllTime;
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)
{
if (vm.CurrentWellLayerPicAndVideo != null && !string.IsNullOrEmpty(vm.CurrentWellLayerPicAndVideo.videoUrl) && vm.CurrentWellLayerPicAndVideo.videoUrl != AppData.Instance.CleanVideoString)
{
TimeLog($"视频设置完成");
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 SetEmbryoPic()
{
Image item = null;
for (int i = 0; i < 16; i++)
{
if (!PicImageList.Any()) return;
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.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 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;
}
//var bb = PicImageList[(well - 1)];
//var cc = ((BitmapImage)bb.Source).UriSource.AbsolutePath.Replace("_80x80.jpg", ".jpg").Substring(1);
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.Canvas_preview.Visibility = Visibility.Visible;
//this._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 SetEmbryoState(int well, int embryoState)
{
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;
backItme.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/DetailEmbryoSelectedIcon.png", UriKind.Absolute));
backItme.Tag = 2;
break;
}
}
///
/// 切换图层
///
///
private void ChangeFocal(bool isMax)
{
try
{
//DebugLog($"开始切换图层:{DateTime.Now}");
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;
//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.TextBlock_preview.Text = "";
this._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 = 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);
//var time2 = stopwatch.Elapsed;
//DebugLog($"切换图层确定新图层:{DateTime.Now},耗时:{(time2 - time1).TotalMilliseconds},切换图层以及设置视频源总耗时:{time2.TotalMilliseconds}");
}
catch (Exception ex)
{
ExLog(ex, "ChangeFocal");
}
//finally
//{
// stopwatch.Stop();
//}
}
///
/// 切换图层
///
///
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;
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._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 = 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;
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, "ChangeImageFocal");
}
//finally
//{
// stopwatch.Stop();
//}
}
private void ChangeFocalNoVideo(bool isMax)
{
try
{
//DebugLog($"开始切换图层:{DateTime.Now}");
int maxFocal = (vm.CurrentPic.totalLayer - 1) / 2;
int minFocal = -maxFocal;
int newCurrentFocal = vm.CurrentFocal;
CC:
Debug.WriteLine($"{newCurrentFocal}、{vm.CurrentPic.developTime}");
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;
//totalLayer返回11,但是视频图片数据只有7层
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.Visibility = Visibility.Visible;
this._preview.Source = a;
}
});
});
vm.CurrentFocal = newCurrentFocal;
}
catch (Exception ex)
{
ExLog(ex, "ChangeFocalNoVideo");
}
}
private void SetVideoButtonState(bool IsEnabledVideo)
{
Task.Run(() =>
{
Dispatcher.Invoke(() =>
{
this._lastButton.IsEnabled = IsEnabledVideo;
this._playButton.IsEnabled = IsEnabledVideo;
this._nextButton.IsEnabled = IsEnabledVideo;
});
});
}
#endregion
#region 进度条事件
private void ProgressbarUserControl_BeforeInteractionEvent()
{
CloseCeLiang();
PlayerPause();
if (PlayerState != PlayerStateEnum.Nothing && PlayerState != PlayerStateEnum.Error)
{
//this._preview.Visibility = Visibility.Hidden;
this.Canvas_preview.Visibility = Visibility.Hidden;
}
else
{
}
}
private void ProgressbarUserControl_AfterInteractionEvent(double obj)
{
//Debug.WriteLine($"After:{obj}->{ProToImageIndex()} ->{vm.CurrentWellLayerPicAndVideo.videoPictures.Count}");
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_ProChangendEvent(double obj)
{
//Debug.WriteLine($"ProChangend:{obj}->{ProToImageIndex()}");
if (PlayerState != PlayerStateEnum.Nothing || PlayerState != PlayerStateEnum.Error)
{
SetPlayerPosition(obj);
}
else
{
//this._preview.Source = AppData.Instance.StringToBitmapImage($"{AppData.Instance.BaseUrl}{vm.CurrentWellLayerPicAndVideo.videoPictures[ProToImageIndex()].imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}");
}
}
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";
}
}
///
/// 0- count-1
///
///
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;
}
}
///
/// 进度条换算图片下标
///
///
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 视频基础操作
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.BufferingEnded -= CurrentMediaElement_BufferingEnded;
currentMediaElement.MediaEnded += MediaEndedEvent;
currentMediaElement.MediaOpened += MediaOpenedEvent;
currentMediaElement.MediaFailed += MediaFailedEvent;
//currentMediaElement.BufferingEnded += CurrentMediaElement_BufferingEnded;
dispatcherTimer.Interval = 25;
dispatcherTimer.Elapsed -= dispatcherTimer_Elapsed;
dispatcherTimer.Elapsed += dispatcherTimer_Elapsed;
}
catch (Exception ex)
{
ExLog(ex, $"播放器事件初始化");
}
}
private void CurrentMediaElement_BufferingEnded(object sender, RoutedEventArgs e)
{
TimeLog($"媒体缓冲结束时");
}
private string LocalVideo()
{
switch (vm.CurrentEmbryo.wellSn)
{
case 1:
return @"C:\Users\20552\Desktop\t-修改_24-01-23-17-35-08\t-修改_well_1.mp4";
case 2:
return @"C:\Users\20552\Desktop\t-修改_24-01-23-17-35-08\t-修改_well_2.mp4";
case 3:
return @"C:\Users\20552\Desktop\t-修改_24-01-23-17-35-08\t-修改_well_3.mp4";
case 4:
return @"C:\Users\20552\Desktop\t-修改_24-01-23-17-35-08\t-修改_well_4.mp4";
case 5:
return @"C:\Users\20552\Desktop\t-修改_24-01-23-17-35-08\t-修改_well_5.mp4";
case 6:
return @"C:\Users\20552\Desktop\t-修改_24-01-23-17-35-08\t-修改_well_6.mp4";
case 7:
return @"C:\Users\20552\Desktop\t-修改_24-01-23-17-35-08\t-修改_well_7.mp4";
}
return "";
}
private string LocalVideo1()
{
switch (vm.CurrentEmbryo.wellSn)
{
case 1:
return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_1.mp4";
case 2:
return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_2.mp4";
case 3:
return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_3.mp4";
case 4:
return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_4.mp4";
case 5:
return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_5.mp4";
case 6:
return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_6.mp4";
case 7:
return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_7.mp4";
}
return @"C:\Users\20552\Desktop\2_24-01-23-17-51-51\2_well_1.mp4";
}
///
/// 设置播放源
///
///
public bool PlayerSetSource(string FileName)
{
try
{
//FileName = "http://192.168.0.218:8300/vod/index.m3u8";
//FileName = LocalVideo1();
PlayerDispose();
currentMediaElement.Source = new Uri(FileName, UriKind.RelativeOrAbsolute);
currentMediaElement.LoadedBehavior = MediaState.Manual;
currentMediaElement.SpeedRatio = 1;
currentMediaElement.Play();
currentMediaElement.Pause();
return true;
}
catch (Exception ex)
{
ExLog(ex, $"设置播放源");
return false;
}
}
///
/// 播放器加载视频完成事件
///
///
///
private void MediaOpenedEvent(object sender, RoutedEventArgs e)
{
try
{
if (!this.IsLoaded) return;
if (vm == null) return;
//Stopwatch stopwatch = Stopwatch.StartNew();
TimeLog($"视频加载完成");
//bool isWhile = true;
//while (isWhile)
//{
// DebugLog($"视频下载进度:{currentMediaElement.DownloadProgress}");
// isWhile = !(currentMediaElement.DownloadProgress == 1);
// Thread.Sleep(20);
//}
//isWhile = true;
//while (isWhile)
//{
// DebugLog($"视频加载进度:{currentMediaElement.BufferingProgress}");
// isWhile = !(currentMediaElement.BufferingProgress == 1);
// Thread.Sleep(20);
//}
//ErrorLog($"视频加载完成,开始设置属性", LogEnum.RunRecord);
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;
//Debug.WriteLine($"{vm.CurrentFocal}:{vm.VideoAllTime}:{currentMediaElement.Source}");
currentMediaElement.ScrubbingEnabled = true;
//currentMediaElement.SpeedRatio = vm.SelectedFps.Key;
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;
}
//ErrorLog($"视频属性设置完成:{DateTime.Now},总耗时:{stopwatch.Elapsed.TotalMilliseconds}", LogEnum.RunRecord);
//stopwatch.Stop();
}
catch (Exception ex)
{
PlayerState = PlayerStateEnum.Error;
ExLog(ex, $"播放器加载视频完成事件");
}
}
///
/// 播放完成事件
///
///
///
private void MediaEndedEvent(object sender, RoutedEventArgs e)
{
//bool isCan = currentMediaElement.CanPause;
try
{
PlayerState = PlayerStateEnum.Paused;
dispatcherTimer_Stop();
//currentMediaElement.LoadedBehavior = MediaState.Stop;
//currentMediaElement.LoadedBehavior = MediaState.Play;
//currentMediaElement.LoadedBehavior = MediaState.Pause;
//currentMediaElement.SpeedRatio = 1;
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;
if (vm != null)
{
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
{
if (vm == null) return;
vm.VideoCurrentTime = newTime;
}
catch (Exception ex)
{
ExLog(ex, $"设置进度条进度");
}
}
///
/// 释放播放器
///
public void PlayerDispose()
{
try
{
dispatcherTimer_Stop();
if (PlayerState != PlayerStateEnum.Nothing)
{
if (currentMediaElement != null)
{
currentMediaElement.Close();
currentMediaElement.LoadedBehavior = MediaState.Close;
}
PlayerState = PlayerStateEnum.Nothing;
}
}
catch (Exception ex)
{
PlayerState = PlayerStateEnum.Nothing;
ExLog(ex, $"释放播放器");
}
}
///
/// 设置倍率
///
///
public void PlayerSetSpeedRatio(double newSpeedRatio)
{
try
{
beilv = newSpeedRatio;
if (PlayerState == PlayerStateEnum.Playing)
{
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();
//currentMediaElement.LoadedBehavior = MediaState.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.LoadedBehavior = MediaState.Pause;
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) return;
//var currentPositionTime = currentMediaElement.Position.TotalMilliseconds;
if (vm.VideoCurrentTime == 0) return;
var c = vm.VideoCurrentTime - (1000.00 / zhenshu);
if (c < 0) c = 0;
SetPlayerPosition(c);
SetTimeProgressbarProgressValue(c);
return;
}
catch (Exception ex)
{
ExLog(ex, $"上一帧");
}
}
///
/// 下一帧
///
public void PlayerNextFrame(int zhenshu)
{
try
{
bool isOK = 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;
}
catch (Exception ex)
{
ExLog(ex, $"下一帧");
}
}
#endregion
}
}