Ejemplo n.º 1
0
 public static void ImportFixedData(string path)
 {
     //var excelFile = new ExcelQueryFactory(path) { TrimSpaces = TrimSpacesType.Both, ReadOnly = true };
     //foreach (var row in excelFile.GetWorksheetNames()
     //    .Select(worksheet => (from row in excelFile.Worksheet(worksheet) select row)).SelectMany(rows => rows))
     {
         using (var ds = FillDataSet(path))
         {
             for (var i = 1; i < ds.Tables[0].Rows.Count; i++)
             {
                 using (var db = new SqLiteDbContext())
                 {
                     var local = ds.Tables[0].Rows[i][1].ToString();
                     switch (local)
                     {
                         case "Klub":
                             var club = new Club();
                             SetCommonData(club, ds.Tables[0].Rows[i], db);
                             SetClubData(club, ds.Tables[0].Rows[i], db);
                             db.Clubs.AddOrUpdate(x => x.Code, club);
                             break;
                         case "Pub":
                             var pub = new Pub();
                             SetCommonData(pub, ds.Tables[0].Rows[i], db);
                             SetPubData(pub, ds.Tables[0].Rows[i], db);
                             db.Pubs.AddOrUpdate(x => x.Code, pub);
                             break;
                         case "Restaurant":
                             var restaurant = new Restaurant();
                             SetCommonData(restaurant, ds.Tables[0].Rows[i], db);
                             SetRestaurantData(restaurant, ds.Tables[0].Rows[i], db);
                             db.Restaurants.AddOrUpdate(x => x.Code, restaurant);
                             break;
                         case "Kawiarnie":
                             var café = new Cafe();
                             SetCommonData(café, ds.Tables[0].Rows[i], db);
                             SetCaféData(café, ds.Tables[0].Rows[i], db);
                             db.Cafes.AddOrUpdate(x => x.Code, café);
                             break;
                         case "Hotel":
                             var hotel = new Hotel();
                             SetCommonData(hotel, ds.Tables[0].Rows[i], db);
                             SetHotelData(hotel, ds.Tables[0].Rows[i], db);
                             db.Hotels.AddOrUpdate(x => x.Code, hotel);
                             break;
                     }
                     db.SaveChanges();
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 private static void SetRestaurantData(Restaurant restaurant, DataRow row, SqLiteDbContext db)
 {
     restaurant.MondayOpening = row[8].ToString();
     restaurant.MondayClosing = row[9].ToString();
     restaurant.ThusdayClosing = row[10].ToString();
     restaurant.ThusdayOpening = row[11].ToString();
     restaurant.WednesdayOpening = row[12].ToString();
     restaurant.WednesdayClosing = row[13].ToString();
     restaurant.ThursdayOpening = row[14].ToString();
     restaurant.ThursdayClosing = row[15].ToString();
     restaurant.FridayOpening = row[16].ToString();
     restaurant.FridayClosing = row[17].ToString();
     restaurant.SaturdayOpening = row[18].ToString();
     restaurant.SaturdayClosing = row[19].ToString();
     restaurant.SundayOpening = row[20].ToString();
     restaurant.SundayClosing = row[21].ToString();
     restaurant.AvailableCoupons = row[33].ToString().ToLower().Equals("yes");
     string food = row[45].ToString();
     var foodType = db.FoodTypes.FirstOrDefault(x => x.TypeOfFood.Equals(food));
     if (foodType != null)
     {
         var foodTypeId = foodType.Id;
         restaurant.FoodTypeId = foodTypeId;
     }
     else
         restaurant.FoodType = new FoodType {TypeOfFood = food};
     restaurant.PricesRange1 = row[46].ToString();
     restaurant.PricesRange2 = row[47].ToString();
     restaurant.CheckMenu = row[48].ToString();
 }