📄 connectform.~pas
字号:
unit ConnectForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TfrmConnect = class(TForm)
lblConnectInfo: TLabel;
private
{ Private declarations }
public
{ Public declarations }
function InitialApp(): integer;
procedure ShowInformation(AInfo: string);
//
function DownLoadCard(ControlAddr: string;APort: integer;ADateTime: TDateTime;
AGroupId : integer): integer;
end;
var
frmConnect: TfrmConnect;
implementation
uses
DB,ADODB,
PlmsDM,GlobalUnit,
LoginForm,
ControlClass,
ScreenClass,
SysConfigClass,
ErrorRecordUnit;
{$R *.DFM}
{ TForm3 }
function TfrmConnect.DownLoadCard(ControlAddr: string; APort: integer;
ADateTime: TDateTime; AGroupId: integer): integer;
var
mConnection : TADOConnection;
mQuery1,mQuery2 : TADOQuery;
mStr1,mStr2: string;
//mDate : TDateTime;
mCardNo : string;
mState: integer;
mDateTime : TDateTime;
mRecordNo,mRecordCount : integer;
i: integer;
mCardType : string;
mLoseMk : integer;
mUsrType : string;
mRet : integer;
begin
mConnection := GetRemoteConnection();
if mConnection = nil then
begin
Result := -1;
Exit;
end;
mQuery1 := TADOQuery.Create(nil);
mQuery1.Connection := mConnection;
//mQuery2 := TADOQuery.Create(nil);
//mQuery2.Connection := mConnection;
mStr1 := 'select * from card where modi_date > :AModiDate order by card_num';
with mQuery1 do
begin
SQL.Clear;
SQL.Add(mStr1);
try
Parameters.ParamValues['AModiDate'] := ADateTime;
Open;
mRecordCount := RecordCount;
if mRecordCount > 0 then
begin
//写开始
i := 0;
mRecordNo := 0;
while not EOF do
begin
Inc(i);
ShowInformation('正在处理数据(' +IntToStr(i) + '/' + IntToStr(mRecordCount) + ')');
mCardNo := Trim(FieldByName('card_num').AsString);
mCardType := Trim(FieldByName('card_type').AsString);
mLoseMk :=FieldByName('card_state').AsInteger;
mUsrType :=Trim(FieldByName('user_type').AsString);
mDateTime := FieldByName('expire_date').AsDateTime;
mState := 0;
if mCardType = 'ID' then
begin
mState := mState or $1;
end
else if mCardType = 'IC' then
begin
mState := mState and $FE;
end;
if mLoseMk = 0 then
begin
mState := mState and $FB;
end
else if mLoseMk = 1 then
begin
mState := mState or $4;
end;
if (mUsrType = '固定用户') and (mCardType = 'ID') then
begin
mState := mState or $8;
end
else begin
mState := mState and $F7;
end;
mRecordNo := (mRecordNo + 1) mod 256;
if i = 1 then
begin
mRet := gControl.WriteFixCardUser(1,
mCardNo,mState,mDateTime,mRecordNo);
end
else
begin
mRet := gControl.WriteFixCardUser(2,
mCardNo,mState,mDateTime,mRecordNo);
end;
if mRet < 0 then
begin
Result := -2;
//Free;
Exit;
end;
Next;
end;
//写完成
mCardNo := '00000000';
gControl.WriteFixCardUser(3,mCardNo,0,0,0);
end; //end if mRecordcount > 0
except
end; //end try
end; //end with mQuery1
Result := 1;
end;
function TfrmConnect.InitialApp: integer;
begin
gErrorRecord := TErrorRecord.Create();
//得到配置参数
if gConfig = nil then
begin
gConfig := TSysConfig.Create;
gConfig.ReadData;
end;
//不能连接 sql server.
ShowInformation('正在连接远程数据库...');
if ConnectRemote() < 0 then
begin
ShowInformation('连接远程数据库失败!');
gErrorRecord.Append(0,'连接远程数据库失败!');
Sleep(1000);
end;
ShowInformation('正在初始化本地数据库...');
//不能连接 access.
if ConnectLocal() < 0 then
begin
ShowInformation('初始化本地数据库失败,请立即和系统管理员联系!');
Sleep(1000);
ShowMessage('初始化本地数据库失败,请立即和系统管理员联系!');
Application.Terminate; //退出系统
end;
//获取收费站编号
gStationId := GetStationId();
if gStationId < 0 then
begin
Result := -1;
end;
//初始化硬件
//读取硬件的配置数据
//控制器
gControl := TControlMachine.Create(gConfig.ControlAddr,gConfig.ControlPort);
end;
procedure TfrmConnect.ShowInformation(AInfo: string);
begin
lblConnectInfo.Caption := AInfo;
//强制界面刷新
lblConnectInfo.Repaint();
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -