El primer obstaculo es conseguir una interface muy similar a la que el usuario esta acostumbrado: tenemos 2 opciones:
Contact Selector
People Selector
De ambas opciones yo prefiero el people selector, porque ya nativo del Sharepoint.
Haremos un webpart, usando el template que nos proporciona WSPBuilder, herramienta que podemos descargar de codeplex.
Crearemos un proyecto Provider que sera nuestro People Selector y un Consumer que solo sera demostrativo.
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint.WebPartPages;
using System.Web.UI.WebControls;
using System.Collections.ObjectModel;
using Microsoft.SharePoint.WebControls;
namespace FilterProvider
{
[Guid("5a74bba3-4f58-46b2-a988-401ecc3ecf58")]
public class FilterProvider : Microsoft.SharePoint.WebPartPages.WebPart, ITransformableFilterValues
{
private bool _error = false;
private PeopleEditor _PeopleEditor;
private Button _Button;
public FilterProvider()
{
this.ExportMode = WebPartExportMode.All;
}
///
/// Create all your controls here for rendering.
/// Try to avoid using the RenderWebPart() method.
///
protected override void CreateChildControls()
{
if (!_error)
{
try
{
base.CreateChildControls();
_PeopleEditor = new PeopleEditor();
_PeopleEditor.MultiSelect = true;
_PeopleEditor.AutoPostBack = false;
_Button = new Button();
_Button.Text = "Consultar Datos";
_Button.Click += new EventHandler(_Button_Click);
this.Controls.Add(_PeopleEditor);
this.Controls.Add(_Button);
// Your code here...
this.Controls.Add(new LiteralControl(this.MyProperty));
}
catch (Exception ex)
{
HandleException(ex);
}
}
}
///
/// Ensures that the CreateChildControls() is called before events.
/// Use CreateChildControls() to create your controls.
///
///
protected void _Button_Click(object sender, EventArgs e)
{
Listpeople = new List ();
for (int i = 0; i <>
/// Clear all child controls and add an error message for display.
///
///
private void HandleException(Exception ex)
{
this._error = true;
this.Controls.Clear();
this.Controls.Add(new LiteralControl(ex.Message));
}
[ConnectionProvider("People", "UniqueIDForPeopleConnection", AllowsMultipleConnections = true)]
public ITransformableFilterValues SetConnection() { return this; }
#region Miembros de ITransformableFilterValues
bool ITransformableFilterValues.AllowAllValue
{
get { return true; }
}
bool ITransformableFilterValues.AllowEmptyValue
{
get { return false; }
}
bool ITransformableFilterValues.AllowMultipleValues
{
get { return true; }
}
string ITransformableFilterValues.ParameterName
{
get { return "People"; }
}
System.Collections.ObjectModel.ReadOnlyCollectionITransformableFilterValues.ParameterValues
{
get {
EnsureChildControls();
Listpeople = new List ();
for (int i = 0; i <> result = new ReadOnlyCollection(people);
return result;
}
}
#endregion
}
}
De todo esto lo mas interensate es:
017 private PeopleEditor _PeopleEditor;
Que nos permite reutilizar visual y funcionalmente el control People Editor que nos proporciona Sharepoint para sus columnas tipo Person/Group
077 [ConnectionProvider("People", "UniqueIDForPeopleConnection", AllowsMultipleConnections = true)]
078 public ITransformableFilterValues SetConnection() { return this; }
102 System.Collections.ObjectModel.ReadOnlyCollection
Estas funciones permite dar la funcionalidad de Filtro a nuestro WebPart.
En este caso hemos hecho un filtro multi valores, segun las necesidades puede ser modificado.
Ahora el Consumer.
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint.WebPartPages;
namespace FilterConsumer
{
[Guid("b9e3fb99-7c6b-4386-b7c1-5fcc37f01740")]
public class FilterConsumer : Microsoft.SharePoint.WebPartPages.WebPart
{
private bool _error = false;
private List_filterProviders;
private ListFilterProviders {
get
{
return _filterProviders;
}
}
public FilterConsumer()
{
_filterProviders = new List();
}
///
/// Create all your controls here for rendering.
/// Try to avoid using the RenderWebPart() method.
///
protected override void CreateChildControls()
{
if (!_error)
{
try
{
base.CreateChildControls();
// Your code here...
this.Controls.Add(new LiteralControl(this.MyProperty));
}
catch (Exception ex)
{
HandleException(ex);
}
}
}
///
/// Ensures that the CreateChildControls() is called before events.
/// Use CreateChildControls() to create your controls.
///
///
protected override void OnLoad(EventArgs e)
{
if (!_error)
{
try
{
base.OnLoad(e);
this.EnsureChildControls();
// Your code here...
}
catch (Exception ex)
{
HandleException(ex);
}
}
}
///
/// Clear all child controls and add an error message for display.
///
///
private void HandleException(Exception ex)
{
this._error = true;
this.Controls.Clear();
this.Controls.Add(new LiteralControl(ex.Message));
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
foreach (IFilterValues filter in FilterProviders)
{ writer.WriteLine(string.Format("Parameter: {0}
", filter.ParameterName));
if (filter.ParameterValues != null)
{
foreach (string value in filter.ParameterValues)
if (!string.IsNullOrEmpty(value))
writer.WriteLine(string.Format(" value: {0}
", value));
}
}
base.Render(writer);
}
[ConnectionConsumer("filter", "UniqueIDForConsumer", AllowsMultipleConnections = true)]
public void SetFilter(IFilterValues filterValues) {
if (filterValues != null) {
EnsureChildControls();
Listparameters = new List ();
parameters.Add(new ConsumerParameter("People", ConsumerParameterCapabilities.SupportsMultipleValues | ConsumerParameterCapabilities.SupportsAllValue));
//parameters.Add(new ConsumerParameter("Status", ConsumerParameterCapabilities.SupportsMultipleValues | ConsumerParameterCapabilities.SupportsAllValue));
filterValues.SetConsumerParameters(new System.Collections.ObjectModel.ReadOnlyCollection(parameters));
this.FilterProviders.Add(filterValues);
}
}
}
}
De igual manera tenemos que recuperar los datos que el provider nos envia.
100 [ConnectionConsumer("filter", "UniqueIDForConsumer", AllowsMultipleConnections = true)]
101 public void SetFilter(IFilterValues filterValues)
Finalmente deberiamos obtener algo como esto:
No hay comentarios:
Publicar un comentario