コード例 #1
0
        public clsChessClubMeeting GetPreviousMeetingFromDataStore(DateTime meetingDate)
        {
            try
            {
                clsSettings settings = LoadSettingsFromDataStore();

                DateTime previousMeetingDate = new DateTime(1900, 1, 1);

                foreach (DateTime date in settings.meetingDates)
                {
                    if ((date > previousMeetingDate) && (date < meetingDate))
                    {
                        previousMeetingDate = date;
                    }
                }

                return(GetMeetingByDate(previousMeetingDate));
            }
            catch (Exception ex)
            {
                frmMessage messageForm = new frmMessage();
                messageForm.SetMessageText("Error getting previous meeting info: " + ex.Message);
                messageForm.ShowDialog();
                return(null);
            }
        }
コード例 #2
0
        public bool SaveSettingsToDataStore(clsSettings appSettings)
        {
            try
            {
                if (System.IO.Directory.Exists(GetCurrentYearSettingsDirectory()) == false)
                {
                    System.IO.Directory.CreateDirectory(GetCurrentYearSettingsDirectory());
                }

                using (System.IO.FileStream fs = new System.IO.FileStream(GetCurrentYearSettingsFile(), System.IO.FileMode.Create))
                {
                    XmlSerializer s = new XmlSerializer(appSettings.GetType());
                    s.Serialize(fs, appSettings);
                    fs.Close();
                }
            }
            catch (Exception ex)
            {
                frmMessage messageForm = new frmMessage();
                messageForm.SetMessageText("Error saving settings: " + ex.Message);
                messageForm.ShowDialog();
                return(false);
            }

            return(true);
        }
コード例 #3
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);
        }
コード例 #4
0
        public clsSettings LoadSettingsFromDataStore()
        {
            clsSettings appSettings = new clsSettings();

            try
            {
                System.IO.FileStream fs         = new System.IO.FileStream(GetCurrentYearSettingsFile(), System.IO.FileMode.Open, System.IO.FileAccess.Read);
                XmlSerializer        serializer = new XmlSerializer(typeof(clsSettings));
                appSettings = (clsSettings)serializer.Deserialize(fs);
                fs.Close();
            }
            catch (Exception ex)
            {
                frmMessage messageForm = new frmMessage();
                messageForm.SetMessageText("Error loading settings: " + ex.Message);
                messageForm.ShowDialog();
            }

            return(appSettings);
        }