public int AddNewAdvanceRequest(TBL_MP_HR_AdvanceRequestApplication model) { int newID = 0; try { model.AdvanceRequestNo = this.GenerateNewAdvanceRequestNumber(model.Fk_YearID, model.Fk_BranchID, model.FK_CompanyID); model.ApprovalStatus = REQUEST_STATUS_PENDING_ID; model.IsDeleted = false; model.ApprovalDate = null; model.FK_ApprovedBy = null; model.RemarksApproved = string.Empty; _dbContext.TBL_MP_HR_AdvanceRequestApplication.Add(model); _dbContext.SaveChanges(); newID = model.PK_AdvancRequestID; } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceAdvanceRequest::AddNewAdvanceRequest", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(newID); }
public void ScatterData() { ServiceAdvanceRequest _service = new ServiceAdvanceRequest(); try { TBL_MP_HR_AdvanceRequestApplication model = _service.GetAdvanceRequestInfoDbRecord(this.AdvanceRequestID); if (model != null) { txtAdvanceRequestNo.Text = model.AdvanceRequestNo; dtRequestDate.Value = model.RequestDate; cboEmployees.SelectedItem = ((List <SelectListItem>)cboEmployees.DataSource).Where(x => x.ID == model.FK_EmployeeID).FirstOrDefault(); cboRequestTo.SelectedItem = ((List <SelectListItem>)cboRequestTo.DataSource).Where(x => x.ID == model.FK_RequestTo).FirstOrDefault(); txtRemarks.Text = model.Remarks; txtRequestedAmount.Text = model.RequestedAmount.ToString(); if (model.ExpectedDate != null) { dtExpectedDate.Value = (DateTime)model.ExpectedDate; } } } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "frmAddEditAdvanceRequest::ScatterData", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnSave_Click(object sender, EventArgs e) { errorProvider1.Clear(); TBL_MP_HR_AdvanceRequestApplication model = null; ServiceAdvanceRequest service = new ServiceAdvanceRequest(); try { if (!this.ValidateChildren()) { return; } if (this.AdvanceRequestID == 0) { model = new TBL_MP_HR_AdvanceRequestApplication(); } else { model = service.GetAdvanceRequestInfoDbRecord(this.AdvanceRequestID); } #region GATHER DATA INTO MODEL FROM VIEW model.AdvanceRequestNo = txtAdvanceRequestNo.Text.Trim(); model.RequestDate = dtRequestDate.Value; model.ExpectedDate = dtExpectedDate.Value; model.FK_EmployeeID = ((SelectListItem)cboEmployees.SelectedItem).ID; model.FK_RequestTo = ((SelectListItem)cboRequestTo.SelectedItem).ID; model.RequestedAmount = decimal.Parse(txtRequestedAmount.Text.Trim()); model.Remarks = txtRemarks.Text.Trim(); #endregion if (this.AdvanceRequestID == 0) { model.Fk_YearID = Program.CURR_USER.FinYearID; model.Fk_BranchID = Program.CURR_USER.BranchID; model.FK_CompanyID = Program.CURR_USER.CompanyID; this.AdvanceRequestID = service.AddNewAdvanceRequest(model); } else { service.UpdateAdvanceRequest(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, "frmAddEditAdvanceRequest::btnOk_Click", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public bool UpdateAdvanceRequest(TBL_MP_HR_AdvanceRequestApplication model) { bool result = false; try { TBL_MP_HR_AdvanceRequestApplication dbModel = _dbContext.TBL_MP_HR_AdvanceRequestApplication.Where(x => x.PK_AdvancRequestID == model.PK_AdvancRequestID).FirstOrDefault(); if (dbModel != null) { dbModel.FK_EmployeeID = model.FK_EmployeeID; dbModel.FK_RequestTo = model.FK_RequestTo; dbModel.RequestDate = model.RequestDate; dbModel.ExpectedDate = model.ExpectedDate; dbModel.RequestedAmount = model.RequestedAmount; dbModel.Remarks = model.Remarks; dbModel.AdvanceRequestNo = model.AdvanceRequestNo; dbModel.ApprovalDate = model.ApprovalDate; dbModel.ApprovalStatus = model.ApprovalStatus; dbModel.ApprovedAmount = model.ApprovedAmount; dbModel.FK_ApprovedBy = model.FK_ApprovedBy; dbModel.Fk_BranchID = model.Fk_BranchID; dbModel.FK_CompanyID = model.FK_CompanyID; dbModel.Fk_YearID = model.Fk_YearID; dbModel.IsDeleted = model.IsDeleted; dbModel.RemarksApproved = model.RemarksApproved; _dbContext.SaveChanges(); result = true; } else { MessageBox.Show("Unable to Locate this Record in Database", "ERROR"); return(false); } } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceAdvanceRequest::UpdateAdvanceRequest", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(result); }
public TBL_MP_HR_AdvanceRequestApplication GetAdvanceRequestInfoDbRecord(int AdvRequestID) { TBL_MP_HR_AdvanceRequestApplication model = null; try { model = _dbContext.TBL_MP_HR_AdvanceRequestApplication.Where(x => x.PK_AdvancRequestID == AdvRequestID).FirstOrDefault(); } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceAdvanceRequest::GetAdvanceRequestInfoDbRecord", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(model); }
private void btnSave_Click(object sender, EventArgs e) { try { errorProvider1.Clear(); if (!this.ValidateChildren()) { return; } ServiceAdvanceRequest service = new ServiceAdvanceRequest(); TBL_MP_HR_AdvanceRequestApplication model = service.GetAdvanceRequestInfoDbRecord(this.AdvanceRequestID); if (model != null) { model.RemarksApproved = txtApprovalRemarks.Text.Trim(); model.FK_ApprovedBy = Program.CURR_USER.EmployeeID; if (rbtnApproveAdvanceRequest.Checked) { model.ApprovalStatus = service.REQUEST_STATUS_APPROVED_ID; } if (rbtnRejectAdvanceRequest.Checked) { model.ApprovalStatus = service.REQUEST_STATUS_REJECTED_ID; } model.ApprovalDate = dtApprovalDate.Value; model.ApprovedAmount = decimal.Parse(txtApprovedAmount.Text.Trim()); // put validation on this service.UpdateAdvanceRequest(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, "frmApproveRejectAdvanceRequest::btnSave_Click", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnDeleteAdvanceRequests_Click(object sender, EventArgs e) { try { // TBL_MP_HR_LeaveApplication model = new TBL_MP_HR_LeaveApplication(); ServiceAdvanceRequest service = new ServiceAdvanceRequest(); TBL_MP_HR_AdvanceRequestApplication dbModel = service.GetAdvanceRequestInfoDbRecord(SelectedAdvanceRequestID); { string msg = "Are you sure to Delete selected advanced request Permanently"; DialogResult res = MessageBox.Show(msg, "Caution", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res == DialogResult.Yes) { if (dbModel.ApprovalStatus == service.REQUEST_STATUS_PENDING_ID) { (new ServiceAdvanceRequest()).DeleteAdvancedRequest(this.SelectedAdvanceRequestID); PopulateAdvanceRequestGrid(); } else { msg = "Unable to delete selected advanced request.."; MessageBox.Show(msg, "Caution", MessageBoxButtons.YesNo, MessageBoxIcon.Question); } } } } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "PageMyAdvanceRequests::btnDeleteAdvanceRequests_Click", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public bool DeleteAdvancedRequest(int AdvcancedID) { bool result = false; try { TBL_MP_HR_AdvanceRequestApplication model = _dbContext.TBL_MP_HR_AdvanceRequestApplication.Where(x => x.PK_AdvancRequestID == AdvcancedID).FirstOrDefault(); model.IsDeleted = true; _dbContext.SaveChanges(); result = true; } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceAdvanceRequest::DeleteAdvancedRequest", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(result); }
public int GetAdvanceRequestApplicationStatus(int applicationID) { int statusID = 0; try { TBL_MP_HR_AdvanceRequestApplication model = _dbContext.TBL_MP_HR_AdvanceRequestApplication.Where(x => x.PK_AdvancRequestID == applicationID).FirstOrDefault(); if (model != null) { statusID = model.ApprovalStatus; } } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceAdvanceRequest::GetAdvanceRequestApplicationStatus", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(statusID); }
private void gridAdvanceRegister_RowEnter(object sender, DataGridViewCellEventArgs e) { try { ServiceAdvanceRequest service = new ServiceAdvanceRequest(); this.AdvanceRequestID = (int)(gridAdvanceRegister.Rows[e.RowIndex].Cells["PK_AdvancRequestID"].Value); TBL_MP_HR_AdvanceRequestApplication model = service.GetAdvanceRequestInfoDbRecord(this.AdvanceRequestID); //if (AppCommon.GetServerDateTime() < model.RequestDate) // btnApproveReject.Enabled = ComponentFactory.Krypton.Toolkit.ButtonEnabled.True; //else // btnApproveReject.Enabled = ComponentFactory.Krypton.Toolkit.ButtonEnabled.False; } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "PageAdvanceRequestsRegister::gridAdvanceRegister_RowEnter", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public string GenerateNewAdvanceRequestNumber(int currFinYear, int currBrachID, int companyID) { string keyCode = string.Empty; int intPreviousYearCount = 0; int cnt; string strNumber; string strQuery = string.Empty; try { // 0123 TBL_MP_Admin_VoucherNoSetup objAdvanceSetup = (from xx in _dbContext.TBL_MP_Admin_VoucherNoSetup where xx.fk_FormID == (int)DB_FORM_IDs.ADVANCE_REQUEST && xx.Fk_YearID == currFinYear && xx.Fk_BranchID == currBrachID select xx).FirstOrDefault(); if (objAdvanceSetup == null) { string strMessage = "Unable to locate Voucher No. setup for the selected Financial Year or Branch"; MessageBox.Show(strMessage, "Caution", MessageBoxButtons.OK, MessageBoxIcon.Error); return(string.Empty); } strQuery = string.Format("SELECT count(*) FROM TBL_MP_HR_AdvanceRequestApplication WHERE FK_YearID={0} AND FK_BranchID={1} AND FK_CompanyID={2}", currFinYear, currBrachID, companyID); cnt = _dbContext.Database.SqlQuery <int>(strQuery).FirstOrDefault(); // IF NO. CONTINUED FROM PREVIOUS YEAR GENERATE NEXT NUMBER BY REFEREING PREVIOUS YEAR MAX. NUMBER if (objAdvanceSetup.Is_NoContinuedNextYear) { TBL_MP_Admin_VoucherNoSetup objVoucherSetupPrevYear = (from xx in _dbContext.TBL_MP_Admin_VoucherNoSetup where xx.fk_FormID == (int)DB_FORM_IDs.ADVANCE_REQUEST && xx.Fk_YearID == currFinYear - 1 && xx.Fk_BranchID == currBrachID select xx).FirstOrDefault(); TBL_MP_HR_AdvanceRequestApplication lastLeavePrevYear = (from xx in _dbContext.TBL_MP_HR_AdvanceRequestApplication where xx.Fk_YearID == currFinYear - 1 && xx.Fk_BranchID == currBrachID && xx.FK_CompanyID == companyID orderby xx.RequestDate descending select xx).FirstOrDefault(); if (lastLeavePrevYear != null) { string lstnumber = lastLeavePrevYear.AdvanceRequestNo.Replace(objVoucherSetupPrevYear.NoPrefix, "").Replace(objVoucherSetupPrevYear.NoPostfix, "").Replace(objVoucherSetupPrevYear.NoSeperator, ""); intPreviousYearCount = int.Parse(lstnumber); } else { intPreviousYearCount = 1; } cnt += intPreviousYearCount; } else { cnt += (int)objAdvanceSetup.NoStartingFrom; } strNumber = cnt.ToString().PadLeft(objAdvanceSetup.NoPad, '0'); //0083 keyCode += objAdvanceSetup.NoPrefix + objAdvanceSetup.NoSeperator + strNumber + objAdvanceSetup.NoSeperator + objAdvanceSetup.NoPostfix; // XL/SO/0083/2018-19 } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ServiceAdvanceRequest::GenerateNewAdvanceRequestNumber", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(keyCode); }