/// <summary> /// Save all LH Costing Sheets /// </summary> /// <param name="companyId">companyId</param> /// <param name="costingSheetId">costingSheetId</param> public void Save(int companyId, int costingSheetId) { ProjectCostingSheetInformationTDS labourHourInformationChanges = (ProjectCostingSheetInformationTDS)Data.GetChanges(); if (labourHourInformationChanges.LabourHoursInformation.Rows.Count > 0) { ProjectCostingSheetInformationLabourHoursInformationGateway projectCostingSheetInformationLabourHoursInformationGateway = new ProjectCostingSheetInformationLabourHoursInformationGateway(labourHourInformationChanges); foreach (ProjectCostingSheetInformationTDS.LabourHoursInformationRow row in (ProjectCostingSheetInformationTDS.LabourHoursInformationDataTable)labourHourInformationChanges.LabourHoursInformation) { // Insert new costing sheet Labour Hours if ((!row.Deleted) && (!row.InDatabase)) { int? mealsQuantity = null; if (!row.IsMealsQuantityNull()) mealsQuantity = row.MealsQuantity; int? motelQuantity = null; if (!row.IsMotelQuantityNull()) motelQuantity = row.MotelQuantity; decimal? measlCostCad = null; if (!row.IsMealsCostCadNull()) measlCostCad = row.MealsCostCad; decimal? motelCostCad = null; if (!row.IsMotelCostCadNull()) motelCostCad = row.MotelCostCad; decimal? measlCostUsd = null; if (!row.IsMealsCostUsdNull()) measlCostUsd = row.MealsCostUsd; decimal? motelCostUsd = null; if (!row.IsMotelCostUsdNull()) motelCostUsd = row.MotelCostUsd; ProjectCostingSheetLabourHours labourHours = new ProjectCostingSheetLabourHours(null); labourHours.InsertDirect(costingSheetId, row.Work_, row.EmployeeID, row.RefID, row.LHQuantity, row.LHUnitOfMeasurement, row.MealsUnitOfMeasurement, mealsQuantity, row.MotelUnitOfMeasurement, motelQuantity, row.LHCostCad, measlCostCad, motelCostCad, row.TotalCostCad, row.LHCostUsd, measlCostUsd, motelCostUsd, row.TotalCostUsd, false, companyId, row.StartDate, row.EndDate, row.Function_); } // Update costing sheet Labour Hours if ((!row.Deleted) && (row.InDatabase)) { string work_ = row.Work_; int employeeId = row.EmployeeID; int refId = row.RefID; bool deleted = false; //original values string originalLHUnitOfMeasurement = projectCostingSheetInformationLabourHoursInformationGateway.GetLHUnitOfMeasurementOriginal(costingSheetId, work_, employeeId, refId); double originalLHQuantity = projectCostingSheetInformationLabourHoursInformationGateway.GetLHQuantityOriginal(costingSheetId, work_, employeeId, refId); string originalMealsUnitOfMeasurement = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsUnitOfMeasurementOriginal(costingSheetId, work_, employeeId, refId); int? originalMealsQuantity = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMealsQuantityOriginal(costingSheetId, work_, employeeId, refId).HasValue) originalMealsQuantity = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsQuantityOriginal(costingSheetId, work_, employeeId, refId).Value; string originalMotelUnitOfMeasurement = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelUnitOfMeasurementOriginal(costingSheetId, work_, employeeId, refId); int? originalMotelQuantity = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMotelQuantityOriginal(costingSheetId, work_, employeeId, refId).HasValue) originalMotelQuantity = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelQuantityOriginal(costingSheetId, work_, employeeId, refId).Value; decimal originalLHCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetLHCostCadOriginal(costingSheetId, work_, employeeId, refId); decimal? originalMealsCostCad = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostCadOriginal(costingSheetId, work_, employeeId, refId).HasValue) originalMealsCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostCadOriginal(costingSheetId, work_, employeeId, refId); decimal? originalMotelCostCad = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostCadOriginal(costingSheetId, work_, employeeId, refId).HasValue) originalMotelCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostCadOriginal(costingSheetId, work_, employeeId, refId); decimal originalTotalCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetTotalCostCadOriginal(costingSheetId, work_, employeeId, refId); decimal originalLHCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetLHCostUsdOriginal(costingSheetId, work_, employeeId, refId); decimal? originalMealsCostUsd = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostUsdOriginal(costingSheetId, work_, employeeId, refId).HasValue) originalMealsCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostUsdOriginal(costingSheetId, work_, employeeId, refId); decimal? originalMotelCostUsd = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostUsdOriginal(costingSheetId, work_, employeeId, refId).HasValue) originalMotelCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostUsdOriginal(costingSheetId, work_, employeeId, refId); decimal originalTotalCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetTotalCostUsdOriginal(costingSheetId, work_, employeeId, refId); DateTime originalStartDate = projectCostingSheetInformationLabourHoursInformationGateway.GetStartDateOriginal(costingSheetId, work_, employeeId, refId); DateTime originalEndDate = projectCostingSheetInformationLabourHoursInformationGateway.GetEndDateOriginal(costingSheetId, work_, employeeId, refId); string originalFunction_ = projectCostingSheetInformationLabourHoursInformationGateway.GetFunction_Original(costingSheetId, work_, employeeId, refId); //original values string newLHUnitOfMeasurement = projectCostingSheetInformationLabourHoursInformationGateway.GetLHUnitOfMeasurement(costingSheetId, work_, employeeId, refId); double newLHQuantity = projectCostingSheetInformationLabourHoursInformationGateway.GetLHQuantity(costingSheetId, work_, employeeId, refId); string newMealsUnitOfMeasurement = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsUnitOfMeasurement(costingSheetId, work_, employeeId, refId); int? newMealsQuantity = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMealsQuantity(costingSheetId, work_, employeeId, refId).HasValue) newMealsQuantity = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsQuantity(costingSheetId, work_, employeeId, refId).Value; string newMotelUnitOfMeasurement = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelUnitOfMeasurement(costingSheetId, work_, employeeId, refId); int? newMotelQuantity = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMotelQuantity(costingSheetId, work_, employeeId, refId).HasValue) newMotelQuantity = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelQuantity(costingSheetId, work_, employeeId, refId).Value; decimal newLHCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetLHCostCad(costingSheetId, work_, employeeId, refId); decimal? newMealsCostCad = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostCad(costingSheetId, work_, employeeId, refId).HasValue) newMealsCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostCad(costingSheetId, work_, employeeId, refId); decimal? newMotelCostCad = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostCad(costingSheetId, work_, employeeId, refId).HasValue) newMotelCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostCad(costingSheetId, work_, employeeId, refId); decimal newTotalCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetTotalCostCad(costingSheetId, work_, employeeId, refId); decimal newLHCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetLHCostUsd(costingSheetId, work_, employeeId, refId); decimal? newMealsCostUsd = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostUsd(costingSheetId, work_, employeeId, refId).HasValue) newMealsCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostUsd(costingSheetId, work_, employeeId, refId); decimal? newMotelCostUsd = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostUsd(costingSheetId, work_, employeeId, refId).HasValue) newMotelCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostUsd(costingSheetId, work_, employeeId, refId); decimal newTotalCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetTotalCostUsd(costingSheetId, work_, employeeId, refId); DateTime newStartDate = projectCostingSheetInformationLabourHoursInformationGateway.GetStartDate(costingSheetId, work_, employeeId, refId); DateTime newEndDate = projectCostingSheetInformationLabourHoursInformationGateway.GetEndDate(costingSheetId, work_, employeeId, refId); string newFunction_ = projectCostingSheetInformationLabourHoursInformationGateway.GetFunction_(costingSheetId, work_, employeeId, refId); ProjectCostingSheetLabourHours labourHours = new ProjectCostingSheetLabourHours(null); labourHours.UpdateDirect(costingSheetId, employeeId, refId, work_, originalLHQuantity, originalLHUnitOfMeasurement, originalMealsUnitOfMeasurement, originalMealsQuantity, originalMealsUnitOfMeasurement, originalMotelQuantity, originalLHCostCad, originalMealsCostCad, originalMotelCostCad, originalTotalCostCad, originalLHCostUsd, originalMealsCostUsd, originalMotelCostUsd, originalTotalCostUsd, deleted, companyId, originalStartDate, originalEndDate, originalFunction_, work_, newLHQuantity, newLHUnitOfMeasurement, newMealsUnitOfMeasurement, newMealsQuantity, newMotelUnitOfMeasurement, newMotelQuantity, newLHCostCad, newMealsCostCad, newMotelCostCad, newTotalCostCad, newLHCostUsd, newMealsCostUsd, newMotelCostUsd, newTotalCostUsd, deleted, companyId, newStartDate, newEndDate, newFunction_); } // Delete costing sheet Labour Hours if ((row.Deleted) && (row.InDatabase)) { ProjectCostingSheetLabourHours labourHours = new ProjectCostingSheetLabourHours(null); labourHours.DeleteDirect(row.CostingSheetID, row.Work_, row.EmployeeID, row.RefID, row.COMPANY_ID); } } } }