View Communication - Stuck

Topics: CAB & Smart Client Software Factory
Mar 21, 2007 at 9:43 PM
Hi,
I am stuck here.
I have a orders view and order details view.
I have an event published from orders and subscribed by the order details.
But, I am unable to figure out, where should my logic of opening the order details view should be.
The order details should open from button click of orders..
can somebody help me with this with some sample code..
thanx.
Developer
Mar 22, 2007 at 1:31 PM
Hi bsatyen, you are in the right way. The AppraiserWorkbench application (included in SCSF) have a similar scenario.

In your orders presenter you have to publish an event, then when In your View you select an order, you call the presenter and the presenter raise the event with your order as event args. Something like this (from MyAppraisalsViewPresenter):

[EventPublication(EventTopicNames.WorkingAppraisalSelected, PublicationScope.Global)]
public event EventHandler<EventArgs<Appraisal>> WorkingAppraisalSelected;
 
public void AppraisalSelected(Appraisal appraisal)
{
     if (WorkingAppraisalSelected != null)
          WorkingAppraisalSelected(this, new EventArgs<Appraisal>(appraisal));
}

Then in your order details presenter, you subscribe to that event and you take the order from the event args: (From AppraisalDetailViewPresenter)

[EventSubscription(EventTopicNames.WorkingAppraisalSelected, Thread = ThreadOption.UserInterface)]
public void WorkingAppraisalSelectedHandler(object sender, EventArgs<Appraisal> e)
{
     ShowAppraisal(e.Data);
}
 
public void ShowAppraisal(Appraisal appraisal)
{
      …
 
      View.ShowAppraisal(appraisal);
                                               
      …
}

Let me know if this helps,

Ezequiel Jadib
http://staff.southworks.net/blogs/ejadib
Mar 22, 2007 at 3:07 PM
The following are my Orders Presenter and View

ORDERS PRESENTER:
EventPublication(EventTopicNames.OnOrderDetials, PublicationScope.Descendants)
public event EventHandler<EventArgs>OnOrderDetials;

public virtual void OnOrderSelected(string orderNumber)
{
if (OrderSelected != null)
{
OrderSelected(this, new EventArgs<string>(orderNumber) );
}

}

ORDERS VIEW:
private void button1_Click(object sender, EventArgs e)
{
_presenter.OnOrderSelected(listBox1.SelectedItem.ToString());
}

ORDER DETIALS PRESENTER:
EventSubscription(EventTopicNames.OrderSelected, ThreadOption.UserInterface)
public void OnOrderSelected(object sender, EventArgs<string> eventArgs)
{//TODO: Add your code here
Orders details = WorkItem.SmartParts.AddNew<Orders>();
details.UpdateDetails(eventArgs.Data.ToString());
//WorkItem.WorkspacesConstants.WorkspaceNames.RightWorkspace.Show(details);
}

ORDER DETAILS VIEW:
public void UpdateDetails(string orderNo)
{
textBox1.Text = orderNo;
}

Please let me know the missing piece...
Mar 22, 2007 at 4:16 PM
The following are my Orders Presenter and View

ORDERS PRESENTER:
EventPublication(EventTopicNames.OnOrderDetials, PublicationScope.Descendants)
public event EventHandler<EventArgs>OnOrderDetials;

public virtual void OnOrderSelected(string orderNumber)
{
if (OrderSelected != null)
{
OrderSelected(this, new EventArgs<string>(orderNumber) );
}

}

ORDERS VIEW:
private void button1_Click(object sender, EventArgs e)
{
_presenter.OnOrderSelected(listBox1.SelectedItem.ToString());
}

ORDER DETIALS PRESENTER:
EventSubscription(EventTopicNames.OrderSelected, ThreadOption.UserInterface)
public void OnOrderSelected(object sender, EventArgs<string> eventArgs)
{//TODO: Add your code here
Orders details = WorkItem.SmartParts.AddNew<Orders>();
details.UpdateDetails(eventArgs.Data.ToString());
//WorkItem.WorkspacesConstants.WorkspaceNames.RightWorkspace.Show(details);
}

ORDER DETAILS VIEW:
public void UpdateDetails(string orderNo)
{
textBox1.Text = orderNo;
}

Please let me know the missing piece...

Developer
Mar 23, 2007 at 1:30 PM
Hi, try to do this:

Instead of subscribe to the event in the OrderDetailsPresenter, subscribe to the event in your ModuleController like this:

[EventSubscription(EventTopicNames.EditOrder)]
public void OnEditOrder(object sender, EventArgs<Order> e)
{
      ControlledWorkItem<OrderWorkItemController> workitem =
      WorkItem.WorkItems.AddNew<ControlledWorkItem<OrderWorkItemController>>();
      workitem.Controller.Order = e.Data;
      workitem.Controller.Run();
}

Take a look a this example: http://staff.southworks.net/files/folders/3336/download.aspx . This application has an order list, and when you click in the order, you see the details.

Let me know if this helps,
Ezequiel Jadib
http://staff.southworks.net/blogs/ejadib