YuJing.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using SuperMap.Data;
  2. using SuperMap.Mapping;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Windows.Forms;
  8. using WWPipeLine.MapBasic;
  9. using WWPipeLine.MapBasic.Conditions;
  10. namespace WWPipeLine.MapTools.Conditions.AnalystToolBar
  11. {
  12. public class YuJing : BasicToolBar
  13. {
  14. GeoRegion m_geo = null;
  15. public YuJing() : base()
  16. {
  17. this.ConditionPanelName = "预警分析";
  18. var analystToolStripButton = new ToolStripButton()
  19. {
  20. DisplayStyle = ToolStripItemDisplayStyle.ImageAndText,
  21. Text = "开始分析",
  22. Name = "Analyst",
  23. AutoToolTip = false
  24. };
  25. base.ToolStrip.Items.Add(analystToolStripButton);
  26. analystToolStripButton.Click += AnalystToolStripButton_Click;
  27. }
  28. private void AnalystToolStripButton_Click(object sender, EventArgs e)
  29. {
  30. if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("请先绘制预警区域"); return; }
  31. Recordset rdJSLK = ComsStatic.dvJSLK.Query(m_geo, 1, "1=1", CursorType.Static);
  32. if (rdJSLK is null)
  33. {
  34. Sunny.UI.UIMessageTip.ShowError("当前图层没有查询到数据"); return;
  35. }
  36. DataTable dt = MapBasic.ComsStatic.RecordsetToDataTable(rdJSLK);
  37. rdJSLK.Close(); rdJSLK.Dispose();
  38. DataTable dtNew = dt.DefaultView.ToTable(false, new string[] { "smid", "bsm", "qsdh", "zddh", "lx", "cz", "gj", "cd", "dzms", "msfs", "msrq", "qsdw" });
  39. DataColumn dataColumn;
  40. dataColumn = new DataColumn { ColumnName = "nxyj", Caption = "预警年限" }; dtNew.Columns.Add(dataColumn); dtNew.Columns["nxyj"].SetOrdinal(0);
  41. dataColumn = new DataColumn { ColumnName = "nxbz", Caption = "标准使用年限" }; dtNew.Columns.Add(dataColumn); dtNew.Columns["nxbz"].SetOrdinal(1);
  42. DataTable dtChaoChu = dtNew.Clone();
  43. DataTable dtQueShao = dtNew.Clone();
  44. DataTable dtYuJing = dtNew.Clone();
  45. Dictionary<string, object> dic = ComsStatic.getGuanXianPeiZhi("年限预警配置");
  46. string dicKey1 = "";
  47. string dicKey2 = "";
  48. int NianXianYuJing = 0;
  49. int NianXianBiaoZhun = 0;
  50. foreach (DataRow dr in dtNew.Rows)
  51. {
  52. NianXianYuJing = 0; NianXianBiaoZhun = 0;
  53. dicKey1 = dr["cz"].ToString() + "_gxyjnx";
  54. dicKey2 = dr["cz"].ToString() + "_gxbznx";
  55. if (dic.ContainsKey(dicKey1)) NianXianYuJing = ComsStatic.StringToInt(dic[dicKey1]);
  56. if (dic.ContainsKey(dicKey2)) NianXianBiaoZhun = ComsStatic.StringToInt(dic[dicKey2]);
  57. if (NianXianYuJing == 0 || NianXianBiaoZhun == 0)
  58. {
  59. dtQueShao.ImportRow(dr); continue;
  60. }
  61. dr["nxyj"] = NianXianYuJing; dr["nxbz"] = NianXianBiaoZhun;
  62. DateTime msrq = DateTime.Parse(dr["msrq"].ToString());
  63. //已经超过 标准年限
  64. if (DateTime.Now > msrq.AddYears(NianXianBiaoZhun))
  65. dtChaoChu.ImportRow(dr);
  66. //超过预警年限 未达到标准年限
  67. if (DateTime.Now > msrq.AddYears(NianXianYuJing) && DateTime.Now < msrq.AddYears(NianXianBiaoZhun))
  68. dtYuJing.ImportRow(dr);
  69. }
  70. DataSet ds = new DataSet();
  71. dtYuJing.TableName = string.Format("达到预警年限 {0}根", dtYuJing.Rows.Count); ds.Tables.Add(dtYuJing);
  72. dtChaoChu.TableName = string.Format("超出使用年限 {0}根", dtChaoChu.Rows.Count); ds.Tables.Add(dtChaoChu);
  73. dtQueShao.TableName = string.Format("缺少配置预警 {0}根", dtQueShao.Rows.Count); ds.Tables.Add(dtQueShao);
  74. AnalystResultTabControl from = new AnalystResultTabControl(ds, "预警分析结果");
  75. from.ShowDialog();
  76. this.CloseToolBar();
  77. }
  78. private void MapControl_Tracked(object sender, SuperMap.UI.TrackedEventArgs e)
  79. {
  80. if (e.Geometry is null) return;
  81. m_geo = e.Geometry.Clone() as GeoRegion;
  82. if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("查询区域绘制失败"); return; }
  83. m_geo.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate;
  84. MapControl.Map.TrackingLayer.Clear();
  85. MapControl.Map.TrackingLayer.Add(m_geo, "GeoRectangle");
  86. MapControl.Map.Refresh();
  87. }
  88. protected override void OnLoad(EventArgs e)
  89. {
  90. MapControl.Action = SuperMap.UI.Action.CreatePolygon;
  91. MapControl.Tracked += MapControl_Tracked;
  92. }
  93. public override void AfterClose()
  94. {
  95. MapControl.Tracked -= MapControl_Tracked;
  96. base.AfterClose();
  97. }
  98. private void InitializeComponent()
  99. {
  100. this.SuspendLayout();
  101. //
  102. // ToolsConditions
  103. //
  104. this.Name = "ToolsConditions";
  105. this.ResumeLayout(false);
  106. }
  107. }
  108. }