BZGuanWang.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using SuperMap.Data;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Windows.Forms;
  5. using WWPipeLine.MapBasic.Conditions;
  6. using WWPipeLine.MapBasic;
  7. using SuperMap.UI;
  8. using SuperMap.Mapping;
  9. using System.Text;
  10. namespace WWPipeLine.MapTools.Conditions.FuZhuGongJu
  11. {
  12. public class BZGuanWang : BasicToolBar
  13. {
  14. private Recordset m_recordset = null;
  15. private StringBuilder sb = new StringBuilder();
  16. public BZGuanWang() : base()
  17. {
  18. this.ConditionPanelName = "管网标注";
  19. InitializeComponent();
  20. toolStripLB.Text = "先框选需要标注的管线,然后点击“标注信息”完成标注。";
  21. var bzBiaozhu = new ToolStripButton()
  22. {
  23. DisplayStyle = ToolStripItemDisplayStyle.ImageAndText,
  24. Text = "标注信息",
  25. Name = "bzBiaozhu",
  26. AutoToolTip = false
  27. };
  28. var img = Commons.Paths.ApplicationResourcesDir + "\\ToolBar\\标注信息.png";
  29. if (System.IO.File.Exists(img)) bzBiaozhu.Image = System.Drawing.Image.FromFile(img);
  30. base.ToolStrip.Items.Add(bzBiaozhu); bzBiaozhu.Click += bzBiaozhu_Click;
  31. }
  32. private void bzBiaozhu_Click(object sender, EventArgs e)
  33. {
  34. Selection[] m_selection = MapControl.Map.FindSelection(true);
  35. if (m_selection is null || m_selection.Length != 1)
  36. {
  37. Sunny.UI.UIMessageTip.ShowError("没有选中任何管线元素"); return;
  38. }
  39. m_recordset = m_selection[0].ToRecordset();
  40. if (m_recordset.Dataset.Name != ComsStatic.dvJSLK.Name)
  41. {
  42. Sunny.UI.UIMessageTip.ShowError("当前选择图层不是管线图层"); return;
  43. }
  44. QueryParameter queryParameter = new QueryParameter
  45. {
  46. AttributeFilter = string.Format(" pzlx='标注字段配置' AND gxlx='{0}' AND valueEnable=1 ", m_recordset.Dataset.Name),
  47. ResultFields = new string[] { "pzKey", "valueBefore", "valueAfter" },
  48. OrderBy = new string[] { " valueSort asc " },
  49. CursorType = CursorType.Static
  50. };
  51. Recordset rd = ComsStatic.dvJSLK_PZ.Query(queryParameter);
  52. if (rd.RecordCount == 0) { Sunny.UI.UIMessageTip.ShowError("选中的图层未配置标注字段信息"); return; }
  53. GeoLine g;
  54. TextPart m_TextPart = new TextPart();
  55. GeoText geoText = new GeoText();
  56. geoText.TextStyle = ComsStatic.BiaoZhuFengGe();
  57. m_recordset.MoveFirst();
  58. while (!m_recordset.IsEOF)
  59. {
  60. g = m_recordset.GetGeometry() as GeoLine;
  61. m_TextPart.AnchorPoint = g.InnerPoint;
  62. //m_TextPart.Text = string.Format("D{0} {1}M", m_recordset.GetFieldValue("gj"), ComsStatic.StringToDouble(m_recordset.GetFieldValue("cd")), 0);
  63. rd.MoveFirst();
  64. sb.Clear();
  65. while (!rd.IsEOF)
  66. {
  67. string ziduan = rd.GetFieldValue("pzKey").ToString();
  68. if (ComsStatic.HasField(m_recordset, ziduan))
  69. {
  70. sb.AppendFormat("{0}:{1}{2}\r\n", rd.GetFieldValue("valueBefore"), m_recordset.GetFieldValue(ziduan)?.ToString().Split('.')[0], rd.GetFieldValue("valueAfter"));
  71. }
  72. rd.MoveNext();
  73. }
  74. m_TextPart.Text = sb.ToString();
  75. geoText.AddPart(m_TextPart);
  76. m_recordset.MoveNext();
  77. }
  78. MapControl.Map.TrackingLayer.Add(geoText, "geoText");
  79. MapControl.Map.Refresh();
  80. }
  81. protected override void OnLoad(EventArgs e)
  82. {
  83. ComsStatic.SetLayersIsSelectableFalse(ComsStatic.dvJSLK.Name, true);
  84. MapControl.Action = SuperMap.UI.Action.Select2;
  85. }
  86. public override void AfterClose()
  87. {
  88. ComsStatic.RecordsetDispose(m_recordset);
  89. base.AfterClose();
  90. }
  91. private void InitializeComponent()
  92. {
  93. this.SuspendLayout();
  94. //
  95. // ToolsConditions
  96. //
  97. this.Name = "坐标标注";
  98. this.ResumeLayout(false);
  99. }
  100. }
  101. }