using Admin.Core.Common; using Admin.Core.IService; using Admin.Core.Model; using Admin.Core.Model.ViewModels; using Admin.Core.Service; using Admin.Core.Tasks; using Aucma.Core.DoorFoam.Business; using Aucma.Core.DoorFoam.Models; using CommunityToolkit.Mvvm.ComponentModel; using log4net; using Microsoft.Extensions.DependencyInjection; using Microsoft.IdentityModel.Logging; using StackExchange.Profiling.Internal; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Aucma.Core.DoorFoam.ViewModels { public partial class FoamMachinesPageViewModel : ObservableObject { IBoxLastShotRecordServices _boxLastShotRecordServices; private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(FoamMachinesPageViewModel)); public FoamMachinesPageViewModel() { CollectionFoamMachine.RefreshLastShotDataDelegateEvent += RefreshData; CollectionFoamMachine.RefreshGunDataDelegateEvent += RefreshGunData; CollectionFoamMachine.RefreshSystemDataDelegateEvent += RefreshSystemData; _boxLastShotRecordServices = App.ServiceProvider.GetService(); LoadData(); //Task.WaitAll(LoadData()); } #region 刷新系统参数---系统1,系统2 /// /// 系统1,系统2数据刷新 /// public void RefreshSystemData(Dictionary keys) { foreach (KeyValuePair kvp in keys) { if (kvp.Key.Equals("1")) { RefreshSystem1(kvp.Value); } else if (kvp.Key.Equals("2")) { RefreshSystem2(kvp.Value); } } } /// /// 刷新系统1 /// /// public void RefreshSystem1(FoamMachinesModel record) { PolInputPressure1 = record.POL_LP; IsoInputPressure1 = record.ISO_LP; PolOutputPressure1 = record.POL_HP; IsoOutputPressure1 = record.ISO_HP; PolFlow1 = record.POL_Vol; IsoFlow1 = record.ISO_Vol; PoleTmperature1 = record.POL_Temp; IsoTemperature1 = record.ISO_Temp; PolMaterialLevel1 = record.POL_Level; IsoMaterialLevel1 = record.ISO_Level; Pressure1 = record.Hydr_Press; Temperature1 = record.Hydr_Temp; } /// /// 刷新系统2 /// /// public void RefreshSystem2(FoamMachinesModel record) { PolInputPressure2 = record.POL_LP; IsoInputPressure2 = record.ISO_LP; PolOutputPressure2 = record.POL_HP; IsoOutputPressure2 = record.ISO_HP; PolFlow2 = record.POL_Vol; IsoFlow2 = record.ISO_Vol; PoleTmperature2 = record.POL_Temp; IsoTemperature2 = record.ISO_Temp; PolMaterialLevel2 = record.POL_Level; IsoMaterialLevel2 = record.ISO_Level; Pressure2 = record.Hydr_Press; Temperature2 = record.Hydr_Temp; } #endregion #region 刷新每一枪数据 /// /// A1,B1,A2,B2枪数据刷新 /// public void RefreshGunData(Dictionary keys) { foreach (KeyValuePair kvp in keys) { if (kvp.Key.Equals("A1")) { RefreshA1(kvp.Value); } else if (kvp.Key.Equals("B1")) { RefreshB1(kvp.Value); } else if (kvp.Key.Equals("A2")) { RefreshA2(kvp.Value); } else if (kvp.Key.Equals("B2")) { RefreshB2(kvp.Value); } } } /// /// 刷新A1数据 /// /// public void RefreshA1(BoxLastShotRecord record) { POLPressure1a = record.PolHp; POLTemperature1a = record.PolTemp; ISOPressure1a = record.IsoHp; ISOTemperature1a = record.IsoTemp; } /// /// 刷新B1数据 /// /// public void RefreshB1(BoxLastShotRecord record) { POLPressure1b = record.PolHp; POLTemperature1b = record.PolTemp; ISOPressure1b = record.IsoHp; ISOTemperature1b = record.IsoTemp; } /// /// 刷新A2数据 /// /// public void RefreshA2(BoxLastShotRecord record) { POLPressure2a = record.PolHp; POLTemperature2a = record.PolTemp; ISOPressure2a = record.IsoHp; ISOTemperature2a = record.IsoTemp; } /// /// 刷新B2数据 /// /// public void RefreshB2(BoxLastShotRecord record) { POLPressure2b = record.PolHp; POLTemperature2b = record.PolTemp; ISOPressure2b = record.IsoHp; ISOTemperature2b = record.IsoTemp; } #endregion /// /// datagrid刷新 /// /// public void RefreshData(BoxLastShotRecord record) { System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => { string system = string.Empty; if (record.System == "1") { system = "1系统"; // PolFlow1 = record.POLInjecFlowRate; // IsoFlow1 = record.ISOInjecFlowRate; // PoleTmperature1 = record.POLInjecTemperatureOfGunHead; // IsoTemperature1 = record.ISOInjecTemperatureOfGunHead; } if (record.System == "2") { system = "2系统"; } LastShotRecordModel model = new LastShotRecordModel(); model.No = LastShotRecordDataGrid.Count + 1; model.System = system; model.GunHead = record.GunCode; // StationNumber = record.StationNumber, model.IsoInjectionpressure = record.PolHp; model.IsoInjectionpressure = record.IsoHp; model.PolInjectiontemperature = record.PolTemp; model.IsoInjectiontemperature = record.IsoTemp; model.PolInjectionpressure = record.PolHp; model.StationNumber = record.PourNu; model.LastTime = record.CreateTime; model.Createtime = record.CreateTime; LastShotRecordDataGrid.Insert(0, model); })); } #region 加载DataGrid数据 private void LoadData() { try { var list = _boxLastShotRecordServices.QueryAsync(x => x.StationNumber == "1020").Result.OrderBy(d => d.CreateTime).Take(10); if (list == null) return; System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => { LastShotRecordDataGrid.Clear(); // var list = await _boxLastShotRecordServices.QueryAsync(); // list.OrderByDescending(d => d.CreateTime).Take(30); foreach (var item in list) { string system = string.Empty; if (item.System == "1") { system = "1系统"; } if (item.System == "2") { system = "2系统"; } LastShotRecordModel model = new LastShotRecordModel(); model.No = LastShotRecordDataGrid.Count() + 1; model.System = system; model.GunHead = item.GunCode; model.PolInjectionpressure = item.PolHp; model.IsoInjectionpressure = item.IsoHp; model.PolInjectiontemperature = item.PolTemp; model.IsoInjectiontemperature = item.IsoTemp; model.LastTime = item.CreateTime; model.Createtime = item.CreateTime; model.StationNumber = item.PourNu; LastShotRecordDataGrid.Insert(0, model); } })); } catch (Exception ex) { logHelper.Info(ex.Message.ToString()); } } #endregion #region 初始化datagrid private ObservableCollection _lastShotRecordDataGrid = new ObservableCollection(); public ObservableCollection LastShotRecordDataGrid { get { return _lastShotRecordDataGrid; } set { _lastShotRecordDataGrid = value; OnPropertyChanged();//属性通知 } } #endregion #region 1系统属性 /// /// POL输入压力 /// private string _PolInputPressure = "0.00"; public string PolInputPressure1 { get => _PolInputPressure; set => SetProperty(ref _PolInputPressure, value); } /// /// ISO输入压力 /// private string _IsoInputPressure = "0.00"; public string IsoInputPressure1 { get => _IsoInputPressure; set => SetProperty(ref _IsoInputPressure, value); } /// /// POL输出压力 /// private string _polOutputPressure = "0.0"; public string PolOutputPressure1 { get => _polOutputPressure; set => SetProperty(ref _polOutputPressure, value); } /// /// ISO输出压力 /// private string _isoOutputPressure1 = "0.0"; public string IsoOutputPressure1 { get => _isoOutputPressure1; set => SetProperty(ref _isoOutputPressure1, value); } /// /// Pol流量 /// private string _Polflow1 = "0"; public string PolFlow1 { get => _Polflow1; set => SetProperty(ref _Polflow1, value); } /// /// Iso流量 /// private string _isoflow1 = "0"; public string IsoFlow1 { get => _isoflow1; set => SetProperty(ref _isoflow1, value); } /// /// Pol温度 /// private string _PoleTmperature = "0"; public string PoleTmperature1 { get => _PoleTmperature; set => SetProperty(ref _PoleTmperature, value); } /// /// Iso温度 /// private string _isoTemperature = "0"; public string IsoTemperature1 { get => _isoTemperature; set => SetProperty(ref _isoTemperature, value); } /// /// 料位 /// private string _PolMaterialLevel1 = "0"; public string PolMaterialLevel1 { get => _PolMaterialLevel1; set => SetProperty(ref _PolMaterialLevel1, value); } /// /// Iso温度 /// private string _IsoMaterialLevel1 = "0"; public string IsoMaterialLevel1 { get => _IsoMaterialLevel1; set => SetProperty(ref _IsoMaterialLevel1, value); } /// /// 压力 /// private string _pressure1 = "0.00"; public string Pressure1 { get => _pressure1; set => SetProperty(ref _pressure1, value); } /// /// 温度 /// private string _temperature1 = "0.00"; public string Temperature1 { get => _temperature1; set => SetProperty(ref _temperature1, value); } /// /// A枪状态 /// //private string _status1a; //public string Status1a //{ // get => _status1a; // set => SetProperty(ref _status1a, value); //} /// /// pol压力 /// private string _POLPressure1a = "0.00"; public string POLPressure1a { get => _POLPressure1a; set => SetProperty(ref _POLPressure1a, value); } /// /// A枪POL温度 /// private string _POLTemperature1a = "0.00"; public string POLTemperature1a { get => _POLTemperature1a; set => SetProperty(ref _POLTemperature1a, value); } /// /// iso压力 /// private string _ISOPressure1a = "0.00"; public string ISOPressure1a { get => _ISOPressure1a; set => SetProperty(ref _ISOPressure1a, value); } /// /// iso温度 /// private string _ISOTemperature1a = "0.0"; public string ISOTemperature1a { get => _ISOTemperature1a; set => SetProperty(ref _ISOTemperature1a, value); } /// /// B枪状态 /// //private string _status1b; //public string Status1b //{ // get => _status1b; // set => SetProperty(ref _status1b, value); //} /// /// B枪pol压力 /// private string _POLPressure1b = "0.00"; public string POLPressure1b { get => _POLPressure1b; set => SetProperty(ref _POLPressure1b, value); } /// /// B枪POL温度 /// private string _POLTemperature1b = "0.00"; public string POLTemperature1b { get => _POLTemperature1b; set => SetProperty(ref _POLTemperature1b, value); } /// /// B枪iso压力 /// private string _ISOPressure1b = "0.00"; public string ISOPressure1b { get => _ISOPressure1b; set => SetProperty(ref _ISOPressure1b, value); } /// /// B枪iso温度 /// private string _ISOTemperature1b = "0.0"; public string ISOTemperature1b { get => _ISOTemperature1b; set => SetProperty(ref _ISOTemperature1b, value); } #endregion #region 2系统属性 /// /// POL输入压力 /// private string _PolInputPressure2 = "0.00"; public string PolInputPressure2 { get => _PolInputPressure2; set => SetProperty(ref _PolInputPressure2, value); } /// /// ISO输入压力 /// private string _IsoInputPressure2 = "0.00"; public string IsoInputPressure2 { get => _IsoInputPressure2; set => SetProperty(ref _IsoInputPressure2, value); } /// /// POL输出压力 /// private string _polOutputPressure2 = "0.00"; public string PolOutputPressure2 { get => _polOutputPressure2; set => SetProperty(ref _polOutputPressure2, value); } /// /// ISO输出压力 /// private string _isoOutputPressure2 = "0.00"; public string IsoOutputPressure2 { get => _isoOutputPressure2; set => SetProperty(ref _isoOutputPressure2, value); } /// /// Pol流量 /// private string _Polflow2 = "0"; public string PolFlow2 { get => _Polflow2; set => SetProperty(ref _Polflow2, value); } /// /// Iso流量 /// private string _isoflow2 = "0"; public string IsoFlow2 { get => _isoflow2; set => SetProperty(ref _isoflow2, value); } /// /// Pol温度 /// private string _PoleTmperature2 = "0"; public string PoleTmperature2 { get => _PoleTmperature2; set => SetProperty(ref _PoleTmperature2, value); } /// /// Iso温度 /// private string _isoTemperature2 = "0"; public string IsoTemperature2 { get => _isoTemperature2; set => SetProperty(ref _isoTemperature2, value); } /// /// 料位 /// private string _PolMaterialLevel2 = "0"; public string PolMaterialLevel2 { get => _PolMaterialLevel2; set => SetProperty(ref _PolMaterialLevel2, value); } /// /// Iso温度 /// private string _IsoMaterialLevel2 = "0"; public string IsoMaterialLevel2 { get => _IsoMaterialLevel2; set => SetProperty(ref _IsoMaterialLevel2, value); } /// /// 压力 /// private string _pressure2 = "0.00"; public string Pressure2 { get => _pressure2; set => SetProperty(ref _pressure2, value); } /// /// 温度 /// private string _temperature2 = "0.00"; public string Temperature2 { get => _temperature2; set => SetProperty(ref _temperature2, value); } /// /// A枪POL压力 /// private string _POLPressure2a = "0.00"; public string POLPressure2a { get => _POLPressure2a; set => SetProperty(ref _POLPressure2a, value); } /// /// A枪POL温度 /// private string _POLTemperature2a = "0.00"; public string POLTemperature2a { get => _POLTemperature2a; set => SetProperty(ref _POLTemperature2a, value); } /// /// iso压力 /// private string _ISOPressure2a = "0.00"; public string ISOPressure2a { get => _ISOPressure2a; set => SetProperty(ref _ISOPressure2a, value); } /// /// iso温度 /// private string _ISOTemperature2a = "0.0"; public string ISOTemperature2a { get => _ISOTemperature2a; set => SetProperty(ref _ISOTemperature2a, value); } /// /// B枪状态 /// //private string _status2b; //public string Status2b //{ // get => _status2b; // set => SetProperty(ref _status2b, value); //} /// /// B枪pol压力 /// private string _POLPressure2b = "0.00"; public string POLPressure2b { get => _POLPressure2b; set => SetProperty(ref _POLPressure2b, value); } /// /// B枪POL温度 /// private string _POLTemperature2b = "0.00"; public string POLTemperature2b { get => _POLTemperature2b; set => SetProperty(ref _POLTemperature2b, value); } /// /// B枪iso压力 /// private string _ISOPressure2b = "0.00"; public string ISOPressure2b { get => _ISOPressure2b; set => SetProperty(ref _ISOPressure2b, value); } /// /// B枪iso温度 /// private string _ISOTemperature2b = "0.0"; public string ISOTemperature2b { get => _ISOTemperature2b; set => SetProperty(ref _ISOTemperature2b, value); } #endregion } }