suggestion for the location of user vailidation code
I have a table containing the users of the app and this is where I track what menu options are available to them. Basically if the have "claims" as a value in the department field I enable claims on the menu. Should this be done in the splash screen or the main form. I don't really know what the acceptable practices are.
Also If the apps is based on reporting from a single database. Should I open the conecction once in the spalsh screen and have it public for the app or open it each time when the user needs to access it.
I don't think that I understand the first question. Why are mixing the authorization mechanism with the splash screen? If you are conserned about how fast your application will start the general idea is that splash screen opens before anything else is executed so that the end-user gets an indication that the application responds. I don't think it would be a problem if a user sees all of the menus at the beginning and when the application is ready some of the disappear. If you dont want this make all of your menus invisible from design time and only make visible the appropriate menus after authenticating the user.
About connections, the common practice is not to open a connection and keep it open in application level. You should dispose the connection object as soon as possible. Actually, after disposing the connection, it may be still open but it will be available for other applications or the same application for later. If the connection will close depends on the connection pooling mechanism. This propably is nothing the you are to be conserned of. Just make sure you dispose the connections as soon as possible. Check out the 'Using' block for this case (Using is a VB statement - I dont know the C# ecquivelant).
So if I do this in the splashscreen_load event
Dim MainForm As New MainMenu
Application.Run(MainForm)And put the validation code in the new sub in the maiN form as so
Public sub New
InitializeComponent()
EnableMenus()
end sub Private
Sub EnableMenus()
Dim SelectStatement As String = "Select Menu_Group from
PRH_User_MenuAccess " _& "WHERE Username = '" &
System.Environment.UserName.ToUpper & "'"
Dim SqlConnection As New SqlClient.SqlConnection
SqlConnection.ConnectionString = "Data Source = LOCAL; " & _
"Initial Catalog = DATA; Integrated Security = True"
Dim SelectCommand As New SqlClient.SqlCommand(SelectStatement,
SqlConnection) Try
SqlConnection.Open()
UserRights = SelectCommand.ExecuteScalar
Finally
SqlConnection.Close()
End Try Dim MenuGroups() As String = UserRights.ToUpper.Replace(" ", "").Split(",")
Dim MenuGroup As String = "" For Each MenuGroup In MenuGroups
Select Case MenuGroup
Case "ADMIN"
MyTasksToolStripMenuItem.Visible = True
End Select
Next
End SubThis should enable the menuitems while the splash screen is on and before the mainform shows. Is that close to what your were describing. I set the visible property of the menu items to false.
yes, this is the main idea.
I you are using VS 2005 you should consider checking Splash Screen feature of the project properties. Apart from setting the start up form, which in your case is the MainForm, you set the splash screen also, and the rest is done by auto generated code. So you put your code in your MainForm_Load event and you don't mix the splash screen with the rest stuff at all. The auto generated code will show the splash screen and then load the MainForm. When it's ready it will hide the splash screen.
Thanks for the tips. I found the splash form properties thru digging thru help.
I put this line in the new event of the main form to cause a delay
InitializeComponent()
EnableMenus()
System.Threading.Thread.Sleep(3000)