⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rptmain.cpp

📁 是我编写的一个考勤机管理系统,用于计算某员工某段时间以来的迟到与早退等情况.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "RptMain.h"
#include "DM.h"
#include "Public.h"
#include <StrUtils.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "DBGridEh"
#pragma resource "*.dfm"
TfrmRptMain *frmRptMain;
//---------------------------------------------------------------------------
__fastcall TfrmRptMain::TfrmRptMain(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TfrmRptMain::LoadData(void)
{
    OpenSQL(QurFree,"select * from Employee");
    CmbEmployee->Text="";
    CmbEmployee->Items->Clear();
    if (QurFree->RecordCount>0)
    {
        QurFree->First();
        while (!QurFree->Eof)
        {
            CEmp = new cEmployee;
            CEmp->iID = QurFree->FieldByName("EmployeeID")->AsInteger ;
            CEmp->sName = QurFree->FieldByName("Name")->AsString ;
            CEmp->sCard = QurFree->FieldByName("Card")->AsString ;
            CmbEmployee->Items->AddObject(CEmp->sName,CEmp );
            QurFree->Next();
        }
        CmbEmployee->Items->Add("<   全部   >");
        CmbEmployee->ItemIndex =CmbEmployee->Items->Count - 1;
    }
}
void __fastcall TfrmRptMain::FormShow(TObject *Sender)
{
    LoadData();
}
//---------------------------------------------------------------------------
void __fastcall TfrmRptMain::BtnQueryClick(TObject *Sender)
{
    FillData(DtpBeginDate->Date,DtpEndDate->Date);
    LoadGrid(GetTimePosCount());
    ShowGrid(DtpBeginDate->Date,DtpEndDate->Date);
}
//---------------------------------------------------------------------------
void __fastcall TfrmRptMain::FormClose(TObject *Sender,
      TCloseAction &Action)
{
    frmRptMain=NULL;
    Action=caFree;
}
//---------------------------------------------------------------------------


void __fastcall TfrmRptMain::LoadGrid(int ATimePosCount)
{
    Grid->FixedCols =1;
    Grid->FixedRows =1;
    Grid->ColWidths[0]=40;
    Grid->RowHeights[0]=20;


    for (int i=0;i<Grid->RowCount;i++)
       Grid->Rows[i]->Clear();


    ATimePosCount=ATimePosCount*2;

    Grid->ColCount=10+ATimePosCount;
    Grid->RowCount=3;
    //Grid->RowCount= (DtpEndDate->Date - DtpBeginDate->Date + 2) * EmployeeArr[0].Length;

    Grid->Cells[1][0]=("日期");
    Grid->Cells[2][0]=("星期");
    Grid->Cells[3][0]=("员工名称");
    Grid->Cells[4][0]=("员工卡号");
    Grid->Cells[5][0]=("应刷卡次数");
    Grid->Cells[6][0]=("迟到早退次数");
    Grid->Cells[7][0]=("旷工次数");
    Grid->Cells[8][0]=("加班次数");
    Grid->Cells[9][0]=("备注");

    int Index=0;
    for (int i=0;i<ATimePosCount;i+=2)
    {
        Index++;
        Grid->Cells[10+i][0]=("时间段"+IntToStr(Index)+"上班");
        Grid->Cells[11+i][0]=("时间段"+IntToStr(Index)+"下班");
    }


}

void __fastcall TfrmRptMain::ShowGrid(TDate ABeginDate, TDate AEndDate)
{
    TDate dBeginDate,dEndDate;

    int iCardCount=0,Index=0,iTimePos=0,iTmpTimePos=0,
        iTimeState=0,iTimeState2=0,LastPos=0,MemoPos=0,AddClassPos=0,
        AbsentPos=0,LatePos=0;

    AnsiString sBeginDate,sEndDate,sInDate,SQL;

    dBeginDate=ABeginDate;
    dEndDate=AEndDate;
    sBeginDate = FormatDateTime("yyyymmdd",ABeginDate);
    sEndDate =  FormatDateTime("yyyymmdd",AEndDate);

    SQL = "select distinct InDate,InCode,InTime from indata where InDate Between '"
             + sBeginDate + "' and '" + sEndDate + "'";

    if (Trim(CmbEmployee->Text)!=""  && Trim(CmbEmployee->Text)!= "<   全部   >")
        SQL = SQL + " and InCode='"
            + ((cEmployee*)(CmbEmployee->Items->Objects[CmbEmployee->Items->IndexOf(CmbEmployee->Text)]))->sCard + "'";

    SQL = SQL + "order by incode,indate,InTime asc";
         //    ((cClass*)(CmbTimePos->Items->Objects[CmbTimePos->Items->IndexOf(CmbTimePos->Text)]))->sCard;
             
    OpenSQL(QurFree,SQL);

    QurFree->First();
    for (int i=0;i<EmployeeArr[0].Length;i++)
    {

        if ( Trim(CmbEmployee->Text)!= "" && Trim(CmbEmployee->Text)!="<   全部   >" && EmployeeArr[i].EmployeeName != Trim(CmbEmployee->Text))
            continue;

       // if (( Trim(CmbEmployee->Text)== "" ) ||
       //    ( Trim(CmbEmployee->Text)!= ""  && EmployeeArr[i].EmployeeName != Trim(CmbEmployee->Text)))
       // {

        dBeginDate=ABeginDate;
        while(dBeginDate <= dEndDate)
        {

            Index=Index+1;

            sInDate=FormatDateTime("yyyy-mm-dd",dBeginDate);
            Grid->Cells[0][Index]=Index;
            Grid->Cells[1][Index]=sInDate;
            Grid->Cells[2][Index]=GetWeek(dBeginDate);
            Grid->Cells[3][Index]=EmployeeArr[i].EmployeeName;
            Grid->Cells[4][Index]=EmployeeArr[i].Card;

            CreateTmpClassID(EmployeeArr[i].Card,dBeginDate);
            iCardCount=CreateTmpClass();

            Grid->Cells[5][Index]=IntToStr(iCardCount);
            Grid->Cells[6][Index]=0;
            Grid->Cells[7][Index]=0;
            Grid->Cells[8][Index]=WAddClassCount;
            Grid->Cells[9][Index]=WRptMemo;



            LastPos=9;
            MemoPos=9;
            AddClassPos=8;
            LatePos=6;
            AbsentPos=7;

            sInDate= MidStr(sInDate, 1, 4) + MidStr(sInDate, 6, 2) + MidStr(sInDate, 9, 2);

            while (!QurFree->Eof)
            {
                if ( EmployeeArr[i].Card != QurFree->FieldByName("InCode")->AsString || sInDate != QurFree->FieldByName("InDate")->AsString ) break;

                if (iCardCount == 0 || iCardCount == -1)
                {
                    QurFree->Next();
                    continue;
                }

///==============================================================================
                iTimePos = GetTimePos(QurFree->FieldByName("InTime")->AsString);

                //==========返回 -1,0 是班次时间出错
                if (iTimePos == -1)
                {
                    // rstGrid.Fields("备注") = "时间段设置有冲突!"
                }
                else if (iTimePos == 0)
                {
                    // rstGrid.Fields("备注") = "时间段设置有冲突!"
                }
                //==========返回奇数是上班时间
                else if (iTimePos % 2 == 1)
                {
                    //===========如果该位置为空,则将时间直接放入
                    if (Trim(Grid->Cells[LastPos+iTimePos][Index])=="")
                    {
                        Grid->Cells[LastPos+iTimePos][Index] = QurFree->FieldByName("InTime")->AsString;
                    }
                    else
                    {
                        iTimeState = GetTimeState(QurFree->FieldByName("InTime")->AsString, iTimePos, 0, 0);
                        if (iTimeState==1 && iTimeState==2)
                        {
                            //===========如果前则为满,后则为空,则放入后则。
                            if (Trim(Grid->Cells[LastPos+iTimePos+1][Index])=="")
                                Grid->Cells[LastPos+iTimePos+1][Index] = QurFree->FieldByName("InTime")->AsString;
                            else
                            {
                                //=======如果前,后则都为满,把后则移置前则,把刷卡时间放入后则。
                                Grid->Cells[LastPos+iTimePos][Index] = Grid->Cells[LastPos+iTimePos+1][Index];
                                Grid->Cells[LastPos+iTimePos+1][Index] = QurFree->FieldByName("InTime")->AsString;
                            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -