protected void grdCompaniesSetup_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // Delete subcontractor
            int companiesId = (int)e.Keys["COMPANIES_ID"];
            DateTime date = (DateTime)e.Keys["Date"];

            BondingCompaniesSetupBondingCompaniesSetup model = new BondingCompaniesSetupBondingCompaniesSetup(bondingCompaniesSetupTDS);
            model.Delete(companiesId, date);

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

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_RESOURCES_BONDINGCOMPANIES_VIEW"]) && Convert.ToBoolean(Session["sgLFS_RESOURCES_BONDINGCOMPANIES_EDIT"]))  && Convert.ToBoolean(Session["sgLFS_RESOURCES_BONDINGCOMPANIES_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("bondingCompaniesSetupTableDummy");
                tdNoResults.Visible = false;

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

                    BondingCompaniesSetupBondingCompaniesSetup model = new BondingCompaniesSetupBondingCompaniesSetup(bondingCompaniesSetupTDS);
                    int companyId = Int32.Parse(hdfCompanyId.Value);
                    model.LoadAll(companyId);

                    // Check if there is data
                    BondingCompaniesSetupBondingCompaniesSetup modelForMessage = new BondingCompaniesSetupBondingCompaniesSetup(bondingCompaniesSetupTDS);
                    modelForMessage.Load(companyId);

                    if (modelForMessage.Table.Rows.Count > 0)
                    {
                        tdNoResults.Visible = false;
                    }
                    else
                    {
                        tdNoResults.Visible = true;
                    }

                    // Store tables
                    Session["bondingCompaniesSetupTDS"] = bondingCompaniesSetupTDS;
                    Session["bondingCompaniesSetupTable"] = bondingCompaniesSetupTDS.BondingCompaniesSetup;
                }
            }
            else
            {
                // Restore datasets
                bondingCompaniesSetupTDS = (BondingCompaniesSetupTDS)Session["bondingCompaniesSetupTDS"];
                Session["bondingCompaniesSetupTable"] = bondingCompaniesSetupTDS.BondingCompaniesSetup;
            }
        }
        private void UpdateDatabase()
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);

            DB.Open();
            DB.BeginTransaction();
            try
            {
                // Save subcontractors
                BondingCompaniesSetupBondingCompaniesSetup bondingCompaniesSetupBondingCompaniesSetup = new BondingCompaniesSetupBondingCompaniesSetup(bondingCompaniesSetupTDS);
                bondingCompaniesSetupBondingCompaniesSetup.Save(companyId);

                DB.CommitTransaction();

                // Store datasets
                bondingCompaniesSetupTDS.AcceptChanges();
                Session["bondingCompaniesSetupTDS"] = bondingCompaniesSetupTDS;
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }