NavService.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. using IntelligentControlForsx.ChildForms;
  8. using IntelligentControlForsx.MyControls;
  9. using IntelligentControlForsx.Template;
  10. namespace IntelligentControlForsx.Service
  11. {
  12. public class NavService
  13. {
  14. private TemplateForm currentForm;
  15. //原标题
  16. //public static Title title = null;
  17. //仅风机控制页标题
  18. public static Title title = null;
  19. public static Bottom projectBottom = null;
  20. public static Bottom2 projectBottom2 = null;
  21. public Dictionary<String, TemplateForm> dictForm;
  22. private static MainWindow projectMDIParentForm = null;
  23. private NavService()
  24. {
  25. dictForm = new Dictionary<string, TemplateForm>();
  26. dictForm.Add("pictureBoxStatistics", null);
  27. dictForm.Add("pictureBoxMainParam", null);
  28. dictForm.Add("pictureBoxHome", null);
  29. dictForm.Add("pictureBoxMatrix", null);
  30. dictForm.Add("pictureBoxControl", null);
  31. dictForm.Add("pictureBoxParamters", null);
  32. dictForm.Add("pictureBoxElectrical", null);
  33. dictForm.Add("pictureBoxFault", null);
  34. dictForm.Add("pictureBoxAGC", null);
  35. dictForm.Add("pictureBoxSYZ", null);
  36. dictForm.Add("ZMForm", null);
  37. dictForm.Add("MapForm", null);
  38. }
  39. public static NavService Instance
  40. {
  41. get { return SingletonCreator.instance; }
  42. }
  43. class SingletonCreator
  44. {
  45. internal static readonly NavService instance = new NavService();
  46. }
  47. public List<TemplateForm> GetAllForm()
  48. {
  49. return new List<TemplateForm>();
  50. }
  51. public void Nav(String formName, MainWindow mdiParentForm)
  52. {
  53. if (String.IsNullOrWhiteSpace(formName))
  54. return;
  55. if (projectMDIParentForm == null)
  56. projectMDIParentForm = mdiParentForm;
  57. if (dictForm.ContainsKey(formName))
  58. {
  59. TemplateForm form = dictForm[formName];
  60. if (form == null)
  61. {
  62. form = CreateForm(formName, mdiParentForm);
  63. dictForm[formName] = form;
  64. }
  65. Nav(form, mdiParentForm);
  66. }
  67. }
  68. private string stationId = "SBQ_FDC";
  69. public string StationId
  70. {
  71. get
  72. {
  73. return stationId;
  74. }
  75. set
  76. {
  77. stationId = value;
  78. }
  79. }
  80. public void StationSelectedChanged(String stationId)
  81. {
  82. this.stationId = stationId;
  83. if (currentForm != null)
  84. currentForm.SelectedStationChanged(stationId);
  85. }
  86. private TemplateForm CreateForm(String formName, MainWindow mdiParentForm)
  87. {
  88. if (projectMDIParentForm == null)
  89. projectMDIParentForm = mdiParentForm;
  90. TemplateForm form = null;
  91. switch (formName)
  92. {
  93. case "pictureBoxHome":
  94. form = new HomeForm();
  95. form.MdiParent = mdiParentForm;
  96. form.Parent = mdiParentForm.panel1;
  97. form.Dock = DockStyle.Fill;
  98. break;
  99. case "pictureBoxMatrix":
  100. form = new MatrixForm();
  101. form.MdiParent = mdiParentForm;
  102. form.Parent = mdiParentForm.panel1;
  103. form.Dock = DockStyle.Fill;
  104. break;
  105. case "pictureBoxStatistics":
  106. form = new StatForm();
  107. form.MdiParent = mdiParentForm;
  108. form.Parent = mdiParentForm.panel1;
  109. form.Dock = DockStyle.Fill;
  110. break;
  111. case "pictureBoxMainParam":
  112. form = new ParamsForm();
  113. form.MdiParent = mdiParentForm;
  114. form.Parent = mdiParentForm.panel1;
  115. form.Dock = DockStyle.Fill;
  116. break;
  117. case "pictureBoxParamters":
  118. form = new WindturbineForm();
  119. form.MdiParent = mdiParentForm;
  120. form.Parent = mdiParentForm.panel1;
  121. form.Dock = DockStyle.Fill;
  122. break;
  123. //case "pictureBoxControl":
  124. // //form = new ControlForm2();
  125. // //form.MdiParent = mdiParentForm;
  126. // //form.Parent = mdiParentForm.panel1;
  127. // //form.Dock = DockStyle.Fill;
  128. // form = new CleverControlForm();
  129. // form.MdiParent = mdiParentForm;
  130. // form.Parent = mdiParentForm.panel1;
  131. // form.Dock = DockStyle.Fill;
  132. // break;
  133. case "pictureBoxSYZ":
  134. form = new ElectricalForm();
  135. form.MdiParent = mdiParentForm;
  136. form.Parent = mdiParentForm.panel1;
  137. form.Dock = DockStyle.Fill;
  138. break;
  139. case "pictureBoxFault":
  140. form = new AlarmForm();
  141. form.MdiParent = mdiParentForm;
  142. form.Parent = mdiParentForm.panel1;
  143. form.Dock = DockStyle.Fill;
  144. break;
  145. case "pictureBoxAGC":
  146. form = new AGCForm();
  147. form.MdiParent = mdiParentForm;
  148. form.Parent = mdiParentForm.panel1;
  149. form.Dock = DockStyle.Fill;
  150. break;
  151. case "ZMForm":
  152. {
  153. form = new ZMForm();
  154. form.MdiParent = mdiParentForm;
  155. form.Parent = mdiParentForm.panel1;
  156. form.Dock = DockStyle.Fill;
  157. //form = new ZMForm();
  158. //form.MdiParent = mdiParentForm;
  159. //form.Parent = mdiParentForm.panel1;
  160. //form.Dock = DockStyle.Fill;
  161. }
  162. break;
  163. case "MapForm":
  164. {
  165. form = new MapForm();
  166. //form = new MapForm();
  167. form.MdiParent = mdiParentForm;
  168. form.Parent = mdiParentForm.panel1;
  169. form.Dock = DockStyle.Fill;
  170. }
  171. break;
  172. default:
  173. break;
  174. }
  175. return form;
  176. }
  177. private void Nav(TemplateForm form, MainWindow mdiParent)
  178. {
  179. if (currentForm != null)
  180. currentForm.DeActive();
  181. form.Active();
  182. currentForm = form;
  183. }
  184. //提供从风场总貌图 风机跳转到风机参数页面
  185. public void NavForWindturbine(String formName, string windturbineId, string stationId)
  186. {
  187. this.stationId = stationId;
  188. if (projectBottom != null)
  189. projectBottom.StationChange(stationId);
  190. if (String.IsNullOrWhiteSpace(formName))
  191. return;
  192. if (dictForm.ContainsKey(formName))
  193. {
  194. TemplateForm form = dictForm[formName];
  195. if (form == null)
  196. {
  197. if (projectMDIParentForm != null)
  198. {
  199. form = CreateForm(formName, projectMDIParentForm);
  200. dictForm[formName] = form;
  201. }
  202. }
  203. WindturbineForm fm = (WindturbineForm)form;
  204. fm.SetNowWindturbineId(windturbineId, stationId);
  205. Nav(form, projectMDIParentForm);
  206. if (title != null)
  207. {
  208. title.StyleImgChange("pictureBoxParamters");
  209. }
  210. }
  211. }
  212. public void NavForMap(string formName, string stationId)
  213. {
  214. if (String.IsNullOrWhiteSpace(formName))
  215. return;
  216. if (dictForm.ContainsKey(formName))
  217. {
  218. TemplateForm form = dictForm[formName];
  219. if (form == null)
  220. {
  221. if (projectMDIParentForm != null)
  222. {
  223. form = CreateForm(formName, projectMDIParentForm);
  224. dictForm[formName] = form;
  225. }
  226. }
  227. NavService.Instance.StationId = stationId;
  228. MapForm fm = form as MapForm;
  229. Nav(form, projectMDIParentForm);
  230. }
  231. }
  232. public void NavForElectrical(string formName, string StationId)
  233. {
  234. if (title != null)
  235. title.StyleImgChange("pictureBoxSYZ");
  236. if (String.IsNullOrWhiteSpace(formName))
  237. return;
  238. if (dictForm.ContainsKey(formName))
  239. {
  240. TemplateForm form = dictForm[formName];
  241. if (form == null)
  242. {
  243. if (projectMDIParentForm != null)
  244. {
  245. form = CreateForm(formName, projectMDIParentForm);
  246. dictForm[formName] = form;
  247. }
  248. }
  249. try
  250. {
  251. ElectricalForm eForm = (ElectricalForm)form;
  252. eForm.StationId = stationId;
  253. }
  254. catch (Exception ex)
  255. {
  256. throw;
  257. }
  258. finally
  259. {
  260. Nav(form, projectMDIParentForm);
  261. }
  262. }
  263. }
  264. }
  265. }