using DevExpress.XtraEditors;
|
using System;
|
|
namespace IStation.WinFrmUI.Basic
|
{
|
public partial class EditStationDlg : DevExpress.XtraEditors.XtraForm
|
{
|
public EditStationDlg()
|
{
|
InitializeComponent();
|
IconOptions.Icon = WinFrmUI.Properties.Resources.App;
|
dataLayoutControl1.SetupLayoutControl();
|
}
|
|
/// <summary>
|
/// 回调事件
|
/// </summary>
|
public event Func<Model.Station, bool> ReloadDataEvent;
|
|
/// <summary>
|
/// 验证识别码是否存在事件
|
/// </summary>
|
public event Func<string, long, bool> VerifyTagNameExistEvent;
|
|
|
private Model.Station _model = null;
|
|
/// <summary>
|
/// 绑定
|
/// </summary>
|
public void SetBindingData(Model.Station model)
|
{
|
_model = new Model.Station(model);
|
NameTextEdit.EditValue = _model.Name;
|
TagNameTextEdit.EditValue = _model.TagName;
|
DescriptionTextEdit.EditValue = _model.Description;
|
}
|
|
//验证
|
private bool Valid()
|
{
|
dxErrorProvider1.ClearErrors();
|
if (string.IsNullOrEmpty(NameTextEdit.Text.Trim()))
|
{
|
dxErrorProvider1.SetError(NameTextEdit, "必填项");
|
return false;
|
}
|
|
var tagName = TagNameTextEdit.Text.Trim();
|
if (!string.IsNullOrEmpty(tagName))
|
{
|
if (_model.TagName != tagName)
|
{
|
if (VerifyTagNameExistEvent != null)
|
{
|
if (VerifyTagNameExistEvent(tagName, _model.ID))
|
{
|
dxErrorProvider1.SetError(TagNameTextEdit, "重复");
|
return false;
|
}
|
}
|
}
|
}
|
|
return true;
|
}
|
|
//确定
|
private void btnOk_Click(object sender, EventArgs e)
|
{
|
if (_model == null)
|
return;
|
if (!Valid())
|
return;
|
_model.Name = NameTextEdit.Text.Trim();
|
_model.Description = DescriptionTextEdit.Text.Trim();
|
_model.TagName = TagNameTextEdit.Text.Trim();
|
|
if (ReloadDataEvent == null)
|
return;
|
if (!ReloadDataEvent(_model))
|
{
|
XtraMessageBox.Show("更新失败!");
|
return;
|
}
|
XtraMessageBox.Show("更新成功!");
|
DialogResult = System.Windows.Forms.DialogResult.OK;
|
Close();
|
}
|
}
|
}
|