PageBoostStation2.xaml.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. using NEIntelligentControl2.Models.BoostStation;
  2. using NEIntelligentControl2.Models.Messages;
  3. using NEIntelligentControl2.Models.Pages;
  4. using NEIntelligentControl2.Models.Station;
  5. using NEIntelligentControl2.Service.Station;
  6. using NEIntelligentControl2.Windows.BoostStation;
  7. using SVGViewer.Models.Info;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Configuration;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using System.Windows.Controls;
  16. using System.Windows.Data;
  17. using System.Windows.Documents;
  18. using System.Windows.Input;
  19. using System.Windows.Media;
  20. using System.Windows.Media.Imaging;
  21. using System.Windows.Navigation;
  22. using System.Windows.Shapes;
  23. namespace NEIntelligentControl2.Pages.BoostStation
  24. {
  25. /// <summary>
  26. /// 组态升压站页面
  27. /// </summary>
  28. public partial class PageBoostStation2 : Page
  29. {
  30. private Dictionary<string, Page> _Stations;
  31. private IPageAction _IPageAction;
  32. private TagManager _TagManager;
  33. private StationManager _StationManager;
  34. /// <summary>
  35. /// 当前 选择的场站
  36. /// </summary>
  37. private string _CurrentStationId;
  38. private List<StationInfo> _StationInfos;
  39. private List<ShapeInfo> customizeShapes;
  40. /// <summary>
  41. /// 自定义控件
  42. /// </summary>
  43. private List<ShapeInfo> _CustomizeShapes
  44. {
  45. get
  46. {
  47. if (customizeShapes == null)
  48. {
  49. customizeShapes = _StationManager.GetCustomizeShapes();
  50. }
  51. return customizeShapes;
  52. }
  53. }
  54. private Dictionary<string, ShapeInfo> _BoostStationShapes;
  55. public PageBoostStation2(StationManager sm, IPageAction pa, TagManager tm)
  56. {
  57. InitializeComponent();
  58. _StationManager = sm;
  59. _IPageAction = pa;
  60. _TagManager = tm;
  61. _Stations = new Dictionary<string, Page>();
  62. InitBoostatationInfos();
  63. }
  64. private void InitBoostatationInfos()
  65. {
  66. _StationInfos = _StationManager.GetBoostStationInfos();
  67. var sis = _StationManager.GetBoostStationShapes();
  68. _BoostStationShapes = sis.ToDictionary(i => i.Id, i => i);
  69. _Stations.Add("ALL", new PageStationAll(sis) { StationChanged = StationChanged2 });
  70. }
  71. private void Button_Click(object sender, RoutedEventArgs e)
  72. {
  73. switch (((Control)sender).Tag)
  74. {
  75. case "edit": // 编辑
  76. EditBoostStation();
  77. break;
  78. case "add": // 添加升压站
  79. AddBoostStation();
  80. break;
  81. case "addsub": // 添加二次图
  82. AddSubStation();
  83. break;
  84. case "remove": // 删除升压站
  85. Remove();
  86. break;
  87. case "manage": // 管理二次图
  88. SubStationManageWindow.ShowWindow();
  89. break;
  90. case "big":
  91. case "medium":
  92. case "small":
  93. SwitchSize(((Control)sender).Tag as string);
  94. break;
  95. default: return;
  96. }
  97. }
  98. /// <summary>
  99. /// 切换缩略图大小
  100. /// </summary>
  101. private void SwitchSize(string v)
  102. {
  103. int i = 3;
  104. switch (v)
  105. {
  106. case "big":
  107. i = 3;
  108. break; ;
  109. case "medium":
  110. i = 4;
  111. break;
  112. case "small":
  113. i = 5;
  114. break;
  115. default:
  116. break;
  117. }
  118. (_Stations["ALL"] as PageStationAll).SwitchSize(i);
  119. }
  120. /// <summary>
  121. /// 添加二次图
  122. /// </summary>
  123. private void AddSubStation()
  124. {
  125. var info = ShapeAddWindow.Show(BoostStationEditType.SubStationAdd, "添加二次图", _CustomizeShapes, CustomizeShapeEdit);
  126. }
  127. /// <summary>
  128. /// 删除升压站
  129. /// </summary>
  130. private void Remove()
  131. {
  132. var b = MessageWindow.ShowMessage("即将删除升压站!", "警告");
  133. if (!b) return;
  134. if (string.IsNullOrWhiteSpace(_CurrentStationId)) return;
  135. var shape = _BoostStationShapes[_CurrentStationId];
  136. string val = _StationManager.RemoveBoostStation(shape);
  137. if (val == "success")
  138. {
  139. var v = _StationInfos.Where(i => i.Id == shape.Id).FirstOrDefault();
  140. if (v == null) return;
  141. _StationInfos.Remove(v);
  142. _TagManager.TagChanged?.Invoke(null);
  143. _TagManager.TagChanged?.Invoke(_StationInfos);
  144. _BoostStationShapes.Remove(_CurrentStationId);
  145. return;
  146. }
  147. MessageWindow.ShowMessage($"升压站删除失败:{val}");
  148. }
  149. /// <summary>
  150. /// 编辑升压站
  151. /// </summary>
  152. private async void EditBoostStation()
  153. {
  154. if (string.IsNullOrWhiteSpace(_CurrentStationId) || _CurrentStationId == "ALL") return;
  155. var shape = _BoostStationShapes[_CurrentStationId];
  156. var info = ShapeAddWindow.Show(BoostStationEditType.BoostStationEdit, "升压站编辑", _CustomizeShapes, CustomizeShapeEdit, shape);
  157. if (info == null) return;
  158. ShapeInfo si = await _StationManager.GetNewStationInfo(_CurrentStationId);
  159. (_Stations[_CurrentStationId] as PageStation2).ShapeInfo = si;
  160. }
  161. /// <summary>
  162. /// 添加升压站
  163. /// </summary>
  164. /// <exception cref="NotImplementedException"></exception>
  165. private void AddBoostStation()
  166. {
  167. var info = ShapeAddWindow.Show(BoostStationEditType.BoostStationAdd, "添加升压站", _CustomizeShapes, CustomizeShapeEdit);
  168. if (info == null) return;
  169. _StationInfos.Add(new StationInfo() { Name = info.Name, Id = info.Id });
  170. _BoostStationShapes.Add(info.Id, info);
  171. _TagManager.TagChanged?.Invoke(null);
  172. _TagManager.TagChanged?.Invoke(_StationInfos);
  173. }
  174. /// <summary>
  175. /// 添加自定义控件
  176. /// </summary>
  177. /// <param name="info">控件信息</param>
  178. /// <param name="addOrRemove">添加或移除</param>
  179. private bool CustomizeShapeEdit(ShapeInfo info, string type)
  180. {
  181. var v = _StationManager.AddOrRemoveCustomizeShape(info, type);
  182. if (v != "success")
  183. {
  184. MessageWindow.ShowMessage(v);
  185. return false;
  186. }
  187. return true;
  188. }
  189. /// <summary>
  190. /// 场站选择改变
  191. /// </summary>
  192. /// <param name="stationId">场站ID</param>
  193. public void StationChanged(string stationId)
  194. {
  195. if (_CurrentStationId == stationId) return;
  196. if (!_Stations.ContainsKey(stationId))
  197. {
  198. var bsp = _BoostStationShapes[stationId];
  199. Page sp = _IPageAction["BoostStation.PageStation2"];
  200. (sp as PageStation2).ShapeInfo = bsp;
  201. _Stations.Add(stationId, sp as PageStation2);
  202. }
  203. _CurrentStationId = stationId;
  204. _MainFrame.Navigate(_Stations[stationId]);
  205. m1.Visibility = _CurrentStationId == "ALL" ? Visibility.Collapsed : Visibility.Visible;
  206. m2.Visibility = _CurrentStationId == "ALL" ? Visibility.Visible : Visibility.Collapsed;
  207. if (!_MainFrame.NavigationService.CanGoBack) return;
  208. var en = _MainFrame.NavigationService.RemoveBackEntry();
  209. while (en != null)
  210. {
  211. en = _MainFrame.NavigationService.RemoveBackEntry();
  212. }
  213. }
  214. private void StationChanged2(string obj)
  215. {
  216. _TagManager.ChangeTag?.Invoke(obj);
  217. }
  218. private void Page_Loaded(object sender, RoutedEventArgs e)
  219. {
  220. _TagManager.TagSwitched = TagSwitched;
  221. _TagManager.TagChanged?.Invoke(_StationInfos);
  222. //_CurrentStationId = null;
  223. }
  224. private void TagSwitched(StationInfo obj)
  225. {
  226. StationChanged(obj.Id);
  227. }
  228. private void Page_Unloaded(object sender, RoutedEventArgs e)
  229. {
  230. _CurrentStationId = null;
  231. }
  232. }
  233. }