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

377 lines
14 KiB

2 years ago
  1. 
  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 ICS.WCF.Base;
  11. using UFIDA.U9.ISV.Mobile.TransferInISV;
  12. using UFSoft.UBF.Service;
  13. namespace ICS.CreateTransInDoc
  14. {
  15. public class CreateTransInDoc
  16. {
  17. private static string ORGCode = ConfigurationManager.AppSettings["orgCode"].ToString();
  18. private static string ERPConStr = Appconfig.GetU9ConnStr();
  19. private static string UserCode = ConfigurationManager.AppSettings["userCode"].ToString();
  20. public static ReturnValue CustCreatePR(List<ITEMREQDATA> PRList)
  21. {
  22. #region 服务调用框架结构
  23. //实例化代理类 UFIDAU9ISVItemIBatchCreateItemByDTOSRVClient
  24. CreateTransferInRestSVClient client = new CreateTransferInRestSVClient();
  25. //服务返回结果
  26. //UFIDAU9ISVPRSVPRBizKeyDTOData[] returnItems;
  27. TransInRestResultDTOData[] returnItems;
  28. //返回异常信息,目前还没有使用此属性
  29. //UFSoft.UBF.Exceptions1.MessageBase[] returnMsg;
  30. //上下文信息
  31. ISVContext context;
  32. //传入 参数
  33. string[] splitBy = new string[] { };
  34. try
  35. {
  36. if (PRList == null || PRList.Count == 0)
  37. {
  38. throw new Exception("传入数据为空");
  39. }
  40. string ORGID = "";
  41. string OrgCode = "";
  42. ORGID = Appconfig.IsExistsCode(ORGCode, "Base_Organization");
  43. if (string.IsNullOrEmpty(ORGID))
  44. {
  45. throw new Exception("组织编码:" + ORGCode + "在U9中不存在。");
  46. }
  47. //给上下文信息赋值
  48. context = CreateContextObj(ORGID);
  49. //给传入参数赋值
  50. TransInRestInputDTOData[] itemDatas = setDataForItem(PRList, ORGID, ORGCode);
  51. //服务调用
  52. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  53. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  54. returnItems = client.Do(context, itemDatas.ToArray(), 0,false);
  55. foreach (TransInRestResultDTOData data in returnItems)
  56. {
  57. StringBuilder str = new StringBuilder();
  58. str.AppendLine("创建U9调入单");
  59. str.AppendLine("单号:" + data.DocNo);
  60. Appconfig.WriteLogFile(str.ToString(), "创建U9调入单");
  61. }
  62. ReturnValue value = new ReturnValue();
  63. value.IsSuccess = true;
  64. value.Message = "调入单成功";
  65. List<RtnPRData> values = new List<RtnPRData>();
  66. int msgnumber = 0;
  67. foreach (TransInRestResultDTOData data in returnItems)
  68. {
  69. msgnumber++;
  70. if (msgnumber != 1)
  71. {
  72. continue;
  73. }
  74. RtnPRData prvalue = new RtnPRData();
  75. prvalue.DocNo = data.DocNo;
  76. prvalue.msg = data.SyncErrMsg;
  77. if (prvalue.msg != null)
  78. {
  79. value.IsSuccess = false;
  80. value.Message = "调入单失败";
  81. }
  82. values.Add(prvalue);
  83. }
  84. value.PRList = values;
  85. Appconfig.WriteLogFile("成功", "创建U9调入单");
  86. return value;
  87. }
  88. catch (Exception ex)
  89. {
  90. //异常信息捕获
  91. string HeadList = string.Empty;
  92. StringBuilder str = new StringBuilder();
  93. foreach (ITEMREQDATA data in PRList)
  94. {
  95. str.AppendLine("创建U9调入单");
  96. str.AppendLine(ex.ToString());
  97. HeadList += "\r\n 数量:" + data.TransferQty + ",调入仓库:" + data.TransInWh + ",库位:" + data.TransInBin + ",批号:" + data.LotCode + ",单位:" + data.Uom;
  98. HeadList += "\r\n 数量:" + data.TransferQty + ",调出仓库:" + data.TransOutWh + ",库位:" + data.TransOutBin + ",批号:" + data.LotCode + ",单位:" + data.Uom;
  99. }
  100. str.AppendLine(HeadList);
  101. str.AppendLine("结果:" + "False");
  102. Appconfig.WriteLogFile(str.ToString(), "创建U9调入单");
  103. ReturnValue value = new ReturnValue();
  104. value.IsSuccess = false;
  105. value.Message = ex.ToString();
  106. return value;
  107. }
  108. #endregion
  109. }
  110. #region 给上下文信息赋值1
  111. /// <summary>
  112. /// 给上下文信息赋值
  113. /// </summary>
  114. /// <returns></returns>
  115. private static ISVContext CreateContextObj(string ORGID)
  116. {
  117. // 实例化应用上下文对象
  118. ISVContext isvContext = new ISVContext();
  119. isvContext.OrgID = Convert.ToInt64(ORGID);
  120. isvContext.OrgCode = ORGCode;
  121. isvContext.UserCode = UserCode;
  122. isvContext.EntCode = ConfigurationManager.AppSettings["enterpriseID"].ToString();
  123. return isvContext;
  124. }
  125. #endregion
  126. private static TransInRestInputDTOData[] setDataForItem(List<ITEMREQDATA> datas, string ORGID, string OrgCode)
  127. {
  128. int number = 0;
  129. List<TransInRestInputDTOData> prs = new List<TransInRestInputDTOData>();
  130. List<ItemCURR> lstitem = new List<ItemCURR>();
  131. foreach (ITEMREQDATA data in datas)
  132. {
  133. string INORGID = Appconfig.IsExistsCode(data.TransInOrg, "Base_Organization");
  134. if (string.IsNullOrEmpty(INORGID))
  135. {
  136. throw new Exception("调入组织编码:" + data.TransInOrg + "在U9中不存在。");
  137. }
  138. string OUTORGID = Appconfig.IsExistsCode(data.TransOutOrg, "Base_Organization");
  139. if (string.IsNullOrEmpty(OUTORGID))
  140. {
  141. throw new Exception("调入组织编码:" + data.TransOutOrg + "在U9中不存在。");
  142. }
  143. if (INORGID!=OUTORGID)
  144. {
  145. throw new Exception("调入组织不一致!请重新操作!");
  146. }
  147. ORGID = INORGID;
  148. ItemCURR item = new ItemCURR();
  149. if (lstitem.Count == 0)
  150. {
  151. item.BIN = data.TransOutBin;
  152. item.LOTNO = data.LotCode;
  153. item.ITEM = data.ItemMaster;
  154. item.WH = data.TransOutWh;
  155. item.ORG = data.TransOutOrg;
  156. item.QTY = 0;
  157. lstitem.Add(item);
  158. }
  159. else
  160. {
  161. int isrd = 0;
  162. foreach (ItemCURR item1 in lstitem)
  163. {
  164. if (item1.BIN == data.TransOutBin && item1.LOTNO == data.LotCode && item1.ITEM == data.ItemMaster && item1.WH == data.TransOutWh && item1.ORG == data.TransOutOrg)
  165. {
  166. isrd++;
  167. }
  168. }
  169. if (isrd == 0)
  170. {
  171. item.BIN = data.TransOutBin;
  172. item.LOTNO = data.LotCode;
  173. item.ITEM = data.ItemMaster;
  174. item.WH = data.TransOutWh;
  175. item.ORG = data.TransOutOrg;
  176. item.QTY = 0;
  177. lstitem.Add(item);
  178. }
  179. }
  180. }
  181. foreach (ITEMREQDATA data in datas)
  182. {
  183. foreach (ItemCURR item1 in lstitem)
  184. {
  185. if (item1.BIN == data.TransOutBin && item1.LOTNO == data.LotCode && item1.ITEM == data.ItemMaster && item1.WH == data.TransOutWh && item1.ORG == data.TransOutOrg)
  186. {
  187. item1.QTY += data.TransferQty;
  188. }
  189. }
  190. }
  191. string msg = "";
  192. foreach (ItemCURR item1 in lstitem)
  193. {
  194. DataTable request = Appconfig.GetItemRequestList(item1.LOTNO, item1.BIN, item1.ITEM, item1.WH, item1.QTY.ToString(), item1.ORG, ERPConStr);
  195. TransInRestInputDTOData pr = new TransInRestInputDTOData();
  196. if (request != null && request.Rows.Count > 0)
  197. {
  198. string ky = request.Rows[0]["可用量"].ToString();
  199. if (Convert.ToDecimal(ky) < 0)
  200. {
  201. msg += "组织:" + item1.ORG + ",料号:" + item1.ITEM
  202. + @",存储地点:" + item1.WH + ",库位:" + item1.BIN + ",批号:" + item1.LOTNO + "可用量不足;";
  203. }
  204. }
  205. else
  206. {
  207. msg += "组织:" + item1.ORG + ",料号:" + item1.ITEM
  208. + @",存储地点:" + item1.WH + ",库位:" + item1.BIN + ",批号:" + item1.LOTNO + "没有可以用量;";
  209. }
  210. }
  211. if (msg != "")
  212. {
  213. throw new Exception("料品需求单:" + msg + "");
  214. }
  215. foreach (ITEMREQDATA data in datas)
  216. {
  217. number++;
  218. TransInRestInputDTOData pr = new TransInRestInputDTOData();
  219. if (Appconfig.Getusername(data.CreatedBy) != null)
  220. pr.CreatedBy = data.CreatedBy;//创建人
  221. else
  222. throw new Exception("用户:" + data.CreatedBy + "不存在");
  223. pr.DocTypeCode = data.DocTypeCode;
  224. string INORGID = Appconfig.IsExistsCode(data.TransInOrg, "Base_Organization");
  225. pr.TransInOrg = Convert.ToInt64(INORGID);
  226. string OUTORGID = Appconfig.IsExistsCode(data.TransOutOrg, "Base_Organization");
  227. pr.TransOutOrg = Convert.ToInt64(OUTORGID);
  228. pr.ItemMaster = Convert.ToInt64(Appconfig.ITEMMATERID(data.ItemMaster, ORGID));//料品
  229. pr.ItemBarCode = data.ItemBarCode;//料品条码
  230. pr.GroupFlag = data.GroupFlag;
  231. pr.OtherDesc = data.OtherDesc;
  232. if (Appconfig.GetMarkid(data.Mfc) != "")
  233. pr.Mfc = Convert.ToInt64(Appconfig.GetMarkid(data.Mfc));
  234. else
  235. pr.Mfc = 0;
  236. if (Appconfig.uomid(data.Uom) != "")
  237. pr.Uom = Convert.ToInt64(Appconfig.uomid(data.Uom));
  238. else
  239. throw new Exception("计量单位:" + data.Uom + "不存在");
  240. if (Appconfig.GetWhCodeByBinid(data.TransOutWh, ORGID) != "")
  241. pr.TransOutWh = Convert.ToInt64(Appconfig.GetWhCodeByBinid(data.TransOutWh, ORGID)); //调出仓库id
  242. else
  243. pr.TransOutWh = 0;
  244. if (Appconfig.GetWhCodeByBinid(data.TransInWh, ORGID) != "")
  245. pr.TransInWh = Convert.ToInt64(Appconfig.GetWhCodeByBinid(data.TransInWh, ORGID)); //调出仓库id
  246. else
  247. pr.TransInWh = 0;
  248. //throw new Exception("存储地点:" + data.Wh + "不存在");
  249. if (Appconfig.GetByBinid(data.TransOutBin, ORGID) != "")
  250. pr.TransOutBin = Convert.ToInt64(Appconfig.GetByBinid(data.TransOutBin, ORGID));
  251. else
  252. pr.TransOutBin = 0;
  253. if (Appconfig.GetByBinid(data.TransInBin, ORGID) != "")
  254. pr.TransInBin = Convert.ToInt64(Appconfig.GetByBinid(data.TransInBin, ORGID));
  255. else
  256. pr.TransInBin = 0;
  257. //throw new Exception("库位:" + data.Bin + "不存在");
  258. if (Appconfig.GetBysupid(data.Supplier, ORGID) != "")
  259. pr.Supplier = Convert.ToInt64(Appconfig.GetBysupid(data.Supplier, ORGID));
  260. else
  261. pr.Supplier = 0;
  262. //if (Appconfig.GetProjectid(data.Project, ORGID) != "")
  263. // pr.Project = Convert.ToInt64(Appconfig.GetProjectid(data.Project, ORGID));
  264. //else
  265. // pr.Project = 0;
  266. //throw new Exception("项目:" + data.Project + "不存在");
  267. //pr.SrcLineID = Convert.ToInt64(request.Rows[0]["id"].ToString());//行号
  268. //pr.ShipDate = data.ShipDate;//杂发时间
  269. pr.TransferQty = Convert.ToDecimal(data.TransferQty);//数量
  270. pr.LotCode = data.LotCode;
  271. prs.Add(pr);
  272. }
  273. return prs.ToArray();
  274. }
  275. #region 时间戳方法
  276. private DateTime TimestampToDateTime(long timestamp)
  277. {
  278. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  279. long lTime = timestamp * 10000000;
  280. TimeSpan nowTimeSpan = new TimeSpan(lTime);
  281. DateTime resultDateTime = dateTimeStart.Add(nowTimeSpan);
  282. return resultDateTime;
  283. }
  284. #endregion
  285. }
  286. public class ItemCURR
  287. {
  288. public string LOTNO { get; set; }//批号
  289. public string ORG { get; set; }//组织编码
  290. public string WH { get; set; }//仓库
  291. public string BIN { get; set; }//库位
  292. public string ITEM { get; set; }//物料
  293. public decimal QTY { get; set; }//数量
  294. }
  295. public class ItemRatio
  296. {
  297. public long ID { get; set; }//单位编码
  298. public string Code { get; set; }//单位编码
  299. public decimal Ratio { get; set; }//位数
  300. public int Precision { get; set; }//精度
  301. }
  302. }