using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.OperationCenter; 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.Util; using Aitex.Core.Common.DeviceData; namespace SicUI.Models.PMs { public class PMMfcRorViewModel : UiViewModelBase, ISupportMultipleSystem { //标准MFC [Subscription("StandardMfcRorData")] public MfcRorData StandardMfcRorData { get; set; } //选中的MFC public MfcRorData SelectedMfcRorData { get; set; } public List MfcList { get; set; } public List MfcRorDataList { get; set; } public PMMfcRorViewModel() { SelectedMfcRorData = new MfcRorData(); MfcList = new List() { "Mfc1", "Mfc2", "Mfc3", "Mfc4", "Mfc6", "Mfc7", "Mfc8", "Mfc9", "Mfc10", "Mfc11", "Mfc12", "Mfc13", "Mfc14", "Mfc15", "Mfc16", "Mfc19", "Mfc20", "Mfc22", "Mfc23", "Mfc25", "Mfc26", "Mfc27", "Mfc28", "Mfc29", "Mfc31", "Mfc32", "Mfc33", "Mfc35", "Mfc36", "Mfc37", "Mfc38", "Mfc38", "Mfc40", }; } 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.ActualFlow = SelectedMfcRorData.SetFlow; 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; } 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); MfcRorDataList = TableToListModel(dbData); Refresh(); } catch (Exception) { } } public List TableToListModel(DataTable dt) where T : new() { // 定义集合 List ts = new List(); // 获得此模型的类型 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; } } }