MapForm.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using IntelligentControlForsx.Service;
  11. using IntelligentControlForsx.Template;
  12. using log4net;
  13. using IntelligentControlForsx.MyControls.zm.map;
  14. namespace IntelligentControlForsx.ChildForms
  15. {
  16. public partial class MapForm : TemplateForm
  17. {
  18. public MapForm()
  19. {
  20. InitializeComponent();
  21. SetStyle(ControlStyles.UserPaint, true);
  22. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.  
  23. SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲  
  24. this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  25. this.UpdateStyles();
  26. // 动态添加控件和关联事件
  27. // 自定义label title
  28. this.lbTitle.AutoSize = true;
  29. this.lbTitle.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  30. this.lbTitle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(184)))), ((int)(((byte)(250)))));
  31. this.lbTitle.Location = new System.Drawing.Point(3, 11);
  32. this.lbTitle.Name = "lbTitle";
  33. this.lbTitle.Size = new System.Drawing.Size(138, 22);
  34. this.lbTitle.TabIndex = 1;
  35. this.lbTitle.Text = "风机排布图";
  36. Init();
  37. }
  38. Label lbTitle = new Label();// title
  39. Dictionary<int, MapControl> dicProjectMap = new Dictionary<int, MapControl>();
  40. int currentIndex = 1;//第几期工程图
  41. string currentStationID = "";
  42. private static ILog logger = LogManager.GetLogger("AppInfoLog");
  43. private Label cashLabel = null;
  44. private void Init()
  45. {
  46. if (dicProjectMap.ContainsKey(currentIndex))
  47. {
  48. dicProjectMap[currentIndex].DeActive();
  49. }
  50. flowLayout.Controls.Clear();// TOP
  51. dicProjectMap.Clear();
  52. plCenter.Controls.Clear();//Center
  53. flowLayout.Controls.Add(lbTitle);
  54. currentStationID = NavService.Instance.StationId;
  55. // 自定义项目数量项目一...
  56. switch (NavService.Instance.StationId)
  57. {
  58. #region 根据风机站的ID动态创建对应的控件
  59. case "NSS_FDC"://牛首山
  60. {
  61. #region 牛首山相关控件
  62. this.Text = "牛首山风机排布图";
  63. this.lbTitle.Text = "牛首山风机排布图";
  64. flowLayout.Controls.Add(this.lbTitle);
  65. NSS_Project1 p1 = new NSS_Project1();
  66. NSS_Project2 p2 = new NSS_Project2();
  67. NSS_Project3 p3 = new NSS_Project3();
  68. dicProjectMap.Add(1, p1);
  69. dicProjectMap.Add(2, p2);
  70. dicProjectMap.Add(3, p3);
  71. Panel pal1 = new Panel();
  72. Panel pal2 = new Panel();
  73. Panel pal3 = new Panel();
  74. Label lb1 = new Label();
  75. Label lb2 = new Label();
  76. Label lb3 = new Label();
  77. lb1.Text = "一 期";
  78. lb1.Tag = 1;
  79. lb2.Text = "二 期";
  80. lb2.Tag = 2;
  81. lb3.Text = "三 期";
  82. lb3.Tag = 3;
  83. pal1.Controls.Add(lb1);
  84. pal2.Controls.Add(lb2);
  85. pal3.Controls.Add(lb3);
  86. flowLayout.Controls.Add(pal1);
  87. flowLayout.Controls.Add(pal2);
  88. flowLayout.Controls.Add(pal3);
  89. #endregion
  90. }
  91. break;
  92. case "SBQ_FDC"://石板泉
  93. {
  94. #region
  95. this.Text = "石板泉风机排布图";
  96. this.lbTitle.Text = "石板泉风机排布图";
  97. flowLayout.Controls.Add(this.lbTitle);
  98. SBQ_Project1 p1 = new SBQ_Project1();
  99. SBQ_Project2 p2 = new SBQ_Project2();
  100. SBQ_Project3 p3 = new SBQ_Project3();
  101. SBQ_Project4 p4 = new SBQ_Project4();
  102. dicProjectMap.Add(1, p1);
  103. dicProjectMap.Add(2, p2);
  104. dicProjectMap.Add(3, p3);
  105. dicProjectMap.Add(4, p4);
  106. Panel pal1 = new Panel();
  107. Panel pal2 = new Panel();
  108. Panel pal3 = new Panel();
  109. Panel pal4 = new Panel();
  110. Label lb1 = new Label();
  111. Label lb2 = new Label();
  112. Label lb3 = new Label();
  113. Label lb4 = new Label();
  114. lb1.Text = "一 期";
  115. lb1.Tag = 1;
  116. lb2.Text = "二 期";
  117. lb2.Tag = 2;
  118. lb3.Text = "三 期";
  119. lb3.Tag = 3;
  120. lb4.Text = "四 期";
  121. lb4.Tag = 4;
  122. pal1.Controls.Add(lb1);
  123. pal2.Controls.Add(lb2);
  124. pal3.Controls.Add(lb3);
  125. pal4.Controls.Add(lb4);
  126. flowLayout.Controls.Add(pal1);
  127. flowLayout.Controls.Add(pal2);
  128. flowLayout.Controls.Add(pal3);
  129. flowLayout.Controls.Add(pal4);
  130. #endregion
  131. }
  132. break;
  133. case "MHS_FDC"://麻黄山
  134. {
  135. #region
  136. this.Text = "麻黄山风机排布图";
  137. this.lbTitle.Text = "麻黄山风机排布图";
  138. flowLayout.Controls.Add(this.lbTitle);
  139. MHS_Project1 p1 = new MHS_Project1();
  140. MHS_Project2 p2 = new MHS_Project2();
  141. dicProjectMap.Add(1, p1);
  142. dicProjectMap.Add(2, p2);
  143. Panel pal1 = new Panel();
  144. Panel pal2 = new Panel();
  145. Label lb1 = new Label();
  146. Label lb2 = new Label();
  147. lb1.Text = "一 期";
  148. lb1.Tag = 1;
  149. lb2.Text = "二 期";
  150. lb2.Tag = 2;
  151. pal1.Controls.Add(lb1);
  152. pal2.Controls.Add(lb2);
  153. flowLayout.Controls.Add(pal1);
  154. flowLayout.Controls.Add(pal2);
  155. #endregion
  156. }
  157. break;
  158. case "QS_FDC"://青山
  159. {
  160. #region
  161. this.Text = "青山风机排布图";
  162. this.lbTitle.Text = "青山风机排布图";
  163. flowLayout.Controls.Add(this.lbTitle);
  164. QS_Project1 p1 = new QS_Project1();
  165. QS_Project2 p2 = new QS_Project2();
  166. dicProjectMap.Add(1, p1);
  167. dicProjectMap.Add(2, p2);
  168. Panel pal1 = new Panel();
  169. Panel pal2 = new Panel();
  170. Label lb1 = new Label();
  171. Label lb2 = new Label();
  172. lb1.Text = "一 期";
  173. lb1.Tag = 1;
  174. lb2.Text = "二 期";
  175. lb2.Tag = 2;
  176. pal1.Controls.Add(lb1);
  177. pal2.Controls.Add(lb2);
  178. flowLayout.Controls.Add(pal1);
  179. flowLayout.Controls.Add(pal2);
  180. #endregion
  181. }
  182. break;
  183. case "XS_FDC"://香山
  184. {
  185. #region
  186. this.Text = "青山风机排布图";
  187. this.lbTitle.Text = "青山风机排布图";
  188. flowLayout.Controls.Add(this.lbTitle);
  189. XS_Project1 p1 = new XS_Project1();
  190. XS_Project2 p2 = new XS_Project2();
  191. dicProjectMap.Add(1, p1);
  192. dicProjectMap.Add(2, p2);
  193. Panel pal1 = new Panel();
  194. Panel pal2 = new Panel();
  195. Label lb1 = new Label();
  196. Label lb2 = new Label();
  197. lb1.Text = "一 期";
  198. lb1.Tag = 1;
  199. lb2.Text = "二 期";
  200. lb2.Tag = 2;
  201. pal1.Controls.Add(lb1);
  202. pal2.Controls.Add(lb2);
  203. flowLayout.Controls.Add(pal1);
  204. flowLayout.Controls.Add(pal2);
  205. #endregion
  206. }
  207. break;
  208. default:
  209. {
  210. currentIndex = 1;
  211. return;
  212. }
  213. #endregion
  214. }
  215. currentIndex = 1;
  216. #region 顶部标题样式设置
  217. foreach (var c in flowLayout.Controls)
  218. {
  219. if (c is Panel)
  220. {
  221. Panel panel = c as Panel;
  222. panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(184)))), ((int)(((byte)(250)))));
  223. panel.Location = new System.Drawing.Point(260, 1);
  224. panel.Name = "panel4";
  225. panel.Size = new System.Drawing.Size(80, 36);
  226. #region 多期工程标题样式设置
  227. foreach (var l in panel.Controls)
  228. {
  229. if (l is Label)
  230. {
  231. Label la = l as Label;
  232. la.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  233. if ((int)la.Tag == currentIndex)
  234. {
  235. la.ForeColor = Color.FromArgb(15, 45, 74);
  236. la.BackColor = Color.FromArgb(48, 184, 250);
  237. cashLabel = la;
  238. }
  239. else
  240. {
  241. la.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(184)))), ((int)(((byte)(250)))));
  242. la.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(15)))), ((int)(((byte)(45)))), ((int)(((byte)(74)))));
  243. }
  244. la.Location = new System.Drawing.Point(1, 1);
  245. la.Size = new System.Drawing.Size(78, 34);
  246. la.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  247. la.Click += new System.EventHandler(this.lblProject_Click);
  248. la.MouseEnter += new System.EventHandler(this.lblProject_MouseEnter);
  249. la.MouseLeave += new System.EventHandler(this.lblProject_MouseLeave);
  250. }
  251. }
  252. #endregion
  253. }
  254. }
  255. #endregion
  256. #region 中间地图模块的样式设置
  257. foreach (MapControl c in dicProjectMap.Values)// 设置map控件的属性
  258. {
  259. c.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  260. c.Location = new System.Drawing.Point(1, 1);
  261. c.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
  262. c.Size = new System.Drawing.Size(1918, 926);
  263. }
  264. #endregion
  265. // 将项目一展示出来
  266. if (dicProjectMap.Count>0&&dicProjectMap[currentIndex] !=null)//
  267. {
  268. plCenter.Hide();
  269. plCenter.Controls.Add(dicProjectMap[currentIndex]);
  270. dicProjectMap[currentIndex].Active();
  271. plCenter.Show();
  272. }
  273. }
  274. public override void Active()
  275. {
  276. // 此处切换
  277. if (NavService.Instance.StationId == currentStationID)
  278. {
  279. this.Show();
  280. }
  281. else
  282. {
  283. Init();
  284. this.Show();
  285. }
  286. }
  287. public override void DeActive()
  288. {
  289. foreach (MapControl c in dicProjectMap.Values)
  290. {
  291. c.DeActive();
  292. }
  293. this.Hide();
  294. }
  295. private void lblProject_Click(object sender, EventArgs e)
  296. {
  297. Label currentLabel = (Label)sender;
  298. int pointIndex =(int) currentLabel.Tag;
  299. if(pointIndex== currentIndex)
  300. {
  301. return;
  302. }
  303. cashLabel.BackColor = Color.FromArgb(15, 45, 74);
  304. cashLabel.ForeColor = Color.FromArgb(48, 184, 250);
  305. cashLabel = currentLabel;
  306. if (dicProjectMap.ContainsKey(currentIndex))
  307. {
  308. plCenter.Hide();
  309. dicProjectMap[currentIndex].DeActive();
  310. plCenter.Controls.Clear();
  311. plCenter.Controls.Add(dicProjectMap[pointIndex]);
  312. currentIndex = pointIndex;
  313. dicProjectMap[pointIndex].Active();
  314. plCenter.Show();
  315. }
  316. }
  317. private void lblProject_MouseEnter(object sender, EventArgs e)
  318. {
  319. if (!this.DesignMode)
  320. {
  321. Label currentLabel = (Label)sender;
  322. int pointIndex = (int)currentLabel.Tag;
  323. if (pointIndex != currentIndex)
  324. {
  325. currentLabel.ForeColor = Color.FromArgb(15, 45, 74);
  326. currentLabel.BackColor = Color.FromArgb(48, 184, 250);
  327. }
  328. }
  329. }
  330. private void lblProject_MouseLeave(object sender, EventArgs e)
  331. {
  332. if (!this.DesignMode)
  333. {
  334. Label currentLabel = (Label)sender;
  335. int pointIndex = (int)currentLabel.Tag;
  336. if (pointIndex != currentIndex)
  337. {
  338. currentLabel.BackColor = Color.FromArgb(15, 45, 74);
  339. currentLabel.ForeColor = Color.FromArgb(48, 184, 250);
  340. }
  341. }
  342. }
  343. private void btnReturn_Click(object sender, EventArgs e)
  344. {
  345. NavService.Instance.StationId = currentStationID;
  346. NavService.Instance.Nav("ZMForm", (MainWindow)this.Parent.Parent);
  347. }
  348. public override void SelectedStationChanged(string stationId)
  349. {
  350. NavService.Instance.StationId = stationId;
  351. if (currentStationID == NavService.Instance.StationId)
  352. {
  353. this.Show();
  354. return;
  355. }
  356. else
  357. {
  358. Init();
  359. this.Show();
  360. }
  361. }
  362. }
  363. }