using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.OperationCenter; using MECF.Framework.Common.Utilities; using MECF.Framework.UI.Client.CenterViews.ROR; using MECF.Framework.UI.Client.ClientBase; using Newtonsoft.Json; using SicModules.PMs.Utilities; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Net.Mime.MediaTypeNames; using System.Windows.Controls; using System.Reflection; using MECF.Framework.UI.Client.CenterViews.DataLogs.ProcessHistory; using SicUI.Models.PMs.Charting; using System.Data; using System.Windows.Forms; namespace SicUI.Models.PMs { public class PMMfcRorViewModel : UiViewModelBase, ISupportMultipleSystem { //标准MFC public MfcRorData StandardMfcRorData { get; set; } //选中的MFC public MfcRorData SelectedMfcRorData { get; set; } public List MfcList { get; set; } public List MfcRorDataList { get; set; } public PMMfcRorViewModel() { StandardMfcRorData = new MfcRorData(); 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.Volume; SelectedMfcRorData.Module = SystemName; Refresh(); } public void StartMfcRor() { InvokeClient.Instance.Service.DoOperation($"{SystemName}.MfcRor", JsonConvert.SerializeObject(SelectedMfcRorData)); } public void Query(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 \"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; } } }