// ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_RESOURCES_MATERIALS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_RESOURCES_MATERIALS_EDIT"])))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                }

                // Validate query string
                if (((string)Request.QueryString["material_state"] == null) || ((string)Request.QueryString["source_page"] == null) || ((string)Request.QueryString["material_id"] == null) || ((string)Request.QueryString["active_tab"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in materials_state.aspx");
                }

                // Tag page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfMaterialId.Value = Request.QueryString["material_id"];
                hdfActiveTab.Value = Request.QueryString["active_tab"].ToString();

                // Prepare initial data
                // ... for material title
                int companyId = Int32.Parse(hdfCompanyId.Value.Trim());
                int materialId = Int32.Parse(hdfMaterialId.Value);

                MaterialsGateway materialsGateway = new MaterialsGateway();
                materialsGateway.LoadByMaterialId(materialId, companyId);
                lblTitleMaterial.Text = "Material: " + materialsGateway.GetDescription(materialId);

                // If coming from materials_summary.aspx
                if ((string)Request.QueryString["source_page"] == "materials_summary.aspx")
                {
                    // Store Navigator State and Update control
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];

                    // Get project record
                    materialsInformationTDS = (MaterialsInformationTDS)Session["materialsInformationTDS"];
                    MaterialsInformationBasicInformationGateway materialsInformationBasicInformationGateway = new MaterialsInformationBasicInformationGateway(materialsInformationTDS);
                    materialsInformationBasicInformationGateway.LoadByMaterialId(materialId, companyId);

                    // Store datasets
                    Session["materialsInformationTDS"] = materialsInformationTDS;
                }
            }
            else
            {
                // Restore dataset
                materialsInformationTDS = (MaterialsInformationTDS)Session["materialsInformationTDS"];
            }
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            // Set active toolbar
            mForm6 master = (mForm6)this.Master;
            master.ActiveToolbar = "Resources";

            // Format Description
            if (hdfProcess.Value == "Full Length Lining")
            {
                pnlJunctionLiner.Visible = false;
                pnlPointRepairs.Visible = false;
                pnlFullLengthLining.Visible = true;

                // make extra rows not visible
                extraRow1.Visible = false;
                extraRow2.Visible = false;
                extraRow3.Visible = false;
                extraRow4.Visible = false;
                extraRow5.Visible = false;
                extraRow6.Visible = false;
                extraRow7.Visible = false;
                extraRow8.Visible = false;
                extraRow9.Visible = false;
                extraRow10.Visible = false;
                extraRow11.Visible = false;
                extraRow12.Visible = false;
            }

            if (hdfProcess.Value == "Point Repairs")
            {
                pnlJunctionLiner.Visible = false;
                pnlPointRepairs.Visible = true;
                pnlFullLengthLining.Visible = false;

                // make extra rows not visible
                extraRow1.Visible = false;
                extraRow2.Visible = false;
                extraRow3.Visible = false;
                extraRow4.Visible = false;
                extraRow5.Visible = false;
                extraRow6.Visible = false;
                extraRow7.Visible = false;
                extraRow8.Visible = false;
                extraRow9.Visible = false;
                extraRow10.Visible = false;
                extraRow11.Visible = false;
                extraRow12.Visible = false;
            }

            if (hdfProcess.Value == "Junction Lining")
            {
                pnlJunctionLiner.Visible = true;
                pnlPointRepairs.Visible = false;
                pnlFullLengthLining.Visible = false;

                // make extra rows not visible
                extraRow1.Visible = true;
                extraRow2.Visible = true;
                extraRow3.Visible = true;
                extraRow4.Visible = true;
                extraRow5.Visible = true;
                extraRow6.Visible = true;
                extraRow7.Visible = true;
                extraRow8.Visible = true;
                extraRow9.Visible = true;
                extraRow10.Visible = true;
                extraRow11.Visible = true;
                extraRow12.Visible = true;

                // Load correct radiobutton for new options
                int materialId = Int32.Parse(hdfCurrentMaterialId.Value);
                int companyId = Int32.Parse(hdfCompanyId.Value);

                MaterialsInformationBasicInformationGateway materialsInformationBasicInformationGatewayForLoad = new MaterialsInformationBasicInformationGateway(materialsInformationTDS);
                materialsInformationBasicInformationGatewayForLoad.LoadByMaterialId(materialId, companyId);
                string jlDescription = materialsInformationBasicInformationGatewayForLoad.GetDescription(materialId);
                if (jlDescription == "Lateral / Misc Supplies")
                {
                    rbtnMiscSupplies.Checked = true;
                    rbtnCleanoutMaterial.Checked = false;
                    rbtnBackfillCleanout.Checked = false;
                    rbtnRestorationCrowleCap.Checked = false;
                    rbtnOther.Checked = false;
                    tbxJLSize.Text = "";
                }
                else
                {
                    if (jlDescription == "Lateral / Cleanout Material")
                    {
                        rbtnMiscSupplies.Checked = false;
                        rbtnCleanoutMaterial.Checked = true;
                        rbtnBackfillCleanout.Checked = false;
                        rbtnRestorationCrowleCap.Checked = false;
                        rbtnOther.Checked = false;
                        tbxJLSize.Text = "";
                    }
                    else
                    {
                        if (jlDescription == "Lateral / Backfill - Cleanout")
                        {
                            rbtnMiscSupplies.Checked = false;
                            rbtnCleanoutMaterial.Checked = false;
                            rbtnBackfillCleanout.Checked = true;
                            rbtnRestorationCrowleCap.Checked = false;
                            rbtnOther.Checked = false;
                            tbxJLSize.Text = "";
                        }
                        else
                        {
                            if (jlDescription == "Lateral / Restoration & Crowle Cap")
                            {
                                rbtnMiscSupplies.Checked = false;
                                rbtnCleanoutMaterial.Checked = false;
                                rbtnBackfillCleanout.Checked = false;
                                rbtnRestorationCrowleCap.Checked = true;
                                rbtnOther.Checked = false;
                                tbxJLSize.Text = "";
                            }
                            else
                            {
                                rbtnMiscSupplies.Checked = false;
                                rbtnCleanoutMaterial.Checked = false;
                                rbtnBackfillCleanout.Checked = false;
                                rbtnRestorationCrowleCap.Checked = false;
                                rbtnOther.Checked = true;
                                tbxJLSize.Text = materialsInformationBasicInformationGatewayForLoad.GetSize(materialId);
                            }
                        }
                    }
                }
            }
        }
 // ////////////////////////////////////////////////////////////////////////
 // PUBLIC METHODS
 //
 /// <summary>
 /// LoadByMaterialId
 /// </summary>
 /// <param name="materialId">materialId</param>              
 /// <param name="companyId">companyId</param>
 public void LoadByMaterialId(int materialId, int companyId)
 {
     MaterialsInformationBasicInformationGateway materialsInformationBasicInformationGateway = new MaterialsInformationBasicInformationGateway(Data);
     materialsInformationBasicInformationGateway.LoadByMaterialId(materialId, companyId);
 }