GuanXianHeBing.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 UILabel lbRemark;
  17. private Selection[] _selection = null;
  18. private Panel plMain;
  19. private string _qsdh_new = "未确认";
  20. private string _zddh_new = "未确认";
  21. private UIButton uiButton1;
  22. private UILabel uilbNew;
  23. private UIButton uiButton2;
  24. private GeoLine _geoLine = null;
  25. private DatasetVectorEx _dvEx;
  26. private EditHistory m_EditHistory = new EditHistory();
  27. public GuanXianHeBing() : base()
  28. {
  29. this.ConditionPanelName = "管线合并";
  30. InitializeComponent();
  31. lbRemark.Text = "请依次选择需要合并的管线, 至少选择2根管线。\r\n 合并后管线的起点为第一根管线的起点,\r\n终点为最后一根管线的终点。";
  32. }
  33. protected override void OnLoad(EventArgs e)
  34. {
  35. ComsStatic.SetLayerIsEditableFalse();
  36. }
  37. private void uiButton1_Click(object sender, EventArgs e)
  38. {
  39. uilbNew.Text = "合并后的管线信息:";
  40. StringBuilder sb = new StringBuilder();
  41. _selection = base.MapControl.Map.FindSelection(true);
  42. if (_selection.Length != 1 || _selection[0].Count < 2)
  43. {
  44. Sunny.UI.UIMessageTip.ShowError("依次选择需要合并的管线,至少选择2跟管线。"); return;
  45. }
  46. DatasetVectorEx _dvExJSJDPT = new DatasetVectorEx(ComsStatic.dvJSJDPT.Name) { DatasetVector = ComsStatic.dvJSJDPT };
  47. _dvExJSJDPT.ResultFields.AddRange(new string[] { "x", "y", "fsw", "gg", "cz" });
  48. _dvEx = new DatasetVectorEx(dvJSLK_cp.Name) { DatasetVector = dvJSLK_cp };
  49. _qsdh_new = _dvEx.QueryGetValueByOnlyField(string.Format(" smid={0}", _selection[0][0]), "qsdh");
  50. if (string.IsNullOrEmpty(_qsdh_new))
  51. {
  52. Sunny.UI.UIMessageTip.ShowError("所选择管线不存在起始点号,请先修改管线信息!"); return;
  53. }
  54. DataTable dataTable = _dvExJSJDPT.Query(string.Format(" bsm = '{0}' ", _qsdh_new));
  55. if (dataTable.Rows.Count != 1)
  56. {
  57. Sunny.UI.UIMessageTip.ShowError("管线起始点号的管点信息不存在", 2000); return;
  58. }
  59. Point2D startPoint = new Point2D(double.Parse(dataTable.Rows[0]["x"].ToString()), double.Parse(dataTable.Rows[0]["y"].ToString()));
  60. sb.AppendFormat("\r\n起始点号:{0},为{1}附属物 规格是{2} 材质是{3}。", _qsdh_new, dataTable.Rows[0]["fsw"], dataTable.Rows[0]["gg"], dataTable.Rows[0]["cz"]);
  61. sb.AppendFormat("\r\n坐标:{0:F2}-{1:F2}\r\n", startPoint.X, startPoint.Y);
  62. _zddh_new = _dvEx.QueryGetValueByOnlyField(string.Format(" smid={0}", _selection[0][_selection[0].Count - 1]), "zddh");
  63. if (string.IsNullOrEmpty(_zddh_new))
  64. {
  65. Sunny.UI.UIMessageTip.ShowError("所选择管线不存在终点点号,请先修改管线信息!"); return;
  66. }
  67. dataTable = _dvExJSJDPT.Query(string.Format(" wth='{0}' ", _zddh_new));
  68. if (dataTable.Rows.Count != 1)
  69. {
  70. Sunny.UI.UIMessageTip.ShowError("管线终点点号的管点信息不存在"); return;
  71. }
  72. Point2D endPoint = new Point2D(double.Parse(dataTable.Rows[0]["x"].ToString()), double.Parse(dataTable.Rows[0]["y"].ToString()));
  73. sb.AppendFormat("\r\n终点点号:{0},为{1}附属物 规格是{2} 材质是{3}。", _zddh_new, dataTable.Rows[0]["fsw"], dataTable.Rows[0]["gg"], dataTable.Rows[0]["cz"]);
  74. sb.AppendFormat("\r\n坐标:{0:F2}-{1:F2}\r\n", endPoint.X, endPoint.Y);
  75. Point2Ds _goeLinePoints = new Point2Ds(); _goeLinePoints.Add(startPoint); _goeLinePoints.Add(endPoint);
  76. _geoLine = new GeoLine(_goeLinePoints);
  77. _geoLine.Style = new GeoStyle { LineColor = Color.Red, LineWidth = 3 }; ;
  78. if (_geoLine.Length == 0)
  79. {
  80. Sunny.UI.UIMessageTip.ShowError("管线选择错误,请重新选择。目前选择的管线无法合并!", 2000); return;
  81. }
  82. sb.AppendFormat("\r\n新管线长度:{0:F2}\r\n", _geoLine.Length);
  83. uilbNew.Text = sb.ToString();
  84. int index = MapControl.Map.TrackingLayer.IndexOf("geoLineNew");
  85. if (index >= 0) MapControl.Map.TrackingLayer.Remove(index);
  86. MapControl.Map.TrackingLayer.Add(_geoLine, "geoLineNew");
  87. MapControl.Map.Refresh();
  88. #region 由于ToRecordset方法会将 Selection[] 按照SMID从小到大排序,打乱选择的顺序。无法根据选择的先后顺序进行合并管线。
  89. //Recordset _recordset = _selection[0].ToRecordset();//此处ToRecordset方法会将 Selection按照SMID从小到大排序,打乱选择的顺序
  90. ////验证 ToRecordset方法会将 Selection按照SMID从小到大排序,打乱选择的顺序
  91. ////for (int i = 0; i < _selection[0].Count; i++)
  92. ////{
  93. //// uilbNew.Text += string.Format("\r\n _selection[0][{0}] value:{1}", i, _selection[0][i]);
  94. ////}
  95. ////_recordset.MoveFirst();
  96. ////for (int i = 0; i < _recordset.RecordCount; i++)
  97. ////{
  98. //// uilbNew.Text += string.Format("\r\n Recordset SmID:{0} 起始点号:{1} 终点点号:{2}", _recordset.GetFieldValue("smid"), _recordset.GetFieldValue("qsdh"), _recordset.GetFieldValue("zddh"));
  99. //// _recordset.MoveNext();
  100. ////}
  101. ////验证 结束
  102. #endregion
  103. }
  104. public override object Do(DockPanel dockPanel = null)
  105. {
  106. if (_qsdh_new == _zddh_new)
  107. {
  108. Sunny.UI.UIMessageTip.ShowError("起始点号和终点点号不能相同"); return false;
  109. }
  110. m_EditHistory.Capacity = 3;
  111. this.IsShowResultWindow = false;
  112. if (_geoLine is null)
  113. {
  114. Sunny.UI.UIMessageTip.ShowError("未执行合并管线操作", 2000); return false;
  115. }
  116. try
  117. {
  118. //1 新增合并后的管线
  119. Recordset _rd = dvJSLK_cp.GetRecordset(false, CursorType.Dynamic);
  120. m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, true);
  121. _rd.AddNew(_geoLine);
  122. _rd.SetFieldValue("qsdh", _qsdh_new);
  123. _rd.SetFieldValue("zddh", _zddh_new);
  124. _rd.SetFieldValue("cd", double.Parse(string.Format("{0:F2}", _geoLine.Length)));
  125. _rd.SetFieldValue("enabled", 1);
  126. _rd.SetFieldValue("shape_length", _geoLine.Length);
  127. Int32 objID = Int32.Parse(ComsStatic.GetMaxValue(ComsStatic.dvJSLK, "OBJECTID").ToString()) + 1;
  128. _rd.SetFieldValue("objectid", objID);
  129. _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
  130. _rd.SetFieldValue("objectid", objID);
  131. _rd.SetFieldValue("bsm", "JSLK" + objID);
  132. _rd.SetFieldValue("fldm", "供水管线");
  133. _rd.SetFieldValue("cqbh", "管线合并");
  134. if (_rd.Update())
  135. { Commons.LogHelper.Error(string.Format("管线合并-新增合并后管线成功!新增的OBJECTID是{0}。", objID)); }
  136. else
  137. {
  138. ComsStatic.EditHistoryUndo(m_EditHistory);
  139. ComsStatic.ShowErrorLog("新增合并后的管线操作失败"); return false;
  140. }
  141. //2 删除原管线 至少2条
  142. Recordset _recordset = _selection[0].ToRecordset();
  143. m_EditHistory.Add(SuperMap.Data.EditType.Delete, _recordset, true);
  144. if (_recordset.DeleteAll())
  145. { Commons.LogHelper.Error(string.Format("管线合并-删除原管线成功!")); }
  146. else
  147. {
  148. ComsStatic.EditHistoryUndo(m_EditHistory);
  149. ComsStatic.ShowErrorLog("原管线删除操作失败"); return false;
  150. }
  151. }
  152. catch
  153. {
  154. ComsStatic.EditHistoryUndo(m_EditHistory);
  155. ComsStatic.ShowErrorLog("管线合并失败!"); return false;
  156. }
  157. MapControl.Map.Refresh();
  158. return true;
  159. }
  160. public override void AfterClose()
  161. {
  162. m_EditHistory.Clear(); m_EditHistory.Dispose();
  163. base.AfterClose();
  164. }
  165. private void InitializeComponent()
  166. {
  167. this.plMain = new System.Windows.Forms.Panel();
  168. this.uiButton2 = new Sunny.UI.UIButton();
  169. this.uilbNew = new Sunny.UI.UILabel();
  170. this.uiButton1 = new Sunny.UI.UIButton();
  171. this.lbRemark = new Sunny.UI.UILabel();
  172. this.plMain.SuspendLayout();
  173. this.SuspendLayout();
  174. //
  175. // plMain
  176. //
  177. this.plMain.AutoScroll = true;
  178. this.plMain.Controls.Add(this.uiButton2);
  179. this.plMain.Controls.Add(this.uilbNew);
  180. this.plMain.Controls.Add(this.uiButton1);
  181. this.plMain.Controls.Add(this.lbRemark);
  182. this.plMain.Dock = System.Windows.Forms.DockStyle.Fill;
  183. this.plMain.Location = new System.Drawing.Point(0, 0);
  184. this.plMain.Name = "plMain";
  185. this.plMain.Size = new System.Drawing.Size(445, 317);
  186. this.plMain.TabIndex = 0;
  187. //
  188. // uiButton2
  189. //
  190. this.uiButton2.Cursor = System.Windows.Forms.Cursors.Default;
  191. this.uiButton2.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  192. this.uiButton2.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  193. this.uiButton2.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  194. this.uiButton2.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  195. this.uiButton2.Font = new System.Drawing.Font("微软雅黑", 12F);
  196. this.uiButton2.Location = new System.Drawing.Point(181, 137);
  197. this.uiButton2.Margin = new System.Windows.Forms.Padding(30);
  198. this.uiButton2.MinimumSize = new System.Drawing.Size(1, 1);
  199. this.uiButton2.Name = "uiButton2";
  200. this.uiButton2.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  201. this.uiButton2.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  202. this.uiButton2.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  203. this.uiButton2.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  204. this.uiButton2.Size = new System.Drawing.Size(146, 35);
  205. this.uiButton2.Style = Sunny.UI.UIStyle.Gray;
  206. this.uiButton2.TabIndex = 3;
  207. this.uiButton2.Text = "重新选择管线";
  208. this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click);
  209. //
  210. // uilbNew
  211. //
  212. this.uilbNew.AutoSize = true;
  213. this.uilbNew.Font = new System.Drawing.Font("微软雅黑", 12F);
  214. this.uilbNew.Location = new System.Drawing.Point(10, 189);
  215. this.uilbNew.Margin = new System.Windows.Forms.Padding(0);
  216. this.uilbNew.Name = "uilbNew";
  217. this.uilbNew.Size = new System.Drawing.Size(138, 21);
  218. this.uilbNew.Style = Sunny.UI.UIStyle.Gray;
  219. this.uilbNew.TabIndex = 2;
  220. this.uilbNew.Text = "合并后的管线信息";
  221. this.uilbNew.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  222. //
  223. // uiButton1
  224. //
  225. this.uiButton1.Cursor = System.Windows.Forms.Cursors.Default;
  226. this.uiButton1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  227. this.uiButton1.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  228. this.uiButton1.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  229. this.uiButton1.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  230. this.uiButton1.Font = new System.Drawing.Font("微软雅黑", 12F);
  231. this.uiButton1.Location = new System.Drawing.Point(10, 137);
  232. this.uiButton1.Margin = new System.Windows.Forms.Padding(30);
  233. this.uiButton1.MinimumSize = new System.Drawing.Size(1, 1);
  234. this.uiButton1.Name = "uiButton1";
  235. this.uiButton1.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  236. this.uiButton1.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  237. this.uiButton1.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  238. this.uiButton1.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  239. this.uiButton1.Size = new System.Drawing.Size(146, 35);
  240. this.uiButton1.Style = Sunny.UI.UIStyle.Gray;
  241. this.uiButton1.TabIndex = 1;
  242. this.uiButton1.Text = "生成合并后管线";
  243. this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click);
  244. //
  245. // lbRemark
  246. //
  247. this.lbRemark.AutoSize = true;
  248. this.lbRemark.Dock = System.Windows.Forms.DockStyle.Top;
  249. this.lbRemark.Font = new System.Drawing.Font("微软雅黑", 12F);
  250. this.lbRemark.Location = new System.Drawing.Point(0, 0);
  251. this.lbRemark.Margin = new System.Windows.Forms.Padding(0);
  252. this.lbRemark.Name = "lbRemark";
  253. this.lbRemark.Size = new System.Drawing.Size(74, 21);
  254. this.lbRemark.Style = Sunny.UI.UIStyle.Gray;
  255. this.lbRemark.TabIndex = 0;
  256. this.lbRemark.Text = "操作说明";
  257. this.lbRemark.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  258. //
  259. // GuanXianHeBing
  260. //
  261. this.Controls.Add(this.plMain);
  262. this.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244)))));
  263. this.Name = "GuanXianHeBing";
  264. this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  265. this.Size = new System.Drawing.Size(445, 317);
  266. this.Style = Sunny.UI.UIStyle.Gray;
  267. this.plMain.ResumeLayout(false);
  268. this.plMain.PerformLayout();
  269. this.ResumeLayout(false);
  270. }
  271. private void uiButton2_Click(object sender, EventArgs e)
  272. {
  273. uilbNew.Text = "合并后的管线信息:";
  274. MapControl.Action = SuperMap.UI.Action.Pan;
  275. MapControl.Cursor = Cursors.Default;
  276. MapControl.Map.TrackingLayer.Clear();
  277. MapControl.Map.Refresh();
  278. }
  279. }
  280. }