Module SQL_考勤系統
    Friend Sub SQL_人員薪資資料()
        ConnOpen()
        SQL1 = "SELECT   ras_Users.DIN AS [No.], ras_Users.DIN AS 編號, ras_Users.UserName AS 姓名, 使用者權限管理表.CC18 AS 時薪人員, 
                         使用者權限管理表.月薪, 使用者權限管理表.時薪, 使用者權限管理表.主管加級, 使用者權限管理表.職務加級, 
                         使用者權限管理表.勞保費, 使用者權限管理表.健保費, 使用者權限管理表.到職日
                FROM     ras_Users INNER JOIN 使用者權限管理表 ON ras_Users.DIN = 使用者權限管理表.DIN
                WHERE    IsLockedOut = 0 AND ras_Users.DIN NOT LIKE '18' AND ras_Users.DIN NOT LIKE '19' AND 
                         ras_Users.DIN NOT LIKE '21' AND ras_Users.DIN NOT LIKE '90'
                ORDER BY 編號"
        CmdSet_For_DGV()
    End Sub
    Friend Sub SQL_考勤明細表_人員()
        ConnOpen()
        SQL1 = "SELECT     ras_Users.DIN AS [No.], ras_Users.DIN AS 編號, ras_Users.UserName AS 姓名, 使用者權限管理表.CC18, 
                           使用者權限管理表.月薪, 使用者權限管理表.時薪, 使用者權限管理表.主管加級, 使用者權限管理表.職務加級, 
                           使用者權限管理表.勞保費, 使用者權限管理表.健保費, 使用者權限管理表.到職日
                FROM       ras_Users INNER JOIN
                           使用者權限管理表 ON ras_Users.DIN = 使用者權限管理表.DIN
                WHERE     (ras_Users.IsLockedOut = 0) AND (ras_Users.DIN NOT LIKE '999') AND (ras_Users.DIN NOT LIKE '18') AND 
                          (ras_Users.DIN NOT LIKE '19') AND (ras_Users.DIN NOT LIKE '21')
                ORDER BY   編號"
        CmdSet_For_DGV()
    End Sub
    Friend Sub SQL_考勤明細表_月份考勤()  '8、9、11、12、14、15
        ConnOpen()
        SQL1 = "SELECT   萬年曆.日期, 萬年曆.星期, AA.請假類別 AS 休假類別, AA.事由 AS 假期內容, AA.是否生效, AA.核准人, AA.核准日期, 
                         萬年曆.星期 AS 班別判斷, 萬年曆.星期 AS 一段上班, 萬年曆.星期 AS 一段下班, 萬年曆.星期 AS 休息1, 
                         萬年曆.星期 AS 二段上班, 萬年曆.星期 AS 二段下班, 萬年曆.星期 AS 休息2, 萬年曆.星期 AS 加班上班, 
                         萬年曆.星期 AS 加班下班, 萬年曆.星期 AS 一段工時, 萬年曆.星期 AS 二段工時, 萬年曆.星期 AS 加班工時, 
                         萬年曆.星期 AS 一段加班, 萬年曆.星期 AS 二段加班, QQ.半天, QQ.班別, 萬年曆.下診 AS 最後下診, 
                         BB.申請狀態, BB.加班狀態, AA.申請時數
                FROM     萬年曆 LEFT OUTER JOIN
                        (SELECT 排班資料表.日期, 排班資料表.項次, 排班資料表.姓名, 排班資料表.班別, 排班資料表.上班時段, 
                                排班資料表.時數, 排班資料表.半天, 排班資料表.休息, 排班資料表.一段, 排班資料表.二段, 
                                排班資料表.排時, ras_Users.DIN
                         FROM 排班資料表 INNER JOIN ras_Users ON 排班資料表.姓名 = ras_Users.UserName
                         WHERE (排班資料表.日期 LIKE N'" & PA1 & "/" & PA2 & "%') AND (ras_Users.DIN = " & PA & ")) AS QQ ON 萬年曆.日期 = QQ.日期 LEFT OUTER JOIN
                        (SELECT 員工編號, 日期, 請假類別, 事由, 是否生效, 核准人, 核准日期, 申請時數
                         FROM   人事請假單
                         WHERE (員工編號 LIKE N'" & PA & "') AND (日期 LIKE N'" & PA1 & "/" & PA2 & "%')) AS AA ON 萬年曆.日期 = AA.日期 LEFT OUTER JOIN
                        (SELECT 員工編號, 日期, 加班狀態, 是否生效 AS 申請狀態
                         FROM   加班申請單
                         WHERE (員工編號 LIKE N'" & PA & "') AND (日期 LIKE N'" & PA1 & "/" & PA2 & "%')) AS BB ON 萬年曆.日期 = BB.日期
                WHERE   (萬年曆.日期 LIKE N'" & PA1 & "/" & PA2 & "%')
                ORDER BY 萬年曆.日期"
        CmdSet_For_DGV()
    End Sub
    Friend Sub SQL_考勤明細表_考勤流水()
        ConnOpen()
        SQL1 = "SELECT   ID AS [No.], ID, CONVERT(varchar(100), Clock, 120) AS 打卡時間
                FROM     ras_AttRecord
                WHERE   (DIN = " & PA & ") AND (MONTH(Clock) = N'" & PA2 & "') AND (YEAR(Clock) = N'" & PA1 & "')
                ORDER BY Clock"
        CmdSet_For_DGV()
    End Sub
    Friend Sub SQL_考勤明細表_班別()
        ConnOpen()
        SQL1 = "SELECT ID, 時段, 上午上班, 一段休息, 下午上班, 二段休息, 加班上班, 時段1, 時段2, 時段3, 時段4, 時段5, 時段6, 時段7, 時段8 
                FROM  時段設定 WHERE ID > 0 ORDER BY ID"
        CmdSet_For_DGV()
    End Sub
    Friend Sub SQL_考勤明細表_打卡讀取_上午上班()
        ConnOpen()
        SQL1 = "SELECT    CONVERT(varchar(100), Clock, 24) AS 打卡時間, CONVERT(varchar(10), Clock, 111) AS 日期
                FROM      ras_AttRecord
                WHERE    (DIN = " & PA & ") AND (MONTH(Clock) = N'" & PA2 & "') AND (YEAR(Clock) = N'" & PA1 & "') AND 
                         (CAST(Clock AS TIME) >= '05:00:00')
                ORDER BY  Clock"
        CmdSet_For_DGV()
        'SQL1 = "WHERE   (DIN = " & PA & ") AND (DAY(Clock) = N'" & PA3 & "') AND (MONTH(Clock) = N'" & PA2 & "') AND (YEAR(Clock) = N'" & PA1 & "') AND 
        '                (Clock >= N'" & PA1 & "/" & PA2 & "/" & PA3 & " 05:00:00')"
    End Sub
    Friend Sub SQL_考勤明細表_打卡讀取_中午下上班()
        ConnOpen()
        SQL1 = "SELECT    CONVERT(varchar(100), Clock, 24) AS 打卡時間, CONVERT(varchar(10), Clock, 111) AS 日期
                FROM      ras_AttRecord
                WHERE    (DIN = " & PA & ") AND (MONTH(Clock) = N'" & PA2 & "') AND (YEAR(Clock) = N'" & PA1 & "') AND 
                         (CAST(Clock AS TIME) <= '23:59:59')
                ORDER BY  Clock"
        CmdSet_For_DGV()
        'SQL1 = "WHERE    (DIN = " & PA & ") AND (DAY(Clock) = N'" & PA3 & "') AND (MONTH(Clock) = N'" & PA2 & "') AND (YEAR(Clock) = N'" & PA1 & "') AND 
        '                 (Clock < N'" & PA1 & "/" & PA2 & "/" & PA3 & " 23:59:59' AND Clock >= N'" & PA1 & "/" & PA2 & "/" & PA3 & " " & DTPS(0) & "')"
    End Sub
    Friend Sub SQL_考勤明細表_打卡讀取_晚上下上班()
        ConnOpen()
        SQL1 = "SELECT   CONVERT(varchar(100), Clock, 24) AS 打卡時間, CONVERT(varchar(10), Clock, 111) AS 日期
                FROM     ras_AttRecord
                WHERE   (DIN = " & PA & ") AND (DAY(Clock) = N'" & PA3 & "') AND (MONTH(Clock) = N'" & PA2 & "') AND (YEAR(Clock) = N'" & PA1 & "') AND 
                        (Clock < N'" & PA1 & "/" & PA2 & "/" & PA3 & " " & DTPS(3) & "' AND Clock >= N'" & PA1 & "/" & PA2 & "/" & PA3 & " " & DTPS(2) & "')
                ORDER BY Clock"
        CmdSet_For_DGV()
    End Sub
    Friend Sub SQL_考勤明細表_打卡讀取_加班下班()
        ConnOpen()
        SQL1 = "SELECT   CONVERT(varchar(100), Clock, 24) AS 打卡時間, CONVERT(varchar(10), Clock, 111) AS 日期
                FROM     ras_AttRecord
                WHERE   (DIN = " & PA & ") AND (Clock < N'" & PA4 & " 05:00:00' AND Clock >= N'" & PA1 & "/" & PA2 & "/" & PA3 & " " & DTPS(4) & "')
                ORDER BY Clock"
        CmdSet_For_DGV()
    End Sub
    Friend Sub SQL_考勤明細表_年份_下拉()
        ConnOpen() : SQL1 = "SELECT  年份 FROM 年份清單 ORDER BY 年份 DESC" : CmdSet_For_dr()
    End Sub
    Friend Sub SQL_考勤明細表_讀取編號()
        ConnOpen()
        SQL1 = "SELECT DIN FROM ras_Users WHERE (UserName LIKE N'" & gUserName & "')"
        CmdSet_For_dr()
    End Sub
    Friend Sub SQL_讀取日期()
        ConnOpen()
        SQL1 = "SELECT 日期, 星期 FROM 萬年曆 WHERE   日期 LIKE N'" & PA1 & "/" & PA2 & "%' ORDER BY 日期"
        CmdSet_For_DGV()
    End Sub
    Friend Sub SQL_時間新增()
        ConnOpen()
        SQL1 = "INSERT INTO ras_AttRecord (DN, DIN, Clock, VerifyMode, Action, AttTypeId, CollectDate, JobCode, Antipassback, LastUpdatedUID, 
                            LastUpdatedDate, Remark) 
                VALUES ('1', N'" & PA4 & "', N'" & PA3 & "', N'0', N'1', N'H01', N'" & Today() & "', 0, 0, 0, " & Today() & ", N'')"
        CmdSet_For_dr()
    End Sub
    Friend Sub SQL_時間修改()
        ConnOpen()
        SQL1 = "UPDATE ras_AttRecord SET Clock = N'" & PA3 & "' WHERE ID = " & PA4 & ""
        CmdSet_For_dr()
    End Sub
    Friend Sub SQL_時間刪除()
        ConnOpen()
        SQL1 = "DELETE ras_AttRecord  WHERE ID = " & PA4 & ""
        CmdSet_For_dr()
    End Sub
    Friend Sub SQL_資料庫選擇()
        ConnOpen() : SQL1 = "SELECT  TOP (1) 圖片資料庫  FROM  圖片資料庫管理  WHERE  (是否可用 = 0)  ORDER BY  圖片資料庫" : CmdSet_For_dr()
    End Sub
End Module
