//// ////////////////////////////////////////////////////////////////////////
        //// PRIVATE METHODS
        ////
        /// <summary>
        /// Save all subcontractors to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>        
        public void Save(int companyId)
        {
            SubcontractorsAddTDS subcontractorChanges = (SubcontractorsAddTDS)Data.GetChanges();

            if (subcontractorChanges.Subcontractors.Rows.Count > 0)
            {
                SubcontractorsAddSubcontractorsGateway subcontractorsAddSubcontractorsGateway = new SubcontractorsAddSubcontractorsGateway(subcontractorChanges);

                foreach (SubcontractorsAddTDS.SubcontractorsRow row in (SubcontractorsAddTDS.SubcontractorsDataTable)subcontractorChanges.Subcontractors)
                {
                    //Insert companies
                    SubcontractorsResoucesSubcontractors subcontractorsResoucesSubcontractors = new SubcontractorsResoucesSubcontractors(null);
                    subcontractorsResoucesSubcontractors.InsertDirect(row.COMPANIES_ID, row.Date, row.Name, row.Active, row.Udf, row.Deleted, row.COMPANY_ID);
                }
            }
        }
        /// <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);
                        }
                    }
                }
            }
        }