我也给你一份,不过我看了一下,你好象只有200分了,假如,有两个人发了,你怎么给,
废话少说,access的,
unit UMyTest;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls,ADOX_TLB, DBTables, Buttons, ComCtrls,
ExtCtrls;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOConnection2: TADOConnection;
ADODataSet1: TADODataSet;
ADODataSet2: TADODataSet;
Button3: TButton;
Label1: TLabel;
OpenDialog1: TOpenDialog;
OpenDialog2: TOpenDialog;
Button1: TButton;
Button2: TButton;
ProgressBar1: TProgressBar;
StatusBar1: TStatusBar;
Label4: TLabel;
Edit2: TEdit;
Bevel1: TBevel;
SaveDialog1: TSaveDialog;
Button4: TButton;
Edit1: TEdit;
Label2: TLabel;
Edit3: TEdit;
Procedure GetTableData(TableName : Table ; ExamTableName : Table) ;
Procedure GetData(TableName : Table ;ExamTableName : Table) ;
procedure FormDestroy(Sender: TObject);
function GetADOXFieldType(aType: DataTypeEnum): string ;
procedure Button3Click(Sender: TObject);
procedure GetAdoField(TableName : Table ;ExamTableName : Table ) ;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure GetTable ;
procedure GetTableStructuer ;
// Procedure ChangeName ;
private
adoxTable : Table ;
adoxTables : Tables ;
adoxColumns : Columns ;
adoxColumn : Column ;
adoxCatalog : Catalog ;
adoxTable1 : Table ;
adoxTables1 : Tables ;
adoxColumns1 : Columns ;
adoxColumn1 : Column ;
adoxCatalog1 : Catalog ;
Procedure GetAllData ;
Procedure GetSysTableData(TableName : Table ; ExamTableName : Table) ;
{ Private declarations }
public
strName : string ;
str : string ;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.GetTableData(TableName : Table ; ExamTableName : Table) ;
var
adoxpros : Properties ;
adoxpro : Property_ ;
i,ipro : integer ;
begin
strName := '' ;
if ADODataSet1.Active then
ADODataSet1.Active := False ;
with ADODataSet1 do
begin
CommandType := cmdText ;
CommandText := 'select * from '+ TableName.Name ;
open ;
end ;
adoxcolumns := TableName.Columns ; //原数据
adoxcolumns1 := ExamTableName.Columns ; //目标数据
For i := 0 to adoxColumns1.Count -1 do
begin
adoxColumn1 := adoxColumns1.Item
;
adoxpros := adoxColumn1.Properties ;
For ipro := 0 to adoxpros.Count -1 do
begin
adoxpro := adoxpros.Item[ipro] ;
if adoxpro.Value = true then
begin
strName := adoxColumn1.Name ;
break ;
end
else
break ;
end ;
if strname <>'' then
break ;
end ;
if ADODataSet2.Active then
ADODataSet2.Active := False ;
with ADODataSet2 do
begin
CommandType := cmdText ;
CommandText := ' select * from '+ ExamTableName.Name ;
Open ;
end ;
if strName <> '' then
begin
if ADODataSet1.Active then
ADODataSet1.Active := False ;
with ADODataSet1 do
begin
CommandType := cmdText ;
CommandText := 'select * from ' +TableName.Name + #32+ 'order by'+ #32 + strName ;
open ;
end ;
if ADODataSet2.Active then
ADODataSet2.Active := False ;
with ADODataSet2 do
begin
CommandType := cmdText ;
CommandText := 'select * from ' +ExamTableName.Name + #32+ 'order by'+ #32 + strName ;
open ;
end ;
end ;
end;
// 取到数据
procedure TForm1.GetData(TableName : Table ;ExamTableName : Table);
begin
//
str := '' ;
ADODataSet1.First ;
while not ADODataSet1.Eof do
begin
GetAdoField(TableName,ExamTableName);
//
if strName <> '' then
if ADODataSet1.FieldValues[strName]< ADODataSet2.FieldValues[strName] then
begin
if MessageDlg('数据模板的数据错误,重新下载新的模板',mtInformation, [mbok], 0) = mrok then
begin
str := 'MyData' ;
break ;
end ;
end ;
//
if strName <> '' then
{ if ADODataSet2.Locate(strName,ADODataSet1.FieldValues[strName],[]) = False then
begin
ADODataSet2.Delete ;
GetAdoField(TableName,ExamTableName);
end ; }
while ADODataSet1.FieldValues[strName]<>ADODataSet2.FieldValues[strName] do
begin
ADODataSet2.Delete ;
GetAdoField(TableName,ExamTableName);
end ;
application.ProcessMessages ;
ADODataSet1.Next ;
end ;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
adoxCatalog := nil ;
adoxCatalog1 := nil;
end;
function TForm1.GetADOXFieldType(aType: DataTypeEnum): string;
begin
case aType of
adEmpty : Result := 'adEmpty' ;
adTinyInt : Result := 'adTinyInt' ;
adSmallInt : Result := 'adSmallInt' ;
adInteger: Result := 'adInteger';
adBigInt: Result := 'adBigInt';
adUnsignedTinyInt: Result := 'adUnsignedTinyInt';
adUnsignedSmallInt: Result := 'adUnsignedSmallInt';
adUnsignedInt: Result := 'adUnsignedInt';
adUnsignedBigInt: Result := 'adUnsignedBigInt';
adSingle: Result := 'adSingle';
adDouble: Result := 'adDouble';
adCurrency: Result := 'adCurrency';
adDecimal: Result := 'adDecimal';
adNumeric: Result := 'adNumeric';
adBoolean: Result := 'adBoolean';
adError: Result := 'adError';
adUserDefined: Result := 'adUserDefined';
adVariant: Result := 'adVariant';
adIDispatch: Result := 'adIDispatch';
adIUnknown: Result := 'adIUnknown';
adGUID: Result := 'adGUID';
adDate: Result := 'adDate';
adDBDate: Result := 'adDBDate';
adDBTime: Result := 'adDBTime';
adDBTimeStamp: Result := 'adDBTimeStamp';
adBSTR: Result := 'adBSTR';
adChar: Result := 'adChar';
adVarChar: Result := 'adVarChar';
adLongVarChar: Result := 'adLongVarChar';
adWChar: Result := 'adWChar';
adVarWChar: Result := 'adVarWChar';
adLongVarWChar: Result := 'adLongVarWChar';
adBinary: Result := 'adBinary';
adVarBinary: Result := 'adVarBinary';
adLongVarBinary: Result := 'adLongVarBinary';
adChapter: Result := 'adChapter';
adFileTime: Result := 'adFileTime';
adPropVariant: Result := 'adPropVariant';
adVarNumeric: Result := 'adVarNumeric';
end ;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
GetAllData ;
end;
procedure TForm1.GetAdoField(TableName, ExamTableName: Table);
var
i : Integer ;
iColumn : integer ;
begin
adoxcolumns := TableName.Columns ; //原数据
adoxcolumns1 := ExamTableName.Columns ; //目标数据
//数据的插入
ADODataSet2.Insert;
//根据表取得字段
For i := 0 to adoxColumns1.Count -1 do
begin
for icolumn := 0 to adoxColumns.Count -1 do
begin
adoxColumn1 := adoxColumns1.Item ;
adoxColumn := adoxColumns.Item[icolumn] ;
// 如果字段相同
if adoxColumn.Name = adoxColumn1.Name then
begin
//
if strName <> adoxColumn.Name then
begin
//插入
ADODataSet2.FieldValues[adoxColumn.Name] := ADODataSet1.FieldValues[adoxColumn.Name] ;
end ;
break ;
end ;
end ;
end ;
ADODataSet2.Post ;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Dsnstr : String ;
begin
Edit3.Text := '' ;
if ADOConnection1.Connected then
ADOConnection1.Connected := False ;
if OpenDialog1.Execute then
begin
Dsnstr := 'Password=wearewinners;User ID=wisenter;'
+ ' Data Source='+ OpenDialog1.FileName +';'
+ ' Mode=Share Deny None;Extended Properties=""; '
+ ' Jet OLEDB:System database=system.mdw;'
+ ' Jet OLEDB:Registry Path="";'
+ ' Jet OLEDBatabase Password="";'
+ ' Jet OLEDB:Engine Type=5;'
+ ' Jet OLEDBatabase Locking Mode=1;'
+ ' Jet OLEDB:Global Partial Bulk Ops=2;'
+ ' Jet OLEDB:Global Bulk Transactions=1;'
+ ' Jet OLEDB:New Database Password="";'
+ ' Jet OLEDB:Create System Database=False;'
+ ' Jet OLEDB:Encrypt Database=False;'
+ ' Jet OLEDBon''t Copy Locale on Compact=False;'
+ ' Jet OLEDB:Compact Without Replica Repair=False;'
+ ' Jet OLEDB:SFP=False' ;
//
ADOConnection1.ConnectionString := Dsnstr;
ADOConnection1.LoginPrompt := False ;
Edit3.Text := OpenDialog1.FileName ;
try
ADOConnection1.Connected := True;
except
Application.MessageBox(pchar('数据库出错,打开数据库失败' ),
'错误', MB_OK or MB_ICONWARNING);
Halt;
end;
end ;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Dsnstr : String ;
FromF, ToF: file;
NumRead, NumWritten: Integer;
Buf: array[1..2048] of Char;
strN : string ;
begin
Edit2.Text := '' ;
if ADOConnection2.Connected then
ADOConnection2.Connected := False ;
if OpenDialog2.Execute then
begin
AssignFile(FromF,OpenDialog2.FileName);
Reset(FromF,1) ;
strN := Edit1.Text + '.wsd' ;
if strN = '' then
ShowMessage('先输入要保存的名字!!!');
AssignFile(ToF,strN);
Rewrite(ToF,1) ;
repeat
BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
BlockWrite(ToF, Buf, NumRead, NumWritten);
until (NumRead = 0) or (NumWritten <> NumRead);
CloseFile(FromF);
CloseFile(ToF);
//
Edit2.Text := OpenDialog2.FileName ;
//
Dsnstr := 'Password=wearewinners;User ID=wisenter;'
+ ' Data Source='+ strN +';'
+ ' Mode=Share Deny None;Extended Properties=""; '
+ ' Jet OLEDB:System database=system.mdw;'
+ ' Jet OLEDB:Registry Path="";'
+ ' Jet OLEDBatabase Password="";'
+ ' Jet OLEDB:Engine Type=5;'
+ ' Jet OLEDBatabase Locking Mode=1;'
+ ' Jet OLEDB:Global Partial Bulk Ops=2;'
+ ' Jet OLEDB:Global Bulk Transactions=1;'
+ ' Jet OLEDB:New Database Password="";'
+ ' Jet OLEDB:Create System Database=False;'
+ ' Jet OLEDB:Encrypt Database=False;'
+ ' Jet OLEDBon''t Copy Locale on Compact=False;'
+ ' Jet OLEDB:Compact Without Replica Repair=False;'
+ ' Jet OLEDB:SFP=False' ;
ADOConnection2.ConnectionString := Dsnstr;
ADOConnection2.LoginPrompt := False ;
//ListBox2.Items.Add(OpenDialog2.FileName) ;
try
ADOConnection2.Connected := True;
except
Application.MessageBox(pchar('数据库出错,打开数据库失败' + #13 + '[状态]'),
'错误,请看read.txt文件', MB_OK or MB_ICONWARNING);
Halt;
end;
end ;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
if SaveDialog1.Execute then
Edit1.Text := SaveDialog1.FileName ;
end;
procedure TForm1.GetTable;
begin
ADODataSet2.First ;
while not ADODataSet2.Eof do
begin
if strName <> '' then
if ADODataSet1.Locate('Parameter_Item',ADODataSet2.FieldValues['Parameter_Item'],[]) then
begin
ADODataSet2.Edit ;
if ADODataSet2.Fieldvalues['Parameter_Item']<>'DB_Version' then
begin
ADODataSet2.Fieldvalues['value'] := ADODataSet1.FieldValues['value'] ;
end ;
ADODataSet2.post ;
end ;
ADODataSet2.Next ;
end ;
end;
procedure TForm1.GetTableStructuer;
begin
ADODataSet2.First ;
while not ADODataSet2.Eof do
begin
if ADODataSet1.Locate('TableName',ADODataSet2.FieldValues['TableName'],[]) then
begin
ADODataSet2.Edit ;
ADODataSet2.FieldValues['DictName'] := ADODataSet1.FieldValues['DictName'] ;
ADODataSet2.Post ;
end ;
ADODataSet2.Next ;
end ;
end;
procedure TForm1.GetAllData;
var
i,int : integer ;
iView : integer ;
adoxViews1 : views ;
adoxview1 : view ;
viewName : string ;
begin
//建立原生接口,
adoxCatalog := CoCatalog.Create ;
adoxCatalog1 := CoCatalog.Create ;
//连接数据库
adoxCatalog.Set_ActiveConnection(ADOConnection1.ConnectionObject);
adoxCatalog1.Set_ActiveConnection(ADOConnection2.ConnectionObject); //新库
//生成表
adoxTables1 := adoxCatalog1.Tables ;
adoxTables := adoxCatalog.Tables ;
//生成视图
adoxViews1 := adoxCatalog1.Views ;
//
ProgressBar1.Max := adoxTables1.Count ;
ProgressBar1.Min := 0 ;
//
For int := 0 to adoxTables1.Count - 1 do
begin
// ShowMessage(adoxTable1.Name);
For i := 0 to adoxTables.Count -1 do
begin
adoxTable1 := adoxTables1.Item[int] ;
adoxTable := adoxTables.Item ;
viewName := '' ;
//如果是系统表就不处理
if (adoxTable1.Name = 'DictStructure')or (adoxTable1.Name = 'System_Parameter')or(adoxTable1.Name ='MSysAccessObjects') or (adoxTable1.Name = 'MSysAccessXML')or (adoxTable1.Name = 'MSysACEs') or (adoxTable1.Name = 'MSysObjects') or (adoxTable1.Name = 'MSysQueries')or (adoxTable1.Name = 'MSysRelationships')then
begin
if adoxTable1.Name = 'DictStructure'then
begin
GetTableData(adoxTable1,adoxTable1) ;
GetTableStructuer ;
end ;
if adoxTable1.Name = 'System_Parameter' then
begin
GetSysTableData(adoxTable1,adoxTable1) ;
GetTable ;
end ;
break ;
end
else begin
//表相同
if adoxTable.Name = adoxTable1.Name then
begin
//判断视图
For iView := 0 to adoxviews1.Count -1 do
begin
adoxview1 := adoxviews1.Item[iView] ;
//如果是视图
if adoxTable.Name = adoxview1.Name then
begin
viewName := adoxTable.Name ;
break ;
end ;
end ;
//如果不是视图
if adoxTable.Name <> viewName then
begin
//启动数据集
GetTableData(adoxTable1,adoxtable) ;
//
ProgressBar1.Position := int +2 ;
ProgressBar1.Update ;
//取道数据
GetData(adoxTable,adoxTable1);
end ;
Break ;
end ;
end ;
end ;
if str = 'MyData' then
break ;
end ;
if str = 'MyData' then
begin
Application.Terminate ;
end
else begin
if MessageDlg('数据升级完毕!!!',mtInformation, [mbok], 0) = mrok then
Application.Terminate ;
end ;
end;
procedure TForm1.GetSysTableData(TableName, ExamTableName: Table);
var
adoxpros : Properties ;
adoxpro : Property_ ;
i,ipro : integer ;
begin
strName := '' ;
// showmessage(strName) ;
if ADODataSet1.Active then
ADODataSet1.Active := False ;
with ADODataSet1 do
begin
CommandType := cmdText ;
CommandText := 'select * from '+ TableName.Name ;
open ;
end ;
adoxcolumns := TableName.Columns ; //原数据
adoxcolumns1 := ExamTableName.Columns ; //目标数据
For i := 0 to adoxColumns1.Count -1 do
begin
adoxColumn1 := adoxColumns1.Item ;
//判断属性
// ShowMessage(adoxColumn1.Name) ;
adoxpros := adoxColumn1.Properties ;
For ipro := 0 to adoxpros.Count -1 do
begin
adoxpro := adoxpros.Item[ipro] ;
//如果为true就为自增行
// ShowMessage(adoxpro.Value);
if adoxpro.Value = true then
begin
strName := adoxColumn1.Name ;
break ;
end
else
break ;
end ;
if strname <>'' then
break ;
end ;
if ADODataSet2.Active then
ADODataSet2.Active := False ;
with ADODataSet2 do
begin
CommandType := cmdText ;
CommandText := ' select * from '+ ExamTableName.Name ;
Open ;
end ;
if strName <> '' then
begin
// ShowMessage('ddd');
if ADODataSet1.Active then
ADODataSet1.Active := False ;
with ADODataSet1 do
begin
CommandType := cmdText ;
CommandText := 'select * from ' + TableName.Name ;
open ;
end ;
if ADODataSet2.Active then
ADODataSet2.Active := False ;
with ADODataSet2 do
begin
CommandType := cmdText ;
CommandText := 'select * from ' + ExamTableName.Name + #32+ 'order by'+ #32 + strName ;
open ;
end ;
end ;
end;
end.