// Set date range tags in a separate method, as it might
        // be useful to set them before editing style in print setup forms.
        internal void SetDateRangeTags(C1PrintDocument printDoc, DateTime start, DateTime end)
        {
            Tag           tag  = null;
            TagCollection Tags = printDoc.Tags;

            if ((Context & PrintContextType.DateRange) != 0)
            {
                if (Tags.IndexOfName("StartDate") >= 0)
                {
                    tag = Tags["StartDate"];
                    if (tag != null && tag.Type == typeof(DateTime))
                    {
                        tag.Value = start;
                    }
                }
                if (Tags.IndexOfName("EndDate") >= 0)
                {
                    tag = Tags["EndDate"];
                    if (tag != null && tag.Type == typeof(DateTime))
                    {
                        tag.Value = end;
                    }
                }
            }
        }
        // Use this method to set all tags at document starting.
        // Note: start and end parameters are just default values.
        // If document contains StartDate and EndDate tags,
        // actual start and end values go from the tags.
        internal void SetupTags(C1PrintDocument printDoc, AppointmentCollection appointmentCollection,
                                List <Appointment> appointmentList, DateTime start, DateTime end, bool hidePrivateAppointments, CalendarInfo calendarInfo)
        {
            Tag           tag  = null;
            TagCollection Tags = printDoc.Tags;

            if (Tags.IndexOfName("Appointment") >= 0)
            {
                tag = Tags["Appointment"];
                if (tag != null && tag.Type == typeof(Appointment) &&
                    appointmentList != null && appointmentList.Count > 0)
                {
                    tag.Value = appointmentList[0];
                }
            }
            if (Tags.IndexOfName("Appointments") >= 0)
            {
                tag = Tags["Appointments"];
                if (tag != null)
                {
                    if (tag.Type == typeof(AppointmentCollection))
                    {
                        tag.Value = appointmentCollection;
                    }
                    else if (tag.Type == typeof(IList <Appointment>))
                    {
                        if ((Context & PrintContextType.Appointment) != 0 &&
                            appointmentList != null)
                        {
                            appointmentList.Sort(AppointmentComparer.Default);
                            tag.Value = appointmentList;
                        }
                        else
                        {
                            Tag tag1 = null;
                            if (Tags.IndexOfName("StartDate") >= 0)
                            {
                                tag1 = Tags["StartDate"];
                                if (tag1 != null && tag1.Type == typeof(DateTime))
                                {
                                    start = (DateTime)tag1.Value;
                                }
                            }
                            if (Tags.IndexOfName("EndDate") >= 0)
                            {
                                tag1 = Tags["EndDate"];
                                if (tag1 != null && tag1.Type == typeof(DateTime))
                                {
                                    end = (DateTime)tag1.Value;
                                }
                            }
                            C1Scheduler scheduler = ((C1ScheduleStorage)appointmentCollection.ParentStorage.ScheduleStorage).Scheduler;
                            // get appointments for the currently selected SchedulerGroupItem if any,
                            // or all appointments otherwise.
                            AppointmentList list = appointmentCollection.GetOccurrences(
                                scheduler.SelectedGroupItem == null ? null : scheduler.SelectedGroupItem.Owner,
                                scheduler.GroupBy, start, end.AddDays(1), !hidePrivateAppointments);
                            list.Sort();
                            tag.Value = list;
                        }
                    }
                }
            }
            if (Tags.IndexOfName("CalendarInfo") >= 0)
            {
                tag = Tags["CalendarInfo"];
                if (tag != null && tag.Type == typeof(CalendarInfo))
                {
                    tag.Value = calendarInfo;
                }
            }
            if (Tags.IndexOfName("HidePrivateAppointments") >= 0)
            {
                tag = Tags["HidePrivateAppointments"];
                if (tag != null && tag.Type == typeof(bool))
                {
                    tag.Value = hidePrivateAppointments;
                }
            }
            // update string tags
            foreach (Tag t in Tags)
            {
                if (t.Type == typeof(string))
                {
                    string key = t.Name.ToLower();
                    switch (key)
                    {
                    case "start":
                        key = "startTime";
                        break;

                    case "end":
                        key = "endTime";
                        break;

                    case "showtimeas":
                        key = "showTimeAs";
                        break;

                    case "contacts":
                        key = "contactsButton";
                        break;

                    case "resources":
                        key = "resourcesButton";
                        break;

                    case "categories":
                        key = "categoriesButton";
                        break;
                    }
                    if (!string.IsNullOrEmpty(key))
                    {
                        // try find localized value from the Scheduler resources
                        string str = C1.WPF.Localization.C1Localizer.GetString("EditAppointment", key, (string)t.Value).Trim();
                        if (!string.IsNullOrEmpty(str))
                        {
                            while (str.EndsWith("."))
                            {
                                str = str.Substring(0, str.Length - 1);
                            }
                            if (!str.EndsWith(":"))
                            {
                                str += ":";
                            }
                            t.Value = str;
                        }
                    }
                }
            }
        }