예제 #1
0
        //Load from file in .exe directory
        void LoadEvents()
        {
            EventsList el = new EventsList();

            XmlSerializer serializer = new XmlSerializer(typeof(EventsList));

            try
            {
                using (var x = new FileStream(xmlDirectoryPath, FileMode.Open))
                {
                    var xml = new XmlSerializer(typeof(EventsList));
                    el = (EventsList)xml.Deserialize(x);

                    bool changes = false;
                    foreach (var item in el.Events)
                    {
                        if (item.EventDate < DateTime.Now)
                        {
                            changes = true;
                        }
                        else
                        {
                            Events.Add(item);
                        }
                    }
                    if (changes)
                    {
                        MessageBox.Show("Some outdated events have been removed.");
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Problem with opening events. Created new, empty file.");
                File.Create(xmlDirectoryPath);
            }
            if (Events.Count > 0 && Events != null)
            {
                SelectedEvent = Events[0];
            }
        }
예제 #2
0
        //Save to file in .exe file directory
        void SaveEvents()
        {
            try
            {
                using (var newFile = new FileStream(xmlDirectoryPath, FileMode.Create))
                {
                    EventsList el = new EventsList();
                    foreach (var item in Events)
                    {
                        el.Events.Add(item);
                    }

                    var xml = new XmlSerializer(typeof(EventsList));
                    xml.Serialize(newFile, el);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Problem with saving data");
            }
        }
예제 #3
0
        //Load from file in .exe directory
        void LoadEvents()
        {
            EventsList el = new EventsList();

            try
            {
                using (var x = new FileStream(xmlDirectoryPath, FileMode.Open))
                {
                    var xml = new XmlSerializer(typeof(EventsList));
                    el = (EventsList)xml.Deserialize(x);
                    bool changes = false;
                    foreach (var item in el.Events)
                    {
                        if (item.EventDate < DateTime.Now)
                        {
                            changes = true;
                        }
                        else
                        {
                            Events.Add(item);
                        }
                    }
                    if (changes)
                    {
                        MessageBox.Show("Some outdated events have been removed.");
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Problem with opening events. Created new, empty file.");
                File.Create(xmlDirectoryPath);
            }
            foreach (var item in Events)
            {
                if (string.IsNullOrEmpty(item.ProjectTitle))
                {
                    string x = item.EventDesc;
                    foreach (var y in Projects)
                    {
                        if (x == y.Title)
                        {
                            item.ProjectTitle    = y.Title;
                            item.ProjectDuty     = y.Duty;
                            item.ProjectCreator  = y.Creator;
                            item.ProjectDeadLine = y.DeadLine;
                            item.Project         = y;
                        }
                    }
                }
                else
                {
                    string x = item.EventDesc;
                    foreach (var y in Projects)
                    {
                        if (x == y.Title)
                        {
                            item.Project = y;
                        }
                    }
                }
            }

            if (Events.Count > 0 && Events != null)
            {
                SelectedEvent = Events[0];
            }
        }