/Docs/07-Implementacion/Source/trunk/EDUAR_actual/EDUAR/EDUAR_UI/Private/Account/Profiles.aspx.cs

http://blpm.googlecode.com/ · C# · 415 lines · 310 code · 31 blank · 74 comment · 11 complexity · 02c2ff772b797f342bf1c05c468de754 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Web.UI;
  4. using System.Web.UI.WebControls;
  5. using EDUAR_BusinessLogic.Security;
  6. using EDUAR_Entities.Security;
  7. using EDUAR_UI.Shared;
  8. using EDUAR_Utility.Constantes;
  9. using EDUAR_Utility.Enumeraciones;
  10. namespace EDUAR_UI
  11. {
  12. public partial class Profiles : EDUARBasePage
  13. {
  14. #region --[Atributos]--
  15. private BLSeguridad objBLSeguridad;
  16. #endregion
  17. #region --[Propiedades]--
  18. /// <summary>
  19. /// Propiedad que contiene el objeto seguridad que devuelve la consulta a la Capa de Negocio.
  20. /// </summary>
  21. public DTSeguridad propSeguridad
  22. {
  23. get
  24. {
  25. if (ViewState["propSeguridad"] == null)
  26. return null;
  27. return (DTSeguridad)ViewState["propSeguridad"];
  28. }
  29. set { ViewState["propSeguridad"] = value; }
  30. }
  31. /// <summary>
  32. /// Propiedad que contiene el objeto rol que se edita/crea/elimina.
  33. /// </summary>
  34. /// <value>
  35. /// The obj propRol.
  36. /// </value>
  37. public DTRol propRol
  38. {
  39. get
  40. {
  41. if (ViewState["propRol"] == null)
  42. return new DTRol();
  43. return (DTRol)ViewState["propRol"];
  44. }
  45. set { ViewState["propRol"] = value; }
  46. }
  47. #endregion
  48. #region --[Eventos]--
  49. /// <summary>
  50. /// Método que se ejecuta al dibujar los controles de la página.
  51. /// Se utiliza para gestionar las excepciones del método Page_Load().
  52. /// </summary>
  53. /// <param name="e"></param>
  54. protected override void OnPreRender(EventArgs e)
  55. {
  56. base.OnPreRender(e);
  57. if (AvisoMostrar)
  58. {
  59. AvisoMostrar = false;
  60. try
  61. {
  62. Master.ManageExceptions(AvisoExcepcion);
  63. }
  64. catch (Exception ex) { Master.ManageExceptions(ex); }
  65. }
  66. }
  67. /// <summary>
  68. /// Handles the Load event of the Page control.
  69. /// </summary>
  70. /// <param name="sender">The source of the event.</param>
  71. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  72. protected void Page_Load(object sender, EventArgs e)
  73. {
  74. try
  75. {
  76. Master.BotonAvisoAceptar += (VentanaAceptar);
  77. if (!Page.IsPostBack)
  78. {
  79. propSeguridad = new DTSeguridad();
  80. objBLSeguridad = new BLSeguridad(propSeguridad);
  81. CargarPresentacion();
  82. CargarCamposFiltros();
  83. BuscarRoles(propSeguridad);
  84. }
  85. }
  86. catch (Exception ex)
  87. {
  88. AvisoMostrar = true;
  89. AvisoExcepcion = ex;
  90. }
  91. }
  92. /// <summary>
  93. /// Ventanas the aceptar.
  94. /// </summary>
  95. /// <param name="sender">The sender.</param>
  96. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  97. void VentanaAceptar(object sender, EventArgs e)
  98. {
  99. try
  100. {
  101. DTRol objRol;
  102. switch (AccionPagina)
  103. {
  104. case enumAcciones.Eliminar:
  105. AccionPagina = enumAcciones.Limpiar;
  106. objRol = new DTRol();
  107. objRol.Nombre = propRol.Nombre;
  108. EliminarRol(objRol);
  109. break;
  110. case enumAcciones.Guardar:
  111. AccionPagina = enumAcciones.Limpiar;
  112. objRol = new DTRol();
  113. if (esNuevo)
  114. {
  115. objRol.Descripcion = txtNuevaDescripcion.Text;
  116. objRol.Nombre = txtNuevoRol.Text;
  117. objRol.NombreCorto = objRol.Nombre.ToLower();
  118. objRol.RoleId = null;
  119. }
  120. else
  121. {
  122. objRol.Descripcion = txtDescripcion.Text;
  123. objRol.RoleId = propRol.RoleId;
  124. objRol.Nombre = propRol.Nombre;
  125. }
  126. GuardarRol(objRol);
  127. Master.MostrarMensaje(enumTipoVentanaInformacion.Satisfactorio.ToString(), UIConstantesGenerales.MensajeGuardadoOk, enumTipoVentanaInformacion.Satisfactorio);
  128. break;
  129. case enumAcciones.Nuevo:
  130. break;
  131. }
  132. CargarPresentacion();
  133. }
  134. catch (Exception ex)
  135. {
  136. Master.ManageExceptions(ex);
  137. }
  138. }
  139. /// <summary>
  140. /// Handles the Click event of the btnBuscar control.
  141. /// </summary>
  142. /// <param name="sender">The source of the event.</param>
  143. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  144. protected void btnBuscar_Click(object sender, EventArgs e)
  145. {
  146. try
  147. {
  148. BuscarFiltrando();
  149. }
  150. catch (Exception ex)
  151. {
  152. Master.ManageExceptions(ex);
  153. }
  154. }
  155. /// <summary>
  156. /// Handles the Click event of the btnNuevo control.
  157. /// </summary>
  158. /// <param name="sender">The source of the event.</param>
  159. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  160. protected void btnNuevo_Click(object sender, EventArgs e)
  161. {
  162. try
  163. {
  164. AccionPagina = enumAcciones.Nuevo;
  165. esNuevo = true;
  166. btnGuardar.Visible = true;
  167. btnBuscar.Visible = false;
  168. btnVolver.Visible = true;
  169. btnNuevo.Visible = false;
  170. gvwPerfiles.Visible = false;
  171. udpEditRoles.Visible = false;
  172. udpControlesBusqueda.Visible = false;
  173. udpNewRol.Visible = true;
  174. udpFiltros.Update();
  175. udpGrilla.Update();
  176. }
  177. catch (Exception ex)
  178. {
  179. Master.ManageExceptions(ex);
  180. }
  181. }
  182. /// <summary>
  183. /// Handles the Click event of the btnAsignarRol control.
  184. /// </summary>
  185. /// <param name="sender">The source of the event.</param>
  186. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  187. protected void btnGuardar_Click(object sender, EventArgs e)
  188. {
  189. try
  190. {
  191. if (Page.IsValid)
  192. {
  193. AccionPagina = enumAcciones.Guardar;
  194. Master.MostrarMensaje(enumTipoVentanaInformacion.Confirmación.ToString(), UIConstantesGenerales.MensajeConfirmarCambios, enumTipoVentanaInformacion.Confirmación);
  195. }
  196. else
  197. {
  198. AccionPagina = enumAcciones.Limpiar;
  199. Master.MostrarMensaje(enumTipoVentanaInformacion.Advertencia.ToString(), UIConstantesGenerales.MensajeDatosRequeridos, enumTipoVentanaInformacion.Advertencia);
  200. }
  201. }
  202. catch (Exception ex)
  203. {
  204. Master.ManageExceptions(ex);
  205. }
  206. }
  207. /// <summary>
  208. /// Handles the Click event of the btnVolver control.
  209. /// </summary>
  210. /// <param name="sender">The source of the event.</param>
  211. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  212. protected void btnVolver_Click(object sender, EventArgs e)
  213. {
  214. try
  215. {
  216. CargarPresentacion();
  217. }
  218. catch (Exception ex)
  219. {
  220. Master.ManageExceptions(ex);
  221. }
  222. }
  223. /// <summary>
  224. /// Método que se llama al hacer click sobre las acciones de la grilla
  225. /// </summary>
  226. /// <param name="sender">The source of the event.</param>
  227. /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewCommandEventArgs"/> instance containing the event data.</param>
  228. protected void gvwPerfiles_RowCommand(object sender, GridViewCommandEventArgs e)
  229. {
  230. try
  231. {
  232. switch (e.CommandName)
  233. {
  234. case "Eliminar":
  235. AccionPagina = enumAcciones.Eliminar;
  236. propRol = new DTRol();
  237. propRol.Nombre = e.CommandArgument.ToString();
  238. Master.MostrarMensaje(enumTipoVentanaInformacion.Confirmación.ToString(), UIConstantesGenerales.MensajeEliminar, enumTipoVentanaInformacion.Confirmación);
  239. break;
  240. case "Editar":
  241. AccionPagina = enumAcciones.Modificar;
  242. esNuevo = false;
  243. propRol = new DTRol();
  244. propRol.RoleId = e.CommandArgument.ToString();
  245. propRol.Nombre = lblNombreRol.Text;
  246. btnBuscar.Visible = false;
  247. btnNuevo.Visible = false;
  248. btnVolver.Visible = true;
  249. btnGuardar.Visible = true;
  250. CargarRol();
  251. udpEditRoles.Visible = true;
  252. udpEditRoles.Update();
  253. break;
  254. }
  255. }
  256. catch (Exception ex)
  257. {
  258. Master.ManageExceptions(ex);
  259. }
  260. }
  261. #endregion
  262. #region --[Métodos Privados]--
  263. /// <summary>
  264. /// Cargars the presentacion.
  265. /// </summary>
  266. private void CargarPresentacion()
  267. {
  268. LimpiarCampos();
  269. udpEditRoles.Visible = false;
  270. udpNewRol.Visible = false;
  271. btnVolver.Visible = false;
  272. btnGuardar.Visible = false;
  273. btnBuscar.Visible = false;
  274. btnNuevo.Visible = false;
  275. udpControlesBusqueda.Visible = true;
  276. gvwPerfiles.Visible = true;
  277. udpFiltros.Update();
  278. udpGrilla.Update();
  279. BuscarFiltrando();
  280. }
  281. /// <summary>
  282. /// Cargars the campos filtros.
  283. /// </summary>
  284. private void CargarCamposFiltros()
  285. {
  286. objBLSeguridad.GetRoles();
  287. foreach (DTRol rol in objBLSeguridad.Data.ListaRoles)
  288. {
  289. chkListRolesBusqueda.Items.Add(new ListItem(rol.Nombre, rol.NombreCorto));
  290. }
  291. }
  292. private void BuscarFiltrando()
  293. {
  294. List<DTRol> ListaRoles = new List<DTRol>();
  295. foreach (ListItem item in chkListRolesBusqueda.Items)
  296. {
  297. if (item.Selected)
  298. {
  299. ListaRoles.Add(new DTRol() { Nombre = item.Value });
  300. }
  301. }
  302. DTSeguridad objSeguridad = new DTSeguridad();
  303. objSeguridad.ListaRoles = ListaRoles;
  304. BuscarRoles(objSeguridad);
  305. }
  306. /// <summary>
  307. /// Obteners the datos.
  308. /// </summary>
  309. private void BuscarRoles(DTSeguridad objSeguridad)
  310. {
  311. objBLSeguridad = new BLSeguridad(objSeguridad);
  312. objBLSeguridad.Data = objSeguridad;
  313. objBLSeguridad.GetRoles();
  314. propSeguridad = objBLSeguridad.Data;
  315. CargarGrilla();
  316. }
  317. /// <summary>
  318. /// Cargars the grilla.
  319. /// </summary>
  320. private void CargarGrilla()
  321. {
  322. gvwPerfiles.DataSource = propSeguridad.ListaRoles;
  323. gvwPerfiles.DataBind();
  324. gvwPerfiles.SelectedIndex = -1;
  325. udpEditRoles.Visible = false;
  326. udpGrilla.Update();
  327. }
  328. /// <summary>
  329. /// Cargars the usuario.
  330. /// </summary>
  331. private void CargarRol()
  332. {
  333. LimpiarCampos();
  334. objBLSeguridad = new BLSeguridad();
  335. objBLSeguridad.Data.Rol = new DTRol();
  336. objBLSeguridad.Data.Rol = propRol;
  337. objBLSeguridad.GetRol();
  338. propRol = objBLSeguridad.Data.Rol;
  339. lblNombreRol.Text = propRol.Nombre;
  340. txtDescripcion.Text = propRol.Descripcion;
  341. udpControlesBusqueda.Visible = false;
  342. udpControlesBusqueda.Update();
  343. gvwPerfiles.Visible = false;
  344. udpEditRoles.Visible = true;
  345. udpEditRoles.Update();
  346. }
  347. /// <summary>
  348. /// Limpiars the campos.
  349. /// </summary>
  350. private void LimpiarCampos()
  351. {
  352. lblNombreRol.Text = string.Empty;
  353. txtDescripcion.Text = string.Empty;
  354. foreach (ListItem item in chkListRolesBusqueda.Items)
  355. { item.Selected = false; }
  356. }
  357. /// <summary>
  358. /// Guardars the rol.
  359. /// </summary>
  360. private void GuardarRol(DTRol objRol)
  361. {
  362. DTSeguridad objDTSeguridad = new DTSeguridad { Rol = objRol };
  363. objBLSeguridad = new BLSeguridad();
  364. objBLSeguridad.Data = objDTSeguridad;
  365. objBLSeguridad.GuardarRol();
  366. BuscarRoles(propSeguridad);
  367. LimpiarCampos();
  368. }
  369. /// <summary>
  370. /// Eliminars the rol.
  371. /// </summary>
  372. /// <param name="objRol">The obj rol.</param>
  373. private void EliminarRol(DTRol objRol)
  374. {
  375. DTSeguridad objDTSeguridad = new DTSeguridad { Rol = objRol };
  376. objBLSeguridad = new BLSeguridad();
  377. objBLSeguridad.Data = objDTSeguridad;
  378. objBLSeguridad.EliminarRol();
  379. BuscarRoles(propSeguridad);
  380. LimpiarCampos();
  381. }
  382. #endregion
  383. }
  384. }