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); Reinvestment expPro = CommonBLL.GetReinvestment(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.UpdateReinvestment(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); } }
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()); Reinvestment estf = CommonBLL.GetReinvestment(index); CommonBLL.DeleteReinvestment(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()); Reinvestment estf = CommonBLL.GetReinvestment(index); txtID.Text = estf.ID.ToString(); txtTot.Text = estf.Amount.ToString(); ddlCat.SelectedValue = estf.ReinvestmentID.ToString(); ddlMonth.SelectedValue = estf.Month.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) { Reinvestment 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.GetReinvestment(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.ReinvestmentID = int.Parse(ddlCat.SelectedValue); expPro.DepartmentID = usr.DepartmentID; expPro.Status = (int)Utility.BudgetItemStatus.Pending_Approval; expPro.Month = month; expPro.BudgetYrID = budYr.ID; rst = CommonBLL.UpdateReinvestment(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 Reinvestment(); int month = int.Parse(ddlMonth.SelectedValue); expPro.ReinvestmentID = int.Parse(ddlCat.SelectedValue); expPro.DepartmentID = usr.DepartmentID; expPro.AddedBy = User.Identity.Name; expPro.DateAdded = DateTime.Now; expPro.Amount = tot; expPro.BudgetYrID = budYr.ID; expPro.Month = month; expPro.Status = (int)Utility.BudgetItemStatus.Pending_Approval; result = CommonBLL.AddReinvestment(expPro); if (result) { BindGrid(); txtTot.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); Reinvestment expPro = CommonBLL.GetReinvestment(recID); if (expPro != null && expPro.Status == (int)Utility.BudgetItemStatus.Approved) { expPro.Status = (int)Utility.BudgetItemStatus.Returned_For_Correction; CommonBLL.UpdateReinvestment(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", "Re-investment 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); } }