/Docs/07-Implementacion/Source/trunk/EDUAR_Regular/EDUAR/EDUAR_UI/Private/Reports/ReportCalificacionesAlumnoPeriodo.aspx.cs

http://blpm.googlecode.com/ · C# · 851 lines · 646 code · 77 blank · 128 comment · 68 complexity · 25e013076c2ae9db97bbf576b23c6dc8 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using EDUAR_BusinessLogic.Common;
  10. using EDUAR_BusinessLogic.Reports;
  11. using EDUAR_Entities;
  12. using EDUAR_Entities.Reports;
  13. using EDUAR_UI.Shared;
  14. using EDUAR_UI.Utilidades;
  15. using EDUAR_Utility.Constantes;
  16. using EDUAR_Utility.Enumeraciones;
  17. using iTextSharp.text;
  18. namespace EDUAR_UI
  19. {
  20. public partial class ReportCalificacionesAlumnoPeriodo : EDUARBasePage
  21. {
  22. #region --[Propiedades]--
  23. /// <summary>
  24. /// Gets or sets the filtro calificaciones.
  25. /// </summary>
  26. /// <value>
  27. /// The filtro calificaciones.
  28. /// </value>
  29. public FilCalificacionesAlumnoPeriodo filtroReporte
  30. {
  31. get
  32. {
  33. if (ViewState["filtroCalificaciones"] == null)
  34. filtroReporte = new FilCalificacionesAlumnoPeriodo();
  35. return (FilCalificacionesAlumnoPeriodo)ViewState["filtroCalificaciones"];
  36. }
  37. set
  38. {
  39. ViewState["filtroCalificaciones"] = value;
  40. }
  41. }
  42. /// <summary>
  43. /// Gets or sets the lista calificaciones.
  44. /// </summary>
  45. /// <value>
  46. /// The lista calificaciones.
  47. /// </value>
  48. public List<RptCalificacionesAlumnoPeriodo> listaReporte
  49. {
  50. get
  51. {
  52. if (Session["listaCalificaciones"] == null)
  53. listaReporte = new List<RptCalificacionesAlumnoPeriodo>();
  54. return (List<RptCalificacionesAlumnoPeriodo>)Session["listaCalificaciones"];
  55. }
  56. set
  57. {
  58. Session["listaCalificaciones"] = value;
  59. }
  60. }
  61. /// <summary>
  62. /// Gets or sets the filtros aplica2.
  63. /// </summary>
  64. /// <value>
  65. /// The filtros aplica2.
  66. /// </value>
  67. public string filtrosAplicados
  68. {
  69. get
  70. {
  71. if (Session["filtrosAplicados"] == null)
  72. filtrosAplicados = string.Empty;
  73. return Session["filtrosAplicados"].ToString();
  74. }
  75. set
  76. {
  77. Session["filtrosAplicados"] = value;
  78. }
  79. }
  80. /// <summary>
  81. /// Gets or sets the lista asignaturas.
  82. /// </summary>
  83. /// <value>
  84. /// The lista sanciones.
  85. /// </value>
  86. public List<Asignatura> listaAsignatura
  87. {
  88. get
  89. {
  90. if (ViewState["listaAsignatura"] == null)
  91. listaAsignatura = new List<Asignatura>();
  92. return (List<Asignatura>)ViewState["listaAsignatura"];
  93. }
  94. set
  95. {
  96. ViewState["listaAsignatura"] = value;
  97. }
  98. }
  99. /// <summary>
  100. /// Gets or sets the lista ciclo lectivo.
  101. /// </summary>
  102. /// <value>
  103. /// The lista ciclo lectivo.
  104. /// </value>
  105. public List<CicloLectivo> listaCicloLectivo
  106. {
  107. get
  108. {
  109. if (ViewState["listaCicloLectivo"] == null)
  110. {
  111. listaCicloLectivo = new List<CicloLectivo>();
  112. BLCicloLectivo objBLCicloLectivo = new BLCicloLectivo();
  113. listaCicloLectivo = objBLCicloLectivo.GetCicloLectivos(null);
  114. }
  115. return (List<CicloLectivo>)ViewState["listaCicloLectivo"];
  116. }
  117. set
  118. {
  119. ViewState["listaCicloLectivo"] = value;
  120. }
  121. }
  122. #endregion
  123. #region --[Eventos]--
  124. /// <summary>
  125. /// Método que se ejecuta al dibujar los controles de la página.
  126. /// Se utiliza para gestionar las excepciones del método Page_Load().
  127. /// </summary>
  128. /// <param name="e"></param>
  129. protected override void OnPreRender(EventArgs e)
  130. {
  131. base.OnPreRender(e);
  132. if (AvisoMostrar)
  133. {
  134. AvisoMostrar = false;
  135. try
  136. {
  137. Master.ManageExceptions(AvisoExcepcion);
  138. }
  139. catch (Exception ex) { Master.ManageExceptions(ex); }
  140. }
  141. }
  142. /// <summary>
  143. /// Handles the Load event of the Page control.
  144. /// </summary>
  145. /// <param name="sender">The source of the event.</param>
  146. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  147. protected void Page_Load(object sender, EventArgs e)
  148. {
  149. try
  150. {
  151. rptCalificaciones.ExportarPDFClick += (ExportarPDF);
  152. rptCalificaciones.VolverClick += (VolverReporte);
  153. rptCalificaciones.PaginarGrilla += (PaginarGrilla);
  154. Master.BotonAvisoAceptar += (VentanaAceptar);
  155. rptCalificaciones.GraficarClick += (btnGraficar);
  156. if (!Page.IsPostBack)
  157. {
  158. TablaGrafico = null;
  159. CargarPresentacion();
  160. divFiltros.Visible = true;
  161. divReporte.Visible = false;
  162. }
  163. if (listaReporte != null)
  164. rptCalificaciones.CargarReporte<RptCalificacionesAlumnoPeriodo>(listaReporte);
  165. }
  166. catch (Exception ex)
  167. {
  168. AvisoMostrar = true;
  169. AvisoExcepcion = ex;
  170. }
  171. }
  172. /// <summary>
  173. /// Ventanas the aceptar.
  174. /// </summary>
  175. /// <param name="sender">The sender.</param>
  176. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  177. protected void VentanaAceptar(object sender, EventArgs e)
  178. {
  179. AccionPagina = enumAcciones.Limpiar;
  180. //divFiltros.Visible = true;
  181. //divReporte.Visible = false;
  182. }
  183. /// <summary>
  184. /// Handles the Click event of the btnBuscar control.
  185. /// </summary>
  186. /// <param name="sender">The source of the event.</param>
  187. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  188. protected void btnBuscar_Click(object sender, EventArgs e)
  189. {
  190. try
  191. {
  192. fechas.ValidarRangoDesdeHasta(false);
  193. string mensaje = ValidarPagina();
  194. if (mensaje == string.Empty)
  195. {
  196. AccionPagina = enumAcciones.Buscar;
  197. if (BuscarCalificaciones())
  198. {
  199. AccionPagina = enumAcciones.Limpiar;
  200. divFiltros.Visible = false;
  201. divReporte.Visible = true;
  202. }
  203. else
  204. { Master.MostrarMensaje("Faltan Datos", UIConstantesGenerales.MensajeDatosRequeridos, EDUAR_Utility.Enumeraciones.enumTipoVentanaInformacion.Advertencia); }
  205. }
  206. else
  207. { Master.MostrarMensaje("Faltan Datos", UIConstantesGenerales.MensajeDatosFaltantes + mensaje, EDUAR_Utility.Enumeraciones.enumTipoVentanaInformacion.Advertencia); }
  208. }
  209. catch (Exception ex)
  210. { Master.ManageExceptions(ex); }
  211. }
  212. /// <summary>
  213. /// Exportars the PDF.
  214. /// </summary>
  215. /// <param name="sender">The sender.</param>
  216. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  217. protected void ExportarPDF(object sender, EventArgs e)
  218. {
  219. try
  220. {
  221. AccionPagina = enumAcciones.Limpiar;
  222. string nombreGrafico = string.Empty;
  223. if (rptCalificaciones.verGrafico)
  224. nombreGrafico = nombrePNG;
  225. ExportPDF.ExportarPDF(Page.Title, rptCalificaciones.dtReporte, ObjSessionDataUI.ObjDTUsuario.Nombre, filtrosAplicados, nombreGrafico);
  226. }
  227. catch (Exception ex)
  228. { Master.ManageExceptions(ex); }
  229. }
  230. /// <summary>
  231. /// Volvers the reporte.
  232. /// </summary>
  233. /// <param name="sender">The sender.</param>
  234. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  235. protected void VolverReporte(object sender, EventArgs e)
  236. {
  237. try
  238. {
  239. AccionPagina = enumAcciones.Limpiar;
  240. rptCalificaciones.verGrafico = false;
  241. divFiltros.Visible = true;
  242. divReporte.Visible = false;
  243. }
  244. catch (Exception ex)
  245. { Master.ManageExceptions(ex); }
  246. }
  247. /// <summary>
  248. /// BTNs the graficar.
  249. /// </summary>
  250. /// <param name="sender">The sender.</param>
  251. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  252. private void btnGraficar(object sender, EventArgs e)
  253. {
  254. try
  255. {
  256. //GenerarDatosGrafico();
  257. AccionPagina = enumAcciones.Limpiar;
  258. float sumaNotas = 0;
  259. rptCalificaciones.graficoReporte.LimpiarSeries();
  260. string alumno = string.Empty;
  261. if (Convert.ToInt32(ddlAlumno.SelectedValue) > 0)
  262. alumno = "\n" + ddlAlumno.SelectedItem.Text + "\n";
  263. if (ddlAsignatura.SelectedIndex > 0)
  264. { // so reporte distribucion de calificaciones por asignatura
  265. foreach (System.Web.UI.WebControls.ListItem asignatura in ddlAsignatura.Items)
  266. {
  267. if (asignatura.Selected)
  268. {
  269. var serie = new List<RptCalificacionesAlumnoPeriodo>();
  270. for (int i = 1; i < 11; i++)
  271. {
  272. var listaParcial = listaReporte.FindAll(p => p.calificacion == i.ToString() && p.asignatura == asignatura.Text);
  273. if (listaParcial.Count > 0)
  274. {
  275. serie.Add(new RptCalificacionesAlumnoPeriodo
  276. {
  277. calificacion = listaParcial.Count.ToString(),
  278. asignatura = i.ToString()
  279. });
  280. }
  281. }
  282. if (serie != null && serie.Count > 0)
  283. {
  284. DataTable dt = UIUtilidades.BuildDataTable<RptCalificacionesAlumnoPeriodo>(serie);
  285. // En alumno envio la nota y en calificación la cantidad de esa nota que se produjo
  286. rptCalificaciones.graficoReporte.AgregarSerie(asignatura.Text, dt, "asignatura", "calificacion");
  287. }
  288. }
  289. }
  290. rptCalificaciones.graficoReporte.Titulo = "Distribución de Calificaciones \n" + alumno;
  291. }
  292. else
  293. { // promedio de calificaciones por curso en un determinado periodo
  294. var serie = new List<RptCalificacionesAlumnoPeriodo>();
  295. foreach (var item in listaAsignatura)
  296. {
  297. sumaNotas = 0;
  298. var listaParcial = listaReporte.FindAll(p => p.asignatura == item.nombre);
  299. if (listaParcial.Count > 0)
  300. {
  301. foreach (var nota in listaParcial)
  302. {
  303. sumaNotas += Convert.ToInt16(nota.calificacion);
  304. }
  305. serie.Add(new RptCalificacionesAlumnoPeriodo
  306. {
  307. calificacion = Math.Round(sumaNotas / listaParcial.Count, 2).ToString(CultureInfo.InvariantCulture),
  308. asignatura = item.nombre
  309. });
  310. }
  311. }
  312. DataTable dt = UIUtilidades.BuildDataTable<RptCalificacionesAlumnoPeriodo>(serie);
  313. rptCalificaciones.graficoReporte.AgregarSerie("Promedio", dt, "asignatura", "calificacion");
  314. BLValoresEscalaCalificacion objBLNivelAprobacion = new BLValoresEscalaCalificacion();
  315. ValoresEscalaCalificacion escala = new ValoresEscalaCalificacion();
  316. escala = objBLNivelAprobacion.GetNivelProbacion();
  317. List<ValoresEscalaCalificacion> listaEscala = new List<ValoresEscalaCalificacion>();
  318. foreach (RptCalificacionesAlumnoPeriodo item in serie)
  319. {
  320. listaEscala.Add(new ValoresEscalaCalificacion
  321. {
  322. valor = escala.valor,
  323. nombre = item.asignatura
  324. });
  325. }
  326. DataTable dtEscala = UIUtilidades.BuildDataTable<ValoresEscalaCalificacion>(listaEscala);
  327. rptCalificaciones.graficoReporte.AgregarSerie("Nivel de Aprobación (" + escala.nombre + ")", dtEscala, "nombre", "valor", true);
  328. rptCalificaciones.graficoReporte.Titulo = "Promedio Por Asignatura \n" + ddlCurso.SelectedItem.Text + " - " + ddlCicloLectivo.SelectedItem.Text + alumno;
  329. }
  330. GenerarDatosGrafico();
  331. rptCalificaciones.graficoReporte.GraficarBarra();
  332. rptCalificaciones.CargarReporte<RptCalificacionesAlumnoPeriodo>(listaReporte);
  333. }
  334. catch (Exception ex)
  335. { Master.ManageExceptions(ex); }
  336. }
  337. /// <summary>
  338. /// Paginars the grilla.
  339. /// </summary>
  340. /// <param name="sender">The sender.</param>
  341. /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewPageEventArgs"/> instance containing the event data.</param>
  342. protected void PaginarGrilla(object sender, GridViewPageEventArgs e)
  343. {
  344. try
  345. {
  346. int pagina = e.NewPageIndex;
  347. if (rptCalificaciones.GrillaReporte.PageCount > pagina)
  348. {
  349. rptCalificaciones.GrillaReporte.PageIndex = pagina;
  350. rptCalificaciones.CargarReporte<RptCalificacionesAlumnoPeriodo>(listaReporte);
  351. }
  352. }
  353. catch (Exception ex)
  354. {
  355. Master.ManageExceptions(ex);
  356. }
  357. }
  358. /// <summary>
  359. /// Handles the SelectedIndexChanged event of the ddlCicloLectivo control.
  360. /// </summary>
  361. /// <param name="sender">The source of the event.</param>
  362. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  363. protected void ddlCicloLectivo_SelectedIndexChanged(object sender, EventArgs e)
  364. {
  365. try
  366. {
  367. AccionPagina = enumAcciones.Limpiar;
  368. int idCicloLectivo = Convert.ToInt32(ddlCicloLectivo.SelectedValue);
  369. if (idCicloLectivo > 0)
  370. {
  371. fechas.startDate = listaCicloLectivo.Find(p => p.idCicloLectivo == idCicloLectivo).fechaInicio;
  372. fechas.endDate = listaCicloLectivo.Find(p => p.idCicloLectivo == idCicloLectivo).fechaFin;
  373. CargarComboCursos(idCicloLectivo, ddlCurso);
  374. }
  375. else
  376. {
  377. if (ddlCurso.Items.Count > 0)
  378. {
  379. ddlCurso.Items.Clear();
  380. ddlCurso.Enabled = false;
  381. }
  382. }
  383. ddlAsignatura.Items.Clear();
  384. ddlAlumno.Items.Clear();
  385. }
  386. catch (Exception ex)
  387. {
  388. Master.ManageExceptions(ex);
  389. }
  390. }
  391. /// <summary>
  392. /// Handles the SelectedIndexChanged event of the ddlCurso control.
  393. /// </summary>
  394. /// <param name="sender">The source of the event.</param>
  395. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  396. protected void ddlCurso_SelectedIndexChanged(object sender, EventArgs e)
  397. {
  398. try
  399. {
  400. AccionPagina = enumAcciones.Limpiar;
  401. CargarAlumnos(Convert.ToInt32(ddlCurso.SelectedValue));
  402. ddlAlumno.Enabled = true;
  403. ddlAsignatura.Items.Clear();
  404. CargarComboAsignatura();
  405. }
  406. catch (Exception ex)
  407. {
  408. Master.ManageExceptions(ex);
  409. }
  410. }
  411. #endregion
  412. #region --[Métodos Privados]--
  413. /// <summary>
  414. /// Cargars the presentacion.
  415. /// </summary>
  416. private void CargarPresentacion()
  417. {
  418. CargarCombos();
  419. btnBuscar.Visible = true;
  420. }
  421. /// <summary>
  422. /// Buscars the calificaciones.
  423. /// </summary>
  424. private bool BuscarCalificaciones()
  425. {
  426. if (AccionPagina == enumAcciones.Buscar)
  427. {
  428. filtroReporte = new FilCalificacionesAlumnoPeriodo();
  429. StringBuilder filtros = new StringBuilder();
  430. if (Convert.ToInt32(ddlCicloLectivo.SelectedValue) > 0 && Convert.ToInt32(ddlCurso.SelectedValue) > 0 /*&& Convert.ToInt32(ddlAsignatura.SelectedValue) > 0*/)
  431. {
  432. filtros.AppendLine("- " + ddlCicloLectivo.SelectedItem.Text + " - Curso: " + ddlCurso.SelectedItem.Text);
  433. List<Asignatura> listaAsignatura = new List<Asignatura>();
  434. foreach (System.Web.UI.WebControls.ListItem item in ddlAsignatura.Items)
  435. {
  436. if (item.Selected)
  437. {
  438. if (!filtros.ToString().Contains("- Asignatura"))
  439. filtros.AppendLine("- Asignatura");
  440. filtros.AppendLine(" * " + item.Text);
  441. listaAsignatura.Add(new Asignatura() { idAsignatura = Convert.ToInt16(item.Value) });
  442. }
  443. }
  444. filtroReporte.listaAsignaturas = listaAsignatura;
  445. if (fechas.ValorFechaDesde != null)
  446. {
  447. filtros.AppendLine("- Fecha Desde: " + ((DateTime)fechas.ValorFechaDesde).ToShortDateString());
  448. filtroReporte.fechaDesde = (DateTime)fechas.ValorFechaDesde;
  449. }
  450. if (fechas.ValorFechaHasta != null)
  451. {
  452. filtros.AppendLine("- Fecha Hasta: " + ((DateTime)fechas.ValorFechaHasta).ToShortDateString());
  453. filtroReporte.fechaHasta = (DateTime)fechas.ValorFechaHasta;
  454. }
  455. filtroReporte.idCurso = Convert.ToInt32(ddlCurso.SelectedValue);
  456. filtroReporte.idCicloLectivo = Convert.ToInt32(ddlCicloLectivo.SelectedValue);
  457. if (Convert.ToInt32(ddlAlumno.SelectedValue) > 0)
  458. {
  459. filtroReporte.idAlumno = Convert.ToInt32(ddlAlumno.SelectedValue);
  460. filtros.AppendLine("- Alumno: " + ddlAlumno.SelectedItem.Text);
  461. }
  462. if (Context.User.IsInRole(enumRoles.Docente.ToString()))
  463. filtroReporte.username = ObjSessionDataUI.ObjDTUsuario.Nombre;
  464. BLRptCalificacionesAlumnoPeriodo objBLReporte = new BLRptCalificacionesAlumnoPeriodo();
  465. listaReporte = objBLReporte.GetRptCalificacionesAlumnoPeriodo(filtroReporte);
  466. filtrosAplicados = filtros.ToString();
  467. rptCalificaciones.CargarReporte<RptCalificacionesAlumnoPeriodo>(listaReporte);
  468. //udpReporte.Update();
  469. return true;
  470. }
  471. return false;
  472. }
  473. else
  474. return false;
  475. }
  476. /// <summary>
  477. /// Validars the pagina.
  478. /// </summary>
  479. /// <returns></returns>
  480. private string ValidarPagina()
  481. {
  482. string mensaje = string.Empty;
  483. if (string.IsNullOrEmpty(ddlCicloLectivo.SelectedValue) || Convert.ToInt32(ddlCicloLectivo.SelectedValue) <= 0)
  484. mensaje = "- Ciclo Lectivo<br />";
  485. if (string.IsNullOrEmpty(ddlCurso.SelectedValue) || Convert.ToInt32(ddlCurso.SelectedValue) <= 0)
  486. mensaje += "- Curso<br />";
  487. return mensaje;
  488. }
  489. /// <summary>
  490. /// Cargars the combos.
  491. /// </summary>
  492. private void CargarCombos()
  493. {
  494. List<Curso> listaCurso = new List<Curso>();
  495. List<Alumno> listaAlumno = new List<Alumno>();
  496. UIUtilidades.BindCombo<CicloLectivo>(ddlCicloLectivo, listaCicloLectivo, "idCicloLectivo", "nombre", true);
  497. UIUtilidades.BindCombo<Curso>(ddlCurso, listaCurso, "idCurso", "nombre", true);
  498. if (ddlCicloLectivo.Items.Count > 0)
  499. {
  500. ddlCicloLectivo.SelectedIndex = ddlCicloLectivo.Items.Count - 1;
  501. fechas.startDate = listaCicloLectivo.Find(p => p.idCicloLectivo == Convert.ToInt16(ddlCicloLectivo.SelectedValue)).fechaInicio;
  502. fechas.endDate = listaCicloLectivo.Find(p => p.idCicloLectivo == Convert.ToInt16(ddlCicloLectivo.SelectedValue)).fechaFin;
  503. CargarComboCursos(Convert.ToInt16(ddlCicloLectivo.SelectedValue), ddlCurso);
  504. ddlCurso.Enabled = true;
  505. ddlCurso.SelectedIndex = -1;
  506. }
  507. ddlAsignatura.Disabled = true;
  508. ddlAlumno.Enabled = false;
  509. }
  510. /// <summary>
  511. /// Cargars the combo cursos.
  512. /// </summary>
  513. /// <param name="idCicloLectivo">The id ciclo lectivo.</param>
  514. /// <param name="ddlCurso">The DDL curso.</param>
  515. private void CargarComboCursos(int idCicloLectivo, DropDownList ddlCurso)
  516. {
  517. if (idCicloLectivo > 0)
  518. {
  519. List<Curso> listaCurso = new List<Curso>();
  520. BLCicloLectivo objBLCicloLectivo = new BLCicloLectivo();
  521. Asignatura objAsignatura = new Asignatura();
  522. objAsignatura.curso.cicloLectivo.idCicloLectivo = idCicloLectivo;
  523. if (User.IsInRole(enumRoles.Docente.ToString()))
  524. objAsignatura.docente.username = ObjSessionDataUI.ObjDTUsuario.Nombre;
  525. listaCurso = objBLCicloLectivo.GetCursosByAsignatura(objAsignatura);
  526. UIUtilidades.BindCombo<Curso>(ddlCurso, listaCurso, "idCurso", "nombre", true);
  527. ddlCurso.Enabled = true;
  528. }
  529. else
  530. {
  531. ddlCurso.Enabled = false;
  532. }
  533. }
  534. /// <summary>
  535. /// Cargars the combo asignatura.
  536. /// </summary>
  537. private void CargarComboAsignatura()
  538. {
  539. BLAsignatura objBLAsignatura = new BLAsignatura();
  540. Asignatura materia = new Asignatura();
  541. materia.cursoCicloLectivo.idCursoCicloLectivo = Convert.ToInt32(ddlCurso.SelectedValue);
  542. if (User.IsInRole(enumRoles.Docente.ToString()))
  543. materia.docente.username = ObjSessionDataUI.ObjDTUsuario.Nombre;
  544. listaAsignatura = objBLAsignatura.GetAsignaturasCurso(materia);
  545. ddlAsignatura.Items.Clear();
  546. listaAsignatura.Sort((p, q) => string.Compare(p.nombre, q.nombre));
  547. foreach (Asignatura asignatura in listaAsignatura)
  548. {
  549. ddlAsignatura.Items.Add(new System.Web.UI.WebControls.ListItem(asignatura.nombre, asignatura.idAsignatura.ToString()));
  550. }
  551. if (ddlAsignatura.Items.Count > 0)
  552. ddlAsignatura.Disabled = false;
  553. }
  554. /// <summary>
  555. /// Cargars the alumnos.
  556. /// </summary>
  557. /// <param name="idCurso">The id curso.</param>
  558. private void CargarAlumnos(int idCurso)
  559. {
  560. BLAlumno objBLAlumno = new BLAlumno();
  561. UIUtilidades.BindCombo<Alumno>(ddlAlumno, objBLAlumno.GetAlumnos(new AlumnoCurso(idCurso)), "idAlumno", "apellido", "nombre", true);
  562. ddlAlumno.Enabled = true;
  563. }
  564. /// <summary>
  565. /// Generars the datos grafico.
  566. /// </summary>
  567. private void GenerarDatosGrafico()
  568. {
  569. TablaGrafico = new List<TablaGrafico>();
  570. TablaGrafico tabla3 = new TablaGrafico();
  571. tabla3.listaCuerpo = new List<List<string>>();
  572. List<string> encabezado3 = new List<string>();
  573. List<string> fila3 = new List<string>();
  574. var fechaMin =
  575. from p in listaReporte
  576. group p by p.alumno into g
  577. select new { Alumno = g.Key, Fecha = g.Min(p => p.fecha) };
  578. var fechaMax =
  579. from p in listaReporte
  580. group p by p.alumno into g
  581. select new { Alumno = g.Key, Fecha = g.Max(p => p.fecha) };
  582. //TablaGrafico.Add("- Periodo de notas: " + fechaMin.First().Fecha.ToShortDateString() + " - " + fechaMax.First().Fecha.ToShortDateString());
  583. tabla3.titulo = "Periodo Analizado " + fechaMin.First().Fecha.ToShortDateString() + " - " + fechaMax.First().Fecha.ToShortDateString();
  584. var cantAlumnos =
  585. from p in listaReporte
  586. group p by p.alumno into g
  587. select new { Alumno = g.Key, Cantidad = g.Count() };
  588. //TablaGrafico.Add("- Cantidad de Alumnos analiza2: " + cantAlumnos.Count().ToString());
  589. encabezado3.Add("Cantidad de Alumnos");
  590. fila3.Add(cantAlumnos.Count().ToString());
  591. //TablaGrafico.Add("- Cantidad de Calificaciones: " + listaReporte.Count.ToString());
  592. encabezado3.Add("Cantidad de Calificaciones");
  593. fila3.Add(listaReporte.Count().ToString());
  594. tabla3.listaEncabezados = encabezado3;
  595. tabla3.listaCuerpo.Add(fila3);
  596. TablaGrafico.Add(tabla3);
  597. TablaGrafico tabla2 = new TablaGrafico();
  598. tabla2.listaCuerpo = new List<List<string>>();
  599. List<string> encabezado2 = new List<string>();
  600. List<List<string>> filasTabla2 = new List<List<string>>();
  601. List<string> fila2 = new List<string>();
  602. //TablaGrafico.Add("- Desviacion Estandar por materia: ");
  603. tabla2.titulo = "Desviación Estandar por Asignatura";
  604. encabezado2.Add("Asignatura");
  605. encabezado2.Add("Promedio");
  606. encabezado2.Add("Desviación Estándar");
  607. double sumaNotas, promedio, desvStd, dif, cociente, sumaDifCuad = 0;
  608. var serie = new List<RptCalificacionesAlumnoPeriodo>();
  609. foreach (var item in listaAsignatura)
  610. {
  611. promedio = 0;
  612. cociente = 0;
  613. desvStd = 0;
  614. sumaNotas = 0;
  615. dif = 0;
  616. sumaDifCuad = 0;
  617. var listaParcial = listaReporte.FindAll(p => p.asignatura == item.nombre);
  618. if (listaParcial.Count > 0)
  619. {
  620. foreach (var nota in listaParcial)
  621. {
  622. sumaNotas += Convert.ToInt16(nota.calificacion);
  623. }
  624. promedio = sumaNotas / listaParcial.Count;
  625. foreach (var nota in listaParcial)
  626. {
  627. dif = (Convert.ToInt32(nota.calificacion) - promedio);
  628. sumaDifCuad += Math.Pow(dif, 2);
  629. }
  630. // Revisar la formula de desviacion standard
  631. //cociente = (sumaDifCuad / (listaParcial.Count-1));
  632. cociente = (sumaDifCuad / (listaParcial.Count));
  633. desvStd = Math.Sqrt(cociente);
  634. //TablaGrafico.Add(item.nombre + " Promedio: " + promedio.ToString("#.##") + " , Desviacion Standard: " + desvStd.ToString("#.##"));
  635. fila2 = new List<string>();
  636. fila2.Add(item.nombre);
  637. fila2.Add(promedio.ToString("#.##"));
  638. fila2.Add(desvStd.ToString("#.##"));
  639. filasTabla2.Add(fila2);
  640. }
  641. }
  642. tabla2.listaEncabezados = encabezado2;
  643. tabla2.listaCuerpo = filasTabla2;
  644. TablaGrafico.Add(tabla2);
  645. TablaGrafico tabla4 = new TablaGrafico();
  646. tabla4.listaCuerpo = new List<List<string>>();
  647. List<string> encabezado4 = new List<string>();
  648. List<List<string>> filasTabla4 = new List<List<string>>();
  649. List<string> fila4 = new List<string>();
  650. if (Convert.ToInt32(ddlAsignatura.SelectedIndex) < 0)
  651. {
  652. var topPromedio =
  653. (from p in listaReporte
  654. group p by p.asignatura into g
  655. orderby g.Average(p => Convert.ToInt32(p.calificacion)) descending
  656. select new { Asignatura = g.Key, Promedio = g.Average(p => Convert.ToInt32(p.calificacion)), Cantidad = g.Count() }).Distinct().Take(3);
  657. if (topPromedio.Count() > 1)
  658. {
  659. //TablaGrafico.Add("- Top 3 Materias con mejor desempeńo:");
  660. tabla4.titulo = "Top Asignaturas con mejor desempeńo";
  661. encabezado4.Add("Asignatura");
  662. encabezado4.Add("Promedio");
  663. encabezado4.Add("Cantidad de Evaluaciones");
  664. tabla4.listaEncabezados = encabezado4;
  665. foreach (var item in topPromedio)
  666. {
  667. //TablaGrafico.Add(item.Asignatura + " - Promedio: " + item.Promedio.ToString("#.##") + " - Cantidad de Evaluaciones: " + item.Cantidad.ToString());
  668. fila4 = new List<string>();
  669. fila4.Add(item.Asignatura);
  670. fila4.Add(item.Promedio.ToString("#.##"));
  671. fila4.Add(item.Cantidad.ToString());
  672. filasTabla4.Add(fila4);
  673. }
  674. tabla4.listaEncabezados = encabezado4;
  675. tabla4.listaCuerpo = filasTabla4;
  676. TablaGrafico.Add(tabla4);
  677. }
  678. var worstPromedio =
  679. (from p in listaReporte
  680. group p by p.asignatura into g
  681. orderby g.Average(p => Convert.ToInt32(p.calificacion)) ascending
  682. select new { Asignatura = g.Key, Promedio = g.Average(p => Convert.ToInt32(p.calificacion)), Cantidad = g.Count() }).Distinct().Take(3);
  683. if (worstPromedio.Count() > 1)
  684. {
  685. TablaGrafico tabla5 = new TablaGrafico();
  686. tabla5.listaCuerpo = new List<List<string>>();
  687. List<string> encabezado5 = new List<string>();
  688. List<List<string>> filasTabla5 = new List<List<string>>();
  689. List<string> fila5 = new List<string>();
  690. tabla5.titulo = "Top Asignaturas con bajo desempeńo";
  691. encabezado5.Add("Asignatura");
  692. encabezado5.Add("Promedio");
  693. encabezado5.Add("Cantidad de Evaluaciones");
  694. //TablaGrafico.Add("- Top 3 Materias con bajo desempeńo:");
  695. foreach (var item in worstPromedio)
  696. {
  697. //TablaGrafico.Add(item.Asignatura + " - Promedio: " + item.Promedio.ToString("#.##") + " - Cantidad de Evaluaciones: " + item.Cantidad.ToString());
  698. fila5 = new List<string>();
  699. fila5.Add(item.Asignatura);
  700. fila5.Add(item.Promedio.ToString("#.##"));
  701. fila5.Add(item.Cantidad.ToString());
  702. filasTabla5.Add(fila5);
  703. }
  704. tabla5.listaEncabezados = encabezado5;
  705. tabla5.listaCuerpo = filasTabla5;
  706. TablaGrafico.Add(tabla5);
  707. }
  708. }
  709. if (Convert.ToInt32(ddlAlumno.SelectedValue) < 0)
  710. {
  711. var worstAlumnos =
  712. (from p in listaReporte
  713. group p by p.alumno into g
  714. orderby g.Average(p => Convert.ToInt32(p.calificacion)) ascending
  715. select new { Alumno = g.Key, Promedio = g.Average(p => Convert.ToInt32(p.calificacion)) }).Distinct().Take(3);
  716. if (worstAlumnos.Count() > 1)
  717. {
  718. TablaGrafico tabla6 = new TablaGrafico();
  719. tabla6.listaCuerpo = new List<List<string>>();
  720. List<string> encabezado6 = new List<string>();
  721. List<List<string>> filasTabla6 = new List<List<string>>();
  722. List<string> fila6 = new List<string>();
  723. tabla6.titulo = "Top Alumnos a observar";
  724. encabezado6.Add("Alumno");
  725. encabezado6.Add("Promedio General");
  726. //TablaGrafico.Add("- Top 3 de Alumnos a observar:");
  727. foreach (var item in worstAlumnos)
  728. {
  729. //TablaGrafico.Add(item.Alumno + " - Promedio General: " + item.Promedio.ToString("#.##"));
  730. fila6 = new List<string>();
  731. fila6.Add(item.Alumno);
  732. fila6.Add(item.Promedio.ToString("#.##"));
  733. filasTabla6.Add(fila6);
  734. }
  735. tabla6.listaEncabezados = encabezado6;
  736. tabla6.listaCuerpo = filasTabla6;
  737. TablaGrafico.Add(tabla6);
  738. }
  739. }
  740. if (Convert.ToInt32(ddlAlumno.SelectedValue) < 0)
  741. {
  742. var worstAlumnos =
  743. (from p in listaReporte
  744. group p by p.alumno into g
  745. orderby g.Average(p => Convert.ToInt32(p.calificacion)) descending
  746. select new { Alumno = g.Key, Promedio = g.Average(p => Convert.ToInt32(p.calificacion)) }).Distinct().Take(3);
  747. if (worstAlumnos.Count() > 1)
  748. {
  749. TablaGrafico tabla7 = new TablaGrafico();
  750. tabla7.listaCuerpo = new List<List<string>>();
  751. List<string> encabezado7 = new List<string>();
  752. List<List<string>> filasTabla7 = new List<List<string>>();
  753. List<string> fila7 = new List<string>();
  754. tabla7.titulo = "Top Alumnos con mejores Promedios";
  755. encabezado7.Add("Alumno");
  756. encabezado7.Add("Promedio General");
  757. //TablaGrafico.Add("- Top 3 de Alumnos con mejores notas:");
  758. foreach (var item in worstAlumnos)
  759. {
  760. //TablaGrafico.Add(item.Alumno + " - Promedio General: " + item.Promedio.ToString("#.##"));
  761. fila7 = new List<string>();
  762. fila7.Add(item.Alumno);
  763. fila7.Add(item.Promedio.ToString("#.##"));
  764. filasTabla7.Add(fila7);
  765. }
  766. tabla7.listaEncabezados = encabezado7;
  767. tabla7.listaCuerpo = filasTabla7;
  768. TablaGrafico.Add(tabla7);
  769. }
  770. }
  771. }
  772. #endregion
  773. }
  774. }