📄 unit2.pas
字号:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, ExtCtrls, StdCtrls, Db, DBTables,printers,
OleCtrls, MSCommLib_TLB;
type
Tsyssetting=Record
shopname:string[40];
polite:string[40];
telephone:string[20];
poscode:string[5];
IsPrint:string[2];
IsShow:string[2];
end;
Tmainform = class(TForm)
Panel1: TPanel;
Panel3: TPanel;
QueryInsert: TQuery;
Query2: TQuery;
Timer1: TTimer;
Queryreport: TQuery;
Querycur: TQuery;
Editclerk: TEdit;
Editdate: TEdit;
pcodeedit: TEdit;
Editbkclerk: TEdit;
StringGrid1: TStringGrid;
Panel2: TPanel;
Image2: TImage;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Image1: TImage;
MSComm1: TMSComm;
labelposcode: TEdit;
Query2id: TIntegerField;
Query2BDEDesigner: TStringField;
Query2BDEDesigner2: TStringField;
Query2BDEDesigner3: TStringField;
Query2BDEDesigner4: TStringField;
Query2BDEDesigner5: TStringField;
Query2BDEDesigner6: TStringField;
Query2BDEDesigner7: TStringField;
Query2BDEDesigner8: TFloatField;
Query2BDEDesigner9: TFloatField;
Query2BDEDesigner10: TStringField;
Query2BDEDesigner11: TStringField;
Query2BDEDesigner12: TDateTimeField;
Query2BDEDesigner13: TStringField;
Query2BDEDesigner14: TStringField;
Query2BDEDesigner15: TFloatField;
Editsaler: TEdit;
Query3: TQuery;
Edittotalsub: TEdit;
QryCode: TQuery;
Queryreport2: TQuery;
Queryreport4: TQuery;
Labelstate: TLabel;
Querydetail: TQuery;
Queryreportsum: TQuery;
procedure FormCreate(Sender: TObject);
procedure PcodeeditKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure PcodeeditKeyPress(Sender: TObject; var Key: Char);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
procedure Timer1Timer(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormShow(Sender: TObject);
procedure StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure MakeCursorHide;
procedure ReadFromBase;
procedure FormKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
IsPrinted,IsShowed:boolean;
sysfile:File of Tsyssetting;
end;
var
mainform: Tmainform;
sno,row,number:integer;
tmpaction:string;
tmppay1,tmppay2,tmppay3,tmppay4,tmppay5,tmppay6:boolean;
implementation
uses unit1,unit3, Unit4, Unit5, Unit7,Unit8,Unit9, Unit10,Unit11, Unit12,Unit14,Unit16;
{$R *.DFM}
procedure Tmainform.FormCreate(Sender: TObject);
begin
stringGrid1.RowHeights[0]:=20;
end;
procedure Tmainform.PcodeeditKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
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 key=Vk_F5 then //进入系统设置界面
begin
if row>0 then
begin
messagebox(mainform.handle,'还有未交易数据','提示',MB_OK+MB_ICONINFORMATION);
exit;
end;
formsetting.Show;
mainform.Hide;
end;
if key=Vk_F7 then //进入当日销售纪录查询界面
begin
if row>0 then
begin
messagebox(mainform.handle,'还有未交易数据','提示',MB_OK+MB_ICONINFORMATION);
exit;
end;
Application.CreateForm(TFormquery, Formquery);
formquery.ShowModal;
end;
if key=Vk_ESCAPE then
Pcodeedit.text:='';
if key=VK_DOWN then
StringGrid1.SetFocus;
if (key=VK_RETURN) and (Pcodeedit.text<>'') then
begin
ReadFromBase; //取商品信息
end;
end;
procedure Tmainform.PcodeeditKeyPress(Sender: TObject; var Key: Char);
var
i,j,selerow,tmpint,maxrow,lastmonth:integer;
tmpzq,tmphj,tmpzk,tmpcash,tmpreal,tmpnum:real;
tmpposcode,tmpdatetime,curdate,lastdate,tmpreceive,tmpback,tmpsql:string;
tmptotal,cash,tmpcheck,tmpcard,tmpother,tmpshop,tmpwait:string;
tmpdate,tmptime,tmpclerk,tmpbkclerk,tmpsaler:string;
gznum,endtime:string;
tmpstr,oldprice:string;
Year, Month, Day, Hour, Min:word;
tmpyear,tmpmonth,tmpgcode,tmpday:string;
begin
maxrow:=0;
if key='a' then //数字00
begin
postmessage(pcodeedit.handle,WM_KEYDOWN,48,0);
postmessage(pcodeedit.handle,WM_KEYDOWN,48,0);
end;
if key='c' then //代码
begin
if pcodeedit.Text<>'' then
begin
ReadFromBase; //取商品信息
end;
end;
if (key='d') and (row>0) then //单价
begin
tmphj:=0;
maxrow:=row-1;
if (pcodeedit.text<>'') then
begin
try
strtofloat(pcodeedit.text);
except
Application.MessageBox('请输入实数!','提示',MB_OK+MB_ICONINFORMATION);
key:=chr(0);
pcodeedit.SetFocus;
Exit;
end;
oldprice:=stringGrid1.Cells[3,maxrow];
if strtofloat(oldprice)=0 then
stringGrid1.Cells[7,maxrow]:='0'
else
stringGrid1.Cells[7,maxrow]:=floattostr(strtofloat(oldprice)-strtofloat(pcodeedit.text));
stringGrid1.Cells[3,maxrow]:=pcodeedit.text;
if stringGrid1.Cells[5,maxrow]='0' then
begin
stringGrid1.Cells[6,maxrow]:=formatfloat('0.00',strtofloat(stringGrid1.Cells[3,maxrow])*strtofloat(stringGrid1.Cells[4,maxrow]));
end
else
begin
stringGrid1.Cells[6,maxrow]:=formatfloat('0.00',strtofloat(stringGrid1.Cells[3,maxrow])*strtofloat(stringGrid1.Cells[4,maxrow])*strtofloat(stringGrid1.Cells[5,maxrow])/100);
end;
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);
pcodeedit.Text:='';
pcodeedit.SetFocus;
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) + 'PRICE '+mainform.stringGrid1.Cells[3,maxrow]+ 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='e') and (row>0) then //数量
begin
if pcodeedit.text<>'' then
begin
try
strtofloat(pcodeedit.text);
except
Application.MessageBox('请输入实数!','提示',MB_OK+MB_ICONINFORMATION);
key:=chr(0);
pcodeedit.SetFocus;
Exit;
end;
if (strtofloat(pcodeedit.text)>0) and (strtofloat(pcodeedit.text)<10000) then
begin
maxrow:=row-1;
tmpnum:=strtofloat(stringGrid1.Cells[4,maxrow]);
stringGrid1.Cells[4,maxrow]:=pcodeedit.text;
if stringGrid1.Cells[5,maxrow]='0' then
begin
stringGrid1.Cells[6,maxrow]:=formatfloat('0.00',strtofloat(stringGrid1.Cells[3,maxrow])*strtofloat(stringGrid1.Cells[4,maxrow]));
end
else
begin
stringGrid1.Cells[6,maxrow]:=formatfloat('0.00',strtofloat(stringGrid1.Cells[3,maxrow])*strtofloat(stringGrid1.Cells[4,maxrow])*strtofloat(stringGrid1.Cells[5,maxrow])/100);
end;
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);
pcodeedit.Text:='';
pcodeedit.SetFocus;
end
else
begin
Application.MessageBox('请输入0-10000之间的实数!','提示',MB_OK+MB_ICONINFORMATION);
key:=chr(0);
exit;
end;
end
else
if row<>0 then
begin
maxrow:=row-1;
tmpnum:=strtofloat(stringGrid1.Cells[4,maxrow]);
stringGrid1.Cells[4,maxrow]:=floattostr(tmpnum+1);
if stringGrid1.Cells[5,maxrow]='0' then
begin
stringGrid1.Cells[6,maxrow]:=formatfloat('0.00',strtofloat(stringGrid1.Cells[3,maxrow])*strtofloat(stringGrid1.Cells[4,maxrow]));
end
else
begin
stringGrid1.Cells[6,maxrow]:=formatfloat('0.00',strtofloat(stringGrid1.Cells[3,maxrow])*strtofloat(stringGrid1.Cells[4,maxrow])*strtofloat(stringGrid1.Cells[5,maxrow])/100);
end;
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);
pcodeedit.Text:='';
pcodeedit.SetFocus;
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) + 'PRICE '+mainform.stringGrid1.Cells[3,maxrow]+ Chr(13); //确保
mainform.MSComm1.Output := Chr($1B) + Chr($51) + Chr($42) + 'TOTAL '+formatfloat('#,##0.00',strtofloat(edit2.Text))+ Chr(13); //确保
//关闭串行端口。
mainform.MSComm1.PortOpen := False;
end;
end;
if (key='f') 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
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); //确保
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -