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.

319 lines
13 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. /// <summary>
  14. /// 管控方式
  15. /// </summary>
  16. public class ICSControlModeService
  17. {
  18. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  19. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
  20. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  21. DataTable table = null;
  22. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  23. string sql = string.Empty;
  24. string sqlInfo = string.Empty;
  25. VerificationMethod verification = new VerificationMethod();
  26. /// <summary>
  27. /// 获取当前启用的管控方式
  28. /// </summary>
  29. /// <param name="cmd"></param>
  30. /// <param name="language"></param>
  31. /// <returns></returns>
  32. /// <exception cref="Exception"></exception>
  33. public static ControlMode GetControlMode()
  34. {
  35. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  36. {
  37. conn.Open();
  38. SqlCommand cmd = new SqlCommand();
  39. SqlTransaction sqlTran = conn.BeginTransaction();
  40. cmd.Transaction = sqlTran;
  41. cmd.Connection = conn;
  42. try
  43. {
  44. string sql = @"SELECT TOP 1 F_ItemCode as itemCode,F_ItemName as itemName,F_EnabledMark as enableMark
  45. FROM [dbo].[Sys_SRM_ItemsDetail] WHERE F_ItemId='14361ce1-c5e3-4e85-a253-51aa3cdde3e6'AND F_EnabledMark='1' ORDER BY F_ItemCode";
  46. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  47. string json = JsonConvert.SerializeObject(table);
  48. List<ControlMode> model = JsonConvert.DeserializeObject<List<ControlMode>>(json);
  49. cmd.Transaction.Commit();
  50. return model[0];
  51. }
  52. catch (Exception ex)
  53. {
  54. if (cmd.Transaction != null)
  55. cmd.Transaction.Rollback();
  56. log.Error(ex.Message);
  57. throw new Exception(ex.Message);
  58. }
  59. finally
  60. {
  61. if (conn.State == ConnectionState.Open)
  62. {
  63. conn.Close();
  64. }
  65. conn.Dispose();
  66. }
  67. }
  68. }
  69. /// <summary>
  70. /// 获取建议库位方式
  71. /// </summary>
  72. /// <param name="cmd"></param>
  73. /// <param name="language"></param>
  74. /// <returns></returns>
  75. /// <exception cref="Exception"></exception>
  76. public static ControlMode GetSuLocation()
  77. {
  78. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  79. {
  80. conn.Open();
  81. SqlCommand cmd = new SqlCommand();
  82. ControlMode contro = new ControlMode();
  83. SqlTransaction sqlTran = conn.BeginTransaction();
  84. cmd.Transaction = sqlTran;
  85. cmd.Connection = conn;
  86. try
  87. {
  88. string sql = @"SELECT Top 1 a.F_ItemCode as itemCode,a.F_ItemName as itemName,a.F_EnabledMark as enableMark
  89. FROM [dbo].[Sys_SRM_ItemsDetail] a
  90. LEFT JOIN [dbo].[Sys_SRM_Items] b ON a.F_ItemId=b.F_Id AND b.F_EnabledMark='1'
  91. WHERE F_ItemId='c8767643-1429-48b1-ad31-c6b19a1dfcb9'AND a.F_EnabledMark='1' ORDER BY a.F_ItemCode";
  92. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  93. if (table == null || table.Rows.Count <= 0)
  94. {
  95. return null;
  96. }
  97. else
  98. {
  99. string json = JsonConvert.SerializeObject(table);
  100. List<ControlMode> model = JsonConvert.DeserializeObject<List<ControlMode>>(json);
  101. cmd.Transaction.Commit();
  102. return model[0];
  103. }
  104. }
  105. catch (Exception ex)
  106. {
  107. if (cmd.Transaction != null)
  108. cmd.Transaction.Rollback();
  109. log.Error(ex.Message);
  110. throw new Exception(ex.Message);
  111. }
  112. finally
  113. {
  114. if (conn.State == ConnectionState.Open)
  115. {
  116. conn.Close();
  117. }
  118. conn.Dispose();
  119. }
  120. }
  121. }
  122. /// <summary>
  123. /// 获取拣配
  124. /// </summary>
  125. /// <param name="cmd"></param>
  126. /// <param name="language"></param>
  127. /// <returns></returns>
  128. /// <exception cref="Exception"></exception>
  129. public static DataTable GetZL()
  130. {
  131. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  132. {
  133. conn.Open();
  134. SqlCommand cmd = new SqlCommand();
  135. ControlMode contro = new ControlMode();
  136. SqlTransaction sqlTran = conn.BeginTransaction();
  137. cmd.Transaction = sqlTran;
  138. cmd.Connection = conn;
  139. try
  140. {
  141. string sql = @"select b.F_ItemCode as Code ,b.F_Define2 as Name,b.F_EnabledMark AS Enable,b.F_Define1 AS BusinessCode
  142. from Sys_SRM_Items a
  143. left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  144. where a.F_EnCode='PL00001' order by cast(b.F_SortCode as int) asc";
  145. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  146. if (table == null || table.Rows.Count <= 0)
  147. {
  148. return null;
  149. }
  150. else
  151. {
  152. return table;
  153. //string json = JsonConvert.SerializeObject(table);
  154. //List<ControlMode> model = JsonConvert.DeserializeObject<List<ControlMode>>(json);
  155. //cmd.Transaction.Commit();
  156. //return model[0];
  157. }
  158. }
  159. catch (Exception ex)
  160. {
  161. if (cmd.Transaction != null)
  162. cmd.Transaction.Rollback();
  163. log.Error(ex.Message);
  164. throw new Exception(ex.Message);
  165. }
  166. finally
  167. {
  168. if (conn.State == ConnectionState.Open)
  169. {
  170. conn.Close();
  171. }
  172. conn.Dispose();
  173. }
  174. }
  175. }
  176. /// <summary>
  177. /// 获取单据是否需要检验
  178. /// </summary>
  179. /// <param name="cmd"></param>
  180. /// <param name="language"></param>
  181. /// <returns></returns>
  182. /// <exception cref="Exception"></exception>
  183. public static bool GetOrderIns(string orderType)
  184. {
  185. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  186. {
  187. conn.Open();
  188. SqlCommand cmd = new SqlCommand();
  189. ControlMode contro = new ControlMode();
  190. SqlTransaction sqlTran = conn.BeginTransaction();
  191. cmd.Transaction = sqlTran;
  192. cmd.Connection = conn;
  193. try
  194. {
  195. string sql = @"select b.* from Sys_SRM_ItemsDetail b inner join Sys_SRM_Items a on a.F_Id=b.F_ItemId where b.F_ItemCode = '" + orderType + "' and b.F_EnabledMark= 1 and a.F_EnabledMark= 1 and a.F_ENCODE = 'ICSInspectionCheck'";
  196. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  197. if (table == null || table.Rows.Count <= 0)
  198. {
  199. return false;
  200. }
  201. else
  202. {
  203. return true;
  204. //string json = JsonConvert.SerializeObject(table);
  205. //List<ControlMode> model = JsonConvert.DeserializeObject<List<ControlMode>>(json);
  206. //cmd.Transaction.Commit();
  207. //return model[0];
  208. }
  209. }
  210. catch (Exception ex)
  211. {
  212. if (cmd.Transaction != null)
  213. cmd.Transaction.Rollback();
  214. log.Error(ex.Message);
  215. throw new Exception(ex.Message);
  216. }
  217. finally
  218. {
  219. if (conn.State == ConnectionState.Open)
  220. {
  221. conn.Close();
  222. }
  223. conn.Dispose();
  224. }
  225. }
  226. }
  227. /// <summary>
  228. /// 根据条码获取信息
  229. /// </summary>
  230. /// <param name="LotNo"></param>
  231. /// <param name="WorkPoint"></param>
  232. /// <returns></returns>
  233. /// <exception cref="Exception"></exception>
  234. public static string QueryLotNo(string LotNo,string WorkPoint)
  235. {
  236. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  237. {
  238. conn.Open();
  239. SqlCommand cmd = new SqlCommand();
  240. SqlTransaction sqlTran = conn.BeginTransaction();
  241. cmd.Transaction = sqlTran;
  242. cmd.Connection = conn;
  243. try
  244. {
  245. string sql = @"SELECT a.ID,
  246. con.ContainerCode,
  247. con.ContainerName,
  248. a.LotNo,
  249. a.InvCode,
  250. inv.InvName,
  251. inv.InvStd,
  252. inv.InvUnit,-- {0}
  253. inv.AmountUnit,
  254. ext.ID AS ExtensionID,
  255. ext.ProjectCode,
  256. ext.Version,
  257. ext.BatchCode,
  258. ext.Brand,
  259. ext.cFree1,
  260. ext.cFree2,
  261. ext.cFree3,
  262. ext.cFree4,
  263. ext.cFree5,
  264. ext.cFree6,
  265. ext.cFree7,
  266. ext.cFree8,
  267. ext.cFree9,
  268. ext.cFree10,
  269. a.MUSER AS [ USER ],
  270. a.MTIME AS [ MTime ]
  271. FROM
  272. ICSInventoryLot a
  273. LEFT JOIN ICSContainerLot conlot ON a.LotNo = conlot.LotNo AND a.WorkPoint = conlot.WorkPoint
  274. LEFT JOIN ICSContainer con ON conlot.ContainerID = con.ID AND conlot.WorkPoint = con.WorkPoint
  275. INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
  276. INNER JOIN ICSExtension ext ON a.ExtensionID = ext.ID AND a.WorkPoint = ext.WorkPoint
  277. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  278. sql = string.Format(sql, LotNo, WorkPoint);
  279. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  280. string json = JsonConvert.SerializeObject(table);
  281. //List<LotNoMode> model = JsonConvert.DeserializeObject<List<LotNoMode>>(json);
  282. cmd.Transaction.Commit();
  283. return json;
  284. }
  285. catch (Exception ex)
  286. {
  287. if (cmd.Transaction != null)
  288. cmd.Transaction.Rollback();
  289. log.Error(ex.Message);
  290. throw new Exception(ex.Message);
  291. }
  292. finally
  293. {
  294. if (conn.State == ConnectionState.Open)
  295. {
  296. conn.Close();
  297. }
  298. conn.Dispose();
  299. }
  300. }
  301. }
  302. }
  303. }