Get Active Ledger from WindowManager

Discussions related to custom development with Select.
Post Reply
kwesterlage
Posts: 73
Joined: Thu May 21, 2015 2:28 pm

Get Active Ledger from WindowManager

Post by kwesterlage »

How to we get to the underlying ledger in a ProTrust active document?

We are using the following code to access the underlying order in a ProForm active document:

Code: Select all

var windowManager = _sp.GetService<IWindowManager>();
var order = windowManager.ActiveDocument?.GetProperty("Order") as IOrder;
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Get Active Ledger from WindowManager

Post by BobRichards »

Using the IOrder to get the ledger where ss is the SelectServer object.

Code: Select all

// Get order guid.
Guid orderGuid = order.Identifier.Guid;

// Get light-weight ledger info object from manager.
ILedgersManager ledMgr = ss.GetService<ILedgersManager>();
ILedgerInfo ledgerInfo = ledMgr.GetLedgerForOrder(orderGuid);

// If you need heavy-weight legder then do this next.
IOrderLedger ledger = (IOrderLedger)lm.GetLedger(ledgerInfo);
Bob Richards, Senior Software Developer, SoftPro
kwesterlage
Posts: 73
Joined: Thu May 21, 2015 2:28 pm

Re: Get Active Ledger from WindowManager

Post by kwesterlage »

Sorry, I should have been more clear with the code snippet.

The ledger is being accessed directly from the ProTrust tab, so we do not have the order.
The included code was meant to be an example of an equivalent operation for the order in the ProForm tab.
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Get Active Ledger from WindowManager

Post by BobRichards »

Include a code snippet for what you do have so I have a starting point for your question.
Bob Richards, Senior Software Developer, SoftPro
kwesterlage
Posts: 73
Joined: Thu May 21, 2015 2:28 pm

Re: Get Active Ledger from WindowManager

Post by kwesterlage »

How about this?

Code: Select all

// From inside a shell package OnInitialize method
// This code will be hit on the initial load and when opening/changing tabs
var manager = GetService<IWindowManager>();
manager.ActiveDocumentChanged += (sender, e) => // Standard event args
{	
	var order = _windowManager.ActiveDocument.GetProperty("Order") as IOrder;
	if (order != null) 
		MessageBox.Show("The selected tab is an order!");

	var ledger = _windowManager.ActiveDocument.GetProperty("Ledger") as ILedger; // this does not work
	if (ledger != null)
		MessageBox.Show("The selected tab is a ledger!");
};	
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Get Active Ledger from WindowManager

Post by BobRichards »

(I originally posted that we don't support this. Then another dev gave me the answer...)

You need to subscribe to the "IWindowManager.ActiveDocumentChanged" event. Then in the handler, you can request properties that are specific to the type of window you are handling. The ledger windows allow you to get the guid for the current ledger.

Code: Select all

IWindowManager wm = GetService<IWindowManager>();
IWindowFrame window = wm.ActiveWindow;
if (window != null)
{
    var prop = window.GetProperty("LedgerId");
    if (prop != null)
    {
        Guid ledgerGuid = (Guid)prop;
        string ledgerName = (string)window.GetProperty("LedgerName");
    }
}
Bob Richards, Senior Software Developer, SoftPro
Post Reply