📄 frmreaddevices.pas
字号:
unit FrmReadDeviceS;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, fcLabel, StdCtrls, TFlatButtonUnit,ICCTRL,IniFiles,
TFlatProgressBarUnit;
type
PClockInfo=^TClockInfo;
TClockInfo=record
ID: WORD;
ClockNo: String;
ClockName: String;
Port: WORD;
BaudRate: DWORD;
end;
type
TFrmReadDevice = class(TForm)
Notebook1: TNotebook;
Image1: TImage;
Bevel1: TBevel;
fcLabel1: TfcLabel;
Bevel2: TBevel;
fcLabel2: TfcLabel;
Image2: TImage;
Bevel4: TBevel;
fcLabel4: TfcLabel;
Image4: TImage;
Label1: TLabel;
ListBox1: TListBox;
CheckBox1: TCheckBox;
FlatButton1: TFlatButton;
FlatButton2: TFlatButton;
FlatButton6: TFlatButton;
FlatButton7: TFlatButton;
FlatButton8: TFlatButton;
FlatButton9: TFlatButton;
FlatButton11: TFlatButton;
Label3: TLabel;
FlatProgressBar1: TFlatProgressBar;
Label4: TLabel;
Label5: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure FlatButton2Click(Sender: TObject);
procedure FlatButton1Click(Sender: TObject);
procedure FlatButton5Click(Sender: TObject);
procedure readdata();
procedure FlatButton3Click(Sender: TObject);
procedure FlatButton7Click(Sender: TObject);
procedure FlatButton6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FrmReadDevice: TFrmReadDevice;
implementation
uses MainFRMS, DTConnects;
{$R *.dfm}
function OpenPort(pclk: PClockInfo):THandle;
var
Ret : DWORD;
begin
Screen.Cursor:=crHourGlass;
try
MainFRM.StatusBar1.Panels[0].Text := Format('正在连接"%s"...', [pclk.ClockName]);
Result := OpenCommPort(pclk.Port, pclk.BaudRate);
if Result<>INVALID_HANDLE_VALUE then
begin
Ret:=LinkCommPort(Result, PChar(pclk.ClockNo));
case Ret of
OPEN_PORT_FAILE : MainFRM.StatusBar1.Panels[0].Text := Format('不能打开端口"%d"!', [pclk.Port]);
CREATE_LINK_TIMEOUT : MainFRM.StatusBar1.Panels[0].Text := Format('连接设备"%s"超时!', [pclk.ClockNo]);
LINK_FAILE : MainFRM.StatusBar1.Panels[0].Text := Format('连接设备"%s"失败!', [pclk.ClockNo]);
COMM_PORT_INVALID : MainFRM.StatusBar1.Panels[0].Text := Format('端口"%d"无效', [pclk.Port]);
end;
if Ret<>0 then
begin
CloseCommPort(Result);
Result:=0;
end;
end else begin
MainFRM.StatusBar1.Panels[0].Text:='Connected...';
Result:=0;
end;
finally
Screen.Cursor:=crDefault;
end;
end;
procedure TFrmReadDevice.ReadData();
var ReadInfo:TIniFile;
FileName,S,ICCardNo,GetTime,UserName:String;
DeviceCount,i,j:integer;
InfoStr:String;
pclk: PClockInfo;
hPort: THandle;
Right: Boolean;
nSize : Cardinal;
Rd : TClockData;
begin
DeviceCount:=1;
nSize:=0;
for i:=1 to ListBox1.Count do begin
new(pclk);
pclk.ClockNo:=copy(ListBox1.Items.Strings[i-1],1,2);
pclk.ClockName:=copy(ListBox1.Items.Strings[i-1],4,2);
pclk.BaudRate:=StrToIntDef('9600', 9600);
pclk.Port:=StrToIntDef('0001',4);
hPort:=OpenPort(pclk);
if hPort<>0 then begin
repeat
SetLength(S, 100);
right:=ReadDataStr(hPort,pchar(S),DeviceCount);
Inc(DeviceCount);
StrLCopy(@RD.Card, PChar(S), 10);
SetLength(S, StrLen(PChar(S)));
Label5.Caption:=inttostr(DeviceCount);
if StrPos(@Rd.Card[1],'OVER')<>nil then
break;
ICCardNo:=copy(s,11,5);
GetTime:=copy(s,1,2)+'-'+copy(s,3,2)+'-'+copy(s,5,2)+
' '+copy(s,7,2)+':'+copy(s,9,2);
with DTConnect do begin
QryUser.Close;
QryUser.SQL.Text:='Select UserName,AddCount from [User] where IccardNO ='+
chr(39)+ICCardNo+chr(39);
QryUser.Open;
UserName:=QryUser.FieldValues['UserName'];
QrySellMoney.Close;
QrySellMoney.SQL.Text:='Select Top 1 * from SellMoney';
QrySellMoney.Open;
QrySellMoney.Append;
QrySellMoney.FieldByName('Device').AsString:=ListBox1.Items.Strings[i-1];
QrySellMoney.FieldByName('Getdate').AsDateTime:=StrToDateTime(GetTime);
QrySellMoney.FieldByName('UserName').AsString:=UserName;
QrySellMoney.FieldByName('IccardNo').AsString:=copy(s,11,5);
QrySellMoney.FieldByName('Money').AsCurrency:=StrToCurr(copy(s,20,3)+'.'+copy(s,23,1));
QrySellMoney.FieldByName('UseMoney').AsCurrency:=StrToCurr(copy(s,25,3)+'.'+copy(s,28,1));
QrySellMoney.Post;
end;
windows.Beep(2500,150);
until FALSE;
end else begin
Application.MessageBox('读卡机链接不成功!','操作提示',0+16);
end;
FlatProgressBar1.Position:=FlatProgressBar1.Position+1;
CloseCommPort(hPort);
FreeMemory(pclk);
end;
if hPort <>0 then
Notebook1.PageIndex:=Notebook1.PageIndex +1;
end;
procedure TFrmReadDevice.FormCreate(Sender: TObject);
var FileName,StrInfo:String;
ReadInfo:TIniFile;
i:integer;
begin
FileName:=ExtractFilePath(Application.ExeName)+'CardInfo.ini';
ReadInfo:=TIniFile.Create(FileName);
with ReadInfo do begin
for i:=1 to StrToInt(ReadString('Device','Counter','0')) do begin
StrInfo:=ReadString('Device','Device'+inttostr(i),'');
ListBox1.Items.Add (copy(StrInfo,3,2)+'-'+copy(StrInfo,17,StrLen(pchar(StrInfo))-16));
end;
FlatProgressBar1.Max:=i;
FlatProgressBar1.Min:=0;
end;
end;
procedure TFrmReadDevice.FlatButton2Click(Sender: TObject);
begin
self.Release;
end;
procedure TFrmReadDevice.FlatButton1Click(Sender: TObject);
begin
if (ListBox1.SelCount =0) and (CheckBox1.Checked=false) then
Application.MessageBox('请选择要读取的消费机!','操作提示',0+64)
else
Notebook1.PageIndex:=Notebook1.PageIndex+1;
end;
procedure TFrmReadDevice.FlatButton5Click(Sender: TObject);
begin
Notebook1.PageIndex:=Notebook1.PageIndex -1;
end;
procedure TFrmReadDevice.FlatButton3Click(Sender: TObject);
begin
Notebook1.PageIndex:=Notebook1.PageIndex +1;
end;
procedure TFrmReadDevice.FlatButton7Click(Sender: TObject);
begin
readdata;
end;
procedure TFrmReadDevice.FlatButton6Click(Sender: TObject);
begin
Notebook1.PageIndex:=Notebook1.PageIndex -1;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -