protected void btnApprv_Click(object sender, EventArgs e) { try { AppUser usr = null; if (Session["user"] != null) { usr = (AppUser)Session["user"]; } else { Response.Redirect("../Login.aspx", false); return; } bool isset = false; foreach (GridViewRow row in gvDept.Rows) { if (((CheckBox)row.FindControl("chkRow")).Checked) { Label lbID = row.FindControl("lbRecID") as Label; int recID = int.Parse(lbID.Text); ExpenseProjection expPro = CommonBLL.GetExpensePRojection(recID); if (expPro != null && expPro.Status == (int)Utility.BudgetItemStatus.Pending_Approval) { expPro.Status = (int)Utility.BudgetItemStatus.Approved; expPro.ApprovedBy = usr.FullName; expPro.DateApproved = DateTime.Now; CommonBLL.UpdateExpenseProjection(expPro); isset = true; } } } if (isset) { BindGrid(); success.Visible = true; success.InnerHtml = "<button type='button' class='close' data-dismiss='alert'>×</button>Selected Record(s) has been successfully approved."; return; } else { BindGrid(); error.Visible = true; error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>×</button> An error occured some of selected record(s) could not be approved.If error persist contact Administrator!!."; } } catch (Exception ex) { error.Visible = true; error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>×</button> An error occured. Kindly try again. If error persist contact Administrator!!."; Utility.WriteError("Error: " + ex.InnerException); } }
public static bool AddExpenseProjection(ExpenseProjection expPro) { try { using (BudgetCaptureDBEntities db = new BudgetCaptureDBEntities()) { db.ExpenseProjections.Add(expPro); db.SaveChanges(); return(true); } } catch (Exception ex) { // Utility.WriteError("Error Msg: " + ex.Message); throw ex; } }
public static bool DeleteExpensePro(ExpenseProjection expPro) { try { bool rst = false; using (var db = new BudgetCaptureDBEntities()) { db.Entry(expPro).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); rst = true; } return(rst); } catch (Exception ex) { throw ex; } }
public static bool UpdateExpenseProjection(ExpenseProjection expPro) { try { bool rst = false; using (var db = new BudgetCaptureDBEntities()) { db.ExpenseProjections.Attach(expPro); db.Entry(expPro).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); rst = true; } return(rst); } catch (Exception ex) { // Utility.WriteError("Error Msg: " + ex.Message); throw ex; } }
protected void gvDept_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName == "del") { int index = int.Parse(e.CommandArgument.ToString()); // int key = Convert.ToInt32(gvDept.DataKeys[index].Value.ToString()); ExpenseProjection estf = CommonBLL.GetExpensePRojection(index); CommonBLL.DeleteExpensePro(estf); BindGrid(); success.Visible = true; success.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>×</button> Record deleted successfully!!."; return; } if (e.CommandName == "edt") { hid.Value = "Update"; dvID.Visible = false; btnSubmit.Text = "Update"; //GridViewRow row = gvDept.SelectedRow; int index = int.Parse(e.CommandArgument.ToString()); ExpenseProjection estf = CommonBLL.GetExpensePRojection(index); txtID.Text = estf.ID.ToString(); txtDetails.Text = estf.Details; txtTot.Text = estf.Amount.ToString(); ddlCat.SelectedValue = estf.ExpenseTypeID.ToString(); ddlMonth.SelectedValue = estf.MonthYr.ToString(); } } catch (Exception ex) { error.Visible = true; error.InnerHtml = "<button type='button' class='close' data-dismiss='alert'>×</button> An error occurred. kindly try again!!!"; Utility.WriteError("Error: " + ex.InnerException); } }
protected void btnSubmit_Click(object sender, EventArgs e) { ExpenseProjection expPro = null; try { usr = (AppUser)Session["user"]; budYr = (BudgetYear)Session["budgetYr"]; if (hid.Value == "Update") { bool rst = false; decimal tot = 0; int month = int.Parse(ddlMonth.SelectedValue); expPro = CommonBLL.GetExpensePRojection(Convert.ToInt32(txtID.Text)); if (expPro != null) { if (!decimal.TryParse(txtTot.Text, out tot)) { error.Visible = true; error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>×</button>Amount must be numeric!!."; return; } expPro.Amount = tot; expPro.Details = txtDetails.Text; expPro.ExpenseTypeID = int.Parse(ddlCat.SelectedValue); expPro.DepartmentID = usr.DepartmentID; expPro.Status = (int)Utility.BudgetItemStatus.Pending_Approval; expPro.MonthYr = month; expPro.BudgetYrID = budYr.ID; rst = CommonBLL.UpdateExpenseProjection(expPro); if (rst != false) { BindGrid(); success.Visible = true; success.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>×</button> Record updated successfully!!."; return; } } else { error.Visible = true; error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>×</button>Record could Not updated. Kindly try again. If error persist contact Administrator!!."; } } else { decimal tot = 0; if (!decimal.TryParse(txtTot.Text, out tot)) { error.Visible = true; error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>×</button>Amount must be numeric!!."; return; } bool result = false; expPro = new ExpenseProjection(); int month = int.Parse(ddlMonth.SelectedValue); expPro.ExpenseTypeID = int.Parse(ddlCat.SelectedValue); expPro.DepartmentID = usr.DepartmentID; expPro.Details = txtDetails.Text; expPro.AddedBy = User.Identity.Name; expPro.DateAdded = DateTime.Now; expPro.Amount = tot; expPro.BudgetYrID = budYr.ID; expPro.MonthYr = month; expPro.Status = (int)Utility.BudgetItemStatus.Pending_Approval; result = CommonBLL.AddExpenseProjection(expPro); if (result) { BindGrid(); txtTot.Text = ""; txtDetails.Text = ""; ddlCat.SelectedValue = ""; ddlMonth.SelectedValue = ""; success.Visible = true; success.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>×</button> Record added successfully!!."; return; } else { error.Visible = true; error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>×</button>Record could Not added. Kindly try again. If error persist contact Administrator!!."; } } } catch (Exception ex) { error.Visible = true; error.InnerHtml = "<button type='button' class='close' data-dismiss='alert'>×</button> An error occurred. kindly try again!!!"; Utility.WriteError("Error: " + ex.Message); } }
protected void btnReturn_Click(object sender, EventArgs e) { try { AppUser usr = null; if (Session["user"] != null) { usr = (AppUser)Session["user"]; } else { Response.Redirect("../Login.aspx", false); return; } if (string.IsNullOrEmpty(txtcomment.Text)) { modalErr.Visible = true; modalErr.InnerText = "Comment is required!!!"; mpeAppr.Show(); return; } bool isset = false; AppUser budgetInputer = new AppUser(); foreach (GridViewRow row in gvDept.Rows) { if (((CheckBox)row.FindControl("chkRow")).Checked) { Label lbID = row.FindControl("lbRecID") as Label; int recID = int.Parse(lbID.Text); ExpenseProjection expPro = CommonBLL.GetExpensePRojection(recID); if (expPro != null && expPro.Status == (int)Utility.BudgetItemStatus.Approved) { expPro.Status = (int)Utility.BudgetItemStatus.Returned_For_Correction; CommonBLL.UpdateExpenseProjection(expPro); budgetInputer = UserBLL.GetUserByUserName(expPro.AddedBy); isset = true; } } } if (isset) { BindGrid(); //sending mail string body = ""; string from = ConfigurationManager.AppSettings["exUser"].ToString(); string siteUrl = ConfigurationManager.AppSettings["siteUrl"].ToString(); string appLogo = ConfigurationManager.AppSettings["appLogoUrl"].ToString(); string hodEmail = UserBLL.GetApproverEmailByDept(budgetInputer.DepartmentID.Value); string subject = "Budget Item Correction Notification"; string FilePath = Server.MapPath("EmailTemplates/"); if (File.Exists(FilePath + "ReturnBudget.htm")) { FileStream f1 = new FileStream(FilePath + "ReturnBudget.htm", FileMode.Open); StreamReader sr = new StreamReader(f1); body = sr.ReadToEnd(); body = body.Replace("@add_appLogo", appLogo); body = body.Replace("@siteUrl", siteUrl); body = body.Replace("@BudgetElement", "Expense Projection"); body = body.Replace("@add_Comment", txtcomment.Text); //Replace the values from DB or any other source to personalize each mail. f1.Close(); } string rst = ""; try { rst = Utility.SendMail(budgetInputer.Email, from, hodEmail, subject, body); } catch { } if (rst.Contains("Successful")) { success.Visible = true; success.InnerHtml = "<button type='button' class='close' data-dismiss='alert'>×</button>Selected Record(s) has been successfully Returned for correction.Notification has been sent to Initiator"; return; } else { success.Visible = true; success.InnerHtml = "<button type='button' class='close' data-dismiss='alert'>×</button>Selected Record(s) has been successfully Returned for correction.Notification could NOT be sent at this time"; return; } } else { BindGrid(); error.Visible = true; error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>×</button> An error occured. Either no record is selected OR some of selected record(s) could not be approved.If error persist contact Administrator!!."; } } catch (Exception ex) { error.Visible = true; error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>×</button> An error occured. Kindly try again. If error persist contact Administrator!!."; Utility.WriteError("Error: " + ex.Message); } }