Imports System.Web.Security
Public Class frmLogin
 Inherits System.Web.UI.Page

#Region "Classes"
 Private db As New psdWebUtility.clsDatabase
 Private fn As New psdWebUtility.clsFunctions
 Private t As New psdWebUtility.clsTime
 Private d As New psdWebUtility.clsDate
 Private u As New clsUtility
#End Region

#Region "Property "
 Property ppCnnStr() As String
  Get
   ppCnnStr = clsGlobal.vpCnnstr
  End Get
  Set(ByVal value As String)
   clsGlobal.vpCnnstr = value
  End Set
 End Property
 Property ppFNow() As String
  Get
   ppFNow = clsGlobal.vpFNow
  End Get
  Set(ByVal value As String)
   clsGlobal.vpFNow = value
  End Set
 End Property

 Property ppUserId() As Integer
  Get
   ppUserId = clsGlobal.vpUserId
  End Get
  Set(ByVal value As Integer)
   clsGlobal.vpUserId = value
  End Set
 End Property

 Property ppUserTitle() As String
  Get
   ppUserTitle = clsGlobal.vpUserTitle
  End Get
  Set(ByVal value As String)
   clsGlobal.vpUserTitle = value
  End Set
 End Property

 Property ppOrgTitle() As String
  Get
   ppOrgTitle = clsGlobal.vpOrgTitle
  End Get
  Set(ByVal value As String)
   clsGlobal.vpOrgTitle = value
  End Set
 End Property

 Property ppUserProperty() As String
  Get
   ppUserProperty = clsGlobal.vpUserProperty
  End Get
  Set(ByVal value As String)
   clsGlobal.vpUserProperty = value
  End Set
 End Property

#End Region

#Region "Ini"
 Private Function fini() As Boolean

 End Function
#End Region

#Region "Private Code"
 Private Function fValidateForm() As Boolean
  fValidateForm = False
  If Me.fldUserName.Text.Length = 0 Or Me.fldPassWord.Text.Length = 0 Then Exit Function
  fValidateForm = True
 End Function
 Private Function fCheckUser() As Boolean
  fCheckUser = False
  Dim vSql As String = "SELECT user_id,user_title FROM tbl_wg_users "
  vSql += " WHERE user_code='" + Me.fldUserName.Text + "' AND user_identify='" + u.fHashData(Me.fldPassWord.Text) + "' AND wg_id=01 AND is_delete=0 "
  Dim vR As DataRow = db.fSqlDataRow(ppCnnStr, vSql)
  If vR Is Nothing Then Exit Function
  ppUserId = fn.fNumeric(vR("user_id"))
  ppUserTitle = vR("user_title")
  fCheckUser = True
 End Function
#End Region

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  If IsPostBack Then Exit Sub
  fini()
 End Sub

 Protected Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
  Me.lblMsg.Text = ""
  If fValidateForm() Then
   If fCheckUser() Then
    db.pInsertLog(ppCnnStr, ppUserId, ppFNow, 10, 1, Request.UserHostAddress, "")
    Response.Redirect("frmMain.aspx?pTabId=1")
   Else
    Me.fldPassWord.Text = ""
    Me.fldUserName.Text = ""
    Me.lblMsg.Text = "نام کاربري يا کلمه عبور اشتباه است"
   End If
  Else
   Me.lblMsg.Text = "اطلاعات به صورت کامل وارد نشده است"
  End If
 End Sub
End Class