示例#1
0
        public clsChallengeGameList LoadAllGamesFromDataStore()
        {
            clsChallengeGameList allGames = new clsChallengeGameList();

            try
            {
                allGames.AddRange(LoadOutsideGamesFromDataStore());

                if (System.IO.Directory.Exists(GetCurrentYearMeetingDirectory()) == true)
                {
                    string[] fileList = System.IO.Directory.GetFiles(GetCurrentYearMeetingDirectory());
                    foreach (string filePath in fileList)
                    {
                        string fileName = System.IO.Path.GetFileNameWithoutExtension(filePath);
                        if (fileName.Contains(GamesFile))
                        {
                            clsChessClubMeeting retrievedMeeting = LoadMeeting_XML(filePath);
                            allGames.AddRange(retrievedMeeting.listChallengeGames);
                        }
                    }
                }
                return(allGames);
            }
            catch (Exception ex)
            {
                frmMessage messageForm = new frmMessage();
                messageForm.SetMessageText("Error loading all challenge games: " + ex.Message);
                messageForm.ShowDialog();
                return(new clsChallengeGameList());
            }
        }
示例#2
0
        public bool SaveMeetingToDataStore(clsChessClubMeeting meetingToSave)
        {
            bool   returnValue = true;
            string fileName    = GetCurrentYearMeetingDirectory() + MeetingsFile + meetingToSave.MeetingDate.ToShortDateString() + ".xml";

            fileName = fileName.Replace("/", "-");
            string backupFileName = GetCurrentYearMeetingBackupDirectory() + MeetingsFile + meetingToSave.MeetingDate.ToShortDateString() + ".xml";

            backupFileName = backupFileName.Replace("/", "-");
            try
            {
                if (System.IO.Directory.Exists(GetCurrentYearMeetingBackupDirectory()) == false)
                {
                    Directory.CreateDirectory(GetCurrentYearMeetingBackupDirectory());
                }
                else if (System.IO.File.Exists(fileName) == true)
                {
                    if (System.IO.File.Exists(backupFileName) == true)
                    {
                        System.IO.File.Delete(backupFileName);
                    }
                    System.IO.File.Move(fileName, backupFileName);
                }

                if (System.IO.Directory.Exists(GetCurrentYearMeetingDirectory()) == false)
                {
                    System.IO.Directory.CreateDirectory(GetCurrentYearMeetingDirectory());
                }
            }
            catch (Exception ex)
            {
                frmMessage messageForm = new frmMessage();
                messageForm.SetMessageText("Error backing up club meeting: " + ex.Message);
                messageForm.ShowDialog();
                returnValue = false;
            }

            if (SaveMeeting_XML(meetingToSave, fileName) == false)
            {
                returnValue = false;
            }

            try
            {
                clsSettings settings = LoadSettingsFromDataStore();
                if (!settings.meetingDates.Contains(meetingToSave.MeetingDate))
                {
                    settings.meetingDates.Add(meetingToSave.MeetingDate);
                    SaveSettingsToDataStore(settings);
                }
            }
            catch (Exception ex)
            {
                frmMessage messageForm = new frmMessage();
                messageForm.SetMessageText("Error updating meeting list in settings: " + ex.Message);
                messageForm.ShowDialog();
                returnValue = false;
            }
            return(returnValue);
        }
示例#3
0
        private clsChessClubMeeting LoadMeeting_XML(string filePath)
        {
            try
            {
                System.IO.FileStream fs               = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                XmlSerializer        serializer       = new XmlSerializer(typeof(clsChessClubMeeting));
                clsChessClubMeeting  retrievedMeeting = (clsChessClubMeeting)serializer.Deserialize(fs);
                fs.Close();
                return(retrievedMeeting);
            }
            catch (Exception ex)
            {
                frmMessage messageForm = new frmMessage();
                messageForm.SetMessageText("Error loading club meetings: " + ex.Message);
                messageForm.ShowDialog();
            }

            return(null);
        }
示例#4
0
 public clsChessClubMeeting GetMeetingByDate(DateTime meetingDate)
 {
     if (System.IO.Directory.Exists(GetCurrentYearMeetingDirectory()) == true)
     {
         string[] fileList = System.IO.Directory.GetFiles(GetCurrentYearMeetingDirectory());
         foreach (string filePath in fileList)
         {
             string fileName   = System.IO.Path.GetFileNameWithoutExtension(filePath);
             string dateString = meetingDate.ToShortDateString();
             dateString = dateString.Replace("/", "-");
             string ext = System.IO.Path.GetExtension(filePath);
             if (fileName.Contains(dateString) && ext.Equals(".xml"))
             {
                 clsChessClubMeeting retrievedMeeting = LoadMeeting_XML(filePath);
                 return(retrievedMeeting);
             }
         }
     }
     return(null);
 }
示例#5
0
        private bool SaveMeeting_XML(clsChessClubMeeting meetingToSave, string filepath)
        {
            try
            {
                using (System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.Create))
                {
                    XmlSerializer s = new XmlSerializer(meetingToSave.GetType());
                    s.Serialize(fs, meetingToSave);
                    fs.Close();
                }
            }
            catch (Exception ex)
            {
                frmMessage messageForm = new frmMessage();
                messageForm.SetMessageText("Error saving club meeting info: " + ex.Message);
                messageForm.ShowDialog();
                return(false);
            }

            return(true);
        }