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

434 lines
18 KiB

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