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