using Mapster;
namespace Yw.WinFrmUI
{
///
/// 编辑模型文件
///
public partial class EditBimfaceFileDlg : DevExpress.XtraEditors.XtraForm
{
public EditBimfaceFileDlg()
{
InitializeComponent();
this.layoutControl1.SetupLayoutControl();
}
public event Action ReloadDataEvent;
private Yw.Vmo.BimfaceFileVmo _updateModel = null;
///
/// 绑定数据
///
public void SetBindingData(BimfaceFileMgrViewModel vm)
{
InitialModelType();
InitialFormatType();
InitialFileStatus();
_updateModel = vm.Adapt();
this.txtBimfaceId.EditValue = vm.BimfaceId;
this.txtName.EditValue = vm.Name;
this.imgCmbBimfaceModelType.EditValue = vm.ModelType;
this.imgCmbFormatType.EditValue = vm.FormatType;
this.imgCmbFileStatus.EditValue = vm.FileStatus;
this.txtFileSize.EditValue = vm.FileSize;
this.txtExtension.EditValue = vm.FileSuffix;
this.txtDescription.EditValue = vm.Description;
}
//初始化模型类型
private void InitialModelType()
{
this.imgCmbBimfaceModelType.Properties.BeginUpdate();
this.imgCmbBimfaceModelType.Properties.Items.Clear();
this.imgCmbBimfaceModelType.Properties.Items.AddEnum(typeof(eModelType), false);
this.imgCmbBimfaceModelType.EditValue = eModelType.File;
this.imgCmbBimfaceModelType.Properties.EndUpdate();
this.imgCmbBimfaceModelType.Enabled = false;
}
//初始化文件格式
private void InitialFormatType()
{
this.imgCmbFormatType.Properties.BeginUpdate();
this.imgCmbFormatType.Properties.Items.Clear();
this.imgCmbFormatType.Properties.Items.AddEnum(typeof(eFormatType), false);
this.imgCmbFormatType.EditValue = eFormatType.d3;
this.imgCmbFormatType.Properties.EndUpdate();
}
//初始化文件状态
private void InitialFileStatus()
{
this.imgCmbFileStatus.Properties.BeginUpdate();
this.imgCmbFileStatus.Properties.Items.Clear();
this.imgCmbFileStatus.Properties.Items.AddEnum(typeof(eFileStatus), false);
this.imgCmbFileStatus.EditValue = eFileStatus.ConvertSucceed;
this.imgCmbFileStatus.Properties.EndUpdate();
}
//验证
private bool Valid()
{
this.dxErrorProvider1.ClearErrors();
if (string.IsNullOrEmpty(this.txtBimfaceId.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.txtBimfaceId, "必填项");
return false;
}
if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.txtName, "必填项");
return false;
}
if (string.IsNullOrEmpty(this.txtExtension.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.txtExtension, "必填项");
return false;
}
if (string.IsNullOrEmpty(this.imgCmbBimfaceModelType.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.imgCmbBimfaceModelType, "必选项");
return false;
}
if (string.IsNullOrEmpty(this.imgCmbFormatType.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.imgCmbFormatType, "必选项");
return false;
}
if (string.IsNullOrEmpty(this.imgCmbFileStatus.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.imgCmbFileStatus, "必选项");
return false;
}
return true;
}
//确定
private async void btnOk_Click(object sender, EventArgs e)
{
if (!Valid())
{
return;
}
_updateModel.BimfaceId = this.txtBimfaceId.Text.Trim();
_updateModel.Name = this.txtName.Text.Trim();
_updateModel.ModelType = (int)(eModelType)this.imgCmbBimfaceModelType.EditValue;
_updateModel.FormatType = (int)(eFormatType)this.imgCmbFormatType.EditValue;
_updateModel.FileStatus = (int)(eFileStatus)this.imgCmbFileStatus.EditValue;
_updateModel.FileSuffix = this.txtExtension.Text.Trim();
_updateModel.FileSize = this.txtFileSize.Text.Trim();
_updateModel.Description = this.txtDescription.Text.Trim();
if (!await BLLFactory.Instance.Update(_updateModel))
{
XtraMessageBox.Show("更新失败!");
return;
}
if (this.ReloadDataEvent != null)
{
this.ReloadDataEvent(_updateModel.ID);
}
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}