// ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS - DATASET
        //
        /// <summary>
        /// LoadAll
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void LoadAll(int companyId)
        {
            SubcontractorsSetupSubcontractorsSetupGateway subcontractorsSetupSubcontractorsSetupGateway = new SubcontractorsSetupSubcontractorsSetupGateway(Data);
            subcontractorsSetupSubcontractorsSetupGateway.LoadAll(companyId);

            UpdateDataForNavigators();
        }
        protected void grdCompaniesSetup_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            // Normal rows
            if ((e.Row.RowType == DataControlRowType.DataRow) && ((e.Row.RowState == DataControlRowState.Normal) || (e.Row.RowState == (DataControlRowState.Normal | DataControlRowState.Alternate))))
            {
                int subcontractorId = int.Parse(((Label)e.Row.FindControl("lblCOMPANIES_IDId")).Text);
                int companyId = Int32.Parse(hdfCompanyId.Value);

                SubcontractorsSetupSubcontractorsSetupGateway subcontractorsSetupSubcontractorsSetupGateway = new SubcontractorsSetupSubcontractorsSetupGateway();
                if (subcontractorsSetupSubcontractorsSetupGateway.IsUsedInSubcontractorCosts(subcontractorId, companyId))
                {
                    ((ImageButton)e.Row.FindControl("ibtnDelete")).Visible = false;
                }
                else
                {
                    ((ImageButton)e.Row.FindControl("ibtnDelete")).Visible = true;
                }
            }
        }
        /// <summary>
        /// Save all subcontractors to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>        
        public void Save(int companyId)
        {
            SubcontractorsSetupTDS subcontractorSetupChanges = (SubcontractorsSetupTDS)Data.GetChanges();

            if (subcontractorSetupChanges != null)
            {
                if (subcontractorSetupChanges.SubcontractorsSetup.Rows.Count > 0)
                {
                    SubcontractorsSetupSubcontractorsSetupGateway subcontractorsSetupSubcontractorsSetupGateway = new SubcontractorsSetupSubcontractorsSetupGateway(subcontractorSetupChanges);

                    foreach (SubcontractorsSetupTDS.SubcontractorsSetupRow row in (SubcontractorsSetupTDS.SubcontractorsSetupDataTable)subcontractorSetupChanges.SubcontractorsSetup)
                    {
                        //Update subcontractors
                        if (!row.Deleted)
                        {
                            int companiesId = row.COMPANIES_ID;
                            DateTime date = row.Date;
                            bool deleted = row.Deleted;

                            // original values
                            bool originalActive = subcontractorsSetupSubcontractorsSetupGateway.GetActiveOriginal(companiesId, date);

                            // new values
                            bool newActive = subcontractorsSetupSubcontractorsSetupGateway.GetActive(companiesId, date);

                            SubcontractorsResoucesSubcontractors subcontractorsResoucesSubcontractors = new SubcontractorsResoucesSubcontractors(null);
                            subcontractorsResoucesSubcontractors.UpdateDirect(companiesId, date, originalActive, row.Udf, deleted, companyId, companiesId, date, newActive, row.Udf, deleted, companyId);
                        }

                        // Delete subcontractors
                        if (row.Deleted)
                        {
                            SubcontractorsResoucesSubcontractors subcontractorsResoucesSubcontractorsDelete = new SubcontractorsResoucesSubcontractors(null);
                            subcontractorsResoucesSubcontractorsDelete.DeleteDirect(row.COMPANIES_ID, row.Date);
                        }
                    }
                }
            }
        }