【问题标题】:OPOS Printing using ASP.NET使用 ASP.NET 进行 OPOS 打印
【发布时间】:2014-05-06 05:56:10
【问题描述】:

我使用ASP.NET Web Forms C# 4.0 开发了一个餐厅计费网络应用程序(不是桌面应用程序,因为要求是在浏览器中运行的网络应用程序)。现在的新要求是 POS 热敏打印机收据打印。我对 POS 很陌生,但不知何故,我设法使用 c# 构建并运行了一个示例 Windows 窗体应用程序以在 POSIFLEX PP6800 Thermal Receipt Printer 上打印。

问题是我无法在 Localhost 网站上使用相同的代码进行打印。我正在使用OPOS CCOOposForDotNetAssemblies-1_13_000

我的问题是:

  1. 是否可以在 LocalHost 上的 OPOS 上打印?
  2. 是否可以通过 Internet 网站在 OPOS 上打印?
  3. 如果是,我应该怎么做?我做错了什么?

我使用的代码是:

using POS.Devices;
private OPOSPOSPrinter Printer = null;
protected void Button1_Click(object sender, EventArgs e)
{
    Printer = new OPOSPOSPrinterClass();

    // Open the printer.
    Printer.Open("PosPrinter");
    Printer.ClaimDevice(1000);
    Printer.AsyncMode = true;
    Printer.DeviceEnabled = true;
    Printer.ResultCode;
    Printer.PrintNormal(2, "\x1B|cA\x1B|2CHeading\x1B|1C\n"+DateTime.Now.ToString("D")+"\n\n" );
    Printer.CutPaper(1);
    Printer.Close();
 }

有趣的是没有错误,但我听到哔哔声直到超时,然后打印机在一行中打印一些点和字符,没有别的。 Windows 窗体中没有发生这种情况。提前致谢。

【问题讨论】:

    标签: c# asp.net thermal-printer opos posiflex


    【解决方案1】:

    我最近开发了一个 POS Web 应用程序 它使用热敏打印机打印收据,它使用本地打印机

    您只需使用 javascript 来捕获容器或.....您的内容

    只需使用 window.print() 调用它即可打印您的收据,它对我有用

    【讨论】:

      【解决方案2】:

      Public Sub GiftReceipt()

      试试

          Dim displayString As String
      
           Dim ESC As String = Chr(&H1B)
      
          displayString = ESC + "!" + Chr(1) + ESC + "|cA" + "Store Name" + ESC + "|1lF"
          displayString += ESC + "|cA" + "Store Address" + ESC + "|1lF"
          displayString += ESC + "|2C" + ESC + "|cA" + ESC + "|bC" + "Gift Receipt" + ESC + "|1lF" + ESC + "|1lF"
          displayString += ESC + "|N" + ESC + "!" + Chr(1) + "  Transaction #:  " + vbTab.ToString() + "105" + ESC + "|1lF"
      

      displayString += " 日期:" + Date.Today() + vbTab.ToString() + "时间:"

         displayString += DateAndTime.Now().ToLongTimeString() + ESC + "|1lF"
      
         displayString += "  Cashier:  " + CStr(_currSess.Cashier.Number) + vbTab.ToString() + "Register:  " + CStr(_currSess.Register.Number) + ESC + "|1lF" + ESC + "|1lF"
      
         displayString += ESC + "|2uC" + "  Item                 Description           Quantity" + ESC + "|N" + ESC + "!" + Chr(1) + ESC + "|1lF" + ESC + "|1lF" + "  "
      
          'Iterate loop for each row of the Data Set.
      For k As Integer = 0 To TransactionSet1.TransactionEntry.Rows.Count - 1
      
                  'Checking for each row which has selected in DataGrid item.
        If CType(dgTransactionList.Item(k, 0), System.String) = "True" Then
      
                        'Get the Item value from selected row.
            Dim item As String = dgTransactionList.Item(k, 1).ToString()
      
                        Dim itemValue As String = String.Empty
                         If item.Length > 11 Then
      

      '如果Item长度大于11,则取item 0到11的子串。 item = item.Substring(0, 11) 别的 '在项目字符串中添加“”,直到长度为 11。 而 item.Length

                                       item += " "
      
                                End While
      
                        End If
      
           displayString += item + vbTab.ToString()
       Dim desc As String = dgTransactionList.Item(k, 2).ToString()
           Dim descValue As String = String.Empty
      
            If desc.Length > 20 Then
      
        'If Description length is greater then 20, then take substring of item 0 to 20.
                   desc = desc.Substring(0, 20)
      
                      Else
                  While desc.Length <= 20
      
                 'Adding " " in Description string until length 20.
                                    desc += " "
      
                             End While
      
                      End If
      
                      displayString += desc + vbTab.ToString()
          Dim qnty As String = dgTransactionList.Item(k, 3).ToString()
                      Dim qntyValue As String = String.Empty
      
                      If qnty.Length > 3 Then
      
        'If Quantity length is greater then 20, then take substring of quantity 0 to 3.
            qnty = qnty.Substring(0, 3)
      
                      Else
      
                          While qnty.Length <= 3
      
                        'Adding " " in Quantity string until length 20.
                                   qntyValue += " "
                                    qnty += " "
      
                          End While
      
                      End If
      
                      qntyValue += qnty.Trim()
                      displayString += qntyValue
                      displayString += ESC + "|1lF" + "  "
      
                  End If
      
          Next k
      
       displayString += ESC + "|1lF"
       displayString += ESC + "|cA" + "Thank You for shopping" + ESC + "|1lF"
              displayString += ESC + "|cA" + _currSess.Configuration.StoreName + ESC + "|1lF"
              displayString += ESC + "|cA" + "We hope you'll come back soon!" + ESC + "|1lF" + ESC + "|1lF" + ESC + "|fP"
              _currSess.Register.SetActivePrinterNumber(0)
      
              Dim objRp As Object = _currSess.Register.ReceiptPrinter
              objRp.PrintNormal(2, displayString))
      
              objRp.Release()
              MsgBox("Gift Receipt printed Successfully.")
      
      Catch ex As Exception
      
              MsgBox(ex.ToString())
      
       End Try
      

      结束子

      【讨论】:

        猜你喜欢
        • 2015-09-03
        • 2013-04-08
        • 2012-08-30
        • 2014-05-24
        • 2014-02-23
        • 2013-04-13
        • 2016-08-16
        • 2012-01-26
        • 1970-01-01
        相关资源
        最近更新 更多