|
@@ -1,275 +1,275 @@
|
|
|
-using PhihongEv.Lib;
|
|
|
-using System;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Linq;
|
|
|
-using System.Text;
|
|
|
-using System.Threading.Tasks;
|
|
|
-
|
|
|
-namespace MesAdaptor
|
|
|
-{
|
|
|
- public class SajectConnectSajet : ISajetConnect
|
|
|
- {
|
|
|
- private enum CMD
|
|
|
- {
|
|
|
- Signin = 1,
|
|
|
- SnCheck = 2,
|
|
|
- WoCheck = -1,
|
|
|
- Report = 3,
|
|
|
- Log = 4,
|
|
|
- HeaderRegister = 8,
|
|
|
- ValueReport = 5,
|
|
|
- StringValueReport = 6,
|
|
|
- }
|
|
|
-
|
|
|
- public bool SajetTransStart() => SajetConnectAdapter.SajetTransStart();
|
|
|
- public bool SajetTransClose() => SajetConnectAdapter.SajetTransClose();
|
|
|
-
|
|
|
- private string userId = "";
|
|
|
- public bool SajetTransSignIn(ref string data)
|
|
|
- {
|
|
|
- var attemptId = 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;
|
|
|
- }
|
|
|
-
|
|
|
- private string WorkOrder = "";
|
|
|
- public bool SajetTransWoCheck(ref string workOrder)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- private string SN;
|
|
|
- public bool SajetTransSnCheck(ref string serialNumber)
|
|
|
- {
|
|
|
- var attemptSN = serialNumber;
|
|
|
- var msg = serialNumber;
|
|
|
-
|
|
|
- if (SajetTransData(CMD.SnCheck, ref msg))
|
|
|
- {
|
|
|
- if (string.IsNullOrEmpty(msg) || msg.StartsWith("NG"))
|
|
|
- {
|
|
|
- SN = "";
|
|
|
- return false;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- SN = attemptSN;
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- SN = "";
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- public bool SajetTranFinishSuccess()
|
|
|
- {
|
|
|
- if (string.IsNullOrEmpty(userId))
|
|
|
- return false;
|
|
|
- if (string.IsNullOrEmpty(SN))
|
|
|
- return false;
|
|
|
- string msg = userId + ";" + SN + ";";
|
|
|
-
|
|
|
- if (string.IsNullOrEmpty(msg))
|
|
|
- return false;
|
|
|
-
|
|
|
- msg += "OK";
|
|
|
-
|
|
|
-#if DEBUG
|
|
|
- return true;
|
|
|
-#endif
|
|
|
-
|
|
|
- return SajetTransData(CMD.Report, ref msg);
|
|
|
- }
|
|
|
-
|
|
|
- public bool SajetTranFinishFail(MesErrorCode errorCode)
|
|
|
- {
|
|
|
- if (string.IsNullOrEmpty(userId))
|
|
|
- return false;
|
|
|
- if (string.IsNullOrEmpty(SN))
|
|
|
- return false;
|
|
|
- string msg = userId + ";" + SN + ";";
|
|
|
-
|
|
|
- if (string.IsNullOrEmpty(msg))
|
|
|
- return false;
|
|
|
-
|
|
|
- msg += $"NG;{errorCode};";
|
|
|
-
|
|
|
-#if DEBUG
|
|
|
- return true;
|
|
|
-#endif
|
|
|
-
|
|
|
- return SajetTransData(CMD.Report, ref msg);
|
|
|
- }
|
|
|
-
|
|
|
- public string SajetTransRegisterHeader(string model, string header)
|
|
|
- {
|
|
|
- if (string.IsNullOrEmpty(userId))
|
|
|
- return "";
|
|
|
- var msg = userId + ";";
|
|
|
- msg += model + ";" + header;
|
|
|
- if (SajetTransData(CMD.HeaderRegister, ref msg))
|
|
|
- {
|
|
|
- if (msg.StartsWith("OK"))
|
|
|
- {
|
|
|
-
|
|
|
- msg = msg.Substring(3);
|
|
|
- var spaceIndex = msg.IndexOf(";");
|
|
|
- if (spaceIndex > 0)
|
|
|
- {
|
|
|
- msg = msg.Substring(0, spaceIndex);
|
|
|
- }
|
|
|
- return msg;
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- public bool SajetTransReport(ValueReportDatas reportPair)
|
|
|
- {
|
|
|
-
|
|
|
- Dictionary<string, int> valuePairs = new Dictionary<string, int>();
|
|
|
- foreach (var data in reportPair)
|
|
|
- {
|
|
|
- if (int.TryParse(data.Val, out int val))
|
|
|
- {
|
|
|
- valuePairs.Add(data.Key, val);
|
|
|
- }
|
|
|
- else if (data.Val.ToLower().Contains("fail"))
|
|
|
- {
|
|
|
- valuePairs.Add(data.Key, 0);
|
|
|
- }
|
|
|
- else if (data.Val.ToLower().Contains("success"))
|
|
|
- {
|
|
|
- valuePairs.Add(data.Key, 1);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- valuePairs.Add(string.Format("{0}:{1}", data.Key, data.Val), 1);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var codePair = new Dictionary<string, string>();
|
|
|
-
|
|
|
- string model = "";
|
|
|
- if (SystemID.TryParse(SN,out var systemID))
|
|
|
- {
|
|
|
- model = systemID.ModelName.ToString();
|
|
|
- }
|
|
|
-
|
|
|
- foreach (var key in valuePairs.Keys)
|
|
|
- {
|
|
|
- var code = SajetTransRegisterHeader(model, key);
|
|
|
- if (string.IsNullOrEmpty(code))
|
|
|
- continue;
|
|
|
- codePair.Add(key, code);
|
|
|
- }
|
|
|
-
|
|
|
- var reportResult = SajetTransReport(valuePairs, codePair);
|
|
|
- return reportResult;
|
|
|
- }
|
|
|
-
|
|
|
- public bool SajetTransReport(Dictionary<string, int> resultPair, Dictionary<string, string> codePair)
|
|
|
- {
|
|
|
- if (string.IsNullOrEmpty(userId))
|
|
|
- return false;
|
|
|
- if (string.IsNullOrEmpty(SN))
|
|
|
- return false;
|
|
|
- string msgHeader = userId + ";" + SN;
|
|
|
- string msg = "";
|
|
|
-
|
|
|
- foreach (var result in resultPair)
|
|
|
- {
|
|
|
- if (codePair.Keys.Contains(result.Key))
|
|
|
- {
|
|
|
- msg = string.Format("{0};{1}:{2};",msgHeader, codePair[result.Key], string.Format("{0}.00", result.Value));
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- SajetTransData(CMD.ValueReport, ref msg);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- public bool SajetTransReport(Dictionary<string, string> resultPair, Dictionary<string, string> codePair)
|
|
|
- {
|
|
|
- if (string.IsNullOrEmpty(userId))
|
|
|
- return false;
|
|
|
- if (string.IsNullOrEmpty(SN))
|
|
|
- return false;
|
|
|
- string msg = userId + ";" + SN;
|
|
|
- foreach (var result in resultPair)
|
|
|
- {
|
|
|
- if (codePair.Keys.Contains(result.Key))
|
|
|
- {
|
|
|
- msg += string.Format(";{0}:{1}", codePair[result.Key], string.Format("{0}.00", result.Value));
|
|
|
- }
|
|
|
- msg += ";";
|
|
|
- SajetTransData(CMD.StringValueReport, ref msg);
|
|
|
- msg = userId + ";" + SN;
|
|
|
- }
|
|
|
- msg += ";";
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- public bool SajetTransLog(string data)
|
|
|
- {
|
|
|
- return true;
|
|
|
-
|
|
|
- if (string.IsNullOrEmpty(userId))
|
|
|
- return false;
|
|
|
- if (string.IsNullOrEmpty(SN))
|
|
|
- return false;
|
|
|
- string prefix = userId + ";" + SN + ";";
|
|
|
- while (data.Length > 0)
|
|
|
- {
|
|
|
- var msg = prefix;
|
|
|
- int sendLength = Math.Min(250 - msg.Length, data.Length);
|
|
|
- var sendString = data.Substring(0, sendLength);
|
|
|
- msg += sendString;
|
|
|
- if (!SajetTransData(CMD.Log, ref msg))
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- data = data.Substring(sendLength);
|
|
|
- }
|
|
|
- return data.Length == 0;
|
|
|
- }
|
|
|
-
|
|
|
- private bool SajetTransData(CMD command, ref string data)
|
|
|
- {
|
|
|
- return SajetConnectAdapter.SajetTransData((int)command, ref data);
|
|
|
- }
|
|
|
-
|
|
|
- private string GetSendPrefix()
|
|
|
- {
|
|
|
- string msg = "";
|
|
|
- if (string.IsNullOrEmpty(userId))
|
|
|
- {
|
|
|
- return null;
|
|
|
- }
|
|
|
- msg = userId + ";";
|
|
|
- if (string.IsNullOrEmpty(WorkOrder))
|
|
|
- {
|
|
|
- return null;
|
|
|
- }
|
|
|
- msg += WorkOrder + ";";
|
|
|
- return msg;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+using PhihongEv.Lib;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+
|
|
|
+namespace MesAdaptor
|
|
|
+{
|
|
|
+ public class SajectConnectSajet : ISajetConnect
|
|
|
+ {
|
|
|
+ private enum CMD
|
|
|
+ {
|
|
|
+ Signin = 1,
|
|
|
+ SnCheck = 2,
|
|
|
+ WoCheck = -1,
|
|
|
+ Report = 3,
|
|
|
+ Log = 4,
|
|
|
+ HeaderRegister = 8,
|
|
|
+ ValueReport = 5,
|
|
|
+ StringValueReport = 6,
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool SajetTransStart() => SajetConnectAdapter.SajetTransStart();
|
|
|
+ public bool SajetTransClose() => SajetConnectAdapter.SajetTransClose();
|
|
|
+
|
|
|
+ private string userId = "";
|
|
|
+ public bool SajetTransSignIn(ref string data)
|
|
|
+ {
|
|
|
+ var attemptId = 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ private string WorkOrder = "";
|
|
|
+ public bool SajetTransWoCheck(ref string workOrder)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private string SN;
|
|
|
+ public bool SajetTransSnCheck(ref string serialNumber)
|
|
|
+ {
|
|
|
+ var attemptSN = serialNumber;
|
|
|
+ var msg = serialNumber;
|
|
|
+
|
|
|
+ if (SajetTransData(CMD.SnCheck, ref msg))
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(msg) || msg.StartsWith("NG"))
|
|
|
+ {
|
|
|
+ SN = "";
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SN = attemptSN;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SN = "";
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool SajetTranFinishSuccess()
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(userId))
|
|
|
+ return false;
|
|
|
+ if (string.IsNullOrEmpty(SN))
|
|
|
+ return false;
|
|
|
+ string msg = userId + ";" + SN + ";";
|
|
|
+
|
|
|
+ if (string.IsNullOrEmpty(msg))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ msg += "OK";
|
|
|
+
|
|
|
+#if DEBUG
|
|
|
+ return true;
|
|
|
+#endif
|
|
|
+
|
|
|
+ return SajetTransData(CMD.Report, ref msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool SajetTranFinishFail(MesErrorCode errorCode)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(userId))
|
|
|
+ return false;
|
|
|
+ if (string.IsNullOrEmpty(SN))
|
|
|
+ return false;
|
|
|
+ string msg = userId + ";" + SN + ";";
|
|
|
+
|
|
|
+ if (string.IsNullOrEmpty(msg))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ msg += $"NG;{errorCode};";
|
|
|
+
|
|
|
+#if DEBUG
|
|
|
+ return true;
|
|
|
+#endif
|
|
|
+
|
|
|
+ return SajetTransData(CMD.Report, ref msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ public string SajetTransRegisterHeader(string model, string header)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(userId))
|
|
|
+ return "";
|
|
|
+ var msg = userId + ";";
|
|
|
+ msg += model + ";" + header;
|
|
|
+ if (SajetTransData(CMD.HeaderRegister, ref msg))
|
|
|
+ {
|
|
|
+ if (msg.StartsWith("OK"))
|
|
|
+ {
|
|
|
+
|
|
|
+ msg = msg.Substring(3);
|
|
|
+ var spaceIndex = msg.IndexOf(";");
|
|
|
+ if (spaceIndex > 0)
|
|
|
+ {
|
|
|
+ msg = msg.Substring(0, spaceIndex);
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool SajetTransReport(ValueReportDatas reportPair)
|
|
|
+ {
|
|
|
+
|
|
|
+ Dictionary<string, int> valuePairs = new Dictionary<string, int>();
|
|
|
+ foreach (var data in reportPair)
|
|
|
+ {
|
|
|
+ if (int.TryParse(data.Val, out int val))
|
|
|
+ {
|
|
|
+ valuePairs.Add(data.Key, val);
|
|
|
+ }
|
|
|
+ else if (data.Val.ToLower().Contains("fail"))
|
|
|
+ {
|
|
|
+ valuePairs.Add(data.Key, 0);
|
|
|
+ }
|
|
|
+ else if (data.Val.ToLower().Contains("success"))
|
|
|
+ {
|
|
|
+ valuePairs.Add(data.Key, 1);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ valuePairs.Add(string.Format("{0}:{1}", data.Key, data.Val), 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var codePair = new Dictionary<string, string>();
|
|
|
+
|
|
|
+ string model = "";
|
|
|
+ if (SystemID.TryParse(SN,out var systemID))
|
|
|
+ {
|
|
|
+ model = systemID.ModelName.ToString();
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (var key in valuePairs.Keys)
|
|
|
+ {
|
|
|
+ var code = SajetTransRegisterHeader(model, key);
|
|
|
+ if (string.IsNullOrEmpty(code))
|
|
|
+ continue;
|
|
|
+ codePair.Add(key, code);
|
|
|
+ }
|
|
|
+
|
|
|
+ var reportResult = SajetTransReport(valuePairs, codePair);
|
|
|
+ return reportResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool SajetTransReport(Dictionary<string, int> resultPair, Dictionary<string, string> codePair)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(userId))
|
|
|
+ return false;
|
|
|
+ if (string.IsNullOrEmpty(SN))
|
|
|
+ return false;
|
|
|
+ string msgHeader = userId + ";" + SN;
|
|
|
+ string msg = "";
|
|
|
+
|
|
|
+ foreach (var result in resultPair)
|
|
|
+ {
|
|
|
+ if (codePair.Keys.Contains(result.Key))
|
|
|
+ {
|
|
|
+ msg = string.Format("{0};{1}:{2};",msgHeader, codePair[result.Key], string.Format("{0}.00", result.Value));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ SajetTransData(CMD.ValueReport, ref msg);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool SajetTransReport(Dictionary<string, string> resultPair, Dictionary<string, string> codePair)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(userId))
|
|
|
+ return false;
|
|
|
+ if (string.IsNullOrEmpty(SN))
|
|
|
+ return false;
|
|
|
+ string msg = userId + ";" + SN;
|
|
|
+ foreach (var result in resultPair)
|
|
|
+ {
|
|
|
+ if (codePair.Keys.Contains(result.Key))
|
|
|
+ {
|
|
|
+ msg += string.Format(";{0}:{1}", codePair[result.Key], string.Format("{0}.00", result.Value));
|
|
|
+ }
|
|
|
+ msg += ";";
|
|
|
+ SajetTransData(CMD.StringValueReport, ref msg);
|
|
|
+ msg = userId + ";" + SN;
|
|
|
+ }
|
|
|
+ msg += ";";
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool SajetTransLog(string data)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+
|
|
|
+ if (string.IsNullOrEmpty(userId))
|
|
|
+ return false;
|
|
|
+ if (string.IsNullOrEmpty(SN))
|
|
|
+ return false;
|
|
|
+ string prefix = userId + ";" + SN + ";";
|
|
|
+ while (data.Length > 0)
|
|
|
+ {
|
|
|
+ var msg = prefix;
|
|
|
+ int sendLength = Math.Min(250 - msg.Length, data.Length);
|
|
|
+ var sendString = data.Substring(0, sendLength);
|
|
|
+ msg += sendString;
|
|
|
+ if (!SajetTransData(CMD.Log, ref msg))
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ data = data.Substring(sendLength);
|
|
|
+ }
|
|
|
+ return data.Length == 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool SajetTransData(CMD command, ref string data)
|
|
|
+ {
|
|
|
+ return SajetConnectAdapter.SajetTransData((int)command, ref data);
|
|
|
+ }
|
|
|
+
|
|
|
+ private string GetSendPrefix()
|
|
|
+ {
|
|
|
+ string msg = "";
|
|
|
+ if (string.IsNullOrEmpty(userId))
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ msg = userId + ";";
|
|
|
+ if (string.IsNullOrEmpty(WorkOrder))
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ msg += WorkOrder + ";";
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|