using Aitex.Core.RT.SCCore; using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig; using MECF.Framework.UI.Client.CenterViews.Dialogs; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Text.RegularExpressions; using System.Windows.Media; using MECF.Framework.UI.Client.ClientBase; using FurnaceUI.Models; namespace FurnaceUI.Views.Operations { public class ValveInterlockTimeViewModel : FurnaceUIViewModelBase { public Dictionary RecipeStepTime = new Dictionary(); public bool IsSave { get; set; } = false; private string _selectTime; public string SelectTime { get => _selectTime; set { _selectTime = value; if (!string.IsNullOrEmpty(value) && !value.Contains(" ") && value.Contains(":")) { SelectValueTime = value; SelectValueTimeM = value.Split(':')[0]; SelectValueTimeS = value.Split(':')[1]; } else if (!string.IsNullOrEmpty(value) && RecipeStepTime.ContainsKey(value)) { SelectValueTime = RecipeStepTime[value]; SelectValueTimeM = SelectValueTime.Split(':')[0]; SelectValueTimeS = SelectValueTime.Split(':')[1]; } } } private string _selectValueTime = "00:10.0"; public string SelectValueTime { get { return _selectValueTime; } set { _selectValueTime = value; NotifyOfPropertyChange(SelectValueTime); } } private string _selectValueTimeM = "00"; public string SelectValueTimeM { get { return _selectValueTimeM; } set { _selectValueTimeM = value; NotifyOfPropertyChange(SelectValueTimeM); } } private string _selectValueTimeS = "10"; public string SelectValueTimeS { get { return _selectValueTimeS; } set { _selectValueTimeS = value; NotifyOfPropertyChange(SelectValueTimeS); } } private string _TimeModel; public string TimeModel { get { return _TimeModel; } set { _TimeModel = value; NotifyOfPropertyChange(nameof(TimeModel)); } } public string TimeParam { get; set; } public bool IsEnable => CGlobal.RecipeProcessEditViewEnable;//是否是View模式 private void GetDataOfConfigItems() { if (SelectTime != null && SelectTime.Length > 1 && SelectTime.Split(':').Length > 2) { SelectValueTimeM = SelectTime.Split(':')[0]; SelectValueTimeS = SelectTime.Split(':')[1]; } var temp = generate(); foreach (var item in temp) { RecipeStepTime[item] = SystemConfigProvider.Instance.GetValueByName($"PM1.RecipeEditParameter.{TimeParam}.{item}"); } } public ValveInterlockTimeViewModel(string timeParam) { TimeParam = timeParam; Initialize(); } protected override void OnInitialize() { base.OnInitialize(); InitTime(); } protected override void OnViewLoaded(object view) { GetDataOfConfigItems(); base.OnViewLoaded(view); foreach (var item in RecipeStepTime.Keys) { object Txt = ((ValveInterlockTimeView)(((Window)GetView()).Content)).FindName("Txt" + item); if (Txt is TextBlock) { ((TextBlock)Txt).Text = RecipeStepTime[item]; } } } public void SetValue(object sender, string isFullKeyboard = "") { string value = ((TextBox)sender).Text; if (!string.IsNullOrEmpty(isFullKeyboard)) { FullKeyboard fullKeyboard1 = new FullKeyboard("", value); if ((bool)fullKeyboard1.ShowDialog()) { ((TextBox)sender).Text = fullKeyboard1.ValueString; } } else { NumberKeyboard fullKeyboard = new NumberKeyboard("", value); if ((bool)fullKeyboard.ShowDialog()) { ((TextBox)sender).Text = fullKeyboard.ValueString; } } } public void InitTime() { if (string.IsNullOrEmpty(SelectValueTime)) { return; } var timeList = SelectValueTime.Split(':').ToList(); var first = timeList[0]; string pattern = "^[0-9]*$"; Regex rex = new Regex(pattern); if (!rex.IsMatch(first)) { timeList.Remove(first); } SelectValueTimeM = timeList.FirstOrDefault(); SelectValueTimeS = timeList.LastOrDefault(); SetTimeValue("Value"); } public void Initialize() { var temp = generate(); foreach (var item in temp) { RecipeStepTime.Add(item, "00:00.0"); } } IEnumerable generate() { for (char c = 'A'; c <= 'Z'; c++) yield return new string(c, 1); } public void SetTimeValue(string nameCmd) { SelectTime = nameCmd; TimeModel = nameCmd; if (TimeModel != "Value") { object Txt = ((ValveInterlockTimeView)(((Window)GetView()).Content)).FindName("TxtTime"); if (Txt is TextBox) { ((TextBox)Txt).Foreground = new SolidColorBrush(Colors.Black); } } } public void SetTimeCmd(string nameCmd) { SelectValueTime = SelectValueTimeM + ":" + SelectValueTimeS; switch (nameCmd) { case "Save": if (!CheckTimeFormat( SelectValueTimeM, SelectValueTimeS)) return; IsSave = true; break; case "Close": IsSave = false; break; default: break; } ((Window)GetView()).Close(); } private bool CheckTimeFormat(string strTimeM, string strTimeS) { bool bResult = true, bTimeM = true, bTimeS = true; string pattern = "^[0-9]*$"; Regex rex = new Regex(pattern); //秒需要设置小数 Regex reg = new Regex(@"^\d+(\.\d+)?$"); object TxtM = ((ValveInterlockTimeView)(((Window)GetView()).Content)).FindName("TxtTimeM"); object TxtS = ((ValveInterlockTimeView)(((Window)GetView()).Content)).FindName("TxtTimeS"); if (!rex.IsMatch(strTimeM)|| double.Parse(strTimeM) > 59) { bTimeM = false; } if (!bTimeM) { if (TxtM is TextBox)((TextBox)TxtM).Foreground = new SolidColorBrush(Colors.Red); } else { if (TxtM is TextBox) ((TextBox)TxtM).Foreground = new SolidColorBrush(Colors.Black); } double value; if (!double.TryParse(strTimeS, out value)) { bTimeS = false; } //if (Convert.ToDouble(value) < 0) //{ // bTimeS = false; //} if (!reg.IsMatch(strTimeS) || double.Parse(strTimeS) >= 60) { bTimeS = false; } if (!bTimeS) { if (TxtS is TextBox) ((TextBox)TxtS).Foreground = new SolidColorBrush(Colors.Red); } else { if (TxtS is TextBox) ((TextBox)TxtS).Foreground = new SolidColorBrush(Colors.Black); } bResult = bTimeM && bTimeS; return bResult; } } }