using NEIntelligentControl2.Models.BoostStation; using NEIntelligentControl2.Models.Messages; using NEIntelligentControl2.Models.Pages; using NEIntelligentControl2.Models.Station; using NEIntelligentControl2.Service.Station; using NEIntelligentControl2.Windows.BoostStation; using SVGViewer.Models.Info; using System; using System.Collections.Generic; using System.Configuration; 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.Navigation; using System.Windows.Shapes; namespace NEIntelligentControl2.Pages.BoostStation { /// /// 组态升压站页面 /// public partial class PageBoostStation2 : Page { private Dictionary _Stations; private IPageAction _IPageAction; private TagManager _TagManager; private StationManager _StationManager; /// /// 当前 选择的场站 /// private string _CurrentStationId; private List _StationInfos; private List customizeShapes; /// /// 自定义控件 /// private List _CustomizeShapes { get { if (customizeShapes == null) { customizeShapes = _StationManager.GetCustomizeShapes(); } return customizeShapes; } } private Dictionary _BoostStationShapes; public PageBoostStation2(StationManager sm, IPageAction pa, TagManager tm) { InitializeComponent(); _StationManager = sm; _IPageAction = pa; _TagManager = tm; _Stations = new Dictionary(); InitBoostatationInfos(); } private void InitBoostatationInfos() { _StationInfos = _StationManager.GetBoostStationInfos(); var sis = _StationManager.GetBoostStationShapes(); _BoostStationShapes = sis.ToDictionary(i => i.Id, i => i); _Stations.Add("ALL", new PageStationAll(sis) { StationChanged = StationChanged2 }); } private void Button_Click(object sender, RoutedEventArgs e) { switch (((Control)sender).Tag) { case "edit": // 编辑 EditBoostStation(); break; case "add": // 添加升压站 AddBoostStation(); break; case "addsub": // 添加二次图 AddSubStation(); break; case "remove": // 删除升压站 Remove(); break; case "manage": // 管理二次图 SubStationManageWindow.ShowWindow(); break; case "big": case "medium": case "small": SwitchSize(((Control)sender).Tag as string); break; default: return; } } /// /// 切换缩略图大小 /// private void SwitchSize(string v) { int i = 3; switch (v) { case "big": i = 3; break; ; case "medium": i = 4; break; case "small": i = 5; break; default: break; } (_Stations["ALL"] as PageStationAll).SwitchSize(i); } /// /// 添加二次图 /// private void AddSubStation() { var info = ShapeAddWindow.Show(BoostStationEditType.SubStationAdd, "添加二次图", _CustomizeShapes, CustomizeShapeEdit); } /// /// 删除升压站 /// private void Remove() { var b = MessageWindow.ShowMessage("即将删除升压站!", "警告"); if (!b) return; if (string.IsNullOrWhiteSpace(_CurrentStationId)) return; var shape = _BoostStationShapes[_CurrentStationId]; string val = _StationManager.RemoveBoostStation(shape); if (val == "success") { var v = _StationInfos.Where(i => i.Id == shape.Id).FirstOrDefault(); if (v == null) return; _StationInfos.Remove(v); _TagManager.TagChanged?.Invoke(null); _TagManager.TagChanged?.Invoke(_StationInfos); _BoostStationShapes.Remove(_CurrentStationId); return; } MessageWindow.ShowMessage($"升压站删除失败:{val}"); } /// /// 编辑升压站 /// private async void EditBoostStation() { if (string.IsNullOrWhiteSpace(_CurrentStationId) || _CurrentStationId == "ALL") return; var shape = _BoostStationShapes[_CurrentStationId]; var info = ShapeAddWindow.Show(BoostStationEditType.BoostStationEdit, "升压站编辑", _CustomizeShapes, CustomizeShapeEdit, shape); if (info == null) return; ShapeInfo si = await _StationManager.GetNewStationInfo(_CurrentStationId); (_Stations[_CurrentStationId] as PageStation2).ShapeInfo = si; } /// /// 添加升压站 /// /// private void AddBoostStation() { var info = ShapeAddWindow.Show(BoostStationEditType.BoostStationAdd, "添加升压站", _CustomizeShapes, CustomizeShapeEdit); if (info == null) return; _StationInfos.Add(new StationInfo() { Name = info.Name, Id = info.Id }); _BoostStationShapes.Add(info.Id, info); _TagManager.TagChanged?.Invoke(null); _TagManager.TagChanged?.Invoke(_StationInfos); } /// /// 添加自定义控件 /// /// 控件信息 /// 添加或移除 private bool CustomizeShapeEdit(ShapeInfo info, string type) { var v = _StationManager.AddOrRemoveCustomizeShape(info, type); if (v != "success") { MessageWindow.ShowMessage(v); return false; } return true; } /// /// 场站选择改变 /// /// 场站ID public void StationChanged(string stationId) { if (_CurrentStationId == stationId) return; if (!_Stations.ContainsKey(stationId)) { var bsp = _BoostStationShapes[stationId]; Page sp = _IPageAction["BoostStation.PageStation2"]; (sp as PageStation2).ShapeInfo = bsp; _Stations.Add(stationId, sp as PageStation2); } _CurrentStationId = stationId; _MainFrame.Navigate(_Stations[stationId]); m1.Visibility = _CurrentStationId == "ALL" ? Visibility.Collapsed : Visibility.Visible; m2.Visibility = _CurrentStationId == "ALL" ? Visibility.Visible : Visibility.Collapsed; if (!_MainFrame.NavigationService.CanGoBack) return; var en = _MainFrame.NavigationService.RemoveBackEntry(); while (en != null) { en = _MainFrame.NavigationService.RemoveBackEntry(); } } private void StationChanged2(string obj) { _TagManager.ChangeTag?.Invoke(obj); } private void Page_Loaded(object sender, RoutedEventArgs e) { _TagManager.TagSwitched = TagSwitched; _TagManager.TagChanged?.Invoke(_StationInfos); //_CurrentStationId = null; } private void TagSwitched(StationInfo obj) { StationChanged(obj.Id); } private void Page_Unloaded(object sender, RoutedEventArgs e) { _CurrentStationId = null; } } }