SicMultiplate/SicUI/Models/PMs/PMMfcRorViewModel.cs

187 lines
5.2 KiB
C#
Raw Normal View History

2023-06-05 14:39:23 +08:00
using MECF.Framework.Common.DataCenter;
using MECF.Framework.Common.OperationCenter;
2023-06-07 17:41:20 +08:00
using MECF.Framework.Common.Utilities;
2023-06-05 14:39:23 +08:00
using MECF.Framework.UI.Client.CenterViews.ROR;
using MECF.Framework.UI.Client.ClientBase;
using Newtonsoft.Json;
2023-06-08 17:34:02 +08:00
using SicModules.PMs.Utilities;
2023-06-05 14:39:23 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2023-06-08 17:34:02 +08:00
using static System.Net.Mime.MediaTypeNames;
using System.Windows.Controls;
using System.Reflection;
2023-06-09 18:31:58 +08:00
using MECF.Framework.UI.Client.CenterViews.DataLogs.ProcessHistory;
using SicUI.Models.PMs.Charting;
using System.Data;
using System.Windows.Forms;
2023-06-05 14:39:23 +08:00
namespace SicUI.Models.PMs
{
public class PMMfcRorViewModel : UiViewModelBase, ISupportMultipleSystem
{
2023-06-08 17:34:02 +08:00
//标准MFC
public MfcRorData StandardMfcRorData { get; set; }
//选中的MFC
public MfcRorData SelectedMfcRorData { get; set; }
2023-06-05 14:39:23 +08:00
public List<string> MfcList { get; set; }
2023-06-08 17:34:02 +08:00
2023-06-09 18:31:58 +08:00
public List<MfcRorData> MfcRorDataList { get; set; }
2023-06-05 14:39:23 +08:00
public PMMfcRorViewModel()
{
2023-06-08 17:34:02 +08:00
StandardMfcRorData = new MfcRorData();
SelectedMfcRorData = new MfcRorData();
2023-06-12 14:35:24 +08:00
QueryStandardData();
2023-06-05 14:39:23 +08:00
MfcList = new List<string>()
{
2023-06-07 17:41:20 +08:00
"Mfc1",
"Mfc2",
"Mfc3",
"Mfc4",
"Mfc6",
"Mfc7",
"Mfc8",
"Mfc9",
"Mfc10",
"Mfc11",
"Mfc12",
"Mfc13",
"Mfc14",
"Mfc15",
"Mfc16",
"Mfc19",
"Mfc20",
"Mfc22",
"Mfc23",
2023-06-05 14:39:23 +08:00
"Mfc25",
"Mfc26",
"Mfc27",
"Mfc28",
"Mfc29",
2023-06-07 17:41:20 +08:00
"Mfc31",
"Mfc32",
"Mfc33",
"Mfc35",
"Mfc36",
"Mfc37",
"Mfc38",
"Mfc38",
"Mfc40",
};
2023-06-05 14:39:23 +08:00
}
2023-06-08 17:34:02 +08:00
2023-06-05 14:39:23 +08:00
public void MfcSelectionChanged()
{
2023-06-08 17:34:02 +08:00
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.ActualFlow = SelectedMfcRorData.SetFlow;
SelectedMfcRorData.BasePressure = 400;
SelectedMfcRorData.Volume = StandardMfcRorData.Volume;
SelectedMfcRorData.Module = SystemName;
2023-06-05 14:39:23 +08:00
Refresh();
}
2023-06-08 17:34:02 +08:00
public void StartMfcRor()
2023-06-05 14:39:23 +08:00
{
2023-06-08 17:34:02 +08:00
InvokeClient.Instance.Service.DoOperation($"{SystemName}.MfcRor", JsonConvert.SerializeObject(SelectedMfcRorData));
2023-06-05 14:39:23 +08:00
}
2023-06-09 18:31:58 +08:00
2023-06-12 14:35:24 +08:00
public void QueryData(DateTime queryStartTime, DateTime queryEndTime)
2023-06-09 18:31:58 +08:00
{
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 \"starttime\" >='{queryStartTime:yyyyMMdd HHmmss}' and \"endtime\" <='{queryEndTime:yyyyMMdd HHmmss}'";
DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
MfcRorDataList = TableToListModel<MfcRorData>(dbData);
Refresh();
}
catch (Exception)
{
}
}
2023-06-12 14:35:24 +08:00
public void QueryStandardData()
{
try
{
string sql = $"select * from \"pm_mfcror\" where \"isstandardmfc\" = 't' order by \"endtime\" DESC";
DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
if(dbData != null)
{
StandardMfcRorData = TableToListModel<MfcRorData>(dbData).FirstOrDefault();
Refresh();
}
}
catch (Exception)
{
}
}
2023-06-09 18:31:58 +08:00
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;
}
2023-06-05 14:39:23 +08:00
}
}