How to use Global Properties for preference settings in .NET


Author
Message
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi,

In all projects I have tables like CompanySetup or WorkstationSetup where I save user/application settings, in my VFP applications I made heavy use of the _SCREEN.oSetup or _SCREEN.oWorkstation custom properties to hold the values for those tables using the VFP command SCATTER NAME _SCREEN.oSetup.

In .NET/SF what would be the recomended way to create/have the same functionality of that data and make all those properties available anywhere in the application, like reports, forms, etc.?

Thanks!

Edhy Rijo

Replies
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Thanks Greg,

I like the idea, specially since having the BO with strong typed properties it is easier to maintain, but in the shared class how would I loop trough the BO properties to create properties with the same name as the BO and assign their values to the newly created shared properties?

I guess so sort of reflection here should be use? Cool

Edhy Rijo

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
..., but in the shared class how would I loop trough the BO properties to create properties with the same name as the BO and assign their values to the newly created shared properties?




No need to do this at all. The shared properties of the global class ARE BOs (instances of them).



From my example:



Settings.App.Theme




Settings is the global class used to access all settings.



App is a shared property of type AppBO (which was built by the BOMapper and stores app specific settings).



Theme is a strongly typed property that access the underlying data, via AppBO (it's a data property of the BO...built by BOMapper).



To add a new setting, you update your db (however that works for you), open the BOMapper, configure the new field and rebuild the partial...boom, a new property is available. BigGrin



Does that makes sense?
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Greg McGuffey (02/26/2009)
Does that makes sense?

Yes, thanks.  I did make sense and I got it done in no time, here is the resulting code:

Imports CardTrackingSystem.Business

Public MustInherit Class AppSettings

     Private Sub New()

     End Sub

     '-- Set the Company Setting Object

     Private Shared _company As bizCompany

     Public Shared Property Company() As bizCompany

          Get

               Return _company

          End Get

          Set(ByVal value As bizCompany)

               Dim loBO As New bizCompany

               loBO.FillAllRecords()

               _company = loBO

          End Set

     End Property

     '-- Set the Workstation Setting Object

     Private Shared _workstation As bizWorkstation

     Public Shared Property Workstation() As bizWorkstation

          Get

               Return _workstation

          End Get

          Set(ByVal value As bizWorkstation)

               Dim loBO As New bizWorkstation

               loBO.FillAllRecords()

               _workstation = loBO

          End Set

     End Property

End Class

Now I can reference the properties anywhere like this:

 

AppSettings.Company.CompanyName = String.Empty

AppSettings.Workstation.WorkstationName = String.Empty

Of course I have not tried this on reports yet, but there should be no problem Hehe

Edhy Rijo

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Very cool! That's what I was talking about! Actually Charles Hankey got me thinking this way a while back, so thanks to him for the initial idea too. BigGrin
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