【delphi开源代码栏目提醒】:网学会员为广大网友收集整理了,GDZCCX.pas,希望对大家有所帮助!
unit GDZCCX;
interface
uses
Windows, SysUtils, Variants, Classes, Controls, Forms, StdCtrls, ExtCtrls,
dmGdzc, DB, Grids, DBGrids, GDZCCommon;
type
TGDZCCXForm = class(TForm)
pnlToolBar: TPanel;
btQuery: TButton;
lblBh: TLabel;
lblMc: TLabel;
edtMC: TEdit;
edtBH: TEdit;
cbYZ: TComboBox;
lblYz: TLabel;
edtYZ: TEdit;
lblBs: TLabel;
dbGDZCCX: TDBGrid;
dsGDZCCX: TDataSource;
btAll: TButton;
pnlTitle: TPanel;
cbSFBS: TComboBox;
procedure btQueryClick(Sender: TObject);
procedure btAllClick(Sender: TObject);
private
{ Private declarations }
FdmGDZC: TdmGdzc;
function GetSEdit(AFieldName: string; AEdit: TEdit): string;
function GetIEdit(AFieldName: string; AComboBox:TComboBox; AEdit: TEdit): string;
function GetComboBox(AFieldName: string; AComboBox: TComboBox): string;
function GetSQL(All: Boolean): string;
public
{ Public declarations }
constructor Create(AOwner: TComponent; AdmGDZC: TdmGdzc); reintroduce;
end;
var
GDZCCXForm: TGDZCCXForm;
implementation
{$R *.dfm}
constructor TGDZCCXForm.Create(AOwner: TComponent; AdmGDZC: TdmGdzc);
begin
inherited Create(AOwner);
FdmGDZC := admGDZC;
InitDBGrid(FdmGDZC.cdGDZCCXField, dbGDZCCX);
dsGDZCCX.DataSet := FdmGDZC.cdGDZCCX;
end;
function TGDZCCXForm.GetComboBox(AFieldName: string; AComboBox: TComboBox): string;
begin
Result := '';
case AComboBox.ItemIndex of
1:
Result := 'a.' + AFieldName + '=1';
2:
Result := 'a.' + AFieldName + '=0';
end;
end;
function TGDZCCXForm.GetIEdit(AFieldName: string;
AComboBox: TComboBox; AEdit: TEdit): string;
begin
Result := '';
if AComboBox.ItemIndex < 0 then Exit;
Aedit.Text := Trim(AEdit.Text);
if not IsNumeric(AEdit.Text) then exit;
if Length(AEdit.Text) > 0 then
Result := 'a.' + AFieldName + Trim(AComboBox.Text) + AEdit.Text;
end;
function TGDZCCXForm.GetSEdit(AFieldName: string; AEdit: TEdit): string;
begin
Result := '';
Aedit.Text := Trim(AEdit.Text);
if Length(AEdit.Text) > 0 then
Result := 'a.' + AFieldName + ' Like ' + Quotedstr('%'+ AEdit.Text + '%');
end;
function TGDZCCXForm.GetSQL(All: Boolean): string;
const
conSQL = 'select a.*, b.ZJJE from GDZC a ' +
'left join (Select BH, Sum(ZJJE) as ZJJE From GDZCZJ group by BH) b ' +
'on a.BH = b.BH';
procedure AddSQL(ASQL: string);
begin
if Length(ASQL) > 0 then
begin
if Length(Result) = 0 then
Result := ASQL
else
Result := Result + ' and ' + ASQL;
end;
end;
begin
if All then
begin
Result := conSQL;
Exit;
end;
Result := '';
AddSQL(GetSEdit('BH', edtBH));
AddSQL(GetSEdit('MC', edtMC));
AddSQL(GetComboBox('SFBS', cbSFBS));
AddSQL(GetIEdit('YZ', cbYZ, edtYZ));
if Length(Result) > 0 then
Result := conSQL + ' where ' + Result
else
Result := conSQL;
end;
procedure TGDZCCXForm.btQueryClick(Sender: TObject);
begin
with FdmGDZC, sqlGDZCCX do
begin
if cdGDZCCX.Active then cdGDZCCX.Close;
if Active then Close;
SQL.Text := GetSQL(False);
Open;
cdGDZCCX.Open;
end;
end;
procedure TGDZCCXForm.btAllClick(Sender: TObject);
begin
edtBH.Text := '';
edtMC.Text := '';
cbYZ.ItemIndex := -1;
edtYZ.Text := '';
cbSFBS.ItemIndex := -1;
with FdmGDZC,
sqlGDZCCX do
begin
if cdGDZCCX.Active then cdGDZCCX.Close;
if Active then Close;
SQL.Text := GetSQL(True);
Open;
cdGDZCCX.Open;
end;
end;
end.