Example #1
0
        public void TestPrint()
        {
            IntPtr hUSB        = PrintBridge.OpenUsb();
            int    sendSize    = 0;
            string teststr     = "打印机测试成功\r\n\r\n\r\n\r\n\r\n";
            string sendUnicode = Encoding.Unicode.GetString(Encoding.Default.GetBytes(teststr));

            PrintBridge.WriteUsb(hUSB, sendUnicode, Encoding.Unicode.GetByteCount(sendUnicode), ref sendSize);
        }
Example #2
0
        public void Print(object state)
        {
            if (state == null)
            {
                return;
            }

            //POS_SDK
            //IntPtr h_Printer = PrintBridge.POS_Port_OpenW("SP-USB1", 1002, false, null);

            //PrintBridge.POS_Output_PrintFontStringW(h_Printer, 0, 0, 0, 0, 0, "POS_SDK DLL Print testing\r\n");

            //long i = PrintBridge.POS_Port_Close(h_Printer);

            //if (i == 0)
            //{
            //    Console.ReadKey();
            //}

            //IntPtr hPrinter = new IntPtr(h_Printer);



            //芯烨提供的dll
            IntPtr hUSB     = PrintBridge.OpenUsb();
            int    sendSize = 0;
            //设置下划线
            //1b2d32
            //byte[] vs = { 0x1b, 0x2d, 0x32 };
            //byte[] vs = { 0x1b, 0x61, 0x01 };
            //byte[] vs = { 0x1c, 0xfc, 0x1c,0x2f,0x04,0x1c,0x15 };
            //gprinter 倍高倍宽
            //byte[] vs = { 0x1b, 0x21, 0x30 };
            //初始化打印设置
            //byte[] vs = { 0x1b, 0x40 };
            //byte[] vs = { 0x1b, 0x61,0x31 };
            //PrintBridge.WriteUsb(hUSB, Encoding.Unicode.GetString(vs), vs.Length, ref sendSize);
            string teststr     = "打印机测试成功\r\n\r\n\r\n\r\n\r\n";
            string sendUnicode = Encoding.Unicode.GetString(Encoding.Default.GetBytes(teststr));

            PrintBridge.WriteUsb(hUSB, sendUnicode, Encoding.Unicode.GetByteCount(sendUnicode), ref sendSize);



            PrintBridge.CloseUsb(hUSB);



            //string title = "";
            //string content = "";


            ////        Type stringObjectMap = new TypeToken<Map<String, Object>>() {
            ////        }.getType();
            //BillEntity billEntity = new BillEntity();
            //StringBuilder sb = new StringBuilder();

            //        usbPrinter.setPrinter(BluetoothPrinter.COMM_ALIGN, BluetoothPrinter.COMM_ALIGN_CENTER);
            //        usbPrinter.setCharacterMultiple(1, 1);
            //        usbPrinter.printText(billEntity.getBranchname() + "\n");

            //        usbPrinter.setPrinter(BluetoothPrinter.COMM_ALIGN, BluetoothPrinter.COMM_ALIGN_LEFT);
            //        usbPrinter.setCharacterMultiple(0, 0);

            //        sb.append(R.string.shop_num + billEntity.getBranchcode() + "   ");
            //        sb.append(R.string.shop_cashier_num + billEntity.getCashiername() + "\n");
            //        sb.append(R.string.shop_receipt_num + billEntity.getTicketcode() + "\n");

            //        sb.append(R.string.time + DateUtil.getTime(new Date()) + "\n");
            //        usbPrinter.printText(sb.toString());

            //        List<BillCommodityEntity> commoditys = billEntity.getCommoditys();
            //        List<PayDetailEntity> paydetails = billEntity.getPaydetails();


            //        if (commoditys != null && commoditys.size() > 0) {
            //            PrintUtils.printTable1(commoditys, usbPrinter); //打印表格
            //            double number = 0;
            //        float buyTotal = 0f;//原价总额
            //        float saleTotal = 0f;//售价总额
            //        float payTotal = 0f;//付款总额
            //            for (BillCommodityEntity billCommodityEntity : commoditys) {
            //                number = number + Double.valueOf(billCommodityEntity.getSalenums());
            ////                buyTotal = buyTotal + Float.valueOf(billCommodityEntity.getSaleprice()) * Integer.valueOf(billCommodityEntity.getSalenums());
            ////                saleTotal = saleTotal + Float.valueOf(billCommodityEntity.getSaleprice()) * Integer.valueOf(billCommodityEntity.getSalenums());
            //            }
            //    buyTotal = Float.valueOf(billEntity.getTotal());
            //            saleTotal = Float.valueOf(billEntity.getPaytotal());
            //            payTotal = Float.valueOf(billEntity.getCollection());
            ////            if (paydetails != null && paydetails.size() > 0) {
            ////                for (PayDetailEntity payDetailEntity : paydetails) {
            ////                    payTotal = payTotal + Float.valueOf(payDetailEntity.getPayamount());
            ////                }
            ////            }
            //            sb = new StringBuffer();
            //    sb.append(R.string.shop_goods_number + "  " + DateFormatUtil.parseDoubleString(number + "") + "\n");
            //            sb.append(R.string.shop_goods_buy_total_price + "  " + DateFormatUtil.parseDoubleString(buyTotal + "") + "\n");
            //            sb.append(R.string.shop_goods_sale_total_price + "  " + DateFormatUtil.parseDoubleString(saleTotal + "") + "\n");
            //            sb.append(R.string.shop_goods_sale_total_collection + "  " + DateFormatUtil.parseDoubleString(payTotal + "") + "\n");
            //            if ("2".equals(billEntity.getTradeid())) {
            //                sb.append(R.string.shop_goods_youhui + "  " + "0.00" + "\n");
            //            } else {
            //                sb.append(R.string.shop_goods_youhui + "  " + DateFormatUtil.parseDoubleString(buyTotal - saleTotal + "") + "\n");
            //            }
            //            sb.append(R.string.shop_payment + "  ");
            //            for (int i = 0; i<billEntity.getPaydetails().size(); i++) {
            //                PayDetailEntity payDetailEntity = billEntity.getPaydetails().get(i);
            //                if (i > 0) {
            //                    sb.append("   " + payDetailEntity.getPayname() + "  " + DateFormatUtil.parseDoubleString(payDetailEntity.getPayamount()) + "\n");

            //                } else {
            //                    sb.append(payDetailEntity.getPayname() + "  " + DateFormatUtil.parseDoubleString(payDetailEntity.getPayamount()) + "\n");
            //                }
            //            }
            //            if ("2".equals(billEntity.getTradeid())) {
            //                sb.append(R.string.shop_change + "  " + "0.00" + "\n");
            //            } else {
            //                sb.append(R.string.shop_change + "  " + DateFormatUtil.parseDoubleString(payTotal - saleTotal + "") + "\n");
            //            }
            ////            if (mPrinter.getCurrentPrintType() == com.printer.sdk.api.PrinterType.TIII || mPrinter.getCurrentPrintType() == com.printer.sdk.api.PrinterType.T5) {
            ////                sb.append(resources.getString(R.string.shop_goods_number) + "  " + DateFormatUtil.parseDoubleString(number + "") + "\n");
            ////                sb.append(resources.getString(R.string.shop_goods_buy_total_price) + "  " + DateFormatUtil.parseDoubleString(buyTotal + "") + "\n");
            ////                sb.append(resources.getString(R.string.shop_goods_sale_total_price) + "  " + DateFormatUtil.parseDoubleString(saleTotal + "") + "\n");
            ////                sb.append(resources.getString(R.string.shop_goods_youhui) + "  " + DateFormatUtil.parseDoubleString(buyTotal - saleTotal + "") + "\n");
            ////                sb.append(resources.getString(R.string.shop_payment) + "  ");
            ////                for (int i = 0; i < billEntity.getPaydetails().size(); i++) {
            ////                    PayDetailEntity payDetailEntity = billEntity.getPaydetails().get(i);
            ////                    if (i > 0) {
            ////                        sb.append("   " + DateFormatUtil.parseDoubleString(payDetailEntity.getPayname() + "  " + payDetailEntity.getPayamount()) + "\n");
            ////
            ////                    } else {
            ////                        sb.append(DateFormatUtil.parseDoubleString(payDetailEntity.getPayname() + "  " + payDetailEntity.getPayamount()) + "\n");
            ////                    }
            ////                }
            ////                sb.append(resources.getString(R.string.shop_change) + "  " + DateFormatUtil.parseDoubleString(payTotal - saleTotal + "") + "\n");
            ////            } else {
            ////                sb.append(resources.getString(R.string.shop_goods_number) + "                                " + DateFormatUtil.parseDoubleString(number + "") + "\n");
            ////                sb.append(resources.getString(R.string.shop_goods_buy_total_price) + "                                " + DateFormatUtil.parseDoubleString(buyTotal + "") + "\n");
            ////                sb.append(resources.getString(R.string.shop_goods_sale_total_price) + "                                " + DateFormatUtil.parseDoubleString(saleTotal + "") + "\n");
            ////                sb.append(resources.getString(R.string.shop_goods_youhui) + "                                " + DateFormatUtil.parseDoubleString(buyTotal - saleTotal + "") + "\n");
            ////
            ////                sb.append(resources.getString(R.string.shop_payment) + "                                " + DateFormatUtil.parseDoubleString(payTotal + "") + "\n");
            ////                sb.append(resources.getString(R.string.shop_change) + "                                " + DateFormatUtil.parseDoubleString(payTotal - saleTotal + "") + "\n");
            ////            }

            ////            sb.append(resources.getString(R.string.shop_company_name) + "\n");
            ////            sb.append(resources.getString(R.string.shop_company_site) + "www.jiangsu1510.com\n");
            ////            sb.append(resources.getString(R.string.shop_company_address) + "\n");
            ////            sb.append(resources.getString(R.string.shop_company_tel) + "0574-88222999\n");
            ////            sb.append(resources.getString(R.string.shop_Service_Line) + "4008-567-567 \n");
            //            if (usbPrinter.getCurrentPrintType() == PrinterType.TIII || usbPrinter.getCurrentPrintType() == PrinterType.T5) {
            //                sb.append("------------------------------\n");
            //            } else {
            //                sb.append("----------------------------------------------\n");
            //            }
            //            usbPrinter.printText(sb.toString());

            //            if (!StringUtil.isEmpty(billEntity.getMemberid())) {
            //                StringBuffer memSb = new StringBuffer();
            //memSb.append(R.string.member_name + billEntity.getMembername());
            //                memSb.append("\n");
            //                memSb.append(R.string.member_code + billEntity.getMembercode());
            //                memSb.append("\n");
            //                memSb.append(R.string.balance + billEntity.getMemberacount());
            //                memSb.append("  ");
            //                memSb.append(R.string.integral + billEntity.getMembercredit());
            //                memSb.append("\n");
            //                if (usbPrinter.getCurrentPrintType() == PrinterType.TIII || usbPrinter.getCurrentPrintType() == PrinterType.T5) {
            //                    memSb.append("------------------------------\n");
            //                } else {
            //                    memSb.append("----------------------------------------------\n");
            //                }
            //                usbPrinter.printText(memSb.toString());
            //            }

            //            usbPrinter.setPrinter(BluetoothPrinter.COMM_ALIGN, BluetoothPrinter.COMM_ALIGN_CENTER);
            //            usbPrinter.setCharacterMultiple(0, 1);
            //            usbPrinter.printText(R.string.shop_thanks + "\n\n\n\n\n\n");
            //            usbPrinter.setPrinter(BluetoothPrinter.COMM_ALIGN, BluetoothPrinter.COMM_ALIGN_LEFT);
            //            usbPrinter.setCharacterMultiple(0, 0);
            ////            mPrinter.printText(resources.getString(R.string.shop_demo) + "\n\n\n");
            //        }
        }