Imports System.Xml
Module M_User_Login
Public Usr_ID As Integer
Public Usr_Name As String
Public Ses_ID As Integer
Public Terminal_Id As Integer
Public Sub Read_User_Loged_Xml()
Dim xDoc As XmlDocument = New XmlDocument()
Dim Ses_ID_Str As String
Dim User_ID_Str As String
Dim Trm_Id_Str As String
xDoc.Load("User_Loged.xml")
Dim UserId As XmlNodeList = xDoc.GetElementsByTagName("User_ID")
Dim UserName As XmlNodeList = xDoc.GetElementsByTagName("User_Name")
Dim TrmID As XmlNodeList = xDoc.GetElementsByTagName("Terminal_ID")
Dim SesID As XmlNodeList = xDoc.GetElementsByTagName("Session_ID")
'Dim TimeLogedIn As XmlNodeList = xDoc.GetElementsByTagName("Time_Loged_In")
'Dim Ses_Guid As XmlNodeList = xDoc.GetElementsByTagName("Session_GUID")
'Dim Usr_Guid As XmlNodeList = xDoc.GetElementsByTagName("User_GUID")
Usr_Name = UserName(0).InnerText
Ses_ID_Str = SesID(0).InnerText
User_ID_Str = UserId(0).InnerText
Trm_Id_Str = TrmID(0).InnerText
Try
If User_ID_Str = String.Empty Then
Usr_ID = 0
ElseIf Ses_ID_Str = String.Empty Then
Ses_ID = 0
ElseIf Trm_Id_Str = String.Empty Then
Terminal_Id = 0
Else
Usr_ID = Convert.ToInt32(User_ID_Str)
Ses_ID = Convert.ToInt32(Ses_ID_Str)
Terminal_Id = Convert.ToInt32(Trm_Id_Str)
End If
Catch ex As Exception
MsgBox("Read User Login XML.... " & ex.Message)
End Try
Get_Terminal()
'MsgBox(Usr_ID & "---" & Ses_ID)
End Sub
Private Sub Write_User_Loged_Xml()
Dim xDoc As XmlDocument = New XmlDocument()
xDoc.Load("User_Loged.xml")
Dim UserId As XmlNodeList = xDoc.GetElementsByTagName("User_ID")
Dim UserName As XmlNodeList = xDoc.GetElementsByTagName("User_Name")
Dim TrmID As XmlNodeList = xDoc.GetElementsByTagName("Terminal_ID")
Dim Ses_ID As XmlNodeList = xDoc.GetElementsByTagName("Session_ID")
'Dim TimeLogedIn As XmlNodeList = xDoc.GetElementsByTagName("Time_Loged_In")
'Dim Ses_Guid As XmlNodeList = xDoc.GetElementsByTagName("Session_GUID")
'Dim Usr_Guid As XmlNodeList = xDoc.GetElementsByTagName("User_GUID")
UserId(0).InnerText = M_User_Login.Usr_ID
UserName(0).InnerText = M_User_Login.Usr_Name
TrmID(0).InnerText = M_User_Login.Terminal_Id
Ses_ID(0).InnerText = M_User_Login.Ses_ID
'Dep_Name(0).InnerText = Tx_Dep_Name.Text
'Trm_Expiry(0).InnerText = Tx_Expiry.Text
'Trm_Cert(0).InnerText = Tx_Trm_Cert.Text
xDoc.Save("User_Loged.xml")
End Sub
Private Sub Log_off_User_Xml()
Dim xDoc As XmlDocument = New XmlDocument()
xDoc.Load("User_Loged.xml")
Dim UserId As XmlNodeList = xDoc.GetElementsByTagName("User_ID")
Dim UserName As XmlNodeList = xDoc.GetElementsByTagName("User_Name")
Dim TrmID As XmlNodeList = xDoc.GetElementsByTagName("Terminal_ID")
Dim Ses_ID As XmlNodeList = xDoc.GetElementsByTagName("Session_ID")
Dim TimeLogedIn As XmlNodeList = xDoc.GetElementsByTagName("Time_Loged_In")
Dim Ses_Guid As XmlNodeList = xDoc.GetElementsByTagName("Session_GUID")
Dim Usr_Guid As XmlNodeList = xDoc.GetElementsByTagName("User_GUID")
UserName(0).InnerText = ""
UserId(0).InnerText = ""
TrmID(0).InnerText = ""
Ses_ID(0).InnerText = ""
TimeLogedIn(0).InnerText = ""
Ses_Guid(0).InnerText = ""
Usr_Guid(0).InnerText = ""
xDoc.Save("User_Loged.xml")
End Sub
Public Sub Usr_Login()
Read_User_Loged_Xml()
If User_Login_Dialog.ShowDialog = DialogResult.OK Then
MsgBox("Starting Login Process Please Waite")
Read_User_Loged_Xml()
If M_User_Login.Usr_Name = String.Empty Or M_User_Login.Ses_ID <= 0 Then
MsgBox("No Previous User Loged")
Close_All_terminal_Sessions()
'De activate all terminal Session if any
'
If User_Login_Dialog.Tx_User.Text <> "" And User_Login_Dialog.Tx_Password.Text <> "" Then
MsgBox("1st Loging in Please waite")
Try
Dim StProc As String
Core.DbCon.Close()
Core.DbCon.Open()
StProc = "Sec.usp_Login"
Dim DbConCmd As New SqlClient.SqlCommand(StProc, Core.DbCon)
DbConCmd.CommandType = CommandType.StoredProcedure
With DbConCmd.Parameters 'Core.DbConCmd.Parameters
.Add("@User_ID", SqlDbType.Int, 10)
DbConCmd.Parameters("@User_ID").Direction = ParameterDirection.Output
.AddWithValue("@User_Name", User_Login_Dialog.Tx_User.Text)
.Add("@User_Name_Out", SqlDbType.VarChar, 50)
DbConCmd.Parameters("@User_Name_Out").Direction = ParameterDirection.Output
.AddWithValue("@Password", User_Login_Dialog.Tx_Password.Text)
End With
DbConCmd.ExecuteNonQuery()
If DbConCmd.Parameters("@User_ID").Value Is DBNull.Value Then
MsgBox("User not Found or wrong Password")
Else
M_User_Login.Usr_ID = DbConCmd.Parameters("@User_ID").Value
End If
If DbConCmd.Parameters("@User_Name_Out").Value Is DBNull.Value Then
MsgBox("User not Found or wrong Password")
User_Login_Dialog.ShowDialog()
Else
M_User_Login.Usr_Name = DbConCmd.Parameters("@User_Name_Out").Value
MsgBox("Creating User Session Please Waite...")
NewSes()
MsgBox("Write local local user Login XML Please Waite...")
Write_User_Loged_Xml()
End If
Core.DbCon.Close()
Catch ex As Exception
MsgBox("User Login Exception... " & ex.ToString)
Core.DbCon.Close()
End Try
Else
MsgBox("Empty User Name or Password not allowed")
User_Login_Dialog.ShowDialog()
End If
Else
If M_User_Login.Usr_Name = String.Empty Or M_User_Login.Ses_ID <= 0 Then
MsgBox("No prevoise session Logged")
logoff()
Close_All_terminal_Sessions()
'De activate all Terminal Sessions"
ElseIf M_User_Login.Ses_ID > 0 Then
If User_Login_Dialog.Tx_User.Text = "" Or User_Login_Dialog.Tx_Password.Text = "" Then
MsgBox("User Name or password is Empty Please Enter User Name and Password")
User_Login_Dialog.ShowDialog()
'End
Else
If M_User_Login.Usr_Name <> User_Login_Dialog.Tx_User.Text Then
MsgBox("User Already Loged in would you like to log off him/Her...")
'Log off current user close all other sessions running on that terminal
If MessageBox.Show("User already Loged in Would you like to logoff Him/Her...", "User Already Loged", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button2) = _
Windows.Forms.DialogResult.Yes Then
'Log off close all active session
'empty user loged xml
'Close all related sessions
logoff()
Log_off_User_Xml()
User_Login_Dialog.ShowDialog()
User_Login_Dialog.Tx_Password.Text = ""
Else
MsgBox("User Canceled the log off action")
End
End If
Else
Step2:
MsgBox("2nd Loging in Please Waite...")
Try
Dim StProc As String
Core.DbCon.Close()
Core.DbCon.Open()
StProc = "Sec.usp_Login"
Dim DbConCmd As New SqlClient.SqlCommand(StProc, Core.DbCon)
DbConCmd.CommandType = CommandType.StoredProcedure
With DbConCmd.Parameters 'Core.DbConCmd.Parameters
.Add("@User_ID", SqlDbType.Int, 10)
DbConCmd.Parameters("@User_ID").Direction = ParameterDirection.Output
.AddWithValue("@User_Name", User_Login_Dialog.Tx_User.Text)
.Add("@User_Name_Out", SqlDbType.VarChar, 50)
DbConCmd.Parameters("@User_Name_Out").Direction = ParameterDirection.Output
.AddWithValue("@Password", User_Login_Dialog.Tx_Password.Text)
End With
DbConCmd.ExecuteNonQuery()
If DbConCmd.Parameters("@User_ID").Value Is DBNull.Value Then
MsgBox("User not Found or wrong Password")
Else
M_User_Login.Usr_ID = DbConCmd.Parameters("@User_ID").Value
End If
If DbConCmd.Parameters("@User_Name_Out").Value Is DBNull.Value Then
MsgBox("User not Found or wrong Password")
User_Login_Dialog.ShowDialog()
GoTo Step2
Else
M_User_Login.Usr_Name = DbConCmd.Parameters("@User_Name_Out").Value
MsgBox("Creating User Session Please Waite...")
NewSes()
MsgBox("Write local local user Login XML Please Waite...")
Write_User_Loged_Xml()
End If
Core.DbCon.Close()
Catch ex As Exception
MsgBox("2nd User Login Exception... " & ex.ToString)
Core.DbCon.Close()
End Try
'Execute Process login
End If
End If
End If
End If
ElseIf User_Login_Dialog.ShowDialog = DialogResult.Cancel Then
End
Else
MsgBox("Closing App")
End If
End Sub
Public Sub Get_Session_Local()
Read_User_Loged_Xml()
If Ses_ID <= 0 Or Usr_Name = String.Empty Then
MsgBox("User or Session ID not Found")
Close_All_terminal_Sessions()
End If
End Sub
Private Sub Get_Sesssion()
End Sub
Public Sub Usr_Logof()
Get_Terminal()
logoff()
Log_off_User_Xml()
Read_User_Loged_Xml()
End Sub
Private Sub All_Trm_Ses_Logoff()
End Sub
Public Sub NewSes()
If Usr_Name = String.Empty Then
Usr_Logof()
All_Trm_Ses_Logoff()
Else
Try
Dim StProc As String
Core.DbCon.Close()
Core.DbCon.Open()
StProc = "Sec.cb_sp_User_Sessions_New"
Dim DbConCmd As New SqlClient.SqlCommand(StProc, Core.DbCon)
DbConCmd.CommandType = CommandType.StoredProcedure
With DbConCmd.Parameters 'Core.DbConCmd.Parameters
.Add("@Session_ID", SqlDbType.Int, 10)
DbConCmd.Parameters("@Session_ID").Direction = ParameterDirection.Output
.AddWithValue("@User_ID", Usr_ID)
.AddWithValue("@Terminal_ID", Terminal_Id)
'.AddWithValue("@Login_Time", )
.AddWithValue("@Active_Session", True)
'.AddWithValue("@Session_GUID", "")
'.AddWithValue("@Logof_Time", "")
End With
DbConCmd.ExecuteNonQuery()
If DbConCmd.Parameters("@Session_ID").Value Is DBNull.Value Then
Else
Ses_ID = DbConCmd.Parameters("@Session_ID").Value
End If
Core.DbCon.Close()
Catch ex As Exception
MsgBox(ex.ToString)
Core.DbCon.Close()
End Try
End If
End Sub
Public Sub CloseSes()
If Ses_ID <= 0 Then
MsgBox("No Active Sesion Found localy...")
Else
Try
Dim StProc As String
Core.DbCon.Close()
Core.DbCon.Open()
StProc = "Sec.cb_sp_User_Sessions_Logoff"
Dim DbConCmd As New SqlClient.SqlCommand(StProc, Core.DbCon)
DbConCmd.CommandType = CommandType.StoredProcedure
With DbConCmd.Parameters 'Core.DbConCmd.Parameters
.AddWithValue("@Session_ID", Ses_ID)
End With
DbConCmd.ExecuteNonQuery()
Core.DbCon.Close()
Catch ex As Exception
MsgBox(ex.ToString)
Core.DbCon.Close()
End Try
End If
End Sub
Private Sub Close_All_terminal_Sessions()
If Terminal_Id <= 0 Then
MsgBox("Getting Terminal ID...Please Waite")
Get_Terminal()
Else
Try
Dim StProc As String
Core.DbCon.Close()
Core.DbCon.Open()
StProc = "Sec.cb_sp_LogOff_AllTerminals"
Dim DbConCmd As New SqlClient.SqlCommand(StProc, Core.DbCon)
DbConCmd.CommandType = CommandType.StoredProcedure
With DbConCmd.Parameters 'Core.DbConCmd.Parameters
.AddWithValue("@Terminal_ID", Terminal_Id)
End With
DbConCmd.ExecuteNonQuery()
Core.DbCon.Close()
Catch ex As Exception
MsgBox(ex.ToString)
Core.DbCon.Close()
End Try
End If
End Sub
Private Sub Get_Terminal()
Dim xDoc As XmlDocument = New XmlDocument()
Dim Trm_ID_Str As String
xDoc.Load("Terminal_Config.xml")
Dim TrmID As XmlNodeList = xDoc.GetElementsByTagName("Terminal_Id")
'Dim Trm_Name As XmlNodeList = xDoc.GetElementsByTagName("Terminal_Name")
'Dim Dep_ID As XmlNodeList = xDoc.GetElementsByTagName("Department_ID")
'Dim Dep_Name As XmlNodeList = xDoc.GetElementsByTagName("Department_Name")
'Dim Trm_Cert As XmlNodeList = xDoc.GetElementsByTagName("Terminal_Cert")
'Dim Trm_Expiry As XmlNodeList = xDoc.GetElementsByTagName("Expiry")
Trm_ID_Str = TrmID(0).InnerText
Try
Terminal_Id = Convert.ToInt32(Trm_ID_Str)
Catch ex As Exception
MsgBox("Get Terminal.... " & ex.Message)
End Try
If Terminal_Id <= 0 Then
MsgBox("Terminal Not Registered Please Contact your System Administrator")
End
End If
End Sub
Private Sub logoff()
MsgBox("Loging off Session Please waite...")
If Ses_ID <= 0 Then
MsgBox("No local Running Session Found...")
Else
Try
Dim StProc As String
Core.DbCon.Close()
Core.DbCon.Open()
StProc = "Sec.cb_sp_User_Sessions_Logoff"
Dim DbConCmd As New SqlClient.SqlCommand(StProc, Core.DbCon)
DbConCmd.CommandType = CommandType.StoredProcedure
With DbConCmd.Parameters 'Core.DbConCmd.Parameters
.AddWithValue("@Session_ID", M_User_Login.Ses_ID)
End With
DbConCmd.ExecuteNonQuery()
Core.DbCon.Close()
Catch ex As Exception
MsgBox("Logging off Error ..." & ex.ToString)
Core.DbCon.Close()
End Try
End If
End Sub
Public Sub Btn_Login(ByVal MyLoginBtn As DevComponents.DotNetBar.ButtonItem)
If MyLoginBtn.Text = "" Or MyLoginBtn.Text = "log Me: " Then
If Check_Login() = True Then
MyLoginBtn.Text = "Logoff: " & M_User_Login.Usr_Name
Else
Usr_Login()
MyLoginBtn.Text = "Logoff: " & M_User_Login.Usr_Name
End If
Else
Usr_Logof()
MyLoginBtn.Text = "log Me: "
End If
End Sub
Public Sub lb_Login(ByRef Login_Lebel As Label)
End Sub
Public Function Check_Login() As Boolean
If Usr_Name <> String.Empty And Ses_ID > 0 Then
Check_Login = True
End If
End Function
End Module
No comments:
Post a Comment