代码如下:
unit Qryfrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls, jpeg, Db, ADODB, Grids, DBGrids, DBCtrls,
Buttons, ImgList, Qrctrls, QuickRpt, Gauges, DBTables;
type
Tqryfm = class(TForm)
Panel3: TPanel;
Image1: TImage;
Label1: TLabel;
StatusBar1: TStatusBar;
DataSource1: TDataSource;
Panel2: TPanel;
Image2: TImage;
Edit1: TEdit;
BtnQuery: TBitBtn;
BtnCancel: TBitBtn;
Doing: TAnimate;
Splitter1: TSplitter;
Panel1: TPanel;
Splitter2: TSplitter;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
DBMemo1: TDBMemo;
TabSheet2: TTabSheet;
DBMemo2: TDBMemo;
TabSheet3: TTabSheet;
DBMemo3: TDBMemo;
DBGrid1: TDBGrid;
ImageList1: TImageList;
Btnscdd: TBitBtn;
BtnPrnt: TBitBtn;
reportPl: TPanel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Label5: TLabel;
ADOQuery1: TQuery;
ADOQueryTxtRecord: TQuery;
Session1: TSession;
Database1: TDatabase;
procedure Tqryfm.BtnQueryClick(Sender: TObject);
VAR whereStr: String;cxLx:Byte;
begin
Doing.Visible:=True;Doing.Active:=True;screen.cursor:=crSQLWait;
whereStr:='';cxLx:=1; // 1: 查客户订单,2:查生产订单
Btnscdd.Enabled:=False;
IF Edit2.Text<>'' THEN cxLx:=1
ELSE if Edit3.Text<>'' THEN cxLx:=2
else IF Edit2.Focused then cxLx:=1
ELSE if Edit3.Focused then cxLx:=2;
IF cxLx=1 THEN begin // 查询客户订单
Label1.Caption:='客户订单正文查询';
IF Trim(Edit2.Text)<>'' THEN
whereStr:=' (ONBOOK.物料 like '+Chr(39)+Trim(Edit2.Text)+'%'+Chr(39)+') AND ';
ADOQuery1.Close; //排出下达生产订单的记录
IF Trim(Edit1.Text)<>'' THEN
ADOQuery1.SQL.Text:=' SELECT * FROM ONBOOK '+
' WHERE '+whereStr+'not exists (select * from ONMAKE where ONBOOK.客户订单=ONMAKE.客户订单'+
' AND ONBOOK.行号=ONMAKE.订单行号)'+
' AND 物料 IN (SELECT IMPN FROM MFG_ITMMAST WHERE IMPLNR='+
Chr(39)+TRIM(Edit1.Text)+Chr(39)+')'+
' ORDER BY ONBOOK.客户订单,ONBOOK.行号 ' // 限制在本生产计划员所管物料内。
ELSE
ADOQuery1.SQL.Text:=' SELECT * FROM ONBOOK '+
' WHERE'+whereStr+' not exists (select * from ONMAKE where ONBOOK.客户订单=ONMAKE.客户订单'+
' AND ONBOOK.行号=ONMAKE.订单行号)'+
' ORDER BY ONBOOK.客户订单,ONBOOK.行号 ' ;
BtnPrnt.Tag:=1;
end
ELSE begin // 按生产订单查询(已下达生产订单的记录)
Label1.Caption:='生产订单正文查询';
whereStr:='';
IF Trim(Edit3.Text)<>'' THEN
whereStr:=' (ONMAKE.生产订单 like '+Chr(39)+Trim(Edit3.Text)+'%'+Chr(39)+') ';
IF Trim(Edit1.Text)<>'' THEN begin
if whereStr<>'' then whereStr:=whereStr+' AND ';
whereStr := whereStr+'(ONMAKE.生产计划员='+Chr(39)+Trim(Edit1.Text)+Chr(39)+') ';end;
if whereStr<>'' then whereStr:= 'WHERE '+ whereStr;
ADOQuery1.Close;
ADOQuery1.SQL.Text:=' SELECT * From ONMAKE '+whereStr+' ORDER BY 客户订单,订单行号,生产订单,行号 ';
BtnPrnt.Tag:=2;
end; // ENDIF
Statusbar1.Panels[0].Text:='>>>正在查询……';refresh;
Try
adoquery1.sql.text;
ADOQuery1.Open ;
Finally
ADOQuery1.FieldByName('单位').DisplayWidth:=4;
IF cxLx=1 THEN begin
ADOQuery1.FieldByName('承诺交货日').DisplayWidth:=10;
ADOQuery1.FieldByName('原承交日').DisplayWidth:=10;
end else begin
if NOT ADOQuery1.IsEmpty AND (Copy(OperPower,3,1)='1') then Btnscdd.Enabled:=True;
ADOQuery1.FieldByName('开工日期').DisplayWidth:=10;
ADOQuery1.FieldByName('完工日期').DisplayWidth:=10
end; // endif
DBGrid1.SetFocus;
ADOQuery1.last;
Statusbar1.Panels[0].Text:='完成';
IF NOT ADOQuery1.BOF then ADOQuery1.Prior;
end;//endTry
Doing.Visible:=False;Doing.Active:=False;screen.cursor:=crDefault;
end;
procedure Tqryfm.ADOQuery1AfterScroll(DataSet: TDataSet);
begin
IF DBGrid1.Focused THEN begin
if Length(ADOQuery1.FieldByName('技术要求').AsString)=0 then TabSheet1.TabVisible:=False
else TabSheet1.TabVisible:=True;
if Length(ADOQuery1.FieldByName('生产要求').AsString)=0 then TabSheet2.TabVisible:=False
else TabSheet2.TabVisible:=True;
if Length(ADOQuery1.FieldByName('检验要求').AsString)=0 then TabSheet3.TabVisible:=False
else TabSheet3.TabVisible:=True;
end;
end;
注:在onbook和onmake表中技术要求,生产要求,检验要求3个字段的类型为varchar(4000),
在dbmemo中显示其内容。