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

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

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

                string clientids = string.Empty;

                if (!string.IsNullOrWhiteSpace(parameters.referenceid) || !string.IsNullOrWhiteSpace(parameters.jobcode))
                {
                    param.Add("@JobCode", string.IsNullOrWhiteSpace(parameters.referenceid) ? parameters.jobcode : parameters.referenceid, DbType.String);
                }
                if (!string.IsNullOrWhiteSpace(parameters.title))
                {
                    param.Add("@Title", parameters.title, DbType.String);
                }
                if (!string.IsNullOrWhiteSpace(parameters.location))
                {
                    param.Add("@Location", parameters.location, DbType.String);
                }
                if (!string.IsNullOrWhiteSpace(parameters.publisheddate))
                {
                    param.Add("@PublishedDate", parameters.publisheddate, DbType.String);
                }
                if (parameters.status >= 0)
                {
                    param.Add("@IsActive", parameters.status, DbType.Int16);
                }
                if (!string.IsNullOrWhiteSpace(parameters.fromdate))
                {
                    param.Add("@FromDate", parameters.fromdate, DbType.String);
                }
                if (!string.IsNullOrWhiteSpace(parameters.todate))
                {
                    param.Add("@ToDate", parameters.todate, DbType.String);
                }
                if (parameters.lastdays != -1)
                {
                    param.Add("@LastDays", parameters.lastdays, DbType.Int32);
                }

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

                result = (List <JobReport>)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> GetJobReportFile(string sourceParam)
        {
            HttpResponse     response   = HttpContext.Current.Response;
            List <JobReport> reportData = new List <JobReport>();
            string           clientids  = string.Empty;

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

            if (reportResponse.Output != null)
            {
                reportData = (List <JobReport>)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\\JobReport.rdlc");

                List <ReportParameter> parameters = new List <ReportParameter>();
                parameters.Add(new ReportParameter("JobCode", source.referenceid));
                parameters.Add(new ReportParameter("Title", source.title));
                parameters.Add(new ReportParameter("Location", source.location));
                parameters.Add(new ReportParameter("PublishedDate", source.publisheddate));
                parameters.Add(new ReportParameter("IsActive", source.status.ToString()));
                parameters.Add(new ReportParameter("FromDate", source.fromdate));
                parameters.Add(new ReportParameter("ToDate", source.todate));
                parameters.Add(new ReportParameter("LastDays", source.lastdays.ToString()));
                lr.SetParameters(parameters);

                lr.DataSources.Clear();
                lr.DataSources.Add(new ReportDataSource("DsJobReport", 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, "JobReport_", source.reporttype);

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