public void ScatterData() { ServiceEmployee _service = new ServiceEmployee(); try { TBL_MP_Master_Employee_MedicalDetail obj = (new ServiceEmployee()).GetEmployeeMedicalInfoDbRecord(this.EmployeeMedicalID); if (obj != null) { //populate all textboxes,datepickers from obj txtMedicalName.Text = obj.MedicalName; cboRelation.SelectedItem = ((List <SelectListItem>)cboRelation.DataSource).Where(x => x.ID == obj.FK_UL_RelationID).FirstOrDefault(); txtCardNo.Text = obj.CardNo; txtCardType.Text = obj.CardType; txtCompanyName.Text = obj.CompanyName; txtRemark.Text = obj.Remark; chkIsActive.Checked = obj.IsActive; dtIssueDate.Value = obj.IssueDate; dtExpieryDate.Value = obj.ExpiryDate; } TBL_MP_Master_Employee emp = _service.GetEmployeeDbRecordByID(obj.fk_EmployeeId); this.Text = string.Format("{0} ({1}) - Update Medical Info", emp.EmployeeName, emp.EmployeeCode); } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "frmAddEditMedicalInfo::ScatterData", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnOK_Click(object sender, EventArgs e) { TBL_MP_Master_Employee_MedicalDetail model = null; ServiceEmployee serviceEmployee = new ServiceEmployee(); try { if (!this.ValidateChildren()) { return; } if (this.EmployeeMedicalID == 0) { model = new TBL_MP_Master_Employee_MedicalDetail(); } else { model = serviceEmployee.GetEmployeeMedicalInfoDbRecord(this.EmployeeMedicalID); } model.fk_EmployeeId = this.EmployeeID; #region GATHER DATA INTO MODEL FROM VIEW model.MedicalName = txtMedicalName.Text; model.FK_UL_RelationID = ((SelectListItem)cboRelation.SelectedItem).ID; model.CardNo = txtCardNo.Text; model.CardType = txtCardType.Text; model.CompanyName = txtCompanyName.Text; model.IssueDate = dtIssueDate.Value; model.ExpiryDate = dtExpieryDate.Value; model.Remark = txtRemark.Text; model.IsActive = chkIsActive.Checked; #endregion if (this.EmployeeMedicalID == 0) { this.EmployeeMedicalID = serviceEmployee.AddNewEmployeeMedicalnfo(model); } else { serviceEmployee.UpdateEmployeeMedicalnfo(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, "frmAddEditMedicalInfo::btnOK_Click", MessageBoxButtons.OK, MessageBoxIcon.Error); } }