1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
|
unit Unit5;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, IBDatabase, Db, IBTable, IBCustomDataSet, IBQuery;
type
TForm5 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Label3: TLabel;
IBTable1: TIBTable;
IBDatabase: TIBDatabase;
IBTransaction: TIBTransaction;
IBTable2: TIBTable;
IBTable1IDI: TIntegerField;
IBTable1XIDI: TIntegerField;
IBTable1SEXE: TIBStringField;
IBTable1DATEN: TDateField;
IBTable1XDATEN: TIntegerField;
IBTable1LIEUN: TIBStringField;
IBTable1XLIEUN: TIntegerField;
IBTable1PERE: TIntegerField;
IBTable1MERE: TIntegerField;
IBTable1DATED: TDateField;
IBTable1XDATED: TIntegerField;
IBTable1LIEUD: TIBStringField;
IBTable1XLIEUD: TIntegerField;
IBTable1APX: TDateField;
IBTable1AVX: TDateField;
IBTable2UNI: TIntegerField;
IBTable2HOMME: TIntegerField;
IBTable2FEMME: TIntegerField;
IBTable2DATEM: TDateField;
IBTable2XDATEM: TIntegerField;
IBTable2LIEUM: TIBStringField;
IBTable2XLIEUM: TIntegerField;
IBTable2RANGMARIAGEHOM: TIntegerField;
IBTable2RANGMARIAGEFEM: TIntegerField;
IBTable2DATEFU: TDateField;
IBTable2XDATEFU: TIntegerField;
IBTable2XSEXE: TIntegerField;
IBTable2SEXES: TIBStringField;
IBTable2LIEUFU: TIBStringField;
IBQuery2: TIBQuery;
IBQuery2UNI: TIntegerField;
IBQuery2HOMME: TIntegerField;
IBQuery2FEMME: TIntegerField;
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form5: TForm5;
implementation
uses Unit2, Unit4;
{$R *.DFM}
procedure Remplir_indiv();
begin
form4.table1.first;
//TANT QUE LA BASE DBASE N EST PAS FINI
//ON INSERE LES ENREGISTREMNTS DANS LA BASE FIREBIRD
while not form4.table1.Eof do
begin
form5.Ibtable1.Insert;
if form4.table1IDI.AsInteger <> 0 then
begin
form5.ibtable1IDI.AsInteger:=form4.table1IDI.AsInteger;
if form4.table1XIDI.AsString <> '' then
form5.ibtable1XIDI.AsInteger:=form4.table1XIDI.AsInteger;
if form4.table1SEXE.AsString <> '' then
form5.ibtable1SEXE.AsString:=form4.table1SEXE.AsString;
if form4.table1DATEN.AsString <> '' then
form5.ibtable1DATEN.AsDateTime:=form4.table1DATEN.AsDateTime;
if form4.table1XDATEN.AsString <> '' then
form5.ibtable1XDATEN.AsInteger:=form4.table1XDATEN.AsInteger;
if form4.table1LIEUN.AsString <> '' then
form5.ibtable1LIEUN.AsString:=form4.table1LIEUN.AsString;
if form4.table1XLIEUN.AsString <> '' then
form5.ibtable1XLIEUN.AsInteger:=form4.table1XLIEUN.AsInteger;
if form4.table1PERE.AsInteger <> 0 then
form5.ibtable1PERE.AsInteger:=form4.table1PERE.AsInteger;
if form4.table1MERE.AsInteger <> 0 then
form5.ibtable1MERE.AsInteger:=form4.table1MERE.AsInteger;
if form4.table1DATED.AsString <> '' then
form5.ibtable1DATED.AsDateTime:=form4.table1DATED.AsDateTime;
if form4.table1XDATED.AsString <> '' then
form5.ibtable1XDATED.AsInteger:=form4.table1XDATED.AsInteger;
if form4.table1LIEUD.AsString <> '' then
form5.ibtable1LIEUD.AsString:=form4.table1LIEUD.AsString;
if form4.table1XLIEUD.AsString <> '' then
form5.ibtable1XLIEUD.AsInteger:=form4.table1XLIEUD.AsInteger;
if form4.table1APX.AsString <> '' then
form5.ibtable1APX.AsDateTime:=form4.table1APX.AsDateTime;
if form4.table1AVX.AsString <> '' then
form5.ibtable1AVX.AsDateTime:=form4.table1AVX.AsDateTime;
form5.ibtable1.post;
form5.IBTransaction.CommitRetaining;
end;
form4.table1.next;
end;
end;
procedure Remplir_union();
begin
form4.table2.first;
while not form4.table2.Eof do
begin
form5.IBTable2.Insert;
if (form4.table2UNION.AsInteger <> 0) then
begin
form5.IBTable2UNI.AsInteger:=form4.table2UNION.AsInteger;
if form4.table2HOMME.AsString <> '' then
form5.IBTable2HOMME.AsInteger:=form4.table2HOMME.AsInteger;
if form4.table2FEMME.AsString <> '' then
form5.IBTable2FEMME.AsInteger:=form4.table2FEMME.AsInteger;
if form4.table2DATEM.AsString <> '' then
form5.IBTable2DATEM.AsDateTime:=form4.table2DATEM.AsDateTime;
if form4.table2XDATEM.AsString = 'A' then
begin
form5.IBTable2XDATEM.AsInteger:=1;
end
else
begin
if form4.table2XDATEM.AsString <> '' then
form5.IBTable2XDATEM.AsInteger:=form4.table2XDATEM.AsInteger;
end;
if form4.table2LIEUM.AsString <> '' then
form5.IBTable2LIEUM.AsString:=form4.table2LIEUM.AsString;
if form4.table2XLIEUM.AsString <> '' then
form5.IBTable2XLIEUM.AsInteger:=form4.table2XLIEUM.AsInteger;
if form4.table2RANGMARHOM.AsString <> '' then
form5.IBTable2RANGMARIAGEHOM.AsInteger:=form4.table2RANGMARHOM.AsInteger;
if form4.table2RANGMARFEM.AsString <> '' then
form5.IBTable2RANGMARIAGEFEM.AsInteger:=form4.table2RANGMARFEM.AsInteger;
if form4.table2DATEFU.AsString <> '' then
form5.IBTable2DATEFU.AsDateTime:=form4.table2DATEFU.AsDateTime;
if form4.table2XDATEFU.AsString ='DV' then
begin
form5.IBTable2XDATEFU.AsInteger:=0;
end
else
begin
if form4.table2XDATEFU.AsString <> '' then
form5.IBTable2XDATEFU.AsInteger:=form4.table2XDATEFU.AsInteger
end;
if form4.table2XSEXE.AsString <> '' then
form5.IBTable2XSEXE.AsInteger:=form4.table2XSEXE.AsInteger;
if form4.table2SEXES.AsString <> '' then
form5.IBTable2SEXES.AsString:=form4.table2SEXES.AsString;
if form4.table2LIEUFU.AsString <> '' then
form5.IBTable2LIEUFU.AsString:=form4.table2LIEUFU.AsString;
form5.IBTable2.post;
form5.IBTransaction.CommitRetaining;
end;
form4.table2.next;
end;
end;
procedure supprimer_intrus();
var IBQuery: TIBQuery;
begin
IBQuery := TIBQuery.Create(nil);
form5.Ibquery2.open();
form5.IBQuery2.first;
while not form5.IBQuery2.Eof do
begin
IBQuery.Database := form5.IBDatabase;
IBQuery.Transaction := form5.IBTransaction;
try
IBQuery.SQL.Clear();
IBQuery.SQL.add('Delete from "FBUNIMODIF" where "HOMME"='+form5.IBQUERY2HOMME.AsString+';');
IBQuery.ExecSQL;
form5.IBTransaction.CommitRetaining;
except
form5.IBTransaction.Rollback;
end;
form5.ibquery2.next;
end;
form5.ibquery2.Close();
FreeAndNil(IBQuery);
end;
procedure cle_etr();
var IBQuery: TIBQuery;
IBTransaction : TIBTransaction ;
IBDatabase : TIBDatabase;
begin
IBQuery := TIBQuery.Create(nil);
IBDATABASE := TIBDatabase.create(nil);
IBTransaction := TIBTransaction.Create(nil);
IBQuery.SQL.Clear();
IBDataBase.DatabaseName := migration.opendialog1.filename;
IBDataBase.SQLDialect := 3;
IBDatabase.Connected := true;
IBTransaction.DefaultDatabase :=IBDataBase;
IBTransaction.Active:=True;
IBQuery.Database:= IBDatabase;
IBQuery.Transaction := IBTransaction;
//CREATION CONTRAINTE CLE ETRANGERE UNION HOMME
IBQuery.SQL.Add('ALTER TABLE "FBUNIMODIF" ADD CONSTRAINT '+
'"CLE_ETRAN_HOM" FOREIGN KEY (HOMME) REFERENCES "FBIDIMODIF"("IDI");');
IBQuery.ExecSQL;
ibquery.Transaction.CommitRetaining;
IBQuery.SQL.Clear;
IBTransaction.Active:=True;
//CREATION CONTRAINTE CLE ETRANGERE UNION FEMME
IBQuery.SQL.Add('ALTER TABLE "FBUNIMODIF" ADD CONSTRAINT'+
'"CLE_ETRAN_FEM" FOREIGN KEY (FEMME) REFERENCES "FBIDIMODIF"("IDI");');
IBQuery.ExecSQL;
ibquery.Transaction.CommitRetaining;
IBQuery.SQL.Clear;
end;
procedure TForm5.Button1Click(Sender: TObject);
begin
try
IBDataBase.DatabaseName := migration.opendialog1.filename;
//IBDataBase.DatabaseName :='C:\Documents and Settings\Administrateur\Bureau\STAGE\loimp.fdb';
IBDataBase.SQLDialect := 3;
Ibdatabase.LoginPrompt:=false;
IBDatabase.Connected := true;
IBTransaction.DefaultDatabase := IBDataBase;
IBTransaction.Active:=True;
IBTable1.tablename:='FBIDIMODIF';
IBTable2.tablename:='FBUNIMODIF';
IBTable1.Active:=True;
IBTable2.Active:=True;
remplir_indiv();
remplir_union();
supprimer_intrus();
IBTable1.Active:=false;
IBTable2.Active:=false;
IBTable1.TableName:='';
IBTable2.TableName:='';
IBTransaction.Active:=False;
IBDatabase.Connected := False;
IBDataBase.DatabaseName :='';
FreeAndNil(ibtable1);
FreeAndNil(ibtable2);
FreeAndNil(IBTransaction);
FreeAndNil(IBDataBase);
cle_etr();
finally
FreeAndNil(IBTransaction);
FreeAndNil(IBDataBase);
end;
form5.close;
end;
end. |
Partager