主要作用
实现早上电脑弹屏提醒做系统签入操作,下班后弹屏提醒做系统签出操作
' 如果是早上上班前,则返回0
' 如果是下午下班后,则返回1
' 如果是上班中,则返回-1
CONST BEFORE_GO_TO_WORKING = 0
CONST AFTER_WORK = 1
CONST WORKING = -1
' 上班的时间 H时 M分
CONST WORKING_H = 9
CONST WORKING_M = 30
' 下班的时间 H时 M分
CONST AFTER_WORK_H = 18
CONST AFTER_WORK_M = 0
' 配置文件路径
CONST CONFIG_FILE_PATH = ".\task.config"
' 配置文件中的属性值
CONST DATENOW = "DATENOW"
CONST CHECKIN = "CHECKIN"
CONST CHECKIN_TIME = "CHECKIN_TIME"
CONST CHECKOUT = "CHECKOUT"
CONST CHECKOUT_TIME = "CHECKOUT_TIME"
' Utils Function
Public Function Get_Date_Now()
Get_Date_Now = Year(NOW)&Month(NOW)&Day(NOW)
End Function
Public Function Get_Now_Timestamp()
Get_Now_Timestamp = DateDiff("s", "01/01/1970 08:00:00", Now())
End Function
' End Utils Function
' Methods
Public Function IsWorking()
Dim hNow, mNow, result
hNow = Hour(Now)
mNow=Minute(Now)
if (hNow <= WORKING_H and mNow <= WORKING_M) then
IsWorking = BEFORE_GO_TO_WORKING
else
if hNow >= AFTER_WORK_H then
IsWorking = AFTER_WORK
else
IsWorking = WORKING
end if
end if
End Function
Public Function Get_Config()
Dim FOS, OPF, COPF, objDict
Set FOS = WScript.CreateObject("Scripting.FileSystemObject")
Set objDict = WScript.CreateObject("Scripting.Dictionary")
if NOT FOS.fileExists(CONFIG_FILE_PATH) then
Set COPF = FOS.OpenTextFile(CONFIG_FILE_PATH, 2, true)
COPF.Writeline DATENOW & "=" & Get_Date_Now()
COPF.WriteLine CHECKIN & "=" & false
COPF.WriteLine CHECKIN_TIME & "=" & 0
COPF.WriteLine CHECKOUT & "=" & false
COPF.WriteLine CHECKOUT_TIME & "=" & 0
COPF.Close()
Set COPF = nothing
end if
Set OPF = FOS.OpenTextFile(CONFIG_FILE_PATH, 1, false)
Dim isReadOver, tempArr
isReadOver = false
do
tempArr = Split(OPF.ReadLine(), "=")
if UBound(tempArr) >= 1 then
objDict.add tempArr(0), tempArr(1)
end if
isReadOver = not OPF.atEndOfStream
Loop While isReadOver
Set Get_Config = objDict
Set FOS = nothing
End Function
Private Function IsCheck()
Dim config, today, H9
Set config = Get_Config()
today = config.Item(DATENOW)
H9 = 60 * 60 * 9 'ss
if today <> Get_Date_Now() then
IsCheck = false
else
if (Hour(Now) <= WORKING_H and Minute(Now) <= WORKING_M) then
IsCheck = config.Item(CHECKIN)
else
if (Hour(Now) >= AFTER_WORK_H and (Get_Now_Timestamp - config.Item(CHECKIN_TIME) >= H9)) then
IsCheck = config.Item(CHECKOUT)
else
IsCheck = true
end if
end if
end if
End Function
Private Function Set_Config(key, value)
Dim FOS, COPF, config, keys, items, i
Set config = Get_Config()
Set FOS = WScript.CreateObject("Scripting.FileSystemObject")
Set COPF = FOS.OpenTextFile(CONFIG_FILE_PATH, 2, true)
If config.Exists(key) then
config.Remove(key)
end if
config.add key, value
keys = config.keys
items = config.items
for i = 0 to config.count - 1
COPF.WriteLine keys(i) & "=" & items(i)
Next
COPF.Close()
Set COPF = nothing
End Function
' End Methods
' Main
Private Sub Form_Load()
Dim str,tm,title
tm = IsWorking()
if tm = WORKING or IsCheck() then
WScript.quit()
end if
if tm = BEFORE_GO_TO_WORKING then
title = "入"
else
title = "出"
end if
Do
str = InputBox("你今天签"&title&"了吗??????"&vbCrLf&"如果签了就输入:签"&title&"了","签"&title,"没签"&title)
Loop While str <> "签"&title&"了"
if tm = BEFORE_GO_TO_WORKING then
Set_Config CHECKIN, true
Set_Config CHECKIN_TIME, Get_Now_Timestamp
else
Set_Config CHECKOUT, true
Set_Config CHECKOUT_TIME, Get_Now_Timestamp
end if
End Sub
' End Main
Form_Load()