|
-
Jan 2nd, 2013, 08:29 AM
#1
Thread Starter
Addicted Member
Execute command saved in variable...
I don't know if this is possible, but what I want to have is a SQL table that contains has one column called "Command" that contains a VB.Net code E.g.
Me.btnHome.Enabled = False
Me.btnSave.Enabled = True
What I then want to do is query the database, and then loop through the datareader and execute each command. I am able to do the SQL call and datareader stuff, however I am not sure how to execute the VB.Net command held in the variable / datareader
Thanks
Simon
-
Jan 2nd, 2013, 08:40 AM
#2
Re: Execute command saved in variable...
You don't... not sure why you would want to...
maybe a better way would be to have a field that has the name of the control, and a field that contains what the property value should be... then you could use the .Controls() property of the form to set the property... but you would need to know what the property is ahead of time... additionally if the control is nested (not directly on the form itself) then that creates a problem as well.
-tg
-
Jan 2nd, 2013, 08:56 AM
#3
Thread Starter
Addicted Member
Re: Execute command saved in variable...
tg,
That approach would work. Basically I am trying to make my application completely customisable depending on access rights that the end user could control.
I have tried doing the following but it always returns 0 in the myObjControl. Would you be able to offer some guidance?
Code:
Dim myControl As String = "btnViewImage"
Dim myMode As Boolean = False
Dim myObjControl As Control() = Controls.Find(myControl, True)
myObjControl(0).Visible = myMode
Thanks
Simon
-
Jan 2nd, 2013, 09:30 AM
#4
Re: Execute command saved in variable...
If that's the case... you're going about it all the wrong way (in my opinion)...
What you should have (and this is what I've seen in systems I've worked on that do this) is a users table... then you have a Roles table... and then a UserRole table... the users have the, well, Users... names, pwd (optional), etc... Roles contains the list of roles in the system, Admin, Manager, USer, etc... the roles can be functional-based... like "Billing" for instance or "Customer Service" ... you get the idea... UserRole then links the two... it says, this User has this Role...
Now... in the code... when the form starts up, it looks to see if the user is a member of a given role and then activates or deactivates the controls based on that membership... One way of doing this is to have a User class that contains a property called Roles which is a List(Of String) that contains the list of roles the user is a member of... then you can do this:
Code:
Me.SomeMenuItem.Enabled = CurrentUser.Roles.Contains("Billing") ' Is user a member of the billing role?
Or you can wrap that up in a function called IsMemberOf in the User class... then it would look like this:
Code:
Me.SomeMenuItem.Enabled = CurrentUser.IsMemberOf("Billing") ' Is user a member of the billing role?
-tg
-
Jan 2nd, 2013, 09:41 AM
#5
Thread Starter
Addicted Member
Re: Execute command saved in variable...
tg,
This is exactly the way I am doing my application. User account table and every user is a member of a team (Role) table and this team / role table is the one that I want to hold the controls list in, and I'll explain why.
I have made it so the administrator of my software can create customs teams / roles and therefore I need to be able to give them the flexibility of being able to control the user interface depending on what the administrator deems appropriate. I thought it would be better coding practice to add the controls to a table with the visibility and then just iterate through the rows of the table and set the control visibility when the application is launched. This therefore means that if I add aditional buttons to my form I do not need to add a new row to the table as well as add code to my application, I could just add a row to the table only.
I hope that makes sense?
Thanks
Simon
-
Jan 2nd, 2013, 09:46 AM
#6
Re: Execute command saved in variable...
What TG has described is the typical situation with users and rolls (my typical situation in those cases is that I eat the rolls), but that isn't FULLY customizable, as you would normally have a group of users that had the same access by definition (a roll). If you want it to be fully user customizable, a slightly different approach would probably make sense, but I don't think that storing controls and properties would be the best way to go.
One thing I would note is that when you give users this amount of flexibility, you will generally find that they won't thank you for it. I have a program where people can do a pretty comprehensive set of enabling/disabling controls, making various controls mandatory, and setting ranges for controls. It's quite flexible. However, the vast majority of people either use the default, or create one set of rules and leave them in place for years. That's ok with me, as both of those are reasonable intended uses of the program. You will almost certainly find the same thing, but that may not help, since only experience with what users choose will tell you exactly what you could have left out.
What I would suggest you consider is decoupling the rules that the user can set from the actual controls. For example, if you have a rule such as Enable btnKillMeNow, you might want the rule you save to just be something like KillNow with a value of True. All that DB might hold would be a key/value pair, which is what you are doing now, but the key isn't a specific control. Therefore, the key KillNow with a value of True could do more than just set one control property to True, it might be used to set other controls. This would ultimately require a bit more code, but could be simpler.
Still, that's kind of rambling. You know what you are trying to do better than we do, and there was something odd about the code snippet you posted. Try this to see what it does:
Dim myControl As String = "btnViewImage"
Dim myObjControl As Control = Me.Controls.(myControl)
if myObjControl is nothing after that, then there is no control called "btnViewImage" in that collection. If you think it should be there....well, it isn't, so then you can figure out why not.
My usual boring signature: Nothing
 
-
Jan 2nd, 2013, 09:56 AM
#7
Re: Execute command saved in variable...
True, mine isn't fully flexible... but I wasn't trying to flesh out something in detail... just providing a concept... you could easily take it further with the proper architecture... in one system I used to work on, for each role, we granted/revoked permissons at the CRUD level... in the system I work on now... it's at an even finer level, where you can even control access to portions of the screen...
-tg
-
Jan 2nd, 2013, 03:27 PM
#8
Re: Execute command saved in variable...
Doggone it. I consistently misspelled role thoughout the whole post. That's a mental error (and perhaps an indication of an edible complex).
My usual boring signature: Nothing
 
-
Jan 2nd, 2013, 03:32 PM
#9
Re: Execute command saved in variable...
Oh, you and your rye humour. Wheat'll you think of next?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jan 2nd, 2013, 03:40 PM
#10
Re: Execute command saved in variable...
Well, it wouldn't go against the grain.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|