VERSION 5.00
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Object = "{00025600-0000-0000-C000-000000000046}#5.2#0"; "Crystl32.OCX"
Begin VB.Form frm_employee 
   AutoRedraw      =   -1  'True
   Caption         =   "Employee"
   ClientHeight    =   7035
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   11880
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MDIChild        =   -1  'True
   ScaleHeight     =   8492.96
   ScaleMode       =   0  'User
   ScaleWidth      =   11880
   WindowState     =   2  'Maximized
   Begin Crystal.CrystalReport CReport 
      Left            =   225
      Top             =   5775
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   348160
      PrintFileLinesPerPage=   60
   End
   Begin VB.PictureBox Picture1 
      BackColor       =   &H80000000&
      BorderStyle     =   0  'None
      Height          =   4950
      Left            =   240
      ScaleHeight     =   4950
      ScaleWidth      =   11340
      TabIndex        =   7
      Top             =   495
      Width           =   11340
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid oGrid 
         Height          =   4875
         Left            =   30
         TabIndex        =   8
         Top             =   30
         Width           =   11280
         _ExtentX        =   19897
         _ExtentY        =   8599
         _Version        =   393216
         Cols            =   6
         FixedCols       =   0
         ForeColorFixed  =   8388608
         BackColorBkg    =   16777215
         WordWrap        =   -1  'True
         TextStyleFixed  =   1
         FocusRect       =   0
         HighLight       =   2
         ScrollBars      =   2
         SelectionMode   =   1
         BorderStyle     =   0
         Appearance      =   0
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty FontFixed {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   9
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         _NumberOfBands  =   1
         _Band(0).Cols   =   6
         _Band(0).GridLinesBand=   1
         _Band(0).TextStyleBand=   0
         _Band(0).TextStyleHeader=   0
      End
   End
   Begin VB.PictureBox Picture2 
      Align           =   2  'Align Bottom
      BackColor       =   &H00800000&
      BorderStyle     =   0  'None
      Height          =   780
      Left            =   0
      ScaleHeight     =   780
      ScaleWidth      =   11880
      TabIndex        =   0
      Top             =   6255
      Width           =   11880
      Begin VB.CommandButton cmdSearch 
         Caption         =   "Find"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   222
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   645
         Left            =   90
         Picture         =   "frm_employee.frx":0000
         Style           =   1  'Graphical
         TabIndex        =   9
         ToolTipText     =   "Find"
         Top             =   75
         Width           =   900
      End
      Begin VB.CommandButton Command5 
         Caption         =   "Report"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   222
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   645
         Left            =   9705
         Picture         =   "frm_employee.frx":08CA
         Style           =   1  'Graphical
         TabIndex        =   4
         ToolTipText     =   "Print List"
         Top             =   75
         Width           =   900
      End
      Begin VB.CommandButton Command1 
         Caption         =   "Add"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   222
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   645
         Left            =   6645
         Picture         =   "frm_employee.frx":1494
         Style           =   1  'Graphical
         TabIndex        =   1
         ToolTipText     =   "Add"
         Top             =   75
         Width           =   900
      End
      Begin VB.CommandButton Command2 
         Caption         =   "Edit"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   222
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   645
         Left            =   7590
         Picture         =   "frm_employee.frx":1D5E
         Style           =   1  'Graphical
         TabIndex        =   2
         ToolTipText     =   "Edit"
         Top             =   75
         Width           =   900
      End
      Begin VB.CommandButton Command3 
         Caption         =   "Delete"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   222
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   645
         Left            =   8535
         Picture         =   "frm_employee.frx":2628
         Style           =   1  'Graphical
         TabIndex        =   3
         ToolTipText     =   "Delete"
         Top             =   75
         Width           =   900
      End
      Begin VB.CommandButton Command4 
         Caption         =   "Close"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   222
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   645
         Left            =   10650
         Picture         =   "frm_employee.frx":2EF2
         Style           =   1  'Graphical
         TabIndex        =   5
         ToolTipText     =   "Exit"
         Top             =   75
         Width           =   900
      End
   End
   Begin VB.Label lblVehicleType 
      BackStyle       =   0  'Transparent
      Caption         =   "List of employee"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   11.25
         Charset         =   222
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00800000&
      Height          =   300
      Left            =   225
      TabIndex        =   6
      Top             =   120
      Width           =   5865
   End
End
Attribute VB_Name = "frm_employee"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long

Private Sub LocateForEmployee()
    Dim n_loop As Integer
    Dim key_column As Integer
    Dim ll_founded As Boolean

    ll_founded = False
    Select Case Trim(g_PopupKey2)
        Case "0"
            key_column = 0
        Case "1"
            key_column = 2
        Case "2"
            key_column = 5
    End Select
    
    For n_loop = 1 To oGrid.Rows - 1
        If Trim(oGrid.TextMatrix(n_loop, key_column)) = g_PopupKey1 Then
            ll_founded = True
            oGrid.Row = n_loop
            oGrid.SetFocus
            SendKeys "{LEFT}"
            Exit For
        End If
    Next n_loop
    
    If ll_founded = False Then
        MsgBox "No record matching criteria specified.", vbInformation, "Search"
    End If

End Sub

Private Sub cmdSearch_Click()
    frm_SearchEmp.Show vbModal
    
    DoEvents
    
    If g_PopupSucceed = True Then
        Call LocateForEmployee
    End If
End Sub

Private Sub Form_Activate()
    If fEmployee_RefreshFlag Then
        Call Format_Grid
        DoEvents
        Call QueryData
        fEmployee_RefreshFlag = False
    End If
    oGrid.SetFocus
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyEscape Then
        Unload Me
    End If
End Sub

Private Sub Command1_Click()
    Call Add_Record
End Sub

Private Sub Command2_Click()
    Call Edit_Record
End Sub

Private Sub Command3_Click()
    Call Delete_Record
End Sub

Private Sub Command4_Click()
    Unload Me
End Sub

Private Sub Add_Record()
    fEmployee_Mode = "add"
    frm_employee_Entry.Show
End Sub

Private Sub Edit_Record()
    If Trim(oGrid.TextMatrix(oGrid.Row, 0)) = "" Then
        MsgBox "Please select a record you want to edit.", vbInformation, "Edit Data"
    Else
        fEmployee_Mode = "edit"
        fEmployee_SelectedKey1 = Trim(oGrid.TextMatrix(oGrid.Row, 0))
        frm_employee_Entry.Show
    End If
End Sub

Private Sub Delete_Record()
    If Trim(oGrid.TextMatrix(oGrid.Row, 0)) = "" Then
        MsgBox "Please select a record you want to delete.", vbInformation, "Delete Data"
    Else
        If UCase(Trim(gUserId)) = UCase(Trim(oGrid.TextMatrix(oGrid.Row, 0))) Then
            MsgBox "Can not delete your own information.", vbExclamation, "WSC"
        Else
            fEmployee_Mode = "delete"
            fEmployee_SelectedKey1 = Trim(oGrid.TextMatrix(oGrid.Row, 0))
            frm_employee_Entry.Show
        End If
    End If
End Sub

Private Sub Format_Grid()
    With oGrid
        .ClearStructure
        .Cols = 6
        .Rows = 2
        .FixedCols = 0
        .FixedRows = 1
        .RowHeight(0) = 400
        
        .ColWidth(0) = 1400
        .ColWidth(1) = 5200
        .ColWidth(2) = 1200
        .ColWidth(3) = 1200
        .ColWidth(4) = 2000
        .ColWidth(5) = 0
        
        .TextMatrix(0, 0) = "Code"
        .TextMatrix(0, 1) = "Name/Surname"
        .TextMatrix(0, 2) = "Initial"
        .TextMatrix(0, 3) = "Nick Name"
        .TextMatrix(0, 4) = "Position"
        
        .ColAlignmentFixed(0) = flexAlignCenterCenter
        .ColAlignmentFixed(1) = flexAlignCenterCenter
        .ColAlignmentFixed(2) = flexAlignCenterCenter
        .ColAlignmentFixed(3) = flexAlignCenterCenter
        .ColAlignmentFixed(4) = flexAlignCenterCenter
    
        .ColAlignment(0) = flexAlignLeftCenter
        .ColAlignment(1) = flexAlignLeftCenter
        .ColAlignment(2) = flexAlignCenterCenter
        .ColAlignment(3) = flexAlignCenterCenter
        .ColAlignment(4) = flexAlignCenterCenter
        .HighLight = flexHighlightWithFocus
        
        ' to make grid full screen display
'        .Height = frm_MDI_main.Height - .Top - frm_MDI_main.Picture1.Height
    End With
End Sub

Private Sub QueryData()
    Dim rs As New ADODB.Recordset
    Dim cSql As String
    
    On Error GoTo Local_Error
    cSql = ""
    cSql = cSql & "SELECT * "
    cSql = cSql & "FROM empmaster "
    cSql = cSql & "Where 1=1 "
'    cSql = cSql & "ORDER BY UserId "
    
    If rs.State = adStateOpen Then rs.Close
    rs.Open cSql, gConn, adOpenForwardOnly
    
    If Not rs.EOF Then
        rs.Sort = "empid"
        rs.MoveFirst
        Do Until rs.EOF
            If oGrid.Rows <= rs.AbsolutePosition Then oGrid.Rows = oGrid.Rows + 1
            oGrid.TextMatrix(rs.AbsolutePosition, 0) = Trim(CVL(rs!empid))
            oGrid.TextMatrix(rs.AbsolutePosition, 1) = Trim(CVL(rs!thaifname)) & " " & Trim(CVL(rs!thailname))
            oGrid.TextMatrix(rs.AbsolutePosition, 2) = Trim(CVL(rs!iname))
            oGrid.TextMatrix(rs.AbsolutePosition, 3) = Trim(CVL(rs!nickname))
            oGrid.TextMatrix(rs.AbsolutePosition, 4) = Trim(CVL(rs!cur_position))
            oGrid.TextMatrix(rs.AbsolutePosition, 5) = Trim(CVL(rs!thaifname))
            rs.MoveNext
        Loop
        oGrid.HighLight = flexHighlightAlways
    Else
        oGrid.HighLight = flexHighlightNever
    End If
    GoTo Exit_Sub

Local_Error:
   MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error"
   
Exit_Sub:
    If rs.State = adStateOpen Then rs.Close
    Set rs = Nothing
End Sub

Private Sub Form_Load()
    fEmployee_RefreshFlag = True
End Sub

Private Sub Command5_Click()
    If DocumentExists() Then
'        Call Print_Report
        frm_PrintReport.Show vbModal
        If g_PopupSucceed Then
            If g_PopupKey2 = "1" Then
                Call Print_List
            Else
               If g_PopupKey2 = "2" Then
                 Call Print_Profile
               Else
                 frm_SubPrint.Show vbModal
                 Call PrintReportZ
               End If
            End If
        End If
    Else
        MsgBox "There is no document to print", vbExclamation, "WSC"
'        Text1.SetFocus
    End If
End Sub
Private Sub PrintReportZ()
    Dim cSql As String
    Dim cDataFile As String
    
    Dim rs As New ADODB.Recordset
    Dim hWndCrystalWindow As Long

    cDataFile = GetINI("LOCATION", "DATAFILE", "", App.Path & "\" & GLOBAL_INIFILE)

    With CReport
        .Connect = gConn
        .DataFiles(0) = cDataFile
        .SelectionFormula = Trim(g_PopupKey1)
        ' .SQLQuery = cSql
        .WindowState = crptMaximized
        .Destination = crptToWindow
'        .Destination = crptToPrinter
        .ReportFileName = App.Path & "\Reports\" & "Resigned List.rpt"
        .Action = 1
    End With
    
'    Wait until the preview window is closed
    hWndCrystalWindow = GetActiveWindow()
    While (IsWindow(hWndCrystalWindow) = 1)
        DoEvents
    Wend
    
    If rs.State = adStateOpen Then rs.Close
    Set rs = Nothing
End Sub

Private Function DocumentExists() As Boolean
    Dim rs As New ADODB.Recordset
    Dim cSql As String

    On Error GoTo Err_Exit
    DocumentExists = False
    
    cSql = ""
    cSql = cSql & " select * "
    cSql = cSql & " from empmaster  "
    cSql = cSql & " WHERE 1=1 "

    If rs.State = adStateOpen Then rs.Close
    rs.Open cSql, gConn
    
    If Not rs.EOF Then
        DocumentExists = True
    End If
    GoTo Exit_Func

Err_Exit:
    MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error"

Exit_Func:
    If rs.State = adStateOpen Then rs.Close
    Set rs = Nothing
End Function

Private Sub Print_List()
    Dim cSql As String
    Dim cDataFile As String
    
    Dim rs As New ADODB.Recordset
    Dim hWndCrystalWindow As Long

    cDataFile = GetINI("LOCATION", "DATAFILE", "", App.Path & "\" & GLOBAL_INIFILE)
    
    With CReport
        .Connect = gConn
        .DataFiles(0) = cDataFile
        .SelectionFormula = Trim(g_PopupKey1)
        ' .SQLQuery = cSql
        .WindowState = crptMaximized
        .Destination = crptToWindow
'        .Destination = crptToPrinter
        .ReportFileName = App.Path & "\Reports\" & "EmployeeList.rpt"
        .Action = 1
    End With
    
'    Wait until the preview window is closed
    hWndCrystalWindow = GetActiveWindow()
    While (IsWindow(hWndCrystalWindow) = 1)
        DoEvents
    Wend
    
    If rs.State = adStateOpen Then rs.Close
    Set rs = Nothing
End Sub

Private Sub Print_Profile()
    Dim cSql As String
    Dim cDataFile As String
    
    Dim rs As New ADODB.Recordset
    Dim hWndCrystalWindow As Long

    cDataFile = GetINI("LOCATION", "DATAFILE", "", App.Path & "\" & GLOBAL_INIFILE)

    With CReport
        .Connect = gConn
        .DataFiles(0) = cDataFile
        .SelectionFormula = Trim(g_PopupKey1)
        ' .SQLQuery = cSql
        .WindowState = crptMaximized
        .Destination = crptToWindow
'        .Destination = crptToPrinter
        .ReportFileName = App.Path & "\Reports\" & "EmployeeProfile.rpt"
        .Action = 1
    End With
    
'    Wait until the preview window is closed
    hWndCrystalWindow = GetActiveWindow()
    While (IsWindow(hWndCrystalWindow) = 1)
        DoEvents
    Wend
    
    If rs.State = adStateOpen Then rs.Close
    Set rs = Nothing
End Sub

