📄 unit12.pas
字号:
unit Unit12;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DBGridEh, ExtCtrls, Db, DBTables, StdCtrls;
type
TFormquery = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
DataSourcequery: TDataSource;
querygoods: TQuery;
Editsaler: TEdit;
Label1: TLabel;
Label2: TLabel;
Editunit: TEdit;
Button2: TButton;
Button1: TButton;
Notebook1: TNotebook;
DBGridEh1: TDBGridEh;
DBGridEh2: TDBGridEh;
Querypayed: TQuery;
DataSource1: TDataSource;
Button3: TButton;
procedure FormShow(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Formquery: TFormquery;
implementation
uses Unit2;
{$R *.DFM}
procedure TFormquery.FormShow(Sender: TObject);
begin
notebook1.ActivePage:='Default';
end;
procedure TFormquery.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
tmpposcode,endtime,tmpyear,tmpmonth,tmpday,lastdate,curdate,tmpsql:string;
Year,Month,Day:word;
lastmonth:integer;
begin
if (key=VK_DOWN) and (notebook1.ActivePage='Default') then
dbgrideh1.SetFocus
else if (key=VK_DOWN) and (notebook1.ActivePage='payed') then
dbgrideh2.SetFocus;
if key=Vk_ESCAPE then
begin
//mainform.show;
//设置焦点
mainform.pcodeedit.SetFocus;
formquery.Close;
end;
if key=VK_RETURN then
begin
tmpposcode:=trim(mainform.labelposcode.text);
DecodeDate(now, Year, Month, Day);
endtime:='15:00:00'; //将12:00:00改为15:00:00
if Month=1 then
lastmonth:=12
else
lastmonth:=Month-1;
if Day=1 then //如果当日为每月第一号,计算前一天的日期
begin
tmpmonth:=inttostr(lastmonth);
if lastmonth=12 then
begin
tmpyear:=inttostr(Year-1);
tmpday:='31';
end;
if lastmonth=2 then
begin
tmpyear:=inttostr(Year);
if (Year mod 4 <>0) then
tmpday:='28'
else if (Year mod 100 <>0) then
tmpday:='29'
else if (Year mod 400 <>0) then
tmpday:='28'
else
tmpday:='29';
end;
if (lastmonth=1) or (lastmonth=3) or (lastmonth=5) or (lastmonth=7) or (lastmonth=8) or (lastmonth=10) then
begin
tmpyear:=inttostr(Year);
tmpday:='31';
end;
if (lastmonth=4) or (lastmonth=6) or (lastmonth=9) or (lastmonth=11) then
begin
tmpyear:=inttostr(Year);
tmpday:='30';
end;
end
else
begin
tmpyear:=inttostr(Year);
tmpmonth:=inttostr(Month);
if length(inttostr(Day-1))=1 then
tmpday:='0'+inttostr(Day-1)
else
tmpday:=inttostr(Day-1);
end;
if length(tmpmonth)=1 then
tmpmonth:='0'+tmpmonth
else
tmpmonth:=tmpmonth;
lastdate:=tmpyear+'-'+tmpmonth+'-'+tmpday;
curdate:=formatdatetime('yyyy-mm-dd',now);
if notebook1.ActivePage='Default' then
begin
try
with querygoods do
begin
if (editsaler.Text='') and (editunit.Text='') then
begin
tmpsql:='select * from trade,pricebase where ecr='''+tmpposcode+''' and trade.code=pricebase.条码 and trade.op=''G'' and (((saledate='''+lastdate+''') and (saletime>='''+endtime+''')) or ((saledate='''+curdate+''')';
tmpsql:=tmpsql+' and (saletime<='''+endtime+'''))) order by sno ASC';
end
else
begin
tmpsql:='select * from trade,pricebase where trade.clerk like ''%'+trim(editsaler.text)+'%'' and trade.code like '''+trim(editunit.text)+'%'' ';
tmpsql:=tmpsql+' and trade.code=pricebase.条码 and trade.op=''G'' and (((saledate='''+lastdate+''') and (saletime>='''+endtime+''')) or ((saledate='''+curdate+''') and (saletime<='''+endtime+'''))) order by sno ASC';
end;
close;
sql.clear;
sql.add(tmpsql);
prepare;
open;
end;
except
messagebox(formquery.handle,'数据库连接失败','错误',MB_OK+MB_ICONERROR);
exit;
end;
if not querygoods.Eof then
dbgrideh1.Columns.Items[0].Footers[0].Value:=inttostr(querygoods.recordcount)
else
dbgrideh1.Columns.Items[0].Footers[0].Value:='0';
querygoods.active:=false;
querygoods.active:=true;
end;
if notebook1.ActivePage='payed' then
begin
try
with Querypayed do
begin
if (editsaler.Text='') and (editunit.Text='') then
begin
tmpsql:='select ecr,clerk,saler,saledate,saletime,tmpclerk,sno,orgtotal,(total+change) as stotal,change,totaldis,';
tmpsql:=tmpsql+'(pay1+change) as spay1,pay2,pay3,pay4,pay5,pay6,totalsub from trade where ecr='''+tmpposcode+''' and trade.op=''T'' and (((saledate='''+lastdate+''') and (saletime>='''+endtime+''')) or ((saledate='''+curdate+''')';
tmpsql:=tmpsql+' and (saletime<='''+endtime+'''))) order by sno ASC';
end
else
begin
tmpsql:='select ecr,clerk,saler,saledate,saletime,tmpclerk,sno,orgtotal,(total+change) as stotal,change,totaldis,';
tmpsql:=tmpsql+'(pay1+change) as spay1,pay2,pay3,pay4,pay5,pay6,totalsub from trade where trade.clerk like ''%'+trim(editsaler.text)+'%'' and trade.op=''T''';
tmpsql:=tmpsql+' and (((saledate='''+lastdate+''') and (saletime>='''+endtime+''')) or ((saledate='''+curdate+''') and (saletime<='''+endtime+''')))';
tmpsql:=tmpsql+' and sno In (select sno from trade,pricebase where trade.clerk like ''%'+trim(editsaler.text)+'%'' and trade.code like '''+trim(editunit.text)+'%'' ';
tmpsql:=tmpsql+' and trade.code=pricebase.条码 and trade.op=''G'' and (((saledate='''+lastdate+''') and (saletime>='''+endtime+''')) or ((saledate='''+curdate+''') and (saletime<='''+endtime+''')))) order by sno ASC';
end;
close;
sql.clear;
sql.add(tmpsql);
prepare;
open;
end;
except
messagebox(formquery.handle,'数据库连接失败','错误',MB_OK+MB_ICONERROR);
exit;
end;
Querypayed.active:=false;
Querypayed.active:=true;
end;
end;
end;
procedure TFormquery.Button2Click(Sender: TObject);
var
tmpposcode,endtime,tmpyear,tmpmonth,tmpday,lastdate,curdate,tmpsql:string;
Year,Month,Day:word;
lastmonth:integer;
begin
tmpposcode:=trim(mainform.labelposcode.text);
DecodeDate(now, Year, Month, Day);
endtime:='15:00:00';//将12:00:00改为15:00:00
if Month=1 then
lastmonth:=12
else
lastmonth:=Month-1;
if Day=1 then //如果当日为每月第一号,计算前一天的日期
begin
tmpmonth:=inttostr(lastmonth);
if lastmonth=12 then
begin
tmpyear:=inttostr(Year-1);
tmpday:='31';
end;
if lastmonth=2 then
begin
tmpyear:=inttostr(Year);
if (Year mod 4 <>0) then
tmpday:='28'
else if (Year mod 100 <>0) then
tmpday:='29'
else if (Year mod 400 <>0) then
tmpday:='28'
else
tmpday:='29';
end;
if (lastmonth=1) or (lastmonth=3) or (lastmonth=5) or (lastmonth=7) or (lastmonth=8) or (lastmonth=10) then
begin
tmpyear:=inttostr(Year);
tmpday:='31';
end;
if (lastmonth=4) or (lastmonth=6) or (lastmonth=9) or (lastmonth=11) then
begin
tmpyear:=inttostr(Year);
tmpday:='30';
end;
end
else
begin
tmpyear:=inttostr(Year);
tmpmonth:=inttostr(Month);
if length(inttostr(Day-1))=1 then
tmpday:='0'+inttostr(Day-1)
else
tmpday:=inttostr(Day-1);
end;
if length(tmpmonth)=1 then
tmpmonth:='0'+tmpmonth
else
tmpmonth:=tmpmonth;
lastdate:=tmpyear+'-'+tmpmonth+'-'+tmpday;
curdate:=formatdatetime('yyyy-mm-dd',now);
if notebook1.ActivePage='Default' then
begin
try
with querygoods do
begin
if (editsaler.Text='') and (editunit.Text='') then
begin
tmpsql:='select * from trade,pricebase where ecr='''+tmpposcode+''' and trade.code=pricebase.条码 and trade.op=''G'' and (((saledate='''+lastdate+''') and (saletime>='''+endtime+''')) or ((saledate='''+curdate+''')';
tmpsql:=tmpsql+' and (saletime<='''+endtime+'''))) order by sno ASC';
end
else
begin
tmpsql:='select * from trade,pricebase where trade.clerk like ''%'+trim(editsaler.text)+'%'' and trade.code like '''+trim(editunit.text)+'%'' and trade.code=pricebase.条码 and trade.op=''G''';
tmpsql:=tmpsql+' and (((saledate='''+lastdate+''') and (saletime>='''+endtime+''')) or ((saledate='''+curdate+''') and (saletime<='''+endtime+'''))) order by sno ASC';
end;
close;
sql.clear;
sql.add(tmpsql);
prepare;
open;
end;
except
messagebox(formquery.handle,'数据库连接失败','错误',MB_OK+MB_ICONERROR);
exit;
end;
if not querygoods.Eof then
dbgrideh1.Columns.Items[0].Footers[0].Value:=inttostr(querygoods.recordcount)
else
dbgrideh1.Columns.Items[0].Footers[0].Value:='0';
querygoods.active:=false;
querygoods.active:=true;
end;
if notebook1.ActivePage='payed' then
begin
try
with Querypayed do
begin
if (editsaler.Text='') and (editunit.Text='') then
begin
tmpsql:='select ecr,clerk,saler,saledate,saletime,tmpclerk,sno,orgtotal,(total+change) as stotal,change,totaldis,';
tmpsql:=tmpsql+'(pay1+change) as spay1,pay2,pay3,pay4,pay5,pay6,totalsub from trade where ecr='''+tmpposcode+''' and trade.op=''T'' and (((saledate='''+lastdate+''') and (saletime>='''+endtime+''')) or ((saledate='''+curdate+''')';
tmpsql:=tmpsql+' and (saletime<='''+endtime+'''))) order by sno ASC';
end
else
begin
tmpsql:='select ecr,clerk,saler,saledate,saletime,tmpclerk,sno,orgtotal,(total+change) as stotal,change,totaldis,';
tmpsql:=tmpsql+'(pay1+change) as spay1,pay2,pay3,pay4,pay5,pay6,totalsub from trade where trade.clerk like ''%'+trim(editsaler.text)+'%'' and trade.op=''T''';
tmpsql:=tmpsql+' and (((saledate='''+lastdate+''') and (saletime>='''+endtime+''')) or ((saledate='''+curdate+''') and (saletime<='''+endtime+''')))';
tmpsql:=tmpsql+' and sno In (select sno from trade,pricebase where trade.clerk like ''%'+trim(editsaler.text)+'%'' and trade.code like '''+trim(editunit.text)+'%'' ';
tmpsql:=tmpsql+' and trade.code=pricebase.条码 and trade.op=''G'' and (((saledate='''+lastdate+''') and (saletime>='''+endtime+''')) or ((saledate='''+curdate+''') and (saletime<='''+endtime+''')))) order by sno ASC';
end;
close;
sql.clear;
sql.add(tmpsql);
prepare;
open;
end;
except
messagebox(formquery.handle,'数据库连接失败','错误',MB_OK+MB_ICONERROR);
exit;
end;
Querypayed.active:=false;
Querypayed.active:=true;
end;
end;
procedure TFormquery.Button1Click(Sender: TObject);
var
tmpposcode,endtime,curdate,tmpsql:string;
begin
tmpposcode:=trim(mainform.labelposcode.text);
endtime:='15:00:00'; //将12:00:00改为15:00:00
curdate:=formatdatetime('yyyy-mm-dd',now);
if notebook1.ActivePage='Default' then
begin
try
with querygoods do
begin
if (editsaler.Text='') and (editunit.Text='') then
tmpsql:='select * from trade,pricebase where ecr='''+tmpposcode+''' and trade.code=pricebase.条码 and trade.op=''G'' and (saledate='''+curdate+''') and (saletime>='''+endtime+''') order by sno ASC'
else
begin
tmpsql:='select * from trade,pricebase where trade.clerk like ''%'+trim(editsaler.text)+'%'' and trade.code like '''+trim(editunit.text)+'%'' and trade.code=pricebase.条码';
tmpsql:=tmpsql+' and trade.op=''G'' and (saledate='''+curdate+''') and (saletime>='''+endtime+''') order by sno ASC';
end;
close;
sql.clear;
sql.add(tmpsql);
prepare;
open;
end;
except
messagebox(formquery.handle,'数据库连接失败','错误',MB_OK+MB_ICONERROR);
exit;
end;
if not querygoods.Eof then
dbgrideh1.Columns.Items[0].Footers[0].Value:=inttostr(querygoods.recordcount)
else
dbgrideh1.Columns.Items[0].Footers[0].Value:='0';
querygoods.active:=false;
querygoods.active:=true;
end;
if notebook1.ActivePage='payed' then
begin
try
with Querypayed do
begin
if (editsaler.Text='') and (editunit.Text='') then
begin
tmpsql:='select ecr,clerk,saler,saledate,saletime,tmpclerk,sno,orgtotal,(total+change) as stotal,change,totaldis,';
tmpsql:=tmpsql+'(pay1+change) as spay1,pay2,pay3,pay4,pay5,pay6,totalsub from trade where ecr='''+tmpposcode+''' and trade.op=''T'' and ((saledate='''+curdate+''') and (saletime>='''+endtime+''')) order by sno ASC';
end
else
begin
tmpsql:='select ecr,clerk,saler,saledate,saletime,tmpclerk,sno,orgtotal,(total+change) as stotal,change,totaldis,';
tmpsql:=tmpsql+'(pay1+change) as spay1,pay2,pay3,pay4,pay5,pay6,totalsub from trade where trade.clerk like ''%'+trim(editsaler.text)+'%'' and trade.op=''T''';
tmpsql:=tmpsql+' and ((saledate='''+curdate+''') and (saletime>='''+endtime+'''))';
tmpsql:=tmpsql+' and sno In (select sno from trade,pricebase where trade.clerk like ''%'+trim(editsaler.text)+'%'' and trade.code like '''+trim(editunit.text)+'%'' ';
tmpsql:=tmpsql+' and trade.code=pricebase.条码 and trade.op=''G'' and ((saledate='''+curdate+''') and (saletime>='''+endtime+'''))) order by sno ASC';
end;
close;
sql.clear;
sql.add(tmpsql);
prepare;
open;
end;
except
messagebox(formquery.handle,'数据库连接失败','错误',MB_OK+MB_ICONERROR);
exit;
end;
Querypayed.active:=false;
Querypayed.active:=true;
end;
end;
procedure TFormquery.Button3Click(Sender: TObject);
begin
if Button3.Caption='收付款查询' then
begin
notebook1.ActivePage:='payed';
Button3.Caption:='返回';
editsaler.SetFocus;
exit;
end;
if Button3.Caption='返回' then
begin
notebook1.ActivePage:='Default';
Button3.Caption:='收付款查询';
editsaler.SetFocus;
exit;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -