SubStationManageWindow.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using NEIntelligentControl2.Service.Station;
  2. using NEIntelligentControl2.Views.BoostStation;
  3. using SVGViewer.Models.Info;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Shapes;
  17. namespace NEIntelligentControl2.Windows.BoostStation
  18. {
  19. /// <summary>
  20. /// 二次图管理窗口
  21. /// </summary>
  22. public partial class SubStationManageWindow : Window
  23. {
  24. private StationManager _StationManager;
  25. private List<ShapeInfo> customizeShapes;
  26. /// <summary>
  27. /// 自定义控件
  28. /// </summary>
  29. private List<ShapeInfo> _CustomizeShapes
  30. {
  31. get
  32. {
  33. if (customizeShapes == null)
  34. {
  35. customizeShapes = _StationManager.GetCustomizeShapes();
  36. }
  37. return customizeShapes;
  38. }
  39. }
  40. public SubStationManageWindow()
  41. {
  42. InitializeComponent();
  43. _StationManager = App.ServiceProvider.GetService(typeof(StationManager)) as StationManager;
  44. Init();
  45. }
  46. private async void Init()
  47. {
  48. List<ShapeInfo> ls = await _StationManager.GetSubStations();
  49. if (ls == null) return;
  50. foreach (var v in ls)
  51. {
  52. SubStationView ssv = new SubStationView(v);
  53. ssv.ContentMenuAction = ControlSubStation;
  54. _ug.Children.Add(ssv);
  55. }
  56. }
  57. /// <summary>
  58. /// 卡片右键菜单事件
  59. /// </summary>
  60. /// <param name="arg1">图形信息</param>
  61. /// <param name="arg2">操作类型</param>
  62. private void ControlSubStation(SubStationView sv, ShapeInfo arg1, string arg2)
  63. {
  64. if (arg1 == null) return;
  65. switch (arg2)
  66. {
  67. case "edit": // 编辑
  68. Edit(sv, arg1);
  69. break;
  70. case "remove": // 移除
  71. Remove(sv, arg1);
  72. break;
  73. default: return;
  74. }
  75. }
  76. /// <summary>
  77. /// 移除二次图
  78. /// </summary>
  79. private void Remove(SubStationView sv, ShapeInfo arg1)
  80. {
  81. var b = MessageWindow.ShowMessage("即将删除二次图!", "警告");
  82. if (!b) return;
  83. string val = _StationManager.RemoveSubStation(arg1);
  84. if (val == "success")
  85. {
  86. _ug.Children.Remove(sv);
  87. return;
  88. }
  89. MessageWindow.ShowMessage($"二次图删除失败:{val}");
  90. }
  91. /// <summary>
  92. /// 编辑二次图
  93. /// </summary>
  94. private void Edit(SubStationView sv, ShapeInfo arg1)
  95. {
  96. var info = ShapeAddWindow.Show(BoostStationEditType.SubStationEdit, "编辑二次图", _CustomizeShapes, CustomizeShapeEdit, arg1);
  97. if(info == null) return;
  98. sv.SwitchInfo(info);
  99. }
  100. /// <summary>
  101. /// 添加自定义控件
  102. /// </summary>
  103. /// <param name="info">控件信息</param>
  104. /// <param name="addOrRemove">添加或移除</param>
  105. private bool CustomizeShapeEdit(ShapeInfo info, string type)
  106. {
  107. var v = _StationManager.AddOrRemoveCustomizeShape(info, type);
  108. if (v != "success")
  109. {
  110. MessageWindow.ShowMessage(v);
  111. return false;
  112. }
  113. return true;
  114. }
  115. public static void ShowWindow()
  116. {
  117. SubStationManageWindow ssmw = new SubStationManageWindow();
  118. ssmw.Owner = Application.Current.MainWindow;
  119. ssmw.ShowDialog();
  120. }
  121. }
  122. }