Пример #1
0
        private void btnPrintRpt_Click(object sender, EventArgs e)
        {
            string query = "SELECT Tag, FeesPaid, Count(*) AS \"Count\" FROM Enrollments WHERE ClassID IN (SELECT ClassID FROM Classes WHERE SessionID = @SessionID) GROUP BY Tag, FeesPaid";
            Dictionary <string, object> p = new Dictionary <string, object>();

            p.Add("@SessionID", cmbSession.SelectedValue);
            DataSet tagBreakDown = SqlHelper.GetDataSet(query, p);

            query = "SELECT SUM(FeesPaid) FROM Enrollments WHERE ClassID IN (SELECT ClassID FROM Classes WHERE SessionID = @SessionID)";
            double sessionTotal = Convert.ToDouble(SqlHelper.GetScalar(query, p));

            FileInfo template = new FileInfo("SessionEndReportTemplate.pyhtm");

            if (!template.Exists)
            {
                MessageBox.Show("Cannot find template file");
                return;
            }
            StreamReader sr          = template.OpenText();
            string       strTemplate = sr.ReadToEnd();

            sr.Close();
            StringBuilder sb = new StringBuilder();

            sb.Append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
            sb.Append("<html>");
            sb.Append("<head>");
            sb.Append("<title>Session End Report</title>");
            sb.Append("</head>");
            sb.Append("<body>");
            PyTemplate py = new PyTemplate();

            py.AddGlobal("TagBreakDown", tagBreakDown.Tables[0]);
            py.AddGlobal("SessionTotal", sessionTotal);
            query = "SELECT Name FROM Sessions WHERE SessionID = @SessionID";
            string SessionName = SqlHelper.GetScalar(query, p).ToString();

            py.AddGlobal("Session", SessionName);
            py.Parse(strTemplate);
            sb.AppendLine(py.Render());
            sb.Append("</body>");
            sb.Append("</html>");
            webBrowser1.DocumentText = sb.ToString();
            do
            {
                Application.DoEvents();
            } while (webBrowser1.ReadyState != WebBrowserReadyState.Complete);

            webBrowser1.ShowPrintPreviewDialog();
        }
Пример #2
0
        private void btnPrintRpt_Click(object sender, EventArgs e)
        {
            string query = "SELECT Tag, FeesPaid, Count(*) AS \"Count\" FROM Enrollments WHERE ClassID IN (SELECT ClassID FROM Classes WHERE SessionID = @SessionID) GROUP BY Tag, FeesPaid";
            Dictionary<string, object> p = new Dictionary<string, object>();
            p.Add("@SessionID", cmbSession.SelectedValue);
            DataSet tagBreakDown = SqlHelper.GetDataSet(query, p);

            query = "SELECT SUM(FeesPaid) FROM Enrollments WHERE ClassID IN (SELECT ClassID FROM Classes WHERE SessionID = @SessionID)";
            double sessionTotal = Convert.ToDouble(SqlHelper.GetScalar(query, p));

            FileInfo template = new FileInfo("SessionEndReportTemplate.pyhtm");
            if (!template.Exists)
            {
                MessageBox.Show("Cannot find template file");
                return;
            }
            StreamReader sr = template.OpenText();
            string strTemplate = sr.ReadToEnd();
            sr.Close();
            StringBuilder sb = new StringBuilder();
            sb.Append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
            sb.Append("<html>");
            sb.Append("<head>");
            sb.Append("<title>Session End Report</title>");
            sb.Append("</head>");
            sb.Append("<body>");
            PyTemplate py = new PyTemplate();
            py.AddGlobal("TagBreakDown", tagBreakDown.Tables[0]);
            py.AddGlobal("SessionTotal", sessionTotal);
            query = "SELECT Name FROM Sessions WHERE SessionID = @SessionID";
            string SessionName = SqlHelper.GetScalar(query, p).ToString();
            py.AddGlobal("Session", SessionName);
            py.Parse(strTemplate);
            sb.AppendLine(py.Render());
            sb.Append("</body>");
            sb.Append("</html>");
            webBrowser1.DocumentText = sb.ToString();
            do
            {
                Application.DoEvents();
            } while (webBrowser1.ReadyState != WebBrowserReadyState.Complete);

            webBrowser1.ShowPrintPreviewDialog();
        }
Пример #3
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            string query = @"SELECT ClassID,
            Course.Title, Course.Description,
            Instructors.LastName, Instructors.FirstName,
            Periods.Name AS Period, Periods.StartTime, Periods.EndTime,
            ClassRooms.RoomNumber, ClassRooms.MaxStudents, ClassRooms.Notes,
            Schools.Name As School,
            Sessions.Name AS Session, Sessions.StartDate AS StartDate, Sessions.EndDate
            FROM Classes
            LEFT OUTER JOIN Course ON Course.CourseID = Classes.CourseID
            LEFT OUTER JOIN Instructors ON Classes.InstructorID = Instructors.InstructorID
            LEFT OUTER JOIN Periods ON Classes.PeriodID = Periods.PeriodID
            LEFT OUTER JOIN ClassRooms ON Classes.ClassRoomID = ClassRooms.ClassRoomID
            LEFT OUTER JOIN Schools ON ClassRooms.SchoolID = Schools.SchoolID
            LEFT OUTER JOIN Sessions ON Classes.SessionID = Sessions.SessionID
            WHERE ClassID = @ClassID;";
            FileInfo template = new FileInfo("RollTemplate.pyhtm");
            if (!template.Exists)
            {
                MessageBox.Show("Cannot find template file");
                return;
            }
            StreamReader sr = template.OpenText();
            string strTemplate = sr.ReadToEnd();
            sr.Close();
            StringBuilder sb = new StringBuilder();
            sb.Append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
            sb.Append("<html>");
            sb.Append("<head>");
            sb.Append("<title>Class Roll</title>");
            sb.Append("</head>");
            sb.Append("<body>");
            int count = 0;
            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                PyTemplate py = new PyTemplate();
                SqlHelper.Parameters.Clear();
                Int64 ID = Convert.ToInt64(((DataRowView)row.DataBoundItem).Row["ClassID"]);
                SqlHelper.Parameters.Add("@ClassID", ID);
                DataSet dsClassInfo = SqlHelper.GetDataSet(query);
                py.AddGlobal("ClassInfo", dsClassInfo.Tables[0]);
                string enrollmentQuery = @"SELECT LastName, FirstName, Schools.Name AS School FROM Enrollments
            JOIN Students ON Enrollments.StudentID = Students.StudentID
            JOIN Schools ON Students.SchoolID = Schools.SchoolID
            WHERE ClassID = @ClassID
            ORDER BY LastName ASC";
                SqlHelper.Parameters.Clear();
                SqlHelper.Parameters.Add("@ClassID", ID);
                DataSet dsRoll = SqlHelper.GetDataSet(enrollmentQuery);
                py.AddGlobal("RollInfo", dsRoll.Tables[0]);
                py.Parse(strTemplate);
                sb.AppendLine(py.Render());
                count++;
                if(count < dataGridView1.SelectedRows.Count)
                    sb.AppendLine("<br style=\"page-break-after: always;\"/>");
            }
            sb.Append("</body>");
            sb.Append("</html>");
            webBrowser1.DocumentText = sb.ToString();
            do
            {
                Application.DoEvents();
            } while (webBrowser1.ReadyState != WebBrowserReadyState.Complete);

            webBrowser1.ShowPrintPreviewDialog();
        }
Пример #4
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            string   query    = @"SELECT ClassID, 
Course.Title, Course.Description,
Instructors.LastName, Instructors.FirstName, 
Periods.Name AS Period, Periods.StartTime, Periods.EndTime,
ClassRooms.RoomNumber, ClassRooms.MaxStudents, ClassRooms.Notes,
Schools.Name As School,
Sessions.Name AS Session, Sessions.StartDate AS StartDate, Sessions.EndDate
FROM Classes 
LEFT OUTER JOIN Course ON Course.CourseID = Classes.CourseID
LEFT OUTER JOIN Instructors ON Classes.InstructorID = Instructors.InstructorID
LEFT OUTER JOIN Periods ON Classes.PeriodID = Periods.PeriodID
LEFT OUTER JOIN ClassRooms ON Classes.ClassRoomID = ClassRooms.ClassRoomID
LEFT OUTER JOIN Schools ON ClassRooms.SchoolID = Schools.SchoolID
LEFT OUTER JOIN Sessions ON Classes.SessionID = Sessions.SessionID
WHERE ClassID = @ClassID;";
            FileInfo template = new FileInfo("RollTemplate.pyhtm");

            if (!template.Exists)
            {
                MessageBox.Show("Cannot find template file");
                return;
            }
            StreamReader sr          = template.OpenText();
            string       strTemplate = sr.ReadToEnd();

            sr.Close();
            StringBuilder sb = new StringBuilder();

            sb.Append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
            sb.Append("<html>");
            sb.Append("<head>");
            sb.Append("<title>Class Roll</title>");
            sb.Append("</head>");
            sb.Append("<body>");
            int count = 0;

            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                PyTemplate py = new PyTemplate();
                SqlHelper.Parameters.Clear();
                Int64 ID = Convert.ToInt64(((DataRowView)row.DataBoundItem).Row["ClassID"]);
                SqlHelper.Parameters.Add("@ClassID", ID);
                DataSet dsClassInfo = SqlHelper.GetDataSet(query);
                py.AddGlobal("ClassInfo", dsClassInfo.Tables[0]);
                string enrollmentQuery = @"SELECT LastName, FirstName, Schools.Name AS School FROM Enrollments
JOIN Students ON Enrollments.StudentID = Students.StudentID
JOIN Schools ON Students.SchoolID = Schools.SchoolID 
WHERE ClassID = @ClassID 
ORDER BY LastName ASC";
                SqlHelper.Parameters.Clear();
                SqlHelper.Parameters.Add("@ClassID", ID);
                DataSet dsRoll = SqlHelper.GetDataSet(enrollmentQuery);
                py.AddGlobal("RollInfo", dsRoll.Tables[0]);
                py.Parse(strTemplate);
                sb.AppendLine(py.Render());
                count++;
                if (count < dataGridView1.SelectedRows.Count)
                {
                    sb.AppendLine("<br style=\"page-break-after: always;\"/>");
                }
            }
            sb.Append("</body>");
            sb.Append("</html>");
            webBrowser1.DocumentText = sb.ToString();
            do
            {
                Application.DoEvents();
            } while (webBrowser1.ReadyState != WebBrowserReadyState.Complete);

            webBrowser1.ShowPrintPreviewDialog();
        }