// adds assembly references and initializes document tags
        private void _printDoc_DocumentStarting(object sender, EventArgs e)
        {
            // add references needed for document scripts execution
            _printDoc.ScriptingOptions.ExternalAssemblies.Add(Assembly.GetAssembly(typeof(C1.WPF.Schedule.C1Scheduler)).Location);
            _printDoc.ScriptingOptions.ExternalAssemblies.Add("WindowsBase.dll");
            string path = Assembly.GetAssembly(typeof(System.Windows.Media.Color)).Location;

            _printDoc.ScriptingOptions.ExternalAssemblies.Add(path);

            path = Assembly.GetAssembly(typeof(System.Collections.Specialized.INotifyCollectionChanged)).Location;
            _printDoc.ScriptingOptions.ExternalAssemblies.Add(path);

            // initialize document tags
            DateTime start = Scheduler.VisibleDates[0];
            DateTime end   = Scheduler.VisibleDates[Scheduler.VisibleDates.Count - 1];

            Tag tag = _printDoc.Tags["StartDate"];

            if (tag != null && tag.Type == typeof(DateTime))
            {
                tag.Value = start;
            }
            tag = _printDoc.Tags["EndDate"];
            if (tag != null && tag.Type == typeof(DateTime))
            {
                tag.Value = end;
            }

            // show tag input form to user
            _printDoc.EditTags();

            tag = _printDoc.Tags["StartDate"];
            if (tag != null && tag.Type == typeof(DateTime))
            {
                start = (DateTime)tag.Value;
            }
            tag = _printDoc.Tags["EndDate"];
            if (tag != null && tag.Type == typeof(DateTime))
            {
                end = (DateTime)tag.Value;
            }

            tag = _printDoc.Tags["Appointment"];
            if (tag != null && tag.Type == typeof(Appointment) && Scheduler.SelectedAppointment != null)
            {
                tag.Value = Scheduler.SelectedAppointment;
            }

            tag = _printDoc.Tags["CalendarInfo"];
            if (tag != null && tag.Type == typeof(CalendarInfo))
            {
                tag.Value = Scheduler.CalendarHelper.Info;
            }

            tag = _printDoc.Tags["Appointments"];
            if (tag != null)
            {
                if (tag.Type == typeof(AppointmentCollection))
                {
                    tag.Value = Scheduler.DataStorage.AppointmentStorage.Appointments;
                }
                else if (tag.Type == typeof(IList <Appointment>))
                {
                    bool isAppointmentContext = _printDoc.DocumentFileName.Contains("Memo") || _printDoc.DocumentFileName.Contains("Details");
                    if (isAppointmentContext && Scheduler.SelectedAppointment != null)
                    {
                        List <Appointment> list = new List <Appointment>();
                        list.Add(Scheduler.SelectedAppointment);
                        tag.Value = list;
                    }
                    else
                    {
                        // get appointments for the currently selected SchedulerGroupItem if any,
                        // or all appointments otherwise.
                        AppointmentList list = Scheduler.DataStorage.AppointmentStorage.Appointments.GetOccurrences(
                            Scheduler.SelectedGroupItem == null ? null : Scheduler.SelectedGroupItem.Owner,
                            Scheduler.GroupBy, start, end.AddDays(1), true);
                        list.Sort();
                        tag.Value = list;
                    }
                }
            }
        }
Exemple #2
0
        // adds assembly references and initializes document tags
        private void _printDoc_DocumentStarting(object sender, EventArgs e)
        {
            // add references needed for document scripts execution
            _printDoc.ScriptingOptions.ExternalAssemblies.Add(System.Reflection.Assembly.GetAssembly(typeof(C1Schedule)).Location);

            // initialize document tags
            DateTime start = c1Schedule1.SelectedDates[0].Date;
            DateTime end   = c1Schedule1.SelectedDates[c1Schedule1.SelectedDates.Length - 1].Date;

            Tag tag = _printDoc.Tags["StartDate"];

            if (tag != null && tag.Type == typeof(DateTime))
            {
                tag.Value = start;
            }
            tag = _printDoc.Tags["EndDate"];
            if (tag != null && tag.Type == typeof(DateTime))
            {
                tag.Value = end;
            }

            // show tag input form to user
            _printDoc.EditTags();

            tag = _printDoc.Tags["StartDate"];
            if (tag != null && tag.Type == typeof(DateTime))
            {
                start = (DateTime)tag.Value;
            }
            tag = _printDoc.Tags["EndDate"];
            if (tag != null && tag.Type == typeof(DateTime))
            {
                end = (DateTime)tag.Value;
            }

            tag = _printDoc.Tags["Appointment"];
            if (tag != null && tag.Type == typeof(Appointment) && c1Schedule1.SelectedAppointments != null && c1Schedule1.SelectedAppointments.Count > 0)
            {
                tag.Value = c1Schedule1.SelectedAppointments[0];
            }

            tag = _printDoc.Tags["CalendarInfo"];
            if (tag != null && tag.Type == typeof(CalendarInfo))
            {
                tag.Value = c1Schedule1.CalendarInfo;
            }

            tag = _printDoc.Tags["Appointments"];
            if (tag != null)
            {
                if (tag.Type == typeof(AppointmentCollection))
                {
                    tag.Value = c1Schedule1.DataStorage.AppointmentStorage.Appointments;
                }
                else if (tag.Type == typeof(IList <Appointment>))
                {
                    bool isAppointmentContext = _printDoc.DocumentFileName.Contains("Memo") || _printDoc.DocumentFileName.Contains("Details");
                    if (isAppointmentContext && c1Schedule1.SelectedAppointments != null && c1Schedule1.SelectedAppointments.Count > 0)
                    {
                        tag.Value = c1Schedule1.SelectedAppointments;
                    }
                    else
                    {
                        // get appointments for the currently selected SchedulerGroupItem if any,
                        // or all appointments otherwise.
                        AppointmentList list = c1Schedule1.DataStorage.AppointmentStorage.Appointments.GetOccurrences(
                            c1Schedule1.SelectedGroupItem == null ? null : c1Schedule1.SelectedGroupItem.Owner,
                            c1Schedule1.GroupBy, start, end.AddDays(1), true);
                        list.Sort();
                        tag.Value = list;
                    }
                }
            }
        }