protected override void OnPreRenderComplete(EventArgs e)
    {
        try
        {
            lblErr.Text = "";
            hfLocal_plan_id.Value = Session[Session.SessionID.ToString() + "PlanID"].ToString();
            Panel1.Visible = true;
        }
        catch
        {
            scs_error_dictionary errObj = new scs_error_dictionary();
            errObj.ConnectionString = DataAccess.getConnStr();

            if (errObj.LoadByPrimaryKey("100"))
            {
                lblErr.Text = errObj.Txt_message;
                hl_UpdateApprovals.Visible = false;
            }
            hfLocal_plan_id.Value = "-1";
            Panel1.Visible = false;
        }

        RadGrid1.DataBind();

        try
        {
            #region This section test for Plan Level and Roleid if Level 103 - Under review by So and userroleid 101 SO Admin allow quick checkbox update else no updateing available

            lp_local_plan lpObj = new lp_local_plan();
            lpObj.ConnectionString = DataAccess.getConnStr();
            lpObj.LoadByPrimaryKey(Convert.ToInt32(Session[Session.SessionID + "PlanID"].ToString()));

            string roleid = Session[Session.SessionID + "roleid"].ToString();

            if (lpObj.Key_local_plan_level_id.ToString() != "103" || roleid != "101")
            {
                hl_UpdateApprovals.Visible = false;
            }
            else
            {
                hl_UpdateApprovals.Visible = true;
            }

            #endregion

        }
        catch
        {
        }

        base.OnPreRenderComplete(e);
    }
    protected override void OnPreRenderComplete(EventArgs e)
    {
        base.OnPreRenderComplete(e);
        try
        {
            hfLpid.Value = Session[Session.SessionID + "PlanID"].ToString();
            lblErr.Text = "";
            Panel1.Visible = true;
        }
        catch
        {
            scs_error_dictionary errObj = new scs_error_dictionary();
            errObj.ConnectionString = DataAccess.getConnStr();

            if (errObj.LoadByPrimaryKey("100"))
            {
                lblErr.Text = errObj.Txt_message;
            }
            hfLpid.Value = "-1";
            Panel1.Visible = false;
        }
        RadGrid1.DataBind();
    }
    protected override void OnPreRenderComplete(EventArgs e)
    {
        base.OnPreRenderComplete(e);
        DropDownList ddl = (DropDownList)Master.FindControl("DropDownList2");
        hfFiscalYear.Value = ddl.SelectedValue.ToString();

        try
        {

            hfLpid.Value = Session[Session.SessionID + "PlanID"].ToString();
            lblErr.Text = "";
            Panel1.Visible = true;

            lp_local_plan lpObj = new lp_local_plan();
            lpObj.ConnectionString = DataAccess.getConnStr();

            if (lpObj.LoadByPrimaryKey(Convert.ToInt32(hfLpid.Value)))
            {
                if (lpObj.Flg_accepted_assurances == true)
                {
                    cbAccepted.Checked = lpObj.Flg_accepted_assurances;
                }
                else
                    cbAccepted.Checked = false;

            }
            GearBox_Assurances_Secruity();
        }
        catch (Exception ex)
        {
            scs_error_dictionary errObj = new scs_error_dictionary();
            errObj.ConnectionString = DataAccess.getConnStr();

            if (errObj.LoadByPrimaryKey("100"))
            {
                lblErr.Text = errObj.Txt_message;
            }
            hfLpid.Value = "-1";
            //Panel1.Visible = false;
        }
        RadGrid1.DataBind();
        GearBox_Assurances_Secruity();
    }
    protected override void OnPreRenderComplete(EventArgs e)
    {
        base.OnPreRenderComplete(e);

        try
        {
            hfLocal_plan_id.Value = Session[Session.SessionID.ToString() + "PlanID"].ToString();
            hl_fundpl.NavigateUrl = "Javascript:OpenFundingplan(" + hfLocal_plan_id.Value + ")";
            lblErr.Text = "";
            Panel1.Visible = true;

        }
        catch
        {
            scs_error_dictionary errObj = new scs_error_dictionary();
            errObj.ConnectionString = DataAccess.getConnStr();

            hfLocal_plan_id.Value = "-1";
            if (errObj.LoadByPrimaryKey("100"))
            {
                lblErr.Text = errObj.Txt_message;
            }
            Panel1.Visible = false;
        }
        RadGrid1.DataBind();
        GearBox_Amendments_Secruity();
    }
    protected void GearBox_Amendments_Secruity()
    {
        try
        {
            lp_local_plan lpObj = new lp_local_plan();
            lpObj.ConnectionString = DataAccess.getConnStr();
            lpObj.LoadByPrimaryKey(Convert.ToInt32(Session[Session.SessionID + "PlanID"].ToString()));

            string roleid = Session[Session.SessionID + "roleid"].ToString();
            switch (lpObj.Key_local_plan_level_id.ToString())
            {
                case "101":
                    //Level 0 Awaiting CO Admin

                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                       //     if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                     //       else
                     //           hlNewAmendment.Visible = true;
                            break;
                        case "102":
                            //CAO
                     //       if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                     //       else
                     //           hlNewAmendment.Visible = true;
                            break;
                        case "101":
                            //SO Admin
                    //        if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                   //         else
                   //             hlNewAmendment.Visible = true;
                            break;
                        case "104":
                            //View Only
                            hlNewAmendment.Visible = false;
                            break;
                    }

                    break;
                case "102":
                    //Level 1 Awaiting CAO
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin

                     //       if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                     //       else
                      //          hlNewAmendment.Visible = true;

                            break;
                        case "102":
                            //CAO
                      //      if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                      //      else
                      //          hlNewAmendment.Visible = true;

                            break;
                        case "101":
                            //SO Admin
                       //     if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                        //    else
                       //         hlNewAmendment.Visible = true;

                            break;
                        case "104":
                            //View Only
                            hlNewAmendment.Visible = false;
                            break;
                    }
                    break;
                case "103":
                    //Review by So
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                     //       if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                      //      else
                      //          hlNewAmendment.Visible = true;

                            break;
                        case "102":
                            //CAO
                         //   if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                          //  else
                          //      hlNewAmendment.Visible = true;

                            break;
                        case "101":
                            //SO Admin
                          //  if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                          //  else
                          //      hlNewAmendment.Visible = true;

                            break;
                        case "104":
                            //View Only
                            hlNewAmendment.Visible = false;
                            break;
                    }
                    break;

                case "104":
                    //So 3 Revision Requested by So
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                        //    if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                         //   else
                        //        hlNewAmendment.Visible = true;
                            break;
                        case "102":
                            //CAO
                        //    if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                       //     else
                       //         hlNewAmendment.Visible = true;
                            break;
                        case "101":
                            //SO Admin
                         //       hlNewAmendment.Visible = true;
                            hlNewAmendment.Visible = false;
                            break;
                        case "104":
                            //View Only
                            hlNewAmendment.Visible = false;
                            break;
                    }
                    break;

                case "105":
                    //Level 4 Pending SDE Review
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                       //     if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                       //     else
                       //         hlNewAmendment.Visible = true;

                            break;
                        case "102":
                            //CAO
                      //      if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                       //     else
                       //         hlNewAmendment.Visible = true;
                            break;
                        case "101":
                            //SO Admin

                        //    if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                        //    else
                         //       hlNewAmendment.Visible = true;

                            break;
                        case "104":
                            //View Only
                            hlNewAmendment.Visible = false;
                            break;
                    }
                    break;

                case "106":
                    //Level 5 Approved
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                            else
                                hlNewAmendment.Visible = true;

                            break;
                        case "102":
                            //CAO
                            if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                            else
                                hlNewAmendment.Visible = true;

                            break;
                        case "101":
                            //SO Admin
                            if (lpObj.Flg_lock_amendment_period == true)
                                hlNewAmendment.Visible = false;
                            else
                                hlNewAmendment.Visible = true;

                            break;
                        case "104":
                            //View Only
                            hlNewAmendment.Visible = false;

                            break;
                    }
                    break;

                default:
                    // View Only, and anything not covered
                    hlNewAmendment.Visible = false;
                    break;
            }
        }
        catch
        {
            scs_error_dictionary errObj = new scs_error_dictionary();
            errObj.ConnectionString = DataAccess.getConnStr();

            hfLocal_plan_id.Value = "-1";
            if (errObj.LoadByPrimaryKey("100"))
            {
                lblErr.Text = errObj.Txt_message;
            }
            Panel1.Visible = false;
        }

        //try
        //{
        //    DataView dv = (DataView)SQLDS_RLGETPLANSTATUS.Select(DataSourceSelectArguments.Empty);
        //    if (dv.Table.Rows.Count > 0)
        //    {
        //        Boolean returnval = (Boolean)dv.Table.Rows[0][0];
        //        if (returnval)
        //        {
        //            //deactivate button if status is closed on plan status
        //            string nostring = "Filler Line";
        //                              hlNewAmendment.Visible = false;
        //        }

        //    }
        //}
        //catch (Exception ex)
        //{

        //}
    }
    protected override void OnPreRenderComplete(EventArgs e)
    {
        base.OnPreRenderComplete(e);

        try
        {

            if (Session[Session.SessionID.ToString() + "PlanID"].ToString() == "-1")
            {
                scs_error_dictionary errObj = new scs_error_dictionary();

                hfLocal_plan_id.Value = "-1";
                if (errObj.LoadByPrimaryKey("100"))
                {
                    lblErr.Text = errObj.Txt_message;
                }
                Panel1.Visible = false;
            }
            else
            {
                if (hfLocal_plan_id.Value.ToString() != Session[Session.SessionID.ToString() + "PlanID"].ToString())
                {
                    hfLocal_plan_id.Value = Session[Session.SessionID.ToString() + "PlanID"].ToString();
                    FundPlanChange();
                }

                lblErr.Text = "";
                Panel1.Visible = true;

            }

            SqlDataReader dr = FundingPlan.get_Header_Info(Convert.ToInt32(cbFundPlanVersion.SelectedValue.ToString()));

            if (dr.HasRows)
            {
                while (dr.Read())
                    FundingPlan_GearBox(dr["key_funding_plan_level_id"].ToString());
            }
        }
        catch
        {
            scs_error_dictionary errObj = new scs_error_dictionary();

            hfLocal_plan_id.Value = "-1";
            if (errObj.LoadByPrimaryKey("100"))
            {
                lblErr.Text = "<image src='../../images/msgIcons/stop.jpg' style='WIDTH: 25px;VERTICAL-ALIGN: middle; valign=middle; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; HEIGHT: 26px; BORDER-BOTTOM-STYLE: none' />  There is no local plan for this selection! Please contact system office.";
            }
            Panel1.Visible = false;
        }
    }
    protected void Save(bool displayMsg)
    {
        lp_local_plan_narrative lpnObj = new lp_local_plan_narrative();
        lpnObj.ConnectionString = DataAccess.getConnStr();
        try
        {

            if (lpnObj.LoadByPrimaryKey(Convert.ToInt32(Request.QueryString.Get("nid").ToString())))
            {
                lpnObj.Txt_narrative_response = lblResponse.Text;
                lpnObj.Txt_system_office_notes = txtSystemOfficeNotes.Text;
                lpnObj.Flg_locked = cbLocked.Checked;
                lpnObj.Flg_approved = cbApproved.Checked;
                lpnObj.Dte_updated_date = DateTime.Now;
                lblDateUpdated.Text = DateTime.Now.ToShortDateString();
                lpnObj.Txt_updated_user = HttpContext.Current.User.Identity.Name.ToString();
                lblUpdatedBy.Text = HttpContext.Current.User.Identity.Name.ToString();
                //Check with Warren for key_level_id

                lpnObj.Key_level_id = Convert.ToInt32(ddStatus.SelectedValue);
                lpnObj.Save();
            }
            scs_error_dictionary errObj = new scs_error_dictionary();

            if (errObj.LoadByPrimaryKey("200"))
            {
                if (displayMsg)
                    lblErr.Text = errObj.Txt_message;
                else
                    lblErr.Text = "";
            }
        }
        catch (Exception ex)
        {
            lblErr.Text = ex.ToString();
        }
    }
    protected void GearBox_Assurances_Secruity()
    {
        lp_local_plan lpObj = new lp_local_plan();
        lpObj.ConnectionString = DataAccess.getConnStr();
        lpObj.LoadByPrimaryKey(Convert.ToInt32(hfLpid.Value));

        try
        {

            string roleid = Session[Session.SessionID + "roleid"].ToString();
            switch (lpObj.Key_local_plan_level_id.ToString())
            {
                case "101":
                    //Level 0 Awaiting CO Admin

                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;

                            break;
                        case "102":
                            //CAO
                            cbAccepted.Enabled = true;
                            btnSubmit.Enabled = true;
                            btnPrint.Enabled = true;
                            break;
                        case "101":
                            //SO Admin
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;
                            break;
                        case "104":
                            //View Only
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;
                            break;
                    }

                    break;
                case "102":
                    //Level 1 Awaiting CAO
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin

                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;

                            break;
                        case "102":
                            //CAO
                            cbAccepted.Enabled = true;
                            btnSubmit.Enabled = true;
                            btnPrint.Enabled = true;
                            break;
                        case "101":
                            //SO Admin
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;
                            break;
                        case "104":
                            //View Only
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;
                            break;
                    }
                    break;
                case "103":
                    //Review by So
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin

                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;
                            break;
                        case "102":
                            //CAO
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;

                            break;
                        case "101":
                            //SO Admin
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;
                            break;
                        case "104":
                            //View Only
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;
                            break;
                    }
                    break;

                case "104":
                    //So 3 Revision Requested by So
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;

                            break;
                        case "102":
                            //CAO
                            cbAccepted.Enabled = true;
                            btnSubmit.Enabled = true;
                            btnPrint.Enabled = true;

                            break;
                        case "101":
                            //SO Admin
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;
                            break;
                        case "104":
                            //View Only
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;
                            break;
                    }
                    break;

                case "105":
                    //Level 4 Pending SDE Review
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;

                            break;
                        case "102":
                            //CAO
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;

                            break;
                        case "101":
                            //SO Admin
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;

                            break;
                        case "104":
                            //View Only
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;
                            break;
                    }
                    break;

                case "106":
                    //Level 5 Approved
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;

                            break;
                        case "102":
                            //CAO
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;

                            break;
                        case "101":
                            //SO Admin
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;
                            break;
                        case "104":
                            //View Only
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;
                            break;
                    }
                    break;

                case "107":
                    //Level 6 Closed
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;

                            break;
                        case "102":
                            //CAO
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = true;

                            break;
                        case "101":
                            //SO Admin
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = false;

                            break;
                        case "104":
                            //View Only
                            cbAccepted.Enabled = false;
                            btnSubmit.Enabled = false;
                            btnPrint.Enabled = false;
                            break;
                    }
                    break;
                default:
                    // View Only, and anything not covered

                    break;
            }

            //4-23-2008 added to trump all if assurances accepted then checkbox and submit buttun disabled
            if (lpObj.LoadByPrimaryKey(Convert.ToInt32(hfLpid.Value)))
            {
                if (lpObj.Flg_accepted_assurances == true)
                {
                    cbAccepted.Enabled = (!lpObj.Flg_accepted_assurances);
                    btnSubmit.Enabled = (!lpObj.Flg_accepted_assurances);
                }

            }

        }
        catch(Exception ex)
        {
            scs_error_dictionary errObj = new scs_error_dictionary();
            errObj.ConnectionString = DataAccess.getConnStr();
            if (errObj.LoadByPrimaryKey("100"))
            {
                lblErr.Text = errObj.Txt_message;
                //lblErr.Text = ex.ToString();
            }
            else
                lblErr.Text = ex.ToString();
            Panel1.Visible = false;
        }
    }
    protected void GearBox_ActivityReimbursement_Secruity()
    {
        lp_local_plan lpObj = new lp_local_plan();
        lpObj.ConnectionString = DataAccess.getConnStr();
        lpObj.LoadByPrimaryKey(Convert.ToInt32(hfLpId.Value));

        try
        {

            string roleid = Session[Session.SessionID + "roleid"].ToString();
            switch (lpObj.Key_local_plan_level_id.ToString())
            {
                case "101":
                    //Level 0 Awaiting CO Admin

                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;

                            break;
                        case "102":
                            //CAO
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;
                            break;
                        case "101":
                            //SO Admin
                            ddlActivityLineItem.Enabled = true;
                            ddlQuarter.Enabled = true;
                            txtAmount.Enabled = true;
                            btnSave.Enabled = true;
                            btnClear.Enabled = true;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = true;
                            break;
                        case "104":
                            //View Only
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;
                            break;
                    }

                    break;
                case "102":
                    //Level 1 Awaiting CAO
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;

                            break;
                        case "102":
                            //CAO
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;
                            break;
                        case "101":
                            //SO Admin
                            ddlActivityLineItem.Enabled = true;
                            ddlQuarter.Enabled = true;
                            txtAmount.Enabled = true;
                            btnSave.Enabled = true;
                            btnClear.Enabled = true;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = true;
                            break;
                        case "104":
                            //View Only
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;
                            break;
                    }
                    break;
                case "103":
                    //Review by So
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;

                            break;
                        case "102":
                            //CAO
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;

                            break;
                        case "101":
                            //SO Admin
                            ddlActivityLineItem.Enabled = true;
                            ddlQuarter.Enabled = true;
                            txtAmount.Enabled = true;
                            btnSave.Enabled = true;
                            btnClear.Enabled = true;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = true;
                            break;
                        case "104":
                            //View Only
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;
                            break;
                    }
                    break;

                case "104":
                    //So 3 Revision Requested by So
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;

                            break;
                        case "102":
                            //CAO
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;
                            break;
                        case "101":
                            //SO Admin
                            ddlActivityLineItem.Enabled = true;
                            ddlQuarter.Enabled = true;
                            txtAmount.Enabled = true;
                            btnSave.Enabled = true;
                            btnClear.Enabled = true;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = true;
                            break;
                        case "104":
                            //View Only
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;
                            break;
                    }
                    break;

                case "105":
                    //Level 4 Pending SDE Review
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin

                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;

                            break;
                        case "102":
                            //CAO
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;

                            break;
                        case "101":
                            //SO Admin
                            ddlActivityLineItem.Enabled = true;
                            ddlQuarter.Enabled = true;
                            txtAmount.Enabled = true;
                            btnSave.Enabled = true;
                            btnClear.Enabled = true;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = true;

                            break;
                        case "104":
                            //View Only
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;
                            break;
                    }
                    break;

                case "106":
                    //Level 5 Approved
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin

                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;

                            break;
                        case "102":
                            //CAO
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;

                            break;
                        case "101":
                            //SO Admin
                            ddlActivityLineItem.Enabled = true;
                            ddlQuarter.Enabled = true;
                            txtAmount.Enabled = true;
                            btnSave.Enabled = true;
                            btnClear.Enabled = true;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = true;
                            break;
                        case "104":
                            //View Only
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;
                            break;
                    }
                    break;

                case "107":
                    //Level 6 Closed
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;

                            break;
                        case "102":
                            //CAO
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;
                            break;
                        case "101":
                            //SO Admin
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;
                            break;
                        case "104":
                            //View Only
                            ddlActivityLineItem.Enabled = false;
                            ddlQuarter.Enabled = false;
                            txtAmount.Enabled = false;
                            btnSave.Enabled = false;
                            btnClear.Enabled = false;
                            RadGrid2.MasterTableView.Columns.FindByUniqueName("column").Display = false;
                            break;
                    }
                    break;
                default:
                    // View Only, and anything not covered

                    break;
            }
        }
        catch (Exception ex)
        {
            scs_error_dictionary errObj = new scs_error_dictionary();
            errObj.ConnectionString = DataAccess.getConnStr();
            if (errObj.LoadByPrimaryKey("100"))
            {
                lblErr.Text = errObj.Txt_message;
                //lblErr.Text = ex.ToString();
            }
            else
                lblErr.Text = ex.ToString();

        }
    }
    protected void GearBox_Activities_Secruity()
    {
        try
        {

            lp_local_plan lpObj = new lp_local_plan();
            lpObj.ConnectionString = DataAccess.getConnStr();
            lpObj.LoadByPrimaryKey(Convert.ToInt32(Session[Session.SessionID + "PlanID"].ToString()));

            string roleid = Session[Session.SessionID + "roleid"].ToString();
            switch (lpObj.Key_local_plan_level_id.ToString())
            {
                case "101":
                    //Level 0 Awaiting CO Admin

                    switch (roleid)
                    {
                        case "103":
                            //CO Admin

                            break;
                        case "102":
                            //CAO

                            break;
                        case "101":
                            //SO Admin
                            RadGrid1.Columns[10].Visible = true;
                            break;
                        case "104":
                            //View Only
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;
                            break;
                    }

                    break;
                case "102":
                    //Level 1 Awaiting CAO
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin

                            break;
                        case "102":
                            //CAO

                            break;
                        case "101":
                            //SO Admin
                            RadGrid1.Columns[10].Visible = true;
                            break;
                        case "104":
                            //View Only
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;
                            break;
                    }
                    break;
                case "103":
                    //Review by So
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;

                            break;
                        case "102":
                            //CAO
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;

                            break;
                        case "101":
                            //SO Admin
                            RadGrid1.Columns[10].Visible = true;
                            break;
                        case "104":
                            //View Only
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;
                            break;
                    }
                    break;

                case "104":
                    //So 3 Revision Requested by So
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin

                            break;
                        case "102":
                            //CAO

                            break;
                        case "101":
                            //SO Admin
                            RadGrid1.Columns[10].Visible = true;
                            break;
                        case "104":
                            //View Only
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;
                            break;
                    }
                    break;

                case "105":
                    //Level 4 Pending SDE Review
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;

                            break;
                        case "102":
                            //CAO
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;

                            break;
                        case "101":
                            //SO Admin

                            RadGrid1.Columns[10].Visible = true;
                            break;
                        case "104":
                            //View Only
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;
                            break;
                    }
                    break;

                case "106":
                    //Level 5 Approved
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;

                            break;
                        case "102":
                            //CAO
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;

                            break;
                        case "101":
                            //SO Admin

                            break;
                        case "104":
                            //View Only
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;
                            break;
                    }
                    break;

                case "107":
                    //Level 6 Closed
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;

                            break;
                        case "102":
                            //CAO
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;

                            break;
                        case "101":
                            //SO Admin
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;

                            break;
                        case "104":
                            //View Only
                            hlNewEA.Visible = false;
                            hlNewFA.Visible = false;
                            break;
                    }
                    break;
                default:
                    // View Only, and anything not covered

                    break;
            }
        }
        catch
        {
            scs_error_dictionary errObj = new scs_error_dictionary();
            errObj.ConnectionString = DataAccess.getConnStr();

            hfLocal_plan_id.Value = "-1";
            if (errObj.LoadByPrimaryKey("100"))
            {
                lblErr.Text = errObj.Txt_message;
            }
            Panel1.Visible = false;
        }
    }
    protected override void OnPreRenderComplete(EventArgs e)
    {
        base.OnPreRenderComplete(e);

        ddlLevel.DataBind();
        ddlLpNExtLevel.DataBind();

        ddlLevel.Enabled = true;
        String errType = "";

        try
        {
            DropDownList ddlFiscalYear = Master.FindControl("DropDownList2") as DropDownList;
            lp_local_plan lpObj = new lp_local_plan();
            lpObj.ConnectionString = DataAccess.getConnStr();

            hfLpid.Value = Session[Session.SessionID + "PlanID"].ToString();
            HL_Errors.NavigateUrl = "Javascript:OpenErrors(" + hfLpid.Value + ")";
            HL_RPLIST.NavigateUrl = "javascript:OpenReportLIst(" + hfLpid.Value + "," + ddlFiscalYear.SelectedValue + ")";
            if (lpObj.LoadByPrimaryKey(Convert.ToInt32(hfLpid.Value.ToString())))
            {

                txtLocalPlanId.Text = hfLpid.Value.ToString();
                txtCollegeName.Text = lpObj.Txt_college_name;

                txtFiscalYear.Text = lpObj.Nbr_fiscal_year.ToString();

                try
                {
                    txtFiscalYearAppropiation.Text = string.Format("{0:C}", lpObj.Nbr_yearly_appropiation);
                }
                catch
                {
                    txtFiscalYearAppropiation.Text = string.Format("{0:C}", 0);
                }

                try
                {
                    txtTotalActivities.Text = string.Format("{0:C}", lpObj.nbr_total_activities);
                }
                catch
                {
                    txtTotalActivities.Text = string.Format("{0:C}", 0);
                }

                try
                {
                    txtBalance.Text = string.Format("{0:C}", lpObj.nbr_balance);
                }
                catch
                {
                    txtBalance.Text = string.Format("{0:C}", 0);
                }

                try
                {
                    txtExpenditures.Text = string.Format("{0:C}", lpObj.nbr_reimbursements);
                }
                catch
                {
                    txtExpenditures.Text = string.Format("{0:C}", 0);
                }

                cbAccepted.Checked = lpObj.Flg_accepted_assurances;
                txtSystemOfficeNotes.Text = "";
                ddlLevel.SelectedIndex = ddlLevel.Items.IndexOf(ddlLevel.Items.FindByValue(lpObj.Key_local_plan_level_id.ToString()));

                lblLevel.Text = ddlLevel.SelectedItem.Text;

                ddlLpNExtLevel.DataBind();

                try
                {
                    txtSystemOfficeNotes.Text = lpObj.Txt_system_office_notes.ToString();
                }
                catch (Exception ex)
                {
                    txtSystemOfficeNotes.Text = "";
                }

            }
            cbAccepted.Enabled = false;
            Panel1.Visible = true;
        }
        //catch (NullReferenceException nex)
        //{
        //    lblErr.Text = nex.ToString();
        //}
        catch (Exception ex)
        {
            scs_error_dictionary errObj = new scs_error_dictionary();
            errObj.ConnectionString = DataAccess.getConnStr();
            if (errObj.LoadByPrimaryKey("100"))
            {
                lblErr.Text = errObj.Txt_message;
                //lblErr.Text = ex.ToString();
            }
            else
                lblErr.Text = ex.ToString();
            Panel1.Visible = false;
        }

        GearBox_LocalPlan_Security();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            try
            {
                //Update current activity
                DataAccess obj = new DataAccess();
                act_activity actObj = new act_activity();
                actObj.ConnectionString = DataAccess.getConnStr();
                int ika = Convert.ToInt32(Request.QueryString.Get("keyid").ToString());

                if (actObj.LoadByPrimaryKey(ika))
                {
                    obj.updateActivity(ika,
                                       Convert.ToInt32(Session[Session.SessionID.ToString() + "PlanID"].ToString()),
                                       (FormView1.FindControl("txtActivityName") as TextBox).Text,
                                       (FormView1.FindControl("txtDescActivity") as TextBox).Text,
                                       Convert.ToInt32((FormView1.FindControl("ddlProgramType") as DropDownList).SelectedValue),
                                       (FormView1.FindControl("txtDescCoreInd") as TextBox).Text,
                                       Convert.ToInt32((FormView1.FindControl("DLB_Category") as DropDownList).SelectedValue),
                                       Convert.ToInt32((FormView1.FindControl("DLB_FunCode") as DropDownList).SelectedValue),
                                       actObj.Key_activity_type_id,
                                       (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Text,
                                       Convert.ToInt32((FormView1.FindControl("ddStatus") as DropDownList).SelectedValue),
                                       (FormView1.FindControl("cbLocked") as CheckBox).Checked,
                                       (FormView1.FindControl("cbApproved") as CheckBox).Checked,
                                       true,
                                       (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Text,
                                       102);

                    //Insert Core Indicator

                    CheckBoxList cblCoreIndicators = FormView1.FindControl("chkCoreIndicators") as CheckBoxList;
                    for (int i = 0; i < cblCoreIndicators.Items.Count; i++)
                        if (cblCoreIndicators.Items[i].Selected)
                            obj.insertFundedActivityCoreIndicator(Convert.ToInt32(ika),
                                                                  Convert.ToInt32(cblCoreIndicators.Items[i].Value));

                    //update Line Item
                    //for (int i = 0; i < TRG_Funds.MasterTableView.Items.Count; i++)
                    //{
                    //    TextBox tb = (TextBox)TRG_Funds.MasterTableView.Items[i].FindControl("txt_Funds");
                    //    if (tb != null && !tb.Text.Equals(""))
                    //    {
                    //        obj.updateFundedActivityLineItems(Convert.ToInt32(ika),
                    //                                          Convert.ToInt32(TRG_Funds.MasterTableView.Items[i].GetDataKeyValue("key_line_item_type_id")),
                    //                                          Convert.ToDecimal(tb.Text));
                    //    }
                    //}

                    scs_error_dictionary errObj = new scs_error_dictionary();

                    if (errObj.LoadByPrimaryKey("200"))
                    {
                        (FormView1.FindControl("lblMsg") as Label).Text = errObj.Txt_message;
                    }

                }
            }
            catch(Exception ex)
            {
                scs_error_dictionary errObj = new scs_error_dictionary();

                if (errObj.LoadByPrimaryKey("201"))
                {
                    (FormView1.FindControl("lblMsg") as Label).Text = errObj.Txt_message;
                }
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            lblMsg.Text = "";
            hfPageInfo.Value = "0";
            hfFlgSave.Value = "";

            try
            {
                if (Request.QueryString.Get("acrId").Equals("-1"))
                {
                    //Add new Activity Request

                    DataAccess obj = new DataAccess();
                    //Local Plan id will be enter later, use 101 for now
                    int aId = Convert.ToInt32(Request.QueryString.Get("aid").ToString());

                    int key_acId = obj.insertNewActivity(aId,
                                          txtNewActivityName.Text,
                                          txtNewActivityDesc.Text,
                                          txtNewCoreIndicatorDesc.Text);

                    //Insert Core Indicator
                    if (key_acId > 0)
                    {
                        for (int i = 0; i < cblCoreIndicators.Items.Count; i++)
                            if (cblCoreIndicators.Items[i].Selected)
                                obj.insertNewNewCoreInd(key_acId,
                                                        aId,
                                                        Convert.ToInt32(cblCoreIndicators.Items[i].Value));
                    }

                    selectReturnForm(-1);
                }
                else
                {
                    //Update Current Activity Request

                    DataAccess obj = new DataAccess();
                    //Local Plan id will be enter later, use 101 for now
                    int aId = Convert.ToInt32(Request.QueryString.Get("aid").ToString());
                    int acId = Convert.ToInt32(Request.QueryString.Get("acrId").ToString());

                    obj.updateActivityChangeRequest(acId, aId,
                          txtNewActivityName.Text,
                          txtNewActivityDesc.Text,
                          txtNewCoreIndicatorDesc.Text,
                          cbApproved.Checked);

                    //Insert Core Indicator

                        for (int i = 0; i < cblCoreIndicators.Items.Count; i++)
                            if (cblCoreIndicators.Items[i].Selected)
                                obj.insertNewNewCoreInd(acId,
                                                        aId,
                                                        Convert.ToInt32(cblCoreIndicators.Items[i].Value));

                        //Approved by SO
                        if (cbApproved.Checked)
                        {
                            String returnVal = obj.approveChangeRequest(acId, aId);
                        }
                }
                scs_error_dictionary errObj = new scs_error_dictionary();

                if (errObj.LoadByPrimaryKey("200"))
                {
                    lblMsg.Text = errObj.Txt_message;
                }

            }
            catch
            {
                scs_error_dictionary errObj = new scs_error_dictionary();

                if (errObj.LoadByPrimaryKey("201"))
                {
                    lblMsg.Text = errObj.Txt_message;
                }
            }
        }
    }
    protected override void OnPreRenderComplete(EventArgs e)
    {
        base.OnPreRenderComplete(e);

        try
        {
            hfLocal_plan_id.Value = Session[Session.SessionID.ToString() + "PlanID"].ToString();
            //(FormView1.FindControl("lblMsg") as Label).Text = "";
            //Panel1.Visible = true;
            lp_local_plan lpObj = new lp_local_plan();

            DropDownList ddStatus = (DropDownList) FormView1.FindControl("ddStatus");
            if (lpObj.LoadByPrimaryKey(Convert.ToInt32(Session[Session.SessionID.ToString() + "PlanID"].ToString())))
            {
                if (lpObj.Flg_lock_amendment_period != true && ddStatus.SelectedValue == "107")
                {
                    RadTabStrip1.Tabs[1].Visible = true;
                    hlActivityChangeRequest.Visible = true;
                }
                else
                {
                    RadTabStrip1.Tabs[1].Visible = false;
                    hlActivityChangeRequest.Visible = false;
                }

            }
        }
        catch
        {
            scs_error_dictionary errObj = new scs_error_dictionary();
            errObj.ConnectionString = DataAccess.getConnStr();

            hfLocal_plan_id.Value = "-1";
            if (errObj.LoadByPrimaryKey("100"))
            {
                (FormView1.FindControl("lblMsg") as Label).Text = errObj.Txt_message;
            }
            //Panel1.Visible = false;
            hlActivityChangeRequest.Visible = false;
        }
        //RadGrid1.DataBind();
        GearBox_Ammendments_Secruity();
    }
    protected void GearBox_Ammendments_Secruity()
    {
        try
        {
            int aid = Convert.ToInt32(Request.QueryString.Get("keyid").ToString());

            //lp_local_plan lpObj = new lp_local_plan();
            //lpObj.ConnectionString = DataAccess.getConnStr();
            //lpObj.LoadByPrimaryKey(Convert.ToInt32(Session[Session.SessionID + "PlanID"].ToString()));

            string roleid = Session[Session.SessionID + "roleid"].ToString();
            switch (FundingPlan.get_Funding_Plan_Level(aid))
            {
                case "101":
                    //Level 0 Awaiting CO Admin

                    switch (roleid)
                    {
                        case "103":
                            //CO Admin

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = true;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = true;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = true;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = true;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = true;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = true;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = true;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = true;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = true;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;
                            break;
                        case "102":
                            //CAO

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = true;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = true;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = true;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = true;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = true;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = true;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = true;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = true;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = true;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;
                            break;
                        case "101":
                            //SO Admin
                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            break;
                        case "104":
                            //View Only
                            (FormView1.FindControl("btnSave") as Button ).Enabled = false;
                            (FormView1.FindControl("btnDelete") as Button).Enabled = false;
                         // (FormView1.FindControl("btnPrint") as Button).Enabled = false;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = false;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = false;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = false;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = false;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = false;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;
                            break;
                    }

                    break;
                case "102":
                    //Level 1 Awaiting CAO
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = true;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = true;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = true;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = true;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = true;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = true;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = true;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = true;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = true;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;

                            break;
                        case "102":
                            //CAO
                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = true;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = true;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = true;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = true;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = true;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = true;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = true;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = true;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = true;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;
                            break;
                        case "101":
                            //SO Admin
                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            break;
                        case "104":
                            //View Only
                            (FormView1.FindControl("btnSave") as Button).Enabled = false;
                            (FormView1.FindControl("btnDelete") as Button).Enabled = false;
                        //    (FormView1.FindControl("btnPrint") as Button).Enabled = false;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = false;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = false;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = false;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = false;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = false;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox ).Enabled = false;
                            break;
                    }
                    break;
                case "103":
                    //Review by So
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin

                            (FormView1.FindControl("btnSave") as Button).Enabled = false;
                            (FormView1.FindControl("btnDelete") as Button).Enabled = false;
                            // (FormView1.FindControl("btnPrint") as Button).Enabled = false;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = false;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = false;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = false;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = false;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = false;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList ).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;
                            break;
                        case "102":
                            //CAO
                            (FormView1.FindControl("btnSave") as Button).Enabled = false;
                            (FormView1.FindControl("btnDelete") as Button).Enabled = false;
                            // (FormView1.FindControl("btnPrint") as Button).Enabled = false;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = false;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = false;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = false;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = false;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = false;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;
                            break;
                        case "101":
                            //SO Admin
                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            break;
                        case "104":
                            //View Only
                            (FormView1.FindControl("btnSave") as Button).Enabled = false;
                            (FormView1.FindControl("btnDelete") as Button).Enabled = false;
                            // (FormView1.FindControl("btnPrint") as Button).Enabled = false;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = false;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = false;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = false;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = false;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = false;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;
                            break;
                    }
                    break;

                case "104":
                    //So 3 Revision Requested by So
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = true;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = true;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = true;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = true;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = true;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = true;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = true;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = true;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = true;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;

                            break;
                        case "102":
                            //CAO
                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = true;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = true;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = true;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = true;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = true;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = true;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = true;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = true;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = true;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = true;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;

                            break;
                        case "101":
                            //SO Admin
                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;

                            break;
                        case "104":
                            //View Only
                            (FormView1.FindControl("btnSave") as Button).Enabled = false;
                            (FormView1.FindControl("btnDelete") as Button).Enabled = false;
                            // (FormView1.FindControl("btnPrint") as Button).Enabled = false;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = false;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = false;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = false;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = false;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = false;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;
                            break;
                    }
                    break;

                case "105":
                    //Level 4 Pending SDE Review
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            (FormView1.FindControl("btnSave") as Button).Enabled = false;
                            (FormView1.FindControl("btnDelete") as Button).Enabled = false;
                            // (FormView1.FindControl("btnPrint") as Button).Enabled = false;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = false;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = false;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = false;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = false;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = false;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;

                            break;
                        case "102":
                            //CAO
                            (FormView1.FindControl("btnSave") as Button).Enabled = false;
                            (FormView1.FindControl("btnDelete") as Button).Enabled = false;
                            // (FormView1.FindControl("btnPrint") as Button).Enabled = false;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = false;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = false;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = false;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = false;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = false;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;

                            break;
                        case "101":
                            //SO Admin
                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;

                            break;
                        case "104":
                            //View Only
                            (FormView1.FindControl("btnSave") as Button).Enabled = false;
                            (FormView1.FindControl("btnDelete") as Button).Enabled = false;
                            // (FormView1.FindControl("btnPrint") as Button).Enabled = false;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = false;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = false;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = false;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = false;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = false;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;
                            break;
                    }
                    break;

                case "106":
                    //Level 5 Approved
                    switch (roleid)
                    {
                        case "103":
                            //CO Admin
                            (FormView1.FindControl("btnSave") as Button).Enabled = false;
                            (FormView1.FindControl("btnDelete") as Button).Enabled = false;
                            // (FormView1.FindControl("btnPrint") as Button).Enabled = false;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = false;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = false;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = false;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = false;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = false;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;
                            break;
                        case "102":
                            //CAO
                            (FormView1.FindControl("btnSave") as Button).Enabled = false;
                            (FormView1.FindControl("btnDelete") as Button).Enabled = false;
                            // (FormView1.FindControl("btnPrint") as Button).Enabled = false;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = false;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = false;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = false;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = false;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = false;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;
                            break;
                        case "101":
                            //SO Admin
                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;

                            break;
                        case "104":
                            //View Only
                            (FormView1.FindControl("btnSave") as Button).Enabled = false;
                            (FormView1.FindControl("btnDelete") as Button).Enabled = false;
                            // (FormView1.FindControl("btnPrint") as Button).Enabled = false;
                            (FormView1.FindControl("txtDescActivity") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtDescCoreInd") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Enabled = false;
                            (FormView1.FindControl("txtActivityName") as TextBox).Enabled = false;

                            (FormView1.FindControl("DLB_Category") as DropDownList).Enabled = false;
                            (FormView1.FindControl("DLB_FunCode") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txt_SourceofFunds") as TextBox).Enabled = false;
                            (FormView1.FindControl("ddlProgramType") as DropDownList).Enabled = false;
                            (FormView1.FindControl("chkCoreIndicators") as CheckBoxList).Enabled = false;

                            (FormView1.FindControl("cbApproved") as CheckBox).Enabled = false;
                            (FormView1.FindControl("cbLocked") as CheckBox).Enabled = false;
                            (FormView1.FindControl("ddStatus") as DropDownList).Enabled = false;
                            (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Enabled = false;

                            break;
                    }
                    break;

                default:
                    // View Only, and anything not covered

                    break;
            }

            //if (lpObj.Flg_lock_amendment_period != true)
            //{
            //    hlNewAmendment.Visible = true;
            //}
            //else
            //    hlNewAmendment.Visible = false;
        }
        catch (Exception ex)
        {
            scs_error_dictionary errObj = new scs_error_dictionary();
            errObj.ConnectionString = DataAccess.getConnStr();

            hfLocal_plan_id.Value = "-1";
            if (errObj.LoadByPrimaryKey("100"))
            {
                //lblMsg.Text = errObj.Txt_message;
            }
            Panel1.Visible = false;
        }
    }
    protected void Save()
    {
        if (Page.IsValid)
        {
            try
            {
                //Update current activity
                DataAccess obj = new DataAccess();
                act_activity actObj = new act_activity();
                actObj.ConnectionString = DataAccess.getConnStr();
                int ika = Convert.ToInt32(Request.QueryString.Get("keyid").ToString());

                if (actObj.LoadByPrimaryKey(ika))
                {
                    String sRet = obj.updateActivity(ika,
                                       Convert.ToInt32(Session[Session.SessionID.ToString() + "PlanID"].ToString()),
                                       (FormView1.FindControl("txtActivityName") as TextBox).Text,
                                       (FormView1.FindControl("txtDescActivity") as TextBox).Text,
                                       -1,
                                       (FormView1.FindControl("txtDescCoreInd") as TextBox).Text,
                                       -1,
                                       -1,
                                       actObj.Key_activity_type_id,
                                       (FormView1.FindControl("txtSystemOfficeNotes") as TextBox).Text,
                                       Convert.ToInt32((FormView1.FindControl("ddStatus") as DropDownList).SelectedValue),
                                       (FormView1.FindControl("cbLocked") as CheckBox).Checked,
                                       (FormView1.FindControl("cbApproved") as CheckBox).Checked,
                                       true,
                                       (FormView1.FindControl("txtAmdReductionDesc") as TextBox).Text,
                                       102);

                    String errCode;

                    if (sRet.Equals("0"))
                        errCode = "200";
                    else
                        errCode = "201";

                    scs_error_dictionary errObj = new scs_error_dictionary();

                    if (errObj.LoadByPrimaryKey(errCode))
                    {
                        (FormView1.FindControl("lblMsg") as Label).Text = errObj.Txt_message; // errObj.Txt_message;
                    }

                }
            }
            catch (Exception ex)
            {
                scs_error_dictionary errObj = new scs_error_dictionary();

                if (errObj.LoadByPrimaryKey("201"))
                {
                    (FormView1.FindControl("lblMsg") as Label).Text = errObj.Txt_message;
                }
            }
        }
    }
    protected override void OnPreRenderComplete(EventArgs e)
    {
        base.OnPreRenderComplete(e);

        try
        {
            hfLocal_plan_id.Value = Session[Session.SessionID.ToString() + "PlanID"].ToString();
            //(FormView1.FindControl("lblMsg") as Label ).Text = "";
            Panel1.Visible = true;

        }
        catch
        {
            scs_error_dictionary errObj = new scs_error_dictionary();
            errObj.ConnectionString = DataAccess.getConnStr();

            hfLocal_plan_id.Value = "-1";
            if (errObj.LoadByPrimaryKey("100"))
            {
                (FormView1.FindControl("lblMsg") as Label).Text = errObj.Txt_message;
            }
            Panel1.Visible = false;
            //RadTabStrip1.Tabs[1].Visible = false;
        }
        //RadGrid1.DataBind();
        GearBox_Ammendments_Secruity();
    }
    protected override void OnPreRenderComplete(EventArgs e)
    {
        base.OnPreRenderComplete(e);

        try
        {
            if (Session[Session.SessionID.ToString() + "PlanID"].ToString() == "-1")
            {
                scs_error_dictionary errObj = new scs_error_dictionary();

                hfLocal_plan_id.Value = "-1";
                if (errObj.LoadByPrimaryKey("100"))
                {
                    lblErr.Text = errObj.Txt_message;
                }
                Panel1.Visible = false;
            }
            else
            {
                if (hfLocal_plan_id.Value.ToString() != Session[Session.SessionID.ToString() + "PlanID"].ToString())
                {
                    hfLocal_plan_id.Value = Session[Session.SessionID.ToString() + "PlanID"].ToString();
                    FundPlanChange();
                }

                lblErr.Text = "";
                Panel1.Visible = true;

                if (ddlLineItemCategory.SelectedIndex == 0)
                {
                    //gvFundingPlan.DataSource = "None";
                    //gvFundingPlan.DataBind();
                }
            }
        }
        catch (Exception ex)
        {
            scs_error_dictionary errObj = new scs_error_dictionary();

            hfLocal_plan_id.Value = "-1";
            if (errObj.LoadByPrimaryKey("100"))
            {
                lblErr.Text = "<image src='../../images/msgIcons/stop.jpg' style='WIDTH: 25px;VERTICAL-ALIGN: middle; valign=middle; BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; HEIGHT: 26px; BORDER-BOTTOM-STYLE: none' />  There is no local plan for this selection! Please contact system office.";
            }
            Panel1.Visible = false;
        }

        //GearBox_Activities_Secruity();
    }
    protected void Save()
    {
        lblMsg.Text = "";
        hfPageInfo.Value = "0";
        hfFlgSave.Value = "";

        try
        {
            if (Request.QueryString.Get("id").Equals("-1"))
            {
                //Add new Activity
                DataAccess obj = new DataAccess();
                //Local Plan id will be enter later, use 101 for now
                int iLpid;

                iLpid = Convert.ToInt32(Session[Session.SessionID + "PlanID"].ToString());

                String ika = obj.insertActivity(iLpid,
                                                   txtTypeEquip.Text,
                                                   txtSupProgram.Text,
                                                   101,
                                                   "",
                                                   Convert.ToInt32(DLB_Category.SelectedValue),
                                                   Convert.ToInt32(DLB_FunCode.SelectedValue),
                                                   102,
                                                   101);
                lblAid.Text = ika;
                //Insert Core Indicator
                for (int i = 0; i < cblCoreIndicators.Items.Count; i++)
                    if (cblCoreIndicators.Items[i].Selected)
                        obj.insertFundedActivityCoreIndicator(Convert.ToInt32(ika),
                                                              Convert.ToInt32(cblCoreIndicators.Items[i].Value));

                //update Line Item
                for (int i = 0; i < TRG_Funds.MasterTableView.Items.Count; i++)
                {
                    TextBox tb = (TextBox)TRG_Funds.MasterTableView.Items[i].FindControl("txt_Funds");
                    if (tb != null && !tb.Text.Equals(""))
                    {
                        obj.updateFundedActivityLineItems(Convert.ToInt32(ika),
                                                          Convert.ToInt32(TRG_Funds.MasterTableView.Items[i].GetDataKeyValue("key_line_item_type_id")),
                                                          Convert.ToDecimal(tb.Text));
                    }
                }
                InjectScript.Text = "<script>refreshPage(" + ika + ")</" + "script>";
            }
            else
            {
                //Update current activity
                DataAccess obj = new DataAccess();
                //Local Plan id will be enter later, use 101 for now
                int ika = Convert.ToInt32(Request.QueryString.Get("id").ToString());
                obj.updateActivity(ika,
                                   101,
                                   txtTypeEquip.Text,
                                   txtSupProgram.Text,
                                   0,
                                   "",
                                   Convert.ToInt32(DLB_Category.SelectedValue),
                                   Convert.ToInt32(DLB_FunCode.SelectedValue),
                                   102,
                                   txtSystemOfficeNotes.Text,
                                   Convert.ToInt32(ddStatus.SelectedValue),
                                   cbLocked.Checked,
                                   cbApproved.Checked,
                                   false,
                                   "",
                                   101);

                //Insert Core Indicator
                for (int i = 0; i < cblCoreIndicators.Items.Count; i++)
                    if (cblCoreIndicators.Items[i].Selected)
                        obj.insertFundedActivityCoreIndicator(Convert.ToInt32(ika),
                                                              Convert.ToInt32(cblCoreIndicators.Items[i].Value));

                //update Line Item
                for (int i = 0; i < TRG_Funds.MasterTableView.Items.Count; i++)
                {
                    TextBox tb = (TextBox)TRG_Funds.MasterTableView.Items[i].FindControl("txt_Funds");
                    if (tb != null && !tb.Text.Equals(""))
                    {
                        obj.updateFundedActivityLineItems(Convert.ToInt32(ika),
                                                          Convert.ToInt32(TRG_Funds.MasterTableView.Items[i].GetDataKeyValue("key_line_item_type_id")),
                                                          Convert.ToDecimal(tb.Text));
                    }
                }
            }
            scs_error_dictionary errObj = new scs_error_dictionary();

            if (errObj.LoadByPrimaryKey("200"))
            {
                lblMsg.Text = errObj.Txt_message;
            }
            TRG_Funds.DataBind();
            RadGrid1.DataBind();

        }
        catch (Exception ex)
        {
            scs_error_dictionary errObj = new scs_error_dictionary();

            if (errObj.LoadByPrimaryKey("201"))
            {
                lblMsg.Text = errObj.Txt_message;
            }
        }
    }
    protected void GearBox_LocalPlan_Security()
    {
        try{

        string roleid = Session[Session.SessionID + "roleid"].ToString();

        switch (ddlLevel.SelectedValue.ToString())
        {
            case "101":
                //Level 0 Awaiting CO Admin

                switch (roleid)
                {
                    case "101":
                        // Admin

                        btnSaveNote.Visible = true;
                        btnSaveNote.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = true;
                        ddlLpNExtLevel.SelectedIndex = ddlLpNExtLevel.Items.IndexOf(ddlLpNExtLevel.Items.FindByValue("102"));
                        break;
                    case "102":
                        //CAO
                       // txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = true;
                        ddlLpNExtLevel.Enabled = true;
                        btnSaveNote.Enabled = false;

                        break;
                    case "103":
                        //Perkins Admin

                        txtSystemOfficeNotes.Enabled = true;
                        txtSystemOfficeNotes.ReadOnly = false ;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSaveNote.Visible = true;
                        btnSaveNote.Enabled = true;
                        btnSubmitPlan.Enabled = true;
                        ddlLpNExtLevel.Enabled = true;
                        break;
                    case "104":
                        //View Only
                        ddlLpNExtLevel.Enabled = false;
                    //    txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;

                        break;
                }

                break;
            case "102":
                //Level 1 Awaiting CAO
                switch (roleid)
                {
                    case "103":
                        //CO Admin

                      //  txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = false;
                        ddlLpNExtLevel.Enabled = false;
                        break;
                    case "102":
                        //CAO
                        //txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = true;

                        break;
                    case "101":
                        //SO Admin
                        //ddlLpNExtLevel.SelectedIndex = ddlLpNExtLevel.Items.IndexOf(ddlLpNExtLevel.Items.FindByValue("103"));
                        btnSaveNote.Visible = true;
                      txtSystemOfficeNotes.Enabled = true;

                        btnSubmitPlan.Enabled = true;

                        break;
                    case "104":
                        //View Only
                        ddlLpNExtLevel.Enabled = false;
                       // txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true; txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;

                        break;
                }
                break;
            case "103":
                //Review by So
                switch (roleid)
                {
                    case "103":
                        //CO Admin

                        lnkSubmit.Enabled = false;
                     //   txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = false;
                        ddlLpNExtLevel.Enabled = false;
                        btnSaveNote.Enabled = false;
                        break;
                    case "102":
                        //CAO
                        ddlLpNExtLevel.Enabled = false;
                        lnkSubmit.Enabled = false;
                       // txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = false;
                        btnSaveNote.Enabled = false;
                        ddlLpNExtLevel.Enabled = false;
                        break;
                    case "101":
                        //SO Admin
                        btnSaveNote.Visible = true;
                        ddlLpNExtLevel.Enabled = true;
                        txtSystemOfficeNotes.Enabled = true;
                        btnSubmitPlan.Enabled = true;

                        break;
                    case "104":
                        //View Only
                        ddlLpNExtLevel.Enabled = false;
                       // txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = false;
                        break;
                }
                break;

            case "104":
                //So 3 Revision Requested by So
                switch (roleid)
                {
                    case "103":
                        //CO Admin

                      //  txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSaveNote.Enabled = false;
                        btnSubmitPlan.Enabled = false;
                        ddlLpNExtLevel.Enabled = false;
                        break;
                    case "102":
                        //CAO

                       // txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSaveNote.Enabled = false;
                        btnSubmitPlan.Enabled = true;

                        break;
                    case "101":
                        //SO Admin
                        btnSaveNote.Visible = true;
                        ddlLpNExtLevel.Enabled = true;
                        txtSystemOfficeNotes.Enabled = true;
                        btnSubmitPlan.Enabled = true;

                        break;
                    case "104":
                        //View Only
                        ddlLpNExtLevel.Enabled = false;
                        btnSaveNote.Enabled = false;
                     //   txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = false;
                        break;
                }
                break;

            case "105":
                //Level 4 Pending SDE Review
                switch (roleid)
                {
                    case "103":
                        //CO Admin
                        btnSaveNote.Enabled = false;
                        lnkSubmit.Enabled  = false;
                        //   txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = false;
                        ddlLpNExtLevel.Enabled = false;
                        break;
                    case "102":
                        //CAO
                        //   txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = false;
                        ddlLpNExtLevel.Enabled = false;
                        lnkSubmit.Enabled = false;
                        btnSaveNote.Enabled = false;
                        btnSubmitPlan.Enabled = false;
                        lnkSubmit.Enabled = false;
                        break;
                    case "101":
                        //SO Admin
                        btnSaveNote.Visible = true;
                        ddlLpNExtLevel.Enabled = true;
                        txtSystemOfficeNotes.Enabled = true;
                        btnSubmitPlan.Enabled = true;
                        btnSaveNote.Enabled = true;
                        break;
                    case "104":
                        //View Only
                        ddlLpNExtLevel.Enabled = false;
                        //   txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = false;
                        lnkSubmit.Enabled = false;
                        break;
                }
                break;

            case "106":
                //Level 5 Approved
                switch (roleid)
                {
                    case "103":
                        //CO Admin
                        btnSaveNote.Enabled = false;
                        lnkSubmit.Enabled  = false;
                        //   txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = false;
                        ddlLpNExtLevel.Enabled = false;
                        break;
                    case "102":
                        //CAO
                        //   txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = false;
                        ddlLpNExtLevel.Enabled = false;
                        lnkSubmit.Enabled = false;
                        btnSaveNote.Enabled = false;
                        break;
                    case "101":
                        //SO Admin
                        btnSaveNote.Visible = true;
                        ddlLpNExtLevel.Enabled = true;
                        txtSystemOfficeNotes.Enabled = true;
                        btnSubmitPlan.Enabled = true;
                        btnSaveNote.Enabled = true;
                        break;
                    case "104":
                        //View Only
                        ddlLpNExtLevel.Enabled = false;
                        //   txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = false;
                        lnkSubmit.Enabled = false;
                        break;
                }
                break;

            case "107":
                //Level 6 Closed
                switch (roleid)
                {
                    case "103":
                        //CO Admin

                        lnkSubmit.Enabled = false;
                        //   txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = false;
                        ddlLpNExtLevel.Enabled = false;
                        break;
                    case "102":
                        //CAO
                        //   txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true; txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = false;
                        ddlLpNExtLevel.Enabled = false;
                        lnkSubmit.Enabled = false;

                        break;
                    case "101":
                        //SO Admin
                        ddlLpNExtLevel.Enabled = false;
                        //   txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true; txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = false;
                        lnkSubmit.Enabled = false;
                        break;
                    case "104":
                        //View Only
                        ddlLpNExtLevel.Enabled = false;
                        //   txtSystemOfficeNotes.Enabled = false;
                        txtSystemOfficeNotes.ReadOnly = true; txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                        btnSubmitPlan.Enabled = false;
                        lnkSubmit.Enabled = false;
                        break;
                }
                break;
            default:
                // View Only, and anything not covered
                //   txtSystemOfficeNotes.Enabled = false;
                txtSystemOfficeNotes.ReadOnly = true; txtSystemOfficeNotes.ForeColor = System.Drawing.Color.Gray;
                btnSubmitPlan.Enabled = false;
                ddlLpNExtLevel.Enabled = false;
                break;

        }

            //RL added 5/15/2008
        if (ddlLevel.SelectedValue.ToString() != "107" && roleid == "101")
        {
            btnSaveNote.Enabled = true;
        }
        else
        {
            btnSaveNote.Enabled = false;
        }
        if (ddlLevel.SelectedValue.ToString() != "107" && roleid == "101")
        {
            txtSystemOfficeNotes.Enabled = true;
        }

        }
        catch (Exception ex)
        {
        scs_error_dictionary errObj = new scs_error_dictionary();
        errObj.ConnectionString = DataAccess.getConnStr();
        if (errObj.LoadByPrimaryKey("100"))
        {
            lblErr.Text = errObj.Txt_message;
            //lblErr.Text = ex.ToString();
        }
        else
            lblErr.Text = ex.ToString();
        Panel1.Visible = false;
        }
    }