📄 inipublicfun.pas
字号:
//henry write the ini public function
//time 2006-07-05 20 function for database handle and data handle.
//tar -cksf minepack.tgz aaa.txt wang.txt ,压缩文件为tgz
//{$define ZEM300} //先不考虑300的
//{$DEFINE Debug}
unit IniPublicFun;
interface
uses
StrUtils, SysUtils, Windows, Classes, shellapi, db, adodb, dialogs, Forms, Inifiles, Graphics,
tlhelp32,StdCtrls, CheckLst, IdGlobal, ComCtrls, Messages, Registry;
function connect_DB(ADO: TADOConnection; ConnStr: string): bool;
function GetBlobToStream(Table: TDataSet; const FieldName: string; var ResultStream: TmemoryStream): Bool;
function GetBlobFileToStream(ADOTable1: TAdoQuery; Name: string): TStream;
function blobcontenttostring(const fileName: string; ADOTable1: TDataSet; FiledName: string): bool;
function RestartDevice(ZKEH: THandle): bool;
function EnableDevice(ZKEH: THandle; Enabled: boolean): boolean;
function ReadOption(ZKEH: THandle; const Option: string): string;
function ClearARPMemo(Handle: HWnd): bool;
function SendDataToDevice(ZKEH: THandle; data: TMemoryStream; DataType: Word; Address: DWORD): Boolean;
procedure GetBuildInfo(var V1, V2, V3, V4: Word);
function CheckMAC(SN: string; MAC: string): boolean;
function GetCfgValue(const key: string; cfgFileName: string): string;
function SetCfgValue(const key: string; Value: string; cfgFileName: string): bool;
function selectDB(Aform: TForm): string;
function FormCenter(AForm: TForm): bool;
function checkValue(ATable: string; AFile: string; Avalue: string): bool;
function GetValueToCMB(ATable: string; AFile: string; Avalue: string): TStrings;
function GetValueToListstr(ATable: string; AFile: string; AFlagField: string; Avalue: string): TStrings;
//get local name and MAC.
function GetMacAddress(const AServerName: string): string;
function GetLocalName: string;
function CheckListWithValue(AListStrs: TStrings; AValue: string): integer;
function SetOptions(index: integer; ZKEH: THandle; sAllOpts: Tstrings): integer;
function SetDevTime(ZKEH: THandle; TimeFlag: integer): integer;
function UpdateSecurityKey(ZKEH: THandle; ID: Word): bool;
function UpdateFlashSecurityKey(ZKEH: THandle; c: integer): boolean;
function ClearDevData(ZKEH: THandle): bool;
function AGetBlobA(Table: TDataSet; const FieldName: string): string;
function SetBlob(Table: TDataSet; const FieldName, Template: string): Boolean;
function ByteToHex(b: BYTE): string;
function GetDisTValueToCMB(ATable: string; AFeild: string): TStrings;
//取得一个值
function GetValueTostr(ATable: string; AFile: string; AFlagField: string; Avalue: string): string;
//execute update
function ExeUpdateValue(AtableNmae: string; DevField: string; DevValue: string; LimitField: string; LimitValue: string): bool;
//get a data as time
function GetATimeValueTostr(ATable: string; AFile: string; AFlagField: string; Avalue: string): TDateTime;
//闪烁
function flashBack(Aobject: TMemo; flashtime: integer): bool;
procedure flashMineForm(AForm: Tform);
//保存列表内容到数据库字段
function SaveAStreamToDataTable(const AStream: TmemoryStream; ADOTable1: TDataSet; FiledName: string): bool;
function getDevfirmwareVer(ZKEH: THandle): string;
//压缩tgz包
function TarCreateTGZ(Handle: HWnd; EXEPath: string; CMDStr: string): bool;
//文操作,拷贝,删除,
function delTheFile(scr: string): integer;
function copyTheFile(scr: string; dec: string): integer;
//生成所需要的bat文件。
function createABATFile(AFilePath: string; FileListStr: Tstrings): bool;
//取得某一符号后面的值
function GetACharAfterStr(Astring: string; AChar: string): string;
//杀死进程。
function KillTask(ExeFileName: string): Integer;
//返回下一个ID取最大值(整型)
function GetNextRecNoMax(ADOConnection: TADOConnection; TableName, Fieldstr, Condition, DesFieldstr: string; FieldLen: integer): longint;
//返回下一个ID取最大值string
function GetNextRecNo(ADOConnection: TADOConnection; TableName, Fieldstr, Condition, DesFieldstr: string; FieldLen: integer): string;
////获取系统目录'C:\WINNT'
function myGetWindowsDirectory: string;
function getchklstCurrSelected(chklst: TCheckListBox): string;
function getchklstAllChecked(chklst: TCheckListBox): TStrings;
function LocaleStr(eee, tt: string): string;
//压缩流为包文件 TgzFileName
function AutoComp(fileNames: string; TgzFileName: string): boolean;
//从数据库提出流数据
function CreateZKPackChildPub(OptName, table, NameField, NameFieldValue, StreamField: string; var TempMemorystream: TmemoryStream): boolean;
procedure AddInfo(const s: string; Color: integer = clBlack);
procedure AddInfoINI(ispub: byte; index: byte; const s: string; Color: integer = clBlack);
procedure DelayTime(Second: Cardinal);
procedure DelayTimeMs(iMillisecond: Cardinal);
function getfeildValue(tableName, DfeildName, SfeildName, value: string): string;
function getNamefromOtherOpts(tableName, DfeildName, SfeildName, devNum: string): string;
//下载文件
function downLoadfiles(Table: TDataSet; const FieldName, hint: string; filePathAndNamestr: string): boolean;
//去掉字符串中的某一字符除去空格
function checkFilename(tempchar: string; SourceStr: string): string; //去掉filemae中的s除去空格
//导出导入文件true为ex else 为im
function Imexportfiles(exOrIm: boolean; Table: TDataSet; const FieldName, hint: string): boolean;
//获取usb232com口
function GetUSB232com: string;
//該函數的功能就是取兩個相隔符之間的字符(两字符不可相同).
function FindStr(BegSprStr, EdSpStr: string; var Source: string): string;
//获得下一个机器序列号
function GetMachineNumber: string;
implementation
uses
PunParam, uSecu, Main, Communal; //
//該函數的功能就是取兩個相隔符之間的字符(两字符不可相同).
function GetMachineNumber: string;
var
serialnum: string;
begin
dm.ADOStoredProc2.ExecProc; //执行存储过程获得下一序列号
serialnum := DM.ADOStoredProc2.Parameters.ParamByName('@serialnum').Value;
serialnum := copy('0000' + serialnum, length(serialnum) + 1, 4);
Result := SerialNumberStart + serialnum; //+'_'+copy(EmList[index].IP, LastDelimiter('.', EmList[index].IP) + 1, 3);;
end;
function FindStr(BegSprStr, EdSpStr: string; var Source: string): string;
var
BegStr1Len, EdSpStr2Len, BegStr1Index, EdSpStr2index: integer;
Temp: string;
begin
Temp := Source;
BegStr1Index := Pos(BegSprStr, Temp);
BegStr1Len := Length(BegSprStr);
delete(Temp, BegStr1Index, BegStr1Index + BegStr1Len - 1);
EdSpStr2index := Pos(EdSpStr, Temp);
EdSpStr2Len := Length(EdSpStr);
Result := Copy(Temp, 1, EdSpStr2index - 1);
Delete(Temp, 1, EdSpStr2index + EdSpStr2Len - 1);
Source := temp;
{// Source:= '<1111> string1 <1122> <2233> string2 <3344> <4455> string3 <5566>' ;
// string1 := FindStr('<1111>', '<1122>', Source);
// String2 := FindStr('<2233>', '<3344>', Source);
// String3 := FindStr('<4455>', '<5566>', Source);}
end;
procedure AddInfo(const s: string; Color: integer = clBlack);
var
ListItem: TListItem;
begin
setLength(arrLvColor, FrmMain.lstOptLog.Items.Count + 1);
arrLvColor[FrmMain.lstOptLog.Items.Count] := Color;
ListItem := FrmMain.lstOptLog.Items.Add;
ListItem.Caption := s;
FrmMain.lstOptLog.Refresh;
SendMessage(FrmMain.lstOptLog.Handle, WM_VSCROLL, SB_LINEDOWN, 0) //
end;
//ispub表示是公共还是某机器0表示仅公共1,表示机器和公共,2仅机器, //index表示某机器信息
procedure AddInfoINI(ispub: byte; index: byte; const s: string; Color: integer = clBlack);
var
ListItem: TListItem;
begin
if SingleUpdate or UpdateUserTmp then
begin
AddInfo(s, Color); //如果为单项升级或为仅上传指纹模板
exit;
end;
try
if inttostr(Color) = '' then
begin
AddInfo('Color为空', clBlack);
exit;
end;
except
exit;
end;
if (ispub = 0) or (ispub = 1) then
begin //ispub=0或1直接写在公共内
setLength(arrLvColorini, FrmInitialize.lstOptLog.Items.Count + 1);
arrLvColorini[FrmInitialize.lstOptLog.Items.Count] := Color;
ListItem := FrmInitialize.lstOptLog.Items.Add;
ListItem.Caption := s;
FrmInitialize.lstOptLog.Refresh;
SendMessage(FrmInitialize.lstOptLog.Handle, WM_VSCROLL, SB_LINEDOWN, 0) //
end;
//EnterCriticalSection(CS);
if (ispub = 1) or (ispub = 2) then
begin //先存到库中
//if DM.QDeviniInfo.Active = false then DM.QDeviniInfo.Active := true;
try
try
with DevInfoRec do
begin
//devinfoIndex:=index;
DevInfoColor := Color;
DevInfoInfo := s;
end;
// Write the new record to the stream
if Assigned(DevInfoFileArr[index]) then
DevInfoFileArr[index].AppendRec(DevInfoRec);
//DevInfoFile.AppendRec(DevInfoRec);
{ devinfoIndex.add(inttostr(index));
DevInfoInfo.add(s);
DevInfoColor.add(inttostr(Color));}
//DM.QDeviniInfo.Append;
//DM.QDeviniInfo.FieldValues['index'] := index;
//DM.QDeviniInfo.FieldValues['info'] := s;
//DM.QDeviniInfo.FieldValues['Color'] := Color;
//DM.QDeviniInfo.Post;
except
// if DM.QDeviniInfo.State in [dsInsert,dsEdit] then DM.QDeviniInfo.Cancel;
end;
finally
// LeaveCriticalSection(CS); // CS ends here
end;
end;
end;
function LocaleStr(eee, tt: string): string;
begin
Result := tt;
end;
//过程描述
{取得MAC字符串后六位,然后去除:,得到一个十六进制的字符串,判断SN和MAC后六位
是否相等}
//返回true,false.int SN = int 后六位 MAC 则返回true.
//begin
function CheckMAC(SN: string; MAC: string): boolean;
var
s, cts, hex: string;
p: integer;
begin
result := False;
if MAC = '' then
exit
else
begin
s := rightstr(MAC, 8);
while s > '' do begin
p := Pos(':', s);
if p = 0 then
begin
cts := s;
s := '';
end
else
begin
cts := copy(s, 1, p - 1);
delete(s, 1, p);
end;
hex := hex + cts;
end;
end;
Result := strtointdef(SN, 0) = StrToInt('$' + copy(hex, 1, 6));
end;
//end
//取得系统的版本号。
//begin
procedure GetBuildInfo(var V1, V2, V3, V4: Word);
var
VerInfoSize: DWORD;
VerInfo: Pointer;
VerValueSize: DWORD;
VerValue: PVSFixedFileInfo;
Dummy: DWORD; //存储版本信息需要的长度
begin
VerInfoSize := GetFileVersionInfoSize(PChar(ParamStr(0)), Dummy);
GetMem(VerInfo, VerInfoSize); //地址空间申请。
GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo);
VerQueryValue(VerInfo, '\', Pointer(VerValue), VerValueSize);
with VerValue^ do
begin
V1 := dwFileVersionMS shr 16; //高16位
V2 := dwFileVersionMS and $FFFF; //低16位
V3 := dwFileVersionLS shr 16;
V4 := dwFileVersionLS and $FFFF;
end;
FreeMem(VerInfo, VerInfoSize);
end;
//end
//上传固件
//2006-6-28日精简了原系统的代码。
function SendDataToDevice(ZKEH: THandle; data: TMemoryStream; DataType: Word; Address: DWORD): Boolean;
var
CmdBuf: array[0..1] of Dword;
begin
cmd := CMD_UPDATE_FIRMWARE;
CmdBuf[0] := DataType; //更新类型
CmdBuf[1] := Address;
//t:=GetTickCount; //计时,在此无用
if pos('ZEM300', UpperCase(ZEM300_TFT)) > 0 then
begin
if (UpperCase(ZEM300_TFT) = 'ZEM300_TFT') then
begin
if (DataType <> 10) and (DataType <> 7) and (DataType <> 8) then CmdBuf[0] := UPDATE_CFIRMWARE; //2006-9-8 修改,zem300初始化问题。//
end
else
begin
if (DataType <> 10) and (DataType <> 7) and (DataType <> 0) then CmdBuf[0] := UPDATE_CFIRMWARE; //2006-9-8 修改,zem300初始化问题。//
end;
end;
ZEMBPRO_SENDCMDDATA(ZKEH, cmd, data.Memory, data.Size, @CmdBuf[0], 8, 10000);
//{$IFDEF ZEM300}
{ if (DataType <> 10) and (DataType <> 7) then
begin
CmdBuf[0] := UPDATE_CFIRMWARE; //2006-9-8 修改,zem300初始化问题。
ZEMBPRO_SENDCMDDATA(ZKEH, cmd, data.Memory, data.Size, @CmdBuf[0], 8, 10000);
end
else
begin
ZEMBPRO_SENDCMDDATA(ZKEH, cmd, data.Memory, data.Size, @CmdBuf[0], 8, 10000);
end;
{$ELSE}
// ZEMBPRO_SENDCMDDATA(ZKEH, cmd, data.Memory, data.Size, @CmdBuf[0], 8, 10000);
//{$ENDIF}
if cmd <> CMD_ACK_OK then
begin
result := false;
end
else
result := true;
end;
//上传固件
//清除ARP缓存
function ClearARPMemo(Handle: HWnd): bool;
begin
shellexecute(Handle, 'OPEN', 'ARP.EXE', '-d', nil, 0);
result := true;
//arp.exe 是一个管理网卡底层物理地址的程序,每个网卡都有一个全球唯一的物理地址
//,上网时,动态的IP地址就是根据这个物理地址影射的。
{在同一个局域网段内有两个物理地址相同的网络适配器,不论如何配置都会造成IP地址
冲突。
arp -a,显示arp的影射;
arp -s IP地址 物理地址,增加一个arp影射,如arp -s 192.168.1.1 00-aa-00-00-c2
-99;
arp -d IP地址 物理地址,del掉一个arp影射。 用法:当IP地址冲突时,使用此命令可以把冲突的IP地址屏蔽掉!
arp.exe 是一个管理网卡底层物理地址的程序
有一个没关系,不用管它
如果是很多个,而且很占CPU,那就是木马了
可能是被远程控制了,用软件查杀一下 }
end;
//清除ARP缓存
//读option某一项值
function ReadOption(ZKEH: THandle; const Option: string): string;
var
s: string;
begin
s := stringofchar(#0, 200); //初始化字符串为200个空格
cmd := CMD_OPTIONS_RRQ;
move(Option[1], s[1], length(Option));
ZEMBPRO_SENDCMD(ZKEH, cmd, @s[1], 200, length(Option) + 1, 1000);
if cmd = CMD_ACK_OK then
result := strpas(@s[Length(Option) + 2]) //得到等号后面的值
else
result := '';
end;
//读option
//device enable
function EnableDevice(ZKEH: THandle; Enabled: boolean): boolean;
var CMDACK: word;
i: byte;
begin
Result := false;
CMDACK := 0;
if Enabled then
begin
i := 0;
while true do
begin
DelayTimeMs(50);
cmd := CMD_ENABLEDEVICE;
ZEMBPRO_SENDCMD(ZKEH, cmd, nil, 0, 0, 1000);
CMDACK := cmd;
i := i + 1;
if (CMDACK = CMD_ACK_OK) or (i = 10) then break;
end;
i := 0;
while true do
begin
DelayTimeMs(50);
cmd := CMD_REFRESHOPTION;
ZEMBPRO_SENDCMD(ZKEH, cmd, nil, 0, 0, 1000);
CMDACK := cmd;
i := i + 1;
if (CMDACK = CMD_ACK_OK) or (i = 10) then break;
end;
end
else
begin
i := 0;
while true do
begin
DelayTimeMs(50);
cmd := CMD_DISABLEDEVICE;
ZEMBPRO_SENDCMD(ZKEH, cmd, nil, 0, 0, 2000);
CMDACK := cmd;
i := i + 1;
if (CMDACK = CMD_ACK_OK) or (i = 10) then break;
end;
end;
if CMDACK = CMD_ACK_OK then Result := true;
end;
//device enable.
//重新启动机器
function RestartDevice(ZKEH: THandle): bool;
begin
cmd := CMD_RESTART;
ZEMBPRO_SENDCMD(ZKEH, cmd, nil, 0, 0, 1000);
//ZKEH:=0;
result := true;
end;
//重新启动机器
//读文件,存储文件到blob
function blobcontenttostring(const fileName: string; ADOTable1: TDataSet; FiledName: string): bool;
var
AStream: TmemoryStream;
begin
//result:=Tmemorystream.Create ;
AStream := TmemoryStream.Create;
AStream.LoadFromFile(fileName);
if AStream.Size <= 0 then begin Result := false; Abort; end;
if not (ADOTable1.State in [dsinsert, dsedit]) then ADOTable1.edit;
try
with ADOTable1.FieldByName(FiledName) as TBlobField do
begin
Astream.Position := 0;
LoadFromStream(Astream);
end;
result := true;
finally
//ADOTable1.post;
AStream.Position := 0;
//AStream.ReadBuffer(result,Astream.Size-1);
AStream.Free;
end;
end;
//存储文件到blob
//将blob读到tstream
function GetBlobFileToStream(ADOTable1: TAdoQuery; Name: string): TStream;
var
AFiled: Tfield;
begin
Afiled := Tfield.Create(nil);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -