Advertisement
Guest User

Untitled

a guest
Jul 12th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. public class PrintService : IPrintService
  2. {
  3. readonly ReportDocument _reportDocument = new ReportDocument();
  4.  
  5. private readonly string _reportPath = ConfigurationManager.AppSettings["ReportPath"];
  6. private readonly string _reportUser = ConfigurationManager.AppSettings["ReportUser"];
  7. private readonly string _reportPassword = ConfigurationManager.AppSettings["ReportPassword"];
  8. private readonly string _reportServer = ConfigurationManager.AppSettings["ReportServer"];
  9. private readonly string _reportDatabase = ConfigurationManager.AppSettings["ReportDatabase"];
  10. private readonly string _spbuNumber = ConfigurationManager.AppSettings["SPBUNumber"];
  11. private readonly string _spbuAddress = ConfigurationManager.AppSettings["SPBUAddress"];
  12. private readonly string _spbuPhone = ConfigurationManager.AppSettings["SPBUPhone"];
  13.  
  14. public void Print(string number, string reportName)
  15. {
  16. var path = _reportPath + reportName;
  17. _reportDocument.Load(path);
  18. _reportDocument.SetDatabaseLogon(_reportUser, _reportPassword, _reportServer, _reportDatabase);
  19. _reportDocument.SetParameterValue("@Number", number);
  20. _reportDocument.SetParameterValue("@Location", _spbuNumber );
  21. _reportDocument.SetParameterValue("@Address", _spbuAddress);
  22. _reportDocument.SetParameterValue("@Phone", _spbuPhone);
  23. var print = new PrintDocument();
  24. _reportDocument.PrintOptions.PrinterName = print.PrinterSettings.PrinterName;
  25. _reportDocument.PrintOptions.PaperSize = (PaperSize) print.PrinterSettings.DefaultPageSettings.PaperSize.RawKind;
  26. _reportDocument.PrintToPrinter(1, false, 1, 1);
  27. }
  28. }
  29.  
  30. ReportDocument doc = new ReportDocument();
  31. String CS = (String)ConfigurationManager.ConnectionStrings[csName].ConnectionString;
  32. doc.Load(prerap);
  33. String DS = CS.Substring(12 + CS.IndexOf("data source"), CS.IndexOf("SQLEXPRESS") - CS.IndexOf("data source") - 2);
  34. if (doc.DataSourceConnections[0].ServerName != DS)
  35. {
  36. for(int i=0;i<doc.DataSourceConnections.Count;i++)
  37. {
  38. doc.DataSourceConnections[i].SetConnection(DS, dbName, true);
  39. }
  40.  
  41. doc.SaveAs(prerap);
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement