Exemple #1
0
        // Copy timetable information from currently selected week to another one
        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Create CopyForm.
            CopyForm f = new CopyForm();

            // If user have selected a new week
            if (f.ShowDialog() == DialogResult.OK)
            {
                DateTime weekStart = c1Schedule1.SelectedDates[0];

                DateTime newWeekStart = f.Date.Date;
                while (newWeekStart.DayOfWeek != c1Schedule1.CalendarInfo.WeekStart)
                {
                    newWeekStart = newWeekStart.AddDays(-1);
                }

                if (newWeekStart == weekStart)
                {
                    // don't copy if user selected the same week
                    return;
                }

                // A days number to add to the Appointment.Start value
                int days = ((TimeSpan)(newWeekStart - weekStart)).Days;

                // Get all current week Appointments
                AppointmentList list = c1Schedule1.DataStorage.AppointmentStorage.Appointments.GetOccurrences(
                    weekStart, weekStart.AddDays(7));

                // For each current week Appointment, create a new one for the selected week
                foreach (Appointment app in list)
                {
                    // Create new Appointment
                    Appointment newApp = new Appointment();
                    // Copy properties from the existent one
                    newApp.CopyFrom(app, false);
                    // Change start time
                    newApp.Start = newApp.Start.AddDays(days);
                    // Add new Appointment to AppointmentStorage
                    c1Schedule1.DataStorage.AppointmentStorage.Appointments.Add(newApp);
                }
            }
        }
Exemple #2
0
        // Copy timetable information from currently selected day to another one
        private void copyDayToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Create CopyForm
            CopyForm f = new CopyForm();

            f._message.Text = "Select a day for copy to (choose one)";
            f.Text          = "Select Day";

            // If user have selected a new day
            if (f.ShowDialog() == DialogResult.OK)
            {
                DateTime originalDate = c1Schedule1.CurrentDate.Date;

                DateTime newDate = f.Date.Date;

                if (newDate == originalDate)
                {
                    // don't copy if user selected the same day
                    return;
                }

                // A days number to add to the Appointment.Start value
                int days = ((TimeSpan)(newDate - originalDate)).Days;

                // Get all current day Appointments
                AppointmentList list = c1Schedule1.DataStorage.AppointmentStorage.Appointments.GetOccurrences(
                    originalDate, originalDate.AddDays(1));

                // For each current day Appointment, create a new one for the selected day
                foreach (Appointment app in list)
                {
                    // Create new Appointment
                    Appointment newApp = new Appointment();
                    // Copy properties from the existent one
                    newApp.CopyFrom(app, false);
                    // Change start time
                    newApp.Start = newApp.Start.AddDays(days);
                    // Add new Appointment to AppointmentStorage
                    c1Schedule1.DataStorage.AppointmentStorage.Appointments.Add(newApp);
                }
            }
        }