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

📄 kqjtx.cpp

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

if (ComboBoxFileType->Text == "舒特考勤机数据文件")
{
  pSk->Close();
  pSk->LockType = ltBatchOptimistic;
  try
    {
      pSk->Open();
    }
  catch(...)
    {
      ShowMessage("打开刷卡数据表失败!");
      return;
    }


  pFile = fopen(EditFile->Text.c_str(),"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);
  LabelCount2->Caption = pSk->RecordCount;
  BitBtnReadFile->Tag = 1;
  if (pSk->RecordCount < 1)
  {
    EditFile->Clear();
    return;
  }
  try
   {
    pSk->UpdateBatch(arAll);

   }
  catch(Exception &exception)
   {
     ShowMessage("保存失败!\n原因:" + exception.Message);
     return;
   }
   ShowMessage("保存成功!");
   EditFile->Clear();

}
else
{
  pDaoRu->Close();

  pDaoRu->SQL->Clear();
  pDaoRu->SQL->Add("select ygbh,sksj,sfyx from kq_shuaka where 1 = 2");
  try
    {
      pDaoRu->Open();
    }
  catch(...)
    {
      ShowMessage("打开刷卡数据表失败!");
      return;
    }


  pFile = fopen(EditFile->Text.c_str(),"r");
  if (pFile == NULL)
    {
      ShowMessage("打开文件失败!");
      return;
    }

  fgets(temp,256,pFile);
  while(!feof(pFile))
    {
      pFind = strchr(temp,';');
      if (pFind == NULL) goto label_2;
      nLen = pFind - temp;

      strncpy(szKpbh,temp,nLen);
      szKpbh[nLen] = 0;
      MoveMemory(temp,temp + nLen +1,strlen(temp) - nLen);
      pFind = strchr(temp,';');
      if (pFind == NULL) goto label_2;
      nLen = pFind - temp;
      strncpy(szTime,temp,nLen);
      szTime[nLen] = 0;
      MoveMemory(temp,temp + nLen +1,strlen(temp)-nLen);
      pFind = strchr(temp,';');
      if (pFind == NULL) goto label_2;
      nLen = pFind - temp;
      temp[nLen] = 0;
      if (String(temp) == "True") nLen = 1;
      else if(String(temp) == "False") nLen = 0;
      else goto label_2;

      try
        {
          StrToInt(szKpbh);
          StrToDateTime(szTime);
        }
      catch(...)
        {
          goto label_2;
        }

      pDaoRu->Append();
      pDaoRu->FieldByName("ygbh")->AsInteger = StrToInt(szKpbh);
      pDaoRu->FieldByName("sksj")->AsString = szTime;
      pDaoRu->FieldByName("sfyx")->AsBoolean = nLen;
      pDaoRu->Post();

      label_2:
      fgets(temp,256,pFile);
    }
  fclose(pFile);
  LabelCount2->Caption = pDaoRu->RecordCount;
  BitBtnReadFile->Tag = 2;
  if (pDaoRu->RecordCount < 1)
  {
    EditFile->Clear();
    return;
  }
  try
   {
    pDaoRu->UpdateBatch(arAll);

   }
  catch(Exception &exception)
   {
     ShowMessage("保存失败!\n原因:" + exception.Message);
     return;
   }
   ShowMessage("保存成功!");
   EditFile->Clear();

}
  //BitBtnRead->Enabled = false;
}
//---------------------------------------------------------------------------

void __fastcall TFormKqjTx::FormClose(TObject *Sender,
      TCloseAction &Action)
{
  pKqjLx->Close();
  pKqjBh->Close();
  pSk->Close();
  pSk->LockType = ltBatchOptimistic;
  pDaoRu->Close();
  pDaoRu->LockType = ltOptimistic;
  pDaoRu->SQL->Clear();
  ADOQuery1->Close();
  ADOConnection1->Close();
  pCard->Close();
}
//---------------------------------------------------------------------------

void __fastcall TFormKqjTx::BitBtn1Click(TObject *Sender)
{
if (BitBtnReadFile->Tag == 1)
{
  TFormShowPb * FormShowShuaka = new TFormShowPb(this);
  FormShowShuaka->Caption = "刷卡数据";
  FormShowShuaka->DataSource1->DataSet = pSk;
  FormShowShuaka->DBGrid1->Columns->Clear();
  FormShowShuaka->DBGrid1->Columns->Add();
  FormShowShuaka->DBGrid1->Columns->Items[0]->Title->Caption = "员工编号";
  FormShowShuaka->DBGrid1->Columns->Items[0]->Title->Font->Assign(FormShowShuaka->Font);
  FormShowShuaka->DBGrid1->Columns->Items[0]->Title->Font->Color = clHighlight ;
  FormShowShuaka->DBGrid1->Columns->Items[0]->FieldName = "ygbh";
  FormShowShuaka->DBGrid1->Columns->Add();
  FormShowShuaka->DBGrid1->Columns->Items[1]->Title->Caption = "卡片编号";
  FormShowShuaka->DBGrid1->Columns->Items[1]->Title->Font->Assign(FormShowShuaka->Font);
  FormShowShuaka->DBGrid1->Columns->Items[1]->Title->Font->Color = clHighlight ;
  FormShowShuaka->DBGrid1->Columns->Items[1]->FieldName = "kpbh";
  FormShowShuaka->DBGrid1->Columns->Add();
  FormShowShuaka->DBGrid1->Columns->Items[2]->Title->Caption = "卡片内码";
  FormShowShuaka->DBGrid1->Columns->Items[2]->Title->Font->Assign(FormShowShuaka->Font);
  FormShowShuaka->DBGrid1->Columns->Items[2]->Title->Font->Color = clHighlight ;
  FormShowShuaka->DBGrid1->Columns->Items[2]->FieldName = "kpid";
  FormShowShuaka->DBGrid1->Columns->Add();
  FormShowShuaka->DBGrid1->Columns->Items[3]->Title->Caption = "刷卡时间";
  FormShowShuaka->DBGrid1->Columns->Items[3]->Title->Font->Assign(FormShowShuaka->Font);
  FormShowShuaka->DBGrid1->Columns->Items[3]->Title->Font->Color = clHighlight ;
  FormShowShuaka->DBGrid1->Columns->Items[3]->FieldName = "sksj";
  FormShowShuaka->ShowModal();
  delete FormShowShuaka;
}
else
{
  TFormShowPb * FormShowShuaka = new TFormShowPb(this);
  FormShowShuaka->Caption = "刷卡数据";
  FormShowShuaka->DataSource1->DataSet = pDaoRu;
  FormShowShuaka->DBGrid1->Columns->Clear();
  FormShowShuaka->DBGrid1->Columns->Add();
  FormShowShuaka->DBGrid1->Columns->Items[0]->Title->Caption = "员工编号";
  FormShowShuaka->DBGrid1->Columns->Items[0]->Title->Font->Assign(FormShowShuaka->Font);
  FormShowShuaka->DBGrid1->Columns->Items[0]->Title->Font->Color = clHighlight ;
  FormShowShuaka->DBGrid1->Columns->Items[0]->FieldName = "ygbh";
  FormShowShuaka->DBGrid1->Columns->Add();
  FormShowShuaka->DBGrid1->Columns->Items[1]->Title->Caption = "刷卡时间";
  FormShowShuaka->DBGrid1->Columns->Items[1]->Title->Font->Assign(FormShowShuaka->Font);
  FormShowShuaka->DBGrid1->Columns->Items[1]->Title->Font->Color = clHighlight ;
  FormShowShuaka->DBGrid1->Columns->Items[1]->FieldName = "sksj";
  FormShowShuaka->DBGrid1->Columns->Add();
  FormShowShuaka->DBGrid1->Columns->Items[2]->Title->Caption = "是否有效";
  FormShowShuaka->DBGrid1->Columns->Items[2]->Title->Font->Assign(FormShowShuaka->Font);
  FormShowShuaka->DBGrid1->Columns->Items[2]->Title->Font->Color = clHighlight ;
  FormShowShuaka->DBGrid1->Columns->Items[2]->FieldName = "sfyx";

  FormShowShuaka->ShowModal();
  delete FormShowShuaka;

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



void __fastcall TFormKqjTx::Image2Click(TObject *Sender)
{
  OpenDialog2->InitialDir = Application->ExeName ;
  OpenDialog2->Execute();
  EditDB->Text = OpenDialog2->FileName;
}
//---------------------------------------------------------------------------

void __fastcall TFormKqjTx::BitBtnQueryClick(TObject *Sender)
{
  TDate StartDate,EndDate;

  if (EditDB->Text.Trim().IsEmpty())
  {
    ShowMessage("请输入门禁数据库所在目录!");
    return;
  }

  if (DateTimePicker2->Date < DateTimePicker1->Date)
  {
    ShowMessage("结束日期不能小于开始日期!");
    DateTimePicker2->SetFocus();
    return;
  }

  ADOConnection1->Close();
  ADOConnection1->ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=MS Access Database;Mode=Read;Initial Catalog=" + EditDB->Text;
  try
  {
    ADOConnection1->Connected = true;
  }
  catch(...)
  {
    ShowMessage("连接门禁数据库失败!");
    return;
  }


  StartDate = DateTimePicker1->Date;
  EndDate = DateTimePicker2->Date;

  ADOQuery1->Close();
  ADOQuery1->Parameters->ParamByName("date1")->Value = StartDate;
  ADOQuery1->Parameters->ParamByName("date2")->Value = EndDate;
  try
  {
    ADOQuery1->Open();
  }
  catch(...)
  {
    ShowMessage("执行查询失败!请检查门禁数据库文件是否正确!");
    return;
  }
  if (ADOQuery1->RecordCount > 0) BitBtnSaveTo->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TFormKqjTx::EditDBChange(TObject *Sender)
{
  ADOQuery1->Close();
}
//---------------------------------------------------------------------------

void __fastcall TFormKqjTx::BitBtnSaveToClick(TObject *Sender)
{
  int nYgbh;
  String sCardNo,sDate,sTime;
  if (ADOQuery1->RecordCount < 1) return;

  pSk->Close();
  pSk->LockType = ltBatchOptimistic;
  try
    {
      pSk->Open();
    }
  catch(...)
    {
      ShowMessage("打开刷卡数据表失败!");
      return;
    }
  ADOQuery1->First();
  while (!ADOQuery1->Eof)
  {
    sCardNo = ADOQuery1->FieldByName("cardno")->AsString;
    sDate = ADOQuery1->FieldByName("iodate")->AsString;
    sTime = ADOQuery1->FieldByName("iotime")->AsString;
    try
    {
      StrToInt(sCardNo);
      StrToDateTime(sDate + " " + sTime);
    }
    catch(...)
    {
      ADOQuery1->Next();
      continue;
    }
    nYgbh = FindYgbhBh(StrToInt(sCardNo));
    pSk->Append();
    if (nYgbh > 0)
    pSk->FieldByName("ygbh")->AsInteger =nYgbh;
    pSk->FieldByName("kpbh")->AsString = sCardNo;
    pSk->FieldByName("sksj")->AsString = FormatDateTime("yyyy-mm-dd hh:mm:ss",StrToDateTime(sDate + " " + sTime));
    pSk->Post();
    ADOQuery1->Next();
  }

  if (pSk->RecordCount < 1)
  {
    BitBtnSaveTo->Enabled = false;
    return;
  }
  try
   {
    pSk->UpdateBatch(arAll);
   }
  catch(Exception &exception)
   {
     ShowMessage("保存失败!\n原因:" + exception.Message);
     return;
   }
  ShowMessage("保存成功!");
  BitBtnSaveTo->Enabled = false;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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