private void btnPrint_Clicked(object sender, EventArgs e) { Report report = visualizer.GetPrintData(Title); report.SetName(string.Format("{0} - {1}", Title, Translator.GetString("Document"))); FormHelper.PrintPreviewObject(report); }
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 waste"), string.Empty, Translator.GetString("Do you want to save the changes?"), "Icons.Question32.png"); } else { dialogSave = new MessageOkCancel( Translator.GetString("Saving waste"), 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; } } 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 waste 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 waste operation!"), ErrorSeverity.Error, ex); return; } if (printReceipt && WaitForPendingOperationCompletion()) { try { WasteProtocol protocol = new WasteProtocol(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); } }
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); } }