📄 devicemanageunit.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "DeviceManageUnit.h"
#include "DeviceInfoInputUnit.h"
#include "DeviceTimeInputUnit.h"
#include "DeviceCaptionInputUnit.h"
#include "DeviceOpenPwdInputUnit.h"
#include "EnguardRoleUnit.h"
#include "BaseConvertorUnit.h"
#include "GuardModeUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ObjectManageUnit"
#pragma resource "*.dfm"
TDeviceManageFrm *DeviceManageFrm;
//---------------------------------------------------------------------------
__fastcall TDeviceManageFrm::TDeviceManageFrm(TComponent* Owner)
: TBaseObjectManageFrm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TDeviceManageFrm::FormCreate(TObject *Sender)
{
lvObject->OnColumnClick = OnRecordInfoColumnClick;
lvObject->OnCompare = OnRecordInfoCompare;
lDeviceChanged = false;
pDBAccess = new TDBAccess();
pDeviceAccess = GetDeviceAccessInstance();
pEventEngine = GetEventEngineInstance();
ClearSpeedButtonCaption();
CurDeviceInfo.DeviceID = 0;
}
//---------------------------------------------------------------------------
void __fastcall TDeviceManageFrm::FormDestroy(TObject *Sender)
{
delete pDBAccess;
}
//---------------------------------------------------------------------------
bool TDeviceManageFrm::IsDeviceChanged()
{
return lDeviceChanged;
}
//---------------------------------------------------------------------------
void TDeviceManageFrm::RefreshListView()
{
DeviceInfoArray_T aDeviceList;
pDBAccess->GetDeviceList(aDeviceList);
IterDeviceInfo_T IterDevice;
DeviceInfo_T aDBDeviceInfo,aEngineDeviceInfo;
lvObject->Clear();
int lDeviceID;
for(IterDevice = aDeviceList.begin();IterDevice!=aDeviceList.end();++IterDevice)
{
aDBDeviceInfo = *IterDevice;
lDeviceID = aDBDeviceInfo.DeviceID;
pEventEngine->GetDeviceInfo(lDeviceID,&aEngineDeviceInfo);
if(aEngineDeviceInfo.DeviceStatus == dsOpened) //监控
{
AddDeviceInfoToListView(aEngineDeviceInfo);
}
else
{
AddDeviceInfoToListView(aDBDeviceInfo);
}
}
aDeviceList.clear();
CurDeviceInfo.DeviceID = 0;
}
//---------------------------------------------------------------------------
void TDeviceManageFrm::SetFunctionEnabled(bool iEnabled)
{
aEditDevice->Enabled = iEnabled;
aDeleteDevice->Enabled = iEnabled;
aState->Enabled = iEnabled;
aSetTime->Enabled = iEnabled;
aSetCaption->Enabled = iEnabled;
aResumeCaption->Enabled = iEnabled;
aEmergencyOpen->Enabled = iEnabled;
aSetPassword->Enabled = iEnabled;
aAutoLock->Enabled = iEnabled;
aDeviceLinkTest->Enabled = iEnabled;
aSetDeviceRole->Enabled = iEnabled;
aGetDeviceRole->Enabled = iEnabled;
aViewDevice->Enabled = iEnabled;
aSetEmergencyState->Enabled = iEnabled;
aSetDeviceMode->Enabled = iEnabled;
}
//---------------------------------------------------------------------------
void __fastcall TDeviceManageFrm::FormShow(TObject *Sender)
{
aRefesh->Execute();
SetFunctionEnabled(false);
}
//---------------------------------------------------------------------------
void TDeviceManageFrm::AddDeviceInfoToListView(DeviceInfo_T iDeviceInfo)
{
TListItem *pListItem = lvObject->Items->Add();
pListItem->Caption = iDeviceInfo.DeviceID;
pListItem->SubItems->Add(iDeviceInfo.DeviceName);
pListItem->SubItems->Add(aCnv.GetDeviceTypeName(iDeviceInfo.DeviceType));
pListItem->SubItems->Add(iDeviceInfo.DeviceCaption);
pListItem->SubItems->Add(AnsiString(iDeviceInfo.AutoLockSec)+"秒");
pListItem->SubItems->Add(aCnv.GetDeviceModeName(iDeviceInfo.DeviceMode));
pListItem->SubItems->Add(aCnv.GetDeviceStatusName(iDeviceInfo.DeviceStatus));
AnsiString lParamStr;
switch(iDeviceInfo.DeviceType)
{
case dtCOM:
{
lParamStr = "串口:" + AnsiString(iDeviceInfo.DeviceParams.UartParam.COMID) + " 波特率:" + AnsiString(iDeviceInfo.DeviceParams.UartParam.Baud);
}break;
case dtIP:
{
lParamStr = "IP:"+ AnsiString(iDeviceInfo.DeviceParams.IPParam.IPs[0]) + "."+ AnsiString(iDeviceInfo.DeviceParams.IPParam.IPs[1]) + "."+ AnsiString(iDeviceInfo.DeviceParams.IPParam.IPs[2]) + "." + AnsiString(iDeviceInfo.DeviceParams.IPParam.IPs[3]);
lParamStr = lParamStr + " 端口号:" + AnsiString(iDeviceInfo.DeviceParams.IPParam.Port);
}break;
case dtUSB:lParamStr = "无";break;
}
pListItem->SubItems->Add(lParamStr);
pListItem->SubItems->Add(iDeviceInfo.DeviceDesc);
}
//---------------------------------------------------------------------------
void __fastcall TDeviceManageFrm::lvObjectClick(TObject *Sender)
{
TListItem *pItem = lvObject->Selected;
if(pItem)
{
SetFunctionEnabled(true);
sbInfo->Panels->Items[0]->Text = "当前设备:" + pItem->SubItems->Strings[0];
int lDeviceID = pItem->Caption.Trim().ToInt();
DeviceInfo_T aDeviceInfo;
if (pDBAccess->GetDeviceInfo(lDeviceID,aDeviceInfo) == OK)
{
memcpy(&CurDeviceInfo,&aDeviceInfo,sizeof(aDeviceInfo));
SetDeviceStatusIcon(aDeviceInfo.DeviceStatus);
}
else
{
CurDeviceInfo.DeviceID = 0;
}
}
else
{
SetFunctionEnabled(false);
CurDeviceInfo.DeviceID = 0;
}
}
//---------------------------------------------------------------------------
void TDeviceManageFrm::SetDeviceStatusIcon(int iStatus)
{
if (iStatus == dsOutStatus)
{
aState->Caption = "启用设备 &S";
aState->Hint = "启用设备";
sbState->Glyph = NULL;
mlState->GetBitmap(1,sbState->Glyph);
}
else
{
aState->Caption = "停用设备 &S";
aState->Hint = "停用设备";
sbState->Glyph = NULL;
mlState->GetBitmap(0,sbState->Glyph);
}
}
//---------------------------------------------------------------------------
void __fastcall TDeviceManageFrm::aAddDeviceExecute(TObject *Sender)
{
//新增设备信息
TDeviceInfoInputFrm* pDeviceInfoInputFrm = new TDeviceInfoInputFrm(this);
pDeviceInfoInputFrm->SetOperateMode(omAdd);
pDeviceInfoInputFrm->SetCaption("设备管理->","新增设备信息");
pDeviceInfoInputFrm->ShowModal();
if (!pDeviceInfoInputFrm->IsCanceled())
{
RefreshListView();
lDeviceChanged = true;
}
delete pDeviceInfoInputFrm;
}
//---------------------------------------------------------------------------
void __fastcall TDeviceManageFrm::aEditDeviceExecute(TObject *Sender)
{
//修改设备信息
int lDeviceID = CurDeviceInfo.DeviceID;
if (lDeviceID != 0)
{
TDeviceInfoInputFrm* pDeviceInfoInputFrm = new TDeviceInfoInputFrm(this);
pDeviceInfoInputFrm->SetOperateMode(omEdit);
pDeviceInfoInputFrm->SetCaption("设备管理->","修改设备信息");
pDeviceInfoInputFrm->SetDeviceInfo(CurDeviceInfo);
pDeviceInfoInputFrm->ShowModal();
if (!pDeviceInfoInputFrm->IsCanceled())
{
RefreshListView();
lDeviceChanged = true;
}
delete pDeviceInfoInputFrm;
}
}
//---------------------------------------------------------------------------
void __fastcall TDeviceManageFrm::aDeleteDeviceExecute(TObject *Sender)
{
TListItem *pItem = lvObject->Selected;
if(pItem)
{
AnsiString lDeviceID = pItem->Caption.Trim();
AnsiString lMsg = "您确认要删除编码为:" + lDeviceID + "的设备吗?";
if(Application->MessageBoxA(lMsg.c_str(),"提示信息",MB_YESNO + MB_ICONQUESTION) == ID_YES)
{
int lRV = pDBAccess->DeleteDeviceInfo(lDeviceID.ToInt());
if (lRV == OK)
{
Application->MessageBoxA("删除设备信息成功!","提示信息",MB_OK + MB_ICONINFORMATION);
RefreshListView();
lDeviceChanged = true;
}
else
Application->MessageBoxA("删除设备信息失败!","提示信息",MB_OK + MB_ICONERROR);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TDeviceManageFrm::aCloseExecute(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TDeviceManageFrm::aStateExecute(TObject *Sender)
{
int lDeviceID = CurDeviceInfo.DeviceID;
if (lDeviceID != 0)
{
AnsiString lMsg;
DeviceInfo_T aDeviceInfo;
if (pDBAccess->GetDeviceInfo(lDeviceID,aDeviceInfo) != OK)
{
Application->MessageBoxA("获取设备信息失败!","提示信息",MB_OK + MB_ICONINFORMATION);
return;
}
if (CurDeviceInfo.DeviceStatus == dsRightStatus)
{
CurDeviceInfo.DeviceStatus = dsOutStatus;
lMsg = AnsiString(CurDeviceInfo.DeviceName).Trim() + " 设备已经被停用!";
}
else if(CurDeviceInfo.DeviceStatus == dsOutStatus)
{
CurDeviceInfo.DeviceStatus = dsRightStatus;
lMsg = AnsiString(CurDeviceInfo.DeviceName).Trim() + " 设备已经被启用!";
}
else
{
CurDeviceInfo.DeviceStatus = dsOpened;
lMsg = AnsiString(CurDeviceInfo.DeviceName).Trim() + " 设备已经被监控!";
}
int lRV = pDBAccess->UpdateDeviceInfo(CurDeviceInfo.DeviceID,CurDeviceInfo);
if (lRV == OK)
{
SetDeviceStatusIcon(CurDeviceInfo.DeviceStatus);
RefreshListView();
lDeviceChanged = true;
Application->MessageBoxA(lMsg.c_str(),"提示信息",MB_OK + MB_ICONINFORMATION);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TDeviceManageFrm::aSetTimeExecute(TObject *Sender)
{
//:设置设备时间
int lDeviceID = CurDeviceInfo.DeviceID;
if (lDeviceID != 0)
{
TDeviceTimeInputFrm* pDeviceTimeInputFrm = new TDeviceTimeInputFrm(this);
pDeviceTimeInputFrm->SetDeviceName(CurDeviceInfo.DeviceName);
pDeviceTimeInputFrm->SetCaption("设备管理->","设置时间");
pDeviceTimeInputFrm->ShowModal();
SYSTEMTIME lSystemTime;
pDeviceTimeInputFrm->GetSetTime(lSystemTime);
if (!pDeviceTimeInputFrm->IsCanceled())
{
int lHandle = pEventEngine->GetDeviceHandle(lDeviceID);
if (lHandle != 0)
{
int lRV = pDeviceAccess->SetDeviceTime(lHandle,lSystemTime);
pEventEngine->ReleaseDeviceHandle(lDeviceID,lHandle);
if(lRV != OK)
{
Application->MessageBoxA("设置时间失败!","提示信息",MB_OK + MB_ICONERROR);
}
else
{
Application->MessageBoxA("设置时间成功!","提示信息",MB_OK + MB_ICONINFORMATION);
}
}
else
Application->MessageBoxA("连接设备失败!","提示信息",MB_OK + MB_ICONERROR);
}
delete pDeviceTimeInputFrm;
}
}
//---------------------------------------------------------------------------
void __fastcall TDeviceManageFrm::aSetCaptionExecute(TObject *Sender)
{
//:设置设备标签
int lDeviceID = CurDeviceInfo.DeviceID;
if (lDeviceID != 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -