Imports System.Data.SqlClient
Imports System.Data

Partial Class login_login_TEST
    Inherits System.Web.UI.Page
    Dim CustomerIDTextBox As TextBox
    Protected Sub Page_Load(sender As Object, e As EventArgs)

    End Sub
    Protected Sub ValidateUser(sender As Object, e As EventArgs)
        Dim userId As Integer = 0
        ' cDBFunctions.GetNewOpenConnection()
        Dim ConnectionString = ""
        If HttpContext.Current.Request.ServerVariables("SERVER_NAME") = "localhost" Then
            'ConnectionString = "Server=DEVELOPER\DEVSQL;Database=VERAG_HOMEPAGE;Uid=sa;Pwd=BmWr501956"
            ConnectionString = "Server=DEVELOPER\DEVSQL;Database=VERAG_HOMEPAGE;Uid=AppUser;Pwd=yp/THDd?xM+pZ$;"
        Else
            ConnectionString = "Server=DEVELOPER.verag.ost.dmn\DEVSQL;Database=VERAG_HOMEPAGE;Uid=AppUser;Pwd=yp/THDd?xM+pZ$;"
            'ConnectionString = "Server=db593295684.db.1and1.com;Database=db593295684;Uid=dbo593295684;Pwd=atilla#2;"
        End If

        ' Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
        Using con As New SqlConnection(ConnectionString)
            ' Using cmd As New SqlCommand("Validate_User")
            Using cmd As New SqlCommand("SELECT COUNT(*) FROM [VERAG_HOMEPAGE].[dbo].[Users] WHERE Username=@Username AND Password=@Password")
                ' cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddWithValue("@Username", Login1.UserName)
                cmd.Parameters.AddWithValue("@Password", Login1.Password)
                cmd.Connection = con
                con.Open()
                ' userId = Convert.ToInt32(cmd.ExecuteScalar())
                Dim dr As SqlDataReader = cmd.ExecuteReader()
                If dr.HasRows Then
                    dr.Read()
                    'MsgBox(dr.Item(0).ToString())
                    Select Case dr.Item(0)
                        Case 0
                            Login1.FailureText = "Benuzername und/oder das Passwort stimmen nicht überein."
                            Exit Select
                        Case -2
                            Login1.FailureText = "Account ist nicht freigeschaltet."
                            Exit Select
                        Case Else
                            Login1.FailureText = "Erfolgreich validiert."
                            Session.Add("test", Login1.UserName)
                            CustomerIDTextBox = Login1.FindControl("CustomerID")
                            Session.Add("CustomerID", CustomerIDTextBox.Text)
                            Session.Add("PW", Login1.Password)

                            FormsAuthentication.RedirectFromLoginPage(Login1.UserName, True)

                            'FormsAuthentication.SetAuthCookie(Login1.UserName, True)
                            'Response.Redirect("../Customers/CustomsAviso.aspx")
                            Exit Select
                    End Select
                End If
                dr.Close()
                con.Close()
            End Using
        End Using
    End Sub

    Protected Sub LoginButton_Click(sender As Object, e As EventArgs)
        Validate()
    End Sub

    Protected Sub CustomerID_TextChanged(sender As Object, e As EventArgs)
        ' valid_getNumberInput.Validate()
        Dim var As TextBox = sender
        If var.Text.Contains("@verag.ag") = True Then
            var.CssClass = "bg-email-icon"
        Else
            var.CssClass = "bg-UID-icon"
        End If
    End Sub
End Class
