public override void RefreshView()
        {
            SchoolObjContext Context = new SchoolObjContext();

            this.AllSubjects = new ObservableCollection <object>(
                (from Subject in Context.Subjects
                 join Standard in Context.Standards
                 on Subject.StandardId equals Standard.StandardId
                 select new
            {
                Id = Subject.Id,
                Name = Subject.Name,
                Standard = Standard.StandardName
            }).ToList()
                );

            AllStandards = Context.Standards.ToList();
            AllStandards.Insert(0, new EntityDatabase.DomainClasses.Standard()
            {
                StandardId = 0, StandardName = "All"
            });
            this.SelectedStandard = this._SelectedStandard;
        }
        public SubjectViewModel(string StdId = "0")
        {
            this.TabTitle    = "Subjects";
            this.ButtonText  = "Save";
            this.UserControl = new UserControls.Subject()
            {
                DataContext = this
            };

            using (var context = new SchoolObjContext())
            {
                AllStandards = context.Standards.ToList();
                AllStandards.Insert(0, new EntityDatabase.DomainClasses.Standard()
                {
                    StandardId = 0, StandardName = "All"
                });
            }

            this.StandardSelectionChanged(new EntityDatabase.DomainClasses.Standard());
            StdColumnVisibility = System.Windows.Visibility.Visible;
            SelectedStandard    = AllStandards.Find(x => x.StandardId == int.Parse(StdId));

            SaveChangesCommand = new RelayCommand(x => SaveChanges());
        }
Пример #3
0
        public ReportResultViewModel()
        {
            this.TabTitle    = "Result Report";
            this.UserControl = new ResultReport()
            {
                DataContext = this
            };
            using (var context = new SchoolObjContext())
            {
                AllStandards = context.Standards.ToList();
                AllStandards.Insert(0, new EntityDatabase.DomainClasses.Standard()
                {
                    StandardId = 0, StandardName = "All"
                });
                SelectedStandard = AllStandards[0];
            }
            ShowResultCommand  = new RelayCommand(x => MainViewModel.Tabs.Add(new ViewModels.ResultViewModel((int)CurrentItem.Student.StudentId, (int)CurrentItem.StandardId)));
            PrintResultCommand = new RelayCommand(x =>
            {
                Student student          = x as Student;
                student.StandardId       = (int)(CurrentItem as dynamic).StandardId;
                SchoolObjContext Context = new SchoolObjContext();

                SaveFileDialog Dialog = new SaveFileDialog()
                {
                    Filter = "FDF (.*pdf)|*.pdf"
                };
                if (Dialog.ShowDialog() == false)
                {
                    return;
                }

                System.IO.FileStream fs = new FileStream(Dialog.FileName, FileMode.Create);
                Document document       = new Document(PageSize.A4, 7f, 5f, 5f, 0f);
                PdfWriter writer        = PdfWriter.GetInstance(document, fs);
                document.Open();

                PdfPTable StudentInfoTable = new PdfPTable(2);

                PdfPCell cell            = new PdfPCell(new Phrase("Student"));
                cell.Colspan             = 2;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.Padding             = 10;
                StudentInfoTable.AddCell(cell);

                StudentInfoTable.AddCell("Name");
                StudentInfoTable.AddCell(student.FirstName + " " + student.MiddleName + " " + student.LastName);


                StudentInfoTable.AddCell("Seat No.");
                StudentInfoTable.AddCell(student.StudentId.ToString());

                StudentInfoTable.AddCell("Standard");
                StudentInfoTable.AddCell(Context.Standards.Where(s => s.StandardId == student.StandardId).Select(s => s.StandardName).FirstOrDefault().ToString());

                StudentInfoTable.AddCell("Age");
                StudentInfoTable.AddCell(student.Age.ToString());

                StudentInfoTable.AddCell("City");
                StudentInfoTable.AddCell(student.City);

                document.Add(StudentInfoTable);

                PdfPTable ResultTable = new PdfPTable(3);
                cell                     = new PdfPCell(new Phrase("Result"));
                cell.Colspan             = 3;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.Padding             = 10;
                ResultTable.AddCell(cell);

                var SubAndMarks = (from Subject in Context.Subjects
                                   join Marksheet in Context.AllMarks
                                   on Subject.Id equals Marksheet.SubjectId
                                   orderby Marksheet.StudentId descending
                                   where Marksheet.StudentId == student.StudentId && Marksheet.StandardId == student.StandardId
                                   select new
                {
                    MarksheetId = Marksheet.Id,
                    SubjectName = Subject.Name,
                    Mark = Marksheet.Mark,
                    Result = Marksheet.Mark < 35 ? "Fail" : "Pass"
                }).ToList();

                int Total = 0, Count = 0;
                foreach (dynamic item in SubAndMarks)
                {
                    ResultTable.AddCell(item.SubjectName as string);
                    int Mark = ((int)item.Mark);
                    Total   += Mark;
                    Count++;
                    ResultTable.AddCell(Mark.ToString());
                    ResultTable.AddCell(item.Result as string);
                }
                cell         = new PdfPCell(new Phrase("Total : " + Total));
                cell.Colspan = 3;
                cell.Padding = 5;
                ResultTable.AddCell(cell);

                cell         = new PdfPCell(new Phrase("Percentage : " + (CurrentItem as dynamic).Percentage + "%"));
                cell.Colspan = 3;
                cell.Padding = 5;
                ResultTable.AddCell(cell);

                cell         = new PdfPCell(new Phrase("Result : " + (CurrentItem as dynamic).Result));
                cell.Colspan = 3;
                cell.Padding = 5;
                ResultTable.AddCell(cell);

                document.Add(ResultTable);

                document.Close();
                writer.Close();
                fs.Close();

                Context.StudentResultCanEditables.Add(new StudentResultCanEditable()
                {
                    StandardId = student.StandardId,
                    StudentId  = student.StudentId
                });
                Context.SaveChanges();
            });
        }