using Aitex.Core.RT.Event; using Caliburn.Micro.Core; using MECF.Framework.Common.Alarms; using MECF.Framework.Common.OperationCenter; using MECF.Framework.UI.Client.CenterViews.Alarms; using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig; using MECF.Framework.UI.Client.ClientBase; using OpenSEMI.ClientBase; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace MECF.Framework.UI.Client.CenterViews.Parameter { public class AlarmtableParameterViewModel : ModuleUiViewModelBase { public bool IsPermission { get => this.Permission == 3; } private AlarmProvider _alarmProvider = new AlarmProvider(); public ObservableCollection AlarmParameterOperations { get; set; } = new ObservableCollection(); public ObservableCollection AlarmGroups { get; set; } = new ObservableCollection(); public ObservableCollection TableList { get; set; } = new ObservableCollection(); private int _alarmGroupsWidth = 285; public string SelectedAlarmGroup { get; set; } public int AlarmGroupsWidth { get => _alarmGroupsWidth; set { _alarmGroupsWidth = value; NotifyOfPropertyChange("AlarmGroupsWidth"); } } private List _groupNames = new List (new string[] { "Group1", "Group2", "Group3", "Group4", "Group5", "Group6", "Group7", "Group8", "Group9", "Group10" }); public Dictionary> AllGroupAlarmList = new Dictionary>(); public List GroupNames { get => _groupNames; set { _groupNames = value; NotifyOfPropertyChange("GroupNames"); } } public int SelectedAlarmTableIndex = 0; public string EntryValue; public Visibility _alarmTableVisibility = Visibility.Collapsed; public Visibility AlarmTableVisibility { get => _alarmTableVisibility; set { _alarmTableVisibility = value; NotifyOfPropertyChange("AlarmTableVisibility"); } } public Visibility _alarmGroupsVisibility = Visibility.Collapsed; public Visibility AlarmGroupsVisibility { get => _alarmGroupsVisibility; set { _alarmGroupsVisibility = value; if (_alarmGroupsVisibility == Visibility.Visible) { AlarmGroupsWidth = 235; } else { AlarmGroupsWidth = 0; } NotifyOfPropertyChange("AlarmGroupsVisibility"); } } protected override void OnViewLoaded(object view) { base.OnViewLoaded(view); var alarmDict = _alarmProvider.GetXmlAlarmList(); AllGroupAlarmList = alarmDict; SetVisibility(); } private void SetVisibility() { if (AllGroupAlarmList != null) { if (AllGroupAlarmList.Count < 2) { AlarmTableVisibility = Visibility.Collapsed; if (AllGroupAlarmList.Count != 0) { AlarmParameterOperations.Clear(); foreach (var subitem in AllGroupAlarmList[AllGroupAlarmList.Keys.FirstOrDefault()].Keys) { AlarmParameterOperations.Add(new AlarmParameterOperation(subitem, AllGroupAlarmList[AllGroupAlarmList.Keys.FirstOrDefault()][subitem])); } } } else { AlarmTableVisibility = Visibility.Visible; TableList.Clear(); foreach (var item in AllGroupAlarmList.Keys) { TableList.Add(item); } AlarmParameterOperations.Clear(); foreach (var subitem in AllGroupAlarmList[AllGroupAlarmList.Keys.FirstOrDefault()].Keys) { AlarmParameterOperations.Add(new AlarmParameterOperation(subitem, AllGroupAlarmList[AllGroupAlarmList.Keys.FirstOrDefault()][subitem])); } } SetAlarmGroup(AllGroupAlarmList.Keys.FirstOrDefault()); } else { AlarmTableVisibility = Visibility.Hidden; } } public void AlarmTableSelected(string index) { SaveAlarmGroup(); int tempValue = int.Parse(index); SelectedAlarmTableIndex = tempValue; SelectedAlarmGroup = string.Empty; AlarmParameterOperations.Clear(); SetAlarmGroup(index); } private void SetAlarmGroup(string index) { AlarmGroups.Clear(); var categoryList = AllGroupAlarmList[index].Values.Select(x => x.Category); foreach (var item in categoryList) { if (!AlarmGroups.Contains(item)) { AlarmGroups.Add(item); } } if (AlarmGroups.Count < 2) { AlarmGroupsVisibility = Visibility.Collapsed; AlarmParameterOperations.Clear(); foreach (var subitem in AllGroupAlarmList[AllGroupAlarmList.Keys.FirstOrDefault()].Keys) { AlarmParameterOperations.Add(new AlarmParameterOperation(subitem, AllGroupAlarmList[AllGroupAlarmList.Keys.FirstOrDefault()][subitem])); } } else { AlarmGroupsVisibility = Visibility.Visible; AlarmParameterOperations.Clear(); foreach (var subitem in AllGroupAlarmList[index].Keys) { AlarmParameterOperations.Add(new AlarmParameterOperation(subitem, AllGroupAlarmList[index][subitem])); } } } private void SaveAlarmGroup() { foreach (var item in AlarmParameterOperations) { AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Id = item.ID; AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Source = item.Source; AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Description = item.Description; AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Solution = item.Solution; AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Explaination = item.Explaination; AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Bypass = item.Bypass; AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Group = (EventGroup)Enum.Parse(typeof(EventGroup), item.Group); AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Editable = item.IsEdit; } } public void AlarmTableSave() { SaveAlarmGroup(); InvokeClient.Instance.Service.DoOperation($"System.UpdateAlarmTable", AllGroupAlarmList); } /// /// 按照Id号或者Alarm文本查找 /// /// /// public void AlarmValueFind(string alarmId, string alarmText) { if (!string.IsNullOrWhiteSpace(alarmId) || !string.IsNullOrWhiteSpace(alarmText)) { AlarmParameterOperations.Clear(); bool b1, b2, b3, b4; if (!string.IsNullOrEmpty(SelectedAlarmGroup)) { foreach(var alarmOperation in AllGroupAlarmList[SelectedAlarmTableIndex.ToString()]) { b1 = alarmOperation.Value.Category == SelectedAlarmGroup; b2 = string.IsNullOrWhiteSpace(alarmId) && alarmOperation.Value.Description.ToLower().Contains(alarmText.ToLower()); b3 = string.IsNullOrWhiteSpace(alarmText) && alarmOperation.Value.Id.ToString() == alarmId; b4 = !string.IsNullOrWhiteSpace(alarmId) && !string.IsNullOrWhiteSpace(alarmText) && alarmOperation.Value.Id.ToString() == alarmId && alarmOperation.Value.Description.ToLower().Contains(alarmText.ToLower()); if (b1 && (b2 || b3 || b4)) { AlarmParameterOperations.Add(new AlarmParameterOperation(alarmOperation.Key, alarmOperation.Value)); } } } else { foreach (var alarmOperation in AllGroupAlarmList[SelectedAlarmTableIndex.ToString()]) { b2 = string.IsNullOrWhiteSpace(alarmId) && alarmOperation.Value.Description.ToLower().Contains(alarmText.ToLower()); b3 = string.IsNullOrWhiteSpace(alarmText) && alarmOperation.Value.Id.ToString() == alarmId; b4 = !string.IsNullOrWhiteSpace(alarmId) && !string.IsNullOrWhiteSpace(alarmText) && alarmOperation.Value.Id.ToString() == alarmId && alarmOperation.Value.Description.ToLower().Contains(alarmText.ToLower()); if (b2 || b3 || b4) { AlarmParameterOperations.Add(new AlarmParameterOperation(alarmOperation.Key, alarmOperation.Value)); } } } } else { DialogBox.ShowWarning("Please input condition!"); } } public void AlarmTableAllOn() { if (DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, "Whether all switches are turned on?") == DialogButton.Yes) { EntryValue = "AllOn"; GetAlarmParameterOperations(); } } public void AlarmTableAllOff() { if (DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, "Whether all switches are turned off?") == DialogButton.Yes) { EntryValue = "AllOff"; GetAlarmParameterOperations(); } } public void AlarmTableCancel() { } public void GetAlarmParameterOperations() { if (AllGroupAlarmList == null || AllGroupAlarmList.Count == 0) return; foreach (var item in AllGroupAlarmList[SelectedAlarmTableIndex.ToString()]) { if (AlarmGroups.Count < 2) { if (EntryValue == "AllOn") item.Value.Bypass = true; else if (EntryValue == "AllOff") item.Value.Bypass = false; } else { if (SelectedAlarmGroup != null) { if (item.Value.Category == SelectedAlarmGroup) { if (EntryValue == "AllOn") item.Value.Bypass = true; else if (EntryValue == "AllOff") item.Value.Bypass = false; } } } } AlarmParameterOperations.Clear(); IEnumerable> findGroupAlarm; if (SelectedAlarmGroup != null) { findGroupAlarm = AllGroupAlarmList[SelectedAlarmTableIndex.ToString()].Where(x => x.Value.Category == SelectedAlarmGroup); } else { findGroupAlarm = AllGroupAlarmList[SelectedAlarmTableIndex.ToString()]; } foreach (var item in findGroupAlarm) { AlarmParameterOperations.Add(new AlarmParameterOperation(item.Key, item.Value)); } } public void AlarmTypeSelected(object obj) { var tempobj = obj; var selectedAlarmGroup = (string)tempobj; SelectedAlarmGroup = selectedAlarmGroup; SaveAlarmGroup(); AlarmParameterOperations.Clear(); var findGroupAlarm = AllGroupAlarmList[SelectedAlarmTableIndex.ToString()].Where(x => x.Value.Category == selectedAlarmGroup); foreach (var item in findGroupAlarm) { AlarmParameterOperations.Add(new AlarmParameterOperation(item.Key, item.Value)); } } public class AlarmParameterOperation : PropertyChangedBase { public AlarmParameterOperation() { } private string _alarmName; public string AlarmName { get => _alarmName; set { _alarmName = value; NotifyOfPropertyChange("AlarmName"); } } private string _source; public string Source { get => _source; set { _source = value; NotifyOfPropertyChange("Source"); } } private long _id; public long ID { get => _id; set { _id = value; NotifyOfPropertyChange("ID"); } } private string _description; public string Description { get => _description; set { _description = value; NotifyOfPropertyChange("Description"); } } private string _solution; public string Solution { get => _solution; set { _solution = value; NotifyOfPropertyChange("Solution"); } } private string _explaination; public string Explaination { get => _explaination; set { _explaination = value; NotifyOfPropertyChange("Explaination"); } } private bool _bypass; public bool Bypass { get => _bypass; set { _bypass = value; NotifyOfPropertyChange("Bypass"); } } private string _group; public string Group { get => _group; set { _group = value; NotifyOfPropertyChange("Group"); } } private bool _isEdit; public bool IsEdit { get => _isEdit; set { _isEdit = value; NotifyOfPropertyChange("IsEdit"); } } private int _selectedIndex; public int SelectedIndex { get => _selectedIndex; set { _selectedIndex = value; NotifyOfPropertyChange("SelectedIndex"); } } public AlarmParameterOperation(string key, EventItem eventItem) { AlarmName = key; if (eventItem != null) { ID = eventItem.Id; Source = eventItem.Source; Description = eventItem.Description; Solution = eventItem.Solution; Explaination = eventItem.Explaination; Bypass = eventItem.Bypass; if (eventItem.Group == EventGroup.Group0) eventItem.Group = EventGroup.Group1; Group = eventItem.Group.ToString(); IsEdit = eventItem.Editable; } } public AlarmParameterOperation(string alarmParameterStr) { if (alarmParameterStr != null) { var alarmPar = alarmParameterStr.Split(','); if (alarmPar != null && alarmPar.Length > 0) { _id = int.Parse(alarmPar[0]); //_isSave = bool.Parse(alarmPar[1]); _group = alarmPar[2]; _isEdit = bool.Parse(alarmPar[3]); } } } public override string ToString() { string rtnString = $"{_id},{_group},{_isEdit}"; return rtnString; } } public class ShowAlarmGroup : PropertyChangedBase { private string _name; public string Name { get => _name; set { _name = value; NotifyOfPropertyChange("Name"); } } private string _display; public string Display { get => _display; set { _display = value; NotifyOfPropertyChange("Display"); } } private bool _bvalue = false; public bool AlarmBoolValue { get { return _bvalue; } set { _bvalue = value; NotifyOfPropertyChange("AlarmBoolValue"); } } } } }