Shuxia Ning
2024-11-19 a01861a95ede48fa4979a47b24f21616e362e534
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
using HStation.WinFrmUI.Dict.Core;
using Mapster;
 
namespace HStation.WinFrmUI.Dict
{
    public partial class SetDictDataDlg : DevExpress.XtraEditors.XtraForm
    {
        public SetDictDataDlg()
        {
            InitializeComponent();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
        }
 
        private long _typeId;
 
        private Yw.BLL.SysDictData _bll;
        private List<DictDataViewModel> _allBindingList;
 
        public async void SetBindingData(long typeId)
        {
            _typeId = typeId;
            _bll = new Yw.BLL.SysDictData();
            var alllist = await _bll.GetByTypeID(typeId);
            _allBindingList = new List<DictDataViewModel>();
            if (alllist != null)
            {
                foreach (var item in alllist)
                {
                    _allBindingList.Add(new DictDataViewModel(item));
                }
            }
            this.dictDataViewModelBindingSource.DataSource = _allBindingList;
            this.dictDataViewModelBindingSource.ResetBindings(false);
        }
 
        //完成
        private async void BtnOk_Click(object sender, EventArgs e)
        {
            bool isfinish = false;
            var AddSysPropChoices = new List<Yw.Vmo.SysDictDataVmo>();
            foreach (var item in _allBindingList)
            {
                var choiceitem = item.Adapt<DictDataViewModel, Yw.Vmo.SysDictDataVmo>();
                choiceitem.TypeID = _typeId;
                AddSysPropChoices.Add(choiceitem);
            }
            if (AddSysPropChoices.Count <= 0)
            {
                if (await _bll.DeleteByTypeID(_typeId))
                {
                    isfinish = true;
                }
            }
            else
            {
                if (await _bll.GetByTypeID(_typeId) == null)
                {
                    if (await _bll.Inserts(AddSysPropChoices))
                    {
                        isfinish = true;
                    }
                }
                else if ((await _bll.GetByTypeID(_typeId)).Count == 0)
                {
                    if (await _bll.Inserts(AddSysPropChoices))
                    {
                        isfinish = true;
                    }
                }
                else
                {
                    if (await _bll.DeleteByTypeID(_typeId))
                    {
                        if (await _bll.Inserts(AddSysPropChoices))
                        {
                            isfinish = true;
                        }
                    }
                }
            }
            if (isfinish)
            {
                TipFormHelper.ShowSucceed("设置成功!");
            }
            else
            {
                TipFormHelper.ShowError("设置失败!");
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
        //删除
        private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            if (_allBindingList == null || _allBindingList.Count < 1)
                return;
            var row = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (row == null)
                return;
            if (e.Column == this.ColDelete)
                _allBindingList.Remove(row);
            this.dictDataViewModelBindingSource.ResetBindings(false);
        }
    }
}