StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Field sizesExpand / Collapse
Author
Message
Posted 03/01/2007 2:40:25 PM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: Forum Members
Last Login: 04/11/2007 8:30:06 AM
Posts: 99, Visits: 253
This is more out of curiosity but also lends itself to efficiency.  When creating the BO's using the Business Object Mapper, shouldn't there be some way of creating a property with MaximumSize?  This way when creating the UI, I do not have to keep referring to our SQL Schema to find out the size of each field.  We have over 540 tables in our schema, more tables and fields being added by the DBA frequently so I cannot keep track of the sizes in my head.

So whether the field should accept 1 character or 5,000, it would be easier to type:

MyTextField.MaximumSize = Me.MyBO1.Field.MaximumSize - or if you look at my enhancement idea for an automatic screen builder wizard, this metadata could be used to set the property automagically.

You have the data in the DDT and even if you directly import into the BOM, all you need is an additional MaxSize field listed here to support this feature. 

So, out of curiosity, is this something that "might" be supported in the future?

Ben

Post #7248
Posted 03/02/2007 8:57:36 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 1:09:23 PM
Posts: 2,686, Visits: 1,888
We do not currently have plans to implement a "MaxSize" property on the business object... however, we already have a FieldLengths property... For string fields, it will contain the length of characters that the field can contain (i.e. for VarChar(150), the value will be 150).  For other data types, it will be 0 (and it's part of the partial class, so it gets updated when you rebuild the partial class).  As I said, though, we don't have plans to automatically set the MaximumLength property on a textbox to the specified value.


www.bungie.net
Post #7263
Posted 03/02/2007 12:53:35 PM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: Forum Members
Last Login: 04/11/2007 8:30:06 AM
Posts: 99, Visits: 253
Ben,

Thank you.  That worked like a charm.  Hopefully one of these days I will be as well versed in .NET as you

Now to make it generic so I can call it whenever initializing a form

Ben

Post #7279
Posted 03/02/2007 1:35:41 PM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: Forum Members
Last Login: 04/11/2007 8:30:06 AM
Posts: 99, Visits: 253
Ben,

I think I am close to a generic solution that I can call from any StrataFrame form.  However, I cannot for the life of me figure out what the proper AS "Control" to use from SF's object library.

Public Sub SetMaxLengths(ByVal MyForm As MicroFour.StrataFrame.UI.Windows.Forms.BaseForm, ByVal BO As MicroFour.StrataFrame.Business.BusinessLayer)

 For Each MyControl As Control In MyForm.Controls 'HERE the AS CONTROL needs to be   
   
replaced with a more specific type of control from SF library since .BindingField
    and .MaxLength are none standard

  If (TypeOf MyControl Is MicroFour.StrataFrame.UI.Windows.Forms.Textbox) Then
   
If MyControl.BindingField Then
           
MyControl.MaxLength = BO.FieldLengths(MyControl.BindingField)
   
End If
    End If
 Next
End Sub

Or is there a better way with reflection?

Ben

Post #7280
Posted 03/02/2007 4:59:41 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 1:09:23 PM
Posts: 2,686, Visits: 1,888
No, reflection is going to slow you down tons... your best bet is probably to do a TryCast... it's much faster than catching any InvalidCastExceptions and a little faster than testing the TypeOf or GetType() of something.  And you'll also need to call it recursively (because not all of the textboxes are going to be in the root Controls collection).

Public Shared Sub SetAllMaxLengths(ByVal container As ContainerControl)
    Dim box As MicroFour.StrataFrame.UI.Windows.Forms.TextBox
    Dim container2 As ContainerControl

    For Each ctrl As Control In container.Controls
        box = TryCast(ctrl, MicroFour.StrataFrame.UI.Windows.Forms.TextBox)
        If box IsNot Nothing Then
            box.MaxLength = box.BusinessObject.FieldLengths(box.BindingField)
        Else
            container2 = TryCast(ctrl, ContainerControl)
            If container2 IsNot Nothing Then
                SetAllMaxLengths(container2)
            End If
        End If        
    Next

End Sub

You can then call this method from within any form by just passing Me as a reference to the parameter (because a form is a ContainerControl).


www.bungie.net
Post #7287
Posted 03/05/2007 7:27:15 AM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: Forum Members
Last Login: 04/11/2007 8:30:06 AM
Posts: 99, Visits: 253
Thanks Ben.  However, when I copy this code into my tools module, I get two errors:

1. Shared is not allowed in a module <--- I removed the Shared

2. box.BusinessObject.FieldLengths(box.BindingField) - FieldLengths is not a member of MicroFour.StrataFrame.Business.BusinessLayerBase <-- isn't FieldLengths a property of the IBusinessBindable interface?  If so, how do I cast that into your code example?

Thanks!

Ben

Post #7301
Posted 03/05/2007 9:00:11 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 1:09:23 PM
Posts: 2,686, Visits: 1,888
I assumed that your code was going to be in a class... therefore Shared (in fact, when you put code in a module, .NET compiles the module as a class and then adds all of the methods to it as Shared ).  As for the FieldLengths not being a property, you will need to change that line to:

box.MaxLength = CType(box.BusinessObject, BusinessLayer).FieldLengths(box.BindingField)


www.bungie.net
Post #7302
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 8:21am

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.125. 9 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.