Browse Source

add sajet2 , not tested yet

Robert 3 years ago
parent
commit
c927cfd519

+ 1 - 1
AwInitilizer/App.xaml.cs

@@ -55,7 +55,7 @@ namespace AwInitilizer
         {
             base.OnExit(e);
 
-            if (SajetConnect.Type != MesType.none)
+            if (SajetConnect.Instance != null)
             {
                 var stopResult = SajetConnect.SajetTransClose();
             }

+ 1 - 0
AwInitilizer/Model/AppSettingConfig.cs

@@ -11,5 +11,6 @@ namespace AwInitilizer.Model
         public string FirmwareRoot { get; set; }
         public string Language { get; set; }
         public string MES { get; set; }
+        public string MechineCode { get; set; }
     }
 }

+ 1 - 1
AwInitilizer/Properties/AssemblyInfo.cs

@@ -53,4 +53,4 @@ using System.Windows;
 // [assembly: AssemblyVersion("1.5.0.0")]
 [assembly: AssemblyVersion("1.5.0.0")]
 [assembly: AssemblyFileVersion("1.5.0.0")]
-[assembly: AssemblyInformationalVersion("a0384e2")]
+[assembly: AssemblyInformationalVersion("652a2f3")]

+ 1 - 1
AwInitilizer/Properties/Settings.Designer.cs

@@ -12,7 +12,7 @@ namespace AwInitilizer.Properties {
     
     
     [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
-    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")]
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
     internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
         
         private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

+ 14 - 1
AwInitilizer/SettingConfig.cs

@@ -45,9 +45,21 @@ namespace AwInitilizer
             }
         }
 
+        public static string MechineCode
+        {
+            get
+            {
+                if (Instance == null)
+                {
+                    Instance = new AppSettingConfig();
+                }
+                return Instance._MechineCode;
+            }
+        }
+
         private static AppSettingConfig Instance;
 
-        private string _FirmwareRoot, _Language, _MES;
+        private string _FirmwareRoot, _Language, _MES , _MechineCode;
 
         private static string settingFileName = "config.ini";
 
@@ -74,6 +86,7 @@ namespace AwInitilizer
                 _FirmwareRoot = config.FirmwareRoot;
                 _Language = config.Language;
                 _MES = config.MES;
+                _MechineCode = config.MechineCode;
             }
             catch
             {

+ 7 - 3
AwInitilizer/SigninDialog.xaml.cs

@@ -42,7 +42,7 @@ namespace AwInitilizer
             if (CheckIsMesDisableAccount())
             {
                 //SajetConnect.IsEmsEnabled = false;
-                SajetConnect.Type = MesType.test;
+                SajetConnect.Instance = new SajectConnectTest();
                 DialogResult = true;
                 this.Close();
                 return;
@@ -114,11 +114,15 @@ namespace AwInitilizer
 
             if (mesSetting == "php" || mesSetting == "shinewave")
             {
-                SajetConnect.Type = MesType.shinewave;
+                SajetConnect.Instance = new SajetConnectShinewave();
             }
             else if (mesSetting == "phv" || mesSetting == "sajet")
             {
-                SajetConnect.Type = MesType.sajet;
+                SajetConnect.Instance = new SajectConnectSajet();
+            }
+            else if (mesSetting == "phv" || mesSetting == "sajet")
+            {
+                SajetConnect.Instance = new SajectConnectSajet2(AppSettingConfig.MechineCode);
             }
         }
     }

+ 1 - 1
Initilizer/AssemblyInfo.cs

@@ -11,5 +11,5 @@
 
 [assembly: AssemblyVersion("1.5.0.0")]
 [assembly: AssemblyFileVersion("1.5.0.0")]
-[assembly: AssemblyInformationalVersion("a0384e2")]
+[assembly: AssemblyInformationalVersion("652a2f3")]
 

+ 1 - 0
MesAdaptor/MesAdaptor.csproj

@@ -44,6 +44,7 @@
     <Compile Include="ISajetConnect.cs" />
     <Compile Include="MesErrorCode.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="SajectConnectSajet2.cs" />
     <Compile Include="SajectConnectSajet.cs" />
     <Compile Include="SajectConnectTest.cs" />
     <Compile Include="SajetConnect.cs" />

+ 1 - 1
MesAdaptor/Properties/AssemblyInfo.cs

@@ -34,4 +34,4 @@ using System.Runtime.InteropServices;
 // [assembly: AssemblyVersion("1.5.0.0")]
 [assembly: AssemblyVersion("1.5.0.0")]
 [assembly: AssemblyFileVersion("1.5.0.0")]
-[assembly: AssemblyInformationalVersion("a0384e2")]
+[assembly: AssemblyInformationalVersion("652a2f3")]

+ 166 - 0
MesAdaptor/SajectConnectSajet2.cs

@@ -0,0 +1,166 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MesAdaptor
+{
+    public class SajectConnectSajet2 : ISajetConnect
+    {
+        private enum CMD
+        {
+            Signin = 1,
+            SnCheck = 2,
+            Report = 3,
+            ValueReport = 4,
+        }
+
+        private readonly string _MechineCode;
+        public SajectConnectSajet2(string MechineCode)
+        {
+            if (string.IsNullOrEmpty(_MechineCode))
+            {
+                throw new Exception("MechineCode cannot not be empty");
+            }
+
+            _MechineCode = MechineCode;
+        }
+
+        public bool SajetTransStart() => SajetConnectAdapter.SajetTransStart();
+        public bool SajetTransClose() => SajetConnectAdapter.SajetTransClose();
+
+        private string userId = "";
+        public bool SajetTransSignIn(ref string data)
+        {
+            var attemptId = data;
+            var msg = data + ";";
+            if (SajetTransData(CMD.Signin, ref data))
+            {
+                if (string.IsNullOrEmpty(data) || data.StartsWith("NG"))
+                {
+                    userId = "";
+                    return false;
+                }
+                else
+                {
+                    userId = attemptId;
+                    return true;
+                }
+            }
+            userId = "";
+            return false;
+        }
+
+        [Obsolete]
+        public bool SajetTransWoCheck(ref string workOrder)
+        {
+            return true;
+        }
+
+        private PhihongSystemID.SystemID systemID;
+        public bool SajetTransSnCheck(ref string serialNumber)
+        {
+            if (!PhihongSystemID.SystemID.TryParse(serialNumber, out var id))
+            {
+                return false;
+            }
+
+            var msg = string.Format("{0};{1};;", id.ModelName.ToString(), id.ToString());
+
+            if (SajetTransData(CMD.SnCheck, ref msg))
+            {
+                if (string.IsNullOrEmpty(msg) || msg.StartsWith("NG"))
+                {
+                    systemID = null;
+                    return false;
+                }
+                systemID = id;
+                return true;
+            }
+            systemID = null;
+            return false;
+        }
+
+        public bool SajetTranFinishSuccess()
+        {
+            if (string.IsNullOrEmpty(userId))
+                return false;
+            if (systemID == null)
+                return false;
+            //string msg = userId + ";" + systemID.ToString() + ";";
+            string msg = string.Format("{0};{1};{2}:0;", userId, _MechineCode, systemID.ModelName.ToString(), systemID.ToString());
+
+            if (string.IsNullOrEmpty(msg))
+                return false;
+
+#if DEBUG
+            return true;
+#endif
+
+            return SajetTransData(CMD.Report, ref msg);
+        }
+
+        public bool SajetTranFinishFail(MesErrorCode errorCode)
+        {
+            if (string.IsNullOrEmpty(userId))
+                return false;
+            if (systemID == null)
+                return false;
+            //string msg = userId + ";" + systemID.ToString() + ";";
+            string msg = string.Format("{0};{1};{2}:{3};", userId, _MechineCode, systemID.ModelName.ToString(), systemID.ToString(), errorCode);
+
+            if (string.IsNullOrEmpty(msg))
+                return false;
+
+            msg += $"NG;{errorCode};";  //E114
+
+#if DEBUG
+            return true;
+#endif
+
+            return SajetTransData(CMD.Report, ref msg);
+        }
+
+        [Obsolete]
+        public string SajetTransRegisterHeader(string model, string header)
+        {
+            return "";
+        }
+
+        public bool SajetTransReport(Dictionary<string, string> reportPair)
+        {
+            var totalResult = true;
+            foreach(var pair in reportPair)
+            {
+                var msg = string.Format("{0};{1};{2};{3};{4}:{5};", userId,_MechineCode,systemID.ModelName.ToString(),systemID.ToString(),pair.Key,pair.Value);
+                var result = SajetTransData(CMD.ValueReport, ref msg);
+                totalResult &= result;
+            }
+            return totalResult;
+        }
+
+        [Obsolete]
+        public bool SajetTransReport(Dictionary<string, int> resultPair, Dictionary<string, string> codePair)
+        {
+            return true;
+        }
+
+        [Obsolete]
+        public bool SajetTransReport(Dictionary<string, string> resultPair, Dictionary<string, string> codePair)
+        {
+            return true;
+        }
+
+        [Obsolete]
+        public bool SajetTransLog(string data)
+        {
+            return true;
+        }
+
+        private bool SajetTransData(CMD command, ref string data)
+        {
+            return SajetConnectAdapter.SajetTransData((int)command, ref data);
+        }
+    }
+}

+ 2 - 29
MesAdaptor/SajetConnect.cs

@@ -16,36 +16,9 @@ namespace MesAdaptor
         test
     }
 
-    public class SajetConnect
+    public static class SajetConnect
     {
-        public static ISajetConnect Instance { get; private set; }
-
-        //public static bool IsEmsEnabled { get; set; } = true;
-
-        private static MesType _Type = MesType.none;
-        public static MesType Type
-        {
-            get => _Type;
-            set
-            {
-                _Type = value;
-                switch (_Type)
-                {
-                    case MesType.none:
-                        Instance = null;
-                        break;
-                    case MesType.sajet:
-                        Instance = new SajectConnectSajet();
-                        break;
-                    case MesType.shinewave:
-                        Instance = new SajetConnectShinewave();
-                        break;
-                    case MesType.test:
-                        Instance = new SajectConnectTest();
-                        break;
-                }
-            }
-        }
+        public static ISajetConnect Instance { get; set; }
 
         public static bool SajetTransStart() => Instance.SajetTransStart();
         public static bool SajetTransClose() => Instance.SajetTransClose();

+ 1 - 1
PhihongSystemID/Properties/AssemblyInfo.cs

@@ -34,4 +34,4 @@ using System.Runtime.InteropServices;
 // [assembly: AssemblyVersion("1.5.0.0")]
 [assembly: AssemblyVersion("1.5.0.0")]
 [assembly: AssemblyFileVersion("1.5.0.0")]
-[assembly: AssemblyInformationalVersion("a0384e2")]
+[assembly: AssemblyInformationalVersion("652a2f3")]