duheng
2024-11-19 74706b439194deed9c5fde2d5ed02226fc33fd69
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
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
 
namespace HStation.WinFrmUI.Assets
{
    public partial class AddAssetsPackageMainDlg : DevExpress.XtraEditors.XtraForm
    {
        public AddAssetsPackageMainDlg()
        {
            InitializeComponent();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
        }
 
        private Vmo.AssetsPackageMainVmo _EquipmentVmo = null;
 
        public event Func<Vmo.AssetsPackageMainVmo, List<PumpAccountViewModel>, Task<bool>> ReloadDataEvent = null;
 
        private List<PumpAccountViewModel> _allBindingList;
 
        public async void SetBindingData(long SeriesID)
        {
            var pumpAllList = await new BLL.AssetsPumpMain().GetAll();
            this.repositoryItemTreeListLookUpEdit1.DataSource = pumpAllList;
            _allBindingList = new List<PumpAccountViewModel>();
            this.pumpAccountViewModelBindingSource.DataSource = _allBindingList;
            _EquipmentVmo = new Vmo.AssetsPackageMainVmo();
            _EquipmentVmo.SeriesID = SeriesID;
            var bll = new Yw.BLL.SysCatalog();
            var alllist = await bll.GetAll();
            foreach (var item in alllist)
            {
                var imageItem = new ImageComboBoxItem(item.Name, item.ID);
                textEditCatalog.Properties.Items.Add(imageItem);
            }
        }
 
        //删除
        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.pumpAccountViewModelBindingSource.DataSource = _allBindingList;
            this.pumpAccountViewModelBindingSource.ResetBindings(false);
        }
 
        //数据验证
        private bool Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(textEditName.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.textEditName, "必填项");
                return false;
            }
            if (string.IsNullOrEmpty(textEditReserveCount.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.textEditReserveCount, "必填项");
                return false;
            }
 
            return true;
        }
 
        //完成
        private async void BtnOk_ClickAsync(object sender, EventArgs e)
        {
            if (!(Valid()))
                return;
            _EquipmentVmo.Description = DescriptionTextEdit.Text.Trim();
            _EquipmentVmo.Name = textEditName.Text.Trim();
            _EquipmentVmo.NO = textEditNo.Text.Trim();
            if (int.TryParse(this.textEditReserveCount.Text, out int equipmentCount))
            {
                _EquipmentVmo.PumpCount = equipmentCount;
            }
            if (long.TryParse(textEditCatalog.EditValue?.ToString() ?? "", out long catalogID))
            {
                _EquipmentVmo.CatalogID = catalogID;
            }
            if (await this.ReloadDataEvent.Invoke(_EquipmentVmo, _allBindingList))
            {
                TipFormHelper.ShowSucceed("添加成功!");
            }
            else
            {
                TipFormHelper.ShowError("添加失败!");
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}