Студопедия

Главная страница Случайная страница

КАТЕГОРИИ:

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника






FrmLogin






Public Class frmLogin

 

Public Property playerId1 As Integer

Public Property playerId2 As Integer

 

Private Sub btnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click

frmMainMenu.Show()

Me.Close()

End Sub

 

Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click

 

'if both login details are valid

If ((checkDetails(lstBlack.SelectedItem, txtPWBlack.Text, chkAIBlack.Checked) <> False) _

And checkDetails(lstWhite.SelectedItem, txtPWWhite.Text, chkAIWhite.Checked) <> False) Then

 

playerId1 = checkDetails(lstBlack.SelectedItem, txtPWBlack.Text, chkAIBlack.Checked)

playerId2 = checkDetails(lstWhite.SelectedItem, txtPWWhite.Text, chkAIWhite.Checked)

 

'load the game form

frmGame.Show()

 

'load the Ids of the players into the Game form

frmGame.playerBlack = playerId1

frmGame.playerWhite = playerId2

 

 

Else

MsgBox("ERROR: wrong login details")

End If

End Sub

 

Private Sub frmLogin_Load(sender As Object, e As EventArgs) Handles MyBase.Load

 

'load the drop down menus with usernames

loadDropDown(lstBlack)

loadDropDown(lstWhite)

 

 

End Sub

 

Private Sub loadDropDown(id)

'get all the usernames to put into the drop down menus

Dim ds As New DataSet

dbConnector.connect()

ds = dbConnector.SQLselect("SELECT ID, Username FROM tblUsers")

 

For n = 0 To ds.Tables("Results").Rows.Count - 1

id.Items.Add(ds.Tables("Results").Rows(n).Item(1))

Next

 

dbConnector.reset()

End Sub

 

Private Function checkDetails(id, pw, AI)

 

If AI Then

'if AI is being used, don't check login details

Return True

Else

Dim ds As New DataSet

dbConnector.connect()

dbConnector.reset()

ds = dbConnector.SQLselect("SELECT ID, Username FROM tblUsers WHERE Username = '" & id & "' AND Pword = '" & pw & "'")



 

If ds.Tables("Results").Rows.Count > 0 Then

Console.WriteLine(ds.Tables("Results").Rows(0).Item(0))

Return ds.Tables("Results").Rows(0).Item(0)

Else

Return False

End If

End If

 

End Function

 

 

Private Sub chkAIBlack_CheckedChanged(sender As Object, e As EventArgs) Handles chkAIBlack.CheckedChanged

'only allow on check box to be checked at a time

 

If chkAIWhite.Checked Then

chkAIWhite.Checked = False

txtPWWhite.Enabled = True

lstWhite.Enabled = True

End If

 

If chkAIBlack.Checked Then

txtPWBlack.Enabled = False

lstBlack.Enabled = False

Else

txtPWBlack.Enabled = True

lstBlack.Enabled = True

End If

End Sub

 

Private Sub chkAIWhite_CheckedChanged(sender As Object, e As EventArgs) Handles chkAIWhite.CheckedChanged

'only allow on check box to be checked at a time

 

If chkAIBlack.Checked Then

chkAIBlack.Checked = False

txtPWBlack.Enabled = True

lstBlack.Enabled = True

End If

 

If chkAIWhite.Checked Then

txtPWWhite.Enabled = False

lstWhite.Enabled = False

Else

txtPWWhite.Enabled = True

lstWhite.Enabled = True

End If

End Sub

End Class



mylektsii.su - Мои Лекции - 2015-2022 год. (0.023 сек.)Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав Пожаловаться на материал