RTFormwork/public10/ThreeFun/Form/U_SelPrintFieldNew.pas

293 lines
7.0 KiB
ObjectPascal
Raw Permalink Normal View History

2024-07-07 09:35:27 +08:00
unit U_SelPrintFieldNew;
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
TfrmSelPrintFieldNew = class(TForm)
RMPrintDBGrid1: TRMPrintDBGrid;
Button1: TButton;
Button2: TButton;
PrintDataSource: TDataSource;
PrnGrid: TDBGrid;
RMXLSExport1: TRMXLSExport;
ClientDataSet1: TClientDataSet;
Panel2: TScrollBox;
Label4: TLabel;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox2Click(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
frmSelPrintFieldNew: TfrmSelPrintFieldNew;
implementation
{$R *.dfm}
procedure TfrmSelPrintFieldNew.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:=Panel2;
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 TfrmSelPrintFieldNew.Button1Click(Sender: TObject);
begin
//ShowMessage('10<31><30><EFBFBD><EFBFBD><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 TfrmSelPrintFieldNew.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action:=caFree;
end;
procedure TfrmSelPrintFieldNew.FormDestroy(Sender: TObject);
begin
frmSelPrintFieldNew:=nil;
end;
procedure TfrmSelPrintFieldNew.FormShow(Sender: TObject);
begin
CreateCheckBox();
ReadINIFile(IniName);
IsCheck();
end;
procedure TfrmSelPrintFieldNew.IsCheck();
var
i:Integer;
fsj:string;
begin
with Panel2 do
begin
for i:=0 to Panel2.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 TfrmSelPrintFieldNew.PrintData();
var
i,j,k:Integer;
FFieldName:string;
begin
j:=0;
k:=0;
with Panel2 do
begin
for i:=0 to Panel2.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 TfrmSelPrintFieldNew.Button2Click(Sender: TObject);
begin
Close;
end;
procedure TfrmSelPrintFieldNew.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 TfrmSelPrintFieldNew.GetPrintFields();
var
i:Integer;
begin
PrintFields:='Begin';
with Panel2 do
begin
for i:=0 to Panel2.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 TfrmSelPrintFieldNew.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 TfrmSelPrintFieldNew.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;
procedure TfrmSelPrintFieldNew.CheckBox1Click(Sender: TObject);
var
i:Integer;
begin
if CheckBox1.Checked then
begin
CheckBox2.Checked:=False;
with Panel2 do
begin
for i:=0 to Panel2.ControlCount-1 do
begin
if Controls[i] is TCheckBox then
begin
if (TCheckBox(Controls[i]).Name<>'CheckBox1') and (TCheckBox(Controls[i]).Name<>'CheckBox2') then
begin
TCheckBox(Controls[i]).Checked:=True;
end;
end;
end;
end;
end;
end;
procedure TfrmSelPrintFieldNew.CheckBox2Click(Sender: TObject);
var
i:Integer;
begin
if CheckBox2.Checked then
begin
CheckBox1.Checked:=False;
with Panel2 do
begin
for i:=0 to Panel2.ControlCount-1 do
begin
if Controls[i] is TCheckBox then
begin
if (TCheckBox(Controls[i]).Name<>'CheckBox1') and (TCheckBox(Controls[i]).Name<>'CheckBox2') then
begin
TCheckBox(Controls[i]).Checked:=False;
end;
end;
end;
end;
end;
end;
end.