Example #1
0
        public async Task <HttpResponseMessage> GetClientReport(string source)
        {
            ClientReportParam param  = JsonConvert.DeserializeObject <ClientReportParam>(source);
            ResponseModel     result = await ReportDal.Instance.GetClientReport(param);

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Example #2
0
        internal async Task <ResponseModel> GetClientReport(ClientReportParam parameters)
        {
            ResponseModel       response = new ResponseModel();
            List <ClientReport> result   = new List <ClientReport>();

            using (IDbConnection conn = _dbConnection.Connection)
            {
                DynamicParameters param = new DynamicParameters();

                string clientids = string.Empty;
                if (parameters.clientids != null && parameters.clientids.Count > 0)
                {
                    clientids = string.Join(",", parameters.clientids);
                }

                if (!string.IsNullOrWhiteSpace(clientids))
                {
                    param.Add("@ClientIds", clientids, DbType.String);
                }
                if (!string.IsNullOrWhiteSpace(parameters.jobcode))
                {
                    param.Add("@JobCode", parameters.jobcode, DbType.String);
                }
                if (!string.IsNullOrWhiteSpace(parameters.title))
                {
                    param.Add("@Title", parameters.title, DbType.String);
                }
                if (!string.IsNullOrWhiteSpace(parameters.publisheddate))
                {
                    param.Add("@PublishedDate", parameters.publisheddate, DbType.String);
                }
                if (parameters.lastdays != -1)
                {
                    param.Add("@LastDays", parameters.lastdays, DbType.Int32);
                }

                dynamic data = await conn.QueryAsync <ClientReport>(Constants.StoredProcedure.GETCLIENTREPORT, param, null, null, CommandType.StoredProcedure);

                result = (List <ClientReport>)data;

                response.ResultStatus = result.Count > 0 ? Constants.ResponseResult.SUCCESS : Constants.ResponseResult.NODATA;
                response.Output       = result;
                response.OutputCount  = result.Count;
            }

            return(response);
        }
Example #3
0
        public async Task <HttpResponseMessage> GetClientReportFile(string sourceParam)
        {
            HttpResponse        response   = HttpContext.Current.Response;
            List <ClientReport> reportData = new List <ClientReport>();
            string clientids = string.Empty;

            ClientReportParam source = JsonConvert.DeserializeObject <ClientReportParam>(sourceParam);
            var reportResponse       = await ReportDal.Instance.GetClientReport(source);

            if (reportResponse.Output != null)
            {
                reportData = (List <ClientReport>)reportResponse.Output;
            }

            /* Follow the below URL, so report will work.
             * https://stackoverflow.com/questions/38902037/ssrs-report-definition-is-newer-than-server?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
             */
            try
            {
                byte[]    bytes;
                Warning[] warnings;
                string[]  streamids;
                string    mimeType, encoding, extension;

                LocalReport lr = new LocalReport();
                lr.ReportPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Reports\\ClientReport.rdlc");

                if (source.clientids != null && source.clientids.Count > 0)
                {
                    clientids = string.Join(",", source.clientids);
                }

                List <ReportParameter> parameters = new List <ReportParameter>();
                parameters.Add(new ReportParameter("ClientIds", clientids));
                parameters.Add(new ReportParameter("JobCode", source.jobcode));
                parameters.Add(new ReportParameter("Title", source.title));
                parameters.Add(new ReportParameter("PublishedDate", source.publisheddate));
                parameters.Add(new ReportParameter("LastDays", source.lastdays.ToString()));
                lr.SetParameters(parameters);

                lr.DataSources.Clear();
                lr.DataSources.Add(new ReportDataSource("DsClientReport", reportData));
                lr.Refresh();

                /* < PageWidth > 8.5in</ PageWidth > < PageHeight > 11in</ PageHeight > */
                string deviceInfo = @"<DeviceInfo>
                    <OutputFormat>EMF</OutputFormat>
                    <PageWidth>11.5in</PageWidth>
                    <PageHeight>8.5in</PageHeight>
                    <MarginTop>0.25in</MarginTop>
                    <MarginLeft>0.15in</MarginLeft>
                    <MarginRight>0.15in</MarginRight>
                    <MarginBottom>0.25in</MarginBottom>
                </DeviceInfo>";

                if (source.reporttype == "excel")
                {
                    bytes = lr.Render("EXCELOPENXML", deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);
                }
                else
                {
                    bytes = lr.Render("pdf", deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);
                }

                generateFile(response, bytes, "ClientReport_", source.reporttype);

                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
        }