圣珀
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.

393 lines
18 KiB

2 years ago
2 years ago
2 years ago
  1. using ICS.WCF.Base;
  2. using ICSSoft.Entity;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Configuration;
  6. using System.Data;
  7. using System.Linq;
  8. using System.ServiceModel;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using UFSoft.UBF.Exceptions1;
  12. using UFSoft.UBF.Service;
  13. using UFSoft.UBF.Util.Context;
  14. using www.ufida.org.EntityData;
  15. namespace ICS.CreateSMShip
  16. {
  17. public class CreateSMShip
  18. {
  19. private static string ORGCode = ConfigurationManager.AppSettings["orgCode"].ToString();
  20. public OperationResult CustCreateSMShip(List<SMShip> modellist)
  21. {
  22. OperationResult result = new OperationResult();
  23. //object context = new object();
  24. try
  25. {
  26. StringBuilder beginstrlog = new StringBuilder();
  27. beginstrlog.AppendLine("创建委外备料单(传入数据开始)");
  28. beginstrlog.AppendLine("*****************************************************");
  29. foreach (var model in modellist)
  30. {
  31. //beginstrlog.AppendLine("生产订单:" + model.MOCODE);
  32. //foreach (var item in model.linelist)
  33. //{
  34. // beginstrlog.AppendLine("行号:" + item.DOCLINENO);
  35. // beginstrlog.AppendLine("料号:" + item.ITEM);
  36. // beginstrlog.AppendLine("实际需求数量:" + item.ActualReqQty);
  37. // beginstrlog.AppendLine("标准用量:" + item.STDReqQty);
  38. //}
  39. beginstrlog.AppendLine("--------------------------------------------------");
  40. }
  41. beginstrlog.AppendLine("*****************************************************");
  42. beginstrlog.AppendLine("创建委外备料单(传入数据结束)");
  43. Appconfig.WriteLogFile(beginstrlog.ToString(), "创建委外备料单");
  44. string _MOCode = string.Empty;
  45. UFIDAU9ISVSMISMPullSrcDocSVClient client = new UFIDAU9ISVSMISMPullSrcDocSVClient();
  46. MessageBase[] message = null;
  47. StringBuilder str = new StringBuilder();
  48. string OrgID = "";
  49. OrgID = Appconfig.IsExistsCode(ORGCode, "Base_Organization");
  50. if (string.IsNullOrEmpty(OrgID))
  51. {
  52. throw new Exception("组织编码:" + ORGCode + "在U9中不存在。");
  53. }
  54. ThreadContext context = CreateContextObj(OrgID);
  55. //context = CreateContextObj(OrgID);
  56. //UFIDAU9ISVMOIssueKeyDTOData[] _result = null;
  57. long shipDocTypeID = 1002303100391036;
  58. DateTime shipDate = DateTime.Now;
  59. List<UFIDAU9ISVSMSrcDocInfoDTOData> list = new List<UFIDAU9ISVSMSrcDocInfoDTOData>();
  60. foreach (var item in modellist)
  61. {
  62. UFIDAU9ISVSMSrcDocInfoDTOData model = new UFIDAU9ISVSMSrcDocInfoDTOData();
  63. model.m_curShipQty1 = item.CurShipQty1;
  64. model.m_sOIsConsign = true;
  65. model.m_srcDocType = item.SrcDocType;
  66. string SrcID = Appconfig.GetSOLineID(item.SrcDocNo, item.SrcDocLineNo,item.SrcDocSubLineNo);
  67. string _OrgID = Appconfig.GetOrgID(item.SrcDocNo, item.SrcDocLineNo);
  68. if (!string.IsNullOrWhiteSpace(SrcID))
  69. {
  70. model.m_srcDocLineID = long.Parse(SrcID);
  71. }
  72. else
  73. {
  74. //_result.Message = "传入销售订单信息有误,请核对";
  75. //_result.IsSuccess = false;
  76. //str = JsonConvert.SerializeObject(_result);
  77. //result.Content = new StringContent(str.ToString(), Encoding.GetEncoding("UTF-8"), "application/json");
  78. //Appconfig.WriteLogFile(str.ToString(), "创建标准出货单异常日志");
  79. //return result;
  80. }
  81. string WHID = Appconfig.GetWhIDByCode(item.WH, OrgID);
  82. model.m_wH = long.Parse(WHID);
  83. list.Add(model);
  84. }
  85. long[] IDD = client.Do(out message, context, shipDocTypeID, shipDate, list.ToArray());
  86. List<string> LLCodeList = new List<string>();
  87. StringBuilder endstr = new StringBuilder();
  88. endstr.AppendLine("**************创建委外备料单返回日志******************");
  89. //if (_result != null && _result.Count() > 0)
  90. //{
  91. // for (int i = 0; i < _result.Count(); i++)
  92. // {
  93. // LLCodeList.Add(_result[i].ToString());
  94. // endstr.AppendLine("退料单号" + _result[i].ToString());
  95. // }
  96. //}
  97. endstr.AppendLine("**************创建委外备料单返回日志结束******************");
  98. Appconfig.WriteLogFile(endstr.ToString(), "创建委外备料单");
  99. }
  100. catch (Exception ex)
  101. {
  102. string Message = GetExceptionMessage(ex);
  103. result.IsSuccess = false;
  104. result.MESSAGE += Message;
  105. StringBuilder str = new StringBuilder();
  106. str.AppendLine("创建委外备料单:");
  107. //for (int i = 0; i < modellist.Count(); i++)
  108. //{
  109. // str.AppendLine("单号:" + modellist[i]);
  110. //}
  111. str.AppendLine("返回错误信息:" + result.MESSAGE);
  112. Appconfig.WriteLogFile(str.ToString(), "创建委外备料单");
  113. }
  114. return result;
  115. }
  116. // private UFIDAU9ISVMOIssueDTOData[] createiss(List<IssueData> modellist, string OrgID)
  117. // {
  118. // List<UFIDAU9ISVMOIssueDTOData> lsslist = new List<UFIDAU9ISVMOIssueDTOData>();
  119. // foreach (IssueData model in modellist)
  120. // {
  121. // string moid = "";
  122. // UFIDAU9ISVMOIssueDTOData lss = new UFIDAU9ISVMOIssueDTOData();
  123. // if (!string.IsNullOrWhiteSpace(model.MOCODE))
  124. // {
  125. // string orgsql = @"select ID from MO_MO
  126. // where DocNo='{0}'";
  127. // orgsql = string.Format(orgsql, model.MOCODE);
  128. // DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
  129. // if (orgdt.Rows.Count != 0)
  130. // {
  131. // moid = orgdt.Rows[0]["ID"].ToString();
  132. // }
  133. // else
  134. // throw new Exception("工单:" + model.MOCODE + "不存在!");
  135. // List<UFIDAU9CBOPubControllerCommonArchiveDataDTOData> molst = new List<UFIDAU9CBOPubControllerCommonArchiveDataDTOData>();
  136. // UFIDAU9CBOPubControllerCommonArchiveDataDTOData mo1 = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  137. // mo1.m_iD = Convert.ToInt64(moid);
  138. // mo1.m_code = model.MOCODE;
  139. // molst.Add(mo1);
  140. // lss.m_mOs = molst.ToArray();
  141. // UFIDAU9CBOPubControllerCommonArchiveDataDTOData d = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  142. // d.m_iD = Convert.ToInt64(OrgID);
  143. // d.m_code = ORGCode;
  144. // lss.m_issueOrg = d;
  145. // List<UFIDAU9ISVMOPickListDTOData> picklst = new List<UFIDAU9ISVMOPickListDTOData>();
  146. // UFIDAU9ISVMOPickListDTOData pick = new UFIDAU9ISVMOPickListDTOData();
  147. // foreach (IssueDatas line in model.linelist)
  148. // {
  149. // string ORGID = Appconfig.IsExistsCode(line.ORGCODE, "Base_Organization");
  150. // if (string.IsNullOrEmpty(ORGID))
  151. // {
  152. // throw new Exception("组织编码:" + line.ORGCODE + "在U9中不存在。");
  153. // }
  154. // pick.m_aCDType = 0;
  155. // //无备料领料
  156. // pick.m_isNoPickLine = true;
  157. // //生产订单
  158. // UFIDAU9CBOPubControllerCommonArchiveDataDTOData mo = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  159. // mo.m_iD = Convert.ToInt64(moid);
  160. // mo.m_code = model.MOCODE;
  161. // pick.m_mO = mo;
  162. // // 料品
  163. // string itemid = "";
  164. // orgsql = @"select id from CBO_ItemMaster where code=='{0}'";
  165. // orgsql = string.Format(orgsql, line.ITEM);
  166. // orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
  167. // if (orgdt.Rows.Count != 0)
  168. // itemid = orgdt.Rows[0]["ID"].ToString();
  169. // else
  170. // throw new Exception("料品:" + line.ITEM + "不存在!");
  171. // UFIDAU9CBOPubControllerCommonArchiveDataDTOData item = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  172. // mo.m_iD = Convert.ToInt64(itemid);
  173. // mo.m_code = line.ITEM;
  174. // pick.m_item = item;
  175. // //领料单位
  176. // if (Appconfig.uomid(line.UOM) != "")
  177. // {
  178. // UFIDAU9CBOPubControllerCommonArchiveDataDTOData uom = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  179. // mo.m_iD = Convert.ToInt64(Appconfig.uomid(line.UOM));
  180. // mo.m_code = line.UOM;
  181. // pick.m_issueUOM = uom;
  182. // }
  183. // //发料数量
  184. // pick.m_issuedQty = Convert.ToDecimal(line.ActualReqQty);
  185. // // 应发数量
  186. // pick.m_issueQty = Convert.ToDecimal(line.ActualReqQty);
  187. // //存储地点
  188. // if (string.IsNullOrWhiteSpace(line.WH))
  189. // {
  190. // throw new Exception("第 " + line.DOCLINENO + " 行,请传入仓库 ");
  191. // }
  192. // if (Appconfig.GetWhCodeByBinid(line.WH, ORGID) != "")
  193. // {
  194. // UFIDAU9CBOPubControllerCommonArchiveDataDTOData ww = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  195. // mo.m_iD = Convert.ToInt64(Appconfig.GetWhCodeByBinid(line.WH, ORGID));
  196. // mo.m_code = line.WH;
  197. // pick.m_issueWh = ww;
  198. // }
  199. // UFIDAU9CBOPubControllerCommonArchiveDataDTOData org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  200. // mo.m_iD = Convert.ToInt64(ORGID);
  201. // mo.m_code = line.ORGCODE;
  202. // pick.m_ownerOrg = org;
  203. // //库位
  204. // //子料项目号
  205. // if (!string.IsNullOrEmpty(line.Project))
  206. // {
  207. // if (Appconfig.GetProjectid(line.Project, ORGID) != "")
  208. // {
  209. // UFIDAU9CBOPubControllerCommonArchiveDataDTOData project = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  210. // mo.m_iD = Convert.ToInt64(Appconfig.GetProjectid(line.Project, ORGID));
  211. // mo.m_code = line.Project;
  212. // pick.m_project = project;
  213. // }
  214. // }
  215. // pick.m_issueDocLineID = 1;
  216. // picklst.Add(pick);
  217. // }
  218. // lss.m_pickListDTOs = picklst.ToArray();
  219. // lsslist.Add(lss);
  220. // }
  221. // else
  222. // {
  223. // throw new Exception("存在生产订单号为空!");
  224. // }
  225. // }
  226. // return lsslist.ToArray();
  227. // }
  228. # region 辅助方法
  229. /// <summary>
  230. /// 创建上下文
  231. /// </summary>
  232. /// <returns></returns>
  233. //private static object CreateContextObj(string OrgID)
  234. //{
  235. // // 实例化应用上下文对象
  236. // object thContext = new object();
  237. // System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  238. // ns.Add("OrgID", OrgID);
  239. // ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  240. // ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  241. // ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  242. // ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  243. // ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  244. // ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  245. // thContext = ns;
  246. // return thContext;
  247. //}
  248. private static ThreadContext CreateContextObj(string OrgID)
  249. {
  250. // 实例化应用上下文对象
  251. ThreadContext thContext = new ThreadContext();
  252. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  253. ns.Add("OrgID", OrgID);
  254. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  255. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  256. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  257. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  258. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  259. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  260. thContext.nameValueHas = ns;
  261. return thContext;
  262. }
  263. # endregion
  264. #region 提取异常信息
  265. /// <summary>
  266. /// 提取异常信息
  267. /// </summary>
  268. /// <param name="ex"></param>
  269. private static string GetExceptionMessage(Exception ex)
  270. {
  271. string faultMessage = "未知错误,请查看ERP日志!";
  272. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  273. if (timeoutEx != null)
  274. {
  275. faultMessage = "访问服务超时,请修改配置信息!";
  276. }
  277. else
  278. {
  279. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  280. if (faultEx == null)
  281. {
  282. faultMessage = ex.Message;
  283. }
  284. else
  285. {
  286. ServiceException serviceEx = faultEx.Detail;
  287. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  288. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  289. {
  290. // 错误信息在faultEx.Message中,请提取,
  291. // 格式为"Fault:料品不能为空,请录入\n 在....."
  292. int startIndex = serviceEx.Message.IndexOf(":");
  293. int endIndex = serviceEx.Message.IndexOf("\n");
  294. if (endIndex == -1)
  295. endIndex = serviceEx.Message.Length;
  296. if (endIndex > 0 && endIndex > startIndex + 1)
  297. {
  298. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  299. }
  300. else
  301. {
  302. faultMessage = serviceEx.Message;
  303. }
  304. }
  305. }
  306. }
  307. return faultMessage;
  308. }
  309. #endregion
  310. public class OperationResult
  311. {
  312. /// <summary>
  313. /// 结果状态,默认值false
  314. /// </summary>
  315. public bool IsSuccess { get; set; }
  316. /// <summary>
  317. ///处理消息
  318. /// </summary>
  319. public string MESSAGE { get; set; }
  320. /// <summary>
  321. /// 输出领料订单
  322. /// </summary>
  323. public string LLCode { get; set; }
  324. }
  325. public class IssueData
  326. {
  327. public string MOCODE { get; set; }
  328. public string DOCNO { get; set; }
  329. public List<IssueDatas> linelist { get; set; }
  330. }
  331. public class IssueDatas
  332. {
  333. public string ORGCODE { get; set; }
  334. public string DOCLINENO { get; set; }
  335. public string ITEM { get; set; }
  336. public string UOM { get; set; }
  337. public string Project { get; set; }
  338. public string WH { get; set; }
  339. public decimal ActualReqQty { get; set; }
  340. public decimal STDReqQty { get; set; }
  341. }
  342. }
  343. }