lixiaojun
2024-11-23 2c9f613860b0f1f104da43f67895e221e6f7cf11
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
namespace Yw.WinFrmUI
{
    public partial class PartitionMgr : DocumentPage
    {
        public PartitionMgr()
        {
            InitializeComponent();
            this.PageTitle.Caption = "分区";
            this.gridView1.SetNormalView();
            this.gridView1.RegistCustomDrawRowIndicator(50);
        }
 
        private List<PartViewModel> _allbindingList = new List<PartViewModel>();
        private BLL.Part _Bll = new BLL.Part();
 
        //初始化
        public override void InitialDataSource()
        {
            SetBindingData();
        }
 
        private async void SetBindingData()
        {
            var bll = new BLL.Part();
            var all = await bll.GetAll();
            if (all.Count != 0)
            {
                foreach (var item in all)
                {
                    _allbindingList.Add(new PartViewModel(item));
                }
            }
            _allbindingList = _allbindingList.OrderBy(sort => sort.SortCode).ToList();
            this.PartbindingSource.DataSource = _allbindingList;
            this.PartbindingSource.ResetBindings(false);
        }
 
        //添加
        private void barBtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new AddPartDlg();
            dlg.ReloadEvent += async (rhs) =>
            {
                rhs.SortCode = _allbindingList.Count == 0 ? 1 : _allbindingList.Max(x => x.SortCode) + 1;
                var id = await _Bll.Insert(rhs);
                if (id > 0)
                {
                    rhs.ID = id;
                    _allbindingList.Add(new PartViewModel(rhs));
                    this.PartbindingSource.ResetBindings(false);
                    return true;
                }
                return false;
            };
            dlg.ShowDialog();
        }
 
        //编辑
        private async void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allbindingList);
            if (vm == null)
            {
                MessageBox.Show("请选择数据行!");
                return;
            }
            var dlg = new EditPartDlg();
            var model = await _Bll.GetByID(vm.ID);
            if (model == null)
                return;
            dlg.SetbindingData(model);
            dlg.ReloadData += async (rhs) =>
            {
                vm.Reset(rhs);
                if (await _Bll.Update(rhs))
                {
                    return true;
                }
                return false;
            };
            dlg.ShowDialog();
        }
 
        //标签名称
        private void barTagName_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            /*    var vm = this.gridView1.GetCurrentViewModel(_allbindingList);
                if (vm == null)
                {
                    XtraMessageBox.Show("请选择数据行!");
                    return;
                }
                var dlg = new SetTagNameDlg();
                dlg.SetBindingData(vm.TagName);
                dlg.ReloadDataEvent += (rhs) =>
                {
                    vm.TagName = rhs;
                    if (_Bll.Update(vm))
                    {
                        return true;
                    }
                    return false;
                };
                dlg.ShowDialog();*/
        }
 
        //使用状态
        private void barBtnUpdateUseStatus_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            /*   var vm = this.gridView1.GetCurrentViewModel(_allbindingList);
               if (vm == null)
               {
                   XtraMessageBox.Show("请选择数据行");
                   return;
               }
               var dlg = new SetUseStatusDlg();
               dlg.SetBindingData(vm.UseStatus);
               dlg.ReloadDataEvent += (rhs) =>
               {
                   vm.UseStatus = rhs;
                   if (_Bll.Update(vm))
                   {
                       return true;
                   }
                   return false;
               };
 
               dlg.ShowDialog();*/
        }
 
        //排序码
        private void barBtnSortCode_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            /*   var vm = this.gridView1.GetCurrentViewModel(_allbindingList);
               if (vm == null) { XtraMessageBox.Show("请选择数据行!"); }
               var dlg = new SetSortCodeDlg();
               dlg.SetBindingData(vm.SortCode);
               dlg.ReloadDataEvent += (SortCode) =>
               {
                   vm.SortCode = SortCode;
                   if (_Bll.Update(vm))
                   {
                       return true;
                   }
                   return false;
               };
               dlg.ShowDialog();*/
        }
 
        //删除
        private void barBtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            /*     var vm = this.gridView1.GetCurrentViewModel(_allbindingList);
                 if (vm == null)
                 { XtraMessageBox.Show("请选择数据行!"); }
                 if (XtraMessageBox.Show($"确认删除数据行?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) != DialogResult.OK)
                     return;
                 if (_Bll.DeleteByID(vm.ID, out string msg))
                 {
                     XtraMessageBox.Show("删除成功!");
                     _allbindingList.Remove(vm);
                     this.PartbindingSource.ResetBindings(false);
                 }
                 else XtraMessageBox.Show($"删除失败!\n{msg}");*/
        }
 
        //检索
        private void barBtnSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.gridView1.IsFindPanelVisible)
                this.gridView1.HideFindPanel();
            else
                this.gridView1.ShowFindPanel();
        }
    }
}