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

120 lines
5.2 KiB

8 months ago
  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Data;
  4. using NFine.Code;
  5. using NFine.Repository;
  6. using NFine.Domain._03_Entity.SRM;
  7. using System.Data.SqlClient;
  8. using System.Text;
  9. namespace NFine.Application.WMS
  10. {
  11. public class UpdateBinCodeApp : RepositoryFactory<ICSVendor>
  12. {
  13. public string SetData_PR(String savePath, string Year)
  14. {
  15. //数据获取
  16. try
  17. {
  18. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  19. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  20. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  21. SqlConnection conn = SqlHelper.GetDataCenterConn();
  22. DataTable data = FileToExcel.ExcelToTable(savePath);
  23. string sql1 = "";
  24. if (data != null && data.Rows.Count > 0)
  25. {
  26. foreach (DataRow dr in data.Rows)
  27. {
  28. string lotno = dr["物料条码"].ToString().ToUpper();
  29. string binCode = dr["库位"].ToString().ToUpper();
  30. //查询条码是否存在,并且获取条码初始仓库
  31. string sql = $@"SELECT WarehouseCode, LocationCode,LotNo FROM ICSWareHouseLotInfo WHERE LotNo='{lotno}' AND WorkPoint='{WorkPoint}' ";
  32. DataTable dataset = Repository().FindDataSetBySql(sql).Tables[0];
  33. if (dataset.Rows.Count == 0)
  34. {
  35. return "条码" + lotno + "不存在";
  36. }
  37. else
  38. {
  39. //查询修改的库位
  40. string binSql = $@"SELECT WarehouseCode,LocationCode FROM ICSLocation a
  41. LEFT JOIN ICSWarehouse b ON a.WHID=b.ID AND a.WorkPoint=b.WorkPoint
  42. WHERE a.LocationCode='{binCode}' AND a.WorkPoint='{WorkPoint}' ";
  43. DataTable binDt = Repository().FindDataSetBySql(binSql).Tables[0];
  44. if (binDt.Rows.Count == 0)
  45. {
  46. return "库位" + binCode + "不存在";
  47. }
  48. else
  49. {
  50. string newWHCode = binDt.Rows[0]["WarehouseCode"].ToString().ToUpper();
  51. if (newWHCode != dataset.Rows[0]["WarehouseCode"].ToString().ToUpper())
  52. {
  53. return "条码" + lotno + "原仓库" + dataset.Rows[0]["WarehouseCode"].ToString().ToUpper() + "和修改后仓库" + newWHCode + "不一致";
  54. }
  55. else
  56. {
  57. ///添加日志
  58. sql1 += @"
  59. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  60. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  61. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  62. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  63. MTIME,WorkPoint,EATTRIBUTE1)
  64. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  65. c.WarehouseCode,c.LocationCode,'{8}','{9}',c.Quantity,
  66. '','0','{6}','{7}','0','',
  67. '','','',f.F_Account ,f.F_RealName ,
  68. SYSDATETIME() ,a.WorkPoint ,''
  69. FROM ICSInventoryLot a
  70. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  71. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  72. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  73. ";
  74. ///修改库位
  75. sql1 += @" UPDATE ICSWareHouseLotInfo SET WarehouseCode='{8}',LocationCode='{9}' WHERE LotNo='{0}' AND WorkPoint='{1}' ";
  76. sql1 = string.Format(sql1, lotno, WorkPoint, MUSER, Guid.NewGuid().ToString(), "", "", "7", "29", newWHCode, binCode);
  77. }
  78. }
  79. }
  80. }
  81. if (!string.IsNullOrWhiteSpace(sql1))
  82. {
  83. StringBuilder sqlb = new StringBuilder(sql1);
  84. Repository().ExecuteBySql(sqlb);
  85. }
  86. }
  87. else
  88. {
  89. return "无有效的导入数据。";
  90. }
  91. return "true";
  92. }
  93. catch (Exception ex)
  94. {
  95. return ex.Message;
  96. }
  97. }
  98. public string GetNewid()
  99. {
  100. string sql = "select newid() AS ID";
  101. return Repository().FindTableBySql(sql, null).Rows[0]["ID"].ToString();
  102. }
  103. }
  104. }