Esempio n. 1
0
        private void btnConsultar_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtIdCurso.Text))
            {
                txtCurso.Text = "";
                errorContainer1.errorProvider1.SetError(txtIdCurso, "Debe seleccionar un curso.");
                txtIdCurso.Select(0, txtIdCurso.Text.Length);
                txtIdCurso.Focus();
                return;
            }
            if (string.IsNullOrWhiteSpace(cboHorario.Text))
            {
                cboHorario.Text = "";
                errorContainer1.errorProvider1.SetError(cboHorario, "Debe seleccionar un horario.");
                cboHorario.Select(0, cboHorario.Text.Length);
                cboHorario.Focus();
                return;
            }
            if (string.IsNullOrWhiteSpace(cboProfesor.Text))
            {
                cboProfesor.Text = "";
                errorContainer1.errorProvider1.SetError(cboProfesor, "Debe seleccionar un profesor.");
                cboProfesor.Select(0, cboProfesor.Text.Length);
                cboProfesor.Focus();
                return;
            }
            ReportDataSource reportDataSource1 = new ReportDataSource();

            //this.bindingSource1.DataSource = typeof(CursosEntities.Entities.Curso);
            reportDataSource1.Name  = "DataSet1";
            reportDataSource1.Value = this.bindingSource1;
            var viewer = new Reports.ReportViewer();

            viewer.reportViewer1.LocalReport.DataSources.Add(reportDataSource1);
            viewer.reportViewer1.LocalReport.ReportEmbeddedResource =
                "Cursos.Presentation.Reports.Ausencias.Ausencias.rdlc";
            try
            {
                //var query = from u in commB.GetList<Curso>()
                //                select u;
                var query = commB.ReporteAusenciasDtos();
                if (!string.IsNullOrEmpty(txtIdCurso.Text))
                {
                    query = query.Where(q => q.IdCurso == Convert.ToInt32(txtIdCurso.Text));
                }
                if (!string.IsNullOrEmpty(txtIdEstudiante.Text))
                {
                    query = query.Where(q => q.IdEstudiante == Convert.ToInt32(txtIdEstudiante.Text));
                }
                query = query.Where(q => q.IdHorario == Convert.ToInt32(cboHorario.SelectedValue));
                query = query.Where(q => q.IdProfesor == Convert.ToInt32(cboProfesor.SelectedValue));
                List <CursosDtos.ReporteAusenciasList> ls = query.ToList();
                foreach (var item in ls)
                {
                    Debug.WriteLine(item.NombreEstudiante);
                }
                List <ReportParameter> paramList = new List <ReportParameter>();
                string parameterNombre           = commB.GetList <Parametro>().FirstOrDefault().Nombre;

                string cursosDescripcion = commB.GetList <Curso>().
                                           Where(c => c.IdCurso == Convert.ToInt32(txtIdCurso.Text.Trim())).FirstOrDefault().Descripcion;

                // nombre profesor
                //string profesoresNombre = "Sin profesor";
                //if (cboProfesor.SelectedValue!=null)
                string profesoresNombre = commB.GetList <Profesore>().
                                          Where(h => h.IdProfesor == Convert.ToInt32(cboProfesor.SelectedValue)).FirstOrDefault().Nombre;
                //List<CursosProfesor> lsP = new List<CursosProfesor>();
                //lsP = commB.GetList<CursosProfesor>().Where(c => c.IdCurso == Convert.ToInt32(txtIdCurso.Text.Trim())).ToList();
                //if (lsP.Count > 0)
                //{
                //    profesoresNombre = commB.GetList<Profesore>().FirstOrDefault().
                //        lsP.Where
                //    profesoresNombre = commB.GetList<Curso>().FirstOrDefault().CursosProfesors.
                //        Where(c => c.IdCurso == Convert.ToInt32(txtIdCurso.Text.Trim())).
                //        FirstOrDefault().Profesore.Nombre;
                //}

                string horariosDescripcion = commB.GetList <Horario>().
                                             Where(h => h.IdHorario == Convert.ToInt32(cboHorario.SelectedValue)).FirstOrDefault().Descripcion;

                paramList.Add(new ReportParameter("pParametrosNombre", @parameterNombre));
                paramList.Add(new ReportParameter("pCursosDescripcion", @cursosDescripcion));
                paramList.Add(new ReportParameter("pProfesoresNombre", @profesoresNombre));
                paramList.Add(new ReportParameter("pHorariosDescripcion", @horariosDescripcion));
                viewer.reportViewer1.LocalReport.SetParameters(paramList);

                bindingSource1.DataSource = ls;
                viewer.ShowDialog();
                viewer.reportViewer1.RefreshReport();
            }
            catch (Exception ex)
            {
                General.LogInfo(ex, "Cursos", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }