VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmUser 
   BackColor       =   &H00808080&
   Caption         =   "Usuários"
   ClientHeight    =   7020
   ClientLeft      =   3825
   ClientTop       =   5160
   ClientWidth     =   10200
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   468
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   680
   Begin VB.PictureBox picDataholder 
      Align           =   4  'Align Right
      Height          =   6270
      Left            =   6630
      ScaleHeight     =   6210
      ScaleWidth      =   3510
      TabIndex        =   14
      Top             =   420
      Width           =   3570
      Begin VB.TextBox txtData 
         Height          =   285
         Index           =   6
         Left            =   1800
         TabIndex        =   2
         Top             =   1170
         Width           =   1635
      End
      Begin VB.CommandButton cmdUpdate 
         Caption         =   "Gravar"
         Height          =   375
         Left            =   2340
         TabIndex        =   8
         Top             =   4545
         Width           =   1095
      End
      Begin VB.ComboBox cmbData 
         Height          =   315
         ItemData        =   "frmUser.frx":0000
         Left            =   90
         List            =   "frmUser.frx":0002
         TabIndex        =   7
         Text            =   "Combo1"
         Top             =   3960
         Width           =   3345
      End
      Begin VB.TextBox txtData 
         Height          =   285
         Index           =   5
         Left            =   1800
         TabIndex        =   6
         Top             =   3330
         Width           =   1635
      End
      Begin VB.TextBox txtData 
         Height          =   285
         Index           =   4
         Left            =   90
         TabIndex        =   5
         Top             =   3330
         Width           =   1635
      End
      Begin VB.TextBox txtData 
         Height          =   285
         Index           =   3
         Left            =   90
         TabIndex        =   4
         Top             =   2700
         Width           =   3345
      End
      Begin VB.TextBox txtData 
         Height          =   570
         Index           =   2
         Left            =   90
         MultiLine       =   -1  'True
         TabIndex        =   3
         Top             =   1800
         Width           =   3345
      End
      Begin VB.TextBox txtData 
         Height          =   285
         Index           =   1
         Left            =   90
         TabIndex        =   1
         Top             =   1170
         Width           =   1635
      End
      Begin VB.TextBox txtData 
         Height          =   285
         Index           =   0
         Left            =   90
         TabIndex        =   0
         Top             =   540
         Width           =   3345
      End
      Begin VB.Label lblDeco 
         AutoSize        =   -1  'True
         Caption         =   "Data de Nascimento:"
         Height          =   195
         Index           =   7
         Left            =   1845
         TabIndex        =   23
         Top             =   945
         Width           =   1500
      End
      Begin VB.Label lblDeco 
         AutoSize        =   -1  'True
         Caption         =   "Nível:"
         Height          =   195
         Index           =   6
         Left            =   135
         TabIndex        =   22
         Top             =   3735
         Width           =   405
      End
      Begin VB.Label lblDeco 
         AutoSize        =   -1  'True
         Caption         =   "ICQ:"
         Height          =   195
         Index           =   5
         Left            =   1845
         TabIndex        =   21
         Top             =   3105
         Width           =   345
      End
      Begin VB.Label lblDeco 
         AutoSize        =   -1  'True
         Caption         =   "Telefone:"
         Height          =   195
         Index           =   4
         Left            =   135
         TabIndex        =   20
         Top             =   3105
         Width           =   690
      End
      Begin VB.Label lblDeco 
         AutoSize        =   -1  'True
         Caption         =   "eMail:"
         Height          =   195
         Index           =   3
         Left            =   135
         TabIndex        =   19
         Top             =   2475
         Width           =   420
      End
      Begin VB.Label lblDeco 
         AutoSize        =   -1  'True
         Caption         =   "Endereço:"
         Height          =   195
         Index           =   2
         Left            =   135
         TabIndex        =   18
         Top             =   1575
         Width           =   735
      End
      Begin VB.Label lblDeco 
         AutoSize        =   -1  'True
         Caption         =   "Nickname:"
         Height          =   195
         Index           =   1
         Left            =   135
         TabIndex        =   17
         Top             =   945
         Width           =   735
      End
      Begin VB.Label lblArt 
         Alignment       =   2  'Center
         BackColor       =   &H00FF8080&
         Caption         =   " Dados do Usuário"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00FFFFFF&
         Height          =   240
         Left            =   0
         TabIndex        =   16
         Top             =   0
         Width           =   3540
      End
      Begin VB.Label lblDeco 
         AutoSize        =   -1  'True
         Caption         =   "Nome:"
         Height          =   195
         Index           =   0
         Left            =   135
         TabIndex        =   15
         Top             =   315
         Width           =   465
      End
   End
   Begin VB.PictureBox picCommandHolder 
      Align           =   1  'Align Top
      BorderStyle     =   0  'None
      Height          =   420
      Left            =   0
      ScaleHeight     =   420
      ScaleWidth      =   10200
      TabIndex        =   9
      Top             =   0
      Width           =   10200
      Begin VB.CommandButton cmdUsuario 
         Caption         =   "Excluir"
         Height          =   420
         Index           =   1
         Left            =   810
         TabIndex        =   13
         Top             =   0
         Width           =   780
      End
      Begin VB.CommandButton cmdUsuario 
         Caption         =   "Incluir"
         Height          =   420
         Index           =   0
         Left            =   0
         TabIndex        =   12
         Top             =   0
         Width           =   780
      End
   End
   Begin MSComctlLib.StatusBar stbMain 
      Align           =   2  'Align Bottom
      Height          =   330
      Left            =   0
      TabIndex        =   10
      Top             =   6690
      Width           =   10200
      _ExtentX        =   17992
      _ExtentY        =   582
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   2
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Alignment       =   1
            AutoSize        =   1
            Object.Width           =   16219
            MinWidth        =   1058
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Alignment       =   1
            Bevel           =   2
            Object.Width           =   1235
            MinWidth        =   1235
            Text            =   "Fechar"
            TextSave        =   "Fechar"
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.ImageList imlGeral 
      Left            =   675
      Top             =   5130
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   19
      ImageHeight     =   14
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   9
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":0004
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":0140
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":027C
            Key             =   ""
         EndProperty
         BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":03B8
            Key             =   ""
         EndProperty
         BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":04F4
            Key             =   ""
         EndProperty
         BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":0630
            Key             =   ""
         EndProperty
         BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":076C
            Key             =   ""
         EndProperty
         BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":08AC
            Key             =   ""
         EndProperty
         BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":09E8
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.ListView lstUsers 
      DragIcon        =   "frmUser.frx":0B24
      Height          =   4200
      Left            =   135
      TabIndex        =   11
      Top             =   585
      Width           =   2175
      _ExtentX        =   3836
      _ExtentY        =   7408
      View            =   3
      LabelEdit       =   1
      MultiSelect     =   -1  'True
      LabelWrap       =   -1  'True
      HideSelection   =   0   'False
      FullRowSelect   =   -1  'True
      _Version        =   393217
      Icons           =   "imlGeral"
      SmallIcons      =   "imlGeral"
      ForeColor       =   -2147483640
      BackColor       =   16777215
      Appearance      =   0
      NumItems        =   3
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Text            =   "Nick"
         Object.Width           =   2117
      EndProperty
      BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   1
         Text            =   "Nome"
         Object.Width           =   2646
      EndProperty
      BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   2
         Text            =   "Idade"
         Object.Width           =   1058
      EndProperty
   End
End
Attribute VB_Name = "frmUser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub cmdUpdate_Click()
On Error GoTo pscmdUpdate_ClickErr 'EHCG.UID.pscmdUpdate_Click

Dim pID As Long, PName As String, pAlias As String, pAdress As String, pEMail As String, pPhone As String, pUIN  As String, pBirth As Date, pClassID As Long
Dim pSQL As String

pID = Val(Me.picDataholder.Tag)
PName = Me.txtData(0)
pAlias = Me.txtData(1)
pAdress = Me.txtData(2)
pEMail = Me.txtData(3)
pPhone = Me.txtData(4)
pUIN = Me.txtData(5)
pBirth = Me.txtData(6)
pClassID = 2

    If pID > 0 Then

        If PName <> "" And pAlias <> "" Then
        pSQL = "UPDATE [user] AS U SET U.alias = '" & pAlias & "', U.Name = '" & PName & "', U.Adress = '" & pAdress & "', U.Phone = '" & pPhone & "', U.eMail = '" & pEMail & "', U.ICQ = " & pUIN & ", U.Birth = #" & CDate(pBirth) & "# WHERE U.ID=" & pID
        End If

    Else

        If PName <> "" And pAlias <> "" Then
        pSQL = "INSERT INTO [user] ( alias, Name, Adress, Phone, eMail, ICQ, User_classID, Birth ) VALUES " & _
        "('" & pAlias & "', '" & PName & "', '" & pAdress & "', '" & pPhone & "', '" & pEMail & "', " & ValidNum(pUIN) & ", " & pClassID & ", '" & pBirth & "')"
        End If

    End If

    If pSQL <> "" Then Data.Database.Execute pSQL

LoadUserList
LoadUserData 0

Exit Sub
pscmdUpdate_ClickErr:
Err.Raise Err.number, Err.Source, "ps.cmdUpdate_Click:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub cmdUsuario_Click(Index As Integer)
On Error GoTo pscmdUsuario_ClickErr 'EHCG.UID.pscmdUsuario_Click

    Select Case Index
    Case 0
    LoadUserData 0

    Case 1
    Call DeleteUser

    End Select

Exit Sub
pscmdUsuario_ClickErr:
Resume
Err.Raise Err.number, Err.Source, "ps.cmdUsuario_Click:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub Form_Load()
On Error GoTo psForm_LoadErr 'EHCG.UID.psForm_Load

Data.UserListLoaded = True
Call LoadUserList
Call LoadLevels

Exit Sub
psForm_LoadErr:
Err.Raise Err.number, Err.Source, "ps.Form_Load:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo psForm_UnloadErr 'EHCG.UID.psForm_Unload

Data.UserListLoaded = False

Exit Sub
psForm_UnloadErr:
Err.Raise Err.number, Err.Source, "ps.Form_Unload:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Sub DeleteUser()
On Error GoTo sDeleteUserErr 'EHCG.UID.sDeleteUser

    If Val(Me.picDataholder.Tag) > 0 Then
    Data.Database.Execute "DELETE FROM [user] WHERE ID = " & Val(Me.picDataholder.Tag)
    End If

LoadUserList
LoadUserData 0

Exit Sub
sDeleteUserErr:
Err.Raise Err.number, Err.Source, "s.DeleteUser:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub lstUsers_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
On Error GoTo pslstUsers_ColumnClickErr 'EHCG.UID.pslstUsers_ColumnClick

    With Me.lstUsers
    .Sorted = True

        If (.SortKey = ColumnHeader.Index - 1) Then

            If .SortOrder <> lvwAscending Then
            .SortOrder = lvwAscending
            Else
            .SortOrder = lvwDescending
            End If

        Else
        .SortOrder = lvwAscending

        End If

    .SortKey = ColumnHeader.Index - 1
    End With

Exit Sub
pslstUsers_ColumnClickErr:
Err.Raise Err.number, Err.Source, "ps.lstUsers_ColumnClick:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub lstUsers_ItemClick(ByVal Item As MSComctlLib.ListItem)
On Error GoTo pslstUsers_ItemClickErr 'EHCG.UID.pslstUsers_ItemClick

    LoadUserData CLng(Right$(Item.Key, Len(Item.Key) - 1))

Exit Sub
pslstUsers_ItemClickErr:
Err.Raise Err.number, Err.Source, "ps.lstUsers_ItemClick:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Sub LoadUserData(ByVal Index As Long)
On Error GoTo sLoadUserDataErr 'EHCG.UID.sLoadUserData

Dim uSQL As String, uRS As Recordset

uSQL = "SELECT U.*, UC.name as [ClassName] FROM user_class AS UC INNER JOIN [user] AS U ON UC.ID = U.user_classID WHERE U.ID = " & Index
Set uRS = Data.Database.Execute(uSQL)

    If Not uRS.EOF Then
    Me.picDataholder.Tag = Index
    Me.txtData(0) = ValidStr(uRS("Name"))
    Me.txtData(1) = ValidStr(uRS("Alias"))
    Me.txtData(2) = ValidStr(uRS("Adress"))
    Me.txtData(3) = ValidStr(uRS("eMail"))
    Me.txtData(4) = ValidStr(uRS("Phone"))
    Me.txtData(5) = ValidStr(uRS("ICQ"))
    Me.txtData(6) = ValidStr(uRS("Birth"))
    Me.cmbData = uRS("ClassName")

    Else
    Me.picDataholder.Tag = ""
    Me.txtData(0) = ""
    Me.txtData(1) = ""
    Me.txtData(2) = ""
    Me.txtData(3) = ""
    Me.txtData(4) = ""
    Me.txtData(5) = ""
    Me.txtData(6) = ""
    Me.cmbData = ""

    End If

Exit Sub
sLoadUserDataErr:
Err.Raise Err.number, Err.Source, "s.LoadUserData:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub lstUsers_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
On Error GoTo pslstUsers_MouseDownErr 'EHCG.UID.pslstUsers_MouseDown

Dim uIndex As String
uIndex = Right$(Me.lstUsers.HitTest(x, y).Key, Len(Me.lstUsers.HitTest(x, y).Key) - 1)

If Err.number <> 0 Then Exit Sub

LoadUserData uIndex

Dim uI As ListItem

    For Each uI In Me.lstUsers.ListItems
    uI.Selected = False
    Next uI

Me.lstUsers.HitTest(x, y).Selected = True
Data.UserOnDrag = uIndex
Me.lstUsers.Drag 1

Exit Sub
pslstUsers_MouseDownErr:
Resume Next

End Sub
Private Sub stbMain_PanelClick(ByVal Panel As MSComctlLib.Panel)
On Error GoTo psstbMain_PanelClickErr 'EHCG.UID.psstbMain_PanelClick

    If Panel.Index = 2 Then
    Unload Me
    End If

Exit Sub
psstbMain_PanelClickErr:
Err.Raise Err.number, Err.Source, "ps.stbMain_PanelClick:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Private Sub Form_Resize()
On Error GoTo psForm_ResizeErr 'EHCG.UID.psForm_Resize

Me.lstUsers.Left = 0
Me.lstUsers.Top = Me.picCommandHolder.Height
Me.lstUsers.Width = Me.ScaleWidth - Me.picDataholder.Width
Me.lstUsers.Height = Me.ScaleHeight - (Me.picCommandHolder.Height + Me.stbMain.Height)

Exit Sub
psForm_ResizeErr:
Err.Raise Err.number, Err.Source, "ps.Form_Resize:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Sub LoadUserList()
On Error GoTo sLoadUserListErr 'EHCG.UID.sLoadUserList

Dim lsSQL As String, loRS As ADODB.Recordset, lobjItem As ListItem

lsSQL = "SELECT U.* FROM User AS U"

Me.lstUsers.ListItems.Clear

Set loRS = Data.Database.Execute(lsSQL)

    Do While Not loRS.EOF
    Set lobjItem = Me.lstUsers.ListItems.Add
    lobjItem.Text = loRS("Alias")
    lobjItem.Key = "U" & loRS("ID")
    lobjItem.SubItems(1) = IIf(IsNull(loRS("Name")), "", loRS("Name"))

        If Not IsNull(loRS("Birth")) Then
        lobjItem.SubItems(2) = Int(DateDiff("m", loRS("Birth"), Date) / 12)
        End If

    lobjItem.SmallIcon = 2

    loRS.MoveNext
    Loop

Set loRS = Nothing

Exit Sub
sLoadUserListErr:
Err.Raise Err.number, Err.Source, "s.LoadUserList:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
Sub LoadLevels()
On Error GoTo sLoadLevelsErr 'EHCG.UID.sLoadLevels

Dim uSQL As String, uRS As Recordset

uSQL = "SELECT * FROM [user_class] UC"
Set uRS = Data.Database.Execute(uSQL)

    If Not uRS.EOF Then
    Me.cmbData.Clear

        Do

            If uRS.EOF Then Exit Do

        Me.cmbData.AddItem uRS("Name")
        Me.cmbData.ItemData(Me.cmbData.ListCount - 1) = uRS("ID")
        uRS.MoveNext
        Loop

    End If

Exit Sub
sLoadLevelsErr:
Err.Raise Err.number, Err.Source, "s.LoadLevels:" & vbCrLf & "Error: " & Err.number & vbCrLf & "Description: " & Err.Description & vbCrLf, Err.HelpFile, Err.HelpContext

End Sub
