BJunit.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using WWPipeLine.MapBasic.Conditions;
  11. using SuperMap.Data;
  12. using Sunny.UI;
  13. using WWPipeLine.MapBasic;
  14. using WeifenLuo.WinFormsUI.Docking;
  15. using SuperMap.UI;
  16. namespace WWPipeLine.MapTools.Conditions.FuZhuGongJu
  17. {
  18. public partial class BJunit : ConditionPanel
  19. {
  20. private GeoPoint _geoPoint = null;
  21. Recordset rd;
  22. private int _rdsmid = 0;
  23. public BJunit()
  24. {
  25. this.ConditionPanelName = "用水单位信息管理";
  26. InitializeComponent();
  27. this.IsShowPanelFooter = false;
  28. }
  29. protected override void OnLoad(EventArgs e)
  30. {
  31. DatasetVector dv = ComsStatic.Datasource.Datasets["pyunit"] as DatasetVector;
  32. if (dv == null)
  33. {
  34. Sunny.UI.UIMessageTip.ShowError("当前数据源中不包含相应的矢量数据集"); return;
  35. }
  36. rd = dv.Query("1=1", CursorType.Dynamic);
  37. ComsStatic.setUIDataGridView(uidgvTable, ComsStatic.RecordsetToDataTable(rd, false), null, ",fldm,smid,");
  38. MapControl.MouseDoubleClick += MapControl_MouseDoubleClick;
  39. }
  40. private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e)
  41. {
  42. Point2D pClick = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  43. _geoPoint = new GeoPoint(pClick);
  44. _geoPoint.Style = ComsStatic.geoStyle_Red_Mark5mm;
  45. MapControl.Map.TrackingLayer.Clear();
  46. MapControl.Map.TrackingLayer.Add(_geoPoint, "jiedian");
  47. MapControl.Map.RefreshTrackingLayer();
  48. }
  49. private void uiButtonAdd_Click(object sender, EventArgs e)
  50. {
  51. if (_geoPoint is null) { Sunny.UI.UIMessageTip.ShowError("请先双击确定用水单位的坐标"); return; }
  52. if (string.IsNullOrEmpty(uitb_name.Text)) { Sunny.UI.UIMessageTip.ShowError("请先输入用水单位名称"); return; }
  53. rd.AddNew(_geoPoint);
  54. rd.SetFieldValue("fldm", "用水单位");
  55. rd.SetFieldValue("name", uitb_name.Text);
  56. rd.SetFieldValue("address", uitb_address.Text);
  57. ComsStatic.ShowUIMessageTipOKorError(rd.Update(), "用水单位新增");
  58. uitb_name.Text = ""; uitb_address.Text = ""; MapControl.Map.TrackingLayer.Clear(); MapControl.Map.Refresh();
  59. OnLoad(e);
  60. }
  61. private void uiButtonUpdate_Click(object sender, EventArgs e)
  62. {
  63. if (string.IsNullOrEmpty(uitb_name.Text)) { Sunny.UI.UIMessageTip.ShowError("请先输入用水单位名称"); return; }
  64. if (_rdsmid == 0) { UIMessageTip.ShowError("请先选择需要编辑的信息!"); return; }
  65. if (rd.SeekID(_rdsmid))
  66. {
  67. rd.Edit();
  68. rd.SetFieldValue("name", uitb_name.Text);
  69. rd.SetFieldValue("address", uitb_address.Text);
  70. ComsStatic.ShowUIMessageTipOKorError(rd.Update(), "用水单位编辑");
  71. uitb_name.Text = ""; uitb_address.Text = "";
  72. OnLoad(e);
  73. }
  74. else
  75. { Sunny.UI.UIMessageTip.ShowError("信息在编辑选择时失败!"); }
  76. }
  77. private void uiButtonDel_Click(object sender, EventArgs e)
  78. {
  79. if (_rdsmid == 0) { UIMessageTip.ShowError("请先选择需要删除的信息!"); return; }
  80. if (rd.SeekID(_rdsmid))
  81. {
  82. ComsStatic.ShowUIMessageTipOKorError(rd.Delete(), "用水单位删除");
  83. uitb_name.Text = ""; uitb_address.Text = "";
  84. OnLoad(e);
  85. }
  86. else
  87. { Sunny.UI.UIMessageTip.ShowError("信息在删除选择时失败!"); }
  88. }
  89. private void uiDataGridViewtb_SelectIndexChange(object sender, int index)
  90. {
  91. DataGridViewRow dr = uidgvTable.Rows[index];
  92. _rdsmid = ComsStatic.StringToInt(dr.Cells["SmID"].Value.ToString());
  93. uitb_name.Text = dr.Cells["name"].Value?.ToString();
  94. uitb_address.Text = dr.Cells["address"].Value?.ToString();
  95. }
  96. public override void AfterClose()
  97. {
  98. ComsStatic.RecordsetDispose(rd);
  99. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  100. base.AfterClose();
  101. }
  102. }
  103. }