using System; using System.Collections.Generic; using System.Linq; using Aitex.Core.Util; using Aitex.Core.Common.DeviceData; using System.Text; using System.Threading.Tasks; using System.Windows; using FurnaceUI.Models; using Caliburn.Micro; using Caliburn.Micro.Core; using System.Windows.Controls; using MECF.Framework.UI.Client.CenterViews.Dialogs; using FurnaceUI.Views.Editors; using OpenSEMI.ClientBase; using MECF.Framework.Common.OperationCenter; using FurnaceUI.Client; using MECF.Framework.Common.DataCenter; namespace FurnaceUI.Views.Operations { public class TemperatureDetailViewModel : FurnaceUIViewModelBase { public bool IsManagerPermission { get; set; } = false; public bool IsLspMode { get; set; } = false; [Subscription("System.Heater1.DeviceData")] public AITHeaterData Heater1Data { get; set; } [Subscription("System.Heater2.DeviceData")] public AITHeaterData Heater2Data { get; set; } [Subscription("System.Heater3.DeviceData")] public AITHeaterData Heater3Data { get; set; } [Subscription("System.Heater4.DeviceData")] public AITHeaterData Heater4Data { get; set; } [Subscription("System.Heater5.DeviceData")] public AITHeaterData Heater5Data { get; set; } [Subscription("PM1.BottomHeaterData")] public AITHeaterData BottomHeaterData { get; set; } [Subscription("PM1.CenterBottomHeaterData")] public AITHeaterData CenterBottomHeaterData { get; set; } [Subscription("PM1.CenterHeaterData")] public AITHeaterData CenterHeaterData { get; set; } [Subscription("PM1.TopCenterHeaterData")] public AITHeaterData TopCenterHeaterData { get; set; } [Subscription("PM1.TopHeaterData")] public AITHeaterData TopHeaterData { get; set; } [Subscription("PM1.Status")] public string PM1Status { get; set; } [Subscription("PM1.RecipeHold")] public bool PM1RecipeHold { get; set; } public bool IsMannualButtonEnabled { get { return PM1Status != "Process" || (PM1Status == "Process" && PM1RecipeHold); } } #region AnaLog [Subscription("PM1.HTCurrent1.DeviceData")] public AITWaterFlowMeterData HTCurrent1 { get; set; } [Subscription("PM1.HTCurrent2.DeviceData")] public AITWaterFlowMeterData HTCurrent2 { get; set; } [Subscription("PM1.HTCurrent3.DeviceData")] public AITWaterFlowMeterData HTCurrent3 { get; set; } [Subscription("PM1.HTCurrent4.DeviceData")] public AITWaterFlowMeterData HTCurrent4 { get; set; } [Subscription("PM1.HTCurrent5.DeviceData")] public AITWaterFlowMeterData HTCurrent5 { get; set; } [Subscription("PM1.HTVoltage1.DeviceData")] public AITWaterFlowMeterData HTVoltage1 { get; set; } [Subscription("PM1.HTVoltage2.DeviceData")] public AITWaterFlowMeterData HTVoltage2 { get; set; } [Subscription("PM1.HTVoltage3.DeviceData")] public AITWaterFlowMeterData HTVoltage3 { get; set; } [Subscription("PM1.HTVoltage4.DeviceData")] public AITWaterFlowMeterData HTVoltage4 { get; set; } [Subscription("PM1.HTVoltage5.DeviceData")] public AITWaterFlowMeterData HTVoltage5 { get; set; } public string HTCurrent1Feedback { get; set; } public string HTCurrent2Feedback { get; set; } public string HTCurrent3Feedback { get; set; } public string HTCurrent4Feedback { get; set; } public string HTCurrent5Feedback { get; set; } public string HTVoltage1Feedback { get; set; } public string HTVoltage2Feedback { get; set; } public string HTVoltage3Feedback { get; set; } public string HTVoltage4Feedback { get; set; } public string HTVoltage5Feedback { get; set; } #endregion public Dictionary _dicTemperatualMaxValue; private string _topHeaterSetPoint; public string TopHeaterSetPoint { get { return _topHeaterSetPoint; } set { _topHeaterSetPoint = value; NotifyOfPropertyChange("TopHeaterSetPoint"); } } private string _topCenterHeaterSetPoint; public string TopCenterHeaterSetPoint { get { return _topCenterHeaterSetPoint; } set { _topCenterHeaterSetPoint = value; NotifyOfPropertyChange("TopCenterHeaterSetPoint"); } } private string _centerHeaterSetPoint; public string CenterHeaterSetPoint { get { return _centerHeaterSetPoint; } set { _centerHeaterSetPoint = value; NotifyOfPropertyChange("CenterHeaterSetPoint"); } } private string _centerBottomHeaterSetPoint; public string CenterBottomHeaterSetPoint { get { return _centerBottomHeaterSetPoint; } set { _centerBottomHeaterSetPoint = value; NotifyOfPropertyChange("CenterBottomHeaterSetPoint"); } } private string _bottomHeaterSetPoint; public string BottomHeaterSetPoint { get { return _bottomHeaterSetPoint; } set { _bottomHeaterSetPoint = value; NotifyOfPropertyChange("BottomHeaterSetPoint"); } } private bool _isEnableMannual = false; public bool IsEnableMannual { get => _isEnableMannual; set { _isEnableMannual = value; NotifyOfPropertyChange(nameof(IsEnableMannual)); } } private int _mannualSelectCount; private string _lspModel; public string LspModel { get => _lspModel; set { _lspModel = value; NotifyOfPropertyChange(nameof(LspModel)); } } private string _topHeaterRampSetPoint; public string TopHeaterRampSetPoint { get => _topHeaterRampSetPoint; set { _topHeaterRampSetPoint = value; NotifyOfPropertyChange(nameof(TopHeaterRampSetPoint)); } } private string _topCenterHeaterRampSetPoint; public string TopCenterHeaterRampSetPoint { get => _topCenterHeaterRampSetPoint; set { _topCenterHeaterRampSetPoint = value; NotifyOfPropertyChange(nameof(TopCenterHeaterRampSetPoint)); } } private string _centerHeaterRampSetPoint; public string CenterHeaterRampSetPoint { get => _centerHeaterRampSetPoint; set { _centerHeaterRampSetPoint = value; NotifyOfPropertyChange(nameof(CenterHeaterRampSetPoint)); } } private string _bottomCenterHeaterRampSetPoint; public string BottomCenterHeaterRampSetPoint { get => _bottomCenterHeaterRampSetPoint; set { _bottomCenterHeaterRampSetPoint = value; NotifyOfPropertyChange(nameof(BottomCenterHeaterRampSetPoint)); } } private string _bottomHeaterRampSetPoint; public string BottomHeaterRampSetPoint { get => _bottomHeaterRampSetPoint; set { _bottomHeaterRampSetPoint = value; NotifyOfPropertyChange(nameof(BottomHeaterRampSetPoint)); } } //public string ProfileTable //{ // get // { // return (string.IsNullOrEmpty(Heater2Data.ProfileTable) || Heater2Data.ProfileTable == "None") ? "None" : Heater2Data.ProfileTable; // } //} protected override void InvokeAfterUpdateProperty(Dictionary data) { if (!IsEnableMannual) { //LspModel= Heater2Data.IsLspModeFeedBack ? "Outer Control" : "Inner Control"; //InitSetPoint(); //InitRampRate(); } } public void InitSetPoint() { TopHeaterSetPoint = TopHeaterData.SetPoint.ToString("F1"); TopCenterHeaterSetPoint = TopCenterHeaterData.SetPoint.ToString("F1"); CenterHeaterSetPoint = CenterHeaterData.SetPoint.ToString("F1"); CenterBottomHeaterSetPoint = CenterBottomHeaterData.SetPoint.ToString("F1"); BottomHeaterSetPoint = BottomHeaterData.SetPoint.ToString("F1"); HTCurrent1Feedback = HTCurrent1?.FeedBack.ToString("F3"); HTCurrent2Feedback = HTCurrent2?.FeedBack.ToString("F3"); HTCurrent3Feedback = HTCurrent3?.FeedBack.ToString("F3"); HTCurrent4Feedback = HTCurrent4?.FeedBack.ToString("F3"); HTCurrent5Feedback = HTCurrent5?.FeedBack.ToString("F3"); HTVoltage1Feedback = HTVoltage1?.FeedBack.ToString("F3"); HTVoltage2Feedback = HTVoltage2?.FeedBack.ToString("F3"); HTVoltage3Feedback = HTVoltage3?.FeedBack.ToString("F3"); HTVoltage4Feedback = HTVoltage4?.FeedBack.ToString("F3"); HTVoltage5Feedback = HTVoltage5?.FeedBack.ToString("F3"); } public void InitRampRate() { TopHeaterRampSetPoint = CompterRampPoint(TopHeaterData).ToString("F1"); TopCenterHeaterRampSetPoint = CompterRampPoint(TopCenterHeaterData).ToString("F1"); CenterHeaterRampSetPoint = CompterRampPoint(CenterHeaterData).ToString("F1"); BottomCenterHeaterRampSetPoint = CompterRampPoint(CenterBottomHeaterData).ToString("F1"); BottomHeaterRampSetPoint = CompterRampPoint(BottomHeaterData).ToString("F1"); } protected override void OnInitialize() { base.OnInitialize(); string[] strTempsNames = { "Heater1", "Heater3", "Heater5", "Heater7", "Heater9", "Heater2", "Heater4", "Heater6", "Heater8", "Heater10" }; _dicTemperatualMaxValue = new Dictionary(); //获取温度限制配置信息 for (int i = 0; i < strTempsNames.Length; i++) { object obj = QueryDataClient.Instance.Service.GetConfig($"PM1.Heater.{strTempsNames[i]}.Range"); _dicTemperatualMaxValue.Add(strTempsNames[i],Convert.ToDouble(obj)); } } public void MannualSelectCmd() { _mannualSelectCount++; if (_mannualSelectCount == 1) { IsEnableMannual = true; } else { _mannualSelectCount = 0; IsEnableMannual = false; } } public double CompterRampPoint(AITHeaterData data) { if(data.IsLspModeFeedBack) { return data.FeedBack >= data.SetPoint ? data.LspDecreaseRampRateFeedBack : data.LspIncreaseRampRateFeedBack; } else { return data.FeedBack >= data.SetPoint ? data.RspDecreaseRampRateFeedBack : data.RspIncreaseRampRateFeedBack; } } public void ManualCmd() { //((Window)GetView()).DialogResult = true; var wm = IoC.Get(); SetTemperatureViewModel setTemperatureViewModel = new SetTemperatureViewModel(); (wm as WindowManager)?.ShowDialogWithTitle(setTemperatureViewModel, null, "Set Temperature"); } public void SetCmd(object senderName, object sender, object typeName) { double temval = 0; string name = senderName.ToString(); switch (typeName.ToString()) { case "setpoint": double maxvalue = 0; string tName = GetTempratualMaxValue(name); if (!string.IsNullOrEmpty(tName)) { maxvalue = _dicTemperatualMaxValue[tName]; } string strRetValue = ShowNumberKeyboard(sender as Button, "",true, maxvalue); if (strRetValue != "Cancel") { //if (double.TryParse(strRetValue, out temval)) { SelectPostionSetPoint(name, strRetValue); } } break; case "ramp": strRetValue = ShowNumberKeyboard(sender as Button,"",false,0); if (strRetValue != "Cancel") { //if (double.TryParse(strRetValue, out temval)) { SelectPositionRamp(name, strRetValue); } } break; } } private string GetTempratualMaxValue(string typeName) { string dicName = string.Empty; bool isLspMode = LspModel!= "Outer Control"; switch (typeName) { case "TopHeater": dicName = isLspMode ? "Heater1" : "Heater2"; break; case "TopCenterHeater": dicName = isLspMode ? "Heater3" : "Heater4"; break; case "CenterHeater": dicName = isLspMode ? "Heater5" : "Heater6"; break; case "CenterBottomHeater": dicName = isLspMode ? "Heater7" : "Heater8"; break; case "BottomHeater": dicName = isLspMode ? "Heater9" : "Heater10"; break; } return dicName; } private void SelectPostionSetPoint(string name,string value) { switch (name) { case "TopHeater": TopHeaterSetPoint = value; break; case "TopCenterHeater": TopCenterHeaterSetPoint = value; break; case "CenterHeater": CenterHeaterSetPoint = value; break; case "CenterBottomHeater": CenterBottomHeaterSetPoint = value; break; case "BottomHeater": BottomHeaterSetPoint = value; break; } } private void SelectPositionRamp(string name, string value) { switch (name) { case "TopHeater": TopHeaterRampSetPoint = value; break; case "TopCenterHeater": TopCenterHeaterRampSetPoint = value; break; case "CenterHeater": CenterHeaterRampSetPoint = value; break; case "CenterBottomHeater": BottomCenterHeaterRampSetPoint = value; break; case "BottomHeater": BottomHeaterRampSetPoint = value; break; } } private string ShowNumberKeyboard(Control control, string defaultValue,bool isValidate,double maxValue=double.MaxValue) { NumberKeyboard numberKeyboard = new NumberKeyboard("", defaultValue); var point = control.PointFromScreen(new Point(0, 0)); double wx = SystemParameters.WorkArea.Width; double hy = SystemParameters.WorkArea.Height; if (-point.Y + control.ActualHeight + 5 + numberKeyboard.Height < hy) { numberKeyboard.Top = -point.Y + control.ActualHeight + 5; } else { numberKeyboard.Top = -point.Y - numberKeyboard.Height - 5; } if (-point.X + numberKeyboard.Width < wx) { numberKeyboard.Left = -point.X; } else { numberKeyboard.Left = -point.X - (numberKeyboard.Width - control.ActualWidth); } if ((bool)numberKeyboard.ShowDialog()) return numberKeyboard.ValueString; else return "Cancel"; } public void SelectControlMode() { var windowManager = IoC.Get(); RecipeConditionCheckConModeViewModel recipeConditionCheckConModeViewModel = new RecipeConditionCheckConModeViewModel(); recipeConditionCheckConModeViewModel.SelectControlMode = LspModel; var result = (windowManager as WindowManager)?.ShowDialogWithTitle(recipeConditionCheckConModeViewModel, null, "Temperature Control Mode Setting"); LspModel = recipeConditionCheckConModeViewModel.SelectControlMode; } public void AllZone(string obj) { var windowManager = IoC.Get(); TemperatureDetailAllZoneViewModel temperatureDetailAllZoneViewModel = new TemperatureDetailAllZoneViewModel(); switch (obj) { case "Set": if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(temperatureDetailAllZoneViewModel, null, "Temperature Value Set")) { TopHeaterSetPoint = temperatureDetailAllZoneViewModel.TempSetValue; TopCenterHeaterSetPoint = temperatureDetailAllZoneViewModel.TempSetValue; CenterHeaterSetPoint = temperatureDetailAllZoneViewModel.TempSetValue; CenterBottomHeaterSetPoint = temperatureDetailAllZoneViewModel.TempSetValue; BottomHeaterSetPoint = temperatureDetailAllZoneViewModel.TempSetValue; } break; case "Ramp": if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(temperatureDetailAllZoneViewModel, null, "Temperature Ramp Set")) { TopHeaterRampSetPoint = temperatureDetailAllZoneViewModel.TempSetValue; TopCenterHeaterRampSetPoint = temperatureDetailAllZoneViewModel.TempSetValue; CenterHeaterRampSetPoint = temperatureDetailAllZoneViewModel.TempSetValue; BottomCenterHeaterRampSetPoint = temperatureDetailAllZoneViewModel.TempSetValue; BottomHeaterRampSetPoint = temperatureDetailAllZoneViewModel.TempSetValue; } break; default: break; } } public void ExecCmd() { if (!DialogBox.Confirm("Ara you sure to execute?")) return; if (LspModel != "Outer Control") { InvokeClient.Instance.Service.DoOperation("PM1.Heater1.SetParameters", $"{BottomHeaterSetPoint};{BottomHeaterRampSetPoint};inner"); InvokeClient.Instance.Service.DoOperation("PM1.Heater2.SetParameters", $"{BottomHeaterSetPoint};{BottomHeaterRampSetPoint};inner"); InvokeClient.Instance.Service.DoOperation("PM1.Heater3.SetParameters", $"{CenterBottomHeaterSetPoint};{BottomCenterHeaterRampSetPoint};inner"); InvokeClient.Instance.Service.DoOperation("PM1.Heater4.SetParameters", $"{CenterBottomHeaterSetPoint};{BottomCenterHeaterRampSetPoint};inner"); InvokeClient.Instance.Service.DoOperation("PM1.Heater5.SetParameters", $"{CenterHeaterSetPoint};{CenterHeaterRampSetPoint};inner"); InvokeClient.Instance.Service.DoOperation("PM1.Heater6.SetParameters", $"{CenterHeaterSetPoint};{CenterHeaterRampSetPoint};inner"); InvokeClient.Instance.Service.DoOperation("PM1.Heater7.SetParameters", $"{TopCenterHeaterSetPoint};{TopCenterHeaterRampSetPoint};inner"); InvokeClient.Instance.Service.DoOperation("PM1.Heater8.SetParameters", $"{TopCenterHeaterSetPoint};{TopCenterHeaterRampSetPoint};inner"); InvokeClient.Instance.Service.DoOperation("PM1.Heater9.SetParameters", $"{TopHeaterSetPoint};{TopHeaterRampSetPoint};inner"); InvokeClient.Instance.Service.DoOperation("PM1.Heater10.SetParameters", $"{TopHeaterSetPoint};{TopHeaterRampSetPoint};inner"); } else { InvokeClient.Instance.Service.DoOperation("PM1.Heater1.SetParameters", $"{BottomHeaterSetPoint};{BottomHeaterRampSetPoint};outer"); InvokeClient.Instance.Service.DoOperation("PM1.Heater2.SetParameters", $"{BottomHeaterSetPoint};{BottomHeaterRampSetPoint};outer"); InvokeClient.Instance.Service.DoOperation("PM1.Heater3.SetParameters", $"{CenterBottomHeaterSetPoint};{BottomCenterHeaterRampSetPoint};outer"); InvokeClient.Instance.Service.DoOperation("PM1.Heater4.SetParameters", $"{CenterBottomHeaterSetPoint};{BottomCenterHeaterRampSetPoint};outer"); InvokeClient.Instance.Service.DoOperation("PM1.Heater5.SetParameters", $"{CenterHeaterSetPoint};{CenterHeaterRampSetPoint};outer"); InvokeClient.Instance.Service.DoOperation("PM1.Heater6.SetParameters", $"{CenterHeaterSetPoint};{CenterHeaterRampSetPoint};outer"); InvokeClient.Instance.Service.DoOperation("PM1.Heater7.SetParameters", $"{TopCenterHeaterSetPoint};{TopCenterHeaterRampSetPoint};outer"); InvokeClient.Instance.Service.DoOperation("PM1.Heater8.SetParameters", $"{TopCenterHeaterSetPoint};{TopCenterHeaterRampSetPoint};outer"); InvokeClient.Instance.Service.DoOperation("PM1.Heater9.SetParameters", $"{TopHeaterSetPoint};{TopHeaterRampSetPoint};outer"); InvokeClient.Instance.Service.DoOperation("PM1.Heater10.SetParameters", $"{TopHeaterSetPoint};{TopHeaterRampSetPoint};outer"); } _mannualSelectCount = 0; IsEnableMannual = false; } public void CloseCmd() { ClientApp.Instance.SwitchPage("status", "main", null); } } }