using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using IntelligentControlForsx.Service; using IntelligentControlForsx.Template; using log4net; using IntelligentControlForsx.MyControls.zm.map; namespace IntelligentControlForsx.ChildForms { public partial class MapForm : TemplateForm { public MapForm() { InitializeComponent(); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.   SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲   this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); this.UpdateStyles(); // 动态添加控件和关联事件 // 自定义label title this.lbTitle.AutoSize = true; this.lbTitle.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.lbTitle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(184)))), ((int)(((byte)(250))))); this.lbTitle.Location = new System.Drawing.Point(3, 11); this.lbTitle.Name = "lbTitle"; this.lbTitle.Size = new System.Drawing.Size(138, 22); this.lbTitle.TabIndex = 1; this.lbTitle.Text = "风机排布图"; Init(); } Label lbTitle = new Label();// title Dictionary dicProjectMap = new Dictionary(); int currentIndex = 1;//第几期工程图 string currentStationID = ""; private static ILog logger = LogManager.GetLogger("AppInfoLog"); private Label cashLabel = null; private void Init() { if (dicProjectMap.ContainsKey(currentIndex)) { dicProjectMap[currentIndex].DeActive(); } flowLayout.Controls.Clear();// TOP dicProjectMap.Clear(); plCenter.Controls.Clear();//Center flowLayout.Controls.Add(lbTitle); currentStationID = NavService.Instance.StationId; // 自定义项目数量项目一... switch (NavService.Instance.StationId) { #region 根据风机站的ID动态创建对应的控件 case "NSS_FDC"://牛首山 { #region 牛首山相关控件 this.Text = "牛首山风机排布图"; this.lbTitle.Text = "牛首山风机排布图"; flowLayout.Controls.Add(this.lbTitle); NSS_Project1 p1 = new NSS_Project1(); NSS_Project2 p2 = new NSS_Project2(); NSS_Project3 p3 = new NSS_Project3(); dicProjectMap.Add(1, p1); dicProjectMap.Add(2, p2); dicProjectMap.Add(3, p3); Panel pal1 = new Panel(); Panel pal2 = new Panel(); Panel pal3 = new Panel(); Label lb1 = new Label(); Label lb2 = new Label(); Label lb3 = new Label(); lb1.Text = "一 期"; lb1.Tag = 1; lb2.Text = "二 期"; lb2.Tag = 2; lb3.Text = "三 期"; lb3.Tag = 3; pal1.Controls.Add(lb1); pal2.Controls.Add(lb2); pal3.Controls.Add(lb3); flowLayout.Controls.Add(pal1); flowLayout.Controls.Add(pal2); flowLayout.Controls.Add(pal3); #endregion } break; case "SBQ_FDC"://石板泉 { #region this.Text = "石板泉风机排布图"; this.lbTitle.Text = "石板泉风机排布图"; flowLayout.Controls.Add(this.lbTitle); SBQ_Project1 p1 = new SBQ_Project1(); SBQ_Project2 p2 = new SBQ_Project2(); SBQ_Project3 p3 = new SBQ_Project3(); SBQ_Project4 p4 = new SBQ_Project4(); dicProjectMap.Add(1, p1); dicProjectMap.Add(2, p2); dicProjectMap.Add(3, p3); dicProjectMap.Add(4, p4); Panel pal1 = new Panel(); Panel pal2 = new Panel(); Panel pal3 = new Panel(); Panel pal4 = new Panel(); Label lb1 = new Label(); Label lb2 = new Label(); Label lb3 = new Label(); Label lb4 = new Label(); lb1.Text = "一 期"; lb1.Tag = 1; lb2.Text = "二 期"; lb2.Tag = 2; lb3.Text = "三 期"; lb3.Tag = 3; lb4.Text = "四 期"; lb4.Tag = 4; pal1.Controls.Add(lb1); pal2.Controls.Add(lb2); pal3.Controls.Add(lb3); pal4.Controls.Add(lb4); flowLayout.Controls.Add(pal1); flowLayout.Controls.Add(pal2); flowLayout.Controls.Add(pal3); flowLayout.Controls.Add(pal4); #endregion } break; case "MHS_FDC"://麻黄山 { #region this.Text = "麻黄山风机排布图"; this.lbTitle.Text = "麻黄山风机排布图"; flowLayout.Controls.Add(this.lbTitle); MHS_Project1 p1 = new MHS_Project1(); MHS_Project2 p2 = new MHS_Project2(); dicProjectMap.Add(1, p1); dicProjectMap.Add(2, p2); Panel pal1 = new Panel(); Panel pal2 = new Panel(); Label lb1 = new Label(); Label lb2 = new Label(); lb1.Text = "一 期"; lb1.Tag = 1; lb2.Text = "二 期"; lb2.Tag = 2; pal1.Controls.Add(lb1); pal2.Controls.Add(lb2); flowLayout.Controls.Add(pal1); flowLayout.Controls.Add(pal2); #endregion } break; case "QS_FDC"://青山 { #region this.Text = "青山风机排布图"; this.lbTitle.Text = "青山风机排布图"; flowLayout.Controls.Add(this.lbTitle); QS_Project1 p1 = new QS_Project1(); QS_Project2 p2 = new QS_Project2(); dicProjectMap.Add(1, p1); dicProjectMap.Add(2, p2); Panel pal1 = new Panel(); Panel pal2 = new Panel(); Label lb1 = new Label(); Label lb2 = new Label(); lb1.Text = "一 期"; lb1.Tag = 1; lb2.Text = "二 期"; lb2.Tag = 2; pal1.Controls.Add(lb1); pal2.Controls.Add(lb2); flowLayout.Controls.Add(pal1); flowLayout.Controls.Add(pal2); #endregion } break; case "XS_FDC"://香山 { #region this.Text = "青山风机排布图"; this.lbTitle.Text = "青山风机排布图"; flowLayout.Controls.Add(this.lbTitle); XS_Project1 p1 = new XS_Project1(); XS_Project2 p2 = new XS_Project2(); dicProjectMap.Add(1, p1); dicProjectMap.Add(2, p2); Panel pal1 = new Panel(); Panel pal2 = new Panel(); Label lb1 = new Label(); Label lb2 = new Label(); lb1.Text = "一 期"; lb1.Tag = 1; lb2.Text = "二 期"; lb2.Tag = 2; pal1.Controls.Add(lb1); pal2.Controls.Add(lb2); flowLayout.Controls.Add(pal1); flowLayout.Controls.Add(pal2); #endregion } break; default: { currentIndex = 1; return; } #endregion } currentIndex = 1; #region 顶部标题样式设置 foreach (var c in flowLayout.Controls) { if (c is Panel) { Panel panel = c as Panel; panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(184)))), ((int)(((byte)(250))))); panel.Location = new System.Drawing.Point(260, 1); panel.Name = "panel4"; panel.Size = new System.Drawing.Size(80, 36); #region 多期工程标题样式设置 foreach (var l in panel.Controls) { if (l is Label) { Label la = l as Label; la.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); if ((int)la.Tag == currentIndex) { la.ForeColor = Color.FromArgb(15, 45, 74); la.BackColor = Color.FromArgb(48, 184, 250); cashLabel = la; } else { la.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(184)))), ((int)(((byte)(250))))); la.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(15)))), ((int)(((byte)(45)))), ((int)(((byte)(74))))); } la.Location = new System.Drawing.Point(1, 1); la.Size = new System.Drawing.Size(78, 34); la.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; la.Click += new System.EventHandler(this.lblProject_Click); la.MouseEnter += new System.EventHandler(this.lblProject_MouseEnter); la.MouseLeave += new System.EventHandler(this.lblProject_MouseLeave); } } #endregion } } #endregion #region 中间地图模块的样式设置 foreach (MapControl c in dicProjectMap.Values)// 设置map控件的属性 { c.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); c.Location = new System.Drawing.Point(1, 1); c.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); c.Size = new System.Drawing.Size(1918, 926); } #endregion // 将项目一展示出来 if (dicProjectMap.Count>0&&dicProjectMap[currentIndex] !=null)// { plCenter.Hide(); plCenter.Controls.Add(dicProjectMap[currentIndex]); dicProjectMap[currentIndex].Active(); plCenter.Show(); } } public override void Active() { // 此处切换 if (NavService.Instance.StationId == currentStationID) { this.Show(); } else { Init(); this.Show(); } } public override void DeActive() { foreach (MapControl c in dicProjectMap.Values) { c.DeActive(); } this.Hide(); } private void lblProject_Click(object sender, EventArgs e) { Label currentLabel = (Label)sender; int pointIndex =(int) currentLabel.Tag; if(pointIndex== currentIndex) { return; } cashLabel.BackColor = Color.FromArgb(15, 45, 74); cashLabel.ForeColor = Color.FromArgb(48, 184, 250); cashLabel = currentLabel; if (dicProjectMap.ContainsKey(currentIndex)) { plCenter.Hide(); dicProjectMap[currentIndex].DeActive(); plCenter.Controls.Clear(); plCenter.Controls.Add(dicProjectMap[pointIndex]); currentIndex = pointIndex; dicProjectMap[pointIndex].Active(); plCenter.Show(); } } private void lblProject_MouseEnter(object sender, EventArgs e) { if (!this.DesignMode) { Label currentLabel = (Label)sender; int pointIndex = (int)currentLabel.Tag; if (pointIndex != currentIndex) { currentLabel.ForeColor = Color.FromArgb(15, 45, 74); currentLabel.BackColor = Color.FromArgb(48, 184, 250); } } } private void lblProject_MouseLeave(object sender, EventArgs e) { if (!this.DesignMode) { Label currentLabel = (Label)sender; int pointIndex = (int)currentLabel.Tag; if (pointIndex != currentIndex) { currentLabel.BackColor = Color.FromArgb(15, 45, 74); currentLabel.ForeColor = Color.FromArgb(48, 184, 250); } } } private void btnReturn_Click(object sender, EventArgs e) { NavService.Instance.StationId = currentStationID; NavService.Instance.Nav("ZMForm", (MainWindow)this.Parent.Parent); } public override void SelectedStationChanged(string stationId) { NavService.Instance.StationId = stationId; if (currentStationID == NavService.Instance.StationId) { this.Show(); return; } else { Init(); this.Show(); } } } }