public IHttpActionResult ExportMap(AMRSearchMapDTO model)
        {
            //DateTime modelMonthFrom = Convert.ToDateTime(model.month_start_str);  //Convert.ToDateTime("01/01/2020");// Convert.ToDateTime(model.month_start_str);
            //DateTime modelMonthTo = Convert.ToDateTime(model.month_end_str);  //Convert.ToDateTime("01/06/2020");//Convert.ToDateTime(model.month_end_str);

            DateTime modelMonthFrom = DateTime.ParseExact(model.month_start_str, "yyyy/MM/dd", new CultureInfo("en-US"));
            DateTime modelMonthTo   = DateTime.ParseExact(model.month_end_str, "yyyy/MM/dd", new CultureInfo("en-US"));

            ReportDocument rpt           = new ReportDocument();
            var            query         = new List <sp_GET_RPAntibiotrendAMRStrategy_Result>();
            var            strReportName = "rptAntibiotrendMap.rpt";

            query = db.sp_GET_RPAntibiotrendAMRStrategy(modelMonthFrom, modelMonthTo).ToList();

            if (query.Count() > 0)
            {
                var strHeaderDateFromTo = string.Format("{0} - {1} {2}"
                                                        , modelMonthFrom.ToString("MMMM", new CultureInfo("en-US"))
                                                        , modelMonthTo.ToString("MMMM", new CultureInfo("en-US"))
                                                        , modelMonthTo.ToString("yyyy")
                                                        );

                var Targetpath = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/Report"), strReportName);
                rpt.Load(Targetpath);
                rpt.SetDataSource(query);
                rpt.SetParameterValue("paramStrHeader", strHeaderDateFromTo);

                // --------------- Export to PDF -------------------------------

                var stream = rpt.ExportToStream(ExportFormatType.PortableDocFormat);
                // processing the stream.
                var sm     = ReadFully(stream);
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ByteArrayContent(sm.ToArray())
                };
                result.Content.Headers.ContentDisposition =
                    new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
                {
                    //FileName = "AMR_MAP.xls"
                    FileName = "AMR_MAP.pdf"
                };
                result.Content.Headers.ContentType =
                    new MediaTypeHeaderValue("application/pdf");

                rpt.Dispose();

                var response = ResponseMessage(result);
                return(response);
            }
            else
            {
                var result   = new HttpResponseMessage(HttpStatusCode.NotFound);
                var response = ResponseMessage(result);
                return(response);
            }
        }
Exemplo n.º 2
0
        public async Task <string> ExportMapDataAsync(AMRSearchMapDTO selectedobj)
        {
            //20200801_Jan-Dec_AMPMAP.pdf

            var filename = string.Format("{0}_{1}-{2}_{3}"
                                         , DateTime.Today.ToString("yyyyMMdd")
                                         , selectedobj.month_start.Value.ToString("MMMyy", new CultureInfo("en-US"))
                                         , selectedobj.month_end.Value.ToString("MMMyy", new CultureInfo("en-US"))
                                         , "AMPMap.pdf"
                                         );
            //var filename = "AMPMAP.pdf";

            var    strDirectoryPath = "ANTIBIOTREND" + "/" + DateTime.Today.ToString("yyyyMMdd");
            var    filepath         = strDirectoryPath + "/" + filename;
            string statuscode       = "";

            List <ParameterDTO> objParamList = new List <ParameterDTO>();
            var searchParam = new ParameterDTO()
            {
                prm_code_major = "RPT_PROCESS_PATH"
            };

            objParamList = await _apiHelper.GetDataListByModelAsync <ParameterDTO, ParameterDTO>("dropdownlist_api/GetParameterList", searchParam);

            if (objParamList.FirstOrDefault(x => x.prm_code_minor == "PATH") != null)
            {
                _reportPath = objParamList.FirstOrDefault(x => x.prm_code_minor == "PATH").prm_value;
                var outputfileInfo = new FileInfo(Path.Combine(_reportPath, filepath));
                if (!Directory.Exists(Path.Combine(_reportPath, strDirectoryPath)))
                {
                    Directory.CreateDirectory(Path.Combine(_reportPath, strDirectoryPath));
                }
                statuscode = await _apiHelper.ExportDataAsync <AMRSearchMapDTO>("exportmap_api/ExportMap", outputfileInfo, selectedobj);
            }
            else
            {
                statuscode = "ERR_PATH";
            }

            return(statuscode);
        }