Переглянути джерело

打印插件以及供应商条码打印CS程序修改

Hcsy 7 роки тому
батько
коміт
49bbc48cbf

+ 1 - 1
UAS_PRINT/Form2.cs

@@ -66,7 +66,7 @@ namespace UAS_PRINT
                         Stream stream = requestContext.Request.InputStream;
                         var memoryStream = new MemoryStream();
                         //将基础流写入内存流
-                        const int bufferLength = 10 * 1024 * 1024;
+                        const int bufferLength = 2 * 1024 * 1024;
                         byte[] buffera = new byte[bufferLength];
                         int actual = stream.Read(buffera, 0, bufferLength);
                         if (actual > 0)

+ 0 - 2
UAS_PRINT/PrintHandler.cs

@@ -58,7 +58,6 @@ namespace UAS_PRINT
                 {
                     return;
                 }
-                Console.WriteLine(PrintCode);
                 PrintHelper.SendStringToPrinter(PrinterName, PrintCode);
                 PrintDocument pd = new PrintDocument();
                 pd.PrinterSettings.PrinterName = PrinterName;
@@ -205,7 +204,6 @@ namespace UAS_PRINT
                             if (itemstr.Contains("\\\""))
                             {
                                 itemstr = itemstr.Replace("\\\"", "\"");
-                                Console.WriteLine(itemstr);
                             }
                         }
                         dr[itemc.Key] = itemstr;

+ 41 - 2
UAS_Web/Browser.cs

@@ -6,6 +6,9 @@ using CefSharp;
 using CefSharp.WinForms;
 using System.Text.RegularExpressions;
 using System.Collections.Generic;
+using System.Net;
+using System.Text;
+using System.IO;
 
 namespace UAS_Web
 {
@@ -13,12 +16,14 @@ namespace UAS_Web
     {
 
         private ChromiumWebBrowser webBrowser;
+ 
 
-        public Browser()
+           public Browser()
         {
             InitializeComponent();
             Text = "供应商条码打印";
-            string path = "http://192.168.253.80:8090/ERP/jsps/vendbarcode/login.jsp";
+ 
+            string path = "http://192.168.253.6/uas_dev/jsps/vendbarcode/login.jsp";
             webBrowser = new ChromiumWebBrowser(path)
             {
                 Dock = DockStyle.Fill
@@ -29,6 +34,40 @@ namespace UAS_Web
             webBrowser.DownloadHandler = new DownLoadFile();
             Controls.Add(webBrowser);
             webBrowser.LoadError += WebBrowser_LoadError;
+            webBrowser.FrameLoadEnd += FrameLoadEnd;
+            webBrowser.FrameLoadStart += WebBrowser_FrameLoadStart;
+        }
+
+        private void WebBrowser_FrameLoadStart(object sender, FrameLoadStartEventArgs e)
+        {
+          
+        }
+
+        void FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
+        {
+            if (e.Url.Contains("vendbarcode/login.jsp") || e.Url.Contains("relogin.action"))
+            {
+                e.Browser.FocusedFrame.EvaluateScriptAsync("document.getElementById('username').value = '"+BaseUtil.GetCacheData("username") +"';document.getElementById('password').value = '"+ BaseUtil.GetCacheData("password") + "';document.getElementById('master').innerHTML = '"+ BaseUtil.GetCacheData("master") + "';document.getElementById('master1').value = '"+ BaseUtil.GetCacheData("master1") + "';", new TimeSpan(600000));
+            }
+                var cookiemanager = CefSharp.Cef.GetGlobalCookieManager();
+                CookieVisitor visitor = new CookieVisitor();
+                visitor.SendCookie += visitor_SendCookie;
+                cookiemanager.VisitAllCookies(visitor);
+        }
+        
+        private void visitor_SendCookie(CefSharp.Cookie obj)
+        {
+            if (obj.Path.Contains("jsps/vendbarcode"))
+            {
+                if (obj.Name == "username")
+                    BaseUtil.SetCacheData("username", obj.Value);
+                if (obj.Name == "password")
+                    BaseUtil.SetCacheData("password", obj.Value);
+                if (obj.Name == "master_name")
+                    BaseUtil.SetCacheData("master_name", obj.Value);
+                if (obj.Name == "master_fun")
+                    BaseUtil.SetCacheData("master_fun", obj.Value);
+            }
         }
 
         private void WebBrowser_LoadError(object sender, LoadErrorEventArgs e)

+ 16 - 0
UAS_Web/Program.cs

@@ -1,8 +1,10 @@
 using CefSharp;
 using System;
+using System.IO;
 using System.Security.Principal;
 using System.Text;
 using System.Windows.Forms;
+using System.Xml;
 
 namespace UAS_Web
 {
@@ -30,6 +32,20 @@ namespace UAS_Web
                 Cef.Initialize(setting);
                 Application.EnableVisualStyles();
                 Application.SetCompatibleTextRenderingDefault(false);
+                FileStream fcaches = new FileStream(System.AppDomain.CurrentDomain.BaseDirectory + "cache.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite);
+                fcaches.Close();
+                FileInfo info = new FileInfo(System.AppDomain.CurrentDomain.BaseDirectory + "cache.xml");
+                if (info.Length == 0)
+                {
+                    XmlDocument doc = new XmlDocument();
+                    //创建类型声明节点  
+                    XmlNode node = doc.CreateXmlDeclaration("1.0", "utf-8", "");
+                    doc.AppendChild(node);
+                    //创建根节点  
+                    XmlElement xeRoot = doc.CreateElement("cacheInfo");
+                    doc.AppendChild(xeRoot);
+                    doc.Save(System.AppDomain.CurrentDomain.BaseDirectory + "cache.xml");
+                }
                 //如果是管理员的身份
                 if (principal.IsInRole(WindowsBuiltInRole.Administrator))
                 {

+ 2 - 0
UAS_Web/UAS_Web.csproj

@@ -120,7 +120,9 @@
     </Compile>
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="tool\BaseUtil.cs" />
     <Compile Include="tool\Code128.cs" />
+    <Compile Include="tool\CookieVisitor .cs" />
     <Compile Include="tool\CustomCommand.cs" />
     <Compile Include="tool\DownLoadFile.cs" />
     <Compile Include="tool\FilterManager.cs" />

+ 113 - 0
UAS_Web/tool/BaseUtil.cs

@@ -0,0 +1,113 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Xml;
+
+namespace UAS_Web.tool
+{
+    class BaseUtil
+    {
+
+        public static Object GetCacheData(string ParamName)
+        {
+            try
+            {
+                Object o = null;
+                //根据地址读取xml文件
+                XmlDocument doc = new XmlDocument();
+                XmlReaderSettings settings = new XmlReaderSettings { CheckCharacters = false };
+                //忽略文档里面的注释
+                settings.IgnoreComments = true;
+                XmlReader reader = XmlReader.Create(System.AppDomain.CurrentDomain.BaseDirectory + "cache.xml", settings);
+                doc.Load(reader);
+                //先得到根节点
+                XmlNode rootNode = doc.SelectSingleNode("cacheInfo");
+                //再由根节点去找制定的节点
+                XmlNodeList nodeList = rootNode.ChildNodes;
+                foreach (XmlNode node in nodeList)
+                {
+                    //找到了这个节点名字
+                    if (node.Name == ParamName)
+                    {
+                        //返回节点的内容
+                        switch (((XmlElement)node).GetAttribute("Type"))
+                        {
+                            case "System.String":
+                                o = node.InnerText;
+                                break;
+                            case "System.Int32":
+                                o = int.Parse(node.InnerText);
+                                break;
+                            case "System.Boolean":
+                                o = node.InnerText == "True" ? true : false;
+                                break;
+                            default:
+                                break;
+                        }
+                        break;
+                    }
+                }
+                //关闭reader
+                reader.Close();
+                if (o == null)
+                    return "";
+                else
+                    return o;
+            }
+            catch (Exception e)
+            {
+        
+                return "";
+            }
+        }
+
+        public static void SetCacheData(string ParamName, object Value)
+        {
+            try
+            {
+                //根据地址读取xml文件
+                XmlDocument doc = new XmlDocument();
+                XmlReaderSettings settings = new XmlReaderSettings { CheckCharacters = false };
+                //忽略文档里面的注释
+                settings.IgnoreComments = true;
+                XmlReader reader = XmlReader.Create(System.AppDomain.CurrentDomain.BaseDirectory + "cache.xml", settings);
+                doc.Load(reader);
+                //先得到根节点
+                XmlNode rootNode = doc.SelectSingleNode("cacheInfo");
+                //再由根节点去找制定的节点
+                XmlNodeList nodeList = rootNode.ChildNodes;
+                bool flag = false;
+                foreach (XmlNode node in nodeList)
+                {
+                    //找到了这个节点名字
+                    if (node.Name == ParamName)
+                    {
+                        //就直接赋值
+                        node.InnerText = Value.ToString();
+                        flag = true;
+                    }
+                }
+                //如果没有该节点,就创建节点保存结果
+                if (!flag)
+                {
+                    //创建节点
+                    XmlElement newNode = doc.CreateElement(ParamName);
+                    XmlAttribute attr = doc.CreateAttribute("Type");
+                    attr.InnerText = Value.GetType().ToString();
+                    newNode.InnerText = Value.ToString();
+                    newNode.SetAttributeNode(attr);
+                    //讲新建的节点挂到根节点上
+                    rootNode.AppendChild(newNode);
+                }
+                //关闭Reader
+                reader.Close();
+                doc.Save(System.AppDomain.CurrentDomain.BaseDirectory + "cache.xml");
+            }
+            catch (Exception e)
+            {
+              
+            }
+        }
+    }
+}

+ 28 - 0
UAS_Web/tool/CookieVisitor .cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using CefSharp;
+
+namespace UAS_Web.tool
+{
+    public class CookieVisitor : CefSharp.ICookieVisitor
+    {
+        public event Action<CefSharp.Cookie> SendCookie;
+
+        public void Dispose()
+        {
+            //throw new NotImplementedException();
+        }
+
+        public bool Visit(CefSharp.Cookie cookie, int count, int total, ref bool deleteCookie)
+        {
+            deleteCookie = false;
+            SendCookie?.Invoke(cookie);
+
+            return true;
+
+        }
+
+    }
+}

+ 1 - 1
UAS_Web/tool/MenuHandler.cs

@@ -9,7 +9,7 @@ namespace UAS_Web.tool
             model.Clear();
             model.AddItem(CefMenuCommand.Copy, "复制");
             model.AddItem(CefMenuCommand.Paste, "粘贴");
-            model.AddItem(CefMenuCommand.Reload, "重新加载");
+            model.AddItem(CefMenuCommand.ReloadNoCache, "重新加载");
         }
 
         public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)

+ 13 - 20
UAS_Web/tool/RequestHandler.cs

@@ -23,11 +23,7 @@ namespace UAS_Web.tool
 
         //打印图片集合
         List<Bitmap> bitmaps = new List<Bitmap>();
-
-     
-
         Report BarcodeReport  = new Report();
-        Report BoxReport = new Report();
 
         //图片打印中间变量
         int imagecount = 0;
@@ -160,6 +156,8 @@ namespace UAS_Web.tool
                     {
                         filter = FilterManager.GetFileter(request.Identifier.ToString()) as MessageFilter;
                         str = System.Text.Encoding.UTF8.GetString(filter.dataAll.ToArray());
+                        if (str.Contains("不允许打印"))
+                            return;
                         data = ToDictionary(str);
                         vendorZplPrint(data);                   
                     }
@@ -189,7 +187,7 @@ namespace UAS_Web.tool
                 barcode = (List<Dictionary<string, object>>)((Dictionary<string, object>)data)["barcode"];
             }
             catch {
-                MessageBox.Show("打印数据解析异常,请联系管理员进行处理");
+                MessageBox.Show("打印数据异常,请联系管理员");
                 return;
             }
             try
@@ -219,16 +217,10 @@ namespace UAS_Web.tool
                     i++;
                 }
                 if (DownLoadFile.downloading)
-                    Console.WriteLine("标签更新有误");
+                    MessageBox.Show("标签更新有误");
                 try
                 {
-                    if (type == "box")
-                    {
-                        BoxReport.Load(System.AppDomain.CurrentDomain.BaseDirectory + LABELNAME + ".frx");
-                    }
-                    else {
-                        BarcodeReport.Load(System.AppDomain.CurrentDomain.BaseDirectory + LABELNAME + ".frx");
-                    }
+                  BarcodeReport.Load(System.AppDomain.CurrentDomain.BaseDirectory + LABELNAME + ".frx");   
                 }
                 catch
                 {
@@ -387,11 +379,11 @@ namespace UAS_Web.tool
                     {
                         if (type == "box")
                         {
-                            BoxReport.RegisterData(dt, "VENDORBARCODE_BOX_VIEW");
-                            BoxReport.GetDataSource("VENDORBARCODE_BOX_VIEW").Enabled = true;
-                            BoxReport.PrintSettings.ShowDialog = false;
-                            BoxReport.PrintSettings.Printer = PrinterName;
-                            BoxReport.Print();
+                            BarcodeReport.RegisterData(dt, "VENDORBARCODE_BOX_VIEW");
+                            BarcodeReport.GetDataSource("VENDORBARCODE_BOX_VIEW").Enabled = true;
+                            BarcodeReport.PrintSettings.ShowDialog = false;
+                            BarcodeReport.PrintSettings.Printer = PrinterName;
+                            BarcodeReport.Print();
                         }
                         else
                         {
@@ -402,13 +394,14 @@ namespace UAS_Web.tool
                             BarcodeReport.Print();
                         }
                     }
-                    else {
+                    else
+                    {
                         BarcodeReport.RegisterData(dt, labelview);
                         BarcodeReport.GetDataSource(labelview).Enabled = true;
                         BarcodeReport.PrintSettings.ShowDialog = false;
                         BarcodeReport.PrintSettings.Printer = PrinterName;
                         BarcodeReport.Print();
-                    }    
+                    }
                 }
                 catch(Exception ex)
                 {