duheng
2024-10-22 a95dc42495472cf931db97f8ccbe9d075708aa0b
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
using DevExpress.XtraDiagram.Bars;
using DevExpress.XtraEditors.Controls;
using HStation.WinFrmUI.Basic;
using Yw.Basic;
 
namespace HStation.WinFrmUI
{
    public partial class AddPumpPropDlg : DevExpress.XtraEditors.XtraForm
    {
        public AddPumpPropDlg()
        {
            InitializeComponent();
        }
 
        public event Func<Yw.Vmo.SysPropVmo, string, string, Task<bool>> ReloadDataEvent; //属性类, 组名,属性值
 
        private Yw.Vmo.SysPropVmo _AddPropDto { get; set; }
        private Yw.BLL.SysPropMapping _bll = null;
 
        private long _catalogId;
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public async void SetBindingData(long CatalogID)
        {
            _catalogId = CatalogID;
            var catalogVmo = await new Yw.BLL.SysCatalog().GetByID(CatalogID);
            if (catalogVmo == null)
                return;
            var propGroup = new Yw.BLL.SysPropGroup();
            var alllist = await propGroup.GetByTypeID(catalogVmo.TypeID);
            foreach (var item in alllist)
            {
                var imageItem = new ImageComboBoxItem(item.Name, item.ID);
                this.imageComboBoxEditPropGroup.Properties.Items.Add(imageItem);
            }
            _AddPropDto = new Yw.Vmo.SysPropVmo();
            _AddPropDto.TypeID = catalogVmo.TypeID;
        }
 
        private bool Valid()
        {
            bool isContinue = true;
            this.dxErrorProvider1.ClearErrors();
            if (imageComboBoxEditPropGroup.EditValue == null)
            {
                this.dxErrorProvider1.SetError(imageComboBoxEditPropGroup, "必填项!");
                isContinue = false;
            }
            if (textEditName.EditValue == null)
            {
                this.dxErrorProvider1.SetError(textEditName, "必填项!");
                isContinue = false;
            }
            return isContinue;
        }
 
        private async void BtnOk_Click(object sender, EventArgs e)
        {
            if (!Valid())
                return;
            _AddPropDto.GroupID = Convert.ToInt64(this.imageComboBoxEditPropGroup.EditValue);
            _AddPropDto.Name = textEditName.Text.Trim();
            _AddPropDto.Description = TextEditDescription.Text.Trim();
            _AddPropDto.Code = TextEditCode.Text.Trim();
            _AddPropDto.UnitName = TextEditUnitName.Text.Trim();
            _AddPropDto.IsNull = CheckEditIsNull.Checked;
            if (TextEditFormat.SelectedIndex == 0)
            {
                _AddPropDto.Format = (Yw.Basic.ePropFormat)ePropFormat.Integer;
            }
            else if (TextEditFormat.SelectedIndex == 1)
            {
                _AddPropDto.Format = (Yw.Basic.ePropFormat)ePropFormat.Bigint;
            }
            else if (TextEditFormat.SelectedIndex == 2)
            {
                _AddPropDto.Format = (Yw.Basic.ePropFormat)ePropFormat.Numeric;
            }
            else if (TextEditFormat.SelectedIndex == 3)
            {
                _AddPropDto.Format = (Yw.Basic.ePropFormat)ePropFormat.Text;
            }
            else if (TextEditFormat.SelectedIndex == 4)
            {
                _AddPropDto.Format = (Yw.Basic.ePropFormat)ePropFormat.MultiText;
            }
            else if (TextEditFormat.SelectedIndex == 5)
            {
                _AddPropDto.Format = (Yw.Basic.ePropFormat)ePropFormat.Time;
            }
            else
            {
                _AddPropDto.Format = (Yw.Basic.ePropFormat)ePropFormat.Boolen;
            }
            var selected = (ImageComboBoxItem)this.imageComboBoxEditPropGroup.SelectedItem;
            if (await this.ReloadDataEvent.Invoke(_AddPropDto, selected.Description, TextEditValue.Text))
            {
                MessageBoxHelper.ShowSuccess("添加成功!");
            }
            else
            {
                MessageBoxHelper.ShowError("添加失败!");
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}