private void LoadData(int projectId, int refId)
        {
            string category = hdfCategory.Value;

            // Load Data
            if (category == "Subcontractors")
            {
                ActualCostsInformationSubcontractorBasicInformationGateway actualCostsInformationSubcontractorBasicInformationGateway = new ActualCostsInformationSubcontractorBasicInformationGateway(actualCostsInformationTDS);
                if (actualCostsInformationSubcontractorBasicInformationGateway.Table.Rows.Count > 0)
                {
                    // Load subcontractor basic data
                    tbxCategory.Text = actualCostsInformationSubcontractorBasicInformationGateway.GetSubcontractor(projectId, refId);

                    if (tbxState.Visible)
                    {
                        if (actualCostsInformationSubcontractorBasicInformationGateway.GetActive(projectId, refId))
                        {
                            tbxState.Text = "Active";
                        }
                        else
                        {
                            tbxState.Text = "Inactive";
                        }
                    }

                    tbxClient.Text = actualCostsInformationSubcontractorBasicInformationGateway.GetClient(projectId, refId);
                    tbxProject.Text = actualCostsInformationSubcontractorBasicInformationGateway.GetProject(projectId, refId);
                    hdfClientId.Value = actualCostsInformationSubcontractorBasicInformationGateway.GetClientID(projectId, refId).ToString();

                    tkrdpDate_.SelectedDate = (DateTime)(actualCostsInformationSubcontractorBasicInformationGateway.GetDate(projectId, refId));

                    if (tbxQuantity.Visible)
                    {
                        decimal quantity = decimal.Parse(actualCostsInformationSubcontractorBasicInformationGateway.GetQuantity(projectId, refId).ToString());
                        tbxQuantity.Text = decimal.Round(quantity, 1).ToString();
                    }

                    if (actualCostsInformationSubcontractorBasicInformationGateway.GetCountryId(projectId, refId) == 1) // Canada
                    {
                        decimal rate = decimal.Parse(actualCostsInformationSubcontractorBasicInformationGateway.GetRateCad(projectId, refId).ToString());
                        tbxRate.Text = decimal.Round(rate, 2).ToString();

                        if (tbxTotal.Visible)
                        {
                            decimal total = decimal.Parse(actualCostsInformationSubcontractorBasicInformationGateway.GetTotalCad(projectId, refId).ToString());
                            tbxTotal.Text = decimal.Round(total, 2).ToString();
                        }
                    }
                    else // Usa
                    {
                        decimal rate = decimal.Parse(actualCostsInformationSubcontractorBasicInformationGateway.GetRateUsd(projectId, refId).ToString());
                        tbxRate.Text = decimal.Round(rate, 2).ToString();

                        if (tbxTotal.Visible)
                        {
                            decimal total = decimal.Parse(actualCostsInformationSubcontractorBasicInformationGateway.GetTotalUsd(projectId, refId).ToString());
                            tbxTotal.Text = decimal.Round(total, 2).ToString();
                        }
                    }

                    hdfCountryId.Value = actualCostsInformationSubcontractorBasicInformationGateway.GetCountryId(projectId, refId).ToString();
                    tbxComments.Text = actualCostsInformationSubcontractorBasicInformationGateway.GetComment(projectId, refId);
                }
            }
            else
            {
                if (category == "Hotels")
                {
                    ActualCostsInformationHotelCostsBasicInformationGateway actualCostsInformationHotelCostsBasicInformationGateway = new ActualCostsInformationHotelCostsBasicInformationGateway(actualCostsInformationTDS);
                    if (actualCostsInformationHotelCostsBasicInformationGateway.Table.Rows.Count > 0)
                    {
                        // Load subcontractor basic data
                        tbxCategory.Text = actualCostsInformationHotelCostsBasicInformationGateway.GetHotel(projectId, refId);
                        tbxClient.Text = actualCostsInformationHotelCostsBasicInformationGateway.GetClient(projectId, refId);
                        tbxProject.Text = actualCostsInformationHotelCostsBasicInformationGateway.GetProject(projectId, refId);
                        hdfClientId.Value = actualCostsInformationHotelCostsBasicInformationGateway.GetClientID(projectId, refId).ToString();

                        tkrdpDate_.SelectedDate = (DateTime)(actualCostsInformationHotelCostsBasicInformationGateway.GetDate(projectId, refId));

                        if (actualCostsInformationHotelCostsBasicInformationGateway.GetCountryId(projectId, refId) == 1) // Canada
                        {
                            decimal rate = decimal.Parse(actualCostsInformationHotelCostsBasicInformationGateway.GetRateCad(projectId, refId).ToString());
                            tbxRate.Text = decimal.Round(rate, 2).ToString();
                        }
                        else // Usa
                        {
                            decimal rate = decimal.Parse(actualCostsInformationHotelCostsBasicInformationGateway.GetRateUsd(projectId, refId).ToString());
                            tbxRate.Text = decimal.Round(rate, 2).ToString();
                        }

                        hdfCountryId.Value = actualCostsInformationHotelCostsBasicInformationGateway.GetCountryId(projectId, refId).ToString();
                        tbxComments.Text = actualCostsInformationHotelCostsBasicInformationGateway.GetComment(projectId, refId);
                    }
                }
                else
                {
                    if (category == "Insurance")
                    {
                        ActualCostsInformationInsuranceCostsBasicInformationGateway actualCostsInformationInsuranceCostsBasicInformationGateway = new ActualCostsInformationInsuranceCostsBasicInformationGateway(actualCostsInformationTDS);
                        if (actualCostsInformationInsuranceCostsBasicInformationGateway.Table.Rows.Count > 0)
                        {
                            // Load subcontractor basic data
                            tbxCategory.Text = actualCostsInformationInsuranceCostsBasicInformationGateway.GetInsurance(projectId, refId);
                            tbxClient.Text = actualCostsInformationInsuranceCostsBasicInformationGateway.GetClient(projectId, refId);
                            tbxProject.Text = actualCostsInformationInsuranceCostsBasicInformationGateway.GetProject(projectId, refId);
                            hdfClientId.Value = actualCostsInformationInsuranceCostsBasicInformationGateway.GetClientID(projectId, refId).ToString();

                            tkrdpDate_.SelectedDate = (DateTime)(actualCostsInformationInsuranceCostsBasicInformationGateway.GetDate(projectId, refId));

                            if (actualCostsInformationInsuranceCostsBasicInformationGateway.GetCountryId(projectId, refId) == 1) // Canada
                            {
                                decimal rate = decimal.Parse(actualCostsInformationInsuranceCostsBasicInformationGateway.GetRateCad(projectId, refId).ToString());
                                tbxRate.Text = decimal.Round(rate, 2).ToString();
                            }
                            else // Usa
                            {
                                decimal rate = decimal.Parse(actualCostsInformationInsuranceCostsBasicInformationGateway.GetRateUsd(projectId, refId).ToString());
                                tbxRate.Text = decimal.Round(rate, 2).ToString();
                            }

                            hdfCountryId.Value = actualCostsInformationInsuranceCostsBasicInformationGateway.GetCountryId(projectId, refId).ToString();
                            tbxComments.Text = actualCostsInformationInsuranceCostsBasicInformationGateway.GetComment(projectId, refId);
                        }
                    }
                    else
                    {
                        if (category == "Bonding")
                        {
                            ActualCostsInformationBondingCostsBasicInformationGateway actualCostsInformationBondingCostsBasicInformationGateway = new ActualCostsInformationBondingCostsBasicInformationGateway(actualCostsInformationTDS);
                            if (actualCostsInformationBondingCostsBasicInformationGateway.Table.Rows.Count > 0)
                            {
                                // Load subcontractor basic data
                                tbxCategory.Text = actualCostsInformationBondingCostsBasicInformationGateway.GetBonding(projectId, refId);
                                tbxClient.Text = actualCostsInformationBondingCostsBasicInformationGateway.GetClient(projectId, refId);
                                tbxProject.Text = actualCostsInformationBondingCostsBasicInformationGateway.GetProject(projectId, refId);
                                hdfClientId.Value = actualCostsInformationBondingCostsBasicInformationGateway.GetClientID(projectId, refId).ToString();

                                tkrdpDate_.SelectedDate = (DateTime)(actualCostsInformationBondingCostsBasicInformationGateway.GetDate(projectId, refId));

                                if (actualCostsInformationBondingCostsBasicInformationGateway.GetCountryId(projectId, refId) == 1) // Canada
                                {
                                    decimal rate = decimal.Parse(actualCostsInformationBondingCostsBasicInformationGateway.GetRateCad(projectId, refId).ToString());
                                    tbxRate.Text = decimal.Round(rate, 2).ToString();
                                }
                                else // Usa
                                {
                                    decimal rate = decimal.Parse(actualCostsInformationBondingCostsBasicInformationGateway.GetRateUsd(projectId, refId).ToString());
                                    tbxRate.Text = decimal.Round(rate, 2).ToString();
                                }

                                hdfCountryId.Value = actualCostsInformationBondingCostsBasicInformationGateway.GetCountryId(projectId, refId).ToString();
                                tbxComments.Text = actualCostsInformationBondingCostsBasicInformationGateway.GetComment(projectId, refId);
                            }
                        }
                        else
                        {
                            // for other categories
                            ActualCostsInformationOtherCostsBasicInformationGateway actualCostsInformationOtherCostsBasicInformationGateway = new ActualCostsInformationOtherCostsBasicInformationGateway(actualCostsInformationTDS);
                            if (actualCostsInformationOtherCostsBasicInformationGateway.Table.Rows.Count > 0)
                            {
                                // Load subcontractor basic data
                                tbxCategory.Text = actualCostsInformationOtherCostsBasicInformationGateway.GetCategory(projectId, refId);
                                tbxClient.Text = actualCostsInformationOtherCostsBasicInformationGateway.GetClient(projectId, refId);
                                tbxProject.Text = actualCostsInformationOtherCostsBasicInformationGateway.GetProject(projectId, refId);
                                hdfClientId.Value = actualCostsInformationOtherCostsBasicInformationGateway.GetClientID(projectId, refId).ToString();

                                tkrdpDate_.SelectedDate = (DateTime)(actualCostsInformationOtherCostsBasicInformationGateway.GetDate(projectId, refId));

                                if (actualCostsInformationOtherCostsBasicInformationGateway.GetCountryId(projectId, refId) == 1) // Canada
                                {
                                    decimal rate = decimal.Parse(actualCostsInformationOtherCostsBasicInformationGateway.GetRateCad(projectId, refId).ToString());
                                    tbxRate.Text = decimal.Round(rate, 2).ToString();
                                }
                                else // Usa
                                {
                                    decimal rate = decimal.Parse(actualCostsInformationOtherCostsBasicInformationGateway.GetRateUsd(projectId, refId).ToString());
                                    tbxRate.Text = decimal.Round(rate, 2).ToString();
                                }

                                hdfCountryId.Value = actualCostsInformationOtherCostsBasicInformationGateway.GetCountryId(projectId, refId).ToString();
                                tbxComments.Text = actualCostsInformationOtherCostsBasicInformationGateway.GetComment(projectId, refId);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Save
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void Save(int companyId)
        {
            ActualCostsInformationTDS subcontractorHoursInformationChanges = (ActualCostsInformationTDS)Data.GetChanges();

            if (subcontractorHoursInformationChanges.SubcontractorBasicInformation.Rows.Count > 0)
            {
                ActualCostsInformationSubcontractorBasicInformationGateway actualCostsInformationSubcontractorBasicInformationGateway = new ActualCostsInformationSubcontractorBasicInformationGateway(subcontractorHoursInformationChanges);

                // Update employee
                foreach (ActualCostsInformationTDS.SubcontractorBasicInformationRow row in (ActualCostsInformationTDS.SubcontractorBasicInformationDataTable)subcontractorHoursInformationChanges.SubcontractorBasicInformation)
                {
                    // Insert new hours
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        string comment = ""; if (!row.IsCommentNull()) comment = row.Comment;
                        ActualCostsSubcontractorCosts actualCostsSubcontractorCosts = new ActualCostsSubcontractorCosts(null);
                        actualCostsSubcontractorCosts.InsertDirect(row.ProjectID, row.RefID, row.SubcontractorID, row.Date, row.Quantity, row.RateCad, row.TotalCad, row.RateUsd, row.TotalUsd, comment, row.Deleted, row.COMPANY_ID);
                    }

                    // Update hours
                    if ((!row.Deleted) && (row.InDatabase))
                    {
                        int projectId = row.ProjectID;
                        int refId = row.RefID;
                        bool originalDeleted = false;
                        int originalCompanyId = companyId;

                        // Original values
                        int originalSubcontractorId = actualCostsInformationSubcontractorBasicInformationGateway.GetSubcontractorIDOriginal(projectId, refId);
                        DateTime originalDate = actualCostsInformationSubcontractorBasicInformationGateway.GetDateOriginal(projectId, refId);
                        double originalQuantity = actualCostsInformationSubcontractorBasicInformationGateway.GetQuantityOriginal(projectId, refId);
                        decimal originalRateCad = actualCostsInformationSubcontractorBasicInformationGateway.GetRateCadOriginal(projectId, refId);
                        decimal originalTotalCad = actualCostsInformationSubcontractorBasicInformationGateway.GetTotalCadOriginal(projectId, refId);
                        decimal originalRateUsd = actualCostsInformationSubcontractorBasicInformationGateway.GetRateUsdOriginal(projectId, refId);
                        decimal originalTotalUsd = actualCostsInformationSubcontractorBasicInformationGateway.GetTotalUsdOriginal(projectId, refId);
                        string originalComment = actualCostsInformationSubcontractorBasicInformationGateway.GetCommentOriginal(projectId, refId);

                        // New values
                        int newSubcontractorId = actualCostsInformationSubcontractorBasicInformationGateway.GetSubcontractorID(projectId, refId);
                        DateTime newDate = actualCostsInformationSubcontractorBasicInformationGateway.GetDate(projectId, refId);
                        double newQuantity = actualCostsInformationSubcontractorBasicInformationGateway.GetQuantity(projectId, refId);
                        decimal newRateCad = actualCostsInformationSubcontractorBasicInformationGateway.GetRateCad(projectId, refId);
                        decimal newTotalCad = actualCostsInformationSubcontractorBasicInformationGateway.GetTotalCad(projectId, refId);
                        decimal newRateUsd = actualCostsInformationSubcontractorBasicInformationGateway.GetRateUsd(projectId, refId);
                        decimal newTotalUsd = actualCostsInformationSubcontractorBasicInformationGateway.GetTotalUsd(projectId, refId);
                        string newComment = actualCostsInformationSubcontractorBasicInformationGateway.GetComment(projectId, refId);

                        ActualCostsSubcontractorCosts actualCostsSubcontractorCosts = new ActualCostsSubcontractorCosts(null);
                        actualCostsSubcontractorCosts.UpdateDirect(projectId, refId, originalSubcontractorId, originalDate, originalQuantity, originalRateCad, originalTotalCad, originalRateUsd, originalTotalUsd, originalComment, originalDeleted, originalCompanyId, projectId, refId, newSubcontractorId, newDate, newQuantity, newRateCad, newTotalCad, newRateUsd, newTotalUsd, newComment, originalDeleted, originalCompanyId);
                    }

                    // Delete hours
                    if ((row.Deleted) && (row.InDatabase))
                    {
                        ActualCostsSubcontractorCosts actualCostsSubcontractorCosts = new ActualCostsSubcontractorCosts(null);
                        actualCostsSubcontractorCosts.DeleteDirect(row.ProjectID, row.RefID, row.COMPANY_ID);
                    }
                }
            }
        }