275 lines
9.2 KiB
C#
275 lines
9.2 KiB
C#
using Aitex.Core.RT.DataCenter;
|
||
using Aitex.Core.RT.SCCore;
|
||
using Aitex.Core.Util;
|
||
using Caliburn.Micro;
|
||
using MECF.Framework.Common.Aitex.Core.Common.DeviceData;
|
||
using MECF.Framework.Common.DataCenter;
|
||
using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.PMs;
|
||
using MECF.Framework.UI.Client.CenterViews.Core;
|
||
using MECF.Framework.UI.Client.ClientBase;
|
||
using SciChart.Charting.Model.DataSeries;
|
||
using SciChart.Charting.Visuals.Axes;
|
||
using SciChart.Charting.Visuals.RenderableSeries;
|
||
using SciChart.Data.Model;
|
||
using Sicentury.Core;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using System.Dynamic;
|
||
using System.Threading;
|
||
using System.Windows;
|
||
using System.Windows.Controls;
|
||
|
||
namespace MECF.Framework.UI.Client.CenterViews.DataLogs.ProcessHistory
|
||
{
|
||
public class ProcessHistoryTestViewModel : UiViewModelBase
|
||
{
|
||
#region Variables
|
||
|
||
private IRange _timeRange;
|
||
private IRange _visibleRangeValue;
|
||
private AutoRange _autoRange;
|
||
private List<ProcessDeviceItem> PMItemList { get; set; }
|
||
|
||
/// <summary>
|
||
/// 返回ViewModel绑定的视图对象。
|
||
/// </summary>
|
||
public UserControl View { get; private set; }
|
||
|
||
public DateTime StartDateTime
|
||
{
|
||
get => ((ProcessHistoryTestView)View).wfTimeFrom.Value;
|
||
set
|
||
{
|
||
((ProcessHistoryTestView)View).wfTimeFrom.Value = value;
|
||
NotifyOfPropertyChange(nameof(StartDateTime));
|
||
}
|
||
}
|
||
|
||
public DateTime EndDateTime
|
||
{
|
||
get => ((ProcessHistoryTestView)View).wfTimeTo.Value;
|
||
set
|
||
{
|
||
((ProcessHistoryTestView)View).wfTimeTo.Value = value;
|
||
NotifyOfPropertyChange(nameof(EndDateTime));
|
||
}
|
||
}
|
||
|
||
public List<string> PmList { get; set; }
|
||
|
||
private string cbSelectPM;
|
||
|
||
public string CbSelectPM
|
||
{
|
||
get => cbSelectPM;
|
||
set
|
||
{
|
||
cbSelectPM = value;
|
||
PMItemList = (List<ProcessDeviceItem>)QueryDataClient.Instance.Service.GetData($"{cbSelectPM}.ProcessHistoryItemsDefault");//选择的PM变化时,重新加载模板
|
||
}
|
||
}
|
||
|
||
public RecipeProcessHistoryData RecipeProcessHistoryData { get; set; }
|
||
|
||
private ObservableCollection<ProcessHistoryData> processHistoryDataList;
|
||
|
||
public ObservableCollection<ProcessHistoryData> ProcessHistoryDataList
|
||
{
|
||
get => processHistoryDataList;
|
||
set
|
||
{
|
||
processHistoryDataList = value;
|
||
NotifyOfPropertyChange(nameof(ProcessHistoryDataList));
|
||
}
|
||
}
|
||
|
||
public ProcessHistoryData SelectProcessHistoryData { get; set; }
|
||
|
||
private ObservableCollection<ProcessHistoryDeviceData> processHistoryDeviceDataList;
|
||
|
||
public ObservableCollection<ProcessHistoryDeviceData> ProcessHistoryDeviceDataList
|
||
{
|
||
get => processHistoryDeviceDataList;
|
||
set
|
||
{
|
||
processHistoryDeviceDataList = value;
|
||
NotifyOfPropertyChange(nameof(ProcessHistoryDeviceDataList));
|
||
}
|
||
}
|
||
|
||
public ProcessHistoryDeviceData SelectProcessHistoryDeviceData { get; set; }
|
||
|
||
private ObservableCollection<IRenderableSeries> appendedSeries;
|
||
|
||
public ObservableCollection<IRenderableSeries> AppendedSeries
|
||
{
|
||
get => appendedSeries;
|
||
set
|
||
{
|
||
appendedSeries = value;
|
||
NotifyOfPropertyChange(nameof(AppendedSeries));
|
||
}
|
||
}
|
||
|
||
public IRange VisibleRangeTime
|
||
{
|
||
get => _timeRange;
|
||
set
|
||
{
|
||
_timeRange = value;
|
||
NotifyOfPropertyChange(nameof(VisibleRangeTime));
|
||
}
|
||
}
|
||
|
||
public IRange VisibleRangeValue
|
||
{
|
||
get => _visibleRangeValue;
|
||
set
|
||
{
|
||
_visibleRangeValue = value;
|
||
NotifyOfPropertyChange(nameof(VisibleRangeValue));
|
||
}
|
||
}
|
||
|
||
public AutoRange ChartAutoRange
|
||
{
|
||
get => _autoRange;
|
||
set
|
||
{
|
||
_autoRange = value;
|
||
NotifyOfPropertyChange(nameof(ChartAutoRange));
|
||
}
|
||
}
|
||
|
||
#endregion Variables
|
||
|
||
protected override void OnViewLoaded(object _view)
|
||
{
|
||
base.OnViewLoaded(_view);
|
||
View = (ProcessHistoryTestView)_view;
|
||
IniUIData();
|
||
}
|
||
|
||
private void IniUIData()
|
||
{
|
||
PmList = new List<string>();
|
||
for (int i = 1; i <= 2; i++)
|
||
{
|
||
if ((bool)QueryDataClient.Instance.Service.GetConfig($"System.SetUp.IsPM{i}Installed"))
|
||
PmList.Add($"PM{i}");
|
||
}
|
||
if (PmList.Count > 0)
|
||
CbSelectPM = PmList[0];
|
||
StartDateTime = DateTime.Now.Date;
|
||
EndDateTime = DateTime.Now.Date.AddDays(1).AddTicks(-1);
|
||
|
||
VisibleRangeTime = new DateRange(DateTime.Now.AddMinutes(-60), DateTime.Now.AddMinutes(60));
|
||
VisibleRangeValue = new DoubleRange(0, 10);
|
||
|
||
Refresh();
|
||
}
|
||
|
||
protected override void OnDeactivate(bool close)
|
||
{
|
||
ActiveUpdateData = true;
|
||
base.OnDeactivate(close);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据时间段查询Recipe生产的历史记录
|
||
/// </summary>
|
||
public void QueryRecipeProcessHistory()
|
||
{
|
||
if (StartDateTime > EndDateTime)
|
||
{
|
||
MessageBox.Show("time range invalid, start time should be early than end time.", "Error",
|
||
MessageBoxButton.OK,
|
||
MessageBoxImage.Error);
|
||
return;
|
||
}
|
||
|
||
var dialog = new ProcessHistoryInfMessageBoxViewModel(StartDateTime.ToString("yyyy-MM-dd HH:mm:ss"), EndDateTime.ToString("yyyy-MM-dd HH:mm:ss"), CbSelectPM);
|
||
var wm = new WindowManager();
|
||
|
||
dynamic settings = new ExpandoObject();
|
||
settings.WindowStartupLocation = WindowStartupLocation.CenterOwner;
|
||
settings.Title = "Recipe历史生产数据选择";
|
||
settings.ResizeMode = ResizeMode.NoResize;
|
||
settings.ShowInTaskbar = false;
|
||
|
||
var bret = wm.ShowDialog(dialog, null, settings);
|
||
if ((bool)bret)
|
||
{
|
||
if (dialog.RecipeProcessHistoryData == null)
|
||
return;
|
||
|
||
RecipeProcessHistoryData = dialog.RecipeProcessHistoryData;
|
||
ProcessHistoryDataList = ProcessHistorySqlHelp.QueryProcessHistoryData(dialog.RecipeProcessHistoryData.ProcessGuid, dialog.RecipeProcessHistoryData.Name, dialog.StepModel);
|
||
ProcessHistoryDeviceDataList?.Clear();
|
||
AppendedSeries?.Clear();
|
||
Refresh();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 选择Recipe后,自动查询当时记录的Step详情
|
||
/// </summary>
|
||
public void GetProcessHistory()
|
||
{
|
||
if (SelectProcessHistoryData == null)
|
||
return;
|
||
QueryProcessHistory(SelectProcessHistoryData);
|
||
|
||
Refresh();
|
||
}
|
||
|
||
public void QueryProcessHistory(ProcessHistoryData processHistoryData)
|
||
{
|
||
var daySlices = DateRangeHelper.SplitInToHours(new DateRangeHelper(Convert.ToDateTime(processHistoryData.StepBeginTime), Convert.ToDateTime(processHistoryData.StepEndTime)), 12);
|
||
List<List<GasFlowSum>> gasFlowRunVent = new List<List<GasFlowSum>>();
|
||
|
||
//按天查询数据库,单天返回数据类型为List<GasFlowSum>
|
||
ProcessHistoryDeviceDataList = ProcessHistorySqlHelp.GetProcessHistoryDeviceData(daySlices, CbSelectPM, PMItemList);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 显示Charting历史数据记录
|
||
/// </summary>
|
||
public void DeviceCharting()
|
||
{
|
||
if (SelectProcessHistoryDeviceData == null)
|
||
return;
|
||
GetDeviceCharting();
|
||
}
|
||
|
||
private void GetDeviceCharting()
|
||
{
|
||
RenderableSeriesProvide renderableSeries = new RenderableSeriesProvide();
|
||
AppendedSeries = new ObservableCollection<IRenderableSeries> {renderableSeries.GetLineSeries(SelectProcessHistoryDeviceData.DeviceName)};
|
||
|
||
var dataSeries = AppendedSeries[0].DataSeries as XyDataSeries<DateTime, double>;
|
||
var dateList = new List<DateTime>();
|
||
var valueList = new List<double>();
|
||
var metaList = new List<ParameterNodePoint>();
|
||
|
||
// 数据记录点
|
||
for (int i = 0; i < SelectProcessHistoryDeviceData.DeviceValue.Count; i++)
|
||
{
|
||
var date = new DateTime(long.Parse(SelectProcessHistoryDeviceData.TimeStamp[i]));
|
||
var cellValue = SelectProcessHistoryDeviceData.DeviceValue[i];
|
||
|
||
dateList.Add(date);
|
||
valueList.Add(cellValue);
|
||
metaList.Add(new ParameterNodePoint(date, cellValue));
|
||
}
|
||
dataSeries.Append(dateList, valueList, metaList);
|
||
|
||
Thread.Sleep(10);
|
||
ChartAutoRange = AutoRange.Never;
|
||
((ProcessHistoryTestView)View).chart.ZoomExtents();
|
||
}
|
||
|
||
|
||
}
|
||
} |