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
|
private void secondpass(ref DataSet ds1, string pk1, ref DataSet ds2, string pk2)
{
//ds1 has priority
for (int x = 0; x < ds2.Tables[0].Rows.Count; x++)
{
//check if row exist in ds2
if (!this.isin(ds1, ds2.Tables[0].Rows[x][pk2].ToString(), pk1))
{
//primary key of ds1 does not match ds2
Console.WriteLine(">>>Deleting Data : " + ds2.Tables[0].Rows[x].ToString());
ds2.Tables[0].Rows[x].Delete();
}
}
}
private void thirdpasss(ref DataSet ds1, string pk1,string[] fields1, ref DataSet ds2, string pk2,string[] fields2){
/* if rowcount ds1 != ds2 throw
* here we have to compare all row from ds1 to ds2,
* for each row in ds1,
* for each field in fieldsa
* if ds2[row][fieldsb[index of fielda]] != ds1[row][field]
* ds2[row][[fieldsb[index of fielda]] = ds1[row][field]
*/
if (this.getrcount(ds1) != this.getrcount(ds2))
throw new ApplicationException("Row count dont match, cannot synchronize.Rerun pass 1 and 2");
if (fields1.Count() != fields2.Count())
throw new ApplicationException("fields count dont match, cannot synchronize.Check config");
for (int r1=0; r1 < ds1.Tables[0].Rows.Count; r1++){
if (ds1.Tables[0].Rows[r1].RowState == DataRowState.Deleted)
continue;
for (int f1 = 0; f1 < fields1.Count(); f1++){
//first ensure that ds1 pk is in ds2
// then get index of ds2
//int r2index = this.getindex(ds2, ds1.Tables[0].Rows[r1][pk1].ToString(),pk1);
int r2index = 0;
if (r2index == -1)
throw new ApplicationException("Trying to synchronize pass 3, row not found in noprio ds, rerun pass1 and 2");
L(ds2.Tables[0].Rows[0][1].ToString());
string ds1str = "";
string ds2str = "";
ds1str = ds1.Tables[0].Rows[r1][fields1[f1]].ToString();
ds2str = ds2.Tables[0].Rows[r2index][fields2[f1]].ToString();
L("*******");
Console.WriteLine(ds1str.ToString());
Console.WriteLine(ds2str.ToString());
if ( ds2str != ds1str){
Console.WriteLine("Field modified");
Console.WriteLine("ds1 :" + ds1.Tables[0].Rows[r1][fields1[f1]].ToString());
Console.WriteLine("ds2 :" + ds2.Tables[0].Rows[r2index][fields2[f1]].ToString());
ds2.Tables[0].Rows[r2index][fields1[f1]] = ds1.Tables[0].Rows[r1][fields1[f1]].ToString();
}
}
}
} |
Partager