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.

175 lines
7.7 KiB

1 year ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace ICSSoft.DataProject
  12. {
  13. public class ICSLibrary
  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. DataTable table = null;
  19. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  20. string sql = string.Empty;
  21. VerificationMethod verification = new VerificationMethod();//验证公共方法
  22. public object LibraryGet(ICSLibraryModel JsonData)
  23. {
  24. conn.Open();
  25. SqlTransaction sqlTran = conn.BeginTransaction();
  26. SqlCommand cmd = new SqlCommand();
  27. cmd.Transaction = sqlTran;
  28. cmd.Connection = conn;
  29. string jsonInfo;
  30. #region sql
  31. try
  32. {
  33. bool isBool= verification.isStockZero(JsonData.LotNo, JsonData.WorkPoint);
  34. if (isBool==true)
  35. {
  36. sql = @"select
  37. f.ContainerCODE,
  38. f.ContainerName,
  39. d.InvCode,
  40. d.InvName,
  41. d.InvStd,
  42. a.Quantity,
  43. d.InvUnit,
  44. d.AmountUnit,
  45. i.WarehouseCode,
  46. i.WarehouseName,
  47. q.LocationCode,
  48. q.LocationName,
  49. c.ProjectCode,
  50. c.BatchCode,
  51. c.Version,
  52. c.Brand,
  53. y.TransCode,--
  54. y.TransSequence,--
  55. a.LotNo,
  56. c.cFree1,
  57. c.cFree2,
  58. c.cFree3,
  59. c.cFree4,
  60. c.cFree5,
  61. c.cFree6,
  62. c.cFree7,
  63. c.cFree8,
  64. c.cFree9,
  65. c.cFree10
  66. from ICSWareHouseLotInfo a
  67. left join ICSInventoryLot b on a.LotNo=b.LotNo
  68. left join ICSExtension c on b.ExtensionID=c.id
  69. left join ICSInventory d on b.InvCode=d.InvCode
  70. left join ICSContainerLot e on e.LotNo=a.LotNo
  71. left join ICSContainer f on f.ContainerID= e.ID
  72. left join ICSLocation q on q.LocationCode=a.LocationCode
  73. left join ICSWarehouse i on i.ID=q.WHID
  74. left join ICSInventoryLotDetail y on y.LotNo=a.LotNo
  75. where a.LotNo='{0}' and a.WorkPoint='{1}'";
  76. sql = string.Format(sql, JsonData.LotNo, JsonData.WorkPoint);
  77. table = DBHelper.SQlReturnData(sql, cmd);
  78. if (table.Rows.Count > 0)
  79. {
  80. jsonInfo = JsonConvert.SerializeObject(table);
  81. var Library = JsonConvert.DeserializeObject(jsonInfo);
  82. return Library;
  83. }
  84. else
  85. {
  86. throw new Exception("暂无数据!");
  87. }
  88. }
  89. return null;
  90. }
  91. catch (Exception ex)
  92. {
  93. cmd.Transaction.Rollback();
  94. log.Error(ex.Message);
  95. throw new Exception(ex.Message);
  96. }
  97. finally
  98. {
  99. if (conn.State == ConnectionState.Open)
  100. {
  101. conn.Close();
  102. }
  103. conn.Dispose();
  104. }
  105. #endregion
  106. }
  107. public object LibraryUpdate(ICSLibraryModel JsonData)
  108. {
  109. conn.Open();
  110. SqlTransaction sqlTran = conn.BeginTransaction();
  111. SqlCommand cmd = new SqlCommand();
  112. cmd.Transaction = sqlTran;
  113. cmd.Connection = conn;
  114. //string jsonInfo;
  115. string sqlLog = string.Empty;
  116. ///修改库存表的库位
  117. sql = @"update ICSWareHouseLotInfo set WarehouseCode='{0}' ,LocationCode ='{1}' where LotNo='{2}' and WorkPoint='{3}'";
  118. sql = string.Format(sql,JsonData.WarehouseCode,JsonData.LocationCode,JsonData.LotNo,JsonData.WorkPoint);
  119. cmd.CommandText = sql;
  120. int PurchaseList= cmd.ExecuteNonQuery();//返回数量
  121. ///添加日志
  122. if (PurchaseList > 0)
  123. {
  124. sqlLog = @" INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  125. ([ID]
  126. ,[TransCode]
  127. ,[TransSequence]
  128. ,[LotNo]
  129. ,[InvCode]
  130. ,[FromWarehouseCode]
  131. ,[FromLocationCode]
  132. ,[ToWarehouseCode]
  133. ,[ToLocationCode]
  134. ,[Quantity]
  135. ,[Memo]
  136. ,[Lock]
  137. ,[TransType]
  138. ,[BusinessCode]
  139. ,[ERPID]
  140. ,[ERPDetailID]
  141. ,[ERPCode]
  142. ,[ERPSequence]
  143. ,[MUSER]
  144. ,[MUSERName]
  145. ,[MTIME]
  146. ,[WorkPoint]
  147. ,[EATTRIBUTE1])
  148. (select newid(),'{0}','{1}','{2}',a.InvCode ,' ', ' ','{3}','{4}',a.Quantity,' ','0','7','14',' ',' ',' ',' ','{5}',e.F_RealName,'{6}','{7}',' '
  149. from ICSWareHouseLotInfo a--
  150. left join Sys_SRM_User e on e.F_Account='{5}' and e.F_Location='{7}'
  151. where a.LotNo='{2}' and a. WorkPoint='{7}' )";
  152. sqlLog = string.Format(sqlLog, JsonData.TransCode, JsonData.TransSequence, JsonData.LotNo, JsonData.WarehouseCode,JsonData.LocationCode, JsonData.User, DateTime.Now, JsonData.WorkPoint);
  153. cmd.CommandText = sqlLog;
  154. int Purchase = cmd.ExecuteNonQuery();//返回数量
  155. if (Purchase>0)
  156. {
  157. cmd.Transaction.Commit();
  158. }
  159. else
  160. {
  161. cmd.Transaction.Rollback();
  162. }
  163. }
  164. return null;
  165. }
  166. }
  167. }