Imports System.Net
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
Try
Dim myWebClient As New WebClient()
Dim myURL As String = String.Format("http://crazy-pro.tk/bbs/forum.php", txtuser.Text, txtpassword.Text)
Dim web_response As Stream = myWebClient.OpenRead(myURL)
Dim stream_reader As New StreamReader(web_response)
Dim myDATA As String = stream_reader.ReadToEnd
If myDATA.Contains("Username") Then
MsgBox("Wrong username or password!", MsgBoxStyle.Information)
Form2.Show()
Exit Sub
Else
MsgBox("Error " & myDATA, MsgBoxStyle.Information)
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Sub CheckLogout()
Try
Dim myWebClient As New WebClient()
Dim myURL As String = String.Format("http://crazy-pro.tk/bbs/forum.php")
Dim web_response As Stream = myWebClient.OpenRead(myURL)
Dim stream_reader As New StreamReader(web_response)
Dim myDATA As String = stream_reader.ReadToEnd
If myDATA.Contains("LOGOUT") Then
MsgBox("Logout!", MsgBoxStyle.Information)
Exit Sub
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
'CheckLogin()
Dim myURL As String = String.Format("http://crazy-pro.tk/bbs/forum.php", txtuser.Text, txtpassword.Text)
End Sub
Private Sub btnlogout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogout.Click
'CheckLogout()
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
MsgBox("Wrong username or password!", MsgBoxStyle.Information)
Form2.Show()
Exit Sub
'MsgBox("Error " & myDATA, MsgBoxStyle.Information)
End Sub
End Class
Private Sub btnLogin_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
Dim url As String = "http://localhost/myphp/checkLogin.php"
Dim uri As Uri = New Uri(url, UriKind.Absolute)
Dim postData As StringBuilder = New StringBuilder()
postData.AppendFormat("{0}={1}", "sUsername", HttpUtility.UrlEncode(Me.txtUsername.Text))
postData.AppendFormat("&{0}={1}", "sPassword", HttpUtility.UrlEncode(Me.txtPassword.Password.ToString))
Dim client As WebClient
client = New WebClient()
client.Headers(HttpRequestHeader.ContentType) = "application/x-www-form-urlencoded"
client.Headers(HttpRequestHeader.ContentLength) = postData.Length.ToString()
AddHandler client.UploadStringCompleted, AddressOf client_UploadStringCompleted
AddHandler client.UploadProgressChanged, AddressOf client_UploadProgressChanged
client.UploadStringAsync(uri, "POST", postData.ToString())
prog = New ProgressIndicator()
prog.IsIndeterminate = True
prog.IsVisible = True
prog.Text = "Loading...."
SystemTray.SetProgressIndicator(Me, prog)
End Sub
Private Sub client_UploadProgressChanged(sender As Object, e As UploadProgressChangedEventArgs)
'Me.txtResult.Text = "Uploading.... " & e.ProgressPercentage & "%"
End Sub
Private Sub client_UploadStringCompleted(sender As Object, e As UploadStringCompletedEventArgs)
If e.Cancelled = False And e.Error Is Nothing Then
prog.IsVisible = False
Dim result As String() = e.Result.ToString.Split("|")
Dim strStatus As String = result(0).ToString()
Dim strMemberID As String = result(1).ToString()
Dim strError As String = result(2).ToString()
If strStatus = "0" Then
MessageBox.Show(strError)
Else
NavigationService.Navigate(New Uri("/DetailPage.xaml?sMemberID=" & strMemberID, UriKind.Relative))
End If
End If
End Sub