📄 unit2.pas
字号:
//关闭串行端口。
mainform.MSComm1.PortOpen := False;
end;
end
else
begin
tmpaction:='折扣';
mainform.SetFocus;
end;
end
else
begin
Application.MessageBox('请输入0-100之间的整数!','提示',MB_OK+MB_ICONINFORMATION);
key:=chr(0);
end;
end;
if (key='g') and (row>0) then //合计折扣
begin
try
strtoint(pcodeedit.text);
except
Application.MessageBox('请输入整数!','提示',MB_OK+MB_ICONINFORMATION);
key:=chr(0);
pcodeedit.SetFocus;
Exit;
end;
if (strtoint(pcodeedit.text)>0) and (strtoint(pcodeedit.text)<100) then
begin
if (strtoint(pcodeedit.text)/100<0) 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
else
begin
tmpaction:='合计折扣';
mainform.SetFocus;
end;
end
else
Application.MessageBox('请输入0-100之间的整数!','提示',MB_OK+MB_ICONINFORMATION);
key:=chr(0);
end;
if key='h' then //取消交易
begin
for i:=0 to row-1 do
for j:=0 to 7 do
begin
mainform.stringGrid1.Cells[j,i]:='';
end;
mainform.edit1.text:='';
mainform.edit2.text:='';
mainform.edit3.text:='';
mainform.Editsaler.Text:='';
mainform.Edittotalsub.Text:='';
row:=0;
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 '+'0.00' + Chr(13); //确保
//关闭串行端口。
mainform.MSComm1.PortOpen := False;
end;
end;
if key='i' then //替班
begin
application.CreateForm(Tformconfirm,formconfirm);
formconfirm.showmodal;
if confirm=true then
begin
confirm:=false;
application.CreateForm(Tformbkclerk,formbkclerk);
formbkclerk.showmodal;
end;
end;
if key='j' then //开钱箱
begin
application.CreateForm(Tformconfirm,formconfirm);
formconfirm.showmodal;
if confirm=true then
begin
confirm:=false;
printer.BeginDoc;
printer.canvas.Font.name:='control';
printer.Canvas.Font.Size:=10;
printer.Canvas.TextOut(10,10,'A');
printer.EndDoc;
end;
end;
if (key='k') and (row>0) then //合计折让
begin
try
strtofloat(pcodeedit.text);
except
Application.MessageBox('请输入实数!','提示',MB_OK+MB_ICONINFORMATION);
key:=chr(0);
pcodeedit.SetFocus;
Exit;
end;
if strtofloat(pcodeedit.text)<strtofloat(edit2.text) then
begin
if (strtofloat(pcodeedit.text)/strtofloat(edit2.text)<0) then
begin
edit2.text:=formatfloat('0.00',strtofloat(edit2.text)-strtofloat(pcodeedit.text));
edittotalsub.text:=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
else
begin
tmpaction:='合计折让';
mainform.SetFocus;
end;
end;
end;
if (key='l') and (row>0) then //立即更正
begin
maxrow:=row-1;
stringGrid1.Rows[maxrow].Clear;
row:=row-1;
pcodeedit.SetFocus;
tmphj:=0;
for i:=0 to row-1 do
begin
tmphj:=tmphj+strtofloat(mainform.stringGrid1.Cells[6,i]);
end;
edit1.text:=formatfloat('0.00',tmphj);
if (edit3.text='') or (edit3.text='0') then
edit2.text:=formatfloat('0.00',tmphj)
else
edit2.text:=formatfloat('0.00',tmphj*strtofloat(edit3.text)/100);
if row=0 then
begin
mainform.Editsaler.Text:='';
mainform.Edittotalsub.Text:='';
mainform.Edit3.Text:='';
end;
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 '+formatfloat('#,##0.00',tmphj) + Chr(13); //确保
//关闭串行端口。
mainform.MSComm1.PortOpen := False;
end;
end;
if (key='m') and (row>0) then //挂帐处理-存信息
begin
gznum:=inputbox('挂帐处理','请输入挂帐编号','');
if gznum='' then
messagebox(mainform.handle,'编号不能为空!','警告',MB_OK+MB_ICONINFORMATION)
else
begin
//判断编号是否存在
with querycur do
begin
tmpsql:='select * from tmptrade where tradenum='''+gznum+'''';
close;
sql.clear;
sql.add(tmpsql);
prepare;
try
open;
except
messagebox(mainform.handle,'数据库连接失败','错误',MB_OK);
exit;
end;
end;
if querycur.Eof then
begin
// form1.Database2.StartTransaction;
try
for i:=0 to row-1 do
with querycur do
begin
tmpsql:='Insert Into tmptrade(tradenum,Pdept,Pcode,Pname,discount,Pnum,price,amount,sub,sumamount,totaldis,totalsub,receive)';
tmpsql:=tmpsql+' values('''+gznum+''','''+mainform.stringGrid1.cells[2,i]+''','''+mainform.stringGrid1.cells[0,i]+''','''+trim(mainform.stringGrid1.cells[1,i])+''',';
tmpsql:=tmpsql+''''+mainform.stringGrid1.cells[5,i]+''',:gcount,';
tmpsql:=tmpsql+':tmpdj,:tmpje,:tmpzr,:tmpsumamount,:tmptotaldis,:xjzr,:tmpys)';
close;
sql.clear;
sql.add(tmpsql);
parambyname('gcount').asfloat:=strtofloat(mainform.stringGrid1.cells[4,i]);
parambyname('tmpdj').asfloat:= strtofloat(mainform.stringGrid1.cells[3,i]);
parambyname('tmpje').asfloat:= strtofloat(mainform.stringGrid1.cells[6,i]);
parambyname('tmpzr').asfloat:= strtofloat(mainform.stringGrid1.cells[7,i]);
parambyname('tmpsumamount').asfloat:= strtofloat(mainform.edit1.text);
parambyname('tmpys').asfloat:= strtofloat(mainform.edit2.text);
if (mainform.edit3.text='') or (mainform.Edit3.text='0') then
parambyname('tmptotaldis').asinteger:=0
else
parambyname('tmptotaldis').asinteger:= strtoint(mainform.edit3.text);
if (mainform.Edittotalsub.Text='') then
parambyname('xjzr').asfloat:=0
else
parambyname('xjzr').asfloat:= strtofloat(mainform.edittotalsub.text);
prepare;
try
execsql;
except
messagebox(mainform.handle,'挂帐失败','错误',MB_OK);
pcodeedit.Text:='';
exit;
end;
end;
// form1.Database2.Commit;
//清除数据
for i:=0 to row-1 do
for j:=0 to 7 do
begin
mainform.stringGrid1.Cells[j,i]:='';
end;
mainform.edit1.text:='';
mainform.edit2.text:='';
mainform.edit3.text:='';
mainform.Editsaler.Text:='';
mainform.Edittotalsub.Text:='';
except
//form1.Database2.Rollback;
messagebox(mainform.handle,'数据写入失败','错误',MB_OK);
exit;
end;
row:=0;
messagebox(mainform.handle,'挂帐操作完成','提示',MB_OK);
end
else
begin
messagebox(mainform.handle,'此编号已经存在','提示',MB_OK);
key:=chr(0);
exit;
end;
end;
end;
if key='n' then ////挂帐处理-取信息
begin
with querycur do
begin
tmpsql:='select * from tmptrade';
close;
sql.clear;
sql.add(tmpsql);
prepare;
try
open;
except
messagebox(mainform.handle,'数据库连接失败','错误',MB_OK);
key:=chr(0);
exit;
end;
end;
if not querycur.Eof then
begin
gznum:=inputbox('挂帐处理','请输入挂帐编号','');
if gznum='' then
begin
messagebox(mainform.handle,'编号不能为空!','警告',MB_OK+MB_ICONINFORMATION);
key:=chr(0);
end
else
begin
with querycur do
begin
tmpsql:='select * from tmptrade where tradenum='''+gznum+'''';
close;
sql.clear;
sql.add(tmpsql);
prepare;
try
open;
except
messagebox(mainform.handle,'数据库连接失败','错误',MB_OK);
pcodeedit.Text:='';
exit;
end;
end;
while not querycur.Eof do
begin
mainform.stringGrid1.Cells[0,row]:=mainform.querycur['Pcode'];
mainform.stringGrid1.Cells[1,row]:=mainform.querycur['Pname'];
mainform.stringGrid1.Cells[2,row]:=mainform.querycur['Pdept'];
mainform.stringGrid1.Cells[3,row]:=formatfloat('0.00',mainform.querycur.fieldbyname('price').asfloat);
mainform.stringGrid1.Cells[4,row]:=floattostr(mainform.querycur['Pnum']);
mainform.stringGrid1.Cells[5,row]:=inttostr(mainform.querycur['discount']);
mainform.stringGrid1.Cells[6,row]:=formatfloat('0.00',mainform.querycur.fieldbyname('amount').asfloat);
mainform.stringGrid1.Cells[7,row]:=floattostr(mainform.querycur.fieldbyname('sub').asfloat);
row:=row+1;
querycur.Next;
end;
if (mainform.edit1.Text='') or (strtofloat(mainform.edit1.text)=0) then
mainform.edit1.text:=formatfloat('0.00',mainform.querycur.fieldbyname('sumamount').asfloat)
else
mainform.edit1.text:=formatfloat('0.00',strtofloat(mainform.edit1.text)+mainform.querycur.fieldbyname('sumamount').asfloat);
mainform.edit3.text:=inttostr(mainform.querycur.fieldbyname('totaldis').asinteger);
if (mainform.edit2.Text<>'') and (mainform.edit3.Text<>'') and (strtofloat(mainform.edit3.text)<>0) then
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -