/// <summary>
        /// Save all udfs to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>        
        public void Save(int companyId)
        {
            ActualCostsAddTDS subcontractorsChanges = (ActualCostsAddTDS)Data.GetChanges();

            if (subcontractorsChanges != null)
            {
                if (subcontractorsChanges.SubcontractorCosts.Rows.Count > 0)
                {
                    ActualCostsAddSubcontractorCostsGateway actualCostsAddSubcontractorCostsGateway = new ActualCostsAddSubcontractorCostsGateway(subcontractorsChanges);

                    foreach (ActualCostsAddTDS.SubcontractorCostsRow row in (ActualCostsAddTDS.SubcontractorCostsDataTable)subcontractorsChanges.SubcontractorCosts)
                    {
                        // Insert new subcontractor hours
                        if ((!row.Deleted) && (!row.InDatabase))
                        {
                            int projectId = row.ProjectID;
                            int refId = row.RefID;
                            int subcontractorId = row.SubcontractorID;

                            decimal rateUsd = 0; if (!row.IsRateUsdNull()) rateUsd = row.RateUsd;
                            decimal totalUsd = 0; if (!row.IsTotalUsdNull()) totalUsd = row.TotalUsd;
                            string comment = ""; if (!row.IsCommentNull()) comment = row.Comment;

                            ActualCostsSubcontractorCosts actualCostsSubcontractorCosts = new ActualCostsSubcontractorCosts(null);
                            actualCostsSubcontractorCosts.InsertDirect(projectId, refId, subcontractorId, row.Date, row.Quantity, row.RateCad, row.TotalCad, rateUsd, totalUsd, comment, row.Deleted, row.COMPANY_ID);
                        }
                    }
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // PRIVATE METHODS
        //
        /// <summary>
        /// GetNewRefId
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="companyId">companyId</param>
        /// <returns>New ID</returns>
        public int GetNewRefId(int projectId, int companyId)
        {
            int newRefId = 0;

            if (Table.Rows.Count == 0)
            {
                ActualCostsAddSubcontractorCostsGateway rr = new ActualCostsAddSubcontractorCostsGateway();
                rr.LoadAllByProjectId(projectId, companyId);

                foreach (ActualCostsAddTDS.SubcontractorCostsRow row1 in (ActualCostsAddTDS.SubcontractorCostsDataTable)rr.Table)
                {
                    if (newRefId < row1.RefID)
                    {
                        newRefId = row1.RefID;
                    }
                }
            }
            else
            {
                // ... If there are rows at the grid
                // ... ... Verify if there are rows for the same project at the grid
                bool existProject = false;
                foreach (ActualCostsAddTDS.SubcontractorCostsRow row2 in (ActualCostsAddTDS.SubcontractorCostsDataTable)Table)
                {
                    if (projectId == row2.ProjectID)
                    {
                        existProject = true;
                    }
                }

                // ... ... If there are rows at the grid get new Id
                if (existProject)
                {
                    foreach (ActualCostsAddTDS.SubcontractorCostsRow row3 in (ActualCostsAddTDS.SubcontractorCostsDataTable)Table)
                    {
                        if (projectId == row3.ProjectID)
                        {
                            if (newRefId < row3.RefID)
                            {
                                newRefId = row3.RefID;
                            }
                        }
                    }
                }
                else
                {
                    // ... ... There are no rows for the project at the grid, verify on de db.
                    ActualCostsAddSubcontractorCostsGateway rrsc = new ActualCostsAddSubcontractorCostsGateway();
                    rrsc.LoadAllByProjectId(projectId, companyId);

                    foreach (ActualCostsAddTDS.SubcontractorCostsRow row3 in (ActualCostsAddTDS.SubcontractorCostsDataTable)rrsc.Table)
                    {
                        if (newRefId < row3.RefID)
                        {
                            newRefId = row3.RefID;
                        }
                    }
                }
            }

            newRefId++;

            return newRefId;
        }
 // ////////////////////////////////////////////////////////////////////////
 // PUBLIC METHODS - DATASET
 //
 /// <summary>
 /// LoadAllByProjectId
 /// </summary>
 /// <param name="projectId">projectId</param>
 /// <param name="companyId">companyId</param>
 public void LoadAllByProjectId(int projectId, int companyId)
 {
     ActualCostsAddSubcontractorCostsGateway actualCostsAddSubcontractorCostsGateway = new ActualCostsAddSubcontractorCostsGateway(Data);
     actualCostsAddSubcontractorCostsGateway.LoadAllByProjectId(projectId, companyId);
 }