public partial class FrmEditCustomer : BaseUI.BaseEditForm
{
public FrmEditCustomer()
{
InitializeComponent();
}
/// <summary>
/// 实现控件输入检查的函数
/// </summary>
/// <returns></returns>
public override bool CheckInput()
{
bool result = true;
#region 输入验证
if (this.txtName.Text.Length == 0)
{
MessageUtil.ShowTips("宾客名称不能为空");
this.txtName.Focus();
result = false;
}
else if (this.txtIDNumber.Text.Length == 0)
{
MessageUtil.ShowTips("证件号码不能为空");
this.txtIDNumber.Focus();
result = false;
}
#endregion
return result;
}
/// <summary>
/// 编辑或者保存状态下取值函数
/// </summary>
/// <param name="info"></param>
private void SetInfo(CustomerInfo info)
{
info.Address = txtAddress.Text;
info.CompanyName = txtCompany.Text;
info.IDCarType = cmbIDCarType.Text;
info.Name = txtName.Text;
info.Note = txtNote.Text;
info.IDNumber = txtIDNumber.Text;
info.Telephone = txtTelephone.Text;
info.Source = cmbSource.Text;
info.CustomerType = cmbType.Text;
info.Sex = cmbSex.Text;
}
/// <summary>
/// 数据字典加载
/// </summary>
private void InitDictItem()
{
this.cmbSource.Items.Clear();
this.cmbSource.Items.AddRange(DictItemUtil.GetCustomerSource());
this.cmbType.Items.Clear();
this.cmbType.Items.AddRange(DictItemUtil.GetCustomerType());
this.cmbIDCarType.Items.Clear();
this.cmbIDCarType.Items.AddRange(DictItemUtil.GetIDCarType());
}
/// <summary>
/// 数据显示的函数
/// </summary>
public override void DisplayData()
{
//数据字典加载(公用)
InitDictItem();
if (!string.IsNullOrEmpty(ID))
{
//编辑状态下的数据显示
CustomerInfo info = BLLFactory<Customer>.Instance.FindByID(ID);
if (info != null)
{
#region 显示客户信息
txtAddress.Text = info.Address;
txtCompany.Text = info.CompanyName;
txtName.Text = info.Name;
txtNote.Text = info.Note;
txtIDNumber.Text = info.IDNumber;
txtTelephone.Text = info.Telephone;
cmbSource.Text = info.Source;
cmbType.Text = info.CustomerType;
cmbSex.Text = info.Sex;
cmbIDCarType.Text = info.IDCarType;
lblCreateDate.Text = info.RegistrationDate.ToString();
#endregion
}
}
else
{
//新增状态的数据显示
lblCreateDate.Text = DateTime.Now.ToString();
}
}
/// <summary>
/// 新增状态下的数据保存
/// </summary>
/// <returns></returns>
public override bool SaveAddNew()
{
CustomerInfo info = new CustomerInfo();
SetInfo(info);
info.RegistrationDate = DateTime.Now;
bool succeed = BLLFactory<Customer>.Instance.Insert(info);
return succeed;
}
/// <summary>
/// 编辑状态下的数据保存
/// </summary>
/// <returns></returns>
public override bool SaveUpdated()
{
CustomerInfo info = BLLFactory<Customer>.Instance.FindByID(ID);
if (info != null)
{
SetInfo(info);
bool succeed = BLLFactory<Customer>.Instance.Update(info, info.ID.ToString());
return succeed;
}
return false;
}
}