public void GenerateReport()
        {
            int      clientID  = 0;
            SurveyBL objSurvey = new SurveyBL();

            clientID = objSurvey.GetPortalClientId();


            int examId = 0;

            if (!string.IsNullOrEmpty(txtExamID.Text))
            {
                examId = Convert.ToInt32(txtExamID.Text);
            }

            SurveyBL objBl = new SurveyBL();
            DataSet  ds    = objBl.GetSurveyIndividualReport(clientID.ToString(), txtStudentName.Text, examId, rdpFromDate.SelectedDate.Value, rdpToDate.SelectedDate.Value);



            FileInfo rptFileName = new FileInfo(Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["Reports"].ToString()) + @"\ Individual Responses from_" + rdpFromDate.SelectedDate.Value.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()) + @"\ Individual Responses from_" + rdpFromDate.SelectedDate.Value.ToString("MM/dd/yyyy HH:mm:ss").Replace("/", "-").Replace(":", "-") + ".xls");
            }
            // this.DeleteHistoricFiles();

            if (ds != null & ds.Tables.Count > 0)
            {
                ExcelSheetGenerator objExcel = new ExcelSheetGenerator();
                objExcel.GenerateReport(ds.Tables[0], rptFileName, "Individual Responses", "UserName");
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + "Individual Responses Report From -" + rdpFromDate.SelectedDate.Value.ToString("MM/dd/yyyy").Replace("/", "-").Replace(":", "-") + " " + rdpToDate.SelectedDate.Value.ToString("MM/dd/yyyy").Replace("/", "-").Replace(":", "-") + "" + ".xlsx");
                Response.TransmitFile(rptFileName.ToString());
                Response.End();
                gReport.DataSource = ds.Tables[0];
            }
            else
            {
                gReport.DataSource = new object[0];
            }
        }
Exemple #2
0
        protected void gReport_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            int      providerId = Convert.ToInt32(Session[BaseClass.EnumPageSessions.USERID]);
            int      clientID   = 0;
            SurveyBL objSurvey  = new SurveyBL();

            clientID = objSurvey.GetPortalClientId();

            int examId = 0;

            if (!string.IsNullOrEmpty(txtExamID.Text))
            {
                examId = Convert.ToInt32(txtExamID.Text);
            }

            SurveyBL objBl = new SurveyBL();
            DataSet  ds    = null;

            if (rdpFromDate.SelectedDate != null && rdpToDate.SelectedDate != null)
            {
                ds = objBl.GetSurveyIndividualReport(clientID.ToString(), txtStudentName.Text, examId, rdpFromDate.SelectedDate.Value, rdpToDate.SelectedDate.Value, providerId);
            }
            if (ds != null)
            {
                if (ds.Tables.Count > 0)
                {
                    gReport.DataSource = ds.Tables[0];
                }
                else
                {
                    gReport.DataSource = new object[0];
                }
            }
            else
            {
                gReport.DataSource = new object[0];
            }
            objBl = null;
        }