YuJing.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. public YuJing() : base()
  15. {
  16. this.ConditionPanelName = "预警分析";
  17. var analystToolStripButton = new ToolStripButton()
  18. {
  19. DisplayStyle = ToolStripItemDisplayStyle.ImageAndText,
  20. Text = "开始分析",
  21. Name = "Analyst",
  22. AutoToolTip = false
  23. };
  24. base.ToolStrip.Items.Add(analystToolStripButton);
  25. analystToolStripButton.Click += AnalystToolStripButton_Click;
  26. }
  27. private void AnalystToolStripButton_Click(object sender, EventArgs e)
  28. {
  29. int index = MapControl.Map.TrackingLayer.IndexOf(ComsStatic.ControlToolsTrackingName);
  30. if (index == -1)
  31. {
  32. Sunny.UI.UIMessageTip.ShowError("请先绘制区域"); return;
  33. }
  34. GeoRegion geo = MapControl.Map.TrackingLayer.Get(index) as GeoRegion;
  35. Recordset rdJSLK = ComsStatic.gsGuanXian.Query(geo, 1, " enabled=1 ", CursorType.Static);
  36. if (rdJSLK.IsEmpty) { Sunny.UI.UIMessageTip.ShowError("当前区域内没有查询到数据"); return; }
  37. DataTable dt = ComsStatic.RecordsetToDataTable(rdJSLK);
  38. DataTable dtNew = dt.DefaultView.ToTable(false, new string[] { "smid", "bsm", "qsdh", "zddh", "lx", "cz", "gj", "cd", "dzms", "msfs", "msrq", "qsdw" });
  39. dtNew.Columns.Add(new DataColumn { ColumnName = "nxyj", Caption = "预警年限" }); dtNew.Columns["nxyj"].SetOrdinal(0);
  40. dtNew.Columns.Add(new DataColumn { ColumnName = "nxbz", Caption = "标准使用年限" }); dtNew.Columns["nxbz"].SetOrdinal(1);
  41. DataTable dtChaoChu = dtNew.Clone();
  42. DataTable dtQueShao = dtNew.Clone();
  43. DataTable dtYuJing = dtNew.Clone();
  44. Dictionary<string, object> dic = ComsStatic.getGuanXianPeiZhi("年限预警配置");
  45. string dicKey1 = "";
  46. string dicKey2 = "";
  47. int NianXianYuJing = 0;
  48. int NianXianBiaoZhun = 0;
  49. foreach (DataRow dr in dtNew.Rows)
  50. {
  51. NianXianYuJing = 0; NianXianBiaoZhun = 0;
  52. dicKey1 = dr["cz"].ToString() + "_gxyjnx";
  53. dicKey2 = dr["cz"].ToString() + "_gxbznx";
  54. if (dic.ContainsKey(dicKey1)) NianXianYuJing = ComsStatic.StringToInt(dic[dicKey1]);
  55. if (dic.ContainsKey(dicKey2)) NianXianBiaoZhun = ComsStatic.StringToInt(dic[dicKey2]);
  56. if (NianXianYuJing == 0 || NianXianBiaoZhun == 0)
  57. {
  58. dtQueShao.ImportRow(dr); continue;
  59. }
  60. dr["nxyj"] = NianXianYuJing; dr["nxbz"] = NianXianBiaoZhun;
  61. DateTime msrq = DateTime.Parse(dr["msrq"].ToString());
  62. //已经超过 标准年限
  63. if (DateTime.Now > msrq.AddYears(NianXianBiaoZhun))
  64. dtChaoChu.ImportRow(dr);
  65. //超过预警年限 未达到标准年限
  66. if (DateTime.Now > msrq.AddYears(NianXianYuJing) && DateTime.Now < msrq.AddYears(NianXianBiaoZhun))
  67. dtYuJing.ImportRow(dr);
  68. }
  69. DataSet ds = new DataSet();
  70. dtYuJing.TableName = string.Format("达到预警年限 {0}根", dtYuJing.Rows.Count); ds.Tables.Add(dtYuJing);
  71. dtChaoChu.TableName = string.Format("超出使用年限 {0}根", dtChaoChu.Rows.Count); ds.Tables.Add(dtChaoChu);
  72. dtQueShao.TableName = string.Format("缺少配置预警 {0}根", dtQueShao.Rows.Count); ds.Tables.Add(dtQueShao);
  73. AnalystResultTabControl from = new AnalystResultTabControl(ds, "预警分析结果");
  74. from.ShowDialog();
  75. this.CloseToolBar();
  76. }
  77. protected override void OnLoad(EventArgs e)
  78. {
  79. MapControl.Action = SuperMap.UI.Action.CreatePolygon;
  80. MapControl.Tracked += ComsStatic.MapControl_Tracked_TrackingName;
  81. }
  82. private void InitializeComponent()
  83. {
  84. this.SuspendLayout();
  85. //
  86. // ToolsConditions
  87. //
  88. this.Name = "ToolsConditions";
  89. this.ResumeLayout(false);
  90. }
  91. }
  92. }