lixiaojun
2025-02-13 bfd1b73be85fd66ee37031eadcd4d09e7dafb52f
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
namespace HStation.WinFrmUI
{
    /// <summary>
    /// 
    /// </summary>
    public partial class XhsProjectResultRevitCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public XhsProjectResultRevitCtrl()
        {
            InitializeComponent();
            this.gridView1.SetNormalView(30);
            this.gridView1.RegistCustomDrawRowIndicator(40);
            InitialPropStatus();
            this.generalSearchAndExportCtrl1.SearchEvent += Search;
            this.generalSearchAndExportCtrl1.ClearEvent += Clear;
            this.generalSearchAndExportCtrl1.ExportEvent += Export;
        }
 
        private ImportXhsProjectViewModel _vm = null;//操作对象
        private List<XhsProjectResultRevitViewModel> _allList = null;//所有列表
        private List<XhsProjectResultRevitViewModel> _allBindingList;//绑定列表
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(ImportXhsProjectViewModel vm)
        {
            if (vm == null)
            {
                return;
            }
            _vm = vm;
            SetBindingData(vm.RevitModel);
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(Model.RevitModel revitModel)
        {
            if (revitModel == null)
            {
                return;
            }
            _allList = new List<XhsProjectResultRevitViewModel>();
            var allParterList = revitModel.GetAllParters();
            foreach (var parter in allParterList)
            {
                if (parter.PropStatusList != null && parter.PropStatusList.Count > 0)
                {
                    foreach (var propStatus in parter.PropStatusList)
                    {
                        if (propStatus.PropStatus == Revit.ePropStatus.Normal)
                        {
                            continue;
                        }
                        _allList.Add(new XhsProjectResultRevitViewModel(parter, propStatus));
                    }
                }
            }
            Search();
        }
 
        //查询
        private void Search()
        {
            _allBindingList = _allList?.ToList();
            var catalog = this.txtCatalog.Text.Trim();
            if (!string.IsNullOrEmpty(catalog))
            {
                _allBindingList = _allBindingList?.Where(x => !string.IsNullOrEmpty(x.Catalog) && x.Catalog.Contains(catalog)).ToList();
            }
            var name = this.txtName.Text.Trim();
            if (!string.IsNullOrEmpty(name))
            {
                _allBindingList = _allBindingList?.Where(x => !string.IsNullOrEmpty(x.Name) && x.Name.Contains(name)).ToList();
            }
            var code = this.txtCode.Text.Trim();
            if (!string.IsNullOrEmpty(code))
            {
                _allBindingList = _allBindingList?.Where(x => !string.IsNullOrEmpty(x.Code) && x.Code.Contains(code)).ToList();
            }
            Revit.ePropStatus? propStatus = this.imgCmbPropStatus.EditValue == null ? null : (Revit.ePropStatus)this.imgCmbPropStatus.EditValue;
            if (propStatus.HasValue)
            {
                _allBindingList = _allBindingList?.Where(x => x.PropStatus == propStatus.Value).ToList();
            }
            this.xhsProjectResultRevitViewModelBindingSource.DataSource = _allBindingList;
            this.xhsProjectResultRevitViewModelBindingSource.ResetBindings(false);
        }
 
        //清理
        private void Clear()
        {
            this.txtCatalog.EditValue = null;
            this.txtName.EditValue = null;
            this.txtCode.EditValue = null;
            this.imgCmbPropStatus.EditValue = null;
            Search();
        }
 
        //导出
        private void Export()
        {
            var dlg = new SaveFileDialog();
            dlg.Title = "Excel导出";
            dlg.Filter = "Excel文件|*.xls";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.gridView1.ExportToXls(dlg.FileName);
                TipFormHelper.ShowSucceed("导出成功!");
            }
        }
 
        //初始化属性状态
        private void InitialPropStatus()
        {
            this.imgCmbPropStatus.Properties.BeginUpdate();
            this.imgCmbPropStatus.Properties.Items.Clear();
            this.imgCmbPropStatus.Properties.Items.Add("全部", null, -1);
            this.imgCmbPropStatus.Properties.Items.Add(Revit.ePropStatus.Lack.GetDisplayText(), Revit.ePropStatus.Lack, -1);
            this.imgCmbPropStatus.Properties.Items.Add(Revit.ePropStatus.Abnormal.GetDisplayText(), Revit.ePropStatus.Abnormal, -1);
            this.imgCmbPropStatus.Properties.Items.Add(Revit.ePropStatus.Error.GetDisplayText(), Revit.ePropStatus.Error, -1);
            this.imgCmbPropStatus.Properties.EndUpdate();
        }
 
        //自定义单元格颜色
        private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            var row = this.gridView1.GetRow(e.RowHandle) as XhsProjectResultRevitViewModel;
            if (row == null)
            {
                return;
            }
            if (e.RowHandle != this.gridView1.FocusedRowHandle)
            {
                switch (row.PropStatus)
                {
                    case Revit.ePropStatus.Lack:
                        {
                            e.Appearance.BackColor = Color.Gray;
                            e.Appearance.ForeColor = Color.White;
                        }
                        break;
                    case Revit.ePropStatus.Abnormal:
                        {
                            e.Appearance.BackColor = Color.Orange;
                            e.Appearance.ForeColor = Color.White;
                        }
                        break;
                    case Revit.ePropStatus.Error:
                        {
                            e.Appearance.BackColor = Color.Red;
                            e.Appearance.ForeColor = Color.White;
                        }
                        break;
                    default: break;
                }
            };
        }
 
 
    }
}