|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|