// ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        public SubcontractorsSetupTDS.SubcontractorsSetupDataTable GetCompaniesSetupNew()
        {
            subcontractorsSetupTable = (SubcontractorsSetupTDS.SubcontractorsSetupDataTable)Session["subcontractorsSetupTableDummy"];

            if (subcontractorsSetupTable == null)
            {
                subcontractorsSetupTable = ((SubcontractorsSetupTDS.SubcontractorsSetupDataTable)Session["subcontractorsSetupTable"]);
            }

            return subcontractorsSetupTable;
        }
        protected void grdCompaniesSetup_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // Subcontractors Gridview, if the gridview is edition mode
            if (grdCompaniesSetup.EditIndex >= 0)
            {
                grdCompaniesSetup.UpdateRow(grdCompaniesSetup.EditIndex, true);
            }

            // Delete subcontractor
            int companiesId = (int)e.Keys["COMPANIES_ID"];
            DateTime date = (DateTime)e.Keys["Date"];

            SubcontractorsSetupSubcontractorsSetup model = new SubcontractorsSetupSubcontractorsSetup(subcontractorsSetupTDS);
            model.Delete(companiesId, date);

            // Store dataset
            Session["subcontractorsSetupTDS"] = subcontractorsSetupTDS;
            subcontractorsSetupTable = subcontractorsSetupTDS.SubcontractorsSetup;
            Session["subcontractorsSetupTable"] = subcontractorsSetupTable;
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_RESOURCES_SUBCONTRACTORS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_RESOURCES_SUBCONTRACTORS_EDIT"]))  && Convert.ToBoolean(Session["sgLFS_RESOURCES_SUBCONTRACTORS_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)
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in subcontractors_navigator.aspx");
                }

                // Tag page
                hdfCompanyId.Value = Session["companyID"].ToString();

                // Prepare initial data
                Session.Remove("subcontractorsSetupTableDummy");

                // If coming from
                // ... Left Menu or select_project
                if (Request.QueryString["source_page"] == "out")
                {
                    // Load
                    subcontractorsSetupTDS = new SubcontractorsSetupTDS();

                    SubcontractorsSetupSubcontractorsSetup model = new SubcontractorsSetupSubcontractorsSetup(subcontractorsSetupTDS);
                    int companyId = Int32.Parse(hdfCompanyId.Value);
                    model.LoadAll(companyId);

                    // Store tables
                    Session["subcontractorsSetupTDS"] = subcontractorsSetupTDS;
                    subcontractorsSetupTable = subcontractorsSetupTDS.SubcontractorsSetup;
                    Session["subcontractorsSetupTable"] = subcontractorsSetupTable;
                }
            }
            else
            {
                // Restore datasets
                subcontractorsSetupTDS = (SubcontractorsSetupTDS)Session["subcontractorsSetupTDS"];
                subcontractorsSetupTable = subcontractorsSetupTDS.SubcontractorsSetup;
                Session["subcontractorsSetupTable"] = subcontractorsSetupTable;
            }
        }
        protected void grdCompaniesSetup_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int companiesId = (int)e.Keys["COMPANIES_ID"];
            DateTime date = (DateTime)e.Keys["Date"];

            bool active = ((CheckBox)grdCompaniesSetup.Rows[e.RowIndex].Cells[2].FindControl("cbxActiveEdit")).Checked;

            SubcontractorsSetupSubcontractorsSetup model = new SubcontractorsSetupSubcontractorsSetup(subcontractorsSetupTDS);
            model.Update(companiesId, date, active);

            // Store dataset
            Session["subcontractorsSetupTDS"] = subcontractorsSetupTDS;
            subcontractorsSetupTable = subcontractorsSetupTDS.SubcontractorsSetup;
            Session["subcontractorsSetupTable"] = subcontractorsSetupTable;
        }