1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
| using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Reflection;
using System.Xml;
using System.Data.SqlClient;
public partial class Visonneuse : System.Web.UI.Page
{
//private Guid InvoiceId;
private Guid IdDeLaFenetre;
private DataTable Commande;
//Invoice Panier;
protected void Page_Load(object sender, EventArgs e)
{
bool IsFirstTime = false;
// A ne faire que lors du 1er chargement de la page
if (!(Page.IsPostBack))
{
IdDeLaFenetre = Guid.NewGuid();
ViewState["IdDeLaFenetre"] = IdDeLaFenetre.ToString();
ViewState.Add("LangueSelectionnee_" + IdDeLaFenetre, "fr");
IsFirstTime = true;
}
else IdDeLaFenetre = new Guid(ViewState["IdDeLaFenetre"].ToString());
// On récupère la langue choisie
// On récupère le titre de la galerie
DataSet DataSetPhotosDeLaGalerie = new DataSet();
// Ouverture connexion BDD
SqlConnection Connexion = new SqlConnection(ConfigurationManager.AppSettings["ConnectionBase"]);
Connexion.Open();
// Si un dataset est déjà présent en variable de session, on le prend. Sinon on récupère les photos
if (Session["DataSetPhotos_" + IdDeLaFenetre.ToString()] == null)
{
SqlCommand Commande = new SqlCommand("aspnet_GetAllPhotosByPartialPath", Connexion);
Commande.CommandType = CommandType.StoredProcedure;
SqlDataAdapter Adapteur = new SqlDataAdapter(Commande);
SqlParameter Chemin = Commande.Parameters.Add("@PartialPath", SqlDbType.VarChar, 1000);
Chemin.Value = Path.GetDirectoryName(Request.AppRelativeCurrentExecutionFilePath).Replace("\\","/") + "%";
Adapteur.Fill(DataSetPhotosDeLaGalerie);
DataSet DataSetTitre = new DataSet();
Commande = new SqlCommand("aspnet_GetTitreName", Connexion);
Commande.CommandType = CommandType.StoredProcedure;
Adapteur = new SqlDataAdapter(Commande);
SqlParameter TitreId = Commande.Parameters.Add("@TitreId", SqlDbType.Int);
TitreId.Value = DataSetPhotosDeLaGalerie.Tables[0].Rows[0]["TitreId"];
Adapteur.Fill(DataSetTitre);
DataRow[] TitreName = DataSetTitre.Tables[0].Select("Langage='" + ViewState["LangueSelectionnee_" + IdDeLaFenetre] + "'".ToString());
LabelTitreGalerie.Text = TitreName[0]["TitreName"].ToString();
Session["DataSetPhotos_" + IdDeLaFenetre.ToString()] = DataSetPhotosDeLaGalerie;
}
else DataSetPhotosDeLaGalerie = (DataSet)Session["DataSetPhotos_" + IdDeLaFenetre.ToString()];
Connexion.Close();
// Création du conteneur des miniatures (nécessaire afin de correctement gérer l'overflow horizontal)
Panel Conteneur = new Panel();
Conteneur.Width = new Unit(120 * DataSetPhotosDeLaGalerie.Tables[0].Rows.Count/2);
foreach (DataRow Ligne in DataSetPhotosDeLaGalerie.Tables[0].Rows)
{
// On ne sélectionne qu' 1/2 photo puisqu'on a les francais ET les anglais dans le dataset
if (Ligne["Langage"].ToString() == ViewState["LangueSelectionnee_" + IdDeLaFenetre].ToString())
{
// lors du premier passage on sélectionne et affiche en grand la première photo de la galerie
if (IsFirstTime)
{
ViewState.Add("PhotoSelectionnee_" + IdDeLaFenetre.ToString(), Ligne["PhotoId"].ToString());
IsFirstTime = false;
}
// Création de la miniature et des évents associés
Conteneur.CssClass = "PlusADroite MarginLeftRight20px";
ImageButton Miniature = new ImageButton();
Miniature.ImageUrl = Ligne["PhotoVignettePath"].ToString();
Miniature.ImageAlign = ImageAlign.Middle;
Miniature.Command += new CommandEventHandler(Miniature_Command);
Miniature.CommandName = Ligne["PhotoVignettePath"].ToString();
Miniature.CommandArgument = Ligne["PhotoId"].ToString();
Miniature.CssClass = "Image";
Conteneur.Controls.Add(Miniature);
}
}
PanelPellicule.Controls.Add(Conteneur);
MAJPanier();
}
/// <summary>
/// Rafraichissement du panier
/// </summary>
private void MAJPanier()
{
if (Session["Panier_" + Request.UserHostAddress] != null)
{
// Récupération de la commande utilisateur
PanelPanierConteneurPhoto.Controls.Clear();
Commande = (DataTable)Session["Panier_" + Request.UserHostAddress];
foreach (DataRow PhotoCommandee in Commande.Rows)
{
AjoutImagePanier(PhotoCommandee["CheminVignette"].ToString(), PhotoCommandee["PhotoId"].ToString(), PhotoCommandee["PhotoName"].ToString(), PhotoCommandee["Prix"].ToString());
}
UpdatePanel3.Update();
PanelPanierConteneurPhoto.Focus();
}
}
/// <summary>
/// CLick sur la miniature. Passage en paramètre de l'ID et du nom de la photo
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Miniature_Command(object sender, CommandEventArgs e)
{
IdDeLaFenetre = new Guid(ViewState["IdDeLaFenetre"].ToString());
ViewState["PhotoSelectionnee_" + IdDeLaFenetre.ToString()] = e.CommandArgument.ToString();
DataSet DataSetPhotosDeLaGalerie = (DataSet)Session["DataSetPhotos_" + IdDeLaFenetre.ToString()];
DataRow[] LigneSelectionnee = DataSetPhotosDeLaGalerie.Tables[0].Select("PhotoId=" + e.CommandArgument.ToString() + "AND Langage='" + ViewState["LangueSelectionnee_" + IdDeLaFenetre].ToString() + "'");
Label1.Text = LigneSelectionnee[0]["PhotoName"].ToString();
LabelNom.Text = LigneSelectionnee[0]["PhotoPrice"].ToString() + " ";
UpdatePanel1.Update();
}
/// <summary>
/// Accesseur PhotoAAfficher (variable passée à la visionneuse flash)
/// </summary>
public string AccesseurPhotoAAfficher
{
get
{
IdDeLaFenetre = new Guid(ViewState["IdDeLaFenetre"].ToString());
return ViewState["PhotoSelectionnee_" + IdDeLaFenetre.ToString()].ToString();
}
set {
IdDeLaFenetre = new Guid(ViewState["IdDeLaFenetre"].ToString());
ViewState["PhotoSelectionnee_" + IdDeLaFenetre.ToString()] = value;
}
}
/// <summary>
/// Méthode qui ajoute un contrôle panier dans le panel "Panier"
/// </summary>
protected void AjoutImagePanier(string CheminVignette, string PhotoId, string Nom, string Prix)
{
Control LienVisionneusePagePhoto = LoadControl("~/controles/ControlePanier.ascx", new object[] {});
Image Vignette = (Image)LienVisionneusePagePhoto.FindControl("MiniatPhoto");
Vignette.ImageUrl = CheminVignette;
ImageButton Supprimer = (ImageButton)LienVisionneusePagePhoto.FindControl("BtnSupprimer");
// Ajout de l'event SUPPRESSION (celui où il faut cliquer 2 fois distinctement pour effacer)
Supprimer.Command += new CommandEventHandler(Supprimer_Command);
Supprimer.CommandArgument = PhotoId;
Supprimer.CommandName = PhotoId;
Label LabelNom = (Label)LienVisionneusePagePhoto.FindControl("LabelNom");
LabelNom.Text = Nom;
Label LabelPrix = (Label)LienVisionneusePagePhoto.FindControl("LabelPrix");
LabelPrix.Text = Prix;
PanelPanierConteneurPhoto.Controls.Add(LienVisionneusePagePhoto);
}
/// <summary>
/// Délégué de suppression. Passage en param du photoId
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Supprimer_Command(object sender, CommandEventArgs e)
{
Commande = (DataTable)Session["Panier_" + Request.UserHostAddress];
DataRow[] LigneSelectionnee = Commande.Select("PhotoId=" + e.CommandArgument.ToString());
Commande.Rows.Remove(LigneSelectionnee[0]);
Session["Panier_" + Request.UserHostAddress] = Commande;
MAJPanier();
}
/// <summary>
/// Méthode lors du clic sur une miniature
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
IdDeLaFenetre = new Guid(ViewState["IdDeLaFenetre"].ToString());
DataSet DataSetPhotosDeLaGalerie = (DataSet)Session["DataSetPhotos_" + IdDeLaFenetre.ToString()];
if (Session["Panier_" + Request.UserHostAddress] != null)
{
Commande = (DataTable)Session["Panier_" + Request.UserHostAddress];
}
else
{
Commande = new DataTable("Commande");
Commande.Columns.Add("PhotoId", Type.GetType("System.Int32"));
Commande.Columns.Add("PhotoName", Type.GetType("System.String"));
Commande.Columns.Add("CheminVignette", Type.GetType("System.String"));
Commande.Columns.Add("Prix", Type.GetType("System.Decimal"));
}
DataRow[] LigneSelectionnee = DataSetPhotosDeLaGalerie.Tables[0].Select("PhotoId=" + Convert.ToInt16(ViewState["PhotoSelectionnee_" + IdDeLaFenetre.ToString()]) + "AND Langage='"+ ViewState["LangueSelectionnee_" + IdDeLaFenetre].ToString() + "'");
DataRow LigneAjoutee = Commande.NewRow();
LigneAjoutee["PhotoId"] = LigneSelectionnee[0]["PhotoId"];
LigneAjoutee["PhotoName"] = LigneSelectionnee[0]["PhotoName"];
LigneAjoutee["CheminVignette"] = LigneSelectionnee[0]["PhotoVignettePath"];
LigneAjoutee["Prix"] = LigneSelectionnee[0]["PhotoPrice"];
Commande.Rows.Add(LigneAjoutee);
Session["Panier_" + Request.UserHostAddress] = Commande;
foreach (DataRow PhotoCommandee in Commande.Rows)
{
AjoutImagePanier(PhotoCommandee["CheminVignette"].ToString(), PhotoCommandee["PhotoId"].ToString(), PhotoCommandee["PhotoName"].ToString(), PhotoCommandee["Prix"].ToString());
}
MAJPanier();
}
/// <summary>
/// Chargement de contrôles utilisateur
/// </summary>
/// <param name="UserControlPath"></param>
/// <param name="constructorParameters"></param>
/// <returns></returns>
public UserControl LoadControl(string UserControlPath, params object[] constructorParameters)
{
List<Type> constParamTypes = new List<Type>();
foreach (object constParam in constructorParameters)
{
constParamTypes.Add(constParam.GetType());
}
UserControl ctl = Page.LoadControl(UserControlPath) as UserControl;
// On recherche le constructeur approprié ...
ConstructorInfo constructor = ctl.GetType().BaseType.GetConstructor(constParamTypes.ToArray());
// Et on l'appelle
if (constructor == null)
{
throw new MemberAccessException("Le constructeur n'existe pas : " + ctl.GetType().BaseType.ToString());
}
else
{
constructor.Invoke(ctl, constructorParameters);
}
// Et enfin, on retourne le controle
return ctl;
}
/// <summary>
/// Se produit lors de la validation du panier.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ImageButtonValierLePanier_Click(object sender, ImageClickEventArgs e)
{
if (Session["Panier_" + Request.UserHostAddress] != null)
{
Commande = (DataTable)Session["Panier_" + Request.UserHostAddress];
if (Commun.AccesseurListeCommandes.Contains(Request.UserHostAddress))
{
Commun.AccesseurListeCommandes[Request.UserHostAddress] = Commande;
}
else Commun.AccesseurListeCommandes.Add(Request.UserHostAddress, Commande);
Response.Redirect("~/photos.aspx");
}
}
/// <summary>
/// Click sur le bouton changement langue
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ImageButtonFr_Click(object sender, ImageClickEventArgs e)
{
IdDeLaFenetre = new Guid(ViewState["IdDeLaFenetre"].ToString());
if (ViewState["LangueSelectionnee_" + IdDeLaFenetre] != null)
{
ViewState["LangueSelectionnee_" + IdDeLaFenetre] = "fr";
}
else ViewState.Add("LangueSelectionnee_" + IdDeLaFenetre, "fr");
}
protected void ImageButtonEn_Click(object sender, ImageClickEventArgs e)
{
IdDeLaFenetre = new Guid(ViewState["IdDeLaFenetre"].ToString());
if (ViewState["LangueSelectionnee_" + IdDeLaFenetre] != null)
{
ViewState["LangueSelectionnee_" + IdDeLaFenetre] = "en";
}
else ViewState.Add("LangueSelectionnee_" + IdDeLaFenetre, "en");
}
} |
Partager