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

279 lines
6.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_SelExportField;
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, cxStyles, cxCustomData,
cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData,
cxGridLevel, cxClasses, cxControls, cxGridCustomView,
cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid,
cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore, dxSkinsDefaultPainters,
cxNavigator, dxDateRanges;
type
TfrmSelExportField = class(TForm)
Button1: TButton;
Button2: TButton;
ExportDataSource: TDataSource;
ExpGrid: TcxGridDBTableView;
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
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 ExportData();
procedure ReadINIFile(fieldname:string);
procedure WriteINIFile(fieldname:string);
Function IsINIFile(fieldname:string):Boolean;
procedure GetExportFields();
procedure IsCheck();
{ Private declarations }
public
ExportFields,IniName:string;
{ Public declarations }
end;
var
frmSelExportField: TfrmSelExportField;
implementation
uses U_Fun;
{$R *.dfm}
procedure TfrmSelExportField.CreateCheckBox();
var
i,j,FTop,FLeft,Fdiv,FMod,z:Integer;// mod ÓàÊý£¬divÉÌ
FCheckBox:TCheckBox;
begin
z:=0;
for i:=0 to ExpGrid.ColumnCount-1 do
begin
if ExpGrid.Columns[i].Visible=True then
begin
Fdiv:=(z+1) div 3;
FMod:=(z+1) mod 3;
FCheckBox:=TCheckBox.Create(Self);
FCheckBox.Caption:=Trim(ExpGrid.Columns[i].Caption);
FCheckBox.Tag:=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;
z:=z+1;
end;
end;
end;
procedure TfrmSelExportField.Button1Click(Sender: TObject);
begin
//ShowMessage('10³ýÒÔ3È¡Óà'+inttostr(10 mod 3)+',È¡Õû'+inttostr(10 div 3));
ExportData();
GetExportFields();
if IsINIFile(IniName)=True then
begin
DeleteFile(IniName);
end;
WriteINIFile(IniName);
end;
procedure TfrmSelExportField.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action:=caFree;
end;
procedure TfrmSelExportField.FormDestroy(Sender: TObject);
begin
frmSelExportField:=nil;
end;
procedure TfrmSelExportField.FormShow(Sender: TObject);
begin
CreateCheckBox();
ReadINIFile(IniName);
IsCheck();
end;
procedure TfrmSelExportField.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,ExportFields)>0 then
TCheckBox(Controls[i]).Checked:=True
else
TCheckBox(Controls[i]).Checked:=False;
end;
end;
end;
end;
procedure TfrmSelExportField.ExportData();
var
i,j:Integer;
begin
j:=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;
ExpGrid.Columns[TCheckBox(Controls[i]).Tag].Visible:=True
end else
begin
ExpGrid.Columns[TCheckBox(Controls[i]).Tag].Visible:=False;
end;
end;
end;
end;
TcxGridToExcel(Trim(IniName),cxGrid1);
end;
procedure TfrmSelExportField.Button2Click(Sender: TObject);
begin
Close;
end;
procedure TfrmSelExportField.ReadINIFile(fieldname:string);
var
programIni:Tinifile; //ÅäÖÃÎļþÃû
FName:string;
begin
FName:=ExtractFilePath(Application.ExeName)+'FieldExportSet\' +trim(fieldname)+'.INI';
programIni:=Tinifile.create(FName);
ExportFields:=programIni.ReadString('µ¼³öÉèÖÃ','µ¼³ö×Ö¶Î','');
programIni.Free;
end;
procedure TfrmSelExportField.GetExportFields();
var
i:Integer;
begin
ExportFields:='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
ExportFields:=ExportFields+'/'+TCheckBox(Controls[i]).Caption;
end;
end;
end;
end;
end;
//////////////////////////////////////////////////////////////////
//дÉèÖÃÐÅÏ¢µ½INIÎļþ
//²ÎÊý
//////////////////////////////////////////////////////////////////
procedure TfrmSelExportField.WriteINIFile(fieldname:string);
var
programIni:Tinifile; //ÅäÖÃÎļþÃû
FName:string;
begin
FName:=ExtractFilePath(Application.ExeName)+'FieldExportSet\'+trim(fieldname)+'.INI';
if not DirectoryExists(ExtractFileDir(FName)) then
CreateDir(ExtractFileDir(FName));
programIni:=Tinifile.create(FName);
programIni.WriteString('µ¼³öÉèÖÃ','µ¼³ö×Ö¶Î',ExportFields);
programIni.Free;
end;
//////////////////////////////////////////////////////////////////
//ÅжÏInIÎļþÊÇ·ñ´æÔÚ
//////////////////////////////////////////////////////////////////
Function TfrmSelExportField.IsINIFile(fieldname:string):Boolean;
var
FName:string;
begin
FName:=ExtractFilePath(Application.ExeName)+'FieldExportSet\'+trim(fieldname)+'.INI';
if FileExists(FName) then
Result:=True
else
Result:=false;
end;
procedure TfrmSelExportField.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 TfrmSelExportField.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.