Example #1
0
        private void cmdSelect_Click(object sender, EventArgs e)
        {
            if (cboSections.SelectedItem != null)
            {
                Cursor = Cursors.WaitCursor;

                try
                {
                    // Get classes and courses of the section.
                    GetClasses();
                    GetCourses();

                    // determine if classes has saturday or sunday
                    for (int i = 0; i < classes.Count; i++)
                    {
                        if (classes[i].Day == "Saturday" || classes[i].Day == "Sunday")
                        {
                            hasweekend = true;
                            break;
                        }
                    }

                    // Create a new report.
                    report = new SectionReport(sections[cboSections.SelectedIndex].SectionName, sections[cboSections.SelectedIndex].YearLevel, hasweekend);
                    report.AddNewPage();
                    report.AddLogo(string.Concat(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "ACRACS-Schedule"), "/reports/logo.png"));
                    report.AddHeaderText_SchoolName("Asian College", "Dumaguete");
                    report.AddHeaderText_Department(Program.currentuser_deptDesc);
                    report.AddHeaderText_Section(sections[cboSections.SelectedIndex].SectionName);
                    report.Create_ReportTable();

                    for (int i = 0; i < classes.Count; i++)
                    {
                        // concatenate all sections
                        for (int x = 0; x < classes[i].Sections.Count; x++)
                        {
                            if (x == 0)
                            {
                                msections = classes[i].Sections[0].SectionName;
                            }
                            else
                            {
                                msections += string.Concat(", ", classes[i].Sections[x].SectionName);
                            }
                        }

                        GetIndexClassCourse(classes[i]);
                        report.AddClass(classes[i], classes[i].Course.Coursecode, classes[i].Room.Name, msections, new MigraDoc.DocumentObjectModel.Color(Program.subjectColors[index_ClassCourse].R, Program.subjectColors[index_ClassCourse].G, Program.subjectColors[index_ClassCourse].B));

                        msections = string.Empty;
                    }
                    report.Render();
                    report.Save(string.Concat(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "ACRACS-Schedule", "reports"), "/", sections[cboSections.SelectedIndex].SectionName, ".pdf"));
                    Program.mainForm.pdfViewer.Document = new Apitron.PDF.Rasterizer.Document(new FileStream(string.Concat(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "ACRACS-Schedule"), "/reports/", sections[cboSections.SelectedIndex].SectionName, ".pdf"), FileMode.Open));

                    hasweekend = false;
                    Cursor     = Cursors.Default;
                    Close();
                }
                catch (Exception ex)
                {
                    Program.dbConnection.Close();
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                MessageBox.Show("Please select a section first.", "No section selected", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }
        }