123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- using System;
- using System.Collections.Generic;
- using WeifenLuo.WinFormsUI.Docking;
- using WWPipeLine.MapBasic.Conditions;
- using WWPipeLine.MapBasic;
- using SuperMap.Data;
- using SuperMap.Mapping;
- using System.Data;
- using System.Windows.Forms;
- namespace WWPipeLine.MapTools.Conditions.Locations
- {
- public class DWBookMarks : ConditionPanel
- {
- private Sunny.UI.UIPanel uiPanel1;
- private Sunny.UI.UIButton uibtnAdd;
- private Sunny.UI.UITextBox uitbDesc;
- private Sunny.UI.UITextBox uitbName;
- private Sunny.UI.UILabel uiLabel1;
- private Sunny.UI.UILabel uiLabel2;
- private Sunny.UI.UIDataGridView dgvBooks;
- private Sunny.UI.UIButton uiButton1;
- private BookMarks m_BookMarks;
- public DWBookMarks() : base()
- {
- this.ConditionPanelName = "按照书签定位";
- InitializeComponent();
- this.IsShowPanelFooter = false;
- }
- protected override void OnLoad(EventArgs e)
- {
- m_BookMarks = MapControl.Map.BookMarks;
- if (m_BookMarks.Count == 0)
- {
- Sunny.UI.UIMessageTip.ShowError("当前地图没有任何书签信息"); return;
- }
- bind();
- }
- private void bind()
- {
- dgvBooks.ClearAll();
- DataTable dt = new DataTable();
- dt.Columns.Add("书签名称"); dt.Columns.Add("书签描述");
- DataRow drNew;
- foreach (BookMark bm in m_BookMarks)
- {
- drNew = dt.NewRow();
- drNew[0] = bm.Name; drNew[1] = bm.Description;
- dt.Rows.Add(drNew);
- }
- dgvBooks.DataSource = dt;
- }
- private void uibtnAdd_Click(object sender, EventArgs e)
- {
- if (!m_BookMarks.IsAvailableName(uitbName.Text) || uitbName.Text.Length < 1)
- {
- Sunny.UI.UIMessageTip.ShowError("书签名称不合法,请重新输入!", 3000);
- uitbName.Text = ""; uitbName.Focus(); return;
- }
- BookMark bookMark = new BookMark();
- bookMark.Name = uitbName.Text;
- bookMark.Description = uitbDesc.Text;
- bookMark.MapCenter = MapControl.Map.Center;
- bookMark.MapScale = MapControl.Map.Scale;
- bookMark.CreateTime = DateTime.Now.ToString();
- int bookMarksIndex = MapControl.Map.BookMarks.Add(bookMark);
- if (bookMarksIndex > -1)
- {
- uitbName.Text = ""; uitbDesc.Text = ""; uitbName.Focus();
- if (MapControl.Map.IsModified)
- {
- bool result = MapControl.Map.Workspace.Maps.SetMapXML(MapControl.Map.Name, MapControl.Map.ToXML());
- MapControl.Map.Workspace.Save();
- ComsStatic.ShowUIMessageTipOKorError(result, "书签 " + bookMark.Name + " 保存至地图");
- }
- }
- bind();
- }
- private void uiButton1_Click(object sender, EventArgs e)
- {
- var selectRows = dgvBooks.SelectedRows;
- if (selectRows == null || selectRows.Count != 1)
- {
- Sunny.UI.UIMessageTip.ShowError("请选择一个需要删除的书签", 3000);
- return;
- }
- string bookName = selectRows[0].Cells[0].Value.ToString();
- if (MapControl.Map.BookMarks.Remove(bookName))
- Sunny.UI.UIMessageTip.ShowOk("书签移除成功");
- else
- Sunny.UI.UIMessageTip.ShowError("书签移除失败,请重试", 3000);
- bind();
- }
- private void dgvBooks_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- var selectRows = dgvBooks.SelectedRows;
- if (selectRows == null || selectRows.Count != 1) return;
- DataGridViewRow selectRow = selectRows[0];
- string bookName = selectRow.Cells[0].Value.ToString();
- BookMark bookMark = MapControl.Map.BookMarks[bookName];
- if (bookMark is null)
- {
- Sunny.UI.UIMessageTip.ShowError("错误", 3000); return;
- }
- else
- {
- MapControl.Map.Center = bookMark.MapCenter;
- MapControl.Map.Scale = bookMark.MapScale;
- MapControl.Map.Refresh();
- }
- }
- private void InitializeComponent()
- {
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
- this.uiPanel1 = new Sunny.UI.UIPanel();
- this.uiButton1 = new Sunny.UI.UIButton();
- this.uiLabel2 = new Sunny.UI.UILabel();
- this.uiLabel1 = new Sunny.UI.UILabel();
- this.uitbDesc = new Sunny.UI.UITextBox();
- this.uitbName = new Sunny.UI.UITextBox();
- this.uibtnAdd = new Sunny.UI.UIButton();
- this.dgvBooks = new Sunny.UI.UIDataGridView();
- this.uiPanel1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dgvBooks)).BeginInit();
- this.SuspendLayout();
- //
- // uiPanel1
- //
- this.uiPanel1.Controls.Add(this.uiButton1);
- this.uiPanel1.Controls.Add(this.uiLabel2);
- this.uiPanel1.Controls.Add(this.uiLabel1);
- this.uiPanel1.Controls.Add(this.uitbDesc);
- this.uiPanel1.Controls.Add(this.uitbName);
- this.uiPanel1.Controls.Add(this.uibtnAdd);
- this.uiPanel1.Dock = System.Windows.Forms.DockStyle.Top;
- this.uiPanel1.Font = new System.Drawing.Font("微软雅黑", 12F);
- this.uiPanel1.Location = new System.Drawing.Point(0, 0);
- this.uiPanel1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
- this.uiPanel1.MinimumSize = new System.Drawing.Size(1, 1);
- this.uiPanel1.Name = "uiPanel1";
- this.uiPanel1.Size = new System.Drawing.Size(500, 79);
- this.uiPanel1.TabIndex = 0;
- this.uiPanel1.Text = null;
- this.uiPanel1.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
- //
- // uiButton1
- //
- this.uiButton1.Cursor = System.Windows.Forms.Cursors.Hand;
- this.uiButton1.Font = new System.Drawing.Font("微软雅黑", 12F);
- this.uiButton1.Location = new System.Drawing.Point(411, 20);
- this.uiButton1.MinimumSize = new System.Drawing.Size(1, 1);
- this.uiButton1.Name = "uiButton1";
- this.uiButton1.Size = new System.Drawing.Size(83, 32);
- this.uiButton1.TabIndex = 5;
- this.uiButton1.Text = "删除书签";
- this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click);
- //
- // uiLabel2
- //
- this.uiLabel2.Font = new System.Drawing.Font("微软雅黑", 12F);
- this.uiLabel2.Location = new System.Drawing.Point(3, 40);
- this.uiLabel2.Name = "uiLabel2";
- this.uiLabel2.Size = new System.Drawing.Size(74, 23);
- this.uiLabel2.TabIndex = 4;
- this.uiLabel2.Text = "书签描述";
- this.uiLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
- //
- // uiLabel1
- //
- this.uiLabel1.Font = new System.Drawing.Font("微软雅黑", 12F);
- this.uiLabel1.Location = new System.Drawing.Point(3, 6);
- this.uiLabel1.Name = "uiLabel1";
- this.uiLabel1.Size = new System.Drawing.Size(74, 23);
- this.uiLabel1.TabIndex = 3;
- this.uiLabel1.Text = "书签名称";
- this.uiLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
- //
- // uitbDesc
- //
- this.uitbDesc.Cursor = System.Windows.Forms.Cursors.IBeam;
- this.uitbDesc.FillColor = System.Drawing.Color.White;
- this.uitbDesc.Font = new System.Drawing.Font("微软雅黑", 12F);
- this.uitbDesc.Location = new System.Drawing.Point(84, 40);
- this.uitbDesc.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
- this.uitbDesc.Maximum = 2147483647D;
- this.uitbDesc.Minimum = -2147483648D;
- this.uitbDesc.MinimumSize = new System.Drawing.Size(1, 1);
- this.uitbDesc.Name = "uitbDesc";
- this.uitbDesc.Size = new System.Drawing.Size(212, 29);
- this.uitbDesc.TabIndex = 2;
- this.uitbDesc.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
- //
- // uitbName
- //
- this.uitbName.Cursor = System.Windows.Forms.Cursors.IBeam;
- this.uitbName.FillColor = System.Drawing.Color.White;
- this.uitbName.Font = new System.Drawing.Font("微软雅黑", 12F);
- this.uitbName.Location = new System.Drawing.Point(84, 6);
- this.uitbName.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
- this.uitbName.Maximum = 2147483647D;
- this.uitbName.Minimum = -2147483648D;
- this.uitbName.MinimumSize = new System.Drawing.Size(1, 1);
- this.uitbName.Name = "uitbName";
- this.uitbName.Size = new System.Drawing.Size(212, 29);
- this.uitbName.TabIndex = 1;
- this.uitbName.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
- //
- // uibtnAdd
- //
- this.uibtnAdd.Cursor = System.Windows.Forms.Cursors.Hand;
- this.uibtnAdd.Font = new System.Drawing.Font("微软雅黑", 12F);
- this.uibtnAdd.Location = new System.Drawing.Point(313, 20);
- this.uibtnAdd.MinimumSize = new System.Drawing.Size(1, 1);
- this.uibtnAdd.Name = "uibtnAdd";
- this.uibtnAdd.Size = new System.Drawing.Size(83, 32);
- this.uibtnAdd.TabIndex = 0;
- this.uibtnAdd.Text = "新增书签";
- this.uibtnAdd.Click += new System.EventHandler(this.uibtnAdd_Click);
- //
- // dgvBooks
- //
- this.dgvBooks.AllowUserToAddRows = false;
- dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
- this.dgvBooks.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
- this.dgvBooks.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
- this.dgvBooks.BackgroundColor = System.Drawing.Color.White;
- this.dgvBooks.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
- dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
- dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
- dataGridViewCellStyle2.Font = new System.Drawing.Font("微软雅黑", 12F);
- dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White;
- dataGridViewCellStyle2.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
- dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
- dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
- this.dgvBooks.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
- this.dgvBooks.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
- dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Window;
- dataGridViewCellStyle3.Font = new System.Drawing.Font("微软雅黑", 12F);
- dataGridViewCellStyle3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
- dataGridViewCellStyle3.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(200)))), ((int)(((byte)(255)))));
- dataGridViewCellStyle3.SelectionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
- dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
- this.dgvBooks.DefaultCellStyle = dataGridViewCellStyle3;
- this.dgvBooks.Dock = System.Windows.Forms.DockStyle.Fill;
- this.dgvBooks.EnableHeadersVisualStyles = false;
- this.dgvBooks.Font = new System.Drawing.Font("微软雅黑", 12F);
- this.dgvBooks.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
- this.dgvBooks.Location = new System.Drawing.Point(0, 79);
- this.dgvBooks.MultiSelect = false;
- this.dgvBooks.Name = "dgvBooks";
- this.dgvBooks.ReadOnly = true;
- dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
- dataGridViewCellStyle4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
- dataGridViewCellStyle4.Font = new System.Drawing.Font("微软雅黑", 12F);
- dataGridViewCellStyle4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
- dataGridViewCellStyle4.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
- dataGridViewCellStyle4.SelectionForeColor = System.Drawing.Color.White;
- dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
- this.dgvBooks.RowHeadersDefaultCellStyle = dataGridViewCellStyle4;
- dataGridViewCellStyle5.BackColor = System.Drawing.Color.White;
- this.dgvBooks.RowsDefaultCellStyle = dataGridViewCellStyle5;
- this.dgvBooks.RowTemplate.Height = 23;
- this.dgvBooks.SelectedIndex = -1;
- this.dgvBooks.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
- this.dgvBooks.ShowGridLine = true;
- this.dgvBooks.Size = new System.Drawing.Size(500, 286);
- this.dgvBooks.TabIndex = 1;
- this.dgvBooks.CellMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dgvBooks_CellMouseDoubleClick);
- //
- // DWBookMarks
- //
- this.Controls.Add(this.dgvBooks);
- this.Controls.Add(this.uiPanel1);
- this.Name = "DWBookMarks";
- this.Size = new System.Drawing.Size(500, 365);
- this.uiPanel1.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.dgvBooks)).EndInit();
- this.ResumeLayout(false);
- }
- }
- }
|