tangxu
2024-03-20 7947ecd7933cc92f5d9565afb51aff6e744074c5
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
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace IStation.WinFrmUI.Product
{
    public partial class AddProductGroupDlg : DevExpress.XtraEditors.XtraForm
    {
        public AddProductGroupDlg()  
        {
            InitializeComponent();
            this.IconOptions.Icon = WinFrmUI.Properties.Resources.app;
            this.dataLayoutControl1.SetupLayoutControl();
        }
 
        /// <summary>
        /// 回调事件
        /// </summary>
        public event Action<Model.ProductGroup> ReloadDataEvent;
 
        private Model.ProductGroup _model = null;//当前操作对象
 
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(long CorpID,string BelongType,long BelongID, int SortCode, List<long> ParentIds = null)
        {
            this.Text = "添加设备组";
            _model = new Model.ProductGroup();
            _model.CorpID = CorpID;
            _model.BelongType = BelongType;
            _model.BelongID = BelongID;
            _model.SortCode = SortCode;
            _model.ParentIds = ParentIds;
        }
 
        //验证
        private bool Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.NameTextEdit.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.NameTextEdit, "必填项");
                return false;
            }
            return true;
        }
 
        //确定
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!Valid())
                return;
            _model.Name = this.NameTextEdit.Text.Trim();
            _model.TagName = this.TagNameTextEdit.Text.Trim();
            _model.Description = this.DescriptionMemoEdit.Text.Trim();
 
            var bll = new BLL.ProductGroup();
            var id = bll.Insert(_model);
            if (id < 1)
            {
                XtraMessageBox.Show("添加失败!");
                return;
            }
            if (this.ReloadDataEvent != null)
            {
                var model = bll.GetByID(_model.CorpID, id);
                this.ReloadDataEvent.Invoke(model);
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
 
    }
}