StrataFrame Forum

Displaying Busines Rules

http://forum.strataframe.net/Topic29958.aspx

By Ger Cannoll - 5/10/2011

In the BusinessRulesChecked event of a Form , I want to call a 'Common' routine which will loop through all Errors on all Business objects and display them in a Message Box. I have the code (from another Thread) whcih loops through All Broken Rule of all business Objects, but dont know how to pass the object to my common routine. (Sometmes when the Broken Rules display, they may be in different tabs on the form and I need to see them all at the same time, rather than searching through each of the Tabs to locate them).

private void MyForm_BusinessRulesChecked(MicroFour.StrataFrame.Business.BusinessRulesCheckedEventArgs e)
{
ShowBusinessRules(????????????XXXXX);
}


Then in my ShowBusinessRules code, I want to loop through the BrokenRules of the BusinessObjects

public static void ShowBusinessRules(?????????YYYY)
{
string myBrokenRules 

//Loop through BrokenRules in each Business Object and add a line to myBrokenRules..... this bit I am ok with
MessageBox.Show(myBrokenRules);
}


Its the ??????????XXXXXX and  ??????YYYYYYYYY I am unsure about

By Greg McGuffey - 5/10/2011

Just pass along the AllBrokenRules dictionary provided by the event args:

private void MyForm_BusinessRulesChecked(MicroFour.StrataFrame.Business.BusinessRulesCheckedEventArgs e)
{
    ShowBusinessRules(e.AllBrokenRules);
}


In your common routine, just accept of a generic dictionary of the appropriate type:

public static void ShowBusinessRules(Dictionary<BusinessLayer, BrokenRuleCollection> allBrokenRules)
{
    string myBrokenRules

    //Loop through BrokenRules in each Business Object and add a line to myBrokenRules.
    foreach(KeyValue<BusinessLayer, BrokenRuleCollection> item in allBrokenRules)
    {
        //-- Build line for broken rule.
    }
    MessageBox.Show(myBrokenRules);
}
By Ger Cannoll - 5/10/2011

Hi Greg. Thanks for reply.

I have inserted your code, but compiler is complaining about the BrokenRuleCollection in the [public void static line] . Do I need a SF reference ?

(I have included using MicroFour.StrataFrame.Business;using MicroFour.StrataFrame.Data;using MicroFour.StrataFrame.MessagingWink

 

By Ger Cannoll - 5/10/2011

Got this working

public static void ShowBrokenRules(Dictionary<BusinessLayer,MicroFour.StrataFrame.Business.BrokenRulesCollection> allBrokenRules)
{
string myBrokenRules = "";
foreach (MicroFour.StrataFrame.Business.BusinessLayer bo in allBrokenRules.Keys)
{
foreach (MicroFour.StrataFrame.Business.BrokenRule br in bo.BrokenRules.ToArray())
{
myBrokenRules = myBrokenRules + br.Description + Environment.NewLine;
}
}
MessageBox.Show(myBrokenRules, "Kernel Software - Invalid Items");
// Why wont following work (brok must take at least one argument ???
MicroFour.StrataFrame.Business.BusinessLayer busobj = new BusinessLayer();
MicroFour.StrataFrame.Business.BrokenRule brok = new BrokenRule();
} // End of ShowBrokenRules




But dont know why the two last lines give an error. I have seen some code on another thread where a version , in VB, similar to this seems to work:

Dim loBO As MicroFour.StrataFrame.Business.BusinessLayer
Dim loRule as MicroFour.Strataframe.Business.BrokenRule
By Greg McGuffey - 5/10/2011

Well a couple of things are likely going on...

First, if you construct a BusinessLayer, there are a bunch of properties that are not actually implemented and intended to implemented by actual BOs (which the BO Mapper takes care of for you). So it quite safe to have variables and arguments of type BusinessLayer, but don't try to just create an object of that type.

Second, there is no blank or default construct for BrokenRule. Check out Intellisense or help to see the valid constructors.

Glad you got the other bit going!