纽威
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.

269 lines
11 KiB

  1. using ICSSoft.Common;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.Data.SqlClient;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using ICSSoft.Entity;
  11. using UFSoft.UBF.Util.Context;
  12. using System.ServiceModel;
  13. using www.ufida.org.EntityData;
  14. using UFSoft.UBF.Exceptions1;
  15. using UFSoft.UBF.Service;
  16. namespace ICSSoft.APIApproveMiscShip
  17. {
  18. public class ApproveMiscShip
  19. {
  20. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  21. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
  22. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  23. /// <summary>
  24. /// 审核杂发单(外部通过API调用)
  25. /// </summary>
  26. /// <param name="infos"></param>
  27. /// <returns></returns>
  28. public bool Approve(List<ICSOtherOutDoc> infos)
  29. {
  30. bool ResultFlag = false;
  31. UFIDAU9ISVMiscShipISVICommonApproveMiscShipSVClient client = new UFIDAU9ISVMiscShipISVICommonApproveMiscShipSVClient();
  32. //返回异常信息,目前还没有使用此属性
  33. MessageBase[] returnMsg;
  34. //上下文信息
  35. object context;
  36. //传入 参数
  37. try
  38. {
  39. if (infos == null || infos.Count == 0)
  40. {
  41. throw new Exception("传入数据不能为空!");
  42. }
  43. string OrgID = "";
  44. string orgsql = @"select ID from Base_Organization
  45. where Code='{0}'";
  46. orgsql = string.Format(orgsql, infos[0].WorkPoint);
  47. DataTable orgdt = DBHelper.Query(orgsql, connString);
  48. if (orgdt.Rows.Count != 0)
  49. {
  50. OrgID = orgdt.Rows[0]["ID"].ToString();
  51. }
  52. else
  53. {
  54. throw new Exception("传入组织编码错误!");
  55. }
  56. UFIDAU9ISVMiscShipISVIC_MiscShipmentDTOData[] returnItems;
  57. //给上下文信息赋值
  58. context = CreateContextObj(OrgID);
  59. //给传入参数赋值
  60. //服务调用
  61. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  62. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  63. UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] queryArr = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] { };
  64. List<UFIDAU9CBOPubControllerCommonArchiveDataDTOData> queryList = new List<UFIDAU9CBOPubControllerCommonArchiveDataDTOData>();
  65. UFIDAU9CBOPubControllerCommonArchiveDataDTOData q = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  66. foreach (ICSOtherOutDoc Info in infos)
  67. {
  68. string DocNo = "";
  69. string sql = @"SELECT DocNO FROM InvDoc_MiscShip a WHERE a.ID='" + Info.ID + "' AND Org='" + OrgID + "'";
  70. DataTable dt = DBHelper.Query(sql, connString);
  71. if (dt != null && dt.Rows.Count > 0)
  72. {
  73. string a = dt.Rows[0][0].ToString();
  74. if (string.IsNullOrWhiteSpace(a))
  75. {
  76. throw new Exception("传入单据ID有误,请确认!");
  77. }
  78. else
  79. {
  80. DocNo = a;
  81. }
  82. }
  83. else
  84. {
  85. throw new Exception("传入单据ID有误,请确认!");
  86. }
  87. q.m_iD = long.Parse(Info.ID);
  88. q.m_code = DocNo;
  89. queryList.Add(q);
  90. }
  91. queryArr = queryList.ToArray();
  92. returnItems = client.Do(out returnMsg, context, queryArr);
  93. ResultFlag = true;
  94. }
  95. catch (Exception ex)
  96. {
  97. log.Error(GetExceptionMessage(ex));
  98. throw new Exception(GetExceptionMessage(ex));
  99. }
  100. return ResultFlag;
  101. }
  102. /// <summary>
  103. /// 审核杂发单(接口内部调用,如:创建退料单后调用审核单据)
  104. /// </summary>
  105. /// <param name="DocNOList"></param>
  106. /// <param name="OrgCode"></param>
  107. /// <returns></returns>
  108. public bool Approve(List<string> DocIDList, string OrgCode)
  109. {
  110. bool ResultFlag = false;
  111. UFIDAU9ISVMiscShipISVICommonApproveMiscShipSVClient client = new UFIDAU9ISVMiscShipISVICommonApproveMiscShipSVClient();
  112. //返回异常信息,目前还没有使用此属性
  113. MessageBase[] returnMsg;
  114. //上下文信息
  115. object context;
  116. //传入 参数
  117. try
  118. {
  119. if (DocIDList == null || DocIDList.Count == 0)
  120. {
  121. throw new Exception("传入数据不能为空!");
  122. }
  123. string OrgID = "";
  124. string orgsql = @"select ID from Base_Organization
  125. where Code='{0}'";
  126. orgsql = string.Format(orgsql, OrgCode);
  127. DataTable orgdt = DBHelper.Query(orgsql, connString);
  128. if (orgdt.Rows.Count != 0)
  129. {
  130. OrgID = orgdt.Rows[0]["ID"].ToString();
  131. }
  132. else
  133. {
  134. throw new Exception("传入组织编码错误!");
  135. }
  136. UFIDAU9ISVMiscShipISVIC_MiscShipmentDTOData[] returnItems;
  137. //给上下文信息赋值
  138. context = CreateContextObj(OrgID);
  139. //给传入参数赋值
  140. //服务调用
  141. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  142. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  143. UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] queryArr = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] { };
  144. List<UFIDAU9CBOPubControllerCommonArchiveDataDTOData> queryList = new List<UFIDAU9CBOPubControllerCommonArchiveDataDTOData>();
  145. UFIDAU9CBOPubControllerCommonArchiveDataDTOData q = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  146. foreach (string ID in DocIDList)
  147. {
  148. string DocNo = "";
  149. string sql = @"SELECT DocNO FROM InvDoc_MiscShip a WHERE a.ID='" + ID + "' AND Org='" + OrgID + "'";
  150. DataTable dt = DBHelper.Query(sql, connString);
  151. if (dt != null && dt.Rows.Count > 0)
  152. {
  153. string a = dt.Rows[0][0].ToString();
  154. if (string.IsNullOrWhiteSpace(a))
  155. {
  156. throw new Exception("传入单据ID有误,请确认!");
  157. }
  158. else
  159. {
  160. DocNo = a;
  161. }
  162. }
  163. else
  164. {
  165. throw new Exception("传入单据ID有误,请确认!");
  166. }
  167. q.m_iD = long.Parse(ID);
  168. q.m_code = DocNo;
  169. queryList.Add(q);
  170. }
  171. queryArr = queryList.ToArray();
  172. returnItems = client.Do(out returnMsg, context, queryArr);
  173. ResultFlag = true;
  174. }
  175. catch (Exception ex)
  176. {
  177. log.Error(GetExceptionMessage(ex));
  178. throw new Exception(GetExceptionMessage(ex));
  179. }
  180. return ResultFlag;
  181. }
  182. #region 给上下文信息赋值
  183. /// <summary>
  184. /// 给上下文信息赋值
  185. /// </summary>
  186. /// <returns></returns>
  187. private static ThreadContext CreateContextObj(string OrgID)
  188. {
  189. // 实例化应用上下文对象
  190. ThreadContext thContext = new ThreadContext();
  191. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  192. ns.Add("OrgID", OrgID);
  193. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  194. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  195. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  196. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  197. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  198. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  199. thContext.nameValueHas = ns;
  200. return thContext;
  201. }
  202. #endregion
  203. #region 提取异常信息
  204. /// <summary>
  205. /// 提取异常信息
  206. /// </summary>
  207. /// <param name="ex"></param>
  208. private string GetExceptionMessage(Exception ex)
  209. {
  210. string faultMessage = "未知错误,请查看ERP日志!";
  211. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  212. if (timeoutEx != null)
  213. {
  214. faultMessage = "访问服务超时,请修改配置信息!";
  215. }
  216. else
  217. {
  218. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  219. if (faultEx == null)
  220. {
  221. faultMessage = ex.Message;
  222. }
  223. else
  224. {
  225. ServiceException serviceEx = faultEx.Detail;
  226. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  227. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  228. {
  229. // 错误信息在faultEx.Message中,请提取,
  230. // 格式为"Fault:料品不能为空,请录入\n 在....."
  231. int startIndex = serviceEx.Message.IndexOf(":");
  232. int endIndex = serviceEx.Message.IndexOf("\n");
  233. if (endIndex == -1)
  234. endIndex = serviceEx.Message.Length;
  235. if (endIndex > 0 && endIndex > startIndex + 1)
  236. {
  237. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  238. }
  239. else
  240. {
  241. faultMessage = serviceEx.Message;
  242. }
  243. }
  244. }
  245. }
  246. return faultMessage;
  247. }
  248. #endregion
  249. }
  250. }