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.

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