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

727 lines
40 KiB

3 years ago
2 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
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 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 a.ID as DHID, d.ID ,h.ID as JYID, a.ODNCode as DNCode ,a.Sequence ,a.OASNCode ,l.OOCode,c.InvCode , c.InvName , c.INVSTD , c.ClassName,
  176. 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,
  177. CAST(b.ODNQuantity as NUMERIC(10,4)) as AllNumber,
  178. CAST(ISNULL(h.QualifiedQuantity, b.ODNQuantity)as NUMERIC(10,4))as YLOTQTY ,
  179. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  180. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  181. c.InvUnit , b.LotNo , g.BadReasonDesc as BadReasonDesc ,g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc,
  182. k.ContainerID,isnull(h.MUSERName,'') MUSERName, CONVERT(VARCHAR(100),d.ProductDate,23) as ProductTime,
  183. CONVERT(VARCHAR(100),a.CreateDateTime,23) as CreateDateTime,CONVERT(VARCHAR(100),h.MTIME,23) as MTIME,
  184. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,a.VenCode,m.VenName,
  185. isnull(h.MUSER,'') as Surveyor, h.MUSERName as ProvingTime
  186. FROM ICSODeliveryNotice a
  187. LEFT JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint
  188. LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  189. inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  190. left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  191. LEFT JOIN dbo.ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  192. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  193. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  194. LEFT JOIN ICSContainerLot k ON b.LotNo=k.LotNo AND b.WorkPoint=k.WorkPoint
  195. inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint
  196. left join ICSExtension f on l.ExtensionID=f.ID and l.WorkPoint=f.WorkPoint
  197. left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint
  198. where b.LotNo is not null and ISNULL(CAST(b.ODNQuantity as VARCHAR), '')! ='' AND ISNULL(b.ODNQuantity, 0)<>0 {0}
  199. ";
  200. #region 无SRM逻辑
  201. // sql = @"UNION all
  202. //select
  203. // a.ID as DHID,
  204. // d.ID ,
  205. // h.ID as JYID,
  206. // a.ODNCode as DNCode ,
  207. // a.Sequence ,
  208. // a.OASNCode ,
  209. // c.InvCode ,
  210. // c.InvName ,
  211. // c.INVSTD ,
  212. // c.ClassName,
  213. // f.BatchCode ,
  214. // CAST(d.Quantity as NUMERIC(10,4)) as AllNumber,
  215. // CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  216. // CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  217. // CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  218. // c.InvUnit ,
  219. // d.LotNo ,
  220. // g.BadReasonDesc as BadReasonDesc ,
  221. // g.BadReasonCode as BRCodeValue,
  222. // j.BadCode as BCCodeValue,
  223. // j.BadDesc as BadDesc,
  224. // k.ContainerID,
  225. // isnull(h.MUSERName,'开发者') MUSERName,
  226. // CONVERT(VARCHAR(100),d.ProductDate,23) as ProductTime,
  227. // CONVERT(VARCHAR(100),h.MTIME,23) as MTIME,
  228. // CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState
  229. // FROM ICSODeliveryNotice a
  230. // inner join ICSInventoryLotDetail e on e.TransCode =a.ODNCode AND e.TransSequence=a.Sequence AND e.WorkPoint=a.WorkPoint
  231. // inner JOIN ICSInventoryLot d ON d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  232. // LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  233. // LEFT JOIN dbo.ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=d.WorkPoint
  234. // left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  235. // left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  236. // LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND d.WorkPoint=k.WorkPoint
  237. // left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  238. // where 1=1 {0}";
  239. #endregion
  240. string wheresql = "";
  241. if (!string.IsNullOrWhiteSpace(queryJson))
  242. {
  243. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  244. {
  245. wheresql += " and a.ODNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  246. }
  247. if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
  248. {
  249. wheresql += " and a.OASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ";
  250. }
  251. if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString()))
  252. {
  253. wheresql += " and l.OOCode like '%" + queryParam["CaiGouCode"].ToString() + "%' ";
  254. }
  255. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  256. {
  257. wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  258. }
  259. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  260. {
  261. wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  262. }
  263. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  264. {
  265. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  266. }
  267. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  268. {
  269. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  270. }
  271. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  272. {
  273. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  274. }
  275. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  276. {
  277. string ReleaseState = queryParam["ReleaseState"].ToString();
  278. if (ReleaseState == "1")
  279. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  280. else if (ReleaseState == "0")
  281. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  282. }
  283. }
  284. sql = string.Format(sql, wheresql);
  285. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  286. }
  287. //工单
  288. public DataTable GetICSInspection3(ref Pagination jqgridparam, string queryJson)
  289. {
  290. DataTable dt = new DataTable();
  291. var queryParam = queryJson.ToJObject();
  292. List<DbParameter> parameter = new List<DbParameter>();
  293. string sql = @"select a.ID as GDID, e.ID , a.MOCode as DNCode, a.Sequence , h.ID as JYID, c.InvCode , c.InvName , c.INVSTD , c.ClassName,
  294. 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, e.Quantity as AllNumber,
  295. CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  296. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  297. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  298. c.InvUnit , e.LotNo , g.BadReasonDesc as BadReasonDesc ,
  299. g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc, i.ContainerID,
  300. isnull(h.MUSERName,'') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,23) as ProductTime,CONVERT(VARCHAR(100),h.MTIME,23) as MTIME,
  301. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  302. isnull(h.MUSER,'') as Surveyor, h.MUSERName as ProvingTime
  303. from ICSMO a
  304. left JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint
  305. left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint
  306. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  307. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint
  308. LEFT JOIN dbo.ICSInspection h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint
  309. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  310. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  311. LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint
  312. where e.LotNO is not null {0} ";
  313. string wheresql = "";
  314. if (!string.IsNullOrWhiteSpace(queryJson))
  315. {
  316. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  317. {
  318. wheresql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  319. }
  320. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  321. {
  322. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  323. }
  324. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  325. {
  326. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  327. }
  328. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  329. {
  330. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  331. }
  332. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  333. {
  334. string ReleaseState = queryParam["ReleaseState"].ToString();
  335. if (ReleaseState == "1")
  336. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  337. else if (ReleaseState == "0")
  338. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  339. }
  340. }
  341. sql = string.Format(sql, wheresql);
  342. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  343. }
  344. //获取不良原因
  345. public DataTable Select_ICSBadReason(string InvCode)
  346. {
  347. string sql = string.Empty;
  348. DataTable dt = null;
  349. sql = @"select '' as BadReasonCode,'' as BadReasonDesc from ICSBadReason a left join
  350. ICSInventoryBadGroup b on a.BRGroupID=b.BRGroupID
  351. union
  352. select a.BadReasonCode,a.BadReasonDesc from ICSBadReason a left join
  353. ICSInventoryBadGroup b on a.BRGroupID=b.BRGroupID
  354. where b.InvCode='{0}'";
  355. sql = string.Format(sql, InvCode);
  356. dt = SqlHelper.GetDataTableBySql(sql);
  357. return dt;
  358. }
  359. //获取不良代码
  360. public DataTable GetSelectICSBadCode(string InvCode)
  361. {
  362. string sql = string.Empty;
  363. DataTable dt = null;
  364. sql = @"
  365. select '' as BadCode ,'' as BadDesc
  366. from dbo.ICSBadCode a left join
  367. ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID
  368. union
  369. select BadCode,BadDesc from dbo.ICSBadCode a left join
  370. ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID where b.InvCode='{0}'";
  371. // sql = @"select BadCode,BadDesc from dbo.ICSBadCode a left join
  372. //ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID
  373. //where b.InvCode='{0}'";
  374. sql = string.Format(sql, InvCode);
  375. dt = SqlHelper.GetDataTableBySql(sql);
  376. return dt;
  377. }
  378. /// <summary>
  379. /// 新增检验
  380. /// </summary>
  381. /// <param name="queryJson"></param>
  382. /// <returns></returns>
  383. public string CreateICSInspection(string keyValue, string ICSInspections)
  384. {
  385. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  386. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  387. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  388. string msg = "";
  389. string sql = string.Empty;
  390. JArray res = (JArray)JsonConvert.DeserializeObject(ICSInspections);
  391. foreach (var item in res)
  392. {
  393. JObject jo = (JObject)item;
  394. string sqls = string.Empty;
  395. sqls = @"update ICSInspection set Enable='0' WHERE LotNO='{0}' and Enable='1' and WorkPoint='{1}'";
  396. sqls = string.Format(sqls, jo["LotNo"].ToString(), WorkPoint);
  397. SqlHelper.CmdExecuteNonQueryLi(sqls);
  398. //if (jo["TestState"].ToString()=="已检验")
  399. //{
  400. // 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}'";
  401. // 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());
  402. //}
  403. //else
  404. //{
  405. sql += @"INSERT INTO dbo.ICSInspection
  406. ( ID ,LotNo,InvCode ,Quantity,QualifiedQuantity ,UnqualifiedQuantity,WaiveQuantity,BCCode,BRCode,Type,MTIME,MUSER ,MUSERName ,WorkPoint ,Enable)
  407. Values(NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}',getdate(),'{9}','{10}','{11}','1')
  408. ";
  409. 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);
  410. }
  411. //}
  412. try
  413. {
  414. if (SqlHelper.ExecuteNonQuery(sql) > 0)
  415. {
  416. }
  417. else
  418. {
  419. msg = "新增失败";
  420. }
  421. }
  422. catch (Exception ex)
  423. {
  424. throw new Exception(ex.Message);
  425. }
  426. return msg;
  427. }
  428. //生成采购拒收单
  429. public string CreateRejection(string keyValue)
  430. {
  431. string msg = "";
  432. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  433. string sqlAsn = @"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode from ICSDeliveryNotice a
  434. inner join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  435. left join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  436. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  437. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  438. WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ")";
  439. DataTable dt = Repository().FindTableBySql(sqlAsn.ToString());
  440. 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
  441. from ICSDeliveryNotice a
  442. left join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  443. left join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  444. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  445. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  446. left join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint
  447. WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ") ";
  448. DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString());
  449. List<RejectionHead> asn = new List<RejectionHead>();
  450. for (int i = 0; i < dt.Rows.Count; i++)
  451. {
  452. RejectionHead ass = new RejectionHead();
  453. ass.VenCode = dt.Rows[i]["VenCode"].ToString();
  454. ass.ID = dt.Rows[i]["DNID"].ToString();
  455. ass.DepCode = dt.Rows[i]["DepCode"].ToString();
  456. ass.DNCode = dt.Rows[i]["DNCode"].ToString();
  457. ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  458. ass.MTIME = System.DateTime.Now.ToString("s");
  459. ass.WorkPoint = WorkPoint;
  460. DataRow[] drs = dtD.Select("DNID='" + dt.Rows[i]["DNID"].ToString() + "'");
  461. for (int j = 0; j < drs.Length; j++)
  462. {
  463. RejectionBody DetailList = new RejectionBody();
  464. DetailList.Sequence = (j+1).ToString();
  465. DetailList.InvCode = drs[j]["InvCode"].ToString();
  466. DetailList.Quantity = drs[j]["Quantity"].ToString();
  467. DetailList.Amount = drs[j]["Amount"].ToString();
  468. DetailList.Currency = drs[j]["Currency"].ToString();
  469. DetailList.UnitPrice = drs[j]["UnitPrice"].ToString();
  470. DetailList.DNDetailID = drs[j]["DNDetailID"].ToString();
  471. DetailList.LotNo = drs[j]["LotNo"].ToString();
  472. ass.detail.Add(DetailList);
  473. }
  474. asn.Add(ass);
  475. }
  476. string input = JsonConvert.SerializeObject(asn);
  477. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString+ "PurchaseRejectDoc/Create";
  478. string result = HttpPost(APIURL, input);
  479. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  480. string MessAge = Obj["Message"].ToString();
  481. string Success = Obj["Success"].ToString();
  482. if (Success.ToUpper() == "FALSE")
  483. {
  484. msg = MessAge;
  485. }
  486. return msg;
  487. }
  488. //生成委外拒收单
  489. public string CreateWWRejection(string keyValue)
  490. {
  491. string msg = "";
  492. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  493. string sqlAsn = @"select distinct a.VenCode,a.ODNID,a.DepCode,a.ODNCode from ICSODeliveryNotice a
  494. left join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint
  495. LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  496. inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  497. left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  498. inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint
  499. WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ")";
  500. DataTable dt = Repository().FindTableBySql(sqlAsn.ToString());
  501. 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
  502. from ICSODeliveryNotice a
  503. inner join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint
  504. inner join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  505. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  506. inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND c.WorkPoint=l.WorkPoint
  507. inner join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint
  508. WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ") ";
  509. DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString());
  510. List<WWRejectionHead> asn = new List<WWRejectionHead>();
  511. for (int i = 0; i < dt.Rows.Count; i++)
  512. {
  513. WWRejectionHead ass = new WWRejectionHead();
  514. ass.VenCode = dt.Rows[i]["VenCode"].ToString();
  515. ass.ID = dt.Rows[i]["ODNID"].ToString();
  516. ass.DepCode = dt.Rows[i]["DepCode"].ToString();
  517. ass.ODNCode = dt.Rows[i]["ODNCode"].ToString();
  518. ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  519. ass.MTIME = System.DateTime.Now.ToString("s");
  520. ass.WorkPoint = WorkPoint;
  521. DataRow[] drs = dtD.Select("ODNID='" + dt.Rows[i]["ODNID"].ToString() + "'");
  522. for (int j = 0; j < drs.Length; j++)
  523. {
  524. WWRejectionBody DetailList = new WWRejectionBody();
  525. DetailList.Sequence = (j + 1).ToString();
  526. DetailList.InvCode = drs[j]["InvCode"].ToString();
  527. DetailList.Quantity = drs[j]["Quantity"].ToString();
  528. DetailList.Amount = drs[j]["Amount"].ToString();
  529. DetailList.Currency = drs[j]["Currency"].ToString();
  530. DetailList.UnitPrice = drs[j]["UnitPrice"].ToString();
  531. DetailList.ODNDetailID = drs[j]["ODNDetailID"].ToString();
  532. DetailList.LotNo = drs[j]["LotNo"].ToString();
  533. ass.detail.Add(DetailList);
  534. }
  535. asn.Add(ass);
  536. }
  537. string input = JsonConvert.SerializeObject(asn);
  538. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingRejectDoc/Create";
  539. string result = HttpPost(APIURL, input);
  540. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  541. string MessAge = Obj["Message"].ToString();
  542. string Success = Obj["Success"].ToString();
  543. if (Success.ToUpper() == "FALSE")
  544. {
  545. msg = MessAge;
  546. }
  547. return msg;
  548. }
  549. public static string HttpPost(string url, string body)
  550. {
  551. try
  552. {
  553. Encoding encoding = Encoding.UTF8;
  554. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  555. request.Method = "POST";
  556. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  557. request.ContentType = "application/json; charset=utf-8";
  558. byte[] buffer = encoding.GetBytes(body);
  559. request.ContentLength = buffer.Length;
  560. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  561. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  562. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  563. {
  564. return reader.ReadToEnd();
  565. }
  566. }
  567. catch (WebException ex)
  568. {
  569. throw new Exception(ex.Message);
  570. }
  571. }
  572. /// <summary>
  573. /// 删除拒收单
  574. /// </summary>
  575. /// <param name="keyValue">传入ID</param>
  576. /// <returns></returns>
  577. public string DelectRejection(string keyValue)
  578. {
  579. //站点信息
  580. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  581. string msg = "";
  582. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  583. string sql = string.Empty;
  584. sql = string.Format(@"DELETE FROM dbo.ICSDeliveryNotice WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  585. try
  586. {
  587. SqlHelper.ExecuteNonQuery(sql);
  588. }
  589. catch (Exception ex)
  590. {
  591. throw new Exception(ex.Message);
  592. }
  593. return msg;
  594. }
  595. /// <summary>
  596. /// 删除委外拒收单
  597. /// </summary>
  598. /// <param name="keyValue">传入ID</param>
  599. /// <returns></returns>
  600. public string DelectWWRejection(string keyValue)
  601. {
  602. //站点信息
  603. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  604. string msg = "";
  605. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  606. string sql = string.Empty;
  607. sql = string.Format(@"DELETE FROM dbo.ICSODeliveryNotice WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  608. try
  609. {
  610. SqlHelper.ExecuteNonQuery(sql);
  611. }
  612. catch (Exception ex)
  613. {
  614. throw new Exception(ex.Message);
  615. }
  616. return msg;
  617. }
  618. public DataTable GetInventoryInspection(ref Pagination jqgridparam, string InvCode)
  619. {
  620. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  621. DataTable dt = new DataTable();
  622. List<DbParameter> parameter = new List<DbParameter>();
  623. string sql = @"select c.ID,a.GroupCode,a.GroupName,c.InspectionID,b.ListCode, b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,c.SetValue,c.Result
  624. from ICSInventoryInspectionGroup a
  625. left join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint
  626. left join ICSInspectionDetail c on b.ListCode=c.ListCode and b.ListName=c.ListName and b.WorkPoint=c.WorkPoint
  627. where a.InvCode='{0}' and b.Enable='1' and a.WorkPoint='{1}' ";
  628. sql = string.Format(sql, InvCode, WorkPoint);
  629. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  630. }
  631. public string SaveICSInspectionDetail(string ICSMTDOC, string InvCode)
  632. {
  633. string msg = "";
  634. try
  635. {
  636. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  637. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  638. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  639. string sql = string.Empty;
  640. JArray res = (JArray)JsonConvert.DeserializeObject(ICSMTDOC);
  641. foreach (var item in res)
  642. {
  643. JObject jo = (JObject)item;
  644. if (jo["ID"].ToString()==""|| jo["ID"].ToString()==null)
  645. {
  646. sql += @"
  647. INSERT INTO dbo.ICSInspectionDetail
  648. ( ID ,InspectionID ,ListCode ,ListName ,
  649. Unit ,SetValueMax ,SetValueMin ,SetValue ,Result, MUSER ,MUSERName ,MTIME, WorkPoint,GroupCode,GroupName)
  650. values(newid(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}',getdate(),'{10}','{11}','{12}')";
  651. sql = string.Format(sql, jo["InspectionID"].ToString(), jo["ListCode"].ToString(), jo["ListName"].ToString(), jo["Unit"].ToString(), jo["SetValueMax"].ToString(), jo["SetValueMin"].ToString(), jo["SetValue"].ToString(), jo["Result"].ToString(), MUSER, MUSERNAME, WorkPoint, jo["GroupCode"].ToString(), jo["GroupName"].ToString());
  652. }
  653. else
  654. {
  655. sql += @" update ICSInspectionDetail set InspectionID='{0}',ListCode='{1}',ListName='{2}', Unit='{3}' ,SetValueMax='{4}' ,SetValueMin='{5}' ,SetValue='{6}' ,Result='{7}', MUSER='{8}' ,MUSERName='{9}' ,MTIME=getdate(), WorkPoint='{10}', GroupCode='{11}', GroupName='{12}' where ID='{13}'";
  656. sql = string.Format(sql, jo["InspectionID"].ToString(), jo["ListCode"].ToString(), jo["ListName"].ToString(), jo["Unit"].ToString(), jo["SetValueMax"].ToString(), jo["SetValueMin"].ToString(), jo["SetValue"].ToString(), jo["Result"].ToString(), MUSER, MUSERNAME, WorkPoint, jo["GroupCode"].ToString(), jo["GroupName"].ToString(), jo["ID"].ToString());
  657. }
  658. }
  659. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  660. {
  661. }
  662. else
  663. {
  664. msg = "绑定失败";
  665. }
  666. }
  667. catch (Exception ex)
  668. {
  669. msg = ex.Message;
  670. }
  671. return msg;
  672. }
  673. }
  674. }