158 lines
4.9 KiB
C#
158 lines
4.9 KiB
C#
using MECF.Framework.Common.DataCenter;
|
|
using MECF.Framework.UI.Client.ClientBase;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Data;
|
|
using System.Windows.Forms;
|
|
using Aitex.Core.Common.DeviceData;
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
using System.Windows.Media;
|
|
|
|
namespace SicUI.Models.PMs
|
|
{
|
|
public class PMMfcRorViewModel : UiViewModelBase, ISupportMultipleSystem
|
|
{
|
|
//标准MFC
|
|
[Subscription("StandardMfcRorData")]
|
|
public MfcRorData StandardMfcRorData { get; set; }
|
|
|
|
[Subscription("MfcNameList")]
|
|
public List<string> MfcNameList { get; set; }
|
|
|
|
[Subscription("MfcRorList")]
|
|
public List<MfcRorData> MfcRorList { get; set; }
|
|
|
|
//选中的MFC
|
|
public MfcRorData SelectedMfcRorData { get; set; }
|
|
|
|
public List<string> MfcList { get; set; }
|
|
|
|
|
|
|
|
public PMMfcRorViewModel()
|
|
{
|
|
SelectedMfcRorData = new MfcRorData();
|
|
}
|
|
|
|
public void MfcSelectionChanged()
|
|
{
|
|
SelectedMfcRorData.Scale = (double)QueryDataClient.Instance.Service.GetConfig($"PM.{SystemName}.MFC.{SelectedMfcRorData.Name}.N2Scale");
|
|
|
|
SelectedMfcRorData.Temperature = 293;
|
|
|
|
SelectedMfcRorData.Interval = 30;
|
|
|
|
//MFC默认的设定流量为量程的一半
|
|
SelectedMfcRorData.SetFlow = SelectedMfcRorData.Scale / 2.0;
|
|
|
|
SelectedMfcRorData.BasePressure = 400;
|
|
|
|
SelectedMfcRorData.Volume = StandardMfcRorData != null ? StandardMfcRorData.Volume : 0;
|
|
|
|
SelectedMfcRorData.Module = SystemName;
|
|
|
|
Refresh();
|
|
}
|
|
|
|
public void StartMfcRor()
|
|
{
|
|
if(StandardMfcRorData == null && !SelectedMfcRorData.IsStandardMfc)
|
|
{
|
|
MessageBox.Show("Standard Mfc do not Ror!");
|
|
return;
|
|
}
|
|
|
|
if(SelectedMfcRorData.IsStandardMfc)
|
|
{
|
|
SelectedMfcRorData.ActualFlow = SelectedMfcRorData.SetFlow;
|
|
}
|
|
|
|
InvokeClient.Instance.Service.DoOperation($"{SystemName}.MfcRor", JsonConvert.SerializeObject(SelectedMfcRorData));
|
|
}
|
|
|
|
public void QueryData(DateTime queryStartTime, DateTime queryEndTime)
|
|
{
|
|
if (queryStartTime > queryEndTime)
|
|
{
|
|
MessageBox.Show("Time range invalid, start time should be early than end time");
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
string sql = $"select * from \"pm_mfcror\" where \"module\" = '{SystemName}' and \"starttime\" >='{queryStartTime:yyyyMMdd HHmmss}' and \"endtime\" <='{queryEndTime:yyyyMMdd HHmmss}'";
|
|
|
|
DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
|
|
|
|
MfcRorList = TableToListModel<MfcRorData>(dbData);
|
|
|
|
Refresh();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 输入数值检测
|
|
/// </summary>
|
|
class ColorConverter_IsTestOK : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value == null || value.ToString().Length == 0)
|
|
return new SolidColorBrush(Colors.Gray);
|
|
if (value.ToString() == "OK")
|
|
return new SolidColorBrush(Colors.Green);
|
|
else if (value.ToString() == "NG")
|
|
return new SolidColorBrush(Colors.Red);
|
|
else
|
|
return new SolidColorBrush(Colors.Gray);
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public List<T> TableToListModel<T>(DataTable dt) where T : new()
|
|
{
|
|
// 定义集合
|
|
List<T> ts = new List<T>();
|
|
|
|
// 获得此模型的类型
|
|
Type type = typeof(T);
|
|
string tempName = "";
|
|
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
T t = new T();
|
|
// 获得此模型的公共属性
|
|
PropertyInfo[] propertys = t.GetType().GetProperties();
|
|
foreach (PropertyInfo pi in propertys)
|
|
{
|
|
tempName = pi.Name; // 检查DataTable是否包含此列
|
|
|
|
if (dt.Columns.Contains(tempName))
|
|
{
|
|
// 判断此属性是否有Setter
|
|
if (!pi.CanWrite) continue;
|
|
|
|
object value = dr[tempName];
|
|
if (value != DBNull.Value)
|
|
pi.SetValue(t, value, null);
|
|
}
|
|
}
|
|
ts.Add(t);
|
|
}
|
|
return ts;
|
|
}
|
|
}
|
|
}
|