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
|
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]
*/
Console.WriteLine("Third Pass");
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);
if (r2index == -1)
throw new ApplicationException("Trying to synchronize pass 3, row not found in noprio ds, rerun pass1 and 2");
string ds1str = ds1.Tables[0].Rows[r1][fields1[f1]].ToString();
string ds2str = ds2.Tables[0].Rows[r2index][fields2[f1]].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();
}
}
}
}
private int getindex(DataSet dsin, string pk, string pkfield)
{
//get collumn index
//L("Getting Index");
for (int x = 0; x < dsin.Tables[0].Rows.Count; x++)
{
//L(x.ToString());
//L(pkfield.ToString());
//L(dsin.Tables[0].Rows[x][pkfield].ToString());
string t = dsin.Tables[0].Rows[x][pkfield].ToString();
/*
* check if pk or t are double or int convert both to double
* and back to string
*/
try
{ //pk is double
//L("pk is double");
pk = Double.Parse(pk).ToString();
t = Double.Parse(t).ToString();
}
catch {
//L("pk is not double");
}
if (String.Compare(t, pk, true) == 0)
return x;
}
return -1;
} |
Partager