From 36f1be9860b303afac93f93a15f0c62cba57c3c5 Mon Sep 17 00:00:00 2001
From: ningshuxia <ningshuxia0927@outlook.com>
Date: 星期一, 31 三月 2025 11:11:37 +0800
Subject: [PATCH] 快速建模bug修改

---
 WinFrmUI/PBS.WinFrmUI.Hydro/99-map-view/propertyform.cs |  400 ++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 242 insertions(+), 158 deletions(-)

diff --git a/WinFrmUI/PBS.WinFrmUI.Hydro/99-map-view/propertyform.cs b/WinFrmUI/PBS.WinFrmUI.Hydro/99-map-view/propertyform.cs
index 8a5a67d..3d89123 100644
--- a/WinFrmUI/PBS.WinFrmUI.Hydro/99-map-view/propertyform.cs
+++ b/WinFrmUI/PBS.WinFrmUI.Hydro/99-map-view/propertyform.cs
@@ -1,41 +1,55 @@
-锘縰sing System.Data;
-
-
+锘縰sing DevExpress.XtraEditors.Repository;
+using DevExpress.XtraVerticalGrid.Events;
+using System.Data;
+ 
 namespace HydroUI
-{ 
+{
     public partial class PropertyForm : UserControl
     {
-        private IBaseViewModel _selectedObject;
-        private MapObjectType _selectedType=  MapObjectType.鍏ㄩ儴;
-        private List<SelectionSet> selectionSets;
-        public SelectionSet selectionSet=new SelectionSet();
-        private Form fr = null;
+
         public PropertyForm()
         {
             InitializeComponent();
+            this.propertyGridControl1.OptionsBehavior.PropertySort = DevExpress.XtraVerticalGrid.PropertySort.NoSort;
+            this.propertyGridControl1.OptionsView.AllowReadOnlyRowAppearance = DevExpress.Utils.DefaultBoolean.True;
+            this.propertyGridControl1.OptionsView.ShowFocusedFrame = false;
+            this.propertyGridControl1.OptionsView.ShowRootLevelIndent = false;
+            this.propertyGridControl1.RecordWidth = 120;
+            this.propertyGridControl1.RowHeaderWidth = 100;
+
+            propertyGridControl1.CustomRecordCellEdit += propertyGridControl1_CustomRecordCellEdit; 
+            propertyGridControl1.CustomDrawRowHeaderCell += propertyGridControl1_CustomDrawRowHeaderCell;
+            propertyGridControl1.CustomDrawRowValueCell += propertyGridControl1_CustomDrawRowValueCell;
+            propertyGridControl1.ShowingEditor += propertyGridControl1_ShowingEditor;
+
+            this.comboBox_type.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
         }
+
+
+        private IBaseViewModel _selectedObject;
+        private MapObjectType _selectedType = MapObjectType.鍏ㄩ儴;
+        private List<SelectionSet> selectionSets;
+        public SelectionSet selectionSet = new SelectionSet();
+        private Form fr = null;
+
         public void SetEnabled(bool isReadOnly)
         {
-            _isEnable = isReadOnly;
+
         }
 
         public void SetWindows(Form mg)
         {
             if (mg.WindowState == FormWindowState.Maximized)
             {
-                //this.StartPosition = FormStartPosition.Manual;   //璁剧疆绐椾綋浣嶇疆鐢辩▼搴忔帶鍒�
-                this.Height = mg.Height-50;
-                this.Location = new Point(mg.Left + mg.Width -this.Width, mg.Top+50);   //璁剧疆鏂扮獥浣撲綅缃紝褰撳墠绐椾綋鐨勫彸渚э紙X杞存柟鍚戯級
+                this.Height = mg.Height - 50;
+                this.Location = new Point(mg.Left + mg.Width - this.Width, mg.Top + 50);
             }
             else
             {
-                //this.StartPosition = FormStartPosition.Manual;   //璁剧疆绐椾綋浣嶇疆鐢辩▼搴忔帶鍒�
                 this.Height = mg.Height;
-                this.Location = new Point(mg.Left + mg.Width - 15, mg.Top);   //璁剧疆鏂扮獥浣撲綅缃紝褰撳墠绐椾綋鐨勫彸渚э紙X杞存柟鍚戯級
+                this.Location = new Point(mg.Left + mg.Width - 15, mg.Top);
             }
             fr = mg;
-
-            //GlobalObject.PropertyForm.Show();
         }
         public Form GetWindow()
         {
@@ -44,15 +58,14 @@
         public void SetObj(object o)
         {
             propertyGridControl1.SelectedObject = o;
-            this.Text= o.GetType().Name;
+            this.Text = o.GetType().Name;
         }
         public void SetObj(IBaseViewModel selectedObject)
         {
-            lock(selectedObject)
+            lock (selectedObject)
             {
                 _selectedObject = selectedObject;
 
-                
 
                 if (_selectedObject is JunctionViewModel junc)
                 {
@@ -101,10 +114,11 @@
                 {
                     _selectedType = MapObjectType.鍠峰ご;
                     propertyGridControl1.SelectedObjects = new NozzleViewModel[] { nozzle };
-                } else
+                }
+                else
                 {
                     _selectedType = MapObjectType.鍏ㄩ儴;
-                    propertyGridControl1.SelectedObjects =new IBaseViewModel[] { selectedObject };
+                    propertyGridControl1.SelectedObjects = new IBaseViewModel[] { selectedObject };
                 }
                 switch (_selectedType)
                 {
@@ -127,30 +141,30 @@
                         Text = "閲嶅鍣� Properties";
                         break;
                 }
-
-                
             }
 
         }
         public void SetNet(MapViewNetWork net)
         {
             selectionSet.net = net;
+            RefreshListBox();
         }
+
         public void SetObjs(List<IBaseViewModel> selectedObjects)
         {
             if (selectedObjects == null) return;
             selectedObjects.RemoveAll(obj => obj == null);
-            selectedObjects.ForEach(obj => 
+            selectedObjects.ForEach(obj =>
             {
-                if (obj.Tags==null)
+                if (obj.Tags == null)
                 {
                     obj.Tags = new TagList();
                 }
 
             });
-            
+
             selectionSet.selectedObjects = selectedObjects.ToList();
-            if (selectedObjects.Count ==1)
+            if (selectedObjects.Count == 1)
                 SetObj(selectedObjects[0]);
             else
                 ShowProperties(selectedObjects);
@@ -163,13 +177,12 @@
         {
             foreach (var item in Enum.GetValues(typeof(MapObjectType)))
             {
-                comboBox_type.Items.Add(item);
+                comboBox_type.Properties.Items.Add(item);
             }
             comboBox_type.SelectedIndex = 0;
             selectionSets = new List<SelectionSet>();
             selectionSet = new SelectionSet();
-            listBox1.DataSource = selectionSet.View;
-            //listBox1.DisplayMember = "IDType";
+            this.listBoxControl1.DataSource = selectionSet.View;
         }
 
         private void comboBox_type_SelectedIndexChanged(object sender, EventArgs e)
@@ -179,11 +192,11 @@
         void RefreshListBox()
         {
             if (selectionSet == null) return;
-            if (comboBox_type.Items.Count<1)
+            if (comboBox_type.Properties.Items.Count < 1)
             {
                 foreach (var item in Enum.GetValues(typeof(MapObjectType)))
                 {
-                    comboBox_type.Items.Add(item);
+                    comboBox_type.Properties.Items.Add(item);
                 }
                 comboBox_type.SelectedIndex = 0;
             }
@@ -192,35 +205,25 @@
             // 浣跨敤 LINQ 鏌ヨ绛涢�夐�夋嫨闆�
             selectionSet.filterType = selectedType;
             selectionSet.FilterString = textBox_search.Text;
-
-
-            listBox1.SelectedIndexChanged -= listBox1_SelectedIndexChanged;
-
-
-
-            //listBox1.DisplayMember = "ID";
-            //// 閲嶆柊缁戝畾閫夋嫨闆嗗垪琛�
-            //listBox1.DataSource = selectionSet.View;
-            listBox1.DataSource = null;
-            //listBox1.DisplayMember = "IDType";
-            listBox1.DataSource = selectionSet.View;
-
-            listBox1.SelectedIndexChanged += listBox1_SelectedIndexChanged;
+              
+            this.listBoxControl1.DataSource = null;
+            this.listBoxControl1.DataSource = selectionSet.View;
+             
         }
 
         private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
         {
 
-            if (listBox1.SelectedItems.Count == 0)
+            if (this.listBoxControl1.SelectedItems.Count == 0)
             {
                 return;
             }
-            else if (listBox1.SelectedItems.Count == 1)
+            else if (this.listBoxControl1.SelectedItems.Count == 1)
             {
-                var objID = listBox1.SelectedItems[0];
+                var objID = this.listBoxControl1.SelectedItems[0];
                 var findlist = selectionSet.net.MapObjects.FindAll(o => o.ID == objID);
                 if (findlist.Count <= 0) return;
-                IBaseViewModel mapObject = findlist[0];// selectionSet.selectedObjects.Find(obj => obj.ID == ((MapObject)listBox1.SelectedItems[0]).ID);
+                IBaseViewModel mapObject = findlist[0];// selectionSet.selectedObjects.Find(obj => obj.ID == ((MapObject)this.listBoxControl1.SelectedItems[0]).ID);
                 if (mapObject != null) SetObj(mapObject);
                 GlobalObject.map.selectedObjs.ForEach(o => o.Selected = false); ;
                 GlobalObject.map.selectedObjs.Clear();
@@ -231,102 +234,46 @@
             else
             {
                 List<IBaseViewModel> list = new List<IBaseViewModel>();
-                foreach (var o in listBox1.SelectedItems)
+                foreach (var o in this.listBoxControl1.SelectedItems)
                 {
-                    var objID = listBox1.SelectedItems[0];
-                    IBaseViewModel mapObject = selectionSet. net.MapObjects.FindAll(obj => obj.ID == objID)[0];
+                    var objID = this.listBoxControl1.SelectedItems[0];
+                    IBaseViewModel mapObject = selectionSet.net.MapObjects.FindAll(obj => obj.ID == objID)[0];
                     list.Add(mapObject);
                 }
-                ShowProperties( list);
+                ShowProperties(list);
                 GlobalObject.map.selectedObjs.ForEach(o => o.Selected = false); ;
                 GlobalObject.map.selectedObjs.Clear();
-                list.ForEach(o=>o.Selected=true);
+                list.ForEach(o => o.Selected = true);
                 GlobalObject.map.selectedObjs.AddRange(list);
                 GlobalObject.map.SetMapInvalidate();
             }
-           
-
 
         }
         private void listBox1_DoubleClick(object sender, EventArgs e)
         {
-            if (listBox1.SelectedItems.Count == 1)
-            {
-                //IBaseViewModel mapObject = (IBaseViewModel)listBox1.SelectedItems[0];
-                var objID = listBox1.SelectedItems[0];
+            if (this.listBoxControl1.SelectedItems.Count == 1)
+            { 
+                var objID = this.listBoxControl1.SelectedItems[0];
                 IBaseViewModel mapObject = selectionSet.net.MapObjects.FindAll(obj => obj.ID == objID)[0];
-                GlobalObject.map.setCenter (mapObject);
-
-
+                GlobalObject.map.setCenter(mapObject);  
                 GlobalObject.map.SetMapInvalidate();
             }
         }
-        private void PropertyForm_FormClosing(object sender, FormClosingEventArgs e)
-        {
-            e.Cancel = true;
-            this.Hide();
-        }
 
-        bool _isEnable = true;
-
-        private static Dictionary<object, List<object>> _selectedObjectsDict = new Dictionary<object, List<object>>();
-        private void propertyGridControl1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
-        {
-            //foreach (var item in listBox1.SelectedItems)
-            //{
-
-            //    var mapObject = selectionSet.selectedObjects.Find(obj => obj.ID == ((MapObject)item).ID);
-            //    if (e.ChangedItem.Label == " 鎵规缂栧彿 ")
-            //    {
-            //        mapObject.Level = (int)e.ChangedItem.Value;
-            //    }
-            //}
-            if (!_isEnable)
-            {
-                MessageBox.Show("褰撳墠鐘舵�佺殑淇敼灏嗕笉浼氳淇濆瓨","閲嶅鍣ㄥ睍寮�涓�");
-                _isEnable = true;
-            }
-
-
-            //object firstObj = selectionSet.selectedObjects.First();
-
-
-            //if (_selectedObjectsDict[firstObj].Contains(e.ChangedItem.Label))
-            //{
-            //    foreach (var obj in selectionSet.selectedObjects)
-            //    {
-            //        var props = TypeDescriptor.GetProperties(obj);
-            //        foreach (PropertyDescriptor prop in props)
-            //        {
-            //            if (prop.Name == e.ChangedItem.Label)
-            //            {
-            //                prop.SetValue(obj, e.ChangedItem.Value);
-            //                break;
-            //            }
-            //        }
-            //    }
-            //}
-            GlobalObject.map.SetMapInvalidate();
-        }
-
-        
 
         public void ShowProperties(IEnumerable<IBaseViewModel> selectedObjects)
         {
             IBaseViewModel[] objs = null;
             try
             {
-                if (selectedObjects!=null)
-                    objs= selectedObjects.ToArray();
+                if (selectedObjects != null)
+                    objs = selectedObjects.ToArray();
             }
             catch
             {
                 return;
             }
             propertyGridControl1.SelectedObjects = objs;
-
-
-
         }
 
         private void textBox_search_TextChanged(object sender, EventArgs e)
@@ -339,12 +286,12 @@
             selectionSet.OnlyViewSelected = checkBox_OnlyShowSelected.Checked;
             RefreshListBox();
         }
-        
+
         private void label_lock_Click(object sender, EventArgs e)
         {
             var label_lock = (Label)sender;
 
-            GlobalObject.LockSelect=!GlobalObject.LockSelect;
+            GlobalObject.LockSelect = !GlobalObject.LockSelect;
             if (GlobalObject.LockSelect)
             {
                 label_lock.BackColor = Color.Blue;
@@ -353,16 +300,16 @@
             else
             {
                 label_lock.BackColor = Color.Green;
-                label_lock.Text = "馃敁"; 
+                label_lock.Text = "馃敁";
             }
         }
         private void label_filter_Click(object sender, EventArgs e)
         {
             var label_lock = (Label)sender;
 
-           
+
             TagList tags = new TagList();
-            var mobjs=selectionSet.OnlyViewSelected? selectionSet.selectedObjects:selectionSet.net.MapObjects;
+            var mobjs = selectionSet.OnlyViewSelected ? selectionSet.selectedObjects : selectionSet.net.MapObjects;
             foreach (var item in mobjs)
             {
                 tags.AddRange(item.Tags);
@@ -373,10 +320,10 @@
             var form = new FormFilter(tags);
             if (form.ShowDialog() == DialogResult.OK)
             {
-                
+
                 selectionSet.FilterTags = form.Tags;
                 selectionSet.rules = form.rules;
-                GlobalObject.ApplyFilter=selectionSet.FilterTags.Count > 0 || selectionSet.rules.Count > 0;
+                GlobalObject.ApplyFilter = selectionSet.FilterTags.Count > 0 || selectionSet.rules.Count > 0;
                 if (GlobalObject.ApplyFilter)
                 {
 
@@ -392,8 +339,7 @@
 
                 RefreshListBox();
             }
-            
-            
+
         }
 
         private void PropertyForm_KeyDown(object sender, KeyEventArgs e)
@@ -401,49 +347,187 @@
             //Ctrl+A锛屽垯閫変腑褰撳墠listbox涓殑鎵�鏈夐」
             if (e.Control && e.KeyCode == Keys.A)
             {
-                for (int i = 0; i < listBox1.Items.Count; i++)
+                for (int i = 0; i < this.listBoxControl1.Items.Count; i++)
                 {
-                    listBox1.SetSelected(i, true);
+                    this.listBoxControl1.SetSelected(i, true);
                 }
             }
         }
 
-
-        private void 鍏ㄩ�塗oolStripMenuItem_Click(object sender, EventArgs e)
-        {
-            listBox1.SelectedIndexChanged -= listBox1_SelectedIndexChanged;
-            for (int i = 0; i < listBox1.Items.Count; i++)
-            {
-                listBox1.SetSelected(i, true);
-            }
-            listBox1.SelectedIndexChanged += listBox1_SelectedIndexChanged;
-            this.propertyGridControl1.SelectedObjects =selectionSet. CurrentSelectedObjects?.ToArray();
-            GlobalObject.map.selectedObjs.ForEach(o => o.Selected = false);
-            if (selectionSet.CurrentSelectedObjects!=null)
-            {
-                GlobalObject.map.selectedObjs.AddRange(selectionSet.CurrentSelectedObjects);
-                selectionSet.CurrentSelectedObjects.ForEach(o => 
-                {
-                    o.Selected = true;
-                });
-            }
-            GlobalObject.map.SetMapInvalidate();
-
-
-
-
-        }
-
-        private void listBox1_MouseDown(object sender, MouseEventArgs e)
+        private void listBoxControl1_MouseDown(object sender, MouseEventArgs e)
         {
             if (e.Button == MouseButtons.Right)
             {
-                if (listBox1.SelectedItems.Count > 0)
+                this.popupMenuRight.ShowPopup(MousePosition);
+            }
+
+        }
+
+        private void barBtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
+        {
+            if (this.listBoxControl1.SelectedItems.Count == 1)
+            { 
+                GlobalObject.map.DeleteChoosedObj();
+                RefreshListBox();
+            }
+        }
+
+
+        #region Property
+
+
+        //鑷畾涔夊睘鎬eader鏄剧ず
+        private void propertyGridControl1_CustomDrawRowHeaderCell(object sender, CustomDrawRowHeaderCellEventArgs e)
+        {
+            //瀛楁鍚嶇О
+            var fieldName = e.Row.Properties.FieldName.Split(new char[] { '.' }).Last();
+            if (string.IsNullOrEmpty(fieldName))
+            {
+                return;
+            }
+            var realFieldName = fieldName;
+            //灞炴�ф弿杩板櫒
+            var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row);
+            if (descriptor != null)
+            {
+                //鍚嶇О
+                var displayNameAttri = (DisplayNameAttribute)descriptor.Attributes[typeof(DisplayNameAttribute)];
+                if (displayNameAttri != null && !string.IsNullOrEmpty(displayNameAttri.DisplayName))
                 {
-                    contextMenuStrip1.Show(listBox1, e.Location);
+                    e.Caption = displayNameAttri.DisplayName;
                 }
             }
         }
+
+        //鑷畾涔夊睘鎬у�兼樉绀�
+        private void propertyGridControl1_CustomDrawRowValueCell(object sender, CustomDrawRowValueCellEventArgs e)
+        {
+            //琛屽瓧娈靛悕绉�
+            var fieldName = e.Row.Properties.FieldName.Split(new char[] { '.' }).Last();
+            if (string.IsNullOrEmpty(fieldName))
+            {
+                return;
+            }
+            //琛岀被鍨嬪叏鍚嶇О
+            var fullTypeName = e.Row.Properties.RowType.FullName;
+
+            if (fullTypeName == typeof(DateTime).FullName)
+            {
+                e.CellText = ((DateTime)e.Properties.Value).ToString("yyyy-MM-dd HH:mm:ss");
+            }
+            else if (fullTypeName == typeof(string[]).FullName)
+            {
+                var stringValue = (string[])e.Properties.Value;
+                e.CellText = stringValue?.Length.ToString();
+            }
+            else if (fullTypeName == typeof(DictionaryPropertyAdapter).FullName)
+            {
+                e.CellText = string.Empty;
+            }
+            else
+            {
+                var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row);
+                if (descriptor != null)
+                {
+                    var displayUnitAttri = (DisplayUnitAttribute)descriptor.Attributes[typeof(DisplayUnitAttribute)];
+                    if (displayUnitAttri != null)
+                    {
+                        if (e.Properties.Value != null)
+                        {
+                            e.CellText = e.Properties.Value.ToString() + " " + displayUnitAttri.Unit;
+                        }
+                    }
+                }
+            }
+        }
+
+        //灞炴�х紪杈戞鐨勬樉绀轰笌鍙栨秷
+        private void propertyGridControl1_ShowingEditor(object sender, CancelEventArgs e)
+        {
+            var rowTypeFullName = this.propertyGridControl1.FocusedRow.Properties.RowType.FullName;
+            var fieldName = this.propertyGridControl1.FocusedRow.Properties.FieldName.Split(new char[] { '.' }).Last();
+
+            if (rowTypeFullName == typeof(Image).FullName)
+            {
+                e.Cancel = true;
+                return;
+            }
+
+            var descriptor = this.propertyGridControl1.GetPropertyDescriptor(this.propertyGridControl1.FocusedRow); 
+            var showEditor = (ShowEditorAttribute)descriptor.Attributes[typeof(ShowEditorAttribute)];
+            if (showEditor != null)
+            {
+                if (!showEditor.ShowEditor)
+                {
+                    e.Cancel = true;
+                    return;
+                }
+            }
+
+        }
+
+        //缂栬緫妗�
+        private void propertyGridControl1_CustomRecordCellEdit(object sender, GetCustomRowCellEditEventArgs e)
+        {
+            var fieldName = e.Row.Properties.FieldName.Split(new char[] { '.' }).Last();
+            if (string.IsNullOrEmpty(fieldName))
+            {
+                return;
+            }
+            var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row);
+            var rowTypeFullName = e.Row.Properties.RowType.FullName;
+
+            #region bool
+
+            if (rowTypeFullName == typeof(bool).FullName)
+            {
+                var ckEdit = new RepositoryItemCheckEdit();
+                ckEdit.CheckStyle = DevExpress.XtraEditors.Controls.CheckStyles.Standard;
+                if (e.Row.Properties.ReadOnly == true)
+                {
+                    ckEdit.ReadOnly = true;
+                }
+                e.RepositoryItem = ckEdit;
+            }
+
+            #endregion
+
+            #region 瀵屾枃鏈�
+
+            if (descriptor != null)
+            {
+                var attri_multi = (MultiTextAttribute)descriptor.Attributes[typeof(MultiTextAttribute)];
+                if (attri_multi != null)
+                {
+                    var memoEdit = new RepositoryItemMemoEdit();
+                    if (e.Row.Properties.ReadOnly == true)
+                    {
+                        memoEdit.ReadOnly = true;
+                    }
+                    e.RepositoryItem = memoEdit;
+                }
+            }
+
+            #endregion
+
+            #region 鍥剧墖
+
+            if (rowTypeFullName == typeof(Image).FullName)
+            {
+                var picEdit = new RepositoryItemPictureEdit();
+                picEdit.ReadOnly = true;
+                picEdit.NullText = "绌�";
+                e.RepositoryItem = picEdit;
+                e.Row.Expanded = true;
+            }
+
+            #endregion
+
+
+
+        } 
+        #endregion
+
     }
 
     public class SelectionSet

--
Gitblit v1.9.3