ShuXingXiuGai.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using Sunny.UI;
  2. using SuperMap.Data;
  3. using SuperMap.Mapping;
  4. using SuperMap.UI;
  5. using System;
  6. using System.Drawing;
  7. using System.Windows.Forms;
  8. using WeifenLuo.WinFormsUI.Docking;
  9. using WWPipeLine.MapBasic;
  10. using WWPipeLine.MapBasic.Conditions;
  11. namespace WWPipeLine.MapTools.Conditions.EditGuanWang
  12. {
  13. public class ShuXingXiuGai : ConditionPanel
  14. {
  15. private Recordset _recordset = null;
  16. public ShuXingXiuGai() : base()
  17. {
  18. this.ConditionPanelName = "修改属性";
  19. this.SetSize(500, 800);
  20. InitializeComponent();
  21. }
  22. protected override void OnLoad(EventArgs e)
  23. {
  24. MapControl.GeometrySelected += MapControl_GeometrySelected;
  25. }
  26. private void MapControl_GeometrySelected(object sender, GeometrySelectedEventArgs e)
  27. {
  28. this.Controls.Clear();
  29. Selection[] _selection = MapControl.Map.FindSelection(true);
  30. if (_selection.Length != 1 || _selection[0].Count != 1)
  31. {
  32. Sunny.UI.UIMessageTip.ShowError("仅可以选择一个图层中的一个元素进行修改操作", 2000); return;
  33. }
  34. _recordset = _selection[0].ToRecordset();
  35. FieldInfos infos = _recordset.GetFieldInfos();
  36. foreach (FieldInfo info in infos)
  37. {
  38. //不显示的字段
  39. string HideTag = ",SmID,SmX,SmY,SmLibTileID,SmLength,SmTopoError,SmUserID,SmGeometry,OBJECTID,WTH,TFH,DMT,TSDH,SSBH,ROTATEANGLE,ENABLED,ANCILLARYROLE,X,Y,SHAPE_Length,ANCILLARYROLE,tzbm,zcbh,qdms,zdms,CQBH,LRRQ,".ToLower();
  40. if (HideTag.Contains("," + info.Name.ToLower() + ",") || info.IsSystemField) continue;
  41. UILabel labName = new UILabel()
  42. {
  43. Name = info.Name,
  44. Text = info.Caption,
  45. TextAlign = ContentAlignment.BottomCenter,
  46. Location = new System.Drawing.Point(20, 20 + this.Controls.Count * 18),
  47. Style = UIStyle.Gray,
  48. Width = 100
  49. };
  50. this.Controls.Add(labName);
  51. //显示但是不允许更改的字段
  52. string EnableTag = ",FLDM,BSM,QSDH,ZDDH,CD,".ToLower();
  53. string shuzi = ",Double,Single,Int32,Int16,Int64,";
  54. bool isEnable = EnableTag.Contains("," + info.Name.ToLower() + ",") ? true : false;
  55. if (info.Type == FieldType.DateTime)
  56. {
  57. UIDatePicker con = new UIDatePicker();
  58. con.DateFormat = "yyyy-MM-dd";
  59. string infoValue = _recordset.GetFieldValue(info.Name)?.ToString();
  60. con.Text = infoValue;
  61. setControl(con, info, isEnable); continue;
  62. }
  63. else
  64. {
  65. UITextBox con = new UITextBox();
  66. string infoValue = _recordset.GetFieldValue(info.Name)?.ToString();
  67. con.Text = infoValue;
  68. con.MaxLength = info.MaxLength;
  69. if (shuzi.Contains("," + info.Type.ToString() + ","))
  70. con.KeyPress += uitb_KeyPress;
  71. setControl(con, info, isEnable); continue;
  72. }
  73. void setControl(UIPanel control, FieldInfo fieldInfo, bool _isEnable)
  74. {
  75. control.Tag = fieldInfo.Name;
  76. if (fieldInfo.IsSystemField || _isEnable)
  77. { control.Name = "SM_tbValue"; control.Enabled = false; }
  78. else
  79. control.Name = "tbValue";
  80. control.Location = new System.Drawing.Point(140, this.Controls.Count * 18);
  81. control.Width = 250;
  82. control.Style = UIStyle.Gray;
  83. this.Controls.Add(control);
  84. }
  85. }
  86. }
  87. private void uitb_KeyPress(object sender, KeyPressEventArgs e)
  88. {
  89. if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar < 96 || e.KeyChar > 105) && (e.KeyChar != 46) && (e.KeyChar != 8))
  90. e.Handled = true;
  91. }
  92. public override object Do(DockPanel dockPanel = null)
  93. {
  94. this.IsShowResultWindow = false;
  95. if (_recordset is null || _recordset.RecordCount != 1)
  96. {
  97. Sunny.UI.UIMessageTip.ShowError("仅可以选择一个图层中的一个元素进行修改操作"); return false;
  98. }
  99. _recordset.Edit();
  100. foreach (Control tb in this.Controls.Find("tbValue", true))
  101. {
  102. _recordset.SetFieldValue(tb.Tag.ToString(), tb.Text);
  103. }
  104. ComsStatic.ShowUIMessageTipOKorError(_recordset.Update(),"属性修改");
  105. return null;
  106. }
  107. public override void AfterClose()
  108. {
  109. MapControl.GeometrySelected -= MapControl_GeometrySelected;
  110. ComsStatic.RecordsetDispose(_recordset);
  111. base.AfterClose();
  112. }
  113. private void InitializeComponent()
  114. {
  115. this.SuspendLayout();
  116. //
  117. // ShuXingXiuGai
  118. //
  119. this.AutoScroll = true;
  120. this.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244)))));
  121. this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 20);
  122. this.Name = "ShuXingXiuGai";
  123. this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  124. this.Size = new System.Drawing.Size(413, 321);
  125. this.Style = Sunny.UI.UIStyle.Gray;
  126. this.ResumeLayout(false);
  127. }
  128. }
  129. }