duheng
2024-12-04 b32c0a21755ac3e86df0242d993398773cb627f2
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
using DevExpress.XtraEditors.Controls;
using HStation.Vmo;
 
namespace HStation.WinFrmUI.Assets
{
    public partial class AddAssetsMeterMainDlg : DevExpress.XtraEditors.XtraForm
    {
        public AddAssetsMeterMainDlg()
        {
            InitializeComponent();
            this.treeList1.InitialMultiColSettings();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
        }
 
        private Vmo.AssetsMeterMainVmo _MeterVmo = null;
 
        private List<Vmo.AssetsMeterCoefficientVmo> _AssetsMeterCoefficient;
 
        public async void SetBindingData(long SeriesID)
        {
            var bll = new BLL.AssetsMeterCoefficient();
            _AssetsMeterCoefficient = await bll.GetAll();
            this.MeterCoefficientViewModelBindingSource.DataSource = _AssetsMeterCoefficient;
            _MeterVmo = new Vmo.AssetsMeterMainVmo();
            _MeterVmo.SeriesID = SeriesID;
            this.selectFlagsPopupCtrl1.SetBindingData<AssetsFlags>();
        }
 
        public event Func<Vmo.AssetsMeterMainVmo, Task<bool>> ReloadDataEvent = null;
 
        //数据验证
        private bool Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(TextEditName.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.TextEditName, "必填项");
                return false;
            }
            if (string.IsNullOrEmpty(TextEditMinorLoss.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.TextEditMinorLoss, "必填项");
                return false;
            }
 
            return true;
        }
 
        //完成
        private async void BtnOk_ClickAsync(object sender, EventArgs e)
        {
            if (!(Valid()))
                return;
            _MeterVmo.Description = DescriptionTextEdit.Text.Trim();
            _MeterVmo.Name = TextEditName.Text.Trim();
            _MeterVmo.KeyWord = this.TextEditKeyWord.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            if (double.TryParse(TextEditMinorLoss.Text, out double minorLoss))
            {
                _MeterVmo.MinorLoss = minorLoss;
            }
            _MeterVmo.Flags = this.selectFlagsPopupCtrl1.SelectedFlags;
            if (await this.ReloadDataEvent.Invoke(_MeterVmo))
            {
                TipFormHelper.ShowSucceed("添加成功!");
            }
            else
            {
                TipFormHelper.ShowError("添加失败!");
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
        private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            var vm = this.treeList1.GetCurrentViewModel(_AssetsMeterCoefficient);
            if (vm == null)
                return;
            this.TextEditCoefficient.Text = vm.MinorLoss.ToString();
        }
    }
}