Ejemplo n.º 1
0
        public ActionResult IndividualGradeSheet(int?examId, int?Roll, int?DeparmentId)
        {
            try
            {
                double totalGPA = 0;
                int    flag     = 1;

                var           getResult = DDL.GetSingleResult(Roll.Value, examId, DeparmentId, null);
                StudentInfo   student   = db.StudentInfoes.Where(t => t.RollNo == Roll).SingleOrDefault();
                FacultyInfo   facinfo   = db.FacultyInfoes.Where(t => t.Id == DeparmentId).SingleOrDefault();
                List <result> result    = new List <result>();

                // get total Subject from StudentInfoSubject Except optional = Y
                int StudentSubject = db.StudentInfoSubjects.Where(t => t.OptionalSubject != "Y" && t.StudentId == student.Id).Count();


                if (getResult != null)
                {
                    foreach (var item in getResult)
                    {
                        //get is this subjectId is Optional
                        grade _grade = new grade();
                        if (item.PassStatus == "F")
                        {
                            _grade.Grade      = "F";
                            _grade.GradePoint = 0;
                        }
                        else
                        {
                            _grade = getGrade(item.MarksObtain);
                        }

                        if (item.OptionalSubject == "Y")
                        {
                            totalGPA += (_grade.GradePoint - 2) > 0 ? (_grade.GradePoint - 2) : 0;
                        }
                        else
                        {
                            if (flag == 1 && _grade.GradePoint < 1)
                            {
                                flag = 0;
                            }
                            totalGPA += _grade.GradePoint;
                        }

                        result.Add(new result
                        {
                            SubjectName = item.SubjectName,
                            Grade       = _grade.Grade,
                            GradePoint  = Convert.ToString(_grade.GradePoint)
                        });
                    }

                    if (flag == 0)
                    {
                        totalGPA = 0;
                    }
                    else
                    {
                        totalGPA = totalGPA / StudentSubject;
                    }
                }

                string GPA = "";

                if (totalGPA < 1)
                {
                    GPA = "0 " + "(F)";
                }
                else if (totalGPA < 2)
                {
                    GPA = totalGPA.ToString("0.##") + " (D)";
                }
                else if (totalGPA < 3)
                {
                    GPA = totalGPA.ToString("0.##") + " (C)";
                }
                else if (totalGPA < 3.5)
                {
                    GPA = totalGPA.ToString("0.##") + " (B)";
                }
                else if (totalGPA < 4)
                {
                    GPA = totalGPA.ToString("0.##") + " (A-)";
                }
                else if (totalGPA < 5)
                {
                    GPA = totalGPA.ToString("0.##") + " (A)";
                }
                else if (totalGPA < 6)
                {
                    GPA = totalGPA.ToString("0.##") + " (A+)";
                }

                LocalReport      lr = new LocalReport();
                ReportDataSource rd = new ReportDataSource();

                lr.ReportPath = Server.MapPath("~/ReporFile/IndividualGradeSheet.rdlc");

                DataTable dtFDRStatement = ConvertToDataTable(result.ToList());
                rd.Name  = "SingleResult";
                rd.Value = dtFDRStatement;

                ReportParameter[] parameters = new ReportParameter[]
                {
                    new ReportParameter("Name", student.StudentName),
                    new ReportParameter("ClassRoll", Convert.ToString(student.RollNo)),
                    new ReportParameter("Faculty", Convert.ToString(facinfo.FacultyName)),
                    new ReportParameter("GPA", GPA)          // returns "0"  when decimalVar == 0
                };

                lr.SetParameters(parameters);
                lr.DataSources.Add(rd);

                string reportType = "PDF";
                string mimeType;
                string encoding;
                string fileNameExtension;

                string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>PDF</OutputFormat>" +
                    "  <PageWidth>10.5in</PageWidth>" +
                    "  <PageHeight>11in</PageHeight>" +
                    "  <MarginTop>0.5in</MarginTop>" +
                    "  <MarginLeft>1in</MarginLeft>" +
                    "  <MarginRight>1in</MarginRight>" +
                    "  <MarginBottom>0.5in</MarginBottom>" +
                    "</DeviceInfo>";

                Warning[] warnings;
                string[]  streams;
                byte[]    renderedBytes;
                renderedBytes = lr.Render(
                    reportType,
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings);

                renderedBytes = lr.Render(reportType);
                string reportName = "IndGradeSheet-Roll" + Convert.ToString(student.RollNo) + ".pdf";
                return(File(renderedBytes, mimeType, reportName));
            }
            catch (Exception ex) {
                ViewBag.Error = ex.Message;
                return(View("Error"));
            }
        }