爱思开
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.

232 lines
10 KiB

2 years ago
  1. using ICSSoft.Common;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data.SqlClient;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using Newtonsoft.Json;
  10. using ICSSoft.Entity;
  11. namespace ICSSoft.DataProject
  12. {
  13. public class ICSQueryService
  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. #region 查询物料信息
  18. public static DataTable MaterialGet(ICSQueryModel JsonData)
  19. {
  20. var language = LanguageHelper.GetName("WMSAPIInfo");
  21. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  22. {
  23. conn.Open();
  24. SqlTransaction sqlTran = conn.BeginTransaction();
  25. SqlCommand cmd = new SqlCommand();
  26. cmd.Transaction = sqlTran;
  27. cmd.Connection = conn;
  28. try
  29. {
  30. string sql = @"IF NOT EXISTS ( SELECT LotNo FROM ICSInventoryLot WHERE LotNo = '{0}' AND WorkPoint = '{1}' )
  31. BEGIN
  32. SELECT a.InvCode,a.InvName,a.InvStd,b.LotNo,c.Quantity,a.InvUnit,d.WarehouseCode,d.WarehouseName,e.LocationCode,e.LocationName,f.ProjectCode,f.Brand,f.BatchCode,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  33. FROM
  34. ICSInventory a
  35. INNER JOIN ICSInventoryLot b ON b.InvCode = a.InvCode
  36. AND b.WorkPoint = a.WorkPoint
  37. INNER JOIN ICSWareHouseLotInfo c ON c.InvCode = b.InvCode
  38. AND c.WorkPoint = b.WorkPoint
  39. INNER JOIN ICSWarehouse d ON d.WarehouseCode = c.WarehouseCode
  40. AND d.WorkPoint = c.WorkPoint
  41. INNER JOIN ICSLocation e ON e.WHID = d.ID
  42. AND e.WorkPoint = d.WorkPoint
  43. INNER JOIN ICSExtension f ON f.ID = b.ExtensionID
  44. AND f.WorkPoint = e.WorkPoint
  45. WHERE
  46. a.InvCode = '{0}'
  47. AND a.WorkPoint = '{1}' RETURN
  48. END
  49. SELECT a.InvCode,a.InvName,a.InvStd,b.LotNo,c.Quantity,a.InvUnit,d.WarehouseCode,d.WarehouseName,e.LocationCode,e.LocationName,f.ProjectCode,f.Brand,f.BatchCode,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  50. FROM
  51. ICSInventory a
  52. INNER JOIN ICSInventoryLot b ON b.InvCode = a.InvCode
  53. AND b.WorkPoint = a.WorkPoint
  54. INNER JOIN ICSWareHouseLotInfo c ON c.InvCode = b.InvCode
  55. AND c.WorkPoint = b.WorkPoint
  56. INNER JOIN ICSWarehouse d ON d.WarehouseCode = c.WarehouseCode
  57. AND d.WorkPoint = c.WorkPoint
  58. INNER JOIN ICSLocation e ON e.WHID = d.ID
  59. AND e.WorkPoint = d.WorkPoint
  60. INNER JOIN ICSExtension f ON f.ID = b.ExtensionID
  61. AND f.WorkPoint = e.WorkPoint
  62. WHERE
  63. a.InvCode = ( SELECT InvCode FROM ICSInventoryLot WHERE LotNo = '{0}' AND WorkPoint = '{1}' )
  64. AND a.WorkPoint = '{1}'
  65. ";
  66. sql = string.Format(sql, JsonData.Material, JsonData.WorkPoint);
  67. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  68. cmd.Transaction.Commit();
  69. return data;
  70. }
  71. catch (Exception ex)
  72. {
  73. if (cmd.Transaction != null)
  74. cmd.Transaction.Rollback();
  75. log.Error(ex.Message);
  76. throw new Exception(ex.Message);
  77. }
  78. finally
  79. {
  80. if (conn.State == ConnectionState.Open)
  81. {
  82. conn.Close();
  83. }
  84. conn.Dispose();
  85. }
  86. }
  87. }
  88. #endregion
  89. #region 查询条码信息(库存)
  90. public static DataTable BarCodeGet(BarCodeModel JsonData)
  91. {
  92. var language = LanguageHelper.GetName("WMSAPIInfo");
  93. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  94. {
  95. conn.Open();
  96. SqlTransaction sqlTran = conn.BeginTransaction();
  97. SqlCommand cmd = new SqlCommand();
  98. cmd.Transaction = sqlTran;
  99. cmd.Connection = conn;
  100. try
  101. {
  102. string sql = @"SELECT a.LotNo,b.InvCode,b.InvName,b.InvStd,c.Quantity,b.InvUnit,e.WarehouseCode,e.WarehouseName,d.LocationCode,d.LocationName,f.ProjectCode,f.Brand,f.BatchCode,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  103. FROM ICSInventoryLot a
  104. INNER JOIN ICSInventory b ON b.InvCode=a.InvCode AND b.WorkPoint=a.WorkPoint
  105. INNER JOIN ICSWareHouseLotInfo c ON c.LotNo=a.LotNo AND c.WorkPoint=a.WorkPoint
  106. INNER JOIN ICSLocation d ON d.LocationCode=c.LocationCode AND d.WorkPoint=c.WorkPoint
  107. INNER JOIN ICSWarehouse e ON e.ID=d.WHID AND e.WorkPoint=d.WorkPoint
  108. INNER JOIN ICSExtension f ON f.ID=a.ExtensionID AND f.WorkPoint=e.WorkPoint
  109. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  110. ";
  111. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  112. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  113. cmd.Transaction.Commit();
  114. return data;
  115. }
  116. catch (Exception ex)
  117. {
  118. if (cmd.Transaction != null)
  119. cmd.Transaction.Rollback();
  120. log.Error(ex.Message);
  121. throw new Exception(ex.Message);
  122. }
  123. finally
  124. {
  125. if (conn.State == ConnectionState.Open)
  126. {
  127. conn.Close();
  128. }
  129. conn.Dispose();
  130. }
  131. }
  132. }
  133. #endregion
  134. #region 查询库位信息
  135. public static DataTable LocationGet(ICSQueryModel JsonData)
  136. {
  137. var language = LanguageHelper.GetName("WMSAPIInfo");
  138. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  139. {
  140. conn.Open();
  141. SqlTransaction sqlTran = conn.BeginTransaction();
  142. SqlCommand cmd = new SqlCommand();
  143. cmd.Transaction = sqlTran;
  144. cmd.Connection = conn;
  145. try
  146. {
  147. string sql = @"SELECT c.LotNo,e.InvCode,e.InvName,e.InvStd,c.Quantity,e.InvUnit,b.WarehouseCode,b.WarehouseName,a.LocationCode,a.LocationName,f.ProjectCode,f.Brand,f.BatchCode,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  148. FROM ICSLocation a
  149. INNER JOIN ICSWarehouse b ON b.ID=a.WHID AND b.WorkPoint=a.WorkPoint
  150. INNER JOIN ICSWareHouseLotInfo c ON c.LocationCode=a.LocationCode AND c.WorkPoint=a.WorkPoint
  151. INNER JOIN ICSInventoryLot d ON d.LotNo=c.LotNo AND d.WorkPoint=c.WorkPoint
  152. INNER JOIN ICSInventory e ON e.InvCode=d.InvCode AND e.WorkPoint=d.WorkPoint
  153. INNER JOIN ICSExtension f ON f.ID=d.ExtensionID AND f.WorkPoint=d.WorkPoint
  154. WHERE a.LocationCode='{0}' AND a.WorkPoint='{1}' AND c.Quantity>0
  155. ";
  156. sql = string.Format(sql, JsonData.LocationCode, JsonData.WorkPoint);
  157. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  158. cmd.Transaction.Commit();
  159. return data;
  160. }
  161. catch (Exception ex)
  162. {
  163. if (cmd.Transaction != null)
  164. cmd.Transaction.Rollback();
  165. log.Error(ex.Message);
  166. throw new Exception(ex.Message);
  167. }
  168. finally
  169. {
  170. if (conn.State == ConnectionState.Open)
  171. {
  172. conn.Close();
  173. }
  174. conn.Dispose();
  175. }
  176. }
  177. }
  178. #endregion
  179. #region 查询条码信息(条码表)
  180. public static DataTable BarCodeGetNew(BarCodeModel JsonData)
  181. {
  182. var language = LanguageHelper.GetName("WMSAPIInfo");
  183. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  184. {
  185. conn.Open();
  186. SqlTransaction sqlTran = conn.BeginTransaction();
  187. SqlCommand cmd = new SqlCommand();
  188. cmd.Transaction = sqlTran;
  189. cmd.Connection = conn;
  190. try
  191. {
  192. string sql = @"SELECT a.LotNo,b.InvCode,b.InvName,b.InvStd,a.Quantity,b.InvUnit,f.ProjectCode,f.Brand,f.BatchCode,f.cFree1,f.cFree2,f.cFree3,f.cFree4,f.cFree5,f.cFree6,f.cFree7,f.cFree8,f.cFree9,f.cFree10
  193. FROM ICSInventoryLot a
  194. INNER JOIN ICSInventory b ON b.InvCode=a.InvCode AND b.WorkPoint=a.WorkPoint
  195. INNER JOIN ICSExtension f ON f.ID=a.ExtensionID AND f.WorkPoint=a.WorkPoint
  196. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  197. ";
  198. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  199. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  200. cmd.Transaction.Commit();
  201. return data;
  202. }
  203. catch (Exception ex)
  204. {
  205. if (cmd.Transaction != null)
  206. cmd.Transaction.Rollback();
  207. log.Error(ex.Message);
  208. throw new Exception(ex.Message);
  209. }
  210. finally
  211. {
  212. if (conn.State == ConnectionState.Open)
  213. {
  214. conn.Close();
  215. }
  216. conn.Dispose();
  217. }
  218. }
  219. }
  220. #endregion
  221. }
  222. }