Пример #1
0
        public override XDocument SaveBusinessObject(WarehouseDocument document)
        {
            DictionaryMapper.Instance.CheckForChanges();

            this.DeliverySelectionCheck(document);

            //validate
            document.Validate();

            //load alternate version
            if (!document.IsNew)
            {
                IBusinessObject alternateBusinessObject = this.mapper.LoadBusinessObject(document.BOType, document.Id.Value);
                document.SetAlternateVersion(alternateBusinessObject);
            }

            this.ProcessShiftOrder(document);

            //update status
            document.UpdateStatus(true);

            if (document.AlternateVersion != null)
            {
                document.AlternateVersion.UpdateStatus(false);
            }

            SqlConnectionManager.Instance.BeginTransaction();

            try
            {
                DictionaryMapper.Instance.CheckForChanges();
                this.mapper.CheckBusinessObjectVersion(document);

                if (document.DocumentStatus == DocumentStatus.Canceled && ConfigurationMapper.Instance.IsWmsEnabled)
                {
                    DependencyContainerManager.Container.Get <WarehouseMapper>().DeleteShiftsForDocument(document.Id.Value);
                }

                if (document.DocumentType.WarehouseDocumentOptions.UpdateLastPurchasePrice)
                {
                    UpdateLastPurchasePriceRequest updateLastPurchasePriceRequest = new UpdateLastPurchasePriceRequest(document);
                    this.mapper.UpdateStock(updateLastPurchasePriceRequest);
                }

                //Make operations list
                XDocument operations = XDocument.Parse("<root/>");

                document.SaveChanges(operations);

                if (document.AlternateVersion != null)
                {
                    document.AlternateVersion.SaveChanges(operations);
                }

                if (operations.Root.HasElements)
                {
                    this.coordinator.UpdateStock(document);
                    //this.mapper.UpdateStockForCanceledDocument(document);

                    this.mapper.ExecuteOperations(operations);

                    this.mapper.CreateCommunicationXml(document);
                    this.mapper.CreateCommunicationXmlForDocumentRelations(operations);
                    this.mapper.UpdateDictionaryIndex(document);
                }

                Coordinator.LogSaveBusinessObjectOperation();

                document.SaveRelatedObjects();

                operations = XDocument.Parse("<root/>");

                document.SaveRelations(operations);

                if (document.AlternateVersion != null)
                {
                    ((WarehouseDocument)document.AlternateVersion).SaveRelations(operations);
                }

                if (operations.Root.HasElements)
                {
                    this.mapper.ExecuteOperations(operations);
                    this.mapper.CreateCommunicationXmlForDocumentRelations(operations); //generowanie paczek dla relacji dokumentow
                }

                this.mapper.ValuateIncomeWarehouseDocument(document, false);

                this.ProcessLocalIncomeShift(document);

                XDocument returnXml = XDocument.Parse(String.Format(CultureInfo.InvariantCulture, "<root><id>{0}</id></root>", document.Id.ToUpperString()));

                //Custom validation
                this.mapper.ExecuteOnCommitValidationCustomProcedure(document);

                if (this.coordinator.CanCommitTransaction)
                {
                    if (!ConfigurationMapper.Instance.ForceRollbackTransaction)
                    {
                        SqlConnectionManager.Instance.CommitTransaction();
                    }
                    else
                    {
                        SqlConnectionManager.Instance.RollbackTransaction();
                    }
                }

                return(returnXml);
            }
            catch (SqlException sqle)
            {
                RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:69");
                Coordinator.ProcessSqlException(sqle, document.BOType, this.coordinator.CanCommitTransaction);
                throw;
            }
            catch (Exception)
            {
                RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:70");
                if (this.coordinator.CanCommitTransaction)
                {
                    SqlConnectionManager.Instance.RollbackTransaction();
                }
                throw;
            }
        }
        /// <summary>
        /// Saves the business object.
        /// </summary>
        /// <param name="document"><see cref="WarehouseDocument"/> to save.</param>
        /// <returns>Xml containing result of oper</returns>
        public XDocument SaveBusinessObject(WarehouseDocument document)
        {
            DictionaryMapper.Instance.CheckForChanges();

            //correct the document that comes from client
            this.CorrectDocumentConsistency(document);

            this.ExecuteDocumentOptions(document);

            //validate
            document.Validate();

            //Walidacja zmian w dokumencie realizującym zamówienie sprzedażowe
            document.CheckDoesRealizeClosedSalesOrder(coordinator);

            //load alternate version
            if (!document.IsNew)
            {
                IBusinessObject alternateBusinessObject = this.mapper.LoadBusinessObject(document.BOType, document.Id.Value);
                document.SetAlternateVersion(alternateBusinessObject);
            }

            //update status
            document.UpdateStatus(true);

            if (document.AlternateVersion != null)
            {
                document.AlternateVersion.UpdateStatus(false);
            }

            SqlConnectionManager.Instance.BeginTransaction();

            try
            {
                DictionaryMapper.Instance.CheckForChanges();
                this.mapper.CheckBusinessObjectVersion(document);

                //logika dla automatycznego zamykania ZS w realizacji bezzaliczkowej
                this.coordinator.TryCloseSalesOrdersWhileRealization(document);

                this.coordinator.UpdateStock(document);

                this.ValidationDuringTransaction(document);

                if (document.DocumentStatus == DocumentStatus.Canceled && ConfigurationMapper.Instance.IsWmsEnabled)
                {
                    DependencyContainerManager.Container.Get <WarehouseMapper>().DeleteShiftsForDocument(document.Id.Value);
                }

                if (!document.IsNew && document.DocumentStatus == DocumentStatus.Committed)
                {
                    this.mapper.DeleteIncomeOutcomeRelations(document);
                }

                if (document.DocumentStatus == DocumentStatus.Committed)
                {
                    this.ProcessIncomeOutcome(document);
                }

                DocumentLogicHelper.AssignNumber(document, this.mapper);

                //Make operations list
                XDocument operations = XDocument.Parse("<root/>");

                document.SaveChanges(operations);

                if (document.AlternateVersion != null)
                {
                    document.AlternateVersion.SaveChanges(operations);
                }

                if (operations.Root.HasElements)
                {
                    // this.mapper.UpdateStockForCanceledDocument(document);
                    this.mapper.ExecuteOperations(operations);
                    this.mapper.ValuateOutcomeWarehouseDocument(document);
                    this.mapper.CreateCommunicationXml(document);
                    this.mapper.CreateCommunicationXmlForDocumentRelations(operations);
                    this.mapper.UpdateDictionaryIndex(document);
                }


                Coordinator.LogSaveBusinessObjectOperation();

                document.SaveRelatedObjects();

                operations = XDocument.Parse("<root/>");

                document.SaveRelations(operations);

                if (document.AlternateVersion != null)
                {
                    ((WarehouseDocument)document.AlternateVersion).SaveRelations(operations);
                }

                if (operations.Root.HasElements)
                {
                    this.mapper.ExecuteOperations(operations);
                    this.mapper.CreateCommunicationXmlForDocumentRelations(operations); //generowanie paczek dla relacji dokumentow
                }

                this.mapper.DeleteDocumentAccountingData(document);

                this.mapper.UpdateReservationAndOrderStock(document);

                WarehouseCoordinator.ProcessWarehouseManagamentSystem(document.ShiftTransaction);

                //Custom validation
                this.mapper.ExecuteOnCommitValidationCustomProcedure(document);
                Coordinator.LogSaveBusinessObjectOperation();

                if (document.DraftId != null)
                {
                    this.mapper.DeleteDraft(document.DraftId.Value);
                }

                XDocument returnXml = XDocument.Parse(String.Format(CultureInfo.InvariantCulture, "<root><id>{0}</id></root>", document.Id.ToUpperString()));

                if (this.coordinator.CanCommitTransaction)
                {
                    if (!ConfigurationMapper.Instance.ForceRollbackTransaction)
                    {
                        SqlConnectionManager.Instance.CommitTransaction();
                    }
                    else
                    {
                        SqlConnectionManager.Instance.RollbackTransaction();
                    }
                }

                return(returnXml);
            }
            catch (SqlException sqle)
            {
                RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:80");
                Coordinator.ProcessSqlException(sqle, document.BOType, this.coordinator.CanCommitTransaction);
                throw;
            }
            catch (Exception)
            {
                RoboFramework.Tools.RandomLogHelper.GetLog().Debug("FractusRefactorTraceCatch:81");
                if (this.coordinator.CanCommitTransaction)
                {
                    SqlConnectionManager.Instance.RollbackTransaction();
                }
                throw;
            }
        }