using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Drawing.Design;
using System.Drawing;
namespace WEBPART_annuaireGenepi
{
[Guid("4aac307b-f91e-4b05-a09c-df0c5130008a")]
public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
{
// DEFINITION DES composants "graphique" de la page
DataGrid mygrid = new DataGrid();
ButtonColumn mybut = new ButtonColumn();
TextBox byname = new TextBox();
TextBox byfonc = new TextBox();
TextBox lblMessage = new TextBox();
String topClicBouton = "";
Button boutnom = new Button();
Button boutfonc = new Button();
// instance du data context LINQ
DataClasses1DataContext ledatc = new DataClasses1DataContext();
public WebPart1()
{
this.ExportMode = WebPartExportMode.All;
}
public void critFoncSearchZone(object sender, EventArgs e)
{
topClicBouton = "F";
}
public void critNameSearchZone(object sender, EventArgs e)
{
topClicBouton = "N";
}
void mygrid_ItemCommand(object sender, DataGridCommandEventArgs e)
{
lblMessage.Width = 750;
lblMessage.Text = "Ligne a editer en page detail : " + e.Item.Cells[2].Text + " " + e.Item.Cells[3].Text;
}
protected override void CreateChildControls()
{
base.CreateChildControls();
// CONCEPTION DU TABLEAU haut
// entête
this.Controls.Add(new LiteralControl("<table cellspacing='3' cellpadding='5' align='center'>"));
// titre
this.Controls.Add(new LiteralControl("<tr>"));
this.Controls.Add(new LiteralControl("<td style='width:450px' colspan = 6>"));
this.Controls.Add(new LiteralControl("<B>Annuaire des Contacts GENEPI</B>"));
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("</tr>"));
// critères nom
this.Controls.Add(new LiteralControl("<tr>"));
this.Controls.Add(new LiteralControl("<td style='width:225px'>"));
this.Controls.Add(new LiteralControl("Par nom :"));
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(byname);
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("<td>"));
boutnom.Text = "ok";
boutnom.CausesValidation = true;
this.Controls.Add(boutnom);
this.Controls.Add(new LiteralControl("</td>"));
// critères fonction
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(new LiteralControl("<td style='width:225px'>"));
this.Controls.Add(new LiteralControl("Par fonction :"));
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(byfonc);
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(boutfonc);
boutfonc.CausesValidation = true;
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("</tr>"));
this.Controls.Add(new LiteralControl("</table>"));
// gestion des clicks sur les boutons noms ou fonctions
boutnom.Click += (critNameSearchZone);
boutfonc.Click += (critFoncSearchZone);
this.Controls.Add(new LiteralControl("<table cellspacing='3' cellpadding='5' align='center'>"));
this.Controls.Add(new LiteralControl("<tr>"));
this.Controls.Add(new LiteralControl("<td style='width:450px'>"));
if (topClicBouton == "N")
{
// Si on clique sur le bouton fonction, je veux utiliser la vue par defautl (nom)
mygrid.DataSource = ledatc.vueTestAlainPortailSharePoint_AnnuaireGenepi;
}
else
{
// sinon, je voudrais voir apparaitre la vue par "fonction"
mygrid.DataSource = ledatc.vueTestAlainPortailSharepoint_AnnuaireGenepi_Fonc;
}
mygrid.AlternatingItemStyle.BackColor = Color.Bisque;
mygrid.HeaderStyle.BackColor = Color.Brown;
mygrid.HeaderStyle.ForeColor = Color.Bisque;
mybut.ButtonType = ButtonColumnType.PushButton;
mybut.Text = "detail";
mybut.CausesValidation = true;
mygrid.Columns.Add(mybut);
mygrid.DataBind();
// ici on gere le lien sur les boutons pour acceder à la fiche détail selectionnée
mygrid.ItemCommand += (mygrid_ItemCommand);
this.Controls.Add(mygrid);
this.Controls.Add(lblMessage);
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("</tr>"));
// fin balise table
this.Controls.Add(new LiteralControl("</table>"));
}
}
}
Partager