| | |
| | | namespace HStation.WinFrmUI.Assets |
| | | using HStation.Vmo; |
| | | using Yw; |
| | | |
| | | namespace HStation.WinFrmUI |
| | | { |
| | | public partial class AddAssetsFourlinkSeriesDlg : DevExpress.XtraEditors.XtraForm |
| | | { |
| | |
| | | { |
| | | InitializeComponent(); |
| | | this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon; |
| | | this.Load += AddAssetsFourlinkSeriesDlg_Load; |
| | | this.layoutControl1.SetupLayoutControl(); |
| | | this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent; |
| | | } |
| | | |
| | | public event Func<Vmo.AssetsFourlinkSeriesVmo, object, Task<bool>> ReloadDataEvent = null; |
| | | private static AssetsFourlinkSeriesVmo _last = null; |
| | | |
| | | private List<AssetsFourlinkSeriesViewModel> _assetsFourlinkSeriesViews; |
| | | /// <summary> |
| | | /// 返回数据事件 |
| | | /// </summary> |
| | | public event Action<AssetsFourlinkSeriesVmo> ReloadDataEvent; |
| | | |
| | | //初始化 |
| | | private async void AddAssetsFourlinkSeriesDlg_Load(object sender, EventArgs e) |
| | | private AssetsFourlinkSeriesVmo _vmo = null; |
| | | |
| | | /// <summary> |
| | | /// 绑定数据 |
| | | /// </summary> |
| | | public async void SetBindingData(long parentId) |
| | | { |
| | | _assetsFourlinkSeriesViews = new List<AssetsFourlinkSeriesViewModel>(); |
| | | var allList = await new BLL.AssetsFourlinkSeries().GetAll(); |
| | | if (allList != null) |
| | | _vmo = new AssetsFourlinkSeriesVmo(); |
| | | _vmo.ParentID = parentId; |
| | | var flags = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(HStation.Assets.DataType.FourlinkSeries); |
| | | this.setFlagsEditCtrl1.SetBindingData(flags?.Select(x => x.Name).ToList(), null); |
| | | if (_last != null) |
| | | { |
| | | foreach (var item in allList) |
| | | { |
| | | _assetsFourlinkSeriesViews.Add(new AssetsFourlinkSeriesViewModel(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 = _assetsFourlinkSeriesViews; |
| | | } |
| | | |
| | | //数据验证 |
| | | 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.AssetsFourlinkMain>.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.AssetsFourlinkSeriesVmo(); |
| | | 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.AssetsFourlinkSeries>.Instance.Insert(_vmo); |
| | | if (id < 1) |
| | | { |
| | | TipFormHelper.ShowError("添加失败!"); |
| | | return; |
| | | } |
| | | var vmo = await BLLFactory<HStation.BLL.AssetsFourlinkSeries>.Instance.GetByID(id); |
| | | _last = vmo; |
| | | this.ReloadDataEvent?.Invoke(vmo); |
| | | this.DialogResult = DialogResult.OK; |
| | | this.Close(); |
| | | } |