Foros del Web » Programación para mayores de 30 ;) » C/C++ »

problemas con impresión por lote

Estas en el tema de problemas con impresión por lote en el foro de C/C++ en Foros del Web. Hola a todos, Mi problema es el sgt, estoy trabajando en una aplicación que ya tiene definido sus reportes en crystal report se imprimen y ...
  #1 (permalink)  
Antiguo 12/07/2012, 08:52
 
Fecha de Ingreso: agosto-2006
Mensajes: 56
Antigüedad: 17 años, 8 meses
Puntos: 0
Información problemas con impresión por lote

Hola a todos,
Mi problema es el sgt, estoy trabajando en una aplicación que ya tiene definido sus reportes en crystal report se imprimen y lo hace bien, pero ahora quieren que se escojan varios reportes y se impriman, yo coloco los check en el datagridview pero tengo un problema que no se como escoger un dato que necesito y está en el data grid.

El codigo que está en el momento es el sgt, éste es el código del botón (este es en detalle de la orden)
Código:
protected void btnInprimir_Click(object sender, EventArgs e)
    {
        Session["criterio"] = "{OrdenesTrabajo.IdOrdenTrabajo}=" + lblOT.Text;
        Session["informe"] = "OrdenTrabajo.rpt";
        Response.Redirect("mreporte.aspx");
    }
éste formulario se llama detOrdenTrabajo.aspx, en la cabecera de éste formulario se encuentra el lblOT.Text
al yo listar las ordenes de trabajo lo hago en el formulario OrdenesTrabajo, ahí coloco los check y el nuevo botón de imprimir, al no tener el lblOT, porqué el número de la orden de trabajo se encuentra es en el datagridview yo coloqué
Código:
protected void btnInprimir_Click(object sender, EventArgs e)
    {
        Session["criterio"] = "{OrdenesTrabajo.IdOrdenTrabajo}=" + detOrdenTrabajo.aspx?id={0};
        Session["informe"] = "OrdenTrabajo.rpt";
        Response.Redirect("mreporte.aspx");
    }
Pero no me funcionó, pensé que si lo colocaba así me taería el número de la OT, y el código de mreporte.aspx es el sgt
Código:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Threading;
using System.Globalization;

public partial class admin_mreporte : System.Web.UI.Page
{
        //protected System.Web.UI.WebControls.Label lblError;
		//protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
		protected CrystalDecisions.CrystalReports.Engine.ReportDocument orpt;
		string CaminoReporte;

		//DiscreteParam crReportDocument;
		ParameterFields crParameterFields;
		ParameterField crParameterField;
		ParameterValues crParameterValues;
		ParameterDiscreteValue crParameterDiscreteValue;

		Database crDatabase;
		Tables crTables;
		TableLogOnInfo crTableLogOnInfo;
		//protected System.Web.UI.WebControls.Label lblError;
		ConnectionInfo crConnectionInfo;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US",false);
			Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");	
			Response.Cache.SetNoServerCaching();
        
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			InitializeComponent();			
			try
			{
				string strTemp = Session["criterio"].ToString();
				strTemp = strTemp.Replace("=0","=false");
				strTemp = strTemp.Replace("= 0","=false");
				Session["criterio"]=strTemp;
                CrystalReportViewer1.Width = Unit.Percentage(100);
				StartReport();
			}
			catch(Exception ex)
			{
				lblError.Text = ex.Message + "<br>" + Session["criterio"].ToString() + "<br>" + CaminoReporte;
			}
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.orpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
			// 
			// orpt
			// 
            //this.orpt.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation;
            //this.orpt.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperLetter;
            //this.orpt.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Upper;
            //this.orpt.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Default;
            
			this.Error += new System.EventHandler(this.WebForm1_Error);
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion

		private void StartReport()
		{
			CaminoReporte = ConfigurationManager.AppSettings["CaminoReportes"];
						
			if(Session["informe"]==null)
			{
				lblError.Text = "Informe no existe";
				return;	
			}

			CaminoReporte +=  Session["informe"].ToString() ;

			orpt.Load(@CaminoReporte);	
			
			crConnectionInfo = new ConnectionInfo();			
			crConnectionInfo.ServerName =  ConfigurationManager.AppSettings["Servidor"];
			crConnectionInfo.DatabaseName =  ConfigurationManager.AppSettings["Bd"];
			crConnectionInfo.UserID = ConfigurationManager.AppSettings["Usuario"];					
			crConnectionInfo.Password = ConfigurationManager.AppSettings["Clave"];		

			//Get the tables collection from the report object
			crDatabase = orpt.Database;
			crTables = crDatabase.Tables;

			Logon(orpt,ConfigurationManager.AppSettings["Servidor"],ConfigurationManager.AppSettings["Bd"],ConfigurationManager.AppSettings["Usuario"],ConfigurationManager.AppSettings["Clave"]);
		    
			orpt.RecordSelectionFormula = Session["criterio"].ToString();
			orpt.Refresh();
			
			//Create an instance of the strongly-typed report object
			//crReportDocument = new DiscreteParam();

			//The viewer's reportsource must be set to a report before any
			//parameter fields can be accessed.
			CrystalReportViewer1.ReportSource = orpt;
            
            //this.orpt.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation;
            this.orpt.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize;
            
            
            //this.orpt.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Default;

			//Set the modified parameters collection back to the viewer so that
			//the new parameter information can be used for the report.
			CrystalReportViewer1.ParameterFieldInfo = crParameterFields;


			//CrystalReportViewer1.ReportSource = orpt;
			CrystalReportViewer1.DataBind();	
		}		

		private void WebForm1_Error(object sender, System.EventArgs e)
		{
			Response.Write(Server.GetLastError());
			// Server.ClearError();
		}

		// Helper method that iterates through all tables in a report document 
		bool ApplyLogon(ReportDocument cr, ConnectionInfo ci) 
		{ 
			TableLogOnInfo li; 

			// for each table apply connection info 
			foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in cr.Database.Tables) 
			{ 
				li = tbl.LogOnInfo; 
				li.ConnectionInfo = ci; 
				tbl.ApplyLogOnInfo(li); 

				// check if logon was successful 
				// if TestConnectivity returns false, check logon credentials 
				if (tbl.TestConnectivity()) 
				{ 
					// drop fully qualified table location 
					if (tbl.Location.IndexOf(".") > 0) 
					{ 
						tbl.Location = tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1); 
					} 
					else tbl.Location = tbl.Location; 
				} 
				else return(false);
			} 
			return(true); 
		} 


		// The Logon method iterates through all tables 
		bool Logon(ReportDocument cr, string server, string db, string id, string pass) 
		{ 
			ConnectionInfo ci = new ConnectionInfo(); 
			SubreportObject subObj; 

			ci.ServerName = server; 
			ci.DatabaseName = db; 
			ci.UserID = id; 
			ci.Password = pass; 

			if (!ApplyLogon(cr, ci)) return (false); 

			foreach (ReportObject obj in cr.ReportDefinition.ReportObjects) 
			{ 
				if (obj.Kind == ReportObjectKind.SubreportObject) 
				{ 
					subObj = (SubreportObject)obj; 
					if (!ApplyLogon(cr.OpenSubreport(subObj.SubreportName), ci)) return(false); 
				} 
			} 
			return (true); 
		} 
	}

Etiquetas: funcion, lote, string
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:57.