157 lines
6.1 KiB
C#
157 lines
6.1 KiB
C#
using Cowain.Bake.BLL;
|
||
using Cowain.Bake.Common.Core;
|
||
using Cowain.Bake.Common.Enums;
|
||
using Cowain.Bake.Model;
|
||
using Cowain.Bake.Model.Models;
|
||
using Newtonsoft.Json;
|
||
using Prism.Commands;
|
||
using Prism.Mvvm;
|
||
using Prism.Services.Dialogs;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Windows;
|
||
using Unity;
|
||
|
||
namespace Cowain.Bake.Main.ViewModels
|
||
{
|
||
internal class MoistureValueViewMode: BindableBase//, Prism.Services.Dialogs.IDialogAware
|
||
{
|
||
private readonly IUnityContainer _unityContainer;
|
||
private float? septumwaterJudge;
|
||
private float? cathodewaterJudge;
|
||
private float? anodewaterJudge ;
|
||
//public string WaterValueModel;
|
||
List<WaterModel> waterModels = null;
|
||
public CavityDtlViewModel thatParent = null;
|
||
|
||
//public string Title => "输入水含量值";
|
||
//// 弹窗打开时触发:读取传递的参数
|
||
//public void OnDialogOpened(IDialogParameters parameters)
|
||
//{
|
||
// thatParent = parameters.GetValue<CavityDtlViewModel>("this");
|
||
// WaterValueModel = thatParent.WaterValueModel ?? "";
|
||
//}
|
||
|
||
//// 允许关闭弹窗(返回true即可)
|
||
//public bool CanCloseDialog() => true;
|
||
|
||
//// 弹窗关闭后清理资源(可选)
|
||
//public void OnDialogClosed() { }
|
||
|
||
//// Prism 8中用于触发弹窗关闭的事件
|
||
//public event Action<IDialogResult> RequestClose;
|
||
|
||
//public DelegateCommand CloseCommand =>
|
||
// new DelegateCommand(() =>
|
||
// RequestClose?.Invoke(new DialogResult(ButtonResult.OK)));
|
||
|
||
|
||
|
||
public MoistureValueViewMode(IUnityContainer unityContainer)
|
||
{
|
||
_unityContainer = unityContainer;
|
||
}
|
||
|
||
public float? SeptumWaterJudge //隔离膜水分
|
||
{
|
||
get => septumwaterJudge;
|
||
set => SetProperty(ref septumwaterJudge, value);
|
||
}
|
||
public float? AnodeWaterJudge //正极水分
|
||
{
|
||
get => anodewaterJudge;
|
||
set => SetProperty(ref anodewaterJudge, value);
|
||
}
|
||
public float? CathodeWaterJudge //负极水分
|
||
{
|
||
get => cathodewaterJudge;
|
||
set => SetProperty(ref cathodewaterJudge, value);
|
||
}
|
||
|
||
|
||
public DelegateCommand<object> Judge => new DelegateCommand<object>((x) =>
|
||
{
|
||
int septumwaterTargetValue = int.Parse(_unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.SeptumwaterTargetJudge.ToString()));
|
||
int cathodewaterTargetValue = int.Parse(_unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.CathodewaterTargetJudge.ToString()));
|
||
int anodewaterTargetValue = int.Parse(_unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.AnodewaterTargetJudge.ToString()));
|
||
//MessageBoxResult result = HandyControl.Controls.MessageBox.Ask($@"是否确定为手动输入的水含量值?", "操作提示");
|
||
//if (result == System.Windows.MessageBoxResult.Cancel)
|
||
//{
|
||
// return;
|
||
//}
|
||
LogHelper.Instance.Warn($"开始测水含量0!");
|
||
if (!septumwaterJudge.HasValue
|
||
|| !anodewaterJudge.HasValue
|
||
|| !cathodewaterJudge.HasValue
|
||
)
|
||
{
|
||
HandyControl.Controls.MessageBox.Warning("数值为空, 请人工输入!");
|
||
return;
|
||
}
|
||
|
||
var WaterModel = new WaterModel();
|
||
WaterModel.AnodeWaterValue = anodewaterJudge.ToString();
|
||
WaterModel.CathodeWaterValue = cathodewaterJudge.ToString();
|
||
WaterModel.SeptumWaterValue = septumwaterJudge.ToString();
|
||
int palletStatus = (int)EPalletStatus.TestOK;
|
||
if (septumwaterJudge >= septumwaterTargetValue
|
||
|| cathodewaterJudge >= cathodewaterTargetValue
|
||
|| anodewaterJudge >= anodewaterTargetValue)
|
||
{
|
||
palletStatus = (int)EPalletStatus.TestNG;
|
||
MessageBoxResult judgeResult = HandyControl.Controls.MessageBox.Ask($@"本次判定水含量值为NG,请确认!", "判定提示");
|
||
if (judgeResult == System.Windows.MessageBoxResult.Cancel)
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
|
||
//WaterValueModel,在这个界面点【判定】,会刷新这个值。也就是这个判断结果会累加,但在【工站明细】中不会
|
||
waterModels = JsonConvert.DeserializeObject<List<WaterModel>>(thatParent.WaterValueModel??""); //WaterValueModel:数据库中的水含量数据
|
||
WaterModel.BatteryCode = GetBatteryCode(waterModels);
|
||
if (null == waterModels)
|
||
{
|
||
waterModels = new List<WaterModel>();
|
||
}
|
||
else
|
||
{
|
||
WaterModel.Id = waterModels.Max(w => w.Id) + 1;
|
||
}
|
||
waterModels.Add(WaterModel);
|
||
|
||
thatParent.MoistureRuturn(palletStatus, JsonConvert.SerializeObject(waterModels));
|
||
HandyControl.Controls.MessageBox.Info("设置测试水含量成功");
|
||
});
|
||
|
||
string GetBatteryCode(List<WaterModel> waterList)
|
||
{
|
||
var dummys = _unityContainer.Resolve<BatteryInfoService>().GetWaterBatteryCode(thatParent.VirtualId);
|
||
|
||
if (0 == dummys.Count)
|
||
{
|
||
return "";
|
||
}
|
||
|
||
if (waterList == null
|
||
|| 0 == waterList.Count)
|
||
{
|
||
return dummys[0].BatteryCode;
|
||
}
|
||
|
||
List<string> dummyCodes = dummys.Select(x => x.BatteryCode).ToList();
|
||
List<string> waterCodes = waterList.Select(x => x.BatteryCode).ToList();
|
||
// 查找 list1 中不在 list2 中的字符串 var notInList2 = list1.Except(list2);
|
||
var batteryCode = dummyCodes.Except(waterCodes);
|
||
if (0 ==batteryCode.Count())
|
||
{
|
||
return waterList.OrderByDescending(x => x.Id).FirstOrDefault().BatteryCode;//最后一次的假电芯码
|
||
}
|
||
return batteryCode.First();
|
||
}
|
||
|
||
|
||
|
||
}
|
||
}
|