private void toolStripButton1_Click(object sender, EventArgs e)
 {
     if (this._pdfDoc == null)
     {
         return;
     }
     try
     {
         string str = Path.GetTempPath() + Guid.NewGuid().ToString() + ".ps";
         if (this.printDialog1.ShowDialog() != DialogResult.OK)
         {
             return;
         }
         if (this.printDialog1.PrinterSettings.PrintToFile)
         {
             this.saveFileDialog1.Filter = "PostScript File (*.ps)|*.ps";
             if (this.saveFileDialog1.ShowDialog() != DialogResult.OK)
             {
                 return;
             }
             this._pdfDoc.PrintToFile(this.saveFileDialog1.FileName, 1, this._pdfDoc.PageCount);
         }
         else
         {
             this._pdfDoc.PrintToFile(str, 1, this._pdfDoc.PageCount);
             RawPrinterHelper.SendFileToPrinter(this.printDialog1.PrinterSettings.PrinterName, str);
         }
     }
     catch (Exception ex)
     {
         int num = (int)MessageBox.Show(ex.Message);
     }
 }
Example #2
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (RawPrinterHelper.SendFileToPrinter("Generic / Text Only", @"C:\Temp\PruebaImpresion.txt"))
            {
                Console.WriteLine("Ando");
            }
            else
            {
                Console.WriteLine("NO Ando");
            }

            /*
             * Excel.ApplicationClass excel = new ApplicationClass();
             * excel.Application.Workbooks.Add(true);
             * int ColumnIndex=0;
             * ColumnIndex++;
             * excel.Cells[1,ColumnIndex]="col.ColumnName";
             * int rowIndex=0;
             * rowIndex++;
             * excel.Cells[rowIndex+1,ColumnIndex]="row.Cells[col.ColumnName].Text";
             * excel.Visible = true;
             * Worksheet worksheet = (Worksheet)excel.ActiveSheet;
             * worksheet.Activate();
             * //DataTable table = DATASETNAME.Tables[0];
             */
        }
Example #3
0
        /*
         * public void SendToPrinter(string fileName, string printname)
         * {
         *  //string FilePath = Properties.Settings.Default.OutputFile + "\\" + fileName;
         *  //File.WriteAllBytes(Properties.Settings.Default.OutputFile + "\\" + fileName, GetBytes());
         *
         *  //string printerName = GetPrinterName();
         *  //RawPrinterHelper.SendFileToPrinter(printerName, FilePath);
         *
         *  string printerName = GetPrinterDotmatrix(printname);
         *  RawPrinterHelper.SendBytesFileToPrinter(printerName, GetBytes());
         * }
         */

        public void SendToPrinter(string fileName, string contents)
        {
            string FilePath = Properties.Settings.Default.OutputFile + "\\" + fileName;

            File.WriteAllBytes(Properties.Settings.Default.OutputFile + "\\" + fileName, GetBytes(contents));

            string printerName = GetPrinterName();

            RawPrinterHelper.SendFileToPrinter(printerName, FilePath);
        }
Example #4
0
        private void btnStampa_Click(object sender, EventArgs e)
        {
            string uplatnica = napravi_uplatnicu();
            string d         = "C:\\blankoUPLATNICE\\" + uplatnica + ".txt";

            string stampac = this.cbStampac.GetItemText(this.cbStampac.SelectedItem);

            RawPrinterHelper.SendFileToPrinter(stampac, d, int.Parse(tbBrKopija.Text));
            unesi(int.Parse(cbPlatilacRacun.SelectedValue.ToString()), int.Parse(cbPrimalac.SelectedValue.ToString()),
                  DateTime.Now, double.Parse(txtIznos.Text));
        }
Example #5
0
        public override void Print(Label label)
        {
            switch (label.Type)
            {
            case Label.Labels.other:
                Console.WriteLine("Printing file to " + Name);
                RawPrinterHelper.SendFileToPrinter(Name, label.FilePath);
                break;

            default:
                Console.WriteLine("Print string to " + Name);
                Print(label.ToString());
                break;
            }
        }
        public void SendFileToPrinterTest()
        {
            string szPrinterName = GetCurrentPrinterName();

            if (!string.IsNullOrEmpty(szPrinterName))
            {
                string szFileName = TestFileName();
                bool   expected   = true;
                bool   actual;
                actual = RawPrinterHelper.SendFileToPrinter(szPrinterName, szFileName);
                Assert.AreEqual(expected, actual, "Failed.  Win32 problem?");
            }
            else
            {
                Assert.Fail("Printer name is unavailable.  No printer installed or selected?");
            }
        }
Example #7
0
        public static bool Print(string url, string printerName)
        {
            RawPrinterHelper.SendFileToPrinter(printerName, url);
            PrintDocument pd = new PrintDocument();

            pd.PrinterSettings.PrinterName = printerName;
            pd.DocumentName = url;


            pd.PrintController = new StandardPrintController();
            pd.Print();


            //PDFFile file = PDFFile.Open(url);
            //PrinterSettings settings = new PrinterSettings();
            //PrintDocument pd = new System.Drawing.Printing.PrintDocument();
            //settings.PrinterName = printerName;
            //settings.PrintToFile = false;

            //设置纸张大小(可以不设置,取默认设置)3.90 in,  8.65 in
            //PaperSize ps = new PaperSize("test", 4, 9);
            //ps.RawKind = 9; //如果是自定义纸张,就要大于118,(A4值为9,详细纸张类型与值的对照请看http://msdn.microsoft.com/zh-tw/library/system.drawing.printing.papersize.rawkind(v=vs.85).aspx)

            //O2S.Components.PDFRender4NET.Printing.PDFPrintSettings pdfPrintSettings = new O2S.Components.PDFRender4NET.Printing.PDFPrintSettings(settings);
            //pdfPrintSettings.PaperSize = ps;
            //pdfPrintSettings.PageScaling = O2S.Components.PDFRender4NET.Printing.PageScaling.FitToPrinterMarginsProportional;
            //pdfPrintSettings.PrinterSettings.Copies = 1;

            try
            {
                //file.Print(pdfPrintSettings);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);

                throw;
            }
            finally
            {
                //file.Dispose();
            }
        }
Example #8
0
        public void printMails()
        {
            try
            {
                foreach (ActiveUp.Net.Mail.Message msg in this.ListMessageInbox)
                {
                    string mailToPrint = this.FormatMailToPrint(msg);
                    RawPrinterHelper.SendStringToPrinter(this.printerName, mailToPrint);
                    msg.StoreToFile("C:/Mytext.txt");

                    if (msg.Attachments != null)
                    {
                        for (int i = 0; i < msg.Attachments.Count; i++)
                        {
                            string directory = Path.Combine(Path.GetTempPath(), Constants.SAVE_FOLDER);

                            if (!Directory.Exists(directory))
                            {
                                Directory.CreateDirectory(directory);
                            }

                            if (msg.Attachments[i] != null)
                            {
                                string fileDirectory = Path.Combine(directory, msg.Attachments[i].Filename);
                                msg.Attachments[i].StoreToFile(fileDirectory);

                                RawPrinterHelper.SendFileToPrinter(this.printerName, fileDirectory);
                                File.Delete(fileDirectory);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Could not print the mails", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #9
0
        private void btImprimir_Click(object sender, EventArgs e)
        {
            int status = 0;

            lbError.Visible = false;
            try
            {
                btImprimir.Enabled = false;
                _faa           = Convert.ToInt64(txtFAA.Text);
                txtFAA.Enabled = false;
                try
                {
                    int retorno = MontagemTxt(_faa);
                    if (retorno.ToString() == "0")
                    {
                        //string endereco = "C:\\Users\\hospub\\Documents\\docteste.txt";
                        // Allow the user to select a printer.
                        PrintDialog pd = new PrintDialog();
                        pd.PrinterSettings = new PrinterSettings();

                        // Print the file to the printer.
                        RawPrinterHelper.SendFileToPrinter(pd.PrinterSettings.PrinterName, enderecoCompleto);

                        //excluir arquivo
                        System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(@"C:\Users\hospub\Documents\Teste");
                        // Delete this dir and all subdirs.
                        try
                        {
                            di.Delete(true);
                        }
                        catch (System.IO.IOException ev)
                        {
                            error              = ev.Message;
                            lbError.Visible    = true;
                            lbError.Text       = error.ToString();
                            btImprimir.Enabled = true;
                            txtFAA.Enabled     = true;
                            status             = 1;
                        }



                        btImprimir.Enabled = true;
                        txtFAA.Enabled     = true;

                        lbError.Text = "";
                        status       = 0;
                    }
                }
                catch (Exception ex)
                {
                    error           = ex.Message;
                    lbError.Visible = true;
                    lbError.Text    = error.ToString();

                    btImprimir.Enabled = true;
                    txtFAA.Enabled     = true;
                    status             = 1;
                }
            }
            catch (Exception ex)
            {
                error           = ex.Message;
                lbError.Visible = true;
                lbError.Text    = error.ToString();

                btImprimir.Enabled = true;
                txtFAA.Enabled     = true;
                status             = 1;
            }
        }
Example #10
0
        private void button_Aceptar_Click(object sender, EventArgs e)
        {
            try
            {
                //importe
                if (textBox_Importe.Text != "")
                {
                    decimal auxiliar = 0;
                    if (Decimal.TryParse(textBox_Importe.Text, out auxiliar) == true)
                    {
                        if (auxiliar > 0)
                        {
                            textBox_Importe.Text = Funciones.Formatea(textBox_Importe.Text);
                        }
                    }
                }

                //detcod
                if (textBox_DetCod.Text != "" && textBox_Importe.Text != "")
                {
                    //insertar cobro
                    //proceso anterior, insertaba el abono en la tabla ABONOS
                    //string insert = "INSERT INTO ABONOS(DetCod, Fecha, Importe, Observaciones) ";
                    //insert += " VALUES(" + textBox_DetCod.Text + ", '" + textBox_Fecha.Text + "', " + textBox_Importe.Text + ", '" + textBox_Observaciones.Text.Replace("'", "''") + "')";

                    //SqlCommand myCommand = new SqlCommand(insert, myConnection);
                    //int res = myCommand.ExecuteNonQuery();

                    //proceso actual, crea un albarán y una factura con importes negativo
                    clase_linea_factura linea_factura = new clase_linea_factura();

                    //ComentadoEncarni
                    //linea_factura.LinF = "1";
                    linea_factura.ArtCod = "9998";
                    //ComentadoEncarni
                    //linea_factura.VelImp = textBox_Importe.Text;

                    string anyo = textBox_Fecha.Text.Substring(6, 4);

                    string factura = Funciones.FacturarAbono2(textBox_DetCod.Text, anyo, "AB", Convert.ToDateTime(textBox_Fecha.Text), linea_factura, textBox_Observaciones.Text, textBox_Importe.Text, myConnection);

                    if (factura != "")
                    {
                        MessageBox.Show("El abono se ha realizado correctamente");

                        //imprimir recibo
                        try
                        {
                            string fichero = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System)) + "\\OREMAPE\\RECIBOS\\temporal.txt";

                            TextWriter tw = new StreamWriter(fichero);


                            string linea = "ENDUMAR .";
                            tw.WriteLine(linea);
                            linea = "Mercavalencia, Modulo 20";
                            tw.WriteLine(linea);
                            linea = "46013 VALENCIA";
                            tw.WriteLine(linea); tw.WriteLine("");

                            linea = DateTime.Today.ToShortDateString();
                            tw.WriteLine(linea); tw.WriteLine("");

                            linea = "Cliente " + detcod;
                            tw.WriteLine(linea);

                            linea = "        " + detnom;
                            tw.WriteLine(linea); tw.WriteLine("");

                            linea = " Abonado: " + textBox_Importe.Text;
                            tw.WriteLine(linea);

                            linea = " ";
                            tw.WriteLine(linea);

                            if (textBox_Observaciones.Text != "")
                            {
                                linea = " Observaciones: " + textBox_Observaciones.Text;
                                tw.WriteLine(linea);
                            }

                            linea = " ";
                            tw.WriteLine(linea);

                            linea = " Firma o sello:";
                            tw.WriteLine(linea);

                            linea = " ";
                            tw.WriteLine(linea); tw.WriteLine(linea);

                            //Añadir 6 líneas en blanco
#if !DEBUG
                            tw.WriteLine(""); tw.WriteLine(""); tw.WriteLine("");
                            tw.WriteLine(""); tw.WriteLine(""); tw.WriteLine("");
#endif
                            tw.Close();


                            //Imprimir RECIBO

                            printDialog1.PrinterSettings = new System.Drawing.Printing.PrinterSettings();
                            string impresora = frmInicioCaja.RUTA_RECIBOS;
                            if (impresora == "")
                            {
                                impresora = printDialog1.PrinterSettings.PrinterName;
                            }

                            AbreCajon(impresora);
                            RawPrinterHelper.SendFileToPrinter(impresora, fichero);
                            CortaTicket(impresora);

                            //las pruebas en la oficina las haremos en Debug, y solo haremos un ticket
                            //al compilar como Release el ejecutable hará dos tickets:

#if !DEBUG
                            AbreCajon(impresora);
                            RawPrinterHelper.SendFileToPrinter(impresora, fichero);
                            CortaTicket(impresora);
#endif
                        }
                        catch (System.Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                    else
                    {
                        MessageBox.Show("Error. No se pudo registrar el abono.");
                    }
                }
                else
                {
                    MessageBox.Show("El importe y el código de cliente son obligatorios");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void button_Aceptar_Click(object sender, EventArgs e)
        {
            try
            {
                //importe
                if (textBox_Importe.Text != "")
                {
                    decimal auxiliar = 0;
                    if (Decimal.TryParse(textBox_Importe.Text, out auxiliar) == true)
                    {
                        if (auxiliar > 0)
                        {
                            textBox_Importe.Text = Funciones.Formatea(textBox_Importe.Text).Replace(",", ".");
                        }
                    }
                }
                //detcod
                if (textBox_DetCod.Text != "")
                {
                    //insertar cobro

                    string insert = "INSERT INTO COBROS_CUENTA(DetCod, FechaRecibido, Importe, Saldo, Observaciones) ";
                    insert += " VALUES(" + textBox_DetCod.Text + ", '" + textBox_Fecha.Text + "', " + textBox_Importe.Text + ", " + textBox_Importe.Text + ", '" + textBox_Observaciones.Text.Replace("'", "''") + "')";

                    SqlCommand myCommand = new SqlCommand(insert, myConnection);
                    int        res       = myCommand.ExecuteNonQuery();

                    if (res == 1)
                    {
                        MessageBox.Show("El cobro a cuenta ha sido almacenado");

                        //imprimir recibo
                        try
                        {
                            string fichero = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System)) + "\\OREMAPE\\RECIBOS\\temporal.txt";

                            TextWriter tw = new StreamWriter(fichero);

                            string linea = "JOSE CARABAL, S.L.";
                            tw.WriteLine(linea);
                            linea = "Mercavalencia, Modulos 12-13";
                            tw.WriteLine(linea);
                            linea = "46013 VALENCIA";
                            tw.WriteLine(linea); tw.WriteLine("");

                            linea = DateTime.Today.ToShortDateString();
                            tw.WriteLine(linea); tw.WriteLine("");

                            linea = "Cliente " + detcod;
                            tw.WriteLine(linea);

                            linea = "        " + detnom;
                            tw.WriteLine(linea); tw.WriteLine("");

                            linea = " Entregado a cuenta: " + textBox_Importe.Text;
                            tw.WriteLine(linea);

                            linea = " ";
                            tw.WriteLine(linea);

                            if (textBox_Observaciones.Text != "")
                            {
                                linea = " Observaciones: " + textBox_Observaciones.Text;
                                tw.WriteLine(linea);
                            }

                            //Añadir 6 líneas en blanco (para la versión Release)
#if !DEBUG
                            tw.WriteLine(""); tw.WriteLine(""); tw.WriteLine("");
                            tw.WriteLine(""); tw.WriteLine(""); tw.WriteLine("");
#endif
                            tw.Close();


                            //Imprimir RECIBO

                            printDialog1.PrinterSettings = new System.Drawing.Printing.PrinterSettings();
                            string impresora = frmInicioCaja.RUTA_RECIBOS;
                            if (impresora == "")
                            {
                                impresora = printDialog1.PrinterSettings.PrinterName;
                            }

                            AbreCajon(impresora);
                            RawPrinterHelper.SendFileToPrinter(impresora, fichero);
                            CortaTicket(impresora);

                            //si se compila como Release se imprimen dos copias:

#if !DEBUG
                            AbreCajon(impresora);
                            RawPrinterHelper.SendFileToPrinter(impresora, fichero);
                            CortaTicket(impresora);
#endif
                        }
                        catch (System.Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                    else
                    {
                        MessageBox.Show("Error. No se pudo registrar el cobro a cuenta");
                    }
                }
                else
                {
                    MessageBox.Show("No se ha dado código de cliente");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #12
0
 private void OnSendZPLRollCommand()
 {
     RawPrinterHelper.SendFileToPrinter(PrinterName, PathToZpl);
 }