View Poll Results: Do you think Topshot was just great here?
- Voters
- 2. You may not vote on this poll
-
Nov 14th, 2016, 01:28 AM
#1
Thread Starter
Frenzied Member
Who logged in?
Hi,
I have create login (with help with some tutorial) I have tblUsers:
- UserID
- UserTypeID
- FName
- LName
- UserName
- Password
- etc
There is 3 type of User (Admin, User, Viewer)
So this login work well. If admin login then display form for admin, if user login then display form for user, etc.
I want to user to login and only show only his/her records. I have create a form1 with DGV1 that show all records for all users. But I also have a textbox on this form:
- If I type in textbox1 "1" then it show only records for UserID 1
- If I type "2" then it show only record for UserID 2
Also this work fine.
But now.....
I not want to type userID. When user login textbox1 must know what UserID is logged in now.
So I think when user press "login" button then textbox1 on form1 must automatically fill with that UserID..
Login form is only show UserName and Password.. So I can not take that data to form1.. I need to take UserID to form1.
Can someone please give me proposal on how to do?
Thanks
M
-
Nov 14th, 2016, 01:30 AM
#2
Hyperactive Member
Re: Who logged in?
 Originally Posted by schoemr
Can someone please give me proposal on how to do?
Thanks
M
I thought you have resolved these issue on your prev post?
-
Nov 14th, 2016, 01:42 AM
#3
Thread Starter
Frenzied Member
Re: Who logged in?
Hi earvinnill,
No in previous post I asked how to click on "a" customer name dgv1 (form1) and show related customer details on dgv2 (form2) So, I could not get that resolved 
So I try to make my solution but I think this solution not the best. There must be better way...
I can get what customer name was click:
Private Sub dgvTest_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvTest.CellDoubleClick
If e.ColumnIndex = 2 Then
frmDetails.txtFirst.Text = dgvTest.Rows(e.RowIndex).Cells(0).Value
frmDetails.txtMiddle.Text = dgvTest.Rows(e.RowIndex).Cells(1).Value
frmDetails.txtLast.Text = dgvTest.Rows(e.RowIndex).Cells(2).Value
frmDetails.Show()
End If
End Sub
So now I can see on customer details for who customer is.. I need to some way of filter that now...
This new question is for login...
I want user to login and only see his records, then click on "a" record in dgv1 and form2 open and show related record.. So I can see why you ask.. It is working together this two things I ask...
-
Nov 14th, 2016, 09:32 AM
#4
Re: Who logged in?
Well, since you didn't show any code, this is a generalization of what you would do. If someone logs in, you know what their UserID is since it is part of the same record. Then you just assign that to the textbox. TextBox1.Text = MyUserID.ToString
The proper syntax to accomplish that is up to you based on how you are getting UserID.
I assume you will be removing these textboxes eventually since that would be a poor design to allow the user to change (or even see) the value of the textbox. It could be locked or hidden, of course, but the textbox serves no purpose whatsoever.
-
Nov 15th, 2016, 02:53 PM
#5
Thread Starter
Frenzied Member
Re: Who logged in?
Hi topshot,
I not have code with me at moment. I will make good explanation and code and post here tomorrow. I was think to hide that textbox, maybe once you observe it you can advise me. Thank you for reply.
Michelle
-
Nov 16th, 2016, 03:09 AM
#6
Thread Starter
Frenzied Member
Re: Who logged in?
hi,
here is code:
Code:
Private Sub btnLOGIN_Click_1(sender As Object, e As EventArgs) Handles btnLOGIN.Click
'ADMIN
Dim int1 As Integer = 1
If Not TblUsersTableAdapter1.ScalarQueryLOGIN(TextBox1.Text, TextBox2.Text, int1) = Nothing Then
End If
If TblUsersTableAdapter1.ScalarQueryGETUSERTYPEID(TextBox1.Text) = 1 Then
MsgBox("Admin login", MsgBoxStyle.Information, "Login")
frmAdmin.Show()
End If
So to determine what user type was log in I make use of query "ScalarQueryGETUSERTYPEID" I 'think' this is how to obtain UserID too? But now I want to take this UserID and Name and Lastname to frmAdmin.. Meaning I want to display that user info (who was login) on frmAdmin.. Also in frmAdmin I have textbox1 (I already make this) - this textbox filter records if type userID in textbox. So when Admin user login then frmAdmin must open and display his name and lastname on top of form and 'filter' textbox must have his UserID so when he login he only see for records that is for him..
Thank you
M
-
Nov 16th, 2016, 09:24 AM
#7
Re: Who logged in?
What is the point of the first If statement? You aren't doing anything with it.
Rather than using an ExecuteScalar function which can return only a single value and, thus, would require a second call to the database, I would change the query and use ExecuteReader so you can retrieve ALL the info you may need at once. One call to get everything you need is usually better than 2 calls for 1 piece of data. But, yes, you could create a second ExecuteScalar to get UserID.
Second question, do you really need 2 separate forms for Admin and User or are they really pretty much the same form with certain controls being visible or not? I would think they would be the same except the admin version would show some extra buttons/menus to Add/Edit/Delete and that sort of thing. If it is like that you could have those controls invisible by default and if UserID is Admin then make them visible.
Back to the question at hand, the best way to pass variables between forms is to use properties.
vb.net Code:
Public Class frmDisplayDGV 'under the Class declaration you would put this Private _userID As Integer 'then somewhere past the class-level declarations, include any properties Public Property UserID() As Integer Get Return _userID End Get Set(ByVal value As Integer) _userID = value 'as an example of what I meant above, you could do something like 'this if it was an admin user so you could have a "generic" form for 'all users that is customized based on user type If value = ADMIN_USER Then 'ADMIN_USER is part of a Public Enumeration or a Const that equals 1 so if you ever need to change the value, it's done in only 1 place btnAdd.Visible = True End If End Set End Property
Then in your Login form you would do something like this
vb.net Code:
Dim frmAdmin As New frmDisplayDGV frmAdmin.UserID = TblUsersTableAdapter1.ScalarQueryGETUSERID(TextBox1.Text) 'you would need to add these and whatever other properties you want frmAdmin.Name = ... frmAdmin.LastName = ... frmAdmin.Show()
-
Nov 16th, 2016, 11:35 AM
#8
Thread Starter
Frenzied Member
Re: Who logged in?
hello topshot, I thank you so much for very detail answer. Really I appreciate 
What is the point of the first If statement? You aren't doing anything with it.
Ok I see if nothing then nothing.. it not do anything if nothing.. I can remove that
Rather than using an ExecuteScalar function which can return only a single value and, thus, would require a second call to the database, I would change the query and use ExecuteReader so you can retrieve ALL the info you may need at once. One call to get everything you need is usually better than 2 calls for 1 piece of data. But, yes, you could create a second ExecuteScalar to get UserID.
Thank you I will think. I work long to get login for working correct. I am afraid to change and then it messed up again..
Second question, do you really need 2 separate forms for Admin and User or are they really pretty much the same form with certain controls being visible or not? I would think they would be the same except the admin version would show some extra buttons/menus to Add/Edit/Delete and that sort of thing. If it is like that you could have those controls invisible by default and if UserID is Admin then make them visible.
Yes admin and users go to different forms..
Also I understand what you say about admin/users same form.. is that why i can remove this if admin/users not use same form. Can I remove this?
If value = ADMIN_USER Then 'ADMIN_USER is part of a Public Enumeration or a Const that equals 1 so if you ever need to change the value, it's done in only 1 place
btnAdd.Visible = True
End If
then:
Code:
frmAdmin.UserID = TblUsersTableAdapter1.ScalarQueryGETUSERID(TextBox1.Text)
frmAdmin.Name = TblUsersTableAdapter1.ScalarQueryGETUSERID(TextBox2.Text)
frmAdmin.LastName = TblUsersTableAdapter1.ScalarQueryGETUSERID(TextBox3.Text)
So i have to change ScalarQueryGETUSERID to get ALL info...? e.g. ReaderQueryGETUSERDETAILS
Also, I load data into frmAdmin before load form?
Thank more for your answer
Michelle
-
Nov 16th, 2016, 12:36 PM
#9
Re: Who logged in?
The way I do it is when the user is on the login screen and presses login the app send a query to the database (a stored procedure) that will check if the username is valid, is the password correct? If this is good return the userId associated with the user (used to store who created or modified a record in the database), what the user level is (admin? user?).
This is stored is a type I have created and used around the program. When the user goes to a user information screen if they are not an admin level the query passed to the database will hold the userID so only that persons information is returned for them to see. If and admin then null is passed as the ID and all records are returned. This user level can be used to control what screens are displayed to the user also.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Nov 16th, 2016, 01:14 PM
#10
Re: Who logged in?
 Originally Posted by schoemr
Also I understand what you say about admin/users same form.. is that why i can remove this if admin/users not use same form. Can I remove this?
Certainly, it was just there as an example.
So i have to change ScalarQueryGETUSERID to get ALL info...? e.g. ReaderQueryGETUSERDETAILS
I would but if you're too scared to break what you've got, do it however you wish. As I explained, it doesn't make a lot of sense to hit the database twice when you can get the data you need in just 1 call. Gary indicated the same thing essentially.
Also, I load data into frmAdmin before load form?
Normally, yes, you would set the properties before you call Show.
-
Nov 16th, 2016, 03:34 PM
#11
Thread Starter
Frenzied Member
Re: Who logged in?
If it is like that you could have those controls invisible by default and if UserID is Admin then make them visible.
I think this is better idea.......
-
Nov 16th, 2016, 03:43 PM
#12
Thread Starter
Frenzied Member
Re: Who logged in?
Tops,
Code:
Public Class frmDisplayDGV
'under the Class declaration you would put this
Private _userID As Integer
'then somewhere past the class-level declarations, include any properties
Public Property UserID() As Integer
Get
Return _userID
End Get
Set(ByVal value As Integer)
_userID = value
'as an example of what I meant above, you could do something like
'this if it was an admin user so you could have a "generic" form for
'all users that is customized based on user type
If value = ADMIN_USER Then 'ADMIN_USER is part of a Public Enumeration or a Const that equals 1 so if you ever need to change the value, it's done in only 1 place
btnAdd.Visible = True
End If
End Set
End Property
How will this change to make include for Name and LastName? Maybe like:
Code:
Public Class frmDisplayDGV
Private _userID As Integer
Private _Name As String
Private _LastName As String
Public Property UserID() As Integer
Public Property Name() As String
Public Property Lastname() As String
Get
Return _userID
Return _Name
Return _Lastname
End Get
Set(ByVal value As Integer)
_userID = value
_Name = ??
_Lastname = ??
btnAdd.Visible = True
End Set
End Property
-
Nov 16th, 2016, 06:21 PM
#13
Re: Who logged in?
Each property has its own Get/Set
Code:
Public Class frmDisplayDGV
Private _userID As Integer
Private _Name As String
Private _LastName As String
Public Property UserID() As Integer
Get
Return _userID
End Get
Set(ByVal value As Integer)
_userID = value
btnAdd.Visible = True 'YOU WOULD WANT THIS IN AN IF OR SELECT CASE STATEMENT OR IT WOULD ALWAYS BE SET TO TRUE
End Set
End Property
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
lblName.Text = value 'example if you wanted to display their name in a label
End Set
End Property
Public Property Lastname() As String
Get
Return _Lastname
End Get
Set(ByVal value As String)
_Lastname = value
End Set
End Property
-
Nov 17th, 2016, 03:53 AM
#14
Thread Starter
Frenzied Member
Re: Who logged in?
Hi again,
I follow this procure but getting error. Can say what I do wrong please?
Attachment 142475
Thanks,
M
-
Nov 17th, 2016, 04:57 AM
#15
Thread Starter
Frenzied Member
Re: Who logged in?
Topshot,
My login is now work perfect! Krrrrrrr!! BIG headache is resolved. For you and also Karen - THANK YOU, THANK YOU, THANK YOU!!!!
-
Nov 17th, 2016, 09:53 AM
#16
Re: Who logged in?
 Originally Posted by schoemr
I follow this procure but getting error. Can say what I do wrong please?
I assume from your last post that you figured out to get rid of the parentheses so it is just
-
Nov 17th, 2016, 02:09 PM
#17
Thread Starter
Frenzied Member
Re: Who logged in?
yes thank you topshot
-
Nov 17th, 2016, 02:31 PM
#18
Re: Who logged in?
If it is resolved please mark it resolved thanks.
Disclaimer: When code is given for example - it is merely a example. •
•
•
Unless said otherwise indicated - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.
Tags for this Thread
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
|