public override void OnOperationSave(bool askForConfirmation)
        {
            #region Prepare the purchase object

            if (!OperationValidate())
            {
                return;
            }

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

            #endregion

            if (!TryApplyRules())
            {
                return;
            }

            bool printPayment;
            using (EditNewPayment dialogFinalize = new EditNewPayment(operation)) {
                if (dialogFinalize.Run() != ResponseType.Ok)
                {
                    ClearDetailsFromPriceRules(true);
                    return;
                }
                printPayment = dialogFinalize.PrintDocument;
            }

            if (!PriceRule.ApplyOnPaymentSet(operation))
            {
                return;
            }

            try {
                var newPayments = GetAllNewPayments(printPayment);
                PrepareOpertionForSaving();
                CommitOperation();
                PrintAllNewPayments(newPayments);
            } catch (InsufficientItemAvailabilityException ex) {
                MessageError.ShowDialog(string.Format(Translator.GetString("The purchase cannot be saved due to insufficient quantities of item \"{0}\"."), ex.ItemName),
                                        ErrorSeverity.Warning, ex);
                ClearDetailsFromPriceRules();
                EditGridField(ex.ItemName);
                return;
            } catch (Exception ex) {
                MessageError.ShowDialog(Translator.GetString("An error occurred while saving purchase document!"),
                                        ErrorSeverity.Error, ex);
                ClearDetailsFromPriceRules(true);
                return;
            }

            ApplyFinalPriceRules();

            if (BusinessDomain.AppConfiguration.AutoCreateInvoiceOnPurchase && !editMode &&
                WaitForPendingOperationCompletion())
            {
                using (EditNewInvoice dlgInvoice = new EditNewInvoice(operation))
                    dlgInvoice.Run();
            }

            #region Ask to print a document

            bool printReceipt = false;

            if (BusinessDomain.AppConfiguration.IsPrintingAvailable() && BusinessDomain.WorkflowManager.AllowPurchaseReceiptPrint(operation, false))
            {
                if (BusinessDomain.AppConfiguration.AskBeforeDocumentPrint == AskDialogState.NotSaved)
                {
                    using (MessageYesNoRemember dialogPrint = new MessageYesNoRemember(
                               Translator.GetString("Print document"), string.Empty,
                               Translator.GetString("Do you want to print a stock receipt?"), "Icons.Question32.png")) {
                        ResponseType resp = dialogPrint.Run();
                        if (resp == ResponseType.Yes)
                        {
                            printReceipt = true;
                        }

                        if (dialogPrint.RememberChoice)
                        {
                            BusinessDomain.AppConfiguration.AskBeforeDocumentPrint = resp == ResponseType.Yes ? AskDialogState.Yes : AskDialogState.No;
                        }
                    }
                }
                else if (BusinessDomain.AppConfiguration.AskBeforeDocumentPrint == AskDialogState.Yes)
                {
                    printReceipt = true;
                }
            }

            if (printReceipt && WaitForPendingOperationCompletion())
            {
                try {
                    PurchaseReceipt receipt = new PurchaseReceipt(operation);
                    FormHelper.PrintPreviewObject(receipt);
                } catch (Exception ex) {
                    MessageError.ShowDialog(
                        Translator.GetString("An error occurred while generating stock receipt!"),
                        ErrorSeverity.Error, ex);
                }
            }

            #endregion

            OnOperationSaved();

            if (editMode)
            {
                OnPageClose();
            }
            else
            {
                ReInitializeForm(null);
            }
        }
        public override void OnOperationSave(bool askForConfirmation)
        {
            bool printReceipt = false;

            if (!OperationValidate())
            {
                return;
            }

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

            if (askForConfirmation)
            {
                MessageOkCancel dialogSave;
                if (editMode)
                {
                    dialogSave = new MessageOkCancel(
                        Translator.GetString("Edit Production"), string.Empty,
                        Translator.GetString("Do you want to save the changes?"), "Icons.Question32.png");
                }
                else
                {
                    dialogSave = new MessageOkCancel(
                        Translator.GetString("Saving production"), string.Empty,
                        Translator.GetString("Do you want to save the operation?"), "Icons.Question32.png");
                }

                if (dialogSave.Run() != ResponseType.Ok)
                {
                    operation.AddNewDetail();
                    EditGridField(operation.DetailsMat.Count - 1, colItem.Index);
                    return;
                }
            }

            if (BusinessDomain.AppConfiguration.IsPrintingAvailable())
            {
                if (BusinessDomain.AppConfiguration.AskBeforeDocumentPrint == AskDialogState.NotSaved)
                {
                    using (MessageYesNoRemember dialogPrint = new MessageYesNoRemember(
                               Translator.GetString("Print document"), string.Empty,
                               Translator.GetString("Do you want to print a document?"), "Icons.Question32.png")) {
                        ResponseType resp = dialogPrint.Run();
                        if (resp == ResponseType.Yes)
                        {
                            printReceipt = true;
                        }

                        if (dialogPrint.RememberChoice)
                        {
                            BusinessDomain.AppConfiguration.AskBeforeDocumentPrint = resp == ResponseType.Yes ? AskDialogState.Yes : AskDialogState.No;
                        }
                    }
                }
                else if (BusinessDomain.AppConfiguration.AskBeforeDocumentPrint == AskDialogState.Yes)
                {
                    printReceipt = true;
                }
            }

            try {
                PrepareOpertionForSaving();
                CommitOperation();
            } catch (InsufficientItemAvailabilityException ex) {
                MessageError.ShowDialog(
                    string.Format(Translator.GetString("The production cannot be saved due to insufficient quantity of item \"{0}\"."), ex.ItemName),
                    ErrorSeverity.Warning, ex);

                for (int i = 0; i < operation.Details.Count; i++)
                {
                    if (operation.Details [i].ItemName != ex.ItemName)
                    {
                        continue;
                    }

                    EditGridField(i, operation.DetailsMat [i].SourceRecipe != null ? colQuantity.Index : colItem.Index);
                    break;
                }
                return;
            } catch (Exception ex) {
                MessageError.ShowDialog(
                    Translator.GetString("An error occurred while saving the production operation!"),
                    ErrorSeverity.Error, ex);
                return;
            }

            if (printReceipt && WaitForPendingOperationCompletion())
            {
                try {
                    ProductionProtocol protocol = new ProductionProtocol(operation);
                    FormHelper.PrintPreviewObject(protocol);
                } catch (Exception ex) {
                    MessageError.ShowDialog(
                        Translator.GetString("An error occurred while generating the protocol!"),
                        ErrorSeverity.Error, ex);
                }
            }

            OnOperationSaved();

            if (editMode)
            {
                OnPageClose();
            }
            else
            {
                ReInitializeForm(null);
            }
        }
Example #3
0
        public override void OnOperationSave(bool askForConfirmation)
        {
            #region Prepare the stock-taking object

            if (!OperationValidate())
            {
                return;
            }

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

            #endregion

            #region Ask to save the stock-taking

            bool printPayment = false;
            if (operation.TotalPlusVAT > 0)
            {
                using (EditNewPayment dialogFinalize = new EditNewPayment(operation)) {
                    if (dialogFinalize.Run() != ResponseType.Ok)
                    {
                        operation.AddNewDetail();
                        EditGridField(operation.Details.Count - 1, colItem.Index);
                        return;
                    }
                    printPayment = dialogFinalize.PrintDocument;
                }
            }
            else if (askForConfirmation)
            {
                MessageOkCancel dialogSave;
                if (editMode)
                {
                    dialogSave = new MessageOkCancel(
                        Translator.GetString("Edit Stock-taking"), string.Empty,
                        Translator.GetString("Do you want to save the changes?"), "Icons.Question32.png");
                }
                else
                {
                    dialogSave = new MessageOkCancel(
                        Translator.GetString("Saving Stock-taking"), string.Empty,
                        Translator.GetString("Do you want to save the operation?"), "Icons.Question32.png");
                }

                if (dialogSave.Run() != ResponseType.Ok)
                {
                    operation.AddNewDetail();
                    EditGridField(operation.Details.Count - 1, colItem.Index);
                    return;
                }
            }

            #endregion

            #region Ask to print a document

            bool printProtocol = false;

            if (BusinessDomain.AppConfiguration.IsPrintingAvailable())
            {
                if (BusinessDomain.AppConfiguration.AskBeforeDocumentPrint == AskDialogState.NotSaved)
                {
                    using (MessageYesNoRemember dialogPrint = new MessageYesNoRemember(
                               Translator.GetString("Print document"), string.Empty,
                               Translator.GetString("Do you want to print a document?"), "Icons.Question32.png")) {
                        ResponseType resp = dialogPrint.Run();
                        if (resp == ResponseType.Yes)
                        {
                            printProtocol = true;
                        }

                        if (dialogPrint.RememberChoice)
                        {
                            BusinessDomain.AppConfiguration.AskBeforeDocumentPrint = resp == ResponseType.Yes ? AskDialogState.Yes : AskDialogState.No;
                        }
                    }
                }
                else if (BusinessDomain.AppConfiguration.AskBeforeDocumentPrint == AskDialogState.Yes)
                {
                    printProtocol = true;
                }
            }

            #endregion

            try {
                List <Payment> newPayments = null;
                if (operation.TotalPlusVAT > 0)
                {
                    newPayments = GetAllNewPayments(printPayment);
                }

                PrepareOpertionForSaving();
                CommitOperation();
                if (operation.TotalPlusVAT > 0)
                {
                    PrintAllNewPayments(newPayments);
                }
            } catch (InsufficientItemAvailabilityException ex) {
                MessageError.ShowDialog(
                    string.Format(Translator.GetString("The stock-taking cannot be saved due to insufficient quantity of item \"{0}\"."), ex.ItemName),
                    ErrorSeverity.Warning, ex);

                EditGridField(ex.ItemName);
                return;
            } catch (Exception ex) {
                MessageError.ShowDialog(
                    Translator.GetString("An error occurred while saving the stock-taking operation!"),
                    ErrorSeverity.Error, ex);
                return;
            }

            if (printProtocol)
            {
                if (!WaitForPendingOperationCompletion())
                {
                    return;
                }

                try {
                    StockTakingProtocol protocol = new StockTakingProtocol(operation);
                    FormHelper.PrintPreviewObject(protocol);
                } catch (Exception ex) {
                    MessageError.ShowDialog(
                        Translator.GetString("An error occurred while generating the protocol!"),
                        ErrorSeverity.Error, ex);
                }
            }

            OnOperationSaved();

            if (editMode)
            {
                OnPageClose();
            }
            else
            {
                ReInitializeForm(null);
            }
        }
 protected virtual void btnExport_Clicked(object sender, EventArgs e)
 {
     FormHelper.ExportDocument(document, portrait);
 }
 protected virtual GtkFormPrintDocument GetPrintDocument()
 {
     return(new GtkFormPrintDocument(FormHelper.LoadForm(document)));
 }
        public static void OpenEntityForEdit(SourceItemId entity)
        {
            object id;
            long   intId;
            object type;

            switch (entity.Table)
            {
            case DbTable.Unknown:
                break;

            case DbTable.ApplicationLog:
                break;

            case DbTable.Cashbook:
                break;

            case DbTable.Configuration:
                break;

            case DbTable.Currencies:
                break;

            case DbTable.CurrenciesHistory:
                break;

            case DbTable.Documents:
                id   = entity [DataField.DocumentOperationNumber];
                type = entity [DataField.DocumentType];
                if (type == null)
                {
                    break;
                }

                try {
                    type  = Enum.ToObject(typeof(OperationType), type);
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                FormHelper.EditOperation((OperationType)type, intId);
                break;

            case DbTable.EcrReceipts:
                break;

            case DbTable.Items:
                id = entity [DataField.ItemId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditGoodsbtnEdit") != UserRestrictionState.Allowed)
                {
                    break;
                }

                using (EditNewItem dialog = new EditNewItem(Item.GetById(intId)))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetItem().CommitChanges();
                    }
                break;

            case DbTable.ItemsGroups:
                id = entity [DataField.ItemGroupId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditGoodsbtnEdit") != UserRestrictionState.Allowed)
                {
                    break;
                }

                using (EditNewGroup <ItemsGroup> dialog = new EditNewGroup <ItemsGroup> (ItemsGroup.GetById(intId), ItemsGroup.GetAll()))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetGroup().CommitChanges();
                    }
                break;

            case DbTable.InternalLog:
                break;

            case DbTable.Lots:
                break;

            case DbTable.Network:
                break;

            case DbTable.NextAcct:
                break;

            case DbTable.Objects:
                id = entity [DataField.LocationId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditObjectsbtnEdit") != UserRestrictionState.Allowed)
                {
                    break;
                }

                using (EditNewLocation dialog = new EditNewLocation(Location.GetById(intId)))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetLocation().CommitChanges();
                    }
                break;

            case DbTable.ObjectsGroups:
                id = entity [DataField.LocationsGroupsId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditObjectsbtnEdit") != UserRestrictionState.Allowed)
                {
                    break;
                }

                using (EditNewGroup <LocationsGroup> dialog = new EditNewGroup <LocationsGroup> (LocationsGroup.GetById(intId), LocationsGroup.GetAll()))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetGroup().CommitChanges();
                    }
                break;

            case DbTable.Operations:
                type = entity [DataField.OperationType];
                if (type == null)
                {
                    break;
                }

                id = entity [DataField.OperationNumber];
                try {
                    type  = Enum.ToObject(typeof(OperationType), type);
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                FormHelper.EditOperation((OperationType)type, intId);
                break;

            case DbTable.OperationDetails:
                break;

            case DbTable.OperationType:
                break;

            case DbTable.Partners:
                id = entity [DataField.PartnerId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditPartnersbtnEdit") != UserRestrictionState.Allowed)
                {
                    break;
                }

                using (EditNewPartner dialog = new EditNewPartner(Partner.GetById(intId)))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetPartner().CommitChanges();
                    }
                break;

            case DbTable.PartnersGroups:
                id = entity [DataField.PartnersGroupsId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditPartnersbtnEdit") != UserRestrictionState.Allowed)
                {
                    break;
                }

                using (EditNewGroup <PartnersGroup> dialog = new EditNewGroup <PartnersGroup> (PartnersGroup.GetById(intId), PartnersGroup.GetAll()))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetGroup().CommitChanges();
                    }
                break;

            case DbTable.Payments:
                type = entity [DataField.PaymentOperationType];
                if (type == null)
                {
                    break;
                }

                id = entity [DataField.PaymentOperationId];
                try {
                    type  = Enum.ToObject(typeof(OperationType), type);
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditPaysPaymentsbtnEdit") != UserRestrictionState.Allowed)
                {
                    break;
                }

                Operation oper = Operation.GetById((OperationType)type, intId);
                if (oper == null)
                {
                    break;
                }

                using (EditNewPayment dialog = new EditNewPayment(oper))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            oper.CommitPayments();
                    }
                break;

            case DbTable.PaymentTypes:
                id = entity [DataField.PaymentTypesId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                using (EditNewPaymentType dialog = new EditNewPaymentType(PaymentType.GetById(intId)))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetPaymentType().CommitChanges();
                    }
                break;

            case DbTable.PriceRules:
                break;

            case DbTable.Registration:
                break;

            case DbTable.Store:
                break;

            case DbTable.System:
                break;

            case DbTable.Transformations:
                break;

            case DbTable.Users:
                EditUser(entity [DataField.UserId]);
                break;

            case DbTable.OperationUsers:
                EditUser(entity [DataField.OperationsUserId]);
                break;

            case DbTable.OperationOperators:
                EditUser(entity [DataField.OperationsOperatorId]);
                break;

            case DbTable.UsersGroup:
                EditUserGroup(entity [DataField.UsersGroupsId]);
                break;

            case DbTable.OperationUsersGroup:
                EditUserGroup(entity [DataField.OperationsUsersGroupsId]);
                break;

            case DbTable.OperationOperatorsGroup:
                EditUserGroup(entity [DataField.OperationsOperatorsGroupsId]);
                break;

            case DbTable.UsersSecurity:
                break;

            case DbTable.VatGroups:
                id = entity [DataField.VATGroupId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditVATGroupsbtnEdit") != UserRestrictionState.Allowed)
                {
                    return;
                }

                using (EditNewVATGroup dialog = new EditNewVATGroup(VATGroup.GetById(intId)))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetVATGroup().CommitChanges();
                    }
                break;
            }
        }
Example #7
0
 private void btnExport_Clicked(object sender, EventArgs e)
 {
     FormHelper.ExportData("report", ReportTypeName ?? title, visualizer.GetExportData(title));
 }