RTFormwork/public10/ThreeFun/Form/U_SelPrintField.pas
“ddf” 61630656e9 1
2024-07-07 09:35:27 +08:00

242 lines
5.8 KiB
ObjectPascal
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 ÓàÊý£¬divÉÌ
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³ýÒÔ3È¡Óà'+inttostr(10 mod 3)+',È¡Õû'+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:='ºÏ¼Æ';
ClientDataSet1.Post;
end;}
if j=1 then
begin
RMPrintDBGrid1.ShowReport ;
end
else
begin
Application.MessageBox('ûÓпɴòÓ¡µÄÐÅÏ¢£¡','Ìáʾ',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; //ÅäÖÃÎļþÃû
FName:string;
begin
FName:=ExtractFilePath(Application.ExeName)+'FieldPrintSet\' +trim(fieldname)+'.INI';
programIni:=Tinifile.create(FName);
PrintFields:=programIni.ReadString('´òÓ¡ÉèÖÃ','´òÓ¡×Ö¶Î','');
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;
//////////////////////////////////////////////////////////////////
//дÉèÖÃÐÅÏ¢µ½INIÎļþ
//²ÎÊý
//////////////////////////////////////////////////////////////////
procedure TfrmSelPrintField.WriteINIFile(fieldname:string);
var
programIni:Tinifile; //ÅäÖÃÎļþÃû
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('´òÓ¡ÉèÖÃ','´òÓ¡×Ö¶Î',PrintFields);
programIni.Free;
end;
//////////////////////////////////////////////////////////////////
//ÅжÏInIÎļþÊÇ·ñ´æÔÚ
//////////////////////////////////////////////////////////////////
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.