DWBookMarks.cs 13 KB

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