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