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

310 lines
8.1 KiB
ObjectPascal
Raw Permalink 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; }
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ToolWin, StdCtrls, BtnEdit, cxStyles, cxCustomData,
cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit,DBGrids, DB, cxDBData,
cxGridLevel, cxClasses, cxControls, cxGridCustomView, ADODB,StrUtils,
Midas,cxGridCustomTableView, cxGridTableView, cxGridDBTableView,cxTimeEdit,
cxTreeView, cxGrid,cxDBLookupComboBox,cxCalendar, cxCurrencyEdit,cxExportGrid4Link,
ExtCtrls, Buttons,DBClient,FTComboBox,cxDropDownEdit,cxGridBandedTableView,
cxGridDBBandedTableView,cxRichEdit,cxButtonEdit,IniFiles,WinSock;
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();
procedure TcxGridToExcel(mfileName:string;gridName:TcxGrid);
{ Private declarations }
public
ExportFields,IniName:string;
{ Public declarations }
end;
var
frmSelExportField: TfrmSelExportField;
implementation
//uses U_SelPrintField,U_FormPas;
{$R *.dfm}
procedure TfrmSelExportField.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 ExpGrid.ColumnCount-1 do
begin
Fdiv:=(i+1) div 3;
FMod:=(i+1) mod 3;
FCheckBox:=TCheckBox.Create(Self);
FCheckBox.Caption:=Trim(ExpGrid.Columns[i].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 TfrmSelExportField.TcxGridToExcel(mfileName:string;gridName:TcxGrid);
var
saveDialog:TSaveDialog;
begin
try
saveDialog:=TSaveDialog.Create(nil);
saveDialog.Filter:='xls(*.xls)|*.xls|ȫ<><C8AB>(*.*)|*.*';
saveDialog.Options:=[ofOverwritePrompt];
saveDialog.FileName:=mfileName;
if saveDialog.Execute then
if Assigned(gridName) then
begin
try
ExportGrid4ToExcel(saveDialog.FileName,gridName);
except
application.MessageBox('<27><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7><>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ܴ<EFBFBD><DCB4>ڱ༭״̬!','<27><>ʾ<EFBFBD><CABE>Ϣ',0);
exit;
end;
application.MessageBox('<27>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>!','<27><>ʾ<EFBFBD><CABE>Ϣ',0);
end
else
application.MessageBox('<27><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>!','<27><>ʾ<EFBFBD><CABE>Ϣ',0);
finally
saveDialog.Free;
end;
end;
procedure TfrmSelExportField.Button1Click(Sender: TObject);
begin
//ShowMessage('10<31><30><EFBFBD><EFBFBD><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]).TabOrder].Visible:=True
end else
begin
ExpGrid.Columns[TCheckBox(Controls[i]).TabOrder].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.