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
| // <copyright file="Right.aspx.cs" company="FEJ">
// Copyright (c) FEJ 2009 All Right Reserved
// </copyright>
// <author>Xavier Millot</author>
// <email>contact@itelios.com</email>
// <date>2009-06-18</date>
// <summary>
// Page de gestion des droits
// </summary>
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business = FEJ.Commerce.V2.Business;
using Common = FEJ.Commerce.V2.Common;
using UI = FEJ.Commerce.V2.BO.UI;
/// <summary>
/// Page de gestion des droits
/// </summary>
public partial class Pages_Administration_Right : System.Web.UI.Page
{
#region Protected events
/// <summary>
/// Chargement de la page
/// </summary>
/// <param name="sender">Objet ayant déclenché l'évènement</param>
/// <param name="e">Arguments passés à l'évènement</param>
protected void Page_Load(object sender, EventArgs e)
{
this.HideError();
this.LoadAllItems();
this.ManageSecurity();
}
/// <summary>
/// Lance la création d'un nouvel élément
/// </summary>
/// <param name="sender">Objet ayant déclenché l'évènement</param>
/// <param name="id">Identifiant de l'objet</param>
protected void Filter1_New(object sender, string id)
{
this.LoadItem(null);
}
/// <summary>
/// Lance la modification d'un nouvel élément
/// </summary>
/// <param name="sender">Objet ayant déclenché l'évènement</param>
/// <param name="id">Identifiant de l'objet</param>
protected void Filter1_Edit(object sender, string id)
{
if (id != string.Empty)
{
int rightID = int.Parse(id);
Business.Data.Right right = Business.Data.Right.GetByID(rightID);
this.LoadItem(right);
}
}
/// <summary>
/// Supprime un élément
/// </summary>
/// <param name="sender">Objet ayant déclenché l'évènement</param>
/// <param name="id">Identifiant de l'objet</param>
protected void Filter1_Delete(object sender, string id)
{
if (id != string.Empty)
{
int rightID = int.Parse(id);
Business.Data.Right right = Business.Data.Right.GetByID(rightID);
if (right.GetBatchRights().Count > 0)
{
this.ShowError(Common.Tools.Localisation.MessageHelper.GetMessage(Common.Constants.Localisation.BO.Message.BOERRORRIGHTHASBATCH, UI.Browsing.VolatilData.CurrentLanguage));
}
else if (right.GetGroupRights().Count > 0)
{
this.ShowError(Common.Tools.Localisation.MessageHelper.GetMessage(Common.Constants.Localisation.BO.Message.BOERRORRIGHTHASGROUP, UI.Browsing.VolatilData.CurrentLanguage));
}
else
{
right.Delete();
}
this.LoadAllItems();
this.Filter1.DataBind();
this.HideEditFields();
}
}
/// <summary>
/// Annule la création ou modification
/// </summary>
/// <param name="sender">Objet ayant déclenché l'évènement</param>
/// <param name="e">Arguments passés à l'évènement</param>
protected void btnCancel_Click(object sender, EventArgs e)
{
this.HideEditFields();
}
/// <summary>
/// Lance la sauvegarde de l'élément en cours
/// </summary>
/// <param name="sender">Objet ayant déclenché l'évènement</param>
/// <param name="e">Arguments passés à l'évènement</param>
protected void btnSave_Click(object sender, EventArgs e)
{
this.Validate("EditItem");
if (this.IsValid)
{
if (hdfId.Value != string.Empty)
{
int rightID = int.Parse(hdfId.Value);
//// Ancien
Business.Data.Right right = Business.Data.Right.GetByID(rightID);
right.Code = txtCode.Text;
right.Label = txtLabel.Text;
right.Update();
}
else
{
//// Nouveau
Business.Data.Right right = new Business.Data.Right();
right.Code = txtCode.Text;
right.Label = txtLabel.Text;
right.Create();
}
this.HideEditFields();
this.LoadAllItems();
this.Filter1.DataBind();
}
}
#endregion
#region Private methods
/// <summary>
/// Affiche une erreur
/// </summary>
/// <param name="error">Erreur à afficher</param>
private void ShowError(string error)
{
lblError.Text = error;
lblError.Visible = true;
}
/// <summary>
/// Maque les message d'erreur
/// </summary>
private void HideError()
{
lblError.Text = string.Empty;
lblError.Visible = false;
}
/// <summary>
/// Chage tous les éléments dans le filter
/// </summary>
private void LoadAllItems()
{
ReadOnlyCollection<Business.Data.Right> rights = Business.Data.Right.GetAll();
Common.Collections.FilterableList<Common.Interfaces.IFilterableItem> filteredLanguages = new FEJ.Commerce.V2.Common.Collections.FilterableList<FEJ.Commerce.V2.Common.Interfaces.IFilterableItem>();
foreach (Business.Data.Right language in rights)
{
filteredLanguages.Add(language);
}
Filter1.DataSource = filteredLanguages;
if (!IsPostBack)
{
Filter1.DataBind();
}
}
/// <summary>
/// Charge un élément (pour création ou modification)
/// </summary>
/// <param name="right">Elément à charger</param>
private void LoadItem(Business.Data.Right right)
{
pnlEdit.Visible = true;
btnCancel.Visible = true;
btnSave.Visible = true;
if (right == null)
{
this.hdfId.Value = string.Empty;
this.txtCode.Text = string.Empty;
this.txtLabel.Text = string.Empty;
if (!UI.Browsing.VolatilData.CurrentUser.HasRight(UI.Security.Rights.NEWADMINRIGHT))
{
btnSave.Visible = false;
}
}
else
{
this.hdfId.Value = right.Rightid.ToString();
this.txtCode.Text = right.Code;
this.txtLabel.Text = right.Label;
if (!UI.Browsing.VolatilData.CurrentUser.HasRight(UI.Security.Rights.EDITADMINRIGHT))
{
btnSave.Visible = false;
}
}
}
/// <summary>
/// Chache les champs d'édition
/// </summary>
private void HideEditFields()
{
this.LoadItem(null);
pnlEdit.Visible = false;
btnCancel.Visible = false;
btnSave.Visible = false;
}
/// <summary>
/// Permet de masquer de éléments de l'interface graphique en fonction des droits de l'utilisateur
/// </summary>
private void ManageSecurity()
{
if (UI.Browsing.VolatilData.CurrentUser != null)
{
if (!UI.Browsing.VolatilData.CurrentUser.HasRight(UI.Security.Rights.VIEWADMINRIGHT))
{
Response.Redirect(Page.ResolveUrl(UI.Browsing.PageNames.ADMINISTRATIONDEFAULT) + "?ErrorCode=" + Common.Constants.Errors.ErrorCode.BOSECURITYNORIGHT.ToString());
}
if (UI.Browsing.VolatilData.CurrentUser.HasRight(UI.Security.Rights.VIEWADMINRIGHT) || UI.Browsing.VolatilData.CurrentUser.HasRight(UI.Security.Rights.EDITADMINRIGHT))
{
this.Filter1.DisplayEditButton = true;
}
else
{
this.Filter1.DisplayEditButton = false;
}
if (UI.Browsing.VolatilData.CurrentUser.HasRight(UI.Security.Rights.NEWADMINRIGHT))
{
this.Filter1.DisplayNewButton = true;
}
else
{
this.Filter1.DisplayNewButton = false;
}
if (UI.Browsing.VolatilData.CurrentUser.HasRight(UI.Security.Rights.DELETEADMINRIGHT))
{
this.Filter1.DisplayDeleteButton = true;
}
else
{
this.Filter1.DisplayDeleteButton = false;
}
}
}
#endregion
} |
Partager