using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WWPipeLine.MapBasic.Conditions; using SuperMap.Data; using Sunny.UI; using WWPipeLine.MapBasic; using WeifenLuo.WinFormsUI.Docking; using SuperMap.UI; namespace WWPipeLine.MapTools.Conditions.FuZhuGongJu { public partial class BJunit : ConditionPanel { private GeoPoint _geoPoint = null; Recordset rd; private int _rdsmid = 0; public BJunit() { this.ConditionPanelName = "用水单位信息管理"; InitializeComponent(); this.IsShowPanelFooter = false; } protected override void OnLoad(EventArgs e) { DatasetVector dv = ComsStatic.Datasource.Datasets["UNITPY"] as DatasetVector; if (dv == null) { Sunny.UI.UIMessageTip.ShowError("当前数据源中不包含相应的矢量数据集"); return; } rd = ComsStatic.QueryRecordsetDynamic(dv, ""); ComsStatic.setUIDataGridView(uidgvTable, ComsStatic.RecordsetToDataTable(rd)); MapControl.MouseDoubleClick += MapControl_MouseDoubleClick; } private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e) { Point2D pClick = MapControl.Map.PixelToMap(new Point(e.X, e.Y)); _geoPoint = new GeoPoint(pClick); _geoPoint.Style = new GeoStyle { MarkerSize = new Size2D(5, 5), LineColor = Color.Red }; MapControl.Map.TrackingLayer.Clear(); MapControl.Map.TrackingLayer.Add(_geoPoint, "jiedian"); MapControl.Map.RefreshEx(MapControl.Map.ViewBounds); } private void uiButtonAdd_Click(object sender, EventArgs e) { if (_geoPoint is null) { Sunny.UI.UIMessageTip.ShowError("请先双击确定用水单位的坐标"); return; } if (string.IsNullOrEmpty(uitb_name.Text)) { Sunny.UI.UIMessageTip.ShowError("请先输入用水单位名称"); return; } rd.AddNew(_geoPoint); rd.SetFieldValue("fldm", "用水单位"); rd.SetFieldValue("name", uitb_name.Text); rd.SetFieldValue("address", uitb_address.Text); ComsStatic.ShowUIMessageTipOKorError(rd.Update(), "用水单位新增"); uitb_name.Text = ""; uitb_address.Text = ""; MapControl.Map.TrackingLayer.Clear(); MapControl.Map.Refresh(); OnLoad(e); } private void uiButtonUpdate_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(uitb_name.Text)) { Sunny.UI.UIMessageTip.ShowError("请先输入用水单位名称"); return; } if (_rdsmid == 0) { UIMessageTip.ShowError("请先选择需要编辑的信息!"); return; } if (rd.SeekID(_rdsmid)) { rd.Edit(); rd.SetFieldValue("name", uitb_name.Text); rd.SetFieldValue("address", uitb_address.Text); ComsStatic.ShowUIMessageTipOKorError(rd.Update(), "行政区域编辑"); uitb_name.Text = ""; uitb_address.Text = ""; OnLoad(e); } else { Sunny.UI.UIMessageTip.ShowError("信息在编辑选择时失败!"); } } private void uiButtonDel_Click(object sender, EventArgs e) { if (_rdsmid == 0) { UIMessageTip.ShowError("请先选择需要删除的信息!"); return; } if (rd.SeekID(_rdsmid)) { ComsStatic.ShowUIMessageTipOKorError(rd.Delete(), "行政区域删除"); uitb_name.Text = ""; uitb_address.Text = ""; OnLoad(e); } else { Sunny.UI.UIMessageTip.ShowError("信息在删除选择时失败!"); } } private void uiDataGridViewtb_SelectIndexChange(object sender, int index) { DataGridViewRow dr = uidgvTable.Rows[index]; _rdsmid = ComsStatic.StringToInt(dr.Cells["SmID"].Value.ToString()); uitb_name.Text = dr.Cells["name"].Value?.ToString(); uitb_address.Text = dr.Cells["address"].Value?.ToString(); } public override void AfterClose() { ComsStatic.RecordsetDispose(rd); MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick; base.AfterClose(); } } }