Browse Source

打印插件与供应商打印CS程序优化

Hcsy 6 years ago
parent
commit
ef0e68aeeb
3 changed files with 36 additions and 7 deletions
  1. 10 1
      UAS_PRINT/Form2.cs
  2. 20 1
      UAS_PRINT/Program.cs
  3. 6 5
      UAS_Web/Browser.cs

+ 10 - 1
UAS_PRINT/Form2.cs

@@ -1,4 +1,5 @@
-using Newtonsoft.Json.Linq;
+using Microsoft.Win32;
+using Newtonsoft.Json.Linq;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -25,6 +26,14 @@ namespace UAS_PRINT
         private Thread ThrednHttpPostRequest;
         private void Form2_Load(object sender, EventArgs e)
         {
+
+            string path = Application.ExecutablePath;
+            RegistryKey rk = Registry.LocalMachine;
+            RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
+            rk2.SetValue("UAS_PRINT.exe", path);
+            rk2.Close();
+            rk.Close();
+
             httpPostRequest.Prefixes.Add("http://localhost:9100/");
             httpPostRequest.Start();
 

+ 20 - 1
UAS_PRINT/Program.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Security.Principal;
 using System.Windows.Forms;
 
 namespace UAS_PRINT
@@ -13,9 +14,27 @@ namespace UAS_PRINT
         [STAThread]
         static void Main()
         {
+            WindowsIdentity identity = WindowsIdentity.GetCurrent();
+            WindowsPrincipal principal = new WindowsPrincipal(identity);
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
-            Application.Run(new Form2());
+            //如果是管理员的身份
+            if (principal.IsInRole(WindowsBuiltInRole.Administrator))
+            {
+                Application.Run(new Form2());
+            }
+            else
+            {
+                //创建启动对象 
+                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
+                // 设置运行文件
+                startInfo.FileName = Application.ExecutablePath;
+                //设置启动动作,确保以管理员身份运行
+                startInfo.Verb = "runas";
+                //如果不是管理员,则启动UAC 
+                System.Diagnostics.Process.Start(startInfo);
+                //退出 System.Windows.Forms.Application.Exit(); 
+            }
         }
     }
 }

+ 6 - 5
UAS_Web/Browser.cs

@@ -9,6 +9,7 @@ using System.Collections.Generic;
 using System.Net;
 using System.Text;
 using System.IO;
+using System.Web;
 
 namespace UAS_Web
 {
@@ -47,7 +48,7 @@ namespace UAS_Web
         {
             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));
+                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_fun") + "';document.getElementById('master1').value = '"+ BaseUtil.GetCacheData("master_name") + "';", new TimeSpan(600000));
             }
                 var cookiemanager = CefSharp.Cef.GetGlobalCookieManager();
                 CookieVisitor visitor = new CookieVisitor();
@@ -60,13 +61,13 @@ namespace UAS_Web
             if (obj.Path.Contains("jsps/vendbarcode"))
             {
                 if (obj.Name == "username")
-                    BaseUtil.SetCacheData("username", obj.Value);
+                    BaseUtil.SetCacheData("username", HttpUtility.UrlDecode(obj.Value));
                 if (obj.Name == "password")
-                    BaseUtil.SetCacheData("password", obj.Value);
+                    BaseUtil.SetCacheData("password", HttpUtility.UrlDecode(obj.Value));
                 if (obj.Name == "master_name")
-                    BaseUtil.SetCacheData("master_name", obj.Value);
+                    BaseUtil.SetCacheData("master_name", HttpUtility.UrlDecode(obj.Value));
                 if (obj.Name == "master_fun")
-                    BaseUtil.SetCacheData("master_fun", obj.Value);
+                    BaseUtil.SetCacheData("master_fun", HttpUtility.UrlDecode(obj.Value));
             }
         }