private void btnOK_Click(object sender, EventArgs e) { TBL_MP_Master_Employee_LastEmployerDetail model = null; ServiceEmployee _service = new ServiceEmployee(); try { if (!this.ValidateChildren()) { return; } if (this.SelectID == 0) { model = new TBL_MP_Master_Employee_LastEmployerDetail(); } else { model = _service.GetLastEmployerInfoDBRecordByID(this.SelectID); } model.LastEmployerID = SelectID; model.FK_EmployeeId = this.SelectedEmployeeID; model.LastEmployerName = txtName.Text.Trim(); model.Address = txtAddress.Text.Trim(); model.ContactNo = int.Parse(txtContactNo.Text.Trim()); model.isActive = chkIsActive.Checked; if (this.SelectID == 0) { this.SelectID = _service.AddNewLastEmployerInfo(model); } else { _service.UpdateLastEmployerInfo(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, "frmAddEditLastEmployerInfo::btnOK_Click", MessageBoxButtons.OK, MessageBoxIcon.Error); } }