N
nzfboy
Unregistered / Unconfirmed
GUEST, unregistred user!
外面公司在线问我问题,大家快来帮我看一下。
他给我这个,考我能看出什么来。给我二十分时间。
unit Checkhzz;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ExtCtrls, Buttons, ToolWin,inifiles, Frame3ds, Grids, shDBGrids,
Db, DBTables, StdCtrls, Klabel2, DBGridEh;
type
TFormCheckhzz = class(TForm)
ToolBar1: TToolBar;
SpeedButtonFind: TSpeedButton;
SpeedButtonPrint: TSpeedButton;
SpeedButtonHelp: TSpeedButton;
SpeedButtonClose: TSpeedButton;
StatusBar1: TStatusBar;
DataSource1: TDataSource;
Query1: TQuery;
SpeedButtonDate: TSpeedButton;
QueryWarehouse: TQuery;
QueryWarecode: TQuery;
DBGrid1: TDBGridEh;
Query2: TQuery;
SpeedButtonFilter: TSpeedButton;
QueryGrouph: TQuery;
Frame1: TFrame;
QueryBrand: TQuery;
QueryWaretype: TQuery;
ComboBox1: TComboBox;
Query3: TQuery;
QueryDepartment: TQuery;
UpdateSQL1: TUpdateSQL;
function myGetdisplaylabel(fieldname:string):string;
procedure myCreateGridEHList(var dbgrid1:TDBGridEH;Columnwidth:string);
procedure mySumColumn;
procedure SpeedButtonCloseClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure SpeedButtonHelpClick(Sender: TObject);
procedure SpeedButtonFindClick(Sender: TObject);
procedure SpeedButtonDateClick(Sender: TObject);
procedure StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
procedure SpeedButtonPrintClick(Sender: TObject);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumneh; State: TGridDrawState);
procedure DBGrid1TitleBtnClick(Sender: TObject; ACol: Integer;
Column: TColumnEh);
procedure DBGrid1DblClick(Sender: TObject);
procedure DBGrid1GetCellParams(Sender: TObject; Column: TColumnEh;
AFont: TFont; var Background: TColor; State: TGridDrawState);
procedure StatusBar1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ComboBox1Click(Sender: TObject);
procedure ComboBox1Exit(Sender: TObject);
procedure ComboBox1Enter(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
pPublicDataBaseName,pUserDataBaseName:string;
end;
procedure MainProc(var Message);export;
exports
MainProc;
var
FormCheckhzz: TFormCheckhzz;
pOrientation,pPaperSize,pPaperwidth,pPaperLength,pLeftMargin,pRightMargin,pTopMargin,pBottomMargin:integer;
pGroupno,pBrandno,pDptno,pTempname,pNoteno,pTypeno,pRemark,pWareNo,pWareName,pHouseno,pHousename,pColumnWidth,pPeriod,pUserdh,pBookmark,pRunPath:string;
pYear,pMonth,pDay:word;
pMaxdate,pMindate:Tdatetime;
pCxfs,pPriceprec:integer;
pUserDataBase:TDatabase;
implementation
uses shxtsy1,shConsts,sunlib,uCommon,suntool1,Checkhzz1,Checkhzz3,SizeField,DateRange,Checkhzz4,Checkhzz5;
{$R *.DFM}
procedure GetModuleInfo(var Message:TWMGetModuleInfo);
begin
with Message.ModuleInfo^ do
begin
Xtname:='库存管理';
ProcName:='Checkhzz';
ProcTitle:='库存盘点汇总帐';
end;
end;
procedure CreateForm(var Message:TWMCreateForm);
begin
with Message.CreateInfo^ do Form := TFormCheckhzz.Create(Owner);
end;
procedure MainProc(var Message);
begin
case TMessage(Message).Msg of
WM_CreateForm:CreateForm(TWMCreateForm(Message));
WM_GetModuleInfo:GetModuleInfo(TWMGetModuleInfo(Message));
end;
end;
procedure TFormCheckhzz.SpeedButtonCloseClick(Sender: TObject);
begin
close;
end;
procedure TFormCheckhzz.FormClose(Sender: TObject; var Action: TCloseAction);
var
inifile:Tinifile;
i:integer;
begin
if tag<>-2 then
begin
inifile:=Tinifile.Create(pRunPath+IniConfig0);
inifile.WriteInteger(name,'Top',top);
inifile.WriteInteger(name,'Left',left);
inifile.WriteInteger(name,'Width',width);
inifile.WriteInteger(name,'Height',height);
inifile.WriteInteger(name,'LeftMargin',pLeftMargin);
inifile.WriteInteger(name,'RightMargin',pRightMargin);
inifile.WriteInteger(name,'TopMargin',pTopMargin);
inifile.WriteInteger(name,'BottomMargin',pBottomMargin);
inifile.WriteInteger(name,'PaperLength',pPaperLength);
inifile.WriteInteger(name,'PaperWidth',pPaperWidth);
inifile.WriteInteger(name,'PaperSize',pPaperSize);
inifile.WriteInteger(name,'Cxfs',pCxfs);
inifile.WriteInteger(name,'Orientation',pOrientation);
inifile.WriteInteger(name,'WindowState',ord(WindowState));
pColumnwidth:='^';
for i:=0 to dbgrid1.Columns.Count-1 do
pColumnwidth:=pColumnwidth+dbgrid1.Columns.fieldname+','+inttostr(dbgrid1.Columns.width)+'^';
inifile.WriteString(name,'ColumnWidth',uppercase(pColumnwidth));
inifile.free;
end;
WriteValue(psClose,pBookmark);
Action:=cafree;
end;
procedure TFormCheckhzz.FormCreate(Sender: TObject);
begin
formCheckhzz:=sender as TFormCheckhzz;
pUserdh:=ReadValue(psUserdh);
pRunPath:=ReadValue(psRunPath);
pUserDataBase:=ReadDataBase(psUserDataBase);
pUserDataBaseName:=pUserDataBase.databasename;
pBookmark:=ReadValue(psBookmark);
if not GetWorkDate(pyear,pmonth,pday,pmaxdate,pmindate) then
begin
Application.MessageBox('未定义开始使用期间!',cTitle,FlagInformation);
tag:=-2;
close;
exit;
end;
pPricePrec:=ReadParamInteger('OPTIONS','PricePrec',2);
pPeriod:=inttostr(pyear)+strright(' '+inttostr(pmonth),2);
//if pMindate=pMaxdate then LabelDate.caption:=DateToLongStr(pMindate)
//else LabelDate.caption:=DateToLongStr(pMindate)+' - '+DateToLongStr(pMaxdate);
if pMindate=pMaxdate then StatusBar1.Panels[0].text:=DateToLongStr(pMindate)
else StatusBar1.Panels[0].text:=DateToLongStr(pMindate)+' - '+DateToLongStr(pMaxdate);
//----------------------------------------------------
ComboBox1.Parent:=StatusBar1;
ComboBox1.top:=2;
ComboBox1.lefT:=StatusBar1.panels[0].width+58;
//----------------------------------------------------
try
Query1.databasename:=pUserDataBaseName;
Query2.databasename:=pUserDataBaseName;
Query3.databasename:=pUserDataBaseName;
QueryGrouph.databasename:=pUserDataBaseName;
QueryGrouph.sql.text:='select * from Grouph where Groupno=:Groupno';
QueryDepartment.databasename:=pUserDataBaseName;
QueryDepartment.sql.text:='select * from Department where dptno=:dptno';
QueryWarehouse.databasename:=pUserDataBaseName;
QueryWarehouse.sql.text:='select * from warehouse where houseno=:houseno';
QueryWaretype.databasename:=pUserDataBaseName;
QueryWaretype.sql.text:='select * from waretype where typeno=:typeno';
QueryWarecode.databasename:=pUserDataBaseName;
QueryWarecode.sql.text:='select * from warecode where wareno=:wareno';
except
Application.MessageBox(errmess,cTitle,FlagInformation);
tag:=-2;
close;
exit;
end;
pWareNo:='';pWareName:='';pHouseno:='';pHousename:='';pRemark:='';
pTypeno:='';pNoteno:='';pDptno:='';pBrandno:='';pGroupno:='';
end;
procedure TFormCheckhzz.FormShow(Sender: TObject);
var
inifile:Tinifile;
//i:integer;
//ss:string;
begin
inifile:=Tinifile.Create(pRunPath+IniConfig0);
top:=inifile.ReadInteger(name,'Top',top);
left:=inifile.ReadInteger(name,'Left',left);
width:=inifile.ReadInteger(name,'Width',width);
height:=inifile.ReadInteger(name,'Height',height);
WindowState:=TWindowState(inifile.ReadInteger(name,'WindowState',0));
pLeftMargin:=inifile.ReadInteger(name,'LeftMargin',10);
pRightMargin:=inifile.ReadInteger(name,'RightMargin',10);
pTopMargin:=inifile.ReadInteger(name,'TopMargin',10);
pBottomMargin:=inifile.ReadInteger(name,'BottomMargin',10);
pPaperWidth:=inifile.ReadInteger(name,'PaperWidth',328);
pPaperLength:=inifile.ReadInteger(name,'PaperLength',280);
pPaperSize:=inifile.ReadInteger(name,'PaperSize',9);
pOrientation:=inifile.ReadInteger(name,'Orientation',0);
pColumnWidth:=inifile.ReadString(name,'ColumnWidth','');
pCxfs:=inifile.ReadInteger(name,'Cxfs',0);
inifile.free;
ComboBox1.itemindex:=pCxfs;
StatusBar1.Panels[1].texT:='汇总方式:'+ComboBox1.text;
if pColumnWidth='' then
case pCxfs of
0ColumnWidth:='^WARENO,75^WARENAME,88^MODEL,40^UNITS,38^AMOUNT,50^PRICE,68^CURR,88^';
1ColumnWidth:='^HOUSENO,40^HOUSENAME,100^AMOUNT,50^PRICE,68^CURR,88^';
//2ColumnWidth:='^PROVNO,40^PROVNAME,100^AMOUNT,50^PRICE,68^CURR,88^';
2ColumnWidth:='^DPTNO,40^DPTNAME,100^AMOUNT,50^PRICE,68^CURR,88^';
end;
myCreateGridEHList(dbgrid1,pColumnwidth);
{for i:=0 to dbgrid1.Columns.Count-1 do
begin
ss:=uppercase(dbgrid1.columns.fieldname);
dbgrid1.Columns.title.TitleButton:=pos('^'+ss+'^','^AAA^')=0;
end;}
end;
procedure TFormCheckhzz.SpeedButtonHelpClick(Sender: TObject);
begin
Application.helpcontext(Helpcontext);
end;
procedure TFormCheckhzz.SpeedButtonFindClick(Sender: TObject);
var
//sqlindex:string;
form1:TForm;
i:integer;
begin
with TformCheckhzz3.create(self) do
begin
showmodal;
i:=tag;
free;
end;
if i=0 then exit;
form1:=messagewaitbox('','正在查询,请稍候......');
query1.DisableControls;
query1.close;
update;
//---------------------------------------------------------------------
if pCxfs<>ComboBox1.itemindex then
begin
dbgrid1.Columns.Clear;
pCxfs:=ComboBox1.itemindex;
case pCxfs of
0ColumnWidth:='^WARENO,75^WARENAME,88^MODEL,40^UNITS,38^AMOUNT,50^PRICE,68^CURR,88^';
1ColumnWidth:='^HOUSENO,40^HOUSENAME,100^AMOUNT,50^PRICE,68^CURR,88^';
//2ColumnWidth:='^PROVNO,40^PROVNAME,100^AMOUNT,50^PRICE,68^CURR,88^';
2ColumnWidth:='^DPTNO,40^DPTNAME,100^AMOUNT,50^PRICE,68^CURR,88^';
end;
myCreateGridEHList(dbgrid1,pColumnwidth);
end;
//---------------------------------------------------------------------
pTempname:='#'+shsjh;
query2.close;
query2.sql.clear;
if pCxfs=0 then //商品代号
begin
query2.sql.add('select b.wareno,c.warename,c.model,c.units,sum(b.amount) as amount,');
query2.sql.add('sum(b.curr) as curr');
query2.sql.add('into '+pTempname);
query2.sql.add('from WareCheckh a,WareCheckm b,warecode c');
query2.sql.add('where a.noteno=b.noteno and b.wareno=c.wareno');
query2.sql.add('and a.tag=1 and b.amount<>0');
Query2.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
Query2.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
if pWareno<>'' then query2.sql.add('and b.wareno like "'+pWareno+'"');
if pGroupno<>'' then
begin
query2.sql.add('and b.wareno in');
query2.sql.add('(select b.wareno from grouph a,groupm b ');
query2.sql.add('where a.groupno=b.groupno');
query2.sql.add('and a.groupno="'+pGroupno+'")');
end;
if pHouseno<>'' then query2.sql.add('and a.Houseno like "'+pHouseno+'"');
if pDptno<>'' then query2.sql.add('and a.Dptno like "'+pDptno+'"');
if pTypeno<>'' then query2.sql.add('and c.Typeno like "'+pTypeno+'"');
query2.sql.add('group by b.wareno,c.warename,c.model,c.units');
query2.ExecSQL;
query1.close;
query1.sql.clear;
query1.sql.add('select a.wareno,a.warename,a.model,a.units');
query1.sql.add(',sum(a.amount) as amount,sum(a.curr)/sum(a.amount) as price,');
query1.sql.add('sum(a.curr) as curr,0 as orderno');
query1.sql.Add('from '+pTempname+' a');
query1.sql.add('group by a.wareno,a.warename,a.model,a.units');
query1.sql.add('order by a.wareno');
end else
if pCxfs=1 then //仓库
begin
query2.sql.add('select a.houseno,d.housename,sum(b.amount) as amount,');
query2.sql.add('sum(b.curr) as curr');
query2.sql.add('into '+pTempname);
query2.sql.add('from WareCheckh a,WareCheckm b,warecode c,warehouse d');
query2.sql.add('where a.noteno=b.noteno and b.wareno=c.wareno and a.houseno=d.houseno');
query2.sql.add('and a.tag=1 and b.amount<>0');
Query2.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
Query2.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
if pWareno<>'' then query2.sql.add('and b.wareno like "'+pWareno+'"');
if pGroupno<>'' then
begin
query2.sql.add('and b.wareno in');
query2.sql.add('(select b.wareno from grouph a,groupm b ');
query2.sql.add('where a.groupno=b.groupno');
query2.sql.add('and a.groupno="'+pGroupno+'")');
end;
if pHouseno<>'' then query2.sql.add('and a.Houseno like "'+pHouseno+'"');
//if pProvno<>'' then query2.sql.add('and a.provno like "'+pProvno+'"');
if pDptno<>'' then query2.sql.add('and a.Dptno like "'+pDptno+'"');
if pTypeno<>'' then query2.sql.add('and c.Typeno like "'+pTypeno+'"');
query2.sql.add('group by a.houseno,d.housename');
query2.ExecSQL;
query1.close;
query1.sql.clear;
query1.sql.add('select a.houseno,a.housename');
query1.sql.add(',sum(a.amount) as amount,sum(a.curr)/sum(a.amount) as price,');
query1.sql.add('sum(a.curr) as curr,0 as orderno');
query1.sql.Add('from '+pTempname+' a');
query1.sql.add('group by a.houseno,a.housename');
query1.sql.add('order by a.houseno');
end else
{if pCxfs=2 then //供应商
begin
query2.sql.add('select a.provno,d.name as provname,sum(b.amount) as amount,');
query2.sql.add('sum(b.curr) as curr');
query2.sql.add('into '+pTempname);
query2.sql.add('from WareCheckh a,WareCheckm b,warecode c,provide d');
query2.sql.add('where a.period=b.period and a.noteno=b.noteno and b.wareno=c.wareno and a.provno=d.code');
Query2.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
Query2.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
if pWareno<>'' then query2.sql.add('and b.wareno like "'+pWareno+'"');
if pHouseno<>'' then query2.sql.add('and a.Houseno like "'+pHouseno+'"');
if pProvno<>'' then query2.sql.add('and a.provno like "'+pProvno+'"');
if pDptno<>'' then query2.sql.add('and a.Dptno like "'+pDptno+'"');
if pTypeno<>'' then query2.sql.add('and c.Typeno like "'+pTypeno+'"');
query2.sql.add('group by a.provno,d.name');
query2.ExecSQL;
query1.close;
query1.sql.clear;
query1.sql.add('select a.provno,a.provname');
query1.sql.add(',sum(a.amount) as amount,sum(a.curr)/sum(a.amount) as price,');
query1.sql.add('sum(a.curr) as curr');
query1.sql.Add('from '+pTempname+' a');
query1.sql.add('group by a.provno,a.provname');
query1.sql.add('order by a.provno');
end else}
if pCxfs=2 then //部门
begin
query2.sql.add('select a.dptno,d.dptname,sum(b.amount) as amount,');
query2.sql.add('sum(b.curr) as curr');
query2.sql.add('into '+pTempname);
query2.sql.add('from WareCheckh a,WareCheckm b,warecode c,department d');
query2.sql.add('where a.noteno=b.noteno and b.wareno=c.wareno and a.dptno=d.dptno');
query2.sql.add('and a.tag=1 and b.amount<>0');
Query2.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
Query2.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
if pWareno<>'' then query2.sql.add('and b.wareno like "'+pWareno+'"');
if pGroupno<>'' then
begin
query2.sql.add('and b.wareno in');
query2.sql.add('(select b.wareno from grouph a,groupm b ');
query2.sql.add('where a.groupno=b.groupno');
query2.sql.add('and a.groupno="'+pGroupno+'")');
end;
if pHouseno<>'' then query2.sql.add('and a.Houseno like "'+pHouseno+'"');
//if pProvno<>'' then query2.sql.add('and a.provno like "'+pProvno+'"');
if pDptno<>'' then query2.sql.add('and a.Dptno like "'+pDptno+'"');
if pTypeno<>'' then query2.sql.add('and c.Typeno like "'+pTypeno+'"');
query2.sql.add('group by a.dptno,d.dptname');
query2.ExecSQL;
query1.close;
query1.sql.clear;
query1.sql.add('select a.dptno,a.dptname');
query1.sql.add(',sum(a.amount) as amount,sum(a.curr)/sum(a.amount) as price,');
query1.sql.add('sum(a.curr) as curr,0 as orderno');
query1.sql.Add('from '+pTempname+' a');
query1.sql.add('group by a.dptno,a.dptname');
query1.sql.add('order by a.dptno');
end;
query1.open;
query1.first;
i:=1;
while not query1.eof do
begin
query1.edit;
query1.FieldByName('orderno').asinteger:=i;
query1.post;
query1.next;
inc(i);
end;
query1.first;
mySumColumn;
SpeedButtonPrint.Enabled:=not query1.IsEmpty;
query1.EnableControls;
form1.free;
end;
procedure TFormCheckhzz.SpeedButtonDateClick(Sender: TObject);
begin
with TformDateRange.create(self) do
begin
DateTimePickerMindate.date:=pMindate;
DateTimePickerMaxdate.date:=pMaxdate;
showmodal;
if tag=1 then
begin
pMindate:=DateTimePickerMindate.date;
pMaxdate:=DateTimePickerMaxdate.date;
if pMindate=pMaxdate then StatusBar1.Panels[0].text:=DateToLongStr(pMindate)
else StatusBar1.Panels[0].text:=DateToLongStr(pMindate)+' - '+DateToLongStr(pMaxdate);
//if datetostr(pMindate)=datetostr(pMaxdate) then LabelDate.caption:=DateToLongStr(pMindate)
//else LabelDate.caption:=DateToLongStr(pMindate)+' - '+DateToLongStr(pMaxdate);
end;
free;
end;
end;
procedure TFormCheckhzz.StatusBar1DrawPanel(StatusBar: TStatusBar;Panel: TStatusPanel; const Rect: TRect);
begin
draw3dtext(StatusBar.Canvas,rect,Panel.Text,tsLowered,panel.Alignment);
end;
procedure TFormCheckhzz.SpeedButtonPrintClick(Sender: TObject);
begin
with TFormCheckhzz1.create(self) do
begin
showmodal;
free;
end;
end;
procedure TFormCheckhzz.DBGrid1DrawColumnCell(Sender: TObject;const Rect: TRect; DataCol: Integer; Column: TColumneh; State: TGridDrawState);
var
ss,fieldname:string;
rect1:TRect;
pict:integer;
begin
pict:=DT_VCENTER+DT_SINGLELINE;
rect1:=rect;
dbgrid1.Canvas.FillRect(rect1);
fieldname:=uppercase(column.fieldname);
if pos('^'+fieldname+'^','^UNITS^MODEL^ORDERNO^')>0 then
begin
ss:=query1.fieldbyname(fieldname).asString;
pict:=pict+DT_center;
end else
if fieldname='PRICE' then
begin
if query1.fieldbyname(fieldname).asfloat=0 then ss:='' else
ss:=floattostrf(query1.fieldbyname(fieldname).asfloat,ffNumber,14,pPriceprec);
pict:=pict+DT_RIGHT;
end else
if pos('^'+fieldname+'^','^CURR^')>0 then
begin
if query1.fieldbyname(fieldname).asfloat=0 then ss:='' else
ss:=floattostrf(query1.fieldbyname(fieldname).asfloat,ffNumber,14,2);
pict:=pict+DT_RIGHT;
end else
if fieldname='AMOUNT' then
begin
if query1.fieldbyname(fieldname).asfloat=0 then ss:='' else
ss:=query1.fieldbyname(fieldname).asstring;
pict:=pict+DT_RIGHT;
end else
begin
ss:=query1.fieldbyname(fieldname).asString;
pict:=pict+DT_LEFT;
end;
drawtext(dbgrid1.Canvas.Handle,pchar(ss),-1,rect1,pict);
end;
procedure TFormCheckhzz.DBGrid1TitleBtnClick(Sender: TObject; ACol: Integer;Column: TColumnEh);
var
fdname,ss:string;
i:integer;
begin
if not query1.Active then exit;
fdname:=uppercase(dbgrid1.columns[acol].fieldname);
//if pos('^'+fdname+'^','^PRICE^')>0 then exit;
for i:=0 to dbgrid1.columns.count-1 do
if acol<>i then dbgrid1.Columns.Title.SortMarker := smNoneEh;
ss:='';
if dbgrid1.Columns[ACol].Title.SortMarker = smUpEh then
begin
dbgrid1.Columns[ACol].Title.SortMarker:=smDownEh;
ss:=' desc ';
end else dbgrid1.Columns[ACol].Title.SortMarker:=smUpEh;
query1.DisableControls;
query1.close;
query1.SQL.Strings[query1.SQL.Count-1]:='order by a.'+DBGrid1.Columns[acol].fieldname+ss;
query1.open;
query1.first;
i:=1;
while not query1.eof do
begin
query1.edit;
query1.FieldByName('orderno').asinteger:=i;
query1.post;
query1.next;
inc(i);
end;
query1.first;
query1.EnableControls;
end;
procedure TFormCheckhzz.mySumColumn;
var
maxnum,i:integer;
hj:array of real;
sreturn,fieldname:string;
hjb:boolean;
begin
hjb:=false;
sreturn:=query1.Bookmark;
maxnum:=dbgrid1.Columns.Count-1;
setlength(hj,maxnum+1);
for i:=0 to maxnum do hj:=0;
query1.first;
while not query1.eof do
begin
for i:=0 to maxnum do
begin
try
fieldname:=uppercase(dbgrid1.Columns.fieldname);
if query1.FindField(fieldname)<>nil then
if pos('^'+fieldname+'^','^PRICE^')=0 then
if (query1.FieldByName(fieldname).datatype=ftFloat) or (query1.FieldByName(fieldname).datatype=ftCurrency) then
hj:=hj+query1.fieldbyname(fieldname).asfloat;
except
end;
end;
query1.next;
end;
for i:=0 to maxnum do
begin
fieldname:=uppercase(dbgrid1.Columns.fieldname);
if query1.FindField(fieldname)<>nil then
case query1.FieldByName(fieldname).datatype of
ftFloat,ftCurrency:
if pos('^'+fieldname+'^','^PRICE^')=0 then
begin
if copy(fieldname,1,6)='AMOUNT' then
if hj=0 then dbgrid1.Columns.footer.value:=''
else dbgrid1.Columns.footer.value:=floattostr(hj)
else
if hj=0 then dbgrid1.Columns.footer.value:=''
else dbgrid1.Columns.footer.value:=floattostrf(hj,ffNumber,16,2);
end;
else
if fieldname<>'ORDERNO' then
if not hjb then
begin
dbgrid1.Columns.footer.value:='合计';
dbgrid1.Columns.footer.Alignment:=taCenter;
hjb:=true;
end else dbgrid1.Columns.footer.value:='';
end;
end;
query1.Bookmark:=sreturn;
end;
procedure TFormCheckhzz.DBGrid1DblClick(Sender: TObject);
var
ss:string;
begin
if query1.IsEmpty then exit;
case pcxfs of
0:begin //商品代号
ss:=query1.fieldbyname('wareno').asstring;
query3.close;
query3.sql.clear;
query3.sql.add('select a.period,a.noteno,a.notedate,b.amount,b.price,b.curr,0 as tag0');
query3.sql.add('from WareCheckh a,WareCheckm b,warecode c');
query3.sql.add('where a.noteno=b.noteno');
query3.sql.add('and b.wareno="'+ss+'" and b.wareno=c.wareno and a.tag=1 and b.amount<>0');
query3.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
query3.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
//if pTypeno<>'' then query3.sql.add('and c.Typeno like "'+pTypeno+'"');
if pHouseno<>'' then query3.sql.add('and a.Houseno like "'+pHouseno+'"');
//if pProvno<>'' then query3.sql.add('and a.provno like "'+pProvno+'"');
if pDptno<>'' then query3.sql.add('and a.Dptno like "'+pDptno+'"');
query3.SQL.add('order by a.noteno');
query3.open;
if not query3.IsEmpty then
with TFormCheckhzz4.create(self) do
begin
caption:='品名:'+ss+' '+query1.fieldbyname('warename').asstring;
showmodal;
free;
end;
end;
1:begin //仓库
ss:=query1.fieldbyname('houseno').asstring;
query2.close;
query2.sql.clear;
query2.sql.add('select b.wareno,c.warename,c.model,c.units,sum(b.amount) as amount,');
query2.sql.add('sum(b.curr) as curr,sum(curr)/sum(amount) as price');
query2.sql.add('from WareCheckh a,WareCheckm b,warecode c');
query2.sql.add('where a.noteno=b.noteno and b.wareno=c.wareno');
query2.sql.add('and a.houseno="'+ss+'" and a.tag=1 and b.amount<>0');
Query2.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
Query2.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
if pWareno<>'' then query2.sql.add('and b.wareno like "'+pWareno+'"');
if pGroupno<>'' then
begin
query2.sql.add('and b.wareno in');
query2.sql.add('(select b.wareno from grouph a,groupm b ');
query2.sql.add('where a.groupno=b.groupno');
query2.sql.add('and a.groupno="'+pGroupno+'")');
end;
if pTypeno<>'' then query2.sql.add('and c.Typeno like "'+pTypeno+'"');
if pBrandno<>'' then query2.sql.add('and c.Brandno like "'+pBrandno+'"');
if pDptno<>'' then query2.sql.add('and a.Dptno like "'+pDptno+'"');
query2.sql.add('group by b.wareno,c.warename,c.model,c.units');
query2.SQL.add('order by b.wareno');
Query2.open;
if not query2.IsEmpty then
with TFormCheckhzz5.create(self) do
begin
caption:='仓库:'+ss+' '+query1.fieldbyname('housename').asstring;
showmodal;
free;
end;
end;
{2:begin //供应商
ss:=query1.fieldbyname('provno').asstring;
query2.close;
query2.sql.clear;
query2.sql.add('select b.wareno,c.warename,c.model,c.units,sum(b.amount) as amount,');
query2.sql.add('sum(b.curr) as curr,sum(curr)/sum(amount) as price');
query2.sql.add('from WareCheckh a,WareCheckm b,warecode c');
query2.sql.add('where a.period=b.period and a.noteno=b.noteno and b.wareno=c.wareno');
query2.sql.add('and a.provno="'+ss+'"');
Query2.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
Query2.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
if pWareno<>'' then query2.sql.add('and b.wareno like "'+pWareno+'"');
if pHouseno<>'' then query2.sql.add('and a.Houseno like "'+pHouseno+'"');
if pTypeno<>'' then query2.sql.add('and c.Typeno like "'+pTypeno+'"');
if pDptno<>'' then query2.sql.add('and a.Dptno like "'+pDptno+'"');
query2.sql.add('group by b.wareno,c.warename,c.model,c.units');
query2.SQL.add('order by b.wareno');
Query2.open;
if not query2.IsEmpty then
with TFormCheckhzz5.create(self) do
begin
caption:='供应商:'+ss+' '+query1.fieldbyname('provname').asstring;
showmodal;
free;
end;
end;}
2:begin //部门
ss:=query1.fieldbyname('dptno').asstring;
query2.close;
query2.sql.clear;
query2.sql.add('select b.wareno,c.warename,c.model,c.units,sum(b.amount) as amount,');
query2.sql.add('sum(b.curr) as curr,sum(curr)/sum(amount) as price');
query2.sql.add('from WareCheckh a,WareCheckm b,warecode c');
query2.sql.add('where a.noteno=b.noteno and b.wareno=c.wareno');
query2.sql.add('and a.dptno="'+ss+'" and a.tag=1 and b.amount<>0');
Query2.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
Query2.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
if pWareno<>'' then query2.sql.add('and b.wareno like "'+pWareno+'"');
if pGroupno<>'' then
begin
query2.sql.add('and b.wareno in');
query2.sql.add('(select b.wareno from grouph a,groupm b ');
query2.sql.add('where a.groupno=b.groupno');
query2.sql.add('and a.groupno="'+pGroupno+'")');
end;
if pHouseno<>'' then query2.sql.add('and a.Houseno like "'+pHouseno+'"');
if pTypeno<>'' then query2.sql.add('and c.Typeno like "'+pTypeno+'"');
//if pProvno<>'' then query2.sql.add('and a.Provno like "'+pProvno+'"');
query2.sql.add('group by b.wareno,c.warename,c.model,c.units');
query2.SQL.add('order by b.wareno');
Query2.open;
if not query2.IsEmpty then
with TFormCheckhzz5.create(self) do
begin
caption:='部门:'+ss+' '+query1.fieldbyname('dptname').asstring;
showmodal;
free;
end;
end;
end;
end;
procedure TFormCheckhzz.DBGrid1GetCellParams(Sender: TObject;
Column: TColumnEh; AFont: TFont; var Background: TColor;State: TGridDrawState);
begin
if not (gdSelected in State) then
if DBGrid1.SumList.RecNo mod 2 = 1 then
Background := $00F0FFFF //$00F9FFFF //$00FFC4C4
else
Background := $00F1E2E2;//$00FFDDDD;
end;
procedure TFormCheckhzz.myCreateGridEHList(var dbgrid1:TDBGridEH;Columnwidth:string);
var
fieldname0,ss0,ss:string;
p:integer;
AutoFitColWidths:boolean;
begin
AutoFitColWidths:=dbgrid1.AutoFitColWidths;
dbgrid1.AutoFitColWidths:=false;
ss0:=Columnwidth;
if copy(ss0,1,1)='^' then delete(ss0,1,1);
dbgrid1.Columns.Clear;
while length(ss0)>0 do
begin
p:=pos('^',ss0);
if p=0 then p:=length(ss0);
ss:=copy(ss0,1,p-1);
delete(ss0,1,p);
p:=pos(',',ss);
with dbgrid1.Columns.add do
begin
fieldname0:=uppercase(copy(ss,1,p-1));
fieldname:=fieldname0;
title.caption:=myGetdisplaylabel(fieldname);
title.Alignment:=taCenter;
footer.valuetype:=fvtStaticText;
{if dbgrid1.Columns.Count=1 then
begin
footer.value:='合计';
footer.alignment:=taCenter;
end else }
footer.alignment:=taRightJustify;
//if fieldname0='WARENO' then buttonstyle:=cbsEllipsis;
title.TitleButton:=pos('^'+fieldname0+'^','^ORDERNO^')=0;
delete(ss,1,p);
width:=strtoint('0'+ss);
if width=0 then width:=dbgrid1.Canvas.TextWidth(title.caption)+4;
end;
end;
dbgrid1.AutoFitColWidths:=AutoFitColWidths;
end;
function TFormCheckhzz.myGetdisplaylabel(fieldname:string):string;
begin
fieldname:=uppercase(fieldname);
if fieldname='ORDERNO' then result:='序号' else
if fieldname='WARENO' then result:='货代号' else
if fieldname='WARENAME' then result:='名称' else
if fieldname='HOUSENO' then result:='仓库代号' else
if fieldname='HOUSENAME' then result:='仓库名称' else
if fieldname='PROVNO' then result:='供应商代号' else
if fieldname='PROVNAME' then result:='供应商名称' else
if fieldname='DPTNO' then result:='部门代号' else
if fieldname='DPTNAME' then result:='部门名称' else
if fieldname='MODEL' then result:='规格' else
if fieldname='UNITS' then result:='单位' else
if fieldname='PRICE' then result:='单价' else
if fieldname='CURR' then result:='金额' else
if fieldname='AMOUNT' then result:='数量' else
if fieldname='NOTENO' then result:='单据号' else
if fieldname='NOTEDATE' then result:='日期' else
if fieldname='OPERANT' then result:='制单' else
if fieldname='CHECKMAN' then result:='审核' else
if fieldname='HOUSEMAN' then result:='库管' else
if fieldname='REMARK' then result:='备注' else
result:='';
end;
procedure TFormCheckhzz.StatusBar1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (x>StatusBar1.Panels[0].width+60) and (x<StatusBar1.Panels[0].width+StatusBar1.Panels[1].width+2) then
begin
combobox1.visible:=true;
combobox1.SetFocus;
end;
end;
procedure TFormCheckhzz.ComboBox1Click(Sender: TObject);
begin
dbgrid1.setfocus;
end;
procedure TFormCheckhzz.ComboBox1Exit(Sender: TObject);
begin
ComboBox1.Visible:=false;
StatusBar1.Panels[1].texT:='汇总方式:'+ComboBox1.text;
end;
procedure TFormCheckhzz.ComboBox1Enter(Sender: TObject);
begin
ComboBox1.itemindex:=pCxfs;
end;
procedure TFormCheckhzz.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key =27 then close;
end;
end.
他给我这个,考我能看出什么来。给我二十分时间。
unit Checkhzz;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ExtCtrls, Buttons, ToolWin,inifiles, Frame3ds, Grids, shDBGrids,
Db, DBTables, StdCtrls, Klabel2, DBGridEh;
type
TFormCheckhzz = class(TForm)
ToolBar1: TToolBar;
SpeedButtonFind: TSpeedButton;
SpeedButtonPrint: TSpeedButton;
SpeedButtonHelp: TSpeedButton;
SpeedButtonClose: TSpeedButton;
StatusBar1: TStatusBar;
DataSource1: TDataSource;
Query1: TQuery;
SpeedButtonDate: TSpeedButton;
QueryWarehouse: TQuery;
QueryWarecode: TQuery;
DBGrid1: TDBGridEh;
Query2: TQuery;
SpeedButtonFilter: TSpeedButton;
QueryGrouph: TQuery;
Frame1: TFrame;
QueryBrand: TQuery;
QueryWaretype: TQuery;
ComboBox1: TComboBox;
Query3: TQuery;
QueryDepartment: TQuery;
UpdateSQL1: TUpdateSQL;
function myGetdisplaylabel(fieldname:string):string;
procedure myCreateGridEHList(var dbgrid1:TDBGridEH;Columnwidth:string);
procedure mySumColumn;
procedure SpeedButtonCloseClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure SpeedButtonHelpClick(Sender: TObject);
procedure SpeedButtonFindClick(Sender: TObject);
procedure SpeedButtonDateClick(Sender: TObject);
procedure StatusBar1DrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
procedure SpeedButtonPrintClick(Sender: TObject);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumneh; State: TGridDrawState);
procedure DBGrid1TitleBtnClick(Sender: TObject; ACol: Integer;
Column: TColumnEh);
procedure DBGrid1DblClick(Sender: TObject);
procedure DBGrid1GetCellParams(Sender: TObject; Column: TColumnEh;
AFont: TFont; var Background: TColor; State: TGridDrawState);
procedure StatusBar1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ComboBox1Click(Sender: TObject);
procedure ComboBox1Exit(Sender: TObject);
procedure ComboBox1Enter(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
pPublicDataBaseName,pUserDataBaseName:string;
end;
procedure MainProc(var Message);export;
exports
MainProc;
var
FormCheckhzz: TFormCheckhzz;
pOrientation,pPaperSize,pPaperwidth,pPaperLength,pLeftMargin,pRightMargin,pTopMargin,pBottomMargin:integer;
pGroupno,pBrandno,pDptno,pTempname,pNoteno,pTypeno,pRemark,pWareNo,pWareName,pHouseno,pHousename,pColumnWidth,pPeriod,pUserdh,pBookmark,pRunPath:string;
pYear,pMonth,pDay:word;
pMaxdate,pMindate:Tdatetime;
pCxfs,pPriceprec:integer;
pUserDataBase:TDatabase;
implementation
uses shxtsy1,shConsts,sunlib,uCommon,suntool1,Checkhzz1,Checkhzz3,SizeField,DateRange,Checkhzz4,Checkhzz5;
{$R *.DFM}
procedure GetModuleInfo(var Message:TWMGetModuleInfo);
begin
with Message.ModuleInfo^ do
begin
Xtname:='库存管理';
ProcName:='Checkhzz';
ProcTitle:='库存盘点汇总帐';
end;
end;
procedure CreateForm(var Message:TWMCreateForm);
begin
with Message.CreateInfo^ do Form := TFormCheckhzz.Create(Owner);
end;
procedure MainProc(var Message);
begin
case TMessage(Message).Msg of
WM_CreateForm:CreateForm(TWMCreateForm(Message));
WM_GetModuleInfo:GetModuleInfo(TWMGetModuleInfo(Message));
end;
end;
procedure TFormCheckhzz.SpeedButtonCloseClick(Sender: TObject);
begin
close;
end;
procedure TFormCheckhzz.FormClose(Sender: TObject; var Action: TCloseAction);
var
inifile:Tinifile;
i:integer;
begin
if tag<>-2 then
begin
inifile:=Tinifile.Create(pRunPath+IniConfig0);
inifile.WriteInteger(name,'Top',top);
inifile.WriteInteger(name,'Left',left);
inifile.WriteInteger(name,'Width',width);
inifile.WriteInteger(name,'Height',height);
inifile.WriteInteger(name,'LeftMargin',pLeftMargin);
inifile.WriteInteger(name,'RightMargin',pRightMargin);
inifile.WriteInteger(name,'TopMargin',pTopMargin);
inifile.WriteInteger(name,'BottomMargin',pBottomMargin);
inifile.WriteInteger(name,'PaperLength',pPaperLength);
inifile.WriteInteger(name,'PaperWidth',pPaperWidth);
inifile.WriteInteger(name,'PaperSize',pPaperSize);
inifile.WriteInteger(name,'Cxfs',pCxfs);
inifile.WriteInteger(name,'Orientation',pOrientation);
inifile.WriteInteger(name,'WindowState',ord(WindowState));
pColumnwidth:='^';
for i:=0 to dbgrid1.Columns.Count-1 do
pColumnwidth:=pColumnwidth+dbgrid1.Columns.fieldname+','+inttostr(dbgrid1.Columns.width)+'^';
inifile.WriteString(name,'ColumnWidth',uppercase(pColumnwidth));
inifile.free;
end;
WriteValue(psClose,pBookmark);
Action:=cafree;
end;
procedure TFormCheckhzz.FormCreate(Sender: TObject);
begin
formCheckhzz:=sender as TFormCheckhzz;
pUserdh:=ReadValue(psUserdh);
pRunPath:=ReadValue(psRunPath);
pUserDataBase:=ReadDataBase(psUserDataBase);
pUserDataBaseName:=pUserDataBase.databasename;
pBookmark:=ReadValue(psBookmark);
if not GetWorkDate(pyear,pmonth,pday,pmaxdate,pmindate) then
begin
Application.MessageBox('未定义开始使用期间!',cTitle,FlagInformation);
tag:=-2;
close;
exit;
end;
pPricePrec:=ReadParamInteger('OPTIONS','PricePrec',2);
pPeriod:=inttostr(pyear)+strright(' '+inttostr(pmonth),2);
//if pMindate=pMaxdate then LabelDate.caption:=DateToLongStr(pMindate)
//else LabelDate.caption:=DateToLongStr(pMindate)+' - '+DateToLongStr(pMaxdate);
if pMindate=pMaxdate then StatusBar1.Panels[0].text:=DateToLongStr(pMindate)
else StatusBar1.Panels[0].text:=DateToLongStr(pMindate)+' - '+DateToLongStr(pMaxdate);
//----------------------------------------------------
ComboBox1.Parent:=StatusBar1;
ComboBox1.top:=2;
ComboBox1.lefT:=StatusBar1.panels[0].width+58;
//----------------------------------------------------
try
Query1.databasename:=pUserDataBaseName;
Query2.databasename:=pUserDataBaseName;
Query3.databasename:=pUserDataBaseName;
QueryGrouph.databasename:=pUserDataBaseName;
QueryGrouph.sql.text:='select * from Grouph where Groupno=:Groupno';
QueryDepartment.databasename:=pUserDataBaseName;
QueryDepartment.sql.text:='select * from Department where dptno=:dptno';
QueryWarehouse.databasename:=pUserDataBaseName;
QueryWarehouse.sql.text:='select * from warehouse where houseno=:houseno';
QueryWaretype.databasename:=pUserDataBaseName;
QueryWaretype.sql.text:='select * from waretype where typeno=:typeno';
QueryWarecode.databasename:=pUserDataBaseName;
QueryWarecode.sql.text:='select * from warecode where wareno=:wareno';
except
Application.MessageBox(errmess,cTitle,FlagInformation);
tag:=-2;
close;
exit;
end;
pWareNo:='';pWareName:='';pHouseno:='';pHousename:='';pRemark:='';
pTypeno:='';pNoteno:='';pDptno:='';pBrandno:='';pGroupno:='';
end;
procedure TFormCheckhzz.FormShow(Sender: TObject);
var
inifile:Tinifile;
//i:integer;
//ss:string;
begin
inifile:=Tinifile.Create(pRunPath+IniConfig0);
top:=inifile.ReadInteger(name,'Top',top);
left:=inifile.ReadInteger(name,'Left',left);
width:=inifile.ReadInteger(name,'Width',width);
height:=inifile.ReadInteger(name,'Height',height);
WindowState:=TWindowState(inifile.ReadInteger(name,'WindowState',0));
pLeftMargin:=inifile.ReadInteger(name,'LeftMargin',10);
pRightMargin:=inifile.ReadInteger(name,'RightMargin',10);
pTopMargin:=inifile.ReadInteger(name,'TopMargin',10);
pBottomMargin:=inifile.ReadInteger(name,'BottomMargin',10);
pPaperWidth:=inifile.ReadInteger(name,'PaperWidth',328);
pPaperLength:=inifile.ReadInteger(name,'PaperLength',280);
pPaperSize:=inifile.ReadInteger(name,'PaperSize',9);
pOrientation:=inifile.ReadInteger(name,'Orientation',0);
pColumnWidth:=inifile.ReadString(name,'ColumnWidth','');
pCxfs:=inifile.ReadInteger(name,'Cxfs',0);
inifile.free;
ComboBox1.itemindex:=pCxfs;
StatusBar1.Panels[1].texT:='汇总方式:'+ComboBox1.text;
if pColumnWidth='' then
case pCxfs of
0ColumnWidth:='^WARENO,75^WARENAME,88^MODEL,40^UNITS,38^AMOUNT,50^PRICE,68^CURR,88^';
1ColumnWidth:='^HOUSENO,40^HOUSENAME,100^AMOUNT,50^PRICE,68^CURR,88^';
//2ColumnWidth:='^PROVNO,40^PROVNAME,100^AMOUNT,50^PRICE,68^CURR,88^';
2ColumnWidth:='^DPTNO,40^DPTNAME,100^AMOUNT,50^PRICE,68^CURR,88^';
end;
myCreateGridEHList(dbgrid1,pColumnwidth);
{for i:=0 to dbgrid1.Columns.Count-1 do
begin
ss:=uppercase(dbgrid1.columns.fieldname);
dbgrid1.Columns.title.TitleButton:=pos('^'+ss+'^','^AAA^')=0;
end;}
end;
procedure TFormCheckhzz.SpeedButtonHelpClick(Sender: TObject);
begin
Application.helpcontext(Helpcontext);
end;
procedure TFormCheckhzz.SpeedButtonFindClick(Sender: TObject);
var
//sqlindex:string;
form1:TForm;
i:integer;
begin
with TformCheckhzz3.create(self) do
begin
showmodal;
i:=tag;
free;
end;
if i=0 then exit;
form1:=messagewaitbox('','正在查询,请稍候......');
query1.DisableControls;
query1.close;
update;
//---------------------------------------------------------------------
if pCxfs<>ComboBox1.itemindex then
begin
dbgrid1.Columns.Clear;
pCxfs:=ComboBox1.itemindex;
case pCxfs of
0ColumnWidth:='^WARENO,75^WARENAME,88^MODEL,40^UNITS,38^AMOUNT,50^PRICE,68^CURR,88^';
1ColumnWidth:='^HOUSENO,40^HOUSENAME,100^AMOUNT,50^PRICE,68^CURR,88^';
//2ColumnWidth:='^PROVNO,40^PROVNAME,100^AMOUNT,50^PRICE,68^CURR,88^';
2ColumnWidth:='^DPTNO,40^DPTNAME,100^AMOUNT,50^PRICE,68^CURR,88^';
end;
myCreateGridEHList(dbgrid1,pColumnwidth);
end;
//---------------------------------------------------------------------
pTempname:='#'+shsjh;
query2.close;
query2.sql.clear;
if pCxfs=0 then //商品代号
begin
query2.sql.add('select b.wareno,c.warename,c.model,c.units,sum(b.amount) as amount,');
query2.sql.add('sum(b.curr) as curr');
query2.sql.add('into '+pTempname);
query2.sql.add('from WareCheckh a,WareCheckm b,warecode c');
query2.sql.add('where a.noteno=b.noteno and b.wareno=c.wareno');
query2.sql.add('and a.tag=1 and b.amount<>0');
Query2.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
Query2.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
if pWareno<>'' then query2.sql.add('and b.wareno like "'+pWareno+'"');
if pGroupno<>'' then
begin
query2.sql.add('and b.wareno in');
query2.sql.add('(select b.wareno from grouph a,groupm b ');
query2.sql.add('where a.groupno=b.groupno');
query2.sql.add('and a.groupno="'+pGroupno+'")');
end;
if pHouseno<>'' then query2.sql.add('and a.Houseno like "'+pHouseno+'"');
if pDptno<>'' then query2.sql.add('and a.Dptno like "'+pDptno+'"');
if pTypeno<>'' then query2.sql.add('and c.Typeno like "'+pTypeno+'"');
query2.sql.add('group by b.wareno,c.warename,c.model,c.units');
query2.ExecSQL;
query1.close;
query1.sql.clear;
query1.sql.add('select a.wareno,a.warename,a.model,a.units');
query1.sql.add(',sum(a.amount) as amount,sum(a.curr)/sum(a.amount) as price,');
query1.sql.add('sum(a.curr) as curr,0 as orderno');
query1.sql.Add('from '+pTempname+' a');
query1.sql.add('group by a.wareno,a.warename,a.model,a.units');
query1.sql.add('order by a.wareno');
end else
if pCxfs=1 then //仓库
begin
query2.sql.add('select a.houseno,d.housename,sum(b.amount) as amount,');
query2.sql.add('sum(b.curr) as curr');
query2.sql.add('into '+pTempname);
query2.sql.add('from WareCheckh a,WareCheckm b,warecode c,warehouse d');
query2.sql.add('where a.noteno=b.noteno and b.wareno=c.wareno and a.houseno=d.houseno');
query2.sql.add('and a.tag=1 and b.amount<>0');
Query2.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
Query2.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
if pWareno<>'' then query2.sql.add('and b.wareno like "'+pWareno+'"');
if pGroupno<>'' then
begin
query2.sql.add('and b.wareno in');
query2.sql.add('(select b.wareno from grouph a,groupm b ');
query2.sql.add('where a.groupno=b.groupno');
query2.sql.add('and a.groupno="'+pGroupno+'")');
end;
if pHouseno<>'' then query2.sql.add('and a.Houseno like "'+pHouseno+'"');
//if pProvno<>'' then query2.sql.add('and a.provno like "'+pProvno+'"');
if pDptno<>'' then query2.sql.add('and a.Dptno like "'+pDptno+'"');
if pTypeno<>'' then query2.sql.add('and c.Typeno like "'+pTypeno+'"');
query2.sql.add('group by a.houseno,d.housename');
query2.ExecSQL;
query1.close;
query1.sql.clear;
query1.sql.add('select a.houseno,a.housename');
query1.sql.add(',sum(a.amount) as amount,sum(a.curr)/sum(a.amount) as price,');
query1.sql.add('sum(a.curr) as curr,0 as orderno');
query1.sql.Add('from '+pTempname+' a');
query1.sql.add('group by a.houseno,a.housename');
query1.sql.add('order by a.houseno');
end else
{if pCxfs=2 then //供应商
begin
query2.sql.add('select a.provno,d.name as provname,sum(b.amount) as amount,');
query2.sql.add('sum(b.curr) as curr');
query2.sql.add('into '+pTempname);
query2.sql.add('from WareCheckh a,WareCheckm b,warecode c,provide d');
query2.sql.add('where a.period=b.period and a.noteno=b.noteno and b.wareno=c.wareno and a.provno=d.code');
Query2.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
Query2.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
if pWareno<>'' then query2.sql.add('and b.wareno like "'+pWareno+'"');
if pHouseno<>'' then query2.sql.add('and a.Houseno like "'+pHouseno+'"');
if pProvno<>'' then query2.sql.add('and a.provno like "'+pProvno+'"');
if pDptno<>'' then query2.sql.add('and a.Dptno like "'+pDptno+'"');
if pTypeno<>'' then query2.sql.add('and c.Typeno like "'+pTypeno+'"');
query2.sql.add('group by a.provno,d.name');
query2.ExecSQL;
query1.close;
query1.sql.clear;
query1.sql.add('select a.provno,a.provname');
query1.sql.add(',sum(a.amount) as amount,sum(a.curr)/sum(a.amount) as price,');
query1.sql.add('sum(a.curr) as curr');
query1.sql.Add('from '+pTempname+' a');
query1.sql.add('group by a.provno,a.provname');
query1.sql.add('order by a.provno');
end else}
if pCxfs=2 then //部门
begin
query2.sql.add('select a.dptno,d.dptname,sum(b.amount) as amount,');
query2.sql.add('sum(b.curr) as curr');
query2.sql.add('into '+pTempname);
query2.sql.add('from WareCheckh a,WareCheckm b,warecode c,department d');
query2.sql.add('where a.noteno=b.noteno and b.wareno=c.wareno and a.dptno=d.dptno');
query2.sql.add('and a.tag=1 and b.amount<>0');
Query2.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
Query2.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
if pWareno<>'' then query2.sql.add('and b.wareno like "'+pWareno+'"');
if pGroupno<>'' then
begin
query2.sql.add('and b.wareno in');
query2.sql.add('(select b.wareno from grouph a,groupm b ');
query2.sql.add('where a.groupno=b.groupno');
query2.sql.add('and a.groupno="'+pGroupno+'")');
end;
if pHouseno<>'' then query2.sql.add('and a.Houseno like "'+pHouseno+'"');
//if pProvno<>'' then query2.sql.add('and a.provno like "'+pProvno+'"');
if pDptno<>'' then query2.sql.add('and a.Dptno like "'+pDptno+'"');
if pTypeno<>'' then query2.sql.add('and c.Typeno like "'+pTypeno+'"');
query2.sql.add('group by a.dptno,d.dptname');
query2.ExecSQL;
query1.close;
query1.sql.clear;
query1.sql.add('select a.dptno,a.dptname');
query1.sql.add(',sum(a.amount) as amount,sum(a.curr)/sum(a.amount) as price,');
query1.sql.add('sum(a.curr) as curr,0 as orderno');
query1.sql.Add('from '+pTempname+' a');
query1.sql.add('group by a.dptno,a.dptname');
query1.sql.add('order by a.dptno');
end;
query1.open;
query1.first;
i:=1;
while not query1.eof do
begin
query1.edit;
query1.FieldByName('orderno').asinteger:=i;
query1.post;
query1.next;
inc(i);
end;
query1.first;
mySumColumn;
SpeedButtonPrint.Enabled:=not query1.IsEmpty;
query1.EnableControls;
form1.free;
end;
procedure TFormCheckhzz.SpeedButtonDateClick(Sender: TObject);
begin
with TformDateRange.create(self) do
begin
DateTimePickerMindate.date:=pMindate;
DateTimePickerMaxdate.date:=pMaxdate;
showmodal;
if tag=1 then
begin
pMindate:=DateTimePickerMindate.date;
pMaxdate:=DateTimePickerMaxdate.date;
if pMindate=pMaxdate then StatusBar1.Panels[0].text:=DateToLongStr(pMindate)
else StatusBar1.Panels[0].text:=DateToLongStr(pMindate)+' - '+DateToLongStr(pMaxdate);
//if datetostr(pMindate)=datetostr(pMaxdate) then LabelDate.caption:=DateToLongStr(pMindate)
//else LabelDate.caption:=DateToLongStr(pMindate)+' - '+DateToLongStr(pMaxdate);
end;
free;
end;
end;
procedure TFormCheckhzz.StatusBar1DrawPanel(StatusBar: TStatusBar;Panel: TStatusPanel; const Rect: TRect);
begin
draw3dtext(StatusBar.Canvas,rect,Panel.Text,tsLowered,panel.Alignment);
end;
procedure TFormCheckhzz.SpeedButtonPrintClick(Sender: TObject);
begin
with TFormCheckhzz1.create(self) do
begin
showmodal;
free;
end;
end;
procedure TFormCheckhzz.DBGrid1DrawColumnCell(Sender: TObject;const Rect: TRect; DataCol: Integer; Column: TColumneh; State: TGridDrawState);
var
ss,fieldname:string;
rect1:TRect;
pict:integer;
begin
pict:=DT_VCENTER+DT_SINGLELINE;
rect1:=rect;
dbgrid1.Canvas.FillRect(rect1);
fieldname:=uppercase(column.fieldname);
if pos('^'+fieldname+'^','^UNITS^MODEL^ORDERNO^')>0 then
begin
ss:=query1.fieldbyname(fieldname).asString;
pict:=pict+DT_center;
end else
if fieldname='PRICE' then
begin
if query1.fieldbyname(fieldname).asfloat=0 then ss:='' else
ss:=floattostrf(query1.fieldbyname(fieldname).asfloat,ffNumber,14,pPriceprec);
pict:=pict+DT_RIGHT;
end else
if pos('^'+fieldname+'^','^CURR^')>0 then
begin
if query1.fieldbyname(fieldname).asfloat=0 then ss:='' else
ss:=floattostrf(query1.fieldbyname(fieldname).asfloat,ffNumber,14,2);
pict:=pict+DT_RIGHT;
end else
if fieldname='AMOUNT' then
begin
if query1.fieldbyname(fieldname).asfloat=0 then ss:='' else
ss:=query1.fieldbyname(fieldname).asstring;
pict:=pict+DT_RIGHT;
end else
begin
ss:=query1.fieldbyname(fieldname).asString;
pict:=pict+DT_LEFT;
end;
drawtext(dbgrid1.Canvas.Handle,pchar(ss),-1,rect1,pict);
end;
procedure TFormCheckhzz.DBGrid1TitleBtnClick(Sender: TObject; ACol: Integer;Column: TColumnEh);
var
fdname,ss:string;
i:integer;
begin
if not query1.Active then exit;
fdname:=uppercase(dbgrid1.columns[acol].fieldname);
//if pos('^'+fdname+'^','^PRICE^')>0 then exit;
for i:=0 to dbgrid1.columns.count-1 do
if acol<>i then dbgrid1.Columns.Title.SortMarker := smNoneEh;
ss:='';
if dbgrid1.Columns[ACol].Title.SortMarker = smUpEh then
begin
dbgrid1.Columns[ACol].Title.SortMarker:=smDownEh;
ss:=' desc ';
end else dbgrid1.Columns[ACol].Title.SortMarker:=smUpEh;
query1.DisableControls;
query1.close;
query1.SQL.Strings[query1.SQL.Count-1]:='order by a.'+DBGrid1.Columns[acol].fieldname+ss;
query1.open;
query1.first;
i:=1;
while not query1.eof do
begin
query1.edit;
query1.FieldByName('orderno').asinteger:=i;
query1.post;
query1.next;
inc(i);
end;
query1.first;
query1.EnableControls;
end;
procedure TFormCheckhzz.mySumColumn;
var
maxnum,i:integer;
hj:array of real;
sreturn,fieldname:string;
hjb:boolean;
begin
hjb:=false;
sreturn:=query1.Bookmark;
maxnum:=dbgrid1.Columns.Count-1;
setlength(hj,maxnum+1);
for i:=0 to maxnum do hj:=0;
query1.first;
while not query1.eof do
begin
for i:=0 to maxnum do
begin
try
fieldname:=uppercase(dbgrid1.Columns.fieldname);
if query1.FindField(fieldname)<>nil then
if pos('^'+fieldname+'^','^PRICE^')=0 then
if (query1.FieldByName(fieldname).datatype=ftFloat) or (query1.FieldByName(fieldname).datatype=ftCurrency) then
hj:=hj+query1.fieldbyname(fieldname).asfloat;
except
end;
end;
query1.next;
end;
for i:=0 to maxnum do
begin
fieldname:=uppercase(dbgrid1.Columns.fieldname);
if query1.FindField(fieldname)<>nil then
case query1.FieldByName(fieldname).datatype of
ftFloat,ftCurrency:
if pos('^'+fieldname+'^','^PRICE^')=0 then
begin
if copy(fieldname,1,6)='AMOUNT' then
if hj=0 then dbgrid1.Columns.footer.value:=''
else dbgrid1.Columns.footer.value:=floattostr(hj)
else
if hj=0 then dbgrid1.Columns.footer.value:=''
else dbgrid1.Columns.footer.value:=floattostrf(hj,ffNumber,16,2);
end;
else
if fieldname<>'ORDERNO' then
if not hjb then
begin
dbgrid1.Columns.footer.value:='合计';
dbgrid1.Columns.footer.Alignment:=taCenter;
hjb:=true;
end else dbgrid1.Columns.footer.value:='';
end;
end;
query1.Bookmark:=sreturn;
end;
procedure TFormCheckhzz.DBGrid1DblClick(Sender: TObject);
var
ss:string;
begin
if query1.IsEmpty then exit;
case pcxfs of
0:begin //商品代号
ss:=query1.fieldbyname('wareno').asstring;
query3.close;
query3.sql.clear;
query3.sql.add('select a.period,a.noteno,a.notedate,b.amount,b.price,b.curr,0 as tag0');
query3.sql.add('from WareCheckh a,WareCheckm b,warecode c');
query3.sql.add('where a.noteno=b.noteno');
query3.sql.add('and b.wareno="'+ss+'" and b.wareno=c.wareno and a.tag=1 and b.amount<>0');
query3.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
query3.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
//if pTypeno<>'' then query3.sql.add('and c.Typeno like "'+pTypeno+'"');
if pHouseno<>'' then query3.sql.add('and a.Houseno like "'+pHouseno+'"');
//if pProvno<>'' then query3.sql.add('and a.provno like "'+pProvno+'"');
if pDptno<>'' then query3.sql.add('and a.Dptno like "'+pDptno+'"');
query3.SQL.add('order by a.noteno');
query3.open;
if not query3.IsEmpty then
with TFormCheckhzz4.create(self) do
begin
caption:='品名:'+ss+' '+query1.fieldbyname('warename').asstring;
showmodal;
free;
end;
end;
1:begin //仓库
ss:=query1.fieldbyname('houseno').asstring;
query2.close;
query2.sql.clear;
query2.sql.add('select b.wareno,c.warename,c.model,c.units,sum(b.amount) as amount,');
query2.sql.add('sum(b.curr) as curr,sum(curr)/sum(amount) as price');
query2.sql.add('from WareCheckh a,WareCheckm b,warecode c');
query2.sql.add('where a.noteno=b.noteno and b.wareno=c.wareno');
query2.sql.add('and a.houseno="'+ss+'" and a.tag=1 and b.amount<>0');
Query2.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
Query2.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
if pWareno<>'' then query2.sql.add('and b.wareno like "'+pWareno+'"');
if pGroupno<>'' then
begin
query2.sql.add('and b.wareno in');
query2.sql.add('(select b.wareno from grouph a,groupm b ');
query2.sql.add('where a.groupno=b.groupno');
query2.sql.add('and a.groupno="'+pGroupno+'")');
end;
if pTypeno<>'' then query2.sql.add('and c.Typeno like "'+pTypeno+'"');
if pBrandno<>'' then query2.sql.add('and c.Brandno like "'+pBrandno+'"');
if pDptno<>'' then query2.sql.add('and a.Dptno like "'+pDptno+'"');
query2.sql.add('group by b.wareno,c.warename,c.model,c.units');
query2.SQL.add('order by b.wareno');
Query2.open;
if not query2.IsEmpty then
with TFormCheckhzz5.create(self) do
begin
caption:='仓库:'+ss+' '+query1.fieldbyname('housename').asstring;
showmodal;
free;
end;
end;
{2:begin //供应商
ss:=query1.fieldbyname('provno').asstring;
query2.close;
query2.sql.clear;
query2.sql.add('select b.wareno,c.warename,c.model,c.units,sum(b.amount) as amount,');
query2.sql.add('sum(b.curr) as curr,sum(curr)/sum(amount) as price');
query2.sql.add('from WareCheckh a,WareCheckm b,warecode c');
query2.sql.add('where a.period=b.period and a.noteno=b.noteno and b.wareno=c.wareno');
query2.sql.add('and a.provno="'+ss+'"');
Query2.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
Query2.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
if pWareno<>'' then query2.sql.add('and b.wareno like "'+pWareno+'"');
if pHouseno<>'' then query2.sql.add('and a.Houseno like "'+pHouseno+'"');
if pTypeno<>'' then query2.sql.add('and c.Typeno like "'+pTypeno+'"');
if pDptno<>'' then query2.sql.add('and a.Dptno like "'+pDptno+'"');
query2.sql.add('group by b.wareno,c.warename,c.model,c.units');
query2.SQL.add('order by b.wareno');
Query2.open;
if not query2.IsEmpty then
with TFormCheckhzz5.create(self) do
begin
caption:='供应商:'+ss+' '+query1.fieldbyname('provname').asstring;
showmodal;
free;
end;
end;}
2:begin //部门
ss:=query1.fieldbyname('dptno').asstring;
query2.close;
query2.sql.clear;
query2.sql.add('select b.wareno,c.warename,c.model,c.units,sum(b.amount) as amount,');
query2.sql.add('sum(b.curr) as curr,sum(curr)/sum(amount) as price');
query2.sql.add('from WareCheckh a,WareCheckm b,warecode c');
query2.sql.add('where a.noteno=b.noteno and b.wareno=c.wareno');
query2.sql.add('and a.dptno="'+ss+'" and a.tag=1 and b.amount<>0');
Query2.sql.add('and a.notedate>="'+formatdatetime('yyyy-mm-dd 00:00:00',pMinDate)+'"');
Query2.sql.add('and a.notedate<="'+formatdatetime('yyyy-mm-dd 23:59:59',pMaxDate)+'"');
if pWareno<>'' then query2.sql.add('and b.wareno like "'+pWareno+'"');
if pGroupno<>'' then
begin
query2.sql.add('and b.wareno in');
query2.sql.add('(select b.wareno from grouph a,groupm b ');
query2.sql.add('where a.groupno=b.groupno');
query2.sql.add('and a.groupno="'+pGroupno+'")');
end;
if pHouseno<>'' then query2.sql.add('and a.Houseno like "'+pHouseno+'"');
if pTypeno<>'' then query2.sql.add('and c.Typeno like "'+pTypeno+'"');
//if pProvno<>'' then query2.sql.add('and a.Provno like "'+pProvno+'"');
query2.sql.add('group by b.wareno,c.warename,c.model,c.units');
query2.SQL.add('order by b.wareno');
Query2.open;
if not query2.IsEmpty then
with TFormCheckhzz5.create(self) do
begin
caption:='部门:'+ss+' '+query1.fieldbyname('dptname').asstring;
showmodal;
free;
end;
end;
end;
end;
procedure TFormCheckhzz.DBGrid1GetCellParams(Sender: TObject;
Column: TColumnEh; AFont: TFont; var Background: TColor;State: TGridDrawState);
begin
if not (gdSelected in State) then
if DBGrid1.SumList.RecNo mod 2 = 1 then
Background := $00F0FFFF //$00F9FFFF //$00FFC4C4
else
Background := $00F1E2E2;//$00FFDDDD;
end;
procedure TFormCheckhzz.myCreateGridEHList(var dbgrid1:TDBGridEH;Columnwidth:string);
var
fieldname0,ss0,ss:string;
p:integer;
AutoFitColWidths:boolean;
begin
AutoFitColWidths:=dbgrid1.AutoFitColWidths;
dbgrid1.AutoFitColWidths:=false;
ss0:=Columnwidth;
if copy(ss0,1,1)='^' then delete(ss0,1,1);
dbgrid1.Columns.Clear;
while length(ss0)>0 do
begin
p:=pos('^',ss0);
if p=0 then p:=length(ss0);
ss:=copy(ss0,1,p-1);
delete(ss0,1,p);
p:=pos(',',ss);
with dbgrid1.Columns.add do
begin
fieldname0:=uppercase(copy(ss,1,p-1));
fieldname:=fieldname0;
title.caption:=myGetdisplaylabel(fieldname);
title.Alignment:=taCenter;
footer.valuetype:=fvtStaticText;
{if dbgrid1.Columns.Count=1 then
begin
footer.value:='合计';
footer.alignment:=taCenter;
end else }
footer.alignment:=taRightJustify;
//if fieldname0='WARENO' then buttonstyle:=cbsEllipsis;
title.TitleButton:=pos('^'+fieldname0+'^','^ORDERNO^')=0;
delete(ss,1,p);
width:=strtoint('0'+ss);
if width=0 then width:=dbgrid1.Canvas.TextWidth(title.caption)+4;
end;
end;
dbgrid1.AutoFitColWidths:=AutoFitColWidths;
end;
function TFormCheckhzz.myGetdisplaylabel(fieldname:string):string;
begin
fieldname:=uppercase(fieldname);
if fieldname='ORDERNO' then result:='序号' else
if fieldname='WARENO' then result:='货代号' else
if fieldname='WARENAME' then result:='名称' else
if fieldname='HOUSENO' then result:='仓库代号' else
if fieldname='HOUSENAME' then result:='仓库名称' else
if fieldname='PROVNO' then result:='供应商代号' else
if fieldname='PROVNAME' then result:='供应商名称' else
if fieldname='DPTNO' then result:='部门代号' else
if fieldname='DPTNAME' then result:='部门名称' else
if fieldname='MODEL' then result:='规格' else
if fieldname='UNITS' then result:='单位' else
if fieldname='PRICE' then result:='单价' else
if fieldname='CURR' then result:='金额' else
if fieldname='AMOUNT' then result:='数量' else
if fieldname='NOTENO' then result:='单据号' else
if fieldname='NOTEDATE' then result:='日期' else
if fieldname='OPERANT' then result:='制单' else
if fieldname='CHECKMAN' then result:='审核' else
if fieldname='HOUSEMAN' then result:='库管' else
if fieldname='REMARK' then result:='备注' else
result:='';
end;
procedure TFormCheckhzz.StatusBar1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (x>StatusBar1.Panels[0].width+60) and (x<StatusBar1.Panels[0].width+StatusBar1.Panels[1].width+2) then
begin
combobox1.visible:=true;
combobox1.SetFocus;
end;
end;
procedure TFormCheckhzz.ComboBox1Click(Sender: TObject);
begin
dbgrid1.setfocus;
end;
procedure TFormCheckhzz.ComboBox1Exit(Sender: TObject);
begin
ComboBox1.Visible:=false;
StatusBar1.Panels[1].texT:='汇总方式:'+ComboBox1.text;
end;
procedure TFormCheckhzz.ComboBox1Enter(Sender: TObject);
begin
ComboBox1.itemindex:=pCxfs;
end;
procedure TFormCheckhzz.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key =27 then close;
end;
end.