Пример #1
0
        public string openCashBox()
        {
            string posNum  = string.Empty;
            string posType = string.Empty;

            try
            {
                //nec的机子,此方法不会真正调钱箱方法,只是会用返回的posNum。真正真正调钱箱方法在IsNec的判断里面
                OpenCashBox.OpenCashBox.openCashBox(out posNum, out posType);
                LogTools.Info(string.Format("调OpenCashBox.openCashBox的结果:posNum:{0},posType:{1}。", posNum, posType));
            }
            catch (Exception ex)
            {
                LogTools.Info("调弹钱箱异常:" + ex.ToString());
            }
            if (IsNec == 1)
            {
                try
                {
                    int num = this.cashDrawer1.Open(cashBox_name);
                    if (num != 0)
                    {
                        cashDrawer1.Close();
                        num = cashDrawer1.Open(cashBox_name);
                        if (num != 0)
                        {
                            throw new Exception("[Pos 2001] 钱箱驱动Open失败!返回码:" + num.ToString());
                        }
                    }
                    int claimResult = cashDrawer1.ClaimDevice(1000);
                    if (claimResult != 0)
                    {
                        throw new Exception("[Pos 2002] 钱箱声明失败!返回码:" + claimResult.ToString());
                    }
                    cashDrawer1.DeviceEnabled = true;
                    cashDrawer1.OpenDrawer();
                    cashDrawer1.DeviceEnabled = false;
                }
                catch (Exception ex)
                {
                    LogTools.Debug("开钱箱异常:" + ex.ToString());
                }
                finally
                {
                    cashDrawer1.ReleaseDevice();
                    cashDrawer1.Close();
                }
            }
            return(posNum);
        }
Пример #2
0
        private void regSvr()
        {
            string s1           = System.Environment.CurrentDirectory;
            string fullFileName = s1 + "\\Files\\Reg.bat";
            bool   IsExists     = false;

            if (!System.IO.File.Exists(fullFileName))
            {
                fullFileName = s1 + "\\Ampm365\\Files\\Reg.bat";
                if (!System.IO.File.Exists(fullFileName))
                {
                    IsExists = false;
                }
                else
                {
                    IsExists = true;
                }
            }
            else
            {
                IsExists = true;
            }
            if (IsExists)
            {
                try
                {
                    System.Diagnostics.ProcessStartInfo myStartInfo = new System.Diagnostics.ProcessStartInfo();
                    myStartInfo.FileName    = fullFileName;
                    myStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
                    myProcess.StartInfo = myStartInfo;
                    myProcess.Start();
                    myProcess.WaitForExit(3000); //等待程序退出
                    myProcess.Close();
                    myStartInfo = null;
                    myProcess   = null;
                }
                catch (Exception ex)
                {
                    LogTools.Debug("注册打印OCX异常:" + ex.Message);
                }
                finally { System.GC.Collect(); }
            }
            else
            {
                LogTools.Debug("注册打印OCX失败:找不到bat文件");
            }
        }
Пример #3
0
 public string Print2Bitmap(string url, string fileName, int lineNum)
 {
     try
     {
         string text2 = Utils.Substitute(AppDomain.CurrentDomain.BaseDirectory, "\\") + fileName;
         FileTransferHttp.DownloadPicture(url, text2);
         LogTools.Info("临时图片路径:" + text2);
         Bitmap bmp = new Bitmap(text2);
         try
         {
             //前置回车
             for (int i = 0; i < lineNum - 1; i++)
             {
                 this.posPrinter.PrintNormal(2, " " + Environment.NewLine);
             }
             int rst = 0;
             #region 图片
             try
             {
                 rst = this.posPrinter.SetBitmap(1, 2, text2, -11, -2);
             }
             catch (Exception ex)
             {
                 LogTools.Debug(ex.Message);
             }
             rst = this.posPrinter.PrintBitmap(2, text2, -11, -2);
             #endregion
         }
         catch (Exception ex)
         {
             LogTools.Info("打印图片异常:" + ex.ToString());
             throw ex;
         }
         finally
         {
             bmp.Dispose();
         }
     }
     catch (Exception)
     {
         throw;
     }
     return(string.Empty);
 }
Пример #4
0
        public string setPrintOrder(string orderInfo)
        {
            string result;

            if (string.IsNullOrEmpty(orderInfo))
            {
                return("false");
            }
            try
            {
                int ix = orderInfo.IndexOf('|');
                if (!(ix >= 0 && ix < orderInfo.Length - 1))
                {
                    return("false");
                }
                string[] array = new string[] { orderInfo.Substring(0, ix), orderInfo.Substring(ix + 1) };
                if (array[0].Equals(this.SYSTEM_BROWSER_NAME))
                {
                    if (Print.IsNewInParam())
                    {
                        List <PrintLineModel> lines = Newtonsoft.Json.JsonConvert.DeserializeObject <List <PrintLineModel> >(array[1]);
                        this.PrintNewList(lines);
                    }
                    else
                    {
                        ////{\"printType\":\"Print2\",\"printData\":{\"order_id\":\"167523\",\"change_price\":\"0.30\",\"order_sn\":\"722450976000041\",\"shop_sn\":\"B00062\",\"org_price\":\"50.10\",\"allprice\":\"40.12(需补现金0.30元)\",\"total_price\":\"40.12\",\"coupMoney\":\"20.00\",\"pay_name\":\"\",\"allnums\":\"\",\"send_type\":\"6\",\"send_price\":\"8.50\",\"cheap_price\":\"9.98\",\"accept_name\":\"蔡云鹤\",\"address\":\"北京市朝阳区西坝河东里社区3号楼3单元303室\",\"mobile\":\"13718070605\",\"add_time\":\"2017-09-17 20:22:55\",\"hope_time\":\"立即送达\",\"platform\":\"京东到家\",\"buyer_note\":\"#所购商品如遇缺货,您需要:其他商品继续配送(缺货商品退款)\",\"wm_order_id_view\":\"\",\"pingtai\":\"\",\"pingtai2\":\"京东到家\",\"costprice\":\"50.10\",\"wuliu\":\"京东到家\",\"shopname\":\"全时-光熙家园\",\"shoptel\":\"010-56912050\",\"onecode\":\"http://service.ampm365.cn/org/generate/barcode?orderSn=722450976000041&dpi=80&fontSize=7&fileType=image/png&width=2.0\",\"status\":\"2\",\"goods\":[{\"goods_name\":\"03010090       多谷物芝士软欧面包\",\"gb\":\"6932005201820\",\"real_price\":5.4,\"nums\":\"1\"},{\"goods_name\":\"07010227       纯享原味发酵乳230g\",\"gb\":\"6922577726494\",\"real_price\":4.03,\"nums\":\"4\"},{\"goods_name\":\"51010104       统一小浣熊干脆面(烤肉味)\",\"gb\":\"6902447168708\",\"real_price\":1.2,\"nums\":\"1\"},{\"goods_name\":\"07010189       乳此新鲜香蕉牛奶236ml\",\"gb\":\"6950418707579\",\"real_price\":5.2,\"nums\":\"1\"},{\"goods_name\":\"51020301       双汇鸡肉肠65g根\",\"gb\":\"6902890235835\",\"real_price\":1.2,\"nums\":\"1\"},{\"goods_name\":\"27010006       怡达果丹皮200g\",\"gb\":\"6920242100280\",\"real_price\":5.5,\"nums\":\"1\"},{\"goods_name\":\"03010292       炼乳吐司面包\",\"gb\":\"6932005204173\",\"real_price\":5.5,\"nums\":\"1\"}]}}
                        //JObject obj = JObject.Parse(array[1]);
                        //this.PrintOrder(obj);
                    }
                }
                result = "true";
            }
            catch (Exception ex)
            {
                LogTools.Debug(ex.Message);
                result = ex.Message;
            }
            return(result);
        }
Пример #5
0
        public string setPrintOrder(string orderInfo)
        {
            string result;

            if (string.IsNullOrEmpty(orderInfo))
            {
                return("false");
            }
            try
            {
                int ix = orderInfo.IndexOf('|');
                if (!(ix >= 0 && ix < orderInfo.Length - 1))
                {
                    return("false");
                }
                string[] array = new string[] { orderInfo.Substring(0, ix), orderInfo.Substring(ix + 1) };
                if (array[0].Equals(this.SYSTEM_BROWSER_NAME))
                {
                    if (Print.IsNewInParam())
                    {
                        List <PrintLineModel> lines = Newtonsoft.Json.JsonConvert.DeserializeObject <List <PrintLineModel> >(array[1]);
                        this.PrintNewList(lines);
                    }
                    else
                    {
                        //JObject obj = JObject.Parse(array[1]);
                        //this.PrintOrder(obj);
                    }
                }
                result = "true";
            }
            catch (Exception ex)
            {
                LogTools.Debug(ex.Message);
                result = ex.Message;
            }
            return(result);
        }
Пример #6
0
 public string setPrintOrder(string orderInfo)
 {
     try
     {
         LogTools.Info(orderInfo);
         if (p1 != null)
         {
             return(p1.setPrintOrder(orderInfo));
         }
         if (p2 != null)
         {
             return(p2.setPrintOrder(orderInfo));
         }
         if (p3 != null)
         {
             return(p3.setPrintOrder(orderInfo));
         }
     }
     catch (Exception ex)
     {
         LogTools.Debug(ex.ToString());
     }
     return("false");
 }
Пример #7
0
 public static void Debug(string msg)
 {
     LogTools.Debug(msg, null);
 }
Пример #8
0
        private string PrintNewList(List <PrintLineModel> lines)
        {
            if (lines == null || lines.Count == 0)
            {
                throw new Exception("[Pos 1000] 无打印数据!");
            }
            string appConfig = Utils.GetAppConfig("LptStr");

            this.lc = new LptControl(appConfig);
            if (!this.lc.Open())
            {
                throw new Exception("[Pos 1001] 设备驱动失败!");
            }
            try
            {
                LogTools.Info("开始打印");
                #region 循环打印
                for (int i = 0; i < lines.Count; i++)
                {
                    PrintLineModel m = lines[i];

                    ////LPT打印,不用手动隔行,因为它不会重叠


                    switch (m.type)
                    {
                    case 1:
                    //图片和条形码都视作图片打印
                    case 2:
                        this.lc.Write(new byte[]
                        {
                            27,
                            64
                        });
                        this.lc.Write(new byte[]
                        {
                            27,
                            33,
                            48
                        });
                        this.lc.Write(new byte[]
                        {
                            27,
                            97,
                            1
                        });
                        //打印图片或条形码
                        try
                        {
                            this.Print2Bitmap(m.content, "tmpBmp.bmp", m.splitLine);
                        }
                        catch (Exception ex)
                        {
                            string sErr = string.Format("[Pos 1003] 打印图片{0},下载地址:{2}。\r\n异常:{1}"
                                                        , "tmpBmp.bmp", ex.ToString(), m.content);
                            //throw new Exception();
                            LogTools.Debug(sErr);
                        }

                        LptControl arg_164_0 = this.lc;
                        byte[]     array     = new byte[3];
                        array[0] = 27;
                        array[1] = 33;
                        arg_164_0.Write(array);
                        LptControl arg_186_0 = this.lc;
                        byte[]     array2    = new byte[3];
                        array2[0] = 27;
                        array2[1] = 97;
                        arg_186_0.Write(array2);
                        //this.lc.Write(Environment.NewLine);
                        break;

                    case 3:
                        StringBuilder sb = new StringBuilder();
                        switch (m.fontSize)
                        {
                        case 1:
                            sb.Append(_1w1h);
                            break;

                        case 2:
                            sb.Append(_1w2h);
                            break;

                        case 3:
                            sb.Append(_2w2h);
                            break;

                        default:
                            break;
                        }
                        sb.Append(m.content + Environment.NewLine);
                        this.lc.Write(sb.ToString());
                        //LogTools.Info(string.Format("打印第{0}行,内容:{1}", i.ToString(), sb.ToString()));
                        for (int j = 0; j < m.splitLine - 2; i++)
                        {
                            this.lc.Write(" " + Environment.NewLine);
                        }
                        break;

                    default:
                        break;
                    }
                }
                #endregion
                #region 打印尾巴
                this.lc.Write(" " + Environment.NewLine);
                this.lc.Write(" " + Environment.NewLine);
                this.lc.Write(" " + Environment.NewLine);
                this.lc.Write(" " + Environment.NewLine);
                this.lc.Write(" " + Environment.NewLine);
                this.lc.Write(" " + Environment.NewLine);
                this.lc.Write(new byte[]
                {
                    27,
                    100,
                    3
                });
                this.lc.Write(new byte[]
                {
                    27,
                    109
                });
                LogTools.Info("打印完毕,切纸");
                #endregion
                return("");
            }
            catch (Exception ex4)
            {
                throw new Exception("[Pos 1005] 打印失败," + ex4.Message);
            }
            finally
            {
                this.lc.Close();
            }
        }
Пример #9
0
        private string PrintNewList(List <PrintLineModel> lines)
        {
            if (lines == null || lines.Count == 0)
            {
                throw new Exception("[Pos 1000] 无打印数据!");
            }
            StringBuilder stringBuilder = new StringBuilder("");
            string        device_name   = Utils.GetAppConfig("device_name");
            int           num           = this.posPrinter.Open(device_name);

            if (num != 0)
            {
                throw new Exception("[Pos 1001] 设备驱动失败!返回码:" + num.ToString());
            }
            try
            {
                LogTools.Info("开始打印");
                #region 初始化
                try
                {
                    this.posPrinter.ClaimDevice(1000);
                    this.posPrinter.DeviceEnabled    = true;
                    this.posPrinter.RecLineChars     = 32;
                    this.posPrinter.RecLetterQuality = true;
                    this.posPrinter.TransactionPrint(2, 11);
                }
                catch (Exception ex2)
                {
                    throw new Exception(string.Format("[Pos 1002] 打印初始化失败:{0}。", ex2.ToString()));
                }
                #endregion
                #region 循环打印
                for (int i = 0; i < lines.Count; i++)
                {
                    PrintLineModel m = lines[i];
#if DEBUG
                    if (m.type == 1)
                    {
                        m.type    = 2;
                        m.content = "1234567890123";
                    }
#endif
                    #region 手动换行(而且要先打换行),如果不这么做,打印图像或高倍字体会重叠
                    if (i == 0)
                    {
                        //第一行就不用前置打换行了。顶头即可。
                        m.splitLine = 1;
                    }
                    for (int j = 0; j < m.splitLine - 1; j++)
                    {
                        this.posPrinter.PrintNormal(2, " " + Environment.NewLine);
                    }
                    #endregion
                    switch (m.type)
                    {
                    case 1:
                        #region 打印图片
                        LogTools.Info("打印图片开始");
                        try
                        {
                            this.Print2Bitmap(m.content, "tmpBmp.bmp", m.splitLine);
                        }
                        catch (Exception ex)
                        {
                            string sErr = string.Format("[Pos 1003] 打印图片{0},下载地址:{2}。\r\n异常:{1}"
                                                        , "tmpBmp.bmp", ex.ToString(), m.content);
                            LogTools.Debug(sErr);
                        }
                        LogTools.Info("打印图片结束");
                        #endregion
                        break;

                    case 2:
                        #region 打印条码
                        LogTools.Info("打印条码开始");
                        string data      = m.content;
                        int    codeWidth = 2;
                        if (m.content.Length > 15)
                        {
                            codeWidth = 1;
                        }
                        num = this.posPrinter.PrintBarCode(2, data, 110, 60, codeWidth, -2, -13);
                        if (num != 0)
                        {
                            LogTools.Info("[Pos 1003] 打印条码失败! 返回码:" + num.ToString());
                            throw new Exception("[Pos 1003] 打印条码失败! 返回码:" + num.ToString());
                        }
                        LogTools.Info("打印条码完成");
                        #endregion
                        break;

                    case 3:
                        #region 打文字
                        if (m.fontSize < 2)
                        {
                            m.splitLine = 1;
                        }
                        else
                        {
                            m.splitLine = 2;
                        }
                        StringBuilder sb = new StringBuilder();
                        switch (m.fontSize)
                        {
                        case 1:
                            sb.Append(_1w1h);
                            break;

                        case 2:
                            sb.Append(_1w2h);
                            break;

                        case 3:
                            sb.Append(_2w2h);
                            break;

                        default:
                            break;
                        }
                        sb.Append(m.content);
                        sb.Append(Environment.NewLine);
                        //LogTools.Info(string.Format("打印第{0}行,内容:{1}", i.ToString(), sb.ToString()));
                        this.posPrinter.PrintNormal(2, sb.ToString());
                        #endregion
                        break;

                    default:
                        break;
                    }
                }
                #endregion
                #region 打印尾巴
                this.posPrinter.PrintNormal(2, " " + Environment.NewLine + " " + Environment.NewLine + " " + Environment.NewLine
                                            + " " + Environment.NewLine + " " + Environment.NewLine + " " + Environment.NewLine + " " + Environment.NewLine
                                            + " " + Environment.NewLine + " " + Environment.NewLine + " " + Environment.NewLine);
                this.posPrinter.CutPaper(100);
                LogTools.Info("打印完毕,切纸");
                #endregion
                return("");
            }
            catch (Exception ex4)
            {
                throw new Exception("[Pos 1005] 打印失败," + ex4.ToString());
            }
            finally
            {
                this.posPrinter.TransactionPrint(2, 12);
                this.posPrinter.RecLetterQuality = false;
                this.posPrinter.DeviceEnabled    = false;
                this.posPrinter.ReleaseDevice();
                this.posPrinter.Close();
            }
        }