Esempio n. 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            TBL_MP_Master_Employee_LeaveConfiguration model = null;
            ServiceEmployee serviceEmpLeave = new ServiceEmployee();

            try
            {
                string strSalaryHeadIDs   = string.Empty;
                string strSalaryHeadNames = string.Empty;

                if (!this.ValidateChildren())
                {
                    return;
                }
                if (this.PK_LeaveID == 0)
                {
                    model               = new TBL_MP_Master_Employee_LeaveConfiguration();
                    model.FK_BranchID   = Program.CURR_USER.BranchID;
                    model.FK_EmployeeID = this.EmployeeID;
                }
                else
                {
                    model = serviceEmpLeave.GetEmpLeaveInfoDbRecord(this.PK_LeaveID);
                }

                #region GATHER DATA INTO MODEL FROM VIEW

                model.FK_LeaveTypeID    = ((SelectListItem)cboLeaveType.SelectedItem).ID;
                model.MaxDaysAllow      = decimal.Parse(txtMaxDaysallow.Text.Trim());
                model.CarryForwardLeave = chkLeaveCarryForward.Checked;
                if (model.CarryForwardLeave)
                {
                    model.CarryForwardLimitDays = decimal.Parse(txtLimitDays.Text.Trim());
                }
                model.ApplicableInProbation = chkApplicableProbationPeriod.Checked;
                model.LeaveEnchashable      = chkLeaveEncashable.Checked;
                model.IsActive     = chkIsActive.Checked;
                model.FK_FinYearID = ((SelectListItem)cboYear.SelectedItem).ID;
                model.LeavesEarned = decimal.Parse(txtLeaveOpeningBalance.Text.Trim());

                #endregion
                #region PREPARE SALARY HEADS STRING
                if (chkLeaveEncashable.Checked)
                {
                    foreach (DataGridViewRow mRow in gridAllounces.Rows)
                    {
                        if ((bool)mRow.Cells["IsActive"].Value == true)
                        {
                            strSalaryHeadIDs   += mRow.Cells["ID"].Value.ToString() + ", ";
                            strSalaryHeadNames += mRow.Cells["Description"].Value.ToString() + ", ";
                        }
                    }
                }
                #endregion
                if (strSalaryHeadIDs.Trim() != string.Empty)
                {
                    model.EncashableSalaryHeadIDs = strSalaryHeadIDs.Trim().TrimEnd(',');
                }
                else
                {
                    model.EncashableSalaryHeadIDs = null;
                }
                if (strSalaryHeadNames.Trim() != string.Empty)
                {
                    model.EncashableSalaryHeadNames = strSalaryHeadNames.Trim().TrimEnd(',');
                }
                else
                {
                    model.EncashableSalaryHeadNames = null;
                }



                if (this.PK_LeaveID == 0)
                {
                    this.PK_LeaveID = serviceEmpLeave.AddNewEmpLeaveConfiguration(model);
                }
                else
                {
                    serviceEmpLeave.UpdateEmpLeaveConfiguration(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, "frmAddEditEmployeeLeaveConfig::btnSave_Click", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }