tx
2025-04-09 fa7510e1ed63df0366787fa4ed1b3db6426d2b46
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
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using TProduct.WinFrmUI.DataBase;
 
namespace TProduct.WinFrmUI.Data4Factory
{
    public partial class ProductStyleMgrPage : DocumentPage
    {
        public ProductStyleMgrPage()
        {
            InitializeComponent();
            this.PageTitle.Caption = "设备分类";
            this._pageOperateInfo = "设备分类列表";
            this.gridViewMain.SetNormalView(42);
            this.gridViewMain.SetGridMianViewColor();
            this.gridViewMain.RegistCustomDrawRowIndicator(25);
        }
        public class CurrentViewModel : Model.ProductStyle
        {
            public CurrentViewModel() { }
            public CurrentViewModel(Model.ProductStyle rhs, List<Model.LoginUser> userList) : base(rhs)
            {
                this.UpadteName = userList?.Find(x => x.ID == rhs?.UpdateUserID)?.RealName;
                this.CreateName = userList?.Find(x => x.ID == rhs?.CreateUserID)?.RealName;
            }
            public string UpadteName { get; set; }
            public string CreateName { get; set; }
            public string strCreateTime
            {
                get
                {
                    var A = DateTime.Compare(this.CreateTime, Convert.ToDateTime("2008-8-8"));
                    if (A > 0)
                    {
                        return this.CreateTime.ToString("yyyy-MM-dd HH:mm");
                    }
                    else
                        return "";
                }
            }
            public string strUpdateTime
            {
                get
                {
                    var A = DateTime.Compare(this.UpdateTime, Convert.ToDateTime("2008-8-8"));
                    if (A > 0)
                    {
                        return this.UpdateTime.ToString("yyyy-MM-dd HH:mm");
                    }
                    else
                        return "";
                }
            }
        }
 
        private List<CurrentViewModel> _bindList = null;
        private List<Model.LoginUser> _userList = null;
        /// <summary>
        /// 初始化数据
        /// </summary>
        public override void InitialDataSource()
        {
            _bindList = new List<CurrentViewModel>();
            var ProductStyleList = new BLL.ProductStyle().GetAll();
            _userList = new BLL.LoginUser().GetAll();
            ProductStyleList?.ForEach(x => _bindList.Add(new CurrentViewModel(x, _userList)));
 
            this.bindingSource1.DataSource = _bindList;
            this.bindingSource1.ResetBindings(false);
        }
 
 
        #region 基础方法
        private void Add()
        {
            WaitFrmHelper.ShowWaitForm();
            var dlg = new AddProductStyleDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData();
            dlg.ReloadDataEvent += (rhs) =>
            {
                var vm = new CurrentViewModel(rhs, _userList);
                _bindList.Add(vm);
                this.bindingSource1.ResetBindings(false);
                XtraMessageBox.Show("添加成功!");
                ShowCmdOperateInfo("添加成功!");
                this.gridViewMain.RefreshData();
 
            };
            ShowCmdOperateInfo("添加设备分类信息");
            dlg.ShowDialog();
            ShowCmdOperateInfo(_pageOperateInfo);
        }
 
        private void Edit()
        {
            var row = this.gridViewMain.GetCurrentViewModel(_bindList);
            if (row == null)
            {
                XtraMessageBox.Show("请选择一行数据!");
                ShowCmdOperateInfo("请选择一行数据!");
                return;
            }
            WaitFrmHelper.ShowWaitForm();
            var dlg = new EditProductStyleDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData(row);
            dlg.ReloadDataEvent += (rhs) =>
            {
                row.Reset(rhs);
                this.bindingSource1.ResetBindings(false);
                this.gridViewMain.RefreshData();
                XtraMessageBox.Show("修改成功!");
                ShowCmdOperateInfo(_pageOperateInfo);
 
            };
            ShowCmdOperateInfo("编辑设备分类信息");
            dlg.ShowDialog();
            ShowCmdOperateInfo(_pageOperateInfo);
 
        }
        #endregion
 
        #region 界面操作
        private void barBtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Add();
        }
 
        private void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Edit();
        }
 
        #endregion
 
        private void barBtnExcelDown_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowCmdOperateInfo("导出列表信息到Excel");
            var path = ExcelSaveFilePathHelper.SaveFilePathName();
            ShowCmdOperateInfo(_pageOperateInfo);
            if (string.IsNullOrEmpty(path)) return;
            DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
            options.RawDataMode = true;//所见即所得
            options.TextExportMode = DevExpress.XtraPrinting.TextExportMode.Text;
            this.colID.DisplayFormat.FormatString = "\t{0}";
            this.colID.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;
            this.gridViewMain.OptionsPrint.AutoWidth = false;
 
            this.gridViewMain.ExportToXls(path, options);
            this.colID.DisplayFormat.FormatType = DevExpress.Utils.FormatType.None;
            DialogResult dr = XtraMessageBox.Show("导出成功!是否打开刚刚保存的Excel文件?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (dr != DialogResult.OK)
                return;
            System.Diagnostics.Process.Start(path);
        }
 
        private void barBtnDel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            WaitFrmHelper.ShowWaitForm();
            if (_bindList == null || _bindList.Count < 1)
                return;
            var row = this.gridViewMain.GetCurrentViewModel(_bindList);
            if (row == null)
            {
                WaitFrmHelper.ShowWaitForm();
                XtraMessageBox.Show("请选择一行数据!");
                ShowCmdOperateInfo("请选择一行数据!");
                return;
            }
            ShowCmdOperateInfo("删除数据:" + row.Name);
            DialogResult dr = XtraMessageBox.Show("您确定要删除'" + row.Name + "'这条数据吗?\n(注:如果当前选中数据仍有关联数据则不能将其删除.)", "删除提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (dr != DialogResult.OK)
            {
                ShowCmdOperateInfo(_pageOperateInfo);
                return;
            }
            var del = new BLL.ProductStyle().DeleteByID(row.ID);
            if (del)
            {
                InitialDataSource();
                XtraMessageBox.Show("删除成功!");
                ShowCmdOperateInfo("删除成功!");
            }
            if (!del)
            {
                XtraMessageBox.Show("删除失败!");
                ShowCmdOperateInfo("删除失败!");
            }
            this.Close();
 
        }
 
        private void barBtnView_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var row = this.gridViewMain.GetCurrentViewModel(_bindList);
            if (row == null)
            {
                XtraMessageBox.Show("请选择一行数据!");
                ShowCmdOperateInfo("请选择一行数据!");
                return;
            }
            var dlg = new ViewProductStyleDlg();
            dlg.SetBindingData(row);
            ShowCmdOperateInfo("查看设备分类信息");
            dlg.ShowDialog();
            ShowCmdOperateInfo(_pageOperateInfo);
        }
 
        private void bbi注意事项配置_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var row = this.gridViewMain.GetCurrentViewModel(_bindList);
            if (row == null)
            {
                XtraMessageBox.Show("请选择一行数据!");
                ShowCmdOperateInfo("请选择一行数据!");
                return;
            }
            WaitFrmHelper.ShowWaitForm();
            var dlg = new MgrTestNoticeMain4StyleDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData(row.ID);
            dlg.ShowDialog();
        }
    }
}