首次提交:添加src文件夹代码

This commit is contained in:
2026-02-27 14:02:43 +08:00
commit d330cfbca7
4184 changed files with 5546478 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
using Cowain.Bake.BLL;
using Cowain.Bake.Common;
using Cowain.Bake.Model;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;
using Prism.Commands;
using System.Windows;
using HandyControl.Controls;
using Cowain.Bake.Model.Entity;
using Cowain.Bake.UI.CsvMap;
namespace Cowain.Bake.UI.DataQuery.ViewModels
{
public class BatteryInfoViewModel : ViewModelBase
{
private DateTime _startTime = DateTime.Now.AddDays(-1);
public DateTime StartDatetime
{
get { return _startTime; }
set { SetProperty(ref _startTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); }
}
private DateTime _endTime = DateTime.Now.AddHours(1);
public DateTime EndDatetime
{
get { return _endTime; }
set { SetProperty(ref _endTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); }
}
public BatteryInfoViewModel(IUnityContainer unityContainer, IRegionManager regionManager) : base(unityContainer, regionManager)
{
this.PageTitle = "电池追踪";
}
public List<BatteryInfoEntity> batteryList = new List<BatteryInfoEntity>();
private ObservableCollection<TBatteryInfo> cellList;
public ObservableCollection<TBatteryInfo> CellList
{
get => cellList ?? (cellList = new ObservableCollection<TBatteryInfo>());
set { SetProperty(ref cellList, value); }
}
public DelegateCommand<object> ExportCommand => new DelegateCommand<object>((x) =>
{
if (batteryList.Count == 0)
{
return;
}
Common.Core.CSVHelper.WriteMap<BatteryInfoEntity, BatteryInfoDetailMap>(batteryList);
//Common.Core.CSVHelper.WriteDataTableToCsv(batteryList, new List<string> { "Id","BatteryCode", "PalletCode", "BatteryStatus",
// "PositionX", "PositionY", "LoadingBegingTime","ScanTime","LoadingOverTime", "BakingPosition", "BakingBeginTime", "BakingOverTime","UnLoadingBegingTime", "UnLoadingOverTime", "WaterValue"}, new List<string> { "序号", "电芯条码", "托盘条码", "电芯状态", "行号", "列号", "上料开始时间","扫码时间", "上料结束时间", "所属烤箱", "烘烤开始时间",
// "烘烤结束时间", "下料开始时间", "下料结束时间", "不含量结果"});
});
public DelegateCommand<object> QueryCommand => new DelegateCommand<object>((x) =>
{
CellList.Clear();
if ((EndDatetime - StartDatetime).TotalDays > 5)
{
HandyControl.Controls.MessageBox.Warning("查询时间差在 5 天以内!");
return;
}
if (string.IsNullOrEmpty(Code))
{
batteryList = _unityContainer.Resolve<BatteryInfoService>().Query(StartDatetime, EndDatetime);
}
else
{
batteryList = _unityContainer.Resolve<BatteryInfoService>().Query(Code);
}
if (0 != batteryList.Count)
{
batteryList.ForEach(item => CellList.Add(item));
Growl.Success("查询完成!");
}
else
{
Growl.Success("没有数据!");
}
});
public DelegateCommand<object> DeleteCommand => new DelegateCommand<object>((x) =>
{
});
}
}

View File

@@ -0,0 +1,365 @@
using Cowain.Bake.BLL;
using Cowain.Bake.Common;
using Cowain.Bake.Common.Core;
using Cowain.Bake.UI.CommonView.Views;
using LiveCharts;
using LiveCharts.Wpf;
using Prism.Commands;
using Prism.Regions;
using System;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Media;
using Unity;
namespace Cowain.Bake.UI.DataQuery.ViewModels
{
public enum EChartType
{
Temp = 1,
Vacuum = 2,
PID = 3
}
public class DemoDataModel
{
public int Index { get; set; }
public string Name { get; set; } = string.Empty;
public bool IsSelected { get; set; }
}
public class CurveViewModel : ViewModelBase
{
//private DataTable _dtChartTemp;
private DataTable _dtTemp;
private ObservableCollection<DemoDataModel> _dataList;
public ObservableCollection<DemoDataModel> DataList
{
get => _dataList;
set => SetProperty(ref _dataList, value);
}
public DataTable DtTemp
{
get => _dtTemp;
set => SetProperty(ref _dtTemp, value);
}
private DataTable _dtPID;
public DataTable DtPID
{
get => _dtPID;
set => SetProperty(ref _dtPID, value);
}
public ChartValues<string> TimeLine { get; set; }
public string XName { get; set; }
public string YName { get; set; }
public SeriesCollection SeriesCollection { get; set; }
private int _stepId = 1;
public int StepId
{
get => _stepId;
set => SetProperty(ref _stepId, value);
}
private string _selectOneItem;
public string SelectOneItem
{
get => _selectOneItem;
set => SetProperty(ref _selectOneItem, value);
}
private DateTime _curveStartDateTime = DateTime.Now.AddHours(-23);
public DateTime CurveStartDateTime
{
get { return _curveStartDateTime; }
set { SetProperty(ref _curveStartDateTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); }
}
private DateTime _curveEndDateTime = DateTime.Now;
public DateTime CurveEndDateTime
{
get { return _curveEndDateTime; }
set { SetProperty(ref _curveEndDateTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); }
}
public CurveViewModel(IUnityContainer unityContainer, IRegionManager regionManager) : base(unityContainer, regionManager)
{
DtTemp = null;
DtPID = null;;
DataList = new ObservableCollection<DemoDataModel>();
SetCheckCombox();
TimeLine = new ChartValues<string>();
SeriesCollection = new SeriesCollection();
this.PageTitle = "曲线图表";
}
private void SetCheckCombox()
{
for (int i = 1; i <= 8; i++)
{
DataList.Add(new DemoDataModel()
{
Index = i,
Name = "温度" + i.ToString(),
IsSelected = true,
});
}
}
void GetTempChartData(DataTable table)
{
for (int i = 2; i < table.Columns.Count; i++)
{
var columnName = table.Columns[i].ColumnName;
var model = DataList.Where(x => x.IsSelected && x.Name == columnName).FirstOrDefault();
if (null == model)
{
continue;
}
ChartValues<double> chartValues = new ChartValues<double>();
table.AsEnumerable().Select(item => item.Field<double>(columnName)).ToList().ForEach(item => chartValues.Add(item));
var lineSeries = new LineSeries
{
Title = columnName,
Values = chartValues,
StrokeThickness = 1,
LineSmoothness = 0,
Fill = Brushes.Transparent,
PointGeometry = null // 不画圆点
};
SeriesCollection.Add(lineSeries);
}
}
void GetVacuumChartData(DataTable table)
{
var columnName = table.Columns[2].ColumnName;
ChartValues<double> chartValues = new ChartValues<double>();
table.AsEnumerable().Select(item => item.Field<float>(columnName)).ToList().ForEach(item => chartValues.Add(Math.Round(item,2)));
var lineSeries = new LineSeries
{
Title = columnName,
Values = chartValues,
StrokeThickness = 1,
LineSmoothness = 0,
Fill = Brushes.Transparent,
PointGeometry = null // 不画圆点
};
SeriesCollection.Add(lineSeries);
}
void GetPIDChartData(DataTable table)
{
for (int i = 2; i < table.Columns.Count; i++)
{
var columnName = table.Columns[i].ColumnName;
ChartValues<double> chartValues = new ChartValues<double>();
table.AsEnumerable().Select(item => item.Field<double>(columnName)).ToList().ForEach(item => chartValues.Add(item));
var lineSeries = new LineSeries
{
Title = columnName,
Values = chartValues,
StrokeThickness = 1,
LineSmoothness = 0,
Fill = Brushes.Transparent,
PointGeometry = null // 不画圆点
};
SeriesCollection.Add(lineSeries);
}
}
private void UpdateSeries(DataTable table, EChartType chartType)
{
if (null == table
|| 0 == table.Rows.Count)
{
HandyControl.Controls.Growl.Warning("请点【查询】数据,或查询数据为空!");
return;
}
StepId = table.Rows.Count / 10;
System.Threading.SynchronizationContext.SetSynchronizationContext(new
System.Windows.Threading.DispatcherSynchronizationContext(System.Windows.Application.Current.Dispatcher));
System.Threading.SynchronizationContext.Current.Post(p1 =>
{
TimeLine.Clear();
SeriesCollection.Clear();
if (chartType == EChartType.Vacuum)
{
GetVacuumChartData(table);
}
else if (chartType == EChartType.Temp)
{
GetTempChartData(table);
}
else
{
GetPIDChartData(table);
}
SetXAxis(table);
}, null);
}
private void SetXAxis(DataTable table)
{
XName = table.Columns[0].ColumnName;
table.AsEnumerable().Select(item => item.Field<string>(XName)).ToList().ForEach(item => TimeLine.Add(item));
}
public DelegateCommand QueryTempCommand { get => new DelegateCommand(async () => await QueryTemp()); }
public async Task QueryTemp()
{
DtTemp = null;
if (!IsAccord("温度曲线(℃)"))
{
return;
}
ProgressBarView dlg = new ProgressBarView();
dlg.Show();
string sql = $@"CALL ProcGetTemperatureAndPressureData('{CurveStartDateTime.ToString("yyyy-MM-dd HH:mm:ss")}'
,'{CurveEndDateTime.ToString("yyyy-MM-dd HH:mm:ss")}','{Code}')";
await Task.Run(new Action(() =>
{
DtTemp = _unityContainer.Resolve<StoveSctualPatrolService>().GetDataTable(sql);
}));
dlg.Close();
Tip(DtTemp);
}
void Tip(DataTable dt)
{
if (0 == dt.Rows.Count)
{
HandyControl.Controls.Growl.Warning("查询数据为空!");
}
else
{
HandyControl.Controls.Growl.Success("查询数据成功!");
}
}
public DelegateCommand ChartTempCommand => new DelegateCommand(async() =>
{
await WaitChartTemp(DtTemp, EChartType.Temp);
});
public async Task AsyncChart(DataTable table, EChartType chartType)
{
Task queryTask = Task.Run(() => UpdateSeries(table, chartType));
var timeouttask = Task.Delay(30 * 1000);
var completedTask = await Task.WhenAny(queryTask, timeouttask);
if (completedTask == timeouttask)
{
HandyControl.Controls.MessageBox.Warning("查询超时!");
}
}
public DelegateCommand ChartVacuumCommand => new DelegateCommand(async() =>
{
if (!IsAccord("真空压力"))
{
return;
}
await WaitChartTemp(DtTemp, EChartType.Vacuum);
});
//public DelegateCommand QueryPIDCommand { get => new DelegateCommand(QueryPID); }
public DelegateCommand QueryPIDCommand { get => new DelegateCommand(async() => await QueryPID()); }
public async Task QueryPID()
{
if (!IsAccord("PID"))
{
return;
}
ProgressBarView dlg = new ProgressBarView();
dlg.Show();
string sql = $@"CALL ProcGetPidData ('{CurveStartDateTime.ToString("yyyy-MM-dd HH:mm:ss")}'
,'{CurveEndDateTime.ToString("yyyy-MM-dd HH:mm:ss")}','{Code}')";
await Task.Run(new Action(() =>
{
DtPID = _unityContainer.Resolve<StoveSctualPatrolService>().GetDataTable(sql);
}));
dlg.Close();
Tip(DtPID);
}
public DelegateCommand ChartPIDCommand => new DelegateCommand(async() =>
{
await WaitChartTemp(DtPID, EChartType.PID);
});
public async Task WaitChartTemp(DataTable table, EChartType eChart)
{
ProgressBarView dlg = new ProgressBarView();
dlg.Show();
await AsyncChart(table, eChart);
dlg.Close();
}
public DelegateCommand<object> ExportTempCommand => new DelegateCommand<object>((x) =>
{
if (null == DtTemp)
{
HandyControl.Controls.MessageBox.Error("温度数据为空!", "操作提示");
return;
}
CSVHelper.WriteDataTableToCsv(DtTemp);
});
public DelegateCommand<object> ExportPIDCommand => new DelegateCommand<object>((x) =>
{
if (null == DtPID)
{
HandyControl.Controls.MessageBox.Error("温度数据为空!", "操作提示");
return;
}
CSVHelper.WriteDataTableToCsv(DtPID);
});
bool IsAccord(string headName)
{
YName = headName;
if (string.IsNullOrWhiteSpace(Code))
{
HandyControl.Controls.MessageBox.Error("请输入条码", "操作提示");
return false;
}
var p = _unityContainer.Resolve<PalletInfoService>().GetPalletInfo(Code);
if (p == null)
{
HandyControl.Controls.MessageBox.Error("没有该托盘码", "操作提示");
return false;
}
TimeSpan timeSpan = CurveEndDateTime - CurveStartDateTime;
if (timeSpan.TotalHours > 24)
{
HandyControl.Controls.MessageBox.Error("请选择时间区间小于24小时的数据", "操作提示");
return false;
}
return true;
}
}
}

View File

@@ -0,0 +1,65 @@
using Cowain.Bake.BLL;
using Cowain.Bake.Model.Entity;
using Cowain.Bake.Common;
using Cowain.Bake.Model;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Unity;
using Prism.Commands;
using HandyControl.Controls;
using Newtonsoft.Json;
using Cowain.Bake.Model.Models;
using System.Linq;
namespace Cowain.Bake.UI.DataQuery.ViewModels
{
public class DummyInfoViewModel:ViewModelBase
{
public DummyInfoViewModel(IUnityContainer unityContainer, IRegionManager regionManager) : base(unityContainer, regionManager)
{
this.PageTitle = "电池追踪";
}
private ObservableCollection<BatteryInfoEntity> cellList;
public ObservableCollection<BatteryInfoEntity> CellList
{
get => cellList ?? (cellList = new ObservableCollection<BatteryInfoEntity>());
set { SetProperty(ref cellList, value); }
}
public DelegateCommand<object> DummyQueryCommand => new DelegateCommand<object>((x) =>
{
CellList.Clear();
if (string.IsNullOrWhiteSpace(Code))
{
HandyControl.Controls.MessageBox.Error($@"没有数据!请输入正确的条码", "操作提示");
return;
}
BatteryInfoEntity batteryInfo = _unityContainer.Resolve<BatteryInfoService>().QueryBatteryWaterValue(Code);
if(null == batteryInfo)
{
HandyControl.Controls.MessageBox.Error($@"没有数据到所属托盘或没有此电芯!", "警告");
return;
}
if (!string.IsNullOrEmpty(batteryInfo.WaterValue))
{
List<WaterModel> waterModelList = JsonConvert.DeserializeObject<List<WaterModel>>(batteryInfo.WaterValue);
WaterModel waterModel = waterModelList.OrderByDescending(w=>w.Id).FirstOrDefault();
batteryInfo.SeptumValue = waterModel.SeptumWaterValue;
batteryInfo.AnodeValue = waterModel.AnodeWaterValue;
batteryInfo.CathodeValue = waterModel.CathodeWaterValue;
}
CellList.Add(batteryInfo);
Growl.Success("查询完成!");
});
}
}

View File

@@ -0,0 +1,192 @@
using Cowain.Bake.Model.Entity;
using Cowain.Bake.BLL;
using Cowain.Bake.Common;
using Cowain.Bake.Common.Enums;
using Cowain.Bake.Common.Interface;
using Cowain.Bake.Model;
using HandyControl.Controls;
using Microsoft.Win32;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using Unity;
using Cowain.Bake.Common.CsvMap;
namespace Cowain.Bake.UI.DataQuery.ViewModels
{
public class GetMesLogViewModel : ViewModelBase, INavigationAware
{
TimeSpan intervalDateTime;
private bool isChecked;
public bool IsChecked
{
get => isChecked;
set => SetProperty(ref isChecked, value);
}
private string batteryCode;
public string BatteryCode
{
get => batteryCode;
set => SetProperty(ref batteryCode, value);
}
private string mesClass;
public string MesClass
{
get => mesClass;
set => SetProperty(ref mesClass, value);
}
private ObservableCollection<MesDataEntity> mesDataList;
public ObservableCollection<MesDataEntity> MesDataList
{
get => mesDataList;
set => SetProperty(ref mesDataList, value);
}
private List<string> mesClassList;
public List<string> MesClassList
{
get => mesClassList;
set => SetProperty(ref mesClassList, value);
}
private DateTime _startTime = DateTime.Now.AddDays(-2);
public DateTime StartDatetime
{
get { return _startTime; }
set { SetProperty(ref _startTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); }
}
private DateTime _endTime = DateTime.Now;
public DateTime EndDatetime
{
get { return _endTime; }
set { SetProperty(ref _endTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); }
}
public GetMesLogViewModel(IUnityContainer unityContainer, IRegionManager regionManager) : base(unityContainer, regionManager)
{
BatteryCode = "";
_unityContainer = unityContainer;
SetPalletStatusCombox();
MesDataList = new ObservableCollection<MesDataEntity>();
}
private void SetPalletStatusCombox()
{
mesClassList = new List<string>();
foreach (EMesLogClass eMesLogClass in System.Enum.GetValues(typeof(EMesLogClass)))
{
mesClassList.Add(eMesLogClass.GetDescription());
}
MesClass = EMesLogClass.EnterStation.GetDescription();
}
public DelegateCommand AutoUploadCommand => new DelegateCommand(() =>
{
foreach (var item in MesDataList)
{
if (item.IsCheck)
{
_unityContainer.Resolve<MesDataService>().ModifySendFlag(item.Id, (sbyte)EMesUpLoadStatus.Wait);
}
}
QueryMesStation();
});
bool QueryMesStation()
{
MesDataList.Clear();
List<MesDataEntity> dataList = null;
if (!ExecuttableOrNot())
{
return false;
}
if (IsChecked)
{
if (string.IsNullOrEmpty(BatteryCode))
{
Growl.Warning("电芯条码为空!");
return false;
}
dataList = _unityContainer.Resolve<MesDataService>().GetMesDataCellState(BatteryCode, StartDatetime, EndDatetime);
dataList.AddRange(_unityContainer.Resolve<MesDataService>().GetMesDataBakingOutput(BatteryCode, StartDatetime, EndDatetime));
}
else
{
if (string.IsNullOrEmpty(MesClass))
{
Growl.Warning("Mes信息类别为空");
return false;
}
var Cmd = EnumHelper.GetValueByDescription<EMesLogClass>(MesClass);
dataList = _unityContainer.Resolve<MesDataService>().GetMesDataList(Cmd, StartDatetime, EndDatetime);
}
dataList.ForEach(item => MesDataList.Add(item));
return true;
}
public DelegateCommand<object> QueryCommand => new DelegateCommand<object>((x) =>
{
if (!QueryMesStation())
{
return;
}
if (MesDataList.Count == 0)
{
Growl.Warning("没有数据!");
return;
}
});
public DelegateCommand<object> GetMesCvsCommand => new DelegateCommand<object>((x) =>
{
if (MesDataList == null
|| MesDataList.Count == 0)
{
Growl.Warning("没有数据!");
return;
}
Common.Core.CSVHelper.WriteMap<MesDataEntity, MesDataMap>(MesDataList);
//Common.Core.CSVHelper.WriteDataTableToCsv(MesDataList, new List<string>() {"CreateTime", "SendTime", "RecvTime", "Content", "RecvContent", "BatteryCode" },
// new List<string>() {"创建时间", "发送时间", "接收时间", "发送信息", "接收信息" , "电芯条码"});
});
void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
{
// 导航到当前页面时的处理逻辑,先执行构造方法,再执行本方法
}
bool INavigationAware.IsNavigationTarget(NavigationContext navigationContext)
{
return false; //false:表示每次导航都创建新实例,不重用旧实例; true:用旧实例,不会执行构造方法
}
void INavigationAware.OnNavigatedFrom(NavigationContext navigationContext)
{
//相当于析构方法,退出时(切换时)再执行。
// 在这里添加释放旧视图实例资源的代码
}
private bool ExecuttableOrNot()
{
intervalDateTime = EndDatetime - StartDatetime;
if (intervalDateTime.TotalDays > 10)
{
Growl.Warning("请选择时间区间小于10天的数据");
return false;
}
return true;
}
}
}

View File

@@ -0,0 +1,146 @@
using Cowain.Bake.BLL;
using Cowain.Bake.Common;
using Cowain.Bake.Model;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;
using Prism.Commands;
using System.Windows;
using HandyControl.Controls;
using Cowain.Bake.UI.CsvMap;
namespace Cowain.Bake.UI.DataQuery.ViewModels
{
public class IncomingCellInfoViewModel : ViewModelBase
{
private DateTime _startTime = DateTime.Now.AddDays(-1);
public DateTime StartDatetime
{
get { return _startTime; }
set { SetProperty(ref _startTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); }
}
private DateTime _endTime = DateTime.Now.AddHours(1);
public DateTime EndDatetime
{
get { return _endTime; }
set { SetProperty(ref _endTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); }
}
List<TBatteryInfo> batteryList = new List<TBatteryInfo>();
public IncomingCellInfoViewModel(IUnityContainer unityContainer, IRegionManager regionManager) : base(unityContainer, regionManager)
{
this.PageTitle = "来料查询";
}
private ObservableCollection<TBatteryInfo> cellList;
public ObservableCollection<TBatteryInfo> CellList
{
get => cellList ?? (cellList = new ObservableCollection<TBatteryInfo>());
set { SetProperty(ref cellList, value); }
}
public void AsyncRefreshTask()
{
Application.Current?.Dispatcher?.Invoke(new Action(() =>
{
Refresh();
}));
}
public async override void Refresh()
{
CellList.Clear();
batteryList.Clear();
batteryList = await System.Threading.Tasks.Task.Run(() =>
{
var cellInfoService = _unityContainer.Resolve<BatteryInfoService>();
//从数据库查询任务
return cellInfoService.GetIncomingCell();
});
batteryList.ForEach(x => CellList.Add(x));
}
public DelegateCommand<object> DeleteCommand => new DelegateCommand<object>((x) =>
{
var result = HandyControl.Controls.MessageBox.Ask($@"确定删除?", "操作提示");
if (result == System.Windows.MessageBoxResult.Cancel)
{
return;
}
var t = x as TBatteryInfo;
if (t != null)
{
int delCount = _unityContainer.Resolve<BatteryInfoService>().Delete(t);
cellList.Remove(t);
if (delCount > 0)
{
Growl.Success("删除成功!");
}
else
{
Growl.Fatal("删除失败!");
}
}
else
{
Growl.Fatal("删除失败!");
}
});
public DelegateCommand<object> ExportCommand => new DelegateCommand<object>((x) =>
{
if (batteryList.Count == 0)
{
HandyControl.Controls.MessageBox.Show("没有数据!");
return;
}
Common.Core.CSVHelper.WriteMap<TBatteryInfo, BatteryInfoMap>(batteryList);
});
public DelegateCommand<object> QueryCommand => new DelegateCommand<object>((x) =>
{
CellList.Clear();
batteryList.Clear();
if ((EndDatetime - StartDatetime).TotalDays > 5)
{
HandyControl.Controls.MessageBox.Warning("查询时间差在 5 天以内!");
return;
}
var cellService = _unityContainer.Resolve<BatteryInfoService>();
if (string.IsNullOrWhiteSpace(Code))
{
batteryList = cellService.QueryIncomingCell(StartDatetime, EndDatetime);
}
else
{
batteryList = cellService.QueryIncomingCellByCode(Code);
}
if (0 != batteryList.Count)
{
batteryList.ForEach(item => CellList.Add(item));
Growl.Success("查询完成!");
}
else
{
Growl.Success("没有数据!");
}
});
}
}

View File

@@ -0,0 +1,179 @@
using Cowain.Bake.Common;
using Cowain.Bake.Model;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;
using Prism.Commands;
using System.Windows;
using HandyControl.Controls;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Cowain.Bake.Common.Core;
using Cowain.Bake.BLL;
using Cowain.Bake.Model.Entity;
using Cowain.Bake.Common.CsvMap;
namespace Cowain.Bake.UI.DataQuery.ViewModels
{
public class NGCellInfoViewModel:ViewModelBase
{
private DateTime _startTime = DateTime.Now.AddDays(-1);
public DateTime StartDatetime
{
get { return _startTime; }
set { SetProperty(ref _startTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); }
}
private DateTime _endTime = DateTime.Now.AddHours(1);
public DateTime EndDatetime
{
get { return _endTime; }
set { SetProperty(ref _endTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); }
}
public NGCellInfoViewModel(IUnityContainer unityContainer, IRegionManager regionManager) : base(unityContainer, regionManager)
{
this.PageTitle = "烘烤NG电芯查询";
}
private ObservableCollection<TBatteryNG> cellList;
public ObservableCollection<TBatteryNG> CellList
{
get => cellList ?? (cellList = new ObservableCollection<TBatteryNG>());
set { SetProperty(ref cellList, value); }
}
public void AsyncRefreshTask()
{
Application.Current?.Dispatcher?.Invoke(new Action(() =>
{
Refresh();
}));
}
public async override void Refresh()
{
CellList.Clear();
var listCell = await System.Threading.Tasks.Task.Run(() =>
{
//从数据库查询任务
return _unityContainer.Resolve<BatteryNGService>().GetAllNGCell();
});
listCell = ExtractJson(listCell);
listCell.ForEach(x => CellList.Add(x));
}
public DelegateCommand<object> ExportCommand => new DelegateCommand<object>((x) =>
{
if (0 == CellList.Count)
{
HandyControl.Controls.MessageBox.Warning("没有数据,导出失败!");
return;
}
Common.Core.CSVHelper.WriteMap<TBatteryNG, FailBatteryMap>(CellList);
//Common.Core.CSVHelper.WriteDataTableToCsv(CellList, new List<string> { "Id","BatteryCode", "PalletCode", "ChannelNo",
// "Desc", "CreateTime"}, new List<string> { "序号", "电芯条码", "托盘条码", "报警通道", "报警描述","报警时间"});
});
public DelegateCommand<object> QueryCommand => new DelegateCommand<object>((x) =>
{
CellList.Clear();
if ((EndDatetime - StartDatetime).TotalDays > 5)
{
HandyControl.Controls.MessageBox.Warning("查询时间差在 5 天以内!");
return;
}
List<TBatteryNG> queryCell = _unityContainer.Resolve<BatteryNGService>().QueryNGCell(StartDatetime, EndDatetime, Code); //出可以直接在数据库中查询得到 SELECT `Desc`->>'$.Info.MOMMessage' cmd FROM TBatteryNG;
queryCell = ExtractJson(queryCell);
if (0 != queryCell.Count)
{
queryCell.ForEach(item => CellList.Add(item));
Growl.Success("查询完成!");
}
else
{
Growl.Success("没有数据!");
}
});
/// <summary>
/// JSON 字符串截取
/// </summary>
/// <param name="failBatterys"></param>
/// <returns></returns>
List<TBatteryNG> ExtractJson(List<TBatteryNG> failBatterys)
{
try
{
foreach (var item in failBatterys)
{
if (!IsValidJson(item.Desc))
{
continue;
}
JObject jsonObject = JObject.Parse(item.Desc);
string keyValue = (string)jsonObject["Info"]["MOMMessage"]; //为什么加try,怕没有MOMMessage
item.Desc = keyValue; // 更新为Key的值
}
}
catch(Exception ex)
{
LogHelper.Instance.Info($"NG电芯,解析JSON失败:{ex.Message}");
}
return failBatterys;
}
bool IsValidJson(string input)
{
try
{
JsonConvert.DeserializeObject(input);
//JsonDocument.Parse(input);
return true;
}
catch
{
return false;
}
}
public DelegateCommand<object> DeleteCommand => new DelegateCommand<object>((x) =>
{
var result = HandyControl.Controls.MessageBox.Ask($@"确定删除?", "操作提示");
if (result == System.Windows.MessageBoxResult.Cancel)
{
return;
}
var t = x as TBatteryNG;
if (t != null)
{
int delCount = _unityContainer.Resolve<BatteryNGService>().Delete(t);
cellList.Remove(t);
if (delCount > 0)
{
Growl.Success("删除成功!");
}
else
{
Growl.Fatal("删除失败!");
}
}
else
{
Growl.Fatal("删除失败!");
}
});
}
}

View File

@@ -0,0 +1,133 @@
using Cowain.Bake.BLL;
using Cowain.Bake.Common;
using Cowain.Bake.Model;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Unity;
using Prism.Commands;
using System.Windows;
using HandyControl.Controls;
using Cowain.Bake.UI.CsvMap;
namespace Cowain.Bake.UI.DataQuery.ViewModels
{
public class PalletInfoViewModel:ViewModelBase
{
private DateTime _startTime = DateTime.Now.AddDays(-1);
public DateTime StartDatetime
{
get { return _startTime; }
set { SetProperty(ref _startTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); }
}
private DateTime _endTime = DateTime.Now.AddHours(1);
public DateTime EndDatetime
{
get { return _endTime; }
set { SetProperty(ref _endTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); }
}
public PalletInfoViewModel(IUnityContainer unityContainer, IRegionManager regionManager) : base(unityContainer, regionManager)
{
this.PageTitle = "托盘追踪";
}
private ObservableCollection<TPalletInfo> palletList;
public ObservableCollection<TPalletInfo> PalletList
{
get => palletList ?? (palletList = new ObservableCollection<TPalletInfo>());
set { SetProperty(ref palletList, value); }
}
List<TPalletInfo> SaveList = new List<TPalletInfo>();
public void AsyncRefreshTask()
{
Application.Current?.Dispatcher?.Invoke(new Action(() =>
{
Refresh();
}));
}
public async override void Refresh()
{
PalletList.Clear();
SaveList.Clear();
SaveList = await System.Threading.Tasks.Task.Run(() =>
{
//从数据库查询任务
return _unityContainer.Resolve<PalletInfoService>().GetAll();
});
SaveList.ForEach(x => PalletList.Add(x));
}
public DelegateCommand<object> ExportCommand => new DelegateCommand<object>((x) =>
{
if (SaveList.Count == 0)
{
HandyControl.Controls.MessageBox.Show("没有数据!");
return;
}
Common.Core.CSVHelper.WriteMap<TPalletInfo, PalletInfoMap>(SaveList);
//Common.Core.CSVHelper.WriteDataTableToCsv(SaveList, new List<string> { "Id","PalletCode", "PalletStatus",
// "BatteryQty", "BakingCount","BakingPosition", "ScanTime", "LoadingOverTime","InStoveTime","BakingBeginTime","BakingOverTime","OutStoveTime","JobNum"},
// new List<string> { "序号", "托盘条码", "托盘状态", "电芯数量", "烘烤次数", "烘烤位置", "扫码时间", "上料完成时间", "入炉时间", "开始烘烤时间", "烘烤完成时间", "出炉时间", "工单号"});
});
public DelegateCommand<object> QueryCommand => new DelegateCommand<object>((x) =>
{
PalletList.Clear();
SaveList.Clear();
if ((EndDatetime - StartDatetime).TotalDays > 30)
{
HandyControl.Controls.MessageBox.Warning("查询时间差在 30 天以内!");
return;
}
var palletInfoService = _unityContainer.Resolve<PalletInfoService>();
SaveList = palletInfoService.Query(StartDatetime, EndDatetime, Code);
if (0 != SaveList.Count)
{
SaveList.ForEach(item => PalletList.Add(item));
Growl.Success("查询完成!");
}
else
{
Growl.Success("没有数据!");
}
});
public DelegateCommand<object> DeleteCommand => new DelegateCommand<object>((x) =>
{
var result = HandyControl.Controls.MessageBox.Ask($@"确定删除?", "操作提示");
if (result == System.Windows.MessageBoxResult.Cancel)
{
return;
}
var t = x as TPalletInfo;
if (t != null)
{
int delCount = _unityContainer.Resolve<PalletInfoService>().Delete(t);
palletList.Remove(t);
if (delCount > 0)
{
Growl.Success("删除成功!");
}
else
{
Growl.Fatal("删除失败!");
}
}
else
{
Growl.Fatal("删除失败!");
}
});
}
}

View File

@@ -0,0 +1,77 @@
using Cowain.Bake.BLL;
using Cowain.Bake.Model.Entity;
using Cowain.Bake.Common;
using Cowain.Bake.Model;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;
using Prism.Commands;
using System.Windows;
using HandyControl.Controls;
using Cowain.Bake.Common.Core;
namespace Cowain.Bake.UI.DataQuery.ViewModels
{
public class ProductionsInfoViewModel:ViewModelBase
{
public ProductionsInfoViewModel(IUnityContainer unityContainer, IRegionManager regionManager) : base(unityContainer, regionManager)
{
this.PageTitle = "产量查询";
}
private ObservableCollection<OutputEntity> productionList;
public ObservableCollection<OutputEntity> ProductionList
{
get => productionList ?? (productionList = new ObservableCollection<OutputEntity>());
set { SetProperty(ref productionList, value); }
}
void ExecuteQuery()
{
List<OutputEntity> query = null;
var cellService = _unityContainer.Resolve<BatteryInfoService>();
if (5 < (EndDateTime - StartDateTime).Days)
{
Growl.Fatal("查询日期间隔不能大于5天!");
return;
}
var task = System.Threading.Tasks.Task.Factory.StartNew(() =>
{
query = cellService.GetProductionOutPut(StartDateTime, EndDateTime);
});
task.Wait();
if (null == query)
{
Growl.Fatal("查询失败,请重新查询!");
return;
}
productionList.Clear();
if (0 != query.Count)
{
query.ForEach(item => ProductionList.Add(item));
Growl.Success("查询完成!");
}
else
{
Growl.Success("没有数据!");
}
}
public DelegateCommand<object> QueryCommand => new DelegateCommand<object>((x) =>
{
ExecuteQuery();
});
}
}