Ejemplo n.º 1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            TBL_MP_Master_Employee_Relative model = null;
            ServiceEmployee _service = new ServiceEmployee();

            try
            {
                if (!this.ValidateChildren())
                {
                    return;
                }

                if (this.EmployeeRelationshipID == 0)
                {
                    model = new TBL_MP_Master_Employee_Relative();
                }
                else
                {
                    model = _service.GetEmployeeRelativeDBRecordByID(EmployeeRelationshipID);
                }

                model.FK_EmployeeID    = this.SelectedEmployeeID;
                model.FK_UL_RelationID = ((SelectListItem)cboSelectRelation.SelectedItem).ID;
                model.RelativeName     = txtRelativeName.Text.Trim();
                if (dtDateOfBirth.Checked)
                {
                    model.RelativeDOB = dtDateOfBirth.Value;
                }
                else
                {
                    model.RelativeDOB = null;
                }
                model.Remarks = txtRemark.Text.Trim();

                if (this.EmployeeRelationshipID == 0)
                {
                    this.EmployeeRelationshipID = _service.AddNewEmployeeRelative(model);
                }
                else
                {
                    _service.UpdateEmployeeRelative(model);
                }


                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "frmAddEditEmployeeRelation::btnOK_Click", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }