namespace Yw.WinFrmUI
{
///
/// 添加文件
///
public partial class AddBimfaceFileDlg : DevExpress.XtraEditors.XtraForm
{
///
///
///
public AddBimfaceFileDlg()
{
InitializeComponent();
this.layoutControl1.SetupLayoutControl();
}
///
/// 返回数据事件
///
public event Action ReloadDataEvent;
private Lazy _bll = new(() => new BLL.BimfaceFile());
///
/// 绑定数据
///
public void SetBindingData()
{
InitialModelType();
InitialFileStatus();
InitialFormatType();
}
//初始化模型类型
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 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 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 bool Valid()
{
this.dxErrorProvider1.ClearErrors();
if (string.IsNullOrEmpty(this.txtBimFaceFileID.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.txtBimFaceFileID, "必填项");
return false;
}
if (string.IsNullOrEmpty(this.txtFileName.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.txtFileName, "必填项");
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;
}
var vmo = new Vmo.BimfaceFileVmo();
vmo.BimfaceId = this.txtBimFaceFileID.Text.Trim();
vmo.Name = this.txtFileName.Text.Trim();
vmo.ModelType = (int)(eModelType)this.imgCmbBimfaceModelType.EditValue;
vmo.FormatType = (int)(eFormatType)this.imgCmbFormatType.EditValue;
vmo.FileStatus = (int)(eFileStatus)this.imgCmbFileStatus.EditValue;
vmo.FileSuffix = this.txtExtension.Text.Trim();
vmo.FileSize = this.txtFileSize.Text.Trim();
vmo.Description = this.txtDescription.Text.Trim();
var id = await _bll.Value.Insert(vmo);
if (id < 1)
{
XtraMessageBox.Show("添加失败!");
return;
}
this.ReloadDataEvent?.Invoke(id);
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}