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.

491 lines
20 KiB

3 weeks 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 DataTable GetJHWHCode()
  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 DISTINCT
  196. b.F_ItemCode
  197. FROM Sys_SRM_Items a
  198. LEFT JOIN Sys_SRM_ItemsDetail b ON a.F_Id = b.F_ItemId
  199. WHERE a.F_EnCode = 'JinHuaLiKu'";
  200. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  201. if (table == null || table.Rows.Count <= 0)
  202. {
  203. return null;
  204. }
  205. else
  206. {
  207. return table;
  208. //string json = JsonConvert.SerializeObject(table);
  209. //List<ControlMode> model = JsonConvert.DeserializeObject<List<ControlMode>>(json);
  210. //cmd.Transaction.Commit();
  211. //return model[0];
  212. }
  213. }
  214. catch (Exception ex)
  215. {
  216. if (cmd.Transaction != null)
  217. cmd.Transaction.Rollback();
  218. log.Error(ex.Message);
  219. throw new Exception(ex.Message);
  220. }
  221. finally
  222. {
  223. if (conn.State == ConnectionState.Open)
  224. {
  225. conn.Close();
  226. }
  227. conn.Dispose();
  228. }
  229. }
  230. }
  231. /// <summary>
  232. /// 晶华立库调用erp数据重传
  233. /// </summary>
  234. /// <param name="cmd"></param>
  235. /// <param name="language"></param>
  236. /// <returns></returns>
  237. /// <exception cref="Exception"></exception>
  238. public static void InsertErrLog(string Url, string JsonStr, string msg, string UserCode, string WorkPoint, SqlCommand cmd)
  239. {
  240. try
  241. {
  242. string sql = @"INSERT INTO ICSAPIErrorLog(ID,Url,JosnStr,ErrorMsg,Status,WorkPoint,MUSER,
  243. MUSERName,MTIME)
  244. SELECT NEWID(),'{0}','{1}','{2}',0,'{4}' ,F_Account ,F_RealName ,SYSDATETIME()
  245. FROM Sys_SRM_User
  246. WHERE F_Account='{3}' and F_Location='{4}'";
  247. sql = string.Format(sql, Url, JsonStr, msg, UserCode, WorkPoint);
  248. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  249. {
  250. throw new Exception("报错信息记录失败!");
  251. }
  252. }
  253. catch (Exception ex)
  254. {
  255. if (cmd.Transaction != null)
  256. cmd.Transaction.Rollback();
  257. log.Error(ex.Message);
  258. throw new Exception(ex.Message);
  259. }
  260. }
  261. /// <summary>
  262. /// 获取车间对应仓库
  263. /// </summary>
  264. /// <param name="cmd"></param>
  265. /// <param name="language"></param>
  266. /// <returns></returns>
  267. /// <exception cref="Exception"></exception>
  268. public static DataTable GetWHCode()
  269. {
  270. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  271. {
  272. conn.Open();
  273. SqlCommand cmd = new SqlCommand();
  274. ControlMode contro = new ControlMode();
  275. SqlTransaction sqlTran = conn.BeginTransaction();
  276. cmd.Transaction = sqlTran;
  277. cmd.Connection = conn;
  278. try
  279. {
  280. string sql = @"SELECT DISTINCT
  281. b.F_ItemName AS CName,
  282. STUFF((
  283. SELECT ',' + b2.F_ItemCode
  284. FROM Sys_SRM_ItemsDetail b2
  285. WHERE b2.F_ItemName = b.F_ItemName
  286. ORDER BY b2.F_ItemCode
  287. FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '') AS WHCode
  288. FROM Sys_SRM_Items a
  289. LEFT JOIN Sys_SRM_ItemsDetail b ON a.F_Id = b.F_ItemId
  290. WHERE a.F_EnCode = 'workShopToWareHouse'
  291. GROUP BY b.F_ItemName";
  292. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  293. if (table == null || table.Rows.Count <= 0)
  294. {
  295. return null;
  296. }
  297. else
  298. {
  299. return table;
  300. //string json = JsonConvert.SerializeObject(table);
  301. //List<ControlMode> model = JsonConvert.DeserializeObject<List<ControlMode>>(json);
  302. //cmd.Transaction.Commit();
  303. //return model[0];
  304. }
  305. }
  306. catch (Exception ex)
  307. {
  308. if (cmd.Transaction != null)
  309. cmd.Transaction.Rollback();
  310. log.Error(ex.Message);
  311. throw new Exception(ex.Message);
  312. }
  313. finally
  314. {
  315. if (conn.State == ConnectionState.Open)
  316. {
  317. conn.Close();
  318. }
  319. conn.Dispose();
  320. }
  321. }
  322. }
  323. /// <summary>
  324. /// 获取单据是否需要检验
  325. /// </summary>
  326. /// <param name="cmd"></param>
  327. /// <param name="language"></param>
  328. /// <returns></returns>
  329. /// <exception cref="Exception"></exception>
  330. public static bool GetOrderIns(string orderType)
  331. {
  332. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  333. {
  334. conn.Open();
  335. SqlCommand cmd = new SqlCommand();
  336. ControlMode contro = new ControlMode();
  337. SqlTransaction sqlTran = conn.BeginTransaction();
  338. cmd.Transaction = sqlTran;
  339. cmd.Connection = conn;
  340. try
  341. {
  342. string sql = @"select b.* from Sys_SRM_ItemsDetail b inner join Sys_SRM_Items a on a.F_Id=b.F_ItemId where
  343. b.F_ItemCode = '" + orderType + "' and b.F_EnabledMark= 1 and a.F_EnabledMark= 1 and a.F_ENCODE = 'ICSInspectionCheck' " +
  344. "union " +
  345. @"select b.* from Sys_SRM_ItemsDetail b inner join Sys_SRM_Items a on a.F_Id=b.F_ItemId where
  346. b.F_ItemName = '" + orderType + @"' and b.F_EnabledMark = 1 and a.F_EnabledMark = 1 and a.F_ENCODE = 'ICSInspectionCheck'";
  347. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  348. if (table == null || table.Rows.Count <= 0)
  349. {
  350. return false;
  351. }
  352. else
  353. {
  354. return true;
  355. //string json = JsonConvert.SerializeObject(table);
  356. //List<ControlMode> model = JsonConvert.DeserializeObject<List<ControlMode>>(json);
  357. //cmd.Transaction.Commit();
  358. //return model[0];
  359. }
  360. }
  361. catch (Exception ex)
  362. {
  363. if (cmd.Transaction != null)
  364. cmd.Transaction.Rollback();
  365. log.Error(ex.Message);
  366. throw new Exception(ex.Message);
  367. }
  368. finally
  369. {
  370. if (conn.State == ConnectionState.Open)
  371. {
  372. conn.Close();
  373. }
  374. conn.Dispose();
  375. }
  376. }
  377. }
  378. /// <summary>
  379. /// 根据条码获取信息
  380. /// </summary>
  381. /// <param name="LotNo"></param>
  382. /// <param name="WorkPoint"></param>
  383. /// <returns></returns>
  384. /// <exception cref="Exception"></exception>
  385. public static string QueryLotNo(string LotNo,string WorkPoint,SqlCommand command=null)
  386. {
  387. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  388. {
  389. SqlCommand cmd;
  390. if (command == null)
  391. {
  392. conn.Open();
  393. cmd = new SqlCommand();
  394. SqlTransaction sqlTran = conn.BeginTransaction();
  395. cmd.Transaction = sqlTran;
  396. cmd.Connection = conn;
  397. }
  398. else
  399. cmd = command;
  400. try
  401. {
  402. string sql = @"SELECT a.ID,
  403. con.ContainerCode,
  404. con.ContainerName,
  405. a.LotNo,
  406. a.InvCode,
  407. inv.InvName,
  408. inv.InvStd,
  409. inv.InvUnit,-- {0}
  410. inv.AmountUnit,
  411. ext.ID AS ExtensionID,
  412. ext.ProjectCode,
  413. ext.Version,
  414. ext.BatchCode,
  415. ext.Brand,
  416. ext.cFree1,
  417. ext.cFree2,
  418. ext.cFree3,
  419. ext.cFree4,
  420. ext.cFree5,
  421. ext.cFree6,
  422. ext.cFree7,
  423. ext.cFree8,
  424. ext.cFree9,
  425. ext.cFree10,
  426. a.MUSER AS [ USER ],
  427. a.MTIME AS [ MTime ]
  428. FROM
  429. ICSInventoryLot a
  430. LEFT JOIN ICSContainerLot conlot ON a.LotNo = conlot.LotNo AND a.WorkPoint = conlot.WorkPoint
  431. LEFT JOIN ICSContainer con ON conlot.ContainerID = con.ID AND conlot.WorkPoint = con.WorkPoint
  432. INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
  433. INNER JOIN ICSExtension ext ON a.ExtensionID = ext.ID AND a.WorkPoint = ext.WorkPoint
  434. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  435. sql = string.Format(sql, LotNo, WorkPoint);
  436. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  437. string json = JsonConvert.SerializeObject(table);
  438. //List<LotNoMode> model = JsonConvert.DeserializeObject<List<LotNoMode>>(json);
  439. if(command==null)
  440. cmd.Transaction.Commit();
  441. return json;
  442. }
  443. catch (Exception ex)
  444. {
  445. if (cmd.Transaction != null&& command==null)
  446. cmd.Transaction.Rollback();
  447. log.Error(ex.Message);
  448. throw new Exception(ex.Message);
  449. }
  450. finally
  451. {
  452. if (conn.State == ConnectionState.Open)
  453. {
  454. conn.Close();
  455. }
  456. conn.Dispose();
  457. }
  458. }
  459. }
  460. }
  461. }