| | |
| | | using DevExpress.Utils; |
| | | using DevExpress.XtraEditors.Controls; |
| | | using DevExpress.XtraEditors; |
| | | using HStation.Vmo; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Data; |
| | | using System.Drawing; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | using Yw; |
| | | |
| | | namespace HStation.WinFrmUI.Assets |
| | | namespace HStation.WinFrmUI |
| | | { |
| | | public partial class EditAssetsPressmeterMainDlg : DevExpress.XtraEditors.XtraForm |
| | | { |
| | | public EditAssetsPressmeterMainDlg() |
| | | { |
| | | InitializeComponent(); |
| | | this.treeList1.InitialMultiColSettings(); |
| | | this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon; |
| | | this.layoutControl1.SetupLayoutControl(); |
| | | this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent; |
| | | } |
| | | |
| | | private Vmo.AssetsPressmeterMainVmo _PressmeterVmo = null; |
| | | /// <summary> |
| | | /// 返回数据事件 |
| | | /// </summary> |
| | | public event Action<HStation.Vmo.AssetsPressmeterMainVmo> ReloadDataEvent; |
| | | |
| | | private List<Vmo.AssetsPressmeterCoefficientVmo> _AssetsPressmeterCoefficient; |
| | | private HStation.Vmo.AssetsPressmeterMainVmo _vmo = null; |
| | | |
| | | public async void SetBindingData(Vmo.AssetsPressmeterMainVmo PressmeterVmo) |
| | | /// <summary> |
| | | /// 绑定数据 |
| | | /// </summary> |
| | | public async void SetBindingData(HStation.Vmo.AssetsPressmeterMainVmo vmo) |
| | | { |
| | | var bll = new BLL.AssetsPressmeterCoefficient(); |
| | | _AssetsPressmeterCoefficient = await bll.GetAll(); |
| | | this.PressmeterCoefficientViewModelBindingSource.DataSource = _AssetsPressmeterCoefficient; |
| | | _PressmeterVmo = PressmeterVmo; |
| | | this.TextEditName.Text = _PressmeterVmo.Name; |
| | | this.TextEditMinorLoss.Text = _PressmeterVmo.MinorLoss.ToString(); |
| | | this.DescriptionTextEdit.Text = _PressmeterVmo.Description; |
| | | this.TextEditKeyWord.Text = string.Join(",", _PressmeterVmo.KeyWord); |
| | | this.selectFlagsPopupCtrl1.SetBindingData<AssetsFlags>(_PressmeterVmo.Flags); |
| | | if (vmo == null) |
| | | { |
| | | return; |
| | | } |
| | | _vmo = new Vmo.AssetsPressmeterMainVmo(vmo); |
| | | this.txtName.EditValue = vmo.Name; |
| | | this.txtMinorLoss.EditValue = vmo.MinorLoss; |
| | | this.txtKeyWord.EditValue = HStation.Service.Assets.KeyWordHelper.ToString(vmo.KeyWords); |
| | | var flags = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(HStation.Assets.DataType.PressmeterMain); |
| | | this.setFlagsEditCtrl1.SetBindingData(flags?.Select(x => x.Name).ToList(), vmo.Flags); |
| | | this.txtTagName.EditValue = vmo.TagName; |
| | | this.txtDescription.EditValue = vmo.Description; |
| | | } |
| | | |
| | | public event Func<Vmo.AssetsPressmeterMainVmo, Task<bool>> ReloadDataEvent = null; |
| | | |
| | | //数据验证 |
| | | private bool Valid() |
| | | //验证 |
| | | private async Task<bool> Valid() |
| | | { |
| | | this.dxErrorProvider1.ClearErrors(); |
| | | if (string.IsNullOrEmpty(TextEditName.Text.Trim())) |
| | | if (string.IsNullOrEmpty(this.txtName.Text.Trim())) |
| | | { |
| | | this.dxErrorProvider1.SetError(this.TextEditName, "必填项"); |
| | | this.dxErrorProvider1.SetError(this.txtName, "必填项"); |
| | | return false; |
| | | } |
| | | if (string.IsNullOrEmpty(this.txtMinorLoss.Text.Trim())) |
| | | { |
| | | this.dxErrorProvider1.SetError(this.txtMinorLoss, "必填项"); |
| | | return false; |
| | | } |
| | | var tagname = this.txtTagName.Text.Trim(); |
| | | if (!string.IsNullOrEmpty(tagname)) |
| | | { |
| | | if (await BLLFactory<HStation.BLL.AssetsPressmeterMain>.Instance.IsExistTagNameExceptID(tagname, _vmo.ID)) |
| | | { |
| | | 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; |
| | | _PressmeterVmo.Description = DescriptionTextEdit.Text.Trim(); |
| | | _PressmeterVmo.Name = TextEditName.Text.Trim(); |
| | | _PressmeterVmo.KeyWord = TextEditKeyWord.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); |
| | | if (double.TryParse(TextEditMinorLoss.Text, out double MinorLoss)) |
| | | { |
| | | _PressmeterVmo.MinorLoss = MinorLoss; |
| | | } |
| | | _PressmeterVmo.Flags = this.selectFlagsPopupCtrl1.SelectedFlags; |
| | | if (await this.ReloadDataEvent.Invoke(_PressmeterVmo)) |
| | | if (!await Valid()) |
| | | { |
| | | TipFormHelper.ShowSucceed("修改成功!"); |
| | | return; |
| | | } |
| | | else |
| | | _vmo.Name = this.txtName.Text.Trim(); |
| | | _vmo.MinorLoss = double.Parse(this.txtMinorLoss.EditValue?.ToString()); |
| | | _vmo.KeyWords = HStation.Service.Assets.KeyWordHelper.ToList(this.txtKeyWord.Text.Trim()); |
| | | _vmo.Flags = this.setFlagsEditCtrl1.SelectedFlagList; |
| | | _vmo.TagName = this.txtTagName.Text.Trim(); |
| | | _vmo.Description = this.txtDescription.Text.Trim(); |
| | | |
| | | var bol = await BLLFactory<HStation.BLL.AssetsPressmeterMain>.Instance.Update(_vmo); |
| | | if (!bol) |
| | | { |
| | | TipFormHelper.ShowSucceed("修改失败!"); |
| | | TipFormHelper.ShowError("更新失败!"); |
| | | return; |
| | | } |
| | | var vmo = await BLLFactory<HStation.BLL.AssetsPressmeterMain>.Instance.GetByID(_vmo.ID); |
| | | this.ReloadDataEvent?.Invoke(vmo); |
| | | this.DialogResult = DialogResult.OK; |
| | | this.Close(); |
| | | } |
| | | |
| | | private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) |
| | | { |
| | | var vm = this.treeList1.GetCurrentViewModel(_AssetsPressmeterCoefficient); |
| | | if (vm == null) |
| | | return; |
| | | this.TextEditMinorLoss.Text = vm.MinorLoss.ToString(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | } |