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

            InsuranceCompaniesSetupInsuranceCompaniesSetup model = new InsuranceCompaniesSetupInsuranceCompaniesSetup(insuranceCompaniesSetupTDS);
            model.Delete(companiesId, date);

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

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_RESOURCES_INSURANCECOMPANIES_VIEW"]) && Convert.ToBoolean(Session["sgLFS_RESOURCES_INSURANCECOMPANIES_EDIT"])) && Convert.ToBoolean(Session["sgLFS_RESOURCES_INSURANCECOMPANIES_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 insuranceCompanies_navigator.aspx");
                }

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

                // Prepare initial data
                Session.Remove("insuranceCompaniesSetupTableDummy");
                tdNoResults.Visible = false;

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

                    InsuranceCompaniesSetupInsuranceCompaniesSetup model = new InsuranceCompaniesSetupInsuranceCompaniesSetup(insuranceCompaniesSetupTDS);
                    int companyId = Int32.Parse(hdfCompanyId.Value);
                    model.LoadAll(companyId);

                    // Check if there is data
                    InsuranceCompaniesSetupInsuranceCompaniesSetup modelForMessage = new InsuranceCompaniesSetupInsuranceCompaniesSetup(insuranceCompaniesSetupTDS);
                    modelForMessage.Load(companyId);

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

                    // Store tables
                    Session["insuranceCompaniesSetupTDS"] = insuranceCompaniesSetupTDS;
                    Session["insuranceCompaniesSetupTable"] = insuranceCompaniesSetupTDS.InsuranceCompaniesSetup;
                }
            }
            else
            {
                // Restore datasets
                insuranceCompaniesSetupTDS = (InsuranceCompaniesSetupTDS)Session["insuranceCompaniesSetupTDS"];
                Session["insuranceCompaniesSetupTable"] = insuranceCompaniesSetupTDS.InsuranceCompaniesSetup;
            }
        }
        private void UpdateDatabase()
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);

            DB.Open();
            DB.BeginTransaction();
            try
            {
                // Save subcontractors
                InsuranceCompaniesSetupInsuranceCompaniesSetup insuranceCompaniesSetupInsuranceCompaniesSetup = new InsuranceCompaniesSetupInsuranceCompaniesSetup(insuranceCompaniesSetupTDS);
                insuranceCompaniesSetupInsuranceCompaniesSetup.Save(companyId);

                DB.CommitTransaction();

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

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