duheng
2024-07-16 e18218195caa7fe3af4efa3cd2e53a53a00d98f7
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
namespace HStation.WinFrmUI.Xhs.Core
{
    public partial class XhsProjectMainPanel : DocumentPage
    {
        public XhsProjectMainPanel()
        {
            InitializeComponent();
            this.PageTitle.Caption = "项目管理";
            this.gridView1.SetNormalView();
            this.gridView1.RegistCustomDrawRowIndicator();
        }
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public override void InitialDataSource()
        {
            SetBindingData();
        }
 
        private new BLL.XhsProject _bll = new BLL.XhsProject();
 
        private List<XhsProjectViewModel> _allBindingList = new List<XhsProjectViewModel>();
 
        private XhsProjectViewModel _prjviewmodel = new XhsProjectViewModel();
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        private async void SetBindingData()
        {
            _allBindingList.Clear();
            var alllist = await _bll.GetAll();
            if (alllist != null)
            {
                foreach (var item in alllist)
                {
                    var model = new XhsProjectViewModel(item);
                    _allBindingList.Add(await _prjviewmodel.SetUploadStatusAsync(model));
                }
                this.projectViewModelBindingSource.DataSource = _allBindingList;
                this.projectViewModelBindingSource.ResetBindings(false);
            }
        }
 
        //添加
        private void BtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new AddXhsProjectDlg();
            dlg.ReloadEvent += async (pro, item, model, map) =>
            {
                var id = await _bll.InsertEx(pro, item, model, map);
                if (id > 0)
                {
                    var vmmodel = await _bll.GetByID(id);
                    _allBindingList.Add(await new XhsProjectViewModel().SetUploadStatusAsync(vmmodel));
                    this.projectViewModelBindingSource.ResetBindings(false);
                    return true;
                }
                return false;
            };
            dlg.ShowDialog();
        }
 
        //修改
        private void BtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                MessageBoxHelper.ShowError("请选择数据行!");
                return;
            }
            var dlg = new EditXhsProjectDlg();
            dlg.SetBindingData(vm.ID);
            dlg.ReloadEvent += async (prj, item) =>
            {
                if (await _bll.UpdateEx(prj, item))
                {
                    vm.Reset(prj);
                    this.projectViewModelBindingSource.ResetBindings(false);
                    return true;
                }
                return false;
            };
            dlg.ShowDialog();
        }
 
        //删除
        private async void BtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                MessageBoxHelper.ShowError("请选择数据行!");
                return;
            }
            if (MessageBoxHelper.IsClickOk($"确认删除数据行?", "提示", MessageBoxButtons.OKCancel))
                return;
            var result = await _bll.DeleteEx(vm.ID);
            if (!result)
            {
                MessageBoxHelper.ShowError($"删除失败!", "警告");
                return;
            }
            MessageBoxHelper.ShowSuccess($"删除成功!");
            _allBindingList.Remove(vm);
            this.projectViewModelBindingSource.ResetBindings(false);
        }
 
        //使用状态
        private void BtnUpdateUseStatus_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                MessageBoxHelper.ShowWarning("请选择数据行!");
                return;
            }
            var dlg = new SetUseStatusDlg();
            dlg.SetBindingData(vm.UseStatus);
            dlg.ReloadDataEvent += async (useStatus) =>
            {
                var result = await _bll.UpdateUseStatus(vm.ID, (int)useStatus);
                if (result)
                {
                    vm.UseStatus = useStatus;
                    vm.Reset(vm);
                    this.projectViewModelBindingSource.ResetBindings(false);
                }
                return result;
            };
            dlg.ShowDialog();
        }
 
        //刷新
        private void BtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.SetBindingData();
        }
 
        //历史模型
        private void BtnModelEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                MessageBoxHelper.ShowWarning("请选择数据行!");
                return;
            }
            var dlg = new XhsModelEdit();
            dlg.SetBiningData(vm.ID);
            dlg.ShowDialog();
        }
 
        //模型编辑
        private void BtnEditModel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                MessageBoxHelper.ShowWarning("请选择数据行!");
                return;
            }
            var dlg = new SetModelEditDlg();
            dlg.SetBindingData(vm.ID);
            dlg.ReloadDataEvent += async (rhs) =>
            {
                var bll = new BLL.XhsProjectItemModel();
                if (await bll.Update(rhs))
                {
                    return true;
                }
                return false;
            };
            dlg.ShowDialog();
        }
 
        private async void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            if (_allBindingList == null || _allBindingList.Count < 1)
                return;
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
                return;
            if (e.Column == this.colModelManage)
            {
                var guid = new SurfaceGuid()
                {
                    Function = "模型管理",
                    Modular = eModular.Basic
                };
                if (!IsExistPage(guid, true))
                {
                    var bll = new BLL.XhsProjectItemModel();
                    var result = await bll.GetByPrjID(vm.ID);
                    var select = result.Where(x => x.UseStatus == 1).FirstOrDefault();
                    if (select != null)
                    {
                        /*    var page = new PumpCurveCtrl(select);
                            page.PageTitle.Caption = guid.Function;
                            page.SurfaceGuid = guid;
                            CreatePage(page, guid);*/
                    }
                }
            }
        }
    }
}