SmartDeviceService.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:SmartDeviceService.cs
  5. * 2.功能描述:接收智能设备请求
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2018/10/25 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.ServiceModel;
  13. using System.ServiceModel.Activation;
  14. using Dongke.IBOSS.PRD.Basics.Library;
  15. using Dongke.IBOSS.PRD.Service.DataModels;
  16. using Dongke.IBOSS.PRD.Service.PMModuleLogic;
  17. using Dongke.IBOSS.PRD.Service.SmartDeviceService;
  18. using Dongke.IBOSS.PRD.WCF.Contracts;
  19. using Dongke.IBOSS.PRD.WCF.DataModels;
  20. namespace Dongke.IBOSS.PRD.WCF.Services
  21. {
  22. /// <summary>
  23. /// 智能设备对接服务
  24. /// </summary>
  25. [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  26. [ServiceBehavior(ConfigurationName = "SmartDeviceService",
  27. InstanceContextMode = InstanceContextMode.PerCall,
  28. ConcurrencyMode = ConcurrencyMode.Multiple,
  29. UseSynchronizationContext = false)]
  30. public class SmartDeviceService : ISmartDevice
  31. {
  32. /// <summary>
  33. /// 连接测试
  34. /// </summary>
  35. /// <param name="message"></param>
  36. /// <returns></returns>
  37. public string Test(string message)
  38. {
  39. return message + " is ok";
  40. }
  41. /// <summary>
  42. /// 自动扫描计件
  43. /// </summary>
  44. /// <returns></returns>
  45. public void AddWorkPiece(string accountCode, string userCode, string userPassword,
  46. int procedureID, string barcode)
  47. {
  48. try
  49. {
  50. DataTable userInfo = SmartDeviceLogic.CheckUserCode(accountCode, userCode);
  51. if (userInfo == null)
  52. {
  53. OutputLog.TraceLog(LogPriority.Warning,
  54. this.ToString(),
  55. System.Reflection.MethodBase.GetCurrentMethod().Name,
  56. " userInfo is null " + userPassword + System.Environment.NewLine +
  57. " accountCode:" + accountCode + " userCode:" + userCode + " procedureID:" + procedureID + " barcode:" + barcode,
  58. LocalPath.LogExePath + "SmartDevice\\");
  59. return;
  60. }
  61. SUserInfo sUserInfo = new SUserInfo();
  62. sUserInfo.AccountID = Convert.ToInt32(userInfo.Rows[0]["AccountID"]);
  63. sUserInfo.AccountCode = accountCode;
  64. sUserInfo.UserID = Convert.ToInt32(userInfo.Rows[0]["userid"]);
  65. sUserInfo.UserCode = userCode;
  66. //DataTable barcodeTable = new DataTable();
  67. //barcodeTable.TableName = "barcodeTable";
  68. //barcodeTable.Columns.Add("BarCode");
  69. //barcodeTable.Columns.Add("UserID");
  70. //barcodeTable.Columns.Add("UserCode");
  71. //barcodeTable.Columns.Add("UserName");
  72. //barcodeTable.Columns.Add("LogoID");
  73. //DataRow drCollectType = barcodeTable.NewRow();
  74. //drCollectType["BarCode"] = barcode;
  75. //drCollectType["UserID"] = sUserInfo.UserID;
  76. //drCollectType["UserCode"] = sUserInfo.UserCode;
  77. //drCollectType["UserName"] = userInfo.Rows[0]["UserName"].ToString();
  78. //barcodeTable.Rows.Add(drCollectType);
  79. DataTable barcodeTable = userInfo;
  80. barcodeTable.Columns.Add("LogoID");
  81. barcodeTable.Columns.Add("BarCode");
  82. barcodeTable.Rows[0]["BarCode"] = barcode;
  83. ProcedureEntity procedureInfo = null;
  84. DataTable dt = PMModuleLogicDAL.AddWorkPiece(procedureID, barcodeTable, sUserInfo, out procedureInfo);
  85. if (dt != null && dt.Rows.Count > 0 && !string.IsNullOrWhiteSpace(dt.Rows[0]["out_errMsg"].ToString()))
  86. {
  87. OutputLog.TraceLog(LogPriority.Warning,
  88. this.ToString(),
  89. System.Reflection.MethodBase.GetCurrentMethod().Name + System.Environment.NewLine +
  90. userPassword + System.Environment.NewLine +
  91. " accountCode:" + accountCode + " userCode:" + userCode + " procedureID:" + procedureID + " barcode:" + barcode,
  92. JsonHelper.ToJson(dt),
  93. LocalPath.LogExePath+ "SmartDevice\\");
  94. }
  95. }
  96. catch (Exception ex)
  97. {
  98. OutputLog.TraceLog(LogPriority.Error,
  99. this.ToString(),
  100. System.Reflection.MethodBase.GetCurrentMethod().Name + System.Environment.NewLine +
  101. userPassword + System.Environment.NewLine +
  102. " accountCode:" + accountCode + " userCode:" + userCode + " procedureID:" + procedureID + " barcode:" + barcode,
  103. ex.ToString(),
  104. LocalPath.LogExePath);
  105. }
  106. }
  107. /// <summary>
  108. /// 自动扫描计件
  109. /// </summary>
  110. /// <returns></returns>
  111. public string AddWorkPieceByStatus(string accountCode, string userCode, string userPassword,
  112. int procedureID, string barcode, string remarks)
  113. {
  114. try
  115. {
  116. DataTable userInfo = SmartDeviceLogic.CheckUserCode(accountCode, userCode);
  117. if (userInfo == null)
  118. {
  119. OutputLog.TraceLog(LogPriority.Warning,
  120. this.ToString(),
  121. System.Reflection.MethodBase.GetCurrentMethod().Name,
  122. " userInfo is null " + userPassword + System.Environment.NewLine +
  123. " accountCode:" + accountCode + " userCode:" + userCode + " procedureID:" + procedureID + " barcode:" + barcode,
  124. LocalPath.LogExePath + "SmartDevice\\");
  125. return "EU-01";
  126. }
  127. SUserInfo sUserInfo = new SUserInfo();
  128. sUserInfo.AccountID = Convert.ToInt32(userInfo.Rows[0]["AccountID"]);
  129. sUserInfo.AccountCode = accountCode;
  130. sUserInfo.UserID = Convert.ToInt32(userInfo.Rows[0]["userid"]);
  131. sUserInfo.UserCode = userCode;
  132. //DataTable barcodeTable = new DataTable();
  133. //barcodeTable.TableName = "barcodeTable";
  134. //barcodeTable.Columns.Add("BarCode");
  135. //barcodeTable.Columns.Add("UserID");
  136. //barcodeTable.Columns.Add("UserCode");
  137. //barcodeTable.Columns.Add("UserName");
  138. //barcodeTable.Columns.Add("LogoID");
  139. //DataRow drCollectType = barcodeTable.NewRow();
  140. //drCollectType["BarCode"] = barcode;
  141. //drCollectType["UserID"] = sUserInfo.UserID;
  142. //drCollectType["UserCode"] = sUserInfo.UserCode;
  143. //drCollectType["UserName"] = userInfo.Rows[0]["UserName"].ToString();
  144. //barcodeTable.Rows.Add(drCollectType);
  145. DataTable barcodeTable = userInfo;
  146. barcodeTable.Columns.Add("LogoID");
  147. barcodeTable.Columns.Add("BarCode");
  148. barcodeTable.Columns.Add("Remarks");
  149. barcodeTable.Rows[0]["BarCode"] = barcode;
  150. barcodeTable.Rows[0]["Remarks"] = remarks;
  151. ProcedureEntity procedureInfo = null;
  152. DataTable dt = PMModuleLogicDAL.AddWorkPiece(procedureID, barcodeTable, sUserInfo, out procedureInfo);
  153. string out_msg = dt.Rows[0]["out_errMsg"].ToString();
  154. if (dt != null && dt.Rows.Count > 0 && !string.IsNullOrWhiteSpace(out_msg))
  155. {
  156. OutputLog.TraceLog(LogPriority.Warning,
  157. this.ToString(),
  158. System.Reflection.MethodBase.GetCurrentMethod().Name + System.Environment.NewLine +
  159. userPassword + System.Environment.NewLine +
  160. " accountCode:" + accountCode + " userCode:" + userCode + " procedureID:" + procedureID + " barcode:" + barcode,
  161. JsonHelper.ToJson(dt),
  162. LocalPath.LogExePath + "SmartDevice\\");
  163. if (out_msg.StartsWith("无效条码"))
  164. {
  165. return "EP-01";
  166. }
  167. if (out_msg.Contains("不能到达该工序"))
  168. {
  169. return "EP-02";
  170. }
  171. return "EP-00";
  172. }
  173. return "OK";
  174. }
  175. catch (Exception ex)
  176. {
  177. OutputLog.TraceLog(LogPriority.Error,
  178. this.ToString(),
  179. System.Reflection.MethodBase.GetCurrentMethod().Name + System.Environment.NewLine +
  180. userPassword + System.Environment.NewLine +
  181. " accountCode:" + accountCode + " userCode:" + userCode + " procedureID:" + procedureID + " barcode:" + barcode,
  182. ex.ToString(),
  183. LocalPath.LogExePath);
  184. return "EE";
  185. }
  186. }
  187. }
  188. }