using SuperMap.Data; using SuperMap.Mapping; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Windows.Forms; using WWPipeLine.MapBasic; using WWPipeLine.MapBasic.Conditions; namespace WWPipeLine.MapTools.Conditions.AnalystToolBar { public class YuJing : BasicToolBar { public YuJing() : base() { this.ConditionPanelName = "预警分析"; var analystToolStripButton = new ToolStripButton() { DisplayStyle = ToolStripItemDisplayStyle.ImageAndText, Text = "开始分析", Name = "Analyst", AutoToolTip = false }; base.ToolStrip.Items.Add(analystToolStripButton); analystToolStripButton.Click += AnalystToolStripButton_Click; } private void AnalystToolStripButton_Click(object sender, EventArgs e) { int index = MapControl.Map.TrackingLayer.IndexOf(ComsStatic.ControlToolsTrackingName); if (index == -1) { Sunny.UI.UIMessageTip.ShowError("请先绘制区域"); return; } GeoRegion geo = MapControl.Map.TrackingLayer.Get(index) as GeoRegion; Recordset rdJSLK = ComsStatic.gsGuanXian.Query(geo, 1, " enabled=1 ", CursorType.Static); if (rdJSLK.IsEmpty) { Sunny.UI.UIMessageTip.ShowError("当前区域内没有查询到数据"); return; } DataTable dt = ComsStatic.RecordsetToDataTable(rdJSLK); DataTable dtNew = dt.DefaultView.ToTable(false, new string[] { "smid", "bsm", "qsdh", "zddh", "lx", "cz", "gj", "cd", "dzms", "msfs", "msrq", "qsdw" }); dtNew.Columns.Add(new DataColumn { ColumnName = "nxyj", Caption = "预警年限" }); dtNew.Columns["nxyj"].SetOrdinal(0); dtNew.Columns.Add(new DataColumn { ColumnName = "nxbz", Caption = "标准使用年限" }); dtNew.Columns["nxbz"].SetOrdinal(1); DataTable dtChaoChu = dtNew.Clone(); DataTable dtQueShao = dtNew.Clone(); DataTable dtYuJing = dtNew.Clone(); Dictionary dic = ComsStatic.getGuanXianPeiZhi("年限预警配置"); string dicKey1 = ""; string dicKey2 = ""; int NianXianYuJing = 0; int NianXianBiaoZhun = 0; foreach (DataRow dr in dtNew.Rows) { NianXianYuJing = 0; NianXianBiaoZhun = 0; dicKey1 = dr["cz"].ToString() + "_gxyjnx"; dicKey2 = dr["cz"].ToString() + "_gxbznx"; if (dic.ContainsKey(dicKey1)) NianXianYuJing = ComsStatic.StringToInt(dic[dicKey1]); if (dic.ContainsKey(dicKey2)) NianXianBiaoZhun = ComsStatic.StringToInt(dic[dicKey2]); if (NianXianYuJing == 0 || NianXianBiaoZhun == 0) { dtQueShao.ImportRow(dr); continue; } dr["nxyj"] = NianXianYuJing; dr["nxbz"] = NianXianBiaoZhun; DateTime msrq = DateTime.Parse(dr["msrq"].ToString()); //已经超过 标准年限 if (DateTime.Now > msrq.AddYears(NianXianBiaoZhun)) dtChaoChu.ImportRow(dr); //超过预警年限 未达到标准年限 if (DateTime.Now > msrq.AddYears(NianXianYuJing) && DateTime.Now < msrq.AddYears(NianXianBiaoZhun)) dtYuJing.ImportRow(dr); } DataSet ds = new DataSet(); dtYuJing.TableName = string.Format("达到预警年限 {0}根", dtYuJing.Rows.Count); ds.Tables.Add(dtYuJing); dtChaoChu.TableName = string.Format("超出使用年限 {0}根", dtChaoChu.Rows.Count); ds.Tables.Add(dtChaoChu); dtQueShao.TableName = string.Format("缺少配置预警 {0}根", dtQueShao.Rows.Count); ds.Tables.Add(dtQueShao); AnalystResultTabControl from = new AnalystResultTabControl(ds, "预警分析结果"); from.ShowDialog(); this.CloseToolBar(); } protected override void OnLoad(EventArgs e) { MapControl.Action = SuperMap.UI.Action.CreatePolygon; MapControl.Tracked += ComsStatic.MapControl_Tracked_TrackingName; } private void InitializeComponent() { this.SuspendLayout(); // // ToolsConditions // this.Name = "ToolsConditions"; this.ResumeLayout(false); } } }