/Docs/07-Implementacion/Source/trunk/EDUAR_Regular/EDUAR/EDUAR_UI/Private/Mensajes/MsjeEnviado.aspx.cs

http://blpm.googlecode.com/ · C# · 448 lines · 348 code · 32 blank · 68 comment · 30 complexity · 2d3293c464a36c835f93567c4256cfc5 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Drawing;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using EDUAR_BusinessLogic.Common;
  8. using EDUAR_Entities;
  9. using EDUAR_UI.Shared;
  10. using EDUAR_UI.Utilidades;
  11. using EDUAR_Utility.Constantes;
  12. using EDUAR_Utility.Enumeraciones;
  13. namespace EDUAR_UI
  14. {
  15. public partial class MsjeEnviado : EDUARBasePage
  16. {
  17. #region --[Atributos]--
  18. private BLMensaje objBLMensaje;
  19. PagedDataSource pds = new PagedDataSource();
  20. #endregion
  21. #region --[Propiedades]--
  22. /// <summary>
  23. /// Gets or sets the prop mensaje.
  24. /// </summary>
  25. /// <value>
  26. /// The prop mensaje.
  27. /// </value>
  28. public Mensaje propMensaje
  29. {
  30. get
  31. {
  32. if (ViewState["propMensaje"] == null)
  33. propMensaje = new Mensaje();
  34. return (Mensaje)ViewState["propMensaje"];
  35. }
  36. set
  37. { ViewState["propMensaje"] = value; }
  38. }
  39. /// <summary>
  40. /// Gets or sets the lista mensajes.
  41. /// </summary>
  42. /// <value>
  43. /// The lista mensajes.
  44. /// </value>
  45. public List<Mensaje> listaMensajes
  46. {
  47. get
  48. {
  49. if (ViewState["listaMensajes"] == null)
  50. listaMensajes = new List<Mensaje>();
  51. return (List<Mensaje>)ViewState["listaMensajes"];
  52. }
  53. set
  54. { ViewState["listaMensajes"] = value; }
  55. }
  56. public int CurrentPage
  57. {
  58. get
  59. {
  60. if (this.ViewState["CurrentPage"] == null)
  61. {
  62. return 0;
  63. }
  64. else
  65. {
  66. return Convert.ToInt16(this.ViewState["CurrentPage"].ToString());
  67. }
  68. }
  69. set
  70. {
  71. this.ViewState["CurrentPage"] = value;
  72. }
  73. }
  74. #endregion
  75. #region --[Eventos]--
  76. /// <summary>
  77. /// Método que se ejecuta al dibujar los controles de la página.
  78. /// Se utiliza para gestionar las excepciones del método Page_Load().
  79. /// </summary>
  80. /// <param name="e"></param>
  81. protected override void OnPreRender(EventArgs e)
  82. {
  83. base.OnPreRender(e);
  84. if (AvisoMostrar)
  85. {
  86. AvisoMostrar = false;
  87. try
  88. {
  89. Master.ManageExceptions(AvisoExcepcion);
  90. }
  91. catch (Exception ex) { Master.ManageExceptions(ex); }
  92. }
  93. }
  94. /// <summary>
  95. /// Handles the Load event of the Page control.
  96. /// </summary>
  97. /// <param name="sender">The source of the event.</param>
  98. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  99. protected void Page_Load(object sender, EventArgs e)
  100. {
  101. try
  102. {
  103. Master.BotonAvisoAceptar += (VentanaAceptar);
  104. if (!Page.IsPostBack)
  105. {
  106. BuscarMensajes();
  107. divContenido.Visible = false;
  108. }
  109. }
  110. catch (Exception ex)
  111. {
  112. AvisoMostrar = true;
  113. AvisoExcepcion = ex;
  114. }
  115. }
  116. /// <summary>
  117. /// Ventanas the aceptar.
  118. /// </summary>
  119. /// <param name="sender">The sender.</param>
  120. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  121. protected void VentanaAceptar(object sender, EventArgs e)
  122. {
  123. try
  124. {
  125. switch (AccionPagina)
  126. {
  127. case enumAcciones.Eliminar:
  128. AccionPagina = enumAcciones.Limpiar;
  129. Mensaje objMensaje = listaMensajes.Find(p => p.idMensaje == propMensaje.idMensajeDestinatario);
  130. //objMensaje.idMensaje = idMensaje;
  131. objMensaje.activo = false;
  132. objMensaje.idMensajeDestinatario = 0;
  133. BLMensaje objBLMensaje = new BLMensaje(objMensaje);
  134. objBLMensaje.EliminarMensaje();
  135. listaMensajes.Remove(objMensaje);
  136. CargarGrilla();
  137. udpGrilla.Update();
  138. break;
  139. case enumAcciones.Limpiar:
  140. CargarPresentacion();
  141. break;
  142. case enumAcciones.Seleccionar:
  143. EliminarSeleccionados();
  144. CargarPresentacion();
  145. break;
  146. default:
  147. break;
  148. }
  149. }
  150. catch (Exception ex)
  151. {
  152. Master.ManageExceptions(ex);
  153. }
  154. }
  155. /// <summary>
  156. /// Método que se llama al hacer click sobre las acciones de la grilla
  157. /// </summary>
  158. /// <param name="sender">The source of the event.</param>
  159. /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewCommandEventArgs"/> instance containing the event data.</param>
  160. protected void gvwReporte_RowCommand(object sender, GridViewCommandEventArgs e)
  161. {
  162. try
  163. {
  164. int idMensajeDestinatario = Convert.ToInt32(e.CommandArgument);
  165. Mensaje objMensaje = null;
  166. switch (e.CommandName)
  167. {
  168. case "Leer":
  169. foreach (GridViewRow item in gvwReporte.Rows)
  170. {
  171. item.BackColor = Color.Transparent;
  172. }
  173. objMensaje = new Mensaje();
  174. objMensaje = listaMensajes.Find(p => p.idMensaje == idMensajeDestinatario);
  175. litAsunto.Text = objMensaje.asuntoMensaje;
  176. litFecha.Text = objMensaje.fechaEnvio.ToShortDateString() + " " + objMensaje.horaEnvio.Hour.ToString() + ":" + objMensaje.horaEnvio.Minute.ToString();
  177. litRemitente.Text = objMensaje.destinatario.nombre + " " + objMensaje.destinatario.apellido;
  178. if (!objMensaje.destinatario.nombre.Contains("-")) litRemitente.Text += " <b>(" + objMensaje.destinatario.tipoPersona.nombre + ")</b>";
  179. litContenido.Text = objMensaje.textoMensaje;
  180. divContenido.Visible = true;
  181. divPaginacion.Visible = true;
  182. GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer;
  183. gvwReporte.Rows[row.RowIndex].BackColor = Color.Gainsboro;
  184. break;
  185. case "Eliminar":
  186. AccionPagina = enumAcciones.Eliminar;
  187. propMensaje.idMensajeDestinatario = Convert.ToInt32(e.CommandArgument.ToString());
  188. divContenido.Visible = false;
  189. Master.MostrarMensaje(this.Page.Title, UIConstantesGenerales.MensajeEliminar, enumTipoVentanaInformacion.Confirmación);
  190. break;
  191. }
  192. udpGrilla.Update();
  193. }
  194. catch (Exception ex)
  195. {
  196. Master.ManageExceptions(ex);
  197. }
  198. }
  199. /// <summary>
  200. /// Handles the Click event of the btnEliminar control.
  201. /// </summary>
  202. /// <param name="sender">The source of the event.</param>
  203. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  204. protected void btnEliminar_Click(object sender, EventArgs e)
  205. {
  206. try
  207. {
  208. bool haySeleccion = false;
  209. for (int i = 0; i < gvwReporte.Rows.Count; i++)
  210. {
  211. CheckBox checkbox = (CheckBox)gvwReporte.Rows[i].FindControl("checkEliminar");
  212. if (checkbox != null && checkbox.Checked)
  213. {
  214. haySeleccion = true;
  215. break;
  216. }
  217. }
  218. if (haySeleccion)
  219. {
  220. AccionPagina = enumAcciones.Seleccionar;
  221. Master.MostrarMensaje(this.Page.Title, UIConstantesGenerales.MensajeEliminarMensajesSeleccionados, enumTipoVentanaInformacion.Confirmación);
  222. }
  223. else
  224. {
  225. AccionPagina = enumAcciones.Limpiar;
  226. Master.MostrarMensaje(this.Page.Title, UIConstantesGenerales.MensajeSinSeleccion, enumTipoVentanaInformacion.Advertencia);
  227. }
  228. }
  229. catch (Exception ex)
  230. {
  231. Master.ManageExceptions(ex);
  232. }
  233. }
  234. /// <summary>
  235. /// Handles the Click event of the btnVolver control.
  236. /// </summary>
  237. /// <param name="sender">The source of the event.</param>
  238. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  239. protected void btnVolver_Click(object sender, EventArgs e)
  240. {
  241. try
  242. {
  243. CargarPresentacion();
  244. }
  245. catch (Exception ex)
  246. {
  247. Master.ManageExceptions(ex);
  248. }
  249. }
  250. /// <summary>
  251. /// Headers the checked changed.
  252. /// </summary>
  253. /// <param name="sender">The sender.</param>
  254. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  255. protected void HeaderCheckedChanged(object sender, EventArgs e)//this is for header checkbox changed event
  256. {
  257. CheckBox cbSelectedHeader = (CheckBox)gvwReporte.HeaderRow.FindControl("cboxhead");
  258. //if u checked header checkbox automatically all the check boxes will be checked,viseversa
  259. foreach (GridViewRow row in gvwReporte.Rows)
  260. {
  261. CheckBox cbSelected = (CheckBox)row.FindControl("checkEliminar");
  262. if (cbSelectedHeader.Checked == true)
  263. {
  264. cbSelected.Checked = true;
  265. }
  266. else
  267. {
  268. cbSelected.Checked = false;
  269. }
  270. }
  271. }
  272. #endregion
  273. #region --[Métodos Privados]--
  274. /// <summary>
  275. /// Cargars the presentacion.
  276. /// </summary>
  277. private void CargarPresentacion()
  278. {
  279. BuscarMensajes();
  280. udpReporte.Visible = true;
  281. divPaginacion.Visible = true;
  282. divContenido.Visible = false;
  283. udpGrilla.Update();
  284. }
  285. /// <summary>
  286. /// Buscars the entidads.
  287. /// </summary>
  288. /// <param name="entidad">The entidad.</param>
  289. private void BuscarMensajes()
  290. {
  291. Mensaje entidad = new Mensaje();
  292. entidad.remitente.username = ObjSessionDataUI.ObjDTUsuario.Nombre;
  293. CargarLista(entidad);
  294. CargarGrilla();
  295. }
  296. /// <summary>
  297. /// Cargars the lista.
  298. /// </summary>
  299. /// <param name="entidad">The entidad.</param>
  300. private void CargarLista(Mensaje entidad)
  301. {
  302. objBLMensaje = new BLMensaje();
  303. listaMensajes = objBLMensaje.GetMensajesEnviados(entidad);
  304. }
  305. /// Cargars the grilla.
  306. /// </summary>
  307. /// <typeparam name="T"></typeparam>
  308. /// <param name="lista">The lista.</param>
  309. private void CargarGrilla()
  310. {
  311. DataTable dt = UIUtilidades.BuildDataTable<Mensaje>(listaMensajes);
  312. pds.DataSource = dt.DefaultView;
  313. pds.AllowPaging = true;
  314. pds.PageSize = Convert.ToInt16(ddlPageSize.SelectedValue);
  315. pds.CurrentPageIndex = (CurrentPage > pds.PageCount) ? (pds.PageCount - 1) : CurrentPage;
  316. lnkbtnNext.Visible = !pds.IsLastPage;
  317. lnkbtnLast.Visible = !pds.IsLastPage;
  318. lnkbtnPrevious.Visible = !pds.IsFirstPage;
  319. lnkbtnFirst.Visible = !pds.IsFirstPage;
  320. gvwReporte.DataSource = pds;
  321. gvwReporte.DataBind();
  322. doPaging();
  323. lblCantidad.Text = dt.Rows.Count.ToString() + " Mensajes";
  324. divContenido.Visible = false;
  325. udpGrilla.Update();
  326. }
  327. /// <summary>
  328. /// Eliminars the seleccionados.
  329. /// </summary>
  330. private void EliminarSeleccionados()
  331. {
  332. Mensaje objMensajesEliminar = new Mensaje();
  333. for (int i = 0; i < gvwReporte.Rows.Count; i++)
  334. {
  335. CheckBox checkbox = (CheckBox)gvwReporte.Rows[i].FindControl("checkEliminar");
  336. if (checkbox != null && checkbox.Checked)
  337. {
  338. int idMensajeDestinatario = 0;
  339. Int32.TryParse(checkbox.Text, out idMensajeDestinatario);
  340. if (idMensajeDestinatario > 0)
  341. objMensajesEliminar.listaIDMensaje += string.Format("{0},", idMensajeDestinatario.ToString());
  342. }
  343. }
  344. if (!string.IsNullOrEmpty(objMensajesEliminar.listaIDMensaje))
  345. {
  346. objMensajesEliminar.listaIDMensaje = objMensajesEliminar.listaIDMensaje.Substring(0, objMensajesEliminar.listaIDMensaje.Length - 1);
  347. objMensajesEliminar.idMensajeDestinatario = 0;
  348. objMensajesEliminar.idMensaje = 1;
  349. //objMensajesEliminar.leido = true;
  350. objMensajesEliminar.activo = false;
  351. objBLMensaje = new BLMensaje(objMensajesEliminar);
  352. objBLMensaje.EliminarListaMensajes();
  353. }
  354. }
  355. #endregion
  356. #region --[Propiedades]--
  357. private void doPaging()
  358. {
  359. DataTable dt = new DataTable();
  360. dt.Columns.Add("PageIndex");
  361. dt.Columns.Add("PageText");
  362. for (int i = 0; i < pds.PageCount; i++)
  363. {
  364. DataRow dr = dt.NewRow();
  365. dr[0] = i;
  366. dr[1] = i + 1;
  367. dt.Rows.Add(dr);
  368. }
  369. dlPaging.DataSource = dt;
  370. dlPaging.DataBind();
  371. }
  372. protected void dlPaging_ItemCommand(object source, DataListCommandEventArgs e)
  373. {
  374. if (e.CommandName.Equals("lnkbtnPaging"))
  375. {
  376. CurrentPage = Convert.ToInt16(e.CommandArgument.ToString());
  377. BuscarMensajes();
  378. }
  379. }
  380. protected void dlPaging_ItemDataBound(object sender, DataListItemEventArgs e)
  381. {
  382. LinkButton lnkbtnPage = (LinkButton)e.Item.FindControl("lnkbtnPaging");
  383. if (lnkbtnPage.CommandArgument.ToString() == CurrentPage.ToString())
  384. {
  385. lnkbtnPage.Enabled = false;
  386. lnkbtnPage.Font.Bold = true;
  387. }
  388. }
  389. protected void lnkbtnPrevious_Click(object sender, EventArgs e)
  390. {
  391. CurrentPage -= 1;
  392. BuscarMensajes();
  393. }
  394. protected void lnkbtnNext_Click(object sender, EventArgs e)
  395. {
  396. CurrentPage += 1;
  397. BuscarMensajes();
  398. }
  399. protected void lnkbtnLast_Click(object sender, EventArgs e)
  400. {
  401. CurrentPage = dlPaging.Controls.Count - 1;
  402. BuscarMensajes();
  403. }
  404. protected void lnkbtnFirst_Click(object sender, EventArgs e)
  405. {
  406. CurrentPage = 0;
  407. BuscarMensajes();
  408. }
  409. protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
  410. {
  411. CurrentPage = 0;
  412. BuscarMensajes();
  413. }
  414. #endregion
  415. }
  416. }