duheng
2025-01-13 1b7957fac12e80698971513b30e65772c4c5c038
WinFrmUI/HStation.WinFrmUI.Assets.Core/06-threeLink/01-series/AddAssetsThreelinkSeriesDlg.cs
@@ -1,4 +1,7 @@
namespace HStation.WinFrmUI.Assets
using HStation.Vmo;
using Yw;
namespace HStation.WinFrmUI
{
    public partial class AddAssetsThreelinkSeriesDlg : DevExpress.XtraEditors.XtraForm
    {
@@ -6,57 +9,82 @@
        {
            InitializeComponent();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
            this.Load += AddAssetsThreelinkSeriesDlg_Load;
            this.layoutControl1.SetupLayoutControl();
            this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
        }
        public event Func<Vmo.AssetsThreelinkSeriesVmo, object, Task<bool>> ReloadDataEvent = null;
        private static AssetsThreelinkSeriesVmo _last = null;
        private List<AssetsThreelinkSeriesViewModel> _assetsThreelinkSeriesViews;
        /// <summary>
        /// 返回数据事件
        /// </summary>
        public event Action<AssetsThreelinkSeriesVmo> ReloadDataEvent;
        //初始化
        private async void AddAssetsThreelinkSeriesDlg_Load(object sender, EventArgs e)
        private AssetsThreelinkSeriesVmo _vmo = null;
        /// <summary>
        /// 绑定数据
        /// </summary>
        public async void SetBindingData(long parentId)
        {
            _assetsThreelinkSeriesViews = new List<AssetsThreelinkSeriesViewModel>();
            var allList = await new BLL.AssetsThreelinkSeries().GetAll();
            if (allList != null)
            _vmo = new AssetsThreelinkSeriesVmo();
            _vmo.ParentID = parentId;
            var flags = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(HStation.Assets.DataType.ThreelinkSeries);
            this.setFlagsEditCtrl1.SetBindingData(flags?.Select(x => x.Name).ToList(), null);
            if (_last != null)
            {
                foreach (var item in allList)
                {
                    _assetsThreelinkSeriesViews.Add(new AssetsThreelinkSeriesViewModel(item));
                }
                this.txtName.EditValue = _last.Name;
                this.setFlagsEditCtrl1.SetBindingData(flags?.Select(x => x.Name).ToList(), _last.Flags);
                this.txtTagName.EditValue = _last.TagName;
                this.txtDescription.EditValue = _last.Description;
            }
            treeListLookUpEdit1TreeList.DataSource = _assetsThreelinkSeriesViews;
        }
        //数据验证
        private bool Valid()
        //验证
        private async Task<bool> Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(NameTextEdit.Text.Trim()))
            if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.NameTextEdit, "必填项");
                this.dxErrorProvider1.SetError(this.txtName, "必填项");
                return false;
            }
            var tagname = this.txtTagName.Text.Trim();
            if (!string.IsNullOrEmpty(tagname))
            {
                if (await BLLFactory<HStation.BLL.AssetsThreelinkMain>.Instance.IsExistTagName(tagname))
                {
                    this.dxErrorProvider1.SetError(this.txtTagName, "重复");
                    return false;
                }
            }
            return true;
        }
        //完成
        private async void BtnOk_ClickAsync(object sender, EventArgs e)
        //确定
        private async void GeneralOkAndCancelCtrl1_OkEvent()
        {
            if (!Valid())
            if (_vmo == null)
            {
                return;
            var model = new Vmo.AssetsThreelinkSeriesVmo();
            model.Name = NameTextEdit.Text;
            model.TagName = TagNameTextEdit.Text;
            model.Description = DescriptionTextEdit.Text;
            if (await this.ReloadDataEvent.Invoke(model, this.textEditParentList.EditValue))
            {
                TipFormHelper.ShowSucceed("添加成功!");
            }
            else
            if (!await Valid())
            {
                TipFormHelper.ShowError("添加失败!");
                return;
            }
            _vmo.Name = this.txtName.Text.Trim();
            _vmo.Flags = this.setFlagsEditCtrl1.SelectedFlagList;
            _vmo.TagName = this.txtTagName.Text.Trim();
            _vmo.Description = this.txtDescription.Text.Trim();
            var id = await BLLFactory<HStation.BLL.AssetsThreelinkSeries>.Instance.Insert(_vmo);
            if (id < 1)
            {
                TipFormHelper.ShowError("添加失败!");
                return;
            }
            var vmo = await BLLFactory<HStation.BLL.AssetsThreelinkSeries>.Instance.GetByID(id);
            _last = vmo;
            this.ReloadDataEvent?.Invoke(vmo);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }