private void Imprimir_factura(string IdFactura)
        {
            //dos copias a impresora

            string detnom = ""; string detvia = ""; string detmun = ""; string detnif = "";

            for (int x = 0; x < Lista_detallistas.Count; x++)
            {
                clase_detallista detallista = (clase_detallista)Lista_detallistas[x];

                if (detallista.DetCod == textBox_DetCod.Text)
                {
                    detnom = detallista.DetNom;
                    detvia = detallista.detvia;
                    detmun = detallista.detmun;
                    detnif = detallista.DetNif;
                }
            }


            //Comenzamos a crear el Report
            CrystalDecisions.CrystalReports.Engine.ReportDocument myReport;
            myReport = new Report_Factura_Carabal();

            switch (frmPpal.USUARIO)
            {
            case "1": myReport = new Report_Factura_Llorens();
                break;

            case "2": myReport = new Report_Factura_Carabal();
                break;

            case "5":
                myReport = new Report_Factura_Dialpesca();
                break;

            case "8":
                myReport = new Report_Factura_Valpeix();
                break;

            default:
                break;
            }

            CrystalDecisions.Shared.TableLogOnInfo tliActual;

            //leer cadena de conexión
            string server = GloblaVar.gREMOTO_SERVER;
            //server=frmPpal.LOCAL;
            string database = GloblaVar.gREMOTO_BD;  // frmPpal.DATABASE;


            //string userid = "reports";
            //string paswd = "crystal";

            foreach (CrystalDecisions.CrystalReports.Engine.Table tbA in myReport.Database.Tables)
            {
                tliActual = tbA.LogOnInfo;
                tliActual.ConnectionInfo.ServerName         = server;   //"localhost\\SQLEXPRESS";
                tliActual.ConnectionInfo.DatabaseName       = database; //"OREMAPEREMdb";
                tliActual.ConnectionInfo.UserID             = "";
                tliActual.ConnectionInfo.Password           = "";
                tliActual.ConnectionInfo.IntegratedSecurity = true;
                tbA.ApplyLogOnInfo(tliActual);
            }
            myReport.DataDefinition.RecordSelectionFormula = "{command.Factura}=" + IdFactura + " and {command.Serie}='" + comboBox_Serie.Text + "' and {command.Anyo}=" + textBox_Anyo.Text;

            myReport.SetParameterValue("idfactura", textBox_Anyo.Text + "/" + IdFactura);
            myReport.SetParameterValue("serie", comboBox_Serie.Text);
            myReport.SetParameterValue("base_imponible", textBox_BI.Text);
            myReport.SetParameterValue("iva", textBox_IVA.Text);
            myReport.SetParameterValue("recargo", textBox_Recargo.Text);
            myReport.SetParameterValue("importe_total", textBox_Importe.Text);
            myReport.SetParameterValue("datos_mayorista", frmPpal.DATOS_MAYORISTA);
            myReport.SetParameterValue("detnom", detnom);
            myReport.SetParameterValue("detvia", detvia);
            myReport.SetParameterValue("detmun", detmun);
            myReport.SetParameterValue("detnif", detnif);
            myReport.SetParameterValue("fecha", DateTime.Today.ToShortDateString());

            myReport.SetParameterValue("texto_cabecera", textBox_TextoCabecera.Text);
            myReport.SetParameterValue("observaciones", textBox_Observaciones.Text);
            myReport.SetParameterValue("texto_pie", textBox_TextoPie.Text);

            //myReport.SetParameterValue("total_pagina", "1");

            crystalReportViewer1.ReportSource     = myReport;
            crystalReportViewer1.SelectionFormula = "{command.Factura}=" + IdFactura + " and {command.Serie}='" + comboBox_Serie.Text + "' and {command.Anyo}=" + textBox_Anyo.Text;
            crystalReportViewer1.ShowLastPage();
            int total_paginas = crystalReportViewer1.GetCurrentPageNumber();

            //string TotalPage = total_paginas.ToString();
            crystalReportViewer1.ShowFirstPage();

            //recargar el total páginas
            //myReport.SetParameterValue("total_pagina", "/" + TotalPage);
            //crystalReportViewer1.ReportSource = myReport;

            //crystalReportViewer1.Zoom(75);
            myReport.PrintToPrinter(1, false, 0, total_paginas);    //primera copia
            myReport.PrintToPrinter(1, false, 0, total_paginas);    //segunda copia
        }
Beispiel #2
0
        private void Imprimir_Factura(clase_factcom factura)
        {
            string gIdent = this.GetType().FullName + " " + System.Reflection.MethodBase.GetCurrentMethod().Name;

            GloblaVar.gUTIL.ATraza("Ejecutando " + this.GetType().FullName);

            string base_imponible = "";
            string iva = "";
            string recargo = "";
            string total_importe = "";
            string detcod = "", detnom = "", detvia = "", detmun = "", detnif = "", detEMail = "";
            string texto_cabecera = ""; string observaciones = ""; string texto_pie = "";

            string strQ = "SELECT * FROM FACTC_CABE WHERE Factura=" + factura.Factura + " AND Anyo=" + factura.Anyo + " AND Serie='" + factura.Serie + "'";

            GloblaVar.gUTIL.ATraza("Se va a imprimir la factura " + factura.Factura + "-" + factura.Serie + "/" + factura.Anyo);
            SqlDataReader myReader = null;

            try
            {
                //SqlDataReader myReader = null;
                SqlCommand myCommand = new SqlCommand(strQ, CnO);
                myReader = myCommand.ExecuteReader();
                while (myReader.Read())
                {
                    base_imponible = myReader["BI1"].ToString();
                    iva            = myReader["IVA1"].ToString();
                    recargo        = myReader["RE1"].ToString();
                    total_importe  = myReader["ImpteFactura"].ToString();

                    texto_cabecera = myReader["TextoCabe"].ToString();
                    observaciones  = myReader["Observaciones"].ToString();
                    texto_pie      = myReader["TextoPie"].ToString();
                    if (myReader["SubSerie"] != DBNull.Value)
                    {
                        SubSerie = myReader["SubSerie"].ToString();
                    }
                }
                //myReader.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
            finally
            {
                myReader.Close();
            }

            //datos del detallista
            strQ = "SELECT DetCod, DetNom, detvia, DetCop, DetMun, DetNif, DetEMail FROM DETALLISTAS WHERE DetCod=" + factura.ProCod;

            try
            {
                SqlCommand myCommand = new SqlCommand(strQ, CnO);
                myReader = myCommand.ExecuteReader();
                while (myReader.Read())
                {
                    detcod   = myReader["DetCod"].ToString();
                    detnom   = myReader["DetNom"].ToString();
                    detvia   = myReader["detvia"].ToString();
                    detmun   = myReader["DetCop"].ToString() + "  " + myReader["DetMun"].ToString();
                    detnif   = myReader["DetNif"].ToString();
                    detEMail = myReader["DetEMail"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
            finally
            {
                myReader.Close();
            }

            ///////

            GloblaVar.gUTIL.ATraza("Leidos datos de cabecera y detallista");

            CrystalDecisions.CrystalReports.Engine.ReportDocument myReport;
            if (SubSerie == "ASG")
            {
                myReport = new CR007();
            }
            else
            {
                myReport = new Report_Factura_Carabal();
            }
            GloblaVar.gUTIL.ATraza(" Usuario " + frmPpal.USUARIO);

            switch (frmPpal.USUARIO)
            {
            case "1":
                myReport = new Report_Factura_Llorens();
                break;

            case "2":
                if (SubSerie == "ASG")
                {
                    myReport = new CR007();
                }
                else
                {
                    myReport = new Report_Factura_Carabal();
                }
                break;

            case "5":
                myReport = new Report_Factura_Dialpesca();
                break;

            case "8":
                myReport = new Report_Factura_Valpeix();
                break;

            default:
                break;
            }

            CrystalDecisions.Shared.TableLogOnInfo tliActual;

            //leer cadena de conexión
            string server   = GloblaVar.gREMOTO_SERVER;
            string database = GloblaVar.gREMOTO_BD;

            foreach (CrystalDecisions.CrystalReports.Engine.Table tbA in myReport.Database.Tables)
            {
                GloblaVar.gUTIL.ATraza("El report se conecta al server  " + server + " Base datos " + database);
                tliActual = tbA.LogOnInfo;
                tliActual.ConnectionInfo.ServerName         = server;   //"localhost\\SQLEXPRESS";
                tliActual.ConnectionInfo.DatabaseName       = database; //"OREMAPEREMdb";
                tliActual.ConnectionInfo.UserID             = "";
                tliActual.ConnectionInfo.Password           = "";
                tliActual.ConnectionInfo.IntegratedSecurity = true;
                tbA.ApplyLogOnInfo(tliActual);
            }

            myReport.DataDefinition.RecordSelectionFormula = "{command.Factura}=" + factura.Factura + " and {command.Serie}='" + factura.Serie + "' and {command.Anyo}=" + factura.Anyo;

            myReport.SetParameterValue("idfactura", factura.Anyo + "/" + factura.Factura);
            myReport.SetParameterValue("serie", factura.Serie);
            myReport.SetParameterValue("base_imponible", Funciones.Formatea(base_imponible));
            myReport.SetParameterValue("iva", Funciones.Formatea(iva));
            myReport.SetParameterValue("recargo", Funciones.Formatea(recargo));
            myReport.SetParameterValue("importe_total", Funciones.Formatea(total_importe));
            myReport.SetParameterValue("datos_mayorista", frmPpal.DATOS_MAYORISTA);
            myReport.SetParameterValue("detcod", detcod);
            myReport.SetParameterValue("detnom", detnom);
            myReport.SetParameterValue("detvia", detvia);
            myReport.SetParameterValue("detmun", detmun);
            myReport.SetParameterValue("detnif", detnif);
            myReport.SetParameterValue("fecha", factura.FechaEmision);

            myReport.SetParameterValue("texto_cabecera", texto_cabecera);
            myReport.SetParameterValue("observaciones", observaciones);
            myReport.SetParameterValue("texto_pie", texto_pie);

            myReport.PrintToPrinter(1, false, 0, 0);    //primera copia
        }