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

114 lines
5.1 KiB

3 years ago
  1. using ICSSoft.Entity;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using Newtonsoft.Json;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using ICSSoft.Common;
  11. namespace ICSSoft.DataProject
  12. {
  13. public class CreateWareHouseLotInfo
  14. {
  15. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  16. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
  17. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  18. //参数示例
  19. //[{
  20. // "LotNO": "PO200219004100005",
  21. // "BinCode": "MAT-BLCA03601",
  22. // "LotQty": "11",
  23. // "User": "CC001",
  24. // "MTime": "2021-08-26 17:20:13",
  25. // "ReturnDoc": "U8000000001",
  26. // "ReturnDocLine": "10"
  27. //}]
  28. //返回参数
  29. //{
  30. //"Success": true,
  31. //"Message": "接口调用成功!",
  32. //"Data": null
  33. //}
  34. /// <summary>
  35. /// 生成条码上架入库
  36. /// </summary>
  37. /// <param name="infos"></param>
  38. /// <returns></returns>
  39. public string Create(List<ICSWareHouseLotInfo> infos)
  40. {
  41. if (infos.Count <= 0)
  42. {
  43. throw new Exception("传送数据为空!");
  44. }
  45. string res = string.Empty;
  46. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  47. conn.Open();
  48. SqlTransaction sqlTran = conn.BeginTransaction();
  49. SqlCommand cmd = new SqlCommand();
  50. cmd.Transaction = sqlTran;
  51. cmd.Connection = conn;
  52. try
  53. {
  54. string sql = string.Empty;
  55. foreach (ICSWareHouseLotInfo info in infos)
  56. {
  57. if (info.MTime < new DateTime(2000, 01, 01))
  58. throw new Exception("请输入正确的操作时间:" + info.MTime);
  59. sql = @" insert into ICSWareHouseLotInfo(ID,LotNO,WHGUID,WHCode,BinGUID,BinCode,INVGUID,INVCode,LotQty,ReceiveDate,MUSER,MTIME,WorkPoint,MUSERName)
  60. select newid(),'{0}',d.Serial,d.StorageCode,e.Serial,'{1}',f.ID,c.ItemCode,'{2}',getdate(),'{3}','{4}',a.WorkPoint,USERName
  61. from ICSPOArrive a --
  62. left join ICSASNDetail b on a.STNO=b.STNO and a.WorkPoint=b.WorkPoint --
  63. left join ICSITEMLot c on b.LOTNO=c.LotNO and b.WorkPoint=c.WorkPoint --
  64. left join ICSINVENTORY f on c.ItemCode=f.INVCODE and c.WorkPoint= f.WorkPoint --
  65. left join ICSStorage d on a.cWhCode=d.StorageCode and a.WorkPoint=d.WorkPoint --
  66. left join ICSStack e on d.Serial=e.Storage_Serial and d.WorkPoint=e.WorkPoint --
  67. inner join dbo. Sys_User on USERCODE='{3}'
  68. where c.LotNO='{0} 'and e.StackCode='{1}'
  69. --
  70. insert into ICSWareHouseLotInfoLog(ID,TransNO,TransLine,ITEMCODE,LotNO,TOStorageCODE,TOStackCODE,TransQTY,MUSER,MTIME,WorkPoint,MUSERName,TransType,BusinessCode,ReturnDoc,ReturnDocLine)
  71. select newid(),c.TransNO,c.TransLine,c.ItemCODE,'{0}',d.StorageCode,'{1}','{2}','{3}','{4}',a.WorkPoint ,USERName,'收','','{5}','{6}'
  72. from ICSPOArrive a --
  73. left join ICSASNDetail b on a.STNO=b.STNO and a.WorkPoint=b.WorkPoint --
  74. left join ICSITEMLot c on b.LOTNO=c.LotNO and b.WorkPoint=c.WorkPoint --
  75. left join ICSINVENTORY f on c.ItemCode=f.INVCODE and c.WorkPoint= f.WorkPoint --
  76. left join ICSStorage d on a.cWhCode=d.StorageCode and a.WorkPoint=d.WorkPoint --
  77. left join ICSStack e on d.Serial=e.Storage_Serial and d.WorkPoint=e.WorkPoint --
  78. inner join dbo. Sys_User on USERCODE='{3}'
  79. where c.LotNO='{0} ' and e.StackCode='{1}' ";
  80. sql = string.Format(sql, info.LotNO, info.BinCode, info.LotQty, info.User ,info.MTime,info.ReturnDoc,info.ReturnDocLine);
  81. DBHelper.CmdExecuteNonQuery(sql, cmd, "条码:" + info.LotNO + "未查询到对应数据!");
  82. }
  83. cmd.Transaction.Commit();
  84. return res;
  85. }
  86. catch (Exception ex)
  87. {
  88. cmd.Transaction.Rollback();
  89. log.Error(ex.Message);
  90. throw new Exception(ex.Message);
  91. }
  92. finally
  93. {
  94. if (conn.State == ConnectionState.Open)
  95. {
  96. conn.Close();
  97. }
  98. conn.Dispose();
  99. }
  100. }
  101. }
  102. }