// ////////////////////////////////////////////////////////////////////////
        // 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["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_edit.aspx");
                }

                // Tag Page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfResourceType.Value = "Materials";
                hdfActiveTab.Value = Request.QueryString["active_tab"].ToString();
                hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString();
                hdfCurrentMaterialId.Value = Request.QueryString["material_id"];

                // Prepare initial data
                Session.Remove("materialsNotesDummy");
                Session.Remove("materialsCostsDummy");
                Session.Remove("materialsCostsExceptionsDummy");
                Session.Remove("costIdSelected");

                // ... for team member title
                int companyId = Int32.Parse(hdfCompanyId.Value.Trim());
                int materialId = Int32.Parse(hdfCurrentMaterialId.Value);

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

                // If coming from
                string resourceType = hdfResourceType.Value;

                // ... materials_navigator2.aspx or materials_add.aspx
                if ((Request.QueryString["source_page"] == "materials_navigator2.aspx")|| (Request.QueryString["source_page"] == "materials_add.aspx"))
                {
                    StoreNavigatorState();
                    ViewState["update"] = "no";

                    // ... Set initial tab
                    if ((string)Session["dialogOpenedMaterials"] != "1")
                    {
                        hdfActiveTab.Value = Request.QueryString["active_tab"];

                        materialsInformationTDS = new MaterialsInformationTDS();
                        materialsTDS = new MaterialsTDS();

                        MaterialsInformationBasicInformation materialsInformationBasicInformation = new MaterialsInformationBasicInformation(materialsInformationTDS);
                        materialsInformationBasicInformation.LoadByMaterialId(materialId, companyId);

                        MaterialsInformationCostHistoryInformation materialsInformationCostHistoryInformation = new MaterialsInformationCostHistoryInformation(materialsInformationTDS);
                        materialsInformationCostHistoryInformation.LoadAllByMaterialId(materialId, companyId);

                        MaterialsInformationCostHistoryExceptionsInformation materialsInformationCostHistoryExceptionsInformation = new MaterialsInformationCostHistoryExceptionsInformation(materialsInformationTDS);
                        materialsInformationCostHistoryExceptionsInformation.LoadAllByMaterialId(materialId, companyId);

                        MaterialsInformationNoteInformation materialsInformationNoteInformationForEdit = new MaterialsInformationNoteInformation(materialsInformationTDS);
                        materialsInformationNoteInformationForEdit.LoadAllByMaterialId(materialId, companyId);
                    }
                    else
                    {
                        hdfActiveTab.Value = (string)Session["activeTabMaterials"];

                        // Restore datasets
                        materialsTDS = (MaterialsTDS)Session["materialsTDS"];
                        materialsInformationTDS = (MaterialsInformationTDS)Session["materialsInformationTDS"];
                    }

                    // ... Store dataset
                    Session["materialsInformationTDS"] = materialsInformationTDS;
                    Session["materialsTDS"] = materialsTDS;
                }

                // ... materials_summary.aspx or materials_edit
                if ((Request.QueryString["source_page"] == "materials_summary.aspx") || (Request.QueryString["source_page"] == "materials_edit.aspx"))
                {
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];

                    // ... Restore dataset
                    materialsTDS = (MaterialsTDS)Session["materialsTDS"];
                    materialsInformationTDS = (MaterialsInformationTDS)Session["materialsInformationTDS"];

                    // ... Set initial tab
                    if ((string)Session["dialogOpenedMaterials"] != "1")
                    {
                        hdfActiveTab.Value = Request.QueryString["active_tab"];
                    }
                    else
                    {
                        hdfActiveTab.Value = (string)Session["activeTabMaterials"];
                    }

                    if (ViewState["update"].ToString().Trim() == "yes")
                    {
                        MaterialsInformationBasicInformation materialsInformationBasicInformation = new MaterialsInformationBasicInformation(materialsInformationTDS);
                        materialsInformationBasicInformation.LoadByMaterialId(materialId, companyId);

                        MaterialsInformationCostHistoryInformation materialsInformationCostHistoryInformation = new MaterialsInformationCostHistoryInformation(materialsInformationTDS);
                        materialsInformationCostHistoryInformation.LoadAllByMaterialId(materialId, companyId);

                        MaterialsInformationCostHistoryExceptionsInformation materialsInformationCostHistoryExceptionsInformation = new MaterialsInformationCostHistoryExceptionsInformation(materialsInformationTDS);
                        materialsInformationCostHistoryExceptionsInformation.LoadAllByMaterialId(materialId, companyId);

                        MaterialsInformationNoteInformation materialsInformationNoteInformationForEdit = new MaterialsInformationNoteInformation(materialsInformationTDS);
                        materialsInformationNoteInformationForEdit.LoadAllByMaterialId(materialId, companyId);

                        // ... Store dataset
                        Session["materialsInformationTDS"] = materialsInformationTDS;
                        Session["materialsTDS"] = materialsTDS;
                    }
                }

                Session["costIdSelected"] = 0;
                grdCostsExceptions.ShowFooter = false;
                string filterOptions = string.Format("CostID = {0} AND Deleted = {1}", 0, 0);
                odsCostsExceptions.FilterExpression = filterOptions;

                // Prepare initial data
                // ... Set initial tab
                int activeTabMaterials = Int32.Parse(hdfActiveTab.Value);
                tcDetailedInformation.ActiveTabIndex = activeTabMaterials;

                // ... Data for current material
                LoadData(companyId);

                // Databind
                Page.DataBind();
            }
            else
            {
                // Restore datasets
                materialsTDS = (MaterialsTDS)Session["materialsTDS"];
                materialsInformationTDS = (MaterialsInformationTDS)Session["materialsInformationTDS"];

                // Set initial tab
                int activeTabMaterials = Int32.Parse(hdfActiveTab.Value);
                tcDetailedInformation.ActiveTabIndex = activeTabMaterials;
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_RESOURCES_EMPLOYEES_VIEW"]) && Convert.ToBoolean(Session["sgLFS_RESOURCES_EMPLOYEES_DELETE"])))
                {
                    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["source_page"] == null) || ((string)Request.QueryString["material_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in materials_delete.aspx");
                }

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

                // 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_navigator2.aspx
                if (Request.QueryString["source_page"] == "materials_navigator2.aspx")
                {
                    StoreNavigatorState();
                    ViewState["update"] = "no";

                    materialsInformationTDS = new MaterialsInformationTDS();
                    materialsTDS = new MaterialsTDS();

                    MaterialsInformationBasicInformation materialsInformationBasicInformation = new MaterialsInformationBasicInformation(materialsInformationTDS);
                    materialsInformationBasicInformation.LoadByMaterialId(materialId, companyId);

                    MaterialsInformationCostHistoryInformation materialsInformationCostHistoryInformation = new MaterialsInformationCostHistoryInformation(materialsInformationTDS);
                    materialsInformationCostHistoryInformation.LoadAllByMaterialId(materialId, companyId);

                    MaterialsInformationCostHistoryExceptionsInformation materialsInformationCostHistoryExceptionsInformation = new MaterialsInformationCostHistoryExceptionsInformation(materialsInformationTDS);
                    materialsInformationCostHistoryExceptionsInformation.LoadAllByMaterialId(materialId, companyId);

                    MaterialsInformationNoteInformation materialsInformationNoteInformation = new MaterialsInformationNoteInformation(materialsInformationTDS);
                    materialsInformationNoteInformation.LoadAllByMaterialId(materialId, companyId);

                    // Store dataset
                    Session["materialsInformationTDS"] = materialsInformationTDS;
                    Session["materialsTDS"] = materialsTDS;
                }

                // ... materials_summary.aspx
                if (Request.QueryString["source_page"] == "materials_summary.aspx")
                {
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];

                    // Restore dataset
                    materialsTDS = (MaterialsTDS)Session["materialsTDS"];
                    materialsInformationTDS = (MaterialsInformationTDS)Session["materialsInformationTDS"];
                }
            }
            else
            {
                // Restore datasets
                materialsTDS = (MaterialsTDS)Session["materialsTDS"];
                materialsInformationTDS = (MaterialsInformationTDS)Session["materialsInformationTDS"];
            }
        }