コード例 #1
0
        /// <summary>
        /// Save all Service to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void Save(int companyId)
        {
            ProjectNavigatorTDS serviceChanges = (ProjectNavigatorTDS)Data.GetChanges();

            if (serviceChanges != null)
            {
                if (serviceChanges.ProjectService.Rows.Count > 0)
                {
                    ProjectNavigatorProjectServiceGateway projectNavigatorProjectServiceGateway = new ProjectNavigatorProjectServiceGateway(serviceChanges);

                    foreach (ProjectNavigatorTDS.ProjectServiceRow row in (ProjectNavigatorTDS.ProjectServiceDataTable)serviceChanges.ProjectService)
                    {
                        // Insert new Service
                        if ((!row.Deleted) && (!row.InDatabase))
                        {
                            int? serviceId = null; if (!row.IsServiceIDNull()) serviceId = row.ServiceID;
                            string description = ""; if (!row.IsDescriptionNull()) description = row.Description;
                            string averageSize = ""; if (!row.IsAverageSizeNull()) averageSize = row.AverageSize;
                            decimal? averagePrice = null; if (!row.IsAveragePriceNull()) averagePrice = row.AveragePrice;

                            ProjectService projectService = new ProjectService(null);
                            projectService.InsertDirect(row.ProjectID, row.RefID, serviceId, description, averageSize, averagePrice, row.Quantity, row.Deleted, row.COMPANY_ID);
                        }

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

                            // original values
                            int? originalServiceId = projectNavigatorProjectServiceGateway.GetServiceIDOriginal(projectId, refId);
                            string originalDescription = projectNavigatorProjectServiceGateway.GetDescriptionOriginal(projectId, refId);
                            string originalAverageSize = projectNavigatorProjectServiceGateway.GetAverageSizeOriginal(projectId, refId);
                            decimal? originalAveragePrice = projectNavigatorProjectServiceGateway.GetAveragePriceOriginal(projectId, refId);
                            int originalQuantity = projectNavigatorProjectServiceGateway.GetQuantityOriginal(projectId, refId);

                            // new values
                            int? newServiceId = projectNavigatorProjectServiceGateway.GetServiceID(projectId, refId);
                            string newDescription = projectNavigatorProjectServiceGateway.GetDescription(projectId, refId);
                            string newAverageSize = projectNavigatorProjectServiceGateway.GetAverageSize(projectId, refId);
                            decimal? newAveragePrice = projectNavigatorProjectServiceGateway.GetAveragePrice(projectId, refId);
                            int newQuantity = projectNavigatorProjectServiceGateway.GetQuantity(projectId, refId);

                            ProjectService projectService = new ProjectService(null);
                            projectService.UpdateDirect(projectId, refId,  originalServiceId, originalDescription, originalAverageSize, originalAveragePrice, originalQuantity, originalDeleted, originalCompanyId, projectId, refId, newServiceId, newDescription, newAverageSize, newAveragePrice, newQuantity, originalDeleted, originalCompanyId);
                        }

                        // Deleted Service
                        if ((row.Deleted) && (row.InDatabase))
                        {
                            ProjectService projectService = new ProjectService(null);
                            projectService.DeleteDirect(row.ProjectID, row.RefID, row.COMPANY_ID);
                        }
                    }
                }
            }
        }