123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using Microsoft.Reporting.WebForms;
- using System.Net;
- using System.Collections.Specialized;
- using System.IO;
- using Spire.Pdf;
- using System.Globalization;
- using System.Text;
- using Newtonsoft.Json;
- using System.Drawing.Printing;
- using System.Drawing;
- using System.Diagnostics;
- using Aspose.Pdf.Facades;
- namespace EmisTerminal.EIF
- {
- public class Report
- {
- public static void PrintStudentScore(Guid userID)
- {
- string reportpath = "/EducationResult/GztyPersonalStudentScoreView";
- List<ReportParameter> parameters = new List<ReportParameter>();
- parameters.Add(new ReportParameter("LoginID", (string)null));
- parameters.Add(new ReportParameter("UserID", userID.ToString()));
- parameters.Add(new ReportParameter("CollegeID", (string)null));
- parameters.Add(new ReportParameter("StandardID", (string)null));
- parameters.Add(new ReportParameter("YearID", (string)null));
- parameters.Add(new ReportParameter("SchoolyearNumID", (string)null));
- parameters.Add(new ReportParameter("SchoolcodeID", (string)null));
- parameters.Add(new ReportParameter("ClassmajorID", (string)null));
- PrintReport(reportpath, parameters);
- }
- public static string GenerateStudentScore(Guid userID, string idNum)
- {
- string reportpath = "/EducationResult/GztyPersonalStudentScoreView";
- List<ReportParameter> parameters = new List<ReportParameter>();
- parameters.Add(new ReportParameter("LoginID", (string)null));
- parameters.Add(new ReportParameter("UserID", userID.ToString()));
- parameters.Add(new ReportParameter("CollegeID", (string)null));
- parameters.Add(new ReportParameter("StandardID", (string)null));
- parameters.Add(new ReportParameter("YearID", (string)null));
- parameters.Add(new ReportParameter("SchoolyearNumID", (string)null));
- parameters.Add(new ReportParameter("SchoolcodeID", (string)null));
- parameters.Add(new ReportParameter("ClassmajorID", (string)null));
- return GenerateReport(reportpath, idNum, parameters);
- }
- private static string GenerateReport(string reportpath, string idNum, List<ReportParameter> parameters = null)
- {
- string User = Const.LOCAL_SETTING_REPORT_USER_NAME;
- string Pass = Const.LOCAL_SETTING_REPORT_PASSWORD;
- string ReportServerUrl = Const.LOCAL_SETTING_REPORT_URL;
- IReportServerCredentials irsc = new CustomReportCredentials(User, Pass, "");
- Uri uri = new Uri(ReportServerUrl);
- ReportViewer reportViewer = new ReportViewer();
- reportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
- reportViewer.ServerReport.ReportServerCredentials = irsc;
- reportViewer.ServerReport.ReportServerUrl = uri;
- reportViewer.ServerReport.ReportPath = reportpath;
- if (parameters != null && parameters.Count != 0)
- {
- reportViewer.ServerReport.SetParameters(parameters);
- }
- string deviceInfo = ReportPrintHelper.CreateEMFDeviceInfo(reportViewer.ServerReport);
- // Generating Image renderer pages one at a time can be expensive. In order
- // to generate page 2, the server would need to recalculate page 1 and throw it
- // away. Using PersistStreams causes the server to generate all the pages in
- // the background but return as soon as page 1 is complete.
- NameValueCollection firstPageParameters = new NameValueCollection();
- firstPageParameters.Add("rs:PersistStreams", "True");
- // GetNextStream returns the next page in the sequence from the background process
- // started by PersistStreams.
- NameValueCollection nonFirstPageParameters = new NameValueCollection();
- nonFirstPageParameters.Add("rs:GetNextStream", "True");
- string mimeType;
- string fileExtension;
- Stream pageStream = reportViewer.ServerReport.Render("PDF", deviceInfo, firstPageParameters, out mimeType, out fileExtension);
-
- PDFSign signControl = new PDFSign();
- string filePath = signControl.Sign("StudentScore" + idNum, pageStream);
- return filePath;
- }
- private static void PrintReport(string reportpath, List<ReportParameter> parameters = null)
- {
- var fileString = GenerateReport(reportpath, "1045123", parameters);
- PdfDocument pdf = new PdfDocument(HttpContext.Current.Server.MapPath(fileString));
- pdf.Print();
- }
- public static void PrintFile(string reportFilePath, Guid userID)
- {
- PdfViewer viewer = new PdfViewer();
- viewer.BindPdf(HttpContext.Current.Server.MapPath(reportFilePath));
- viewer.PrintDocument();
- viewer.Close();
- string postString = "userID=" + userID.ToString();
- byte[] postData = Encoding.UTF8.GetBytes(postString);
- HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(Const.LOCAL_SETTING_EMIS_URL + "/PrintServices/Count");
- req.ContentType = "application/x-www-form-urlencoded";
- req.Method = "POST";
- req.Referer = HttpContext.Current.Request.Url.AbsoluteUri;
- Stream reqStream = req.GetRequestStream();
- reqStream.Write(postData, 0, postData.Length);
- reqStream.Close();
- HttpWebResponse response = (HttpWebResponse)req.GetResponse();
- StreamReader resReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
- string srcString = resReader.ReadToEnd();
- var returnObj = JsonConvert.DeserializeObject<ResultMessage<string>>(srcString);
- if (!returnObj.IsSuccess)
- {
- throw new Exception(returnObj.Message);
- }
- }
- }
- public class CustomReportCredentials : IReportServerCredentials
- {
- private string _UserName;
- private string _PassWord;
- private string _DomainName;
- public CustomReportCredentials(string UserName, string PassWord, string DomainName)
- {
- _UserName = UserName;
- _PassWord = PassWord;
- _DomainName = DomainName;
- }
- public System.Security.Principal.WindowsIdentity ImpersonationUser
- {
- get { return null; }
- }
- public ICredentials NetworkCredentials
- {
- get { return new NetworkCredential(_UserName, _PassWord, _DomainName); }
- }
- public bool GetFormsCredentials(out Cookie authCookie, out string user,
- out string password, out string authority)
- {
- authCookie = null;
- user = password = authority = null;
- return false;
- }
- }
- }
|