DWBookMarks.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. using System;
  2. using System.Collections.Generic;
  3. using WeifenLuo.WinFormsUI.Docking;
  4. using WWPipeLine.MapBasic.Conditions;
  5. using WWPipeLine.MapBasic;
  6. using SuperMap.Data;
  7. using SuperMap.Mapping;
  8. using System.Data;
  9. using System.Windows.Forms;
  10. namespace WWPipeLine.MapTools.Conditions.Locations
  11. {
  12. public class DWBookMarks : ConditionPanel
  13. {
  14. private Sunny.UI.UIPanel uiPanel1;
  15. private Sunny.UI.UIButton uibtnAdd;
  16. private Sunny.UI.UITextBox uitbDesc;
  17. private Sunny.UI.UITextBox uitbName;
  18. private Sunny.UI.UILabel uiLabel1;
  19. private Sunny.UI.UILabel uiLabel2;
  20. private Sunny.UI.UIDataGridView dgvBooks;
  21. private Sunny.UI.UIButton uiButton1;
  22. private BookMarks m_BookMarks;
  23. public DWBookMarks() : base()
  24. {
  25. this.ConditionPanelName = "按照书签定位";
  26. InitializeComponent();
  27. this.SetSize(700, 500);
  28. this.IsShowPanelFooter = false;
  29. }
  30. protected override void OnLoad(EventArgs e)
  31. {
  32. m_BookMarks = MapControl.Map.BookMarks;
  33. if (m_BookMarks.Count == 0)
  34. {
  35. Sunny.UI.UIMessageTip.ShowError("当前地图没有任何书签信息", 3000); return;
  36. }
  37. bind();
  38. }
  39. private void bind()
  40. {
  41. dgvBooks.ClearAll();
  42. DataTable dt = new DataTable();
  43. dt.Columns.Add("名称"); dt.Columns.Add("描述");
  44. DataRow drNew;
  45. foreach (BookMark bm in m_BookMarks)
  46. {
  47. drNew = dt.NewRow();
  48. drNew["名称"] = bm.Name; drNew["描述"] = bm.Description;
  49. dt.Rows.Add(drNew);
  50. }
  51. dgvBooks.DataSource = dt;
  52. }
  53. private void uibtnAdd_Click(object sender, EventArgs e)
  54. {
  55. if (!m_BookMarks.IsAvailableName(uitbName.Text) || uitbName.Text.Length < 1)
  56. {
  57. Sunny.UI.UIMessageTip.ShowError("书签名称不合法,请重新输入!", 3000);
  58. uitbName.Text = ""; uitbName.Focus(); return;
  59. }
  60. BookMark bookMark = new BookMark();
  61. bookMark.Name = uitbName.Text;
  62. bookMark.Description = uitbDesc.Text;
  63. bookMark.MapCenter = MapControl.Map.Center;
  64. bookMark.MapScale = MapControl.Map.Scale;
  65. bookMark.CreateTime = DateTime.Now.ToString();
  66. int bookMarksIndex = MapControl.Map.BookMarks.Add(bookMark);
  67. if (bookMarksIndex > -1)
  68. {
  69. uitbName.Text = ""; uitbDesc.Text = ""; uitbName.Focus();
  70. if (MapControl.Map.IsModified)
  71. {
  72. bool result = MapControl.Map.Workspace.Maps.SetMapXML(MapControl.Map.Name, MapControl.Map.ToXML());
  73. MapControl.Map.Workspace.Save();
  74. ComsStatic.ShowUIMessageTipOKorError(result, "书签 " + bookMark.Name + " 保存至地图");
  75. }
  76. }
  77. bind();
  78. }
  79. //public override object Do(DockPanel dockPanel = null)
  80. //{
  81. // this.IsShowResultWindow = false;
  82. // if (MapControl.Map.IsModified)
  83. // {
  84. // bool result = MapControl.Map.Workspace.Maps.SetMapXML(MapControl.Map.Name, MapControl.Map.ToXML());
  85. // MapControl.Map.Workspace.Save();
  86. // if (result)
  87. // {
  88. // Sunny.UI.UIMessageTip.ShowOk("书签成功保存至地图", 3000);
  89. // MapControl.Map.Refresh();
  90. // }
  91. // else
  92. // {
  93. // Sunny.UI.UIMessageTip.ShowError("书签未能保存,请重试", 3000);
  94. // return false;
  95. // }
  96. // }
  97. // return true;
  98. //}
  99. private void uiButton1_Click(object sender, EventArgs e)
  100. {
  101. var selectRows = dgvBooks.SelectedRows;
  102. if (selectRows == null || selectRows.Count != 1)
  103. {
  104. Sunny.UI.UIMessageTip.ShowError("请选择一个需要删除的书签", 3000);
  105. return;
  106. }
  107. string bookName = selectRows[0].Cells[0].Value.ToString();
  108. if (MapControl.Map.BookMarks.Remove(bookName))
  109. Sunny.UI.UIMessageTip.ShowOk("书签移除成功");
  110. else
  111. Sunny.UI.UIMessageTip.ShowError("书签移除失败,请重试", 3000);
  112. bind();
  113. }
  114. private void dgvBooks_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  115. {
  116. //var dataGridView = (sender as DataGridView);
  117. //var selectRows = dataGridView.SelectedRows;
  118. var selectRows = dgvBooks.SelectedRows;
  119. if (selectRows == null || selectRows.Count != 1) return;
  120. DataGridViewRow selectRow = selectRows[0];
  121. string bookName = selectRow.Cells[0].Value.ToString();
  122. BookMark bookMark = MapControl.Map.BookMarks[bookName];
  123. if (bookMark is null)
  124. {
  125. Sunny.UI.UIMessageTip.ShowError("错误", 3000);
  126. return;
  127. }
  128. else
  129. {
  130. MapControl.Map.Center = bookMark.MapCenter;
  131. MapControl.Map.Scale = bookMark.MapScale;
  132. MapControl.Map.Refresh();
  133. }
  134. }
  135. private void InitializeComponent()
  136. {
  137. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  138. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
  139. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
  140. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
  141. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
  142. this.uiPanel1 = new Sunny.UI.UIPanel();
  143. this.uiButton1 = new Sunny.UI.UIButton();
  144. this.uiLabel2 = new Sunny.UI.UILabel();
  145. this.uiLabel1 = new Sunny.UI.UILabel();
  146. this.uitbDesc = new Sunny.UI.UITextBox();
  147. this.uitbName = new Sunny.UI.UITextBox();
  148. this.uibtnAdd = new Sunny.UI.UIButton();
  149. this.dgvBooks = new Sunny.UI.UIDataGridView();
  150. this.uiPanel1.SuspendLayout();
  151. ((System.ComponentModel.ISupportInitialize)(this.dgvBooks)).BeginInit();
  152. this.SuspendLayout();
  153. //
  154. // uiPanel1
  155. //
  156. this.uiPanel1.Controls.Add(this.uiButton1);
  157. this.uiPanel1.Controls.Add(this.uiLabel2);
  158. this.uiPanel1.Controls.Add(this.uiLabel1);
  159. this.uiPanel1.Controls.Add(this.uitbDesc);
  160. this.uiPanel1.Controls.Add(this.uitbName);
  161. this.uiPanel1.Controls.Add(this.uibtnAdd);
  162. this.uiPanel1.Dock = System.Windows.Forms.DockStyle.Top;
  163. this.uiPanel1.Font = new System.Drawing.Font("微软雅黑", 12F);
  164. this.uiPanel1.Location = new System.Drawing.Point(0, 0);
  165. this.uiPanel1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
  166. this.uiPanel1.MinimumSize = new System.Drawing.Size(1, 1);
  167. this.uiPanel1.Name = "uiPanel1";
  168. this.uiPanel1.Size = new System.Drawing.Size(662, 53);
  169. this.uiPanel1.TabIndex = 0;
  170. this.uiPanel1.Text = null;
  171. this.uiPanel1.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
  172. //
  173. // uiButton1
  174. //
  175. this.uiButton1.Cursor = System.Windows.Forms.Cursors.Hand;
  176. this.uiButton1.Font = new System.Drawing.Font("微软雅黑", 12F);
  177. this.uiButton1.Location = new System.Drawing.Point(559, 5);
  178. this.uiButton1.MinimumSize = new System.Drawing.Size(1, 1);
  179. this.uiButton1.Name = "uiButton1";
  180. this.uiButton1.Size = new System.Drawing.Size(100, 35);
  181. this.uiButton1.TabIndex = 5;
  182. this.uiButton1.Text = "删除书签";
  183. this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click);
  184. //
  185. // uiLabel2
  186. //
  187. this.uiLabel2.Font = new System.Drawing.Font("微软雅黑", 12F);
  188. this.uiLabel2.Location = new System.Drawing.Point(203, 15);
  189. this.uiLabel2.Name = "uiLabel2";
  190. this.uiLabel2.Size = new System.Drawing.Size(45, 23);
  191. this.uiLabel2.TabIndex = 4;
  192. this.uiLabel2.Text = "描述";
  193. this.uiLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  194. //
  195. // uiLabel1
  196. //
  197. this.uiLabel1.Font = new System.Drawing.Font("微软雅黑", 12F);
  198. this.uiLabel1.Location = new System.Drawing.Point(3, 15);
  199. this.uiLabel1.Name = "uiLabel1";
  200. this.uiLabel1.Size = new System.Drawing.Size(45, 23);
  201. this.uiLabel1.TabIndex = 3;
  202. this.uiLabel1.Text = "名称";
  203. this.uiLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  204. //
  205. // uitbDesc
  206. //
  207. this.uitbDesc.Cursor = System.Windows.Forms.Cursors.IBeam;
  208. this.uitbDesc.FillColor = System.Drawing.Color.White;
  209. this.uitbDesc.Font = new System.Drawing.Font("微软雅黑", 12F);
  210. this.uitbDesc.Location = new System.Drawing.Point(251, 11);
  211. this.uitbDesc.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
  212. this.uitbDesc.Maximum = 2147483647D;
  213. this.uitbDesc.Minimum = -2147483648D;
  214. this.uitbDesc.MinimumSize = new System.Drawing.Size(1, 1);
  215. this.uitbDesc.Name = "uitbDesc";
  216. this.uitbDesc.Size = new System.Drawing.Size(186, 29);
  217. this.uitbDesc.TabIndex = 2;
  218. this.uitbDesc.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
  219. //
  220. // uitbName
  221. //
  222. this.uitbName.Cursor = System.Windows.Forms.Cursors.IBeam;
  223. this.uitbName.FillColor = System.Drawing.Color.White;
  224. this.uitbName.Font = new System.Drawing.Font("微软雅黑", 12F);
  225. this.uitbName.Location = new System.Drawing.Point(51, 12);
  226. this.uitbName.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
  227. this.uitbName.Maximum = 2147483647D;
  228. this.uitbName.Minimum = -2147483648D;
  229. this.uitbName.MinimumSize = new System.Drawing.Size(1, 1);
  230. this.uitbName.Name = "uitbName";
  231. this.uitbName.Size = new System.Drawing.Size(150, 29);
  232. this.uitbName.TabIndex = 1;
  233. this.uitbName.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
  234. //
  235. // uibtnAdd
  236. //
  237. this.uibtnAdd.Cursor = System.Windows.Forms.Cursors.Hand;
  238. this.uibtnAdd.Font = new System.Drawing.Font("微软雅黑", 12F);
  239. this.uibtnAdd.Location = new System.Drawing.Point(456, 6);
  240. this.uibtnAdd.MinimumSize = new System.Drawing.Size(1, 1);
  241. this.uibtnAdd.Name = "uibtnAdd";
  242. this.uibtnAdd.Size = new System.Drawing.Size(100, 35);
  243. this.uibtnAdd.TabIndex = 0;
  244. this.uibtnAdd.Text = "新增书签";
  245. this.uibtnAdd.Click += new System.EventHandler(this.uibtnAdd_Click);
  246. //
  247. // dgvBooks
  248. //
  249. this.dgvBooks.AllowUserToAddRows = false;
  250. dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
  251. this.dgvBooks.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
  252. this.dgvBooks.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
  253. this.dgvBooks.BackgroundColor = System.Drawing.Color.White;
  254. this.dgvBooks.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
  255. dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  256. dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
  257. dataGridViewCellStyle2.Font = new System.Drawing.Font("微软雅黑", 12F);
  258. dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White;
  259. dataGridViewCellStyle2.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
  260. dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
  261. dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
  262. this.dgvBooks.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
  263. this.dgvBooks.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  264. dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
  265. dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Window;
  266. dataGridViewCellStyle3.Font = new System.Drawing.Font("微软雅黑", 12F);
  267. dataGridViewCellStyle3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
  268. dataGridViewCellStyle3.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(200)))), ((int)(((byte)(255)))));
  269. dataGridViewCellStyle3.SelectionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
  270. dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
  271. this.dgvBooks.DefaultCellStyle = dataGridViewCellStyle3;
  272. this.dgvBooks.Dock = System.Windows.Forms.DockStyle.Fill;
  273. this.dgvBooks.EnableHeadersVisualStyles = false;
  274. this.dgvBooks.Font = new System.Drawing.Font("微软雅黑", 12F);
  275. this.dgvBooks.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
  276. this.dgvBooks.Location = new System.Drawing.Point(0, 53);
  277. this.dgvBooks.MultiSelect = false;
  278. this.dgvBooks.Name = "dgvBooks";
  279. this.dgvBooks.ReadOnly = true;
  280. dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
  281. dataGridViewCellStyle4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
  282. dataGridViewCellStyle4.Font = new System.Drawing.Font("微软雅黑", 12F);
  283. dataGridViewCellStyle4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
  284. dataGridViewCellStyle4.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
  285. dataGridViewCellStyle4.SelectionForeColor = System.Drawing.Color.White;
  286. dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
  287. this.dgvBooks.RowHeadersDefaultCellStyle = dataGridViewCellStyle4;
  288. dataGridViewCellStyle5.BackColor = System.Drawing.Color.White;
  289. this.dgvBooks.RowsDefaultCellStyle = dataGridViewCellStyle5;
  290. this.dgvBooks.RowTemplate.Height = 23;
  291. this.dgvBooks.SelectedIndex = -1;
  292. this.dgvBooks.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
  293. this.dgvBooks.ShowGridLine = true;
  294. this.dgvBooks.Size = new System.Drawing.Size(662, 293);
  295. this.dgvBooks.TabIndex = 1;
  296. this.dgvBooks.CellMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dgvBooks_CellMouseDoubleClick);
  297. //
  298. // DWBookMarks
  299. //
  300. this.Controls.Add(this.dgvBooks);
  301. this.Controls.Add(this.uiPanel1);
  302. this.Name = "DWBookMarks";
  303. this.Size = new System.Drawing.Size(662, 346);
  304. this.uiPanel1.ResumeLayout(false);
  305. ((System.ComponentModel.ISupportInitialize)(this.dgvBooks)).EndInit();
  306. this.ResumeLayout(false);
  307. }
  308. }
  309. }