Generic Browse Dialog


Author
Message
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Greg. I took your advice and have set up two projects to come as close as possible to the live project I was working on. The first project is just a BO Library with the Customer and Product tables from the SF sample database (in TEST_BOLibrary folder). The second is a very basic SF maintnance screen  project (TEST_APP) , and on it I have a button with just a few lines of code ....still getting the problem with GetType.

On the maintanance Form, I have referenced the BO Library and the cusotmer table is displaying fine on the Maintanance screen but the reflection bit still not working

I would appreciate it if you could take a look..

Attachments
Testing_reflection.zip (72 views, 144.00 KB)
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I'll take a look at this either later today or tomorrow.
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi. just wondering if this has dropped off the radar ??
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Ah...oops. I'll take a look at it today. Sorry for the delay.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
You were really, really close. BigGrin



You had done two things not quite right.

1. When you looked up the type, you used Type.GetType(). If you use this you have to supply a fully qualified name, including assembly info. A pain. Instead use the SF helper function GetTypeFromReferencedAssemblies().

2. You didn't cast the object returned by Actvator.CreateInstance to be a BusinessLayer.



Here is the complete code for the form.



namespace Test_APP

{

  public partial class CustForm : MicroFour.StrataFrame.UI.Windows.Forms.StandardForm

  {

    public CustForm()

    {

      InitializeComponent();

    }



    private void button1_Click( object sender, EventArgs e )

    {

      string boString = "TEST_BOLibrary.SFCustBO";

      MicroFour.StrataFrame.Business.BusinessLayer bo = null;



      //-- Use GetTypeFromReferencedAssemblies because BO is in different assembly than form.

      //-- Wrong --> Type oType = Type.GetType( boString); can't find type in current assembly.

      Type oType = MicroFour.StrataFrame.Tools.Common.GetTypeFromReferencedAssemblies( boString );



      //-- Need to cast object returned by Activator.CreateInstance to a BusinessLayer

      //-- Wrong --> bo = Activator.CreateInstance(oType); Type mismatch as CreateInstance returns an object.

      bo = (MicroFour.StrataFrame.Business.BusinessLayer)Activator.CreateInstance( oType );



      //-- Just access the BO to ensure that it got created.

      MessageBox.Show( string.Format( "Number of records in bo: {0}", bo.Count ) );

    }



    private void sfCustBO1_ParentFormLoading_1()

    {

      //-- I changed this to load just the top 100 records...faster for testing.

      this.sfCustBO1.FillTopN( 100 );

    }

  }

}




In the code above you'll see a reference to the FillTopN method on SFCustBO. I added this instead of the fill all just to speed up loading (yeah, I can be impatient Wink )



//-- In SFCustBO

public void FillTopN( int numberToFill )

{

  this.FillDataTable( string.Format( "Select Top {0} * From {1}", numberToFill, this.TableName ) );

}


Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Thanks for that Greg. I feel I am making  progress now. I am at the stage where I have (using Reflection) created the Buiness Object and the Browse Dialog, but am unsure of the next steps. I am getting an error at Step 10 below(Object reference not set to an instance of an object) which is probably because I have left out a few steps. I am not sure how to progress from Step4 below to Step 10. At this stage, say I have just one or two columns to include in the browse. When manually inputting the properties on the Browse Dialog, there just seems to be a)BrowseResultsLayout  b)FormLayout  c)SearchFields which need to be populated. Is this the same if I am programatically creating the controls? Some pointers as to what I am missing below would be very helpful.

// ---- Assign Strings (There will be taken in as Parameters when its all working
string boString;
string selectString;
boString = "Kernel_BOLibrary.SmaBO";
selectString = "Select * from SMA";

// --- 1. Setup the Business Object
MicroFour.StrataFrame.Business.BusinessLayer bo = null;
Type oType = MicroFour.StrataFrame.Tools.Common.GetTypeFromReferencedAssemblies(boString);
bo = (MicroFour.StrataFrame.Business.BusinessLayer)Activator.CreateInstance(oType);
string boName;
boName = bo.CurrentDataTable.ToString();
bo.FillDataTable(selectString);
MessageBox.Show("No of records in BO" + " " + boName + " " + bo.Count);

// --- 2. Set up a Generic Browse Dialog
string bdString;
bdString = "MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialog";
MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialog bd = null;
Type oBDType = MicroFour.StrataFrame.Tools.Common.GetTypeFromReferencedAssemblies(bdString);
bd = (MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialog)Activator.CreateInstance(oBDType);

// --- 3. Start assigning properties for the generic BrowseDialog
bd.BusinessObjectToPopulate = bo;
bd.BusinessObjectType = oType.ToString();

// --- 4. Create the columns.... in live class, I will need to paramterise this....can I just loop around or do I need reflection here again ??
MicroFour.StrataFrame.UI.Windows.Forms.BrowseColumnItem bdCol01 = new MicroFour.StrataFrame.UI.Windows.Forms.BrowseColumnItem();
bdCol01.ColumnHeaderText = "Col1 header";
bd.BrowseResultsLayout.BrowseColumns.Add(bdCol01);

// --- 5. Create the setting ....do I need this
MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialogLayoutSettings bdSett1 = new MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialogLayoutSettings();

// --- 10. Call up the Browse Dialog
bd.ShowDialog(true);


Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Just wondering...any thoughts on this ?? 
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
If you decide to go this route, and configure the BrowseDialog in code (rather than creating a subclass that is already configured)

you don't need to use reflection...you know it is going to be a BrowseDialog...

// --- 2. Set up a Generic Browse Dialog

MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialog bd = new MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialog();




To configure the BrowseDialog, the easiest is to just look at the designer file of subclassed BrowseDialogs. You can see what code you need and what sort of data you'll need to parametrize. E.g. take a look at the Customers and orders BDs in the sample.
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)Advanced StrataFrame User (630 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
I have changed the code now, and am getting the browse dialog screen up ok. However, when I enter any data in the Search Box, and click Search, I get an error up: ---> The Given Key was not present in the dictionary  <---  Error screen  is attached. I have more or less copied the customerBO in the samples you sent on the Generic Browse. My Code is:

// ---- Assign Strings (There will be taken in as Parameters when its all working
string boString
string selectString;
boString = "Kernel_BOLibrary.SmaBO";
selectString = "Select * from SMA";


// --- 1. Setup the Business Object using reflection as it can be ANY business Object and we dont know whcih one
MicroFour.StrataFrame.Business.BusinessLayer bo = null;
Type oType = MicroFour.StrataFrame.Tools.Common.GetTypeFromReferencedAssemblies(boString);
bo = (MicroFour.StrataFrame.Business.BusinessLayer)Activator.CreateInstance(oType);
string boName;
boName = bo.CurrentDataTable.ToString();
bo.FillDataTable(selectString);
MessageBox.Show("No of records in BO" + " " + boName + " " + bo.Count);


// --- 2. Set up a Generic Browse Dialog
MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialog bd = new MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialog();
// --- 3. Start assigning properties for the generic BrowseDialog
bd.BusinessObjectToPopulate = bo;
bd.BusinessObjectType = "SmaBO";
bd.ViewResultsAsLedgerCard = true;


// --- 4a. Create the columns.... in live class, I will need to paramterise this....can I just loop around or do I need reflection here again ??
MicroFour.StrataFrame.UI.Windows.Forms.BrowseColumnItem bdCol01 = new MicroFour.StrataFrame.UI.Windows.Forms.BrowseColumnItem();
bdCol01.ColumnHeaderText = "Name";
bdCol01.ColumnHeaderWidth = 200;
bdCol01.ColumnTextAlignment = System.Windows.Forms.HorizontalAlignment.Left;
bdCol01.DefaultSort = System.Windows.Forms.SortOrder.None;
bdCol01.FormatString = "{0}";
bdCol01.PopulationType = MicroFour.StrataFrame.UI.ListViewColumnPopulationType.FormattedString;
bdCol01.RegExPattern = "";
bdCol01.RegExReplacementValue = "";
// --- Add Columns to BrowseColumns Colllection
// xxxx bd.BrowseResultsLayout.BrowseColumns.Add(bdCol01);


// --- 5. Create the BrowseResultsPopulationSettings
MicroFour.StrataFrame.UI.Windows.Forms.BrowseResultsPopulationSettings br = new MicroFour.StrataFrame.UI.Windows.Forms.BrowseResultsPopulationSettings();
br.DisplayFieldNames.Add("Sma_name");
br.BrowseColumns.Add(bdCol01);


// --- 6. Create Search Fields
MicroFour.StrataFrame.UI.Windows.Forms.SearchFieldItem SearchFieldItem1 = new MicroFour.StrataFrame.UI.Windows.Forms.SearchFieldItem();
SearchFieldItem1.AllowAdvanced = true;
SearchFieldItem1.DefaultSearchStyle = MicroFour.StrataFrame.UI.BrowseDialogAllSearchTypes.BeginsWith;
SearchFieldItem1.EnumType = "";
SearchFieldItem1.FieldLabelText = "Name";
SearchFieldItem1.FieldMask = "";
SearchFieldItem1.FieldName = "Sma_name";
SearchFieldItem1.FieldType = System.Data.DbType.AnsiString;
SearchFieldItem1.IgnoreInitialValueIfNotVisible = true;
SearchFieldItem1.InitiallyEnabled = true;
SearchFieldItem1.InitialValue = "";
SearchFieldItem1.Key = "Sma_name";
SearchFieldItem1.OverrideFieldType = false;
SearchFieldItem1.PopulationDataSourceSettings = null;
SearchFieldItem1.SecurityKey = "";
SearchFieldItem1.TextMaskFormat = System.Windows.Forms.MaskFormat.ExcludePromptAndLiterals;
SearchFieldItem1.TimeAction = MicroFour.StrataFrame.UI.BrowseDialogDateTimeAction.DoNotChangeTime;
SearchFieldItem1.TopMostText = "<Not Used>";
SearchFieldItem1.TopMostValue = "-1";
SearchFieldItem1.Visible = true;


// --- 7. Add SearchField to SearchFields collection
bd.SearchFields.Add(SearchFieldItem1);
bd.BrowseResultsLayout = br;


// --- 10. Call up the Browse Dialog
bd.ShowDialog(true);





Attachments
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Check that you set the FieldType correctly. This must match the type of defined in the BO for the field. Look in the BO designer file, in the shared/static constructor for the definition of the _FieldDbTypes values.  This is the line of code that likely is causing the issue:

SearchFieldItem1.FieldType = System.Data.DbType.AnsiString;

Likely the type is DbType.String.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search