地铁实训闸机在普通收费软件上集成的方法
地铁闸机可以应用于众多收费系统,但是实际运行中,与现有的收费软件集成是各大厂商头痛的问题。我公司主动式开发包,能主动读取数据库,使得收费软件开发商最小修改系统。本开发包与系统数据库直接连接,实际上只是在我公司DIY开发包上添加了主动读取功能,可以支持的数据库为sql server、oracle、access、mysql等,接口可以是储存过程,也可以是多条sql文本。
本程序是关于sql2000连接的测试,实际运行就是此套代码,用delphi xe2开发,望不吝赐教!
1、先打开“dblink.udl”,配置连接字符串,如果连接串不正确,界面要卡10秒左右,请耐心等待一会,该文件是普通的文本文件(请注意防火墙拦截)
2、“模拟”栏可以模拟闸机刷卡的情况
3、储存过程说明:
CREATE PROCEDURE
HeroGodGetMidState ----储存过程名称
@mbrcode varchar(32)----卡号,即闸机送来的键盘式磁条卡卡号
,@macdir tinyint output----方向,即刷卡的方向,该值不需要处理,直接返回即可,用于确定开闸门的方向
,@mbrna nvarchar(50) output -----会员姓名输出
,@mbrrst bit output ------会员是否有效,如果有效就返回1,否则返回0
AS
begin
set @macdir =@macdir;---原方向返回
set @mbrna='用户名';
set @mbrrst=1;--开闸门 -
end;
GO;
4、本程序是我司检票机开发包的接口程序之一,与贵公司系统sql2000数据库直接;启动顺序不重要;实际运行中,我司开发包占用防火墙的“6001~6030”TCP、UDP端口与检票机通信;
5、您的系统不需要关心检票机的繁忙和准备等状态,如果检票机状态暂时不可用,则此过程不会被调用
1、先打开“dblink.udl”,配置连接字符串,如果连接串不正确,界面要卡10秒左右,请耐心等待一会,该文件是普通的文本文件(请注意防火墙拦截)
2、“模拟”栏可以模拟闸机刷卡的情况
3、储存过程说明:
CREATE PROCEDURE
HeroGodGetMidState ----储存过程名称
@mbrcode varchar(32)----卡号,即闸机送来的键盘式磁条卡卡号
,@macdir tinyint output----方向,即刷卡的方向,该值不需要处理,直接返回即可,用于确定开闸门的方向
,@mbrna nvarchar(50) output -----会员姓名输出
,@mbrrst bit output ------会员是否有效,如果有效就返回1,否则返回0
AS
begin
set @macdir =@macdir;---原方向返回
set @mbrna='用户名';
set @mbrrst=1;--开闸门 -
end;
GO;
4、本程序是我司检票机开发包的接口程序之一,与贵公司系统sql2000数据库直接;启动顺序不重要;实际运行中,我司开发包占用防火墙的“6001~6030”TCP、UDP端口与检票机通信;
5、您的系统不需要关心检票机的繁忙和准备等状态,如果检票机状态暂时不可用,则此过程不会被调用
本程序由delphi开发,也可根据需要,提供Lazarus、QT、C#源码,只有一个窗体,源码如下:
Unit7.pas:
unit Unit7;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.ExtCtrls, Vcl.StdCtrls,
Vcl.Samples.Spin, Vcl.Buttons,Data.DB, Data.Win.ADODB,ComObj, ActiveX;
type
TForm7 = class(TForm)
PageControl1: TPageControl;
ts1: TTabSheet;
grdpnl1: TGridPanel;
ts3: TTabSheet;
redt1: TRichEdit;
lbl1: TLabel;
lbl2: TLabel;
edt1: TEdit;
se1: TSpinEdit;
btn1: TBitBtn;
mmo1: TMemo;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form7: TForm7
;
implementation
{$R *.dfm}
var dbconstr:string='';
glb_exedir:string;
procedure TForm7.btn1Click(Sender: TObject);
var con1:TADOConnection;
proc1:TADOStoredProc;
mbrcode:string;
macdir:ShortInt;
mbrrst:Boolean;
mbrna:WideString;
begin
mbrcode:=edt1.text;
macdir:= se1.value;
CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
with con1 do
begin
con1:=TADOConnection.Create(nil);
ConnectionString:='FILE NAME='+glb_exedir+'dblink.udl';
KeepConnection:=false;
LoginPrompt:=False;
Mode:=cmShareDenyNone;
Provider:='SQLOLEDB.1';
ConnectionTimeout:=5;
CommandTimeout:=10;
end;
proc1:=TADOStoredProc.Create(nil);
with proc1 do
begin
Connection:=con1;
AutoCalcFields:=false;
ProcedureName := 'HeroGodGetMidState';
Parameters.CreateParameter('@mbrcode', ftString, pdInput, 32, mbrcode);
Parameters.CreateParameter('@macdir', ftShortint, pdInputOutput, 0, macdir);
Parameters.CreateParameter('@mbrna', ftWideString, pdInputOutput, 50, '');
Parameters.CreateParameter('@mbrrst', ftBoolean, pdInputOutput, 0,mbrrst);
try
ExecProc;
mbrrst:=Parameters.FindParam('@mbrrst').value;
if mbrrst then
begin
macdir:=Parameters.FindParam('@macdir').value;
mbrna:=Parameters.FindParam('@mbrna').value;
end;
except on E: Exception do
end;
end;
proc1.free;
con1.Free;
if mbrrst then
begin
mmo1.Lines.Insert(0, Format('开闸方向:%d,用户名:%s',
[macdir,mbrna]) );
end
else
begin
mmo1.Lines.Insert(0, Format('拒绝',[] ) );
end;
end;
initialization
begin
glb_exedir := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
end;
end.
Unit7.dfm:
object Form7: TForm7
Left = 0
Top = 0
Caption = 'Form7'
ClientHeight = 323
ClientWidth = 534
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object PageControl1: TPageControl
Left = 0
Top = 0
Width = 534
Height = 323
ActivePage = ts3
Align = alClient
TabOrder = 0
object ts3: TTabSheet
Caption = #35828#26126
object redt1: TRichEdit
Left = 0
Top = 0
Width = 526
Height = 295
Align = alClient
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
Lines.Strings = (
#26412#31243#24207#26159#20851#20110'sql2000'#36830#25509#30340#27979#35797#65292#23454#38469#36816#34892#23601#26159#27492#22871#20195#30721#65292#29992'delphi xe2'#24320#21457#65292#26395#19981#21533#36176#25945#65281
''
'1'#12289#20808#25171#24320#8220'dblink.udl'#8221#65292#37197#32622#36830#25509#23383#31526#20018#65292#22914#26524#36830#25509#20018#19981#27491#30830#65292#30028#38754#35201#21345'10'#31186#24038#21491#65292#35831#32784#24515#31561#24453#19968#20250#65292#35813#25991#20214#26159#26222#36890#30340#25991#26412#25991#20214 +
#65288#35831#27880#24847#38450#28779#22681#25318#25130#65289
'2'#12289#8220#27169#25311#8221#26639#21487#20197#27169#25311#38392#26426#21047#21345#30340#24773#20917
'3'#12289#20648#23384#36807#31243#35828#26126#65306
'CREATE PROCEDURE '
'HeroGodGetMidState ----'#20648#23384#36807#31243#21517#31216
'@mbrcode varchar(32)----'#21345#21495#65292#21363#38392#26426#36865#26469#30340#38190#30424#24335#30913#26465#21345#21345#21495
',@macdir tinyint output----'#26041#21521#65292#21363#21047#21345#30340#26041#21521#65292#35813#20540#19981#38656#35201#22788#29702#65292#30452#25509#36820#22238#21363#21487#65292#29992#20110#30830#23450#24320#38392#38376#30340#26041#21521
',@mbrna nvarchar(50) output -----'#20250#21592#22995#21517#36755#20986
',@mbrrst bit output'#9'------'#20250#21592#26159#21542#26377#25928#65292#22914#26524#26377#25928#23601#36820#22238'1'#65292#21542#21017#36820#22238'0'
'AS'
'begin'
' set @macdir =@macdir;---'#21407#26041#21521#36820#22238
''
' set @mbrna='#39#29992#25143#21517#39';'
''
' set @mbrrst=1;--'#24320#38392#38376' -'
''
'end;'
'GO;'
'4'#12289#26412#31243#24207#26159#25105#21496#26816#31080#26426#24320#21457#21253#30340#25509#21475#31243#24207#20043#19968#65292#19982#36149#20844#21496#31995#32479'sql2000'#25968#25454#24211#30452#25509#65307#21551#21160#39034#24207#19981#37325#35201#65307#23454#38469#36816#34892#20013#65292#25105#21496#24320#21457#21253#21344#29992#38450#28779 +
#22681#30340#8220'6001~6030'#8221'TCP'#12289'UDP'#31471#21475#19982#26816#31080#26426#36890#20449#65307
'5'#12289#24744#30340#31995#32479#19981#38656#35201#20851#24515#26816#31080#26426#30340#32321#24537#21644#20934#22791#31561#29366#24577#65292#22914#26524#26816#31080#26426#29366#24577#26242#26102#19981#21487#29992#65292#21017#27492#36807#31243#19981#20250#34987#35843#29992)
ParentFont = False
ScrollBars = ssBoth
TabOrder = 0
end
end
object ts1: TTabSheet
Caption = #27169#25311
object grdpnl1: TGridPanel
Left = 0
Top = 0
Width = 526
Height = 295
Align = alClient
Caption = 'grdpnl1'
ColumnCollection = <
item
Value = 20.000000000000000000
end
item
Value = 20.000000000000000000
end
item
Value = 20.000000000000000000
end
item
Value = 20.000000000000000000
end
item
Value = 20.000000000000000000
end>
ControlCollection = <
item
Column = 1
Control = lbl1
Row = 1
end
item
Column = 1
Control = lbl2
Row = 2
end
item
Column = 2
Control = edt1
Row = 1
end
item
Column = 2
Control = se1
Row = 2
end
item
Column = 3
Control = btn1
Row = 3
end
item
Column = 1
ColumnSpan = 3
Control = mmo1
Row = 4
end>
RowCollection = <
item
Value = 18.058690744921000000
end
item
SizeStyle = ssAbsolute
Value = 30.000000000000000000
end
item
SizeStyle = ssAbsolute
Value = 30.000000000000000000
end
item
SizeStyle = ssAbsolute
Value = 30.000000000000000000
end
item
Value = 67.720090293453720000
end
item
Value = 14.221218961625280000
end>
ShowCaption = False
TabOrder = 0
DesignSize = (
526
295)
object lbl1: TLabel
Left = 143
Top = 45
Width = 28
Height = 13
Anchors = []
Caption = #21345#21495':'
ExplicitLeft = 70
ExplicitTop = 91
end
object lbl2: TLabel
Left = 143
Top = 75
Width = 28
Height = 13
Anchors = []
Caption = #26041#21521':'
ExplicitLeft = 70
ExplicitTop = 121
end
object edt1: TEdit
Left = 209
Top = 41
Width = 104
Height = 21
Anchors = []
TabOrder = 0
Text = '12345678'
end
object se1: TSpinEdit
Left = 209
Top = 71
Width = 104
Height = 22
Anchors = []
MaxValue = 1
MinValue = 0
TabOrder = 1
Value = 0
end
object btn1: TBitBtn
Left = 327
Top = 99
Width = 75
Height = 25
Anchors = []
Kind = bkOK
NumGlyphs = 2
TabOrder = 2
OnClick = btn1Click
end
object mmo1: TMemo
Left = 105
Top = 127
Width = 312
Height = 137
Align = alClient
ScrollBars = ssVertical
TabOrder = 3
end
end
end
end
end
unit Unit7;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.ExtCtrls, Vcl.StdCtrls,
Vcl.Samples.Spin, Vcl.Buttons,Data.DB, Data.Win.ADODB,ComObj, ActiveX;
type
TForm7 = class(TForm)
PageControl1: TPageControl;
ts1: TTabSheet;
grdpnl1: TGridPanel;
ts3: TTabSheet;
redt1: TRichEdit;
lbl1: TLabel;
lbl2: TLabel;
edt1: TEdit;
se1: TSpinEdit;
btn1: TBitBtn;
mmo1: TMemo;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form7: TForm7
;
implementation
{$R *.dfm}
var dbconstr:string='';
glb_exedir:string;
procedure TForm7.btn1Click(Sender: TObject);
var con1:TADOConnection;
proc1:TADOStoredProc;
mbrcode:string;
macdir:ShortInt;
mbrrst:Boolean;
mbrna:WideString;
begin
mbrcode:=edt1.text;
macdir:= se1.value;
CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
with con1 do
begin
con1:=TADOConnection.Create(nil);
ConnectionString:='FILE NAME='+glb_exedir+'dblink.udl';
KeepConnection:=false;
LoginPrompt:=False;
Mode:=cmShareDenyNone;
Provider:='SQLOLEDB.1';
ConnectionTimeout:=5;
CommandTimeout:=10;
end;
proc1:=TADOStoredProc.Create(nil);
with proc1 do
begin
Connection:=con1;
AutoCalcFields:=false;
ProcedureName := 'HeroGodGetMidState';
Parameters.CreateParameter('@mbrcode', ftString, pdInput, 32, mbrcode);
Parameters.CreateParameter('@macdir', ftShortint, pdInputOutput, 0, macdir);
Parameters.CreateParameter('@mbrna', ftWideString, pdInputOutput, 50, '');
Parameters.CreateParameter('@mbrrst', ftBoolean, pdInputOutput, 0,mbrrst);
try
ExecProc;
mbrrst:=Parameters.FindParam('@mbrrst').value;
if mbrrst then
begin
macdir:=Parameters.FindParam('@macdir').value;
mbrna:=Parameters.FindParam('@mbrna').value;
end;
except on E: Exception do
end;
end;
proc1.free;
con1.Free;
if mbrrst then
begin
mmo1.Lines.Insert(0, Format('开闸方向:%d,用户名:%s',
[macdir,mbrna]) );
end
else
begin
mmo1.Lines.Insert(0, Format('拒绝',[] ) );
end;
end;
initialization
begin
glb_exedir := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
end;
end.
unit Unit7;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.ExtCtrls, Vcl.StdCtrls,
Vcl.Samples.Spin, Vcl.Buttons,Data.DB, Data.Win.ADODB,ComObj, ActiveX;
type
TForm7 = class(TForm)
PageControl1: TPageControl;
ts1: TTabSheet;
grdpnl1: TGridPanel;
ts3: TTabSheet;
redt1: TRichEdit;
lbl1: TLabel;
lbl2: TLabel;
edt1: TEdit;
se1: TSpinEdit;
btn1: TBitBtn;
mmo1: TMemo;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form7: TForm7
;
implementation
{$R *.dfm}
var dbconstr:string='';
glb_exedir:string;
procedure TForm7.btn1Click(Sender: TObject);
var con1:TADOConnection;
proc1:TADOStoredProc;
mbrcode:string;
macdir:ShortInt;
mbrrst:Boolean;
mbrna:WideString;
begin
mbrcode:=edt1.text;
macdir:= se1.value;
CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
with con1 do
begin
con1:=TADOConnection.Create(nil);
ConnectionString:='FILE NAME='+glb_exedir+'dblink.udl';
KeepConnection:=false;
LoginPrompt:=False;
Mode:=cmShareDenyNone;
Provider:='SQLOLEDB.1';
ConnectionTimeout:=5;
CommandTimeout:=10;
end;
proc1:=TADOStoredProc.Create(nil);
with proc1 do
begin
Connection:=con1;
AutoCalcFields:=false;
ProcedureName := 'HeroGodGetMidState';
Parameters.CreateParameter('@mbrcode', ftString, pdInput, 32, mbrcode);
Parameters.CreateParameter('@macdir', ftShortint, pdInputOutput, 0, macdir);
Parameters.CreateParameter('@mbrna', ftWideString, pdInputOutput, 50, '');
Parameters.CreateParameter('@mbrrst', ftBoolean, pdInputOutput, 0,mbrrst);
try
ExecProc;
mbrrst:=Parameters.FindParam('@mbrrst').value;
if mbrrst then
begin
macdir:=Parameters.FindParam('@macdir').value;
mbrna:=Parameters.FindParam('@mbrna').value;
end;
except on E: Exception do
end;
end;
proc1.free;
con1.Free;
if mbrrst then
begin
mmo1.Lines.Insert(0, Format('开闸方向:%d,用户名:%s',
[macdir,mbrna]) );
end
else
begin
mmo1.Lines.Insert(0, Format('拒绝',[] ) );
end;
end;
initialization
begin
glb_exedir := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
end;
end.
unit Unit7;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.ExtCtrls, Vcl.StdCtrls,
Vcl.Samples.Spin, Vcl.Buttons,Data.DB, Data.Win.ADODB,ComObj, ActiveX;
type
TForm7 = class(TForm)
PageControl1: TPageControl;
ts1: TTabSheet;
grdpnl1: TGridPanel;
ts3: TTabSheet;
redt1: TRichEdit;
lbl1: TLabel;
lbl2: TLabel;
edt1: TEdit;
se1: TSpinEdit;
btn1: TBitBtn;
mmo1: TMemo;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form7: TForm7
;
implementation
{$R *.dfm}
var dbconstr:string='';
glb_exedir:string;
procedure TForm7.btn1Click(Sender: TObject);
var con1:TADOConnection;
proc1:TADOStoredProc;
mbrcode:string;
macdir:ShortInt;
mbrrst:Boolean;
mbrna:WideString;
begin
mbrcode:=edt1.text;
macdir:= se1.value;
CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
with con1 do
begin
con1:=TADOConnection.Create(nil);
ConnectionString:='FILE NAME='+glb_exedir+'dblink.udl';
KeepConnection:=false;
LoginPrompt:=False;
Mode:=cmShareDenyNone;
Provider:='SQLOLEDB.1';
ConnectionTimeout:=5;
CommandTimeout:=10;
end;
proc1:=TADOStoredProc.Create(nil);
with proc1 do
begin
Connection:=con1;
AutoCalcFields:=false;
ProcedureName := 'HeroGodGetMidState';
Parameters.CreateParameter('@mbrcode', ftString, pdInput, 32, mbrcode);
Parameters.CreateParameter('@macdir', ftShortint, pdInputOutput, 0, macdir);
Parameters.CreateParameter('@mbrna', ftWideString, pdInputOutput, 50, '');
Parameters.CreateParameter('@mbrrst', ftBoolean, pdInputOutput, 0,mbrrst);
try
ExecProc;
mbrrst:=Parameters.FindParam('@mbrrst').value;
if mbrrst then
begin
macdir:=Parameters.FindParam('@macdir').value;
mbrna:=Parameters.FindParam('@mbrna').value;
end;
except on E: Exception do
end;
end;
proc1.free;
con1.Free;
if mbrrst then
begin
mmo1.Lines.Insert(0, Format('开闸方向:%d,用户名:%s',
[macdir,mbrna]) );
end
else
begin
mmo1.Lines.Insert(0, Format('拒绝',[] ) );
end;
end;
initialization
begin
glb_exedir := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
end;
end.
相关栏目: