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.

5322 lines
331 KiB

3 weeks 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. using NFine.Application.SystemManage;
  22. using ICSSoft.SendMail;
  23. using System.Security.Cryptography;
  24. namespace NFine.Application.WMS
  25. {
  26. public class ICSRCVIQCsApp : RepositoryFactory<ICSVendor>
  27. {
  28. DataActionApp actionapp = new DataActionApp();
  29. /// <summary>
  30. /// 采购
  31. /// </summary>
  32. /// <param name="jqgridparam"></param>
  33. /// <returns></returns>
  34. public DataTable GetICSInspection(ref Pagination jqgridparam, string MenuID, string queryJson)
  35. {
  36. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  37. string ERPSign = Configs.GetValue("ERPSign");
  38. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  39. DataTable dt = new DataTable();
  40. var queryParam = queryJson.ToJObject();
  41. List<DbParameter> parameter = new List<DbParameter>();
  42. string sql = string.Empty;
  43. if (ERPSign == "U8")
  44. {
  45. sql = @"
  46. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1'))
  47. drop table #TempLLData_1
  48. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1_1'))
  49. drop table #TempLLData_1_1
  50. select DISTINCT
  51. a.ID as DHID,
  52. d.ID ,
  53. h.ID as JYID,
  54. a.DNCode ,
  55. -- a.Sequence ,
  56. a.ASNCode ,
  57. l.POCode,
  58. c.InvCode ,
  59. c.InvName ,
  60. c.INVSTD ,
  61. c.ClassName,
  62. c.EATTRIBUTE3 as InvEATTRIBUTE3,
  63. CAST(b.DNQuantity as decimal(18,4)) as AllNumber,
  64. CAST(ISNULL(h.QualifiedQuantity, b.DNQuantity)as decimal(18,4))as YLOTQTY ,
  65. CAST(ISNULL(h.UnqualifiedQuantity, 0) as decimal(18,4)) as NLOTQTY,
  66. CAST(ISNULL(h.WaiveQuantity, 0) as decimal(18,4)) as SpecialQTY,
  67. CASE WHEN isnull(task.ValueParameters,'') =''THEN '否' ELSE '是' END AS IsPrint,
  68. --CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) as SampleQuantity,
  69. c.InvUnit ,
  70. b.LotNo ,
  71. g.BadReasonDesc as BadReasonDesc ,
  72. g.BadReasonCode as BRCodeValue,
  73. j.BadCode as BCCodeValue,
  74. j.BadDesc as BadDesc,
  75. k.ContainerID,
  76. q.ContainerCode,
  77. isnull(h.EATTRIBUTE2,'') as InspectionEATTRIBUTE2,
  78. isnull(h.MUSERName,'') MUSERName,
  79. CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime,
  80. CONVERT(VARCHAR(100),a.CreateDateTime,120) as CreateDateTime,
  81. CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  82. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  83. a.VenCode,
  84. m.VenName,
  85. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  86. isnull(h.MUSERName,'') as Surveyor,
  87. h.MTime as ProvingTime
  88. ,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
  89. ,CASE WHEN h.Result='0' THEN '' when ISNULL(h.Result,'')='' THEN '' ELSE '' END AS Result,
  90. n.FileName
  91. ,CASE WHEN isnull(h.ID,'') ='' and s.Type='Quantity' THEN isnull(p.SampleQuantity,0)
  92. WHEN isnull(h.ID,'') ='' and s.Type='Ratio' THEN isnull(p.SampleQuantity,0)*b.DNQuantity ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity
  93. ,o.Editable
  94. ,(CASE ISNULL((SELECT COUNT(1) FROM dbo.ICSInspection hH2
  95. WHERE hH2.LotNo=b.LotNo AND hH2.WorkPoint=b.WorkPoint),0)
  96. WHEN 0 THEN '' WHEN 1 THEN '是' else '否' end ) IsFirstCK
  97. ,case d.EATTRIBUTE6 when '1' then '是' else '否' end IsUrgent,
  98. case when isnull(qq.EATTRIBUTE1,'')='' then '否' else '是' end Rejected,c.InvIQC{2}
  99. into #TempLLData_1
  100. FROM ICSDeliveryNotice a
  101. inner JOIN ICSExtension extd ON a.ExtensionID=extd.ID AND a.WorkPoint=extd.WorkPoint
  102. inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  103. inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint and c.InvIQC='1'
  104. LEFT JOIN ICSInventoryBatchEnable invBat ON c.InvCode=invBat.InvCode AND (SELECT a.F_itemCode
  105. FROM Sys_SRM_ItemsDetail a
  106. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  107. WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1')=invBat.WHCode AND c.WorkPoint=invBat.WorkPoint
  108. inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  109. INNER JOIN ICSExtension ext ON d.ExtensionID=ext.ID AND d.WorkPoint=ext.WorkPoint
  110. left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  111. LEFT JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint and h.Enable=1
  112. LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID
  113. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  114. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  115. LEFT JOIN ICSContainerLot k ON b.LotNo=k.LotNo AND b.WorkPoint=k.WorkPoint
  116. LEFT JOIN ICSContainer q on k.ContainerID=q.ContainerID AND k.WorkPoint=q.WorkPoint
  117. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND d.WorkPoint=l.WorkPoint
  118. left join ICSExtension f on d.ExtensionID=f.ID and d.WorkPoint=f.WorkPoint
  119. left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint
  120. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  121. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  122. left JOIN ICSInspectionRulesGroup s ON o.RulesCode=s.RulesCode AND o.WorkPoint=s.WorkPoint
  123. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND b.DNQuantity BETWEEN p.SetValueMin AND p.SetValueMax
  124. left join ICSDeliveryNotice qq on e.LotNo =qq.EATTRIBUTE1 and qq.DNType='3' and a.WorkPoint=qq.WorkPoint
  125. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  126. where b.LotNo is not null and a.DNType='1' AND a.WorkPoint='{1}' and
  127. ISNULL(extd.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(c.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(extd.BatchCode, '') ELSE '' END+'~'+ISNULL(extd.Version, '')+'~'+ISNULL(extd.Brand, '')+'~'+
  128. ISNULL(extd.cFree1, '')+'~'+ISNULL(extd.cFree2, '')+'~'+ISNULL(extd.cFree3, '')+'~'+ISNULL(extd.cFree4, '')+'~'+ISNULL(extd.cFree5, '')+'~'+ISNULL(extd.cFree6, '')+'~'+ISNULL(extd.cFree7, '')+'~'+ISNULL(extd.cFree8, '')+'~'+ISNULL(extd.cFree9, '')+'~'+ISNULL(extd.cFree10, '')=ISNULL(ext.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(c.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END+'~'+ISNULL(ext.Version, '')+'~'+ISNULL(ext.Brand, '')+'~'+
  129. ISNULL(ext.cFree1, '')+'~'+ISNULL(ext.cFree2, '')+'~'+ISNULL(ext.cFree3, '')+'~'+ISNULL(ext.cFree4, '')+'~'+ISNULL(ext.cFree5, '')+'~'+ISNULL(ext.cFree6, '')+'~'+ISNULL(ext.cFree7, '')+'~'+ISNULL(ext.cFree8, '')+'~'+ISNULL(ext.cFree9, '')+'~'+ISNULL(ext.cFree10, '')
  130. {0}
  131. select * into #TempLLData_1_1 from #TempLLData_1 where InvIQC='1'
  132. ";
  133. }
  134. else
  135. {
  136. sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1'))
  137. drop table #TempLLData_1
  138. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1'))
  139. drop table #TempIcsinsp_1
  140. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1_1'))
  141. drop table #TempLLData_1_1
  142. select *
  143. into #TempIcsinsp_1
  144. from dbo.ICSInspection
  145. where workpoint='" + WorkPoint + @"' and Enable='1'
  146. select DISTINCT
  147. a.ID as DHID,
  148. d.ID ,
  149. h.ID as JYID,
  150. a.DNCode ,
  151. a.Sequence ,
  152. a.ASNCode ,
  153. l.POCode,
  154. c.InvCode ,
  155. c.InvName ,
  156. c.INVSTD ,
  157. c.ClassName,
  158. c.EATTRIBUTE3 as InvEATTRIBUTE3,
  159. isnull(h.EATTRIBUTE2,'') as InspectionEATTRIBUTE2,
  160. CAST(d.Quantity as decimal(18,4)) as AllNumber,
  161. CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as decimal(18,4))as YLOTQTY ,
  162. CAST(ISNULL(h.UnqualifiedQuantity, 0) as decimal(18,4)) as NLOTQTY,
  163. CAST(ISNULL(h.WaiveQuantity, 0) as decimal(18,4)) as SpecialQTY,
  164. CASE WHEN isnull(task.ValueParameters,'') =''THEN '否' ELSE '是' END AS IsPrint,
  165. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  166. -- CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) as SampleQuantity,
  167. c.InvUnit ,
  168. d.LotNo ,
  169. g.BadReasonDesc as BadReasonDesc ,
  170. g.BadReasonCode as BRCodeValue,
  171. j.BadCode as BCCodeValue,
  172. j.BadDesc as BadDesc,
  173. k.ContainerID,
  174. isnull(h.MUSERName,'') MUSERName,
  175. CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime,
  176. CONVERT(VARCHAR(100),a.CreateDateTime,120) as CreateDateTime,
  177. CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  178. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  179. a.VenCode,
  180. m.VenName,
  181. isnull(h.MUSERName,'') as Surveyor,
  182. h.MTime as ProvingTime
  183. ,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
  184. ,CASE WHEN h.Result='0' THEN '' when ISNULL(h.Result,'')='' THEN '' ELSE '' END AS Result,
  185. n.FileName
  186. ,CASE WHEN isnull(h.ID,'') ='' and s.Type='Quantity' THEN isnull(p.SampleQuantity,0)
  187. WHEN isnull(h.ID,'') ='' and s.Type='Ratio' THEN isnull(p.SampleQuantity,0)*b.DNQuantity ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity
  188. ,o.Editable
  189. ,(CASE ISNULL((SELECT COUNT(1) FROM dbo.ICSInspection hH2
  190. WHERE hH2.LotNo=d.LotNo AND hH2.WorkPoint=a.WorkPoint),0)
  191. WHEN 0 THEN '' WHEN 1 THEN '是' else '否' end ) IsFirstCK
  192. , case d.EATTRIBUTE6 when '1' then '是' else '否' end IsUrgent,c.InvIQC{2}
  193. into #TempLLData_1
  194. FROM ICSDeliveryNotice a
  195. --inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  196. left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint
  197. inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint and c.InvIQC='1'
  198. inner JOIN ICSInventoryLot d ON e.LotNo=d.LotNo AND a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint
  199. LEFT JOIN #TempIcsinsp_1 h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint
  200. LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID
  201. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  202. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  203. LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND a.WorkPoint=k.WorkPoint
  204. inner JOIN ICSPurchaseOrder l ON a.PODetailID=l.PODetailID AND a.WorkPoint=l.WorkPoint
  205. left join ICSExtension f on d.ExtensionID=f.ID and d.WorkPoint=f.WorkPoint
  206. left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint
  207. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  208. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  209. left JOIN ICSInspectionRulesGroup s ON o.RulesCode=s.RulesCode AND o.WorkPoint=s.WorkPoint
  210. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND d.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  211. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  212. where d.LotNo is not null and a.DNType='1' AND a.WorkPoint='{1}' {0}
  213. select * into #TempLLData_1_1 from #TempLLData_1
  214. ";
  215. }
  216. string wheresql = "";
  217. if (!string.IsNullOrWhiteSpace(queryJson))
  218. {
  219. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  220. {
  221. wheresql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  222. }
  223. if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
  224. {
  225. wheresql += " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ";
  226. }
  227. if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString()))
  228. {
  229. wheresql += " and l.POCode like '%" + queryParam["CaiGouCode"].ToString() + "%' ";
  230. }
  231. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  232. {
  233. wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  234. }
  235. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  236. {
  237. wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  238. }
  239. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  240. {
  241. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  242. }
  243. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  244. {
  245. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  246. }
  247. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  248. {
  249. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  250. }
  251. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  252. {
  253. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  254. }
  255. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  256. {
  257. wheresql += " and a.CreateDateTime >= '" + queryParam["TimeFrom"].ToString() + "' ";
  258. }
  259. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  260. {
  261. wheresql += " and a.CreateDateTime <= '" + queryParam["TimeArrive"].ToString() + "' ";
  262. }
  263. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  264. {
  265. wheresql += " and b.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  266. }
  267. if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString()))
  268. {
  269. wheresql += " and case d.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' ";
  270. }
  271. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  272. {
  273. string ReleaseState = queryParam["ReleaseState"].ToString();
  274. if (ReleaseState == "1")
  275. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  276. else if (ReleaseState == "0")
  277. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  278. else
  279. wheresql += " ";
  280. }
  281. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  282. {
  283. if (queryParam["selIsWH"].ToString() == "0")
  284. {
  285. wheresql += " and lotInfo.ID is null ";
  286. }
  287. if (queryParam["selIsWH"].ToString() == "1")
  288. {
  289. wheresql += " and lotInfo.ID is not null ";
  290. }
  291. }
  292. if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString()))
  293. {
  294. string printState = queryParam["selIsPrint"].ToString();
  295. if (printState == "否")
  296. wheresql += " and isnull(task.ValueParameters,'') ='' ";
  297. else if (printState == "是")
  298. wheresql += " and isnull(task.ValueParameters,'') <>''";
  299. }
  300. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  301. {
  302. string selEnableShow = queryParam["selEnableShow"].ToString();
  303. if (selEnableShow == "1")
  304. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  305. else if (selEnableShow == "0")
  306. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  307. }
  308. if (!string.IsNullOrWhiteSpace(queryParam["Rejected"].ToString()))
  309. {
  310. string selEnableShow = queryParam["Rejected"].ToString();
  311. if (selEnableShow == "1")
  312. wheresql += "and isnull(qq.EATTRIBUTE1,'')<>''";
  313. else if (selEnableShow == "2")
  314. wheresql += "and isnull(qq.EATTRIBUTE1,'')=''";
  315. }
  316. }
  317. wheresql += " " + DataActionsql;
  318. List<string> tableName = new List<string> { "ICSInspection", "ICSInventory" };
  319. List<string> tablenameJC = new List<string> { "h.", "c." };
  320. //sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  321. sql = SqlHelper.GetEATTRIBUTE(sql, tableName, tablenameJC, wheresql, WorkPoint);//
  322. //sql = string.Format(sql, wheresql, WorkPoint);
  323. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempLLData_1_1",
  324. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1'))
  325. drop table #TempLLData_1
  326. if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempLLData_1_1'))
  327. drop table #TempLLData_1_1 ",
  328. "connstr", parameter.ToArray(), ref jqgridparam);
  329. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  330. }
  331. public DataTable GetICSInspectionYL(ref Pagination jqgridparam, string MenuID, string queryJson)
  332. {
  333. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  334. string ERPSign = Configs.GetValue("ERPSign");
  335. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  336. DataTable dt = new DataTable();
  337. var queryParam = queryJson.ToJObject();
  338. List<DbParameter> parameter = new List<DbParameter>();
  339. string sql = string.Empty;
  340. if (ERPSign == "U8")
  341. {
  342. sql = @"
  343. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1'))
  344. drop table #TempLLData_1
  345. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1_1'))
  346. drop table #TempLLData_1_1
  347. select DISTINCT
  348. a.ID as DHID,
  349. d.ID ,
  350. h.ID as JYID,
  351. a.DNCode ,
  352. -- a.Sequence ,
  353. a.ASNCode ,
  354. l.POCode,
  355. c.InvCode ,
  356. c.InvName ,
  357. c.INVSTD ,
  358. c.ClassName,
  359. c.EATTRIBUTE3 as InvEATTRIBUTE3,
  360. CAST(b.DNQuantity as decimal(18,4)) as AllNumber,
  361. CAST(ISNULL(h.QualifiedQuantity, b.DNQuantity)as decimal(18,4))as YLOTQTY ,
  362. CAST(ISNULL(h.UnqualifiedQuantity, 0) as decimal(18,4)) as NLOTQTY,
  363. CAST(ISNULL(h.WaiveQuantity, 0) as decimal(18,4)) as SpecialQTY,
  364. CASE WHEN isnull(task.ValueParameters,'') =''THEN '否' ELSE '是' END AS IsPrint,
  365. --CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) as SampleQuantity,
  366. c.InvUnit ,
  367. b.LotNo ,
  368. g.BadReasonDesc as BadReasonDesc ,
  369. g.BadReasonCode as BRCodeValue,
  370. j.BadCode as BCCodeValue,
  371. j.BadDesc as BadDesc,
  372. k.ContainerID,
  373. q.ContainerCode,
  374. isnull(h.EATTRIBUTE2,'') as InspectionEATTRIBUTE2,
  375. isnull(h.MUSERName,'') MUSERName,
  376. CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime,
  377. CONVERT(VARCHAR(100),a.CreateDateTime,120) as CreateDateTime,
  378. CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  379. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  380. a.VenCode,
  381. m.VenName,
  382. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  383. isnull(h.MUSERName,'') as Surveyor,
  384. h.MTime as ProvingTime
  385. ,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
  386. ,CASE WHEN h.Result='0' THEN '' when ISNULL(h.Result,'')='' THEN '' ELSE '' END AS Result,
  387. n.FileName
  388. ,CASE WHEN isnull(h.ID,'') ='' and s.Type='Quantity' THEN isnull(p.SampleQuantity,0)
  389. WHEN isnull(h.ID,'') ='' and s.Type='Ratio' THEN isnull(p.SampleQuantity,0)*b.DNQuantity ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity
  390. ,o.Editable
  391. ,(CASE ISNULL((SELECT COUNT(1) FROM dbo.ICSInspection hH2
  392. WHERE hH2.LotNo=b.LotNo AND hH2.WorkPoint=b.WorkPoint),0)
  393. WHEN 0 THEN '' WHEN 1 THEN '是' else '否' end ) IsFirstCK
  394. ,case d.EATTRIBUTE6 when '1' then '是' else '否' end IsUrgent,
  395. case when isnull(qq.EATTRIBUTE1,'')='' then '否' else '是' end Rejected,c.InvIQC{2}
  396. into #TempLLData_1
  397. FROM ICSDeliveryNotice a
  398. inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  399. inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint and c.InvIQC='1'
  400. inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.ExtensionID=d.ExtensionID AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  401. left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  402. LEFT JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint and h.Enable='1'
  403. LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID
  404. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  405. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  406. LEFT JOIN ICSContainerLot k ON b.LotNo=k.LotNo AND b.WorkPoint=k.WorkPoint
  407. LEFT JOIN ICSContainer q on k.ContainerID=q.ContainerID AND k.WorkPoint=q.WorkPoint
  408. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND d.WorkPoint=l.WorkPoint
  409. left join ICSExtension f on d.ExtensionID=f.ID and d.WorkPoint=f.WorkPoint
  410. left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint
  411. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  412. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  413. left JOIN ICSInspectionRulesGroup s ON o.RulesCode=s.RulesCode AND o.WorkPoint=s.WorkPoint
  414. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND b.DNQuantity BETWEEN p.SetValueMin AND p.SetValueMax
  415. left join ICSDeliveryNotice qq on e.LotNo =qq.EATTRIBUTE1 and qq.DNType='3' and a.WorkPoint=qq.WorkPoint
  416. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  417. where b.LotNo is not null and a.DNType='1' AND a.WorkPoint='{1}' {0}
  418. select * into #TempLLData_1_1 from #TempLLData_1 where InvIQC='1'
  419. ";
  420. }
  421. else
  422. {
  423. sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1'))
  424. drop table #TempLLData_1
  425. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1'))
  426. drop table #TempIcsinsp_1
  427. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1_1'))
  428. drop table #TempLLData_1_1
  429. select *
  430. into #TempIcsinsp_1
  431. from dbo.ICSInspection
  432. where workpoint='" + WorkPoint + @"' and Enable='1'
  433. select DISTINCT
  434. a.ID as DHID,
  435. d.ID ,
  436. h.ID as JYID,
  437. a.DNCode ,
  438. a.Sequence ,
  439. a.ASNCode ,
  440. l.POCode,
  441. c.InvCode ,
  442. c.InvName ,
  443. c.INVSTD ,
  444. c.ClassName,
  445. c.EATTRIBUTE3 as InvEATTRIBUTE3,
  446. isnull(h.EATTRIBUTE2,'') as InspectionEATTRIBUTE2,
  447. CAST(d.Quantity as decimal(18,4)) as AllNumber,
  448. CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as decimal(18,4))as YLOTQTY ,
  449. CAST(ISNULL(h.UnqualifiedQuantity, 0) as decimal(18,4)) as NLOTQTY,
  450. CAST(ISNULL(h.WaiveQuantity, 0) as decimal(18,4)) as SpecialQTY,
  451. CASE WHEN isnull(task.ValueParameters,'') =''THEN '否' ELSE '是' END AS IsPrint,
  452. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  453. -- CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) as SampleQuantity,
  454. c.InvUnit ,
  455. d.LotNo ,
  456. g.BadReasonDesc as BadReasonDesc ,
  457. g.BadReasonCode as BRCodeValue,
  458. j.BadCode as BCCodeValue,
  459. j.BadDesc as BadDesc,
  460. k.ContainerID,
  461. isnull(h.MUSERName,'') MUSERName,
  462. CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime,
  463. CONVERT(VARCHAR(100),a.CreateDateTime,120) as CreateDateTime,
  464. CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  465. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  466. a.VenCode,
  467. m.VenName,
  468. isnull(h.MUSERName,'') as Surveyor,
  469. h.MTime as ProvingTime
  470. ,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
  471. ,CASE WHEN h.Result='0' THEN '' when ISNULL(h.Result,'')='' THEN '' ELSE '' END AS Result,
  472. n.FileName
  473. ,CASE WHEN isnull(h.ID,'') ='' and s.Type='Quantity' THEN isnull(p.SampleQuantity,0)
  474. WHEN isnull(h.ID,'') ='' and s.Type='Ratio' THEN isnull(p.SampleQuantity,0)*b.DNQuantity ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity
  475. ,o.Editable
  476. ,(CASE ISNULL((SELECT COUNT(1) FROM dbo.ICSInspection hH2
  477. WHERE hH2.LotNo=d.LotNo AND hH2.WorkPoint=a.WorkPoint),0)
  478. WHEN 0 THEN '' WHEN 1 THEN '是' else '否' end ) IsFirstCK
  479. , case d.EATTRIBUTE6 when '1' then '是' else '否' end IsUrgent,c.InvIQC{2}
  480. into #TempLLData_1
  481. FROM ICSDeliveryNotice a
  482. --inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  483. left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint
  484. inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint and c.InvIQC='1'
  485. inner JOIN ICSInventoryLot d ON e.LotNo=d.LotNo AND a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint
  486. LEFT JOIN #TempIcsinsp_1 h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint
  487. LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID
  488. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  489. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  490. LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND a.WorkPoint=k.WorkPoint
  491. inner JOIN ICSPurchaseOrder l ON a.PODetailID=l.PODetailID AND a.WorkPoint=l.WorkPoint
  492. left join ICSExtension f on d.ExtensionID=f.ID and d.WorkPoint=f.WorkPoint
  493. left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint
  494. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  495. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  496. left JOIN ICSInspectionRulesGroup s ON o.RulesCode=s.RulesCode AND o.WorkPoint=s.WorkPoint
  497. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND d.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  498. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  499. where d.LotNo is not null and a.DNType='1' AND a.WorkPoint='{1}' {0}
  500. select * into #TempLLData_1_1 from #TempLLData_1
  501. ";
  502. }
  503. string wheresql = "";
  504. if (!string.IsNullOrWhiteSpace(queryJson))
  505. {
  506. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  507. {
  508. wheresql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  509. }
  510. if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
  511. {
  512. wheresql += " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ";
  513. }
  514. if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString()))
  515. {
  516. wheresql += " and l.POCode like '%" + queryParam["CaiGouCode"].ToString() + "%' ";
  517. }
  518. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  519. {
  520. wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  521. }
  522. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  523. {
  524. wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  525. }
  526. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  527. {
  528. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  529. }
  530. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  531. {
  532. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  533. }
  534. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  535. {
  536. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  537. }
  538. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  539. {
  540. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  541. }
  542. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  543. {
  544. wheresql += " and a.CreateDateTime >= '" + queryParam["TimeFrom"].ToString() + "' ";
  545. }
  546. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  547. {
  548. wheresql += " and a.CreateDateTime <= '" + queryParam["TimeArrive"].ToString() + "' ";
  549. }
  550. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  551. {
  552. wheresql += " and b.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  553. }
  554. if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString()))
  555. {
  556. wheresql += " and case d.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' ";
  557. }
  558. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  559. {
  560. string ReleaseState = queryParam["ReleaseState"].ToString();
  561. if (ReleaseState == "1")
  562. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  563. else if (ReleaseState == "0")
  564. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  565. else
  566. wheresql += " ";
  567. }
  568. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  569. {
  570. if (queryParam["selIsWH"].ToString() == "0")
  571. {
  572. wheresql += " and lotInfo.ID is null ";
  573. }
  574. if (queryParam["selIsWH"].ToString() == "1")
  575. {
  576. wheresql += " and lotInfo.ID is not null ";
  577. }
  578. }
  579. if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString()))
  580. {
  581. string printState = queryParam["selIsPrint"].ToString();
  582. if (printState == "否")
  583. wheresql += " and isnull(task.ValueParameters,'') ='' ";
  584. else if (printState == "是")
  585. wheresql += " and isnull(task.ValueParameters,'') <>''";
  586. }
  587. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  588. {
  589. string selEnableShow = queryParam["selEnableShow"].ToString();
  590. if (selEnableShow == "1")
  591. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  592. else if (selEnableShow == "0")
  593. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  594. }
  595. if (!string.IsNullOrWhiteSpace(queryParam["Rejected"].ToString()))
  596. {
  597. string selEnableShow = queryParam["Rejected"].ToString();
  598. if (selEnableShow == "1")
  599. wheresql += "and isnull(qq.EATTRIBUTE1,'')<>''";
  600. else if (selEnableShow == "2")
  601. wheresql += "and isnull(qq.EATTRIBUTE1,'')=''";
  602. }
  603. }
  604. wheresql += " " + DataActionsql;
  605. List<string> tableName = new List<string> { "ICSInspection", "ICSInventory" };
  606. List<string> tablenameJC = new List<string> { "h.", "c." };
  607. //sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  608. sql = SqlHelper.GetEATTRIBUTE(sql, tableName, tablenameJC, wheresql, WorkPoint);//
  609. //sql = string.Format(sql, wheresql, WorkPoint);
  610. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempLLData_1_1",
  611. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1'))
  612. drop table #TempLLData_1
  613. if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempLLData_1_1'))
  614. drop table #TempLLData_1_1 ",
  615. "connstr", parameter.ToArray(), ref jqgridparam);
  616. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  617. }
  618. public DataTable GetInspectionFile(ref Pagination jqgridparam, string queryJson, string JYID)
  619. {
  620. var queryParam = queryJson.ToJObject();
  621. List<DbParameter> parameter = new List<DbParameter>();
  622. string sql = @"SELECT * FROM dbo.ICSInspectionFile WHERE InspectionID='{0}'";
  623. sql = string.Format(sql, JYID);
  624. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  625. }
  626. //委外
  627. public DataTable GetICSInspection2(ref Pagination jqgridparam, string MenuID, string queryJson)
  628. {
  629. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  630. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  631. DataTable dt = new DataTable();
  632. var queryParam = queryJson.ToJObject();
  633. List<DbParameter> parameter = new List<DbParameter>();
  634. string sql = @"
  635. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2'))
  636. drop table #TempWWLLData_2
  637. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2_1'))
  638. drop table #TempWWLLData_2_1
  639. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_2'))
  640. drop table #TempIcsinsp_2
  641. select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,
  642. SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode{2}
  643. into #TempIcsinsp_2
  644. from dbo.ICSInspection
  645. where workpoint='" + WorkPoint + @"' and Enable='1'
  646. select DISTINCT 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,
  647. 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,c.EATTRIBUTE3 as InvEATTRIBUTE3,
  648. CAST(b.ODNQuantity as NUMERIC(10,4)) as AllNumber,
  649. CAST(ISNULL(h.QualifiedQuantity, b.ODNQuantity)as NUMERIC(10,4))as YLOTQTY ,
  650. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  651. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  652. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  653. CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity,
  654. CASE WHEN isnull(task.ValueParameters,'') =''THEN '否' ELSE '是' END AS IsPrint,
  655. c.InvUnit , b.LotNo , g.BadReasonDesc as BadReasonDesc ,g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc,
  656. k.ContainerID,isnull(h.MUSERName,'') MUSERName, CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime,
  657. CONVERT(VARCHAR(100),a.CreateDateTime,120) as CreateDateTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  658. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,a.VenCode,m.VenName,
  659. isnull(h.MUSERName,'') as Surveyor, h.MTime as ProvingTime
  660. ,CASE WHEN h.Result='0' THEN '' when ISNULL(h.Result,'')='' THEN '' ELSE '' END AS Result,
  661. n.FileName,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  662. a.EATTRIBUTE9,a.EATTRIBUTE10
  663. ,(CASE ISNULL((SELECT COUNT(1) FROM dbo.ICSInspection hH2
  664. WHERE hH2.LotNo=b.LotNo AND hH2.WorkPoint=b.WorkPoint),0)
  665. WHEN 0 THEN '' WHEN 1 THEN '是' else '否' end ) IsFirstCK
  666. ,case d.EATTRIBUTE6 when '1' then '是' else '否' end IsUrgent,
  667. case when isnull(qq.EATTRIBUTE1,'')='' then '否' else '是' end Rejected,c.InvIQC{3}
  668. into #TempWWLLData_2
  669. FROM ICSODeliveryNotice a
  670. inner JOIN ICSExtension extd ON a.ExtensionID=extd.ID AND a.WorkPoint=extd.WorkPoint
  671. LEFT JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint
  672. inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint --and c.InvIQC='1'
  673. LEFT JOIN ICSInventoryBatchEnable invBat ON c.InvCode=invBat.InvCode AND (SELECT a.F_itemCode
  674. FROM Sys_SRM_ItemsDetail a
  675. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  676. WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1')=invBat.WHCode AND c.WorkPoint=invBat.WorkPoint
  677. inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint --AND a.ExtensionID=d.ExtensionID
  678. INNER JOIN ICSExtension ext ON d.ExtensionID=ext.ID AND d.WorkPoint=ext.WorkPoint
  679. left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  680. LEFT JOIN #TempIcsinsp_2 h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint -- and Enable='1'
  681. LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID
  682. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  683. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  684. LEFT JOIN ICSContainerLot k ON b.LotNo=k.LotNo AND b.WorkPoint=k.WorkPoint
  685. inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint
  686. left join ICSExtension f on d.ExtensionID=f.ID and d.WorkPoint=f.WorkPoint
  687. left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint
  688. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  689. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  690. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND d.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  691. left join ICSDeliveryNotice qq on e.LotNo =qq.EATTRIBUTE1 and qq.DNType='3' and a.WorkPoint=qq.WorkPoint
  692. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  693. where b.LotNo is not null and ISNULL(CAST(b.ODNQuantity as VARCHAR), '')! =''
  694. AND ISNULL(b.ODNQuantity, 0)<>0 {0} and a.workpoint='{1}' and
  695. ISNULL(extd.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(c.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(extd.BatchCode, '') ELSE '' END+'~'+ISNULL(extd.Version, '')+'~'+ISNULL(extd.Brand, '')+'~'+
  696. ISNULL(extd.cFree1, '')+'~'+ISNULL(extd.cFree2, '')+'~'+ISNULL(extd.cFree3, '')+'~'+ISNULL(extd.cFree4, '')+'~'+ISNULL(extd.cFree5, '')+'~'+ISNULL(extd.cFree6, '')+'~'+ISNULL(extd.cFree7, '')+'~'+ISNULL(extd.cFree8, '')+'~'+ISNULL(extd.cFree9, '')+'~'+ISNULL(extd.cFree10, '')=ISNULL(ext.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(c.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END+'~'+ISNULL(ext.Version, '')+'~'+ISNULL(ext.Brand, '')+'~'+
  697. ISNULL(ext.cFree1, '')+'~'+ISNULL(ext.cFree2, '')+'~'+ISNULL(ext.cFree3, '')+'~'+ISNULL(ext.cFree4, '')+'~'+ISNULL(ext.cFree5, '')+'~'+ISNULL(ext.cFree6, '')+'~'+ISNULL(ext.cFree7, '')+'~'+ISNULL(ext.cFree8, '')+'~'+ISNULL(ext.cFree9, '')+'~'+ISNULL(ext.cFree10, '')
  698. select * into #TempWWLLData_2_1 from #TempWWLLData_2 where InvIQC='1'
  699. ";
  700. #region 无SRM逻辑
  701. // sql = @"UNION all
  702. //select
  703. // a.ID as DHID,
  704. // d.ID ,
  705. // h.ID as JYID,
  706. // a.ODNCode as DNCode ,
  707. // a.Sequence ,
  708. // a.OASNCode ,
  709. // c.InvCode ,
  710. // c.InvName ,
  711. // c.INVSTD ,
  712. // c.ClassName,
  713. // f.BatchCode ,
  714. // CAST(d.Quantity as NUMERIC(10,4)) as AllNumber,
  715. // CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  716. // CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  717. // CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  718. // c.InvUnit ,
  719. // d.LotNo ,
  720. // g.BadReasonDesc as BadReasonDesc ,
  721. // g.BadReasonCode as BRCodeValue,
  722. // j.BadCode as BCCodeValue,
  723. // j.BadDesc as BadDesc,
  724. // k.ContainerID,
  725. // isnull(h.MUSERName,'开发者') MUSERName,
  726. // CONVERT(VARCHAR(100),d.ProductDate,23) as ProductTime,
  727. // CONVERT(VARCHAR(100),h.MTIME,23) as MTIME,
  728. // CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END AS TestState
  729. // FROM ICSODeliveryNotice a
  730. // inner join ICSInventoryLotDetail e on e.TransCode =a.ODNCode AND e.TransSequence=a.Sequence AND e.WorkPoint=a.WorkPoint
  731. // inner JOIN ICSInventoryLot d ON d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  732. // LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  733. // LEFT JOIN dbo.ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=d.WorkPoint
  734. // left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  735. // left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  736. // LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND d.WorkPoint=k.WorkPoint
  737. // left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  738. // where 1=1 {0}";
  739. #endregion
  740. string wheresql = "";
  741. if (!string.IsNullOrWhiteSpace(queryJson))
  742. {
  743. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  744. {
  745. wheresql += " and a.ODNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  746. }
  747. if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
  748. {
  749. wheresql += " and a.OASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ";
  750. }
  751. if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString()))
  752. {
  753. wheresql += " and l.OOCode like '%" + queryParam["CaiGouCode"].ToString() + "%' ";
  754. }
  755. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  756. {
  757. wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  758. }
  759. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  760. {
  761. wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  762. }
  763. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  764. {
  765. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  766. }
  767. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  768. {
  769. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  770. }
  771. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  772. {
  773. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  774. }
  775. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  776. {
  777. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  778. }
  779. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  780. {
  781. wheresql += " and a.CreateDateTime >= '" + queryParam["TimeFrom"].ToString() + "' ";
  782. }
  783. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  784. {
  785. wheresql += " and a.CreateDateTime <= '" + queryParam["TimeArrive"].ToString() + "' ";
  786. }
  787. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  788. {
  789. wheresql += " and b.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  790. }
  791. if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString()))
  792. {
  793. wheresql += " and case d.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' ";
  794. }
  795. if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString()))
  796. {
  797. string printState = queryParam["selIsPrint"].ToString();
  798. if (printState == "否")
  799. wheresql += " and isnull(task.ValueParameters,'') ='' ";
  800. else if (printState == "是")
  801. wheresql += " and isnull(task.ValueParameters,'') <>''";
  802. }
  803. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  804. {
  805. string ReleaseState = queryParam["ReleaseState"].ToString();
  806. if (ReleaseState == "1")
  807. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  808. else if (ReleaseState == "0")
  809. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  810. else
  811. wheresql += " ";
  812. }
  813. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  814. {
  815. string selEnableShow = queryParam["selEnableShow"].ToString();
  816. if (selEnableShow == "1")
  817. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  818. else if (selEnableShow == "0")
  819. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  820. }
  821. if (!string.IsNullOrWhiteSpace(queryParam["Rejected"].ToString()))
  822. {
  823. string selEnableShow = queryParam["Rejected"].ToString();
  824. if (selEnableShow == "1")
  825. wheresql += "and isnull(qq.EATTRIBUTE1,'')<>''";
  826. else if (selEnableShow == "2")
  827. wheresql += "and isnull(qq.EATTRIBUTE1,'')=''";
  828. }
  829. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  830. {
  831. if (queryParam["selIsWH"].ToString() == "0")
  832. {
  833. wheresql += " and lotInfo.ID is null ";
  834. }
  835. if (queryParam["selIsWH"].ToString() == "1")
  836. {
  837. wheresql += " and lotInfo.ID is not null ";
  838. }
  839. }
  840. }
  841. wheresql += " " + DataActionsql;
  842. //sql = string.Format(sql, wheresql, WorkPoint);
  843. sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  844. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempWWLLData_2_1",
  845. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2'))
  846. drop table #TempWWLLData_2
  847. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempWWLLData_2_1'))
  848. drop table #TempWWLLData_2_1
  849. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_2'))
  850. drop table #TempIcsinsp_2 ",
  851. "connstr", parameter.ToArray(), ref jqgridparam);
  852. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  853. }
  854. //工单
  855. public DataTable GetICSInspection3(ref Pagination jqgridparam, string MenuID, string queryJson)
  856. {
  857. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  858. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  859. DataTable dt = new DataTable();
  860. var queryParam = queryJson.ToJObject();
  861. List<DbParameter> parameter = new List<DbParameter>();
  862. string sql = @"
  863. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3'))
  864. drop table #TempMOData_3
  865. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3_1'))
  866. drop table #TempMOData_3_1
  867. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_3'))
  868. drop table #TempIcsinsp_3
  869. select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,
  870. SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode{2}
  871. into #TempIcsinsp_3
  872. from dbo.ICSInspection
  873. where workpoint='" + WorkPoint + @"' and Enable='1'
  874. select DISTINCT a.ID as GDID, e.ID , a.MOCode as DNCode, a.Sequence , h.ID as JYID, c.InvCode , c.InvName , c.INVSTD , c.ClassName,c.InvDesc,
  875. 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,
  876. CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  877. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  878. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  879. CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity ,
  880. c.InvUnit , e.LotNo , g.BadReasonDesc as BadReasonDesc ,
  881. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  882. g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc, i.ContainerID,
  883. isnull(h.MUSERName,'') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  884. CASE WHEN isnull(h.ID,'') ='' and c.InvFQC='1' THEN '' WHEN c.InvFQC='0' then '' ELSE '' END AS TestState,
  885. isnull(h.MUSERName,'') as Surveyor, h.MTime as ProvingTime
  886. ,CASE WHEN h.Result='0' THEN '' when ISNULL(h.Result,'')='' THEN '' ELSE '' END AS Result,
  887. n.FileName,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  888. a.EATTRIBUTE9,a.EATTRIBUTE10--,c.InvIQC
  889. ,c.EATTRIBUTE3 as InvEATTRIBUTE3 ,c.InvFQC{3}
  890. into #TempMOData_3
  891. from ICSMO a
  892. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1'
  893. left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint
  894. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  895. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint
  896. LEFT JOIN #TempIcsinsp_3 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1'
  897. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  898. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  899. LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint
  900. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  901. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  902. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND e.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  903. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  904. where a.MOStatus<>'3' and e.LotNO is not null {0} and isnull(e.EATTRIBUTE1,'' )='' and a.workpoint='{1}'
  905. select * into #TempMOData_3_1 from #TempMOData_3 where --InvIQC='1'
  906. InvFQC='1'
  907. ";
  908. string wheresql = "";
  909. if (!string.IsNullOrWhiteSpace(queryJson))
  910. {
  911. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  912. {
  913. wheresql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  914. }
  915. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  916. {
  917. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  918. }
  919. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  920. {
  921. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  922. }
  923. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  924. {
  925. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  926. }
  927. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  928. {
  929. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  930. }
  931. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  932. {
  933. wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  934. }
  935. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  936. {
  937. string ReleaseState = queryParam["ReleaseState"].ToString();
  938. if (ReleaseState == "1")
  939. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  940. else if (ReleaseState == "0")
  941. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  942. else
  943. wheresql += " ";
  944. }
  945. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  946. {
  947. string selEnableShow = queryParam["selEnableShow"].ToString();
  948. if (selEnableShow == "1")
  949. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  950. else if (selEnableShow == "0")
  951. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  952. }
  953. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  954. {
  955. if (queryParam["selIsWH"].ToString() == "0")
  956. {
  957. wheresql += " and lotInfo.ID is null ";
  958. }
  959. if (queryParam["selIsWH"].ToString() == "1")
  960. {
  961. wheresql += " and lotInfo.ID is not null ";
  962. }
  963. }
  964. }
  965. wheresql += " " + DataActionsql;
  966. //sql = string.Format(sql, wheresql, WorkPoint);
  967. sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  968. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  969. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_3_1",
  970. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3'))
  971. drop table #TempMOData_3
  972. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_3_1'))
  973. drop table #TempMOData_3_1
  974. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_3'))
  975. drop table #TempIcsinsp_3",
  976. "connstr", parameter.ToArray(), ref jqgridparam);
  977. }
  978. //其他入库
  979. public DataTable GetICSInspection4(ref Pagination jqgridparam, string MenuID, string queryJson)
  980. {
  981. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  982. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  983. DataTable dt = new DataTable();
  984. var queryParam = queryJson.ToJObject();
  985. List<DbParameter> parameter = new List<DbParameter>();
  986. string sql = @"
  987. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempQTLLData_4'))
  988. drop table #TempQTLLData_4
  989. if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempQTLLData_4_1'))
  990. drop table #TempQTLLData_4_1
  991. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_4'))
  992. drop table #TempIcsinsp_4
  993. select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,
  994. SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode{2}
  995. into #TempIcsinsp_4
  996. from dbo.ICSInspection
  997. where workpoint='" + WorkPoint + @"' and Enable='1'
  998. select DISTINCT a.ID as GDID, e.ID , a.InCode as DNCode, a.Sequence , h.ID as JYID, c.InvCode , c.InvName , c.INVSTD , c.ClassName,
  999. 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, c.EATTRIBUTE3 as InvEATTRIBUTE3,
  1000. CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  1001. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  1002. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  1003. CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity ,
  1004. c.InvUnit , e.LotNo , g.BadReasonDesc as BadReasonDesc ,
  1005. g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc, i.ContainerID,
  1006. isnull(h.MUSERName,'') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  1007. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  1008. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  1009. CASE WHEN isnull(task.ValueParameters,'') =''THEN '否' ELSE '是' END AS IsPrint,
  1010. isnull(h.MUSERName,'') as Surveyor, h.MTime as ProvingTime
  1011. ,CASE WHEN h.Result='0' THEN '' when ISNULL(h.Result,'')='' THEN '' ELSE '' END AS Result,
  1012. n.FileName,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  1013. a.EATTRIBUTE9,a.EATTRIBUTE10
  1014. ,(CASE ISNULL((SELECT COUNT(1) FROM dbo.ICSInspection hH2
  1015. WHERE hH2.LotNo=e.LotNo AND hH2.WorkPoint=b.WorkPoint and hh2.InvCode=e.InvCode),0)
  1016. WHEN 0 THEN '' WHEN 1 THEN '是' else '否' end ) IsFirstCK
  1017. ,case e.EATTRIBUTE6 when '1' then '是' else '否' end IsUrgent,c.InvIQC{3}
  1018. INTO #TempQTLLData_4
  1019. from ICSOtherIn a
  1020. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1'
  1021. left join ICSInventoryLotDetail b on a.InCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint
  1022. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint AND ISNULL(e.EATTRIBUTE1,'')=''
  1023. left join ICSExtension f on e.ExtensionID=f.ID and e.WorkPoint=f.WorkPoint
  1024. LEFT JOIN #TempIcsinsp_4 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1'
  1025. LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID
  1026. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  1027. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  1028. LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint
  1029. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  1030. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  1031. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND e.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  1032. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  1033. where e.LotNO is not null {0} and a.workpoint='{1}'
  1034. select * into #TempQTLLData_4_1 from #TempQTLLData_4 where InvIQC='1' ";
  1035. string wheresql = "";
  1036. if (!string.IsNullOrWhiteSpace(queryJson))
  1037. {
  1038. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  1039. {
  1040. wheresql += " and a.InCode like '%" + queryParam["POCode"].ToString() + "%' ";
  1041. }
  1042. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1043. {
  1044. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  1045. }
  1046. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  1047. {
  1048. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  1049. }
  1050. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  1051. {
  1052. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  1053. }
  1054. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  1055. {
  1056. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  1057. }
  1058. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  1059. {
  1060. wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  1061. }
  1062. if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString()))
  1063. {
  1064. wheresql += " and case e.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' ";
  1065. }
  1066. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  1067. {
  1068. string ReleaseState = queryParam["ReleaseState"].ToString();
  1069. if (ReleaseState == "1")
  1070. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  1071. else if (ReleaseState == "0")
  1072. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  1073. else
  1074. wheresql += " ";
  1075. }
  1076. if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString()))
  1077. {
  1078. string printState = queryParam["selIsPrint"].ToString();
  1079. if (printState == "否")
  1080. wheresql += " and isnull(task.ValueParameters,'') ='' ";
  1081. else if (printState == "是")
  1082. wheresql += " and isnull(task.ValueParameters,'') <>''";
  1083. }
  1084. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  1085. {
  1086. string selEnableShow = queryParam["selEnableShow"].ToString();
  1087. if (selEnableShow == "1")
  1088. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  1089. else if (selEnableShow == "0")
  1090. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  1091. }
  1092. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  1093. {
  1094. if (queryParam["selIsWH"].ToString() == "0")
  1095. {
  1096. wheresql += " and lotInfo.ID is null ";
  1097. }
  1098. if (queryParam["selIsWH"].ToString() == "1")
  1099. {
  1100. wheresql += " and lotInfo.ID is not null ";
  1101. }
  1102. }
  1103. }
  1104. wheresql += " " + DataActionsql;
  1105. //sql = string.Format(sql, wheresql, WorkPoint);
  1106. sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  1107. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempQTLLData_4_1",
  1108. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempQTLLData_4'))
  1109. drop table #TempQTLLData_4
  1110. if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempQTLLData_4_1'))
  1111. drop table #TempQTLLData_4_1
  1112. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_4'))
  1113. drop table #TempIcsinsp_4 ",
  1114. "connstr", parameter.ToArray(), ref jqgridparam);
  1115. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  1116. }
  1117. //生产退料
  1118. public DataTable GetICSInspection5(ref Pagination jqgridparam, string MenuID, string queryJson)
  1119. {
  1120. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  1121. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1122. DataTable dt = new DataTable();
  1123. var queryParam = queryJson.ToJObject();
  1124. List<DbParameter> parameter = new List<DbParameter>();
  1125. string sql = @"
  1126. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5'))
  1127. drop table #TempMOData_5
  1128. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5_1'))
  1129. drop table #TempMOData_5_1
  1130. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_5'))
  1131. drop table #TempIcsinsp_5
  1132. select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,
  1133. SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode{2}
  1134. into #TempIcsinsp_5
  1135. from dbo.ICSInspection
  1136. where workpoint='" + WorkPoint + @"' and Enable='1'
  1137. select DISTINCT a.ID as GDID, e.ID , a.ApplyNegCode as DNCode, ad.Sequence , h.ID as JYID, c.InvCode , c.InvName , c.INVSTD , c.ClassName,
  1138. 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, c.EATTRIBUTE3 as InvEATTRIBUTE3,
  1139. CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  1140. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  1141. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  1142. CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity ,
  1143. c.InvUnit , e.LotNo , g.BadReasonDesc as BadReasonDesc ,
  1144. g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc, i.ContainerID,
  1145. isnull(h.MUSERName,'') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  1146. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  1147. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  1148. isnull(h.MUSERName,'') as Surveyor, h.MTime as ProvingTime
  1149. ,CASE WHEN h.Result='0' THEN '' when ISNULL(h.Result,'')='' THEN '' ELSE '' END AS Result,
  1150. n.FileName ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  1151. a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC{3}
  1152. into #TempMOData_5
  1153. from ICSMOApplyNeg a
  1154. LEFT JOIN ICSMOApplyNegDetail ad ON a.ApplyNegCode=ad.ApplyNegCode AND a.WorkPoint=ad.WorkPoint
  1155. inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint=c.WorkPoint --and c.InvIQC='1'
  1156. left join ICSInventoryLotDetail b on a.ApplyNegCode=b.TransCode and ad.Sequence=b.TransSequence and ad.WorkPoint=b.WorkPoint
  1157. left join ICSExtension f on ad.ExtensionID=f.ID and ad.WorkPoint=f.WorkPoint
  1158. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint
  1159. LEFT JOIN #TempIcsinsp_5 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint-- and Enable='1'
  1160. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  1161. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  1162. LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint
  1163. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  1164. LEFT JOIN ICSInventoryInspectionRulesGroup o ON ad.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  1165. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND e.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  1166. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  1167. where e.LotNO is not null {0} AND A.Workpoint='{1}'
  1168. select * into #TempMOData_5_1 from #TempMOData_5 where InvIQC='1' ";
  1169. string wheresql = "";
  1170. if (!string.IsNullOrWhiteSpace(queryJson))
  1171. {
  1172. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  1173. {
  1174. wheresql += " and a.ApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' ";
  1175. }
  1176. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1177. {
  1178. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  1179. }
  1180. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  1181. {
  1182. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  1183. }
  1184. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  1185. {
  1186. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  1187. }
  1188. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  1189. {
  1190. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  1191. }
  1192. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  1193. {
  1194. wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  1195. }
  1196. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  1197. {
  1198. string ReleaseState = queryParam["ReleaseState"].ToString();
  1199. if (ReleaseState == "1")
  1200. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  1201. else if (ReleaseState == "0")
  1202. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  1203. else
  1204. wheresql += " ";
  1205. }
  1206. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  1207. {
  1208. string selEnableShow = queryParam["selEnableShow"].ToString();
  1209. if (selEnableShow == "1")
  1210. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  1211. else if (selEnableShow == "0")
  1212. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  1213. }
  1214. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  1215. {
  1216. if (queryParam["selIsWH"].ToString() == "0")
  1217. {
  1218. wheresql += " and lotInfo.ID is null ";
  1219. }
  1220. if (queryParam["selIsWH"].ToString() == "1")
  1221. {
  1222. wheresql += " and lotInfo.ID is not null ";
  1223. }
  1224. }
  1225. }
  1226. wheresql += " " + DataActionsql;
  1227. //sql = string.Format(sql, wheresql, WorkPoint);
  1228. sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  1229. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  1230. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_5_1",
  1231. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5'))
  1232. drop table #TempMOData_5
  1233. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5_1'))
  1234. drop table #TempMOData_5_1
  1235. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_5'))
  1236. drop table #TempIcsinsp_5 ",
  1237. "connstr", parameter.ToArray(), ref jqgridparam);
  1238. }
  1239. //委外退料
  1240. public DataTable GetICSInspection6(ref Pagination jqgridparam, string MenuID, string queryJson)
  1241. {
  1242. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  1243. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1244. DataTable dt = new DataTable();
  1245. var queryParam = queryJson.ToJObject();
  1246. List<DbParameter> parameter = new List<DbParameter>();
  1247. string sql = @"
  1248. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6'))
  1249. drop table #TempMOData_6
  1250. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6_1'))
  1251. drop table #TempMOData_6_1
  1252. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_6'))
  1253. drop table #TempIcsinsp_6
  1254. select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,
  1255. SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode{2}
  1256. into #TempIcsinsp_6
  1257. from dbo.ICSInspection
  1258. where workpoint='" + WorkPoint + @"' and Enable='1'
  1259. select DISTINCT a.ID as GDID, e.ID , a.OApplyNegCode as DNCode, ad.Sequence , h.ID as JYID, c.InvCode , c.InvName , c.INVSTD , c.ClassName,
  1260. 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, c.EATTRIBUTE3 as InvEATTRIBUTE3,
  1261. CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  1262. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  1263. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  1264. CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity ,
  1265. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  1266. c.InvUnit , e.LotNo , g.BadReasonDesc as BadReasonDesc ,
  1267. g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc, i.ContainerID,
  1268. isnull(h.MUSERName,'') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  1269. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  1270. isnull(h.MUSERName,'') as Surveyor, h.MTime as ProvingTime
  1271. ,CASE WHEN h.Result='0' THEN '' when ISNULL(h.Result,'')='' THEN '' ELSE '' END AS Result,
  1272. n.FileName,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  1273. a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC{3}
  1274. into #TempMOData_6
  1275. from ICSOApplyNeg a
  1276. LEFT JOIN ICSOApplyNegDetail ad ON a.OApplyNegCode=ad.OApplyNegCode AND a.WorkPoint=ad.WorkPoint
  1277. inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint=c.WorkPoint --and c.InvIQC='1'
  1278. left join ICSInventoryLotDetail b on a.OApplyNegCode=b.TransCode and ad.Sequence=b.TransSequence and ad.WorkPoint=b.WorkPoint
  1279. left join ICSExtension f on ad.ExtensionID=f.ID and ad.WorkPoint=f.WorkPoint
  1280. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint
  1281. LEFT JOIN #TempIcsinsp_6 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint -- and Enable='1'
  1282. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  1283. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  1284. LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint
  1285. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  1286. LEFT JOIN ICSInventoryInspectionRulesGroup o ON ad.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  1287. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND e.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  1288. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  1289. where e.LotNO is not null {0} and a.workpoint='{1}'
  1290. select * into #TempMOData_6_1 from #TempMOData_6 where InvIQC='1'
  1291. ";
  1292. string wheresql = "";
  1293. if (!string.IsNullOrWhiteSpace(queryJson))
  1294. {
  1295. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  1296. {
  1297. wheresql += " and a.OApplyNegCode like '%" + queryParam["POCode"].ToString() + "%' ";
  1298. }
  1299. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1300. {
  1301. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  1302. }
  1303. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  1304. {
  1305. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  1306. }
  1307. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  1308. {
  1309. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  1310. }
  1311. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  1312. {
  1313. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  1314. }
  1315. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  1316. {
  1317. wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  1318. }
  1319. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  1320. {
  1321. string ReleaseState = queryParam["ReleaseState"].ToString();
  1322. if (ReleaseState == "1")
  1323. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  1324. else if (ReleaseState == "0")
  1325. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  1326. else
  1327. wheresql += " ";
  1328. }
  1329. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  1330. {
  1331. string selEnableShow = queryParam["selEnableShow"].ToString();
  1332. if (selEnableShow == "1")
  1333. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  1334. else if (selEnableShow == "0")
  1335. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  1336. }
  1337. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  1338. {
  1339. if (queryParam["selIsWH"].ToString() == "0")
  1340. {
  1341. wheresql += " and lotInfo.ID is null ";
  1342. }
  1343. if (queryParam["selIsWH"].ToString() == "1")
  1344. {
  1345. wheresql += " and lotInfo.ID is not null ";
  1346. }
  1347. }
  1348. }
  1349. wheresql += " " + DataActionsql;
  1350. //sql = string.Format(sql, wheresql, WorkPoint);
  1351. sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  1352. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  1353. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_6_1",
  1354. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6'))
  1355. drop table #TempMOData_6
  1356. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_6_1'))
  1357. drop table #TempMOData_6_1
  1358. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_6'))
  1359. drop table #TempIcsinsp_6 ",
  1360. "connstr", parameter.ToArray(), ref jqgridparam);
  1361. }
  1362. //销售退货
  1363. public DataTable GetICSInspection7(ref Pagination jqgridparam, string MenuID, string queryJson)
  1364. {
  1365. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  1366. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1367. DataTable dt = new DataTable();
  1368. var queryParam = queryJson.ToJObject();
  1369. List<DbParameter> parameter = new List<DbParameter>();
  1370. string sql = @"
  1371. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_7'))
  1372. drop table #TempMOData_7
  1373. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData7_1'))
  1374. drop table #TempMOData_7_1
  1375. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_7'))
  1376. drop table #TempIcsinsp_7
  1377. select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,
  1378. SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode{2}
  1379. into #TempIcsinsp_7
  1380. from dbo.ICSInspection
  1381. where workpoint='" + WorkPoint + @"' and Enable='1'
  1382. select DISTINCT a.ID as GDID, e.ID , a.SDNCode as DNCode, a.Sequence , h.ID as JYID, c.InvCode , c.InvName , c.INVSTD , c.ClassName,
  1383. 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, c.EATTRIBUTE3 as InvEATTRIBUTE3,
  1384. CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  1385. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  1386. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  1387. CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity ,
  1388. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  1389. c.InvUnit , e.LotNo , g.BadReasonDesc as BadReasonDesc ,
  1390. g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc, i.ContainerID,
  1391. isnull(h.MUSERName,'') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  1392. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  1393. isnull(h.MUSERName,'') as Surveyor, h.MTime as ProvingTime
  1394. ,CASE WHEN h.Result='0' THEN '' when ISNULL(h.Result,'')='' THEN '' ELSE '' END AS Result,
  1395. n.FileName,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  1396. a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC{3}
  1397. into #TempMOData_7
  1398. from ICSSDN a
  1399. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1'
  1400. left join ICSInventoryLotDetail b on a.SDNCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint
  1401. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  1402. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint
  1403. LEFT JOIN #TempIcsinsp_7 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint -- and Enable='1'
  1404. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  1405. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  1406. LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint
  1407. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  1408. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  1409. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND e.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  1410. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  1411. where e.LotNO is not null AND a.Type='2' {0} and a.workpoint='{1}'
  1412. select * into #TempMOData_7_1 from #TempMOData_7 where InvIQC='1' ";
  1413. string wheresql = "";
  1414. if (!string.IsNullOrWhiteSpace(queryJson))
  1415. {
  1416. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  1417. {
  1418. wheresql += " and a.SDNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  1419. }
  1420. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  1421. {
  1422. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  1423. }
  1424. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  1425. {
  1426. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  1427. }
  1428. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  1429. {
  1430. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  1431. }
  1432. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  1433. {
  1434. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  1435. }
  1436. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  1437. {
  1438. wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  1439. }
  1440. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  1441. {
  1442. string ReleaseState = queryParam["ReleaseState"].ToString();
  1443. if (ReleaseState == "1")
  1444. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  1445. else if (ReleaseState == "0")
  1446. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  1447. else
  1448. wheresql += " ";
  1449. }
  1450. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  1451. {
  1452. string selEnableShow = queryParam["selEnableShow"].ToString();
  1453. if (selEnableShow == "1")
  1454. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  1455. else if (selEnableShow == "0")
  1456. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  1457. }
  1458. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  1459. {
  1460. if (queryParam["selIsWH"].ToString() == "0")
  1461. {
  1462. wheresql += " and lotInfo.ID is null ";
  1463. }
  1464. if (queryParam["selIsWH"].ToString() == "1")
  1465. {
  1466. wheresql += " and lotInfo.ID is not null ";
  1467. }
  1468. }
  1469. }
  1470. wheresql += " " + DataActionsql;
  1471. //sql = string.Format(sql, wheresql, WorkPoint);
  1472. sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  1473. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  1474. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_7_1",
  1475. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_7'))
  1476. drop table #TempMOData_7
  1477. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData7_1'))
  1478. drop table #TempMOData_7_1
  1479. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_7'))
  1480. drop table #TempIcsinsp_7 ",
  1481. "connstr", parameter.ToArray(), ref jqgridparam);
  1482. }
  1483. //获取不良原因
  1484. public DataTable Select_ICSBadReason(string InvCode)
  1485. {
  1486. string sql = string.Empty;
  1487. DataTable dt = null;
  1488. sql = @"select '' as BadReasonCode,'' as BadReasonDesc from ICSBadReason a left join
  1489. ICSInventoryBadGroup b on a.BRGroupID=b.BRGroupID
  1490. union
  1491. select a.BadReasonCode,a.BadReasonDesc from ICSBadReason a left join
  1492. ICSInventoryBadGroup b on a.BRGroupID=b.BRGroupID
  1493. where b.InvCode='{0}'";
  1494. sql = string.Format(sql, InvCode);
  1495. dt = SqlHelper.GetDataTableBySql(sql);
  1496. return dt;
  1497. }
  1498. //获取不良代码
  1499. public DataTable GetSelectICSBadCode(string InvCode)
  1500. {
  1501. string sql = string.Empty;
  1502. DataTable dt = null;
  1503. sql = @"
  1504. select '' as BadCode ,'' as BadDesc
  1505. from dbo.ICSBadCode a left join
  1506. ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID
  1507. union
  1508. select BadCode,BadDesc from dbo.ICSBadCode a left join
  1509. ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID where b.InvCode='{0}'";
  1510. // sql = @"select BadCode,BadDesc from dbo.ICSBadCode a left join
  1511. //ICSInventoryBadGroup b on a.BCGroupID=b.BCGroupID
  1512. //where b.InvCode='{0}'";
  1513. sql = string.Format(sql, InvCode);
  1514. dt = SqlHelper.GetDataTableBySql(sql);
  1515. return dt;
  1516. }
  1517. /// <summary>
  1518. /// 新增检验
  1519. /// </summary>
  1520. /// <param name="queryJson"></param>
  1521. /// <returns></returns>
  1522. //public string CreateICSInspection(string keyValue, string ICSInspections)
  1523. //{
  1524. // string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1525. // string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1526. // string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1527. // string msg = "";
  1528. // string sql = string.Empty;
  1529. // JArray res = (JArray)JsonConvert.DeserializeObject(ICSInspections);
  1530. // foreach (var item in res)
  1531. // {
  1532. // object CARID = Guid.NewGuid();
  1533. // JObject jo = (JObject)item;
  1534. // string sqls = string.Empty;
  1535. // if (!string.IsNullOrWhiteSpace(jo["JYID"].ToString()))
  1536. // {
  1537. // sqls += "update ICSInspectionDetailGroup set InspectionID='{2}' WHERE InspectionID='{3}' and WorkPoint='{1}' ";
  1538. // }
  1539. // sqls += @"update ICSInspection set Enable='0' WHERE LotNO='{0}' and Enable='1' and WorkPoint='{1}'";
  1540. // sqls = string.Format(sqls, jo["LotNo"].ToString(), WorkPoint, CARID, jo["JYID"].ToString());
  1541. // SqlHelper.CmdExecuteNonQueryLi(sqls);
  1542. // //if (jo["TestState"].ToString()=="已检验")
  1543. // //{
  1544. // // 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}'";
  1545. // // 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());
  1546. // //}
  1547. // //else
  1548. // //{
  1549. // sql += @"
  1550. // -- IF EXISTS(select LotNo from dbo.ICSWareHouseLotInfo where LotNo='{0}' and WorkPoint='{11}')
  1551. // -- BEGIN
  1552. // -- RAISERROR('条码:{0}已入库!',16,1);
  1553. // -- RETURN
  1554. // -- end
  1555. // INSERT INTO dbo.ICSInspection
  1556. // ( ID ,LotNo,InvCode ,Quantity,QualifiedQuantity ,UnqualifiedQuantity,WaiveQuantity,BCCode,BRCode,Type,MTIME,MUSER ,MUSERName ,WorkPoint ,Enable,SampleQuantity,Result,EATTRIBUTE2)
  1557. // Values('{13}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}',getdate(),'{9}','{10}','{11}','1','{12}','{14}','{15}')
  1558. // ";
  1559. // 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, jo["SampleQuantity"].ToString(), CARID, jo["Result"].ToString(), jo["EATTRIBUTE2"].ToString());
  1560. // }
  1561. // //}
  1562. // try
  1563. // {
  1564. // if (SqlHelper.ExecuteNonQuery(sql) > 0)
  1565. // {
  1566. // }
  1567. // else
  1568. // {
  1569. // msg = "新增失败";
  1570. // }
  1571. // }
  1572. // catch (Exception ex)
  1573. // {
  1574. // throw new Exception(ex.Message);
  1575. // }
  1576. // return msg;
  1577. //}
  1578. public string CreateICSInspection(string keyValue, string ICSInspections)
  1579. {
  1580. string msg = "";
  1581. try
  1582. {
  1583. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1584. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1585. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1586. string sql = string.Empty;
  1587. JArray res = (JArray)JsonConvert.DeserializeObject(ICSInspections);
  1588. foreach (var item in res)
  1589. {
  1590. object CARID = Guid.NewGuid();
  1591. JObject jo = (JObject)item;
  1592. #region 2024-08-09 检验添加是否入库验证
  1593. var checksql = $@"SELECT ID FROM ICSWareHouseLotInfo WHERE LotNo='{jo["LotNo"]}' AND WorkPoint='{WorkPoint}'";
  1594. var checkdt = SqlHelper.CmdExecuteDataTable(checksql);
  1595. if (checkdt.Rows.Count > 0)
  1596. {
  1597. msg = $"条码:{jo["LotNo"]}已经入库,不能再次检验";
  1598. return msg;
  1599. }
  1600. #endregion
  1601. Dictionary<string, string> values = new Dictionary<string, string>();
  1602. foreach (JProperty prop in jo.Properties())
  1603. {
  1604. string key = prop.Name; // 获取键名
  1605. JToken value = prop.Value; // 获取值(JToken类型)
  1606. string stringValue = value?.Type == JTokenType.Null ? string.Empty : value.ToString();
  1607. if (key != "JYID")
  1608. {
  1609. values.Add(key, "'" + stringValue + "'");
  1610. }
  1611. }
  1612. values.Add("ID", "'" + CARID + "'");
  1613. values.Add("MTIME", "'" + DateTime.Now.ToString() + "'");
  1614. values.Add("MUSER", "'" + MUSER + "'");
  1615. values.Add("MUSERName", "'" + MUSERNAME + "'");
  1616. values.Add("WorkPoint", "'" + WorkPoint + "'");
  1617. values.Add("Enable", "'1'");
  1618. string sqls = string.Empty;
  1619. if (!string.IsNullOrWhiteSpace(jo["JYID"].ToString()))
  1620. {
  1621. sqls += "update ICSInspectionDetailGroup set InspectionID='{2}' WHERE InspectionID='{3}' and WorkPoint='{1}' ";
  1622. }
  1623. sqls += @"update ICSInspection set Enable='0' WHERE LotNO='{0}' and Enable='1' and WorkPoint='{1}'";
  1624. sqls = string.Format(sqls, jo["LotNo"].ToString(), WorkPoint, CARID, jo["JYID"].ToString());
  1625. SqlHelper.CmdExecuteNonQueryLi(sqls);
  1626. sql += SqlHelper.InsertSQL("ICSInspection", values);
  1627. }
  1628. //}
  1629. if (SqlHelper.ExecuteNonQuery(sql) > 0)
  1630. {
  1631. }
  1632. else
  1633. {
  1634. msg = "新增失败";
  1635. }
  1636. }
  1637. catch (Exception ex)
  1638. {
  1639. msg = ex.Message;
  1640. }
  1641. return msg;
  1642. }
  1643. //副产品检验(比博---保存检验结果后根据结果分批)
  1644. public string CreateICSInspectionAndSplit(string keyValue, string ICSInspections)
  1645. {
  1646. string msg = "";
  1647. try
  1648. {
  1649. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1650. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1651. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1652. string sqls = string.Empty;
  1653. JArray res = (JArray)JsonConvert.DeserializeObject(ICSInspections);
  1654. foreach (var item in res)
  1655. {
  1656. object GoodJYID = Guid.NewGuid();
  1657. object NGJYID = Guid.NewGuid();
  1658. object PDJYID = Guid.NewGuid();
  1659. JObject jo = (JObject)item;
  1660. #region 2024-08-09 检验添加是否入库验证
  1661. var checksql = $@"SELECT ID FROM ICSWareHouseLotInfo WHERE LotNo='{jo["LotNo"]}' AND WorkPoint='{WorkPoint}'";
  1662. var checkdt = SqlHelper.CmdExecuteDataTable(checksql);
  1663. if (checkdt.Rows.Count > 0)
  1664. {
  1665. msg = $"条码:{jo["LotNo"]}已经入库,不能再次检验";
  1666. return msg;
  1667. }
  1668. decimal GoodQty = Convert.ToDecimal(jo["QualifiedQuantity"].ToString());
  1669. decimal NGQty = Convert.ToDecimal(jo["UnqualifiedQuantity"].ToString());
  1670. decimal PDQty = Convert.ToDecimal(jo["WaiveQuantity"].ToString());
  1671. string LotNO = jo["LotNo"].ToString();
  1672. string NGLotNO = "";
  1673. int NGLotNUM = 0;
  1674. string PDLotNO = "";
  1675. #region 获取本次检验需要拆分的条码最新流水号
  1676. if (NGQty != 0)
  1677. {
  1678. string lotsql = $@" SELECT TOP 1
  1679. LotNo,
  1680. CAST(RIGHT(LotNo, CHARINDEX('-', REVERSE(LotNo)) - 1) AS INT) AS Num
  1681. FROM ICSInventoryLot
  1682. WHERE EATTRIBUTE1='{LotNO}'
  1683. ORDER BY Num DESC";
  1684. DataTable lotdt = SqlHelper.CmdExecuteDataTable(lotsql);
  1685. if (lotdt.Rows.Count == 0)
  1686. {
  1687. NGLotNO = LotNO + "-1";
  1688. NGLotNUM = 1;
  1689. }
  1690. else
  1691. {
  1692. NGLotNO = LotNO + "-" + (Convert.ToInt32(lotdt.Rows[0]["Num"]) + 1).ToString();
  1693. NGLotNUM = Convert.ToInt32(lotdt.Rows[0]["Num"]) + 1;
  1694. }
  1695. }
  1696. if (PDQty != 0)
  1697. {
  1698. if (NGLotNO == "")
  1699. {
  1700. string lotsql = $@" SELECT TOP 1
  1701. LotNo,
  1702. CAST(RIGHT(LotNo, CHARINDEX('-', REVERSE(LotNo)) - 1) AS INT) AS Num
  1703. FROM ICSInventoryLot
  1704. WHERE EATTRIBUTE1='{LotNO}'
  1705. ORDER BY Num DESC";
  1706. DataTable lotdt = SqlHelper.CmdExecuteDataTable(lotsql);
  1707. if (lotdt.Rows.Count == 0)
  1708. {
  1709. PDLotNO = LotNO + "-1";
  1710. }
  1711. else
  1712. {
  1713. PDLotNO = LotNO + "-" + (Convert.ToInt32(lotdt.Rows[0]["Num"]) + 1).ToString();
  1714. }
  1715. }
  1716. else
  1717. {
  1718. PDLotNO = LotNO + "-" + (NGLotNUM + 1).ToString();
  1719. }
  1720. }
  1721. #endregion
  1722. #endregion
  1723. //比博副产品检验连带分批逻辑,将条码按照合格,报废,待定三种检验数量做分批,合格数量使用原条码,数量为0时不分批
  1724. Dictionary<string, string> Goodvalues = new Dictionary<string, string>();//合格数量
  1725. Dictionary<string, string> NGvalues = new Dictionary<string, string>();//报废数量
  1726. Dictionary<string, string> Specialvalues = new Dictionary<string, string>();//待定数量
  1727. #region 合格数量
  1728. foreach (JProperty prop in jo.Properties())
  1729. {
  1730. string key = prop.Name; // 获取键名
  1731. JToken value = prop.Value; // 获取值(JToken类型)
  1732. string stringValue = value?.Type == JTokenType.Null ? string.Empty : value.ToString();
  1733. if (key != "JYID" && key != "UnqualifiedQuantity" && key != "WaiveQuantity" && key != "Quantity")
  1734. {
  1735. if (key == "Result")
  1736. {
  1737. Goodvalues.Add(key, "'1'");
  1738. }
  1739. else
  1740. {
  1741. Goodvalues.Add(key, "'" + stringValue + "'");
  1742. }
  1743. }
  1744. if (key == "QualifiedQuantity")
  1745. {
  1746. Goodvalues.Add("Quantity", "'" + stringValue + "'");
  1747. }
  1748. if (key == "UnqualifiedQuantity")
  1749. {
  1750. Goodvalues.Add(key, "'0'");
  1751. }
  1752. if (key == "WaiveQuantity")
  1753. {
  1754. Goodvalues.Add(key, "'0'");
  1755. }
  1756. }
  1757. Goodvalues.Add("ID", "'" + GoodJYID + "'");
  1758. Goodvalues.Add("MTIME", "'" + DateTime.Now.ToString() + "'");
  1759. Goodvalues.Add("MUSER", "'" + MUSER + "'");
  1760. Goodvalues.Add("MUSERName", "'" + MUSERNAME + "'");
  1761. Goodvalues.Add("WorkPoint", "'" + WorkPoint + "'");
  1762. Goodvalues.Add("Enable", "'1'");
  1763. #endregion
  1764. if (NGQty != 0)
  1765. {
  1766. #region 报废数量
  1767. foreach (JProperty prop in jo.Properties())
  1768. {
  1769. string key = prop.Name; // 获取键名
  1770. JToken value = prop.Value; // 获取值(JToken类型)
  1771. string stringValue = value?.Type == JTokenType.Null ? string.Empty : value.ToString();
  1772. if (key != "JYID" && key != "QualifiedQuantity" && key != "WaiveQuantity" && key != "Quantity" && key != "LotNo" && key != "EATTRIBUTE1")
  1773. {
  1774. if (key == "Result")
  1775. {
  1776. NGvalues.Add(key, "'0'");
  1777. }
  1778. else
  1779. {
  1780. NGvalues.Add(key, "'" + stringValue + "'");
  1781. }
  1782. }
  1783. if (key == "UnqualifiedQuantity")
  1784. {
  1785. NGvalues.Add("Quantity", "'" + stringValue + "'");
  1786. }
  1787. if (key == "QualifiedQuantity")
  1788. {
  1789. NGvalues.Add(key, "'0'");
  1790. }
  1791. if (key == "WaiveQuantity")
  1792. {
  1793. NGvalues.Add(key, "'0'");
  1794. }
  1795. if (key == "LotNo")
  1796. {
  1797. NGvalues.Add(key, "'" + NGLotNO + "'");
  1798. }
  1799. if (key == "EATTRIBUTE1")
  1800. {
  1801. NGvalues.Add(key, "'" + LotNO + "'");
  1802. }
  1803. }
  1804. NGvalues.Add("ID", "'" + NGJYID + "'");
  1805. NGvalues.Add("MTIME", "'" + DateTime.Now.ToString() + "'");
  1806. NGvalues.Add("MUSER", "'" + MUSER + "'");
  1807. NGvalues.Add("MUSERName", "'" + MUSERNAME + "'");
  1808. NGvalues.Add("WorkPoint", "'" + WorkPoint + "'");
  1809. NGvalues.Add("Enable", "'1'");
  1810. #endregion
  1811. }
  1812. if (PDQty != 0)
  1813. {
  1814. #region 待定数量
  1815. foreach (JProperty prop in jo.Properties())
  1816. {
  1817. string key = prop.Name; // 获取键名
  1818. JToken value = prop.Value; // 获取值(JToken类型)
  1819. string stringValue = value?.Type == JTokenType.Null ? string.Empty : value.ToString();
  1820. if (key != "JYID" && key != "QualifiedQuantity" && key != "UnqualifiedQuantity" && key != "Quantity" && key != "LotNo" && key != "EATTRIBUTE1")
  1821. {
  1822. if (key == "Result")
  1823. {
  1824. Specialvalues.Add(key, "'1'");
  1825. }
  1826. else
  1827. {
  1828. Specialvalues.Add(key, "'" + stringValue + "'");
  1829. }
  1830. }
  1831. if (key == "WaiveQuantity")
  1832. {
  1833. Specialvalues.Add("Quantity", "'" + stringValue + "'");
  1834. }
  1835. if (key == "QualifiedQuantity")
  1836. {
  1837. Specialvalues.Add(key, "'0'");
  1838. }
  1839. if (key == "UnqualifiedQuantity")
  1840. {
  1841. Specialvalues.Add(key, "'0'");
  1842. }
  1843. if (key == "LotNo")
  1844. {
  1845. Specialvalues.Add(key, "'" + PDLotNO + "'");
  1846. }
  1847. if (key == "EATTRIBUTE1")
  1848. {
  1849. Specialvalues.Add(key, "'" + LotNO + "'");
  1850. }
  1851. }
  1852. Specialvalues.Add("ID", "'" + PDJYID + "'");
  1853. Specialvalues.Add("MTIME", "'" + DateTime.Now.ToString() + "'");
  1854. Specialvalues.Add("MUSER", "'" + MUSER + "'");
  1855. Specialvalues.Add("MUSERName", "'" + MUSERNAME + "'");
  1856. Specialvalues.Add("WorkPoint", "'" + WorkPoint + "'");
  1857. Specialvalues.Add("Enable", "'1'");
  1858. #endregion
  1859. }
  1860. if (!string.IsNullOrWhiteSpace(jo["JYID"].ToString()))
  1861. {
  1862. sqls += "update ICSInspectionDetailGroup set InspectionID='{2}' WHERE InspectionID='{3}' and WorkPoint='{1}' ";
  1863. }
  1864. //合格条码
  1865. sqls += @"
  1866. update ICSInspection set Enable='0' WHERE LotNO='{0}' and Enable='1' and WorkPoint='{1}' AND ID!='{2}' ";
  1867. sqls = string.Format(sqls, jo["LotNo"].ToString(), WorkPoint, GoodJYID, jo["JYID"].ToString());
  1868. if (NGQty != 0)
  1869. {
  1870. //报废条码
  1871. sqls += @"
  1872. update ICSInspection set Enable='0' WHERE LotNO='{0}' and Enable='1' and WorkPoint='{1}' AND ID!='{2}' ";
  1873. sqls = string.Format(sqls, NGLotNO, WorkPoint, NGJYID, jo["JYID"].ToString());
  1874. }
  1875. if (PDQty != 0)
  1876. {
  1877. //待定条码
  1878. sqls += @"
  1879. update ICSInspection set Enable='0' WHERE LotNO='{0}' and Enable='1' and WorkPoint='{1}' AND ID!='{2}' ";
  1880. sqls = string.Format(sqls, PDLotNO, WorkPoint, PDJYID, jo["JYID"].ToString());
  1881. }
  1882. sqls += SqlHelper.InsertSQL("ICSInspection", Goodvalues) + " ";
  1883. if (NGvalues.Count > 0)
  1884. {
  1885. sqls += SqlHelper.InsertSQL("ICSInspection", NGvalues) + " ";
  1886. }
  1887. if (Specialvalues.Count > 0)
  1888. {
  1889. sqls += SqlHelper.InsertSQL("ICSInspection", Specialvalues) + " ";
  1890. }
  1891. #region 拼接条码表更新/分批SQL语句,原条码作为合格条码只更新条码表数量,其余的需要新增条码表数据
  1892. //合格数量(更新)
  1893. sqls += $@" update ICSInventoryLot set Quantity='{GoodQty}',EATTRIBUTE2='合格'
  1894. where LotNo='{LotNO}' and WorkPoint='{WorkPoint}' ";
  1895. if (NGQty != 0)
  1896. {
  1897. //报废数量(新增)
  1898. sqls += $@"
  1899. insert into ICSInventoryLot
  1900. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Amount,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint
  1901. ,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7,EATTRIBUTE8,EATTRIBUTE9
  1902. ,EATTRIBUTE10,EATTRIBUTE11,EATTRIBUTE12,EATTRIBUTE13,EATTRIBUTE14,EATTRIBUTE15,EATTRIBUTE16,EATTRIBUTE17,EATTRIBUTE18
  1903. ,EATTRIBUTE19,EATTRIBUTE20,EATTRIBUTE21,EATTRIBUTE22,EATTRIBUTE23,EATTRIBUTE24,EATTRIBUTE25,EATTRIBUTE26,EATTRIBUTE27
  1904. ,EATTRIBUTE28,EATTRIBUTE29,EATTRIBUTE30)
  1905. select NEWID(),'{NGLotNO}',InvCode,ProductDate,ExpirationDate,'{NGQty}',Amount,ExtensionID,Type,'{MUSER}','{MUSERNAME}'
  1906. ,GETDATE(),'{WorkPoint}','{LotNO}','',EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7
  1907. ,EATTRIBUTE8,EATTRIBUTE9,EATTRIBUTE10,EATTRIBUTE11,EATTRIBUTE12,EATTRIBUTE13,EATTRIBUTE14,EATTRIBUTE15,EATTRIBUTE16
  1908. ,EATTRIBUTE17,EATTRIBUTE18,EATTRIBUTE19,EATTRIBUTE20,EATTRIBUTE21,EATTRIBUTE22,EATTRIBUTE23,EATTRIBUTE24,EATTRIBUTE25
  1909. ,EATTRIBUTE26,EATTRIBUTE27,EATTRIBUTE28,EATTRIBUTE29,EATTRIBUTE30 from ICSInventoryLot
  1910. where LotNo='{LotNO}' and WorkPoint='{WorkPoint}'
  1911. insert into ICSInventoryLotDetail
  1912. (LotNo,TransID,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1913. select '{NGLotNO}',TransID,TransCode,TransSequence,'{MUSER}','{MUSERNAME}',GETDATE(),'{WorkPoint}'
  1914. from ICSInventoryLotDetail
  1915. where LotNo='{LotNO}' and WorkPoint='{WorkPoint}'";
  1916. }
  1917. if (PDQty != 0)
  1918. {
  1919. //待定数量(新增)
  1920. sqls += $@"
  1921. insert into ICSInventoryLot
  1922. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Amount,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint
  1923. ,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7,EATTRIBUTE8,EATTRIBUTE9
  1924. ,EATTRIBUTE10,EATTRIBUTE11,EATTRIBUTE12,EATTRIBUTE13,EATTRIBUTE14,EATTRIBUTE15,EATTRIBUTE16,EATTRIBUTE17,EATTRIBUTE18
  1925. ,EATTRIBUTE19,EATTRIBUTE20,EATTRIBUTE21,EATTRIBUTE22,EATTRIBUTE23,EATTRIBUTE24,EATTRIBUTE25,EATTRIBUTE26,EATTRIBUTE27
  1926. ,EATTRIBUTE28,EATTRIBUTE29,EATTRIBUTE30)
  1927. select NEWID(),'{PDLotNO}',InvCode,ProductDate,ExpirationDate,'{PDQty}',Amount,ExtensionID,Type,'{MUSER}','{MUSERNAME}'
  1928. ,GETDATE(),'{WorkPoint}','{LotNO}','',EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7
  1929. ,EATTRIBUTE8,EATTRIBUTE9,EATTRIBUTE10,EATTRIBUTE11,EATTRIBUTE12,EATTRIBUTE13,EATTRIBUTE14,EATTRIBUTE15,EATTRIBUTE16
  1930. ,EATTRIBUTE17,EATTRIBUTE18,EATTRIBUTE19,EATTRIBUTE20,EATTRIBUTE21,EATTRIBUTE22,EATTRIBUTE23,EATTRIBUTE24,EATTRIBUTE25
  1931. ,EATTRIBUTE26,EATTRIBUTE27,EATTRIBUTE28,EATTRIBUTE29,EATTRIBUTE30 from ICSInventoryLot
  1932. where LotNo='{LotNO}' and WorkPoint='{WorkPoint}'
  1933. insert into ICSInventoryLotDetail
  1934. (LotNo,TransID,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1935. select '{PDLotNO}',TransID,TransCode,TransSequence,'{MUSER}','{MUSERNAME}',GETDATE(),'{WorkPoint}'
  1936. from ICSInventoryLotDetail
  1937. where LotNo='{LotNO}' and WorkPoint='{WorkPoint}'";
  1938. }
  1939. #endregion
  1940. }
  1941. SqlHelper.CmdExecuteNonQueryLi(sqls);
  1942. }
  1943. catch (Exception ex)
  1944. {
  1945. msg = ex.Message;
  1946. }
  1947. return msg;
  1948. }
  1949. /// <summary>
  1950. /// 在库检验保存检验结果
  1951. /// </summary>
  1952. /// <param name="queryJson"></param>
  1953. /// <returns></returns>
  1954. public string ICSWHLotInspection(string keyValue, string ICSInspections)
  1955. {
  1956. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1957. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1958. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1959. string msg = "";
  1960. string sql = string.Empty;
  1961. JArray res = (JArray)JsonConvert.DeserializeObject(ICSInspections);
  1962. string sqls = string.Empty;
  1963. foreach (var item in res)
  1964. {
  1965. JObject jo = (JObject)item;
  1966. object CARID = Guid.NewGuid();
  1967. decimal YLotQty = Convert.ToDecimal(jo["YLOTQTY"].ToString());
  1968. sqls += @"update ICSInspection set Enable='0' WHERE LotNO='{0}' and Enable='1' and WorkPoint='{1}'";
  1969. sqls = string.Format(sqls, jo["LotNo"].ToString(), WorkPoint);
  1970. sqls += @"INSERT INTO dbo.ICSInspection
  1971. ( ID ,LotNo,InvCode ,Quantity,QualifiedQuantity ,UnqualifiedQuantity,WaiveQuantity,BCCode,BRCode,Type,MTIME,MUSER ,MUSERName ,WorkPoint ,Enable,SampleQuantity,Result,EATTRIBUTE1)
  1972. Values('{13}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}',getdate(),'{9}','{10}','{11}','1','{12}','{14}','{15}')
  1973. ";
  1974. sqls = string.Format(sqls, jo["LotNo"].ToString(), jo["InvCode"].ToString(), jo["AllNumber"].ToString(), jo["YLOTQTY"].ToString()
  1975. , jo["NLOTQTY"].ToString(), "0", jo["BCCode"].ToString(), jo["BRCode"].ToString()
  1976. , jo["Type"].ToString(), MUSER, MUSERNAME, WorkPoint, "0", CARID, jo["Result"].ToString(), jo["DNCode"].ToString());
  1977. sqls += @"update ICSInspectDetail set InspectQuantity={2},MTIME=GETDATE(),MUSER='{5}',MUSERName='{6}',EATTRIBUTE1='已检验',EATTRIBUTE10='{4}'
  1978. where InspectCode='{0}' and LotNo='{3}' and WorkPoint='{1}' ";
  1979. //if (YLotQty == 0)
  1980. //{
  1981. // sqls += @"update ICSWareHouseLotInfo set Quantity=ISNULL(LockQuantity,0)
  1982. // where LotNo='{3}' and WorkPoint='{1}' ";
  1983. //}
  1984. //else
  1985. //{
  1986. // sqls += @"update ICSWareHouseLotInfo set Quantity={4}+ISNULL(LockQuantity,0)
  1987. // where LotNo='{3}' and WorkPoint='{1}'
  1988. // UPDATE ICSInventoryLot SET ExpirationDate='{7}'
  1989. // WHERE LotNo='{3}' AND WorkPoint='{1}' ";
  1990. //}
  1991. sqls = string.Format(sqls, jo["DNCode"].ToString(), WorkPoint, jo["YLOTQTY"].ToString(), jo["LotNo"].ToString(), jo["Memo"].ToString(), MUSER, MUSERNAME, Convert.ToDateTime(jo["ExpirationDate"]));
  1992. }
  1993. try
  1994. {
  1995. if (SqlHelper.ExecuteNonQuery(sqls) > 0)
  1996. {
  1997. }
  1998. else
  1999. {
  2000. msg = "保存失败";
  2001. }
  2002. }
  2003. catch (Exception ex)
  2004. {
  2005. throw new Exception(ex.Message);
  2006. }
  2007. return msg;
  2008. }
  2009. /// <summary>
  2010. /// 在库检验审核
  2011. /// </summary>
  2012. /// <param name="queryJson"></param>
  2013. /// <returns></returns>
  2014. public string ApproveWHLotInspection(string keyValue, string ICSInspections)
  2015. {
  2016. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2017. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2018. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2019. string msg = "";
  2020. string sql = string.Empty;
  2021. JArray res = (JArray)JsonConvert.DeserializeObject(ICSInspections);
  2022. string sqls = string.Empty;
  2023. foreach (var item in res)
  2024. {
  2025. JObject jo = (JObject)item;
  2026. sqls += @"update ICSInspectDetail set EATTRIBUTE1='已审核',EATTRIBUTE2='{3}',EATTRIBUTE3='{4}',EATTRIBUTE10='{5}'
  2027. where InspectCode='{0}' and LotNo='{1}' and WorkPoint='{2}' ";
  2028. sqls = string.Format(sqls, jo["DNCode"].ToString(), jo["LotNo"].ToString(), WorkPoint, MUSER, MUSERNAME, jo["Memo"].ToString());
  2029. }
  2030. try
  2031. {
  2032. if (SqlHelper.ExecuteNonQuery(sqls) > 0)
  2033. {
  2034. }
  2035. else
  2036. {
  2037. msg = "审核失败";
  2038. }
  2039. }
  2040. catch (Exception ex)
  2041. {
  2042. throw new Exception(ex.Message);
  2043. }
  2044. return msg;
  2045. }
  2046. /// <summary>
  2047. /// 在库检验复审
  2048. /// </summary>
  2049. /// <param name="queryJson"></param>
  2050. /// <returns></returns>
  2051. public string SecApproveWHLotInspection(string keyValue, string ICSInspections)
  2052. {
  2053. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2054. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2055. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2056. string msg = "";
  2057. bool IsCQ = false;
  2058. string sql = string.Empty;
  2059. JArray res = (JArray)JsonConvert.DeserializeObject(ICSInspections);
  2060. string chksql = @"select Type from ICSInspect
  2061. where InspectCode='{0}' and WorkPoint='{1}'";
  2062. chksql = string.Format(chksql, res[0]["DNCode"].ToString(), WorkPoint);
  2063. DataTable chkdt = SqlHelper.GetDataTableBySql(chksql);
  2064. if (chkdt.Rows[0]["Type"].ToString() == "0")
  2065. {
  2066. IsCQ = false;
  2067. }
  2068. else
  2069. {
  2070. IsCQ = true;
  2071. }
  2072. string sqls = string.Empty;
  2073. foreach (var item in res)
  2074. {
  2075. JObject jo = (JObject)item;
  2076. object CARID = Guid.NewGuid();
  2077. string newlotStr = "";
  2078. decimal AllNumber = Convert.ToDecimal(jo["AllNumber"].ToString());
  2079. decimal YLotQty = Convert.ToDecimal(jo["YLOTQTY"].ToString());
  2080. sqls += @"update ICSInspectDetail set EATTRIBUTE1='已复审',EATTRIBUTE4='{3}',EATTRIBUTE5='{4}',EATTRIBUTE10='{10}',EATTRIBUTE11='{11}'
  2081. where InspectCode='{0}' and LotNo='{1}' and WorkPoint='{2}'
  2082. update ICSWareHouseLotInfo set Inspect=0
  2083. where LotNo='{1}' and WorkPoint='{2}'";
  2084. if (AllNumber != YLotQty)
  2085. {
  2086. //获取分批条码编号
  2087. string lotsql = @" select top 1 LotNo from ICSInventoryLot
  2088. where LotNo like '{0}-%' AND LotNo!='{0}'
  2089. AND WorkPoint='{1}'
  2090. order by MTIME desc";
  2091. lotsql = string.Format(lotsql, jo["LotNo"].ToString(), WorkPoint);
  2092. DataTable lotdt = SqlHelper.GetDataTableBySql(lotsql);
  2093. if (lotdt.Rows.Count == 0)
  2094. {
  2095. newlotStr = jo["LotNo"].ToString() + "-1";
  2096. }
  2097. else
  2098. {
  2099. newlotStr = jo["LotNo"].ToString() + "-" + (Convert.ToInt32(lotdt.Rows[0]["LotNo"].ToString().Split('-')[lotdt.Rows[0]["LotNo"].ToString().Split('-').Length - 1]) + 1).ToString();
  2100. }
  2101. if (IsCQ == false)
  2102. {
  2103. sqls += @"insert into ICSInventoryLot
  2104. select NEWID(),'{6}',InvCode,ProductDate,ExpirationDate,Quantity-{7},Amount,ExtensionID,'21',null,null,null,'{8}','{9}'
  2105. ,GETDATE(),WorkPoint,'{1}',EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7,EATTRIBUTE8,EATTRIBUTE9
  2106. ,EATTRIBUTE10,EATTRIBUTE11,EATTRIBUTE12,EATTRIBUTE13,EATTRIBUTE14,EATTRIBUTE15,EATTRIBUTE16
  2107. ,EATTRIBUTE17,EATTRIBUTE18,EATTRIBUTE19,EATTRIBUTE20,EATTRIBUTE21,EATTRIBUTE22,EATTRIBUTE23
  2108. ,EATTRIBUTE24,EATTRIBUTE25,EATTRIBUTE26,EATTRIBUTE27,EATTRIBUTE28,EATTRIBUTE29,EATTRIBUTE30 from ICSInventoryLot
  2109. where LotNo='{1}' and WorkPoint='{2}'
  2110. insert into ICSInventoryLotDetail
  2111. select '{6}',TransID,TransCode,TransSequence,'{8}','{9}',GETDATE(),WorkPoint
  2112. ,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7
  2113. ,EATTRIBUTE8,EATTRIBUTE9,EATTRIBUTE10,EATTRIBUTE11,EATTRIBUTE12,EATTRIBUTE13,EATTRIBUTE14,EATTRIBUTE15,EATTRIBUTE16
  2114. ,EATTRIBUTE17,EATTRIBUTE18,EATTRIBUTE19,EATTRIBUTE20,EATTRIBUTE21,EATTRIBUTE22,EATTRIBUTE23
  2115. ,EATTRIBUTE24,EATTRIBUTE25,EATTRIBUTE26,EATTRIBUTE27,EATTRIBUTE28,EATTRIBUTE29,EATTRIBUTE30 from ICSInventoryLotDetail
  2116. where LotNo='{1}' and WorkPoint='{2}'
  2117. insert into ICSWareHouseLotInfo
  2118. select NEWID(),'{6}',WarehouseCode,LocationCode,InvCode,Quantity-{7}-isnull(LockQuantity,0),InDate,0,Freeze,0,'{8}','{9}'
  2119. ,GETDATE(),WorkPoint,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7,EATTRIBUTE8
  2120. ,EATTRIBUTE9,EATTRIBUTE10,EATTRIBUTE11,EATTRIBUTE12,EATTRIBUTE13,EATTRIBUTE14,EATTRIBUTE15,EATTRIBUTE16
  2121. ,EATTRIBUTE17,EATTRIBUTE18,EATTRIBUTE19,EATTRIBUTE20,EATTRIBUTE21,EATTRIBUTE22,EATTRIBUTE23
  2122. ,EATTRIBUTE24,EATTRIBUTE25,EATTRIBUTE26,EATTRIBUTE27,EATTRIBUTE28,EATTRIBUTE29,EATTRIBUTE30 from ICSWareHouseLotInfo
  2123. where LotNo='{1}' and WorkPoint='{2}'
  2124. update ICSWareHouseLotInfo set Quantity={5}+ISNULL(LockQuantity,0)
  2125. where LotNo='{1}' and WorkPoint='{2}' ";
  2126. }
  2127. else
  2128. {
  2129. sqls += @"UPDATE ICSInventoryLot SET ExpirationDate=DateAdd(DAY,Convert(Int,(select F_Define1 from Sys_SRM_ItemsDetail
  2130. where F_ItemCode='Delay_day')),GETDATE())
  2131. WHERE LotNo='{1}' AND WorkPoint='{2}'
  2132. insert into ICSInventoryLot
  2133. select NEWID(),'{6}',InvCode,ProductDate,ExpirationDate,Quantity-{7},Amount,ExtensionID,'21',null,null,null,'{8}','{9}'
  2134. ,GETDATE(),WorkPoint,'{1}',EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7,EATTRIBUTE8,EATTRIBUTE9
  2135. ,EATTRIBUTE10,EATTRIBUTE11,EATTRIBUTE12,EATTRIBUTE13,EATTRIBUTE14,EATTRIBUTE15,EATTRIBUTE16
  2136. ,EATTRIBUTE17,EATTRIBUTE18,EATTRIBUTE19,EATTRIBUTE20,EATTRIBUTE21,EATTRIBUTE22,EATTRIBUTE23
  2137. ,EATTRIBUTE24,EATTRIBUTE25,EATTRIBUTE26,EATTRIBUTE27,EATTRIBUTE28,EATTRIBUTE29,EATTRIBUTE30 from ICSInventoryLot
  2138. where LotNo='{1}' and WorkPoint='{2}'
  2139. insert into ICSInventoryLotDetail
  2140. select '{6}',TransID,TransCode,TransSequence,'{8}','{9}',GETDATE(),WorkPoint
  2141. ,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7
  2142. ,EATTRIBUTE8,EATTRIBUTE9,EATTRIBUTE10,EATTRIBUTE11,EATTRIBUTE12,EATTRIBUTE13,EATTRIBUTE14,EATTRIBUTE15,EATTRIBUTE16
  2143. ,EATTRIBUTE17,EATTRIBUTE18,EATTRIBUTE19,EATTRIBUTE20,EATTRIBUTE21,EATTRIBUTE22,EATTRIBUTE23
  2144. ,EATTRIBUTE24,EATTRIBUTE25,EATTRIBUTE26,EATTRIBUTE27,EATTRIBUTE28,EATTRIBUTE29,EATTRIBUTE30 from ICSInventoryLotDetail
  2145. where LotNo='{1}' and WorkPoint='{2}'
  2146. insert into ICSWareHouseLotInfo
  2147. select NEWID(),'{6}',WarehouseCode,LocationCode,InvCode,Quantity-{7}-isnull(LockQuantity,0),InDate,0,Freeze,0,'{8}','{9}'
  2148. ,GETDATE(),WorkPoint,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7,EATTRIBUTE8
  2149. ,EATTRIBUTE9,EATTRIBUTE10,EATTRIBUTE11,EATTRIBUTE12,EATTRIBUTE13,EATTRIBUTE14,EATTRIBUTE15,EATTRIBUTE16
  2150. ,EATTRIBUTE17,EATTRIBUTE18,EATTRIBUTE19,EATTRIBUTE20,EATTRIBUTE21,EATTRIBUTE22,EATTRIBUTE23
  2151. ,EATTRIBUTE24,EATTRIBUTE25,EATTRIBUTE26,EATTRIBUTE27,EATTRIBUTE28,EATTRIBUTE29,EATTRIBUTE30 from ICSWareHouseLotInfo
  2152. where LotNo='{1}' and WorkPoint='{2}'
  2153. update ICSWareHouseLotInfo set Quantity={5}+ISNULL(LockQuantity,0)
  2154. where LotNo='{1}' and WorkPoint='{2}'";
  2155. }
  2156. }
  2157. /*
  2158. * 1
  2159. 2 + 90
  2160. */
  2161. if (IsCQ && AllNumber == YLotQty)
  2162. {
  2163. sqls += @"UPDATE ICSInventoryLot SET ExpirationDate=DateAdd(DAY,Convert(Int,(select F_Define1 from Sys_SRM_ItemsDetail
  2164. where F_ItemCode='Delay_day')),GETDATE())
  2165. WHERE LotNo='{1}' AND WorkPoint='{2}' ";
  2166. }
  2167. sqls = string.Format(sqls, jo["DNCode"].ToString(), jo["LotNo"].ToString(), WorkPoint, MUSER, MUSERNAME, YLotQty, newlotStr, YLotQty, MUSER, MUSERNAME, jo["Memo"].ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  2168. }
  2169. try
  2170. {
  2171. if (SqlHelper.ExecuteNonQuery(sqls) > 0)
  2172. {
  2173. }
  2174. else
  2175. {
  2176. msg = "保存失败";
  2177. }
  2178. }
  2179. catch (Exception ex)
  2180. {
  2181. throw new Exception(ex.Message);
  2182. }
  2183. return msg;
  2184. }
  2185. //生成采购拒收单
  2186. public string CreateRejection(string keyValue)
  2187. {
  2188. string msg = "";
  2189. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2190. DataTable dt = new DataTable();
  2191. DataTable dtD = new DataTable();
  2192. string Dsql = @"SELECT a.F_itemCode
  2193. FROM Sys_SRM_ItemsDetail a
  2194. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  2195. WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1'";
  2196. DataTable DaoWHCodedt = SqlHelper.GetDataTableBySql(Dsql);
  2197. if (DaoWHCodedt.Rows.Count > 0)
  2198. {
  2199. string sqlAsn = @" select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode,a.Sequence,a.ExtensionID,a.PODetailID
  2200. from ICSDeliveryNotice a
  2201. inner JOIN ICSExtension extd ON a.ExtensionID=extd.ID AND a.WorkPoint=extd.WorkPoint
  2202. inner join ICSASNDetail b on a.ASNCode=b.ASNCode
  2203. inner JOIN ICSInventory inv ON a.InvCode=inv.InvCode and a.WorkPoint=inv.WorkPoint and inv.InvIQC='1'
  2204. LEFT JOIN ICSInventoryBatchEnable invBat ON inv.InvCode=invBat.InvCode AND (SELECT a.F_itemCode
  2205. FROM Sys_SRM_ItemsDetail a
  2206. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  2207. WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1')=invBat.WHCode AND inv.WorkPoint=invBat.WorkPoint
  2208. left join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  2209. INNER JOIN ICSExtension ext ON c.ExtensionID=ext.ID AND c.WorkPoint=ext.WorkPoint
  2210. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  2211. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  2212. where ISNULL(extd.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(extd.BatchCode, '') ELSE '' END+'~'+ISNULL(extd.Version, '')+'~'+ISNULL(extd.Brand, '')+'~'+
  2213. ISNULL(extd.cFree1, '')+'~'+ISNULL(extd.cFree2, '')+'~'+ISNULL(extd.cFree3, '')+'~'+ISNULL(extd.cFree4, '')+'~'+ISNULL(extd.cFree5, '')+'~'+ISNULL(extd.cFree6, '')+'~'+ISNULL(extd.cFree7, '')+'~'+ISNULL(extd.cFree8, '')+'~'+ISNULL(extd.cFree9, '')+'~'+ISNULL(extd.cFree10, '')=ISNULL(ext.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END+'~'+ISNULL(ext.Version, '')+'~'+ISNULL(ext.Brand, '')+'~'+
  2214. ISNULL(ext.cFree1, '')+'~'+ISNULL(ext.cFree2, '')+'~'+ISNULL(ext.cFree3, '')+'~'+ISNULL(ext.cFree4, '')+'~'+ISNULL(ext.cFree5, '')+'~'+ISNULL(ext.cFree6, '')+'~'+ISNULL(ext.cFree7, '')+'~'+ISNULL(ext.cFree8, '')+'~'+ISNULL(ext.cFree9, '')+'~'+ISNULL(ext.cFree10, '')
  2215. and b.LotNo IN (" + keyValue.TrimEnd(',') + ") ";
  2216. dt = Repository().FindTableBySql(sqlAsn.ToString());
  2217. string sqlAsnD = @" select distinct c.InvCode,ISNULL(d.UnqualifiedQuantity,0)-ISNULL(d.WaiveQuantity,0) as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,DNDetailID,DNID,b.LotNo,c.ExtensionID,a.PODetailID
  2218. from ICSDeliveryNotice a
  2219. inner JOIN ICSExtension extd ON a.ExtensionID=extd.ID AND a.WorkPoint=extd.WorkPoint
  2220. left join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  2221. inner JOIN ICSInventory inv ON a.InvCode=inv.InvCode and a.WorkPoint=inv.WorkPoint and inv.InvIQC='1'
  2222. LEFT JOIN ICSInventoryBatchEnable invBat ON inv.InvCode=invBat.InvCode AND (SELECT a.F_itemCode
  2223. FROM Sys_SRM_ItemsDetail a
  2224. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  2225. WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1')=invBat.WHCode AND inv.WorkPoint=invBat.WorkPoint
  2226. left join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  2227. INNER JOIN ICSExtension ext ON c.ExtensionID=ext.ID AND c.WorkPoint=ext.WorkPoint
  2228. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  2229. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  2230. left join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint AND d.Enable='1'
  2231. WHERE ISNULL(extd.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(extd.BatchCode, '') ELSE '' END+'~'+ISNULL(extd.Version, '')+'~'+ISNULL(extd.Brand, '')+'~'+
  2232. ISNULL(extd.cFree1, '')+'~'+ISNULL(extd.cFree2, '')+'~'+ISNULL(extd.cFree3, '')+'~'+ISNULL(extd.cFree4, '')+'~'+ISNULL(extd.cFree5, '')+'~'+ISNULL(extd.cFree6, '')+'~'+ISNULL(extd.cFree7, '')+'~'+ISNULL(extd.cFree8, '')+'~'+ISNULL(extd.cFree9, '')+'~'+ISNULL(extd.cFree10, '')=ISNULL(ext.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END+'~'+ISNULL(ext.Version, '')+'~'+ISNULL(ext.Brand, '')+'~'+
  2233. ISNULL(ext.cFree1, '')+'~'+ISNULL(ext.cFree2, '')+'~'+ISNULL(ext.cFree3, '')+'~'+ISNULL(ext.cFree4, '')+'~'+ISNULL(ext.cFree5, '')+'~'+ISNULL(ext.cFree6, '')+'~'+ISNULL(ext.cFree7, '')+'~'+ISNULL(ext.cFree8, '')+'~'+ISNULL(ext.cFree9, '')+'~'+ISNULL(ext.cFree10, '')
  2234. and b.LotNo in (" + keyValue.TrimEnd(',') + ") ";
  2235. dtD = Repository().FindTableBySql(sqlAsnD.ToString());
  2236. }
  2237. else
  2238. {
  2239. string sqlAsn = @"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode,a.Sequence,a.ExtensionID,a.PODetailID from ICSDeliveryNotice a
  2240. inner join ICSASNDetail b on a.ASNCode=b.ASNCode
  2241. left join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint AND c.ExtensionID=a.ExtensionID
  2242. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  2243. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  2244. WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ")";
  2245. dt = Repository().FindTableBySql(sqlAsn.ToString());
  2246. string sqlAsnD = @" select distinct c.InvCode,ISNULL(d.UnqualifiedQuantity,0)-ISNULL(d.WaiveQuantity,0) as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,DNDetailID,DNID,b.LotNo,c.ExtensionID,a.PODetailID
  2247. from ICSDeliveryNotice a
  2248. left join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  2249. left join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint AND a.ExtensionID=c.ExtensionID
  2250. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  2251. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  2252. left join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint AND d.Enable='1'
  2253. WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ") ";
  2254. dtD = Repository().FindTableBySql(sqlAsnD.ToString());
  2255. }
  2256. List<RejectionHead> asn = new List<RejectionHead>();
  2257. for (int i = 0; i < dt.Rows.Count; i++)
  2258. {
  2259. RejectionHead ass = new RejectionHead();
  2260. ass.VenCode = dt.Rows[i]["VenCode"].ToString();
  2261. ass.ID = dt.Rows[i]["DNID"].ToString();
  2262. ass.DepCode = dt.Rows[i]["DepCode"].ToString();
  2263. ass.DNCode = dt.Rows[i]["DNCode"].ToString();
  2264. ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2265. ass.MTIME = System.DateTime.Now.ToString("s");
  2266. ass.WorkPoint = WorkPoint;
  2267. DataRow[] drs = dtD.Select("DNID='" + dt.Rows[i]["DNID"].ToString() + "' and PODetailID='" + dt.Rows[i]["PODetailID"].ToString() + "'");
  2268. // DataRow[] drs = dtD.Select($"DNID='{dt.Rows[i]["DNID"]}' AND ExtensionID='{dt.Rows[i]["ExtensionID"]}'");
  2269. for (int j = 0; j < drs.Length; j++)
  2270. {
  2271. RejectionBody DetailList = new RejectionBody();
  2272. DetailList.Sequence = (j + 1).ToString();
  2273. DetailList.InvCode = drs[j]["InvCode"].ToString();
  2274. DetailList.Quantity = drs[j]["Quantity"].ToString();
  2275. DetailList.Amount = drs[j]["Amount"].ToString();
  2276. DetailList.Currency = drs[j]["Currency"].ToString();
  2277. DetailList.UnitPrice = drs[j]["UnitPrice"].ToString();
  2278. DetailList.DNDetailID = drs[j]["DNDetailID"].ToString();
  2279. DetailList.LotNo = drs[j]["LotNo"].ToString();
  2280. ass.detail.Add(DetailList);
  2281. }
  2282. asn.Add(ass);
  2283. }
  2284. string input = JsonConvert.SerializeObject(asn);
  2285. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "PurchaseRejectDoc/Create";
  2286. string result = HttpPost(APIURL, input);
  2287. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  2288. string MessAge = Obj["Message"].ToString();
  2289. string Success = Obj["Success"].ToString();
  2290. if (Success.ToUpper() == "FALSE")
  2291. {
  2292. msg = MessAge;
  2293. }
  2294. return msg;
  2295. }
  2296. //生成采购拒收单
  2297. public string CreateRejectionYL(string keyValue)
  2298. {
  2299. string msg = "";
  2300. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2301. DataTable dt = new DataTable();
  2302. DataTable dtD = new DataTable();
  2303. string Dsql = @"SELECT a.F_itemCode
  2304. FROM Sys_SRM_ItemsDetail a
  2305. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  2306. WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1'";
  2307. DataTable DaoWHCodedt = SqlHelper.GetDataTableBySql(Dsql);
  2308. if (DaoWHCodedt.Rows.Count > 0)
  2309. {
  2310. string sqlAsn = @" select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode,a.Sequence,a.ExtensionID,a.PODetailID
  2311. from ICSDeliveryNotice a
  2312. inner JOIN ICSExtension extd ON a.ExtensionID=extd.ID AND a.WorkPoint=extd.WorkPoint
  2313. inner join ICSASNDetail b on a.ASNCode=b.ASNCode
  2314. inner JOIN ICSInventory inv ON a.InvCode=inv.InvCode and a.WorkPoint=inv.WorkPoint and inv.InvIQC='1'
  2315. LEFT JOIN ICSInventoryBatchEnable invBat ON inv.InvCode=invBat.InvCode AND (SELECT a.F_itemCode
  2316. FROM Sys_SRM_ItemsDetail a
  2317. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  2318. WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1')=invBat.WHCode AND inv.WorkPoint=invBat.WorkPoint
  2319. left join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  2320. INNER JOIN ICSExtension ext ON c.ExtensionID=ext.ID AND c.WorkPoint=ext.WorkPoint
  2321. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  2322. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  2323. where ISNULL(extd.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(extd.BatchCode, '') ELSE '' END+'~'+ISNULL(extd.Version, '')+'~'+ISNULL(extd.Brand, '')+'~'+
  2324. ISNULL(extd.cFree1, '')+'~'+ISNULL(extd.cFree2, '')+'~'+ISNULL(extd.cFree3, '')+'~'+ISNULL(extd.cFree4, '')+'~'+ISNULL(extd.cFree5, '')+'~'+ISNULL(extd.cFree6, '')+'~'+ISNULL(extd.cFree7, '')+'~'+ISNULL(extd.cFree8, '')+'~'+ISNULL(extd.cFree9, '')+'~'+ISNULL(extd.cFree10, '')=ISNULL(ext.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END+'~'+ISNULL(ext.Version, '')+'~'+ISNULL(ext.Brand, '')+'~'+
  2325. ISNULL(ext.cFree1, '')+'~'+ISNULL(ext.cFree2, '')+'~'+ISNULL(ext.cFree3, '')+'~'+ISNULL(ext.cFree4, '')+'~'+ISNULL(ext.cFree5, '')+'~'+ISNULL(ext.cFree6, '')+'~'+ISNULL(ext.cFree7, '')+'~'+ISNULL(ext.cFree8, '')+'~'+ISNULL(ext.cFree9, '')+'~'+ISNULL(ext.cFree10, '')
  2326. and b.LotNo IN (" + keyValue.TrimEnd(',') + ") ";
  2327. dt = Repository().FindTableBySql(sqlAsn.ToString());
  2328. string sqlAsnD = @" select distinct c.InvCode,ISNULL(d.UnqualifiedQuantity,0)-ISNULL(d.WaiveQuantity,0) as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,DNDetailID,DNID,b.LotNo,c.ExtensionID,a.PODetailID
  2329. from ICSDeliveryNotice a
  2330. inner JOIN ICSExtension extd ON a.ExtensionID=extd.ID AND a.WorkPoint=extd.WorkPoint
  2331. left join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  2332. inner JOIN ICSInventory inv ON a.InvCode=inv.InvCode and a.WorkPoint=inv.WorkPoint and inv.InvIQC='1'
  2333. LEFT JOIN ICSInventoryBatchEnable invBat ON inv.InvCode=invBat.InvCode AND (SELECT a.F_itemCode
  2334. FROM Sys_SRM_ItemsDetail a
  2335. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  2336. WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1')=invBat.WHCode AND inv.WorkPoint=invBat.WorkPoint
  2337. left join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  2338. INNER JOIN ICSExtension ext ON c.ExtensionID=ext.ID AND c.WorkPoint=ext.WorkPoint
  2339. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  2340. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  2341. left join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint AND d.Enable='1'
  2342. WHERE ISNULL(extd.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(extd.BatchCode, '') ELSE '' END+'~'+ISNULL(extd.Version, '')+'~'+ISNULL(extd.Brand, '')+'~'+
  2343. ISNULL(extd.cFree1, '')+'~'+ISNULL(extd.cFree2, '')+'~'+ISNULL(extd.cFree3, '')+'~'+ISNULL(extd.cFree4, '')+'~'+ISNULL(extd.cFree5, '')+'~'+ISNULL(extd.cFree6, '')+'~'+ISNULL(extd.cFree7, '')+'~'+ISNULL(extd.cFree8, '')+'~'+ISNULL(extd.cFree9, '')+'~'+ISNULL(extd.cFree10, '')=ISNULL(ext.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END+'~'+ISNULL(ext.Version, '')+'~'+ISNULL(ext.Brand, '')+'~'+
  2344. ISNULL(ext.cFree1, '')+'~'+ISNULL(ext.cFree2, '')+'~'+ISNULL(ext.cFree3, '')+'~'+ISNULL(ext.cFree4, '')+'~'+ISNULL(ext.cFree5, '')+'~'+ISNULL(ext.cFree6, '')+'~'+ISNULL(ext.cFree7, '')+'~'+ISNULL(ext.cFree8, '')+'~'+ISNULL(ext.cFree9, '')+'~'+ISNULL(ext.cFree10, '')
  2345. and b.LotNo in (" + keyValue.TrimEnd(',') + ") ";
  2346. dtD = Repository().FindTableBySql(sqlAsnD.ToString());
  2347. }
  2348. else
  2349. {
  2350. string sqlAsn = @"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode,a.Sequence,a.ExtensionID,a.PODetailID from ICSDeliveryNotice a
  2351. inner join ICSASNDetail b on a.ASNCode=b.ASNCode
  2352. left join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint AND c.ExtensionID=a.ExtensionID
  2353. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  2354. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  2355. WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ")";
  2356. dt = Repository().FindTableBySql(sqlAsn.ToString());
  2357. string sqlAsnD = @" select distinct c.InvCode,ISNULL(d.UnqualifiedQuantity,0)-ISNULL(d.WaiveQuantity,0) as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,DNDetailID,DNID,b.LotNo,c.ExtensionID,a.PODetailID
  2358. from ICSDeliveryNotice a
  2359. left join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  2360. left join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint AND a.ExtensionID=c.ExtensionID
  2361. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  2362. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  2363. left join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint AND d.Enable='1'
  2364. WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ") ";
  2365. dtD = Repository().FindTableBySql(sqlAsnD.ToString());
  2366. }
  2367. List<RejectionHead> asn = new List<RejectionHead>();
  2368. for (int i = 0; i < dt.Rows.Count; i++)
  2369. {
  2370. RejectionHead ass = new RejectionHead();
  2371. ass.VenCode = dt.Rows[i]["VenCode"].ToString();
  2372. ass.ID = dt.Rows[i]["DNID"].ToString();
  2373. ass.DepCode = dt.Rows[i]["DepCode"].ToString();
  2374. ass.DNCode = dt.Rows[i]["DNCode"].ToString();
  2375. ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2376. ass.MTIME = System.DateTime.Now.ToString("s");
  2377. ass.WorkPoint = WorkPoint;
  2378. DataRow[] drs = dtD.Select("DNID='" + dt.Rows[i]["DNID"].ToString() + "' and PODetailID='" + dt.Rows[i]["PODetailID"].ToString() + "' and ExtensionID='" + dt.Rows[i]["ExtensionID"].ToString() + "' ");
  2379. // DataRow[] drs = dtD.Select($"DNID='{dt.Rows[i]["DNID"]}' AND ExtensionID='{dt.Rows[i]["ExtensionID"]}'");
  2380. for (int j = 0; j < drs.Length; j++)
  2381. {
  2382. RejectionBody DetailList = new RejectionBody();
  2383. DetailList.Sequence = (j + 1).ToString();
  2384. DetailList.InvCode = drs[j]["InvCode"].ToString();
  2385. DetailList.Quantity = drs[j]["Quantity"].ToString();
  2386. DetailList.Amount = drs[j]["Amount"].ToString();
  2387. DetailList.Currency = drs[j]["Currency"].ToString();
  2388. DetailList.UnitPrice = drs[j]["UnitPrice"].ToString();
  2389. DetailList.DNDetailID = drs[j]["DNDetailID"].ToString();
  2390. DetailList.LotNo = drs[j]["LotNo"].ToString();
  2391. ass.detail.Add(DetailList);
  2392. }
  2393. asn.Add(ass);
  2394. }
  2395. string input = JsonConvert.SerializeObject(asn);
  2396. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "PurchaseRejectDoc/Create";
  2397. string result = HttpPost(APIURL, input);
  2398. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  2399. string MessAge = Obj["Message"].ToString();
  2400. string Success = Obj["Success"].ToString();
  2401. if (Success.ToUpper() == "FALSE")
  2402. {
  2403. msg = MessAge;
  2404. }
  2405. return msg;
  2406. }
  2407. //生成采购拒收单(无来源)
  2408. public string CreateWLYRejection(string keyValue)
  2409. {
  2410. string msg = "";
  2411. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2412. //string sqlAsn = @"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode from ICSDeliveryNotice a
  2413. // inner join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  2414. // left join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  2415. // left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  2416. // inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  2417. // WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ")";
  2418. string sqlAsn = @"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode from ICSDeliveryNotice a
  2419. left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint
  2420. left join dbo.ICSInventoryLot c on e.LotNo=c.LotNo and a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  2421. -- left JOIN ICSPurchaseOrder l ON a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  2422. WHERE c.LotNo IN (" + keyValue.TrimEnd(',') + ")";
  2423. DataTable dt = Repository().FindTableBySql(sqlAsn.ToString());
  2424. //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
  2425. // from ICSDeliveryNotice a
  2426. // left join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  2427. // left join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  2428. // left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  2429. // inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  2430. // left join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint
  2431. // WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ") ";
  2432. 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,d.LotNo
  2433. from ICSDeliveryNotice a
  2434. left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint
  2435. left join ICSInventoryLot c on e.LotNo=c.LotNo and a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint --AND a.ExtensionID=c.ExtensionID
  2436. inner JOIN ICSPurchaseOrder l ON a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  2437. left join ICSInspection d on c.LotNo=d.LotNo and a.WorkPoint=d.WorkPoint and d.Enable='1'
  2438. WHERE d.LotNo in (" + keyValue.TrimEnd(',') + ") ";
  2439. DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString());
  2440. List<RejectionHead> asn = new List<RejectionHead>();
  2441. for (int i = 0; i < dt.Rows.Count; i++)
  2442. {
  2443. RejectionHead ass = new RejectionHead();
  2444. ass.VenCode = dt.Rows[i]["VenCode"].ToString();
  2445. ass.ID = dt.Rows[i]["DNID"].ToString();
  2446. ass.DepCode = dt.Rows[i]["DepCode"].ToString();
  2447. ass.DNCode = dt.Rows[i]["DNCode"].ToString();
  2448. ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2449. ass.MTIME = System.DateTime.Now.ToString("s");
  2450. ass.WorkPoint = WorkPoint;
  2451. DataRow[] drs = dtD.Select("DNID='" + dt.Rows[i]["DNID"].ToString() + "'");
  2452. for (int j = 0; j < drs.Length; j++)
  2453. {
  2454. RejectionBody DetailList = new RejectionBody();
  2455. DetailList.Sequence = (j + 1).ToString();
  2456. DetailList.InvCode = drs[j]["InvCode"].ToString();
  2457. DetailList.Quantity = drs[j]["Quantity"].ToString();
  2458. DetailList.Amount = drs[j]["Amount"].ToString();
  2459. DetailList.Currency = drs[j]["Currency"].ToString();
  2460. DetailList.UnitPrice = drs[j]["UnitPrice"].ToString();
  2461. DetailList.DNDetailID = drs[j]["DNDetailID"].ToString();
  2462. DetailList.LotNo = drs[j]["LotNo"].ToString();
  2463. ass.detail.Add(DetailList);
  2464. }
  2465. asn.Add(ass);
  2466. }
  2467. string input = JsonConvert.SerializeObject(asn);
  2468. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "PurchaseRejectDocNoTrans/Create";
  2469. string result = HttpPost(APIURL, input);
  2470. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  2471. string MessAge = Obj["Message"].ToString();
  2472. string Success = Obj["Success"].ToString();
  2473. if (Success.ToUpper() == "FALSE")
  2474. {
  2475. msg = MessAge;
  2476. }
  2477. return msg;
  2478. }
  2479. //生成委外拒收单
  2480. public string CreateWWRejection(string keyValue)
  2481. {
  2482. try
  2483. {
  2484. string msg = "";
  2485. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2486. DataTable dt = new DataTable();
  2487. DataTable dtD = new DataTable();
  2488. string Dsql = @"SELECT a.F_itemCode
  2489. FROM Sys_SRM_ItemsDetail a
  2490. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  2491. WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1'";
  2492. DataTable DaoWHCodedt = SqlHelper.GetDataTableBySql(Dsql);
  2493. if (DaoWHCodedt.Rows.Count > 0)
  2494. {
  2495. string sqlAsn = @" select distinct a.VenCode,a.ODNID,a.DepCode,a.ODNCode
  2496. from ICSODeliveryNotice a
  2497. inner JOIN ICSExtension extd ON a.ExtensionID=extd.ID AND a.WorkPoint=extd.WorkPoint
  2498. left join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint
  2499. inner JOIN ICSInventory inv ON a.InvCode=inv.InvCode and a.WorkPoint=inv.WorkPoint and inv.InvIQC='1'
  2500. LEFT JOIN ICSInventoryBatchEnable invBat ON inv.InvCode=invBat.InvCode AND (SELECT a.F_itemCode
  2501. FROM Sys_SRM_ItemsDetail a
  2502. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  2503. WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1')=invBat.WHCode AND inv.WorkPoint=invBat.WorkPoint
  2504. inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  2505. INNER JOIN ICSExtension ext ON d.ExtensionID=ext.ID AND d.WorkPoint=ext.WorkPoint
  2506. left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  2507. inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint
  2508. WHERE ISNULL(extd.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(extd.BatchCode, '') ELSE '' END+'~'+ISNULL(extd.Version, '')+'~'+ISNULL(extd.Brand, '')+'~'+
  2509. ISNULL(extd.cFree1, '')+'~'+ISNULL(extd.cFree2, '')+'~'+ISNULL(extd.cFree3, '')+'~'+ISNULL(extd.cFree4, '')+'~'+ISNULL(extd.cFree5, '')+'~'+ISNULL(extd.cFree6, '')+'~'+ISNULL(extd.cFree7, '')+'~'+ISNULL(extd.cFree8, '')+'~'+ISNULL(extd.cFree9, '')+'~'+ISNULL(extd.cFree10, '')=ISNULL(ext.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END+'~'+ISNULL(ext.Version, '')+'~'+ISNULL(ext.Brand, '')+'~'+
  2510. ISNULL(ext.cFree1, '')+'~'+ISNULL(ext.cFree2, '')+'~'+ISNULL(ext.cFree3, '')+'~'+ISNULL(ext.cFree4, '')+'~'+ISNULL(ext.cFree5, '')+'~'+ISNULL(ext.cFree6, '')+'~'+ISNULL(ext.cFree7, '')+'~'+ISNULL(ext.cFree8, '')+'~'+ISNULL(ext.cFree9, '')+'~'+ISNULL(ext.cFree10, '')
  2511. and b.LotNo in (" + keyValue.TrimEnd(',') + ")";
  2512. dt = Repository().FindTableBySql(sqlAsn.ToString());
  2513. 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
  2514. from ICSODeliveryNotice a
  2515. inner JOIN ICSExtension extd ON a.ExtensionID=extd.ID AND a.WorkPoint=extd.WorkPoint
  2516. inner join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint
  2517. inner JOIN ICSInventory inv ON a.InvCode=inv.InvCode and a.WorkPoint=inv.WorkPoint and inv.InvIQC='1'
  2518. LEFT JOIN ICSInventoryBatchEnable invBat ON inv.InvCode=invBat.InvCode AND (SELECT a.F_itemCode
  2519. FROM Sys_SRM_ItemsDetail a
  2520. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  2521. WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1')=invBat.WHCode AND inv.WorkPoint=invBat.WorkPoint
  2522. inner join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  2523. INNER JOIN ICSExtension ext ON c.ExtensionID=ext.ID AND c.WorkPoint=ext.WorkPoint
  2524. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  2525. inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND c.WorkPoint=l.WorkPoint
  2526. inner join ICSInspection d on c.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint and d.Enable='1'
  2527. WHERE ISNULL(extd.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(extd.BatchCode, '') ELSE '' END+'~'+ISNULL(extd.Version, '')+'~'+ISNULL(extd.Brand, '')+'~'+
  2528. ISNULL(extd.cFree1, '')+'~'+ISNULL(extd.cFree2, '')+'~'+ISNULL(extd.cFree3, '')+'~'+ISNULL(extd.cFree4, '')+'~'+ISNULL(extd.cFree5, '')+'~'+ISNULL(extd.cFree6, '')+'~'+ISNULL(extd.cFree7, '')+'~'+ISNULL(extd.cFree8, '')+'~'+ISNULL(extd.cFree9, '')+'~'+ISNULL(extd.cFree10, '')=ISNULL(ext.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END+'~'+ISNULL(ext.Version, '')+'~'+ISNULL(ext.Brand, '')+'~'+
  2529. ISNULL(ext.cFree1, '')+'~'+ISNULL(ext.cFree2, '')+'~'+ISNULL(ext.cFree3, '')+'~'+ISNULL(ext.cFree4, '')+'~'+ISNULL(ext.cFree5, '')+'~'+ISNULL(ext.cFree6, '')+'~'+ISNULL(ext.cFree7, '')+'~'+ISNULL(ext.cFree8, '')+'~'+ISNULL(ext.cFree9, '')+'~'+ISNULL(ext.cFree10, '')
  2530. AND b.LotNo IN (" + keyValue.TrimEnd(',') + ") ";
  2531. dtD = Repository().FindTableBySql(sqlAsnD.ToString());
  2532. }
  2533. else
  2534. {
  2535. string sqlAsn = @"select distinct a.VenCode,a.ODNID,a.DepCode,a.ODNCode from ICSODeliveryNotice a
  2536. left join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint
  2537. LEFT JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  2538. inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  2539. left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  2540. inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND d.WorkPoint=l.WorkPoint
  2541. WHERE b.LotNo in (" + keyValue.TrimEnd(',') + ")";
  2542. dt = Repository().FindTableBySql(sqlAsn.ToString());
  2543. 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
  2544. from ICSODeliveryNotice a
  2545. inner join ICSOASNDetail b on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint
  2546. inner join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint AND a.ExtensionID=c.ExtensionID
  2547. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  2548. inner JOIN ICSOutsourcingOrder l ON e.TransCode =l.OOCode AND e.TransSequence=l.Sequence AND a.OODetailID=l.OODetailID AND c.WorkPoint=l.WorkPoint
  2549. inner join ICSInspection d on c.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint and d.Enable='1'
  2550. WHERE b.LotNo IN (" + keyValue.TrimEnd(',') + ") ";
  2551. dtD = Repository().FindTableBySql(sqlAsnD.ToString());
  2552. }
  2553. List<WWRejectionHead> asn = new List<WWRejectionHead>();
  2554. for (int i = 0; i < dt.Rows.Count; i++)
  2555. {
  2556. WWRejectionHead ass = new WWRejectionHead();
  2557. ass.VenCode = dt.Rows[i]["VenCode"].ToString();
  2558. ass.ID = dt.Rows[i]["ODNID"].ToString();
  2559. ass.DepCode = dt.Rows[i]["DepCode"].ToString();
  2560. ass.ODNCode = dt.Rows[i]["ODNCode"].ToString();
  2561. ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2562. ass.MTIME = System.DateTime.Now.ToString("s");
  2563. ass.WorkPoint = WorkPoint;
  2564. DataRow[] drs = dtD.Select("ODNID='" + dt.Rows[i]["ODNID"].ToString() + "'");
  2565. for (int j = 0; j < drs.Length; j++)
  2566. {
  2567. WWRejectionBody DetailList = new WWRejectionBody();
  2568. DetailList.Sequence = (j + 1).ToString();
  2569. DetailList.InvCode = drs[j]["InvCode"].ToString();
  2570. DetailList.Quantity = drs[j]["Quantity"].ToString();
  2571. DetailList.Amount = drs[j]["Amount"].ToString();
  2572. DetailList.Currency = drs[j]["Currency"].ToString();
  2573. DetailList.UnitPrice = drs[j]["UnitPrice"].ToString();
  2574. DetailList.ODNDetailID = drs[j]["ODNDetailID"].ToString();
  2575. DetailList.LotNo = drs[j]["LotNo"].ToString();
  2576. ass.detail.Add(DetailList);
  2577. }
  2578. asn.Add(ass);
  2579. }
  2580. string input = JsonConvert.SerializeObject(asn);
  2581. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingRejectDoc/Create";
  2582. string result = HttpPost(APIURL, input);
  2583. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  2584. string MessAge = Obj["Message"].ToString();
  2585. string Success = Obj["Success"].ToString();
  2586. if (Success.ToUpper() == "FALSE")
  2587. {
  2588. msg = MessAge;
  2589. }
  2590. return msg;
  2591. }
  2592. catch (Exception ex)
  2593. {
  2594. throw new Exception(ex.Message);
  2595. }
  2596. }
  2597. //生成委外拒收单(无来源)
  2598. public string CreateWWWLYRejection(string keyValue)
  2599. {
  2600. string msg = "";
  2601. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2602. string sqlAsn = @"select distinct a.VenCode,a.ODNID,a.DepCode,a.ODNCode
  2603. from ICSODeliveryNotice a
  2604. left join ICSInventoryLotDetail e on a.ODNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint
  2605. inner JOIN ICSInventoryLot d ON e.LotNo=d.LotNo AND a.InvCode=d.InvCode AND e.WorkPoint=d.WorkPoint
  2606. left JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  2607. WHERE d.LotNo in (" + keyValue.TrimEnd(',') + ")";
  2608. DataTable dt = Repository().FindTableBySql(sqlAsn.ToString());
  2609. 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,c.LotNo
  2610. from ICSODeliveryNotice a
  2611. left join ICSInventoryLotDetail e on a.ODNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint
  2612. inner join ICSInventoryLot c on e.LotNo=c.LotNo and a.InvCode=c.InvCode and e.WorkPoint=c.WorkPoint --AND a.ExtensionID=c.ExtensionID
  2613. inner join ICSInspection d on c.LotNo=d.LotNo and a.WorkPoint=d.WorkPoint and d.Enable='1'
  2614. WHERE c.LotNo IN (" + keyValue.TrimEnd(',') + ") ";
  2615. DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString());
  2616. List<WWRejectionHead> asn = new List<WWRejectionHead>();
  2617. for (int i = 0; i < dt.Rows.Count; i++)
  2618. {
  2619. WWRejectionHead ass = new WWRejectionHead();
  2620. ass.VenCode = dt.Rows[i]["VenCode"].ToString();
  2621. ass.ID = dt.Rows[i]["ODNID"].ToString();
  2622. ass.DepCode = dt.Rows[i]["DepCode"].ToString();
  2623. ass.ODNCode = dt.Rows[i]["ODNCode"].ToString();
  2624. ass.User = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2625. ass.MTIME = System.DateTime.Now.ToString("s");
  2626. ass.WorkPoint = WorkPoint;
  2627. DataRow[] drs = dtD.Select("ODNID='" + dt.Rows[i]["ODNID"].ToString() + "'");
  2628. for (int j = 0; j < drs.Length; j++)
  2629. {
  2630. WWRejectionBody DetailList = new WWRejectionBody();
  2631. DetailList.Sequence = (j + 1).ToString();
  2632. DetailList.InvCode = drs[j]["InvCode"].ToString();
  2633. DetailList.Quantity = drs[j]["Quantity"].ToString();
  2634. DetailList.Amount = drs[j]["Amount"].ToString();
  2635. DetailList.Currency = drs[j]["Currency"].ToString();
  2636. DetailList.UnitPrice = drs[j]["UnitPrice"].ToString();
  2637. DetailList.ODNDetailID = drs[j]["ODNDetailID"].ToString();
  2638. DetailList.LotNo = drs[j]["LotNo"].ToString();
  2639. ass.detail.Add(DetailList);
  2640. }
  2641. asn.Add(ass);
  2642. }
  2643. string input = JsonConvert.SerializeObject(asn);
  2644. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingRejectDocNoTrans/Create";
  2645. string result = HttpPost(APIURL, input);
  2646. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  2647. string MessAge = Obj["Message"].ToString();
  2648. string Success = Obj["Success"].ToString();
  2649. if (Success.ToUpper() == "FALSE")
  2650. {
  2651. msg = MessAge;
  2652. }
  2653. return msg;
  2654. }
  2655. public static string HttpPost(string url, string body)
  2656. {
  2657. try
  2658. {
  2659. Encoding encoding = Encoding.UTF8;
  2660. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  2661. request.Method = "POST";
  2662. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  2663. request.ContentType = "application/json; charset=utf-8";
  2664. byte[] buffer = encoding.GetBytes(body);
  2665. request.ContentLength = buffer.Length;
  2666. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  2667. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  2668. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  2669. {
  2670. return reader.ReadToEnd();
  2671. }
  2672. }
  2673. catch (WebException ex)
  2674. {
  2675. throw new Exception(ex.Message);
  2676. }
  2677. }
  2678. /// <summary>
  2679. /// 删除拒收单
  2680. /// </summary>
  2681. /// <param name="keyValue">传入ID</param>
  2682. /// <returns></returns>
  2683. public string DelectRejection(string keyValue)
  2684. {
  2685. //站点信息
  2686. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2687. string msg = "";
  2688. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  2689. string sql = string.Empty;
  2690. sql = string.Format(@"DELETE FROM dbo.ICSDeliveryNotice WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  2691. try
  2692. {
  2693. SqlHelper.ExecuteNonQuery(sql);
  2694. }
  2695. catch (Exception ex)
  2696. {
  2697. throw new Exception(ex.Message);
  2698. }
  2699. return msg;
  2700. }
  2701. /// <summary>
  2702. /// 删除委外拒收单
  2703. /// </summary>
  2704. /// <param name="keyValue">传入ID</param>
  2705. /// <returns></returns>
  2706. public string DelectWWRejection(string keyValue)
  2707. {
  2708. //站点信息
  2709. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2710. string msg = "";
  2711. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  2712. string sql = string.Empty;
  2713. sql = string.Format(@"DELETE FROM dbo.ICSODeliveryNotice WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  2714. try
  2715. {
  2716. SqlHelper.ExecuteNonQuery(sql);
  2717. }
  2718. catch (Exception ex)
  2719. {
  2720. throw new Exception(ex.Message);
  2721. }
  2722. return msg;
  2723. }
  2724. public DataTable GetInventoryInspection(ref Pagination jqgridparam, string InvCode, int SampleQuantity, string ResultINp)
  2725. {
  2726. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2727. DataTable dt = new DataTable();
  2728. List<DbParameter> parameter = new List<DbParameter>();
  2729. string sql = string.Empty;
  2730. if (ResultINp == "")
  2731. {
  2732. sql = "SELECT 1 AS NUM INTO #TEmpType";
  2733. for (int i = 2; i <= SampleQuantity; i++)
  2734. {
  2735. sql += @" UNION
  2736. SELECT " + i + " AS NUM";
  2737. }
  2738. sql += @" select c.ID,a.GroupCode,a.GroupName,c.InspectionID,b.ListCode, b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,c.SetValue,CASE WHEN c.Result='0' THEN '不合格' when ISNULL(c.Result,'')='' THEN '' ELSE '合格' END AS Result
  2739. INTO #TEmpTypedetail from ICSInventoryInspectionGroup a
  2740. left join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint
  2741. left join ICSInspectionDetail c on b.ListCode=c.ListCode and b.ListName=c.ListName and b.WorkPoint=c.WorkPoint
  2742. where a.InvCode='{0}' and b.Enable='1' and a.WorkPoint='{1}'
  2743. SELECT a.NUM, NEWID() AS ID,b.GroupCode,b.GroupName,b.InspectionID,b.ListCode, b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,b.SetValue,CASE WHEN b.Result='0' THEN '' when ISNULL(b.Result,'')='' THEN '' ELSE '' END AS Result INTO ##SUMCount FROM #TEmpType a ,#TEmpTypedetail b ORDER BY a.NUM,b.GroupCode ASC
  2744. ";
  2745. sql = string.Format(sql, InvCode, WorkPoint);
  2746. return SqlHelper.FindTablePageBySql_OtherTemp(sql.ToString(), " " + "##SUMCount" + " ", " DROP TABLE #TEmpType;DROP TABLE #TEmpTypedetail;DROP TABLE ##SUMCount", parameter.ToArray(), ref jqgridparam);
  2747. }
  2748. else
  2749. {
  2750. sql += @" select c.EATTRIBUTE1 as NUM, c.ID,a.GroupCode,a.GroupName,c.InspectionID,b.ListCode, b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,c.SetValue,CASE WHEN c.Result='0' THEN '不合格' when ISNULL(c.Result,'')='' THEN '' ELSE '合格' END AS Result
  2751. from ICSInventoryInspectionGroup a
  2752. left join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint
  2753. left join ICSInspectionDetail c on b.ListCode=c.ListCode and b.ListName=c.ListName and b.WorkPoint=c.WorkPoint
  2754. where a.InvCode='{0}' and b.Enable='1' and a.WorkPoint='{1}'
  2755. ";
  2756. sql = string.Format(sql, InvCode, WorkPoint);
  2757. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  2758. }
  2759. }
  2760. public string SaveICSInspectionDetail(string ICSMTDOC, string InvCode, string ResultINp)
  2761. {
  2762. string msg = "";
  2763. try
  2764. {
  2765. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2766. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2767. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2768. string sql = string.Empty;
  2769. JArray res = (JArray)JsonConvert.DeserializeObject(ICSMTDOC);
  2770. bool ISOK = false;
  2771. string ID = string.Empty;
  2772. foreach (var item in res)
  2773. {
  2774. JObject jo = (JObject)item;
  2775. ID = jo["InspectionID"].ToString();
  2776. if (string.IsNullOrWhiteSpace(ResultINp))
  2777. {
  2778. sql += @"
  2779. INSERT INTO dbo.ICSInspectionDetail
  2780. ( ID ,InspectionID ,ListCode ,ListName ,
  2781. Unit ,SetValueMax ,SetValueMin ,SetValue ,Result, MUSER ,MUSERName ,MTIME, WorkPoint,GroupCode,GroupName,EATTRIBUTE1)
  2782. values(newid(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}',getdate(),'{10}','{11}','{12}','{13}')";
  2783. 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["NUM"].ToString());
  2784. }
  2785. else
  2786. {
  2787. 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}',EATTRIBUTE1='{14}' where ID='{13}'";
  2788. 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(), jo["NUM"].ToString());
  2789. }
  2790. if (jo["Result"].ToString() == "0")
  2791. {
  2792. ISOK = true;
  2793. }
  2794. }
  2795. if (ISOK == true)
  2796. {
  2797. sql += @" update ICSInspection set Result='{0}' where ID='{1}'";
  2798. sql = string.Format(sql, 0, ID);
  2799. }
  2800. else
  2801. {
  2802. sql += @" update ICSInspection set Result='{0}' where ID='{1}'";
  2803. sql = string.Format(sql, 1, ID);
  2804. }
  2805. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  2806. {
  2807. }
  2808. else
  2809. {
  2810. msg = "绑定失败";
  2811. }
  2812. }
  2813. catch (Exception ex)
  2814. {
  2815. msg = ex.Message;
  2816. }
  2817. return msg;
  2818. }
  2819. /// <summary>
  2820. /// 上传招标文件
  2821. /// </summary>
  2822. /// <param name="keyValue"></param>
  2823. /// <returns></returns>
  2824. public int InsertICSInspectionFile(string ID, string UploadfileName, string fileName)
  2825. {
  2826. DataTable dt = new DataTable();
  2827. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2828. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2829. string MUSERName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2830. string sql = "";
  2831. sql += string.Format(@"Insert into ICSInspectionFile(ID,InspectionID,FileCode,FileName,MUSER,MUSERName,MTIME,WorkPoint) values(NEWID(),'{0}','{1}','{2}','{3}','{4}',GetDate(),'{5}')", ID, UploadfileName, fileName, MUSER, MUSERName, WorkPoint);
  2832. sql += "\r\n";
  2833. StringBuilder Str = new StringBuilder(sql);
  2834. return Repository().ExecuteBySql(Str);
  2835. }
  2836. public DataTable GetICSInspection8(ref Pagination jqgridparam, string MenuID, string queryJson)
  2837. {
  2838. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  2839. //string ERPSign = Configs.GetValue("ERPSign");
  2840. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2841. DataTable dt = new DataTable();
  2842. var queryParam = queryJson.ToJObject();
  2843. List<DbParameter> parameter = new List<DbParameter>();
  2844. string sql = string.Empty;
  2845. sql = @"
  2846. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8'))
  2847. drop table #TempMOData_8
  2848. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8_1'))
  2849. drop table #TempMOData_8_1
  2850. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_8'))
  2851. drop table #TempIcsinsp_8
  2852. select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,EATTRIBUTE2,
  2853. SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode{2}
  2854. into #TempIcsinsp_8
  2855. from dbo.ICSInspection
  2856. where workpoint='" + WorkPoint + @"' and Enable='1'
  2857. select DISTINCT
  2858. a.ID as DHID,
  2859. d.ID ,
  2860. h.ID as JYID,
  2861. a.DNCode ,
  2862. a.Sequence ,
  2863. a.ASNCode ,
  2864. --l.POCode,
  2865. c.InvCode ,
  2866. c.InvName ,
  2867. c.INVSTD ,
  2868. c.ClassName,
  2869. c.EATTRIBUTE3 as InvEATTRIBUTE3,
  2870. CAST(d.Quantity as decimal(18,4)) as AllNumber,
  2871. CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as decimal(18,4))as YLOTQTY ,
  2872. CAST(ISNULL(h.UnqualifiedQuantity, 0) as decimal(18,4)) as NLOTQTY,
  2873. CAST(ISNULL(h.WaiveQuantity, 0) as decimal(18,4)) as SpecialQTY,
  2874. CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity ,
  2875. c.InvUnit ,
  2876. d.LotNo ,
  2877. g.BadReasonDesc as BadReasonDesc ,
  2878. g.BadReasonCode as BRCodeValue,
  2879. j.BadCode as BCCodeValue,
  2880. j.BadDesc as BadDesc,
  2881. k.ContainerID,
  2882. isnull(h.MUSERName,'') MUSERName,
  2883. CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime,
  2884. CONVERT(VARCHAR(100),a.CreateDateTime,120) as CreateDateTime,
  2885. CONVERT(VARCHAR(100),d.MTime,120) as LotCreateDateTime,
  2886. CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  2887. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  2888. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  2889. a.VenCode,
  2890. m.VenName,
  2891. isnull(h.MUSERName,'') as Surveyor,
  2892. --isnull(h.EATTRIBUTE2,'') as InspectionEATTRIBUTE2,
  2893. h.mtime as ProvingTime
  2894. ,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
  2895. ,CASE WHEN h.Result='0' THEN '' when ISNULL(h.Result,'')='' THEN '' ELSE '' END AS Result,
  2896. n.FileName,c.InvIQC{3}
  2897. into #TempMOData_8
  2898. FROM ICSDeliveryNotice a
  2899. --inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  2900. left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint
  2901. inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint-- and c.InvIQC='1'
  2902. inner JOIN ICSInventoryLot d ON e.LotNo=d.LotNo AND a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint and d.type='7'
  2903. LEFT JOIN #TempIcsinsp_8 h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint --and Enable='1'
  2904. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  2905. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  2906. LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND a.WorkPoint=k.WorkPoint
  2907. left join ICSExtension f on d.ExtensionID=f.ID and d.WorkPoint=f.WorkPoint
  2908. left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint
  2909. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  2910. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  2911. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND d.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  2912. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  2913. LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID
  2914. where d.LotNo is not null and a.DNType='1' {0} and a.workpoint='{1}' and Isnull(d.EATTRIBUTE1,'') = ''
  2915. select * into #TempMOData_8_1 from #TempMOData_8 where InvIQC='1'
  2916. ";
  2917. string wheresql = "";
  2918. if (!string.IsNullOrWhiteSpace(queryJson))
  2919. {
  2920. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  2921. {
  2922. wheresql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  2923. }
  2924. //if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
  2925. //{
  2926. // wheresql += " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ";
  2927. //}
  2928. //if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString()))
  2929. //{
  2930. // wheresql += " and l.POCode like '%" + queryParam["CaiGouCode"].ToString() + "%' ";
  2931. //}
  2932. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  2933. {
  2934. wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  2935. }
  2936. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  2937. {
  2938. wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  2939. }
  2940. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  2941. {
  2942. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  2943. }
  2944. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  2945. {
  2946. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  2947. }
  2948. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  2949. {
  2950. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  2951. }
  2952. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  2953. {
  2954. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  2955. }
  2956. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  2957. {
  2958. wheresql += " and d.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  2959. }
  2960. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  2961. {
  2962. string ReleaseState = queryParam["ReleaseState"].ToString();
  2963. if (ReleaseState == "1")
  2964. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  2965. else if (ReleaseState == "0")
  2966. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  2967. else
  2968. wheresql += " ";
  2969. }
  2970. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  2971. {
  2972. string selEnableShow = queryParam["selEnableShow"].ToString();
  2973. if (selEnableShow == "1")
  2974. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  2975. else if (selEnableShow == "0")
  2976. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  2977. }
  2978. if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString()))
  2979. {
  2980. string printState = queryParam["selIsPrint"].ToString();
  2981. if (printState == "否")
  2982. wheresql += " and isnull(task.ValueParameters,'') ='' ";
  2983. else if (printState == "是")
  2984. wheresql += " and isnull(task.ValueParameters,'') <>''";
  2985. }
  2986. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  2987. {
  2988. if (queryParam["selIsWH"].ToString() == "0")
  2989. {
  2990. wheresql += " and lotInfo.ID is null ";
  2991. }
  2992. if (queryParam["selIsWH"].ToString() == "1")
  2993. {
  2994. wheresql += " and lotInfo.ID is not null ";
  2995. }
  2996. }
  2997. }
  2998. wheresql += " " + DataActionsql;
  2999. //sql = string.Format(sql, wheresql, WorkPoint);
  3000. sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  3001. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  3002. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_8_1",
  3003. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8'))
  3004. drop table #TempMOData_8
  3005. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_8_1'))
  3006. drop table #TempMOData_8_1
  3007. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_8'))
  3008. drop table #TempIcsinsp_8 ",
  3009. "connstr", parameter.ToArray(), ref jqgridparam);
  3010. }
  3011. public DataTable GetICSInspection9(ref Pagination jqgridparam, string MenuID, string queryJson)
  3012. {
  3013. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  3014. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3015. DataTable dt = new DataTable();
  3016. var queryParam = queryJson.ToJObject();
  3017. List<DbParameter> parameter = new List<DbParameter>();
  3018. #region
  3019. string sql = @"
  3020. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9'))
  3021. drop table #TempMOData_9
  3022. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9_1'))
  3023. drop table #TempMOData_9_1
  3024. select
  3025. a.ID as DHID,
  3026. d.ID ,
  3027. h.ID as JYID,
  3028. a.ODNCode as DNCode ,
  3029. a.Sequence ,
  3030. a.OASNCode ,
  3031. c.InvCode ,
  3032. c.InvName ,
  3033. c.INVSTD ,
  3034. c.ClassName,
  3035. a.VenCode,
  3036. m.VenName,
  3037. c.EATTRIBUTE3 as InvEATTRIBUTE3,
  3038. f.BatchCode ,
  3039. CAST(d.Quantity as NUMERIC(10,4)) as AllNumber,
  3040. CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  3041. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  3042. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  3043. CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity ,
  3044. CONVERT(VARCHAR(100),d.MTime,120) as LotCreateDateTime,
  3045. c.InvUnit ,
  3046. d.LotNo ,
  3047. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  3048. g.BadReasonDesc as BadReasonDesc ,
  3049. g.BadReasonCode as BRCodeValue,
  3050. j.BadCode as BCCodeValue,
  3051. j.BadDesc as BadDesc,
  3052. k.ContainerID,
  3053. isnull(h.MUSERName,'') MUSERName,
  3054. CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime,
  3055. CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  3056. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,c.InvIQC
  3057. into #TempMOData_9
  3058. FROM ICSODeliveryNotice a
  3059. inner join ICSInventoryLotDetail e on e.TransCode =a.ODNCode AND e.TransSequence=a.Sequence AND e.WorkPoint=a.WorkPoint
  3060. inner JOIN ICSInventoryLot d ON d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint and d.type='8'
  3061. inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint --and c.InvIQC='1'
  3062. left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint
  3063. LEFT JOIN dbo.ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=d.WorkPoint
  3064. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  3065. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  3066. LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND d.WorkPoint=k.WorkPoint
  3067. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3068. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  3069. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND d.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  3070. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  3071. LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID
  3072. where 1=1 {0} and a.workpoint='{1}'
  3073. select * into #TempMOData_9_1 from #TempMOData_9 where InvIQC='1'";
  3074. #endregion
  3075. string wheresql = "";
  3076. if (!string.IsNullOrWhiteSpace(queryJson))
  3077. {
  3078. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  3079. {
  3080. wheresql += " and a.ODNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  3081. }
  3082. //if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
  3083. //{
  3084. // wheresql += " and a.OASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ";
  3085. //}
  3086. //if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString()))
  3087. //{
  3088. // wheresql += " and l.OOCode like '%" + queryParam["CaiGouCode"].ToString() + "%' ";
  3089. //}
  3090. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  3091. {
  3092. wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  3093. }
  3094. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  3095. {
  3096. wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  3097. }
  3098. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  3099. {
  3100. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  3101. }
  3102. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  3103. {
  3104. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  3105. }
  3106. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  3107. {
  3108. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  3109. }
  3110. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  3111. {
  3112. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  3113. }
  3114. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  3115. {
  3116. wheresql += " and d.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  3117. }
  3118. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  3119. {
  3120. string ReleaseState = queryParam["ReleaseState"].ToString();
  3121. if (ReleaseState == "1")
  3122. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  3123. else if (ReleaseState == "0")
  3124. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  3125. else
  3126. wheresql += " ";
  3127. }
  3128. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  3129. {
  3130. string selEnableShow = queryParam["selEnableShow"].ToString();
  3131. if (selEnableShow == "1")
  3132. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  3133. else if (selEnableShow == "0")
  3134. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  3135. }
  3136. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  3137. {
  3138. if (queryParam["selIsWH"].ToString() == "0")
  3139. {
  3140. wheresql += " and lotInfo.ID is null ";
  3141. }
  3142. if (queryParam["selIsWH"].ToString() == "1")
  3143. {
  3144. wheresql += " and lotInfo.ID is not null ";
  3145. }
  3146. }
  3147. if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString()))
  3148. {
  3149. string printState = queryParam["selIsPrint"].ToString();
  3150. if (printState == "否")
  3151. wheresql += " and isnull(task.ValueParameters,'') ='' ";
  3152. else if (printState == "是")
  3153. wheresql += " and isnull(task.ValueParameters,'') <>''";
  3154. }
  3155. }
  3156. wheresql += " " + DataActionsql;
  3157. sql = string.Format(sql, wheresql, WorkPoint);
  3158. //sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  3159. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  3160. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_9_1",
  3161. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9'))
  3162. drop table #TempMOData_9
  3163. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_9_1'))
  3164. drop table #TempMOData_9_1 ",
  3165. "connstr", parameter.ToArray(), ref jqgridparam);
  3166. }
  3167. public DataTable GetICSInspection10(ref Pagination jqgridparam, string MenuID, string queryJson)
  3168. {
  3169. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  3170. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3171. DataTable dt = new DataTable();
  3172. var queryParam = queryJson.ToJObject();
  3173. List<DbParameter> parameter = new List<DbParameter>();
  3174. string sql = @"
  3175. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10'))
  3176. drop table #TempMOData_10
  3177. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10_1'))
  3178. drop table #TempMOData_10_1
  3179. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_10'))
  3180. drop table #TempIcsinsp_10
  3181. select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,
  3182. SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode{2}
  3183. into #TempIcsinsp_10
  3184. from dbo.ICSInspection
  3185. where workpoint='" + WorkPoint + @"' and Enable='1'
  3186. select DISTINCT a.ID as GDID, e.ID , a.MOCode as DNCode, a.Sequence , h.ID as JYID, pick.InvCode, c.InvName , c.INVSTD , c.ClassName,c.InvDesc,
  3187. 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, c.EATTRIBUTE3 as InvEATTRIBUTE3,
  3188. CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  3189. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  3190. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  3191. CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity ,
  3192. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  3193. c.InvUnit , e.LotNo , g.BadReasonDesc as BadReasonDesc ,
  3194. g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc, i.ContainerID,
  3195. isnull(h.MUSERName,'') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  3196. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  3197. isnull(h.MUSERName,'') as Surveyor, h.mtime as ProvingTime
  3198. ,CASE WHEN h.Result='0' THEN '' when ISNULL(h.Result,'')='' THEN '' ELSE '' END AS Result,
  3199. n.FileName,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  3200. a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC{3}
  3201. into #TempMOData_10
  3202. from ICSMO a
  3203. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1'
  3204. LEFT JOIN ICSMOPick pick ON a.MODetailID=pick.MODetailID AND a.WorkPoint=pick.WorkPoint AND pick.EATTRIBUTE1='1'
  3205. left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence+'~'+ pick.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint
  3206. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3207. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint
  3208. LEFT JOIN #TempIcsinsp_10 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1'
  3209. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  3210. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  3211. LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint
  3212. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  3213. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  3214. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND e.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  3215. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  3216. where a.MOStatus<>'3' and e.LotNO is not null {0} and a.workpoint='{1}'
  3217. select * into #TempMOData_10_1 from #TempMOData_10 where InvIQC='1' ";
  3218. string wheresql = "";
  3219. if (!string.IsNullOrWhiteSpace(queryJson))
  3220. {
  3221. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  3222. {
  3223. wheresql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  3224. }
  3225. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  3226. {
  3227. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  3228. }
  3229. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  3230. {
  3231. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  3232. }
  3233. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  3234. {
  3235. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  3236. }
  3237. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  3238. {
  3239. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  3240. }
  3241. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  3242. {
  3243. wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  3244. }
  3245. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  3246. {
  3247. string ReleaseState = queryParam["ReleaseState"].ToString();
  3248. if (ReleaseState == "1")
  3249. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  3250. else if (ReleaseState == "0")
  3251. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  3252. else
  3253. wheresql += " ";
  3254. }
  3255. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  3256. {
  3257. string selEnableShow = queryParam["selEnableShow"].ToString();
  3258. if (selEnableShow == "1")
  3259. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  3260. else if (selEnableShow == "0")
  3261. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  3262. }
  3263. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  3264. {
  3265. if (queryParam["selIsWH"].ToString() == "0")
  3266. {
  3267. wheresql += " and lotInfo.ID is null ";
  3268. }
  3269. if (queryParam["selIsWH"].ToString() == "1")
  3270. {
  3271. wheresql += " and lotInfo.ID is not null ";
  3272. }
  3273. }
  3274. }
  3275. wheresql += " " + DataActionsql;
  3276. //sql = string.Format(sql, wheresql, WorkPoint);
  3277. sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  3278. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  3279. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_10_1",
  3280. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10'))
  3281. drop table #TempMOData_10
  3282. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10_1'))
  3283. drop table #TempMOData_10_1
  3284. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_10'))
  3285. drop table #TempIcsinsp_10 ",
  3286. "connstr", parameter.ToArray(), ref jqgridparam);
  3287. }
  3288. //比博联副产品检验
  3289. public DataTable GetICSInspection101(ref Pagination jqgridparam, string MenuID, string queryJson)
  3290. {
  3291. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  3292. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3293. DataTable dt = new DataTable();
  3294. var queryParam = queryJson.ToJObject();
  3295. List<DbParameter> parameter = new List<DbParameter>();
  3296. string sql = @"
  3297. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10'))
  3298. drop table #TempMOData_10
  3299. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10_1'))
  3300. drop table #TempMOData_10_1
  3301. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_10'))
  3302. drop table #TempIcsinsp_10
  3303. select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,
  3304. SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode,InvCode{2}
  3305. into #TempIcsinsp_10
  3306. from dbo.ICSInspection
  3307. where workpoint='" + WorkPoint + @"' and Enable='1'
  3308. select DISTINCT a.ID as GDID, e.ID , a.MOCode as DNCode, a.Sequence , h.ID as JYID, pick.InvCode, c.InvName , c.INVSTD , c.ClassName,c.InvDesc,
  3309. 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, c.EATTRIBUTE3 as InvEATTRIBUTE3,
  3310. CAST(ISNULL(h.QualifiedQuantity,e.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  3311. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  3312. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  3313. CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity ,
  3314. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  3315. c.InvUnit , e.LotNo , g.BadReasonDesc as BadReasonDesc ,
  3316. g.BadReasonCode as BRCodeValue,j.BadCode as BCCodeValue, j.BadDesc as BadDesc, i.ContainerID,
  3317. isnull(h.MUSERName,'') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  3318. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  3319. isnull(h.MUSERName,'') as Surveyor, h.mtime as ProvingTime
  3320. ,CASE WHEN h.Result='0' THEN ''
  3321. when ISNULL(h.Result,'')='' THEN ''
  3322. WHEN h.Result='1' AND h.WaiveQuantity=0 THEN ''
  3323. WHEN h.Result='1' AND h.WaiveQuantity!=0 THEN '' END AS Result,
  3324. n.FileName,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  3325. a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC{3}
  3326. into #TempMOData_10
  3327. from ICSMO a
  3328. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1'
  3329. LEFT JOIN ICSMOPick pick ON a.MODetailID=pick.MODetailID AND a.WorkPoint=pick.WorkPoint AND pick.EATTRIBUTE1='1'
  3330. left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence+'~'+ pick.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint
  3331. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3332. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint
  3333. LEFT JOIN #TempIcsinsp_10 h ON h.LotNO=e.LotNO and h.InvCode=e.InvCode and h.WorkPoint=e.WorkPoint --and Enable='1'
  3334. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  3335. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  3336. LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint
  3337. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  3338. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  3339. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND e.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  3340. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  3341. where a.MOStatus<>'3' and e.LotNO is not null {0} and a.workpoint='{1}'
  3342. select * into #TempMOData_10_1 from #TempMOData_10 where InvIQC='1' ";
  3343. string wheresql = "";
  3344. if (!string.IsNullOrWhiteSpace(queryJson))
  3345. {
  3346. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  3347. {
  3348. wheresql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  3349. }
  3350. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  3351. {
  3352. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  3353. }
  3354. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  3355. {
  3356. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  3357. }
  3358. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  3359. {
  3360. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  3361. }
  3362. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  3363. {
  3364. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  3365. }
  3366. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  3367. {
  3368. wheresql += " and e.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  3369. }
  3370. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  3371. {
  3372. string ReleaseState = queryParam["ReleaseState"].ToString();
  3373. if (ReleaseState == "1")
  3374. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  3375. else if (ReleaseState == "0")
  3376. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  3377. else
  3378. wheresql += " ";
  3379. }
  3380. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  3381. {
  3382. string selEnableShow = queryParam["selEnableShow"].ToString();
  3383. if (selEnableShow == "1")
  3384. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  3385. else if (selEnableShow == "0")
  3386. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  3387. }
  3388. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  3389. {
  3390. if (queryParam["selIsWH"].ToString() == "0")
  3391. {
  3392. wheresql += " and lotInfo.ID is null ";
  3393. }
  3394. if (queryParam["selIsWH"].ToString() == "1")
  3395. {
  3396. wheresql += " and lotInfo.ID is not null ";
  3397. }
  3398. }
  3399. }
  3400. wheresql += " " + DataActionsql;
  3401. //sql = string.Format(sql, wheresql, WorkPoint);
  3402. sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  3403. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  3404. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_10_1",
  3405. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10'))
  3406. drop table #TempMOData_10
  3407. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_10_1'))
  3408. drop table #TempMOData_10_1
  3409. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_10'))
  3410. drop table #TempIcsinsp_10 ",
  3411. "connstr", parameter.ToArray(), ref jqgridparam);
  3412. }
  3413. //在库检验
  3414. public DataTable GetICSInspection11(ref Pagination jqgridparam, string MenuID, string queryJson)
  3415. {
  3416. try
  3417. {
  3418. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  3419. DataTable dt = new DataTable();
  3420. var queryParam = queryJson.ToJObject();
  3421. List<DbParameter> parameter = new List<DbParameter>();
  3422. string sql = @" select DISTINCT a.ID as GDID, e.ID AS LotID , a.InspectCode as DNCode, d.Sequence , d.ID as ID, e.InvCode, c.InvName , c.INVSTD , c.ClassName,c.InvDesc,
  3423. 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
  3424. --, g.Quantity-ISNULL(g.LockQuantity,0) as AllNumber,
  3425. , d.Quantity AS AllNumber,
  3426. Case When d.EATTRIBUTE1='' Then 0 Else d.InspectQuantity END as YLOTQTY ,
  3427. Case When d.EATTRIBUTE1='' Then 0 Else Convert(decimal(18,4),d.Quantity)-Convert(decimal(18,4),d.InspectQuantity) END as NLOTQTY,
  3428. Case When a.Type=0 Then '' ELSE '' END AS DocType,
  3429. c.InvUnit , d.LotNo ,i.ContainerID,CONVERT(varchar(100), e.ExpirationDate, 23) AS ExpirationDate,
  3430. isnull(a.MUSERName,'') MUSERName, CONVERT(VARCHAR(100),e.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),a.MTIME,120) as MTIME,
  3431. d.EATTRIBUTE1 AS TestState,c.EATTRIBUTE3 as InvEATTRIBUTE3,d.EATTRIBUTE11 AS TestDate,
  3432. Case When d.EATTRIBUTE1='' Then '' else isnull(d.MUSERName,'') end as Surveyor, d.MTIME as ProvingTime,
  3433. a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  3434. a.EATTRIBUTE9,a.EATTRIBUTE10,K.BadReasonDesc as BadReasonDesc ,
  3435. K.BadReasonCode as BRCodeValue,L.BadCode as BCCodeValue, L.BadDesc as BadDesc,d.EATTRIBUTE10 AS Memo
  3436. from ICSInspect a
  3437. inner join ICSInspectDetail d on d.InspectCode=a.InspectCode and d.WorkPoint=a.WorkPoint
  3438. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=d.LotNo AND e.WorkPoint=d.WorkPoint
  3439. LEFT JOIN dbo.ICSWareHouseLotInfo g ON g.LotNo=e.LotNo and g.WorkPoint=e.WorkPoint
  3440. inner JOIN dbo.ICSInventory c ON c.InvCode=e.InvCode AND c.WorkPoint=e.WorkPoint --and c.InvIQC='1'
  3441. left join ICSExtension f on f.ID=e.ExtensionID and f.WorkPoint=e.WorkPoint
  3442. LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint
  3443. LEFT JOIN DBO.ICSInspection J ON J.LotNo=D.LotNo AND J.EATTRIBUTE1=d.InspectCode AND J.WorkPoint=d.WorkPoint AND J.Enable=1
  3444. LEFT JOIN DBO.ICSBadReason K ON K.BadReasonCode=J.BRCode AND K.WorkPoint=J.WorkPoint
  3445. LEFT JOIN DBO.ICSBadCode L ON L.BadCode=J.BCCode AND L.WorkPoint=J.WorkPoint
  3446. where g.LotNO is not null {0} ";
  3447. string wheresql = "";
  3448. if (!string.IsNullOrWhiteSpace(queryJson))
  3449. {
  3450. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  3451. {
  3452. wheresql += " and a.InspectCode like '%" + queryParam["POCode"].ToString() + "%' ";
  3453. }
  3454. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  3455. {
  3456. wheresql += " and e.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  3457. }
  3458. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  3459. {
  3460. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  3461. }
  3462. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  3463. {
  3464. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  3465. }
  3466. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  3467. {
  3468. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  3469. }
  3470. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  3471. {
  3472. wheresql += " and d.LotNo like '%" + queryParam["LotNO"].ToString() + "%' ";
  3473. }
  3474. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  3475. {
  3476. string ReleaseState = queryParam["ReleaseState"].ToString();
  3477. if (ReleaseState == "0")
  3478. wheresql += " and d.EATTRIBUTE1='未检验' ";
  3479. else if (ReleaseState == "1")
  3480. wheresql += " and d.EATTRIBUTE1='已检验'";
  3481. else if (ReleaseState == "3")
  3482. wheresql += " and d.EATTRIBUTE1='已审核'";
  3483. else if (ReleaseState == "4")
  3484. wheresql += " and d.EATTRIBUTE1='已复审'";
  3485. else
  3486. wheresql += " ";
  3487. }
  3488. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  3489. {
  3490. string selEnableShow = queryParam["selEnableShow"].ToString();
  3491. if (selEnableShow == "1")
  3492. wheresql += " and Convert(decimal(18,4),ISNULL(d.InspectQuantity,0))=Convert(decimal(18,4),ISNULL(d.Quantity,0))";
  3493. else if (selEnableShow == "0")
  3494. wheresql += " and Convert(decimal(18,4),ISNULL(d.InspectQuantity,0))!=Convert(decimal(18,4),ISNULL(d.Quantity,0))";
  3495. }
  3496. if (!string.IsNullOrWhiteSpace(queryParam["Surveyor"].ToString()))
  3497. {
  3498. wheresql += " and d.MUSERName like '%" + queryParam["Surveyor"].ToString() + "%' ";
  3499. }
  3500. if (!string.IsNullOrWhiteSpace(queryParam["DocType"].ToString()))
  3501. {
  3502. string docType = queryParam["DocType"].ToString();
  3503. if (docType == "0")
  3504. wheresql += " and a.Type=0 ";
  3505. else if (docType == "1")
  3506. wheresql += " and a.Type!=0 ";
  3507. }
  3508. }
  3509. if (DataActionsql != "")
  3510. {
  3511. sql += DataActionsql;
  3512. }
  3513. sql = string.Format(sql, wheresql);
  3514. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  3515. }
  3516. catch (Exception ex)
  3517. {
  3518. throw new Exception(ex.Message);
  3519. }
  3520. }
  3521. public DataTable GetICSInspection22(ref Pagination jqgridparam, string MenuID, string queryJson)
  3522. {
  3523. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  3524. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3525. DataTable dt = new DataTable();
  3526. var queryParam = queryJson.ToJObject();
  3527. List<DbParameter> parameter = new List<DbParameter>();
  3528. #region
  3529. string sql = @"
  3530. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_22'))
  3531. drop table #TempMOData_22
  3532. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_22_1'))
  3533. drop table #TempMOData_22_1
  3534. select
  3535. a.ID as DHID,
  3536. d.ID ,
  3537. h.ID as JYID,
  3538. a.RCVCode as DNCode ,
  3539. a.Sequence ,
  3540. c.InvCode ,
  3541. c.InvName ,
  3542. c.INVSTD ,
  3543. c.ClassName,
  3544. f.BatchCode ,
  3545. CAST(d.Quantity as NUMERIC(10,4)) as AllNumber,
  3546. CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  3547. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  3548. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  3549. CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity ,
  3550. c.InvUnit ,c.EATTRIBUTE3 as InvEATTRIBUTE3,
  3551. d.LotNo ,
  3552. g.BadReasonDesc as BadReasonDesc ,
  3553. g.BadReasonCode as BRCodeValue,
  3554. j.BadCode as BCCodeValue,
  3555. j.BadDesc as BadDesc,
  3556. k.ContainerID,
  3557. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  3558. isnull(h.MUSERName,'') MUSERName,
  3559. CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime,
  3560. CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  3561. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,c.InvIQC
  3562. into #TempMOData_22
  3563. FROM ICSPurchaseReceive a
  3564. inner join ICSInventoryLotDetail e on e.TransCode =a.RCVCode AND e.TransSequence=a.Sequence AND e.WorkPoint=a.WorkPoint
  3565. inner JOIN ICSInventoryLot d ON d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint and d.type='22'
  3566. inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint --and c.InvIQC='1'
  3567. LEFT JOIN dbo.ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=d.WorkPoint
  3568. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  3569. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  3570. LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND d.WorkPoint=k.WorkPoint
  3571. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3572. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  3573. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND d.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  3574. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  3575. where 1=1 {0} and a.workpoint='{1}'
  3576. select * into #TempMOData_22_1 from #TempMOData_22 where InvIQC='1'";
  3577. #endregion
  3578. string wheresql = "";
  3579. if (!string.IsNullOrWhiteSpace(queryJson))
  3580. {
  3581. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  3582. {
  3583. wheresql += " and a.RCVCode like '%" + queryParam["POCode"].ToString() + "%' ";
  3584. }
  3585. //if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
  3586. //{
  3587. // wheresql += " and a.OASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ";
  3588. //}
  3589. //if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString()))
  3590. //{
  3591. // wheresql += " and l.OOCode like '%" + queryParam["CaiGouCode"].ToString() + "%' ";
  3592. //}
  3593. //if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  3594. //{
  3595. // wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  3596. //}
  3597. //if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  3598. //{
  3599. // wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  3600. //}
  3601. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  3602. {
  3603. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  3604. }
  3605. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  3606. {
  3607. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  3608. }
  3609. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  3610. {
  3611. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  3612. }
  3613. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  3614. {
  3615. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  3616. }
  3617. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  3618. {
  3619. wheresql += " and d.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  3620. }
  3621. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  3622. {
  3623. string ReleaseState = queryParam["ReleaseState"].ToString();
  3624. if (ReleaseState == "1")
  3625. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  3626. else if (ReleaseState == "0")
  3627. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  3628. else
  3629. wheresql += " ";
  3630. }
  3631. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  3632. {
  3633. string selEnableShow = queryParam["selEnableShow"].ToString();
  3634. if (selEnableShow == "1")
  3635. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  3636. else if (selEnableShow == "0")
  3637. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  3638. }
  3639. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  3640. {
  3641. if (queryParam["selIsWH"].ToString() == "0")
  3642. {
  3643. wheresql += " and lotInfo.ID is null ";
  3644. }
  3645. if (queryParam["selIsWH"].ToString() == "1")
  3646. {
  3647. wheresql += " and lotInfo.ID is not null ";
  3648. }
  3649. }
  3650. }
  3651. wheresql += " " + DataActionsql;
  3652. sql = string.Format(sql, wheresql, WorkPoint);
  3653. //sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  3654. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  3655. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_22_1",
  3656. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_22'))
  3657. drop table #TempMOData_22
  3658. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_22_1'))
  3659. drop table #TempMOData_22_1 ",
  3660. "connstr", parameter.ToArray(), ref jqgridparam);
  3661. }
  3662. public DataTable GetICSInspection23(ref Pagination jqgridparam, string MenuID, string queryJson)
  3663. {
  3664. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  3665. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3666. DataTable dt = new DataTable();
  3667. var queryParam = queryJson.ToJObject();
  3668. List<DbParameter> parameter = new List<DbParameter>();
  3669. #region
  3670. string sql = @"
  3671. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_23'))
  3672. drop table #TempMOData_23
  3673. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_23_1'))
  3674. drop table #TempMOData_23_1
  3675. select
  3676. a.ID as DHID,
  3677. d.ID ,
  3678. h.ID as JYID,
  3679. a.RCVCode as DNCode ,
  3680. a.Sequence ,
  3681. c.InvCode ,
  3682. c.InvName ,
  3683. c.INVSTD ,
  3684. c.ClassName,
  3685. f.BatchCode ,
  3686. CAST(d.Quantity as NUMERIC(10,4)) as AllNumber,
  3687. CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  3688. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  3689. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  3690. CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity ,
  3691. c.InvUnit ,c.EATTRIBUTE3 as InvEATTRIBUTE3,
  3692. d.LotNo ,
  3693. g.BadReasonDesc as BadReasonDesc ,
  3694. g.BadReasonCode as BRCodeValue,
  3695. j.BadCode as BCCodeValue,
  3696. j.BadDesc as BadDesc,
  3697. k.ContainerID,
  3698. isnull(h.MUSERName,'') MUSERName,
  3699. CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime,
  3700. CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  3701. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  3702. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,c.InvIQC
  3703. into #TempMOData_23
  3704. FROM ICSOutsourcingReceive a
  3705. inner join ICSInventoryLotDetail e on e.TransCode =a.RCVCode AND e.TransSequence=a.Sequence AND e.WorkPoint=a.WorkPoint
  3706. inner JOIN ICSInventoryLot d ON d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint and d.type='23'
  3707. inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint --and c.InvIQC='1'
  3708. LEFT JOIN dbo.ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=d.WorkPoint
  3709. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  3710. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  3711. LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND d.WorkPoint=k.WorkPoint
  3712. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  3713. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  3714. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND d.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  3715. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  3716. where 1=1 {0} and a.workpoint='{1}'
  3717. select * into #TempMOData_23_1 from #TempMOData_23 where InvIQC='1'";
  3718. #endregion
  3719. string wheresql = "";
  3720. if (!string.IsNullOrWhiteSpace(queryJson))
  3721. {
  3722. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  3723. {
  3724. wheresql += " and a.RCVCode like '%" + queryParam["POCode"].ToString() + "%' ";
  3725. }
  3726. //if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
  3727. //{
  3728. // wheresql += " and a.OASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ";
  3729. //}
  3730. //if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString()))
  3731. //{
  3732. // wheresql += " and l.OOCode like '%" + queryParam["CaiGouCode"].ToString() + "%' ";
  3733. //}
  3734. //if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  3735. //{
  3736. // wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  3737. //}
  3738. //if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  3739. //{
  3740. // wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  3741. //}
  3742. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  3743. {
  3744. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  3745. }
  3746. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  3747. {
  3748. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  3749. }
  3750. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  3751. {
  3752. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  3753. }
  3754. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  3755. {
  3756. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  3757. }
  3758. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  3759. {
  3760. wheresql += " and d.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  3761. }
  3762. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  3763. {
  3764. if (queryParam["selIsWH"].ToString() == "0")
  3765. {
  3766. wheresql += " and lotInfo.ID is null ";
  3767. }
  3768. if (queryParam["selIsWH"].ToString() == "1")
  3769. {
  3770. wheresql += " and lotInfo.ID is not null ";
  3771. }
  3772. }
  3773. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  3774. {
  3775. string ReleaseState = queryParam["ReleaseState"].ToString();
  3776. if (ReleaseState == "1")
  3777. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  3778. else if (ReleaseState == "0")
  3779. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  3780. else
  3781. wheresql += " ";
  3782. }
  3783. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  3784. {
  3785. string selEnableShow = queryParam["selEnableShow"].ToString();
  3786. if (selEnableShow == "1")
  3787. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  3788. else if (selEnableShow == "0")
  3789. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  3790. }
  3791. }
  3792. wheresql += " " + DataActionsql;
  3793. sql = string.Format(sql, wheresql, WorkPoint);
  3794. //sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  3795. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  3796. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_23_1",
  3797. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_23'))
  3798. drop table #TempMOData_23
  3799. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_23_1'))
  3800. drop table #TempMOData_23_1 ",
  3801. "connstr", parameter.ToArray(), ref jqgridparam);
  3802. }
  3803. public DataTable GetInventoryInspectionNew(ref Pagination jqgridparam, string InvCode, int? SampleQuantity, string ResultINp, string JYID, string LotNo)
  3804. {
  3805. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3806. DataTable dt = new DataTable();
  3807. List<DbParameter> parameter = new List<DbParameter>();
  3808. string sql = string.Empty;
  3809. if (ResultINp == "")
  3810. {
  3811. sql += @" IF EXISTS (SELECT ID FROM ICSInspectionDetailGroup WHERE InspectionID='{3}' )
  3812. BEGIN
  3813. declare @sql varchar(8000)
  3814. select distinct b.ID,a.GroupCode,a.GroupName,e.EATTRIBUTE2,c.InspectionID,b.ListCode, c.UnqualifiedQuantity ,b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,d.SetValue,CASE WHEN c.Result='0' THEN '' when ISNULL(c.Result,'')='' THEN '' ELSE '' END AS Result,d.Sequence
  3815. into #TempSORRFQ
  3816. from ICSInventoryInspectionGroup a
  3817. left join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint
  3818. left join ICSInspectionDetailGroup c on b.ListCode=c.ListCode and a.GroupCode=c.GroupCode and b.WorkPoint=c.WorkPoint
  3819. left JOIN ICSInspectionDetail d ON c.ID=d.DetailGroupID AND c.WorkPoint=d.WorkPoint
  3820. left join ICSInspectionGroup e ON a.GroupCode=e.GroupCode and e.WorkPoint=a.WorkPoint
  3821. where a.InvCode='{0}' and b.Enable='1' and a.WorkPoint='{1}'and c.InspectionID='{3}'
  3822. If (SELECT top 1 Sequence FROM #TempSORRFQ) is not null
  3823. BEGIN
  3824. select @sql=isnull(@sql+',','')+' ['+Sequence+']'
  3825. from(select distinct Sequence from #TempSORRFQ)as a
  3826. set @sql='SELECT STUFF((select'','' + Sequence from (SELECT DISTINCT Sequence FROM #TempSORRFQ ) DD for xml path('''')),1,1,'''') as IsTou,*
  3827. FROM #TempSORRFQ PIVOT(MAX(SetValue) FOR Sequence IN ('+@sql+'))a '
  3828. exec(@sql);
  3829. END
  3830. ELSE
  3831. BEGIN
  3832. SELECT * FROM #TempSORRFQ
  3833. END
  3834. drop table #TempSORRFQ;
  3835. END
  3836. ELSE
  3837. BEGIN
  3838. select DISTINCT b.ID,a.GroupCode,a.GroupName,e.EATTRIBUTE2,d.ID as InspectionID,b.ListCode, c.UnqualifiedQuantity ,b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,d.SetValue,CASE WHEN c.Result='0' THEN '' when ISNULL(c.Result,'')='' THEN '' ELSE '' END AS Result
  3839. from ICSInventoryInspectionGroup a
  3840. left join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint
  3841. left join ICSInspectionDetailGroup c on b.ListCode=c.ListCode and a.GroupCode=c.GroupCode and b.WorkPoint=c.WorkPoint and c.InspectionID='{3}'
  3842. left JOIN ICSInspectionDetail d ON c.ID=d.DetailGroupID AND c.WorkPoint=d.WorkPoint
  3843. left join ICSInspectionGroup e ON a.GroupCode=e.GroupCode and e.WorkPoint=a.WorkPoint
  3844. where a.InvCode='{0}' and b.Enable='1' and a.WorkPoint='{1}'
  3845. END
  3846. ";
  3847. sql = string.Format(sql, InvCode, WorkPoint, JYID, LotNo);
  3848. return SqlHelper.CmdExecuteDataTable(sql);
  3849. }
  3850. else
  3851. {
  3852. sql += @" declare @sql varchar(8000)
  3853. select b.ID,a.GroupCode,a.GroupName,e.EATTRIBUTE2,c.InspectionID,b.ListCode, c.UnqualifiedQuantity ,b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,d.SetValue,CASE WHEN c.Result='0' THEN '' when ISNULL(c.Result,'')='' THEN '' ELSE '' END AS Result,d.Sequence
  3854. into #TempSORRFQ
  3855. from ICSInventoryInspectionGroup a
  3856. inner join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint
  3857. left join ICSInspectionDetailGroup c on b.ListCode=c.ListCode and a.GroupCode=c.GroupCode and b.WorkPoint=c.WorkPoint
  3858. left JOIN ICSInspectionDetail d ON c.ID=d.DetailGroupID AND c.WorkPoint=d.WorkPoint
  3859. left join ICSInspectionGroup e ON a.GroupCode=e.GroupCode and e.WorkPoint=a.WorkPoint
  3860. where a.InvCode='{0}' and b.Enable='1' and a.WorkPoint='{1}'and (c.InspectionID='{2}' or c.InspectionID='{3}')
  3861. If (SELECT top 1 Sequence FROM #TempSORRFQ) is not null
  3862. BEGIN
  3863. select @sql=isnull(@sql+',','')+' ['+Sequence+']'
  3864. from(select distinct Sequence from #TempSORRFQ)as a
  3865. set @sql='SELECT STUFF((select'','' + Sequence from (SELECT DISTINCT Sequence FROM #TempSORRFQ ) DD for xml path('''')),1,1,'''') as IsTou,*
  3866. FROM #TempSORRFQ PIVOT(MAX(SetValue) FOR Sequence IN ('+@sql+'))a '
  3867. exec(@sql)
  3868. END
  3869. ELSE
  3870. BEGIN
  3871. SELECT * FROM #TempSORRFQ
  3872. END
  3873. ";
  3874. sql = string.Format(sql, InvCode, WorkPoint, JYID, LotNo);
  3875. return SqlHelper.FindTablePageBySql_OtherTempSORRFQ(sql.ToString(), " " + "#TempSORRFQ" + " ", " drop table #TempSORRFQ", parameter.ToArray(), ref jqgridparam);
  3876. }
  3877. }
  3878. public DataTable GetRulesDetail(string LotNo)
  3879. {
  3880. DataTable dt = new DataTable();
  3881. //var queryParam = queryJson.ToJObject();
  3882. List<DbParameter> parameter = new List<DbParameter>();
  3883. string sql = string.Empty;
  3884. //增加pp子表查询 主要查询U8到货单数量
  3885. sql = @"select DISTINCT
  3886. CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) as SampleQuantity,
  3887. b.LotNo ,
  3888. b.Quantity,
  3889. '',
  3890. g.RulesCode,
  3891. g.InvCode,
  3892. c.InvStd,
  3893. c.InvName
  3894. FROM ICSDeliveryNotice a
  3895. inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  3896. inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint --and c.InvIQC='1'
  3897. inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  3898. left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  3899. LEFT JOIN dbo.ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint --and Enable='1'
  3900. LEFT JOIN ICSInventoryInspectionRulesGroup g ON c.InvCode=g.InvCode AND c.WorkPoint=g.WorkPoint
  3901. Where b.LotNo='" + LotNo + "'";
  3902. return Repository().FindTableBySql(sql.ToString());
  3903. }
  3904. /// <summary>
  3905. /// 检验保存
  3906. /// </summary>
  3907. /// <param name="ICSMTDOC"></param>
  3908. /// <param name="InvCode"></param>
  3909. /// <param name="ResultINp"></param>
  3910. /// <returns></returns>
  3911. public string SaveICSInspectionDetailNew(string ICSMTDOC, string InvCode, string JYID, string AllNumber, string YLOTQTY, string NLOTQTY, string WaiveQuantity, string BCCode, string BRCode, string ResultINp, string Lot, string Type, decimal CJQty)
  3912. {
  3913. string msg = "";
  3914. try
  3915. {
  3916. object CARID = Guid.NewGuid();
  3917. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  3918. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  3919. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3920. string sql = string.Empty;
  3921. JArray res = (JArray)JsonConvert.DeserializeObject(ICSMTDOC);
  3922. bool ISOK = false;
  3923. string ID = string.Empty;
  3924. if (string.IsNullOrEmpty(JYID) || JYID == "null")
  3925. {
  3926. sql += $@"
  3927. INSERT INTO dbo.ICSInspection ( ID ,LotNo,InvCode ,Quantity,QualifiedQuantity ,UnqualifiedQuantity,WaiveQuantity,BCCode,BRCode,Type,MTIME,MUSER ,MUSERName ,WorkPoint ,Enable,SampleQuantity)
  3928. Values('{CARID}','{Lot}','{InvCode}','{AllNumber}','{YLOTQTY}','{NLOTQTY}','{WaiveQuantity}','{BCCode}','{BRCode}','{Type}',getdate(),'{MUSER}','{MUSERNAME}','{WorkPoint}','1','{CJQty}')
  3929. ";
  3930. }
  3931. else
  3932. {
  3933. CARID = JYID;
  3934. }
  3935. foreach (var item in res)
  3936. {
  3937. string Guids = Guid.NewGuid().ToString();
  3938. JObject jo = (JObject)item;
  3939. JArray detailres = (JArray)JsonConvert.DeserializeObject(jo["LWFiledName"].ToString());
  3940. sql += @"
  3941. INSERT INTO dbo.ICSInspectionDetailGroup
  3942. ( ID ,InspectionID,ListCode ,ListName ,
  3943. Unit ,SetValueMax ,SetValueMin ,UnqualifiedQuantity ,Result, MUSER ,MUSERName ,MTIME, WorkPoint,GroupCode,GroupName)
  3944. values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',getdate(),'{11}','{12}','{13}')";
  3945. sql = string.Format(sql, Guids, CARID, jo["ListCode"].ToString(), jo["ListName"].ToString(), jo["Unit"].ToString(),
  3946. jo["SetValueMax"].ToString(), jo["SetValueMin"].ToString(), jo["SetValue"].ToString(), jo["Result"].ToString()
  3947. , MUSER, MUSERNAME, WorkPoint, jo["GroupCode"].ToString(), jo["GroupName"].ToString());
  3948. foreach (var itemdetail in detailres)
  3949. {
  3950. JObject jodetail = (JObject)itemdetail;
  3951. if (string.IsNullOrWhiteSpace(ResultINp))
  3952. {
  3953. sql += @"
  3954. INSERT INTO dbo.ICSInspectionDetail
  3955. ( ID ,DetailGroupID,Sequence ,SetValue ,Result, MUSER ,MUSERName ,MTIME, WorkPoint)
  3956. values(newid(),'{0}','{1}','{2}','{3}','{4}','{5}',getdate(),'{6}')";
  3957. sql = string.Format(sql, Guids, jodetail["FiledNamekey"].ToString(), jodetail["FiledNamevalue"].ToString(),
  3958. jo["Result"].ToString(),
  3959. MUSER, MUSERNAME, WorkPoint);
  3960. }
  3961. else
  3962. {
  3963. 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}',EATTRIBUTE1='{14}' where ID='{13}'";
  3964. sql = string.Format(sql, jodetail["InspectionID"].ToString(), jodetail["ListCode"].ToString(), jodetail["ListName"].ToString(), jodetail["Unit"].ToString(), jodetail["SetValueMax"].ToString(), jodetail["SetValueMin"].ToString(), jodetail["SetValue"].ToString(), jodetail["Result"].ToString(), MUSER, MUSERNAME, WorkPoint, jodetail["GroupCode"].ToString(), jodetail["GroupName"].ToString(), jodetail["ID"].ToString(), jodetail["NUM"].ToString());
  3965. }
  3966. if (jo["Result"].ToString() == "0")
  3967. {
  3968. ISOK = true;
  3969. }
  3970. }
  3971. ID = jo["InspectionID"].ToString();
  3972. }
  3973. if (ISOK == true)
  3974. {
  3975. sql += @" update ICSInspection set Result='{0}' where ID='{1}'";
  3976. sql = string.Format(sql, 0, CARID);
  3977. }
  3978. else
  3979. {
  3980. sql += @" update ICSInspection set Result='{0}' where ID='{1}'";
  3981. sql = string.Format(sql, 1, CARID);
  3982. }
  3983. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  3984. {
  3985. }
  3986. else
  3987. {
  3988. msg = "绑定失败";
  3989. }
  3990. }
  3991. catch (Exception ex)
  3992. {
  3993. msg = ex.Message;
  3994. }
  3995. return msg;
  3996. }
  3997. /// <summary>
  3998. /// 检验暂存
  3999. /// </summary>
  4000. /// <param name="ICSMTDOC"></param>
  4001. /// <param name="InvCode"></param>
  4002. /// <param name="ResultINp"></param>
  4003. /// <returns></returns>
  4004. public string StagingICSInspectionDetailNew(string ICSMTDOC, string InvCode, string JYID, string AllNumber, string YLOTQTY, string NLOTQTY, string WaiveQuantity, string BCCode, string BRCode, string ResultINp, string Lot, string Type, decimal CJQty)
  4005. {
  4006. string msg = "";
  4007. try
  4008. {
  4009. object CARID = Guid.NewGuid();
  4010. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  4011. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  4012. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4013. string sql = $@"IF EXISTS (SELECT ID FROM ICSInspectionDetailGroup WHERE InspectionID='{Lot}' or InspectionID='{JYID}' )
  4014. BEGIN
  4015. DELETE FROM ICSInspectionDetail WHERE DetailGroupID in (SELECT ID FROM ICSInspectionDetailGroup WHERE InspectionID='{Lot}' or InspectionID='{JYID}')
  4016. DELETE FROM ICSInspectionDetailGroup WHERE ID in (SELECT ID FROM ICSInspectionDetailGroup WHERE InspectionID='{Lot}' or InspectionID='{JYID}')
  4017. END;";
  4018. JArray res = (JArray)JsonConvert.DeserializeObject(ICSMTDOC);
  4019. bool ISOK = false;
  4020. string ID = string.Empty;
  4021. foreach (var item in res)
  4022. {
  4023. string Guids = Guid.NewGuid().ToString();
  4024. JObject jo = (JObject)item;
  4025. JArray detailres = (JArray)JsonConvert.DeserializeObject(jo["LWFiledName"].ToString());
  4026. sql += @"
  4027. INSERT INTO dbo.ICSInspectionDetailGroup
  4028. ( ID ,InspectionID,ListCode ,ListName ,
  4029. Unit ,SetValueMax ,SetValueMin ,UnqualifiedQuantity ,Result, MUSER ,MUSERName ,MTIME, WorkPoint,GroupCode,GroupName)
  4030. values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',getdate(),'{11}','{12}','{13}')";
  4031. sql = string.Format(sql, Guids, Lot, jo["ListCode"].ToString(), jo["ListName"].ToString(), jo["Unit"].ToString(),
  4032. jo["SetValueMax"].ToString(), jo["SetValueMin"].ToString(), jo["SetValue"].ToString(), jo["Result"].ToString()
  4033. , MUSER, MUSERNAME, WorkPoint, jo["GroupCode"].ToString(), jo["GroupName"].ToString());
  4034. foreach (var itemdetail in detailres)
  4035. {
  4036. JObject jodetail = (JObject)itemdetail;
  4037. sql += $@"
  4038. INSERT INTO dbo.ICSInspectionDetail
  4039. ( ID ,DetailGroupID,Sequence ,SetValue ,Result, MUSER ,MUSERName ,MTIME, WorkPoint)
  4040. values(newid(),'{Guids}','{jodetail["FiledNamekey"]}','{jodetail["FiledNamevalue"]}','{jo["Result"]}','{MUSER}','{MUSERNAME}',getdate(),'{WorkPoint}')";
  4041. var a = jo["Result"].ToString();
  4042. }
  4043. }
  4044. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  4045. {
  4046. }
  4047. else
  4048. {
  4049. msg = "操作失败";
  4050. }
  4051. }
  4052. catch (Exception ex)
  4053. {
  4054. msg = ex.Message;
  4055. }
  4056. return msg;
  4057. }
  4058. /// <summary>
  4059. /// 检验修改
  4060. /// </summary>
  4061. /// <param name="ICSMTDOC"></param>
  4062. /// <param name="InvCode"></param>
  4063. /// <param name="ResultINp"></param>
  4064. /// <returns></returns>
  4065. public string UpdateICSInspectionDetailNew(string ICSMTDOC, string JYID, string ResultINp)
  4066. {
  4067. string msg = "";
  4068. try
  4069. {
  4070. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  4071. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  4072. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4073. string sql = string.Empty;
  4074. JArray res = (JArray)JsonConvert.DeserializeObject(ICSMTDOC);
  4075. bool ISOK = false;
  4076. string ID = string.Empty;
  4077. sql = @"DELETE c from ICSInspection a
  4078. left join ICSInspectionDetailGroup b on a.ID = b.inspectionID and a.workPoint = b.workPoint
  4079. left join ICSInspectionDetail c on b.id = c.DetailGroupID and b.workPoint = c.workPoint
  4080. Where a.ID='" + JYID + "'";
  4081. sql += "DELETE ICSInspectionDetailGroup where inspectionID='" + JYID + "'";
  4082. foreach (var item in res)
  4083. {
  4084. string Guids = Guid.NewGuid().ToString();
  4085. JObject jo = (JObject)item;
  4086. JArray detailres = (JArray)JsonConvert.DeserializeObject(jo["LWFiledName"].ToString());
  4087. sql += @"
  4088. INSERT INTO dbo.ICSInspectionDetailGroup
  4089. ( ID ,InspectionID,ListCode ,ListName ,
  4090. Unit ,SetValueMax ,SetValueMin ,UnqualifiedQuantity ,Result, MUSER ,MUSERName ,MTIME, WorkPoint,GroupCode,GroupName)
  4091. values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',getdate(),'{11}','{12}','{13}')";
  4092. sql = string.Format(sql, Guids, jo["InspectionID"].ToString(), jo["ListCode"].ToString(), jo["ListName"].ToString(), jo["Unit"].ToString(),
  4093. jo["SetValueMax"].ToString(), jo["SetValueMin"].ToString(), jo["SetValue"].ToString(), jo["Result"].ToString()
  4094. , MUSER, MUSERNAME, WorkPoint, jo["GroupCode"].ToString(), jo["GroupName"].ToString());
  4095. foreach (var itemdetail in detailres)
  4096. {
  4097. JObject jodetail = (JObject)itemdetail;
  4098. //if (string.IsNullOrWhiteSpace(ResultINp))
  4099. //{
  4100. sql += @"
  4101. INSERT INTO dbo.ICSInspectionDetail
  4102. ( ID ,DetailGroupID,Sequence ,SetValue ,Result, MUSER ,MUSERName ,MTIME, WorkPoint)
  4103. values(newid(),'{0}','{1}','{2}','{3}','{4}','{5}',getdate(),'{6}')";
  4104. sql = string.Format(sql, Guids, jodetail["FiledNamekey"].ToString(), jodetail["FiledNamevalue"].ToString(),
  4105. jo["Result"].ToString(),
  4106. MUSER, MUSERNAME, WorkPoint);
  4107. //}
  4108. //else
  4109. //{
  4110. // 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}',EATTRIBUTE1='{14}' where ID='{13}'";
  4111. // sql = string.Format(sql, jodetail["InspectionID"].ToString(), jodetail["ListCode"].ToString(), jodetail["ListName"].ToString(), jodetail["Unit"].ToString(), jodetail["SetValueMax"].ToString(), jodetail["SetValueMin"].ToString(), jodetail["SetValue"].ToString(), jodetail["Result"].ToString(), MUSER, MUSERNAME, WorkPoint, jodetail["GroupCode"].ToString(), jodetail["GroupName"].ToString(), jodetail["ID"].ToString(), jodetail["NUM"].ToString());
  4112. //}
  4113. if (jo["Result"].ToString() == "0")
  4114. {
  4115. ISOK = true;
  4116. }
  4117. }
  4118. ID = jo["InspectionID"].ToString();
  4119. }
  4120. if (ISOK == true)
  4121. {
  4122. sql += @" update ICSInspection set Result='{0}' where ID='{1}'";
  4123. sql = string.Format(sql, 0, ID);
  4124. }
  4125. else
  4126. {
  4127. sql += @" update ICSInspection set Result='{0}' where ID='{1}'";
  4128. sql = string.Format(sql, 1, ID);
  4129. }
  4130. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  4131. {
  4132. }
  4133. else
  4134. {
  4135. msg = "绑定失败";
  4136. }
  4137. }
  4138. catch (Exception ex)
  4139. {
  4140. msg = ex.Message;
  4141. }
  4142. return msg;
  4143. }
  4144. public DataTable SelectSORRFQColumnName(string InvCode, string JYID, string LotNo)
  4145. {
  4146. string sql = string.Empty;
  4147. if (!string.IsNullOrEmpty(JYID) && JYID != "null")
  4148. {
  4149. sql = @"declare @sql varchar(8000)
  4150. SELECT d.Sequence,d.SetValue
  4151. into #Temp
  4152. from ICSInventoryInspectionGroup a
  4153. inner join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint
  4154. left join ICSInspectionDetailGroup c on b.ListCode=c.ListCode and a.GroupCode=c.GroupCode and b.WorkPoint=c.WorkPoint and (c.InspectionID='{1}' or c.InspectionID='{2}')
  4155. left JOIN ICSInspectionDetail d ON c.ID=d.DetailGroupID AND c.WorkPoint=d.WorkPoint
  4156. where a.InvCode='{0}' and b.Enable='1'
  4157. select distinct Sequence as ColCaption,Sequence as ColFiledName from #Temp
  4158. drop table #Temp";
  4159. }
  4160. else
  4161. {
  4162. sql = @"declare @sql varchar(8000)
  4163. SELECT d.Sequence,d.SetValue
  4164. into #Temp
  4165. from ICSInventoryInspectionGroup a
  4166. inner join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint
  4167. left join ICSInspectionDetailGroup c on b.ListCode=c.ListCode and a.GroupCode=c.GroupCode and b.WorkPoint=c.WorkPoint and c.InspectionID='{2}'
  4168. left JOIN ICSInspectionDetail d ON c.ID=d.DetailGroupID AND c.WorkPoint=d.WorkPoint
  4169. where a.InvCode='{0}' and b.Enable='1'
  4170. select distinct Sequence as ColCaption,Sequence as ColFiledName from #Temp
  4171. drop table #Temp";
  4172. }
  4173. sql = string.Format(sql, InvCode, JYID, LotNo);
  4174. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  4175. return dt;
  4176. }
  4177. public DataTable GetDeleteRulesDetail(string InvCode, string JYID)
  4178. {
  4179. DataTable dt = new DataTable();
  4180. //var queryParam = queryJson.ToJObject();
  4181. List<DbParameter> parameter = new List<DbParameter>();
  4182. string sql = string.Empty;
  4183. //增加pp子表查询 主要查询U8到货单数量
  4184. sql = @"
  4185. select a.ID as inspectionID,c.ID,a.lotNO,a.Invcode,c.SetValue from ICSInspection a
  4186. left join ICSInspectionDetailGroup b on a.ID=b.inspectionID and a.workPoint=b.workPoint
  4187. left join ICSInspectionDetail c on b.id=c.DetailGroupID and b.workPoint=c.workPoint
  4188. where a.id='{0}' and a.Invcode='{1}'";
  4189. sql = string.Format(sql, JYID, InvCode);
  4190. return Repository().FindTableBySql(sql.ToString());
  4191. }
  4192. public string DeleteICSInspection(string DetailID)
  4193. {
  4194. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  4195. string MUSERName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  4196. string sql = string.Empty;
  4197. sql = @"delete FROM ICSInspectionDetail where ID in ({0})";
  4198. sql = string.Format(sql, DetailID.TrimEnd(','));
  4199. string msg = "";
  4200. try
  4201. {
  4202. SqlHelper.ExecuteNonQuery(sql);
  4203. }
  4204. catch (Exception ex)
  4205. {
  4206. msg = ex.Message;
  4207. }
  4208. return msg;
  4209. }
  4210. /// <summary>
  4211. /// 数据导入
  4212. /// </summary>
  4213. /// <param name="savePath"></param>
  4214. /// <returns></returns>
  4215. public string SetData_PR(String savePath, string lotNo)
  4216. {
  4217. //数据获取
  4218. try
  4219. {
  4220. int index = 1;
  4221. string msg = "";
  4222. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  4223. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  4224. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4225. HomeWorkApp app = new HomeWorkApp();
  4226. SqlConnection conn = SqlHelper.GetDataCenterConn();
  4227. string sql = "";
  4228. int count = 0;
  4229. DataTable data = FileToExcel.ExcelToTable(savePath);
  4230. var colsMain = new List<string>();
  4231. var cols = new List<string>();
  4232. //循环获取实际值的个数
  4233. foreach (DataColumn item in data.Columns)
  4234. {
  4235. if (item.ColumnName.StartsWith("实际值"))
  4236. cols.Add(item.ColumnName);
  4237. else
  4238. colsMain.Add(item.ColumnName);
  4239. }
  4240. foreach (DataRow dr in data.Rows)
  4241. {
  4242. if (cols.Count <= 0)
  4243. {
  4244. throw new Exception("请填入实际值!");
  4245. }
  4246. index++;
  4247. //string GUID = Guid.NewGuid().ToString();
  4248. string groupCode = dr["检验项目组代码"].ToString().Trim();
  4249. string listCode = dr["检验项目代码"].ToString().Trim();
  4250. string groupName = dr["检验项目组名称"].ToString().Trim();
  4251. string unqualifiedQuantity = dr["不良数"].ToString().Trim();
  4252. string result = dr["结论"].ToString() == "不合格" ? "0" : "1";
  4253. string groupId = app.GetNewid();
  4254. sql += $@"IF NOT EXISTS(SELECT GroupCode FROM ICSInspectionGroup WHERE GroupCode='{groupCode}' and
  4255. WorkPoint='{WorkPoint}' )
  4256. BEGIN
  4257. RAISERROR('{index}:{groupCode}',16,1);
  4258. RETURN
  4259. end;
  4260. IF NOT EXISTS(SELECT ListCode FROM ICSInspectionList WHERE ListCode='{listCode}')
  4261. BEGIN
  4262. RAISERROR('{index}:{listCode}',16,1);
  4263. RETURN
  4264. end
  4265. INSERT INTO dbo.ICSInspectionDetailGroup
  4266. (ID, InspectionID, ListCode, ListName,
  4267. Unit, SetValueMax, SetValueMin, UnqualifiedQuantity, Result, MUSER, MUSERName, MTIME, WorkPoint, GroupCode, GroupName)
  4268. select '{groupId}','{lotNo}', ListCode, ListName, Unit, SetValueMax, SetValueMin,'{unqualifiedQuantity}', '{result}','{MUSER}', '{MUSERNAME}', getdate(), '{WorkPoint}', '{groupCode}', '{groupName}' FROM ICSInspectionList WHERE ListCode='{listCode}' ";
  4269. for (int i = 0; i < cols.Count; i++)
  4270. {
  4271. sql += $@" INSERT INTO dbo.ICSInspectionDetail
  4272. (ID, DetailGroupID, Sequence, SetValue, Result, MUSER, MUSERName, MTIME, WorkPoint)
  4273. values(newid(), '{groupId}', '{cols[i]}','{ dr[cols[i]]}', '{result}', '{MUSER}', '{MUSERNAME}', getdate(), '{WorkPoint}')";
  4274. }
  4275. }
  4276. count = SqlHelper.CmdExecuteNonQueryLi(sql);
  4277. if (count > 0)
  4278. {
  4279. msg = "导入成功";
  4280. }
  4281. else
  4282. {
  4283. return "无有效的导入数据。";
  4284. }
  4285. return msg;
  4286. }
  4287. catch (Exception ex)
  4288. {
  4289. return ex.Message;
  4290. }
  4291. }
  4292. /// <summary>
  4293. /// 红字销售出库单检验
  4294. /// </summary>
  4295. /// <param name="jqgridparam"></param>
  4296. /// <param name="MenuID"></param>
  4297. /// <param name="queryJson"></param>
  4298. /// <returns></returns>
  4299. public DataTable GetICSSSDInspection(ref Pagination jqgridparam, string MenuID, string queryJson)
  4300. {
  4301. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  4302. string ERPSign = Configs.GetValue("ERPSign");
  4303. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4304. DataTable dt = new DataTable();
  4305. var queryParam = queryJson.ToJObject();
  4306. List<DbParameter> parameter = new List<DbParameter>();
  4307. string sql = string.Empty;
  4308. sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1'))
  4309. drop table #TempLLData_1
  4310. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1'))
  4311. drop table #TempIcsinsp_1
  4312. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1_1'))
  4313. drop table #TempLLData_1_1
  4314. select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,SampleQuantity,
  4315. MUSERName,MTIME,Result,LotNo,BCCode,workpoint,BRCode
  4316. into #TempIcsinsp_1
  4317. from dbo.ICSInspection
  4318. where workpoint='" + WorkPoint + @"' and Enable='1'
  4319. select DISTINCT
  4320. a.ID as DHID,
  4321. d.ID ,
  4322. h.ID as JYID,
  4323. a.SSDCode ,
  4324. a.Sequence ,
  4325. c.InvCode ,
  4326. c.InvName ,
  4327. c.InvStd ,
  4328. c.ClassName,
  4329. c.EATTRIBUTE3 as InvEATTRIBUTE3,
  4330. CAST(d.Quantity as decimal(18,4)) as AllNumber,
  4331. CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as decimal(18,4))as YLOTQTY ,
  4332. CAST(ISNULL(h.UnqualifiedQuantity, 0) as decimal(18,4)) as NLOTQTY,
  4333. CAST(ISNULL(h.WaiveQuantity, 0) as decimal(18,4)) as SpecialQTY,
  4334. CASE WHEN isnull(task.ValueParameters,'') =''THEN '否' ELSE '是' END AS IsPrint,
  4335. -- CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) as SampleQuantity,
  4336. c.InvUnit ,
  4337. d.LotNo ,
  4338. g.BadReasonDesc as BadReasonDesc ,
  4339. g.BadReasonCode as BRCodeValue,
  4340. j.BadCode as BCCodeValue,
  4341. j.BadDesc as BadDesc,
  4342. k.ContainerID,
  4343. isnull(h.MUSERName,'') MUSERName,
  4344. CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime,
  4345. CONVERT(VARCHAR(100),a.CreateDateTime,120) as CreateDateTime,
  4346. CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  4347. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  4348. a.CusCode,a.CusName,
  4349. isnull(h.MUSERName,'') as Surveyor,
  4350. h.MTime as ProvingTime
  4351. ,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
  4352. ,CASE WHEN h.Result='0' THEN '' when ISNULL(h.Result,'')='' THEN '' ELSE '' END AS Result,
  4353. n.FileName
  4354. ,CASE WHEN isnull(h.ID,'') ='' and s.Type='Quantity' THEN isnull(p.SampleQuantity,0)
  4355. WHEN isnull(h.ID,'') ='' and s.Type='Ratio' THEN isnull(p.SampleQuantity,0)*a.Quantity ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity
  4356. ,o.Editable
  4357. ,(CASE ISNULL((SELECT COUNT(1) FROM dbo.ICSInspection hH2
  4358. WHERE hH2.LotNo=d.LotNo AND hH2.WorkPoint=a.WorkPoint),0)
  4359. WHEN 0 THEN '' WHEN 1 THEN '是' else '否' end ) IsFirstCK
  4360. , case d.EATTRIBUTE6 when '1' then '是' else '否' end IsUrgent,c.InvIQC
  4361. into #TempLLData_1
  4362. FROM ICSSSD a
  4363. --inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  4364. left join ICSInventoryLotDetail e on a.SSDCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint AND a.ID=e.TransID
  4365. inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint and c.InvIQC='1'
  4366. inner JOIN ICSInventoryLot d ON e.LotNo=d.LotNo AND a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint
  4367. LEFT JOIN #TempIcsinsp_1 h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint
  4368. LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID
  4369. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  4370. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  4371. LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND a.WorkPoint=k.WorkPoint
  4372. left join ICSExtension f on d.ExtensionID=f.ID and d.WorkPoint=f.WorkPoint
  4373. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  4374. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  4375. left JOIN ICSInspectionRulesGroup s ON o.RulesCode=s.RulesCode AND o.WorkPoint=s.WorkPoint
  4376. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND d.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  4377. where d.LotNo is not null and a.Type='2' AND a.Status='1' AND a.WorkPoint='{1}' {0}
  4378. select * into #TempLLData_1_1 from #TempLLData_1
  4379. ";
  4380. string wheresql = "";
  4381. if (!string.IsNullOrWhiteSpace(queryJson))
  4382. {
  4383. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  4384. {
  4385. wheresql += " and a.SSDCode like '%" + queryParam["POCode"].ToString() + "%' ";
  4386. }
  4387. if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
  4388. {
  4389. wheresql += " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ";
  4390. }
  4391. if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString()))
  4392. {
  4393. wheresql += " and l.POCode like '%" + queryParam["CaiGouCode"].ToString() + "%' ";
  4394. }
  4395. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  4396. {
  4397. wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  4398. }
  4399. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  4400. {
  4401. wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  4402. }
  4403. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4404. {
  4405. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  4406. }
  4407. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  4408. {
  4409. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  4410. }
  4411. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  4412. {
  4413. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  4414. }
  4415. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  4416. {
  4417. wheresql += " and a.CreateDateTime >= '" + queryParam["TimeFrom"].ToString() + "' ";
  4418. }
  4419. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  4420. {
  4421. wheresql += " and a.CreateDateTime <= '" + queryParam["TimeArrive"].ToString() + "' ";
  4422. }
  4423. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  4424. {
  4425. wheresql += " and b.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  4426. }
  4427. if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString()))
  4428. {
  4429. wheresql += " and case d.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' ";
  4430. }
  4431. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  4432. {
  4433. string ReleaseState = queryParam["ReleaseState"].ToString();
  4434. if (ReleaseState == "1")
  4435. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  4436. else if (ReleaseState == "0")
  4437. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  4438. else
  4439. wheresql += " ";
  4440. }
  4441. if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString()))
  4442. {
  4443. string printState = queryParam["selIsPrint"].ToString();
  4444. if (printState == "否")
  4445. wheresql += " and isnull(task.ValueParameters,'') ='' ";
  4446. else if (printState == "是")
  4447. wheresql += " and isnull(task.ValueParameters,'') <>''";
  4448. }
  4449. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  4450. {
  4451. string selEnableShow = queryParam["selEnableShow"].ToString();
  4452. if (selEnableShow == "1")
  4453. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  4454. else if (selEnableShow == "0")
  4455. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  4456. }
  4457. }
  4458. wheresql += " " + DataActionsql;
  4459. sql = string.Format(sql, wheresql, WorkPoint);
  4460. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempLLData_1_1",
  4461. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1'))
  4462. drop table #TempLLData_1
  4463. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1'))
  4464. drop table #TempIcsinsp_1
  4465. if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempLLData_1_1'))
  4466. drop table #TempLLData_1_1 ",
  4467. "connstr", parameter.ToArray(), ref jqgridparam);
  4468. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4469. }
  4470. /// <summary>
  4471. /// 海格工单子线检验
  4472. /// </summary>
  4473. /// <param name="jqgridparam"></param>
  4474. /// <param name="MenuID"></param>
  4475. /// <param name="queryJson"></param>
  4476. /// <returns></returns>
  4477. public DataTable GetICSInspection25(ref Pagination jqgridparam, string MenuID, string queryJson)
  4478. {
  4479. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  4480. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4481. DataTable dt = new DataTable();
  4482. var queryParam = queryJson.ToJObject();
  4483. List<DbParameter> parameter = new List<DbParameter>();
  4484. string sql = @"
  4485. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5'))
  4486. drop table #TempMOData_5
  4487. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5_1'))
  4488. drop table #TempMOData_5_1
  4489. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_5'))
  4490. drop table #TempIcsinsp_5
  4491. select ID,QualifiedQuantity,UnqualifiedQuantity,WaiveQuantity,
  4492. SampleQuantity,MUSERName,MTIME,Result,LotNo,BCCode,workpoint,EATTRIBUTE4 BRCodeValue1,BRCode,InvCode{2}
  4493. into #TempIcsinsp_5
  4494. from dbo.ICSInspection
  4495. where workpoint='" + WorkPoint + @"' and Enable='1'
  4496. SELECT DISTINCT h.BRCodeValue1,a.ID as GDID, a.ID , a.MOCode , a.Sequence , h.ID as JYID, c.InvCode , c.InvName , c.INVSTD , c.ClassName,
  4497. 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, a.Quantity as AllNumber, c.EATTRIBUTE3 as InvEATTRIBUTE3,
  4498. CAST(ISNULL(h.QualifiedQuantity,a.Quantity)as NUMERIC(10,4))as YLOTQTY ,
  4499. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as NLOTQTY,
  4500. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as SpecialQTY,
  4501. CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity ,
  4502. c.InvUnit , a.LotNo , g.BadReasonDesc as BadReasonDesc ,
  4503. g.BadReasonCode as BRCodeValue,
  4504. j.BadCode as BCCodeValue, j.BadDesc as BadDesc, i.ContainerID,
  4505. isnull(h.MUSERName,'') MUSERName, CONVERT(VARCHAR(100),a.ProductDate,120) as ProductTime,CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  4506. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  4507. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  4508. isnull(h.MUSERName,'') as Surveyor, h.MTime as ProvingTime
  4509. ,CASE WHEN h.Result='0' THEN '' when ISNULL(h.Result,'')='' THEN '' ELSE '' END AS Result,
  4510. n.FileName ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  4511. a.EATTRIBUTE9,a.EATTRIBUTE10,c.InvIQC
  4512. into #TempMOData_5
  4513. from ICSMOSubInventoryLot a
  4514. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1
  4515. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  4516. LEFT JOIN #TempIcsinsp_5 h ON h.LotNO=a.LotNO and h.InvCode=a.InvCode and h.WorkPoint=a.WorkPoint-- and Enable='1'
  4517. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  4518. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  4519. LEFT JOIN dbo.ICSContainerLot i ON a.LotNO=i.LotNO AND a.WorkPoint=i.WorkPoint
  4520. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  4521. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  4522. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND a.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  4523. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=a.LotNO AND lotInfo.WorkPoint=a.WorkPoint
  4524. where A.Workpoint='{1}' and c.ClassCode like 'P010%' {0}
  4525. select * into #TempMOData_5_1 from #TempMOData_5 where 1=1 ";
  4526. string wheresql = "";
  4527. if (!string.IsNullOrWhiteSpace(queryJson))
  4528. {
  4529. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  4530. {
  4531. wheresql += " and a.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  4532. }
  4533. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4534. {
  4535. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  4536. }
  4537. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  4538. {
  4539. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  4540. }
  4541. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  4542. {
  4543. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  4544. }
  4545. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  4546. {
  4547. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  4548. }
  4549. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  4550. {
  4551. wheresql += " and a.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  4552. }
  4553. if (!string.IsNullOrWhiteSpace(queryParam["FromTime"].ToString()))
  4554. {
  4555. wheresql += " and a.Mtime>= '" + queryParam["FromTime"].ToString() + "' ";
  4556. }
  4557. if (!string.IsNullOrWhiteSpace(queryParam["ToTime"].ToString()))
  4558. {
  4559. wheresql += " and a.Mtime< '" + queryParam["ToTime"].ToString() + "' ";
  4560. }
  4561. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  4562. {
  4563. string ReleaseState = queryParam["ReleaseState"].ToString();
  4564. if (ReleaseState == "1")
  4565. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  4566. else if (ReleaseState == "0")
  4567. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  4568. else
  4569. wheresql += " ";
  4570. }
  4571. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  4572. {
  4573. string selEnableShow = queryParam["selEnableShow"].ToString();
  4574. if (selEnableShow == "1")
  4575. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  4576. else if (selEnableShow == "0")
  4577. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  4578. }
  4579. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  4580. {
  4581. if (queryParam["selIsWH"].ToString() == "0")
  4582. {
  4583. wheresql += " and lotInfo.ID is null ";
  4584. }
  4585. if (queryParam["selIsWH"].ToString() == "1")
  4586. {
  4587. wheresql += " and lotInfo.ID is not null ";
  4588. }
  4589. }
  4590. }
  4591. wheresql += " " + DataActionsql;
  4592. //sql = string.Format(sql, wheresql, WorkPoint);
  4593. sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  4594. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  4595. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempMOData_5_1",
  4596. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5'))
  4597. drop table #TempMOData_5
  4598. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOData_5_1'))
  4599. drop table #TempMOData_5_1
  4600. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_5'))
  4601. drop table #TempIcsinsp_5 ",
  4602. "connstr", parameter.ToArray(), ref jqgridparam);
  4603. }
  4604. /// <summary>
  4605. /// 交期维护(咖博士)
  4606. /// </summary>
  4607. /// <param name="LeadModel"></param>
  4608. /// <returns></returns>
  4609. public string UpdateLeadTime(string LeadModel)
  4610. {
  4611. string msg = "";
  4612. try
  4613. {
  4614. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  4615. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  4616. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4617. string SendHost = "";
  4618. string SendPort = "";
  4619. string SendDisplayName = "";
  4620. string SendAddress = "";
  4621. string CusterJC = "";
  4622. string CusterQC = "";
  4623. string SendPassword = "";
  4624. JObject res = (JObject)JsonConvert.DeserializeObject(LeadModel);
  4625. var lot = res["LotNos"].ToString().TrimEnd(',');
  4626. string ID = string.Empty;
  4627. //获取邮箱信息
  4628. string sql = " SELECT F_ItemCode,F_Define1 FROM Sys_SRM_ItemsDetail WHERE F_ItemId='5f234982-69cc-4c64-9d1a-d43eef4e9ea0'";
  4629. DataTable itemdt = SqlHelper.GetDataTableBySql(sql);
  4630. if (itemdt.Rows.Count < 0)
  4631. {
  4632. throw new Exception("请先在自定义档案中配置发送人邮件信息");
  4633. }
  4634. else
  4635. {
  4636. for (int i = 0; i < itemdt.Rows.Count; i++)
  4637. {
  4638. if (itemdt.Rows[i]["F_ItemCode"].ToString() == "SendHost")
  4639. {
  4640. SendHost = itemdt.Rows[i]["F_Define1"].ToString();
  4641. }
  4642. else if (itemdt.Rows[i]["F_ItemCode"].ToString() == "SendPort")
  4643. {
  4644. SendPort = itemdt.Rows[i]["F_Define1"].ToString();
  4645. }
  4646. else if (itemdt.Rows[i]["F_ItemCode"].ToString() == "SendDisplayName")
  4647. {
  4648. SendDisplayName = itemdt.Rows[i]["F_Define1"].ToString();
  4649. }
  4650. else if (itemdt.Rows[i]["F_ItemCode"].ToString() == "SendAddress")
  4651. {
  4652. SendAddress = itemdt.Rows[i]["F_Define1"].ToString();
  4653. }
  4654. else if (itemdt.Rows[i]["F_ItemCode"].ToString() == "CusterJC")
  4655. {
  4656. CusterJC = itemdt.Rows[i]["F_Define1"].ToString();
  4657. }
  4658. else if (itemdt.Rows[i]["F_ItemCode"].ToString() == "CusterQC")
  4659. {
  4660. CusterQC = itemdt.Rows[i]["F_Define1"].ToString();
  4661. }
  4662. else if (itemdt.Rows[i]["F_ItemCode"].ToString() == "SendPassword")
  4663. {
  4664. SendPassword = itemdt.Rows[i]["F_Define1"].ToString();
  4665. }
  4666. }
  4667. }
  4668. sql = $@"UPDATE [dbo].[ICSDeliveryNotice] SET EATTRIBUTE3='{res["LeadTime"]}',EATTRIBUTE4='{res["User"]}' WHERE EATTRIBUTE1 in ({lot}) and DNType='3' ; ";
  4669. sql = $@"SELECT c.TransCode as POCode,d.VenAddress,d.VenName,d.VenEmail,a.VenCode,a.Quantity FROM ICSDeliveryNotice a
  4670. INNER join ICSInventoryLot b on a.EATTRIBUTE1=b.LotNo AND a.WorkPoint=b.WorkPoint
  4671. INNER JOIN ICSInventoryLotDetail c on b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  4672. INNER JOIN ICSVendor d ON a.VenCode=d.VenCode
  4673. WHERE a.DNType='3' AND a.EATTRIBUTE1 in ({lot})";
  4674. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  4675. SqlHelper.ExecuteWithTrans((dbConn, trans) =>
  4676. {
  4677. if (SqlHelper.ExecuteNonQuery(dbConn, trans, sql) == 0)
  4678. throw new Exception("修改数据失败");
  4679. int SendPorts = Convert.ToInt32(SendPort);
  4680. foreach (DataRow dr in dt.Rows)
  4681. {
  4682. string cVenCode = dr["VenCode"].ToString();
  4683. string TOAddress = GetVendorEmail(cVenCode).TrimEnd(',');
  4684. string CCAddress = "";
  4685. string Subject = "有来自" + CusterJC + "SRM平台新发布的采购订单信息";
  4686. bool isBodyHtml = false;
  4687. string VenName = dr["VenName"].ToString();
  4688. string POCode = dr["POCode"].ToString();
  4689. string NowDate = DateTime.Now.GetDateTimeFormats('D')[0].ToString();
  4690. string body = VenName + ":";
  4691. body += "\r\n";
  4692. body += " 您好!有来自" + CusterJC + "SRM新发布的拒收采购订单:" + POCode + " ,拒收数量为:" + dr["Quantity"].ToString() + ",请在交期" + res["LeadTime"].ToDate().GetDateTimeFormats('D')[0].ToString() + "前送货,可登陆基础SRM系统查看相关信息!";
  4693. body += "\r\n";
  4694. body += " 顺颂商祺!";
  4695. body += "\r\n";
  4696. body += " " + CusterQC + "";
  4697. body += "\r\n";
  4698. body += " " + NowDate;
  4699. string connection = FromMd5(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString);
  4700. ICSSendMail.SendEmail(connection, SendHost, SendPorts, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, isBodyHtml, body);
  4701. }
  4702. }, ex =>
  4703. {
  4704. msg = $"修改失败:{ex.Message}";
  4705. });
  4706. }
  4707. catch (Exception ex)
  4708. {
  4709. msg = ex.Message;
  4710. }
  4711. return msg;
  4712. }
  4713. /// <summary>
  4714. /// 填写快递单号,东辉使用
  4715. /// </summary>
  4716. /// <param name="LeadModel"></param>
  4717. /// <returns></returns>
  4718. public string UpdateTrackCode(string LeadModel)
  4719. {
  4720. string msg = "";
  4721. try
  4722. {
  4723. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  4724. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  4725. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4726. JObject res = (JObject)JsonConvert.DeserializeObject(LeadModel);
  4727. var ids = res["IDs"].ToString().TrimEnd(',');
  4728. var type = res["Type"].ToString();
  4729. string ID = string.Empty;
  4730. //根据类型判断是委外拒收还是采购拒收
  4731. var sql = $@"UPDATE [dbo].[ICSDeliveryNotice] SET EATTRIBUTE5='{res["TrackCode"]}',EATTRIBUTE6='{res["User"]}' WHERE ID in ({ids}) and DNType='3' ; ";
  4732. if (type == "2")
  4733. {
  4734. sql = $@"UPDATE [dbo].[ICSODeliveryNotice] SET EATTRIBUTE5='{res["TrackCode"]}',EATTRIBUTE6='{res["User"]}' WHERE ID in ({ids}) and ODNType='3' ; ";
  4735. }
  4736. int count = SqlHelper.CmdExecuteNonQuery(sql);
  4737. if (count <= 0)
  4738. {
  4739. msg = "更新失败";
  4740. }
  4741. }
  4742. catch (Exception ex)
  4743. {
  4744. msg = ex.Message;
  4745. }
  4746. return msg;
  4747. }
  4748. public string GetVendorEmail(string VenCode)
  4749. {
  4750. string sql = " SELECT F_Email FROM dbo.Sys_SRM_User WHERE F_VenCode='" + VenCode + "'";
  4751. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  4752. string Email = string.Empty;
  4753. foreach (DataRow dr in dt.Rows)
  4754. {
  4755. Email += dr["F_Email"].ToString() + ",";
  4756. }
  4757. return Email;
  4758. }
  4759. public static string FromMd5(string str)
  4760. {
  4761. //return str;
  4762. return Decrypt(str, "&%#@?,:*_");
  4763. }
  4764. /// <summary>
  4765. /// 解密
  4766. /// </summary>
  4767. /// <param name="strText"></param>
  4768. /// <param name="sDecrKey"></param>
  4769. /// <returns></returns>
  4770. private static String Decrypt(String strText, String sDecrKey)
  4771. {
  4772. Byte[] byKey = { };
  4773. Byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
  4774. Byte[] inputByteArray = new byte[strText.Length];
  4775. try
  4776. {
  4777. byKey = System.Text.Encoding.UTF8.GetBytes(sDecrKey.Substring(0, 8));
  4778. DESCryptoServiceProvider des = new DESCryptoServiceProvider();
  4779. inputByteArray = Convert.FromBase64String(strText);
  4780. MemoryStream ms = new MemoryStream();
  4781. CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV),
  4782. CryptoStreamMode.Write);
  4783. cs.Write(inputByteArray, 0, inputByteArray.Length);
  4784. cs.FlushFinalBlock();
  4785. System.Text.Encoding encoding = System.Text.Encoding.UTF8;
  4786. return encoding.GetString(ms.ToArray());
  4787. }
  4788. catch (Exception ex)
  4789. {
  4790. return ex.Message;
  4791. }
  4792. }
  4793. /// <summary>
  4794. /// 全部导出
  4795. /// <returns></returns>
  4796. public DataTable GetInspectionExport(string POCode, string VenCode, string VenName, string InvCode, string InvName, string InvStd, string BatchCode, string ReleaseState, string selEnableShow, string LotNO, string DocType, string Surveyor)
  4797. {
  4798. try
  4799. {
  4800. List<DbParameter> parameter = new List<DbParameter>();
  4801. string sql = @" select DISTINCT a.InspectCode as '检验单号',e.InvCode '料品编码',c.InvName '料品名称', c.INVSTD '规格型号' ,f.BatchCode '批次', d.LotNo '条码',
  4802. Case When a.Type=0 Then '' ELSE '' END AS '',
  4803. d.EATTRIBUTE1 AS '', g.Quantity-ISNULL(g.LockQuantity,0) as '',
  4804. Case When d.EATTRIBUTE1='' Then 0 Else d.InspectQuantity END as '' ,
  4805. Case When d.EATTRIBUTE1='' Then 0 Else Convert(decimal(18,4),d.Quantity)-Convert(decimal(18,4),d.InspectQuantity) END as '',L.BadDesc as '',K.BadReasonDesc as '',d.EATTRIBUTE10 AS '',CONVERT(VARCHAR(100),e.ProductDate,120) as '',CONVERT(varchar(100), e.ExpirationDate, 23) AS '',
  4806. Case When d.EATTRIBUTE1='' Then '' else isnull(d.MUSERName,'') end as '', d.MTIME as '',d.EATTRIBUTE11 AS '',i.ContainerID '',c.EATTRIBUTE3 ''
  4807. from ICSInspect a
  4808. inner join ICSInspectDetail d on d.InspectCode=a.InspectCode and d.WorkPoint=a.WorkPoint
  4809. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=d.LotNo AND e.WorkPoint=d.WorkPoint
  4810. LEFT JOIN dbo.ICSWareHouseLotInfo g ON g.LotNo=e.LotNo and g.WorkPoint=e.WorkPoint
  4811. inner JOIN dbo.ICSInventory c ON c.InvCode=e.InvCode AND c.WorkPoint=e.WorkPoint --and c.InvIQC='1'
  4812. left join ICSExtension f on f.ID=e.ExtensionID and f.WorkPoint=e.WorkPoint
  4813. LEFT JOIN dbo.ICSContainerLot i ON e.LotNO=i.LotNO AND e.WorkPoint=i.WorkPoint
  4814. LEFT JOIN DBO.ICSInspection J ON J.LotNo=D.LotNo AND J.EATTRIBUTE1=d.InspectCode AND J.WorkPoint=d.WorkPoint AND J.Enable=1
  4815. LEFT JOIN DBO.ICSBadReason K ON K.BadReasonCode=J.BRCode AND K.WorkPoint=J.WorkPoint
  4816. LEFT JOIN DBO.ICSBadCode L ON L.BadCode=J.BCCode AND L.WorkPoint=J.WorkPoint
  4817. where g.LotNO is not null {0} ";
  4818. string wheresql = "";
  4819. if (!string.IsNullOrWhiteSpace(POCode))
  4820. {
  4821. wheresql += " and a.InspectCode like '%" + POCode + "%' ";
  4822. }
  4823. if (!string.IsNullOrWhiteSpace(InvCode))
  4824. {
  4825. wheresql += " and e.InvCode like '%" + InvCode + "%' ";
  4826. }
  4827. if (!string.IsNullOrWhiteSpace(InvName))
  4828. {
  4829. wheresql += " and c.InvName like '%" + InvName + "%' ";
  4830. }
  4831. if (!string.IsNullOrWhiteSpace(InvStd))
  4832. {
  4833. wheresql += " and c.InvStd like '%" + InvStd + "%' ";
  4834. }
  4835. if (!string.IsNullOrWhiteSpace(BatchCode))
  4836. {
  4837. wheresql += " and f.BatchCode like '%" + BatchCode + "%' ";
  4838. }
  4839. if (!string.IsNullOrWhiteSpace(LotNO))
  4840. {
  4841. wheresql += " and d.LotNo like '%" + LotNO + "%' ";
  4842. }
  4843. if (!string.IsNullOrWhiteSpace(ReleaseState))
  4844. {
  4845. if (ReleaseState == "0")
  4846. wheresql += " and d.EATTRIBUTE1='未检验' ";
  4847. else if (ReleaseState == "1")
  4848. wheresql += " and d.EATTRIBUTE1='已检验'";
  4849. else if (ReleaseState == "3")
  4850. wheresql += " and d.EATTRIBUTE1='已审核'";
  4851. else if (ReleaseState == "4")
  4852. wheresql += " and d.EATTRIBUTE1='已复审'";
  4853. else
  4854. wheresql += " ";
  4855. }
  4856. if (!string.IsNullOrWhiteSpace(selEnableShow))
  4857. {
  4858. if (selEnableShow == "1")
  4859. wheresql += " and Convert(decimal(18,4),ISNULL(d.InspectQuantity,0))=Convert(decimal(18,4),ISNULL(d.Quantity,0))";
  4860. else if (selEnableShow == "0")
  4861. wheresql += " and Convert(decimal(18,4),ISNULL(d.InspectQuantity,0))!=Convert(decimal(18,4),ISNULL(d.Quantity,0))";
  4862. }
  4863. if (!string.IsNullOrWhiteSpace(Surveyor))
  4864. {
  4865. wheresql += " and d.MUSERName like '%" + Surveyor + "%' ";
  4866. }
  4867. if (!string.IsNullOrWhiteSpace(DocType))
  4868. {
  4869. ;
  4870. if (DocType == "0")
  4871. wheresql += " and a.Type=0 ";
  4872. else if (DocType == "1")
  4873. wheresql += " and a.Type!=0 ";
  4874. }
  4875. sql = string.Format(sql, wheresql);
  4876. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  4877. return dt;
  4878. }
  4879. catch (Exception ex)
  4880. {
  4881. throw new Exception(ex.Message);
  4882. }
  4883. }
  4884. /// <summary>
  4885. /// 全部导出
  4886. /// <returns></returns>
  4887. public DataTable GetInspectionExport25(string POCode, string VenCode, string VenName, string InvCode, string InvName, string InvStd, string BatchCode, string ReleaseState, string selEnableShow, string LotNO, string DocType, string Surveyor, string selIsWH, string FromTime, string ToTime)
  4888. {
  4889. try
  4890. {
  4891. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4892. List<DbParameter> parameter = new List<DbParameter>();
  4893. string sql = @" SELECT DISTINCT a.MOCode '工单号',f.BatchCode '批次', a.LotNo '条码', c.InvCode '料品编码', c.InvName '料品名称', c.INVSTD '规格型号', CONVERT(VARCHAR(100),a.ProductDate,120) as '生产时间', a.Quantity as '总数量',
  4894. CAST(ISNULL(h.QualifiedQuantity,a.Quantity)as NUMERIC(10,4))as '' ,
  4895. CAST(ISNULL(h.UnqualifiedQuantity, 0) as NUMERIC(10,4)) as '',
  4896. CAST(ISNULL(h.WaiveQuantity, 0) as NUMERIC(10,4)) as '',
  4897. CASE WHEN isnull(h.ID,'') ='' THEN isnull(p.SampleQuantity,0) ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS '' , case when Isnull(h.EATTRIBUTE4,'')='' then g.BadReasonDesc ELSE h.EATTRIBUTE4 END as '',
  4898. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS ''
  4899. ,CASE WHEN h.Result='0' THEN '' when ISNULL(h.Result,'')='' THEN '' ELSE '' END AS '',
  4900. isnull(h.MUSERName,'') as '', h.MTime as ''
  4901. ,mo.EATTRIBUTE6 as ''
  4902. from ICSMOSubInventoryLot a
  4903. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1
  4904. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  4905. LEFT JOIN ICSInspection h ON h.LotNO=a.LotNO and h.InvCode=a.InvCode and h.WorkPoint=a.WorkPoint and Enable='1'
  4906. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  4907. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  4908. LEFT JOIN dbo.ICSContainerLot i ON a.LotNO=i.LotNO AND a.WorkPoint=i.WorkPoint
  4909. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  4910. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  4911. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND a.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  4912. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=a.LotNO AND lotInfo.WorkPoint=a.WorkPoint
  4913. LEFT JOIN ICSMO mo ON mo.MOCode=a.MOCode AND a.InvCode=mo.InvCode AND a.WorkPoint=mo.WorkPoint
  4914. where A.Workpoint='{1}' {0} ";
  4915. string wheresql = "";
  4916. if (!string.IsNullOrWhiteSpace(POCode))
  4917. {
  4918. wheresql += " and a.MOCode like '%" + POCode + "%' ";
  4919. }
  4920. if (!string.IsNullOrWhiteSpace(InvCode))
  4921. {
  4922. wheresql += " and c.InvCode like '%" + InvCode + "%' ";
  4923. }
  4924. if (!string.IsNullOrWhiteSpace(InvName))
  4925. {
  4926. wheresql += " and c.InvName like '%" + InvName + "%' ";
  4927. }
  4928. if (!string.IsNullOrWhiteSpace(InvStd))
  4929. {
  4930. wheresql += " and c.InvStd like '%" + InvStd + "%' ";
  4931. }
  4932. if (!string.IsNullOrWhiteSpace(BatchCode))
  4933. {
  4934. wheresql += " and f.BatchCode like '%" + BatchCode + "%' ";
  4935. }
  4936. if (!string.IsNullOrWhiteSpace(LotNO))
  4937. {
  4938. wheresql += " and a.LotNo like '%" + LotNO + "%' ";
  4939. }
  4940. if (!string.IsNullOrWhiteSpace(FromTime))
  4941. {
  4942. wheresql += " and a.Mtime>= '" + FromTime + "' ";
  4943. }
  4944. if (!string.IsNullOrWhiteSpace(ToTime))
  4945. {
  4946. wheresql += " and a.Mtime< '" + ToTime + "' ";
  4947. }
  4948. if (!string.IsNullOrWhiteSpace(ReleaseState))
  4949. {
  4950. if (ReleaseState == "1")
  4951. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  4952. else if (ReleaseState == "0")
  4953. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  4954. else
  4955. wheresql += " ";
  4956. }
  4957. if (!string.IsNullOrWhiteSpace(selEnableShow))
  4958. {
  4959. if (selEnableShow == "1")
  4960. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  4961. else if (selEnableShow == "0")
  4962. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  4963. }
  4964. if (!string.IsNullOrWhiteSpace(selIsWH))
  4965. {
  4966. if (selIsWH == "0")
  4967. {
  4968. wheresql += " and lotInfo.ID is null ";
  4969. }
  4970. if (selIsWH == "1")
  4971. {
  4972. wheresql += " and lotInfo.ID is not null ";
  4973. }
  4974. }
  4975. sql = string.Format(sql, wheresql, WorkPoint);
  4976. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  4977. return dt;
  4978. }
  4979. catch (Exception ex)
  4980. {
  4981. throw new Exception(ex.Message);
  4982. }
  4983. }
  4984. }
  4985. }