📄 dataexport.~pas
字号:
unit dataexport;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, basepop, ExtCtrls, StdCtrls, TFlatEditUnit, TFlatButtonUnit,
TFlatProgressBarUnit, TFlatComboBoxUnit, DB, DBTables, ActnList,
ComCtrls, jpeg, ztvregister, ztvBase, ztvZip;
const
cLicenseString = '17055475153342401579512r612895AS';
xvtError=0;
type
TDataExport_frm = class(Tbasepop_frm)
Panel1: TPanel;
Memo1: TMemo;
FB_next: TFlatButton;
FlatEdit1: TFlatEdit;
Label1: TLabel;
SaveDialog1: TSaveDialog;
ListBox1: TListBox;
FB_cancel: TFlatButton;
FlatButton3: TFlatButton;
Label2: TLabel;
FlatComboBox1: TFlatComboBox;
Label3: TLabel;
FlatEdit2: TFlatEdit;
Query1: TQuery;
BatchMove1: TBatchMove;
Table1: TTable;
Query2: TQuery;
Database1: TDatabase;
ActionList1: TActionList;
help: TAction;
FB_help: TFlatButton;
FB_previous: TFlatButton;
GroupBox3: TGroupBox;
Panel2: TPanel;
Image1: TImage;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
Memo3: TMemo;
TabSheet2: TTabSheet;
Label5: TLabel;
FlatComboBox2: TFlatComboBox;
FlatComboBox3: TFlatComboBox;
FlatComboBox4: TFlatComboBox;
Zip: TZip;
FlatComboBox5: TFlatComboBox;
procedure FB_nextClick(Sender: TObject);
procedure FlatButton3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FlatComboBox1Change(Sender: TObject);
procedure FB_previousClick(Sender: TObject);
procedure FB_cancelClick(Sender: TObject);
{ procedure FB_cancelClick(Sender: TObject);
procedure FlatButton3Click(Sender: TObject);
procedure helpExecute(Sender: TObject);
}
private
Sel_str:TStringList;
hZip : LongInt;
//CPSENO:integer;
procedure export_data(Query:TQuery;Sqlstr,filename:widestring;note:string);
procedure export_dataV1(FN,SqlStr:string;const Mothed: string);
//procedure DeleteAll;
public
{ Public declarations }
//procedure DelExpFile();
end;
{ function XceedZipInitDLL : LongInt; stdcall; external 'XceedZip.DLL';
function XceedZipShutdownDLL : LongInt; stdcall; external 'XceedZip.DLL';
function XzCreateXceedZipA( pszLicense : PChar) : LongInt; stdcall; external 'XceedZip.DLL';
procedure XzDestroyXceedZip( hZip : LongInt ); stdcall; external 'XceedZip.DLL';
procedure XzSetXceedZipWindow( hZip : LongInt; hWnd : LongInt ); stdcall; external 'XceedZip.DLL';
procedure XzSetZipFilenameA( hZip : LongInt; pszValue : PChar); stdcall; external 'XceedZip.DLL';
procedure XzSetFilesToProcessA( hZip : LongInt; pszValue : PChar ); stdcall; external 'XceedZip.DLL';
procedure XzSetProcessSubfolders( hZip : LongInt; bValue : LongInt ); stdcall; external 'XceedZip.DLL';
procedure XzSetEncryptionPasswordA(hZip:LongInt;pwd:PChar); stdcall; external 'XceedZip.DLL';
function XzZip( hZip : LongInt ) : LongInt; stdcall; external 'XceedZip.DLL';
function XzGetErrorDescriptionA( hZip : LongInt; xType : LongInt; xCode : LongInt; pszBuffer : PChar; uMaxLength : LongInt ) : LongInt; stdcall; external 'XceedZip.DLL';}
var
DataExport_frm: TDataExport_frm;
implementation
uses datashare, imp;
//uses datashare, main, commlist, basedialog,hh;
{$R *.dfm}
procedure TDataExport_frm.export_dataV1(FN,SqlStr:string;const Mothed: string);
var
FileName:Tfilename;
filehandle,i:integer;
ls_line:widestring; // dirstr,
txtfile:Textfile;
begin
//SetCurrentDirectory(d);
FileName:=getCurrentdir+'\exportfile\'+FN+'.txt';
filehandle:=FileCreate(FileName);
fileclose(filehandle);
assignfile(txtfile,FileName);
rewrite(txtfile);
try
with Query2 do
begin
close;
sql.Clear;
sql.Add(SqlStr);
prepare;
open;
while not eof do
begin
ls_line:='';
for i:=0 to FieldCount-1 do
begin
if i=FieldCount-1 then
ls_line:=ls_line+fields[i].AsString
else
ls_line:=ls_line+fields[i].AsString+chr(9);
end;
writeln(txtfile,ls_line);
next;
end;
memo1.Lines.Add('共导出'+inttostr(recordcount)+'条信息.')
end;
finally
closefile(txtfile);
end;
end;
procedure TDataexport_frm.export_data(Query:TQuery;Sqlstr,filename:widestring;note:string);
var
filehandle,i:integer;
Namewithdir,ls_line:widestring; // dirstr,
txt:Tstrings;
//txtfile:Textfile;
begin
NamewithDir:=extractfilepath(application.ExeName)+'Exportfile\'+filename+'.txt';
txt:=Tstringlist.Create ;
//filehandle:=Filecreate(namewithdir);
{if filehandle<0 then
begin
application.MessageBox('数据导出异常!','恩普软件',mb_iconerror+mb_ok);
exit;
end;}
{fileclose(filehandle);
assignfile(txtfile,namewithdir);}
try
with Query do
begin
close;
sql.Clear ;
sql.Add(Sqlstr);
prepare;
open;
{(ftUnknown, ftString, ftSmallint, ftInteger, ftWord, ftBoolean,
ftFloat, ftCurrency, ftBCD, ftDate, ftTime, ftDateTime,
ftBytes, ftVarBytes, ftAutoInc, ftBlob, ftMemo, ftGraphic,
ftFmtMemo, ftParadoxOle, ftDBaseOle, ftTypedBinary, ftCursor,
ftFixedChar, ftWideString, ftLargeint, ftADT, ftArray, ftReference,
ftDataSet, ftOraBlob, ftOraClob, ftVariant, ftInterface, ftIDispatch,
ftGuid, ftTimeStamp, ftFMTBcd);}
while not eof do
begin
if not Fields[0].IsNull then
begin
if fields[0].DataType=ftstring then ls_line:=Fields[0].AsString else
if (fields[0].Datatype=ftinteger) or (Fields[0].DataType=ftSmallint) then ls_line:=inttostr(Fields[0].AsInteger) else
if fields[0].DataType=ftfloat then ls_line:=floattostr(fields[0].AsFloat)else
if fields[0].DataType=ftDateTime then ls_line:=datetimetostr(fields[0].AsDateTime) else
if fields[0].DataType=ftTimeStamp then ls_line:=datetimetostr(fields[0].AsDateTime) else
ls_line:=fields[0].AsString ;
end else ls_line:='';
for i:=1 to Fieldcount-1 do
if not Fields[i].IsNull then
begin
//ls_line:=ls_line+chr(9)+Fields[i].AsString
if fields[i].DataType=ftstring then ls_line:=ls_line+chr(9)+Fields[i].AsString else
if (fields[i].Datatype=ftinteger) or (Fields[i].DataType=ftSmallint) then ls_line:=ls_line+chr(9)+inttostr(Fields[i].AsInteger) else
if fields[i].DataType=ftfloat then ls_line:=ls_line+chr(9)+floattostr(fields[i].AsFloat)else
if fields[i].DataType=ftDateTime then ls_line:=ls_line+chr(9)+datetimetostr(fields[i].AsDateTime) else
if fields[i].DataType=ftTimeStamp then ls_line:=ls_line+chr(9)+datetimetostr(fields[i].AsDateTime) else
ls_line:=ls_line+chr(9)+fields[i].AsString ;
end else ls_line:=ls_line+char(9);
txt.Add(ls_line);
next;
end;
memo1.Lines.Add('共导出'+inttostr(recordcount)+'条'+note+'信息.')
end;
except
txt.Free ;
application.MessageBox('导出异常!','恩普软件',mb_iconerror+mb_ok);
end;
if Query.RecordCount>0 then
begin
txt.SaveToFile(NamewithDir);
Flatcombobox4.Items.Add(NamewithDir);
end;
txt.Free ;
end;
procedure TDataExport_frm.FB_nextClick(Sender: TObject);
var
sqlstr,zipfiles:widestring;
loop:integer;
xzresult:longint;
begin
if flatcombobox1.ItemIndex<0 then
begin
application.MessageBox('请选择单位名称!','恩普软件',mb_iconinformation+mb_ok);
exit;
end;
if trim(flatedit1.Text)='' then
begin
application.MessageBox('没有命名导出文件!','恩普软件',mb_iconinformation+mb_ok);
exit;
end;
try
pagecontrol1.ActivePageIndex :=1;
cursor:=crhourglass;
DeleteAll(extractfilepath(application.ExeName)+'exportfile\');
//导出单位还要导出上一级单位
if trim(flatcombobox3.Items[Flatcombobox1.itemindex])<>trim(flatcombobox5.Items[Flatcombobox1.itemindex]) then
sqlstr:='select * from sbdb_cparch where cpseno='+flatcombobox3.Items[Flatcombobox1.itemindex]+ ' or cpseno='+flatcombobox5.Items[Flatcombobox1.itemindex]
else sqlstr:='select * from sbdb_cparch where cpseno='+flatcombobox3.Items[Flatcombobox1.itemindex];
export_data(DataShare_frm.Query1,sqlstr,'sbdb_cparch','单位');
sqlstr:='select * from sbdb_psarch where cpseno='+flatcombobox3.Items[Flatcombobox1.itemindex];
export_data(DataShare_frm.Query1,sqlstr,'sbdb_psarch','在职人员');
sqlstr:='select * from sbdb_rtarch where cpseno='+flatcombobox3.Items[Flatcombobox1.itemindex];
export_data(datashare_frm.Query1,sqlstr,'sbdb_rtarch','退休人员');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -