protected virtual void btnSaveRecipe_Clicked(object sender, EventArgs e)
        {
            if (!OperationValidate())
            {
                return;
            }

            if (!OperationDetailsValidate(true))
            {
                return;
            }

            ComplexRecipe recipe;

            using (EditNewComplexRecipe dialog = new EditNewComplexRecipe(new ComplexRecipe(operation))) {
                if (dialog.Run() != ResponseType.Ok)
                {
                    return;
                }

                recipe = dialog.GetRecipe();
            }

            recipe.CommitChanges();

            operation.DetailsMat.Clear();
            operation.DetailsProd.Clear();
            operation.AddRecipe(recipe, GetOperationPriceGroup());
            EditSecondGridField(operation.DetailsProd.Count - 1, colQuantity.Index);
        }
Exemple #2
0
        public static void EditOperation(OperationType type, long id)
        {
            string message;
            bool   readOnlyView;

            if (!BusinessDomain.CanEditOperation(type, id, out message, out readOnlyView) && !readOnlyView)
            {
                if (!string.IsNullOrWhiteSpace(message))
                {
                    MessageError.ShowDialog(message);
                }

                return;
            }

            WbpOperationBase page = null;
            long             invNum;
            bool             allowView = false;

            switch (type)
            {
            case OperationType.Purchase:
                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditDocsDelivery") != UserRestrictionState.Allowed)
                {
                    break;
                }

                invNum = DocumentBase.GetLastDocumentNumber(id, OperationType.Purchase);
                if (invNum <= 0)
                {
                    if (!PresentationDomain.CheckPurchasePricesDisabled())
                    {
                        page = new WbpPurchase(id);
                    }
                }
                else
                {
                    ShowMessageHasInvoice(Purchase.GetById(id), invNum, "Icons.Purchase16.png", out allowView);
                    if (allowView)
                    {
                        page = new WbpPurchase(id);
                    }
                }
                break;

            case OperationType.Sale:
                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditDocsSale") != UserRestrictionState.Allowed)
                {
                    break;
                }

                invNum = DocumentBase.GetLastDocumentNumber(id, OperationType.Sale);
                if (invNum <= 0)
                {
                    page = new WbpSale(id);
                }
                else
                {
                    ShowMessageHasInvoice(Sale.GetById(id), invNum, "Icons.Sale16.png", out allowView);
                    if (allowView)
                    {
                        page = new WbpSale(id);
                    }
                }
                break;

            case OperationType.Waste:
                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditDocsWaste") != UserRestrictionState.Allowed)
                {
                    break;
                }

                page = new WbpWaste(id);
                break;

            case OperationType.StockTaking:
                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditDocsRevision") != UserRestrictionState.Allowed)
                {
                    break;
                }

                if (!StockTaking.GetById(id).CheckIsNewFormat())
                {
                    break;
                }

                page = new WbpStockTaking(id);
                break;

            case OperationType.TransferIn:
            case OperationType.TransferOut:
                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditDocsTransfer") != UserRestrictionState.Allowed)
                {
                    break;
                }

                page = new WbpTransfer(id);
                break;

            case OperationType.ComplexRecipeMaterial:
            case OperationType.ComplexRecipeProduct:
                if (BusinessDomain.RestrictionTree.GetRestriction("mnuOperProductionComplexRecipes") != UserRestrictionState.Allowed)
                {
                    break;
                }

                if (!PresentationDomain.CheckPurchasePricesDisabled())
                {
                    using (EditNewComplexRecipe dlgRecipe = new EditNewComplexRecipe(ComplexRecipe.GetById(id)))
                        dlgRecipe.Run();
                }
                break;

            case OperationType.ComplexProductionMaterial:
            case OperationType.ComplexProductionProduct:
                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditDocsComplexProduction") != UserRestrictionState.Allowed)
                {
                    break;
                }

                if (!PresentationDomain.CheckPurchasePricesDisabled())
                {
                    page = new WbpProduction(id);
                }
                break;

            default:
                if (operationEditors == null)
                {
                    operationEditors = new List <IOperationEditor> ();
                    foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes("/Warehouse/Presentation/OperationEditor"))
                    {
                        IOperationEditor editor = node.CreateInstance() as IOperationEditor;
                        if (editor != null)
                        {
                            operationEditors.Add(editor);
                        }
                    }
                }

                foreach (IOperationEditor editor in operationEditors)
                {
                    if (editor.SupportedType != type)
                    {
                        continue;
                    }

                    page = editor.GetEditorPage(id);
                    break;
                }
                break;
            }

            if (page == null)
            {
                return;
            }

            if (readOnlyView || allowView)
            {
                page.SetReadOnly();
            }

            PresentationDomain.MainForm.AddNewPage(page);
        }