lixiaojun
2024-11-08 a1fe0840ce2022ca711994ba10ba3512ae3c43be
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
namespace HStation.WinFrmUI
{
    public partial class AddXhsProjectSimulationSchemeDlg : DevExpress.XtraEditors.XtraForm
    {
        public AddXhsProjectSimulationSchemeDlg()
        {
            InitializeComponent();
            this.dataLayoutControl1.SetupLayoutControl();
        }
 
        /// <summary>
        /// 
        /// </summary>
        public event Action<HStation.Vmo.XhsSchemeVmo> ReloadDataEvent;
 
        private HStation.Vmo.XhsSchemeVmo _scheme = null;
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public async Task SetBindingData(long projectSiteId)
        {
            _scheme = new Vmo.XhsSchemeVmo();
            _scheme.SiteID = projectSiteId;
            _scheme.UseStatus = Yw.Model.eUseStatus.Enable;
            _scheme.SchemeType = eSchemeType.Common;
 
            InitialSchemeType();
            await InitialFlags();
        }
 
        //初始化文件格式
        private void InitialSchemeType()
        {
            this.imgCmbSchemeType.Properties.BeginUpdate();
            this.imgCmbSchemeType.Properties.Items.Clear();
            this.imgCmbSchemeType.Properties.Items.AddEnum(typeof(HStation.Xhs.eSchemeType), false);
            this.imgCmbSchemeType.EditValue = eSchemeType.Common;
            this.imgCmbSchemeType.Properties.EndUpdate();
        }
 
        //初始化标签
        private async Task InitialFlags()
        {
            var allFlagList = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(HStation.Xhs.DataType.XhsScheme);
            var allFlagNameList = allFlagList?.Select(x => x.Name).ToList();
            this.setFlagsEditCtrl1.SetBindingData(allFlagNameList, null);
        }
 
        //验证
        private bool Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.txtName, "必填项");
                return false;
            }
            if (string.IsNullOrEmpty(this.imgCmbSchemeType.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.imgCmbSchemeType, "必选项");
                return false;
            }
            return true;
        }
 
        //确定
        private async void btnOk_Click(object sender, EventArgs e)
        {
            if (!Valid())
            {
                return;
            }
            _scheme.NO = this.txtNO.Text.Trim();
            _scheme.Name = this.txtName.Text.Trim();
            _scheme.SchemeType = (eSchemeType)this.imgCmbSchemeType.EditValue;
            _scheme.Flags = this.setFlagsEditCtrl1.SelectedFlagList;
            _scheme.Description = this.txtDescription.Text.Trim();
 
            var id = await BLLFactory<HStation.BLL.XhsScheme>.Instance.Insert(_scheme);
            if (id < 1)
            {
                XtraMessageBox.Show("添加失败!");
                return;
            }
            var scheme = await BLLFactory<HStation.BLL.XhsScheme>.Instance.GetByID(id);
            this.ReloadDataEvent?.Invoke(scheme);
 
            TipFormHelper.ShowSucceed("方案添加成功");
 
            this.DialogResult = DialogResult.OK;
            this.Close();
 
        }
    }
}