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

📄 kqjtx.cpp

📁 企业员工考勤和工资管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#include <stdio.h>
#pragma hdrstop

#include "KqjTx.h"
#include "DM1.h"
#include "ShowPb.h"
#include "syris.h"
#include "vtl.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormKqjTx *FormKqjTx;
//---------------------------------------------------------------------------
__fastcall TFormKqjTx::TFormKqjTx(TComponent* Owner)
        : TForm(Owner)
{

}
//---------------------------------------------------------------------------
int pascal TFormKqjTx::FindYgbhId(int CardId)
{
  int nYgbh;
  //if (pCard->Active == false) return -1;
  TLocateOptions Opts;
  Opts.Clear();
  if (pCard->Locate("CardID",CardId,Opts))
  {
    nYgbh = pCard->FieldByName("HolderNo")->AsInteger;
    return nYgbh;
  }
  else
  {
    return -1;
  }

}

//--------------------------------------------------------------
int pascal TFormKqjTx::FindYgbhBh(int CardBh)
{
  int nYgbh;
  //if (pCard->Active == false) return -1;
  TLocateOptions Opts;
  Opts.Clear();
  if (pCard->Locate("CardNo",CardBh,Opts))
  {
    nYgbh = pCard->FieldByName("HolderNo")->AsInteger;
    return nYgbh;
  }
  else
  {
    return -1;
  }
}
//---------------------------------------------------------

void __fastcall TFormKqjTx::BitBtnReadClick(TObject *Sender)
{
  int nBh,nCom,nZt,nKpbh,nYgbh;
  FILE *pFile;
  char temp[256];
  char szKpbh[7],szTime[6],szYear[5],szMonth[3],szDay[3],szKqjbh[3];
  AnsiString sTemp;

  if (ComboBoxBh->Text.IsEmpty())
   {
     ShowMessage("请选择考勤机!");
     ComboBoxBh->SetFocus();
     return;
   }
 try
 {
   pCard->Open();
 }
 catch(...)
 {
   ShowMessage("打开卡片表失败!");
   return;
 }

  nBh = ComboBoxBh->Text.ToInt();
  temp[0] = 0;
if (ComboBoxLx->Text == "舒特考勤机")
{
  pSk->Close();
  pSk->LockType = ltBatchOptimistic;
  try
    {
      pSk->Open();
    }
  catch(...)
    {
      ShowMessage("打开刷卡数据表失败!");
      return;
    }
  nCom = _TESTCOM(nBh,1);

  if (nCom == -1)
    {
      ShowMessage("找不到考勤机或打开串口失败!请检查考勤机与电脑连接是否正确!");
      return;
    }
  nZt = _DOWNLOAD(nBh,nCom);
  Sleep(1000);
  if (nZt != 0)
    {
      ShowMessage("读取考勤机数据失败!");
      return;
    }

  pFile = fopen("kqrec.txt","r");
  if (pFile == NULL)
    {
      ShowMessage("打开文件失败!");
      return;
    }

  fgets(temp,256,pFile);
  while(!feof(pFile))
    {
      strncpy(szKpbh,temp,6);
      szKpbh[6] = 0;
      strncpy(szTime,temp + 6,5);
      szTime[5] = 0;
      strncpy(szYear,temp + 11,4);
      szYear[4] = 0;
      strncpy(szMonth,temp + 15,2);
      szMonth[2] = 0;
      strncpy(szDay,temp + 17,2);
      szDay[2] = 0;
      strncpy(szKqjbh,temp + 19,2);
      szKqjbh[2] = 0;
      sTemp = String(szYear) + "-" + String(szMonth) + "-" + String(szDay) + " " + String(szTime);
      try
        {
          StrToInt(szKpbh);
          StrToDateTime(sTemp);
        }
      catch(...)
        {
          goto label_1;
        }
      nYgbh = FindYgbhId(StrToInt(szKpbh));
      pSk->Append();
      if (nYgbh > 0)
      pSk->FieldByName("ygbh")->AsInteger = nYgbh;
      pSk->FieldByName("kpid")->AsInteger = StrToInt(szKpbh);
      pSk->FieldByName("sksj")->AsString = sTemp;
      pSk->Post();

      label_1:
      fgets(temp,256,pFile);
    }
  fclose(pFile);
  if (pSk->RecordCount > 0)
  {
    try
     {
      pSk->UpdateBatch(arAll);
     }
    catch(Exception &exception)
     {
       ShowMessage("保存失败!\n原因:" + exception.Message + "  但数据已下载到程序所在目录的'kqrec.txt'文件中,请用'从文件读取'来读取数据!");
       BitBtnRead->Enabled = false;
       return;
     }
    ShowMessage("保存成功!");
  }
}
else if (ComboBoxLx->Text == "Syris门禁控制器")
{
  pSk->Close();
  pSk->LockType = ltOptimistic;  //读一条保存一条
  try
    {
      pSk->Open();
    }
  catch(...)
    {
      ShowMessage("打开刷卡数据表失败!");
      return;
    }
  for (int i =1; i < 3; i++)
  {
    nCom = Syris_InitComm(i);
    if (nCom)
    {
      nZt = Syris_GetVersion(nBh,NULL);
      if(nZt==SYRIS_NOERROR)
      {
        break;
      }
      else
      {
        Syris_CloseComm();
      }
    }
  }
  if (!nCom)
  {
    ShowMessage("初始化端口失败!");
    return;
  }
  if(nZt != SYRIS_NOERROR)
  {
    ShowMessage("通讯失败!请检查控制器与计算机连接是否正确!");
    return;
  }

  while (1 == 1)
  {
   nZt = Syris_ReadIodata(nBh,temp);
   if (nZt != SYRIS_NOERROR)
   {
     ShowMessage("读取数据失败!");
     break;
   }
   else if (Trim(String(temp)) == "0000")
   {
     break;
   }
   else
   {
       strncpy(szKpbh,temp + 19,4);
       szKpbh[4] = 0;
       strncpy(szTime,temp + 13,2);
       szTime[2] = 0;
       strcat(szTime,":");
       strncat(szTime,temp + 15,2);

       strncpy(szYear,temp + 5,4);
       szYear[4] = 0;
       strncpy(szMonth,temp + 9,2);
       szMonth[2] = 0;
       strncpy(szDay,temp + 11,2);
       szDay[2] = 0;
       //strncpy(szKqjbh,temp + 19,2);
       //szKqjbh[2] = 0;
       sTemp = String(szYear) + "-" + String(szMonth) + "-" + String(szDay) + " " + String(szTime);
       temp[0]= 0;
       try
         {
           StrToInt(szKpbh);
           StrToDateTime(sTemp);
         }
       catch(...)
         {
           goto label_2;
         }
       nYgbh = FindYgbhBh(StrToInt(szKpbh));
       pSk->Append();
       if (nYgbh > 0)
       pSk->FieldByName("ygbh")->AsInteger = nYgbh;
       pSk->FieldByName("kpbh")->AsInteger = StrToInt(szKpbh);
       pSk->FieldByName("sksj")->AsString = sTemp;
       try
       {
       pSk->Post();
       }
       catch(...)
       {
         ShowMessage("保存数据失败,读取数据中断!");
         break;
       }

       label_2:
       nZt = Syris_DelOneIodata(nBh);
       if (nZt != SYRIS_NOERROR)
       {
         ShowMessage("删除控制器刷卡记录失败,读取数据中断!");
         break;
       }
   }
  }//读控制器循环结束
  Syris_CloseComm();
  ShowMessage("读取控制器数据结束!");
}
  LabelCount->Caption = pSk->RecordCount;
  BitBtnReadFile->Tag = 1;
  BitBtnRead->Enabled = false;
}
//---------------------------------------------------------------------------



void __fastcall TFormKqjTx::FormCreate(TObject *Sender)
{
  pKqjLx = GetQuery("QTxKqjLx");
  pKqjBh = GetQuery("QTxKqjBh");
  pSk = GetQuery("QTxSk");
  pDaoRu = GetQuery("Query4");
  pCard = GetQuery("QCardWh");
  pDaoRu->LockType = ltBatchOptimistic;

}
//---------------------------------------------------------------------------

void __fastcall TFormKqjTx::FormShow(TObject *Sender)
{
  AnsiString sLx;
  pKqjLx->Open();
  ComboBoxLx->Items->Clear();

  while(!pKqjLx->Eof)
   {
     sLx = pKqjLx->FieldByName("kqjlx")->AsString;
     ComboBoxLx->Items->Add(sLx);
     pKqjLx->Next();
   }
  DateTimePicker1->DateTime = Now();
  DateTimePicker2->DateTime = Now();

}
//---------------------------------------------------------------------------

void __fastcall TFormKqjTx::ComboBoxLxChange(TObject *Sender)
{
  AnsiString sBh;
  ComboBoxBh->Items->Clear();
  pKqjBh->Close();
  pKqjBh->Parameters->ParamByName("Lx")->Value =ComboBoxLx->Text;
  pKqjBh->Open();
  while(!pKqjBh->Eof)
   {
     sBh = pKqjBh->FieldByName("kqjbh")->AsString;
     ComboBoxBh->Items->Add(sBh);
     pKqjBh->Next();
   }
  BitBtnRead->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TFormKqjTx::ComboBoxBhChange(TObject *Sender)
{
  TLocateOptions Opts;
  Opts.Clear();
  if (pKqjBh->Locate("kqjbh",ComboBoxBh->Text,Opts))
  LabelMc->Caption = pKqjBh->FieldByName("kqjmc")->AsString;
  BitBtnRead->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TFormKqjTx::Image1Click(TObject *Sender)
{
  OpenDialog1->InitialDir = Application->ExeName ;
  OpenDialog1->Execute();
  EditFile->Text = OpenDialog1->FileName;
}
//---------------------------------------------------------------------------

void __fastcall TFormKqjTx::BitBtnReadFileClick(TObject *Sender)
{
  int nKpbh,nLen,nYgbh;
  FILE *pFile;
  char temp[256],*pFind;
  char szKpbh[10],szTime[20],szYear[5],szMonth[3],szDay[3],szKqjbh[3];
  AnsiString sTemp;

  if (ComboBoxFileType->ItemIndex == -1)
  {
    ShowMessage("请选择文件类型!");
    ComboBoxFileType->SetFocus();
    return;
  }

  try
 {
   pCard->Open();
 }
 catch(...)
 {
   ShowMessage("打开卡片表失败!");
   return;
 }

⌨️ 快捷键说明

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