📄 cgthbb.pas
字号:
unit cgthbb;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Menus, ExtCtrls, ActnList, XPStyleActnCtrls,
ActnMan, ToolWin, ActnCtrls, ActnMenus, DB, RpDefine, RpBase, RpSystem,
ComCtrls, Grids, DBGrids,main;
type
Tf_cgthbb = class(TForm)
Label1: TLabel;
Panel2: TPanel;
dy: TBitBtn;
yl: TBitBtn;
BitBtn2: TBitBtn;
cx: TBitBtn;
Grid1: TDBGrid;
Panel1: TPanel;
Label2: TLabel;
Check1: TCheckBox;
zd: TComboBox;
zhi: TComboBox;
Check2: TCheckBox;
qssj: TDateTimePicker;
zzsj: TDateTimePicker;
Rprinter: TRvSystem;
DataSource1: TDataSource;
procedure zdChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure cxClick(Sender: TObject);
procedure RprinterPrint(Sender: TObject);
procedure dyClick(Sender: TObject);
procedure ylClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
RFont = Record //设置字体
RFontName: String;
RFontSize: Integer;
RFontColor: Integer;
RFontStyle: TFontStyles;
End;
RContent = ReCord //设置正文
TitleHeight: Real; //标题高度
BtHeight: Real;//表头与标题的间距
Bgjj: Real;//表格与表头的间距
Czyjj: real;//操作员与其标签的水平距离
sjjj: real;//时间与其标签的水平距离
Bgdqfs: integer;//表格内容的对齐方式 0居左,1居右,2居中
end;
var
f_cgthbb: Tf_cgthbb;
TempField: String ='';
Sumzdkd: real=0.0;// 字段总宽度
Rowzdkd: Real=0.0;//每行字段总宽度
zbj: real=0.0; //正文左边距
Content: RContent;
AZdmc: Array[0..8]of String=('采购票号','库存名称','商品代码','商品名称','基本单位','数量','折扣','金额','保质期');
AZdkd : Array[0..8]of Real=(1,1,1,1,1,1,1,1,1); //数组中的元素对应表格中相应字段的宽度
TitleFont,BtFont,BgtitleFont,BgFont: RFont;//读取或设置标题,表头,表格字体,表格标题字体
zds : integer = 9;//表格字段数
Cols: integer = 5;//每行列数
implementation
uses Datamodal,cgthdysz;
{$R *.dfm}
procedure Tf_cgthbb.zdChange(Sender: TObject);
begin
if Trim(zd.Text)<>'' then
begin
zhi.Clear;
Case zd.ItemIndex of
0: TempField := 'thph';
1: TempField := 'spdm';
2: TempField := 'spmc';
3: TempField := 'kcmc';
end;
if TempField<>'spmc' then
begin
with Data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select distinct '+ TempField + ' From t_cgthmx');
Open;
end;
end
else
begin
with Data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select distinct '+ TempField + ' From t_spjcxx');
Open;
end;
end;
while Not Data.Query1.Eof do
begin
zhi.Items.Add(Trim(Data.Query1.Fields[0].AsString));
Data.Query1.Next;
end;
end;
end;
procedure Tf_cgthbb.FormCreate(Sender: TObject);
var
i: Integer;
begin
qssj.DateTime := Now;
zzsj.DateTime := Now;
zds := 9;
cols := 5;
Sumzdkd := 0;
For i := 0 to zds-1 do
begin
Azdkd[i]:= 1;
sumzdkd := Sumzdkd+ Azdkd[i];
end;
Rowzdkd := Cols*(Sumzdkd/9);
with TitleFont do
begin
RFontName := '宋体';
RFontSize := 18;
RFontColor := clRed;
RFontStyle := [];
end;
with BtFont do
begin
RFontName := '宋体';
RFontSize := 10;
RFontColor := clBlue;
RFontStyle := [];
end;
with BgFont do
begin
RFontName := '宋体';
RFontSize := 10;
RFontColor := clBlue;
RFontStyle := [];
end;
with BgtitleFont do
begin
RFontName := '宋体';
RFontSize := 12;
RFontColor := clBlue;
RFontStyle := [fsBold];
end;
with Content do
begin
TitleHeight := 0.8;
BtHeight := 0.4;
Bgjj := 0.4;
Czyjj := 0.8;
sjjj := 0.8;
Bgdqfs := 0;//表格居左对齐
end;
end;
procedure Tf_cgthbb.cxClick(Sender: TObject);
begin
if check1.Checked = True then
begin
if (Trim(zd.Text)<>'')and(Trim(zhi.Text)<>'') then
begin
if check2.Checked = False then
begin
with Data.Query2 do
begin
Close;
SQL.Clear;
if TempField <>'spmc' then
SQL.Add('select aa.thph,aa.kcmc,aa.spdm,bb.spmc,aa.jbdw,aa.sl,aa.zk,aa.je,aa.bzq from t_cgthmx aa inner join t_spjcxx bb on aa.spdm = bb.spdm and aa.'+TempField + ' =:a')
else
SQL.Add('select aa.thph,aa.kcmc,aa.spdm,bb.spmc,aa.jbdw,aa.sl,aa.zk,aa.je,aa.bzq from t_cgthmx aa inner join t_spjcxx bb on aa.spdm = bb.spdm and bb.'+TempField + ' =:a');
ParamByName('a').AsString := Trim(zhi.Text);
Open;
end;
if Data.Query2.RecordCount>0 then
begin
DataSource1.DataSet := Data.Query2;
dy.Enabled := True;
end
else
begin
DataSource1.DataSet := Nil;
dy.Enabled := False;
Application.MessageBox('没有符合条件的记录.','提示',64);
end;
end
else
begin
if zzsj.DateTime<qssj.DateTime then
begin
Application.MessageBox('起始时间不能大于终止时间.','提示',64);
Exit;
end;
with Data.Query2 do
begin
Close;
SQL.Clear;
if TempField <>'spmc' then
SQL.Add('select a.thph,a.kcmc,a.spdm,b.spmc,a.jbdw,a.sl,a.zk,a.je,a.bzq from t_cgthmx a inner join t_spjcxx b on a.spdm = b.spdm and a.'+TempField + ' =:aa and a.thph in (select thph from t_cgthph where sj >=:bb and sj<:cc )')
else
SQL.Add('select a.thph,a.kcmc,a.spdm,b.spmc,a.jbdw,a.sl,a.zk,a.je,a.bzq from t_cgthmx a inner join t_spjcxx b on a.spdm = b.spdm and b.'+TempField + ' =:aa and a.thph in (select thph from t_cgthph where sj >=:bb and sj<:cc )');
ParamByName('aa').AsString := Trim(zhi.Text);
ParamByName('bb').AsDate := Trunc(qssj.DateTime)-2;
ParamByName('cc').AsDate := Trunc(zzsj.DateTime)-2+1;
Open;
end;
if Data.Query2.RecordCount>0 then
begin
DataSource1.DataSet := Data.Query2;
dy.Enabled := True;
end
else
begin
DataSource1.DataSet := Nil;
dy.Enabled := False;
Application.MessageBox('没有符合条件的记录.','提示',64);
end;
end;
end;
end
else if check2.Checked = True then
begin
if zzsj.DateTime<qssj.DateTime then
begin
Application.MessageBox('起始时间不能大于终止时间.','提示',64);
Exit;
end;
with Data.Query2 do
begin
Close;
SQL.Clear;
SQL.Add('select aa.thph,aa.kcmc,aa.spdm,bb.spmc,aa.jbdw,aa.sl,aa.zk,aa.je,aa.bzq from t_cgthmx aa inner join t_spjcxx bb on aa.thph in (select thph from t_cgthph where sj>= :b and sj<:c)');
ParamByName('b').AsDate := Trunc(qssj.DateTime)-2;
ParamByName('c').AsDate := Trunc(zzsj.DateTime)-2+1;
Open;
end;
if Data.Query2.RecordCount>0 then
begin
DataSource1.DataSet := Data.Query2;
dy.Enabled := True;
end
else
begin
DataSource1.DataSet := Nil;
dy.Enabled := False;
Application.MessageBox('没有符合条件的记录.','提示',64);
end;
end
else
Application.MessageBox('请设置查询条件.','提示',64);
end;
procedure Tf_cgthbb.RprinterPrint(Sender: TObject);
var
justify: TPrintJustify;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -