Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<Wine> wines = new List<Wine>();
- List<Food> foods = new List<Food>();
- string path = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\Virtuele Sommelier juli 2015.xlsx" ;
- Excel.Application xlApp = new Excel.Application();
- Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@path);
- Excel.Worksheet xlWorksheet = xlWorkbook.Sheets[1];
- Excel.Range xlRange = xlWorksheet.UsedRange;
- int rCount = xlRange.Rows.Count;
- int cCount = xlRange.Columns.Count;
- string stringRange = "A1:L" + rCount;
- object[,] objectArray = xlWorksheet.get_Range(stringRange).Value2;
- for (int i = 1; i <= rCount; i++)
- {
- SubCategory subCategory = new SubCategory((string)objectArray[i, 2], new Category((string)objectArray[i, 1]));
- Food food = new Food((string)objectArray[i, 3], subCategory);
- WineFoodModel.Type type = (WineFoodModel.Type)Enum.Parse(typeof(WineFoodModel.Type), (string)objectArray[i, 4], true);
- string naamWijn = (string)objectArray[i, 5];
- string url = (string)objectArray[i, 6];
- double price = (double)objectArray[i, 7];
- Region region = new Region((string)objectArray[i, 9], new Country((string)objectArray[i, 8]));
- string appelatie = (string)objectArray[i, 10];
- bool bio = checkBio((string)objectArray[i, 11]);
- string description = (string)objectArray[i, 12];
- Wine wine = new Wine(type, naamWijn, url, price, description, region, appelatie, bio);
- //food.AddWine(wine);
- //foods.Add(food);
- //wine.AddFood(food);
- wines.Add(wine);
- using (var db = new WineContext())
- {
- Country country = new Country("Belgie");
- db.Countries.Add(country);
- db.SaveChanges();
- }
- }
- foreach(Wine wine in wines){
- System.Diagnostics.Debug.WriteLine(wine.ToString());
- }
- public override string ToString()
- {
- if (Bio)
- {
- return "Wine: " + Name + "\tAppelatie: " + Appelatie + "\n" + TypeId.ToString() + "\tPrice: " + Price + "\n" + Region.ToString() + "\nDescription: " + Description + "\nBio: Ja";
- }else
- return "Wine: " + Name + "\tAppelatie: " + Appelatie + "\n" + TypeId.ToString() + "\tPrice: " + Price + "\n" + Region.ToString() + "\nDescription: " + Description + "\nBio: Nee";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement