Exemple #1
0
        /// <summary>
        /// used for genrate the report for Users View as per selected cretariya
        /// </summary>
        /// <param name="dateFrom"></param>
        /// <param name="dateTo"></param>
        /// <param name="status"></param>
        /// <returns>FileContentResult</returns>
        /// <createby>Bobi</createby>
        /// <createddate>25 Aug 2014</createddate>
        public FileContentResult GenrateUsersViewReport(string dateFrom, string dateTo, string status)
        {
            logMessage = new StringBuilder();
            try
            {
                logMessage.AppendLine(string.Format(CultureInfo.InvariantCulture, DecisionPointR.logmessagestart, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));

                userId    = Convert.ToInt32(HttpContext.Session["UserId"], CultureInfo.InvariantCulture);
                companyId = Convert.ToString(HttpContext.Session["CompanyId"], CultureInfo.InvariantCulture);
                using (LocalReport localReport = new LocalReport())
                {
                    ////set the report path
                    localReport.ReportPath = Server.MapPath("~/Content/documents/Reports/UsersView.rdlc");
                    objDecisionPointEngine = new DecisionPointEngine();
                    ReportDataSource reportDataSource = new ReportDataSource();
                    reportDataSource.Name = "GetUsersDetails";
                    objReportResponse     = new ReportResponse()
                    {
                        DateFrom  = Convert.ToDateTime(dateFrom, CultureInfo.InvariantCulture),
                        DateTo    = Convert.ToDateTime(dateTo, CultureInfo.InvariantCulture),
                        Status    = status,
                        CompanyId = companyId,
                        UserId    = userId
                    };
                    //set the value of datasorce of ReportDataSource
                    reportDataSource.Value = objDecisionPointEngine.GetAllUsersDetailsInSystem(objReportResponse);
                    //added the ReportDataSource to LocalReport for Bind in RDLC report
                    localReport.DataSources.Add(reportDataSource);

                    string reportType = "pdf";
                    string mimeType;
                    string encoding;
                    string fileNameExtension;
                    //The DeviceInfo settings should be changed based on the reportType
                    //http://msdn2.microsoft.com/en-us/library/ms155397.aspx
                    string deviceInfo =
                        "<DeviceInfo>" +
                        "  <OutputFormat>PDF</OutputFormat>" +
                        "  <PageWidth>8.5in</PageWidth>" +
                        "  <PageHeight>11in</PageHeight>" +
                        "  <MarginTop>0.2in</MarginTop>" +
                        "  <MarginLeft>.5in</MarginLeft>" +
                        "  <MarginRight>.25in</MarginRight>" +
                        "  <MarginBottom>0.25in</MarginBottom>" +
                        "</DeviceInfo>";
                    Warning[] warnings;
                    string[]  streams;
                    byte[]    renderedBytes;
                    //Render the report
                    renderedBytes = localReport.Render(
                        reportType,
                        deviceInfo,
                        out mimeType,
                        out encoding,
                        out fileNameExtension,
                        out streams,
                        out warnings);
                    //Response.AddHeader("content-disposition", "attachment; filename=NorthWindCustomers." + fileNameExtension);
                    return(File(renderedBytes, mimeType));
                };
            }
            catch (Exception ex)
            {
                log.ErrorFormat(DecisionPointR.logmessageerror, ex.ToString(), typeof(CompanyDashBoardController).Name, MethodBase.GetCurrentMethod().Name);
                throw;
            }
            finally
            {
                logMessage.AppendLine(string.Format(CultureInfo.InvariantCulture, DecisionPointR.logmessagend, MethodBase.GetCurrentMethod().Name));
                log.Info(logMessage.ToString());
            }
        }