public override void Commit()
        {
            bool editMode = true;

            using (DbTransaction transaction = new DbTransaction(BusinessDomain.DataAccessProvider)) {
                transaction.SnapshotObject(this);
                if (BusinessDomain.AppConfiguration.AutoProduction)
                {
                    if (AutomaticProduction())
                    {
                        RecalculatePrices();
                    }
                }

                // Create a new operation Id if needed);
                OperationState operationState = State;
                if (operationState == OperationState.New || operationState == OperationState.NewDraft || operationState == OperationState.NewPending)
                {
                    id       = CreateNewId();
                    editMode = false;

                    if (BusinessDomain.AppConfiguration.ItemsManagementUseLots)
                    {
                        foreach (ComplexProductionDetail detail in DetailsProd)
                        {
                            if (detail.ProductionDate == null)
                            {
                                detail.ProductionDate = Date;
                            }
                        }
                    }
                }

                LotsEvaluate(DetailsMat);

                // Save the output ComplexProduction in the database
                OperationType = OperationType.ComplexProductionMaterial;
                foreach (ComplexProductionDetail detail in DetailsMat)
                {
                    detail.ReferenceDocumentId = id;
                    detail.ResetSign(-1);
                }
                BusinessDomain.DataAccessProvider.AddUpdateComplexProductionMat(this, DetailsMat.ToArray(), BusinessDomain.AppConfiguration.AllowNegativeAvailability);

                // Save the input ComplexProduction in the database
                OperationType = OperationType.ComplexProductionProduct;
                foreach (ComplexProductionDetail detail in DetailsProd)
                {
                    detail.ReferenceDocumentId = id;
                    detail.ResetSign(1);
                }
                BusinessDomain.DataAccessProvider.AddUpdateComplexProductionProd(this, DetailsProd.ToArray(), BusinessDomain.AppConfiguration.AllowNegativeAvailability);
                Item.Cache.Clear(DetailsProd.Select(d => d.ItemId));

                if (editMode && Total.IsZero())
                {
                    BusinessDomain.DataAccessProvider.DeleteOperationId(OperationType.ComplexProductionMaterial, id);

                    ApplicationLogEntry.AddNew(string.Format(Translator.GetString("Void production No.{0} from {1}"), GetFormattedOperationNumber(id), BusinessDomain.GetFormattedDate(date)));
                }
                else if (editMode)
                {
                    ApplicationLogEntry.AddNew(string.Format(Translator.GetString("Edit production No.{0} from {1}"), GetFormattedOperationNumber(id), BusinessDomain.GetFormattedDate(date)));
                }

                if (editMode)
                {
                    RemoveAllEmptyDetails();
                }

                transaction.Complete();
            }
        }
Ejemplo n.º 2
0
        public ComplexRecipe CommitChanges()
        {
            bool editMode = true;

            try {
                using (DbTransaction transaction = new DbTransaction(BusinessDomain.DataAccessProvider)) {
                    // Create a new operation Id if needed
                    if (State == OperationState.New || State == OperationState.NewDraft)
                    {
                        id       = CreateNewId();
                        editMode = false;
                    }

                    // Save the output ComplexRecipe in the database
                    OperationType = OperationType.ComplexRecipeMaterial;
                    foreach (ComplexRecipeDetail detail in DetailsMat)
                    {
                        detail.Note = name;
                    }
                    BusinessDomain.DataAccessProvider.AddUpdateComplexRecipeMat(this, DetailsMat.ToArray());

                    // Save the input ComplexRecipe in the database
                    OperationType = OperationType.ComplexRecipeProduct;
                    foreach (ComplexRecipeDetail detail in DetailsProd)
                    {
                        detail.Note = name;
                    }
                    BusinessDomain.DataAccessProvider.AddUpdateComplexRecipeProd(this, DetailsProd.ToArray());

                    if (editMode && Total.IsZero())
                    {
                        BusinessDomain.DataAccessProvider.DeleteOperationId(OperationType.ComplexRecipeMaterial, id);

                        string format = Translator.GetString("Void recipe No.{0} from {1}");
                        ApplicationLogEntry.AddNew(string.Format(format, GetFormattedOperationNumber(id),
                                                                 BusinessDomain.GetFormattedDate(date)));
                    }
                    else if (editMode)
                    {
                        string format = Translator.GetString("Edit recipe No.{0} from {1}");
                        ApplicationLogEntry.AddNew(string.Format(format, GetFormattedOperationNumber(id),
                                                                 BusinessDomain.GetFormattedDate(date)));
                    }

                    if (editMode)
                    {
                        RemoveAllEmptyDetails();
                    }

                    transaction.Complete();
                }
            } catch {
                if (!editMode)
                {
                    id = -1;
                }

                throw;
            }

            return(this);
        }