/Docs/07-Implementacion/Source/trunk/EDUAR_Regular/EDUAR/EDUAR_UI/Private/Agenda/ManageExcursiones.aspx.cs

http://blpm.googlecode.com/ · C# · 502 lines · 357 code · 39 blank · 106 comment · 28 complexity · 47f9c8979bb7a27ae82d678f1ce1a035 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.Common;
  6. using EDUAR_Entities;
  7. using EDUAR_UI.Utilidades;
  8. using EDUAR_Utility.Constantes;
  9. using EDUAR_Utility.Enumeraciones;
  10. using EDUAR_UI.Shared;
  11. namespace EDUAR_UI
  12. {
  13. public partial class ManageExcursiones : EDUARBasePage
  14. {
  15. #region --[Atributos]--
  16. private BLAgendaActividades objBLAgenda;
  17. #endregion
  18. #region --[Propiedades]--
  19. /// <summary>
  20. /// Mantiene la agenda seleccionada en la grilla.
  21. /// Se utiliza para el manejo de eventos de agenda (evaluación, excursión, reunión).
  22. /// En las pantallas hijas no permito la edición.
  23. /// </summary>
  24. /// <value>
  25. /// The prop agenda.
  26. /// </value>
  27. public AgendaActividades propAgenda
  28. {
  29. get
  30. { return (AgendaActividades)Session["propAgenda"]; }
  31. }
  32. /// <summary>
  33. /// Gets or sets the prop evento.
  34. /// </summary>
  35. /// <value>
  36. /// The prop evento.
  37. /// </value>
  38. public Excursion propFiltroEvento
  39. {
  40. get
  41. {
  42. if (ViewState["propFiltroEvento"] == null)
  43. propFiltroEvento = new Excursion();
  44. return (Excursion)ViewState["propFiltroEvento"];
  45. }
  46. set { ViewState["propFiltroEvento"] = value; }
  47. }
  48. /// <summary>
  49. /// Gets or sets the lista evento.
  50. /// </summary>
  51. /// <value>
  52. /// The lista evento.
  53. /// </value>
  54. public List<Excursion> listaEventos
  55. {
  56. get
  57. {
  58. if (ViewState["listaEventos"] == null)
  59. listaEventos = new List<Excursion>();
  60. return (List<Excursion>)ViewState["listaEventos"];
  61. }
  62. set { ViewState["listaEventos"] = value; }
  63. }
  64. /// <summary>
  65. /// Gets or sets the prop evento.
  66. /// </summary>
  67. /// <value>
  68. /// The prop evento.
  69. /// </value>
  70. public Excursion propEvento
  71. {
  72. get
  73. {
  74. if (ViewState["propEvento"] == null)
  75. propEvento = new Excursion();
  76. return (Excursion)ViewState["propEvento"];
  77. }
  78. set { ViewState["propEvento"] = value; }
  79. }
  80. #endregion
  81. #region --[Eventos]--
  82. /// <summary>
  83. /// Método que se ejecuta al dibujar los controles de la página.
  84. /// Se utiliza para gestionar las excepciones del método Page_Load().
  85. /// </summary>
  86. /// <param name="e"></param>
  87. protected override void OnPreRender(EventArgs e)
  88. {
  89. base.OnPreRender(e);
  90. if (AvisoMostrar)
  91. {
  92. AvisoMostrar = false;
  93. try
  94. {
  95. Master.ManageExceptions(AvisoExcepcion);
  96. }
  97. catch (Exception ex) { Master.ManageExceptions(ex); }
  98. }
  99. }
  100. /// <summary>
  101. /// Handles the Load event of the Page control.
  102. /// </summary>
  103. /// <param name="sender">The source of the event.</param>
  104. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  105. protected void Page_Load(object sender, EventArgs e)
  106. {
  107. try
  108. {
  109. Master.BotonAvisoAceptar += (VentanaAceptar);
  110. if (!Page.IsPostBack)
  111. {
  112. CargarPresentacion();
  113. //Siempre que se acceda a la página debiera existir una agenda
  114. propEvento.idAgendaActividad = propAgenda.idAgendaActividad;
  115. if (propEvento.idAgendaActividad > 0)
  116. {
  117. BuscarAgenda(propEvento);
  118. }
  119. }
  120. calfechas.startDate = cicloLectivoActual.fechaInicio;
  121. calfechas.endDate = cicloLectivoActual.fechaFin;
  122. calFechaEvento.startDate = cicloLectivoActual.fechaInicio;
  123. calFechaEvento.endDate = cicloLectivoActual.fechaFin;
  124. this.txtDescripcionEdit.Attributes.Add("onkeyup", " ValidarCaracteres(this, 4000);");
  125. }
  126. catch (Exception ex)
  127. {
  128. AvisoMostrar = true;
  129. AvisoExcepcion = ex;
  130. }
  131. }
  132. /// <summary>
  133. /// Ventanas the aceptar.
  134. /// </summary>
  135. /// <param name="sender">The sender.</param>
  136. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  137. void VentanaAceptar(object sender, EventArgs e)
  138. {
  139. try
  140. {
  141. switch (AccionPagina)
  142. {
  143. case enumAcciones.Buscar:
  144. break;
  145. case enumAcciones.Nuevo:
  146. break;
  147. case enumAcciones.Modificar:
  148. break;
  149. case enumAcciones.Eliminar:
  150. break;
  151. case enumAcciones.Seleccionar:
  152. break;
  153. case enumAcciones.Limpiar:
  154. CargarPresentacion();
  155. //BuscarAgenda(propEvento);
  156. BuscarFiltrando();
  157. break;
  158. case enumAcciones.Aceptar:
  159. break;
  160. case enumAcciones.Salir:
  161. break;
  162. case enumAcciones.Redirect:
  163. break;
  164. case enumAcciones.Guardar:
  165. AccionPagina = enumAcciones.Limpiar;
  166. GuardarEvento(ObtenerValoresDePantalla());
  167. Master.MostrarMensaje(enumTipoVentanaInformacion.Satisfactorio.ToString(), UIConstantesGenerales.MensajeGuardadoOk, enumTipoVentanaInformacion.Satisfactorio);
  168. break;
  169. case enumAcciones.Ingresar:
  170. break;
  171. case enumAcciones.Desbloquear:
  172. break;
  173. default:
  174. break;
  175. }
  176. }
  177. catch (Exception ex)
  178. {
  179. Master.ManageExceptions(ex);
  180. }
  181. }
  182. /// <summary>
  183. /// Handles the Click event of the btnBuscar 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 btnBuscar_Click(object sender, EventArgs e)
  188. {
  189. try
  190. {
  191. BuscarFiltrando();
  192. }
  193. catch (Exception ex)
  194. {
  195. Master.ManageExceptions(ex);
  196. }
  197. }
  198. /// <summary>
  199. /// DESACTIVADO!!!!!!
  200. /// Handles the Click event of the btnNuevo 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 btnNuevo_Click(object sender, EventArgs e)
  205. {
  206. try
  207. {
  208. AccionPagina = enumAcciones.Nuevo;
  209. LimpiarCampos();
  210. esNuevo = true;
  211. btnGuardar.Visible = true;
  212. btnBuscar.Visible = false;
  213. btnVolver.Visible = true;
  214. btnNuevo.Visible = false;
  215. gvwReporte.Visible = false;
  216. litEditar.Visible = false;
  217. litNuevo.Visible = true;
  218. udpEdit.Visible = true;
  219. udpFiltrosBusqueda.Visible = false;
  220. udpFiltros.Update();
  221. udpGrilla.Update();
  222. }
  223. catch (Exception ex)
  224. {
  225. Master.ManageExceptions(ex);
  226. }
  227. }
  228. /// <summary>
  229. /// Handles the Click event of the btnAsignarRol control.
  230. /// </summary>
  231. /// <param name="sender">The source of the event.</param>
  232. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  233. protected void btnGuardar_Click(object sender, EventArgs e)
  234. {
  235. try
  236. {
  237. string mensaje = ValidarPagina();
  238. if (mensaje == string.Empty)
  239. {
  240. if (Page.IsValid)
  241. {
  242. AccionPagina = enumAcciones.Guardar;
  243. Master.MostrarMensaje(enumTipoVentanaInformacion.Confirmación.ToString(), UIConstantesGenerales.MensajeConfirmarCambios, enumTipoVentanaInformacion.Confirmación);
  244. }
  245. }
  246. else
  247. {
  248. Master.MostrarMensaje(enumTipoVentanaInformacion.Advertencia.ToString(), UIConstantesGenerales.MensajeDatosFaltantes + mensaje, enumTipoVentanaInformacion.Advertencia);
  249. }
  250. }
  251. catch (Exception ex)
  252. {
  253. Master.ManageExceptions(ex);
  254. }
  255. }
  256. /// <summary>
  257. /// Handles the Click event of the btnVolver control.
  258. /// </summary>
  259. /// <param name="sender">The source of the event.</param>
  260. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  261. protected void btnVolver_Click(object sender, EventArgs e)
  262. {
  263. try
  264. {
  265. Response.Redirect("ManageAgendaActividades.aspx", false);
  266. }
  267. catch (Exception ex)
  268. {
  269. Master.ManageExceptions(ex);
  270. }
  271. }
  272. /// <summary>
  273. /// Método que se llama al hacer click sobre las acciones de la grilla
  274. /// </summary>
  275. /// <param name="sender">The source of the event.</param>
  276. /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewCommandEventArgs"/> instance containing the event data.</param>
  277. protected void gvwReporte_RowCommand(object sender, GridViewCommandEventArgs e)
  278. {
  279. try
  280. {
  281. switch (e.CommandName)
  282. {
  283. case "Editar":
  284. propEvento.idEventoAgenda = Convert.ToInt32(e.CommandArgument.ToString());
  285. CargarEvento();
  286. break;
  287. }
  288. }
  289. catch (Exception ex)
  290. {
  291. Master.ManageExceptions(ex);
  292. }
  293. }
  294. #endregion
  295. #region --[Métodos Privados]--
  296. /// <summary>
  297. /// Cargars the grilla.
  298. /// </summary>
  299. /// <typeparam name="T"></typeparam>
  300. /// <param name="lista">The lista.</param>
  301. private void CargarGrilla()
  302. {
  303. gvwReporte.DataSource = UIUtilidades.BuildDataTable<Excursion>(listaEventos).DefaultView;
  304. gvwReporte.DataBind();
  305. udpEdit.Visible = false;
  306. udpGrilla.Update();
  307. }
  308. /// <summary>
  309. /// Cargars the presentacion.
  310. /// </summary>
  311. private void CargarPresentacion()
  312. {
  313. lblTitulo.Text = propAgenda.cursoCicloLectivo.curso.nombre + " - " + propAgenda.cursoCicloLectivo.cicloLectivo.nombre;
  314. LimpiarCampos();
  315. //CargarCombos();
  316. udpEdit.Visible = false;
  317. btnVolver.Visible = true;
  318. btnGuardar.Visible = false;
  319. udpFiltrosBusqueda.Visible = true;
  320. btnNuevo.Visible = true;
  321. btnBuscar.Visible = true;
  322. gvwReporte.Visible = true;
  323. udpFiltros.Update();
  324. udpGrilla.Update();
  325. }
  326. /// <summary>
  327. /// Limpiars the campos.
  328. /// </summary>
  329. private void LimpiarCampos()
  330. {
  331. txtHoraDesdeEdit.Text = string.Empty;
  332. txtHoraHastaEdit.Text = string.Empty;
  333. chkActivo.Checked = true;
  334. chkActivoEdit.Checked = false;
  335. calFechaEvento.LimpiarControles();
  336. calfechas.LimpiarControles();
  337. txtDescripcionEdit.Text = string.Empty;
  338. txtDestinoEdit.Text = string.Empty;
  339. }
  340. /// <summary>
  341. /// Buscars the filtrando.
  342. /// </summary>
  343. private void BuscarFiltrando()
  344. {
  345. calfechas.ValidarRangoDesdeHasta(false);
  346. Excursion evento = new Excursion();
  347. evento.activo = chkActivo.Checked;
  348. evento.fechaEventoDesde = Convert.ToDateTime(calfechas.ValorFechaDesde);
  349. evento.fechaEventoHasta = Convert.ToDateTime(calfechas.ValorFechaHasta);
  350. if (txtHoraDesdeEdit.Text.Trim().Length > 1)
  351. evento.horaDesde = Convert.ToDateTime(txtHoraDesdeEdit.Text);
  352. if (txtHoraHastaEdit.Text.Trim().Length > 1)
  353. evento.horaHasta = Convert.ToDateTime(txtHoraHastaEdit.Text);
  354. propFiltroEvento = evento;
  355. BuscarAgenda(evento);
  356. }
  357. /// <summary>
  358. /// Buscars the eventos.
  359. /// </summary>
  360. /// <param name="evento">The evento.</param>
  361. private void BuscarAgenda(Excursion evento)
  362. {
  363. CargarLista(evento);
  364. CargarGrilla();
  365. }
  366. /// <summary>
  367. /// Cargars the lista.
  368. /// </summary>
  369. /// <param name="evento">The evento.</param>
  370. private void CargarLista(Excursion evento)
  371. {
  372. objBLAgenda = new BLAgendaActividades();
  373. evento.idAgendaActividad = propAgenda.idAgendaActividad;
  374. listaEventos = objBLAgenda.GetExcursionesAgenda(evento);
  375. }
  376. /// <summary>
  377. /// Obteners the valores pantalla.
  378. /// </summary>
  379. /// <returns></returns>
  380. private Excursion ObtenerValoresDePantalla()
  381. {
  382. Excursion evento = new Excursion();
  383. evento = propEvento;
  384. if (!esNuevo)
  385. {
  386. evento.idAgendaActividad = propAgenda.idAgendaActividad;
  387. evento.idEventoAgenda = propEvento.idEventoAgenda;
  388. }
  389. evento.fechaEvento = Convert.ToDateTime(calFechaEvento.ValorFecha);
  390. evento.horaDesde = Convert.ToDateTime(txtHoraDesdeEdit.Text.Trim());
  391. evento.horaHasta = Convert.ToDateTime(txtHoraHastaEdit.Text.Trim());
  392. evento.destino = txtDestinoEdit.Text.Trim();
  393. evento.descripcion = txtDescripcionEdit.Text.Trim();
  394. evento.activo = chkActivoEdit.Checked;
  395. evento.usuario.username = ObjSessionDataUI.ObjDTUsuario.Nombre;
  396. evento.fechaAlta = DateTime.Now;
  397. return evento;
  398. }
  399. /// <summary>
  400. /// Registrar el evento.
  401. /// </summary>
  402. /// <param name="evento">The evento.</param>
  403. private void GuardarEvento(EventoAgenda evento)
  404. {
  405. objBLAgenda = new BLAgendaActividades(propAgenda);
  406. objBLAgenda.GetById();
  407. evento.tipoEventoAgenda.idTipoEventoAgenda = (int)enumEventoAgendaType.Excursion;
  408. if (objBLAgenda.VerificarAgendaExcursion(evento) && objBLAgenda.VerificarAgendaEvaluacion(evento,0))
  409. {
  410. objBLAgenda.Data.listaExcursiones.Add((Excursion)evento);
  411. objBLAgenda.Save();
  412. }
  413. }
  414. /// <summary>
  415. /// Cargars the evento.
  416. /// </summary>
  417. private void CargarValoresEnPantalla(int idEventoAgenda)
  418. {
  419. propEvento = listaEventos.Find(c => c.idEventoAgenda == idEventoAgenda);
  420. txtDescripcionEdit.Text = propEvento.descripcion;
  421. txtDestinoEdit.Text = propEvento.destino;
  422. txtHoraDesdeEdit.Text = Convert.ToDateTime(propEvento.horaDesde).ToShortTimeString();
  423. txtHoraHastaEdit.Text = Convert.ToDateTime(propEvento.horaHasta).ToShortTimeString();
  424. calFechaEvento.Fecha.Text = Convert.ToDateTime(propEvento.fechaEvento).ToShortDateString();
  425. chkActivoEdit.Checked = propEvento.activo;
  426. }
  427. private string ValidarPagina()
  428. {
  429. calFechaEvento.ValidarRangoDesde(true);
  430. string mensaje = string.Empty;
  431. if (txtDescripcionEdit.Text.Trim().Length == 0)
  432. mensaje = "- Descripcion<br />";
  433. if (txtHoraDesdeEdit.Text.Trim().Length == 0)
  434. mensaje += "- Hora Desde<br />";
  435. if (txtHoraHastaEdit.Text.Trim().Length == 0)
  436. mensaje += "- Hora Hasta<br />";
  437. if (calFechaEvento.Fecha.Text.Trim().Length == 0)
  438. mensaje += "- Fecha<br />";
  439. return mensaje;
  440. }
  441. /// <summary>
  442. /// Cargars the evento.
  443. /// </summary>
  444. private void CargarEvento()
  445. {
  446. AccionPagina = enumAcciones.Modificar;
  447. esNuevo = false;
  448. CargarValoresEnPantalla(propEvento.idEventoAgenda);
  449. litEditar.Visible = true;
  450. litNuevo.Visible = false;
  451. btnBuscar.Visible = false;
  452. btnNuevo.Visible = false;
  453. btnVolver.Visible = true;
  454. btnGuardar.Visible = true;
  455. gvwReporte.Visible = false;
  456. udpFiltrosBusqueda.Visible = false;
  457. udpEdit.Visible = true;
  458. udpFiltros.Update();
  459. udpEdit.Update();
  460. }
  461. #endregion
  462. }
  463. }