2023-06-05 14:39:23 +08:00
using MECF.Framework.Common.DataCenter ;
using MECF.Framework.UI.Client.ClientBase ;
using Newtonsoft.Json ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
2023-06-09 13:15:02 +08:00
using System.Reflection ;
2023-06-09 18:31:58 +08:00
using System.Data ;
using System.Windows.Forms ;
2023-06-13 09:23:22 +08:00
using Aitex.Core.Common.DeviceData ;
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
2023-06-13 09:23:22 +08:00
[Subscription("StandardMfcRorData")]
2023-06-08 17:34:02 +08:00
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
SelectedMfcRorData = new MfcRorData ( ) ;
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 . BasePressure = 400 ;
2023-06-14 17:40:00 +08:00
SelectedMfcRorData . Volume = StandardMfcRorData ! = null ? StandardMfcRorData . Volume : 0 ;
2023-06-08 17:34:02 +08:00
2023-06-09 13:15:02 +08:00
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-14 17:40:00 +08:00
if ( StandardMfcRorData = = null & & ! SelectedMfcRorData . IsStandardMfc )
{
MessageBox . Show ( "Standard Mfc do not Ror!" ) ;
return ;
}
2023-06-27 18:24:31 +08:00
if ( SelectedMfcRorData . IsStandardMfc )
{
SelectedMfcRorData . ActualFlow = SelectedMfcRorData . SetFlow ;
}
2023-06-14 17:40:00 +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
{
2023-06-13 09:23:22 +08:00
string sql = $"select * from \" pm_mfcror \ " where \"module\" = '{SystemName}' and \"starttime\" >='{queryStartTime:yyyyMMdd HHmmss}' and \"endtime\" <='{queryEndTime:yyyyMMdd HHmmss}'" ;
2023-06-09 18:31:58 +08:00
DataTable dbData = QueryDataClient . Instance . Service . QueryData ( sql ) ;
MfcRorDataList = TableToListModel < MfcRorData > ( dbData ) ;
Refresh ( ) ;
}
catch ( Exception )
{
}
}
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
}
}