Язык Visual Basic на платформе .NET.
Модераторы: Ramzes, Sebas
-
August
-
- Бывалый
-
-
- Сообщения: 209
- Зарегистрирован: 25.08.2006 (Пт) 10:48
- Откуда: C сибири
August » 19.01.2007 (Пт) 14:19
Форма логин
- Код: Выделить всё
Public Class LoginForm1
Public Delegate Sub idUebergabeDelegate(ByVal i As Integer)
Public Event idUebergabe As idUebergabeDelegate
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
If UsernameTextBox.Text = "1" And Me.PasswordTextBox.Text = "1" Then
RaiseEvent idUebergabe(1)
Me.Close()
Else
UsernameTextBox.Text = ""
PasswordTextBox.Text = ""
End If
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
End
End Sub
End Class
Главная форма
- Код: Выделить всё
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim a As New LoginForm1
AddHandler a.idUebergabe, AddressOf idUebergabe
a.ShowDialog()
End Sub
Private Sub idUebergabe(ByVal i As Integer)
If i = 1 Then MsgBox("hallo user 1") Else End
End Sub
End Class
-
dimaboyko
-
- Начинающий
-
-
- Сообщения: 21
- Зарегистрирован: 03.04.2007 (Вт) 14:00
dimaboyko » 03.04.2007 (Вт) 15:07
- Код: Выделить всё
Private Sub MDIParentMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim NewLoginForm As New LoginForm
If Not ModuleCommon.IsExistOpenForm(NewLoginForm) Then
If NewLoginForm.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
Application.Exit()
Else ' Do app
If CheckLogin(NewLoginForm.UsernameTextBox.Text.Trim, NewLoginForm.PasswordTextBox.Text.Trim) Then
If My.Settings.UseBkg = True Then SetPic(My.Settings.PicPath)
Else
Application.Exit()
End If
End If
End If
End Sub
Private Function CheckLogin(ByVal UserName As String, ByVal UserPass As String) As Boolean
Dim cnn As New OleDb.OleDbConnection(My.Settings.MyConnectionString)
Dim sqlstr As String
sqlstr = " SELECT ID, UserLogin, UserPassword, " + _
" UserFirstName, UserLastName, SecLevelName, SecLevelNum " + _
" FROM vUsers " + _
" WHERE UserLogin='" + UserName + "' AND UserPassword='" + UserPass + "'"
Dim cmd As New OleDb.OleDbCommand(sqlstr, cnn)
Dim result As Boolean = False
Dim DataReader As OleDb.OleDbDataReader
Try
cnn.Open()
DataReader = cmd.ExecuteReader
If DataReader.HasRows Then
While (DataReader.Read)
' Dim MyUser As New ClassUserInfo
MyUser.UserName = DataReader("UserFirstName")
MyUser.LastName = DataReader("UserLastName")
MyUser.Password = DataReader("UserPassword")
MyUser.StatusStr = DataReader("SecLevelName")
MyUser.StatusInt = DataReader("SecLevelNum")
MyUser.UserID = DataReader("ID")
End While
result = True
End If
Catch ex As Exception
result = False
If (cnn IsNot Nothing AndAlso cnn.State = ConnectionState.Open) Then
cnn.Close()
End If
cnn = Nothing
'Throw New SqlDataException(My.Resources.Exceptions.Message, ex)
MsgBox(ex)
End Try
Return result
End Function
И наконец
- Код: Выделить всё
Public Class ClassUserInfo
Private _UserName As String = String.Empty
Private _LastName As String = String.Empty
Private _Password As String = String.Empty
Private _StatusStr As String = String.Empty
Private _StatusInt As Integer = -1
Private _FullUserInfo As String = String.Empty
Private _UserID As Integer = -1
'
Public Property UserName() As String
Get
Return _UserName
End Get
Set(ByVal Value As String)
_UserName = Value
MakeUserInfoStr(_UserName, _LastName, _StatusStr)
End Set
End Property
'
Public Property LastName() As String
Get
Return _LastName
End Get
Set(ByVal Value As String)
_LastName = Value
MakeUserInfoStr(_UserName, _LastName, _StatusStr)
End Set
End Property
'
Public Property Password() As String
Get
Return _Password
End Get
Set(ByVal Value As String)
_Password = Value
MakeUserInfoStr(_UserName, _LastName, _StatusStr)
End Set
End Property
'
Public Property StatusStr() As String
Get
Return _StatusStr
End Get
Set(ByVal Value As String)
_StatusStr = Value
MakeUserInfoStr(_UserName, _LastName, _StatusStr)
End Set
End Property
'
Public Property StatusInt() As Integer
Get
Return _StatusInt
End Get
Set(ByVal Value As Integer)
_StatusInt = Value
End Set
End Property
'
Public ReadOnly Property FullUserInfo() As String ' Only read
Get
Return _FullUserInfo
End Get
End Property
'
Public Property UserID() As Integer
Get
Return _UserID
End Get
Set(ByVal Value As Integer)
_UserID = Value
End Set
End Property
'
Public Sub New()
'
End Sub
'
Public Sub New(ByVal UserName As String, ByVal LastName As String, ByVal Password As String, ByVal StatusStr As String, ByVal StatusInt As Integer)
MakeUserInfoStr(UserName, LastName, StatusStr)
End Sub
Private Sub MakeUserInfoStr(ByVal UserName As String, ByVal LastName As String, ByVal StatusStr As String)
Const Unknown = "Unknown"
If UserName.Length = 0 Then UserName = Unknown
If LastName.Length = 0 Then LastName = Unknown
If StatusStr.Length = 0 Then StatusStr = Unknown
_FullUserInfo = "User: " + UserName + " " + LastName + ", Status: " + StatusStr
End Sub
End Class
Это один из возможных вариантов. Удачи!
-
Viper
-
- Артефакт VBStreets
-
-
- Сообщения: 4394
- Зарегистрирован: 12.04.2005 (Вт) 17:50
- Откуда: Н.Новгород
-
Viper » 03.04.2007 (Вт) 15:14
Некрофилия однако не приветствуется у нас на форуме
Весь мир матрица, а мы в нем потоки байтов!
-
Alex[fj]
-
- Бывалый
-
-
- Сообщения: 278
- Зарегистрирован: 17.02.2007 (Сб) 20:10
- Откуда: Питер
-
Alex[fj] » 03.04.2007 (Вт) 19:05
Очень хотелось добавить!
Будет приколно, если в
TextBox'е, в котором вводишь пароль, в свойстве
PasswordChar поставить звездочку...
Стараюсь быть вполне хорошим (c) Лев Толстой
Вернуться в Visual Basic .NET
Кто сейчас на конференции
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 38