Module Module1 Public Sub Main() Dim Base As New FMBase Base.Show() Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) Dim account As UserInfo = Nothing Using login As New fmlogin() If login.ShowDialog() = System.Windows.Forms.DialogResult.OK Then account = login.LoginAccount Else Return End If End Using If account IsNot Nothing Then Application.Run(New FMBase(※account)) End If End Sub End Module
Imports System.Data.SqlClient Public Class fmlogin Const ConnectString As String = "Data Source=user;Initial Catalog=データベースシステム;Integrated Security=True" Property LoginAccount 'UserInfoのaccount = login.LoginAccuontの為に追加 Private Sub btnGo_Click(sender As System.Object, e As System.EventArgs) Handles btnGo.Click If TextBox1.Text.Length = 0 Or TextBox2.Text.Length = 0 Then MessageBox.Show("パスワードとIDを両方記入して下さい", "エラー!") Else If CheckUser(TextBox1.Text.Trim, TextBox2.Text.Trim) Then Me.DialogResult = Windows.Forms.DialogResult.OK Me.Close() Else MessageBox.Show("入力した情報が間違っています。再度入力して下さい。", "エラー!") End If End If End Sub Private Function CheckUser(id As String, pass As String) As String Dim RESULT As String Dim SQL As String = "SELECT ユーザー名 FROM ユーザー情報 WHERE ユーザーID='" & Replace(id, "'", "''") & "' AND パスワード='" & Replace(pass, "'", "''") & "'" Using conn As New SqlConnection(ConnectString) Dim CMD As New SqlCommand(SQL, conn) Try conn.Open() RESULT = Convert.ToString(CMD.ExecuteScalar()) UserInfo.UserName = RESULT Catch ex As Exception MsgBox(ex.Message) End Try End Using Return ※RESULT※ IsNot Nothing End Function Private Sub btnQuit_Click(sender As System.Object, e As System.EventArgs) Handles btnQuit.Click Me.Close() End Sub End Class
Public Class UserInfo Public Shared Property ID As String Public Shared Property UserName As String '「Login.UserInfoのメンバーではありません」エラー対策の為、修正 End Class