using MECF.Framework.Common.CommonData; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.IOCore; 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; using FurnaceUI.Models; namespace FurnaceUI.Views.Operations { public class InterlockItemViewModel : FurnaceUIViewModelBase { public string ItemType { get; set; } public ObservableCollection InterlockItems { get; set; } = new ObservableCollection(); private InterlockItem _interlockSelectedItem; public InterlockItem InterlockSelectedItem { get => _interlockSelectedItem; set { _interlockSelectedItem = value; NotifyOfPropertyChange(nameof(InterlockSelectedItem)); } } private string _selectedItem; public string SelectedItem { get => _selectedItem; set { _selectedItem = value; NotifyOfPropertyChange(nameof(SelectedItem)); } } private string _searchKey; public string SearchKey { get => _searchKey; set { _searchKey = value; NotifyOfPropertyChange(nameof(SearchKey)); } } public InterlockItemViewModel(string itemType) { ItemType = itemType; } protected override void OnInitialize() { InitItem(); base.OnInitialize(); } private void InitItem() { if (ItemType == "Action") { List notifiableIoItems = new List(); notifiableIoItems = QueryDataClient.Instance.Service.GetDoList($"System.PM1"); for (int i = 0; i < notifiableIoItems.Count; i++) { InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name }); } } else { List notifiableIoItems = new List(); notifiableIoItems = QueryDataClient.Instance.Service.GetDiList($"System.PM1"); for (int i = 0; i < notifiableIoItems.Count; i++) { InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name }); } notifiableIoItems = QueryDataClient.Instance.Service.GetAiList($"System.PM1"); for (int i = 0; i < notifiableIoItems.Count; i++) { InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name }); } notifiableIoItems = QueryDataClient.Instance.Service.GetDoList($"System.PM1"); for (int i = 0; i < notifiableIoItems.Count; i++) { InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name }); } } } public void SearchItem() { if (!string.IsNullOrEmpty(SearchKey)) { InterlockItems.Clear(); if (ItemType == "Action") { List notifiableIoItems = new List(); notifiableIoItems = QueryDataClient.Instance.Service.GetDoList($"System.PM1"); for (int i = 0; i < notifiableIoItems.Count; i++) { if (notifiableIoItems[i].Name.Contains(SearchKey)) InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name }); } } else { List notifiableIoItems = new List(); notifiableIoItems = QueryDataClient.Instance.Service.GetDiList($"System.PM1"); for (int i = 0; i < notifiableIoItems.Count; i++) { if (notifiableIoItems[i].Name.Contains(SearchKey)) InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name }); } notifiableIoItems = QueryDataClient.Instance.Service.GetAiList($"System.PM1"); for (int i = 0; i < notifiableIoItems.Count; i++) { if (notifiableIoItems[i].Name.Contains(SearchKey)) InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name }); } notifiableIoItems = QueryDataClient.Instance.Service.GetDoList($"System.PM1"); for (int i = 0; i < notifiableIoItems.Count; i++) { if (notifiableIoItems[i].Name.Contains(SearchKey)) InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name }); } } } else { DialogBox.ShowWarning("Please input search key!"); } } public void SelectItem() { if (InterlockSelectedItem == null) SelectedItem = ""; else SelectedItem = InterlockSelectedItem.ItemName; } public void SaveCmd() { if (string.IsNullOrEmpty(SelectedItem)) { DialogBox.ShowWarning("SelectedItem is empty!"); return; } ((Window)GetView()).DialogResult = true; } public void CloseCmd() { ((Window)GetView()).DialogResult = false; } } public class InterlockItem : NotifiableItem { private string _itemName; public string ItemName { get => _itemName; set { _itemName = value; InvokePropertyChanged(nameof(ItemName)); } } } }