圣珀
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

301 lines
12 KiB

2 years ago
2 years ago
  1. using ICS.WCF.Base;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.Linq;
  7. using System.ServiceModel;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using UFSoft.UBF.Service;
  11. using UFSoft.UBF.Util.Context;
  12. using www.ufida.org.EntityData;
  13. namespace UFIDA.ISV.CreateLotMaster
  14. {
  15. public class CustCreateLotMaster
  16. {
  17. /// <summary>
  18. /// 创建批号
  19. /// </summary>
  20. /// <param name="model"></param>
  21. /// <returns></returns>
  22. public OperationResule CustCreateRCVLotMaster(string WHCode, string ItemCode, string LotNo, string OrgID, ref string LotID)
  23. {
  24. //U9.PM.PO.POShipLine.CreatePOShipLineDefault();
  25. #region 服务调用框架结构
  26. //实例化代理类 UFIDAU9ISVItemIBatchCreateItemByDTOSRVClient
  27. UFIDAU9ISVCBOLotICommonCreateLotMasterSRVClient client = new UFIDAU9ISVCBOLotICommonCreateLotMasterSRVClient();
  28. //服务返回结果
  29. UFIDAU9BaseDTOsIDCodeNameDTOData[] returnItems;
  30. //返回异常信息,目前还没有使用此属性
  31. UFSoft.UBF.Exceptions1.MessageBase[] returnMsg;
  32. //上下文信息
  33. object context;
  34. //传入 参数
  35. //;
  36. OperationResule result = new OperationResule();
  37. string[] splitBy = new string[] { };
  38. UFIDAU9ISVCBOLotCreateLotMasterDTOData[] createLotMasterDTOList = new UFIDAU9ISVCBOLotCreateLotMasterDTOData[] { };
  39. List<UFIDAU9ISVCBOLotCreateLotMasterDTOData> list = new List<UFIDAU9ISVCBOLotCreateLotMasterDTOData>();
  40. UFIDAU9ISVCBOLotCreateLotMasterDTOData _model = new UFIDAU9ISVCBOLotCreateLotMasterDTOData();
  41. _model.m_lotCode = LotNo;//批号
  42. _model.m_item = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  43. _model.m_item.m_code = ItemCode;//料品
  44. _model.m_usedToOrg = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  45. _model.m_usedToOrg.m_iD = long.Parse(OrgID);
  46. //_model.m_lotDisabledTime = Convert.ToDateTime("9999.12.31");
  47. list.Add(_model);
  48. createLotMasterDTOList = list.ToArray();
  49. try
  50. {
  51. //给上下文信息赋值
  52. context = CreateContextObj(OrgID);
  53. //给传入参数赋值
  54. //pOList = SetrCVDtos( rCVInfoList);
  55. //服务调用
  56. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  57. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  58. returnItems = client.Do(out returnMsg, context, createLotMasterDTOList);
  59. foreach (var item in returnItems)
  60. {
  61. long id = item.m_iD;
  62. string sql = @"SELECT lotcode from Lot_LotMaster WHERE ID={0}";
  63. sql = string.Format(sql, id);
  64. DataTable _dtlotcode = DBhlper.Query(sql, Appconfig.GetU9ConnStr());
  65. string lotcode = string.Empty;
  66. if (_dtlotcode != null && _dtlotcode.Rows.Count > 0)
  67. {
  68. lotcode = _dtlotcode.Rows[0][0].ToString();
  69. }
  70. result.DocNo = lotcode;
  71. result.IsSuccess = true;
  72. LotID = id.ToString();
  73. result.Message = "创建库存批号成功";
  74. }
  75. return result;
  76. }
  77. catch (Exception ex)
  78. {
  79. //异常信息捕获
  80. string Message = GetExceptionMessage(ex);
  81. result.DocNo = "";
  82. result.IsSuccess = false;
  83. result.Message = Message;
  84. return result;
  85. }
  86. #endregion
  87. }
  88. /// <summary>
  89. /// 创建批号(创建时间修改)
  90. /// </summary>
  91. /// <param name="model"></param>
  92. /// <returns></returns>
  93. public OperationResule CustCreateRCVLotMaster(string WHCode, string ItemCode, string LotNo, DateTime CreateTime, string OrgID, ref string LotID)
  94. {
  95. //U9.PM.PO.POShipLine.CreatePOShipLineDefault();
  96. #region 服务调用框架结构
  97. //实例化代理类 UFIDAU9ISVItemIBatchCreateItemByDTOSRVClient
  98. UFIDAU9ISVCBOLotICommonCreateLotMasterSRVClient client = new UFIDAU9ISVCBOLotICommonCreateLotMasterSRVClient();
  99. //服务返回结果
  100. UFIDAU9BaseDTOsIDCodeNameDTOData[] returnItems;
  101. //返回异常信息,目前还没有使用此属性
  102. UFSoft.UBF.Exceptions1.MessageBase[] returnMsg;
  103. //上下文信息
  104. object context;
  105. //传入 参数
  106. //;
  107. OperationResule result = new OperationResule();
  108. string[] splitBy = new string[] { };
  109. UFIDAU9ISVCBOLotCreateLotMasterDTOData[] createLotMasterDTOList = new UFIDAU9ISVCBOLotCreateLotMasterDTOData[] { };
  110. List<UFIDAU9ISVCBOLotCreateLotMasterDTOData> list = new List<UFIDAU9ISVCBOLotCreateLotMasterDTOData>();
  111. UFIDAU9ISVCBOLotCreateLotMasterDTOData _model = new UFIDAU9ISVCBOLotCreateLotMasterDTOData();
  112. _model.m_lotCode = LotNo;//批号
  113. _model.m_item = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  114. _model.m_item.m_code = ItemCode;//料品
  115. _model.m_usedToOrg = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  116. _model.m_usedToOrg.m_iD = long.Parse(OrgID);
  117. //_model.m_lotDisabledTime = Convert.ToDateTime("9999.12.31");
  118. list.Add(_model);
  119. createLotMasterDTOList = list.ToArray();
  120. try
  121. {
  122. //给上下文信息赋值
  123. context = CreateContextObj(OrgID);
  124. //给传入参数赋值
  125. //pOList = SetrCVDtos( rCVInfoList);
  126. //服务调用
  127. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  128. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  129. returnItems = client.Do(out returnMsg, context, createLotMasterDTOList);
  130. foreach (var item in returnItems)
  131. {
  132. long id = item.m_iD;
  133. string sql = @"SELECT lotcode from Lot_LotMaster WHERE ID={0}";
  134. sql = string.Format(sql, id);
  135. DataTable _dtlotcode = DBhlper.Query(sql, Appconfig.GetU9ConnStr());
  136. string lotcode = _dtlotcode.Rows[0][0].ToString();
  137. //if (_dtlotcode != null && _dtlotcode.Rows.Count > 0)
  138. //{
  139. // lotcode = _dtlotcode.Rows[0][0].ToString();
  140. // sql = @"Update Lot_LotMaster set CreatedOn='{0}'
  141. // Where ID='{1}'";
  142. // sql = string.Format(sql, CreateTime, id);
  143. // DBhlper.EXecute(sql, Appconfig.GetU9ConnStr());
  144. //}
  145. result.DocNo = lotcode;
  146. result.IsSuccess = true;
  147. LotID = id.ToString();
  148. result.Message = "创建库存批号成功";
  149. }
  150. return result;
  151. }
  152. catch (Exception ex)
  153. {
  154. //异常信息捕获
  155. string Message = GetExceptionMessage(ex);
  156. result.DocNo = "";
  157. result.IsSuccess = false;
  158. result.Message = Message;
  159. return result;
  160. }
  161. #endregion
  162. }
  163. #region 提取异常信息
  164. /// <summary>
  165. /// 提取异常信息
  166. /// </summary>
  167. /// <param name="ex"></param>
  168. private string GetExceptionMessage(Exception ex)
  169. {
  170. string faultMessage = "未知错误,请查看ERP日志!";
  171. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  172. if (timeoutEx != null)
  173. {
  174. faultMessage = "访问服务超时,请修改配置信息!";
  175. }
  176. else
  177. {
  178. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  179. if (faultEx == null)
  180. {
  181. faultMessage = ex.Message;
  182. }
  183. else
  184. {
  185. ServiceException serviceEx = faultEx.Detail;
  186. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  187. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  188. {
  189. // 错误信息在faultEx.Message中,请提取,
  190. // 格式为"Fault:料品不能为空,请录入\n 在....."
  191. int startIndex = serviceEx.Message.IndexOf(":");
  192. int endIndex = serviceEx.Message.IndexOf("\n");
  193. if (endIndex == -1)
  194. endIndex = serviceEx.Message.Length;
  195. if (endIndex > 0 && endIndex > startIndex + 1)
  196. {
  197. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  198. }
  199. else
  200. {
  201. faultMessage = serviceEx.Message;
  202. }
  203. }
  204. }
  205. }
  206. return faultMessage;
  207. }
  208. #endregion
  209. #region 给上下文信息赋值
  210. /// <summary>
  211. /// 给上下文信息赋值
  212. /// </summary>
  213. /// <returns></returns>
  214. private ThreadContext CreateContextObj(string OrgID)
  215. {
  216. // 实例化应用上下文对象
  217. ThreadContext thContext = new ThreadContext();
  218. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  219. ns.Add("OrgID", OrgID);
  220. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  221. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  222. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  223. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  224. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  225. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  226. thContext.nameValueHas = ns;
  227. return thContext;
  228. }
  229. #endregion
  230. #region 表头类
  231. public class LotMaster
  232. {
  233. //private string _LotCodingRule; //编码规则
  234. private string _ItemCode;
  235. //private string _DocCode;//单据号RCVNo
  236. private string _LotCode;//批号
  237. private string _WHCode;//存储地点
  238. public string LotCode
  239. {
  240. get { return _LotCode; }
  241. set { _LotCode = value; }
  242. }
  243. //public string DocCode
  244. //{
  245. // get { return _DocCode; }
  246. // set { _DocCode = value; }
  247. //}
  248. public string ItemCode
  249. {
  250. get { return _ItemCode; }
  251. set { _ItemCode = value; }
  252. }
  253. public string WHCode
  254. {
  255. get { return _WHCode; }
  256. set { _WHCode = value; }
  257. }
  258. }
  259. #endregion
  260. public class OperationResule
  261. {
  262. public string DocNo { get; set; }
  263. public bool IsSuccess { get; set; }
  264. public string Message { get; set; }
  265. }
  266. }
  267. }