Module Module1 Public Sub Main() 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
Public Class FMBase Private Proterty LoginAccount as Userinfo 'LoginAccount as Userinfoで「ステートメントの終わりを指定してください。」とエラー Sub New(ui As UserInfo) InitializeComponent() LoginAccount = ui 'LoginAccountで「LoginAccountは宣言されていません。アクセス出来ない保護レベルになっています。」とエラー Me.Text = ui.UserName & "が使用中" End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim aaa As New 取引先情報 aaa.Show() End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click Dim bbb As New 品目登録 bbb.Show() End Sub End Class
Public Class UserInfo Public Property ID As String Public Property UserName As String End Class
Imports System.Data.SqlClient Public Class fmlogin Const ConnectString As String = "Data Source=user;Initial Catalog=データベースシステム;Integrated Security=True" 'Property LoginAccount Property LoginAccount As UserInfo 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()) LoginAccount.UserName = RESULT LoginAccount.ID = id 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