This is a migrated thread and some comments may be shown as answers.

ScheduleView Filtering

8 Answers 211 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Tarcisis
Top achievements
Rank 1
Tarcisis asked on 28 Mar 2011, 12:04 PM
Hi,

I want to do somenthing like you have in the example - ScheduleView - First Look. I will have several tabs (CustomViewDefinition), and a few of appointments. And when a click in a tab, i want to filter the appointments by the type of the game, ie, by the tab that i selected.
xaml:

<schedule:RadScheduleView Grid.Row="1"
                       x:Name="radScheduleView"
                                                     AppointmentsSource="{Binding Appointments}"
                                                     Template="{StaticResource RadScheduleViewControlTemplate}"
                                                     BorderBrush="{x:Null}"
                                                     Background="{StaticResource ScheduleViewBackground}">
</schedule:RadScheduleView>

MainPage.cs
private void FillScheduler()
{
 
    ScheduleViewModel cal = new ScheduleViewModel();
    radScheduleView.ViewDefinitions.AddRange(cal.GenerateViewsEncartes());
 
    ResourceTypeCollection collectionTypeEncartes = new ResourceTypeCollection();
    ResourceType encartes = new ResourceType("Games");
    encartes.Resources.AddRange(cal.GenerateResources());
    collectionTypeEncartes.Add(encartes);
    radScheduleView.ResourceTypesSource = collectionTypeEncartes;
    radScheduleView.DataContext = new ScheduleViewModel();
 
}



ScheduleViewModel:
public class ScheduleViewModel : ViewModelBase
{
    private Func<object, bool> groupFilter;
    private ObservableCollection<Etapa> appointments;
    private ObservableCollection<Resource> resources;
    private ObservableCollection<MonthViewDefinition> viewsDefinitions;
    private ObservableCollection<Category> categories;
 
    public ObservableCollection<Resource> Resources
    {
        get
        {
            return this.resources;
        }
        set
        {
            this.resources = value;
        }
    }
    public ObservableCollection<Etapa> Appointments
    {
        get
        {
            return this.appointments;
 
        }
        set
        {
            this.appointments = value;
 
        }
    }
    public ObservableCollection<MonthViewDefinition> ViewsDefinitions
    {
        get
        {
            return this.viewsDefinitions;
        }
        set
        {
            this.viewsDefinitions = value;
        }
    }
    public ObservableCollection<Category> Categories
    {
        get
        {
            return this.categories;
        }
        set
        {
            this.categories = value;
        }
    }
    public ScheduleViewModel()
    {
        //this.viewsDefinitions = this.GenerateViewsEncartes();
        this.categories = this.GenerateCategories();
        //this.resources = this.GenerateResources();
        this.appointments = this.GenerateEvents();
        this.groupFilter = new Func<object, bool>(this.GroupFilterFunc);
    }
    public ObservableCollection<Etapa> GenerateEvents()
    {
        RadScheduleView radScheduleView = new RadScheduleView();
        ObservableCollection<Etapa> result = new ObservableCollection<Etapa>();
 
        int month = DateTime.Now.Month;
        DateTime mondayDate = CalendarHelper.GetFirstDayOfWeek(DateTime.Today, DayOfWeek.Monday);
        DateTime satDate = CalendarHelper.GetFirstDayOfWeek(DateTime.Today, DayOfWeek.Saturday);
        DateTime lastsundayDate = CalendarHelper.GetEndOfMonth(DateTime.Today);
 
        Etapa encarte1 = new Etapa();
        encarte1.Subject = "Tennis";
        encarte1.Encarte = "Tennis";
        encarte1.Body = "";
        encarte1.Category = FindCategory(categories, "Validade");
        encarte1.Start = mondayDate.AddHours(11).AddMinutes(15);
        encarte1.End = mondayDate.AddHours(12).AddMinutes(20);
        Resource etapa1 = new Resource();
        etapa1.ResourceName = "Tennis";
        etapa1.ResourceType = "Games";
        encarte1.Resources.Add(etapa1);
        result.Add(encarte1);
 
        Etapa encarte2 = new Etapa();
        encarte2.Encarte = "Football";
        encarte2.Subject = "Football";
        encarte2.Category = FindCategory(categories, "Recebimento");
        encarte2.Body = "";
        encarte2.Start = mondayDate.AddHours(15);
        encarte2.End = mondayDate.AddHours(16).AddMinutes(15);
        Resource etapa2 = new Resource();
        etapa2.ResourceName = "Football";
        etapa2.ResourceType = "Games";
        encarte2.Resources.Add(etapa2);
        result.Add(encarte2);
 
        Etapa encarte3 = new Etapa();
        encarte3.Encarte = "Golf";
        encarte3.Subject = "Golf";
        encarte3.Category = FindCategory(categories, "Recebimento");
        encarte3.Body = "";
        encarte3.Start = mondayDate.AddHours(15);
        encarte3.End = mondayDate.AddHours(16).AddMinutes(15);
        Resource etapa3 = new Resource();
        etapa3.ResourceName = "Golf";
        etapa3.ResourceType = "Games";
        encarte3.Resources.Add(etapa3);
        result.Add(encarte3);
 
        return result;
    }
    #region Generate Views (Encartes)
    public ObservableCollection<EncartesViewDefinition> GenerateViewsEncartes()
    {
 
        ObservableCollection<EncartesViewDefinition> result = new ObservableCollection<EncartesViewDefinition>();
 
        EncartesViewDefinition encarte = new EncartesViewDefinition();
        encarte.Title = "Tennis";
        encarte.GroupFilter = GroupFilter;
        ResourceGroupDescription resourceGroupDescription = new ResourceGroupDescription();
        resourceGroupDescription.ResourceType = "Games";
        encarte.GroupDescriptions.Add(resourceGroupDescription);
        result.Add(encarte);
 
        encarte = new EncartesViewDefinition();
        encarte.GroupFilter = GroupFilter;
        encarte.Title = "Football";
        ResourceGroupDescription resourceGroupDescription2 = new ResourceGroupDescription();
        resourceGroupDescription2.ResourceType = "Games";
        encarte.GroupDescriptions.Add(resourceGroupDescription2);
        result.Add(encarte);
 
        encarte = new EncartesViewDefinition();
        encarte.Title = "Golf";
        encarte.GroupFilter = GroupFilter;
        ResourceGroupDescription resourceGroupDescription3 = new ResourceGroupDescription();
        resourceGroupDescription3.ResourceType = "Games";
        encarte.GroupDescriptions.Add(resourceGroupDescription3);
        result.Add(encarte);
 
        return result;
    }
    #endregion
    #region Resources
    public ResourceCollection GenerateResources()
    {
        ResourceCollection result = new ResourceCollection();
 
        Resource encarte1 = new Resource("Tennis");
        Resource encarte2 = new Resource("Football");
        Resource encarte3 = new Resource("Golf");
         
        result.Add(encarte1);
        result.Add(encarte2);
        result.Add(encarte3);
 
 
        return result;
    }
    #endregion
    #region Categories
    public ObservableCollection<Category> GenerateCategories()
    {
 
        ObservableCollection<Category> result = new ObservableCollection<Category>();
 
        Category category = new Category();
        category.DisplayName = "Envio da Lista";
        category.CategoryName = "EnvioLista";
        category.CategoryBrush = GetBrushFromHexString("#FF417542");
        result.Add(category);
 
        category = new Category();
        category.DisplayName = "Conferência";
        category.CategoryName = "Conferência";
        category.CategoryBrush = GetBrushFromHexString("#FF0465B3");
        result.Add(category);
 
        category = new Category();
        category.DisplayName = "Sessão de Fotos";
        category.CategoryName = "Sessão";
        category.CategoryBrush = GetBrushFromHexString("#FF973FA8");
        result.Add(category);
 
        category = new Category();
        category.DisplayName = "Diagramação/Tratamento Fotos";
        category.CategoryName = "Diagramação";
        category.CategoryBrush = GetBrushFromHexString("#FFE69E07");
        result.Add(category);
 
        category = new Category();
        category.DisplayName = "Conferência - Bureau";
        category.CategoryName = "ConferênciaBureau";
        category.CategoryBrush = GetBrushFromHexString("#FFE74220");
        result.Add(category);
 
        category = new Category();
        category.DisplayName = "Conferência - Comercial";
        category.CategoryName = "ConferênciaComercial";
        category.CategoryBrush = GetBrushFromHexString("#FFBD0037");
        result.Add(category);
 
        category = new Category();
        category.DisplayName = "Validação - Comercial";
        category.CategoryName = "ValidaçãoComercial";
        category.CategoryBrush = GetBrushFromHexString("#1FEF08");
        result.Add(category);
 
        category = new Category();
        category.DisplayName = "Fechamento de Arquivos";
        category.CategoryName = "FechamentoArquivos";
        category.CategoryBrush = GetBrushFromHexString("#56D1EF");
        result.Add(category);
 
        category = new Category();
        category.DisplayName = "Recebimento nas Lojas";
        category.CategoryName = "Recebimento";
        category.CategoryBrush = GetBrushFromHexString("#E0F80C");
        result.Add(category);
 
        category = new Category();
        category.DisplayName = "Validade do Material";
        category.CategoryName = "Validade";
        category.CategoryBrush = GetBrushFromHexString("#FC03DB");
        result.Add(category);
 
        return result;
    }
    #endregion
    #region Get Color From Hex
    public static SolidColorBrush GetBrushFromHexString(string aarrggbb)
    {
        String xamlString = "<Canvas xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" Background=\"" + aarrggbb + "\"/>";
        Canvas c = (Canvas)System.Windows.Markup.XamlReader.Load(xamlString);
        return (SolidColorBrush)c.Background;
    }
    #endregion
    #region Find Category
    private Category FindCategory(ObservableCollection<Category> all, string name)
    {
        Category selected = new Category();
 
        foreach (Category current in all)
        {
            if (current.CategoryName.Equals(name))
            {
                selected = current;
                break;
            }
 
        }
 
        return selected;
 
    }
    #endregion
    public Func<object, bool> GroupFilter
    {
        get
        {
            return this.groupFilter;
        }
        private set
        {
            this.groupFilter = value;
            this.OnPropertyChanged(() => this.GroupFilter);
        }
    }
    private void UpdateGroupFilter()
    {
        this.GroupFilter = new Func<object, bool>(this.GroupFilterFunc);
    }
    private List<string> teste { get; set; }
    private bool GroupFilterFunc(object groupName)
    {
 
        IResource resource = groupName as IResource;
 
        //The doubt is here!! In this function.....(next line doesn´t work)
        return resource == null ? true : resource.ResourceName =="";
 
 
    }
 
    private bool Filter(string resourceName)
    {
        bool filter = false;
 
        foreach (Etapa etapa in this.appointments) {
            if (etapa.Encarte == resourceName) filter=true;
         
        }
 
 
        return filter;
    }
 
}


EncartesViewDefinition:
public class EncartesViewDefinition : CustomViewDefinition
{
 
    public EncartesViewDefinition()
    {
        this.StretchGroupHeaders = true;
        this.VisibleDays = 7;
        this.LargeChangeInterval = DateTimeInterval.FromDays(7);
        this.GroupHeaderDateStringFormat = "{0:dd dddd}";
        this.Orientation = Orientation.Horizontal;
    }
 
    protected override string FormatVisibleRangeText(System.IFormatProvider formatInfo, System.DateTime rangeStart, System.DateTime rangeEnd, System.DateTime currentDate)
    {
        string format = rangeStart.Year == rangeEnd.Year ?
                        (rangeStart.Month == rangeEnd.Month ?
                        "{0:d } - {1:d MMMM yyyy}" :
                        "{0:d MMMM} - {1:d MMMM yyyy}") :
                        "{0:d MMMM yyyy} - {1:d MMMM yyyy}";
 
        return string.Format(formatInfo, format, rangeStart, rangeEnd);
    }
 
    protected override DateTime GetVisibleRangeStart(DateTime currentDate, CultureInfo culture, DayOfWeek? firstDayOfWeek)
    {
        if (culture == null)
        {
            culture = CultureInfo.InvariantCulture;
        }
 
        DayOfWeek dayOfWeek = firstDayOfWeek ?? culture.DateTimeFormat.FirstDayOfWeek;
 
        return CalendarHelper.GetFirstDayOfWeek(currentDate, dayOfWeek);
    }
 
    protected override DateTime GetVisibleRangeEnd(DateTime currentDate, CultureInfo culture, DayOfWeek? firstDayOfWeek)
    {
        if (culture == null)
        {
            culture = CultureInfo.InvariantCulture;
        }
 
        DayOfWeek dayOfWeek = firstDayOfWeek ?? culture.DateTimeFormat.FirstDayOfWeek;
        if (this.DayEndTime > this.DayStartTime)
        {
            return CalendarHelper.GetFirstDayOfWeek(currentDate, dayOfWeek).AddDays(this.VisibleDays - 1).Add(this.DayEndTime);
        }
 
        return CalendarHelper.GetFirstDayOfWeek(currentDate, dayOfWeek).AddDays(this.VisibleDays).Add(this.DayEndTime);
    }
 
}


Etapa.cs:
public class Etapa : Appointment
{
 
    private string encarte;
    public string Encarte
    {
        get
        {
 
            return this.Storage<Etapa>().encarte;
        }
        set
        {
            var storage = this.Storage<Etapa>();
            if (storage.encarte != value)
            {
                storage.encarte = value;
                this.OnPropertyChanged(() => this.encarte);
            }
        }
 
    }
 
    public override IAppointment Copy()
    {
        IAppointment appointment = new Etapa();
        appointment.CopyFrom(this);
        return appointment;
    }
    public override void CopyFrom(IAppointment other)
    {
        Etapa appointment = other as Etapa;
        if (appointment != null)
        {
            base.CopyFrom(other);
        }
 
    }
 
}


My doubt is in function :  private bool GroupFilterFunc(object groupName)!!
How do i apply the filter!!

Thanks

8 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 31 Mar 2011, 02:59 PM
Hello Tarcisis,

You should create a different GroupFilter for every ViewDefinition. I've attached a simple project based on your code to demonstrate the approach, please download it and examine it.

Regards,
Yana
the Telerik team
0
Tarcisis
Top achievements
Rank 1
answered on 04 Apr 2011, 02:03 PM
Hi,
Thanks for the answer!

You created distinct GroupFilter for each view.
How can i build that GroupFilters dynamically instead of create  private Func<object, bool> for each one?!? (Supose that comming from a DB)
Thanks
0
Tarcisis
Top achievements
Rank 1
answered on 04 Apr 2011, 05:52 PM
For example,

The types of games are coming from DB, so, i can´t create that filters "Hardcoded" , i need to create them in runtime.
Do you have any ideia?

Thanks
0
Tarcisis
Top achievements
Rank 1
answered on 05 Apr 2011, 10:40 AM
That´s why i used only one function...

        private bool GroupFilterFunc(object groupName)
        {

            IResource resource = groupName as IResource;
            return resource == null ? true : resource.ResourceName == **************;

        }

the "**************" means that here i want to know in which CustomViewDefinition did I click.

Thanks
0
Yana
Telerik team
answered on 07 Apr 2011, 03:39 PM
Hello Tarcisis,

You're right that having different GroupFilter functions is not the best solution.  The other option I can suggest is to use an additional parameter in GroupFilterFunc for the different views. I've attached the modified project to demonstrate the approach. Please download it and give it a try.

All the best,
Yana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Tarcisis
Top achievements
Rank 1
answered on 07 Apr 2011, 04:05 PM
Thanks!!
That´s it!!
0
Tarcisis
Top achievements
Rank 1
answered on 07 Apr 2011, 06:38 PM
Hi again,

One last question!
It is possible to use MonthViewDefinition instead of CustomViewDefinition??
I need to use the MonthViewDefinition , but with this kind of view i can´t add GroupDescriptions, and so it doesn´t filter!

Thanks.
0
Accepted
Yana
Telerik team
answered on 08 Apr 2011, 08:47 AM
Hello Tarcisis,

I suggest to set the GroupDescriptions to the ScheduleView, in this way you can use MonthViewDefinition with GroupFilter without a problem.

 You can find the modified project attached.

Kind regards,
Yana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ScheduleView
Asked by
Tarcisis
Top achievements
Rank 1
Answers by
Yana
Telerik team
Tarcisis
Top achievements
Rank 1
Share this question
or