Imports System.Data.SqlClient Public Class fmlogin Const ConnectString As String = "Data Source=user;Initial Catalog=データベースシステム;Integrated Security=True" Property LoginAccount As New UserInfo Dim er As Double = 0 Private Sub btnGo_Click(sender As System.Object, e As System.EventArgs) Handles btnGo.Click er = 0 If TextBox1.Text.Length = 0 Or TextBox2.Text.Length = 0 Then MessageBox.Show("パスワードとIDを両方記入して下さい", "エラー!", MessageBoxButtons.OK, MessageBoxIcon.Error) Else If CheckUser(TextBox1.Text.Trim, TextBox2.Text.Trim) Then If er = 0 Then Me.DialogResult = Windows.Forms.DialogResult.OK Me.Close() Else MessageBox.Show("入力した情報が間違っています。再度入力して下さい。", "エラー!", MessageBoxButtons.OK, MessageBoxIcon.Error) TextBox1.Select() End If 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()) LoginAccount.UserName = RESULT LoginAccount.ID = id Catch ex As Exception MsgBox(ex.Message) End Try If RESULT = "" Then er = 1 End If End Using Return RESULT IsNot Nothing End Function
Private Property LoginAccount As UserInfo Sub New(ui As UserInfo) InitializeComponent() LoginAccount = ui Me.Text = ui.UserName & "が使用中" UserInfo.ID = ui.ID ※ End Sub