授人以渔,不授人以鱼。
程序代码:
CLEAR ALL SET DATE ANSI SET CENTURY ON SET SAFETY OFF Main() CLEAR ALL RETURN PROCEDURE Main() LOCAL loForm loForm = CREATEOBJECT("_Form") WITH loForm .Caption = "考勤日报" .WindowState = 2 .Show ENDWITH READ EVENTS ENDPROC *------------------------ * 规范化时间字段 *------------------------ FUNCTION GetCTime(tcTimeString) RETURN IIF(LEN(tcTimeString) < 8, "0", "") + tcTimeString ENDFUNC FUNCTION Have_OutTime LOCAL lnIndex FOR lnIndex = 1 TO FCOUNT("考勤日报表") IF "刷卡记录" $ FIELD(lnIndex, "考勤日报表") IF GetCTime(ALLTRIM(EVALUATE("考勤日报表." + FIELD(lnIndex, "考勤日报表"))) ) > "18:00:00" RETURN .T. ENDIF ENDIF NEXT RETURN .F. ENDFUNC *------------------------ * 求取加班时间 *------------------------ FUNCTION Get_OutTime LOCAL lnIndex, lnPos, lcString, lcStart, lcEnd lnPos = 0 FOR lnIndex = 1 TO FCOUNT("考勤日报表") IF "刷卡记录" $ FIELD(lnIndex, "考勤日报表") IF GetCTime(ALLTRIM(EVALUATE("考勤日报表." + FIELD(lnIndex, "考勤日报表"))) ) > "18:00:00" lnPos = lnIndex EXIT ENDIF ENDIF NEXT lcString = "" IF (lnPos > 0) .AND. (MOD(INT(VAL(RIGHT(FIELD(lnPos, "考勤日报表"), 1))), 2) == 0) lcStart = GetCTime(ALLTRIM(EVALUATE("考勤日报表." + FIELD(lnPos - 1, "考勤日报表")))) IF lcStart < "18:00:00" lcStart = "18:00:00" ENDIF lcEnd = GetCTime(ALLTRIM(EVALUATE("考勤日报表." + FIELD(lnPos, "考勤日报表")))) lcString = Calc_Time(lcStart, lcEnd) ENDIF RETURN lcString ENDFUNC *------------------------ * 求时间差,以小时为单位返回结果 *------------------------ FUNCTION Calc_Time(tcStart, tcEnd) LOCAL lnStart, lnEnd lnStart = INT(VAL(LEFT(tcStart, 2))) * 3600 + INT(VAL(SUBSTR(tcStart, 4, 2))) * 60 + INT(VAL(RIGHT(tcStart, 2))) lnEnd = INT(VAL(LEFT(tcEnd, 2))) * 3600 + INT(VAL(SUBSTR(tcEnd, 4, 2))) * 60 + INT(VAL(RIGHT(tcEnd, 2))) RETURN TRANSFORM(ROUND((lnEnd - lnStart) / 3600, 2)) + "小时" ENDFUNC DEFINE CLASS _Form AS Form ADD OBJECT Label1 AS Label WITH Caption = "日期:", Height = 25, Width = 60, FontBold = .T., Alignment = 1 ADD OBJECT Text1 AS TextBox WITH Value = DATE(), Height = 25, Width = 100 ADD OBJECT Command1 AS CommandButton WITH Caption = "确认", Height = 25, Width = 40 ADD OBJECT Grid1 AS Grid WITH HighlightStyle = 2 PROCEDURE Load USE 考勤日报表 NOUPDATE IN 0 INDEX ON STR(工号, 5) + DTOC(日期) TO 考勤日报表 GOTO TOP ENDPROC PROCEDURE Unload USE IN 考勤日报表 ENDPROC PROCEDURE Destroy CLEAR EVENTS ENDPROC PROCEDURE Arrange WITH This.Label1 .Top = 5 .Left = 5 ENDWITH WITH This.Text1 .Top = This.Label1.Top .Left = This.Label1.Left + This.Label1.Width ENDWITH WITH Top = This.Text1.Top .Left = This.Text1.Left + This.Text1.Width + 2 ENDWITH WITH This.Grid1 .Top = This.Label1.Top + This.Label1.Height + 5 .Left = 5 .Height = This.Height - .Top - 5 .Width = This.Width - .Left - 5 ENDWITH ENDPROC PROCEDURE Activate WITH This .Arrange .Grid1.SetFocus ENDWITH ENDPROC PROCEDURE Resize This.Arrange ENDPROC PROCEDURE Command1.Click WITH This.Parent.Grid1 .Init .SetFocus ENDWITH ENDPROC PROCEDURE Grid1.Init SELECT 考勤日报表 SET FILTER TO (考勤日报表.日期 == This.Parent.Text1.Value) .AND. Have_OutTime() GOTO TOP WITH This .ColumnCount = FCOUNT("考勤日报表") + 1 WITH .Columns(.ColumnCount) .Header1.Caption = "加班时间" .ControlSource = "Get_OutTime()" .Alignment = 1 ENDWITH .SetAll("FontBold", .T., "Header") .SetAll("Alignment", 2, "Header") ENDWITH ENDPROC ENDDEFINE