Example #1
0
        private void btTaoReport_Click(object sender, EventArgs e)
        {
            this.repBaoCao.RefreshReport();

            try
            {
                var listDTB = diembus.GetDiemHK(int.Parse(cbLop.SelectedValue.ToString()), int.Parse(cbHocKi.SelectedValue.ToString())).GroupBy(x => x.MaHS).Select(x => new DiemTrungBinhMon()
                {
                    TenHS    = x.First().TenHS,
                    NgaySinh = x.First().NgaySinh,
                    GioiTinh = x.First().GioiTinh,
                    SinhHoc  = (x.Where(i => i.IdMonHoc == 1).Sum(j => j.DTB) / x.Where(i => i.IdMonHoc == 1).Count()).ToString(),
                    HoaHoc   = (x.Where(i => i.IdMonHoc == 2).Sum(j => j.DTB) / x.Where(i => i.IdMonHoc == 2).Count()).ToString(),
                    TiengAnh = (x.Where(i => i.IdMonHoc == 3).Sum(j => j.DTB) / x.Where(i => i.IdMonHoc == 3).Count()).ToString(),
                    DiaLi    = (x.Where(i => i.IdMonHoc == 4).Sum(j => j.DTB) / x.Where(i => i.IdMonHoc == 4).Count()).ToString(),
                    LichSu   = (x.Where(i => i.IdMonHoc == 5).Sum(j => j.DTB) / x.Where(i => i.IdMonHoc == 5).Count()).ToString(),
                    NguVan   = (x.Where(i => i.IdMonHoc == 6).Sum(j => j.DTB) / x.Where(i => i.IdMonHoc == 6).Count()).ToString(),
                    Toan     = (x.Where(i => i.IdMonHoc == 7).Sum(j => j.DTB) / x.Where(i => i.IdMonHoc == 7).Count()).ToString(),
                    VatLi    = (x.Where(i => i.IdMonHoc == 8).Sum(j => j.DTB) / x.Where(i => i.IdMonHoc == 8).Count()).ToString(),
                    DTB      = (float)Math.Round(x.Sum(i => i.DTB) / x.Count(), 2),
                    TenLop   = cbLop.SelectedText.ToString()
                }).ToList();

                DataTable dt = ConvertToDataTable(listDTB);
                repBaoCao.ProcessingMode         = Microsoft.Reporting.WinForms.ProcessingMode.Local;
                repBaoCao.LocalReport.ReportPath = "DiemTongKet.rdlc";
                ReportDataSource rds = new ReportDataSource();
                rds.Name  = "DataSet1TongDiem";
                rds.Value = dt;
                if (dt.Rows.Count > 0)
                {
                    repBaoCao.LocalReport.DataSources.Clear();
                    repBaoCao.LocalReport.DataSources.Add(rds);
                    repBaoCao.RefreshReport();
                }
                else
                {
                    repBaoCao.LocalReport.DataSources.Clear();
                    repBaoCao.RefreshReport();
                    MessageBox.Show("Không có học sinh");
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Chưa chọn lớp");
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var listdiem = diembus.GetDiemHK(int.Parse(cbLop.SelectedValue.ToString()),
                                             int.Parse(cbHocKi.SelectedValue.ToString())).GroupBy(x => x.MaHS).Select(x =>
                                                                                                                      new
            {
                TenHS    = x.First().TenHS,
                NgaySinh = x.First().NgaySinh,
                DTB      = Math.Round(x.Sum(i => i.DTB) / x.Count(), 2),
                XepLoai  = (x.Sum(i => i.DTB) / x.Count()) >= 8 ? "Giỏi" : (x.Sum(i => i.DTB) / x.Count()) >= 6.5 && (x.Sum(i => i.DTB) / x.Count()) < 8 ? "Khá" : (x.Sum(i => i.DTB) / x.Count()) >= 5 && (x.Sum(i => i.DTB) / x.Count()) < 6.5 ? "Trung Bình" : "Yếu",
            }).OrderByDescending(x => x.DTB).ToList();

            drgXepLoaiHS.DataSource = listdiem;
            for (int i = 0; i < listdiem.Count; i++)
            {
                drgXepLoaiHS.Rows[i].Cells[0].Value = (i + 1);
            }
        }