using NEIntelligentControl2.Service.Station; using NEIntelligentControl2.Views.BoostStation; using SVGViewer.Models.Info; 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.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace NEIntelligentControl2.Windows.BoostStation { /// /// 二次图管理窗口 /// public partial class SubStationManageWindow : Window { private StationManager _StationManager; private List customizeShapes; /// /// 自定义控件 /// private List _CustomizeShapes { get { if (customizeShapes == null) { customizeShapes = _StationManager.GetCustomizeShapes(); } return customizeShapes; } } public SubStationManageWindow() { InitializeComponent(); _StationManager = App.ServiceProvider.GetService(typeof(StationManager)) as StationManager; Init(); } private async void Init() { List ls = await _StationManager.GetSubStations(); if (ls == null) return; foreach (var v in ls) { SubStationView ssv = new SubStationView(v); ssv.ContentMenuAction = ControlSubStation; _ug.Children.Add(ssv); } } /// /// 卡片右键菜单事件 /// /// 图形信息 /// 操作类型 private void ControlSubStation(SubStationView sv, ShapeInfo arg1, string arg2) { if (arg1 == null) return; switch (arg2) { case "edit": // 编辑 Edit(sv, arg1); break; case "remove": // 移除 Remove(sv, arg1); break; default: return; } } /// /// 移除二次图 /// private void Remove(SubStationView sv, ShapeInfo arg1) { var b = MessageWindow.ShowMessage("即将删除二次图!", "警告"); if (!b) return; string val = _StationManager.RemoveSubStation(arg1); if (val == "success") { _ug.Children.Remove(sv); return; } MessageWindow.ShowMessage($"二次图删除失败:{val}"); } /// /// 编辑二次图 /// private void Edit(SubStationView sv, ShapeInfo arg1) { var info = ShapeAddWindow.Show(BoostStationEditType.SubStationEdit, "编辑二次图", _CustomizeShapes, CustomizeShapeEdit, arg1); if(info == null) return; sv.SwitchInfo(info); } /// /// 添加自定义控件 /// /// 控件信息 /// 添加或移除 private bool CustomizeShapeEdit(ShapeInfo info, string type) { var v = _StationManager.AddOrRemoveCustomizeShape(info, type); if (v != "success") { MessageWindow.ShowMessage(v); return false; } return true; } public static void ShowWindow() { SubStationManageWindow ssmw = new SubStationManageWindow(); ssmw.Owner = Application.Current.MainWindow; ssmw.ShowDialog(); } } }