ningshuxia
2025-03-28 ce9752fd657c6689ea64929eb962146e2730624e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
using DevExpress.Mvvm.POCO;
using DevExpress.XtraBars;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraLayout.Utils;
using DevExpress.XtraVerticalGrid.Events;
using PBS.Vmo;
using System.ComponentModel;
using Yw.Untity;
using Yw.WinFrmUI;
 
namespace PBS.WinFrmUI
{
    public partial class HomePbsProjectPropertyCtrl : XtraUserControl
    {
        public HomePbsProjectPropertyCtrl()
        {
            InitializeComponent();
            //this.layoutControl1.SetupLayoutControl();
            SetDescriptionVisible(false);//默认设置属性描述面板不显示
            this.barBtnDirect.Visibility = BarItemVisibility.Never;
        }
 
        /// <summary>
        /// 跳转事件
        /// </summary>
        public event Action<long> JumpDirectEvent;
 
        private List<FacilityVmo> _allBindingList;
 
        /// <summary>
        /// 绑定对象
        /// </summary>
        public HomePbsProjectPropertyViewModel SelectedObject
        {
            get
            {
                return this.propertyGridControl1.SelectedObject as HomePbsProjectPropertyViewModel;
            }
            set
            {
                this.propertyGridControl1.SelectedObject = value;
                OnChanged();
            }
        }
 
        //改变触发
        protected virtual void OnChanged()
        {
            if (this.SelectedObject == null)
            {
                this.barBtnDirect.Visibility = BarItemVisibility.Never;
            }
            else
            {
                this.barBtnDirect.Visibility = BarItemVisibility.Always;
            }
        }
 
        /// <summary>
        /// 重新从数据源中读取数据,外观恢复刚开始加载的样子
        /// </summary>
        public void UpdateData()
        {
            this.propertyGridControl1.UpdateData();
        }
 
        /// <summary>
        /// 更新数据,样式不变
        /// </summary>
        public void UpdateRows()
        {
            this.propertyGridControl1.UpdateRows();
        }
 
        //设置描述控件的可见性
        private void SetDescriptionVisible(bool isVisible)
        {
            var visible = isVisible ? LayoutVisibility.Always : LayoutVisibility.Never;
            this.layoutDescription.Visibility = this.splitterItem1.Visibility = visible;
        }
 
        //自定义属性值显示内容
        private void propertyGridControl1_CustomDrawRowValueCell(object sender, CustomDrawRowValueCellEventArgs e)
        {
            var rowTypeFullName = e.Row.Properties.RowType.FullName;
 
            if (rowTypeFullName == typeof(DateTime).FullName)
            {
                e.CellText = ((DateTime)e.Properties.Value).ToString("yyyy-MM-dd HH:mm:ss");
            }
            else
            {
                var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row);
                var displayUnit = (DisplayUnitAttribute)descriptor.Attributes[typeof(DisplayUnitAttribute)];
                if (displayUnit != null)
                {
                    if (e.Properties.Value != null)
                    {
                        e.CellText = e.Properties.Value.ToString() + displayUnit.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();
            var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row);
            var rowTypeFullName = e.Row.Properties.RowType.FullName;
 
            #region 属性显示名称和描述
 
            //名称
            var attri_caption = (DisplayNameAttribute)descriptor.Attributes[typeof(DisplayNameAttribute)];
            if (attri_caption != null && !string.IsNullOrEmpty(attri_caption.DisplayName))
            {
                e.Row.Properties.Caption = attri_caption.DisplayName;
            }
 
            //备注
            if (e.Row.Properties.Value == null)
            {
                e.Row.Properties.ToolTip = string.Empty;
            }
            else
            {
                if (e.Row.Properties.RowType.IsEnum)
                {
                    e.Row.Properties.ToolTip = ((Enum)(e.Row.Properties.Value)).GetDisplayText();
                }
                else if (e.Row.Properties.RowType.FullName == typeof(DateTime).FullName)
                {
                    e.Row.Properties.ToolTip = ((DateTime)e.Row.Properties.Value).ToString("yyyy-MM-dd HH:mm:ss");
                }
                else if (e.Row.Properties.RowType.FullName == typeof(Image).FullName)
                {
                    e.Row.Properties.ToolTip = string.Empty;
                }
                else
                {
                    e.Row.Properties.ToolTip = e.Row.Properties.Value.ToString();
                }
            }
 
            #endregion 属性显示名称和描述
 
            #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 bool
 
            #region 富文本
 
            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 图片
        }
 
        //属性值正在改变
        private void propertyGridControl1_CellValueChanging(object sender, DevExpress.XtraVerticalGrid.Events.CellValueChangedEventArgs e)
        {
        }
 
        //属性值改变,更新地图和JsonModel对象
        private void propertyGridControl1_CellValueChanged(object sender, DevExpress.XtraVerticalGrid.Events.CellValueChangedEventArgs e)
        {
            var fieldName = e.Row.Properties.FieldName.Split(new char[] { '.' }).Last();
            var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row);
        }
 
        // 描述
        private void barBtnHelp_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var visible = this.splitterItem1.Visibility == LayoutVisibility.Always ? false : true;
            SetDescriptionVisible(visible);
        }
 
        //全部展开
        private void barBtnExpandAll_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.propertyGridControl1.ExpandAllRows();
        }
 
        //全部折叠
        private void barBtnCollpseAll_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.propertyGridControl1.CollapseAllRows();
        }
 
        //跳转
        private void barBtnDirect_ItemClick(object sender, ItemClickEventArgs e)
        {
            /*   if (this.SelectedObject == null)
               {
                   return;
               }
               JumpDirectEvent?.Invoke(this.SelectedObject.Project.ID);*/
        }
    }
}