PageRenderTime 26ms CodeModel.GetById 10ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/Reports/ReportManager.cs

http://github.com/khaneh/Orders
C# | 160 lines | 120 code | 29 blank | 11 comment | 8 complexity | 9c26fb2d7204f579cb8c34c9b60149ab MD5 | raw file
  1using System;
  2using System.Collections;
  3using System.ComponentModel;
  4using System.Data;
  5using System.Drawing;
  6using System.Web;
  7using System.Web.SessionState;
  8using System.Web.UI;
  9using System.Web.UI.WebControls;
 10using System.Web.UI.HtmlControls;
 11using CrystalDecisions.CrystalReports.Engine;
 12using CrystalDecisions.Shared;
 13using CrystalDecisions.Web;
 14
 15namespace Reports
 16{
 17	/// <summary>
 18	/// One object from this class will initialize and print CR reports
 19	/// </summary>
 20
 21	public class ReportManager
 22	{
 23		protected String PrinterName;
 24		protected ParameterFields paramFields = new ParameterFields ();
 25		protected ParameterField paramField = new ParameterField ();
 26		protected ParameterDiscreteValue discreteVal = new ParameterDiscreteValue ();
 27		protected ParameterField paramField2 = new ParameterField ();
 28		protected ParameterDiscreteValue discreteVal2 = new ParameterDiscreteValue ();
 29
 30		public ReportManager()
 31		{
 32			//PrinterName="\\\\Orders1\\LQ300_O1";
 33			//PrinterName="\\\\mohammad\\LQ300_O2";
 34			//PrinterName="\\\\AHOKI\\LQ300_O3";
 35			//PrinterName="\\\\GOLABI\\LQ300_C";
 36			//PrinterName="\\\\KOOCHAK\\LQ300_P1";
 37			PrinterName="none";
 38		}
 39
 40
 41		public ReportManager(String Printer)
 42		{
 43			PrinterName=Printer;
 44		}
 45
 46		public void SetPrinter(String IP)
 47		{
 48			PrinterName=Util.choosePrinter(IP);
 49		}
 50
 51
 52		public Boolean initReport(ReportClass crReport, CrystalReportViewer CrystalReportViewer1, String param, String ParamName)
 53		{
 54
 55			if(param=="" || param==null	) return false;
 56
 57			paramField.ParameterFieldName = ParamName;
 58			discreteVal.Value = param;
 59			paramField.CurrentValues.Add (discreteVal);
 60			paramFields.Add (paramField);
 61
 62			CrystalReportViewer1.ReportSource = crReport;
 63			CrystalReportViewer1.ParameterFieldInfo = paramFields;
 64			CrystalReportViewer1.RefreshReport();
 65			return true;
 66		}
 67
 68
 69		public Boolean initReport(ReportClass crReport, CrystalReportViewer CrystalReportViewer1, String param1, String ParamName1, String param2, String ParamName2)
 70		{
 71
 72			if(param1=="" || param1==null	) return false;
 73			if(param2=="" || param2==null	) return false;
 74			
 75			paramField.ParameterFieldName = ParamName1;
 76			discreteVal.Value = param1;
 77			paramField.CurrentValues.Add (discreteVal);
 78			paramFields.Add (paramField);
 79			crReport.DataDefinition.ParameterFields[0].CurrentValues.Add (discreteVal); 
 80			
 81			paramField2.ParameterFieldName = ParamName2;
 82			discreteVal2.Value = param2;
 83			paramField2.CurrentValues.Add (discreteVal2);
 84			paramFields.Add (paramField2);
 85			crReport.DataDefinition.ParameterFields[1].CurrentValues.Add (discreteVal2); 
 86			
 87			CrystalReportViewer1.ReportSource = crReport;
 88			CrystalReportViewer1.ParameterFieldInfo = paramFields;
 89			CrystalReportViewer1.RefreshReport();
 90			return true;
 91		}
 92
 93
 94
 95		public Boolean printReport(CrystalDecisions.CrystalReports.Engine.ReportClass crReport, CrystalReportViewer CrystalReportViewer1, String param, String ParamName)
 96		{
 97			bool success=false;
 98			if (PrinterName!="none") 
 99			{
100				try
101				{
102					paramField.ParameterFieldName = ParamName;
103					discreteVal.Value = param;
104					paramField.CurrentValues.Add (discreteVal);
105					paramFields.Add (paramField);
106				
107					crReport.DataDefinition.ParameterFields[0].CurrentValues.Add (discreteVal); 
108					CrystalReportViewer1.ReportSource = crReport;
109					CrystalReportViewer1.ParameterFieldInfo = paramFields;
110					CrystalReportViewer1.RefreshReport();
111			
112					ParameterValues tmpParam = new ParameterValues();
113					tmpParam.Add(discreteVal);
114					crReport.DataDefinition.ParameterFields[0].ApplyCurrentValues(tmpParam);
115					crReport.PrintOptions.PrinterName = PrinterName;
116					//crReport.PrintToPrinter(1,false,1,1);
117					crReport.PrintToPrinter(1,false,1,99);
118					success=true;
119				}
120				catch{}
121			}
122			return success;
123		}
124
125		public Boolean printReport(CrystalDecisions.CrystalReports.Engine.ReportClass crReport, CrystalReportViewer CrystalReportViewer1, String param1, String ParamName1, String param2, String ParamName2)
126		{
127			if (PrinterName=="none") return false;
128
129			paramField.ParameterFieldName = ParamName1;
130			discreteVal.Value = param1;
131			paramField.CurrentValues.Add (discreteVal);
132			paramFields.Add (paramField);
133			crReport.DataDefinition.ParameterFields[0].CurrentValues.Add (discreteVal); 
134
135			paramField2.ParameterFieldName = ParamName2;
136			discreteVal2.Value = param2;
137			paramField2.CurrentValues.Add (discreteVal2);
138			paramFields.Add (paramField2);
139			crReport.DataDefinition.ParameterFields[1].CurrentValues.Add (discreteVal2); 
140				
141			CrystalReportViewer1.ReportSource = crReport;
142			CrystalReportViewer1.ParameterFieldInfo = paramFields;
143			CrystalReportViewer1.RefreshReport();
144			
145			ParameterValues tmpParam = new ParameterValues();
146			ParameterValues tmpParam2 = new ParameterValues();
147			tmpParam.Add(discreteVal);
148			tmpParam2.Add(discreteVal2);
149			crReport.DataDefinition.ParameterFields[0].ApplyCurrentValues(tmpParam);
150			crReport.DataDefinition.ParameterFields[1].ApplyCurrentValues(tmpParam2);
151			crReport.PrintOptions.PrinterName = PrinterName;
152			//			crReport.PrintToPrinter(1,false,1,1);
153			crReport.PrintToPrinter(1,false,1,99);
154
155			//Response.write (PrinterName);
156			return true;
157		}
158	
159	}
160}