GuanXianHeBing.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using Sunny.UI;
  2. using SuperMap.Data;
  3. using SuperMap.Mapping;
  4. using System;
  5. using System.Drawing;
  6. using WeifenLuo.WinFormsUI.Docking;
  7. using WWPipeLine.MapBasic.Conditions;
  8. using System.Windows.Forms;
  9. using WWPipeLine.MapBasic;
  10. using System.Data;
  11. using System.Text;
  12. namespace WWPipeLine.MapTools.Conditions.EditGuanWang
  13. {
  14. public class GuanXianHeBing : ConditionPanel
  15. {
  16. private Recordset rdSelect = null;
  17. private string _qsdh_new = "未确认";
  18. private string _zddh_new = "未确认";
  19. private UIButton uiButton1;
  20. private UIButton uiButton2;
  21. private GeoLine _geoLine = null;
  22. public GuanXianHeBing() : base()
  23. {
  24. this.ConditionPanelName = "管线合并";
  25. InitializeComponent();
  26. this.SetSize(300, 200);
  27. this.IsShowResultWindow = false;
  28. }
  29. protected override void OnLoad(EventArgs e)
  30. {
  31. ComsStatic.SetLayersIsSelectableFalse(ComsStatic.gsGuanXian.Name, true);
  32. }
  33. private void uiButton1_Click(object sender, EventArgs e)
  34. {
  35. Selection[] _selection = MapControl.Map.FindSelection(true);
  36. if (_selection.Length != 1 || _selection[0].Count != 2)
  37. {
  38. Sunny.UI.UIMessageTip.ShowError("依次选择需要合并的两根管线");
  39. _selection[0].Clear();
  40. return;
  41. }
  42. rdSelect = _selection[0].ToRecordset();
  43. rdSelect.SeekID(_selection[0][0]);
  44. _qsdh_new = rdSelect.GetString("qsdh");
  45. //if (string.IsNullOrEmpty(_qsdh_new))
  46. //{
  47. // Sunny.UI.UIMessageTip.ShowError("第一根管线不存在起始点号"); return;
  48. //}
  49. Recordset rdGuanDian = ComsStatic.gsGuanDian.Query(string.Format(" bsm = '{0}' ", _qsdh_new), CursorType.Static);
  50. if (rdGuanDian.RecordCount != 1)
  51. {
  52. Sunny.UI.UIMessageTip.ShowError("无法找到管线起始点号的管点信息"); return;
  53. }
  54. Point2D startPoint = new Point2D(rdGuanDian.GetDouble("x"), rdGuanDian.GetDouble("y"));
  55. rdSelect.SeekID(_selection[0][1]);
  56. _zddh_new = rdSelect.GetString("zddh");
  57. //if (string.IsNullOrEmpty(_zddh_new))
  58. //{
  59. // Sunny.UI.UIMessageTip.ShowError("最后一根管线不存在终点点号"); return;
  60. //}
  61. rdGuanDian = ComsStatic.gsGuanDian.Query(string.Format(" bsm = '{0}' ", _zddh_new), CursorType.Static);
  62. if (rdGuanDian.RecordCount != 1)
  63. {
  64. Sunny.UI.UIMessageTip.ShowError("无法找到管线终点点号的管点信息"); return;
  65. }
  66. Point2D endPoint = new Point2D(rdGuanDian.GetDouble("x"), rdGuanDian.GetDouble("y"));
  67. ComsStatic.RecordsetDispose(rdGuanDian);
  68. Point2Ds _goeLinePoints = new Point2Ds(); _goeLinePoints.Add(startPoint); _goeLinePoints.Add(endPoint);
  69. _geoLine = new GeoLine(_goeLinePoints);
  70. _geoLine.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate;
  71. MapControl.Map.TrackingLayer.Clear();
  72. MapControl.Map.TrackingLayer.Add(_geoLine, "geoLineNew");
  73. MapControl.Map.RefreshTrackingLayer();
  74. #region 由于ToRecordset方法会将 Selection[] 按照SMID从小到大排序,打乱选择的顺序。无法根据选择的先后顺序进行合并管线。
  75. //Recordset _recordset = _selection[0].ToRecordset();
  76. ////验证 ToRecordset方法会将 Selection按照SMID从小到大排序,打乱选择的顺序
  77. ////for (int i = 0; i < _selection[0].Count; i++)
  78. ////{
  79. //// uilbNew.Text += string.Format("\r\n _selection[0][{0}] value:{1}", i, _selection[0][i]);
  80. ////}
  81. ////_recordset.MoveFirst();
  82. ////for (int i = 0; i < _recordset.RecordCount; i++)
  83. ////{
  84. //// uilbNew.Text += string.Format("\r\n Recordset SmID:{0} 起始点号:{1} 终点点号:{2}", _recordset.GetFieldValue("smid"), _recordset.GetFieldValue("qsdh"), _recordset.GetFieldValue("zddh"));
  85. //// _recordset.MoveNext();
  86. ////}
  87. ////验证 结束
  88. #endregion
  89. }
  90. public override object Do(DockPanel dockPanel = null)
  91. {
  92. if (_qsdh_new == _zddh_new || _geoLine is null)
  93. {
  94. Sunny.UI.UIMessageTip.ShowError("未执行合并管线操作"); return false;
  95. }
  96. EditHistory m_EditHistory = new EditHistory();
  97. try
  98. {
  99. //1 新增合并后的管线
  100. Recordset _rd = ComsStatic.gsGuanXian.GetRecordset(true, CursorType.Dynamic);
  101. _rd.AddNew(_geoLine);
  102. m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, false);
  103. m_EditHistory.Add(SuperMap.Data.EditType.Modify, _rd, false);
  104. _rd.Edit();
  105. _rd.SetFieldValue("qsdh", _qsdh_new);
  106. _rd.SetFieldValue("zddh", _zddh_new);
  107. _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
  108. _rd.SetFieldValue("cd", ComsStatic.StringToDouble(_geoLine.Length, 2));
  109. _rd.SetFieldValue("shape_length", _geoLine.Length);
  110. Int32 objID = ComsStatic.GetMaxValueInt(ComsStatic.gsGuanXian, "OBJECTID") + 1;
  111. _rd.SetFieldValue("objectid", objID);
  112. _rd.SetFieldValue("fldm", ComsStatic.dvGXCaption);
  113. _rd.SetFieldValue("bsm", ComsStatic.dvGXDatasetName + objID);
  114. _rd.SetFieldValue("cqbh", "管线合并");
  115. if (_rd.Update())
  116. {
  117. ComsStatic.RecordsetDispose(_rd);
  118. Commons.LogHelper.Info(string.Format("管线合并-新增合并后管线成功!新增的OBJECTID是{0}。", objID));
  119. }
  120. else
  121. {
  122. ComsStatic.EditHistoryUndo(m_EditHistory);
  123. ComsStatic.ShowErrorLog("新增合并后的管线操作失败"); return false;
  124. }
  125. //2 删除原管线 限制2条管线
  126. rdSelect.MoveFirst();
  127. while (!rdSelect.IsEOF)
  128. {
  129. m_EditHistory.Add(SuperMap.Data.EditType.Delete, rdSelect, true);
  130. if (rdSelect.Delete())
  131. {
  132. Commons.LogHelper.Info(string.Format("管线合并-删除原管线成功!smid={0}的管线", rdSelect.GetID()));
  133. }
  134. else
  135. {
  136. ComsStatic.EditHistoryUndo(m_EditHistory);
  137. ComsStatic.ShowErrorLog("原管线删除操作失败"); return false;
  138. }
  139. }
  140. ComsStatic.RecordsetDispose(rdSelect);
  141. ComsStatic.ShowOKLog("操作成功", string.Format("新增管线{0}", objID));
  142. }
  143. catch
  144. {
  145. ComsStatic.EditHistoryUndo(m_EditHistory);
  146. ComsStatic.ShowErrorLog("管线合并失败!"); return false;
  147. }
  148. return true;
  149. }
  150. private void InitializeComponent()
  151. {
  152. this.uiButton2 = new Sunny.UI.UIButton();
  153. this.uiButton1 = new Sunny.UI.UIButton();
  154. this.SuspendLayout();
  155. //
  156. // uiButton2
  157. //
  158. this.uiButton2.Cursor = System.Windows.Forms.Cursors.Default;
  159. this.uiButton2.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  160. this.uiButton2.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  161. this.uiButton2.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  162. this.uiButton2.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  163. this.uiButton2.Font = new System.Drawing.Font("微软雅黑", 12F);
  164. this.uiButton2.Location = new System.Drawing.Point(161, 43);
  165. this.uiButton2.Margin = new System.Windows.Forms.Padding(30);
  166. this.uiButton2.MinimumSize = new System.Drawing.Size(1, 1);
  167. this.uiButton2.Name = "uiButton2";
  168. this.uiButton2.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  169. this.uiButton2.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  170. this.uiButton2.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  171. this.uiButton2.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  172. this.uiButton2.Size = new System.Drawing.Size(126, 30);
  173. this.uiButton2.Style = Sunny.UI.UIStyle.Gray;
  174. this.uiButton2.TabIndex = 3;
  175. this.uiButton2.Text = "取消管线预览";
  176. this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click);
  177. //
  178. // uiButton1
  179. //
  180. this.uiButton1.Cursor = System.Windows.Forms.Cursors.Default;
  181. this.uiButton1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  182. this.uiButton1.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  183. this.uiButton1.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  184. this.uiButton1.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  185. this.uiButton1.Font = new System.Drawing.Font("微软雅黑", 12F);
  186. this.uiButton1.Location = new System.Drawing.Point(12, 43);
  187. this.uiButton1.Margin = new System.Windows.Forms.Padding(30);
  188. this.uiButton1.MinimumSize = new System.Drawing.Size(1, 1);
  189. this.uiButton1.Name = "uiButton1";
  190. this.uiButton1.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  191. this.uiButton1.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  192. this.uiButton1.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  193. this.uiButton1.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  194. this.uiButton1.Size = new System.Drawing.Size(126, 30);
  195. this.uiButton1.Style = Sunny.UI.UIStyle.Gray;
  196. this.uiButton1.TabIndex = 1;
  197. this.uiButton1.Text = "预览合并管线";
  198. this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click);
  199. //
  200. // GuanXianHeBing
  201. //
  202. this.Controls.Add(this.uiButton2);
  203. this.Controls.Add(this.uiButton1);
  204. this.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244)))));
  205. this.Name = "GuanXianHeBing";
  206. this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  207. this.Size = new System.Drawing.Size(300, 115);
  208. this.Style = Sunny.UI.UIStyle.Gray;
  209. this.ResumeLayout(false);
  210. }
  211. private void uiButton2_Click(object sender, EventArgs e)
  212. {
  213. _qsdh_new = "未确认";
  214. _zddh_new = "未确认";
  215. rdSelect = null;
  216. MapControl.Map.TrackingLayer.Clear();
  217. MapControl.Map.RefreshTrackingLayer();
  218. }
  219. }
  220. }