📄 unit2.pas
字号:
end;
procedure Tmainform.Timer1Timer(Sender: TObject);
begin
editdate.Text:=formatdatetime('yyyy-mm-dd hh:mm:ss',now);
end;
procedure Tmainform.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
maxrow:integer;
tmpzk,tmpzr:real;
begin
if key=Vk_F1 then
begin
if row>0 then
begin
messagebox(mainform.handle,'还有未交易数据','提示',MB_OK+MB_ICONINFORMATION);
exit;
end;
form1.Show;
mainform.Hide;
end;
if tmpaction='折扣' then
begin
if key=VK_F3 then
begin
maxrow:=row-1;
stringGrid1.Cells[5,maxrow]:=pcodeedit.text;
tmpzk:=strtofloat(stringGrid1.Cells[6,maxrow])*(1-(strtoint(pcodeedit.text)/100));
stringGrid1.Cells[6,maxrow]:=formatfloat('0.00',strtofloat(stringGrid1.Cells[6,maxrow])*(strtoint(pcodeedit.text)/100));
edit1.Text:=formatfloat('0.00',strtofloat(edit1.text)-tmpzk);
edit2.Text:=formatfloat('0.00',strtofloat(edit2.text)-tmpzk);
pcodeedit.Clear;
pcodeedit.SetFocus;
tmpaction:='';
if mainform.IsShowed then
begin
//客显显示
//使用 COM1。
mainform.MSComm1.CommPort :=1;
//9600 波特,无奇偶校验,8 位数据,一个停止位。
mainform.MSComm1.Settings := '9600,N,8,1';
//当输入占用时,
//告诉控件读入整个缓冲区。
mainform.MSComm1.InputLen := 0;
//打开端口。
mainform.MSComm1.PortOpen := True;
//将 attention 命令送到调制解调器。
mainform.MSComm1.Output := Chr($1B) + Chr($51) + Chr($41) + ' THANKS'+Chr(13);
mainform.MSComm1.Output := Chr($1B) + Chr($51) + Chr($42) + 'TOTAL '+edit2.Text+ Chr(13); //确保
//关闭串行端口。
mainform.MSComm1.PortOpen := False;
end;
end;
end;
if tmpaction='折让' then
begin
if edit1.text='' then
exit
else
if key=VK_F3 then
begin
maxrow:=row-1;
tmpzr:=strtofloat(stringGrid1.Cells[7,maxrow]);
stringGrid1.Cells[7,maxrow]:=floattostr(strtofloat(pcodeedit.text)+tmpzr);
stringGrid1.Cells[6,maxrow]:=formatfloat('0.00',strtofloat(stringGrid1.Cells[6,maxrow])-strtofloat(pcodeedit.text));
edit1.text:=formatfloat('0.00',strtofloat(edit1.text)-strtofloat(pcodeedit.text));
edit2.text:=formatfloat('0.00',strtofloat(edit2.text)-strtofloat(pcodeedit.text));
pcodeedit.Clear;
pcodeedit.SetFocus;
tmpaction:='';
if mainform.IsShowed then
begin
//客显显示
//使用 COM1。
mainform.MSComm1.CommPort :=1;
//9600 波特,无奇偶校验,8 位数据,一个停止位。
mainform.MSComm1.Settings := '9600,N,8,1';
//当输入占用时,
//告诉控件读入整个缓冲区。
mainform.MSComm1.InputLen := 0;
//打开端口。
mainform.MSComm1.PortOpen := True;
//将 attention 命令送到调制解调器。
mainform.MSComm1.Output := Chr($1B) + Chr($51) + Chr($41) + ' THANKS'+Chr(13);
mainform.MSComm1.Output := Chr($1B) + Chr($51) + Chr($42) + 'TOTAL '+edit2.Text+ Chr(13); //确保
//关闭串行端口。
mainform.MSComm1.PortOpen := False;
end;
end;
end;
if tmpaction='合计折扣' then
begin
if key=VK_F3 then
begin
edit3.text:=pcodeedit.text;
tmpzk:=strtofloat(edit1.text)*(1-(strtoint(edit3.text)/100));
edit2.Text:=formatfloat('0.00',strtofloat(edit1.text)-tmpzk);
pcodeedit.Clear;
pcodeedit.SetFocus;
tmpaction:='';
if mainform.IsShowed then
begin
//客显显示
//使用 COM1。
mainform.MSComm1.CommPort :=1;
//9600 波特,无奇偶校验,8 位数据,一个停止位。
mainform.MSComm1.Settings := '9600,N,8,1';
//当输入占用时,
//告诉控件读入整个缓冲区。
mainform.MSComm1.InputLen := 0;
//打开端口。
mainform.MSComm1.PortOpen := True;
//将 attention 命令送到调制解调器。
mainform.MSComm1.Output := Chr($1B) + Chr($51) + Chr($41) + ' THANKS'+Chr(13);
mainform.MSComm1.Output := Chr($1B) + Chr($51) + Chr($42) + 'TOTAL '+edit2.Text+ Chr(13); //确保
//关闭串行端口。
mainform.MSComm1.PortOpen := False;
end;
end;
end;
end;
procedure Tmainform.FormShow(Sender: TObject);
var
fn:TFileName;
s:string;
sys:Tsyssetting;
begin
//判断当前状态
if curstate=false then
mainform.Labelstate.Caption:='单机'
else
mainform.Labelstate.Caption:='';
//隐藏鼠标
MakeCursorHide;
//设置焦点
pcodeedit.SetFocus;
//设置收银员与售货员
editclerk.Text:=form1.User.Text;
editbkclerk.Text:=form1.User.Text;
editsaler.Text:=form1.User.Text;
//读设置文件setting.sys中的pos机编号
fn:='setting.sys';
getdir(0,s);
if FileExists(fn) then
begin
try
assignfile(sysfile,fn);
reset(sysfile);
while not Eof(sysfile) do
begin
read(sysfile,sys);
labelposcode.text:=' '+sys.poscode;
if trim(sys.IsPrint)='是' then
IsPrinted:=true
else
IsPrinted:=false;
if trim(sys.IsShow)='是' then
IsShowed:=true
else
IsShowed:=false;
end;
finally
Closefile(sysfile);
end;
end;
end;
procedure Tmainform.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=VK_ESCAPE then
begin
pcodeedit.Text:='';
pcodeedit.SetFocus;
end;
end;
procedure Tmainform.MakeCursorHide;
begin
SetCursorPos(0,0);
end;
procedure Tmainform.ReadFromBase;
var
tmpsql:string;
tmpsj,tmphj,tmpzk:real;
i:integer;
begin
with mainform.query2 do
begin
tmpsql:='select * from pricebase where 条码='''+trim(mainform.Pcodeedit.text)+'''';
close;
sql.clear;
sql.add(tmpsql);
prepare;
try
open;
except
messagebox(mainform.handle,'现在转入单机模式','提示',MB_OK+MB_ICONINFORMATION);
mainform.Labelstate.Caption:='单机';
form1.database1.Close;
form1.database1.AliasName:='curposdata';
form1.database1.Open;
exit;
end;
end;
if mainform.query2['品名']=null then
messagebox(mainform.handle,'对不起,找不到商品!','提示',MB_OK+MB_ICONINFORMATION)
else
begin
tmpzk:=mainform.query2.fieldbyname('折扣').asfloat;
mainform.stringGrid1.Cells[0,row]:=mainform.query2['条码'];
mainform.stringGrid1.Cells[1,row]:=mainform.query2['品名'];
mainform.stringGrid1.Cells[2,row]:=mainform.query2['销售部门'];
tmpsj:=mainform.query2['售价'];
mainform.stringGrid1.Cells[3,row]:=formatfloat('0.00',tmpsj);
mainform.stringGrid1.Cells[4,row]:=inttostr(1);
mainform.stringGrid1.Cells[5,row]:=floattostr(tmpzk);
if tmpzk=0 then
tmpzk:=100;
mainform.stringGrid1.Cells[6,row]:=formatfloat('0.00',tmpsj*(tmpzk/100));
mainform.stringGrid1.Cells[7,row]:='0';
tmphj:=0;
for i:=0 to row do
begin
tmphj:=tmphj+strtofloat(mainform.stringGrid1.Cells[6,i]);
end;
mainform.Edit1.Text:=formatfloat('0.00',tmphj);
if (mainform.edit3.text<>'') and (mainform.edit3.text<>'0') then
mainform.edit2.Text:=formatfloat('0.00',tmphj*strtofloat(mainform.edit3.text)/100)
else
mainform.edit2.Text:=formatfloat('0.00',tmphj);
if mainform.IsShowed then
begin
//客显显示
//使用 COM1。
mainform.MSComm1.CommPort :=1;
//9600 波特,无奇偶校验,8 位数据,一个停止位。
mainform.MSComm1.Settings := '9600,N,8,1';
//当输入占用时,
//告诉控件读入整个缓冲区。
mainform.MSComm1.InputLen := 0;
//打开端口。
mainform.MSComm1.PortOpen := True;
//将 attention 命令送到调制解调器。
mainform.MSComm1.Output := Chr($1B) + Chr($51) + Chr($41) + 'PRICE '+mainform.stringGrid1.Cells[3,row]+ Chr(13); //确保
mainform.MSComm1.Output := Chr($1B) + Chr($51) + Chr($42) + 'TOTAL '+formatfloat('#,##0.00',tmphj)+ Chr(13); //确保
//关闭串行端口。
mainform.MSComm1.PortOpen := False;
end;
row:=row+1;
mainform.pcodeedit.Text:='';
end;
mainform.pcodeedit.SetFocus;
end;
procedure Tmainform.FormKeyPress(Sender: TObject; var Key: Char);
var
i,j,lastmonth:integer;
tmphj:real;
tmpposcode,tmpdatetime,curdate,lastdate,tmpsql:string;
tmptotal,cash,tmpcheck,tmpcard,tmpother,tmpshop,tmpwait:string;
endtime:string;
Year, Month, Day:word;
tmpyear,tmpmonth,tmpgcode,tmpday:string;
begin
if key='x' then //打印收银员收款报表-统计一
begin
application.CreateForm(Tformmessage,formmessage);
formmessage.Show;
application.ProcessMessages;
//判断是否有单机数据,如果有就上传
//判断网络是否连通
try
form1.databasetest.Connected:=false;
form1.databasetest.AliasName:='guohua';
form1.databasetest.Connected:=true;
if form1.database1.AliasName='curposdata' then
begin
form1.database1.Connected:=false;
form1.database1.AliasName:='guohua';
form1.database1.Connected:=true;
curstate:=true;
end;
except
curstate:=false;
form1.database1.Connected:=false;
form1.database1.AliasName:='curposdata';
form1.database1.Connected:=true;
end;
if form1.database1.AliasName='guohua' then
begin
//把本地数据上传
//读取最大的交易流水号
with form1.qryserupload do
begin
tmpsql:='select max(sno) as Msno from trade';// where clerk=''123''';
close;
sql.Clear;
sql.Add(tmpsql);
prepare;
try
open;
except
messagebox(mainform.handle,'数据库连接失败','错误',MB_OK);
exit;
end;
end;
if form1.qryserupload['msno']=null then
sno:=0
else
sno:=form1.qryserupload['msno'];
with form1.qryposupload do
begin
tmpsql:='select * from trade';
close;
sql.clear;
sql.add(tmpsql);
prepare;
try
open;
except
messagebox(mainform.handle,'本地数据库连接失败,检查网络','警告',MB_OK+MB_ICONERROR);
exit;
end;
end;
form1.database1.StartTransaction;
try
i:=0;
while not form1.qryposupload.Eof do
begin
with form1.qryserupload do
begin
if (i mod 2)=0 then
sno:=sno+1;
tmpsql:='Insert Into trade(op,ecr,clerk,tmpclerk,saler,saledate,saletime,sno,orgtotal,total,totaldis,totalsub,';
tmpsql:=tmpsql+'pay1,pay2,pay3,pay4,pay5,pay6,change,dept,code,name,discount,num,price,amount,sub,imark)';
tmpsql:=tmpsql+' values('''+form1.qryposupload['op']+''','''+form1.qryposupload['ecr']+''','''+form1.qryposupload['clerk']+''','''+form1.qrypo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -