Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Reflection;
  6. using System.Text;
  7.  
  8. namespace Ex02.Model
  9. {
  10.     public class EducationalProduction : Production
  11.     {
  12.         public string TeachingMaterial { get; set; }
  13.         public override string Type { get { return "Educational"; } }
  14.  
  15.  
  16.         public override void OrderNow()
  17.         {
  18.             Debug.WriteLine(string.Format("Ticket ordered for production {0} for the price of €{1}.", Name, Price));
  19.             Debug.WriteLine(string.Format("-- associated educational material can be found here: {0}", TeachingMaterial));
  20.         }
  21.         #region Filling in List
  22.  
  23.        
  24.         public static List<EducationalProduction> ReadEducationalProductions()
  25.         {
  26.             List<EducationalProduction> res = new List<EducationalProduction>();
  27.             var assembly = typeof(EducationalProduction).GetTypeInfo().Assembly;
  28.             Stream stream = assembly.GetManifestResourceStream("Ex02.Assets.educational.csv");
  29.  
  30.             StreamReader oSR = new StreamReader(stream);
  31.  
  32.             string sLine = oSR.ReadLine();  //eerste lijn niet verwerken
  33.             sLine = oSR.ReadLine();         //tweede lijn inlezen
  34.             while (sLine != null)
  35.             {
  36.                 try
  37.                 {
  38.                     //lijn verwerken
  39.                     EducationalProduction educationalProduction = CreateEducationalProduction(sLine);
  40.                     if (educationalProduction != null)
  41.                     {
  42.                         res.Add(educationalProduction);
  43.                         //Debug.WriteLine(educationalProduction);
  44.                     }
  45.  
  46.  
  47.                 }
  48.                 catch (Exception ex)
  49.                 {
  50.                     Debug.WriteLine("Error on exception line: " + sLine);
  51.                     //throw;
  52.                 }
  53.  
  54.                 //nieuwe lijn inlezen
  55.                 sLine = oSR.ReadLine();
  56.  
  57.             }
  58.  
  59.             oSR.Close();
  60.             //Debug.WriteLine(res);
  61.             return res;
  62.  
  63.         }
  64.         private static EducationalProduction CreateEducationalProduction(string sLine)
  65.         {
  66.             EducationalProduction educationalProduction = new EducationalProduction();
  67.             //sLine --> opsplitsen in stukken
  68.             string[] parts = sLine.Split(';');
  69.             //Name;Date(s);Price;Description;TeachingMaterial
  70.             if (parts.Length == 5)
  71.             {
  72.                 educationalProduction.Name = parts[0];
  73.                 double datum = double.Parse(parts[1]);
  74.               // DateTime NormalDate = UnixTimeStampToDateTime(datum);
  75.                 educationalProduction.Date = UnixTimeStampToDateTime(datum);                
  76.                 educationalProduction.Price = double.Parse(parts[2]);
  77.                 educationalProduction.Description = parts[3];
  78.                 educationalProduction.TeachingMaterial = parts[4];
  79.                 return educationalProduction;
  80.             }
  81.             else
  82.             {
  83.                 Debug.WriteLine("Error on line: " + sLine);
  84.                 return null;
  85.             }
  86.         }
  87.         #endregion
  88.         public static DateTime UnixTimeStampToDateTime(double unixTimeStamp)
  89.         {
  90.             // Unix timestamp is seconds past epoch
  91.             System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
  92.             dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
  93.             return dtDateTime;
  94.         }
  95.  
  96.         public List<EducationalProduction> GetEducationalProduction()
  97.         {
  98.            
  99.             //Maak een nieuwe list aan
  100.             List<EducationalProduction> List = new List<EducationalProduction>();
  101.             List<EducationalProduction> FilteredList = new List<EducationalProduction>();
  102.             //Haal de volledige list op
  103.             List = ReadEducationalProductions();
  104.             //foreach om de volledige lijs te overlopen
  105.             foreach (EducationalProduction Elements in List)
  106.             {
  107.                 if (Elements.Date.Month == DateTime.Now.Month)
  108.                 {
  109.                     FilteredList.Add(Elements);
  110.                     Debug.WriteLine("Filtered List Item: " + Elements);
  111.                 }
  112.             }
  113.  
  114.  
  115.             //if structuur om te filteren op de volledige list
  116.  
  117.             //indien de date overeenkomt, voeg toe aan gefilterde list
  118.  
  119.             //return gefilterde list
  120.             return FilteredList;
  121.         }
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement