none
我想请问我如何monitoring我的user login logout 的status 呢 RRS feed

  • 问题

  • 我想请问我如何monitoring我的user login logout 的status 呢!以下是我的login 的code。

       Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
            If un.Text = String.Empty And pw.Text = String.Empty Then
                MessageBox.Show("Please fill in both username and password")
                Return
            End If

            If FailCount = 2 Then
                MessageBox.Show("Sorry, you have exceeded the maximum number of attempts to login", "Message")
                Application.ExitThread()
            End If

            Dim AppLogin As New ApplicatioLogin With
                {
                    .Database = IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mydataX.mdb"),
                    .UserName = un.Text,
                    .UserPassword = pw.Text
                }
            If AppLogin.Login Then
                FailCount = 0
                MyPlayer.SoundLocation = path & LogOnsound
                MyPlayer.Play()
                Me.Hide()
                un.Clear()
                pw.Clear()
            Else
                FailCount += 1
                MyPlayer.SoundLocation = path & LogOffsound
                MyPlayer.Play()
                MessageBox.Show("FailCount" & FailCount)

                If FailCount = 3 Then
                    Application.Exit()
                End If

                un.Clear()
                pw.Clear()
            End If
        End Sub


    2019年12月13日 6:26

全部回复

  • Hi christing, 

    我需要更多的信息来分析你的问题并进行测试。

    请提供’ AppLogin.Login’ ’ MyPlayer’的相关代码。

    另外,关于监测login logout的状态,你想要实现什么样的功能,可以描述的具体一点吗?

    期待你的更新。

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年12月13日 7:49
    版主
  • @Xingyu Zhao 

    感谢你的回复以下是我为AppLogin.Login 与 MyPlayer 篇写的代码。 

    ApplicatioLogin.vb

    Imports System.Data.OleDb
    Public Class ApplicatioLogin
        Public Property UserName As String
        Public Property UserPassword As String
        Public Property Database As String
        Public Property DatabasePassword As String
        Public Property Retries As Integer

        Public Sub New()

        End Sub
        Private Builder As New OleDb.OleDbConnectionStringBuilder With
            {
                .Provider = "Microsoft.ACE.OLEDB.12.0"
            }

        Public Function Login() As Boolean


            Builder.DataSource = Me.Database

            If Not String.IsNullOrWhiteSpace(Me.UserName) AndAlso Not String.IsNullOrWhiteSpace(Me.UserPassword) Then
                Using cn As New OleDb.OleDbConnection With {.ConnectionString = Builder.ConnectionString}
                    Using cmd As New OleDb.OleDbCommand With
                        {
                            .Connection = cn,
                            .CommandText =
                            "SELECT UserName,UserPassword FROM tbl_user " &
                            "WHERE UserName = @UserName AND UserPassword = @UserPassword"
                        }
                        cmd.Parameters.AddWithValue("@UserName", Me.UserName)
                        cmd.Parameters.AddWithValue("@UserPassword", Me.UserPassword)

                        Try
                            cn.Open()
                        Catch ex As Exception
                            If ex.Message.ToLower.Contains("not a valid password") Then
                                Return False
                            Else
                                Throw ex
                            End If
                        End Try

                        Dim Reader = cmd.ExecuteScalar
                        If Reader IsNot Nothing Then
                            Retries = 0
                            Return True
                        Else
                            Retries += 1
                            Return False
                        End If
                    End Using
                End Using
            Else
                Return False
            End If
        End Function
    End Class

    MyPlayer是when login 成功会play (LogOnsound)

    MyPlayer是when login 失败会play (LogOffsound)

    MyPlayer 的code 是

      Dim path = System.Windows.Forms.Application.StartupPath
        Dim LogOnsound As String
        Dim LogOffsound As String
        Dim MyPlayer As New SoundPlayer()
        Dim FailCount As Integer = 0

        Private Sub LoginForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
            LogOnsound = "\LogOn.wav"
            LogOffsound = "\LogOn.wav"
        End Sub

    我想要develop的login是当用户A 成功login 后会被record login 的日期与时间,然后用户A 更改或删除什么资料然后几点logout。

    2019年12月13日 8:37
  • Hi christing,

    我正在针对该问题进行一些测试,这可能需要一点时间。

    感谢你的耐心。

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年12月17日 10:16
    版主
  • Hi christing

    感谢你的耐心,你可以在数据库中设置一个'DateTime'类型的‘login’和'loginout'数据,当你登录或者登出时及时更新这些数据。

    下面是代码:

            If AppLogin.Login() Then
                UpdateTime()
                '...
            End If
    
    
       Private Sub UpdateTime()
            Dim connString As String = "connextion string"
            Dim cmdText As String = $"update tbl_user set UserLoginTime = @time WHERE Id = 1"
    
            Using conn As OleDbConnection = New OleDbConnection(connString)
    
                Using cmd As OleDbCommand = New OleDbCommand(cmdText, conn)
                    conn.Open()
                    cmd.Parameters.AddWithValue("@time", DateTime.Now)
                    cmd.ExecuteNonQuery()
                End Using
            End Using
        End Sub

    希望对你有帮助。

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年12月23日 9:33
    版主