VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmMain 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "SmaFinger.Net Event Server"
   ClientHeight    =   4560
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   9435
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4560
   ScaleWidth      =   9435
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdSaveFile 
      Caption         =   "Save Data"
      Height          =   375
      Left            =   120
      TabIndex        =   4
      Top             =   4080
      Width           =   1335
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   9000
      Top             =   2520
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
      CancelError     =   -1  'True
      Filter          =   "*.txt"
   End
   Begin MSComctlLib.ListView lvEvent 
      Height          =   3615
      Left            =   120
      TabIndex        =   1
      Top             =   360
      Width           =   9135
      _ExtentX        =   16113
      _ExtentY        =   6376
      View            =   3
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      FullRowSelect   =   -1  'True
      PictureAlignment=   2
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   4
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Text            =   "Device"
         Object.Width           =   3351
      EndProperty
      BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   1
         Text            =   "Date"
         Object.Width           =   3528
      EndProperty
      BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   2
         Text            =   "ID"
         Object.Width           =   5292
      EndProperty
      BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   3
         Text            =   "Name"
         Object.Width           =   3175
      EndProperty
   End
   Begin MSWinsockLib.Winsock wsListen 
      Left            =   4125
      Top             =   0
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin VB.Label lblTimeZone 
      Height          =   255
      Left            =   8880
      TabIndex        =   3
      Top             =   120
      Width           =   375
   End
   Begin VB.Label Label1 
      Caption         =   "Current PC Time Zone :"
      Height          =   255
      Left            =   7080
      TabIndex        =   2
      Top             =   120
      Width           =   1695
   End
   Begin VB.Label labNetwork 
      Caption         =   "IP/Port : "
      Height          =   255
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   4575
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Declare Function GetTimeZoneInformation Lib "kernel32" _
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

Private Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type

Private Type TIME_ZONE_INFORMATION
    Bias As Long
    StandardName(0 To 63) As Integer ' used to accommodate Unicode strings
    StandardDate As SYSTEMTIME
    StandardBias As Long
    DaylightName(0 To 63) As Integer ' used to accommodate Unicode strings
    DaylightDate As SYSTEMTIME
    DaylightBias As Long
End Type

Private Const TIME_ZONE_ID_INVALID = &HFFFFFFFF
Private Const TIME_ZONE_ID_UNKNOWN = 0
Private Const TIME_ZONE_ID_STANDARD = 1
Private Const TIME_ZONE_ID_DAYLIGHT = 2

Public g_vTimeZone

Private Sub cmdSaveFile_Click()
    Dim sFileName As String
    Dim response As Long

    On Error GoTo ErrExit
        
    sFileName = Format(Date, "MMYYYY")
    CommonDialog1.FileName = sFileName & ".txt"
    CommonDialog1.ShowOpen
        
    Call frmReceiving.SaveData(CommonDialog1.FileName)
    
    response = MsgBox("Press OK for confirm clear records in the List, and store records.", vbOKCancel, "Save Records")
    
    If response = vbOK Then
        lvEvent.ListItems.Clear
    End If
    
    Exit Sub
ErrExit:

End Sub

Private Sub Form_Load()
    Dim lPort As Long
    lPort = FT_USE_PORT
    wsListen.LocalPort = lPort
    On Error Resume Next
    Do
        wsListen.Listen
        If Err.Number <> 0 Then
            Err.Number = 0
            lPort = lPort + 1
            If lPort >= 65535 Then
                Exit Do
            End If
            wsListen.LocalPort = lPort
        Else
            Exit Do
        End If
    Loop
    On Error GoTo 0
    If lPort >= 65535 Then
        labNetwork.Caption = "Cannot find a correct IP/Port for using!!"
    Else
        labNetwork.Caption = "IP/Port : " & wsListen.LocalIP & ":" & wsListen.LocalPort
    End If
    Call TimeZoneJudge
End Sub

Private Sub TimeZoneJudge()
    Dim TZ As TIME_ZONE_INFORMATION
    Dim lRetVal As Long
    Dim sDisplayTimeZoneSymbol As String
    
    lRetVal = GetTimeZoneInformation(TZ)
    
    If lRetVal <> -1 Then
        g_vTimeZone = TZ.Bias / -60
    Else
        g_vTimeZone = 8
        MsgBox "Get Windows Time Zone Information Fail."
    End If
    
    'for Display Time zone.
    If g_vTimeZone < 0 Then
        sDisplayTimeZoneSymbol = " "
    Else
        sDisplayTimeZoneSymbol = "+"
    End If
    lblTimeZone.Caption = sDisplayTimeZoneSymbol & g_vTimeZone
End Sub

Private Sub labNetwork_DblClick()
    Clipboard.SetText wsListen.LocalIP & ":" & wsListen.LocalPort
End Sub

Private Sub wsListen_ConnectionRequest(ByVal requestID As Long)
  ConnectRequest requestID
End Sub
