279 lines
6.8 KiB
ObjectPascal
279 lines
6.8 KiB
ObjectPascal
|
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 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>div<69><76>
|
|||
|
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<31><30><EFBFBD><EFBFBD>3ȡ<33><C8A1>'+inttostr(10 mod 3)+',ȡ<><C8A1>'+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; //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
|||
|
FName:string;
|
|||
|
begin
|
|||
|
FName:=ExtractFilePath(Application.ExeName)+'FieldExportSet\' +trim(fieldname)+'.INI';
|
|||
|
programIni:=Tinifile.create(FName);
|
|||
|
ExportFields:=programIni.ReadString('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>','');
|
|||
|
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;
|
|||
|
//////////////////////////////////////////////////////////////////
|
|||
|
//д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>INI<4E>ļ<EFBFBD>
|
|||
|
//<2F><><EFBFBD><EFBFBD>
|
|||
|
//////////////////////////////////////////////////////////////////
|
|||
|
procedure TfrmSelExportField.WriteINIFile(fieldname:string);
|
|||
|
var
|
|||
|
programIni:Tinifile; //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
|||
|
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('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>',ExportFields);
|
|||
|
programIni.Free;
|
|||
|
end;
|
|||
|
//////////////////////////////////////////////////////////////////
|
|||
|
//<2F>ж<EFBFBD>InI<6E>ļ<EFBFBD><C4BC>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
//////////////////////////////////////////////////////////////////
|
|||
|
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.
|