public void ScatterData() { try { TBL_MP_Master_Employee_LeaveConfiguration model = (new ServiceEmployee()).GetEmpLeaveInfoDbRecord(this.PK_LeaveID); if (model != null) { if (EmployeeID != 0) { headerEmployeeName.Values.Description = ServiceEmployee.GetEmployeeNameByID(model.FK_EmployeeID); } txtLimitDays.Text = model.CarryForwardLimitDays.ToString(); txtMaxDaysallow.Text = model.MaxDaysAllow.ToString(); cboLeaveType.SelectedItem = ((List <SelectListItem>)cboLeaveType.DataSource).Where(x => x.ID == model.FK_LeaveTypeID).FirstOrDefault(); chkApplicableProbationPeriod.Checked = model.ApplicableInProbation; chkLeaveCarryForward.Checked = model.CarryForwardLeave; chkLeaveEncashable.Checked = model.LeaveEnchashable; txtLeaveOpeningBalance.Text = model.LeavesEarned.ToString(); chkIsActive.Checked = model.IsActive; this.SeledctedYearID = model.FK_FinYearID; if (this.SeledctedYearID != 0) { cboYear.SelectedItem = ((List <SelectListItem>)cboYear.DataSource).Where(x => x.ID == this.SeledctedYearID).FirstOrDefault(); } if (model.LeaveEnchashable) { string[] IDs = model.EncashableSalaryHeadIDs.Split(','); foreach (string headID in IDs) { foreach (DataGridViewRow mRow in gridAllounces.Rows) { if (mRow.Cells["ID"].Value.ToString().Trim() == headID.Trim()) { mRow.Cells["IsActive"].Value = true; } } } } } } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "frmAddEditEmployeeLeaveConfig::ScatterData", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void GenerateEmployeeLeaveConfigurationsForFinYear(int companyID, int branchID, int yearID) { try { int idx = 1; List <TBL_MP_HR_LeaveConfiguration> lstMasterLeaves = (from xx in _dbContext.TBL_MP_HR_LeaveConfiguration where xx.FK_FinYearID == yearID && xx.FK_BranchID == branchID select xx).ToList(); foreach (SelectListItem emp in (new ServiceEmployee()).GetAllActiveEmployees()) { string strMessage = string.Empty; strMessage = string.Format("\n{0}: {1}\n", idx++, emp.Description.ToUpper()); foreach (TBL_MP_HR_LeaveConfiguration item in lstMasterLeaves) { TBL_MP_Master_Employee_LeaveConfiguration confExist = (from xx in _dbContext.TBL_MP_Master_Employee_LeaveConfiguration where xx.FK_EmployeeID == emp.ID && xx.FK_FinYearID == yearID && xx.FK_LeaveTypeID == item.FK_LeaveTypeID select xx).FirstOrDefault(); if (confExist == null) { TBL_MP_Master_Employee_LeaveConfiguration newConf = new TBL_MP_Master_Employee_LeaveConfiguration(); newConf.ApplicableInProbation = item.ApplicableInProbation; newConf.CarryForwardLeave = item.CarryForwardLeave; newConf.CarryForwardLimitDays = item.CarryForwardLimitDays; newConf.EncashableSalaryHeadIDs = item.EncashableSalaryHeadIDs; newConf.EncashableSalaryHeadNames = item.EncashableSalaryHeadNames; newConf.FK_BranchID = branchID; newConf.FK_FinYearID = yearID; newConf.FK_EmployeeID = emp.ID; newConf.FK_LeaveTypeID = item.FK_LeaveTypeID; newConf.IsActive = true; newConf.LeaveEnchashable = item.LeaveEnchashable; newConf.LeavesEarned = 0; newConf.MaxDaysAllow = item.MaxDaysAllow; //int totalLeavesTaken= ( // from xx in _dbContext.TBL_MP_HR_LeaveApplication // where xx.FK_EmployeeID == emp.ID && xx.fK_UsrLst_LeaveTypeID == item.FK_LeaveTypeID && xx.FK_YearID == yearID // select xx.NoOfDays // ).Sum(); (new ServiceEmployee()).AddNewEmpLeaveConfiguration(newConf); } } strMessage += string.Format("Success.......\n"); if (OnEmployeeLeaveConfigurationCompleted != null) { OnEmployeeLeaveConfigurationCompleted(this, new MODELS.COMMON.EventArguementModel() { Message = strMessage }); } } if (OnEmployeeLeaveConfigurationCompleted != null) { OnEmployeeLeaveConfigurationCompleted(this, new MODELS.COMMON.EventArguementModel() { Message = "Completed Leave configuration.\n\n" }); } } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceLeaveConfiguration::GenerateEmployeeLeaveConfigurationsForFinYear", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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); } }