Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                posPrinter.Claim(1000);
                posPrinter.DeviceEnabled = true;
                posPrinter.PrintNormal(PrinterStation.Receipt, "\u001b|4C" + "\u001b|bC" + "\u001b|cA" + "Lista de Faltantes\n");


                string divisionLine = "_".PadLeft(posPrinter.RecLineChars - 2, '_');
                posPrinter.PrintNormal(PrinterStation.Receipt, "\u001b|bC" + divisionLine + "\n");
                posPrinter.PrintNormal(PrinterStation.Receipt, "Stock Actual\tCantidad Faltante\tProducto\n");
                posPrinter.PrintNormal(PrinterStation.Receipt, "\u001b|bC" + divisionLine + "\n");

                foreach (DataGridViewRow row in dataGrid1.Rows)
                {
                    if (Convert.ToBoolean(row.Cells["imprimir"].Value))
                    {
                        posPrinter.PrintNormal(PrinterStation.Receipt, "\u001b|N" + row.Cells["Stock actual"].Value.ToString() + "\t" + row.Cells["Faltante"].Value.ToString()
                                               + "\t" + row.Cells["descripción"].Value.ToString() + ", " + row.Cells["marca"].Value.ToString() + "\n");
                    }
                }

                posPrinter.PrintNormal(PrinterStation.Receipt, "\u001b|fP");

                posPrinter.DeviceEnabled = false;
                posPrinter.Release();
            }
            catch
            {
            }


            /*
             * try
             * {
             *  PrintDocument printDocument = new PrintDocument() { PrintController = new StandardPrintController() };
             *
             *  printDocument.PrinterSettings.PrinterName = this.printer.printerName;
             *  this.printDialog1.Document = printDocument;
             *  printDocument.PrintPage += new PrintPageEventHandler(this.prepareTicket);
             *  printDocument.Print();
             * }
             * catch (InvalidPrinterException)
             * {
             *  int num = (int)MessageBox.Show("Registre una impresora para poder utilizar esta opción", "No se ha registrado impresora");
             * }*/
        }
Exemple #2
0
        private void DisposePrinter()
        {
            if (m_Printer != null)
            {
                try
                {
                    //Cancel the device
                    m_Printer.DeviceEnabled = false;

                    //Release the device exclusive control right.
                    m_Printer.Release();

                    //Finish using the device.
                    m_Printer.Close();
                }
                catch (PosControlException ex)
                {
                    _logger.LogError(ex, "An error occurred", "frmMain", "DeactivateScanner");
                }
                finally
                {
                    Application.Exit();
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// When the method "closing" is called,
 /// the following code is run.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void ReleasePrinter()
 {
     //<<<step1>>>--Start
     if (m_Printer != null && HavePrinter)
     {
         try
         {
             //Cancel the device
             //m_Printer.DeviceEnabled = false;
             m_Printer.Close();
             //Release the device exclusive control right.
             m_Printer.Release();
             m_Printer   = null;
             HavePrinter = false;
         }
         catch (PosException)
         {
         }
         finally
         {
             //Finish using the device.
             //m_Printer.Close();
             HavePrinter = false;
         }
     }
     //<<<step1>>>--End
 }
Exemple #4
0
 /// <summary>
 /// Cierra la conexion a la impresora y corta el papel
 /// </summary>
 public void Close()
 {
     if (_printer != null)
     {
         _printer.CutPaper(100);
         _printer.Release();
         _printer.Close();
     }
 }
Exemple #5
0
 public void Dispose()
 {
     try
     {
         posPrinter.DeviceEnabled = false;
         posPrinter.Release();
         posPrinter.Close();
     }
     catch { } // 握り潰し
 }
Exemple #6
0
 public void Release()
 {
     if (_printer.Claimed)
     {
         if (_printer.DeviceEnabled)
         {
             _printer.DeviceEnabled = false;
         }
         _printer.Release();
     }
 }
 private void DisconnectFromPrinter(PosPrinter printer)
 {
     try
     {
         printer.Release();
         printer.Close();
     }
     catch
     {
     }
 }
        public void Dispose()
        {
            if (_printer != null)
            {
                _printer.TransactionPrint(PrinterStation.Receipt, PrinterTransactionControl.Normal);
                _printer.AsyncMode = false;

                _printer.Release();
                _printer.Close();
                _printer = null;
            }
        }
Exemple #9
0
 public void Close()
 {
     try
     {
         m_Printer.DeviceEnabled = false;
         m_Printer.Release();
     }
     catch (PosControlException)
     {
     }
     finally
     {
         m_Printer.Close();
     }
 }
 public void UnloadPrinter()
 {
     try
     {
         if (m_Printer == null)
         {
             return;
         }
         m_Printer.Release();
         m_Printer.Close();
     }
     catch (PosControlException)
     {
         Debug.WriteLine("Printer cannot unload, perhaps its turned off? Or not connected?");
     }
 }
        public void Dispose()
        {
            if (m_Printer != null)
            {
                try
                {
                    //Cancel the device
                    m_Printer.DeviceEnabled = false;

                    //Release the device exclusive control right.
                    m_Printer.Release();
                }
                catch (PosControlException)
                {
                }
                finally
                {
                    //Finish using the device.
                    m_Printer.Close();
                }
            }
            Release();
        }
Exemple #12
0
        public void print(String PrintString)
        {

            try
            {
                string myString;

                _printer.Open();
                _printer.Claim(1000);
                _printer.AsyncMode = false; //Must be False!!!!!!!!
                _printer.DeviceEnabled = true;

                myString = PrintString.Replace("ESC", Convert.ToChar(27).ToString()) + Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString();

                _printer.PrintNormal(PrinterStation.Receipt, myString);

                //_printer.PrintNormal(PrinterStation.Receipt, Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString());

                //_printer.PrintNormal(PrinterStation.Receipt, Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString());

                //_printer.PrintNormal(PrinterStation.Receipt, Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString());

                //_printer.PrintNormal(PrinterStation.Receipt, Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString());

                _printer.CutPaper(90);

                _printer.DeviceEnabled = false;
                _printer.Release();
                _printer.Close();

            }
            catch (Exception ex)
            {
               // MessageBox.Show(ex.Message);
            }

        }
Exemple #13
0
        /// <summary>
        /// When the method "closing" is called,
        /// the following code is run.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmStep1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //<<<step1>>>--Start
            if (m_Printer != null)
            {
                try
                {
                    //Cancel the device
                    m_Printer.DeviceEnabled = false;

                    //Release the device exclusive control right.
                    m_Printer.Release();
                }
                catch (PosControlException)
                {
                }
                finally
                {
                    //Finish using the device.
                    m_Printer.Close();
                }
            }
            //<<<step1>>>--End
        }
Exemple #14
0
        public void Initialize(PosPrinter mPrinter)
        {
            PosExplorer posExplorer    = null;
            DeviceInfo  deviceInfo     = null;
            string      strLogicalName = "Printer";

            try
            {
                //Create PosExplorer
                posExplorer = new PosExplorer();

                try
                {
                    deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName);
                }
                catch (Exception e)
                {
                    mSend("当前系统中不止一台Printer设备,请设置默认的Printer类型打印机. 打印机异常");
                    mSend("前往 C:\\Program Files\\epson\\OPOS for .NET\\SetupPOS,运行 Epson.opos.tm.setpos.exe ,更改默认实例名为'Printer'");
                    System.IO.File.AppendAllText(@"C:\hot.txt", DateTime.Now.ToString() + ": " + e.ToString() + "\r\n");
                    return;
                }
                try
                {
                    mPrinter = (PosPrinter)posExplorer.CreateInstance(deviceInfo);
                }
                catch (Exception e)
                {
                    mSend("创建PosPrinter设备实例失败.打印机异常");
                    mSend("前往 C:\\Program Files\\epson\\OPOS for .NET\\SetupPOS,运行 Epson.opos.tm.setpos.exe ,检查默认实例名是否为'Printer'");
                    System.IO.File.AppendAllText(@"C:\hot.txt", DateTime.Now.ToString() + ": " + e.ToString() + "\r\n");
                    return;
                }

                AddErrorEvent(mPrinter);
                AddStatusUpdateEvent(mPrinter);

                //Open the device
                try
                {
                    mPrinter.Open();
                }
                catch (PosControlException e)
                {
                    System.IO.File.AppendAllText(@"C:\hot.txt", DateTime.Now.ToString() + ": " + e.ToString() + "\r\n");
                    if (e.ErrorCode == ErrorCode.Illegal)
                    {
                        mSend("打印机已经被打开! 打印机故障");
                    }
                    else
                    {
                        mSend("打开打印机失败! 打印机故障");
                    }
                    return;
                }

                //Get the exclusive control right for the opened device.
                //Then the device is disable from other application.
                try
                {
                    mPrinter.Claim(1000);
                }
                catch (Exception e)
                {
                    mSend("请检查打印机电源、连接线及退出其他正在占用打印机的程序,并稍后重试 打印机故障");
                    System.IO.File.AppendAllText(@"C:\hot.txt", DateTime.Now.ToString() + ": " + e.ToString() + "\r\n");
                    return;
                }

                //Enable the device.
                try
                {
                    mPrinter.DeviceEnabled = true;
                }
                catch (Exception e)
                {
                    mSend("试图使能打印机失败 打印机故障");
                    System.IO.File.AppendAllText(@"C:\hot.txt", DateTime.Now.ToString() + ": " + e.ToString() + "\r\n");
                    return;
                }

                try
                {
                    //Output by the high quality mode
                    mPrinter.RecLetterQuality = true;


                    // Even if using any printers, 0.01mm unit makes it possible to print neatly.
                    mPrinter.MapMode = MapMode.Metric;
                }
                catch (Exception e)
                {
                    System.IO.File.AppendAllText(@"C:\hot.txt", DateTime.Now.ToString() + ": " + e.ToString() + "\r\n");
                    return;
                }
            }
            catch (Exception ex)
            {
                System.IO.File.AppendAllText(@"C:\hot.txt", DateTime.Now.ToString() + ": " + ex.ToString() + "\r\n");
                return;
            }

            try
            {
                mPrinter.DeviceEnabled = false;
                mPrinter.Release();
            }
            catch (PosControlException)
            {
            }
            finally
            {
                mPrinter.Close();
            }
            mSend("打印机正常!");
        }
Exemple #15
0
 private static void DisconnectFromPrinter(PosPrinter printer)
 {
     printer.Release();
     printer.Close();
 }
Exemple #16
-2
        public Printer(string logicalName, bool connect)
        {
            instance = this;
            if (connect)
            {
                this.profile = null;
                this.deviceStatus = PrintDeviceStatus.Properly;
                this.PrintStatus = PrintStatus.Stopped;

                try
                {
                    DeviceInfo deviceInfo = null;
                    PosExplorer posExplorer = new PosExplorer();
                    deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, logicalName);
                    device = (PosPrinter)posExplorer.CreateInstance(deviceInfo);
                    device.Open();
                    device.Claim(1000);
                    device.AsyncMode = false;
                    device.DeviceEnabled = true;

                    device.StatusUpdateEvent += Device_StatusUpdateEvent;
                    device.ErrorEvent += (a, b) => { WriteLog("ERROR - " + b.ToString()); };
                    WriteLog("");
                    WriteLog("Drucker initialisiert; Status: " + device.State + device);
                    if (device.RecNearEnd) Device_StatusUpdateEvent(this, new StatusUpdateEventArgs(25));
                    this.connected = connect;
                }
                catch (Exception ex)
                {
                    string s = ex.Source;
                    try
                    {
                        if (device != null)
                            device.Release();
                    }
                    catch { }
                    throw new Exception("Verbindung zum Drucker fehlgeschlagen.", ex);
                }
            }
            else
            {
                this.connected = false;
                this.PrintStatus = PrintStatus.Stopped;
                this.deviceStatus = PrintDeviceStatus.Properly;
            }
        }