Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Reflection;
- using System.Text;
- namespace Ex02.Model
- {
- public class EducationalProduction : Production
- {
- public string TeachingMaterial { get; set; }
- public override string Type { get { return "Educational"; } }
- public override void OrderNow()
- {
- Debug.WriteLine(string.Format("Ticket ordered for production {0} for the price of €{1}.", Name, Price));
- Debug.WriteLine(string.Format("-- associated educational material can be found here: {0}", TeachingMaterial));
- }
- #region Filling in List
- public static List<EducationalProduction> ReadEducationalProductions()
- {
- List<EducationalProduction> res = new List<EducationalProduction>();
- var assembly = typeof(EducationalProduction).GetTypeInfo().Assembly;
- Stream stream = assembly.GetManifestResourceStream("Ex02.Assets.educational.csv");
- StreamReader oSR = new StreamReader(stream);
- string sLine = oSR.ReadLine(); //eerste lijn niet verwerken
- sLine = oSR.ReadLine(); //tweede lijn inlezen
- while (sLine != null)
- {
- try
- {
- //lijn verwerken
- EducationalProduction educationalProduction = CreateEducationalProduction(sLine);
- if (educationalProduction != null)
- {
- res.Add(educationalProduction);
- //Debug.WriteLine(educationalProduction);
- }
- }
- catch (Exception ex)
- {
- Debug.WriteLine("Error on exception line: " + sLine);
- //throw;
- }
- //nieuwe lijn inlezen
- sLine = oSR.ReadLine();
- }
- oSR.Close();
- //Debug.WriteLine(res);
- return res;
- }
- private static EducationalProduction CreateEducationalProduction(string sLine)
- {
- EducationalProduction educationalProduction = new EducationalProduction();
- //sLine --> opsplitsen in stukken
- string[] parts = sLine.Split(';');
- //Name;Date(s);Price;Description;TeachingMaterial
- if (parts.Length == 5)
- {
- educationalProduction.Name = parts[0];
- double datum = double.Parse(parts[1]);
- // DateTime NormalDate = UnixTimeStampToDateTime(datum);
- educationalProduction.Date = UnixTimeStampToDateTime(datum);
- educationalProduction.Price = double.Parse(parts[2]);
- educationalProduction.Description = parts[3];
- educationalProduction.TeachingMaterial = parts[4];
- return educationalProduction;
- }
- else
- {
- Debug.WriteLine("Error on line: " + sLine);
- return null;
- }
- }
- #endregion
- public static DateTime UnixTimeStampToDateTime(double unixTimeStamp)
- {
- // Unix timestamp is seconds past epoch
- System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
- dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
- return dtDateTime;
- }
- public List<EducationalProduction> GetEducationalProduction()
- {
- //Maak een nieuwe list aan
- List<EducationalProduction> List = new List<EducationalProduction>();
- List<EducationalProduction> FilteredList = new List<EducationalProduction>();
- //Haal de volledige list op
- List = ReadEducationalProductions();
- //foreach om de volledige lijs te overlopen
- foreach (EducationalProduction Elements in List)
- {
- if (Elements.Date.Month == DateTime.Now.Month)
- {
- FilteredList.Add(Elements);
- Debug.WriteLine("Filtered List Item: " + Elements);
- }
- }
- //if structuur om te filteren op de volledige list
- //indien de date overeenkomt, voeg toe aan gefilterde list
- //return gefilterde list
- return FilteredList;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement