| | |
| | | using Yw; |
| | | using HStation.Vmo; |
| | | using Yw; |
| | | |
| | | namespace HStation.WinFrmUI |
| | | { |
| | |
| | | { |
| | | InitializeComponent(); |
| | | this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon; |
| | | this.layoutControl1.SetupLayoutControl(); |
| | | this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent; |
| | | } |
| | | |
| | | public event Func<Vmo.AssetsCoolingSeriesVmo, Task<bool>> ReloadDataEvent = null; |
| | | private static AssetsCoolingSeriesVmo _last = null; |
| | | |
| | | private List<AssetsCoolingSeriesMgrViewModel> _assetsTranslationSeriesViews; |
| | | /// <summary> |
| | | /// 返回数据事件 |
| | | /// </summary> |
| | | public event Action<AssetsCoolingSeriesVmo> ReloadDataEvent; |
| | | |
| | | //初始化 |
| | | public async void SetBindingData() |
| | | private AssetsCoolingSeriesVmo _vmo = null; |
| | | |
| | | /// <summary> |
| | | /// 绑定数据 |
| | | /// </summary> |
| | | public async void SetBindingData(long parentId) |
| | | { |
| | | _assetsTranslationSeriesViews = new List<AssetsCoolingSeriesMgrViewModel>(); |
| | | var allList = await BLLFactory<HStation.BLL.AssetsCoolingSeries>.Instance.GetAll(); |
| | | if (allList != null) |
| | | _vmo = new AssetsCoolingSeriesVmo(); |
| | | _vmo.ParentID = parentId; |
| | | var flags = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(HStation.Assets.DataType.CoolingSeries); |
| | | this.setFlagsEditCtrl1.SetBindingData(flags?.Select(x => x.Name).ToList(), null); |
| | | if (_last != null) |
| | | { |
| | | foreach (var item in allList) |
| | | { |
| | | _assetsTranslationSeriesViews.Add(new AssetsCoolingSeriesMgrViewModel(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 = _assetsTranslationSeriesViews; |
| | | } |
| | | |
| | | //数据验证 |
| | | 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.AssetsCoolingMain>.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.AssetsCoolingSeriesVmo(); |
| | | model.Name = NameTextEdit.Text; |
| | | model.TagName = TagNameTextEdit.Text; |
| | | model.Description = DescriptionTextEdit.Text; |
| | | if (this.textEditParentList.EditValue != null) |
| | | { |
| | | model.ParentID = (long)(this.textEditParentList.EditValue); |
| | | } |
| | | if (await this.ReloadDataEvent.Invoke(model)) |
| | | if (!await Valid()) |
| | | { |
| | | TipFormHelper.ShowSucceed("添加成功!"); |
| | | return; |
| | | } |
| | | else |
| | | _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.AssetsCoolingSeries>.Instance.Insert(_vmo); |
| | | if (id < 1) |
| | | { |
| | | TipFormHelper.ShowError("添加失败!"); |
| | | TipFormHelper.ShowError("添加失败!"); |
| | | return; |
| | | } |
| | | var vmo = await BLLFactory<HStation.BLL.AssetsCoolingSeries>.Instance.GetByID(id); |
| | | _last = vmo; |
| | | this.ReloadDataEvent?.Invoke(vmo); |
| | | this.DialogResult = DialogResult.OK; |
| | | this.Close(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | } |