{ public partial class PersonView : Form , IPersonsView { public event Action Save; public event Action MartialStateChange; public event Action ChildrenClicked;
public partial class PersonView : Form , IPersonsView
{
public event Action Save;
public event Action MartialStateChange;
public event Action ChildrenClicked;
public PersonView()
{
InitializeComponent();
InitLookups();
}
public bool IsMarried { get { return AppUtils.ObjToInt(luMartialStatus.EditValue) == 1; } }
public void LoadPerson(Person data)
{
var yearData = data.Years.First<PersonYear>();
edtPersonCode.DataBindings.Add("Text",data , "PersonCode", true);
edtFirstName.DataBindings.Add("Text", data, "FirstName", true);
edtLastName.DataBindings.Add("Text", data, "LastName", true);
edtIdentityNumber.DataBindings.Add("Text", data, "IdentityNumber", true);
edtSreet.DataBindings.Add("Text", data, "Street", true);
edtCity.DataBindings.Add("Text", data, "City", true);
edtZip.DataBindings.Add("Text", data, "Zip", true);
deBirthDate.DataBindings.Add("DateTime", data, "BirthDate", true);
deBirthDate2.DataBindings.Add("DateTime", data, "PartnerBirthDate", true);
edtLastName2.DataBindings.Add("Text", yearData, "PartnerLastName", true);
edtFirstName2.DataBindings.Add("Text", yearData, "PartnerFirstName", true);
edtIdentityNumber2.DataBindings.Add("Text", data, "PartnerIdentityNumber", true);
edtTaxFileNumber.DataBindings.Add("Text", data, "TaxFileNumber", true);
luTaxClerk.DataBindings.Add("EditValue", yearData, "TaxClerk", true);
luPaymentDoc.DataBindings.Add("EditValue", yearData, "PaymentDoc", true);
luMartialStatus.DataBindings.Add("EditValue", yearData, "MartialState", true);
luGender.DataBindings.Add("EditValue", data, "Gender", true);
luGender2.DataBindings.Add("EditValue", data, "PartnerGender", true);
}
private void InitLookups()
{
DataTable dt = new DataTable();
DataColumn id = new DataColumn("id",typeof(int));
DataColumn desc = new DataColumn("desc",typeof(string));
dt.Columns.AddRange( new [] {id , desc});
dt.Rows.Add(0,"none");
dt.Rows.Add(1,@"monthly");
dt.Rows.Add(2,@"dual");
luPaymentDoc.Properties.DataSource = dt;
luPaymentDoc.Properties.ValueMember = "id";
luPaymentDoc.Properties.DisplayMember = "desc";
DataTable dt2 = new DataTable();
DataColumn id2 = new DataColumn("id", typeof(int));
DataColumn desc2 = new DataColumn("desc", typeof(string));
dt2.Columns.AddRange(new[] { id2, desc2 });
dt2.Rows.Add(1, "male");
dt2.Rows.Add(2, "female");
luGender.Properties.DataSource = dt2;
luGender.Properties.ValueMember = "id";
luGender.Properties.DisplayMember = "desc";
luGender2.Properties.DataSource = dt2;
luGender2.Properties.ValueMember = "id";
luGender2.Properties.DisplayMember = "desc";
luTaxClerk.Properties.DataSource = RamDataSet.GetMinistries();
luTaxClerk.Properties.DisplayMember = "MNS_Description";
luTaxClerk.Properties.ValueMember = "MNS_ID";
luMartialStatus.Properties.DataSource = RamDataSet.GetPersonMartialStatuses();
luMartialStatus.Properties.DisplayMember = "CMS_DESCRIPTION";
luMartialStatus.Properties.ValueMember = "CMS_STATUS_ID";
}
private bool ValidateUserInput()
{
ResetReqLablesError();
if (edtLastName.Text.Trim().Length == 0)
{
edtLastName.Focus();
lbReqFamilyName.Visible = true;
MessageUtils.ShowError("error!");
return false;
}
if (edtFirstName.Text.Trim().Length == 0)
{
edtFirstName.Focus();
lbReqFirstName.Visible = true;
MessageUtils.ShowError("error!");
return false;
}
if (edtIdentityNumber.Text.Trim().Length == 0) // Check if there is ID Validation somewhere.
{
edtIdentityNumber.Focus();
lbReqIdentityNumber.Visible = true;
MessageUtils.ShowError("error!");
return false;
}
if (IDValidator.ISValidId(edtIdentityNumber.Text) == -1)
{
edtIdentityNumber.Focus();
lbReqIdentityNumber.Visible = true;
MessageUtils.ShowError("error!");
return false;
}
if (edtSreet.Text.Trim().Length == 0)
{
edtSreet.Focus();
lbReqSreet.Visible = true;
MessageUtils.ShowError("error!");
return false;
}
if (edtCity.Text.Trim().Length == 0)
{
edtCity.Focus();
lbReqCity.Visible = true;
MessageUtils.ShowError("error!");
return false;
}
if (edtZip.Text.Trim().Length == 0)
{
edtZip.Focus();
lbReqZip.Visible = true;
MessageUtils.ShowError("error!");
return false;
}
DateTime temp;
if (!DateTime.TryParse(deBirthDate.Text, out temp))
{
deBirthDate.Focus();
lbReqBirthDate.Visible = true;
MessageUtils.ShowError("error!");
return false;
}
// Validate partner details
if (IsMarried)
{
if (edtLastName2.Text.Trim().Length == 0)
{
edtLastName2.Focus();
lbReqLastName2.Visible = true;
MessageUtils.ShowError("error!");
return false;
}
if (edtFirstName2.Text.Trim().Length == 0)
{
edtFirstName2.Focus();
lbReqFirstName2.Visible = true;
MessageUtils.ShowError("error!");
return false;
}
if (edtIdentityNumber2.Text.Trim().Length == 0) // Check if there is ID Validation somewhere.
{
edtIdentityNumber2.Focus();
lbReqIdentityNumber2.Visible = true;
MessageUtils.ShowError("error!");
return false;
}
if (IDValidator.ISValidId(edtIdentityNumber2.Text) == -1)
{
edtIdentityNumber2.Focus();
lbReqIdentityNumber2.Visible = true;
MessageUtils.ShowError("error!");
return false;
}
DateTime temp2;
if (!DateTime.TryParse(deBirthDate2.Text, out temp2))
{
deBirthDate2.Focus();
lbReqBirthDate2.Visible = true;
MessageUtils.ShowError("error!");
return false;
}
}
return true;
}
private void ResetReqLablesError()
{
lbReqCity.Visible = lbReqFamilyName.Visible = lbReqFirstName.Visible = lbReqIdentityNumber.Visible = lbReqSreet.Visible = lbReqZip.Visible =
lbReqFirstName2.Visible = lbReqLastName2.Visible = lbReqIdentityNumber2.Visible = lbReqBirthDate2.Visible = false;
}
private void btnSave_Click(object sender, EventArgs e)
{
SaveAndExit();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
private void PersonView_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.F10:
btnSave.PerformClick();
e.Handled = true;
break;
}
}
private void SaveAndExit()
{
if (ValidateUserInput())
{
if (Save != null)
{
this.Save();
}
this.DialogResult = DialogResult.OK;
}
}
private void luMartialStatus_EditValueChanged(object sender, EventArgs e)
{
if (MartialStateChange != null)
{
this.MartialStateChange();
}
}
public bool MartialPanelVisable
{
get { return pnlPartner.Visible;}
set { this.pnlPartner.Visible = value; }
}
private void btnChildrens_Click(object sender, EventArgs e)
{
if (ChildrenClicked != null)
{
ChildrenClicked();
}
}
public int PersonChildrenCount { get { return Int32.Parse(this.edtChildrenCount.Text); } set { this.edtChildrenCount.Text = value.ToString(); } }
}
}