VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form frmCreateUser 
   ClientHeight    =   8595
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   8880
   LinkTopic       =   "Form2"
   MDIChild        =   -1  'True
   ScaleHeight     =   8595
   ScaleWidth      =   8880
   WindowState     =   2  'Maximized
   Begin VB.CommandButton Command2 
      Caption         =   "New"
      Height          =   315
      Left            =   9870
      TabIndex        =   8
      Top             =   3615
      Width           =   900
   End
   Begin VB.CommandButton Command3 
      Appearance      =   0  'Flat
      Caption         =   "&Delete"
      Height          =   315
      Left            =   9870
      TabIndex        =   10
      Top             =   4245
      Width           =   900
   End
   Begin VB.CommandButton Command4 
      Appearance      =   0  'Flat
      Cancel          =   -1  'True
      Caption         =   "&Close"
      Height          =   315
      Left            =   9870
      TabIndex        =   11
      Top             =   4560
      Width           =   900
   End
   Begin VB.CommandButton Command1 
      Appearance      =   0  'Flat
      Caption         =   "&Done"
      Default         =   -1  'True
      Height          =   315
      Left            =   9870
      TabIndex        =   9
      Top             =   3930
      Width           =   900
   End
   Begin VB.Frame Frame2 
      Caption         =   "Previous Records "
      Height          =   3465
      Left            =   1222
      TabIndex        =   12
      Top             =   3525
      Width           =   8580
      Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
         Height          =   3195
         Left            =   135
         TabIndex        =   20
         Top             =   195
         Width           =   8355
         _ExtentX        =   14737
         _ExtentY        =   5636
         _Version        =   393216
         Cols            =   7
         FixedCols       =   0
         RowHeightMin    =   315
         HighLight       =   0
         ScrollBars      =   2
         SelectionMode   =   1
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "User Information"
      Height          =   2145
      Left            =   1215
      TabIndex        =   0
      Top             =   1350
      Width           =   8580
      Begin VB.TextBox txLName 
         Height          =   315
         Left            =   1290
         MaxLength       =   45
         TabIndex        =   1
         Top             =   330
         Width           =   2055
      End
      Begin VB.TextBox txMName 
         Height          =   315
         Left            =   5730
         MaxLength       =   45
         TabIndex        =   3
         Top             =   330
         Width           =   2130
      End
      Begin VB.TextBox txFName 
         Height          =   315
         Left            =   3360
         MaxLength       =   45
         TabIndex        =   2
         Top             =   330
         Width           =   2340
      End
      Begin VB.ComboBox cmbRole 
         Height          =   315
         Left            =   1275
         Style           =   2  'Dropdown List
         TabIndex        =   7
         Top             =   1680
         Width           =   2295
      End
      Begin VB.TextBox txRePasswd 
         Height          =   315
         IMEMode         =   3  'DISABLE
         Left            =   5700
         MaxLength       =   45
         PasswordChar    =   "*"
         TabIndex        =   6
         Top             =   1335
         Width           =   2295
      End
      Begin VB.TextBox txPasswd 
         Height          =   315
         IMEMode         =   3  'DISABLE
         Left            =   1290
         MaxLength       =   45
         PasswordChar    =   "*"
         TabIndex        =   5
         Top             =   1335
         Width           =   2295
      End
      Begin VB.TextBox txLogin 
         Height          =   315
         Left            =   1290
         MaxLength       =   45
         TabIndex        =   4
         Top             =   990
         Width           =   2295
      End
      Begin VB.Label Label8 
         Caption         =   "(Last Name)"
         Height          =   195
         Left            =   1770
         TabIndex        =   26
         Top             =   645
         Width           =   900
      End
      Begin VB.Label Label12 
         Caption         =   "*"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000FF&
         Height          =   150
         Left            =   8070
         TabIndex        =   25
         Top             =   1305
         Width           =   150
      End
      Begin VB.Label Label11 
         Caption         =   "*"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000FF&
         Height          =   150
         Left            =   3645
         TabIndex        =   24
         Top             =   1350
         Width           =   165
      End
      Begin VB.Label Label9 
         Caption         =   "*"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000FF&
         Height          =   105
         Left            =   3645
         TabIndex        =   23
         Top             =   960
         Width           =   180
      End
      Begin VB.Label Label3 
         Caption         =   "*"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000FF&
         Height          =   150
         Left            =   2730
         TabIndex        =   22
         Top             =   630
         Width           =   105
      End
      Begin VB.Label Label2 
         Caption         =   "Role"
         Height          =   195
         Left            =   840
         TabIndex        =   19
         Top             =   1725
         Width           =   375
      End
      Begin VB.Label Label10 
         Caption         =   "Re-enter Password"
         Height          =   195
         Left            =   4260
         TabIndex        =   18
         Top             =   1350
         Width           =   1410
      End
      Begin VB.Label Label7 
         Caption         =   "(Middle Name)"
         Height          =   195
         Left            =   6345
         TabIndex        =   17
         Top             =   660
         Width           =   1035
      End
      Begin VB.Label Label6 
         Caption         =   "(First Name)"
         Height          =   180
         Left            =   4065
         TabIndex        =   16
         Top             =   660
         Width           =   840
      End
      Begin VB.Label Label5 
         Caption         =   "Password"
         Height          =   195
         Left            =   480
         TabIndex        =   15
         Top             =   1380
         Width           =   690
      End
      Begin VB.Label Label4 
         Caption         =   "Login"
         Height          =   195
         Left            =   780
         TabIndex        =   14
         Top             =   1005
         Width           =   435
      End
      Begin VB.Label Label1 
         Caption         =   "Name"
         Height          =   180
         Left            =   765
         TabIndex        =   13
         Top             =   345
         Width           =   495
      End
   End
   Begin VB.Image Image1 
      Height          =   960
      Left            =   0
      Stretch         =   -1  'True
      Top             =   0
      Width           =   12000
   End
   Begin VB.Label Label13 
      Caption         =   "Create User"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   225
      Left            =   5258
      TabIndex        =   27
      Top             =   1050
      Width           =   1365
   End
   Begin VB.Label lblUserSrno 
      Height          =   375
      Left            =   255
      TabIndex        =   21
      Top             =   3450
      Visible         =   0   'False
      Width           =   630
   End
End
Attribute VB_Name = "frmCreateUser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim bNewUser As Boolean '----- to indicate as a new user....



'------------ Create Button ----------
Private Sub Command1_Click()

    '---------- Since a new user is to be created...
    Dim con As ADODB.Connection
    Dim rec As ADODB.Recordset
    
    Set con = modConn.getConnection
    Set rec = New ADODB.Recordset
    
    Dim qry As String
    
    
   If Not fnCheckValidate Then Exit Sub
   
   If bNewUser Then
        If fnChkLogin Then
        qry = "insert into users (" & _
                " user_fname , user_mname, user_lname," & _
                " role, login_name, password, update_user, update_date)" & _
                " values( " & modUtils.fnChkNull(txFName.Text) & ", " & modUtils.fnChkNull(txMName.Text) & "," & _
                modUtils.fnChkNull(txLName.Text) & "," & modUtils.fnChkNull(cmbRole.Text) & "," & modUtils.fnChkNull(txLogin.Text) & ", " & modUtils.fnChkNull(txPasswd.Text) & ",'" & _
                stLogin & "','" & Format(Now, "dd/mm/yyyy") & "')"
        Else
            Exit Sub
        End If
   Else
        qry = ""
        qry = "update users set " & _
              " user_fname =" & modUtils.fnChkNull(txFName.Text) & "," & _
              " user_mname =" & modUtils.fnChkNull(txMName.Text) & "," & _
              " user_lname =" & modUtils.fnChkNull(txLName.Text) & "," & _
              " password   =" & modUtils.fnChkNull(txPasswd.Text) & "," & _
              " role = " & modUtils.fnChkNull(cmbRole.Text) & " " & _
              " where user_id = " & lblUserSrno.Caption
   End If
   con.Execute (qry)

   '---------- now refresh the Flex....
    fnUserFlex
    fnclearUser
  
End Sub

Private Sub Command2_Click()
    Dim i, j As Integer
     For i = 1 To MSFlexGrid1.Rows - 1
        For j = 0 To MSFlexGrid1.Cols - 1
            MSFlexGrid1.Row = i
            MSFlexGrid1.Col = j
            MSFlexGrid1.CellBackColor = vbWhite
        Next
    Next

    fnclearUser
    bNewUser = True '---- since new user to create
    Command1.Caption = "&Add"
End Sub

Private Sub Command3_Click()
'---for delete
 Dim con As ADODB.Connection
    Dim rec As ADODB.Recordset
    Dim cnt, X As Integer
    
    Set con = modConn.getConnection
    Set rec = New ADODB.Recordset
    
    Dim qry As String
    
    If Trim(lblUserSrno.Caption) <> "" Then
      qry = ""
      qry = "delete * from users" & _
           " where user_id = " & lblUserSrno.Caption
      con.Execute qry
    Else
      MsgBox "Please select the user.", vbInformation, "Wrong Selection"
    End If
   
   '------ populate the flex...
    fnUserFlex

    '-------To refresh the data to form
    fnclearUser
    
    '--- set the falg true since next event is as good as form load...
    bNewUser = True
    
    '---- change caption...
    Command1.Caption = "&Add"
    
End Sub

Public Sub Command4_Click()
'--- for close
Unload Me
End Sub

Private Function fnCheckValidate() As Boolean
If Trim(txLName.Text) = "" Then
 MsgBox "Please enter the Last Name", vbInformation, "Insufficient Information"
 txLName.SetFocus
 fnCheckValidate = False
 Exit Function
End If

If Trim(txLogin.Text) = "" Then
 MsgBox "Please enter the Login Name", vbInformation, "Insufficient Information"
 txLogin.SetFocus
 fnCheckValidate = False
 Exit Function
End If

If Trim(txPasswd.Text) = "" Then
 MsgBox "Please enter the Password", vbInformation, "Insufficient Information"
 txPasswd.SetFocus
 fnCheckValidate = False
 Exit Function
End If

If Trim(txRePasswd.Text) = "" Then
 MsgBox "Please enter the Password", vbInformation, "Insufficient Information"
 txRePasswd.SetFocus
 fnCheckValidate = False
 Exit Function
End If

If Trim(txPasswd.Text) <> Trim(txRePasswd.Text) Then
 MsgBox "The Password and Re-entered Password is not matching", vbInformation, "Insufficient Information"
 txPasswd.Text = ""
 txRePasswd.Text = ""
 txPasswd.SetFocus
 fnCheckValidate = False
 Exit Function
End If

fnCheckValidate = True

End Function

Private Sub Form_Activate()
    '--- for shifting between the forms
    Form_GotFocus

    '---- change caption...
    Command1.Caption = "&Add"
End Sub

Private Sub Form_GotFocus()
    '---- Some menu to be disabled 'n some enabled...
    '---- Some menu to be disabled...
    Call fnMenu(False, False, True, False, False)
    
    '--- active form ..
    stActiveForm = "createUser"
    
    '--- set caption
    fnMDICaption ("Estimation Module - Create User")
End Sub

Private Sub Form_Load()
    '---set the logo image
    Image1.Picture = LoadPicture(fnGetImg)
    
    '---- Some menu to be disabled 'n some enabled...
    '---- Some menu to be disabled...
    '--- set caption
    Form_GotFocus
    

    '------- setting the flag as false....
    bNewUser = True
    fnclearUser
    '------ populate the flex...
    fnUserFlex
    
End Sub

'----- Purpose : To update the Flex....
Public Function fnUserFlex()
    Dim con As ADODB.Connection
    Dim rec As ADODB.Recordset
    Dim cnt, X As Integer
    
    Set con = modConn.getConnection
    Set rec = New ADODB.Recordset
    
    Dim qry As String
    
    '----clear the flex
    MSFlexGrid1.Clear
    
    qry = ""
    qry = "select count(*) from  users"
    rec.Open qry, con, adOpenDynamic
    If Not rec.EOF Then cnt = rec.Fields(0)
    rec.Close
    
    cnt = IIf(cnt = 1, 2, cnt + 1) '-----default no. of rows in flex grid
    MSFlexGrid1.Rows = cnt

    
    qry = ""
    qry = "select * from  users"
    rec.Open qry, con, adOpenDynamic
    
    X = 1 '---since zeroth row contains column headers
    
    While Not rec.EOF And X < cnt
          MSFlexGrid1.Row = X
          MSFlexGrid1.Col = 0
          MSFlexGrid1.Text = rec.Fields("login_name") & ""

          MSFlexGrid1.Row = X
          MSFlexGrid1.Col = 1
          MSFlexGrid1.Text = rec.Fields("password") & ""

          MSFlexGrid1.Row = X
          MSFlexGrid1.Col = 2
          MSFlexGrid1.Text = rec.Fields("role") & ""

          MSFlexGrid1.Row = X
          MSFlexGrid1.Col = 3
          MSFlexGrid1.Text = rec.Fields("user_fname") & ""

          MSFlexGrid1.Row = X
          MSFlexGrid1.Col = 4
          MSFlexGrid1.Text = rec.Fields("user_mname") & ""

          MSFlexGrid1.Row = X
          MSFlexGrid1.Col = 5
          MSFlexGrid1.Text = rec.Fields("user_lname") & ""

          MSFlexGrid1.Row = X
          MSFlexGrid1.Col = 6
          MSFlexGrid1.Text = rec.Fields("user_id") & ""

       rec.MoveNext
       X = X + 1
    Wend
    rec.Close
    MSFlexGrid1.FormatString = "Login Name      |     Password        |     Role        |     First Name       |     Middle Name   |     Last Name         |                     .   "


End Function
Private Sub Form_LostFocus()
    '--- set mdi menu title
    '--- Argument is "" since we r assigning the title at single place
    fnLostMDIChildFocus
End Sub

Private Sub Form_Unload(Cancel As Integer)
    '----- on unload, disable the close menu
    fnUnloadMenu
End Sub

Private Sub MSFlexGrid1_Click()
 Dim i, j, k, iTemp As Integer
  
    MSFlexGrid1.Col = 6
    lblUserSrno.Caption = MSFlexGrid1.Text
    bNewUser = False
    fnFlexUpd

    iTemp = MSFlexGrid1.Row

    '---- clear all the rows
    fnCLearFlex
    
    '---- highligt the selected row....
    MSFlexGrid1.Row = iTemp

    For k = 0 To MSFlexGrid1.Cols - 1
        MSFlexGrid1.Col = k
        MSFlexGrid1.CellBackColor = RGB(170, 185, 253) '---light blue
    Next
    
    '----change the button caption
    If MSFlexGrid1.Text <> "" And Not IsNull(MSFlexGrid1.Text) And Not IsEmpty(MSFlexGrid1.Text) Then
      Command1.Caption = "&Done"
    Else
      Command1.Caption = "&Add"
    End If
End Sub

Public Function fnFlexUpd()
 Dim con As ADODB.Connection
    Dim rec As ADODB.Recordset
 
    
    Set con = modConn.getConnection
    Set rec = New ADODB.Recordset
    
    Dim qry As String
    
    qry = ""
    
    qry = "select * from users " & _
        "where user_id = " & lblUserSrno.Caption
    
         
    rec.Open qry, con, adOpenForwardOnly
    If Not rec.EOF Then
    
        txFName.Text = rec.Fields("user_fname") & ""
        txMName.Text = rec.Fields("user_mname") & ""
        txLName.Text = rec.Fields("user_lname") & ""
        txLogin.Text = rec.Fields("login_name") & ""
        txPasswd.Text = rec.Fields("password") & ""
        txRePasswd.Text = rec.Fields("password") & ""
        cmbRole.Text = rec.Fields("role") & ""

    End If
    rec.Close
   End Function


Private Function fnclearUser()

    txFName.Text = ""
    txMName.Text = ""
    txLName.Text = ""
    txLogin.Text = ""
    txPasswd.Text = ""
    txRePasswd.Text = ""
    cmbRole.ListIndex = 2
    lblUserSrno.Caption = ""

End Function

Public Function fnChkLogin() As Boolean

 Dim con As ADODB.Connection
    Dim rec As ADODB.Recordset


    Set con = modConn.getConnection
    Set rec = New ADODB.Recordset

    Dim qry As String
    Dim login As String
    
    login = txLogin.Text

    
    qry = ""
    qry = "select login_name from users"
    rec.Open qry, con, adOpenForwardOnly
    While Not rec.EOF
        If Trim(login) = Trim(rec.Fields(0)) Then
            rec.Close
            MsgBox "Login Name Already Exists, Please change your login name.", vbCritical, "Login Name Exist"
            fnChkLogin = False
            txLogin.SetFocus
           Exit Function
        End If
        rec.MoveNext
    Wend
        
    '------ INCASE, THE SAME LOGIN NAME NOT FOUND THEN ...
    rec.Close
    fnChkLogin = True

End Function

Private Function fnCLearFlex()
Dim i, j As Integer
    '---clear the color of the flex...
    For i = 1 To MSFlexGrid1.Rows - 1
        For j = 0 To MSFlexGrid1.Cols - 1
            MSFlexGrid1.Row = i
            MSFlexGrid1.Col = j
            MSFlexGrid1.CellBackColor = vbWhite
        Next
    Next

End Function
