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

704 lines
37 KiB

3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using NFine.Code;
  9. using NFine.Repository;
  10. using System.Data.Common;
  11. using NFine.Domain._03_Entity.SRM;
  12. using ICS.Application.Entity;
  13. using Newtonsoft.Json;
  14. using System.Configuration;
  15. using System.Data.SqlClient;
  16. using ICS.Data;
  17. using Newtonsoft.Json.Linq;
  18. using NFine.Domain._03_Entity.WMS;
  19. using System.Net;
  20. using System.IO;
  21. namespace NFine.Application.WMS
  22. {
  23. public class ICSRCVIQCsApp:RepositoryFactory<ICSVendor>
  24. {
  25. /// <summary>
  26. /// 采购
  27. /// </summary>
  28. /// <param name="jqgridparam"></param>
  29. /// <returns></returns>
  30. public DataTable GetICSInspection(ref Pagination jqgridparam, string queryJson)
  31. {
  32. DataTable dt = new DataTable();
  33. var queryParam = queryJson.ToJObject();
  34. List<DbParameter> parameter = new List<DbParameter>();
  35. string sql = @" select
  36. a.ID as DHID,
  37. d.ID ,
  38. h.ID as JYID,
  39. a.DNCode ,
  40. a.Sequence ,
  41. a.ASNCode ,
  42. l.POCode,
  43. c.InvCode ,
  44. c.InvName ,
  45. c.INVSTD ,
  46. c.ClassName,
  47. CAST(b.DNQuantity as decimal(18,4)) as AllNumber,
  48. CAST(ISNULL(h.QualifiedQuantity, b.DNQuantity)as decimal(18,4))as YLOTQTY ,
  49. CAST(ISNULL(h.UnqualifiedQuantity, 0) as decimal(18,4)) as NLOTQTY,
  50. CAST(ISNULL(h.WaiveQuantity, 0) as decimal(18,4)) as SpecialQTY,
  51. c.InvUnit ,
  52. b.LotNo ,
  53. g.BadReasonDesc as BadReasonDesc ,
  54. g.BadReasonCode as BRCodeValue,
  55. j.BadCode as BCCodeValue,
  56. j.BadDesc as BadDesc,
  57. k.ContainerID,
  58. isnull(h.MUSERName,'') MUSERName,
  59. CONVERT(VARCHAR(100),d.ProductDate,23) as ProductTime,
  60. CONVERT(VARCHAR(100),a.CreateDateTime,23) as CreateDateTime,
  61. CONVERT(VARCHAR(100),h.MTIME,23) as MTIME,
  62. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  63. a.VenCode,
  64. m.VenName,
  65. isnull(h.MUSER,'') as Surveyor,
  66. h.MUSERName as ProvingTime
  67. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  68. FROM ICSDeliveryNotice a
  69. inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  70. LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  71. inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  72. left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  73. LEFT JOIN dbo.ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  74. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  75. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  76. LEFT JOIN ICSContainerLot k ON b.LotNo=k.LotNo AND b.WorkPoint=k.WorkPoint
  77. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND d.WorkPoint=l.WorkPoint
  78. left join ICSExtension f on l.ExtensionID=f.ID and l.WorkPoint=f.WorkPoint
  79. left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint
  80. where b.LotNo is not null and a.DNType='1' {0}
  81. ";
  82. #region 无srm逻辑
  83. // sql = @"UNION all
  84. //select
  85. // a.ID as DHID,
  86. // d.ID ,
  87. // h.ID as JYID,
  88. // a.DNCode ,
  89. // a.Sequence ,
  90. // a.ASNCode ,
  91. // c.InvCode ,
  92. // c.InvName ,
  93. // c.INVSTD ,
  94. // c.ClassName,
  95. // f.BatchCode ,
  96. // CAST(d.Quantity as decimal(18,4)) as AllNumber,
  97. // CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as decimal(18,4))as YLOTQTY ,
  98. // CAST(ISNULL(h.UnqualifiedQuantity, 0) as decimal(18,4)) as NLOTQTY,
  99. // CAST(ISNULL(h.WaiveQuantity, 0) as decimal(18,4)) as SpecialQTY,
  100. // c.InvUnit ,
  101. // d.LotNo ,
  102. // g.BadReasonDesc as BadReasonDesc ,
  103. // g.BadReasonCode as BRCodeValue,
  104. // j.BadCode as BCCodeValue,
  105. // j.BadDesc as BadDesc,
  106. // k.ContainerID,
  107. // isnull(h.MUSERName,'开发者') MUSERName,
  108. // CONVERT(VARCHAR(100),d.ProductDate,23) as ProductTime,
  109. // CONVERT(VARCHAR(100),h.MTIME,23) as MTIME,
  110. // CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState
  111. // FROM ICSDeliveryNotice a
  112. // inner join ICSInventoryLotDetail e on e.TransCode =a.DNCode AND e.TransSequence=a.Sequence AND e.WorkPoint=a.WorkPoint
  113. // inner JOIN ICSInventoryLot d ON d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  114. // LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  115. // LEFT JOIN dbo.ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=d.WorkPoint
  116. // left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  117. // left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  118. // LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND d.WorkPoint=k.WorkPoint
  119. // left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  120. // where a.DNType='1' {0}";
  121. #endregion
  122. string wheresql = "";
  123. if (!string.IsNullOrWhiteSpace(queryJson))
  124. {
  125. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  126. {
  127. wheresql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  128. }
  129. if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
  130. {
  131. wheresql += " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ";
  132. }
  133. if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString()))
  134. {
  135. wheresql += " and l.POCode like '%" + queryParam["CaiGouCode"].ToString() + "%' ";
  136. }
  137. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  138. {
  139. wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  140. }
  141. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  142. {
  143. wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  144. }
  145. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  146. {
  147. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  148. }
  149. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  150. {
  151. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  152. }
  153. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  154. {
  155. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  156. }
  157. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  158. {
  159. string ReleaseState = queryParam["ReleaseState"].ToString();
  160. if (ReleaseState == "1")
  161. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  162. else if (ReleaseState == "0")
  163. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  164. }
  165. }
  166. sql = string.Format(sql, wheresql);
  167. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  168. }
  169. //委外
  170. public DataTable GetICSInspection2(ref Pagination jqgridparam, string queryJson)
  171. {
  172. DataTable dt = new DataTable();
  173. var queryParam = queryJson.ToJObject();
  174. List<DbParameter> parameter = new List<DbParameter>();
  175. string sql = @" select
  176. a.ID as DHID,
  177. d.ID ,
  178. h.ID as JYID,
  179. a.ODNCode as DNCode ,
  180. a.Sequence ,
  181. a.OASNCode ,
  182. l.OOCode,
  183. c.InvCode ,
  184. c.InvName ,
  185. c.INVSTD ,
  186. c.ClassName,
  187. f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,
  188. CAST(b.ODNQuantity as NUMERIC(10,4)) as AllNumber,
  189. CAST(ISNULL(h.QualifiedQuantity, b.ODNQuantity)as NUMERIC(10,4))as YLOTQTY ,
  190. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  191. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  192. c.InvUnit ,
  193. b.LotNo ,
  194. g.BadReasonDesc as BadReasonDesc ,
  195. g.BadReasonCode as BRCodeValue,
  196. j.BadCode as BCCodeValue,
  197. j.BadDesc as BadDesc,
  198. k.ContainerID,
  199. isnull(h.MUSERName,'') MUSERName,
  200. CONVERT(VARCHAR(100),d.ProductDate,23) as ProductTime,
  201. CONVERT(VARCHAR(100),a.CreateDateTime,23) as CreateDateTime,
  202. CONVERT(VARCHAR(100),h.MTIME,23) as MTIME,
  203. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  204. a.VenCode,
  205. m.VenName,
  206. isnull(h.MUSER,'') as Surveyor,
  207. h.MUSERName as ProvingTime
  208. FROM ICSODeliveryNotice a
  209. LEFT JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint
  210. LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  211. inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  212. left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  213. LEFT JOIN dbo.ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  214. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  215. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  216. LEFT JOIN ICSContainerLot k ON b.LotNo=k.LotNo AND b.WorkPoint=k.WorkPoint
  217. inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint
  218. left join ICSExtension f on l.ExtensionID=f.ID and l.WorkPoint=f.WorkPoint
  219. left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint
  220. where b.LotNo is not null and ISNULL(CAST(b.ODNQuantity as VARCHAR), '')! ='' AND ISNULL(b.ODNQuantity, 0)<>0 {0}
  221. ";
  222. #region 无SRM逻辑
  223. // sql = @"UNION all
  224. //select
  225. // a.ID as DHID,
  226. // d.ID ,
  227. // h.ID as JYID,
  228. // a.ODNCode as DNCode ,
  229. // a.Sequence ,
  230. // a.OASNCode ,
  231. // c.InvCode ,
  232. // c.InvName ,
  233. // c.INVSTD ,
  234. // c.ClassName,
  235. // f.BatchCode ,
  236. // CAST(d.Quantity as NUMERIC(10,4)) as AllNumber,
  237. // CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  238. // CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  239. // CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  240. // c.InvUnit ,
  241. // d.LotNo ,
  242. // g.BadReasonDesc as BadReasonDesc ,
  243. // g.BadReasonCode as BRCodeValue,
  244. // j.BadCode as BCCodeValue,
  245. // j.BadDesc as BadDesc,
  246. // k.ContainerID,
  247. // isnull(h.MUSERName,'开发者') MUSERName,
  248. // CONVERT(VARCHAR(100),d.ProductDate,23) as ProductTime,
  249. // CONVERT(VARCHAR(100),h.MTIME,23) as MTIME,
  250. // CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState
  251. // FROM ICSODeliveryNotice a
  252. // inner join ICSInventoryLotDetail e on e.TransCode =a.ODNCode AND e.TransSequence=a.Sequence AND e.WorkPoint=a.WorkPoint
  253. // inner JOIN ICSInventoryLot d ON d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  254. // LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  255. // LEFT JOIN dbo.ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=d.WorkPoint
  256. // left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  257. // left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  258. // LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND d.WorkPoint=k.WorkPoint
  259. // left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  260. // where 1=1 {0}";
  261. #endregion
  262. string wheresql = "";
  263. if (!string.IsNullOrWhiteSpace(queryJson))
  264. {
  265. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  266. {
  267. wheresql += " and a.ODNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  268. }
  269. if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
  270. {
  271. wheresql += " and a.OASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ";
  272. }
  273. if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString()))
  274. {
  275. wheresql += " and l.OOCode like '%" + queryParam["CaiGouCode"].ToString() + "%' ";
  276. }
  277. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  278. {
  279. wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  280. }
  281. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  282. {
  283. wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  284. }
  285. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  286. {
  287. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  288. }
  289. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  290. {
  291. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  292. }
  293. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  294. {
  295. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  296. }
  297. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  298. {
  299. string ReleaseState = queryParam["ReleaseState"].ToString();
  300. if (ReleaseState == "1")
  301. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  302. else if (ReleaseState == "0")
  303. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  304. }
  305. }
  306. sql = string.Format(sql, wheresql);
  307. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  308. }
  309. //工单
  310. public DataTable GetICSInspection3(ref Pagination jqgridparam, string queryJson)
  311. {
  312. DataTable dt = new DataTable();
  313. var queryParam = queryJson.ToJObject();
  314. List<DbParameter> parameter = new List<DbParameter>();
  315. string sql = @"select
  316. a.ID as GDID,
  317. e.ID ,
  318. a.MOCode as DNCode,
  319. a.Sequence ,
  320. h.ID as JYID,
  321. c.InvCode ,
  322. c.InvName ,
  323. c.INVSTD ,
  324. c.ClassName,
  325. f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,
  326. e.Quantity as AllNumber,
  327. CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  328. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  329. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  330. c.InvUnit ,
  331. e.LotNo ,
  332. g.BadReasonDesc as BadReasonDesc ,
  333. g.BadReasonCode as BRCodeValue,
  334. j.BadCode as BCCodeValue,
  335. j.BadDesc as BadDesc,
  336. i.ContainerID,
  337. isnull(h.MUSERName,'') MUSERName,
  338. CONVERT(VARCHAR(100),e.ProductDate,23) as ProductTime,
  339. CONVERT(VARCHAR(100),h.MTIME,23) as MTIME,
  340. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  341. isnull(h.MUSER,'') as Surveyor,
  342. h.MUSERName as ProvingTime
  343. from ICSMO a
  344. left JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint
  345. left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint
  346. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  347. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint
  348. LEFT JOIN dbo.ICSInspection h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint
  349. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  350. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  351. LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint
  352. where e.LotNO is not null {0} ";
  353. string wheresql = "";
  354. if (!string.IsNullOrWhiteSpace(queryJson))
  355. {
  356. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  357. {
  358. wheresql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  359. }
  360. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  361. {
  362. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  363. }
  364. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  365. {
  366. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  367. }
  368. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  369. {
  370. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  371. }
  372. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  373. {
  374. string ReleaseState = queryParam["ReleaseState"].ToString();
  375. if (ReleaseState == "1")
  376. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  377. else if (ReleaseState == "0")
  378. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  379. }
  380. }
  381. sql = string.Format(sql, wheresql);
  382. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  383. }
  384. //获取不良原因
  385. public DataTable Select_ICSBadReason(string InvCode)
  386. {
  387. string sql = string.Empty;
  388. DataTable dt = null;
  389. sql = @"select '' as BadReasonCode,'' as BadReasonDesc from ICSBadReason a left join
  390. ICSInventoryBadGroup b on a.BRGroupID=b.BRGroupID
  391. union
  392. select a.BadReasonCode,a.BadReasonDesc from ICSBadReason a left join
  393. ICSInventoryBadGroup b on a.BRGroupID=b.BRGroupID
  394. where b.InvCode='{0}'";
  395. sql = string.Format(sql, InvCode);
  396. dt = SqlHelper.GetDataTableBySql(sql);
  397. return dt;
  398. }
  399. //获取不良代码
  400. public DataTable GetSelectICSBadCode(string InvCode)
  401. {
  402. string sql = string.Empty;
  403. DataTable dt = null;
  404. sql = @"
  405. select '' as BadCode ,'' as BadDesc
  406. from dbo.ICSBadCode a left join
  407. ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID
  408. union
  409. select BadCode,BadDesc from dbo.ICSBadCode a left join
  410. ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID where b.InvCode='{0}'";
  411. // sql = @"select BadCode,BadDesc from dbo.ICSBadCode a left join
  412. //ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID
  413. //where b.InvCode='{0}'";
  414. sql = string.Format(sql, InvCode);
  415. dt = SqlHelper.GetDataTableBySql(sql);
  416. return dt;
  417. }
  418. /// <summary>
  419. /// 新增检验
  420. /// </summary>
  421. /// <param name="queryJson"></param>
  422. /// <returns></returns>
  423. public string CreateICSInspection(string keyValue, string ICSInspections)
  424. {
  425. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  426. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  427. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  428. string msg = "";
  429. string sql = string.Empty;
  430. JArray res = (JArray)JsonConvert.DeserializeObject(ICSInspections);
  431. foreach (var item in res)
  432. {
  433. JObject jo = (JObject)item;
  434. string sqls = string.Empty;
  435. sqls = @"update ICSInspection set Enable='0' WHERE LotNO='{0}' and Enable='1' and WorkPoint='{1}'";
  436. sqls = string.Format(sqls, jo["LotNo"].ToString(), WorkPoint);
  437. SqlHelper.CmdExecuteNonQueryLi(sqls);
  438. //if (jo["TestState"].ToString()=="已检验")
  439. //{
  440. // sql += @"UPDATE dbo.ICSInspection set QualifiedQuantity='{0}',UnqualifiedQuantity='{1}',WaiveQuantity='{2}',BCCode='{3}',BRCode='{4}',MTIME=GETDATE(),MUSER='{5}',MUSERName='{6}',WorkPoint='{7}' WHERE ID='{8}'";
  441. // sql = string.Format(sql, jo["YLOTQTY"].ToString(), jo["NLOTQTY"].ToString(), jo["SpecialQTY"].ToString(), jo["BCCode"].ToString(), jo["BRCode"].ToString(), MUSER, MUSERNAME, WorkPoint, jo["JYID"].ToString());
  442. //}
  443. //else
  444. //{
  445. sql += @"INSERT INTO dbo.ICSInspection
  446. ( ID ,LotNo,InvCode ,Quantity,QualifiedQuantity ,UnqualifiedQuantity,WaiveQuantity,BCCode,BRCode,Type,MTIME,MUSER ,MUSERName ,WorkPoint ,Enable)
  447. Values(NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}',getdate(),'{9}','{10}','{11}','1')
  448. ";
  449. sql = string.Format(sql, jo["LotNo"].ToString(), jo["InvCode"].ToString(), jo["AllNumber"].ToString(), jo["YLOTQTY"].ToString(), jo["NLOTQTY"].ToString(), jo["SpecialQTY"].ToString(), jo["BCCode"].ToString(), jo["BRCode"].ToString(), jo["Type"].ToString(), MUSER, MUSERNAME, WorkPoint);
  450. }
  451. //}
  452. try
  453. {
  454. if (SqlHelper.ExecuteNonQuery(sql) > 0)
  455. {
  456. }
  457. else
  458. {
  459. msg = "新增失败";
  460. }
  461. }
  462. catch (Exception ex)
  463. {
  464. throw new Exception(ex.Message);
  465. }
  466. return msg;
  467. }
  468. //生成采购拒收单
  469. public string CreateRejection(string keyValue)
  470. {
  471. string msg = "";
  472. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  473. string sqlAsn = @"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode from ICSDeliveryNotice a
  474. inner join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  475. left join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  476. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  477. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  478. WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ")";
  479. DataTable dt = Repository().FindTableBySql(sqlAsn.ToString());
  480. string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,DNDetailID,DNID,b.LotNo
  481. from ICSDeliveryNotice a
  482. left join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  483. left join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  484. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  485. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  486. left join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint
  487. WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ") ";
  488. DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString());
  489. List<RejectionHead> asn = new List<RejectionHead>();
  490. for (int i = 0; i < dt.Rows.Count; i++)
  491. {
  492. RejectionHead ass = new RejectionHead();
  493. ass.VenCode = dt.Rows[i]["VenCode"].ToString();
  494. ass.ID = dt.Rows[i]["DNID"].ToString();
  495. ass.DepCode = dt.Rows[i]["DepCode"].ToString();
  496. ass.DNCode = dt.Rows[i]["DNCode"].ToString();
  497. ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  498. ass.MTIME = System.DateTime.Now.ToString("s");
  499. ass.WorkPoint = WorkPoint;
  500. DataRow[] drs = dtD.Select("DNID='" + dt.Rows[i]["DNID"].ToString() + "'");
  501. for (int j = 0; j < drs.Length; j++)
  502. {
  503. RejectionBody DetailList = new RejectionBody();
  504. DetailList.Sequence = (j+1).ToString();
  505. DetailList.InvCode = drs[j]["InvCode"].ToString();
  506. DetailList.Quantity = drs[j]["Quantity"].ToString();
  507. DetailList.Amount = drs[j]["Amount"].ToString();
  508. DetailList.Currency = drs[j]["Currency"].ToString();
  509. DetailList.UnitPrice = drs[j]["UnitPrice"].ToString();
  510. DetailList.DNDetailID = drs[j]["DNDetailID"].ToString();
  511. DetailList.LotNo = drs[j]["LotNo"].ToString();
  512. ass.detail.Add(DetailList);
  513. }
  514. asn.Add(ass);
  515. }
  516. string input = JsonConvert.SerializeObject(asn);
  517. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString+ "PurchaseRejectDoc/Create";
  518. string result = HttpPost(APIURL, input);
  519. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  520. string MessAge = Obj["Message"].ToString();
  521. string Success = Obj["Success"].ToString();
  522. if (Success.ToUpper() == "FALSE")
  523. {
  524. msg = MessAge;
  525. }
  526. return msg;
  527. }
  528. //生成委外拒收单
  529. public string CreateWWRejection(string keyValue)
  530. {
  531. string msg = "";
  532. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  533. string sqlAsn = @"select distinct a.VenCode,a.ODNID,a.DepCode,a.ODNCode from ICSODeliveryNotice a
  534. left join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint
  535. LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  536. inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  537. left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  538. inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint
  539. WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ")";
  540. DataTable dt = Repository().FindTableBySql(sqlAsn.ToString());
  541. string sqlAsnD = @"select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,ODNDetailID,ODNID,b.LotNo
  542. from ICSODeliveryNotice a
  543. inner join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint
  544. inner join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  545. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  546. inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND c.WorkPoint=l.WorkPoint
  547. inner join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint
  548. WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ") ";
  549. DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString());
  550. List<WWRejectionHead> asn = new List<WWRejectionHead>();
  551. for (int i = 0; i < dt.Rows.Count; i++)
  552. {
  553. WWRejectionHead ass = new WWRejectionHead();
  554. ass.VenCode = dt.Rows[i]["VenCode"].ToString();
  555. ass.ID = dt.Rows[i]["ODNID"].ToString();
  556. ass.DepCode = dt.Rows[i]["DepCode"].ToString();
  557. ass.ODNCode = dt.Rows[i]["ODNCode"].ToString();
  558. ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  559. ass.MTIME = System.DateTime.Now.ToString("s");
  560. ass.WorkPoint = WorkPoint;
  561. DataRow[] drs = dtD.Select("ODNID='" + dt.Rows[i]["ODNID"].ToString() + "'");
  562. for (int j = 0; j < drs.Length; j++)
  563. {
  564. WWRejectionBody DetailList = new WWRejectionBody();
  565. DetailList.Sequence = (j + 1).ToString();
  566. DetailList.InvCode = drs[j]["InvCode"].ToString();
  567. DetailList.Quantity = drs[j]["Quantity"].ToString();
  568. DetailList.Amount = drs[j]["Amount"].ToString();
  569. DetailList.Currency = drs[j]["Currency"].ToString();
  570. DetailList.UnitPrice = drs[j]["UnitPrice"].ToString();
  571. DetailList.ODNDetailID = drs[j]["ODNDetailID"].ToString();
  572. DetailList.LotNo = drs[j]["LotNo"].ToString();
  573. ass.detail.Add(DetailList);
  574. }
  575. asn.Add(ass);
  576. }
  577. string input = JsonConvert.SerializeObject(asn);
  578. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingRejectDoc/Create";
  579. string result = HttpPost(APIURL, input);
  580. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  581. string MessAge = Obj["Message"].ToString();
  582. string Success = Obj["Success"].ToString();
  583. if (Success.ToUpper() == "FALSE")
  584. {
  585. msg = MessAge;
  586. }
  587. return msg;
  588. }
  589. public static string HttpPost(string url, string body)
  590. {
  591. try
  592. {
  593. Encoding encoding = Encoding.UTF8;
  594. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  595. request.Method = "POST";
  596. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  597. request.ContentType = "application/json; charset=utf-8";
  598. byte[] buffer = encoding.GetBytes(body);
  599. request.ContentLength = buffer.Length;
  600. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  601. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  602. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  603. {
  604. return reader.ReadToEnd();
  605. }
  606. }
  607. catch (WebException ex)
  608. {
  609. throw new Exception(ex.Message);
  610. }
  611. }
  612. /// <summary>
  613. /// 删除拒收单
  614. /// </summary>
  615. /// <param name="keyValue">传入ID</param>
  616. /// <returns></returns>
  617. public string DelectRejection(string keyValue)
  618. {
  619. //站点信息
  620. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  621. string msg = "";
  622. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  623. string sql = string.Empty;
  624. sql = string.Format(@"DELETE FROM dbo.ICSDeliveryNotice WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  625. try
  626. {
  627. SqlHelper.ExecuteNonQuery(sql);
  628. }
  629. catch (Exception ex)
  630. {
  631. throw new Exception(ex.Message);
  632. }
  633. return msg;
  634. }
  635. /// <summary>
  636. /// 删除委外拒收单
  637. /// </summary>
  638. /// <param name="keyValue">传入ID</param>
  639. /// <returns></returns>
  640. public string DelectWWRejection(string keyValue)
  641. {
  642. //站点信息
  643. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  644. string msg = "";
  645. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  646. string sql = string.Empty;
  647. sql = string.Format(@"DELETE FROM dbo.ICSODeliveryNotice WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  648. try
  649. {
  650. SqlHelper.ExecuteNonQuery(sql);
  651. }
  652. catch (Exception ex)
  653. {
  654. throw new Exception(ex.Message);
  655. }
  656. return msg;
  657. }
  658. }
  659. }