242 lines
5.8 KiB
ObjectPascal
242 lines
5.8 KiB
ObjectPascal
|
unit U_SelPrintField;
|
|||
|
|
|||
|
interface
|
|||
|
|
|||
|
uses
|
|||
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|||
|
Dialogs, StdCtrls, ExtCtrls, Grids, DBGrids, RM_FormReport, RM_PDBGrid,
|
|||
|
DB,IniFiles, RM_Common, RM_Class, RM_e_Xls, DBClient;
|
|||
|
|
|||
|
type
|
|||
|
TfrmSelPrintField = class(TForm)
|
|||
|
RMPrintDBGrid1: TRMPrintDBGrid;
|
|||
|
Button1: TButton;
|
|||
|
Button2: TButton;
|
|||
|
PrintDataSource: TDataSource;
|
|||
|
PrnGrid: TDBGrid;
|
|||
|
RMXLSExport1: TRMXLSExport;
|
|||
|
ClientDataSet1: TClientDataSet;
|
|||
|
ScrollBox1: TScrollBox;
|
|||
|
Label4: TLabel;
|
|||
|
procedure Button1Click(Sender: TObject);
|
|||
|
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
|||
|
procedure FormDestroy(Sender: TObject);
|
|||
|
procedure FormShow(Sender: TObject);
|
|||
|
procedure Button2Click(Sender: TObject);
|
|||
|
private
|
|||
|
procedure CreateCheckBox();
|
|||
|
procedure PrintData();
|
|||
|
procedure ReadINIFile(fieldname:string);
|
|||
|
procedure WriteINIFile(fieldname:string);
|
|||
|
Function IsINIFile(fieldname:string):Boolean;
|
|||
|
procedure GetPrintFields();
|
|||
|
procedure IsCheck();
|
|||
|
{ Private declarations }
|
|||
|
public
|
|||
|
PrintFields,IniName:string;
|
|||
|
|
|||
|
{ Public declarations }
|
|||
|
end;
|
|||
|
|
|||
|
var
|
|||
|
frmSelPrintField: TfrmSelPrintField;
|
|||
|
|
|||
|
implementation
|
|||
|
|
|||
|
{$R *.dfm}
|
|||
|
procedure TfrmSelPrintField.CreateCheckBox();
|
|||
|
var
|
|||
|
i,j,FTop,FLeft,Fdiv,FMod:Integer;// mod <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>div<69><76>
|
|||
|
FCheckBox:TCheckBox;
|
|||
|
begin
|
|||
|
for i:=0 to PrnGrid.Columns.Count-1 do
|
|||
|
begin
|
|||
|
Fdiv:=(i+1) div 3;
|
|||
|
FMod:=(i+1) mod 3;
|
|||
|
FCheckBox:=TCheckBox.Create(Self);
|
|||
|
FCheckBox.Caption:=Trim(PrnGrid.Columns[i].Title.Caption);
|
|||
|
FCheckBox.TabOrder:=i;
|
|||
|
FCheckBox.Parent:=ScrollBox1;
|
|||
|
FCheckBox.Checked:=True;
|
|||
|
if FMod>0 then
|
|||
|
FCheckBox.Top:=36*(Fdiv+1)
|
|||
|
else
|
|||
|
FCheckBox.Top:=36*Fdiv;
|
|||
|
if FMod=1 then
|
|||
|
FCheckBox.Left:=29
|
|||
|
else if FMod=2 then
|
|||
|
FCheckBox.Left:=163
|
|||
|
else if FMod=0 then
|
|||
|
FCheckBox.Left:=305;
|
|||
|
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmSelPrintField.Button1Click(Sender: TObject);
|
|||
|
begin
|
|||
|
//ShowMessage('10<31><30><EFBFBD><EFBFBD>3ȡ<33><C8A1>'+inttostr(10 mod 3)+',ȡ<><C8A1>'+inttostr(10 div 3));
|
|||
|
PrintData();
|
|||
|
GetPrintFields();
|
|||
|
if IsINIFile(IniName)=True then
|
|||
|
begin
|
|||
|
DeleteFile(IniName);
|
|||
|
end;
|
|||
|
WriteINIFile(IniName);
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmSelPrintField.FormClose(Sender: TObject;
|
|||
|
var Action: TCloseAction);
|
|||
|
begin
|
|||
|
Action:=caFree;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmSelPrintField.FormDestroy(Sender: TObject);
|
|||
|
begin
|
|||
|
frmSelPrintField:=nil;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmSelPrintField.FormShow(Sender: TObject);
|
|||
|
begin
|
|||
|
CreateCheckBox();
|
|||
|
ReadINIFile(IniName);
|
|||
|
IsCheck();
|
|||
|
end;
|
|||
|
procedure TfrmSelPrintField.IsCheck();
|
|||
|
var
|
|||
|
i:Integer;
|
|||
|
fsj:string;
|
|||
|
begin
|
|||
|
with ScrollBox1 do
|
|||
|
begin
|
|||
|
for i:=0 to ScrollBox1.ControlCount-1 do
|
|||
|
begin
|
|||
|
if Controls[i] is TCheckBox then
|
|||
|
begin
|
|||
|
fsj:=Trim(TCheckBox(Controls[i]).Caption);
|
|||
|
if Pos(fsj,PrintFields)>0 then
|
|||
|
TCheckBox(Controls[i]).Checked:=True
|
|||
|
else
|
|||
|
TCheckBox(Controls[i]).Checked:=False;
|
|||
|
end;
|
|||
|
end;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmSelPrintField.PrintData();
|
|||
|
var
|
|||
|
i,j,k:Integer;
|
|||
|
FFieldName:string;
|
|||
|
begin
|
|||
|
j:=0;
|
|||
|
k:=0;
|
|||
|
with ScrollBox1 do
|
|||
|
begin
|
|||
|
for i:=0 to ScrollBox1.ControlCount-1 do
|
|||
|
begin
|
|||
|
if Controls[i] is TCheckBox then
|
|||
|
begin
|
|||
|
if TCheckBox(Controls[i]).Checked=True then
|
|||
|
begin
|
|||
|
j:=1;
|
|||
|
PrnGrid.Columns[TCheckBox(Controls[i]).TabOrder].Visible:=True;
|
|||
|
k:=k+1;
|
|||
|
if k=1 then
|
|||
|
begin
|
|||
|
FFieldName:=PrnGrid.Columns[TCheckBox(Controls[i]).TabOrder].FieldName;
|
|||
|
end;
|
|||
|
end else
|
|||
|
begin
|
|||
|
PrnGrid.Columns[TCheckBox(Controls[i]).TabOrder].Visible:=False;
|
|||
|
end;
|
|||
|
end;
|
|||
|
end;
|
|||
|
end;
|
|||
|
{ClientDataSet1.Last;
|
|||
|
if Trim(ClientDataSet1.FieldByName('flag').AsString)='Y' then
|
|||
|
begin
|
|||
|
ClientDataSet1.Edit;
|
|||
|
ClientDataSet1.FieldByName(FFieldName).Value:='<27>ϼ<EFBFBD>';
|
|||
|
ClientDataSet1.Post;
|
|||
|
end;}
|
|||
|
|
|||
|
if j=1 then
|
|||
|
begin
|
|||
|
RMPrintDBGrid1.ShowReport ;
|
|||
|
end
|
|||
|
else
|
|||
|
begin
|
|||
|
Application.MessageBox('û<>пɴ<D0BF>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>','<27><>ʾ',0);
|
|||
|
Exit;
|
|||
|
end;
|
|||
|
//Panel2.Visible:=False;
|
|||
|
//RMPrintDBGrid1.ShowReport;
|
|||
|
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmSelPrintField.Button2Click(Sender: TObject);
|
|||
|
begin
|
|||
|
Close;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmSelPrintField.ReadINIFile(fieldname:string);
|
|||
|
var
|
|||
|
programIni:Tinifile; //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
|||
|
FName:string;
|
|||
|
begin
|
|||
|
FName:=ExtractFilePath(Application.ExeName)+'FieldPrintSet\' +trim(fieldname)+'.INI';
|
|||
|
programIni:=Tinifile.create(FName);
|
|||
|
PrintFields:=programIni.ReadString('<27><>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>','<27><>ӡ<EFBFBD>ֶ<EFBFBD>','');
|
|||
|
programIni.Free;
|
|||
|
end;
|
|||
|
procedure TfrmSelPrintField.GetPrintFields();
|
|||
|
var
|
|||
|
i:Integer;
|
|||
|
begin
|
|||
|
PrintFields:='Begin';
|
|||
|
with ScrollBox1 do
|
|||
|
begin
|
|||
|
for i:=0 to ScrollBox1.ControlCount-1 do
|
|||
|
begin
|
|||
|
if Controls[i] is TCheckBox then
|
|||
|
begin
|
|||
|
if TCheckBox(Controls[i]).Checked then
|
|||
|
begin
|
|||
|
PrintFields:=PrintFields+'/'+TCheckBox(Controls[i]).Caption;
|
|||
|
end;
|
|||
|
end;
|
|||
|
end;
|
|||
|
end;
|
|||
|
end;
|
|||
|
//////////////////////////////////////////////////////////////////
|
|||
|
//д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>INI<4E>ļ<EFBFBD>
|
|||
|
//<2F><><EFBFBD><EFBFBD>
|
|||
|
//////////////////////////////////////////////////////////////////
|
|||
|
procedure TfrmSelPrintField.WriteINIFile(fieldname:string);
|
|||
|
var
|
|||
|
programIni:Tinifile; //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
|||
|
FName:string;
|
|||
|
begin
|
|||
|
|
|||
|
FName:=ExtractFilePath(Application.ExeName)+'FieldPrintSet\'+trim(fieldname)+'.INI';
|
|||
|
if not DirectoryExists(ExtractFileDir(FName)) then
|
|||
|
CreateDir(ExtractFileDir(FName));
|
|||
|
programIni:=Tinifile.create(FName);
|
|||
|
programIni.WriteString('<27><>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>','<27><>ӡ<EFBFBD>ֶ<EFBFBD>',PrintFields);
|
|||
|
programIni.Free;
|
|||
|
end;
|
|||
|
//////////////////////////////////////////////////////////////////
|
|||
|
//<2F>ж<EFBFBD>InI<6E>ļ<EFBFBD><C4BC>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
//////////////////////////////////////////////////////////////////
|
|||
|
Function TfrmSelPrintField.IsINIFile(fieldname:string):Boolean;
|
|||
|
var
|
|||
|
FName:string;
|
|||
|
begin
|
|||
|
FName:=ExtractFilePath(Application.ExeName)+'FieldPrintSet\'+trim(fieldname)+'.INI';
|
|||
|
if FileExists(FName) then
|
|||
|
Result:=True
|
|||
|
else
|
|||
|
Result:=false;
|
|||
|
end;
|
|||
|
|
|||
|
end.
|