namespace Yw.WinFrmUI
{
public partial class AddDivisonDlg : DevExpress.XtraEditors.XtraForm
{
private Yw.Vmo.DivisionVmo _model = null;
public AddDivisonDlg()
{
InitializeComponent();
this.dataLayoutControl1.SetupLayoutControl();
}
///
/// 回调事件
///
public event Func> ReloadDataEvent;
///
/// 验证识别码是否存在事件
///
public event Func VerifyTagNameExistEvent;
///
/// 绑定
///
public async void SetBindingData(long id)
{
var list = new List();
_model = new Yw.Vmo.DivisionVmo();
this.TypeImageComboBoxEdit.Properties.AddEnum(typeof(Yw.Model.eDivisionType), false);
this.TypeImageComboBoxEdit.SelectedIndex = 0;
var allList = await new BLL.Division().GetAll();
if (allList != null)
{
foreach (var item in allList)
{
list.Add(new DivisionViewModel(item));
}
}
treeListLookUpEdit1TreeList.DataSource = list;
if (id > 0)
{
this.textEditParents.EditValue = id;
// this.treeListLookUpEdit1TreeList.EditingValue = id;
}
}
//确定
private async void btnOk_Click(object sender, EventArgs e)
{
if (_model == null)
return;
if (!Valid())
return;
_model.Name = this.NameTextEdit.Text.Trim();
_model.Type = (Yw.Model.eDivisionType)this.TypeImageComboBoxEdit.EditValue;
_model.ADCode = this.ADCodeTextEdit.Text.Trim();
_model.Description = this.DescriptionTextEdit.Text.Trim();
_model.TagName = this.TagNameTextEdit.Text.Trim();
if (this.ReloadDataEvent == null)
return;
if (!await this.ReloadDataEvent(_model, this.textEditParents.EditValue))
{
MessageBoxHelper.ShowError("添加失败!");
return;
}
MessageBoxHelper.ShowSuccess("添加成功!");
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
//验证
private bool Valid()
{
this.dxErrorProvider1.ClearErrors();
if (string.IsNullOrEmpty(this.NameTextEdit.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.NameTextEdit, "必填项");
return false;
}
var tagName = this.TagNameTextEdit.Text.Trim();
if (!string.IsNullOrEmpty(tagName))
{
if (VerifyTagNameExistEvent != null)
{
if (VerifyTagNameExistEvent(tagName))
{
this.dxErrorProvider1.SetError(this.TagNameTextEdit, "重复");
return false;
}
}
}
return true;
}
}
}