Пример #1
0
        private void cmdChangeStartWeek_Click(object sender, EventArgs e)
        {
            // Find the first date.
            CalendarWeek objStart;
            try
            {
                 objStart = _objCharacter.Calendar.First();
            }
            catch
            {
                return;
            }

            frmSelectCalendarStart frmPickStart = new frmSelectCalendarStart(objStart);
            frmPickStart.ShowDialog(this);

            if (frmPickStart.DialogResult == DialogResult.Cancel)
                return;

            // Determine the difference between the starting value and selected values for year and week.
            int intYear = frmPickStart.SelectedYear;
            int intWeek = frmPickStart.SelectedWeek;
            int intYearDiff = intYear - objStart.Year;
            int intWeekDiff = intWeek - objStart.Week;

            // Update each of the CalendarWeek entries for the character.
            foreach (CalendarWeek objWeek in _objCharacter.Calendar)
            {
                objWeek.Week += intWeekDiff;
                objWeek.Year += intYearDiff;

                // If the date range goes outside of 52 weeks, increase or decrease the year as necessary.
                if (objWeek.Week < 1)
                {
                    objWeek.Year--;
                    objWeek.Week += 52;
                }
                if (objWeek.Week > 52)
                {
                    objWeek.Year++;
                    objWeek.Week -= 52;
                }
            }

            _blnIsDirty = true;
            UpdateWindowTitle();
            PopulateCalendar();
        }
Пример #2
0
        private void cmdAddWeek_Click(object sender, EventArgs e)
        {
            CalendarWeek objWeek = new CalendarWeek();
            try
            {
                objWeek.Year = _objCharacter.Calendar.Last().Year;
                objWeek.Week = _objCharacter.Calendar.Last().Week;
                objWeek.Week++;
                if (objWeek.Week > 52)
                {
                    objWeek.Week = 1;
                    objWeek.Year++;
                }
            }
            catch
            {
                objWeek = new CalendarWeek();
                frmSelectCalendarStart frmPickStart = new frmSelectCalendarStart();
                frmPickStart.ShowDialog(this);

                if (frmPickStart.DialogResult == DialogResult.Cancel)
                    return;

                objWeek.Year = frmPickStart.SelectedYear;
                objWeek.Week = frmPickStart.SelectedWeek;
            }

            _objCharacter.Calendar.Add(objWeek);

            PopulateCalendar();

            _blnIsDirty = true;
            UpdateWindowTitle();
        }