public void GenerateReport()
        {
            BEAdmin objBEAdmin = new BEAdmin();
            BAdmin  objBAdmin  = new BAdmin();

            objBEAdmin.strCourseID = GetExamIds();
            objBEAdmin.IntUserID   = 0; //for admin
            objBAdmin.BGetAppointmentScheduleReportDetails(objBEAdmin);

            DataTable objDt = objBEAdmin.DtResult;


            objDt.Columns["ExamID"].ColumnName                  = "Exam ID";
            objDt.Columns["StudentFirstName"].ColumnName        = "Student First Name";
            objDt.Columns["StudentLastName"].ColumnName         = "Student Last Name";
            objDt.Columns["EmailAddress"].ColumnName            = "Email Address";
            objDt.Columns["CourseName"].ColumnName              = "Course Name";
            objDt.Columns["ExamName"].ColumnName                = "Exam Name";
            objDt.Columns["InstructorName"].ColumnName          = "Instructor Name";
            objDt.Columns["AppointmentCreationDate"].ColumnName = "Appointment Creation Date [EST]";
            objDt.Columns["AppointmentDate"].ColumnName         = "Appointment Date [EST]";
            objDt.Columns["ExamDuration"].ColumnName            = "Exam Duration";
            objDt.Columns["FairExamLevel"].ColumnName           = "Fair ExamLevel";
            objDt.Columns["StatusName"].ColumnName              = "Status";

            objDt.Columns.Remove("CourseID");


            string Examsummary = Server.MapPath(ConfigurationManager.AppSettings["Reports"].ToString()) + '\\' + "Schedule details" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss").Replace("/", "-").Replace(":", "-") + ".xls";

            if (File.Exists(Examsummary))
            {
                File.Delete(Examsummary);
            }
            FileInfo rptFileName = new FileInfo(Examsummary);

            //  this.DeleteHistoricFiles();

            ExcelSheetGenerator objExcel = new ExcelSheetGenerator();

            objExcel.GenerateReport(objDt, rptFileName, " Schedule details ", "UserName");

            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

            Response.AppendHeader("Content-Disposition", "attachment; filename=" + "Schedule details" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss").Replace("/", "-") + ".xlsx");


            Response.TransmitFile(rptFileName.ToString());
            Response.End();
        }
        protected void LoadSummaryReportSort(string ids)
        {
            try
            {
                BEAdmin objBEAdmin = new BEAdmin();
                BAdmin  objBAdmin  = new BAdmin();

                objBEAdmin.strCourseID = ids;
                objBEAdmin.IntUserID   = 0; //for admin
                objBAdmin.BGetAppointmentScheduleReportDetails(objBEAdmin);

                gvReports.DataSource = objBEAdmin.DtResult;


                ViewState["gvReports"] = objBEAdmin.DtResult;
            }
            catch (Exception Ex)
            {
                ErrorHandlers.ErrorLog.WriteError(Ex);
            }
        }
Пример #3
0
        //for populating the grid
        protected void LoadSummaryReport(string ids)
        {
            try
            {
                BEAdmin objBEAdmin = new BEAdmin();
                BAdmin  objBAdmin  = new BAdmin();

                objBEAdmin.strCourseID = ids;
                objBEAdmin.IntUserID   = Convert.ToInt32(Session[EnumPageSessions.USERID]);
                objBAdmin.BGetAppointmentScheduleReportDetails(objBEAdmin);

                gvReports.DataSource = objBEAdmin.DtResult;
                gvReports.DataBind();

                ViewState["gvReports"] = objBEAdmin.DtResult;
            }
            catch (Exception Ex)
            {
                ErrorHandlers.ErrorLog.WriteError(Ex);
            }
        }
        public void SendEmail()
        {
            lblResult.Text = "";
            BEAdmin objBEAdmin = new BEAdmin();
            BAdmin  objBAdmin  = new BAdmin();

            objBEAdmin.strCourseID = GetExamIds();
            objBEAdmin.IntUserID   = 0; //for admin
            objBAdmin.BGetAppointmentScheduleReportDetails(objBEAdmin);

            DataTable objDt = objBEAdmin.DtResult;


            objDt.Columns["ExamID"].ColumnName                  = "Exam ID";
            objDt.Columns["StudentFirstName"].ColumnName        = "Student First Name";
            objDt.Columns["StudentLastName"].ColumnName         = "Student Last Name";
            objDt.Columns["EmailAddress"].ColumnName            = "Email Address";
            objDt.Columns["CourseName"].ColumnName              = "Course Name";
            objDt.Columns["ExamName"].ColumnName                = "Exam Name";
            objDt.Columns["InstructorName"].ColumnName          = "Instructor Name";
            objDt.Columns["AppointmentCreationDate"].ColumnName = "Appointment Creation Date [EST]";
            objDt.Columns["AppointmentDate"].ColumnName         = "Appointment Date [EST]";
            objDt.Columns["ExamDuration"].ColumnName            = "Exam Duration";
            objDt.Columns["FairExamLevel"].ColumnName           = "Fair ExamLevel";
            objDt.Columns["StatusName"].ColumnName              = "Status";

            objDt.Columns.Remove("CourseID");



            FileInfo rptFileName = new FileInfo(Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["Reports"].ToString()) + @"\Schedule details from_" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss").Replace("/", "-").Replace(":", "-") + ".xls");

            // If any file exists in this directory having name 'Sample1.xlsx', then delete it
            if (rptFileName.Exists)
            {
                rptFileName.Delete(); // ensures we create a new workbook
                rptFileName = new FileInfo(Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["Reports"].ToString()) + @"\Schedule details from_" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss").Replace("/", "-").Replace(":", "-") + ".xls");
            }

            ExcelSheetGenerator objExcel = new ExcelSheetGenerator();

            objExcel.GenerateReport(objDt, rptFileName, "Schedule details _", "UserName");
            string ToEmail = txtEmail.Text;

            System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage();
            StringBuilder body = new StringBuilder();

            email.From = new MailAddress("*****@*****.**");
            email.To.Add(ToEmail.Replace(" ", ""));
            email.Subject = "Schedule details";
            body.Append("<table style='font-family:Helvetica;font-size:9pt;width:600px;'>");
            body.Append(@"<tr><td>Hi,<br/><br/>Please find the enclosed Schedule details report.
<br/><br/><br/>Thank you,<br/>Examity.<br/><b>***DO NOT REPLY TO THIS EMAIL***</b></td></tr>");
            body.Append("</table>");
            // Attachment goes here
            Attachment attachment = new Attachment(rptFileName.ToString());

            attachment.Name = "Schedule details" + ".xlsx";
            email.Attachments.Add(attachment);  //add the attachment

            email.Body       = body.ToString();
            email.IsBodyHtml = true;
            SmtpClient obj = new SmtpClient
            {
                Host                  = ConfigurationManager.AppSettings["smtpServer"],
                Port                  = Convert.ToInt32(ConfigurationManager.AppSettings["smtpPort"]),
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["smtpUser"].ToString(), ConfigurationManager.AppSettings["Reportspassword"].ToString())
            };

            obj.Send(email);

            lblResult.Text = "<font color='Blue' size='4px'>" + "Report emailed sucessfully." + "</font>";
        }