📄 databack_nowuse.pas
字号:
end;
memo1.Lines.Add(filecontent);
//FromTime:=midstr(filecontent,10,(length(filecontent)-9));
//读出备份办事处
readln (myfilename,filecontent);
if leftstr(filecontent,6)<>'办事处' then
begin
showmessage('文件可能已经破坏');
memo1.Lines.Clear ;
edit1.Text :='';
closeFile(myFileName);
exit;
end;
memo1.Lines.Add(filecontent);
FromOffice:=midstr(filecontent,8,(length(filecontent)-7));
if (FromOffice<>unit_wxp.myOffice) and (unit_wxp.myOffice<>'总部') then
begin
showmessage('文件可能已经破坏');
memo1.Lines.Clear ;
edit1.Text :='';
closeFile(myFileName);
exit;
end;
//读出备份人
readln (myfilename,filecontent);
if leftstr(filecontent,6)<>'备份人' then
begin
showmessage('文件可能已经破坏');
memo1.Lines.Clear ;
edit1.Text :='';
closeFile(myFileName);
exit;
end;
memo1.Lines.Add(filecontent);
//FromUser:=midstr(filecontent,8,(length(filecontent)-7));
//备份表数
readln (myfilename,filecontent);
if leftstr(filecontent,8)<>'备份表数' then
begin
showmessage('文件可能已经破坏');
memo1.Lines.Clear ;
closeFile(myFileName);
exit;
end;
memo1.Lines.Add(filecontent);
//tablecount:= strtoint(midstr(filecontent,10,(length(filecontent)-9)));
//备份类型
readln (myfilename,filecontent);
if leftstr(filecontent,8)<>'备份类型' then
begin
showmessage('文件可能已经破坏');
memo1.Lines.Clear ;
closeFile(myFileName);
exit;
end;
memo1.Lines.Add(filecontent);
//backstyle:=rightstr(filecontent,2);
//备份内容
readln (myfilename,filecontent);
if leftstr(filecontent,8)<>'备份内容' then
begin
showmessage('文件可能已经破坏');
memo1.Lines.Clear ;
closeFile(myFileName);
exit;
end;
memo1.Lines.Add(filecontent);
//backtime:=midstr(filecontent,10,(length(filecontent)-9));
//AcceptTableName:=tstringlist.Create ;
while not eof(myFileName) do
begin
readln(myfilename,filecontent);
memo1.Lines.Add(filecontent);
TableName:=midstr(filecontent,6,(length(filecontent)-5));
if fileexists(filepath+'\'+TableName+'.db')=true then
//AcceptTableName.Add(TableName)
else
begin
showmessage('表"'+ TableName+'"不存在!');
continue;
end;
for i:=0 to stable.Count -1 do
begin
if TableName=stable.strings[i] then
begin
CkLBox1.ItemEnabled[i]:=true;
ckLBox1.Checked[i]:=true ;
end;
end;
end;
bitbtn2.Enabled :=true;
closeFile(myFileName);
end;
procedure Tform_cover.BitBtn1Click(Sender: TObject);
var
i,j,cnt1:integer;
tempSql,tempPath:string;
ifChoose:boolean;
myFileName:TextFile;
begin
for i:=0 to stable.count-1 do
begin
if cklbox1.Checked[i]=true then
begin
ifChoose:=true;
break;
end;
end;
if not ifchoose then
begin
showmessage('请选择要备份的表');
exit;
end;
{if edit1.Text='' then
showmessage('请选择上报路径');
exit;}
filepath:=edit1.Text +'\'+unit_wxp.myOffice +'备份_'+datetostr(today);
temppath:=filepath;
i:=1;
while directoryexists(temppath) do
begin
temppath:=filepath+'_'+inttostr(i);
i:=i+1;
end;
filepath:=temppath;
mkdir(filepath);
memo1.Lines.Add('创建目录:'+filepath);
if application.MessageBox(pchar('备份数据将花费较长的时间,确定要备份当前所有数据'),
pchar('注意'),MB_OKCANCEL)<>IDOK then
begin
removedir(filepath);
exit;
end;
showmessage(filepath+'\zxjx_backup.txt');
AssignFile(myFileName,filepath+'\zxjx_backup.txt');
rewrite(myFileName);
fromtime:=datetimetostr(now);
writeln(myFileName,'备份时间:'+fromtime);
memo1.lines.add('备份时间:'+fromtime);
writeln(myFileName,'办事处:'+unit_wxp.myoffice);
memo1.lines.add('办事处:'+unit_wxp.myoffice);
writeln(myFileName,'备份人:'+unit_wxp.username);
memo1.lines.add('备份人:'+unit_wxp.username);
cnt1:=0;
table3.Databasename:='zxjx';
//table2.DatabaseName :='zxjx';
//table2.DatabaseName :='zxjx';
batmove1.mode:=batcopy;
batmove1.Source:=table3;
batmove1.Destination:=table2;
AcceptTableName:=tstringlist.Create;
for i:=0 to stable.count-1 do
begin
if cklbox1.Checked[i]=true then
begin
//在备份以前修改每张表的备份时间
//MOdifyRecord(stable.Strings[i],i);
//备份数据
//if stable.Strings[i]='partleft' then
//AddBackUpFields(stable.Strings[i]);
memo1.lines.add('正在备份【'+stabledes.strings[i]+'】......');
{table1.Close ;
table1.SQL.Clear ;
table1.SQL.Add('select * from '+ stable.Strings[i]);
table1.Active :=true;}
table3.tablename:=stable.Strings[i];
table2.tablename:=filepath+'\' +stable.Strings[i]+'.db';
batmove1.Execute;
cnt1:=cnt1+1;
AcceptTableName.Add(stable.Strings[i]);
end;
end;
writeln(myFileName,'备份表数:'+inttostr(cnt1));
memo1.lines.add('备份表数:'+inttostr(cnt1));
writeln(myFileName,'备份类型:备份数据');
memo1.lines.add('备份类型:备份数据');
writeln(myFileName,'备份内容:所有数据');
memo1.lines.add('备份内容:所有数据');
//写入文件中
for i:=0 to AcceptTableName.Count -1 do
begin
writeln(myFileName,'表名:'+AcceptTableName.Strings[i]);
end;
if cnt1=0 then exit;
memo1.lines.add('数据库备份成功!共有'+inttostr(cnt1)+'个数据库表备份');
//label1.caption:='上次备份数据时间:'+datetimetostr(date());
closeFile(myFileName);
edit1.Text :='';
end;
procedure Tform_cover.ModifyRecord(tableName:string;i:integer);
var
tempSql:string;
begin
query1.Active :=false;
query1.SQL.Clear ;
tempSql:='update '+ tableName +' set 上报时间='''+fromtime+'''';
//showmessage(tempsql);
query1.SQL.Add(tempSql);
query1.ExecSQL ;
//query1.Active :=false;
//table1.SQL.Add('select * from '+ stable.Strings[i]+ getsql(i));
end;
procedure Tform_cover.BitBtn2Click(Sender: TObject);
var
i,cnt1,j:integer;
begin
if application.MessageBox(pchar('此次接收数据的备份时间为'+
fromtime+',恢复数据会删除原来所有的数据,确定要恢复数据嘛?'),
pchar('注意'),MB_OKCANCEL)<>IDOK then
exit;
memo1.Lines.Add('现在开始恢复数据');
cnt1:=0;
table2.Databasename:='zxjx';
batmove1.Mappings.Clear ;
batmove1.mode:=batappend;
batmove1.Source:=table3;
batmove1.Destination:=table2;
for i:=0 to stable.count-1 do
begin
if cklbox1.Checked[i]=true then
begin
//删除原来记录
//DeleteFormerRecord (stable.Strings[i],i);
memo1.lines.add('正在恢复【'+stabledes.strings[i]+'】......');
//table2.IndexFields
AddBackUpFields(stable.Strings[i]);
table2.tablename:=stable.Strings[i];
table3.tablename:=filepath+stable.Strings[i]+'.db';
batmove1.Execute;
cnt1:=cnt1+1;
//将接收记录保存进数据库
//WriteRecord(stable.Strings[i]);
end;
end;
//if cnt1=0 then exit;
memo1.lines.add('数据库恢复成功!共有'+inttostr(cnt1)+'个数据库表');
end;
procedure Tform_cover.AddBackUpFields (tablename:string);
var
i:integer;
begin
query1.Close ;
query1.SQL.Clear ;
query1.SQL.Add('truncate table '+tablename) ;
query1.ExecSQL ;
query1.Close ;
batmove1.Mappings.Clear ;
query1.SQL.Clear ;
query1.SQL.Add('select * from '+tablename);
query1.Active :=true;
for i:=0 to query1.FieldCount-1 do
begin
if query1.Fields[i].FieldName <>'序号' then
batmove1.Mappings.Add(query1.fields[i].fieldname
+'='+query1.fields[i].fieldname);
//showmessage(query1.fields[i].fieldname
//+'='+query1.fields[i].fieldname);
end;
query1.Active :=false;
end;
procedure Tform_cover.Button3Click(Sender: TObject);
var
myF:TextFile;
begin
if fileexists('G:\zxjx.txt') then
begin
AssignFile(myF,'G:\zxjx.txt');
Append(myF);
end
else
showmessage('fuck');
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -