Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. List<Wine> wines = new List<Wine>();
  2. List<Food> foods = new List<Food>();
  3.  
  4. string path = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\Virtuele Sommelier juli 2015.xlsx" ;
  5. Excel.Application xlApp = new Excel.Application();
  6. Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@path);
  7. Excel.Worksheet xlWorksheet = xlWorkbook.Sheets[1];
  8. Excel.Range xlRange = xlWorksheet.UsedRange;
  9.  
  10. int rCount = xlRange.Rows.Count;
  11. int cCount = xlRange.Columns.Count;
  12.  
  13. string stringRange = "A1:L" + rCount;
  14. object[,] objectArray = xlWorksheet.get_Range(stringRange).Value2;
  15.  
  16. for (int i = 1; i <= rCount; i++)
  17. {
  18. SubCategory subCategory = new SubCategory((string)objectArray[i, 2], new Category((string)objectArray[i, 1]));
  19. Food food = new Food((string)objectArray[i, 3], subCategory);
  20.  
  21. WineFoodModel.Type type = (WineFoodModel.Type)Enum.Parse(typeof(WineFoodModel.Type), (string)objectArray[i, 4], true);
  22. string naamWijn = (string)objectArray[i, 5];
  23. string url = (string)objectArray[i, 6];
  24. double price = (double)objectArray[i, 7];
  25. Region region = new Region((string)objectArray[i, 9], new Country((string)objectArray[i, 8]));
  26. string appelatie = (string)objectArray[i, 10];
  27. bool bio = checkBio((string)objectArray[i, 11]);
  28. string description = (string)objectArray[i, 12];
  29.  
  30. Wine wine = new Wine(type, naamWijn, url, price, description, region, appelatie, bio);
  31.  
  32. //food.AddWine(wine);
  33. //foods.Add(food);
  34. //wine.AddFood(food);
  35. wines.Add(wine);
  36.  
  37.  
  38. using (var db = new WineContext())
  39. {
  40. Country country = new Country("Belgie");
  41. db.Countries.Add(country);
  42. db.SaveChanges();
  43. }
  44.  
  45. }
  46.  
  47. foreach(Wine wine in wines){
  48. System.Diagnostics.Debug.WriteLine(wine.ToString());
  49. }
  50.  
  51.  
  52. public override string ToString()
  53. {
  54. if (Bio)
  55. {
  56. return "Wine: " + Name + "\tAppelatie: " + Appelatie + "\n" + TypeId.ToString() + "\tPrice: " + Price + "\n" + Region.ToString() + "\nDescription: " + Description + "\nBio: Ja";
  57. }else
  58. return "Wine: " + Name + "\tAppelatie: " + Appelatie + "\n" + TypeId.ToString() + "\tPrice: " + Price + "\n" + Region.ToString() + "\nDescription: " + Description + "\nBio: Nee";
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement