Example #1
0
        private void ScatterData()
        {
            ServiceEmployee _service = new ServiceEmployee();

            try
            {
                TBL_MP_Master_Employee_Relative model = _service.GetEmployeeRelativeDBRecordByID(this.EmployeeRelationshipID);
                if (model != null)
                {
                    txtRelativeName.Text = model.RelativeName;
                    txtRemark.Text       = model.Remarks;
                    if (model.RelativeDOB != null)
                    {
                        dtDateOfBirth.Value = (DateTime)model.RelativeDOB;
                    }
                    else
                    {
                        dtDateOfBirth.Checked = false;
                    }

                    cboSelectRelation.SelectedItem = ((List <SelectListItem>)cboSelectRelation.DataSource).Where(x => x.ID == model.FK_UL_RelationID).FirstOrDefault();
                }
                TBL_MP_Master_Employee emp = _service.GetEmployeeDbRecordByID(SelectedEmployeeID);
                this.Text = string.Format("{0} ({1}) - Add Relationship", 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, "frmAddEditEmployeeRelation::ScatterData", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
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);
            }
        }