📄 udataquery.pas
字号:
unit uDataQuery;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
cxDataStorage, cxEdit, DB, cxDBData, cxButtonEdit, cxCalc,
cxCurrencyEdit, cxGridLevel, cxGridCustomTableView, cxGridTableView,
cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid,
cxDropDownEdit, cxTextEdit, cxContainer, cxMaskEdit, ExtCtrls, jpeg,
StdCtrls, Buttons, dbClient;
type
TfrmDataQuery = class(TForm)
Shape1: TShape;
Label6: TLabel;
Image1: TImage;
Panel1: TPanel;
Bevel1: TBevel;
Label1: TLabel;
cxComboBox1: TcxComboBox;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
cxComboBox2: TcxComboBox;
cxTextEdit1: TcxTextEdit;
cxComboBox3: TcxComboBox;
cxCalcEdit1: TcxCalcEdit;
Panel2: TPanel;
cxGrid4: TcxGrid;
GridStock: TcxGridDBTableView;
colCode: TcxGridDBColumn;
colName: TcxGridDBColumn;
colHD: TcxGridDBColumn;
colKD: TcxGridDBColumn;
colColor: TcxGridDBColumn;
colDw: TcxGridDBColumn;
colSL: TcxGridDBColumn;
colZl: TcxGridDBColumn;
colNil: TcxGridDBColumn;
cxGrid4Level1: TcxGridLevel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
GridGoods: TcxGridDBTableView;
GridHGoods: TcxGridDBTableView;
colKey: TcxGridDBColumn;
colNameG: TcxGridDBColumn;
colTxm: TcxGridDBColumn;
colColorG: TcxGridDBColumn;
colDWG: TcxGridDBColumn;
colCodeH: TcxGridDBColumn;
colNameH: TcxGridDBColumn;
colColorH: TcxGridDBColumn;
colMS: TcxGridDBColumn;
colDwH: TcxGridDBColumn;
colSLH: TcxGridDBColumn;
colNilH: TcxGridDBColumn;
colSlG: TcxGridDBColumn;
colNilG: TcxGridDBColumn;
colDjG: TcxGridDBColumn;
Label5: TLabel;
cxComboBox4: TcxComboBox;
SpeedButton4: TSpeedButton;
Label7: TLabel;
Label8: TLabel;
procedure SpeedButton2Click(Sender: TObject);
procedure cxComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure cxTextEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure cxComboBox3KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure cxComboBox2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure cxCalcEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure cxComboBox1Exit(Sender: TObject);
procedure cxComboBox4KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
private
cdTem : TclientDataSet;
dsTem : TdataSource;
procedure init();
procedure gridShow(dbName: string);
function GetData(dbName: string):oleVariant;
{ Private declarations }
public
{ Public declarations }
end;
var
frmDataQuery: TfrmDataQuery;
implementation
uses
uGlobal, uGetData, uPublic;
{$R *.dfm}
procedure TfrmDataQuery.SpeedButton2Click(Sender: TObject);
begin
cxComboBox1.Text := '';
cxTextEdit1.Text := '';
cxComboBox3.Text := '';
cxCalcEdit1.Text := '';
cxComboBox1.SetFocus;
end;
procedure TfrmDataQuery.cxComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
vk_return : if not cxComboBox1.DroppedDown then
cxTextEdit1.SetFocus;
end;
end;
procedure TfrmDataQuery.cxTextEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
vk_return : cxComboBox2.SetFocus;
end;
end;
procedure TfrmDataQuery.cxComboBox3KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
vk_return : If cxComboBox4.CanFocus then
cxComboBox4.SetFocus
Else
cxComboBox1.SetFocus;
end;
end;
procedure TfrmDataQuery.cxComboBox2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
vk_return : if not cxComboBox2.DroppedDown then
cxCalcEdit1.SetFocus;
end;
end;
procedure TfrmDataQuery.cxCalcEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
vk_return : IF cxComboBox3.CanFocus Then
cxComboBox3.SetFocus
ELSE
cxComboBox1.SetFocus;
end;
end;
procedure TfrmDataQuery.gridShow(dbName: string);
begin
label5.Visible := false;
cxComboBox4.Visible := false;
label3.Visible := true;
cxComboBox3.Visible := true;
IF DBName = '原材料' THEN
cxGrid4Level1.GridView := GridStock;
IF DBName = '半成品' THEN Begin
label5.Visible := true;
cxComboBox4.Visible := true;
cxGrid4Level1.GridView := GridHGoods;
end;
IF DBName = '成品' THEN Begin
cxGrid4Level1.GridView := GridGoods;
label3.Visible := false;
cxComboBox3.Visible := false;
end;
end;
procedure TfrmDataQuery.cxComboBox1Exit(Sender: TObject);
begin
gridShow(cxComboBox1.Text);
end;
procedure TfrmDataQuery.cxComboBox4KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
vk_return : if not cxComboBox4.DroppedDown then
cxComboBox1.SetFocus;
end;
end;
function TfrmDataQuery.GetData(dbName: string): oleVariant;
var TbName,SqlText,FName: string;
begin
IF cxComboBox1.Text = '' Then Begin
InfoWnd('提示:请选择产品类别!');
abort;
end;
FName := 'cCode';
GridStock.DataController.DataSource := nil;
GridHGoods.DataController.DataSource := nil;
GridGoods.DataController.DataSource := nil;
IF DBName = '原材料' THEN Begin
TbName := 'T_Stock';
GridStock.DataController.DataSource := dsTem;
end;
IF DBName = '半成品' THEN BEGIN
TbName := 'T_HGoods';
GridHGoods.DataController.DataSource := dsTem;
END;
IF DBName = '成品' THEN BEGIN
TbName := 'T_Goods';
FName := 'IKey';
GridGoods.DataController.DataSource := dsTem;
END;
sqlText := '';
IF cxTextEdit1.Text <> '' then
sqlText := 'WHERE (' + FName + ' Like '''+cxTextEdit1.Text+'%'')';
IF (cxComboBox3.Visible) AND (cxComboBox3.Text <> '') then
IF SqlText = '' then
sqlText := 'WHERE (CCOLOR = '''+cxComboBox3.Text+''')'
Else
sqlText := sqlText + ' AND (CCOLOR = '''+cxComboBox3.Text+''')';
IF cxCalcEdit1.Text <> '' then
IF SqlText = '' then
sqlText := 'WHERE (FSL ' + cxComboBox2.Text + ''''+cxCalcEdit1.Text+''')'
Else
sqlText := sqlText + ' AND (FSL ' + cxComboBox2.Text + ''''+cxCalcEdit1.Text+''')';
IF (cxComboBox4.Visible) AND (cxComboBox4.Text <> '') then
IF SqlText = '' then
sqlText := 'WHERE (cMs = '''+cxComboBox4.Text+''')'
ELSE
sqlText := sqlText + ' AND (cMs = '''+cxComboBox4.Text+''')';
with frmMain.cdPub do begin
close;
commandText := 'Select * from ' + TbName + #13+ SqlText + #13+
'ORDER BY ' + FName;
open;
Result := Data;
end;
end;
procedure TfrmDataQuery.init;
begin
cdTem := TclientDataSet.Create(self);
dsTem := TdataSource.Create(self);
dsTem.DataSet := cdTem;
end;
procedure TfrmDataQuery.FormCreate(Sender: TObject);
begin
init();
end;
procedure TfrmDataQuery.SpeedButton1Click(Sender: TObject);
begin
cdTem.Data := GetData(cxComboBox1.text);
end;
procedure TfrmDataQuery.SpeedButton4Click(Sender: TObject);
begin
close;
end;
procedure TfrmDataQuery.SpeedButton3Click(Sender: TObject);
var iObject: integer;
begin
iObject := -1;
if cxGrid4Level1.GridView = GridStock then
iObject := 21;
if cxGrid4Level1.GridView = GridHGoods then
iObject := 31;
if cxGrid4Level1.GridView = GridGoods then
iObject := 41;
frmReport.ReportS(iObject, 0,'',cdTem.Data);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -