Exemplo n.º 1
0
 public static void UpdateLegacyData(string fileName, Dictionary <string, Tuple <int, int, string> > tanks)
 {
     using (IDBHelpers db = new DBHelpers(fileName, true))
     {
         db.BeginTransaction();
         string sql = "select cmCountryID || '_' || cmTankID  TankKey, cmCountryID, cmTankID from File_TankDetails where cmTier is null group by cmCountryID, cmTankID";
         using (DataTable dt = db.GetDataTable(sql))
         {
             if (dt.Rows.Count > 0)
             {
                 foreach (DataRow row in dt.Rows)
                 {
                     Tuple <int, int, string> tankDef;
                     if (tanks.TryGetValue(row["TankKey"].ToString(), out tankDef))
                     {
                         string updateSQL = String.Format("Update File_TankDetails set cmType = '{0}', cmTier = '{1}', cmTankTitle = '{2}' where cmCountryID = '{3}' and cmTankID = '{4}' and cmTier is null",
                                                          tankDef.Item1,
                                                          tankDef.Item2,
                                                          tankDef.Item3,
                                                          row["cmCountryID"],
                                                          row["cmTankID"]);
                         try
                         {
                             db.ExecuteNonQuery(updateSQL);
                         }
                         catch
                         { /*very bad practice. never swallow errors*/ }
                     }
                 }
             }
         }
         db.EndTransaction();
     }
 }