Beispiel #1
0
        public static void SetConfig(string configPath, string logName)
        {
            LogTools.SaveLogFilePath(configPath + logName);
            FileInfo configFile = new FileInfo(LogTools.logXmlFilePath);

            XmlConfigurator.Configure(configFile);
        }
Beispiel #2
0
        public bool Print2Bitmap(PrintLineModel m)
        {
            string fileName = "tmpBmp.bmp";
            string text2    = Utils.Substitute(AppDomain.CurrentDomain.BaseDirectory, "\\") + fileName;

            try
            {
                FileTransferHttp.DownloadPicture(m.content, text2);
            }
            catch (Exception ex)
            {
                try
                {
                    FileTransferHttp.GetImageByHttp(m.content, text2);
                }
                catch (Exception ex2)
                {
                    LogTools.Debug(string.Format("[Pos 1003] 图片下载地址:{0}。下载异常两次:1:{1}。2:{2}。", m.content, ex.ToString(), ex2.ToString()));
                    return(false);
                }
            }
            try
            {
                Invoke1.PrintMiddleBitmapFile0(new StringBuilder(text2), 0);
            }
            catch (Exception ex2)
            {
                LogTools.Debug(string.Format("[Pos 1003] 打印图片tmpBmp.bmp异常:{0}", ex2.ToString()));
                return(false);
            }
            return(true);
        }
Beispiel #3
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) };
                List <PrintLineModel> lines = Newtonsoft.Json.JsonConvert.DeserializeObject <List <PrintLineModel> >(array[1]);
                this.PrintNewList(lines);
                result = "true";
            }
            catch (Exception ex)
            {
                LogTools.Debug(ex.Message);
                result = ex.Message;
            }
            return(result);
        }
Beispiel #4
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
         {
             this.PrintCode(bmp);
         }
         catch (Exception ex2)
         {
             throw ex2;
         }
         finally
         {
             bmp.Dispose();
         }
         for (int i = 0; i < lineNum - 1; i++)
         {
             this.lc.Write(" " + Environment.NewLine);
         }
         return(string.Empty);
     }
     catch (Exception ex)
     {
         LogTools.Info("打印图片异常:" + ex.ToString());
         throw ex;
     }
 }
Beispiel #5
0
 public static string GetImageByHttp(string WebReqUrl, string FileName)
 {
     try
     {
         HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(WebReqUrl);
         httpWebRequest.SendChunked = true;
         httpWebRequest.Method      = "get";
         httpWebRequest.Proxy       = null;
         httpWebRequest.ContentType = "text/xml; charset=utf-8";
         httpWebRequest.Accept      = "*/*";
         httpWebRequest.Headers.Add("Accept-Encoding", "gzip, deflate");
         httpWebRequest.Headers.Add("Accept-Language", "zh-cn");
         httpWebRequest.Headers.Add("Accept-CharSet", "utf-8");
         httpWebRequest.UserAgent = "Mozilla/3.0 (compatible; Indy Library)";
         httpWebRequest.Timeout   = 20000;
         HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
         if (httpWebResponse != null && httpWebResponse.StatusCode == HttpStatusCode.OK)
         {
             using (Stream responseStream = httpWebResponse.GetResponseStream())
             {
                 if (File.Exists(FileName))
                 {
                     File.Delete(FileName);
                 }
                 FileStream fileStream = new FileStream(FileName, FileMode.CreateNew, FileAccess.ReadWrite);
                 try
                 {
                     while (true)
                     {
                         int num = responseStream.ReadByte();
                         if (num == -1)
                         {
                             break;
                         }
                         fileStream.WriteByte((byte)num);
                     }
                     LogTools.Info(string.Format("下载图片完毕:{0}。", FileName));
                 }
                 finally
                 {
                     fileStream.Close();
                 }
             }
         }
         httpWebResponse.Close();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(FileName);
 }
Beispiel #6
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);
        }
Beispiel #7
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文件");
            }
        }
Beispiel #8
0
        private static bool SaveBinaryFile(WebResponse response, string savePath)
        {
            bool value = false;

            byte[] buffer    = new byte[1024];
            Stream outStream = null;
            Stream inStream  = null;

            try
            {
                if (File.Exists(savePath))
                {
                    File.Delete(savePath);
                }
                outStream = System.IO.File.Create(savePath);
                inStream  = response.GetResponseStream();
                int l;
                do
                {
                    l = inStream.Read(buffer, 0, buffer.Length);
                    if (l > 0)
                    {
                        outStream.Write(buffer, 0, l);
                    }
                } while (l > 0);
                value = true;
                LogTools.Info(string.Format("下载图片完毕:{0}。", savePath));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (outStream != null)
                {
                    outStream.Close();
                }
                if (inStream != null)
                {
                    inStream.Close();
                }
            }
            return(value);
        }
Beispiel #9
0
        private string PrintNewList(List <PrintLineModel> lines)
        {
            //Invoke1.PrintText0(new StringBuilder("1234567890一二三四五六七八九十abdefghijk一二三四五"), 32);
            if (lines == null || lines.Count == 0)
            {
                throw new Exception("[Pos 1000] 无打印数据!");
            }
            try
            {
                LogTools.Info("开始打印");
                for (int i = 0; i < lines.Count; i++)
                {
                    PrintLineModel m = lines[i];
                    switch (m.type)
                    {
                    case 1:
                        //图片
                        Print2Bitmap(m);
                        break;

                    case 2:
                        //有安不支持条形码打印
                        break;

                    case 3:
                        Invoke1.PrintText0(new StringBuilder(m.content + Environment.NewLine), 32);    //如果,有config_uan.txt文件。传几都不会有影响。
                        break;

                    default:
                        break;
                    }
                }
                Invoke1.BeginPrint0(8);
                LogTools.Info("打印完毕,切纸");
                return("");
            }
            catch (Exception ex4)
            {
                throw new Exception("[Pos 1005] 打印失败," + ex4.Message);
            }
            finally
            {
            }
        }
Beispiel #10
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);
 }
Beispiel #11
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);
        }
Beispiel #12
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);
        }
Beispiel #13
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");
 }
Beispiel #14
0
 public string posNum()
 {
     LogTools.Info(string.Format("调OpenCashBox_QS.posNum。返回:{0}。", PosNumInit));
     return(PosNumInit);
 }
Beispiel #15
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();
            }
        }
Beispiel #16
0
 public static void Debug(string msg)
 {
     LogTools.Debug(msg, null);
 }
Beispiel #17
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();
            }
        }
Beispiel #18
0
        public MainForm()
        {
            InitializeComponent();
            //this.FormBorderStyle = FormBorderStyle.FixedToolWindow; //FixedToolWindow;// 或SizableToolWindow
            try
            {
                string pageUrl = Utils.GetAppConfig("url");
                if (pageUrl.Trim().Length < 1)
                {
                    pageUrl = "http://order.ampm365.cn/";
                }
                if (typeof(ChromiumWebBrowser).Name == "ChromiumWebBrowser")
                {
                    webCom      = new ChromiumWebBrowser(pageUrl);
                    webCom.Dock = DockStyle.Fill;
                    this.Controls.Add(webCom);
                    //加载页面
                    webCom.Load(pageUrl);
                }
                else
                {
                    //Settings settings = new Settings();
                    //CEF.Initialize(settings);
                    //BrowserSettings settings2 = new BrowserSettings();
                    ////初始化webview
                    //webCom = new WebView(pageUrl, settings2);
                    //webCom.Dock = DockStyle.Fill;
                    ////加入到父控件
                    //webCom.Parent = this;
                }

                try
                {
                    LogTools.SetConfig(Environment.CurrentDirectory + "\\", "PosPrint.log");
                    LogTools.Info("日志初始化成功...");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("日志初始化失败:" + ex.Message);
                }
                //注册打印服务
                regSvr();
                OpenCashBox_QS ocb = new OpenCashBox_QS();
                if (ocb.IsNec == 2)
                {
                    bool isExists = Utils.IsExistsProcess(Utils.GetAppConfig("uanPosExeFullPath"));
                    if (!isExists)
                    {
                        MessageBox.Show("请先启动Pos主程序,然后再启动接单平台!如果已启动Pos主程序,那么请查看config文件,是否配置正确");
                        this.Dispose(true);
                    }
                }
                Print print = new Print(ocb.IsNec);
                webCom.RegisterJsObject("Print", print);
                webCom.RegisterJsObject("OpenCashBox_QS", ocb);

                //webCom.RegisterJsObject("CallNotifyIcon", new CallNotifyIcon(this));

                //try
                //{
                //    print.CreateEANCode("1234567890123");
                //}
                //catch (Exception ex)
                //{
                //    LogTools.Info("测试生成条形码异常:" + ex.ToString());
                //}

                //#region test
                //string sssss = Utils.GetAppConfig("bmpUrl");
                ////string sssss = "http://bto.oh.quanshishequ.com/order/print/receiptPrint?orderId=54232356057";
                //print.print2Bitmap(sssss);
                //#endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #19
0
        public OpenCashBox_QS()
        {
            string strIsNec = string.Empty;

            try
            {
                strIsNec = Utils.GetAppConfig("isNec");
            }
            catch
            {
            }
            if (strIsNec == "2")
            {
                IsNec = 2;
                //有安称
                LogTools.Info("最终判断此pos机品牌为有安称,如判断错误会影响后续打印功能。");
            }
            else
            {
                try
                {
                    string posType = string.Empty;
                    int    rst     = OpenCashBox.OpenCashBox.posType(out posType);
                    LogTools.Info(string.Format("调OpenCashBox.posType的结果:返回值:{0},posType:{1}。", rst.ToString(), posType));
                    if (posType.ToUpper() == "NEC")
                    {
                        cashDrawer1 = new OPOSCashDrawerClass();
                        IsNec       = 1;
                    }
                    else
                    {
                        if (strIsNec == "1")
                        {
                            cashDrawer1 = new OPOSCashDrawerClass();
                            IsNec       = 1;
                        }
                    }
                    if (IsNec == 1)
                    {
                        LogTools.Info("最终判断此pos机品牌为NEC,如判断错误会影响后续打印功能。");
                    }
                    else
                    {
                        LogTools.Info("最终判断此pos机品牌不是NEC。如判断错误,会影响后续打印功能,请检查配置文件是否正确");
                    }
                    OpenCashBox.OpenCashBox.posNo(out PosNumInit);
                    LogTools.Info(string.Format("初始化调OpenCashBox.posNo。出参:{0}。", PosNumInit));
                }
                catch (Exception ex)
                {
                    LogTools.Info("最终判断此pos机品牌不是NEC。如判断错误,会影响后续打印功能,请检查配置文件是否正确。弹钱箱初始化异常:" + ex.ToString());
                }
            }
            try
            {
                cashBox_name = Utils.GetAppConfig("cashBox_name");
                if (string.IsNullOrEmpty(cashBox_name))
                {
                    cashBox_name = "NEC.CDW.1";
                }
            }
            catch
            {
                cashBox_name = "NEC.CDW.1";
            }
        }