Browse Source

添加反射执行代码的方法,进行界面设定

章政 5 years ago
parent
commit
0ec98ed44c

+ 15 - 40
UAS-出货标签管理(贸易版)/PublicMethod/BaseUtil.cs

@@ -890,8 +890,10 @@ namespace UAS_LabelMachine
             return "select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno = '" + pi_inoutno + "' and pib_outboxcode2 = " + (pib_outboxcode2 == "" ? "0" : pib_outboxcode2) + GroupByCondition;
         }
 
-        public static void CustomerInit()
+        public static void CustomerInit(string oContent)
         {
+            if (oContent == ""|| oContent=="null"|| oContent==" ")
+                return;
             //创建编译环境实例
             CSharpCodeProvider objCSharpCodePrivoder = new CSharpCodeProvider();
             //UAS_LabelMachine
@@ -902,11 +904,9 @@ namespace UAS_LabelMachine
             objCompilerParameters.GenerateInMemory = true;
 
             // 4.CompilerResults
-            CompilerResults cr = objCSharpCodePrivoder.CompileAssemblyFromSource(objCompilerParameters, GenerateCode());
-
+            CompilerResults cr = objCSharpCodePrivoder.CompileAssemblyFromSource(objCompilerParameters, oContent);
             if (cr.Errors.HasErrors)
             {
-                Console.WriteLine("编译错误:");
                 foreach (CompilerError err in cr.Errors)
                 {
                     Console.WriteLine(err.ErrorText);
@@ -916,43 +916,18 @@ namespace UAS_LabelMachine
             {
                 // 通过反射,调用HelloWorld的实例
                 Assembly objAssembly = cr.CompiledAssembly;
-                object objHelloWorld = objAssembly.CreateInstance("Test.TestClass");
-                MethodInfo objMI = objHelloWorld.GetType().GetMethod("Test");
-                Console.WriteLine(objMI.Invoke(objHelloWorld, null));
+                object objHelloWorld = objAssembly.CreateInstance("CustInitSpace.CustInitClass", true);
+                MethodInfo objMI = objHelloWorld.GetType().GetMethod("CustInit");
+                try
+                {
+                    objMI.Invoke(objHelloWorld, null);
+                }
+                catch (Exception ex)
+                {
+                    Console.WriteLine(ex.StackTrace);
+                    Console.WriteLine(ex.Message);
+                }
             }
         }
-
-        static string GenerateCode()
-        {
-            StringBuilder sb = new StringBuilder();
-            sb.Append(Environment.NewLine);
-            sb.Append("using System; ");
-            sb.Append(Environment.NewLine);
-            sb.Append("using System.Windows.Forms; ");
-            sb.Append(Environment.NewLine);
-            sb.Append("namespace Test ");
-            sb.Append(Environment.NewLine);
-            sb.Append("{ ");
-            sb.Append("   public class TestClass");
-            sb.Append(Environment.NewLine);
-            sb.Append("  {");
-            sb.Append(Environment.NewLine);
-            sb.Append("      public void Test()  ");
-            sb.Append(Environment.NewLine);
-            sb.Append("     {");
-            sb.Append(Environment.NewLine);
-            sb.Append("          Form f=Form.ActiveForm; if(f.Controls[\"cu_code\"].Text==\"C000027\"){");
-            sb.Append(Environment.NewLine);
-            sb.Append("          (f.Controls[\"OutBoxLabel\"].Controls[\"DiffCustOutBoxCode\"] as CheckBox).Checked = false;}else {(f.Controls[\"OutBoxLabel\"].Controls[\"DiffCustOutBoxCode\"] as CheckBox).Checked = true;}");
-            sb.Append(Environment.NewLine);
-            sb.Append("     }");
-            sb.Append(Environment.NewLine);
-            sb.Append("  }");
-            sb.Append(Environment.NewLine);
-            sb.Append("}");
-            string code = sb.ToString();
-            Console.WriteLine(code);
-            return sb.ToString();
-        }
     }
 }

+ 20 - 0
UAS-出货标签管理(贸易版)/PublicMethod/LogicHandler.cs

@@ -75,6 +75,26 @@ namespace UAS_LabelMachine.PublicMethod
             oSQL = param[1];
         }
 
+        /// <summary>
+        /// 自定义界面代码
+        /// </summary>
+        /// <param name="iPiId"></param>
+        public static void CustInit(string iPiId)
+        {
+            string oContent = "";
+            try
+            {
+                string[] param = new string[] { iPiId, oContent };
+                dh.CallProcedure("SP_CUSTINIT", ref param);
+                oContent = param[1];
+            }
+            catch (Exception)
+            {
+                
+            }
+            BaseUtil.CustomerInit(oContent);
+        }
+
         /// <summary>
         /// 获取生成条码的SQL,目前添加用户海创和凯而高,凯而高有特殊定制逻辑
         /// </summary>

+ 33 - 1
UAS-出货标签管理(贸易版)/SQL/SQL.txt

@@ -284,4 +284,36 @@ AS
    EXCEPTION
       WHEN OTHERS THEN
       V_ERRORMSG :=SQLERRM || dbms_utility.format_error_backtrace();
-   END;
+   END;
+
+/*自定义代码,根据不同客户进行页面设置*/
+create or replace PROCEDURE sp_custinit(
+  KeyValue in varchar2,
+  content out varchar2
+)as
+begin
+declare 
+  v_custcode varchar2(20);
+  begin
+    select pi_cardcode into v_custcode from prodinout where pi_id=KeyValue;
+      content:='
+using System; 
+ using System.Windows.Forms; 
+namespace CustInitSpace 
+{    public class CustInitClass
+    {
+        public void CustInit()  
+        {
+          Form f=Form.ActiveForm; 
+          if(f.Controls["cu_code"].Text=="C000027")
+          {
+             (f.Controls["OutBoxLabel"].Controls["DiffCustOutBoxCode"] as CheckBox).Checked = false;
+          }else
+          {
+            (f.Controls["OutBoxLabel"].Controls["DiffCustOutBoxCode"] as CheckBox).Checked = true;
+          }
+        }
+    }
+}';
+  end;
+end;

+ 1 - 1
UAS-出货标签管理(贸易版)/UAS_出货标签管理.cs

@@ -1223,7 +1223,7 @@ namespace UAS_LabelMachine
                     stw = new SetLoadingWindow(thread, "正在获取打印标签");
                     BaseUtil.SetFormCenter(stw);
                     stw.ShowDialog();
-                    //BaseUtil.CustomerInit();
+                    LogicHandler.CustInit(PI_ID);
                     //重置采集项次
                     LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
                 }