protected void gvDept_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     try
     {
         if (e.CommandName == "del")
         {
             CommonBLL.DeleteDisbursement(CommonBLL.GetDisbursement(int.Parse(e.CommandArgument.ToString())));
             this.BindGrid();
             this.success.Visible   = true;
             this.success.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>&times;</button> Record deleted successfully!!.";
         }
         else if (e.CommandName == "edt")
         {
             this.hid.Value         = "Update";
             this.dvID.Visible      = false;
             this.btnSubmit.Text    = "Update";
             this.btnSubmit.Enabled = true;
             DisbursementProjection disbursement = CommonBLL.GetDisbursement(int.Parse(e.CommandArgument.ToString()));
             this.txtID.Text = disbursement.ID.ToString();
             this.ddlAsset.SelectedItem.Text = disbursement.AssetName;
             this.txtTot.Text            = disbursement.Amount.ToString();
             this.ddlMonth.SelectedValue = disbursement.Month.ToString();
         }
     }
     catch (Exception exception)
     {
         this.error.Visible   = true;
         this.error.InnerHtml = "<button type='button' class='close' data-dismiss='alert'>&times;</button> An error occurred. kindly try again!!!";
         Utility.WriteError("Error: " + exception.InnerException);
     }
 }
 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);
                 DisbursementProjection expPro = CommonBLL.GetDisbursement(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.UpdateDisbursement(expPro);
                     isset = true;
                 }
             }
         }
         if (isset)
         {
             BindGrid();
             success.Visible   = true;
             success.InnerHtml = "<button type='button' class='close' data-dismiss='alert'>&times;</button>Selected Record(s) has been successfully approved.";
             return;
         }
         else
         {
             BindGrid();
             error.Visible   = true;
             error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>&times;</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'>&times;</button> An error occured. Kindly try again. If error persist contact Administrator!!.";
         Utility.WriteError("Error: " + ex.InnerException);
     }
 }
        //protected void btnLoad_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        string agrNo = txtobligor.Text.Trim();
        //        Obligor obl = Utility.GetObligor(agrNo);
        //        if (obl != null)
        //        {
        //            lbName.Text = "Obligor's Name: " + obl.FullName.ToUpper();
        //            lbName.ForeColor = System.Drawing.Color.RoyalBlue;
        //            btnSubmit.Enabled = true;

        //        }
        //        else
        //        {
        //            lbName.Text = "Not Found";
        //            lbName.ForeColor = System.Drawing.Color.Maroon;
        //            btnSubmit.Enabled = false;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        error.Visible = true;
        //        error.InnerHtml = "<button type='button' class='close' data-dismiss='alert'>&times;</button> An error occurred. kindly try again!!!";
        //        Utility.WriteError("Error: " + ex.Message);
        //    }
        //}

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            DisbursementProjection recpro = null;

            try
            {
                decimal num;
                int     num2;
                usr   = (AppUser)this.Session["user"];
                budYr = (BudgetYear)this.Session["budgetYr"];
                if (this.hid.Value == "Update")
                {
                    num    = 0M;
                    num2   = int.Parse(this.ddlMonth.SelectedValue);
                    recpro = CommonBLL.GetDisbursement(Convert.ToInt32(this.txtID.Text));
                    if (recpro != null)
                    {
                        if (!decimal.TryParse(this.txtTot.Text, out num))
                        {
                            this.error.Visible   = true;
                            this.error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>&times;</button>Amount must be numeric!!.";
                        }
                        else
                        {
                            recpro.Amount       = new decimal?(num);
                            recpro.AssetName    = this.ddlAsset.SelectedItem.Text;
                            recpro.DepartmentId = usr.DepartmentID;
                            recpro.Status       = 1;
                            recpro.Month        = new int?(num2);
                            recpro.BudgetYrID   = new int?(budYr.ID);
                            if (CommonBLL.UpdateDisbursement(recpro))
                            {
                                this.BindGrid();
                                this.success.Visible   = true;
                                this.success.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>&times;</button> Record updated successfully!!.";
                            }
                        }
                    }
                    else
                    {
                        this.error.Visible   = true;
                        this.error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>&times;</button>Record could Not updated. Kindly try again. If error persist contact Administrator!!.";
                    }
                }
                else
                {
                    num = 0M;
                    if (!decimal.TryParse(this.txtTot.Text, out num))
                    {
                        this.error.Visible   = true;
                        this.error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>&times;</button>Quantity must be numeric!!.";
                    }
                    else
                    {
                        recpro              = new DisbursementProjection();
                        num2                = int.Parse(this.ddlMonth.SelectedValue);
                        recpro.AssetName    = this.ddlAsset.SelectedItem.Text;
                        recpro.DepartmentId = usr.DepartmentID;
                        recpro.AddedBy      = base.User.Identity.Name;
                        recpro.DateAdded    = new DateTime?(DateTime.Now);
                        recpro.Amount       = new decimal?(num);
                        recpro.BudgetYrID   = new int?(budYr.ID);
                        recpro.Month        = new int?(num2);
                        recpro.Status       = 1;
                        if (CommonBLL.AddDisbursement(recpro))
                        {
                            this.BindGrid();
                            this.txtTot.Text            = "";
                            this.ddlAsset.SelectedValue = "";
                            this.lbName.Text            = "";
                            this.btnSubmit.Enabled      = false;
                            this.ddlMonth.SelectedValue = "";
                            this.success.Visible        = true;
                            this.success.InnerHtml      = " <button type='button' class='close' data-dismiss='alert'>&times;</button> Record added successfully!!.";
                        }
                        else
                        {
                            this.error.Visible   = true;
                            this.error.InnerHtml = " <button type='button' class='close' data-dismiss='alert'>&times;</button>Record could Not added. Kindly try again. If error persist contact Administrator!!.";
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                this.error.Visible   = true;
                this.error.InnerHtml = "<button type='button' class='close' data-dismiss='alert'>&times;</button> An error occurred. kindly try again!!!";
                Utility.WriteError("Error: " + exception.Message);
            }
        }