function daocompactdb:boolean; //compactdatabase<br> var<br> srcfile,dstfile:widestring;<br> db:_DBEngine;<br> dtbs:database;<br> begin<br> srcfile:=extractfilepath(application.ExeName)+'agritax.mdb';<br> dstfile:=extractfilepath(application.ExeName)+'tempfile.mdb';<br><br> try<br> try<br> db:=coDBEngine.Create;<br> dtbs:=db.OpenDatabase(srcfile,true,false,';pwd=agriculture');<br> dtbs.NewPassword('agriculture','');<br> dtbs.Close;<br> dtmd.DataModule1.adocntion.Connected:=false;<br> db.CompactDatabase(srcfile,dstfile,emptyparam,emptyparam,'');<br> // db.CompactDatabase(srcfile,dstfile,emptyparam,emptyparam,'agriculture');<br> dtmd.DataModule1.adocntion.Connected:=false;<br><br> if not copyfile(pchar(dstfile),pchar(srcfile),false) then<br> begin<br> deletefile(dstfile);<br><br> result:=false;<br><br> exit;<br> end;<br><br> finally<br> dtbs:=db.OpenDatabase(srcfile,true,false,';pwd=');<br> dtbs.NewPassword('','agriculture');<br> dtbs.Close;<br> dtmd.DataModule1.adocntion.Connected:=true;<br> end;<br> //dtmd.DataModule1.adocntion.Connected:=true;<br> result:=true;<br> except // wrap up<br> dtmd.DataModule1.adocntion.Connected:=true;<br> result:=false;<br> dtmd.DataModule1.adocntion.Connected:=true;<br> end; // try/except<br> deletefile(dstfile);<br> dtmd.DataModule1.adocntion.Connected:=true;<br><br> end;<br> function daorepairdb:boolean; //repairdatabase<br> var<br> db:_DBEngine;<br> begin<br> db:=coDBEngine.Create;<br> try<br> db.RepairDatabase(extractfilepath(application.ExeName)+'agritax.mdb');<br> result:=true;<br> except<br><br> result:=false;<br> end;<br> end;<br><br>function getusername(userid :string):string;<br>begin<br> with DataModule1.adoqry do<br> begin<br> try<br> Active := False;<br> except<br> end;<br><br> SQL.Clear;<br> SQL.Add('select username from sysusers where userid='''+userid+'''');<br> Active := True;<br> if not (BOF and EOF) then<br> Result:=FieldByName('username').asstring<br> else<br> Result := '';<br><br> try<br> Active := False;<br> except<br> end;<br> end;<br>end;<br><br>