Beispiel #1
0
        public static EventList GetAllEvents()
        {
            EventList events = null;

            if (File.Exists("eventfile.xml"))
            {
                Stream        stream       = File.OpenRead("eventfile.xml");
                XmlSerializer deserializer = new XmlSerializer(typeof(EventList));
                events = (EventList)deserializer.Deserialize(stream);
                stream.Close();
            }
            return(events);
        }
Beispiel #2
0
        public static void SaveEvents(EventList toSave)
        {
            try
            {
                TextWriter    writer     = new StreamWriter("eventfile.xml", false);
                XmlSerializer serializer = new XmlSerializer(typeof(EventList));
                serializer.Serialize(writer, toSave);
                writer.Close();
                writer = new StreamWriter("ticketsales.csv", false);
                foreach (Event e in toSave.events)
                {
                    writer.WriteLine(e.Title + "," + e.TicketSales());
                }
                writer.Close();
            }

            catch (IOException e)
            {
                Console.WriteLine("I/O Error occurred while reading: " + e.Message);
            }
        }