namespace PBS.WinFrmUI.Hydro
|
{
|
public partial class AddModelTemplateDlg : DevExpress.XtraEditors.XtraForm
|
{
|
public AddModelTemplateDlg()
|
{
|
InitializeComponent();
|
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
|
this.layoutControl1.SetupLayoutControl();
|
this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
|
}
|
|
/// <summary>
|
/// 重载数据
|
/// </summary>
|
public event Action<ModelTemplateVmo> ReloadDataEvent;
|
|
private ModelTemplateVmo _modelTemplate = null;//模型模板
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public async void SetBindingData(long groupId = 0)
|
{
|
_modelTemplate = new ModelTemplateVmo();
|
_modelTemplate.GroupID = groupId;
|
var allFlagsList = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(DataType.PBSModelTemplate);
|
this.setFlagsEditCtrl1.SetBindingData(allFlagsList?.Select(x => x.Name).Distinct().ToList(), null);
|
this.imgCmbPlaceType.Properties.AddEnum<PBS.ePlaceType>();
|
this.imgCmbPlaceType.SelectedIndex = 0;
|
this.imgCmbModelTemplateType.Properties.AddEnum<PBS.eModelTemplateType>();
|
this.imgCmbModelTemplateType.SelectedIndex = 1;
|
}
|
|
//数据验证
|
private async Task<bool> Verify()
|
{
|
this.dxErrorProvider1.ClearErrors();
|
if (string.IsNullOrEmpty(txtName.Text.Trim()))
|
{
|
this.dxErrorProvider1.SetError(this.txtName, "必填项");
|
return false;
|
}
|
var tagname = this.txtTagName.Text.Trim();
|
if (!string.IsNullOrEmpty(tagname))
|
{
|
if (await BLLFactory<PBS.BLL.ModelTemplate>.Instance.IsExistTagName(tagname))
|
{
|
this.dxErrorProvider1.SetError(this.txtTagName, "重复");
|
return false;
|
}
|
}
|
return true;
|
}
|
|
//确定
|
private async void GeneralOkAndCancelCtrl1_OkEvent()
|
{
|
if (_modelTemplate == null)
|
{
|
return;
|
}
|
if (!await Verify())
|
{
|
return;
|
}
|
_modelTemplate.Name = this.txtName.Text.Trim();
|
_modelTemplate.Flags = this.setFlagsEditCtrl1.SelectedFlagList;
|
_modelTemplate.TagName = this.txtTagName.Text.Trim();
|
_modelTemplate.Description = this.txtDescription.Text.Trim();
|
|
_modelTemplate.PlaceType = (PBS.ePlaceType)this.imgCmbPlaceType.EditValue;
|
_modelTemplate.TemplateType = (PBS.eModelTemplateType)this.imgCmbModelTemplateType.EditValue;
|
_modelTemplate.UseStatus = Yw.Model.eUseStatus.Enable ;
|
_modelTemplate.ID = await BLLFactory<PBS.BLL.ModelTemplate>.Instance.Insert(_modelTemplate);
|
|
if (_modelTemplate.ID < 1)
|
{
|
TipFormHelper.ShowError("添加失败!");
|
return;
|
}
|
|
var modelTemplate = await BLLFactory<PBS.BLL.ModelTemplate>.Instance.GetByID(_modelTemplate.ID);
|
this.ReloadDataEvent?.Invoke(modelTemplate);
|
this.DialogResult = DialogResult.OK;
|
this.Close();
|
}
|
|
|
}
|
}
|