Page 1 of 1

Form PrintStarting and PrintEnd events

PostPosted: Wed Mar 17, 2021 7:54 pm
by DannyC
Sort of similar to this old post
viewtopic.php?f=26&t=506

I have a client who wants me to somehow record who and when users print some forms - in this case its the Warehouse Transfer Out and In.
Also Purchase Orders.
But my question could apply to several forms.

Basically I intent to simply add an entry to Notes, so in purchase orders, I'd add a notes to the collection. For warehouse transfers I'd just append to the Notes field.

Anyway, the PrintStarting and PrintEnd only has a parameter for the ReportDefinition. How do I get the form and/business logic object(s) so I can do the above?

Re: Form PrintStarting and PrintEnd events  Topic is solved

PostPosted: Wed Mar 17, 2021 9:08 pm
by SBarnes
You are approaching this from the wrong angle if you attach to click event of the ultra toolbars manager which has a signature of

Code: Select all
public virtual void UltraToolbarsManager_ToolClick(object sender, ToolClickEventArgs e)


You then need to check for ID_RecordPrint this is the snippet from Jiwa that does that

Code: Select all
 if ((e.Tool.Owner != null) && (e.Tool.Owner is PopupMenuTool))
            {
                if (((PopupMenuTool) e.Tool.Owner).Key == "ID_RecordPrint")
                {
                    this.PrintRecord(this.ReportDefinitionCollection[e.Tool.Key]);
                }


once you get there you just go after the form with something like this, which is for doing it in the sales order screen

Code: Select all
Infragistics.Win.UltraWinToolbars.UltraToolbarsManager toolbar = (Infragistics.Win.UltraWinToolbars.UltraToolbarsManager)sender;
JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm salesform = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)toolbar.DockWithinContainer;


The once you have the form you can get the object off it like sales order to do your notes.

You could even keep it generic if you wanted to by using the form as JiwaFinancials.Jiwa.JiwaApplication.Maintenance.UserInterface and using its BusinessLogic property and working with the interface JiwaFinancials.Jiwa.JiwaApplication.IJiwaNotes if the businesslogic property was of that type of interface

Re: Form PrintStarting and PrintEnd events

PostPosted: Wed Mar 17, 2021 10:29 pm
by DannyC
Sorted!

Re: Form PrintStarting and PrintEnd events

PostPosted: Thu Mar 18, 2021 2:30 pm
by Mike.Sheen
You could also do this by using a delegate to handle the PrintStarting or PrintEnd events and pass the Form and/or business logic as a parameter.

like so (using the cash book form as an example):

Code: Select all
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{
   if(JiwaForm is JiwaFinancials.Jiwa.JiwaCashBookUI.frmCashBook)
   {
      JiwaFinancials.Jiwa.JiwaCashBookUI.frmCashBook cashBookForm = (JiwaFinancials.Jiwa.JiwaCashBookUI.frmCashBook)JiwaForm;               

      cashBookForm.PrintStarting += delegate(JiwaFinancials.Jiwa.JiwaApplication.PrintGroup.FormReports.ReportDefinition ReportDefinition)
      {
         myPrintStartingHandler(ReportDefinition, cashBookForm);
      };
   }
}

private void myPrintStartingHandler(JiwaFinancials.Jiwa.JiwaApplication.PrintGroup.FormReports.ReportDefinition ReportDefinition, JiwaFinancials.Jiwa.JiwaCashBookUI.frmCashBook cashBookForm)
{
}


This neat little technique is a great way to add effectively additional parameters to event handlers.

The only caveat is that using this technique you cannot remove handlers at runtime - which normally isn't a deal breaker anyway.

Re: Form PrintStarting and PrintEnd events

PostPosted: Thu Mar 18, 2021 4:35 pm
by SBarnes
I didn't think of a delegate but it would work, I usually use them on Jiwa Grid event where I want to get back up to the form and the business logic object but I am yet to come across a situation where I would need to remove one so yes it definitely wouldn't be a deal breaker.

Re: Form PrintStarting and PrintEnd events

PostPosted: Thu Mar 18, 2021 10:12 pm
by DannyC
using a delegate

A delegate! That's exactly what I was looking for.

Anyway, Stuart's idea to hook into the Click event works just as good.