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

📄 employeemanageunit.cpp

📁 指纹门禁机管理系统
💻 CPP
📖 第 1 页 / 共 3 页
字号:
      return;
   }

    TDeptManageFrm* pDeptManageFrm = new TDeptManageFrm(this);
    pDeptManageFrm->SetOperateMode(omSelect);
    pDeptManageFrm->SetCaption("员工管理->请选择部门...");
    pDeptManageFrm->ShowModal();
    if (Application->MessageBoxA("您确认要批量设置您选中所有员工的部门吗?","提示信息",MB_YESNO + MB_ICONQUESTION) == ID_YES)
    {
       int lRV;
       DeptInfo_T lDetpInfo;
       pDeptManageFrm->GetDeptInfo(lDetpInfo);
       for(int i=0;i<lvRecordInfo->Items->Count;i++)
       {
          TListItem* CheckListItem = lvRecordInfo->Items->Item[i];
          if (CheckListItem->Checked)
          {
             int lEmpID = CheckListItem->Caption.ToInt();
             lRV = pDBAccess->SetUserDept(lEmpID,lDetpInfo.DeptID);
             if (lRV != OK)
             {
                Application->MessageBoxA("在批量设置员工部门过程中发生错误!","提示信息",MB_OK + MB_ICONWARNING);
                break;
             }
          }
       }
       if (lRV == OK)
       {
          Application->MessageBoxA("在批量设置员工部门成功!","提示信息",MB_OK + MB_ICONINFORMATION);
          RefreshListView();
       }
    }
    delete pDeptManageFrm;
}
//---------------------------------------------------------------------------

void __fastcall TEmployeeManageFrm::aSetRoleExecute(TObject *Sender)
{
   int lSelectCount = GetSelectedCount();
   if(lSelectCount <= 0)
   {
      Application->MessageBoxA("请选择要批量设置的员工记录!","提示信息",MB_OK + MB_ICONINFORMATION);
      return;
   }

    TSetRoleFrm* pSetRoleFrm = new TSetRoleFrm(this);
    pSetRoleFrm->SetCaption("员工管理->","批量设置门禁规则");
    pSetRoleFrm->ShowModal();
    if (!pSetRoleFrm->IsCanceled())
    {
       if (Application->MessageBoxA("您确认要批量设置您选中所有员工的门禁规则吗?","提示信息",MB_YESNO + MB_ICONQUESTION) == ID_YES)
       {
          int lRV;
          char lRoleVal = pSetRoleFrm->GetRoleValue();
          for(int i=0;i<lvRecordInfo->Items->Count;i++)
          {
             TListItem* CheckListItem = lvRecordInfo->Items->Item[i];
             if (CheckListItem->Checked)
             {
                int lEmpID = CheckListItem->Caption.ToInt();
                lRV = pDBAccess->SetUserRole(lEmpID,lRoleVal);
                if (lRV != OK)
                {
                   Application->MessageBoxA("在批量设置员工门禁规则过程中发生错误!","提示信息",MB_OK + MB_ICONWARNING);
                   break;
                }
             }
          }
          if (lRV == OK)
          {
             Application->MessageBoxA("在批量设置员工门禁规则成功!","提示信息",MB_OK + MB_ICONINFORMATION);
             RefreshListView();
          }

       }

    }
    delete pSetRoleFrm;
}
//---------------------------------------------------------------------------

void __fastcall TEmployeeManageFrm::aEmpCompareExecute(TObject *Sender)
{
    //用户信息比较
    TEmpInfoCompareFrm *pEmpInfoCompareFrm = new TEmpInfoCompareFrm(this);
    //加入要比较的数据库员工编号列表
    for(int i=0;i<lvRecordInfo->Items->Count;i++)
      pEmpInfoCompareFrm->AddDBSelectedEmpID(lvRecordInfo->Items->Item[i]->Caption.ToInt());
    //加入要比较的设备员工编号列表
    for(int i=0;i<lvDeviceUser->Items->Count;i++)
      pEmpInfoCompareFrm->AddDevEmpID(lvDeviceUser->Items->Item[i]->Caption.ToInt());

    pEmpInfoCompareFrm->SetCaption("员工管理->","员工信息比较");
    pEmpInfoCompareFrm->ShowModal();
    delete pEmpInfoCompareFrm;
}
//---------------------------------------------------------------------------

void __fastcall TEmployeeManageFrm::aEmpOutSetExecute(TObject *Sender)
{
   //:修改员工状态
   TListItem *pItem = lvRecordInfo->Selected;
   if(!pItem)
   {
      Application->MessageBoxA("请选择要离职的员工!","提示信息",MB_OK + MB_ICONINFORMATION);
      return;
   }

   int lRV,lFlag;
   if (!pItem->Caption.IsEmpty())
   {
      int lEmpID = pItem->Caption.ToInt();

      TEmployeeFlagFrm* pTEmployeeFlagFrm = new TEmployeeFlagFrm(this);
      pTEmployeeFlagFrm->SetCaption("员工管理->","设置员工状态");
      if(pItem->SubItems->Strings[7] == "在职")
         lFlag = wsInService;
      else if(pItem->SubItems->Strings[7] == "离职")
         lFlag = wsDimission;
      else
         lFlag = wsOther;
      pTEmployeeFlagFrm->InitEmployeeFlag(lFlag);
      pTEmployeeFlagFrm->ShowModal();
      if(!pTEmployeeFlagFrm->IsCanceled())
      {
         lFlag = pTEmployeeFlagFrm->GetEmployeeFlag();
         lRV = pDBAccess->UpdateUserFlag(lEmpID,lFlag);
         if (lRV == OK)
           RefreshListView();
         else
           Application->MessageBoxA("设置员工状态失败!","提示信息",MB_OK + MB_ICONERROR);
      }
      delete pTEmployeeFlagFrm;
   }
}
//---------------------------------------------------------------------------
int  TEmployeeManageFrm::ViewEmpInfo(int iEmpID)
{
   UserInfoEx_T aUserInfo;
   int lRV = pDBAccess->GetUserInfo(iEmpID,aUserInfo);
   if (lRV == OK)
   {
     TEmployeeInfoFrm* pEmployeeInfoFrm = new TEmployeeInfoFrm(this);
     pEmployeeInfoFrm->SetCaption("员工管理->","查看员工信息");
     pEmployeeInfoFrm->SetOperateMode(omView);
     pEmployeeInfoFrm->SetUserInfo(aUserInfo);
     pEmployeeInfoFrm->ShowModal();
     delete pEmployeeInfoFrm;
   }
   return OK;
}
//---------------------------------------------------------------------------

void __fastcall TEmployeeManageFrm::aViewEmpExecute(TObject *Sender)
{
   TListItem *pItem = lvRecordInfo->Selected;
   if(!pItem)
   {
      Application->MessageBoxA("请选择要查看的员工!","提示信息",MB_OK + MB_ICONINFORMATION);
      return;
   }
   ViewEmployeeInfo();
}
//---------------------------------------------------------------------------

void __fastcall TEmployeeManageFrm::aEmpDownExecute(TObject *Sender)
{
   int lSelectCount = GetSelectedCount();
   if(lSelectCount <= 0)
   {
      Application->MessageBoxA("请选择要下载的员工!","提示信息",MB_OK + MB_ICONINFORMATION);
      return;
   }

   TTreeNode *aNewNode;
   TTreeNode* lCurNode = trDevice->Selected;
   if(lCurNode == NULL || lCurNode == trDevice->Items->Item[0])
   {
      Application->MessageBoxA("请选择要下载的设备!","提示信息",MB_OK + MB_ICONINFORMATION);
      return;
   }
   nDeviceID = lCurNode->StateIndex;
   DeviceInfo_T aDeviceInfo;
   pEngine = GetEventEngineInstance();

   nHandle = pEngine->GetDeviceHandle(nDeviceID);
   if(nHandle == 0)
   {
      Application->MessageBoxA("打开要下载的设备失败!","提示信息",MB_OK + MB_ICONINFORMATION);
      return;
   }

   if(Application->MessageBoxA("系统会将设备中存在的员工信息覆盖,您确定要下载吗?","提示信息",MB_YESNO+MB_ICONQUESTION) == ID_NO)
      return;

   DownTimer->Enabled = true;
   spbnCancel->Enabled = false;

   AnsiString lProgress = "进度: 0%";
   sbInfo->Panels->Items[3]->Text = lProgress;
   nNum = 0;
   nSelNum = 0;

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

void __fastcall TEmployeeManageFrm::lvRecordInfoKeyDown(TObject *Sender,
      WORD &Key, TShiftState Shift)
{
   if(Shift.Contains(ssCtrl) && Key == 65) //65 == 'a'
      cbAllSelect->Checked = true;
   if(Shift.Contains(ssCtrl) && Key == 90) //90 == 'z'
      cbAllSelect->Checked = false;
}
//---------------------------------------------------------------------------

void __fastcall TEmployeeManageFrm::lvDeviceUserKeyDown(TObject *Sender,
      WORD &Key, TShiftState Shift)
{
   if(Shift.Contains(ssCtrl) && Key == 65) //65 == 'a'
      cbDBSelect->Checked = true;
   if(Shift.Contains(ssCtrl) && Key == 90) //90 == 'z'
      cbDBSelect->Checked = false;
}
//---------------------------------------------------------------------------

void __fastcall TEmployeeManageFrm::aEmpOutputExecute(TObject *Sender)
{
   if(lvRecordInfo->Items->Count < 1)
   {
      Application->MessageBoxA("列表中无员工信息可以导出!","提示信息",MB_OK + MB_ICONINFORMATION);
      return;
   }

   int lSelectCount = GetSelectedCount();
   if(lSelectCount <= 0)
   {
      Application->MessageBoxA("请选择要导出的员工!","提示信息",MB_OK + MB_ICONINFORMATION);
      return;
   }

   Variant  ExcelApp,NewXls,Cellms;
   try
   {
      ExcelApp = CreateOleObject("Excel.Application");               //启动Excel
      ExcelApp.OlePropertySet("Visible",(Variant)false);                      //使Excel不可见
      NewXls = (ExcelApp.OlePropertyGet("Workbooks")).OleFunction("Add");     //添加一个工作薄
      Cellms = NewXls.OlePropertyGet("ActiveSheet");                          //创建工作区
   }
   catch(...)
   {
      Application->MessageBoxA("无法启动Excel服务失败,请判断本机是否正常安装Excel!","提示信息",MB_OK + MB_ICONWARNING);
      return;
   }
 
   Cellms.OlePropertyGet("Cells",1,1).OlePropertySet("Value",(WideString)"员工编号");
   Cellms.OlePropertyGet("Cells",1,2).OlePropertySet("Value",(WideString)"员工姓名");
   Cellms.OlePropertyGet("Cells",1,3).OlePropertySet("Value",(WideString)"所属部门");
   Cellms.OlePropertyGet("Cells",1,4).OlePropertySet("Value",(WideString)"管理级别");
   Cellms.OlePropertyGet("Cells",1,5).OlePropertySet("Value",(WideString)"门禁规则");
   Cellms.OlePropertyGet("Cells",1,6).OlePropertySet("Value",(WideString)"验证方式");
   Cellms.OlePropertyGet("Cells",1,7).OlePropertySet("Value",(WideString)"已添加指纹数");
   Cellms.OlePropertyGet("Cells",1,8).OlePropertySet("Value",(WideString)"启用密码");
   Cellms.OlePropertyGet("Cells",1,9).OlePropertySet("Value",(WideString)"员工状态");
   Cellms.OlePropertyGet("Cells",1,10).OlePropertySet("Value",(WideString)"用户说明");

   int lIndex = 2;
   for(int i=0;i<lvRecordInfo->Items->Count;i++)
   {
      if(!lvRecordInfo->Items->Item[i]->Checked)
         continue;
      Cellms.OlePropertyGet("Cells",lIndex,1).OlePropertySet("Value",(WideString)lvRecordInfo->Items->Item[i]->Caption);
      Cellms.OlePropertyGet("Cells",lIndex,2).OlePropertySet("Value",(WideString)lvRecordInfo->Items->Item[i]->SubItems->Strings[0]);
      Cellms.OlePropertyGet("Cells",lIndex,3).OlePropertySet("Value",(WideString)lvRecordInfo->Items->Item[i]->SubItems->Strings[1]);
      Cellms.OlePropertyGet("Cells",lIndex,4).OlePropertySet("Value",(WideString)lvRecordInfo->Items->Item[i]->SubItems->Strings[2]);
      Cellms.OlePropertyGet("Cells",lIndex,5).OlePropertySet("Value",(WideString)lvRecordInfo->Items->Item[i]->SubItems->Strings[3]);
      Cellms.OlePropertyGet("Cells",lIndex,6).OlePropertySet("Value",(WideString)lvRecordInfo->Items->Item[i]->SubItems->Strings[4]);
      Cellms.OlePropertyGet("Cells",lIndex,7).OlePropertySet("Value",(WideString)lvRecordInfo->Items->Item[i]->SubItems->Strings[5]);
      Cellms.OlePropertyGet("Cells",lIndex,8).OlePropertySet("Value",(WideString)lvRecordInfo->Items->Item[i]->SubItems->Strings[6]);
      Cellms.OlePropertyGet("Cells",lIndex,9).OlePropertySet("Value",(WideString)lvRecordInfo->Items->Item[i]->SubItems->Strings[7]);
      Cellms.OlePropertyGet("Cells",lIndex,10).OlePropertySet("Value",(WideString)lvRecordInfo->Items->Item[i]->SubItems->Strings[8]);
      lIndex++;
   }

   sdExport->Title = "用户数据导出Excel文件...";
   if(sdExport->Execute())
   {
      AnsiString lSaveFileName = sdExport->FileName;
      if (FileExists(lSaveFileName))
      {
         if(Application->MessageBoxA("文件已经存在,你要覆盖吗?","提示信息",MB_YESNO + MB_ICONQUESTION) == ID_NO)
            return;
         DeleteFile(lSaveFileName);
      }
      NewXls.OleProcedure("SaveAs",lSaveFileName.c_str()); //保存Excel文件
      Application->MessageBoxA("员工信息导出Excel完毕!","提示信息",MB_OK + MB_ICONINFORMATION);
      ExcelApp.OleFunction("Quit");    //退出Excel
      ExcelApp = Unassigned;
      NewXls = Unassigned;
      Cellms = Unassigned;
   }
}
//---------------------------------------------------------------------------

void __fastcall TEmployeeManageFrm::aUpEmpExecute(TObject *Sender)
{
   TTreeNode* lCurNode = trDevice->Selected;
   if(lCurNode == NULL || lCurNode == trDevice->Items->Item[0])
   {
      Application->MessageBoxA("请选择要上传的设备!","提示信息",MB_OK + MB_ICONINFORMATION);
      return;
   }
   nDeviceID = lCurNode->StateIndex;

   DeviceInfo_T aDeviceInfo;
   pEngine = GetEventEngineInstance();
   pEngine->GetDeviceInfo(nDeviceID,&aDeviceInfo); //得到当前设备信息里的状态,是否在用
   nHandle = pEngine->GetDeviceHandle(nDeviceID);
   if(nHandle == 0)
   {
      Application->MessageBoxA("打开要上传的设备失败!","提示信息",MB_OK + MB_ICONINFORMATION);
      return;
   }

   pTDeviceAccess->GetUserCount(nHandle,nUserMax);
   pTDeviceAccess->GetTemplateCount(nHandle,nTemplateMax);
   if(nUserMax < 1)
   {
      Application->MessageBoxA("设备里不存在员工记录!","提示信息",MB_OK + MB_ICONINFORMATION);
      lvDeviceUser->Items->Clear();
      pEngine->ReleaseDeviceHandle(nDeviceID,nHandle);
      return;
   }
   lvDeviceUser->Items->Clear();
   pDBAccess->ClearUserInfo_T();
   pDBAccess->ClearTemplateInfo_T();
   UpTimer->Enabled = true;
   spbnCancel->Enabled = true;

   AnsiString lProgress = "进度: 0%";
   sbInfo->Panels->Items[3]->Text = lProgress;
   nNum = 0;        
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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