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

7695 lines
410 KiB

3 years ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using ICSSoft.Entity;
  4. using Newtonsoft.Json;
  5. using NFine.Code;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Data.SqlClient;
  10. using System.Linq;
  11. using System.Net.Http;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using static ICSSoft.Entity.LOTCreateIModel;
  15. namespace ICSSoft.DataProject
  16. {
  17. /// <summary>
  18. /// WMS条码信息
  19. /// </summary>
  20. public class WMSBarCoreService
  21. {
  22. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  23. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
  24. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  25. DataTable table = null;
  26. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  27. string sql = string.Empty;
  28. string sqlInfo = string.Empty;
  29. VerificationMethod verification = new VerificationMethod();
  30. #region 多语言
  31. /// <summary>
  32. /// 多语言查询
  33. /// </summary>
  34. /// <param name="JsonData"></param>
  35. /// <returns></returns>
  36. public List<WMSBarCoreModel> Get(WMSBarCoreModel JsonData)
  37. {
  38. conn.Open();
  39. SqlTransaction sqlTran = conn.BeginTransaction();
  40. SqlCommand cmd = new SqlCommand();
  41. cmd.Transaction = sqlTran;
  42. cmd.Connection = conn;
  43. try
  44. {
  45. sql = @"select cnValue AS Name,Code from Sys_Language where 1=1";
  46. if (!string.IsNullOrWhiteSpace(JsonData.Code))
  47. {
  48. sql += " and Code='{0}'";
  49. }
  50. sql = string.Format(sql, JsonData.Code);
  51. table = DBHelper.SQlReturnData(sql, cmd);
  52. string json = JsonConvert.SerializeObject(table);
  53. List<WMSBarCoreModel> model = JsonConvert.DeserializeObject<List<WMSBarCoreModel>>(json);
  54. cmd.Transaction.Commit();
  55. return model;
  56. }
  57. catch (Exception ex)
  58. {
  59. cmd.Transaction.Rollback();
  60. log.Error(ex.Message);
  61. throw new Exception(ex.Message);
  62. }
  63. finally
  64. {
  65. if (conn.State == ConnectionState.Open)
  66. {
  67. conn.Close();
  68. }
  69. conn.Dispose();
  70. }
  71. }
  72. #endregion
  73. #region 源头单据信息
  74. /// <summary>
  75. /// 源头单据信息
  76. /// </summary>
  77. /// <param name="JsonData"></param>
  78. /// <returns></returns>
  79. public object DocumentGet(WMSSourceDocumentModel JsonData)
  80. {
  81. conn.Open();
  82. SqlTransaction sqlTran = conn.BeginTransaction();
  83. SqlCommand cmd = new SqlCommand();
  84. cmd.Transaction = sqlTran;
  85. cmd.Connection = conn;
  86. string jsonInfo = null;
  87. int num = 0;
  88. try
  89. {
  90. sql = @"select * from {0} ";
  91. switch (JsonData.TransType )
  92. {
  93. case "送货单":
  94. string sqlInfoList = @"select * from ICSASNDetail where ASNCode='{0}' and WorkPoint='{1}'";
  95. sqlInfoList = string.Format(sqlInfoList, JsonData.TransCode, JsonData.WorkPoint);
  96. table = DBHelper.SQlReturnData(sqlInfoList, cmd);
  97. if (table.Rows.Count <= 0)
  98. {
  99. throw new Exception("源头单据不存在!");
  100. }
  101. else
  102. {
  103. sqlInfo += @" SELECT a.[ID],
  104. b.TransCode as TransCode ,
  105. c.ID as DetailID,
  106. b.TransSequence as TransSequence,
  107. c.InvCode as InvCode,
  108. d.InvName as InvName,
  109. d.InvStd as InvStd,
  110. a.[Quantity] as Quantity,
  111. d.InvUnit as InvUnit,
  112. a.Amount as Amount,
  113. d.AmountUnit as AmountUnit,
  114. c.ExtensionID as BatchCode,
  115. d.InvVersion as InvVersion,
  116. d.InvBrand as InvBrand,
  117. c.VenCode as cFree1,
  118. c.DepCode as cFree2,
  119. c.POCode as cFree3,
  120. c.UnitPrice as cFree4,
  121. c.Currency as cFree5,
  122. c.DepCode as cFree6,
  123. c.VenCode as cFree7,
  124. a.LotNo,
  125. a.ASNCode
  126. FROM {0} a
  127. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  128. left join ICSPurchaseOrder c on b.TransCode = c.POCode and b.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence
  129. left join ICSInventory d on c.InvCode = d.InvCode and c.WorkPoint=d.WorkPoint where 1 = 1 and a.ASNCode='{1}' and a.WorkPoint='{2}'";
  130. sqlInfo = string.Format(sqlInfo, TransTypeEnum.ICSASNDetail, JsonData.TransCode, JsonData.WorkPoint);
  131. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  132. jsonInfo = JsonConvert.SerializeObject(table);
  133. var modelInfo = JsonConvert.DeserializeObject(jsonInfo);
  134. return modelInfo;
  135. }
  136. case "委外送货单":
  137. sql = @"select
  138. a.ID,
  139. H.ContainerCODE,
  140. H.ContainerName,
  141. b.InvCode,
  142. F.InvName,
  143. F.InvStd,
  144. a.Quantity,
  145. F.InvUnit,
  146. F.AmountUnit,
  147. E.ProjectCode,
  148. E.BatchCode,
  149. E.Version,
  150. E.Brand,
  151. a.OASNCode as TransCode,--
  152. a.Sequence as TransSequence,--
  153. A.LotNo,
  154. E.cFree1,
  155. E.cFree2,
  156. E.cFree3,
  157. E.cFree4,
  158. E.cFree5,
  159. E.cFree6,
  160. E.cFree7,
  161. E.cFree8,
  162. E.cFree9,
  163. E.cFree10,
  164. o.VenCode,
  165. isnull((k.UnitPrice),0) as UnitPrice,
  166. isnull((k.Currency), ' ') as Currency,
  167. isnull((k.DepCode), ' ') as DepCode,
  168. isnull(( k.PersonCode), ' ') asPersonCode
  169. from ICSOASNDetail a
  170. left join ICSInventoryLot b on A.LotNo =B.LotNo
  171. LEFT JOIN ICSInventoryLotDetail c ON A.LotNo =c.LotNo
  172. LEFT JOIN ICSExtension E ON E.ID=b.ExtensionID
  173. LEFT JOIN ICSInventory F ON b.InvCode=F.InvCode
  174. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  175. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
  176. inner join ICSOASN O on o.OASNCode=a.OASNCode
  177. LEFT JOIN ICSOutsourcingOrder k on k.OOCode=TransCode and c.TransSequence=k.Sequence
  178. where 1 = 1 and a.OASNCode='{0}' and a.WorkPoint='{1}'";
  179. sql = string.Format(sql, JsonData.TransCode, JsonData.WorkPoint);
  180. table = DBHelper.SQlReturnData(sql, cmd);
  181. jsonInfo = JsonConvert.SerializeObject(table);
  182. var ReceiveTransq = JsonConvert.DeserializeObject(jsonInfo);
  183. return ReceiveTransq;
  184. case "一步式调拨单":
  185. string sqlkk = @"select * from ICSTransfer where TransferNO='{0}' and WorkPoint='{1}'";
  186. sqlkk = string.Format(sqlkk, JsonData.TransCode, JsonData.WorkPoint);
  187. DataTable dataDt = DBHelper.SQlReturnData(sqlkk, cmd);
  188. if (dataDt.Rows.Count <= 0)
  189. {
  190. throw new Exception("调拨单不存在");
  191. }
  192. else
  193. {
  194. sqlInfo = @"select
  195. a.ID as ID,
  196. a.TransferNO as TransCode,
  197. a.Sequence as TransSequence,
  198. a.InvCode as InvCode,
  199. c.InvName as InvName,
  200. c.InvStd as InvStd,
  201. a.Quantity as Quantity,
  202. c.InvUnit as InvUnit,
  203. a.Amount as Amount,
  204. c.AmountUnit as AmountUnit,
  205. a.ToWarehouseCode ,
  206. a.FromWarehouseCode,
  207. a.ToLocationCode as LocationCode,
  208. --f.WarehouseName as WHName,
  209. c.InvVersion as Version,
  210. c.InvBrand as Brand,
  211. a.TransferQuantity as IssueQuantity ,
  212. a.MUSER as MUSER,
  213. a.MTIME as MTime
  214. from ICSTransfer a --
  215. left join ICSExtension b on a.ExtensionID=b.id and a.WorkPoint=b.WorkPoint--
  216. left join ICSInventory c on c.InvCode=a.InvCode and c.WorkPoint=b.WorkPoint--y源头单据
  217. left join ICSWarehouse e on e.WarehouseCode =a.FromWarehouseCode and e.WorkPoint=a.WorkPoint
  218. where a.TransferNO='{0}' and a.WorkPoint='{1}'";
  219. sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
  220. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  221. jsonInfo = JsonConvert.SerializeObject(table);
  222. var ReceiveTrans = JsonConvert.DeserializeObject(jsonInfo);
  223. return ReceiveTrans;
  224. }
  225. case "委外订单备料表":
  226. sqlInfo = @"select
  227. a.ID as ID,
  228. a.OODetailID as TransCode,
  229. b.Sequence+'-'+a.Sequence as TransSequence,
  230. a.InvCode as InvCode,
  231. c.InvName as InvName,
  232. c.InvStd as InvStd,
  233. a.Quantity as Quantity,
  234. c.InvUnit as InvUnit,
  235. a.Amount as Amount,
  236. c.AmountUnit as AmountUnit,
  237. a.WHCode as WHCode,
  238. d.WarehouseName as WHName,
  239. c.InvVersion as Version,
  240. c.InvBrand as Brand,
  241. a.IssueQuantity ,
  242. a.MUSER as MUSER,
  243. a.MTIME as MTime
  244. from ICSOOPick a --
  245. left join ICSOutsourcingOrder b on a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  246. left join ICSInventory c on a.InvCode=c.InvCode AND a.WorkPoint=c.WorkPoint
  247. left join ICSWarehouse d on d.WarehouseCode =a.WHCode AND d.WorkPoint=a.WorkPoint
  248. where b.OOCode='{0}' and b.WorkPoint='{1}'";
  249. sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
  250. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  251. jsonInfo = JsonConvert.SerializeObject(table);
  252. var modelInfoList = JsonConvert.DeserializeObject(jsonInfo);
  253. return modelInfoList;
  254. case "委外领料申请单":
  255. sqlInfo = @"select
  256. a.ID as ID,
  257. c.TransCode as TransCode,
  258. c.TransSequence as TransSequence,
  259. a.InvCode as InvCode,
  260. e.InvName as InvName,
  261. e.InvStd as InvStd,
  262. a.Quantity as Quantity,
  263. e.InvUnit as InvUnit,
  264. a.Amount as Amount,
  265. e.AmountUnit as AmountUnit,
  266. a.WHCode as WHCode,
  267. f.WarehouseName as WHName,
  268. e.InvVersion as Version,
  269. e.InvBrand as Brand,
  270. a.IssueQuantity ,
  271. a.MUSER as MUSER,
  272. a.MTIME as MTime
  273. from {0} a --
  274. left join ICSInventoryLot b on a.ExtensionID=b.ExtensionID and a.WorkPoint=b.WorkPoint--
  275. left join ICSInventoryLotDetail c on c.LotNo=b.LotNo and c.WorkPoint=b.WorkPoint--y源头单据
  276. left join ICSInventory e on e.InvCode=a.InvCode and e.WorkPoint=a.WorkPoint--
  277. left join ICSWarehouse f on f.WarehouseCode =a.WHCode and f.WorkPoint=a.WorkPoint--
  278. where 1=1 and a.Status='2'";
  279. sqlInfo += " and a.ApplyCode='{1}' and a.WorkPoint='{2}'";
  280. sqlInfo = string.Format(sqlInfo, TransTypeEnum.ICSMOApply, JsonData.TransCode, JsonData.WorkPoint);
  281. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  282. jsonInfo = JsonConvert.SerializeObject(table);
  283. var Info = JsonConvert.DeserializeObject(jsonInfo);
  284. return Info;
  285. case "材料出库":
  286. sql = @"select
  287. a.ID as ID,
  288. c.TransCode as TransCode,
  289. c.TransSequence as TransSequence,
  290. a.InvCode as InvCode,
  291. e.InvName as InvName,
  292. e.InvStd as InvStd,
  293. a.Quantity as Quantity,
  294. e.InvUnit as InvUnit,
  295. a.Amount as Amount,
  296. e.AmountUnit as AmountUnit,
  297. a.WHCode as WHCode,
  298. f.WarehouseName as WHName,
  299. e.InvVersion as Version,
  300. e.InvBrand as Brand,
  301. a.IssueQuantity as IssueQuantity ,
  302. a.MUSER as MUSER,
  303. a.MTIME as MTime,
  304. a.Status
  305. from ICSMOIssue a --
  306. left join ICSInventoryLot b on a.ExtensionID=b.ExtensionID and a.WorkPoint=b.WorkPoint--
  307. left join ICSInventoryLotDetail c on c.LotNo=b.LotNo and c.WorkPoint=b.WorkPoint--y源头单据
  308. left join ICSInventory e on e.InvCode=a.InvCode and e.WorkPoint=a.WorkPoint--
  309. left join ICSWarehouse f on f.WarehouseCode =a.WHCode and f.WorkPoint=a.WorkPoint
  310. where a.Status='2' and a.SDNCode='{1}' and a.WorkPoint='{2}'";
  311. sql = string.Format(sql, JsonData.TransCode, JsonData.WorkPoint);
  312. table = DBHelper.SQlReturnData(sql, cmd);
  313. jsonInfo = JsonConvert.SerializeObject(table);
  314. var Issue = JsonConvert.DeserializeObject(jsonInfo);
  315. return Issue;
  316. case "销售发货":
  317. sql = @"select
  318. a.ID as ID,
  319. a.SDNCode as TransCode,
  320. b.ID as DetailID ,
  321. a.Sequence as TransSequence,
  322. b.InvCode as InvCode,
  323. b.InvName as InvName,
  324. b.InvStd as InvStd,
  325. a.Quantity as Quantity,
  326. b.InvUnit as InvUnit,
  327. a.Amount as Amount,
  328. a.SDNQuantity as IssueQuantity,
  329. b.AmountUnit,
  330. d.WarehouseCode as WHCode,
  331. d.WarehouseName as WHName,
  332. c.ProjectCode,
  333. c.BatchCode,
  334. c.Version,
  335. c.Brand,
  336. c.cFree1,
  337. c.cFree2,
  338. c.cFree3,
  339. c.cFree4,
  340. c.cFree5,
  341. c.cFree6,
  342. c.cFree7,
  343. c.cFree8,
  344. c.cFree9,
  345. c.cFree10,
  346. a.Type,
  347. a.MUSER,
  348. a.MTIME as MTime
  349. from ICSSDN a
  350. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  351. left join ICSExtension c on c.ID=a.ExtensionID and c.WorkPoint=a.WorkPoint
  352. left join ICSWarehouse d on d.WarehouseCode=a.WHCode and d.WorkPoint=a.WorkPoint
  353. WHERE type ='1' ";
  354. sql += " and a.SDNCode='{0}' and a.WorkPoint='{1}'";
  355. sql = string.Format(sql, JsonData.TransCode, JsonData.WorkPoint);
  356. table = DBHelper.SQlReturnData(sql, cmd);
  357. jsonInfo = JsonConvert.SerializeObject(table);
  358. var ICSSDN = JsonConvert.DeserializeObject(jsonInfo);
  359. return ICSSDN;
  360. case "生产订单备料表":
  361. sql = @"select
  362. a.ID as ID,
  363. d.MOCode as TransCode,
  364. d.MODetailID as IDDetailID,
  365. d.Sequence+'-'+a.Sequence as TransSequence,
  366. a.InvCode as InvCode,
  367. e.InvName as InvName,
  368. e.InvStd as InvStd,
  369. a.Quantity as Quantity,
  370. e.InvUnit as InvUnit,
  371. isnull((a.Amount),0)as Amount,
  372. e.AmountUnit as AmountUnit,
  373. a.WHCode as WHCode,
  374. f.WarehouseName as WHName,
  375. e.InvVersion as Version,
  376. e.InvBrand as Brand,
  377. isnull((a.IssueQuantity),0)as IssueQuantity,
  378. a.MUSER as MUSER,
  379. a.MTIME as MTime,
  380. a.WorkPoint,
  381. a.Sequence
  382. from {0} a --
  383. INNER JOIN ICSMO d on d.id=a.MODetailID and d.WorkPoint=a.WorkPoint--
  384. INNER JOIN ICSInventory e on e.InvCode=d.InvCode and e.WorkPoint=a.WorkPoint--
  385. LEFT JOIN ICSWarehouse f on f.WarehouseCode =a.WHCode and f.WorkPoint=a.WorkPoint--
  386. where 1=1 ";
  387. sql += " and d.MOCode='{1}' and a.WorkPoint='{2}'";
  388. sql = string.Format(sql, TransTypeEnum.ICSMOPick, JsonData.TransCode, JsonData.WorkPoint);
  389. table = DBHelper.SQlReturnData(sql, cmd);
  390. jsonInfo = JsonConvert.SerializeObject(table);
  391. var MOPic = JsonConvert.DeserializeObject(jsonInfo);
  392. return MOPic;
  393. case "委外材料出库":
  394. sqlInfo = @"select
  395. a.ID as ID,
  396. c.TransCode as TransCode,
  397. c.TransSequence as TransSequence,
  398. a.InvCode as InvCode,
  399. e.InvName as InvName,
  400. e.InvStd as InvStd,
  401. a.Quantity as Quantity,
  402. e.InvUnit as InvUnit,
  403. a.Amount as Amount,
  404. e.AmountUnit as AmountUnit,
  405. a.WHCode as WHCode,
  406. f.WarehouseName as WHName,
  407. e.InvVersion as Version,
  408. e.InvBrand as Brand,
  409. a.IssueQuantity ,
  410. a.MUSER as MUSER,
  411. a.MTIME as MTime
  412. from {0} a --
  413. left join ICSInventoryLot b on a.ExtensionID=b.ExtensionID and a.WorkPoint=b.WorkPoint--
  414. left join ICSInventoryLotDetail c on c.LotNo=b.LotNo and c.WorkPoint=b.WorkPoint--y源头单据
  415. left join ICSInventory e on e.InvCode=a.InvCode and e.WorkPoint=a.WorkPoint--
  416. left join ICSWarehouse f on f.WarehouseCode =a.WHCode and f.WorkPoint=a.WorkPoint--
  417. where 1=1 and a.Status='2'";
  418. sqlInfo += " and a.IssueCode='{1}' and a.WorkPoint='{2}'";
  419. sqlInfo = string.Format(sqlInfo, TransTypeEnum.ICSOIssue, JsonData.TransCode, JsonData.WorkPoint);
  420. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  421. jsonInfo = JsonConvert.SerializeObject(table);
  422. //sqlInfo = string.Format(sqlInfo, Type.ICSMOApply, JsonData.TransCode);
  423. var ICSOIssue = JsonConvert.DeserializeObject(jsonInfo);
  424. return ICSOIssue;
  425. case "杂发单":
  426. sql = @"select
  427. a.ID as ID,
  428. c.TransCode as TransCode,
  429. c.TransSequence as TransSequence,
  430. a.InvCode as InvCode,
  431. e.InvName as InvName,
  432. e.InvStd as InvStd,
  433. a.Quantity as Quantity,
  434. e.InvUnit as InvUnit,
  435. a.Amount as Amount,
  436. e.AmountUnit as AmountUnit,
  437. a.WHCode as WHCode,
  438. f.WarehouseName as WHName,
  439. e.InvVersion as Version,
  440. e.InvBrand as Brand,
  441. a.OutQuantity as IssueQuantity ,
  442. a.MUSER as MUSER,
  443. a.MTIME as MTime
  444. from ICSOtherOut a --
  445. left join ICSInventoryLot b on a.ExtensionID=b.ExtensionID and a.WorkPoint=b.WorkPoint--
  446. left join ICSInventoryLotDetail c on c.LotNo=b.LotNo and c.WorkPoint=b.WorkPoint--y源头单据
  447. left join ICSInventory e on e.InvCode=a.InvCode and e.WorkPoint=a.WorkPoint--
  448. left join ICSWarehouse f on f.WarehouseCode =a.WHCode and f.WorkPoint=a.WorkPoint
  449. where a.Status='2' and a.OutCode='{0}' and a.WorkPoint='{1}'";
  450. sql = string.Format(sql, JsonData.TransCode, JsonData.WorkPoint);
  451. table = DBHelper.SQlReturnData(sql, cmd);
  452. jsonInfo = JsonConvert.SerializeObject(table);
  453. //sqlInfo = string.Format(sqlInfo, Type.ICSMOApply, JsonData.TransCode);
  454. var ItherOut = JsonConvert.DeserializeObject(jsonInfo);
  455. return ItherOut;
  456. case "采购退货单":
  457. sqlInfo += @"select a.ID,
  458. a.InvCode,
  459. C.InvName,
  460. C.InvStd,
  461. a.Quantity ,
  462. C.InvUnit,
  463. a.Amount AS AmountUnit,
  464. --l.WarehouseCode,
  465. --l.WarehouseName,
  466. --j.LocationCode,
  467. --j.LocationName,
  468. a.RCVQuantity as IssueQuantity,
  469. a.Sequence as TransSequence,
  470. b.ProjectCode,
  471. b.BatchCode,
  472. b.Version,
  473. b.Brand,
  474. b.cFree1,
  475. b.cFree2,
  476. b.cFree3,
  477. b.cFree4,
  478. b.cFree5,
  479. b.cFree6,
  480. b.cFree7,
  481. b.cFree8,
  482. b.cFree9,
  483. b.cFree10
  484. from ICSDeliveryNotice a
  485. left join ICSExtension b on a.ExtensionID=b.ID
  486. LEFT JOIN ICSInventory C ON A.InvCode =C.InvCode where 1 = 1 ";
  487. sqlInfo += " and A.DNType='2' AND a.dncode='{0}' and A.WorkPoint='{1}'";
  488. sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
  489. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  490. jsonInfo = JsonConvert.SerializeObject(table);
  491. var Receive = JsonConvert.DeserializeObject(jsonInfo);
  492. return Receive;
  493. case "委外红字入库单":
  494. sql += " and a.RCVCode='{1}' and Type=2";
  495. sql = string.Format(sql, TransTypeEnum.ICSOutsourcingReceive, JsonData.TransCode);
  496. break;
  497. case "销售退货":
  498. sqlInfo = @"select
  499. a.ID as ID,
  500. a.SDNCode as TransCode,
  501. b.ID as DetailID ,
  502. a.Sequence as TransSequence,
  503. b.InvCode as InvCode,
  504. b.InvName as InvName,
  505. b.InvStd as InvStd,
  506. a.Quantity as Quantity,
  507. b.InvUnit as InvUnit,
  508. a.Amount as Amount,
  509. a.SDNQuantity as IssueQuantity,
  510. b.AmountUnit,
  511. d.WarehouseCode as WHCode,
  512. d.WarehouseName as WHName,
  513. c.ProjectCode,
  514. c.BatchCode,
  515. c.Version,
  516. c.Brand,
  517. c.cFree1,
  518. c.cFree2,
  519. c.cFree3,
  520. c.cFree4,
  521. c.cFree5,
  522. c.cFree6,
  523. c.cFree7,
  524. c.cFree8,
  525. c.cFree9,
  526. c.cFree10,
  527. a.Type,
  528. a.MUSER,
  529. a.MTIME as MTime
  530. from {0} a
  531. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  532. left join ICSExtension c on c.ID=a.ExtensionID and c.WorkPoint=a.WorkPoint
  533. left join ICSWarehouse d on d.WarehouseCode=a.WHCode and d.WorkPoint=a.WorkPoint
  534. WHERE type ='2' ";
  535. sqlInfo += " and a.SDNCode='{1}' and a.WorkPoint='{2}'";
  536. sqlInfo = string.Format(sqlInfo, TransTypeEnum.ICSSDN, JsonData.TransCode, JsonData.WorkPoint);
  537. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  538. jsonInfo = JsonConvert.SerializeObject(table);
  539. var ICSSDNInfo = JsonConvert.DeserializeObject(jsonInfo);
  540. return ICSSDNInfo;
  541. case "两步式调拨单":
  542. sql = @"select
  543. a.ID as ID,
  544. c.TransCode as TransCode,
  545. c.TransSequence as TransSequence,
  546. a.InvCode as InvCode,
  547. e.InvName as InvName,
  548. e.InvStd as InvStd,
  549. a.Quantity as Quantity,
  550. e.InvUnit as InvUnit,
  551. a.Amount as Amount,
  552. e.AmountUnit as AmountUnit,
  553. a.FromWarehouseCode as WHCode,
  554. f.WarehouseName as WHName,
  555. e.InvVersion as Version,
  556. e.InvBrand as Brand,
  557. a.TransferQuantity as IssueQuantity ,
  558. a.MUSER as MUSER,
  559. a.MTIME as MTime
  560. from ICSTransfer a --
  561. left join ICSInventoryLot b on a.ExtensionID=b.ExtensionID and a.WorkPoint=b.WorkPoint--
  562. left join ICSInventoryLotDetail c on c.LotNo=b.LotNo and c.WorkPoint=b.WorkPoint--y源头单据
  563. left join ICSInventory e on e.InvCode=a.InvCode and e.WorkPoint=a.WorkPoint--
  564. left join ICSWarehouse f on f.WarehouseCode =a.FromWarehouseCode and f.WorkPoint=a.WorkPoint";
  565. sql += " and a.TransferNO='{0}' and Type=2 and a.WorkPoint='{1}'";
  566. sql = string.Format(sql, JsonData.TransCode, JsonData.WorkPoint);
  567. break;
  568. case "采购红字入库单":
  569. sql = @"SELECT
  570. a.[ID],
  571. b.TransCode as TransCode ,
  572. c.ID as DetailID,
  573. b.TransSequence as TransSequence,
  574. c.InvCode as InvCode,
  575. d.InvName as InvName,
  576. d.InvStd as InvStd,
  577. a.[Quantity] as Quantity,
  578. d.InvUnit as InvUnit,
  579. a.Amount as Amount,
  580. d.AmountUnit as AmountUnit,
  581. c.ExtensionID as BatchCode,
  582. d.InvVersion as InvVersion,
  583. d.InvBrand as InvBrand,
  584. c.VenCode as cFree1,
  585. c.DepCode as cFree2,
  586. c.POCode as cFree3,
  587. c.UnitPrice as cFree4,
  588. c.Currency as cFree5,
  589. c.DepCode as cFree6,
  590. c.VenCode as cFree7,
  591. b.LotNo,a.RCVQuantity as IssueQuantity
  592. FROM {0} a
  593. left join ICSInventoryLotDetail b on a.SourceCode = b.TransCode and a.WorkPoint=b.WorkPoint
  594. left join ICSPurchaseOrder c on b.TransCode = c.POCode and b.WorkPoint=c.WorkPoint
  595. left join ICSInventory d on c.InvCode = d.InvCode and c.WorkPoint=d.WorkPoint where 1 = 1 and a.Status = '2' and a.type = ''";
  596. sql += " and a.RCVCode='{1}' and a.WorkPoint='{2}'";
  597. sql = string.Format(sql, TransTypeEnum.ICSPurchaseReceive, JsonData.TransCode);
  598. break;
  599. case "委外退货单":
  600. sqlInfo = @" SELECT
  601. a.[ID],--
  602. a.ODNCode as TransCode ,--
  603. --c.ID as DetailID,--
  604. a.Sequence as TransSequence,--
  605. a.InvCode as InvCode ,--
  606. b.InvName as InvName,
  607. b.InvStd as InvStd,
  608. a.[Quantity] as Quantity,
  609. b.InvUnit as InvUnit,
  610. a.Amount as Amount,
  611. b.AmountUnit as AmountUnit,
  612. c.ProjectCode as ProjectCode,
  613. c.BatchCode as BatchCode,
  614. c.Version as Version,
  615. c.Brand as Brand,
  616. a.RCVQuantity as IssueQuantity,
  617. c.cFree1,
  618. c.cFree2,
  619. c.cFree3,
  620. c.cFree4,
  621. c.cFree5,
  622. c.cFree6,
  623. c.cFree7,
  624. c.cFree8,
  625. c.cFree9,
  626. c.cFree10
  627. FROM ICSODeliveryNotice a --退
  628. LEFT JOIN ICSInventory B ON A.InvCode=B.InvCode and a.WorkPoint=b.WorkPoint--
  629. LEFT JOIN ICSExtension C ON A.ExtensionID=C.ID and a.WorkPoint=c.WorkPoint--
  630. where a.ODNType='2' and a.ODNCode='{0}' and a.WorkPoint='{1}'";
  631. sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
  632. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  633. jsonInfo = JsonConvert.SerializeObject(table);
  634. var Notice = JsonConvert.DeserializeObject(jsonInfo);
  635. return Notice;
  636. case "盘点":
  637. bool ischeck = verification.isCheck(JsonData.TransCode, JsonData.WorkPoint);
  638. if (ischeck == true)
  639. {
  640. sqlInfo = @"SELECT
  641. a.[ID],--
  642. f.CheckCode as TransCode ,--
  643. --c.ID as DetailID,--
  644. e.TransCode as TransSequence,--
  645. f.InvCode as InvCode ,--
  646. b.InvName as InvName,
  647. b.InvStd as InvStd,
  648. a.[Quantity] as Quantity,
  649. b.InvUnit as InvUnit,
  650. f.Amount as Amount,
  651. b.AmountUnit as AmountUnit,
  652. d.ProjectCode as ProjectCode,
  653. d.BatchCode as BatchCode,
  654. d.Version as Version,
  655. d.Brand as Brand,
  656. f.ActualQuantity as IssueQuantity,
  657. d.cFree2,
  658. d.cFree3,
  659. d.cFree4,
  660. d.cFree5,
  661. d.cFree6,
  662. d.cFree7,
  663. d.cFree8,
  664. d.cFree9,
  665. d.cFree10
  666. FROM ICSWareHouseLotInfo a
  667. left join ICSCheck f on f.WHCode=a.WarehouseCode and a.InvCode=f.InvCode
  668. LEFT JOIN ICSInventory B ON f.InvCode=B.InvCode and a.WorkPoint=b.WorkPoint--
  669. left join ICSInventoryLot c on c.lotno=a.lotno and a.WorkPoint=c.WorkPoint
  670. LEFT JOIN ICSExtension d ON c.ExtensionID=d.ID and a.WorkPoint=c.WorkPoint--
  671. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  672. where f.CheckCode='{0}' and a.WorkPoint='{1}' ";
  673. sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
  674. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  675. jsonInfo = JsonConvert.SerializeObject(table);
  676. var Noticec = JsonConvert.DeserializeObject(jsonInfo);
  677. return Noticec;
  678. }
  679. return false;
  680. case "其它出库":
  681. bool ischecks = verification.IsOtherOut(JsonData.TransCode, JsonData.WorkPoint);
  682. if (ischecks == true)
  683. {
  684. sqlInfo = @"SELECT
  685. a.[ID],--
  686. f.OutCode as TransCode ,--
  687. --c.ID as DetailID,--
  688. f.Sequence as TransSequence,--
  689. f.InvCode as InvCode ,--
  690. b.InvName as InvName,
  691. b.InvStd as InvStd,
  692. a.[Quantity] as Quantity,
  693. b.InvUnit as InvUnit,
  694. f.Amount as Amount,
  695. b.AmountUnit as AmountUnit,
  696. d.ProjectCode as ProjectCode,
  697. d.BatchCode as BatchCode,
  698. d.Version as Version,
  699. d.Brand as Brand,
  700. f.OutQuantity as IssueQuantity,
  701. d.cFree2,
  702. d.cFree3,
  703. d.cFree4,
  704. d.cFree5,
  705. d.cFree6,
  706. d.cFree7,
  707. d.cFree8,
  708. d.cFree9,
  709. d.cFree10
  710. FROM ICSWareHouseLotInfo a
  711. left join ICSOtherOut f on f.WHCode=a.WarehouseCode and a.InvCode=f.InvCode
  712. LEFT JOIN ICSInventory B ON f.InvCode=B.InvCode and a.WorkPoint=b.WorkPoint--
  713. left join ICSInventoryLot c on c.lotno=a.lotno and a.WorkPoint=c.WorkPoint
  714. LEFT JOIN ICSExtension d ON c.ExtensionID=d.ID and a.WorkPoint=c.WorkPoint--
  715. where f.OutCode='{0}' and a.WorkPoint='{1}' ";
  716. sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
  717. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  718. jsonInfo = JsonConvert.SerializeObject(table);
  719. var OtherOut = JsonConvert.DeserializeObject(jsonInfo);
  720. return OtherOut;
  721. }
  722. return false;
  723. case "拆卸单":
  724. bool isDisassemblyDoc = verification.isBoolDisassemblyDoc(JsonData.TransCode, JsonData.WorkPoint);
  725. if (isDisassemblyDoc == true)
  726. {
  727. sqlInfo = @"SELECT
  728. a.[ID],--
  729. a.DABDOCCode as TransCode ,--
  730. a.Sequence as TransSequence,--
  731. a.Quantity as Quantity,
  732. a.Amount as Amount,
  733. a.InvCode as InvCode ,
  734. a.DABDOCQuantity as IssueQuantity,
  735. b.InvName as InvName,--
  736. b.InvStd as InvStd,
  737. b.InvUnit as InvUnit,
  738. b.AmountUnit as AmountUnit,
  739. c.ProjectCode as ProjectCode,--
  740. c.BatchCode as BatchCode,
  741. c.Version as Version,
  742. c.Brand as Brand,
  743. c.cFree2,
  744. c.cFree3,
  745. c.cFree4,
  746. c.cFree5,
  747. c.cFree6,
  748. c.cFree7,
  749. c.cFree8,
  750. c.cFree9,
  751. c.cFree10
  752. FROM ICSDisassemblyDoc a
  753. left join ICSInventory b on b.InvCode=a.InvCode
  754. LEFT JOIN ICSExtension c ON a.ExtensionID=c.id and a.WorkPoint=c.WorkPoint--
  755. where a.DABDOCCode='{0}' and a.WorkPoint='{1}' ";
  756. sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
  757. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  758. jsonInfo = JsonConvert.SerializeObject(table);
  759. var Doc = JsonConvert.DeserializeObject(jsonInfo);
  760. return Doc;
  761. }
  762. return null;
  763. case "两步调入":
  764. sqlInfo = @"SELECT
  765. a.[ID],--
  766. f.InCode as TransCode ,--
  767. --c.ID as DetailID,--
  768. f.Sequence as TransSequence,--
  769. f.InvCode as InvCode ,--
  770. b.InvName as InvName,
  771. b.InvStd as InvStd,
  772. a.[Quantity] as Quantity,
  773. b.InvUnit as InvUnit,
  774. f.Amount as Amount,
  775. b.AmountUnit as AmountUnit,
  776. d.ProjectCode as ProjectCode,
  777. d.BatchCode as BatchCode,
  778. d.Version as Version,
  779. d.Brand as Brand,
  780. f.InQuantity as IssueQuantity,
  781. d.cFree2,
  782. d.cFree3,
  783. d.cFree4,
  784. d.cFree5,
  785. d.cFree6,
  786. d.cFree7,
  787. d.cFree8,
  788. d.cFree9,
  789. d.cFree10,
  790. F.WHCode
  791. from ICSWareHouseLotInfo a
  792. left join ICSOtherIn f on f.WHCode=a.WarehouseCode and a.InvCode=f.InvCode
  793. LEFT JOIN ICSInventory B ON f.InvCode=B.InvCode and a.WorkPoint=b.WorkPoint--
  794. left join ICSInventoryLot c on c.lotno=a.lotno and a.WorkPoint=c.WorkPoint
  795. LEFT JOIN ICSExtension d ON c.ExtensionID=d.ID and a.WorkPoint=c.WorkPoint
  796. where f.InCode='{0}' and f.WorkPoint='{1}'";
  797. sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
  798. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  799. jsonInfo = JsonConvert.SerializeObject(table);
  800. var OtherEnter = JsonConvert.DeserializeObject(jsonInfo);
  801. return OtherEnter;
  802. case "两步调出":
  803. sqlInfo = @"SELECT
  804. a.[ID],--
  805. f.OutCode as TransCode ,--
  806. --c.ID as DetailID,--
  807. f.Sequence as TransSequence,--
  808. f.InvCode as InvCode ,--
  809. b.InvName as InvName,
  810. b.InvStd as InvStd,
  811. a.[Quantity] as Quantity,
  812. b.InvUnit as InvUnit,
  813. f.Amount as Amount,
  814. b.AmountUnit as AmountUnit,
  815. d.ProjectCode as ProjectCode,
  816. d.BatchCode as BatchCode,
  817. d.Version as Version,
  818. d.Brand as Brand,
  819. f.OutQuantity as IssueQuantity,
  820. d.cFree2,
  821. d.cFree3,
  822. d.cFree4,
  823. d.cFree5,
  824. d.cFree6,
  825. d.cFree7,
  826. d.cFree8,
  827. d.cFree9,
  828. d.cFree10
  829. from ICSWareHouseLotInfo a
  830. left join ICSOtherOut f on f.WHCode=a.WarehouseCode and a.InvCode=f.InvCode
  831. LEFT JOIN ICSInventory B ON f.InvCode=B.InvCode and a.WorkPoint=b.WorkPoint--
  832. left join ICSInventoryLot c on c.lotno=a.lotno and a.WorkPoint=c.WorkPoint
  833. LEFT JOIN ICSExtension d ON c.ExtensionID=d.ID and a.WorkPoint=c.WorkPoint
  834. where f.OutCode='{0}' and f.WorkPoint='{1}'";
  835. sqlInfo = string.Format(sqlInfo, JsonData.TransCode, JsonData.WorkPoint);
  836. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  837. jsonInfo = JsonConvert.SerializeObject(table);
  838. var Otheroutr = JsonConvert.DeserializeObject(jsonInfo);
  839. return Otheroutr;
  840. }
  841. table = DBHelper.SQlReturnData(sql, cmd);
  842. string json = JsonConvert.SerializeObject(table);
  843. var model = JsonConvert.DeserializeObject(json);//<List<WMSSourceDocumentModel>>
  844. cmd.Transaction.Commit();
  845. return model;
  846. }
  847. catch (Exception ex)
  848. {
  849. cmd.Transaction.Rollback();
  850. log.Error(ex.Message);
  851. throw new Exception(ex.Message);
  852. }
  853. finally
  854. {
  855. if (conn.State == ConnectionState.Open)
  856. {
  857. conn.Close();
  858. }
  859. conn.Dispose();
  860. }
  861. }
  862. #endregion
  863. #region 获取条码信息
  864. /// <summary>
  865. /// 获取条码信息
  866. /// </summary>
  867. /// <param name="JsonData"></param>
  868. /// <returns></returns>
  869. public object BarCodeGet(BarCodeModel JsonData)
  870. {
  871. conn.Open();
  872. SqlTransaction sqlTran = conn.BeginTransaction();
  873. SqlCommand cmd = new SqlCommand();
  874. cmd.Transaction = sqlTran;
  875. cmd.Connection = conn;
  876. try
  877. {
  878. switch (JsonData.TransType)
  879. {
  880. #region 委外退料单
  881. case "委外退料单":
  882. verification.LotoOut(JsonData.Code, JsonData.WorkPoint);
  883. double numLotoInfo = verification.LotoTest(JsonData.Code, JsonData.WorkPoint);
  884. verification.HouseLotoOut(JsonData.Code, JsonData.WorkPoint);
  885. if (numLotoInfo == 0.0)
  886. {
  887. sql = @"select
  888. a.ID,
  889. H.ContainerCODE,
  890. H.ContainerName,
  891. A.InvCode,
  892. F.InvName,
  893. F.InvStd,
  894. a.Quantity,
  895. F.InvUnit,
  896. F.AmountUnit,
  897. E.ProjectCode,
  898. E.BatchCode,
  899. E.Version,
  900. E.Brand,
  901. l.OApplyNegCode as TransCode,--
  902. l.Sequence as TransSequence,--
  903. A.LotNo,
  904. E.cFree1,
  905. E.cFree2,
  906. E.cFree3,
  907. E.cFree4,
  908. E.cFree5,
  909. E.cFree6,
  910. E.cFree7,
  911. E.cFree8,
  912. E.cFree9,
  913. E.cFree10
  914. FROM ICSInventoryLot A
  915. LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
  916. LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
  917. LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
  918. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  919. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
  920. inner join ICSOApplyNegDetail l on l.OApplyNegCode=b.TransCode and l.Sequence=b.TransSequence";
  921. }
  922. else
  923. {
  924. sql = @"select
  925. a.ID,
  926. H.ContainerCODE,
  927. H.ContainerName,
  928. A.InvCode,
  929. F.InvName,
  930. F.InvStd,
  931. '{2}' as a.Quantity,
  932. F.InvUnit,
  933. F.AmountUnit,
  934. E.ProjectCode,
  935. E.BatchCode,
  936. E.Version,
  937. E.Brand,
  938. l.OApplyNegCode as TransCode,--
  939. l.Sequence as TransSequence,--
  940. A.LotNo,
  941. E.cFree1,
  942. E.cFree2,
  943. E.cFree3,
  944. E.cFree4,
  945. E.cFree5,
  946. E.cFree6,
  947. E.cFree7,
  948. E.cFree8,
  949. E.cFree9,
  950. E.cFree10
  951. FROM ICSInventoryLot A
  952. LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
  953. LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
  954. LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
  955. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  956. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
  957. inner join ICSOApplyNegDetail l on l.OApplyNegCode=b.TransCode and l.Sequence=b.TransSequence";
  958. }
  959. sql += " and a.LotNo='{0}' and a.WorkPoint='{1}' ";
  960. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint, numLotoInfo);
  961. table = DBHelper.SQlReturnData(sql, cmd);
  962. string jsonICSMOs = JsonConvert.SerializeObject(table);
  963. var ICSMOa = JsonConvert.DeserializeObject(jsonICSMOs);
  964. return ICSMOa;
  965. #endregion
  966. #region 委外订单
  967. case "委外订单":
  968. verification.LotoOut(JsonData.Code, JsonData.WorkPoint);
  969. double numLoto = verification.LotoTest(JsonData.Code, JsonData.WorkPoint);
  970. if (numLoto == 0.0)
  971. {
  972. sql = @"select
  973. a.ID,
  974. H.ContainerCODE,
  975. H.ContainerName,
  976. A.InvCode,
  977. F.InvName,
  978. F.InvStd,
  979. a.Quantity,
  980. F.InvUnit,
  981. F.AmountUnit,
  982. E.ProjectCode,
  983. E.BatchCode,
  984. E.Version,
  985. E.Brand,
  986. l.OOCode as TransCode,--
  987. l.Sequence as TransSequence,--
  988. A.LotNo,
  989. E.cFree1,
  990. E.cFree2,
  991. E.cFree3,
  992. E.cFree4,
  993. E.cFree5,
  994. E.cFree6,
  995. E.cFree7,
  996. E.cFree8,
  997. E.cFree9,
  998. E.cFree10
  999. FROM ICSInventoryLot A
  1000. LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
  1001. LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
  1002. LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
  1003. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  1004. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
  1005. left join ICSOutsourcingOrder l on l.OOCode=b.TransCode and l.Sequence=b.TransSequence where 1=1";
  1006. }
  1007. else
  1008. {
  1009. sql = @"select
  1010. a.ID,
  1011. H.ContainerCODE,
  1012. H.ContainerName,
  1013. A.InvCode,
  1014. F.InvName,
  1015. F.InvStd,
  1016. '{2}' as a.Quantity,
  1017. F.InvUnit,
  1018. F.AmountUnit,
  1019. E.ProjectCode,
  1020. E.BatchCode,
  1021. E.Version,
  1022. E.Brand,
  1023. l.OOCode as TransCode,--
  1024. l.Sequence as TransSequence,--
  1025. A.LotNo,
  1026. E.cFree1,
  1027. E.cFree2,
  1028. E.cFree3,
  1029. E.cFree4,
  1030. E.cFree5,
  1031. E.cFree6,
  1032. E.cFree7,
  1033. E.cFree8,
  1034. E.cFree9,
  1035. E.cFree10
  1036. FROM ICSInventoryLot A
  1037. LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
  1038. LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
  1039. LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
  1040. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  1041. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
  1042. left join ICSOutsourcingOrder l on l.OOCode=b.TransCode and l.Sequence=b.TransSequence where 1=1";
  1043. }
  1044. sql += " and a.LotNo='{0}' and a.WorkPoint='{1}' ";
  1045. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint, numLoto);
  1046. table = DBHelper.SQlReturnData(sql, cmd);
  1047. string jsonNegReceive = JsonConvert.SerializeObject(table);
  1048. var ApplyNegjsonNegReceive = JsonConvert.DeserializeObject(jsonNegReceive);//<List<WMSSourceDocumentModel>>
  1049. return ApplyNegjsonNegReceive;
  1050. #endregion
  1051. #region 委外送货单
  1052. case "委外送货单 ":
  1053. sql += " and c.LotNo='{1}' and a.WorkPoint='{2}' ";
  1054. sql = string.Format(sql, TransTypeEnum.ICSODeliveryNotice, JsonData.Code, JsonData.WorkPoint);
  1055. break;
  1056. #endregion
  1057. #region 退料单
  1058. case "退料单":
  1059. sql = @"
  1060. select a.ID,
  1061. a.InvCode,
  1062. a.Quantity,
  1063. d.ProjectCode,
  1064. d.BatchCode,
  1065. d.Version,
  1066. d.Brand,
  1067. c.ApplyNegCode as TransCode,--
  1068. c.Sequence as TransSequence,--
  1069. a.LotNo,
  1070. d.cFree1,
  1071. d.cFree2,
  1072. d.cFree3,
  1073. d.cFree4,
  1074. d.cFree5,
  1075. d.cFree6,
  1076. d.cFree7,
  1077. d.cFree8,
  1078. d.cFree9,
  1079. d.cFree10
  1080. from ICSInventoryLot a
  1081. left join ICSInventoryLotDetail b on a.LotNo=b.LotNo
  1082. left join ICSMOApplyNegDetail c on c.ApplyNegCode=b.TransCode and c.Sequence=b.TransSequence
  1083. left join ICSExtension d on d.ID=a.ExtensionID
  1084. where 1=1 and a.LotNo='{1}' and a.WorkPoint='{2}'";
  1085. sql = string.Format(sql, TransTypeEnum.ICSMOApplyNegDetail, JsonData.Code, JsonData.WorkPoint);
  1086. table = DBHelper.SQlReturnData(sql, cmd);
  1087. string jsonNeg = JsonConvert.SerializeObject(table);
  1088. var ApplyNeg = JsonConvert.DeserializeObject(jsonNeg);//<List<WMSSourceDocumentModel>>
  1089. cmd.Transaction.Commit();
  1090. return ApplyNeg;
  1091. #endregion
  1092. #region 生产订单
  1093. case "生产订单":
  1094. //verification.HouseLotInvCode();
  1095. sql = @"select
  1096. a.ID,
  1097. H.ContainerCODE,
  1098. H.ContainerName,
  1099. A.InvCode,
  1100. F.InvName,
  1101. F.InvStd,
  1102. a.Quantity,
  1103. F.InvUnit,
  1104. F.AmountUnit,
  1105. E.ProjectCode,
  1106. E.BatchCode,
  1107. E.Version,
  1108. E.Brand,
  1109. c.MOCode as TransCode,--
  1110. c.Sequence as TransSequence,--
  1111. A.LotNo,
  1112. E.cFree1,
  1113. E.cFree2,
  1114. E.cFree3,
  1115. E.cFree4,
  1116. E.cFree5,
  1117. E.cFree6,
  1118. E.cFree7,
  1119. E.cFree8,
  1120. E.cFree9,
  1121. E.cFree10
  1122. FROM ICSInventoryLot A
  1123. LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
  1124. LEFT JOIN ICSMO C ON B.TransCode=C.MOCode AND C.Sequence=B.TransSequence
  1125. LEFT JOIN ICSMOPick D ON C.MODetailID=D.ID
  1126. LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
  1127. LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
  1128. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  1129. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID WHERE 1=1 ";
  1130. sql += " and A.LotNo='{1}' and a.WorkPoint='{2}' ";
  1131. sql = string.Format(sql, TransTypeEnum.ICSMO, JsonData.Code, JsonData.WorkPoint);
  1132. table = DBHelper.SQlReturnData(sql, cmd);
  1133. string jsonICSMO = JsonConvert.SerializeObject(table);
  1134. var ICSMO = JsonConvert.DeserializeObject(jsonICSMO);//<List<WMSSourceDocumentModel>>
  1135. cmd.Transaction.Commit();
  1136. return ICSMO;
  1137. #endregion
  1138. case "销售退货":
  1139. string type = "退货";
  1140. bool veri = verification.HouseLotInfo(JsonData.Code, JsonData.WorkPoint, type);
  1141. if (veri == true)
  1142. {
  1143. sql = @"select
  1144. a.ID,
  1145. H.ContainerCODE,
  1146. H.ContainerName,
  1147. A.InvCode,
  1148. F.InvName,
  1149. F.InvStd,
  1150. a.Quantity,
  1151. F.InvUnit,
  1152. F.AmountUnit,
  1153. E.ProjectCode,
  1154. E.BatchCode,
  1155. E.Version,
  1156. E.Brand,
  1157. c.SDNCode as TransCode,--
  1158. c.Sequence as TransSequence,--
  1159. A.LotNo,
  1160. E.cFree1,
  1161. E.cFree2,
  1162. E.cFree3,
  1163. E.cFree4,
  1164. E.cFree5,
  1165. E.cFree6,
  1166. E.cFree7,
  1167. E.cFree8,
  1168. E.cFree9,
  1169. E.cFree10
  1170. FROM ICSInventoryLot A
  1171. LEFT JOIN ICSSDN C ON a.InvCode=C.InvCode AND C.WorkPoint=a.WorkPoint
  1172. LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
  1173. LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
  1174. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  1175. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
  1176. where C.type='2' and A.LotNo='{0}' and A.WorkPoint='{1}'";
  1177. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  1178. }
  1179. break;
  1180. case "盘点":
  1181. sqlInfo = @"select
  1182. a.ID,
  1183. f.ContainerCODE,
  1184. f.ContainerName,
  1185. d.InvCode,
  1186. d.InvName,
  1187. d.InvStd,
  1188. a.Quantity,
  1189. d.InvUnit,
  1190. d.AmountUnit,
  1191. i.WarehouseCode,
  1192. i.WarehouseName,
  1193. q.LocationCode,
  1194. q.LocationName,
  1195. c.ProjectCode,
  1196. c.BatchCode,
  1197. c.Version,
  1198. c.Brand,
  1199. t.TransCode,--
  1200. t.TransSequence,--
  1201. c.cFree1,
  1202. c.cFree2,
  1203. c.cFree3,
  1204. c.cFree4,
  1205. c.cFree5,
  1206. c.cFree6,
  1207. c.cFree7,
  1208. c.cFree8,
  1209. c.cFree9,
  1210. c.cFree10,
  1211. b.LotNo
  1212. from ICSWareHouseLotInfo a
  1213. left join ICSInventoryLot b on b.LotNo=a.LotNo and a.WorkPoint=b.WorkPoint
  1214. left join ICSExtension c on c.ID=B.ExtensionID and c.WorkPoint=b.WorkPoint
  1215. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1216. left join ICSContainerLot e on e.LotNo=a.LotNo and e.WorkPoint=a.WorkPoint
  1217. left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint
  1218. left join ICSWareHouseLotInfo h on h.LotNo=a.LotNo and h.WorkPoint=a.WorkPoint
  1219. left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
  1220. left join ICSWarehouse i on i.ID=q.WHID and i.WorkPoint=q.WorkPoint
  1221. left join ICSInventoryLotDetail t on t.LotNo=a.LotNo and t.WorkPoint=a.WorkPoint where a.LotNo='{0}' and a.WorkPoint='{1}' ";
  1222. sqlInfo = string.Format(sqlInfo, JsonData.Code, JsonData.WorkPoint);
  1223. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  1224. string jsonInfo = JsonConvert.SerializeObject(table);
  1225. var modelInfo = JsonConvert.DeserializeObject(jsonInfo);//<List<WMSSourceDocumentModel>>
  1226. cmd.Transaction.Commit();
  1227. return modelInfo;
  1228. case "盘点单":
  1229. sqlInfo = @" SELECT
  1230. a.[ID],--
  1231. a.CheckCode as TransCode ,--
  1232. --c.ID as DetailID,--
  1233. e.TransCode as TransSequence,--
  1234. f.InvCode as InvCode ,--
  1235. b.InvName as InvName,
  1236. b.InvStd as InvStd,
  1237. a.[Quantity] as Quantity,
  1238. b.InvUnit as InvUnit,
  1239. f.Amount as Amount,
  1240. b.AmountUnit as AmountUnit,
  1241. d.ProjectCode as ProjectCode,
  1242. d.BatchCode as BatchCode,
  1243. d.Version as Version,
  1244. d.Brand as Brand,
  1245. f.ActualQuantity as IssueQuantity,
  1246. d.cFree2,
  1247. d.cFree3,
  1248. d.cFree4,
  1249. d.cFree5,
  1250. d.cFree6,
  1251. d.cFree7,
  1252. d.cFree8,
  1253. d.cFree9,
  1254. d.cFree10,
  1255. c.LotNo
  1256. FROM ICSCheckDetail a --退
  1257. left join ICSCheck f on f.CheckCode=a.CheckCode and a.WorkPoint=f.WorkPoint
  1258. LEFT JOIN ICSInventory B ON f.InvCode=B.InvCode and a.WorkPoint=b.WorkPoint--
  1259. left join ICSInventoryLot c on c.lotno=a.lotno and a.WorkPoint=c.WorkPoint
  1260. LEFT JOIN ICSExtension d ON c.ExtensionID=d.ID and a.WorkPoint=c.WorkPoint--
  1261. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  1262. where f.Status='2' and c.lotno='{0}' and a.WorkPoint='{1}' ";
  1263. sqlInfo = string.Format(sqlInfo, JsonData.Code, JsonData.WorkPoint);
  1264. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  1265. jsonInfo = JsonConvert.SerializeObject(table);
  1266. var Noticec = JsonConvert.DeserializeObject(jsonInfo);
  1267. return Noticec;
  1268. case "采购到货单":
  1269. sql = @"select
  1270. a.ID,
  1271. H.ContainerCODE,
  1272. H.ContainerName,
  1273. A.InvCode,
  1274. F.InvName,
  1275. F.InvStd,
  1276. a.Quantity,
  1277. F.InvUnit,
  1278. F.AmountUnit,
  1279. E.ProjectCode,
  1280. E.BatchCode,
  1281. E.Version,
  1282. E.Brand,
  1283. c.POCode as TransCode,--
  1284. c.Sequence as TransSequence,--
  1285. A.LotNo,
  1286. E.cFree1,
  1287. E.cFree2,
  1288. E.cFree3,
  1289. E.cFree4,
  1290. E.cFree5,
  1291. E.cFree6,
  1292. E.cFree7,
  1293. E.cFree8,
  1294. E.cFree9,
  1295. E.cFree10
  1296. FROM ICSInventoryLot A
  1297. LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
  1298. LEFT JOIN ICSPurchaseOrder C ON b.TransCode=C.POCode AND C.Sequence=B.TransSequence
  1299. LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
  1300. LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
  1301. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  1302. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
  1303. where a.lotno='{0}' and a.WorkPoint='{1}'";
  1304. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  1305. table = DBHelper.SQlReturnData(sql, cmd);
  1306. jsonInfo = JsonConvert.SerializeObject(table);
  1307. var NoticecList = JsonConvert.DeserializeObject(jsonInfo);
  1308. return NoticecList;
  1309. case "采购订单":
  1310. bool SDN = verification.SNDetail(JsonData.Code, JsonData.WorkPoint);
  1311. bool oorder = verification.PurchaseOrder(JsonData.Code, JsonData.WorkPoint);
  1312. if (SDN == true && oorder == true)
  1313. {
  1314. double unm = verification.LotoTest(JsonData.Code, JsonData.WorkPoint);
  1315. if (unm == 0.0)
  1316. {
  1317. ///条码数量
  1318. sqlInfo = @"select
  1319. a.ID,
  1320. H.ContainerCODE,
  1321. H.ContainerName,
  1322. A.InvCode,
  1323. F.InvName,
  1324. F.InvStd,
  1325. j.DNQuantity as Quantity,
  1326. F.InvUnit,
  1327. F.AmountUnit,
  1328. E.ProjectCode,
  1329. E.BatchCode,
  1330. E.Version,
  1331. E.Brand,
  1332. c.POCode as TransCode,--
  1333. c.Sequence as TransSequence,--
  1334. A.LotNo,
  1335. E.cFree1,
  1336. E.cFree2,
  1337. E.cFree3,
  1338. E.cFree4,
  1339. E.cFree5,
  1340. E.cFree6,
  1341. E.cFree7,
  1342. E.cFree8,
  1343. E.cFree9,
  1344. E.cFree10
  1345. FROM ICSInventoryLot A
  1346. LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
  1347. LEFT JOIN ICSPurchaseOrder C ON B.TransCode=C.POCode AND C.Sequence=B.TransSequence
  1348. LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
  1349. LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
  1350. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  1351. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
  1352. left join ICSASNDetail j on j.lotno=a.lotno
  1353. where c.Status='2' and a.lotno='{0}' and a.WorkPoint='{1}'";
  1354. sqlInfo = string.Format(sqlInfo, JsonData.Code, JsonData.WorkPoint);
  1355. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  1356. jsonInfo = JsonConvert.SerializeObject(table);
  1357. var Purchase = JsonConvert.DeserializeObject(jsonInfo);
  1358. return Purchase;
  1359. }
  1360. else
  1361. {
  1362. //检验数量
  1363. sqlInfo = @"select
  1364. a.ID,
  1365. H.ContainerCODE,
  1366. H.ContainerName,
  1367. A.InvCode,
  1368. F.InvName,
  1369. F.InvStd,
  1370. '{2}' as Quantity,
  1371. F.InvUnit,
  1372. F.AmountUnit,
  1373. E.ProjectCode,
  1374. E.BatchCode,
  1375. E.Version,
  1376. E.Brand,
  1377. c.POCode as TransCode,--
  1378. c.Sequence as TransSequence,--
  1379. A.LotNo,
  1380. E.cFree1,
  1381. E.cFree2,
  1382. E.cFree3,
  1383. E.cFree4,
  1384. E.cFree5,
  1385. E.cFree6,
  1386. E.cFree7,
  1387. E.cFree8,
  1388. E.cFree9,
  1389. E.cFree10
  1390. FROM ICSInventoryLot A
  1391. LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
  1392. LEFT JOIN ICSPurchaseOrder C ON B.TransCode=C.POCode AND C.Sequence=B.TransSequence
  1393. LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
  1394. LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
  1395. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  1396. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
  1397. where c.Status='2' and a.lotno='{0}' and a.WorkPoint='{1}'";
  1398. sqlInfo = string.Format(sqlInfo, JsonData.Code, JsonData.WorkPoint, unm);
  1399. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  1400. jsonInfo = JsonConvert.SerializeObject(table);
  1401. var Purchase = JsonConvert.DeserializeObject(jsonInfo);
  1402. return Purchase;
  1403. }
  1404. }
  1405. break;
  1406. case "一步式调拨单":
  1407. bool iSLocationCode = verification.iSLocationCode(JsonData.Code, JsonData.WorkPoint);
  1408. if (iSLocationCode == true)
  1409. {
  1410. sql = @"select
  1411. a.ID,
  1412. f.ContainerCODE,
  1413. f.ContainerName,
  1414. d.InvCode,
  1415. d.InvName,
  1416. d.InvStd,
  1417. a.Quantity,
  1418. d.InvUnit,
  1419. d.AmountUnit,
  1420. i.WarehouseCode,
  1421. i.WarehouseName,
  1422. q.LocationCode,
  1423. q.LocationName,
  1424. c.ProjectCode,
  1425. c.BatchCode,
  1426. c.Version,
  1427. c.Brand,
  1428. t.TransCode,--
  1429. t.TransSequence,--
  1430. c.cFree1,
  1431. c.cFree2,
  1432. c.cFree3,
  1433. c.cFree4,
  1434. c.cFree5,
  1435. c.cFree6,
  1436. c.cFree7,
  1437. c.cFree8,
  1438. c.cFree9,
  1439. c.cFree10,
  1440. b.LotNo
  1441. from ICSWareHouseLotInfo a
  1442. left join ICSInventoryLot b on b.LotNo=a.LotNo and a.WorkPoint=b.WorkPoint
  1443. left join ICSExtension c on c.ID=B.ExtensionID and c.WorkPoint=b.WorkPoint
  1444. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  1445. left join ICSContainerLot e on e.LotNo=a.LotNo and e.WorkPoint=a.WorkPoint
  1446. left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint
  1447. left join ICSWareHouseLotInfo h on h.LotNo=a.LotNo and h.WorkPoint=a.WorkPoint
  1448. left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
  1449. left join ICSWarehouse i on i.ID=q.WHID and i.WorkPoint=q.WorkPoint
  1450. left join ICSInventoryLotDetail t on t.LotNo=a.LotNo and t.WorkPoint=a.WorkPoint
  1451. left join ICSTransfer l on l.TransferNO=t.TransCode and t.TransSequence=l.Sequence
  1452. where a.lotno='{0}' and a.WorkPoint='{1}'";
  1453. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  1454. table = DBHelper.SQlReturnData(sql, cmd);
  1455. jsonInfo = JsonConvert.SerializeObject(table);
  1456. var Transfer = JsonConvert.DeserializeObject(jsonInfo);
  1457. return Transfer;
  1458. }
  1459. return null;
  1460. case "二部调拨":
  1461. sql = @"select
  1462. a.ID,
  1463. f.ContainerCODE,
  1464. f.ContainerName,
  1465. d.InvCode,
  1466. d.InvName,
  1467. d.InvStd,
  1468. a.Quantity,
  1469. d.InvUnit,
  1470. d.AmountUnit,
  1471. i.WarehouseCode,
  1472. i.WarehouseName,
  1473. q.LocationCode,
  1474. q.LocationName,
  1475. b.ProjectCode,
  1476. b.BatchCode,
  1477. b.Version,
  1478. b.Brand,
  1479. t.TransCode,--
  1480. t.TransSequence,--
  1481. a.TransferQuantity as hasQuantity,
  1482. a.FromWarehouseCode as fromWHCode,
  1483. a.ToWarehouseCode as toWHCode,
  1484. b.ProjectCode ,
  1485. a.ToLocationCode as binCode,
  1486. c.LotNo,
  1487. b.cFree1,
  1488. b.cFree2,
  1489. b.cFree3,
  1490. b.cFree4,
  1491. b.cFree5,
  1492. b.cFree6,
  1493. b.cFree7,
  1494. b.cFree8,
  1495. b.cFree9,
  1496. b.cFree10,
  1497. c.LotNo
  1498. from ICSTransfer a
  1499. left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
  1500. left join ICSContainerLot c on c.ID=b.ID and c.WorkPoint=b.WorkPoint--
  1501. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--
  1502. left join ICSContainerLot e on e.LotNo=c.LotNo and e.WorkPoint=c.WorkPoint--
  1503. left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--
  1504. left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
  1505. left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
  1506. left join ICSWarehouse i on i.ID=q.WHID and i.WorkPoint=q.WorkPoint--
  1507. left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint
  1508. where a.Type='2' and c.lotno='{0}' and a.WorkPoint'{1}'";
  1509. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  1510. table = DBHelper.SQlReturnData(sql, cmd);
  1511. jsonInfo = JsonConvert.SerializeObject(table);
  1512. var TOTransfer = JsonConvert.DeserializeObject(jsonInfo);
  1513. return TOTransfer;
  1514. case "其它入库":
  1515. bool BoolOtherIn = verification.HouseLotInfo(JsonData.Code, JsonData.WorkPoint, JsonData.TransType);
  1516. if (BoolOtherIn == true)
  1517. {
  1518. double num = verification.LotoTest(JsonData.Code, JsonData.WorkPoint);
  1519. if (num == 0.0)
  1520. {
  1521. ///条码数量
  1522. sql = @"select
  1523. a.ID,
  1524. H.ContainerCODE,
  1525. H.ContainerName,
  1526. A.InvCode,
  1527. F.InvName,
  1528. F.InvStd,
  1529. a.Quantity,
  1530. F.InvUnit,
  1531. F.AmountUnit,
  1532. E.ProjectCode,
  1533. E.BatchCode,
  1534. E.Version,
  1535. E.Brand,
  1536. c.InCode as TransCode,--
  1537. c.Sequence as TransSequence,--
  1538. A.LotNo,
  1539. E.cFree1,
  1540. E.cFree2,
  1541. E.cFree3,
  1542. E.cFree4,
  1543. E.cFree5,
  1544. E.cFree6,
  1545. E.cFree7,
  1546. E.cFree8,
  1547. E.cFree9,
  1548. E.cFree10
  1549. FROM ICSInventoryLot A
  1550. LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
  1551. LEFT JOIN ICSOtherIn C ON b.TransCode=C.InCode AND C.Sequence=B.TransSequence
  1552. LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
  1553. LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
  1554. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  1555. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
  1556. where a.lotno='{0}' and a.WorkPoint='{1}'";
  1557. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  1558. table = DBHelper.SQlReturnData(sql, cmd);
  1559. }
  1560. else
  1561. {
  1562. ///检验的数量
  1563. sql = @"select
  1564. a.ID,
  1565. H.ContainerCODE,
  1566. H.ContainerName,
  1567. A.InvCode,
  1568. F.InvName,
  1569. F.InvStd,
  1570. '{2}' as Quantity,
  1571. F.InvUnit,
  1572. F.AmountUnit,
  1573. E.ProjectCode,
  1574. E.BatchCode,
  1575. E.Version,
  1576. E.Brand,
  1577. c.InCode as TransCode,--
  1578. c.Sequence as TransSequence,--
  1579. A.LotNo,
  1580. E.cFree1,
  1581. E.cFree2,
  1582. E.cFree3,
  1583. E.cFree4,
  1584. E.cFree5,
  1585. E.cFree6,
  1586. E.cFree7,
  1587. E.cFree8,
  1588. E.cFree9,
  1589. E.cFree10
  1590. FROM ICSInventoryLot A
  1591. LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
  1592. LEFT JOIN ICSOtherIn C ON b.TransCode=C.InCode AND C.Sequence=B.TransSequence
  1593. LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
  1594. LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
  1595. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  1596. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
  1597. where a.lotno='{0}' and a.WorkPoint='{1}'";
  1598. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint, num);
  1599. table = DBHelper.SQlReturnData(sql, cmd);
  1600. }
  1601. }
  1602. jsonInfo = JsonConvert.SerializeObject(table);
  1603. var OtherIn = JsonConvert.DeserializeObject(jsonInfo);
  1604. return OtherIn;
  1605. case "拆分":
  1606. sql = @"select
  1607. a.ID,
  1608. H.ContainerCODE,
  1609. H.ContainerName,
  1610. A.InvCode,
  1611. F.InvName,
  1612. F.InvStd,
  1613. a.Quantity,
  1614. F.InvUnit,
  1615. F.AmountUnit,
  1616. c.ProjectCode,
  1617. c.BatchCode,
  1618. c.Version,
  1619. c.Brand,
  1620. d.TransCode as TransCode,--
  1621. d.TransSequence as TransSequence,--
  1622. A.LotNo,
  1623. c.cFree1,
  1624. c.cFree2,
  1625. c.cFree3,
  1626. c.cFree4,
  1627. c.cFree5,
  1628. c.cFree6,
  1629. c.cFree7,
  1630. c.cFree8,
  1631. c.cFree9,
  1632. c.cFree10
  1633. FROM ICSWareHouseLotInfo A
  1634. LEFT JOIN ICSInventoryLot B ON A.LotNo =B.LotNo
  1635. LEFT JOIN ICSExtension c ON c.ID=b.ExtensionID
  1636. left join ICSInventoryLotDetail d on b.LotNo=d.LotNo
  1637. LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
  1638. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  1639. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
  1640. where a.lotno='{0}' and a.WorkPoint='{1}'";
  1641. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  1642. table = DBHelper.SQlReturnData(sql, cmd);
  1643. jsonInfo = JsonConvert.SerializeObject(table);
  1644. var lotinfo = JsonConvert.DeserializeObject(jsonInfo);
  1645. return lotinfo;
  1646. case "两部调入":
  1647. sqlInfo = @"select
  1648. a.ID,
  1649. H.ContainerCODE,
  1650. H.ContainerName,
  1651. A.InvCode,
  1652. F.InvName,
  1653. F.InvStd,
  1654. a.Quantity,
  1655. F.InvUnit,
  1656. F.AmountUnit,
  1657. E.ProjectCode,
  1658. E.BatchCode,
  1659. E.Version,
  1660. E.Brand,
  1661. c.InCode as TransCode,--
  1662. c.Sequence as TransSequence,--
  1663. A.LotNo,
  1664. E.cFree1,
  1665. E.cFree2,
  1666. E.cFree3,
  1667. E.cFree4,
  1668. E.cFree5,
  1669. E.cFree6,
  1670. E.cFree7,
  1671. E.cFree8,
  1672. E.cFree9,
  1673. E.cFree10
  1674. FROM ICSInventoryLot A
  1675. LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
  1676. LEFT JOIN ICSOtherIn C ON b.TransCode=C.InCode AND C.Sequence=B.TransSequence
  1677. left join ICSTransfer d on d.TransferNO =c.InCode and d.Sequence=c.Sequence
  1678. LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
  1679. LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
  1680. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  1681. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
  1682. where a.lotno ='{0}' and a.WorkPoint='{1}' and d.Type='2' ";
  1683. sqlInfo = string.Format(sqlInfo, JsonData.Code, JsonData.WorkPoint);
  1684. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  1685. if (table.Rows.Count > 0)
  1686. {
  1687. jsonInfo = JsonConvert.SerializeObject(table);
  1688. var loyout = JsonConvert.DeserializeObject(jsonInfo);
  1689. return loyout;
  1690. }
  1691. else
  1692. {
  1693. throw new Exception("调拨单不存在!");
  1694. }
  1695. }
  1696. table = DBHelper.SQlReturnData(sql, cmd);
  1697. string json = JsonConvert.SerializeObject(table);
  1698. var model = JsonConvert.DeserializeObject(json);//<List<WMSSourceDocumentModel>>
  1699. cmd.Transaction.Commit();
  1700. return model;
  1701. }
  1702. catch (Exception ex)
  1703. {
  1704. //cmd.Transaction.Rollback();
  1705. log.Error(ex.Message);
  1706. throw new Exception(ex.Message);
  1707. }
  1708. finally
  1709. {
  1710. if (conn.State == ConnectionState.Open)
  1711. {
  1712. conn.Close();
  1713. }
  1714. conn.Dispose();
  1715. }
  1716. }
  1717. /// <summary>
  1718. /// 获取条码信息()
  1719. /// </summary>入库
  1720. /// <param name="JsonData"></param>
  1721. /// <returns></returns>
  1722. public object BarcodeWarehousing(BarCodeModel JsonData)
  1723. {
  1724. conn.Open();
  1725. SqlTransaction sqlTran = conn.BeginTransaction();
  1726. SqlCommand cmd = new SqlCommand();
  1727. cmd.Transaction = sqlTran;
  1728. cmd.Connection = conn;
  1729. string type;
  1730. try
  1731. {
  1732. sql = @"select
  1733. a.ID,
  1734. f.ContainerCODE,
  1735. f.ContainerName,
  1736. d.InvCode,
  1737. d.InvName,
  1738. d.InvStd,
  1739. h.Quantity,
  1740. d.InvUnit,
  1741. d.AmountUnit,
  1742. i.WarehouseCode,
  1743. i.WarehouseName,
  1744. q.LocationCode,
  1745. q.LocationName,
  1746. b.ProjectCode,
  1747. b.BatchCode,
  1748. b.Version,
  1749. b.Brand,
  1750. t.TransCode,--
  1751. t.TransSequence,--
  1752. c.LotNo,
  1753. b.cFree1,
  1754. b.cFree2,
  1755. b.cFree3,
  1756. b.cFree4,
  1757. b.cFree5,
  1758. b.cFree6,
  1759. b.cFree7,
  1760. b.cFree8,
  1761. b.cFree9,
  1762. b.cFree10,
  1763. c.LotNo
  1764. from {0} a --
  1765. left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
  1766. left join ICSInventoryLot c on c.ID=b.ID and c.WorkPoint=b.WorkPoint--
  1767. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--
  1768. left join ICSContainerLot e on e.LotNo=c.LotNo and e.WorkPoint=c.WorkPoint--
  1769. left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--
  1770. left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
  1771. left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
  1772. left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--
  1773. left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--
  1774. where 1=1 ";
  1775. switch (JsonData.TransType)
  1776. {
  1777. case "送货单":
  1778. verification.HouseLotInfo(JsonData.Code, JsonData.WorkPoint, JsonData.TransCode);//库存条码验证
  1779. sql = @"select
  1780. a.ID,
  1781. f.ContainerCODE,
  1782. f.ContainerName,
  1783. d.InvCode,
  1784. d.InvName,
  1785. d.InvStd,
  1786. h.Quantity,
  1787. d.InvUnit,
  1788. d.AmountUnit,
  1789. i.WarehouseCode,
  1790. i.WarehouseName,
  1791. q.LocationCode,
  1792. q.LocationName,
  1793. c.ProjectCode,
  1794. c.BatchCode,
  1795. c.Version,
  1796. c.Brand,
  1797. t.TransCode,--
  1798. t.TransSequence,--
  1799. a.LotNo,
  1800. c.cFree1,
  1801. c.cFree2,
  1802. c.cFree3,
  1803. c.cFree4,
  1804. c.cFree5,
  1805. c.cFree6,
  1806. c.cFree7,
  1807. c.cFree8,
  1808. c.cFree9,
  1809. c.cFree10
  1810. from {0} a --
  1811. left join ICSInventoryLot b on a.LotNo=b.LotNo and b.WorkPoint=a.WorkPoint--
  1812. left join ICSExtension c on b.ExtensionID=b.ID and b.WorkPoint=c.WorkPoint
  1813. left join ICSInventory d on b.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--
  1814. left join ICSContainerLot e on e.LotNo=a.LotNo and e.WorkPoint=c.WorkPoint--
  1815. left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--
  1816. left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
  1817. left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
  1818. left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--
  1819. left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--
  1820. where 1=1 and a.LotNo='{1}' and a.WorkPoint='{2}' and a.ASNCode='{3}'";
  1821. sql = string.Format(sql, TransTypeEnum.ICSASNDetail, JsonData.Code, JsonData.WorkPoint, JsonData.TransCode);
  1822. break;
  1823. case "委外送货单子表":
  1824. sql = @"select
  1825. a.ID,
  1826. f.ContainerCODE,
  1827. f.ContainerName,
  1828. d.InvCode,
  1829. d.InvName,
  1830. d.InvStd,
  1831. h.Quantity,
  1832. d.InvUnit,
  1833. d.AmountUnit,
  1834. i.WarehouseCode,
  1835. i.WarehouseName,
  1836. q.LocationCode,
  1837. q.LocationName,
  1838. c.ProjectCode,
  1839. c.BatchCode,
  1840. c.Version,
  1841. c.Brand,
  1842. t.TransCode,--
  1843. t.TransSequence,--
  1844. a.LotNo,
  1845. c.cFree1,
  1846. c.cFree2,
  1847. c.cFree3,
  1848. c.cFree4,
  1849. c.cFree5,
  1850. c.cFree6,
  1851. c.cFree7,
  1852. c.cFree8,
  1853. c.cFree9,
  1854. c.cFree10
  1855. from {0} a --
  1856. left join ICSInventoryLot b on a.LotNo=b.LotNo and b.WorkPoint=a.WorkPoint--
  1857. left join ICSExtension c on b.ExtensionID=b.ID and b.WorkPoint=c.WorkPoint
  1858. left join ICSInventory d on b.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--
  1859. left join ICSContainerLot e on e.LotNo=a.LotNo and e.WorkPoint=c.WorkPoint--
  1860. left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--
  1861. left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
  1862. left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
  1863. left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--
  1864. left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--
  1865. where 1=1 and a.LotNo='{1}' and a.WorkPoint='{2}'and a.OASNCode='{3}'";
  1866. sql = string.Format(sql, TransTypeEnum.ICSOASNDetail, JsonData.Code, JsonData.WorkPoint, JsonData.TransCode);
  1867. break;
  1868. case "一步式调拨单":
  1869. sql = @"select
  1870. a.ID,
  1871. f.ContainerCODE,
  1872. f.ContainerName,
  1873. d.InvCode,
  1874. d.InvName,
  1875. d.InvStd,
  1876. h.Quantity,
  1877. d.InvUnit,
  1878. d.AmountUnit,
  1879. i.WarehouseCode,
  1880. i.WarehouseName,
  1881. q.LocationCode,
  1882. q.LocationName,
  1883. b.ProjectCode,
  1884. b.BatchCode,
  1885. b.Version,
  1886. b.Brand,
  1887. t.TransCode,--
  1888. t.TransSequence,--
  1889. c.LotNo,
  1890. b.cFree1,
  1891. b.cFree2,
  1892. b.cFree3,
  1893. b.cFree4,
  1894. b.cFree5,
  1895. b.cFree6,
  1896. b.cFree7,
  1897. b.cFree8,
  1898. b.cFree9,
  1899. b.cFree10,
  1900. c.LotNo
  1901. from {0} a --
  1902. left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
  1903. left join ICSInventoryLot c on c.ID=b.ID and c.WorkPoint=b.WorkPoint--
  1904. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--
  1905. left join ICSContainerLot e on e.LotNo=c.LotNo and e.WorkPoint=c.WorkPoint--
  1906. left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--
  1907. left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
  1908. left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
  1909. left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--
  1910. left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--
  1911. where 1=1 and type='1' and c.lotno='{1}' and a.TransferNO='{2}'";
  1912. sql = string.Format(sql, TransTypeEnum.ICSTransfer, JsonData.Code, JsonData.TransCode);
  1913. break;
  1914. case "二步式调拨单":
  1915. sql = @"select
  1916. a.ID,
  1917. f.ContainerCODE,
  1918. f.ContainerName,
  1919. d.InvCode,
  1920. d.InvName,
  1921. d.InvStd,
  1922. h.Quantity,
  1923. d.InvUnit,
  1924. d.AmountUnit,
  1925. i.WarehouseCode,
  1926. i.WarehouseName,
  1927. q.LocationCode,
  1928. q.LocationName,
  1929. b.ProjectCode,
  1930. b.BatchCode,
  1931. b.Version,
  1932. b.Brand,
  1933. t.TransCode,--
  1934. t.TransSequence,--
  1935. c.LotNo,
  1936. b.cFree1,
  1937. b.cFree2,
  1938. b.cFree3,
  1939. b.cFree4,
  1940. b.cFree5,
  1941. b.cFree6,
  1942. b.cFree7,
  1943. b.cFree8,
  1944. b.cFree9,
  1945. b.cFree10,
  1946. c.LotNo
  1947. from {0} a --
  1948. left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
  1949. left join ICSInventoryLot c on c.ID=b.ID and c.WorkPoint=b.WorkPoint--
  1950. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--
  1951. left join ICSContainerLot e on e.LotNo=c.LotNo and e.WorkPoint=c.WorkPoint--
  1952. left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--
  1953. left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
  1954. left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
  1955. left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--
  1956. left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--
  1957. where 1=1 and type='2' and c.lotno='{1}' and a.TransferNO='{2}' and a.WorkPoint='{3}'";
  1958. sql = string.Format(sql, TransTypeEnum.ICSTransfer, JsonData.Code, JsonData.TransCode, JsonData.WorkPoint);
  1959. break;
  1960. case "委外订单备料表":
  1961. type = "委外发料";
  1962. bool lotInfo = verification.HouseLotInfo(JsonData.Code, JsonData.WorkPoint, type);
  1963. if (lotInfo == true)
  1964. {
  1965. verification.Outsourcing(JsonData.Code, JsonData.WorkPoint, JsonData.TransCode);
  1966. sqlInfo = @"select a.ID,
  1967. b.InvCode,
  1968. o.InvName,
  1969. o.InvStd,
  1970. a.Quantity ,
  1971. o.InvUnit,
  1972. o.AmountUnit,
  1973. l.WarehouseCode,
  1974. l.WarehouseName,
  1975. j.LocationCode,
  1976. j.LocationName,
  1977. e.ProjectCode,
  1978. e.BatchCode,
  1979. e.Version,
  1980. e.Brand,
  1981. c.TransCode,--
  1982. c.TransSequence,--
  1983. a.LotNo,
  1984. e.cFree1,
  1985. e.cFree2,
  1986. e.cFree3,
  1987. e.cFree4,
  1988. e.cFree5,
  1989. e.cFree6,
  1990. e.cFree7,
  1991. e.cFree8,
  1992. e.cFree9,
  1993. e.cFree10 ,
  1994. b.Type
  1995. from ICSWareHouseLotInfo a
  1996. left join ICSInventoryLot b on a.LotNo=b.LotNo and a.InvCode=b.InvCode
  1997. left join ICSInventoryLotDetail c on c .LotNo=b.LotNo
  1998. left join ICSExtension e on e.id=b.ExtensionID
  1999. left join ICSContainerLot f on f.LotNo=b.LotNo
  2000. left join ICSContainer g on g.ContainerID=f.id
  2001. left join ICSLocation j on j.LocationCode=a.LocationCode
  2002. left join ICSWarehouse L ON L.ID=J.WHID
  2003. left join ICSInventory o on o.InvCode=b.InvCode
  2004. where a.LotNo='{0}' and a.WorkPoint='{1}' ";
  2005. sqlInfo = string.Format(sqlInfo, JsonData.Code, JsonData.WorkPoint);
  2006. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  2007. }
  2008. string jsonInfoT = JsonConvert.SerializeObject(table);
  2009. var PickT = JsonConvert.DeserializeObject(jsonInfoT); //<List<WMSSourceDocumentModel>>
  2010. cmd.Transaction.Commit();
  2011. return PickT;
  2012. case "委外领料申请单":
  2013. sql = @"select
  2014. a.ID,
  2015. f.ContainerCODE,
  2016. f.ContainerName,
  2017. d.InvCode,
  2018. d.InvName,
  2019. d.InvStd,
  2020. h.Quantity,
  2021. d.InvUnit,
  2022. d.AmountUnit,
  2023. i.WarehouseCode,
  2024. i.WarehouseName,
  2025. q.LocationCode,
  2026. q.LocationName,
  2027. b.ProjectCode,
  2028. b.BatchCode,
  2029. b.Version,
  2030. b.Brand,
  2031. t.TransCode,--
  2032. t.TransSequence,--
  2033. c.LotNo,
  2034. b.cFree1,
  2035. b.cFree2,
  2036. b.cFree3,
  2037. b.cFree4,
  2038. b.cFree5,
  2039. b.cFree6,
  2040. b.cFree7,
  2041. b.cFree8,
  2042. b.cFree9,
  2043. b.cFree10,
  2044. c.LotNo
  2045. from {0} a --
  2046. left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
  2047. left join ICSInventoryLot c on c.ID=b.ID and c.WorkPoint=b.WorkPoint--
  2048. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--
  2049. left join ICSContainerLot e on e.LotNo=c.LotNo and e.WorkPoint=c.WorkPoint--
  2050. left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--
  2051. left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
  2052. left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
  2053. left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--
  2054. left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--
  2055. where c.LotNo='{1}' and a.WorkPoint='{2}' and a.OODetailID='{3}'";
  2056. sql = string.Format(sql, TransTypeEnum.ICSMOApply, JsonData.Code, JsonData.WorkPoint, JsonData.TransCode);
  2057. break;
  2058. case "销售发货":
  2059. type = "发货";
  2060. bool LotInfo = verification.HouseLotInfo(JsonData.Code, JsonData.WorkPoint, type);
  2061. if (LotInfo == true)
  2062. {
  2063. sql = @"select
  2064. f.ContainerCODE,
  2065. f.ContainerName,
  2066. d.InvCode,
  2067. d.InvName,
  2068. d.InvStd,
  2069. h.Quantity,
  2070. d.InvUnit,
  2071. d.AmountUnit,
  2072. i.WarehouseCode,
  2073. i.WarehouseName,
  2074. q.LocationCode,
  2075. q.LocationName,
  2076. b.ProjectCode,
  2077. b.BatchCode,
  2078. b.Version,
  2079. b.Brand,
  2080. t.TransCode,--
  2081. t.TransSequence,--
  2082. a.LotNo,
  2083. b.cFree1,
  2084. b.cFree2,
  2085. b.cFree3,
  2086. b.cFree4,
  2087. b.cFree5,
  2088. b.cFree6,
  2089. b.cFree7,
  2090. b.cFree8,
  2091. b.cFree9,
  2092. b.cFree10
  2093. from ICSInventoryLot a
  2094. left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
  2095. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--
  2096. left join ICSContainerLot e on e.LotNo=a.LotNo and e.WorkPoint=a.WorkPoint--
  2097. left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--
  2098. left join ICSWareHouseLotInfo h on h.LotNo=a.LotNo and h.WorkPoint=a.WorkPoint
  2099. left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
  2100. left join ICSWarehouse i on i.ID=q.WHID and i.WorkPoint=q.WorkPoint--
  2101. left join ICSInventoryLotDetail t on t.LotNo=a.LotNo and t.WorkPoint=a.WorkPoint--
  2102. where 1=1";
  2103. sql += " and a.LotNo='{0}' and a.WorkPoint='{1}'";
  2104. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  2105. table = DBHelper.SQlReturnData(sql, cmd);
  2106. if (table.Rows.Count <= 0)
  2107. {
  2108. throw new Exception("条码不存在!");
  2109. }
  2110. string jsonInfoInve = JsonConvert.SerializeObject(table);
  2111. var Inve = JsonConvert.DeserializeObject(jsonInfoInve); //<List<WMSSourceDocumentModel>>
  2112. cmd.Transaction.Commit();
  2113. return Inve;
  2114. }
  2115. break;
  2116. case "生产订单备料表":
  2117. type = "生产订单备料表";
  2118. bool nu = verification.HouseLotInfo(JsonData.Code, JsonData.WorkPoint, type);//库存条码验证
  2119. verification.HouseLotInvCode(JsonData.Code, JsonData.WorkPoint, JsonData.TransCode);
  2120. sqlInfo = @"select a.ID,
  2121. b.InvCode,
  2122. o.InvName,
  2123. o.InvStd,
  2124. a.Quantity ,
  2125. o.InvUnit,
  2126. o.AmountUnit,
  2127. l.WarehouseCode,
  2128. l.WarehouseName,
  2129. j.LocationCode,
  2130. j.LocationName,
  2131. e.ProjectCode,
  2132. e.BatchCode,
  2133. e.Version,
  2134. e.Brand,
  2135. c.TransCode,--
  2136. c.TransSequence,--
  2137. a.LotNo,
  2138. e.cFree1,
  2139. e.cFree2,
  2140. e.cFree3,
  2141. e.cFree4,
  2142. e.cFree5,
  2143. e.cFree6,
  2144. e.cFree7,
  2145. e.cFree8,
  2146. e.cFree9,
  2147. e.cFree10
  2148. from ICSWareHouseLotInfo a
  2149. left join ICSInventoryLot b on a.LotNo=b.LotNo and a.InvCode=b.InvCode
  2150. left join ICSInventoryLotDetail c on c .LotNo=b.LotNo
  2151. left join ICSExtension e on e.id=b.ExtensionID
  2152. left join ICSContainerLot f on f.LotNo=b.LotNo
  2153. left join ICSContainer g on g.ContainerID=f.id
  2154. left join ICSLocation j on j.LocationCode=a.LocationCode
  2155. left join ICSWarehouse L ON L.ID=J.WHID
  2156. left join ICSInventory o on o.InvCode=b.InvCode where a.LotNo='{0}' and a.WorkPoint='{1}' ";
  2157. sqlInfo = string.Format(sqlInfo, JsonData.Code, JsonData.WorkPoint, JsonData.TransCode);
  2158. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  2159. string jsonInfo = JsonConvert.SerializeObject(table);
  2160. var Pick = JsonConvert.DeserializeObject(jsonInfo); //<List<WMSSourceDocumentModel>>
  2161. cmd.Transaction.Commit();
  2162. return Pick;
  2163. case "委外材料出库":
  2164. sql = @"select
  2165. a.ID,
  2166. f.ContainerCODE,
  2167. f.ContainerName,
  2168. d.InvCode,
  2169. d.InvName,
  2170. d.InvStd,
  2171. h.Quantity,
  2172. d.InvUnit,
  2173. d.AmountUnit,
  2174. i.WarehouseCode,
  2175. i.WarehouseName,
  2176. q.LocationCode,
  2177. q.LocationName,
  2178. b.ProjectCode,
  2179. b.BatchCode,
  2180. b.Version,
  2181. b.Brand,
  2182. t.TransCode,--
  2183. t.TransSequence,--
  2184. c.LotNo,
  2185. b.cFree1,
  2186. b.cFree2,
  2187. b.cFree3,
  2188. b.cFree4,
  2189. b.cFree5,
  2190. b.cFree6,
  2191. b.cFree7,
  2192. b.cFree8,
  2193. b.cFree9,
  2194. b.cFree10,
  2195. c.LotNo
  2196. from {0} a --
  2197. left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
  2198. left join ICSInventoryLot c on c.ID=b.ID and c.WorkPoint=b.WorkPoint--
  2199. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--
  2200. left join ICSContainerLot e on e.LotNo=c.LotNo and e.WorkPoint=c.WorkPoint--
  2201. left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--
  2202. left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
  2203. left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
  2204. left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--
  2205. left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--
  2206. where 1=1 and c.LotNo='{1}' and a.Status='2' and a.IssueCode='{2}'and a.WorkPoint='{3}'";
  2207. sql = string.Format(sql, TransTypeEnum.ICSOIssue, JsonData.Code, JsonData.TransCode, JsonData.WorkPoint);
  2208. break;
  2209. case "杂发单":
  2210. sql = @"select
  2211. a.ID,
  2212. f.ContainerCODE,
  2213. f.ContainerName,
  2214. d.InvCode,
  2215. d.InvName,
  2216. d.InvStd,
  2217. h.Quantity,
  2218. d.InvUnit,
  2219. d.AmountUnit,
  2220. i.WarehouseCode,
  2221. i.WarehouseName,
  2222. q.LocationCode,
  2223. q.LocationName,
  2224. b.ProjectCode,
  2225. b.BatchCode,
  2226. b.Version,
  2227. b.Brand,
  2228. t.TransCode,--
  2229. t.TransSequence,--
  2230. c.LotNo,
  2231. b.cFree1,
  2232. b.cFree2,
  2233. b.cFree3,
  2234. b.cFree4,
  2235. b.cFree5,
  2236. b.cFree6,
  2237. b.cFree7,
  2238. b.cFree8,
  2239. b.cFree9,
  2240. b.cFree10,
  2241. c.LotNo
  2242. from {0} a --
  2243. left join ICSExtension b on a.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
  2244. left join ICSInventoryLot c on c.ID=b.ID and c.WorkPoint=b.WorkPoint--
  2245. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--
  2246. left join ICSContainerLot e on e.LotNo=c.LotNo and e.WorkPoint=c.WorkPoint--
  2247. left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--
  2248. left join ICSWareHouseLotInfo h on h.LotNo=e.LotNo and h.WorkPoint=e.WorkPoint
  2249. left join ICSLocation q on q.LocationCode=h.LocationCode and q.WorkPoint=h.WorkPoint
  2250. left join ICSWarehouse i on i.WarehouseCode=q.WHID and i.WorkPoint=q.WorkPoint--
  2251. left join ICSInventoryLotDetail t on t.LotNo=e.LotNo and t.WorkPoint=e.WorkPoint--
  2252. where 1=1 and c.LotNo='{1}' and a.Status='2' and a.OutCode='{2}' and a.WorkPoint='{3}'";
  2253. sql = string.Format(sql, TransTypeEnum.ICSOtherOut, JsonData.Code, JsonData.TransCode, JsonData.WorkPoint);
  2254. break;
  2255. case "采购退货单":
  2256. sql = @"select a.ID,
  2257. b.InvCode,
  2258. o.InvName,
  2259. o.InvStd,
  2260. a.Quantity ,
  2261. o.InvUnit,
  2262. o.AmountUnit,
  2263. l.WarehouseCode,
  2264. l.WarehouseName,
  2265. j.LocationCode,
  2266. j.LocationName,
  2267. e.ProjectCode,
  2268. e.BatchCode,
  2269. e.Version,
  2270. e.Brand,
  2271. c.TransCode,--
  2272. c.TransSequence,--
  2273. a.LotNo,
  2274. e.cFree1,
  2275. e.cFree2,
  2276. e.cFree3,
  2277. e.cFree4,
  2278. e.cFree5,
  2279. e.cFree6,
  2280. e.cFree7,
  2281. e.cFree8,
  2282. e.cFree9,
  2283. e.cFree10
  2284. from ICSWareHouseLotInfo a
  2285. left join ICSInventoryLot b on a.LotNo=b.LotNo and a.InvCode=b.InvCode
  2286. left join ICSInventoryLotDetail c on c .LotNo=b.LotNo
  2287. left join ICSExtension e on e.id=b.ExtensionID
  2288. left join ICSContainerLot f on f.LotNo=b.LotNo
  2289. left join ICSContainer g on g.ContainerID=f.id
  2290. left join ICSLocation j on j.LocationCode=a.LocationCode
  2291. left join ICSWarehouse L ON L.ID=J.WHID
  2292. left join ICSInventory o on o.InvCode=b.InvCode where a.LotNo='{0}' and a.WorkPoint='{1}'";
  2293. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  2294. table = DBHelper.SQlReturnData(sql, cmd);
  2295. string jsonNotice = JsonConvert.SerializeObject(table);
  2296. var PickNotice = JsonConvert.DeserializeObject(jsonNotice); //<List<WMSSourceDocumentModel>>
  2297. cmd.Transaction.Commit();
  2298. return PickNotice;
  2299. case "两部调出":
  2300. sql = @"select
  2301. a.ID,
  2302. H.ContainerCODE,
  2303. H.ContainerName,
  2304. A.InvCode,
  2305. F.InvName,
  2306. F.InvStd,
  2307. a.Quantity,
  2308. F.InvUnit,
  2309. F.AmountUnit,
  2310. E.ProjectCode,
  2311. E.BatchCode,
  2312. E.Version,
  2313. E.Brand,
  2314. c.OutCode as TransCode,--
  2315. c.Sequence as TransSequence,--
  2316. A.LotNo,
  2317. E.cFree1,
  2318. E.cFree2,
  2319. E.cFree3,
  2320. E.cFree4,
  2321. E.cFree5,
  2322. E.cFree6,
  2323. E.cFree7,
  2324. E.cFree8,
  2325. E.cFree9,
  2326. E.cFree10
  2327. FROM ICSInventoryLot A
  2328. LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
  2329. LEFT JOIN ICSOtherOut C ON b.TransCode=C.OutCode AND C.Sequence=B.TransSequence
  2330. left join ICSTransfer d on d.TransferNO =c.OutCode and d.Sequence=c.Sequence
  2331. LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
  2332. LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
  2333. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  2334. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID
  2335. where a.lotno ='{0}' and a.WorkPoint='{1}' and d.Type='2'";
  2336. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  2337. table = DBHelper.SQlReturnData(sql, cmd);
  2338. if (table.Rows.Count > 0)
  2339. {
  2340. string jsonCode = JsonConvert.SerializeObject(table);
  2341. var modelCode = JsonConvert.DeserializeObject(jsonCode);
  2342. return modelCode;
  2343. }
  2344. else
  2345. {
  2346. throw new Exception("调拨单不存在!");
  2347. }
  2348. case "委外退货单":
  2349. sql = @"select a.ID,
  2350. b.InvCode,
  2351. o.InvName,
  2352. o.InvStd,
  2353. a.Quantity ,
  2354. o.InvUnit,
  2355. o.AmountUnit,
  2356. l.WarehouseCode,
  2357. l.WarehouseName,
  2358. j.LocationCode,
  2359. j.LocationName,
  2360. e.ProjectCode,
  2361. e.BatchCode,
  2362. e.Version,
  2363. e.Brand,
  2364. c.TransCode,--
  2365. c.TransSequence,--
  2366. a.LotNo,
  2367. e.cFree1,
  2368. e.cFree2,
  2369. e.cFree3,
  2370. e.cFree4,
  2371. e.cFree5,
  2372. e.cFree6,
  2373. e.cFree7,
  2374. e.cFree8,
  2375. e.cFree9,
  2376. e.cFree10
  2377. from ICSWareHouseLotInfo a
  2378. left join ICSInventoryLot b on a.LotNo=b.LotNo and a.InvCode=b.InvCode
  2379. left join ICSInventoryLotDetail c on c .LotNo=b.LotNo
  2380. left join ICSExtension e on e.id=b.ExtensionID
  2381. left join ICSContainerLot f on f.LotNo=b.LotNo
  2382. left join ICSContainer g on g.ContainerID=f.id
  2383. left join ICSLocation j on j.LocationCode=a.LocationCode
  2384. left join ICSWarehouse L ON L.ID=J.WHID
  2385. left join ICSInventory o on o.InvCode=b.InvCode where a.LotNo='{0}' and a.WorkPoint='{1}'";
  2386. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  2387. table = DBHelper.SQlReturnData(sql, cmd);
  2388. string jsonOrder = JsonConvert.SerializeObject(table);
  2389. var PickOrder = JsonConvert.DeserializeObject(jsonOrder); //<List<WMSSourceDocumentModel>>
  2390. cmd.Transaction.Commit();
  2391. return PickOrder;
  2392. case "其它出库":
  2393. bool Zero = verification.isStockZero(JsonData.Code, JsonData.WorkPoint);
  2394. if (Zero == true)
  2395. {
  2396. bool ZeroCode = verification.iSNullLocationCode(JsonData.Code, JsonData.WorkPoint);
  2397. if (ZeroCode == true)
  2398. {
  2399. sql = @"select
  2400. f.ContainerCODE,
  2401. f.ContainerName,
  2402. d.InvCode,
  2403. d.InvName,
  2404. d.InvStd,
  2405. a.Quantity,
  2406. d.InvUnit,
  2407. d.AmountUnit,
  2408. i.WarehouseCode,
  2409. i.WarehouseName,
  2410. q.LocationCode,
  2411. q.LocationName,
  2412. b.ProjectCode,
  2413. b.BatchCode,
  2414. b.Version,
  2415. b.Brand,
  2416. t.TransCode,--
  2417. t.TransSequence,--
  2418. a.LotNo,
  2419. b.cFree1,
  2420. b.cFree2,
  2421. b.cFree3,
  2422. b.cFree4,
  2423. b.cFree5,
  2424. b.cFree6,
  2425. b.cFree7,
  2426. b.cFree8,
  2427. b.cFree9,
  2428. b.cFree10
  2429. from ICSWareHouseLotInfo a
  2430. left join ICSInventoryLot h on a.LotNo=h.LotNo
  2431. left join ICSExtension b on h.ExtensionID=b.ID and a.WorkPoint=b.WorkPoint
  2432. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint--
  2433. left join ICSContainerLot e on e.LotNo=a.LotNo and e.WorkPoint=a.WorkPoint--
  2434. left join ICSContainer f on f.ContainerID= e.ID and f.WorkPoint=e.WorkPoint--
  2435. left join ICSLocation q on q.LocationCode=a.LocationCode and q.WorkPoint=a.WorkPoint
  2436. left join ICSWarehouse i on i.ID=q.WHID and i.WorkPoint=q.WorkPoint--
  2437. left join ICSInventoryLotDetail t on t.LotNo=a.LotNo and t.WorkPoint=a.WorkPoint--
  2438. where a.lotno='{0}' and a.WorkPoint='{1}'";
  2439. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  2440. table = DBHelper.SQlReturnData(sql, cmd);
  2441. string jsonCode = JsonConvert.SerializeObject(table);
  2442. var modelCode = JsonConvert.DeserializeObject(jsonCode);
  2443. return modelCode;
  2444. }
  2445. }
  2446. break;
  2447. }
  2448. sql = string.Format(sql, JsonData.Code);
  2449. table = DBHelper.SQlReturnData(sql, cmd);
  2450. string json = JsonConvert.SerializeObject(table);
  2451. var model = JsonConvert.DeserializeObject(json); //<List<WMSSourceDocumentModel>>
  2452. cmd.Transaction.Commit();
  2453. return model;
  2454. }
  2455. catch (Exception ex)
  2456. {
  2457. // cmd.Transaction.Rollback();
  2458. log.Error(ex.Message);
  2459. throw new Exception(ex.Message);
  2460. }
  2461. finally
  2462. {
  2463. if (conn.State == ConnectionState.Open)
  2464. {
  2465. conn.Close();
  2466. }
  2467. conn.Dispose();
  2468. }
  2469. }
  2470. #endregion
  2471. #region 上架
  2472. /// <summary>
  2473. /// 上架查询
  2474. /// </summary>
  2475. /// <returns></returns>
  2476. public object LOTStockUpGet(WMSTBarCodeModel JsonData)
  2477. {
  2478. //WMSTBarCodeModelInfo model = new WMSTBarCodeModelInfo();
  2479. conn.Open();
  2480. SqlTransaction sqlTran = conn.BeginTransaction();
  2481. SqlCommand cmd = new SqlCommand();
  2482. cmd.Transaction = sqlTran;
  2483. cmd.Connection = conn;
  2484. try
  2485. {
  2486. sql = @"SELECT
  2487. b.ID,
  2488. b.InvCode,
  2489. b.Quantity,
  2490. b.AmountRate,
  2491. a.TransCode,
  2492. a.TransSequence,
  2493. a.LotNo,
  2494. d.WarehouseCode,
  2495. d.WarehouseName,
  2496. e.LocationCode,
  2497. e.LocationName,
  2498. b.Type,
  2499. a.MUSER,
  2500. a.MTIME
  2501. from ICSInventoryLotDetail a
  2502. left join ICSInventoryLot b on a.LotNo=b.LotNo
  2503. left join ICSWareHouseLotInfo c on a.LotNo=c.LotNo
  2504. left join ICSWarehouse d on d.WarehouseCode=c.WarehouseCode
  2505. left join ICSLocation e on e.LocationCode=c.LocationCode where 1=1";
  2506. if (!string.IsNullOrEmpty(JsonData.TransCode))
  2507. {
  2508. sql += " and a.TransCode='{0}'";
  2509. sql = string.Format(sql, JsonData.TransCode);
  2510. }
  2511. if (!string.IsNullOrEmpty(JsonData.User))
  2512. {
  2513. sql += " and MUSER='{1}'";
  2514. sql = string.Format(sql, JsonData.User);
  2515. }
  2516. if (JsonData.MTime.ToString() != "0001/1/1 0:00:00")
  2517. {
  2518. sql += " and MTIME='{2}'";
  2519. sql = string.Format(sql, JsonData.MTime);
  2520. }
  2521. table = DBHelper.SQlReturnData(sql, cmd);
  2522. string json = JsonConvert.SerializeObject(table);
  2523. var model = JsonConvert.DeserializeObject(json);
  2524. //model = JsonConvert.DeserializeObject<WMSTBarCodeModelInfo>(json);//<List<WMSSourceDocumentModel>>
  2525. cmd.Transaction.Commit();
  2526. return model;
  2527. }
  2528. catch (Exception ex)
  2529. {
  2530. cmd.Transaction.Rollback();
  2531. log.Error(ex.Message);
  2532. throw new Exception(ex.Message);
  2533. }
  2534. finally
  2535. {
  2536. if (conn.State == ConnectionState.Open)
  2537. {
  2538. conn.Close();
  2539. }
  2540. conn.Dispose();
  2541. }
  2542. }
  2543. /// <summary>
  2544. /// 上架增加
  2545. /// </summary>BusinessCode,TransType 两个类型
  2546. /// <param name="JsonData"></param>
  2547. /// <returns></returns>
  2548. public List<LOTStockUpCreateIModel> LOTStockCreate(List<LOTStockUpCreateIModel> JsonData)
  2549. {
  2550. List<LOTStockUpCreateIModel> model = new List<LOTStockUpCreateIModel>();
  2551. List<PurchaseReceiveDoc> mddelInfo = new List<PurchaseReceiveDoc>();
  2552. conn.Open();
  2553. SqlTransaction sqlTran = conn.BeginTransaction();
  2554. SqlCommand cmd = new SqlCommand();
  2555. cmd.Transaction = sqlTran;
  2556. cmd.Connection = conn;
  2557. int num = 0;
  2558. int numInfo = 0;
  2559. DataTable tableInfo = null;
  2560. string sqlERP = string.Empty;//ERP的表头
  2561. string sqlERPDetil = string.Empty;//ERP的表体
  2562. string jsonERP = string.Empty;///erpjson
  2563. string IstrErp = string.Empty;
  2564. string iresult = string.Empty;//接口调用
  2565. try
  2566. {
  2567. foreach (var item in JsonData)
  2568. {
  2569. foreach (var itemInfo in item.detail)
  2570. {
  2571. int i = 1;
  2572. switch (item.TransType)
  2573. {
  2574. case "委外退料单":
  2575. // string neg = verification.HouseLotoOut(itemInfo.LotNo, item.WorkPoint);
  2576. //if (neg == null)
  2577. //{
  2578. string numNegDetaill = @"select * from ICSOApplyNegDetail where OApplyNegCode='{0}'and Sequence='{1}' and WorkPoint='{2}' ";
  2579. numNegDetaill = string.Format(numNegDetaill, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint);
  2580. DataTable numNegDetailwl = DBHelper.SQlReturnData(numNegDetaill, cmd);
  2581. foreach (DataRow itemDetail in numNegDetailwl.Rows)
  2582. {
  2583. double Quantity = Convert.ToDouble(itemInfo.Quantity);///输入数量
  2584. double IssueNegQuantity = Convert.ToDouble(itemDetail["IssueNegQuantity"]);//已退数量
  2585. double NegQuantity = Quantity + IssueNegQuantity;//总数量(输入数量+已退数量)
  2586. double QuantityPla = Convert.ToDouble(itemDetail["Quantity"]);//计划数量
  2587. if (QuantityPla >= NegQuantity)
  2588. {
  2589. string NegDetailSql = @"update ICSOApplyNegDetail set IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{3}'
  2590. , MUSER='{4}' ,MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{4}' and F_Location='{2}'), MTIME=GETDATE()
  2591. where OApplyNegCode='{0}' and Sequence='{1}' and WorkPoint='{2}' ";
  2592. NegDetailSql = string.Format(NegDetailSql, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint, itemInfo.Quantity, item.User);
  2593. if (!DBHelper.ExecuteNonQuery(NegDetailSql, cmd))
  2594. {
  2595. throw new Exception("委外退料单更新失败!");
  2596. }
  2597. ///添加库存
  2598. string HouseLotSql = @" insert into ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2599. (select newid(),'{0}' ,a.WHCode,isnull((f.LocationCode),0) ,b.InvCode ,'{1}','{2}','0','{3}' ,g.F_RealName ,'{4}' ,'{5}' ,' '
  2600. from ICSOApplyNeg a --退
  2601. inner join ICSOApplyNegDetail b on a.OApplyNegCode=b.OApplyNegCode and a.WorkPoint=b.WorkPoint --退
  2602. left join ICSInventoryLotDetail c on b.OApplyNegCode=c.TransCode and c.TransSequence=b.Sequence AND b.WorkPoint=c.WorkPoint--
  2603. left join ICSInventoryLot d on c.LOTNO=d.LotNO and d.WorkPoint=c.WorkPoint --
  2604. left join ICSWarehouse e on e.WarehouseCode=a.WHCode and e.WorkPoint=a.WorkPoint--
  2605. left join ICSLocation f on f.WHID=e.ID and f.WorkPoint=e.WorkPoint--
  2606. left join Sys_SRM_User g on g.F_Account='{3}' and F_Location='{5}' --
  2607. where a.OApplyNegCode='{6}' and a. WorkPoint='{5}')";
  2608. HouseLotSql = string.Format(HouseLotSql, itemInfo.LotNo, itemInfo.Quantity, DateTime.Now, item.User, DateTime.Now, item.WorkPoint, itemInfo.TransCode);
  2609. if (!DBHelper.ExecuteNonQuery(HouseLotSql, cmd))
  2610. {
  2611. throw new Exception("委外退料单库存更新失败!");
  2612. }
  2613. ///添加日志
  2614. string sqlLogInfo = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  2615. ([ID]
  2616. ,[TransCode]
  2617. ,[TransSequence]
  2618. ,[LotNo]
  2619. ,[InvCode]
  2620. ,[FromWarehouseCode]
  2621. ,[FromLocationCode]
  2622. ,[ToWarehouseCode]
  2623. ,[ToLocationCode]
  2624. ,[Quantity]
  2625. ,[Memo]
  2626. ,[Lock]
  2627. ,[TransType]
  2628. ,[BusinessCode]
  2629. ,[ERPID]
  2630. ,[ERPDetailID]
  2631. ,[ERPCode]
  2632. ,[ERPSequence]
  2633. ,[MUSER]
  2634. ,[MUSERName]
  2635. ,[MTIME]
  2636. ,[WorkPoint]
  2637. ,[EATTRIBUTE1])
  2638. (select newid(),'{0}','{1}','{2}',b.InvCode ,' ', ' ',a.WHCode,d.LocationCode,'{3}',' ','0','2','8',' ',' ',' ',' ','{4}',e.F_RealName,'{5}','{6}',' '
  2639. from ICSOApplyNeg a--
  2640. inner join ICSOApplyNegDetail b on a.OApplyNegCode=b.OApplyNegCode --
  2641. left join ICSWarehouse c on c.WarehouseCode=a.WHCode and c.WorkPoint=a.WorkPoint--
  2642. left join ICSLocation d on d.WHID=c.ID and d.WorkPoint=c.WorkPoint--
  2643. left join Sys_SRM_User e on e.F_Account='{4}' and e.F_Location='{6}'
  2644. where a.OApplyNegCode='{0}' and a. WorkPoint='{6}')";
  2645. sqlLogInfo = string.Format(sqlLogInfo, itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.User, DateTime.Now, item.WorkPoint);
  2646. cmd.CommandText = sqlLogInfo;
  2647. int numInfoLot = cmd.ExecuteNonQuery();
  2648. if (numInfoLot > 0)
  2649. {
  2650. cmd.Transaction.Commit();
  2651. }
  2652. else
  2653. {
  2654. cmd.Transaction.Rollback();
  2655. }
  2656. }
  2657. else
  2658. {
  2659. throw new Exception("已退数量不能大于计划数量!");
  2660. }
  2661. }
  2662. #region ERP
  2663. string sqlERPOOPick = @" select DepCode,FromWarehouseCode,OOCode,a.MUSER , (getdate())as Mtime from ICSWareHouseLotInfoLog a
  2664. left join ICSOutsourcingOrder b on b.OOCode=a.TransCode and a.TransSequence=b.Sequence
  2665. left join ICSOOPick c on b.OODetailID=c.OODetailID
  2666. where OOCode='{0}' and b.WorkPoint='{1}'
  2667. group by DepCode,FromWarehouseCode,OOCode,a.MUSER ";
  2668. sqlERPOOPick = string.Format(sqlERPOOPick, itemInfo.TransCode, item.WorkPoint);
  2669. table = DBHelper.SQlReturnData(sqlERPOOPick, cmd);
  2670. string sqlERPPickList = @"select a.TransCode, a.TransSequence,a.InvCode,sum(a.Quantity) as Quantity , isnull((b.Amount),0)as Amount,c.PickID from ICSWareHouseLotInfoLog a
  2671. left JOIN ICSOutsourcingOrder B on b.OOCode=a.TransCode and a.TransSequence=b.Sequence
  2672. left join ICSOOPick C on C.OODetailID=B.OODetailID and c.Sequence=a.TransSequence
  2673. where lotno='{0}' and a.Memo<>'1'
  2674. group by a.TransCode, a.TransSequence,a.InvCode,b.Amount ,c.PickID ";
  2675. sqlERPPickList = string.Format(sqlERPPickList, itemInfo.LotNo);
  2676. DataTable ERPOOPick = DBHelper.SQlReturnData(sqlERPPickList, cmd);
  2677. string jsonPickList = null;
  2678. List<IssueDoc> docPickmodel = new List<IssueDoc>();
  2679. foreach (DataRow dts in table.Rows)
  2680. {
  2681. IssueDoc doc = new IssueDoc();
  2682. doc.DepCode = dts["DepCode"].ToString();
  2683. doc.WHCode = dts["FromWarehouseCode"].ToString();
  2684. doc.SourceType = "委外退料";
  2685. doc.SourceCode = dts["OOCode"].ToString();
  2686. doc.User = dts["MUSER"].ToString();
  2687. doc.User = dts["Mtime"].ToString();
  2688. // doc.MTime = DateTime.Now;
  2689. List<IssueDocList> list = new List<IssueDocList>();
  2690. foreach (DataRow dtList in ERPOOPick.Rows)
  2691. {
  2692. IssueDocList docc = new IssueDocList();
  2693. docc.Sequence = dtList["TransSequence"].ToString();
  2694. docc.InvCode = dtList["InvCode"].ToString();
  2695. docc.Quantity = dtList["Quantity"].ToString();
  2696. docc.Amount = dtList["Amount"].ToString();
  2697. docc.SourceDetailID = dtList["PickID"].ToString();
  2698. list.Add(docc);
  2699. }
  2700. doc.details = list;
  2701. docPickmodel.Add(doc);
  2702. //jsonList = JsonConvert.SerializeObject(doc);
  2703. }
  2704. string IstrPick = JsonConvert.SerializeObject(docPickmodel);
  2705. string iresultPick = HttpPost("委外退料", ERPUrl.OutsourcingIssueDoNegativeURL, IstrPick);
  2706. Result OtherOutResultpick = new Result();
  2707. OtherOutResultpick = JsonConvert.DeserializeObject<Result>(iresultPick);
  2708. ERPJsonRetun m = new ERPJsonRetun();
  2709. if (OtherOutResultpick.Success == true)
  2710. {
  2711. string nn = OtherOutResultpick.Data.ToString();//LOTStockModel
  2712. m = JsonConvert.DeserializeObject<ERPJsonRetun>(nn);
  2713. string ERPupdate = @"update ICSWareHouseLotInfoLog set ERPID='{0}',ERPDetailID='{1}',ERPCode='{2}',ERPSequence='{3}',Memo='1'
  2714. where TransCode='{4}' and TransSequence ='{5}'";
  2715. ERPupdate = string.Format(ERPupdate, m.ID, m.DetailID, m.RCVNEGCode, m.Sequence, itemInfo.TransCode, itemInfo.TransSequence);
  2716. cmd.CommandText = ERPupdate;
  2717. num = cmd.ExecuteNonQuery();
  2718. if (num > 0)
  2719. {
  2720. cmd.Transaction.Commit();
  2721. }
  2722. else
  2723. {
  2724. cmd.Transaction.Rollback();
  2725. }
  2726. }
  2727. else
  2728. {
  2729. cmd.Transaction.Rollback();
  2730. throw new Exception(OtherOutResultpick.Message);
  2731. }
  2732. #endregion
  2733. //}
  2734. return null;
  2735. case "采购入库":
  2736. //添加采购入库
  2737. sql = @"update ICSPurchaseOrder set RCVQuantity= RCVQuantity+(select Quantity from ICSInventoryLot where lontno='{0}' ,MTIME='{1}' where RCVCod='{2}' and InvCode=(select InvCode from ICSInventoryLot where lontno='{0}' ),and WorkPoint='{3}')";
  2738. sql = string.Format(sql, itemInfo.LotNo, DateTime.Now, itemInfo.TransCode, item.WorkPoint);
  2739. cmd.CommandText = sql;
  2740. int Purchase = cmd.ExecuteNonQuery();
  2741. cmd.Transaction.Commit();
  2742. //记录日志
  2743. if (Purchase > 0)
  2744. {
  2745. string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  2746. ([ID]
  2747. ,[TransCode]
  2748. ,[TransSequence]
  2749. ,[LotNo]
  2750. ,[InvCode]
  2751. ,[FromWarehouseCode]
  2752. ,[FromLocationCode]
  2753. ,[ToWarehouseCode]
  2754. ,[ToLocationCode]
  2755. ,[Quantity]
  2756. ,[Memo]
  2757. ,[Lock]
  2758. ,[TransType]
  2759. ,[BusinessCode]
  2760. ,[ERPID]
  2761. ,[ERPDetailID]
  2762. ,[ERPCode]
  2763. ,[ERPSequence]
  2764. ,[MUSER]
  2765. ,[MUSERName]
  2766. ,[MTIME]
  2767. ,[WorkPoint]
  2768. ,[EATTRIBUTE1])
  2769. VALUES
  2770. (newid()
  2771. ,'{4}'
  2772. ,''
  2773. ,'{0}'
  2774. ,(SELECT InvCode FROM ICSMO WHERE MOCode='{5}')
  2775. ,(SELECT WarehouseCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
  2776. ,(SELECT LocationCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
  2777. ,''
  2778. ,''
  2779. ,(SELECT Quantity FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
  2780. ,''
  2781. ,''
  2782. ,'1'
  2783. ,''
  2784. ,''
  2785. ,''
  2786. ,''
  2787. ,''
  2788. ,'{1}'
  2789. ,'{1}'
  2790. ,'{2}'
  2791. ,'{3}'
  2792. ,'')";
  2793. sqlLog = string.Format(sqlLog, itemInfo.LotNo, item.User, DateTime.Now, item.WorkPoint, itemInfo.TransCode);
  2794. DBHelper.CmdExecuteNonQuery(sqlLog, cmd, "成功");
  2795. cmd.Transaction.Commit();
  2796. }
  2797. //生产erp订单
  2798. return null;
  2799. case "销售退货":
  2800. string Date = DateTime.Now.ToString("yy");
  2801. string Pre = "CHK" + i + Date;//库存盘点单号
  2802. #region 添加到库存表/日志表
  2803. ///验证条码是否存在或者是否上架
  2804. sqlInfo = @"select * from ICSInventoryLot where LotNo='{0}'";
  2805. sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
  2806. cmd.CommandText = sqlInfo;
  2807. table = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
  2808. if (table.Rows.Count <= 0)
  2809. {
  2810. throw new Exception("条码不存在!");
  2811. }
  2812. string sqlll = @"select * from ICSWareHouseLotInfo where LotNo='{0}'";
  2813. sqlll = string.Format(sqlInfo, itemInfo.LotNo);
  2814. cmd.CommandText = sqlll;
  2815. DataTable dataTex = DBHelper.SQlReturnData(sqlll, cmd);//返回条数
  2816. if (dataTex.Rows.Count <= 0)
  2817. {
  2818. throw new Exception("条码已上架!");
  2819. }
  2820. sqlInfo = @"select * from ICSSDN where SDNCode='{0}' and Status='3' and Type='2'";
  2821. sqlInfo = string.Format(sqlInfo, itemInfo.TransCode);
  2822. cmd.CommandText = sqlInfo;
  2823. tableInfo = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
  2824. if (tableInfo.Rows.Count > 0)
  2825. {
  2826. throw new Exception("销售订单已经关闭!或退货不存在");
  2827. }
  2828. else
  2829. {
  2830. sql = @"update ICSSDN set SDNQuantity= SDNQuantity + Quantity ,MTIME='{1}' where SDNCode ='{2}' and InvCode=(select InvCode from ICSInventoryLot where lotno='{0}' ) and WorkPoint='{3}'";
  2831. sql = string.Format(sql, itemInfo.LotNo, DateTime.Now, itemInfo.TransCode, item.WorkPoint, itemInfo.Quantity);
  2832. cmd.CommandText = sql;
  2833. int ApplyNeg = cmd.ExecuteNonQuery();
  2834. // cmd.Transaction.Commit();
  2835. string sqlLotInfo = @" INSERT INTO[ICSWareHouseLotInfo]
  2836. ([ID]
  2837. ,[LotNo]
  2838. ,[WarehouseCode]
  2839. ,[LocationCode]
  2840. ,[InvCode]
  2841. ,[Quantity]
  2842. ,[InDate]
  2843. ,[LockQuantity]
  2844. ,[MUSER]
  2845. ,[MUSERName]
  2846. ,[MTIME]
  2847. ,[WorkPoint]
  2848. ,[EATTRIBUTE1])
  2849. VALUES
  2850. (newid()
  2851. , '{0}'
  2852. , (select WarehouseCode from ICSWarehouse a left join ICSLocation b on a.ID = b.WHID WHERE LocationCode = '{1}')
  2853. ,'{1}'
  2854. ,(SELECT InvCode FROM ICSInventoryLot WHERE LotNo = '{0}')
  2855. ,'{6}'
  2856. ,'{5}'
  2857. ,0
  2858. ,'{2}'
  2859. ,'{2}'
  2860. ,'{3}'
  2861. ,'{4}'
  2862. ,'')";
  2863. sqlLotInfo = string.Format(sqlLotInfo, itemInfo.LotNo, itemInfo.LocationCode, item.User, DateTime.Now, item.WorkPoint, item.MTime, itemInfo.Quantity);
  2864. DBHelper.CmdExecuteNonQuery(sqlLotInfo, cmd, "成功");
  2865. //cmd.Transaction.Commit();
  2866. string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  2867. ([ID]
  2868. ,[TransCode]
  2869. ,[TransSequence]
  2870. ,[LotNo]
  2871. ,[InvCode]
  2872. ,[FromWarehouseCode]
  2873. ,[FromLocationCode]
  2874. ,[ToWarehouseCode]
  2875. ,[ToLocationCode]
  2876. ,[Quantity]
  2877. ,[Memo]
  2878. ,[Lock]
  2879. ,[TransType]
  2880. ,[BusinessCode]
  2881. ,[ERPID]
  2882. ,[ERPDetailID]
  2883. ,[ERPCode]
  2884. ,[ERPSequence]
  2885. ,[MUSER]
  2886. ,[MUSERName]
  2887. ,[MTIME]
  2888. ,[WorkPoint]
  2889. ,[EATTRIBUTE1])
  2890. VALUES
  2891. (newid()
  2892. ,'{4}'
  2893. ,' '
  2894. ,'{0}'
  2895. ,(SELECT InvCode FROM ICSInventoryLot WHERE LotNo='{0}')
  2896. ,(SELECT WarehouseCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
  2897. ,(SELECT LocationCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
  2898. ,''
  2899. ,''
  2900. ,(SELECT Quantity FROM ICSInventoryLot WHERE LotNo='{0}')
  2901. ,''
  2902. ,''
  2903. ,'21'
  2904. ,''
  2905. ,''
  2906. ,''
  2907. ,''
  2908. ,''
  2909. ,'{1}'
  2910. ,'{1}'
  2911. ,'{2}'
  2912. ,'{3}'
  2913. ,'')";
  2914. sqlLog = string.Format(sqlLog, itemInfo.LotNo, item.User, DateTime.Now, item.WorkPoint, itemInfo.TransCode);
  2915. DBHelper.CmdExecuteNonQuery(sqlLog, cmd, "成功");
  2916. cmd.Transaction.Commit();
  2917. #region ERP接口
  2918. string ERPSnd = @"select A.CusCode,A.SOCode ,B.MUSER,MAX(B.MTIME) AS MTIME,b.TransSequence,b.TransCode,B.InvCode,b.FromWarehouseCode FROM ICSSDN a
  2919. inner join ICSWareHouseLotInfoLog b on a.SDNCode=b.TransCode and b.TransSequence=a.Sequence
  2920. where a.Type='2' and b.TransCode='{0}' and b.WorkPoint='{1}'
  2921. group by A.CusCode,A.SOCode ,B.MUSER,b.TransSequence,b.TransCode,B.InvCode,b.FromWarehouseCode";
  2922. ERPSnd = string.Format(ERPSnd, itemInfo.TransCode, item.WorkPoint);
  2923. table = DBHelper.SQlReturnData(ERPSnd, cmd);
  2924. string ERPSndList = @"select a.TransSequence,b.InvCode,sum(a.Quantity) as Quantity , isnull((b.Amount),0)as Amount ,b.SDNDetailID from ICSWareHouseLotInfoLog a
  2925. inner JOIN ICSSDN B ON b.SDNCode=a.TransCode and a.TransSequence=b.Sequence
  2926. where a.LotNo='{0}' and a.Memo<>'1' and b.WorkPoint='{1}' and b.Type='2'
  2927. group by a.TransSequence,b.InvCode, Amount ,b.SDNDetailID";
  2928. ERPSndList = string.Format(ERPSndList, itemInfo.LotNo, item.WorkPoint);
  2929. DataTable SDNNEG = DBHelper.SQlReturnData(ERPSndList, cmd);
  2930. List<ERPICSSDN> ERPSDNNEG = new List<ERPICSSDN>();
  2931. foreach (DataRow itemNotice in table.Rows)
  2932. {
  2933. ERPICSSDN noticeModel = new ERPICSSDN();
  2934. noticeModel.CusCode = itemNotice["CusCode"].ToString();
  2935. noticeModel.WHCode = itemNotice["FromWarehouseCode"].ToString();
  2936. noticeModel.SDNRTCode = itemNotice["SOCode"].ToString();
  2937. noticeModel.User = itemNotice["MUSER"].ToString();
  2938. noticeModel.MTime = itemNotice["MTIME"].ToString();
  2939. List<ERPICSSDNList> noticeModelList = new List<ERPICSSDNList>();
  2940. foreach (DataRow ERPNoticeList in SDNNEG.Rows)
  2941. {
  2942. ERPICSSDNList listInfo = new ERPICSSDNList();
  2943. listInfo.Sequence = ERPNoticeList["TransSequence"].ToString();
  2944. listInfo.InvCode = ERPNoticeList["InvCode"].ToString();
  2945. listInfo.Quantity = ERPNoticeList["Quantity"].ToString();
  2946. listInfo.Amount = ERPNoticeList["Amount"].ToString();
  2947. listInfo.SDNDetailID = ERPNoticeList["SDNDetailID"].ToString();
  2948. noticeModelList.Add(listInfo);
  2949. }
  2950. noticeModel.details = noticeModelList;
  2951. ERPSDNNEG.Add(noticeModel);
  2952. string ERPICSSDN = JsonConvert.SerializeObject(ERPSDNNEG);
  2953. string Emoiresultsdn = HttpPost("红字销售出库单", ERPUrl.SalesDeliveryNoticeURL, ERPICSSDN);
  2954. Result OtherOutI = new Result();
  2955. OtherOutI = JsonConvert.DeserializeObject<Result>(Emoiresultsdn);
  2956. if (OtherOutI.Message != "200")
  2957. {
  2958. throw new Exception(OtherOutI.Message);
  2959. }
  2960. else
  2961. {
  2962. //OtherOutResult.Data;
  2963. }
  2964. }
  2965. #endregion
  2966. }
  2967. #endregion
  2968. return null;
  2969. case "生产退库":
  2970. #region 添加到库存表/日志表
  2971. sqlInfo = @"select * from ICSLocation where LocationCode='{0}'";
  2972. sqlInfo = string.Format(sqlInfo, itemInfo.LocationCode);
  2973. cmd.CommandText = sqlInfo;
  2974. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  2975. if (table.Rows.Count <= 0)
  2976. {
  2977. throw new Exception("库位不存在!");
  2978. }
  2979. ///验证条码是否存在或者是否上架
  2980. sqlInfo = @"select * from ICSInventoryLot where LotNo='{0}'";
  2981. sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
  2982. cmd.CommandText = sqlInfo;
  2983. table = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
  2984. if (table.Rows.Count <= 0)
  2985. {
  2986. throw new Exception("条码不存在!");
  2987. }
  2988. sqlInfo = @"select * from ICSWareHouseLotInfo where LotNo='{0}'";
  2989. sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
  2990. cmd.CommandText = sqlInfo;
  2991. tableInfo = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
  2992. if (tableInfo.Rows.Count > 0)
  2993. {
  2994. throw new Exception("条码已经上架!");
  2995. }
  2996. else
  2997. {
  2998. sql = @"update ICSMOApplyNegDetail set IssueNegQuantity= IssueNegQuantity + (select Quantity from ICSInventoryLot where lotno='{0}' ) ,MTIME='{1}' where ApplyNegCode ='{2}' and InvCode=(select InvCode from ICSInventoryLot where lotno='{0}' ) and WorkPoint='{3}'";
  2999. sql = string.Format(sql, itemInfo.LotNo, DateTime.Now, itemInfo.TransCode, item.WorkPoint);
  3000. cmd.CommandText = sql;
  3001. int ApplyNeg = cmd.ExecuteNonQuery();
  3002. sql = @" INSERT INTO [ICSWareHouseLotInfo]
  3003. ([ID]
  3004. ,[LotNo]
  3005. ,[WarehouseCode]
  3006. ,[LocationCode]
  3007. ,[InvCode]
  3008. ,[Quantity]
  3009. ,[InDate]
  3010. ,[LockQuantity]
  3011. ,[MUSER]
  3012. ,[MUSERName]
  3013. ,[MTIME]
  3014. ,[WorkPoint]
  3015. ,[EATTRIBUTE1])
  3016. VALUES
  3017. (newid()
  3018. ,'{0}'
  3019. ,(select WarehouseCode from ICSWarehouse a left join ICSLocation b on a.ID =b.WHID WHERE LocationCode='{1}')
  3020. ,'{1}'
  3021. ,(SELECT InvCode FROM ICSInventoryLot WHERE LotNo='{0}')
  3022. ,(SELECT Quantity FROM ICSInventoryLot WHERE LotNo='{0}')
  3023. ,'{5}'
  3024. ,0
  3025. ,'{2}'
  3026. ,'{2}'
  3027. ,'{3}'
  3028. ,'{4}'
  3029. ,'')";
  3030. sql = string.Format(sql, itemInfo.LotNo, itemInfo.LocationCode, item.User, item.MTime, item.WorkPoint, DateTime.Now);
  3031. cmd.CommandText = sql;
  3032. numInfo = cmd.ExecuteNonQuery();
  3033. //cmd.Transaction.Commit();
  3034. if (numInfo > 0)
  3035. {
  3036. string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  3037. ([ID]
  3038. ,[TransCode]
  3039. ,[TransSequence]
  3040. ,[LotNo]
  3041. ,[InvCode]
  3042. ,[FromWarehouseCode]
  3043. ,[FromLocationCode]
  3044. ,[ToWarehouseCode]
  3045. ,[ToLocationCode]
  3046. ,[Quantity]
  3047. ,[Memo]
  3048. ,[Lock]
  3049. ,[TransType]
  3050. ,[BusinessCode]
  3051. ,[ERPID]
  3052. ,[ERPDetailID]
  3053. ,[ERPCode]
  3054. ,[ERPSequence]
  3055. ,[MUSER]
  3056. ,[MUSERName]
  3057. ,[MTIME]
  3058. ,[WorkPoint]
  3059. ,[EATTRIBUTE1])
  3060. VALUES
  3061. (newid()
  3062. ,'{4}'
  3063. ,' '
  3064. ,'{0}'
  3065. ,(SELECT InvCode FROM ICSInventoryLot WHERE LotNo='{0}')
  3066. ,(SELECT WarehouseCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
  3067. ,(SELECT LocationCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
  3068. ,''
  3069. ,''
  3070. ,(SELECT Quantity FROM ICSInventoryLot WHERE LotNo='{0}')
  3071. ,''
  3072. ,''
  3073. ,'21'
  3074. ,''
  3075. ,''
  3076. ,''
  3077. ,''
  3078. ,''
  3079. ,'{1}'
  3080. ,'{1}'
  3081. ,'{2}'
  3082. ,'{3}'
  3083. ,'')";
  3084. sqlLog = string.Format(sqlLog, itemInfo.LotNo, item.User, DateTime.Now, item.WorkPoint, itemInfo.TransCode);
  3085. DBHelper.CmdExecuteNonQuery(sqlLog, cmd, "成功");
  3086. cmd.Transaction.Commit();
  3087. }
  3088. }
  3089. #endregion
  3090. return null;
  3091. case "采购订单":
  3092. ///验证订单是否关闭
  3093. string sqlTYPE = @"SELECT * FROM ICSPurchaseOrder WHERE POCode='{0}' AND WorkPoint='{1}' AND Status='3'";
  3094. sqlTYPE = string.Format(sqlTYPE, itemInfo.TransCode, item.WorkPoint);
  3095. DataTable dtType = DBHelper.SQlReturnData(sqlTYPE, cmd);
  3096. if (dtType.Rows.Count <= 0)
  3097. {
  3098. #region 添加到库存表/日志表
  3099. sqlInfo = @"select * from ICSLocation where LocationCode='{0}'";
  3100. sqlInfo = string.Format(sqlInfo, itemInfo.LocationCode);
  3101. cmd.CommandText = sqlInfo;
  3102. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  3103. if (table.Rows.Count <= 0)
  3104. {
  3105. throw new Exception("库位不存在!");
  3106. }
  3107. ///验证条码是否存在或者是否上架
  3108. sqlInfo = @"select * from ICSInventoryLot where LotNo='{0}'";
  3109. sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
  3110. cmd.CommandText = sqlInfo;
  3111. table = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
  3112. if (table.Rows.Count <= 0)
  3113. {
  3114. throw new Exception("条码不存在!");
  3115. }
  3116. sqlInfo = @"select * from ICSWareHouseLotInfo where LotNo='{0}'";
  3117. sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
  3118. cmd.CommandText = sqlInfo;
  3119. tableInfo = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
  3120. if (tableInfo.Rows.Count > 0)
  3121. {
  3122. throw new Exception("条码已经上架!");
  3123. }
  3124. else
  3125. {
  3126. sql = @"update ICSPurchaseOrder set InQuantity= InQuantity + (select Quantity from ICSInventoryLot where lotno='{0}' ) ,MTIME='{1}' where POCode ='{2}' and InvCode=(select InvCode from ICSInventoryLot where lotno='{0}' ) and WorkPoint='{3}'";
  3127. sql = string.Format(sql, itemInfo.LotNo, DateTime.Now, itemInfo.TransCode, item.WorkPoint);
  3128. cmd.CommandText = sql;
  3129. int PurchaseList = cmd.ExecuteNonQuery();
  3130. if (PurchaseList > 0)
  3131. {
  3132. sql = @" INSERT INTO [ICSWareHouseLotInfo]
  3133. ([ID]
  3134. ,[LotNo]
  3135. ,[WarehouseCode]
  3136. ,[LocationCode]
  3137. ,[InvCode]
  3138. ,[Quantity]
  3139. ,[InDate]
  3140. ,[LockQuantity]
  3141. ,[MUSER]
  3142. ,[MUSERName]
  3143. ,[MTIME]
  3144. ,[WorkPoint]
  3145. ,[EATTRIBUTE1])
  3146. (select newid(),'{0}' ,e.WarehouseCode,isnull((f.LocationCode),0) ,a.InvCode ,'{1}','{2}','0','{3}' ,g.F_RealName ,'{4}' ,'{5}' ,' '
  3147. from ICSPurchaseOrder a
  3148. left join ICSLocation f on LocationCode='{8}'
  3149. left join ICSWarehouse e on e.id=(select WHID from ICSLocation where LocationCode='{8}')
  3150. left join Sys_SRM_User g on g.F_Account='{3}' and F_Location='{5}' --
  3151. where a.POCode='{6}' and a. WorkPoint='{5}' and a.Sequence='{7}')";
  3152. sql = string.Format(sql, itemInfo.LotNo, itemInfo.Quantity, DateTime.Now, item.User, DateTime.Now, item.WorkPoint, itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LocationCode);
  3153. cmd.CommandText = sql;
  3154. numInfo = cmd.ExecuteNonQuery();
  3155. if (numInfo > 0)
  3156. {
  3157. string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  3158. ([ID]
  3159. ,[TransCode]
  3160. ,[TransSequence]
  3161. ,[LotNo]
  3162. ,[InvCode]
  3163. ,[FromWarehouseCode]
  3164. ,[FromLocationCode]
  3165. ,[ToWarehouseCode]
  3166. ,[ToLocationCode]
  3167. ,[Quantity]
  3168. ,[Memo]
  3169. ,[Lock]
  3170. ,[TransType]
  3171. ,[BusinessCode]
  3172. ,[ERPID]
  3173. ,[ERPDetailID]
  3174. ,[ERPCode]
  3175. ,[ERPSequence]
  3176. ,[MUSER]
  3177. ,[MUSERName]
  3178. ,[MTIME]
  3179. ,[WorkPoint]
  3180. ,[EATTRIBUTE1])
  3181. (select newid(),'{0}','{1}','{2}',a.InvCode ,' ', ' ',c.WarehouseCode,'{7}','{3}',' ','0','2','8',' ',' ',' ',' ','{4}',e.F_RealName,'{5}','{6}',' '
  3182. from ICSPurchaseOrder a--
  3183. left join ICSWarehouse c on c.id=(select WHID from ICSLocation where LocationCode='{7}')
  3184. left join Sys_SRM_User e on e.F_Account='{4}' and e.F_Location='{6}'
  3185. where a.POCode='{0}' and a. WorkPoint='{6}')";
  3186. sqlLog = string.Format(sqlLog, itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.User, DateTime.Now, item.WorkPoint, itemInfo.LocationCode);
  3187. cmd.CommandText = sqlLog;
  3188. numInfo = cmd.ExecuteNonQuery();
  3189. }
  3190. }
  3191. else
  3192. {
  3193. throw new Exception("数量不足!");
  3194. }
  3195. }
  3196. #endregion
  3197. #region ERP
  3198. sqlERP = @" select VenCode,POCode, ToWarehouseCode,a.MUSER,b.Sequence ,(getdate())as Mtime from ICSWareHouseLotInfoLog a
  3199. left join ICSPurchaseOrder b on a.TransCode=b.POCode and b.Sequence =a.transSequence
  3200. where b.POCode='{0}' and b.WorkPoint='{1}' and a.Memo <> '1'
  3201. group by VenCode,POCode, ToWarehouseCode,a.MUSER,b.Sequence ";
  3202. sqlERP = string.Format(sqlERP, itemInfo.TransCode, item.WorkPoint);
  3203. table = DBHelper.SQlReturnData(sqlERP, cmd);
  3204. sqlERPDetil = @"select b.Sequence,a.InvCode,sum (a.Quantity) as Quantity,isnull((b.Amount),0) as Amount,b.UnitPrice,b.Currency,b.PODetailID from ICSWareHouseLotInfoLog a
  3205. inner join ICSPurchaseOrder b on a.TransCode=b.POCode and b.Sequence =a.transSequence
  3206. where b.POCode='{0}' and b.WorkPoint='{1}' and a.Memo <> '1'
  3207. group by b.Sequence,a.InvCode,b.Amount,b.UnitPrice,b.Currency,b.PODetailID";
  3208. sqlERPDetil = string.Format(sqlERPDetil, itemInfo.TransCode, item.WorkPoint);
  3209. DataTable ERPtable = DBHelper.SQlReturnData(sqlERPDetil, cmd);
  3210. List<ERPPurchaseOrder> docmodel = new List<ERPPurchaseOrder>();
  3211. foreach (DataRow dtIn in table.Rows)
  3212. {
  3213. ERPPurchaseOrder doc = new ERPPurchaseOrder();
  3214. doc.VenCode = dtIn["VenCode"].ToString();
  3215. doc.POCode = dtIn["POCode"].ToString();
  3216. doc.User = dtIn["MUSER"].ToString();
  3217. doc.MTime = dtIn["Mtime"].ToString();
  3218. doc.WHCode = dtIn["ToWarehouseCode"].ToString();
  3219. doc.DNCode = "";
  3220. List<ERPPurchaseOrderList> list = new List<ERPPurchaseOrderList>();
  3221. foreach (DataRow dtList in ERPtable.Rows)
  3222. {
  3223. ERPPurchaseOrderList docc = new ERPPurchaseOrderList();
  3224. docc.Sequence = dtList["Sequence"].ToString();
  3225. docc.InvCode = dtList["InvCode"].ToString();
  3226. docc.Quantity = dtList["Quantity"].ToString();
  3227. docc.Amount = dtList["Amount"].ToString();
  3228. docc.Currency = dtList["Currency"].ToString();
  3229. docc.UnitPrice = dtList["UnitPrice"].ToString();
  3230. docc.PODetailID = dtList["PODetailID"].ToString();
  3231. docc.DNDetailID = "";
  3232. list.Add(docc);
  3233. }
  3234. doc.details = list;
  3235. docmodel.Add(doc);
  3236. }
  3237. IstrErp = JsonConvert.SerializeObject(docmodel);
  3238. iresult = HttpPost("采购订单", ERPUrl.PurchaseOrderURL, IstrErp);
  3239. Result OtherOutResult = new Result();
  3240. OtherOutResult = JsonConvert.DeserializeObject<Result>(iresult);
  3241. List<ERPJsonRetun> mm = new List<ERPJsonRetun>();//json返回
  3242. if (OtherOutResult.Success == true)
  3243. {
  3244. string nn = OtherOutResult.Data.ToString();//LOTStockModel
  3245. mm = JsonConvert.DeserializeObject<List<ERPJsonRetun>>(nn);
  3246. foreach (var items in mm)
  3247. {
  3248. string ERPupdate = @"update ICSWareHouseLotInfoLog set ERPID='{0}',ERPDetailID='{1}',ERPCode='{2}',ERPSequence='{3}',memo='1'
  3249. where TransCode='{4}' and TransSequence ='{5}'";
  3250. ERPupdate = string.Format(ERPupdate, items.ID, items.DetailID, items.RCVTCode, items.Sequence, itemInfo.TransCode, itemInfo.TransSequence);
  3251. cmd.CommandText = ERPupdate;
  3252. numInfo = cmd.ExecuteNonQuery();
  3253. }
  3254. if (numInfo > 0)
  3255. {
  3256. cmd.Transaction.Commit();
  3257. }
  3258. else
  3259. {
  3260. cmd.Transaction.Rollback();
  3261. }
  3262. }
  3263. else
  3264. {
  3265. cmd.Transaction.Rollback();
  3266. throw new Exception(OtherOutResult.Message);
  3267. }
  3268. #endregion
  3269. }
  3270. else
  3271. {
  3272. throw new Exception("采购订单已经关闭!");
  3273. }
  3274. return null;
  3275. case "成品入库":
  3276. #region 添加到库存表/日志表
  3277. sqlInfo = @"select * from ICSLocation where LocationCode='{0}'";
  3278. sqlInfo = string.Format(sqlInfo, itemInfo.LocationCode);
  3279. cmd.CommandText = sqlInfo;
  3280. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  3281. if (table.Rows.Count <= 0)
  3282. {
  3283. throw new Exception("库位不存在!");
  3284. }
  3285. ///验证条码是否存在或者是否上架
  3286. sqlInfo = @"select * from ICSInventoryLot where LotNo='{0}'";
  3287. sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
  3288. cmd.CommandText = sqlInfo;
  3289. table = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
  3290. if (table.Rows.Count <= 0)
  3291. {
  3292. throw new Exception("条码不存在!");
  3293. }
  3294. sqlInfo = @"select * from ICSWareHouseLotInfo where LotNo='{0}'";
  3295. sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
  3296. cmd.CommandText = sqlInfo;
  3297. tableInfo = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
  3298. if (tableInfo.Rows.Count > 0)
  3299. {
  3300. throw new Exception("条码已经上架!");
  3301. }
  3302. else
  3303. {
  3304. sql = @"update ICSMO set RCVQuantity= RCVQuantity + (select Quantity from ICSInventoryLot where lotno='{0}' ) ,MTIME='{1}' where MOCode ='{2}' and InvCode=(select InvCode from ICSInventoryLot where lotno='{0}' ) and WorkPoint='{3}'";
  3305. sql = string.Format(sql, itemInfo.LotNo, DateTime.Now, itemInfo.TransCode, item.WorkPoint);
  3306. cmd.CommandText = sql;
  3307. int ApplyNeg = cmd.ExecuteNonQuery();
  3308. sql = @" INSERT INTO [ICSWareHouseLotInfo]
  3309. ([ID]
  3310. ,[LotNo]
  3311. ,[WarehouseCode]
  3312. ,[LocationCode]
  3313. ,[InvCode]
  3314. ,[Quantity]
  3315. ,[InDate]
  3316. ,[LockQuantity]
  3317. ,[MUSER]
  3318. ,[MUSERName]
  3319. ,[MTIME]
  3320. ,[WorkPoint]
  3321. ,[EATTRIBUTE1])
  3322. VALUES
  3323. (newid()
  3324. ,'{0}'
  3325. ,(select WarehouseCode from ICSWarehouse a left join ICSLocation b on a.ID =b.WHID WHERE LocationCode='{1}')
  3326. ,'{1}'
  3327. ,(SELECT InvCode FROM ICSInventoryLot WHERE LotNo='{0}')
  3328. ,(SELECT Quantity FROM ICSInventoryLot WHERE LotNo='{0}')
  3329. ,'{5}'
  3330. ,0
  3331. ,'{2}'
  3332. ,'{2}'
  3333. ,'{3}'
  3334. ,'{4}'
  3335. ,'')";
  3336. sql = string.Format(sql, itemInfo.LotNo, itemInfo.LocationCode, item.User, item.MTime, item.WorkPoint, DateTime.Now);
  3337. cmd.CommandText = sql;
  3338. numInfo = cmd.ExecuteNonQuery();
  3339. //cmd.Transaction.Commit();
  3340. if (numInfo > 0)
  3341. {
  3342. string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  3343. ([ID]
  3344. ,[TransCode]
  3345. ,[TransSequence]
  3346. ,[LotNo]
  3347. ,[InvCode]
  3348. ,[FromWarehouseCode]
  3349. ,[FromLocationCode]
  3350. ,[ToWarehouseCode]
  3351. ,[ToLocationCode]
  3352. ,[Quantity]
  3353. ,[Memo]
  3354. ,[Lock]
  3355. ,[TransType]
  3356. ,[BusinessCode]
  3357. ,[ERPID]
  3358. ,[ERPDetailID]
  3359. ,[ERPCode]
  3360. ,[ERPSequence]
  3361. ,[MUSER]
  3362. ,[MUSERName]
  3363. ,[MTIME]
  3364. ,[WorkPoint]
  3365. ,[EATTRIBUTE1])
  3366. VALUES
  3367. (newid()
  3368. ,'{4}'
  3369. ,' '
  3370. ,'{0}'
  3371. ,(SELECT InvCode FROM ICSInventoryLot WHERE LotNo='{0}')
  3372. ,(SELECT WarehouseCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
  3373. ,(SELECT LocationCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
  3374. ,''
  3375. ,''
  3376. ,(SELECT Quantity FROM ICSInventoryLot WHERE LotNo='{0}')
  3377. ,''
  3378. ,''
  3379. ,'21'
  3380. ,''
  3381. ,''
  3382. ,''
  3383. ,''
  3384. ,''
  3385. ,'{1}'
  3386. ,'{1}'
  3387. ,'{2}'
  3388. ,'{3}'
  3389. ,'')";
  3390. sqlLog = string.Format(sqlLog, itemInfo.LotNo, item.User, DateTime.Now, item.WorkPoint, itemInfo.TransCode);
  3391. DBHelper.CmdExecuteNonQuery(sqlLog, cmd, "成功");
  3392. cmd.Transaction.Commit();
  3393. }
  3394. }
  3395. #endregion
  3396. return null;
  3397. case "委外订单"://(委外入库)
  3398. verification.HouseLotoOut(itemInfo.LotNo, item.WorkPoint);
  3399. string numNegDetail = @"select isnull((InQuantity),0) as InQuantity , Quantity from ICSOutsourcingOrder where OOCode='{0}'and Sequence='{1}' and WorkPoint='{2}' and Status <> '3' ";
  3400. numNegDetail = string.Format(numNegDetail, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint);
  3401. DataTable dataDetail = DBHelper.SQlReturnData(numNegDetail, cmd);
  3402. if (dataDetail.Rows.Count < 0)
  3403. {
  3404. throw new Exception("订单已关闭!");
  3405. }
  3406. else
  3407. {
  3408. foreach (DataRow itemDetail in dataDetail.Rows)
  3409. {
  3410. double Quantity = Convert.ToDouble(itemInfo.Quantity);///输入数量
  3411. double IssueNegQuantity = Convert.ToDouble(itemDetail["InQuantity"]);//已退数量
  3412. double NegQuantity = Quantity + IssueNegQuantity;//总数量(输入数量+已退数量)
  3413. double QuantityPla = Convert.ToDouble(itemDetail["Quantity"]);//计划数量
  3414. if (QuantityPla >= NegQuantity)
  3415. {
  3416. string NegDetailSql = @"update ICSOutsourcingOrder set Quantity=(select sum(Quantity) from ICSOutsourcingOrder where OOCode='{0}' and Sequence='{1}' and WorkPoint='{2}') +'{3}'
  3417. , MUSER='{4}' ,MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{4}' and F_Location='{2}'), MTIME='{5}'
  3418. where OOCode='{0}' and Sequence='{1}' and WorkPoint='{2}' ";
  3419. NegDetailSql = string.Format(NegDetailSql, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint, itemInfo.Quantity, item.User, DateTime.Now);
  3420. cmd.CommandText = NegDetailSql;
  3421. numInfo = cmd.ExecuteNonQuery();
  3422. ///添加库存
  3423. string HouseLotSql = @"
  3424. insert into ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3425. (select newid(),'{0}' ,e.WarehouseCode,isnull((d.LocationCode),0) as LocationCode ,a.InvCode ,'{1}','{2}','0','{3}' ,g.F_RealName ,'{2}' ,'{4}' ,' '
  3426. from ICSOutsourcingOrder a --退
  3427. left join ICSLocation d on d.LocationCode='{6}'
  3428. left join ICSWarehouse e on e.id=(select WHID from ICSLocation where LocationCode='{6}')
  3429. left join Sys_SRM_User g on g.F_Account='{3}' and F_Location='{4}' --
  3430. where a.OOCode='{5}' and a. WorkPoint='{4}')";
  3431. HouseLotSql = string.Format(HouseLotSql, itemInfo.LotNo, itemInfo.Quantity, DateTime.Now, item.User, item.WorkPoint, itemInfo.TransCode, itemInfo.LocationCode);
  3432. cmd.CommandText = HouseLotSql;
  3433. num = cmd.ExecuteNonQuery();
  3434. ///添加日志
  3435. string sqlLogInfo = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  3436. ([ID]
  3437. ,[TransCode]
  3438. ,[TransSequence]
  3439. ,[LotNo]
  3440. ,[InvCode]
  3441. ,[FromWarehouseCode]
  3442. ,[FromLocationCode]
  3443. ,[ToWarehouseCode]
  3444. ,[ToLocationCode]
  3445. ,[Quantity]
  3446. ,[Memo]
  3447. ,[Lock]
  3448. ,[TransType]
  3449. ,[BusinessCode]
  3450. ,[ERPID]
  3451. ,[ERPDetailID]
  3452. ,[ERPCode]
  3453. ,[ERPSequence]
  3454. ,[MUSER]
  3455. ,[MUSERName]
  3456. ,[MTIME]
  3457. ,[WorkPoint]
  3458. ,[EATTRIBUTE1])
  3459. (select newid(),'{0}','{1}','{2}',a.InvCode ,' ', ' ',b.WarehouseCode,'{7}','{3}',' ','0','2','8',' ',' ',' ',' ','{4}',e.F_RealName,'{5}','{6}',' '
  3460. from ICSOutsourcingOrder a--
  3461. left join ICSWarehouse b on b.id=(select WHID from ICSLocation where LocationCode='{7}')
  3462. left join Sys_SRM_User e on e.F_Account='{4}' and e.F_Location='{6}'
  3463. where a.OOCode='{0}' and a. WorkPoint='{6}')";
  3464. sqlLogInfo = string.Format(sqlLogInfo, itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.User, DateTime.Now, item.WorkPoint, itemInfo.LocationCode);
  3465. cmd.CommandText = sqlLogInfo;
  3466. int numInfoLot = cmd.ExecuteNonQuery();
  3467. #region ERP
  3468. sqlERP = @" select VenCode,OOCode, ToWarehouseCode,a.MUSER,b.Sequence ,(getdate())as Mtime from ICSWareHouseLotInfoLog a
  3469. left join ICSOutsourcingOrder b on a.TransCode=b.OOCode and b.Sequence =a.transSequence
  3470. where b.OOCode='{0}' and b.WorkPoint='{1}' and a.Memo <> '1'
  3471. group by VenCode,OOCode, ToWarehouseCode,a.MUSER,b.Sequence ";
  3472. sqlERP = string.Format(sqlERP, itemInfo.TransCode, item.WorkPoint);
  3473. table = DBHelper.SQlReturnData(sqlERP, cmd);
  3474. sqlERPDetil = @"select b.Sequence,a.InvCode,sum (a.Quantity) as Quantity,isnull((b.Amount),0) as Amount,isnull((b.UnitPrice),0) as UnitPrice,b.Currency,b.OODetailID from ICSWareHouseLotInfoLog a
  3475. inner join ICSOutsourcingOrder b on a.TransCode=b.OOCode and b.Sequence =a.transSequence
  3476. where b.OOCode='{0}' and b.WorkPoint='{1}' and a.Memo <> '1'
  3477. group by b.Sequence,a.InvCode,b.Amount,b.UnitPrice,b.Currency,b.OODetailID";
  3478. sqlERPDetil = string.Format(sqlERPDetil, itemInfo.TransCode, item.WorkPoint);
  3479. DataTable ERPtable = DBHelper.SQlReturnData(sqlERPDetil, cmd);
  3480. List<ERPPurchaseOrder> docmodel = new List<ERPPurchaseOrder>();
  3481. foreach (DataRow dtIn in table.Rows)
  3482. {
  3483. ERPPurchaseOrder doc = new ERPPurchaseOrder();
  3484. doc.VenCode = dtIn["VenCode"].ToString();
  3485. //doc.OOCode = dtIn["OOCode"].ToString();
  3486. doc.User = dtIn["MUSER"].ToString();
  3487. doc.MTime = dtIn["Mtime"].ToString();
  3488. //doc.MTime = DateTime.Now;
  3489. doc.WHCode = dtIn["ToWarehouseCode"].ToString();
  3490. doc.ODNCode = "";
  3491. List<ERPPurchaseOrderList> list = new List<ERPPurchaseOrderList>();
  3492. foreach (DataRow dtList in ERPtable.Rows)
  3493. {
  3494. ERPPurchaseOrderList docc = new ERPPurchaseOrderList();
  3495. docc.Sequence = dtList["Sequence"].ToString();
  3496. docc.InvCode = dtList["InvCode"].ToString();
  3497. docc.Quantity = dtList["Quantity"].ToString();
  3498. docc.Amount = dtList["Amount"].ToString();
  3499. docc.Currency = dtList["Currency"].ToString();
  3500. docc.UnitPrice = dtList["UnitPrice"].ToString();
  3501. //docc.OODetailID = dtList["OODetailID"].ToString();
  3502. docc.DNDetailID = "";
  3503. list.Add(docc);
  3504. }
  3505. doc.details = list;
  3506. docmodel.Add(doc);
  3507. }
  3508. IstrErp = JsonConvert.SerializeObject(docmodel);
  3509. log.Info("委外入库ERPJSON" + IstrErp);
  3510. iresult = HttpPost("委外入库", ERPUrl.OutsourcingReceiveDocURL, IstrErp);
  3511. Result OtherOutResult = new Result();
  3512. OtherOutResult = JsonConvert.DeserializeObject<Result>(iresult);
  3513. List<ERPJsonRetun> mm = new List<ERPJsonRetun>();//json返回
  3514. if (OtherOutResult.Success == true)
  3515. {
  3516. string nn = OtherOutResult.Data.ToString();//LOTStockModel
  3517. mm = JsonConvert.DeserializeObject<List<ERPJsonRetun>>(nn);
  3518. foreach (var items in mm)
  3519. {
  3520. string ERPupdate = @"update ICSWareHouseLotInfoLog set ERPID='{0}',ERPDetailID='{1}',ERPCode='{2}',ERPSequence='{3}',memo='1'
  3521. where TransCode='{4}' and TransSequence ='{5}'";
  3522. ERPupdate = string.Format(ERPupdate, items.ID, items.DetailID, items.RCVTCode, items.Sequence, itemInfo.TransCode, itemInfo.TransSequence);
  3523. cmd.CommandText = ERPupdate;
  3524. numInfo = cmd.ExecuteNonQuery();
  3525. }
  3526. if (numInfo > 0)
  3527. {
  3528. cmd.Transaction.Commit();
  3529. }
  3530. else
  3531. {
  3532. cmd.Transaction.Rollback();
  3533. }
  3534. }
  3535. else
  3536. {
  3537. cmd.Transaction.Rollback();
  3538. throw new Exception(OtherOutResult.Message);
  3539. }
  3540. #endregion
  3541. if (numInfoLot > 0)
  3542. {
  3543. cmd.Transaction.Commit();
  3544. }
  3545. else
  3546. {
  3547. cmd.Transaction.Rollback();
  3548. }
  3549. }
  3550. }
  3551. }
  3552. return null;
  3553. case "其它入库":
  3554. string SOtherInDetail = @"select * from ICSOtherIn where InCode='{0}'and Sequence='{1}' and WorkPoint='{2}' ";
  3555. SOtherInDetail = string.Format(SOtherInDetail, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint);
  3556. DataTable dataDetailIn = DBHelper.SQlReturnData(SOtherInDetail, cmd);
  3557. if (dataDetailIn.Rows.Count > 0)
  3558. {
  3559. string sqlnn = @"select * from ICSOtherIn where InCode='{0}'and Sequence='{1}' and WorkPoint='{2}' and Status='3' ";
  3560. sqlnn = string.Format(sqlnn, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint);
  3561. DataTable dataDetailll = DBHelper.SQlReturnData(sqlnn, cmd);
  3562. if (dataDetailll.Rows.Count > 0)
  3563. {
  3564. throw new Exception("订单已关闭!");
  3565. }
  3566. else
  3567. {
  3568. foreach (DataRow itemDetail in dataDetailIn.Rows)
  3569. {
  3570. double Quantity = Convert.ToDouble(itemInfo.Quantity);///输入数量
  3571. double IssueNegQuantity = Convert.ToDouble(itemDetail["InQuantity"]);//已退数量
  3572. double NegQuantity = Quantity + IssueNegQuantity;//总数量(输入数量+已退数量)
  3573. double QuantityPla = Convert.ToDouble(itemDetail["Quantity"]);//计划数量
  3574. if (QuantityPla >= NegQuantity)
  3575. {
  3576. string NegDetailSql = @"update ICSOtherIn set InQuantity=(select sum(InQuantity) from ICSOtherIn where InCode='{0}' and Sequence='{1}' and WorkPoint='{2}') +'{3}'
  3577. , MUSER='{4}' ,MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{4}' and F_Location='{2}'), MTIME='{5}'
  3578. where InCode='{0}' and Sequence='{1}' and WorkPoint='{2}' ";
  3579. NegDetailSql = string.Format(NegDetailSql, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint, itemInfo.Quantity, item.User, DateTime.Now);
  3580. cmd.CommandText = NegDetailSql;
  3581. numInfo = cmd.ExecuteNonQuery();
  3582. ///添加库存
  3583. string HouseLotSql = @"
  3584. insert into ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3585. (select newid(),'{0}' ,a.WHCode,isnull((f.LocationCode),0) ,a.InvCode ,'{1}','{2}','0','{3}' ,g.F_RealName ,'{4}' ,'{5}' ,' '
  3586. from ICSOtherIn a --退
  3587. left join ICSInventoryLotDetail c on a.InCode=c.TransCode and c.TransSequence=a.Sequence --
  3588. left join ICSInventoryLot d on c.LOTNO=d.LotNO and d.WorkPoint=c.WorkPoint --
  3589. left join ICSLocation f on f.WHID=(select id from ICSWarehouse where WarehouseCode='{6}')
  3590. left join Sys_SRM_User g on g.F_Account='{3}' and F_Location='{5}' --
  3591. where a.InCode='{6}' and a. WorkPoint='{5}')";
  3592. HouseLotSql = string.Format(HouseLotSql, itemInfo.LotNo, itemInfo.Quantity, DateTime.Now, item.User, DateTime.Now, item.WorkPoint, itemInfo.TransCode, itemInfo.LocationCode);
  3593. cmd.CommandText = HouseLotSql;
  3594. num = cmd.ExecuteNonQuery();
  3595. ///添加日志
  3596. string sqlLogInfo = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  3597. ([ID]
  3598. ,[TransCode]
  3599. ,[TransSequence]
  3600. ,[LotNo]
  3601. ,[InvCode]
  3602. ,[FromWarehouseCode]
  3603. ,[FromLocationCode]
  3604. ,[ToWarehouseCode]
  3605. ,[ToLocationCode]
  3606. ,[Quantity]
  3607. ,[Memo]
  3608. ,[Lock]
  3609. ,[TransType]
  3610. ,[BusinessCode]
  3611. ,[ERPID]
  3612. ,[ERPDetailID]
  3613. ,[ERPCode]
  3614. ,[ERPSequence]
  3615. ,[MUSER]
  3616. ,[MUSERName]
  3617. ,[MTIME]
  3618. ,[WorkPoint]
  3619. ,[EATTRIBUTE1])
  3620. (select newid(),'{0}','{1}','{2}',a.InvCode ,' ', ' ',a.WHCode,d.LocationCode,'{3}',' ','0','2','12',' ',' ',' ',' ','{4}',e.F_RealName,'{5}','{6}',' '
  3621. from ICSOtherIn a--
  3622. left join ICSWarehouse c on c.WarehouseCode=a.WHCode and c.WorkPoint=a.WorkPoint--
  3623. left join ICSLocation d on d.WHID=(select id from ICSWarehouse where WarehouseCode='{7}')--
  3624. left join Sys_SRM_User e on e.F_Account='{4}' and e.F_Location='{6}'
  3625. where a.InCode='{0}' and a. WorkPoint='{6}' AND A.Sequence='{1}' )";
  3626. sqlLogInfo = string.Format(sqlLogInfo, itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.User, DateTime.Now, item.WorkPoint, itemInfo.LocationCode);
  3627. cmd.CommandText = sqlLogInfo;
  3628. int numInfoLot = cmd.ExecuteNonQuery();
  3629. if (numInfoLot > 0)
  3630. {
  3631. cmd.Transaction.Commit();
  3632. }
  3633. else
  3634. {
  3635. cmd.Transaction.Rollback();
  3636. }
  3637. #region ERP
  3638. #endregion
  3639. }
  3640. else
  3641. {
  3642. throw new Exception("已入数量超过计划数量!");
  3643. }
  3644. }
  3645. }
  3646. }
  3647. else
  3648. {
  3649. throw new Exception("查无数据!");
  3650. }
  3651. return null;
  3652. }
  3653. }
  3654. }
  3655. return model;
  3656. }
  3657. catch (Exception ex)
  3658. {
  3659. //cmd.Transaction.Rollback();
  3660. log.Error(ex.Message);
  3661. throw new Exception(ex.Message);
  3662. }
  3663. finally
  3664. {
  3665. if (conn.State == ConnectionState.Open)
  3666. {
  3667. conn.Close();
  3668. }
  3669. conn.Dispose();
  3670. }
  3671. }
  3672. /// <summary>
  3673. /// 上架删除
  3674. /// </summary>BusinessCode,TransType 两个类型
  3675. /// <param name="JsonData"></param>
  3676. /// <returns></returns>
  3677. public List<LOTStockUpDeleteIModel> LOTStockDelete(LOTStockUpDeleteIModel JsonData)
  3678. {
  3679. List<LOTStockUpDeleteIModel> model = new List<LOTStockUpDeleteIModel>();
  3680. conn.Open();
  3681. SqlTransaction sqlTran = conn.BeginTransaction();
  3682. SqlCommand cmd = new SqlCommand();
  3683. cmd.Transaction = sqlTran;
  3684. cmd.Connection = conn;
  3685. try
  3686. {
  3687. sql = @"";
  3688. table = DBHelper.SQlReturnData(sql, cmd);
  3689. string json = JsonConvert.SerializeObject(table);
  3690. model = JsonConvert.DeserializeObject<List<LOTStockUpDeleteIModel>>(json);//<List<WMSSourceDocumentModel>>
  3691. cmd.Transaction.Commit();
  3692. return model;
  3693. }
  3694. catch (Exception ex)
  3695. {
  3696. cmd.Transaction.Rollback();
  3697. log.Error(ex.Message);
  3698. throw new Exception(ex.Message);
  3699. }
  3700. finally
  3701. {
  3702. if (conn.State == ConnectionState.Open)
  3703. {
  3704. conn.Close();
  3705. }
  3706. conn.Dispose();
  3707. }
  3708. }
  3709. #endregion
  3710. #region 下架
  3711. /// <summary>
  3712. /// 下架增加
  3713. /// </summary>BusinessCode,TransType 两个类型
  3714. /// <param name="JsonData"></param>
  3715. /// <returns></returns>
  3716. public int LOTStockDownCreate(List<LOTStockModel> JsonData)
  3717. {
  3718. List<LOTStockUpCreateIModel> model = new List<LOTStockUpCreateIModel>();
  3719. conn.Open();
  3720. SqlTransaction sqlTran = conn.BeginTransaction();
  3721. SqlCommand cmd = new SqlCommand();
  3722. cmd.Transaction = sqlTran;
  3723. cmd.Connection = conn;
  3724. int num;
  3725. string sqlERP = string.Empty;//ERP的表头
  3726. string sqlERPDetil = string.Empty;//ERP的表体
  3727. string jsonERP = string.Empty;///erpjson
  3728. string IstrErp = string.Empty;
  3729. string iresult = string.Empty;//接口调用
  3730. try
  3731. {
  3732. foreach (var item in JsonData)
  3733. {
  3734. foreach (var itemInfo in item.detail)
  3735. {
  3736. switch (item.TransType)
  3737. {
  3738. case "委外退货":
  3739. string sqlNotices = @"select * from ICSODeliveryNotice where ODNCode='{0}' and Sequence='{1}' and ODNType='2' and WorkPoint='{2}'";
  3740. sqlNotices = string.Format(sqlNotices, item.TransCode, itemInfo.TransSequence, item.WorkPoint);
  3741. DataTable Notices = DBHelper.SQlReturnData(sqlNotices, cmd);
  3742. if (Notices.Rows.Count < 0)
  3743. {
  3744. throw new Exception("单据已经关闭!");
  3745. }
  3746. foreach (DataRow itemdata in Notices.Rows)
  3747. {
  3748. int IssueQuantity = Convert.ToInt32(itemdata["RCVQuantity"]);//入库数量
  3749. int Quantity = Convert.ToInt32(itemdata["Quantity"]);//数量
  3750. int CurrentQuantity = Convert.ToInt32(Convert.ToDouble(itemInfo.CurrentQuantity));
  3751. int numQuantity = IssueQuantity + CurrentQuantity;//总数量
  3752. if (numQuantity > Quantity)
  3753. {
  3754. throw new Exception("应退数量大于实际数量");
  3755. }
  3756. }
  3757. //修改退货表
  3758. sql = " update ICSODeliveryNotice set RCVQuantity = RCVQuantity + '{0}' where ODNCode= '{1}' and WorkPoint='{2}' and Sequence='{3}' ";
  3759. sql = string.Format(sql, itemInfo.CurrentQuantity, item.TransCode, item.WorkPoint, itemInfo.TransSequence);
  3760. cmd.CommandText = sql;
  3761. num = cmd.ExecuteNonQuery();
  3762. //修改库存
  3763. sqlInfo = @"update ICSWareHouseLotInfo set Quantity= Quantity -'{0}' where lotno='{1}' and WorkPoint='{2}' ";
  3764. sqlInfo = string.Format(sqlInfo, itemInfo.CurrentQuantity, itemInfo.LotNo, item.WorkPoint);
  3765. cmd.CommandText = sqlInfo;
  3766. num = cmd.ExecuteNonQuery();
  3767. ///添加日志表
  3768. #region 添加日志
  3769. string sqlLogw = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  3770. ([ID]
  3771. ,[TransCode]
  3772. ,[TransSequence]
  3773. ,[LotNo]
  3774. ,[InvCode]
  3775. ,[FromWarehouseCode]
  3776. ,[FromLocationCode]
  3777. ,[ToWarehouseCode]
  3778. ,[ToLocationCode]
  3779. ,[Quantity]
  3780. ,[Memo]
  3781. ,[Lock]
  3782. ,[TransType]
  3783. ,[BusinessCode]
  3784. ,[ERPID]
  3785. ,[ERPDetailID]
  3786. ,[ERPCode]
  3787. ,[ERPSequence]
  3788. ,[MUSER]
  3789. ,[MUSERName]
  3790. ,[MTIME]
  3791. ,[WorkPoint]
  3792. ,[EATTRIBUTE1])
  3793. (select newid(),A.ODNCode,A.Sequence,'{0}',a.InvCode ,' ', ' ',b.WarehouseCode,b.LocationCode,'{1}',' ','0','2','20',' ',' ',' ',' ','{2}',e.F_RealName,'{3}','{4}',' '
  3794. from ICSODeliveryNotice a--
  3795. left join ICSWareHouseLotInfo b on b.LotNo='{0}'
  3796. left join Sys_SRM_User e on e.F_Account='{2}' and e.F_Location='{4}'
  3797. where a.ODNCode='{5}' and a.WorkPoint='{4}' and Sequence='{6}')";
  3798. sqlLogw = string.Format(sqlLogw, itemInfo.LotNo, item.Quantity, item.User, DateTime.Now, item.WorkPoint, item.TransCode, itemInfo.TransSequence, itemInfo.Sequence);
  3799. cmd.CommandText = sqlLogw;
  3800. int numlogs = cmd.ExecuteNonQuery();
  3801. #endregion
  3802. #region ERP
  3803. sqlERP = @" select a.VenCode ,a.POID,b.ToWarehouseCode,b.TransCode,b.MUSER,b.TransSequence,b.InvCode,a.ODNCode ,(getdate())as Mtime from ICSODeliveryNotice a
  3804. inner join ICSWareHouseLotInfoLog b on a.ODNCode=b.TransCode and b.TransSequence=a.Sequence
  3805. where a.ODNType='2' and a.odncode='{0}' and b.WorkPoint='{1}' and b.Memo <> '1'
  3806. group by a.VenCode ,a.POID,b.ToWarehouseCode,b.TransCode,b.MUSER,b.TransSequence,b.InvCode,a.ODNCode";
  3807. sqlERP = string.Format(sqlERP, item.TransCode, item.WorkPoint);
  3808. table = DBHelper.SQlReturnData(sqlERP, cmd);
  3809. sqlERPDetil = @"select a.TransSequence,b.InvCode,sum(a.Quantity) as Quantity, isnull((b.Amount), 0) as Amount ,Currency,ISNULL((UnitPrice),0) AS UnitPrice,b.ODNDetailID from ICSWareHouseLotInfoLog a
  3810. inner JOIN ICSODeliveryNotice B ON b.ODNCode = a.TransCode and a.TransSequence = b.Sequence
  3811. where b.ODNCode='{0}' and a.Memo <> '1' and a.WorkPoint='{1}'
  3812. group by a.TransSequence,b.InvCode,a.Quantity, Amount ,Currency,UnitPrice,b.ODNDetailID";
  3813. sqlERPDetil = string.Format(sqlERPDetil, item.TransCode, item.WorkPoint);
  3814. DataTable ERPtable = DBHelper.SQlReturnData(sqlERPDetil, cmd);
  3815. List<ERPODNRT> docmodel = new List<ERPODNRT>();
  3816. foreach (DataRow dtIn in table.Rows)
  3817. {
  3818. ERPODNRT doc = new ERPODNRT();
  3819. doc.VenCode = dtIn["VenCode"].ToString();
  3820. //doc.POCode = dtIn["POID"].ToString();
  3821. doc.User = dtIn["MUSER"].ToString();
  3822. doc.MTime = dtIn["Mtime"].ToString();
  3823. doc.WHCode = dtIn["ToWarehouseCode"].ToString();
  3824. doc.ODNRTCode = dtIn["Odncode"].ToString();
  3825. List<ERPODNRTList> list = new List<ERPODNRTList>();
  3826. foreach (DataRow dtList in ERPtable.Rows)
  3827. {
  3828. ERPODNRTList docc = new ERPODNRTList();
  3829. docc.Sequence = dtList["TransSequence"].ToString();
  3830. docc.InvCode = dtList["InvCode"].ToString();
  3831. docc.Quantity = dtList["Quantity"].ToString();
  3832. docc.Amount = dtList["Amount"].ToString();
  3833. docc.Currency = dtList["Currency"].ToString();
  3834. docc.UnitPrice = dtList["UnitPrice"].ToString();
  3835. docc.ODNRTDetailID = dtList["ODNDetailID"].ToString();
  3836. list.Add(docc);
  3837. }
  3838. doc.details = list;
  3839. docmodel.Add(doc);
  3840. }
  3841. IstrErp = JsonConvert.SerializeObject(docmodel);
  3842. log.Info("委外退货ERPJSON" + IstrErp);
  3843. iresult = HttpPost("委外退货", ERPUrl.OutsourcingReturnBackURL, IstrErp);
  3844. Result OtherOutResult = new Result();
  3845. OtherOutResult = JsonConvert.DeserializeObject<Result>(iresult);
  3846. int numInfo = 0;
  3847. if (OtherOutResult.Success == false)
  3848. {
  3849. throw new Exception(OtherOutResult.Message);
  3850. }
  3851. else
  3852. {
  3853. List<ERPJsonRetun> list = new List<ERPJsonRetun>();
  3854. //string nn = OtherOutResult.Data.ToString();//LOTStockModel
  3855. list = JsonConvert.DeserializeObject<List<ERPJsonRetun>>(OtherOutResult.Data.ToString());
  3856. foreach (var items in list)
  3857. {
  3858. string ERPupdate = @"update ICSWareHouseLotInfoLog set ERPID='{0}',ERPDetailID='{1}',ERPCode='{2}',ERPSequence='{3}',Memo='1'
  3859. where TransCode='{4}' and TransSequence ='{5}'";
  3860. ERPupdate = string.Format(ERPupdate, items.ID, items.DetailID, items.RCVNEGCode, items.Sequence, item.TransCode, itemInfo.TransSequence);
  3861. cmd.CommandText = ERPupdate;
  3862. numInfo = cmd.ExecuteNonQuery();
  3863. }
  3864. if (numInfo > 0)
  3865. {
  3866. cmd.Transaction.Commit();
  3867. }
  3868. else
  3869. {
  3870. cmd.Transaction.Rollback();
  3871. }
  3872. }
  3873. #endregion
  3874. if (numlogs <= 0)
  3875. {
  3876. cmd.Transaction.Rollback();
  3877. }
  3878. else
  3879. {
  3880. cmd.Transaction.Commit();
  3881. }
  3882. return 0;
  3883. case "材料出库":
  3884. string sqlMOPick = @"SELECT IssueQuantity,Quantity,* from ICSMOPick
  3885. where MODetailID= (SELECT ID FROM ICSMO WHERE MOCode='{0}') and InvCode=(select InvCode from ICSInventoryLot where LotNo='{1}' AND WorkPoint='{2}')";
  3886. sqlMOPick = string.Format(sqlMOPick, item.TransCode, itemInfo.LotNo, item.WorkPoint);
  3887. //cmd.CommandText = sqlMOPick;
  3888. DataTable data = DBHelper.SQlReturnData(sqlMOPick, cmd);
  3889. foreach (DataRow itemdata in data.Rows)
  3890. {
  3891. int IssueQuantity = Convert.ToInt32(itemdata["IssueQuantity"]);
  3892. int Quantity = Convert.ToInt32(itemdata["Quantity"]);
  3893. int CurrentQuantity = Convert.ToInt32(Convert.ToDouble(itemInfo.CurrentQuantity));
  3894. int numQuantity = IssueQuantity + CurrentQuantity;
  3895. if (numQuantity > Quantity)
  3896. {
  3897. throw new Exception("应退数量大于实际数量");
  3898. }
  3899. }
  3900. sql = " update ICSMOPick set IssueQuantity= IssueQuantity + '{0}' where MODetailID= (SELECT ID FROM ICSMO WHERE MOCode='{1}') and WorkPoint='{2}' and InvCode=(select InvCode from ICSInventoryLot where LotNo='{3}' )";
  3901. sql = string.Format(sql, itemInfo.CurrentQuantity, item.TransCode, item.WorkPoint, itemInfo.LotNo);
  3902. cmd.CommandText = sql;
  3903. num = cmd.ExecuteNonQuery();
  3904. if (num <= 0)
  3905. {
  3906. throw new Exception("条码不存在!");
  3907. }
  3908. else
  3909. {
  3910. string sqlVerification = @"select * from ICSWareHouseLotInfo where lotno='{0}' and '{2}'<= Quantity and WorkPoint='{1}'";
  3911. sqlVerification = string.Format(sqlVerification, itemInfo.LotNo, item.WorkPoint, itemInfo.CurrentQuantity);
  3912. DataTable dataTableNum = DBHelper.SQlReturnData(sqlVerification, cmd);
  3913. if (dataTableNum.Rows.Count <= 0)
  3914. {
  3915. throw new Exception("输入数量大于库存数量");
  3916. }
  3917. else
  3918. {
  3919. sqlInfo = @"update ICSWareHouseLotInfo set Quantity= Quantity -'{0}' where lotno='{1}' ";
  3920. sqlInfo = string.Format(sqlInfo, itemInfo.CurrentQuantity, itemInfo.LotNo, item.WorkPoint);
  3921. cmd.CommandText = sqlInfo;
  3922. num = cmd.ExecuteNonQuery();
  3923. //DBHelper.CmdExecuteNonQuery(sqlInfo, cmd, "成功");
  3924. //cmd.Transaction.Commit();
  3925. log.Info("材料出库" + sql);
  3926. }
  3927. ///添加日志表
  3928. #region 添加日志
  3929. string sqlLogs = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  3930. ([ID]
  3931. ,[TransCode]
  3932. ,[TransSequence]
  3933. ,[LotNo]
  3934. ,[InvCode]
  3935. ,[FromWarehouseCode]
  3936. ,[FromLocationCode]
  3937. ,[ToWarehouseCode]
  3938. ,[ToLocationCode]
  3939. ,[Quantity]
  3940. ,[Memo]
  3941. ,[Lock]
  3942. ,[TransType]
  3943. ,[BusinessCode]
  3944. ,[ERPID]
  3945. ,[ERPDetailID]
  3946. ,[ERPCode]
  3947. ,[ERPSequence]
  3948. ,[MUSER]
  3949. ,[MUSERName]
  3950. ,[MTIME]
  3951. ,[WorkPoint]
  3952. ,[EATTRIBUTE1])
  3953. (select newid(),'{5}','{6}','{0}',b.InvCode ,' ', ' ',b.WarehouseCode,b.LocationCode,'{1}',' ','0','2','21',' ',' ',' ',' ','{2}',e.F_RealName,'{3}','{4}',' '
  3954. from
  3955. ICSWareHouseLotInfo b
  3956. left join Sys_SRM_User e on e.F_Account='{2}' and e.F_Location='{4}'
  3957. where b.LotNo='{0}' and b.WorkPoint='{4}' )";
  3958. sqlLogs = string.Format(sqlLogs, itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, DateTime.Now, item.WorkPoint, item.TransCode, itemInfo.TransSequence, itemInfo.Sequence);
  3959. cmd.CommandText = sqlLogs;
  3960. num = cmd.ExecuteNonQuery();
  3961. if (num <= 0)
  3962. {
  3963. cmd.Transaction.Rollback();
  3964. }
  3965. else
  3966. {
  3967. cmd.Transaction.Commit();
  3968. }
  3969. #endregion
  3970. #region ERP
  3971. sqlERP = @"select DepCode,FromWarehouseCode,MOCode,Sequence,a.MUSER ,(getdate())as Mtime,b.TransType from ICSMO a
  3972. left join ICSWareHouseLotInfoLog b on a.MOCode=b.TransCode and a.WorkPoint=b.WorkPoint and a.InvCode=b.InvCode
  3973. where MOCode='{0}' and a.WorkPoint='{1}' ";
  3974. sqlERP = string.Format(sqlERP, item.TransCode, item.WorkPoint);
  3975. table = DBHelper.SQlReturnData(sqlERP, cmd);
  3976. sqlERPDetil = @"select a.TransSequence,b.InvCode,a.Quantity, isnull((b.Amount),0)as Amount ,PickID from ICSWareHouseLotInfoLog a
  3977. LEFT JOIN ICSMO B ON B.MOCode=A.TransCode
  3978. left join ICSMOPick C on C.MODetailID=B.ID where LotNo='{0}' and c.Sequence=a.TransSequence and a.EATTRIBUTE1=b.Sequence and a.Memo<>'1'";
  3979. sqlERPDetil = string.Format(sqlERPDetil, itemInfo.LotNo);
  3980. DataTable ERPtabless = DBHelper.SQlReturnData(sqlERPDetil, cmd);
  3981. List<IssueDoc> docmodelss = new List<IssueDoc>();
  3982. foreach (DataRow dt in table.Rows)
  3983. {
  3984. IssueDoc doc = new IssueDoc();
  3985. doc.DepCode = dt["DepCode"].ToString();
  3986. doc.WHCode = dt["FromWarehouseCode"].ToString();
  3987. doc.SourceType = dt["MOCode"].ToString();
  3988. doc.SourceCode = "生产订单";
  3989. doc.User = dt["MUSER"].ToString();
  3990. doc.MTime = dt["Mtime"].ToString();
  3991. List<IssueDocList> list = new List<IssueDocList>();
  3992. foreach (DataRow dtList in ERPtabless.Rows)
  3993. {
  3994. IssueDocList docc = new IssueDocList();
  3995. docc.Sequence = dtList["TransSequence"].ToString();
  3996. docc.InvCode = dtList["InvCode"].ToString();
  3997. docc.Quantity = dtList["Quantity"].ToString();
  3998. docc.Amount = dtList["Amount"].ToString();
  3999. docc.SourceDetailID = dtList["PickID"].ToString();
  4000. list.Add(docc);
  4001. }
  4002. doc.details = list;
  4003. docmodelss.Add(doc);
  4004. }
  4005. IstrErp = JsonConvert.SerializeObject(docmodelss);
  4006. iresult = HttpPost("材料出库", ERPUrl.MOIssueDocURL, IstrErp);
  4007. Result OtherOutResultss = new Result();
  4008. OtherOutResultss = JsonConvert.DeserializeObject<Result>(iresult);
  4009. if (OtherOutResultss.Success == false)
  4010. {
  4011. throw new Exception(OtherOutResultss.Message);
  4012. }
  4013. else
  4014. {
  4015. //OtherOutResult.Data;
  4016. }
  4017. #endregion
  4018. }
  4019. return 0;
  4020. case "生产退料":
  4021. sql = @"update ICSMOApplyNegDetail set Quantity='{0}',Amount='{1}',IssueNegQuantity =((select sum(IssueNegQuantity) from ICSODelICSMOApplyNegDetailiveryNotice where ApplyNegCode='{2}') - '{0}'), MUSER='{3}',MTIME='{4}' where ApplyNegCode='{2}' and WorkPoint='{5}'";
  4022. sql = string.Format(sql, item.Quantity, item.Amount, item.TransCode, item.User, item.MTime, item.WorkPoint);
  4023. cmd.CommandText = sql;
  4024. num = cmd.ExecuteNonQuery();
  4025. return num;
  4026. case "产品入库":
  4027. sql = @"update ICSODeliveryNotice set Quantity='{0}',Amount='{1}'RCVQuantity =((select sum(RCVQuantity) from ICSODeliveryNotice where ODNCode='{2}') - '{0}') ,MUSER='{3}',MTIME='{4}' where ODNCode='{2}' and WorkPoint='{5}'";
  4028. sql = string.Format(sql, itemInfo.CurrentQuantity, itemInfo.CurrentAmount, item.TransCode, item.User, item.MTime, item.WorkPoint);
  4029. cmd.CommandText = sql;
  4030. num = cmd.ExecuteNonQuery();
  4031. if (num > 0)
  4032. {
  4033. //添加到日志表
  4034. }
  4035. return num;
  4036. case "销售发货":
  4037. #region 添加到库存表/日志表
  4038. ///验证条码是否存在或者是否上架
  4039. sqlInfo = @"select * from ICSInventoryLot where LotNo='{0}'";
  4040. sqlInfo = string.Format(sqlInfo, itemInfo.LotNo);
  4041. cmd.CommandText = sqlInfo;
  4042. table = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
  4043. if (table.Rows.Count <= 0)
  4044. {
  4045. throw new Exception("条码不存在!");
  4046. }
  4047. ///查询销售订单是否已经关闭
  4048. sqlInfo = @"select * from ICSSDN where SDNCode='{0}' and Sequence='{1}' and Status='3' and Type='1' and WorkPoint='{2}'";
  4049. sqlInfo = string.Format(sqlInfo, item.TransCode, itemInfo.TransSequence, item.WorkPoint);
  4050. cmd.CommandText = sqlInfo;
  4051. DataTable tableInfo = DBHelper.SQlReturnData(sqlInfo, cmd);//返回条数
  4052. if (tableInfo.Rows.Count > 0)
  4053. {
  4054. throw new Exception("销售订单已经关闭!");
  4055. }
  4056. else
  4057. {
  4058. string sqlVerification = @"select * from ICSWareHouseLotInfo where lotno='{0}' and '{2}'<= Quantity and WorkPoint='{1}'";
  4059. sqlVerification = string.Format(sqlVerification, itemInfo.LotNo, item.WorkPoint, itemInfo.CurrentQuantity);
  4060. DataTable dataTablel = DBHelper.SQlReturnData(sqlVerification, cmd);
  4061. if (dataTablel.Rows.Count <= 0)
  4062. {
  4063. throw new Exception("输入数量大于库存数量");
  4064. }
  4065. else
  4066. {
  4067. ///修改销售订单表已发数量
  4068. sql = @"update ICSSDN set SDNQuantity= SDNQuantity + '{4}' ,MTIME='{1}' where SDNCode ='{2}' and InvCode=(select InvCode from ICSInventoryLot where lotno='{0}' ) and WorkPoint='{3}'";
  4069. sql = string.Format(sql, itemInfo.LotNo, DateTime.Now, item.TransCode, item.WorkPoint, itemInfo.CurrentQuantity);
  4070. cmd.CommandText = sql;
  4071. num = cmd.ExecuteNonQuery();
  4072. //修改库存表的数量
  4073. sql = @" update ICSWareHouseLotInfo set Quantity=Quantity -'{4}',MTIME='{1}' where lotno ='{0}' and InvCode in (select InvCode from ICSInventoryLot where lotno='{0}' and WorkPoint ='{3}') and WorkPoint='{3}' ";
  4074. sql = string.Format(sql, itemInfo.LotNo, DateTime.Now, item.TransCode, item.WorkPoint, itemInfo.CurrentQuantity);
  4075. cmd.CommandText = sql;
  4076. num = cmd.ExecuteNonQuery();
  4077. // cmd.Transaction.Commit();
  4078. #region 添加日志
  4079. if (num > 0)
  4080. {
  4081. string sqlLogInfoInf = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  4082. ([ID]
  4083. ,[TransCode]
  4084. ,[TransSequence]
  4085. ,[LotNo]
  4086. ,[InvCode]
  4087. ,[FromWarehouseCode]
  4088. ,[FromLocationCode]
  4089. ,[ToWarehouseCode]
  4090. ,[ToLocationCode]
  4091. ,[Quantity]
  4092. ,[Memo]
  4093. ,[Lock]
  4094. ,[TransType]
  4095. ,[BusinessCode]
  4096. ,[ERPID]
  4097. ,[ERPDetailID]
  4098. ,[ERPCode]
  4099. ,[ERPSequence]
  4100. ,[MUSER]
  4101. ,[MUSERName]
  4102. ,[MTIME]
  4103. ,[WorkPoint]
  4104. ,[EATTRIBUTE1])
  4105. VALUES
  4106. (newid()
  4107. ,'{4}'
  4108. ,' '
  4109. ,'{0}'
  4110. ,(SELECT InvCode FROM ICSInventoryLot WHERE LotNo='{0}')
  4111. ,(SELECT WarehouseCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
  4112. ,(SELECT LocationCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
  4113. ,''
  4114. ,''
  4115. ,'{5}'
  4116. ,''
  4117. ,''
  4118. ,'21'
  4119. ,''
  4120. ,''
  4121. ,''
  4122. ,''
  4123. ,''
  4124. ,'{1}'
  4125. ,'{1}'
  4126. ,'{2}'
  4127. ,'{3}'
  4128. ,'')";
  4129. sqlLogInfoInf = string.Format(sqlLogInfoInf, itemInfo.LotNo, item.User, DateTime.Now, item.WorkPoint, item.TransCode, itemInfo.CurrentQuantity);
  4130. cmd.CommandText = sqlLogInfoInf;
  4131. num = cmd.ExecuteNonQuery();
  4132. //cmd.Transaction.Commit();
  4133. }
  4134. #endregion
  4135. #region ERP接口
  4136. string ERPSnd = @"select A.CusCode,A.SDNCode ,B.MUSER,MAX(B.MTIME) AS MTIME,b.TransSequence,b.TransCode,B.InvCode,b.FromWarehouseCode FROM ICSSDN a
  4137. inner join ICSWareHouseLotInfoLog b on a.SDNCode=b.TransCode and b.TransSequence=a.Sequence
  4138. where a.Type='1' and b.TransCode='{0}' and b.TransSequence='{1}' and b.WorkPoint='{2}'
  4139. group by A.CusCode,A.SDNCode ,B.MUSER,b.TransSequence,b.TransCode,B.InvCode,b.FromWarehouseCode";
  4140. ERPSnd = string.Format(ERPSnd, item.TransCode, itemInfo.TransSequence, item.WorkPoint);
  4141. table = DBHelper.SQlReturnData(ERPSnd, cmd);
  4142. string ERPSndList = @"select a.TransSequence,b.InvCode,sum(a.Quantity) as Quantity , isnull((b.Amount),0)as Amount ,b.SDNDetailID from ICSWareHouseLotInfoLog a
  4143. inner JOIN ICSSDN B ON b.SDNCode=a.TransCode and a.TransSequence=b.Sequence
  4144. where a.LotNo='{0}' and a.Memo<>'1' and b.WorkPoint='{1}' and b.Type='1'
  4145. group by a.TransSequence,b.InvCode, Amount ,b.SDNDetailID";
  4146. ERPSndList = string.Format(ERPSndList, itemInfo.LotNo, item.WorkPoint);
  4147. DataTable ERPtbSndList = DBHelper.SQlReturnData(ERPSndList, cmd);
  4148. List<ERPICSSDN> ERPemo = new List<ERPICSSDN>();
  4149. foreach (DataRow itemNotice in table.Rows)
  4150. {
  4151. ERPICSSDN noticeModel = new ERPICSSDN();
  4152. noticeModel.CusCode = itemNotice["CusCode"].ToString();
  4153. noticeModel.WHCode = itemNotice["FromWarehouseCode"].ToString();
  4154. noticeModel.SDNRTCode = itemNotice["SDNCode"].ToString();
  4155. noticeModel.User = itemNotice["MUSER"].ToString();
  4156. noticeModel.MTime = itemNotice["MTIME"].ToString();
  4157. List<ERPICSSDNList> noticeModelList = new List<ERPICSSDNList>();
  4158. foreach (DataRow ERPNoticeList in ERPtbSndList.Rows)
  4159. {
  4160. ERPICSSDNList listInfo = new ERPICSSDNList();
  4161. listInfo.Sequence = ERPNoticeList["TransSequence"].ToString();
  4162. listInfo.InvCode = ERPNoticeList["InvCode"].ToString();
  4163. listInfo.Quantity = ERPNoticeList["Quantity"].ToString();
  4164. listInfo.Amount = ERPNoticeList["Amount"].ToString();
  4165. listInfo.SDNRTDetailID = ERPNoticeList["SDNDetailID"].ToString();
  4166. noticeModelList.Add(listInfo);
  4167. }
  4168. noticeModel.details = noticeModelList;
  4169. ERPemo.Add(noticeModel);
  4170. string ERPICSSDN = JsonConvert.SerializeObject(ERPemo);
  4171. string Emoiresultsdn = HttpPost("销售出库单", ERPUrl.SalesDeliveryNoticeURL, ERPICSSDN);
  4172. Result OtherOutI = new Result();
  4173. OtherOutI = JsonConvert.DeserializeObject<Result>(Emoiresultsdn);
  4174. if (OtherOutI.Message != "200")
  4175. {
  4176. throw new Exception(OtherOutI.Message);
  4177. }
  4178. else
  4179. {
  4180. //OtherOutResult.Data;
  4181. }
  4182. }
  4183. #endregion
  4184. }
  4185. }
  4186. return 0;
  4187. #endregion
  4188. case "采购退货":
  4189. string sqlNotice = @"select * from ICSDeliveryNotice where DNCode='{0}' and Sequence='{1}' and DNType='2' and Status='3' and WorkPoint='{2}'";
  4190. sqlNotice = string.Format(sqlNotice, item.TransCode, itemInfo.TransSequence, item.WorkPoint);
  4191. DataTable Notice = DBHelper.SQlReturnData(sqlNotice, cmd);
  4192. if (Notice.Rows.Count > 0)
  4193. {
  4194. throw new Exception("单据已经关闭!");
  4195. }
  4196. foreach (DataRow itemdata in Notice.Rows)
  4197. {
  4198. int IssueQuantity = Convert.ToInt32(itemdata["RCVQuantity"]);//入库数量
  4199. int Quantity = Convert.ToInt32(itemdata["Quantity"]);//数量
  4200. int CurrentQuantity = Convert.ToInt32(Convert.ToDouble(itemInfo.CurrentQuantity));
  4201. int numQuantity = IssueQuantity + CurrentQuantity;//总数量
  4202. if (numQuantity > IssueQuantity)
  4203. {
  4204. throw new Exception("应退数量大于实际数量");
  4205. }
  4206. }
  4207. //修改退货表
  4208. sql = " update ICSDeliveryNotice set RCVQuantity = RCVQuantity + '{0}' where DNCode= '{1}' and WorkPoint='{2}' and Sequence='{3}' ";
  4209. sql = string.Format(sql, itemInfo.CurrentQuantity, item.TransCode, item.WorkPoint, itemInfo.TransSequence);
  4210. cmd.CommandText = sql;
  4211. num = cmd.ExecuteNonQuery();
  4212. //修改库存
  4213. sqlInfo = @"update ICSWareHouseLotInfo set Quantity= Quantity -'{0}' where lotno='{1}' and WorkPoint='{2}' ";
  4214. sqlInfo = string.Format(sqlInfo, itemInfo.CurrentQuantity, itemInfo.LotNo, item.WorkPoint);
  4215. cmd.CommandText = sqlInfo;
  4216. num = cmd.ExecuteNonQuery();
  4217. ///添加日志表
  4218. #region 添加日志
  4219. string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  4220. ([ID]
  4221. ,[TransCode]
  4222. ,[TransSequence]
  4223. ,[LotNo]
  4224. ,[InvCode]
  4225. ,[FromWarehouseCode]
  4226. ,[FromLocationCode]
  4227. ,[ToWarehouseCode]
  4228. ,[ToLocationCode]
  4229. ,[Quantity]
  4230. ,[Memo]
  4231. ,[Lock]
  4232. ,[TransType]
  4233. ,[BusinessCode]
  4234. ,[ERPID]
  4235. ,[ERPDetailID]
  4236. ,[ERPCode]
  4237. ,[ERPSequence]
  4238. ,[MUSER]
  4239. ,[MUSERName]
  4240. ,[MTIME]
  4241. ,[WorkPoint]
  4242. ,[EATTRIBUTE1])
  4243. ( select newid(),'{5}' ,'{6}' ,'{0}',b.InvCode,b.WarehouseCode,b.LocationCode,'','','{1}' ,'','','2' ,'' ,'' ,'' ,'','' ,'{2}' ,c.F_RealName,'{3}' ,'{4}' ,'{7}'
  4244. from ICSWareHouseLotInfo b
  4245. left join Sys_SRM_User c on c.F_Account='{2}' and c.F_Location='{4}'
  4246. where b.LotNo='{0}' and b.WorkPoint='{4}')";
  4247. sqlLog = string.Format(sqlLog, itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, DateTime.Now, item.WorkPoint, item.TransCode, itemInfo.TransSequence, itemInfo.Sequence);
  4248. cmd.CommandText = sqlLog;
  4249. int numlog = cmd.ExecuteNonQuery();
  4250. #endregion
  4251. #region ERP
  4252. sqlERP = @" select a.VenCode ,a.POID,b.FromWarehouseCode,b.TransCode,b.MUSER,b.TransSequence,b.InvCode,a.dncode,(getdate())as Mtime from ICSDeliveryNotice a
  4253. inner join ICSWareHouseLotInfoLog b on a.DNCode=b.TransCode and b.TransSequence=a.Sequence
  4254. where a.DNType='2' and b.TransCode='{0}' and b.WorkPoint='{1}' and a.Memo <> '1'
  4255. group by a.VenCode ,a.POID,b.FromWarehouseCode,b.TransCode,b.MUSER,b.TransSequence,b.InvCode,a.dncode";
  4256. sqlERP = string.Format(sqlERP, item.TransCode, item.WorkPoint);
  4257. table = DBHelper.SQlReturnData(sqlERP, cmd);
  4258. sqlERPDetil = @"select a.TransSequence,b.InvCode,sum(a.Quantity) as Quantity, isnull((b.Amount), 0) as Amount ,Currency,UnitPrice,b.DNDetailID from ICSWareHouseLotInfoLog a
  4259. inner JOIN ICSDeliveryNotice B ON b.DNCode = a.TransCode and a.TransSequence = b.Sequence
  4260. where LotNo = '{0}' and a.Memo <> '1' and a.WorkPoint='{1}'
  4261. group by a.TransSequence,b.InvCode,a.Quantity, Amount ,Currency,UnitPrice,b.DNDetailID";
  4262. sqlERPDetil = string.Format(sqlERPDetil, itemInfo.LotNo, item.WorkPoint);
  4263. DataTable ERPtables = DBHelper.SQlReturnData(sqlERPDetil, cmd);
  4264. List<ERPPurchaseOrder> docmodels = new List<ERPPurchaseOrder>();
  4265. foreach (DataRow dtIn in table.Rows)
  4266. {
  4267. ERPPurchaseOrder doc = new ERPPurchaseOrder();
  4268. doc.VenCode = dtIn["VenCode"].ToString();
  4269. doc.POCode = dtIn["POID"].ToString();
  4270. doc.User = dtIn["MUSER"].ToString();
  4271. doc.MTime = dtIn["Mtime"].ToString();
  4272. doc.WHCode = dtIn["FromWarehouseCode"].ToString();
  4273. doc.DNCode = dtIn["dncode"].ToString();
  4274. List<ERPPurchaseOrderList> list = new List<ERPPurchaseOrderList>();
  4275. foreach (DataRow dtList in ERPtables.Rows)
  4276. {
  4277. ERPPurchaseOrderList docc = new ERPPurchaseOrderList();
  4278. docc.Sequence = dtList["TransSequence"].ToString();
  4279. docc.InvCode = dtList["InvCode"].ToString();
  4280. docc.Quantity = dtList["Quantity"].ToString();
  4281. docc.Amount = dtList["Amount"].ToString();
  4282. docc.Currency = dtList["Currency"].ToString();
  4283. docc.UnitPrice = dtList["UnitPrice"].ToString();
  4284. docc.DNDetailID = dtList["DNDetailID"].ToString();
  4285. list.Add(docc);
  4286. }
  4287. doc.details = list;
  4288. docmodels.Add(doc);
  4289. }
  4290. IstrErp = JsonConvert.SerializeObject(docmodels);
  4291. iresult = HttpPost("采购退货", ERPUrl.PurchaseReturnBackURL, IstrErp);
  4292. Result OtherOutResults = new Result();
  4293. OtherOutResult = JsonConvert.DeserializeObject<Result>(iresult);
  4294. int numInfos = 0;
  4295. if (OtherOutResult.Success == false)
  4296. {
  4297. throw new Exception(OtherOutResult.Message);
  4298. }
  4299. else
  4300. {
  4301. List<ERPJsonRetun> list = new List<ERPJsonRetun>();
  4302. //string nn = OtherOutResult.Data.ToString();//LOTStockModel
  4303. list = JsonConvert.DeserializeObject<List<ERPJsonRetun>>(OtherOutResult.Data.ToString());
  4304. foreach (var items in list)
  4305. {
  4306. string ERPupdate = @"update ICSWareHouseLotInfoLog set ERPID='{0}',ERPDetailID='{1}',ERPCode='{2}',ERPSequence='{3}',Memo='1'
  4307. where TransCode='{4}' and TransSequence ='{5}'";
  4308. ERPupdate = string.Format(ERPupdate, items.ID, items.DetailID, items.RCVNEGCode, items.Sequence, item.TransCode, itemInfo.TransSequence);
  4309. cmd.CommandText = ERPupdate;
  4310. numInfos = cmd.ExecuteNonQuery();
  4311. }
  4312. if (numInfos > 0)
  4313. {
  4314. cmd.Transaction.Commit();
  4315. }
  4316. else
  4317. {
  4318. cmd.Transaction.Rollback();
  4319. }
  4320. //string sqlupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}'
  4321. // where DNCode='{4}'";
  4322. //sqlupdate = string.Format(sqlupdate);
  4323. }
  4324. #endregion
  4325. return 0;
  4326. case "委外发料":
  4327. string str = itemInfo.TransSequence;
  4328. string[] arrStr = str.Split(',');
  4329. string BSequence = arrStr[0].ToString();
  4330. string ASequence = arrStr[1].ToString();
  4331. string sqlverification = @"select * from ICSOOPick where OODetailID = (select OODetailID from ICSOutsourcingOrder where OOCode='{0}' and Sequence='{2}' and WorkPoint='{1}') and WorkPoint='{1}' AND Sequence='{3}'";
  4332. sqlverification = string.Format(sqlverification, item.TransCode, item.WorkPoint, BSequence, ASequence);
  4333. DataTable tabletion = DBHelper.SQlReturnData(sqlverification, cmd);
  4334. if (tabletion.Rows.Count <= 0)
  4335. {
  4336. throw new Exception("发料单不存在!");
  4337. }
  4338. sql = @"update ICSOOPick set IssueQuantity= (select IssueQuantity from ICSOOPick where OODetailID = (select OODetailID from ICSOutsourcingOrder where OOCode='{1}' and Sequence='{3}' and WorkPoint='{2}') and WorkPoint='{2}' AND Sequence='{4}' ) + '{0}' where OODetailID = (select OODetailID from ICSOutsourcingOrder where OOCode='{1}' and Sequence='{3}' and WorkPoint='{2}') and WorkPoint='{2}' AND Sequence='{4}' ";
  4339. sql = string.Format(sql, itemInfo.CurrentQuantity, item.TransCode, item.WorkPoint, BSequence, ASequence);
  4340. cmd.CommandText = sql;
  4341. num = cmd.ExecuteNonQuery();
  4342. sqlInfo = @"update ICSWareHouseLotInfo set Quantity= (select Quantity from ICSWareHouseLotInfo where lotno='{1}' and WorkPoint='{2}' ) -'{0}' where lotno='{1}' and WorkPoint='{2}' ";
  4343. sqlInfo = string.Format(sqlInfo, itemInfo.CurrentQuantity, itemInfo.LotNo, item.WorkPoint);
  4344. cmd.CommandText = sqlInfo;
  4345. num = cmd.ExecuteNonQuery();
  4346. #region 添加日志
  4347. string sqlPickLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  4348. ([ID]
  4349. ,[TransCode]
  4350. ,[TransSequence]
  4351. ,[LotNo]
  4352. ,[InvCode]
  4353. ,[FromWarehouseCode]
  4354. ,[FromLocationCode]
  4355. ,[ToWarehouseCode]
  4356. ,[ToLocationCode]
  4357. ,[Quantity]
  4358. ,[Memo]
  4359. ,[Lock]
  4360. ,[TransType]
  4361. ,[BusinessCode]
  4362. ,[ERPID]
  4363. ,[ERPDetailID]
  4364. ,[ERPCode]
  4365. ,[ERPSequence]
  4366. ,[MUSER]
  4367. ,[MUSERName]
  4368. ,[MTIME]
  4369. ,[WorkPoint]
  4370. ,[EATTRIBUTE1])
  4371. ( select newid(),'{5}' ,'{6}' ,'{0}',b.InvCode,b.WarehouseCode,b.LocationCode,'','','{1}' ,'','','7' ,'' ,'' ,'' ,'','' ,'{2}' ,c.F_RealName,'{3}' ,'{4}' ,'{7}'
  4372. from ICSWareHouseLotInfo b
  4373. left join Sys_SRM_User c on c.F_Account='{2}' and c.F_Location='{4}'
  4374. where b.LotNo='{0}' and b.WorkPoint='{4}')";
  4375. sqlPickLog = string.Format(sqlPickLog, itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, DateTime.Now, item.WorkPoint, item.TransCode, BSequence, itemInfo.TransSequence);
  4376. cmd.CommandText = sqlPickLog;
  4377. num = cmd.ExecuteNonQuery();
  4378. //if (numPicklog <= 0)
  4379. //{
  4380. // cmd.Transaction.Rollback();
  4381. //}
  4382. //else
  4383. //{
  4384. // cmd.Transaction.Commit();
  4385. //}
  4386. #endregion
  4387. #region ERP
  4388. string sqlERPOOPick = @" select b.DepCode,FromWarehouseCode,b.OOCode,a.MUSER ,(getdate())as Mtime from ICSWareHouseLotInfoLog a
  4389. left join ICSOutsourcingOrder b ON A.TransCode=B.OOCode and b.Sequence=a.TransSequence
  4390. left join ICSOOPick C on b.OODetailID=c.OODetailID and a.WorkPoint=b.WorkPoint and a.InvCode=b.InvCode
  4391. where b.OOCode='{0}' and a.WorkPoint='{1}' and a.memo<>'1'";
  4392. sqlERPOOPick = string.Format(sqlERPOOPick, item.TransCode, item.WorkPoint);
  4393. table = DBHelper.SQlReturnData(sqlERPOOPick, cmd);
  4394. string sqlERPPickList = @"select a.TransCode, a.TransSequence,a.InvCode,sum(a.Quantity) as Quantity , isnull((b.Amount),0)as Amount,c.PickID from ICSWareHouseLotInfoLog a
  4395. left JOIN ICSOutsourcingOrder B ON B.OOCode=A.TransCode and a.TransSequence=b.Sequence
  4396. left join ICSOOPick C on C.OODetailID=B.OODetailID and c.Sequence=a.TransSequence
  4397. where LotNo='{0}' and a.Memo<>'1'
  4398. group by a.TransCode, a.TransSequence,a.InvCode,b.Amount ,c.PickID ";
  4399. sqlERPPickList = string.Format(sqlERPPickList, itemInfo.LotNo);
  4400. DataTable ERPOOPick = DBHelper.SQlReturnData(sqlERPPickList, cmd);
  4401. string jsonPickList = null;
  4402. List<IssueDoc> docPickmodel = new List<IssueDoc>();
  4403. foreach (DataRow dt in table.Rows)
  4404. {
  4405. IssueDoc doc = new IssueDoc();
  4406. doc.DepCode = dt["DepCode"].ToString();
  4407. doc.WHCode = dt["FromWarehouseCode"].ToString();
  4408. doc.SourceType = dt["OOCode"].ToString();
  4409. doc.SourceCode = "委外发料";
  4410. doc.User = dt["MUSER"].ToString();
  4411. doc.MTime = dt["Mtime"].ToString();
  4412. List<IssueDocList> list = new List<IssueDocList>();
  4413. foreach (DataRow dtList in ERPOOPick.Rows)
  4414. {
  4415. IssueDocList docc = new IssueDocList();
  4416. docc.Sequence = dtList["TransSequence"].ToString();
  4417. docc.InvCode = dtList["InvCode"].ToString();
  4418. docc.Quantity = dtList["Quantity"].ToString();
  4419. docc.Amount = dtList["Amount"].ToString();
  4420. docc.SourceDetailID = dtList["PickID"].ToString();
  4421. list.Add(docc);
  4422. }
  4423. doc.details = list;
  4424. docPickmodel.Add(doc);
  4425. //jsonList = JsonConvert.SerializeObject(doc);
  4426. }
  4427. string IstrPick = JsonConvert.SerializeObject(docPickmodel);
  4428. log.Info("委外发料ERP传入的json" + IstrPick);
  4429. string iresultPick = HttpPost("委外发料", ERPUrl.OutsourcingIssueDocURL, IstrPick);
  4430. Result OtherOutResultpick = new Result();
  4431. OtherOutResultpick = JsonConvert.DeserializeObject<Result>(iresultPick);
  4432. List<ERPJsonRetun> m = new List<ERPJsonRetun>();
  4433. if (OtherOutResultpick.Success == true)
  4434. {
  4435. string nn = OtherOutResultpick.Data.ToString();//LOTStockModel
  4436. m = JsonConvert.DeserializeObject<List<ERPJsonRetun>>(nn);
  4437. foreach (var items in m)
  4438. {
  4439. string ERPupdate = @"update ICSWareHouseLotInfoLog set ERPID='{0}',ERPDetailID='{1}',ERPCode='{2}',ERPSequence='{3}',Memo='1'
  4440. where TransCode='{4}' and TransSequence ='{5}'";
  4441. ERPupdate = string.Format(ERPupdate, items.ID, items.DetailID, items.IssueCode, items.Sequence, item.TransCode, BSequence);
  4442. cmd.CommandText = ERPupdate;
  4443. num = cmd.ExecuteNonQuery();
  4444. }
  4445. if (num > 0)
  4446. {
  4447. cmd.Transaction.Commit();
  4448. }
  4449. else
  4450. {
  4451. cmd.Transaction.Rollback();
  4452. }
  4453. }
  4454. else
  4455. {
  4456. cmd.Transaction.Rollback();
  4457. throw new Exception(OtherOutResultpick.Message);
  4458. }
  4459. #endregion
  4460. return 0;
  4461. case "其它出库":
  4462. string sqlOtherOut = @"select * from ICSOtherOut where OutCode = '{0}' and WorkPoint='{1}' AND Sequence='{2}'";
  4463. sqlOtherOut = string.Format(sqlOtherOut, item.TransCode, item.WorkPoint, itemInfo.TransSequence);
  4464. DataTable tabletionIn = DBHelper.SQlReturnData(sqlOtherOut, cmd);
  4465. if (tabletionIn.Rows.Count <= 0)
  4466. {
  4467. throw new Exception("杂发单不存在!");
  4468. }
  4469. string sqlVerificationNum = @"select * from ICSWareHouseLotInfo where lotno='{0}' and '{2}'<= Quantity and WorkPoint='{1}'";
  4470. sqlVerificationNum = string.Format(sqlVerificationNum, itemInfo.LotNo, item.WorkPoint, itemInfo.CurrentQuantity);
  4471. DataTable dataTable = DBHelper.SQlReturnData(sqlVerificationNum, cmd);
  4472. if (dataTable.Rows.Count <= 0)
  4473. {
  4474. throw new Exception("输入数量大于库存数量");
  4475. }
  4476. //修改出库表
  4477. sql = @"update ICSOtherOut set OutQuantity= (select sum(OutQuantity) from ICSOtherOut where OutCode = '{1}')+'{0}' where OutCode = '{1}' and WorkPoint='{2}' AND Sequence='{3}' ";
  4478. sql = string.Format(sql, itemInfo.CurrentQuantity, item.TransCode, item.WorkPoint, itemInfo.TransSequence);
  4479. cmd.CommandText = sql;
  4480. num = cmd.ExecuteNonQuery();
  4481. //修改库存
  4482. sqlInfo = @"update ICSWareHouseLotInfo set Quantity= (select sum(Quantity) from ICSWareHouseLotInfo where lotno='{1}' and WorkPoint='{2}' ) -'{0}' where lotno='{1}' and WorkPoint='{2}' ";
  4483. sqlInfo = string.Format(sqlInfo, itemInfo.CurrentQuantity, itemInfo.LotNo, item.WorkPoint);
  4484. cmd.CommandText = sqlInfo;
  4485. num = cmd.ExecuteNonQuery();
  4486. ///添加日志
  4487. string sqlLogInfo = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  4488. ([ID]
  4489. ,[TransCode]
  4490. ,[TransSequence]
  4491. ,[LotNo]
  4492. ,[InvCode]
  4493. ,[FromWarehouseCode]
  4494. ,[FromLocationCode]
  4495. ,[ToWarehouseCode]
  4496. ,[ToLocationCode]
  4497. ,[Quantity]
  4498. ,[Memo]
  4499. ,[Lock]
  4500. ,[TransType]
  4501. ,[BusinessCode]
  4502. ,[ERPID]
  4503. ,[ERPDetailID]
  4504. ,[ERPCode]
  4505. ,[ERPSequence]
  4506. ,[MUSER]
  4507. ,[MUSERName]
  4508. ,[MTIME]
  4509. ,[WorkPoint]
  4510. ,[EATTRIBUTE1])
  4511. (select newid(),'{0}','{1}','{2}',a.InvCode ,' ', ' ',b.WarehouseCode,b.LocationCode,'{3}',' ','0','2','8',' ',' ',' ',' ','{4}',e.F_RealName,'{5}','{6}',' '
  4512. from ICSOtherOut a--
  4513. left join ICSWareHouseLotInfo b on b.LotNo='{2}'
  4514. left join Sys_SRM_User e on e.F_Account='{4}' and e.F_Location='{6}'
  4515. where a.mocode='{0}' and a.WorkPoint='{6}' and Sequence='{1}')";
  4516. sqlLogInfo = string.Format(sqlLogInfo, item.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, DateTime.Now, item.WorkPoint);
  4517. //left join ICSWarehouse c on c.WarehouseCode = a.WHCode and c.WorkPoint = a.WorkPoint--仓库
  4518. // left join ICSLocation d on d.WHID = c.ID and d.WorkPoint = c.WorkPoint--库位
  4519. cmd.CommandText = sqlLogInfo;
  4520. int numInfoLot = cmd.ExecuteNonQuery();
  4521. if (numInfoLot > 0)
  4522. {
  4523. cmd.Transaction.Commit();
  4524. }
  4525. else
  4526. {
  4527. cmd.Transaction.Rollback();
  4528. }
  4529. return 0;
  4530. }
  4531. }
  4532. }
  4533. return 0;
  4534. }
  4535. catch (Exception ex)
  4536. {
  4537. // cmd.Transaction.Rollback();
  4538. log.Error(ex.Message);
  4539. throw new Exception(ex.Message);
  4540. }
  4541. finally
  4542. {
  4543. if (conn.State == ConnectionState.Open)
  4544. {
  4545. conn.Close();
  4546. }
  4547. conn.Dispose();
  4548. }
  4549. }
  4550. #endregion
  4551. #region 合并
  4552. /// <summary>
  4553. /// 合并 查询
  4554. /// </summary>
  4555. /// <param name="JsonData"></param>
  4556. /// <returns></returns>
  4557. public List<WMSTBarCodeModelInfo> LOTMergeGet(WMSTBarCodeModel JsonData)
  4558. {
  4559. List<WMSTBarCodeModelInfo> model = new List<WMSTBarCodeModelInfo>();
  4560. conn.Open();
  4561. SqlTransaction sqlTran = conn.BeginTransaction();
  4562. SqlCommand cmd = new SqlCommand();
  4563. cmd.Transaction = sqlTran;
  4564. cmd.Connection = conn;
  4565. try
  4566. {
  4567. sql = @"SELECT
  4568. a.[ID] --
  4569. ,[TransCode] --
  4570. ,[TransSequence]--
  4571. ,a.[LotNo] --
  4572. ,a.[InvCode] --
  4573. ,a.[Quantity] --
  4574. ,c.WarehouseCode as WHCode --
  4575. ,c.WarehouseName as WHName --
  4576. ,d.LocationCode as LocationCode --
  4577. ,d.LocationName as LocationName --
  4578. ,e.name as BusinessCode
  4579. ,a.MUSER --
  4580. ,a.[MTIME] --
  4581. FROM [ICSWMS_Base].[dbo].[ICSWareHouseLotInfoLog] a --
  4582. left join ICSWareHouseLotInfo b on a.LotNo=b.LotNo and b.InvCode=a.InvCode and a.WorkPoint=b.WorkPoint --
  4583. left join ICSWarehouse c on c.WarehouseCode=b.WarehouseCode and c.WorkPoint=b.WorkPoint--
  4584. left join ICSLocation d on b.LocationCode=d.LocationCode and b.WorkPoint=d.WorkPoint--
  4585. left join ICSType e on a.BusinessCode=e.ColumnCode and e.Code=a.BusinessCode and e.WorkPoint=a.WorkPoint --
  4586. where 1=1 ";
  4587. if (!string.IsNullOrEmpty(JsonData.TransCode))
  4588. {
  4589. sql += " and TransCode='{0}'";
  4590. sql = string.Format(sql, JsonData.TransCode);
  4591. }
  4592. if (!string.IsNullOrEmpty(JsonData.User))
  4593. {
  4594. sql += " and MUSER='{1}'";
  4595. sql = string.Format(sql, JsonData.User);
  4596. }
  4597. if (JsonData.MTime.ToString() != "0001/1/1 0:00:00")
  4598. {
  4599. sql += " and MTIME='{2}'";
  4600. sql = string.Format(sql, JsonData.MTime);
  4601. }
  4602. table = DBHelper.SQlReturnData(sql, cmd);
  4603. string json = JsonConvert.SerializeObject(table);
  4604. model = JsonConvert.DeserializeObject<List<WMSTBarCodeModelInfo>>(json);//<List<WMSSourceDocumentModel>>
  4605. cmd.Transaction.Commit();
  4606. return model;
  4607. }
  4608. catch (Exception ex)
  4609. {
  4610. cmd.Transaction.Rollback();
  4611. log.Error(ex.Message);
  4612. throw new Exception(ex.Message);
  4613. }
  4614. finally
  4615. {
  4616. if (conn.State == ConnectionState.Open)
  4617. {
  4618. conn.Close();
  4619. }
  4620. conn.Dispose();
  4621. }
  4622. }
  4623. /// <summary>
  4624. /// 合并Create
  4625. /// </summary>
  4626. /// <param name="JsonData"></param>
  4627. /// <returns></returns>,
  4628. public List<WMSTBarCodeModelInfo> LOTMergeCreate(List<LOTCreateIModel> JsonData)
  4629. {
  4630. List<WMSTBarCodeModelInfo> model = new List<WMSTBarCodeModelInfo>();
  4631. var lotNo = string.Empty;
  4632. var CoreNo = string.Empty;//合并的条码
  4633. decimal num = 0;//合并的数量
  4634. var cnum = string.Empty;
  4635. string str = string.Empty;
  4636. string WorkPoint = null;
  4637. string UserName = string.Empty;
  4638. string TransNos = "";
  4639. int numInfo = 0;
  4640. conn.Open();
  4641. SqlTransaction sqlTran = conn.BeginTransaction();
  4642. SqlCommand cmd = new SqlCommand();
  4643. cmd.Transaction = sqlTran;
  4644. cmd.Connection = conn;
  4645. try
  4646. {
  4647. List<string> list = new List<string>();
  4648. ///第一个条码的数量
  4649. foreach (var item in JsonData)
  4650. {
  4651. lotNo = item.LotNo;//条码
  4652. UserName = item.User;
  4653. foreach (var itemInfo in item.detail)
  4654. {
  4655. CoreNo = itemInfo.CurrentLotNo;//合并的条码
  4656. num += Convert.ToDecimal(itemInfo.CurrentQuantity);//合并的数量
  4657. WorkPoint = itemInfo.WorkPoint;
  4658. list.Add(CoreNo);
  4659. }
  4660. }
  4661. //str = string.Join(",", list.ToArray());
  4662. ///主表条码
  4663. //int UpdatenumInfo = 0;
  4664. foreach (var item in list.ToArray())
  4665. {
  4666. str = item.ToString();
  4667. string sql = @"update ICSWareHouseLotInfo set Quantity='0' where LotNo = '{0}' and WorkPoint='{1}'";
  4668. sql = string.Format(sql, str, WorkPoint);
  4669. cmd.CommandText = sql;
  4670. numInfo = cmd.ExecuteNonQuery();
  4671. }
  4672. string updateSql = @"update ICSWareHouseLotInfo set Quantity=(select Quantity from ICSWareHouseLotInfo where LotNo='{1}' and WorkPoint='{2}')+'{0}' where LotNo='{1}' and WorkPoint='{2}'";
  4673. updateSql = string.Format(updateSql, num, lotNo, WorkPoint);
  4674. cmd.CommandText = updateSql;
  4675. numInfo = cmd.ExecuteNonQuery();
  4676. string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  4677. ([ID]
  4678. ,[TransCode]
  4679. ,[TransSequence]
  4680. ,[LotNo]
  4681. ,[InvCode]
  4682. ,[FromWarehouseCode]
  4683. ,[FromLocationCode]
  4684. ,[ToWarehouseCode]
  4685. ,[ToLocationCode]
  4686. ,[Quantity]
  4687. ,[Memo]
  4688. ,[Lock]
  4689. ,[TransType]
  4690. ,[BusinessCode]
  4691. ,[ERPID]
  4692. ,[ERPDetailID]
  4693. ,[ERPCode]
  4694. ,[ERPSequence]
  4695. ,[MUSER]
  4696. ,[MUSERName]
  4697. ,[MTIME]
  4698. ,[WorkPoint]
  4699. ,[EATTRIBUTE1])
  4700. (select newid(),b.TransCode,b.TransSequence,'{0}',a.InvCode ,a.WarehouseCode,a.LocationCode ,'','',a.Quantity,' ','0','5','18',' ',' ',' ',' ','{1}',e.F_RealName,'{2}','{3}',' '
  4701. from ICSWareHouseLotInfo a--
  4702. left join ICSInventoryLotDetail b on b.LotNo=a.LotNo
  4703. left join Sys_SRM_User e on e.F_Account='{1}' and e.F_Location='{3}'
  4704. where a.LotNo='{0}' and a.WorkPoint='{3}' )";
  4705. sqlLog = string.Format(sqlLog, lotNo, UserName, DateTime.Now, WorkPoint);
  4706. cmd.CommandText = sqlLog;
  4707. int numLog = cmd.ExecuteNonQuery();
  4708. if (numLog > 0)
  4709. {
  4710. cmd.Transaction.Commit();
  4711. }
  4712. else
  4713. {
  4714. cmd.Transaction.Rollback();
  4715. }
  4716. return null;
  4717. }
  4718. catch (Exception ex)
  4719. {
  4720. //cmd.Transaction.Rollback();
  4721. log.Error(ex.Message);
  4722. throw new Exception(ex.Message);
  4723. }
  4724. finally
  4725. {
  4726. if (conn.State == ConnectionState.Open)
  4727. {
  4728. conn.Close();
  4729. }
  4730. conn.Dispose();
  4731. }
  4732. }
  4733. /// <summary>
  4734. /// 拆分
  4735. /// </summary>
  4736. /// <param name="JsonData"></param>
  4737. /// <returns></returns>
  4738. public List<WMSTBarCodeModelInfo> LOTSplitCreates(List<LOTCreateIModel> JsonData)
  4739. {
  4740. //List<WMSTBarCodeModelInfo> model = new List<WMSTBarCodeModelInfo>();
  4741. var lotNo = string.Empty;
  4742. var CoreNo = string.Empty;//拆分的条码
  4743. int num = 0;//拆分的数量
  4744. var cnum = string.Empty;//拆分总数量
  4745. string str = string.Empty;
  4746. string WorkPoint = string.Empty;//站点
  4747. string UserName = string.Empty;
  4748. int numInfo = 0;
  4749. Decimal numm = 0;
  4750. conn.Open();
  4751. SqlTransaction sqlTran = conn.BeginTransaction();
  4752. SqlCommand cmd = new SqlCommand();
  4753. cmd.Transaction = sqlTran;
  4754. cmd.Connection = conn;
  4755. try
  4756. {
  4757. List<LOTCreateIModelInfo> list = new List<LOTCreateIModelInfo>();
  4758. ///第一个条码的数量
  4759. foreach (var item in JsonData)
  4760. {
  4761. lotNo = item.LotNo;//条码
  4762. UserName = item.User;
  4763. WorkPoint = item.WorkPoint;
  4764. foreach (var itemInfo in item.detail)
  4765. {
  4766. LOTCreateIModelInfo modelInfo = new LOTCreateIModelInfo();
  4767. modelInfo.CurrentLotNo = itemInfo.CurrentLotNo;//拆分的条码
  4768. modelInfo.CurrentQuantity = itemInfo.CurrentQuantity;//拆分的数量
  4769. modelInfo.WorkPoint = itemInfo.WorkPoint;
  4770. numm += Convert.ToDecimal(itemInfo.CurrentQuantity);
  4771. list.Add(modelInfo);
  4772. }
  4773. }
  4774. //拆分之前记录日志
  4775. //string sqlFront = @"select * from ICSWareHouseLotInfo where LotNo='{0}' and WorkPoint='{1}'";
  4776. //sqlFront = string.Format(sqlFront,lotNo, WorkPoint);
  4777. string primaryLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  4778. ([ID]
  4779. ,[TransCode]
  4780. ,[TransSequence]
  4781. ,[LotNo]
  4782. ,[InvCode]
  4783. ,[FromWarehouseCode]
  4784. ,[FromLocationCode]
  4785. ,[ToWarehouseCode]
  4786. ,[ToLocationCode]
  4787. ,[Quantity]
  4788. ,[Memo]
  4789. ,[Lock]
  4790. ,[TransType]
  4791. ,[BusinessCode]
  4792. ,[ERPID]
  4793. ,[ERPDetailID]
  4794. ,[ERPCode]
  4795. ,[ERPSequence]
  4796. ,[MUSER]
  4797. ,[MUSERName]
  4798. ,[MTIME]
  4799. ,[WorkPoint]
  4800. ,[EATTRIBUTE1])
  4801. (select newid(),b.TransCode,b.TransSequence,'{0}',a.InvCode ,a.WarehouseCode,a.LocationCode ,'','',a.Quantity,' ','0','4','16',' ',' ',' ',' ','{1}',e.F_RealName,'{2}','{3}',' '
  4802. from ICSWareHouseLotInfo a--
  4803. left join ICSInventoryLotDetail b on b.LotNo=a.LotNo
  4804. left join Sys_SRM_User e on e.F_Account='{1}' and e.F_Location='{3}'
  4805. where a.LotNo='{0}' and a.WorkPoint='{3}')";
  4806. primaryLog = string.Format(primaryLog, lotNo, UserName, DateTime.Now, WorkPoint);
  4807. cmd.CommandText = primaryLog;
  4808. int primarynumLog = cmd.ExecuteNonQuery();
  4809. ///拆分后的条码数量
  4810. foreach (var item in list.ToArray())
  4811. {
  4812. CoreNo = item.CurrentLotNo;//条码
  4813. num = Convert.ToInt32(item.CurrentQuantity);//数量
  4814. WorkPoint = item.WorkPoint;//站点
  4815. //拆分条码
  4816. string sql = @"INSERT INTO [dbo].[ICSWareHouseLotInfo]
  4817. ([ID]
  4818. ,[LotNo]
  4819. ,[WarehouseCode]
  4820. ,[LocationCode]
  4821. ,[InvCode]
  4822. ,[Quantity]
  4823. ,[InDate]
  4824. ,[LockQuantity]
  4825. ,[MUSER]
  4826. ,[MUSERName]
  4827. ,[MTIME]
  4828. ,[WorkPoint]
  4829. ,[EATTRIBUTE1])
  4830. select newid()
  4831. ,'{0}'
  4832. ,WarehouseCode
  4833. ,LocationCode
  4834. ,InvCode
  4835. ,'{1}'
  4836. ,InDate
  4837. ,LockQuantity
  4838. ,'{2}'
  4839. ,b.F_RealName
  4840. ,'{3}'
  4841. ,'{4}'
  4842. ,EATTRIBUTE1
  4843. from ICSWareHouseLotInfo
  4844. left join Sys_SRM_User b on b.F_Account='{2}' and b.F_Location='{4}' ";
  4845. sql = string.Format(sql, CoreNo, num, UserName, DateTime.Now, WorkPoint);
  4846. cmd.CommandText = sql;
  4847. numInfo = cmd.ExecuteNonQuery();
  4848. if (numInfo == 0)
  4849. {
  4850. throw new Exception("已经拆分过,请无重复拆分," + "拆分的条码:" + CoreNo);
  4851. }
  4852. }
  4853. ///拆分日志
  4854. foreach (var item in list.ToArray())
  4855. {
  4856. CoreNo = item.CurrentLotNo;//条码
  4857. num = Convert.ToInt32(item.CurrentQuantity);//数量
  4858. WorkPoint = item.WorkPoint;//站点
  4859. //拆分 日志
  4860. string sqlLogs = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  4861. ([ID]
  4862. ,[TransCode]
  4863. ,[TransSequence]
  4864. ,[LotNo]
  4865. ,[InvCode]
  4866. ,[FromWarehouseCode]
  4867. ,[FromLocationCode]
  4868. ,[ToWarehouseCode]
  4869. ,[ToLocationCode]
  4870. ,[Quantity]
  4871. ,[Memo]
  4872. ,[Lock]
  4873. ,[TransType]
  4874. ,[BusinessCode]
  4875. ,[ERPID]
  4876. ,[ERPDetailID]
  4877. ,[ERPCode]
  4878. ,[ERPSequence]
  4879. ,[MUSER]
  4880. ,[MUSERName]
  4881. ,[MTIME]
  4882. ,[WorkPoint]
  4883. ,[EATTRIBUTE1])
  4884. (select newid(),b.TransCode,b.TransSequence,'{0}',a.InvCode ,a.WarehouseCode,a.LocationCode ,'','','{4}',' ','0','4','15',' ',' ',' ',' ','{1}',e.F_RealName,'{2}','{3}',' '
  4885. from ICSWareHouseLotInfo a--
  4886. left join ICSInventoryLotDetail b on b.LotNo=a.LotNo
  4887. left join Sys_SRM_User e on e.F_Account='{1}' and e.F_Location='{3}'
  4888. where a.LotNo='{0}' and a.WorkPoint='{3}' )";
  4889. sqlLogs = string.Format(sqlLogs, CoreNo, UserName, DateTime.Now, WorkPoint, num);
  4890. cmd.CommandText = sqlLogs;
  4891. numInfo = cmd.ExecuteNonQuery();
  4892. }
  4893. //修改拆分总数量
  4894. string updateSql = @"update ICSWareHouseLotInfo set Quantity=(select Quantity from ICSWareHouseLotInfo where LotNo='{1}' and WorkPoint='{2}')-'{0}' where LotNo='{1}' and WorkPoint='{2}'";
  4895. updateSql = string.Format(updateSql, numm, lotNo, WorkPoint);
  4896. cmd.CommandText = updateSql;
  4897. numInfo = cmd.ExecuteNonQuery();
  4898. string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  4899. ([ID]
  4900. ,[TransCode]
  4901. ,[TransSequence]
  4902. ,[LotNo]
  4903. ,[InvCode]
  4904. ,[FromWarehouseCode]
  4905. ,[FromLocationCode]
  4906. ,[ToWarehouseCode]
  4907. ,[ToLocationCode]
  4908. ,[Quantity]
  4909. ,[Memo]
  4910. ,[Lock]
  4911. ,[TransType]
  4912. ,[BusinessCode]
  4913. ,[ERPID]
  4914. ,[ERPDetailID]
  4915. ,[ERPCode]
  4916. ,[ERPSequence]
  4917. ,[MUSER]
  4918. ,[MUSERName]
  4919. ,[MTIME]
  4920. ,[WorkPoint]
  4921. ,[EATTRIBUTE1])
  4922. (select newid(),b.TransCode,b.TransSequence,'{0}',a.InvCode ,a.WarehouseCode,a.LocationCode ,'','',a.Quantity,' ','0','4','15',' ',' ',' ',' ','{1}',e.F_RealName,'{2}','{3}',' '
  4923. from ICSWareHouseLotInfo a--
  4924. left join ICSInventoryLotDetail b on b.LotNo=a.LotNo
  4925. left join Sys_SRM_User e on e.F_Account='{1}' and e.F_Location='{3}'
  4926. where a.LotNo='{0}' and a.WorkPoint='{3}' )";
  4927. sqlLog = string.Format(sqlLog, lotNo, UserName, DateTime.Now, WorkPoint);
  4928. cmd.CommandText = sqlLog;
  4929. int numLog = cmd.ExecuteNonQuery();
  4930. if (numLog > 0)
  4931. {
  4932. cmd.Transaction.Commit();
  4933. }
  4934. else
  4935. {
  4936. cmd.Transaction.Rollback();
  4937. }
  4938. return null;
  4939. }
  4940. catch (Exception ex)
  4941. {
  4942. //cmd.Transaction.Rollback();
  4943. log.Error(ex.Message);
  4944. throw new Exception(ex.Message);
  4945. }
  4946. finally
  4947. {
  4948. if (conn.State == ConnectionState.Open)
  4949. {
  4950. conn.Close();
  4951. }
  4952. conn.Dispose();
  4953. }
  4954. }
  4955. /// <summary>
  4956. /// 更新
  4957. /// </summary>
  4958. public string LOTReviseUpdate(LOTReviseUpdateIModel JsonData)
  4959. {
  4960. List<LOTReviseUpdateIModel> model = new List<LOTReviseUpdateIModel>();
  4961. conn.Open();
  4962. SqlTransaction sqlTran = conn.BeginTransaction();
  4963. SqlCommand cmd = new SqlCommand();
  4964. int result = 0;
  4965. string resultInfo = "数量为0";
  4966. cmd.Transaction = sqlTran;
  4967. cmd.Connection = conn;
  4968. try
  4969. {
  4970. #region 更新ICSWareHouseInfo表
  4971. sql = @"update ICSWareHouseLotInfo
  4972. set Quantity=Quantity - {0},MTIME='{1}'
  4973. where INVCode='{2}' and WorkPoint='{3}'
  4974. update ICSWareHouseLotInfoLog
  4975. set Quantity=Quantity + {0},MTIME='{1}'
  4976. where INVCode='{2}' and WorkPoint='{4}'";
  4977. sql = string.Format(sql, JsonData.Quantityl, DateTime.Now, JsonData.LotNo, JsonData.WorkPoint);
  4978. cmd.CommandText = sql;
  4979. result = cmd.ExecuteNonQuery();//返回条数
  4980. #endregion
  4981. if (result > 0)
  4982. {
  4983. return result.ToString();
  4984. }
  4985. return resultInfo;
  4986. }
  4987. catch (Exception ex)
  4988. {
  4989. cmd.Transaction.Rollback();
  4990. log.Error(ex.Message);
  4991. throw new Exception(ex.Message);
  4992. }
  4993. finally
  4994. {
  4995. if (conn.State == ConnectionState.Open)
  4996. {
  4997. conn.Close();
  4998. }
  4999. conn.Dispose();
  5000. }
  5001. }
  5002. #endregion
  5003. #region 盘点
  5004. /// <summary>
  5005. /// 盘点
  5006. /// </summary>
  5007. /// <param name="JsonData"></param>
  5008. /// <returns></returns>
  5009. public List<ICSCheck> LOTCheckGet(List<ICSCheck> JsonData)
  5010. {
  5011. List<ICSCheck> model = new List<ICSCheck>();
  5012. conn.Open();
  5013. SqlTransaction sqlTran = conn.BeginTransaction();
  5014. SqlCommand cmd = new SqlCommand();
  5015. int result = 0;
  5016. string resultInfo = null;
  5017. cmd.Transaction = sqlTran;
  5018. cmd.Connection = conn;
  5019. try
  5020. {
  5021. foreach (var item in JsonData)
  5022. {
  5023. if (item.CheckCode == null)
  5024. {
  5025. resultInfo = "盘点单号不能为空!";
  5026. }
  5027. #region 查询该盘点号是否有数据
  5028. sql = @"select count(CheckCode) from ICSCheck
  5029. where CheckCode={0}";
  5030. sql = string.Format(sql, item.CheckCode);
  5031. cmd.CommandText = sql;
  5032. result = cmd.ExecuteNonQuery();//返回条数
  5033. if (result > 0)
  5034. {
  5035. sql = @"select
  5036. a.ID,
  5037. a.CheckCode,
  5038. a.WHCode,
  5039. B.WarehouseName,
  5040. a.InvCode,
  5041. a.Quantity,
  5042. a.ActualQuantity,
  5043. a.MUSER,
  5044. a.MTIME,
  5045. c.id,
  5046. c.LotNo,
  5047. c.ActualQuantity,
  5048. c.Quantity
  5049. from ICSCheck a
  5050. left join ICSWarehouse b on a.WHCode=B.WarehouseCode and a.WorkPoint=b.WorkPoint
  5051. left join ICSCheckDetail c on c.CheckCode=a.CheckCode and c.WorkPoint=a.WorkPoint
  5052. where 1=1 and a.CheckCode='{0}'";
  5053. sql = string.Format(sql, item.CheckCode, item.MTime, item.User);
  5054. table = DBHelper.SQlReturnData(sql, cmd);
  5055. string json = JsonConvert.SerializeObject(table);
  5056. model = JsonConvert.DeserializeObject<List<ICSCheck>>(json);//<List<WMSSourceDocumentModel>>
  5057. cmd.Transaction.Commit();
  5058. return model;
  5059. }
  5060. else
  5061. {
  5062. resultInfo = "没有数据!";
  5063. }
  5064. }
  5065. #endregion
  5066. return null;
  5067. }
  5068. catch (Exception ex)
  5069. {
  5070. cmd.Transaction.Rollback();
  5071. log.Error(ex.Message);
  5072. throw new Exception(ex.Message);
  5073. }
  5074. finally
  5075. {
  5076. if (conn.State == ConnectionState.Open)
  5077. {
  5078. conn.Close();
  5079. }
  5080. conn.Dispose();
  5081. }
  5082. }
  5083. /// <summary>
  5084. /// 盘点添加
  5085. /// </summary>
  5086. /// <param name="JsonData"></param>
  5087. /// <returns></returns>
  5088. public string LOTCheckCreate(List<ICSCheck> infoModel)
  5089. {
  5090. List<ICSCheck> model = new List<ICSCheck>();
  5091. DataTable dt = null;
  5092. conn.Open();
  5093. SqlTransaction sqlTran = conn.BeginTransaction();
  5094. SqlCommand cmd = new SqlCommand();
  5095. cmd.Transaction = sqlTran;
  5096. cmd.Connection = conn;
  5097. string result = null;
  5098. int resultInfo = 0;
  5099. int Status = 1;
  5100. try
  5101. {
  5102. //根据条码查询库存数量
  5103. foreach (var item in infoModel)
  5104. {
  5105. foreach (var itemInfo in item.detail)
  5106. {
  5107. sql = @"select * from ICSWareHouseLotInfo where LotNo='{0}' ";
  5108. sql = string.Format(sql, itemInfo.LotNo);
  5109. dt = DBHelper.SQlReturnData(sql, cmd);
  5110. if (dt.Rows.Count > 0)
  5111. {
  5112. sql = @"INSERT INTO [dbo].[ICSCheck]
  5113. ([ID]
  5114. ,[CheckCode]
  5115. ,[WHCode]
  5116. ,[InvCode]
  5117. ,[Status]
  5118. ,[Quantity]
  5119. ,[MUSER]
  5120. ,[MTIME]
  5121. ,MUSERName
  5122. ,[WorkPoint])
  5123. VALUES
  5124. ( NEWID(),
  5125. '{0}',
  5126. (select WarehouseCode from ICSWareHouseLotInfo where LotNo='{4}' ),
  5127. (select InvCode from ICSWareHouseLotInfo where LotNo='{4}'),
  5128. '1',
  5129. (select Quantity from ICSWareHouseLotInfo where LotNo='{4}'),
  5130. '{1}',
  5131. '{2}',
  5132. '{1}',
  5133. '{3}' )";
  5134. sql = string.Format(sql, item.CheckCode, item.User, item.MTime, item.WorkPoint, itemInfo.LotNo);
  5135. cmd.CommandText = sql;
  5136. DBHelper.CmdExecuteNonQuery(sql, cmd, "成功");
  5137. resultInfo = cmd.ExecuteNonQuery();//返回条数
  5138. sqlInfo = @" INSERT INTO [dbo].[ICSCheckDetail]
  5139. ([ID]
  5140. ,[CheckCode]
  5141. ,[LotNo]
  5142. ,[Quantity]
  5143. ,[ActualQuantity]
  5144. ,[MUSER]
  5145. ,[MUSERName]
  5146. ,[MTIME]
  5147. ,[WorkPoint])
  5148. VALUES(
  5149. newid(),'{0}','{1}',
  5150. (select Quantity from ICSWareHouseLotInfo where LotNo='{1}'),
  5151. '{4}',
  5152. '{2}','{2}','{3}')";
  5153. sqlInfo = string.Format(sqlInfo, item.CheckCode, itemInfo.LotNo, item.User, item.MTime, itemInfo.ActualQuantity);
  5154. cmd.CommandText = sqlInfo;
  5155. DBHelper.CmdExecuteNonQuery(sqlInfo, cmd, "成功");
  5156. resultInfo = cmd.ExecuteNonQuery();//返回条数
  5157. }
  5158. else
  5159. {
  5160. throw new Exception("条码没有查询到数据");
  5161. }
  5162. }
  5163. }
  5164. }
  5165. catch (Exception ex)
  5166. {
  5167. cmd.Transaction.Rollback();
  5168. log.Error(ex.Message);
  5169. throw new Exception(ex.Message);
  5170. }
  5171. finally
  5172. {
  5173. if (conn.State == ConnectionState.Open)
  5174. {
  5175. conn.Close();
  5176. }
  5177. conn.Dispose();
  5178. }
  5179. return resultInfo.ToString();
  5180. }
  5181. /// <summary>
  5182. /// 删除盘点数据
  5183. /// </summary>
  5184. /// <param name="infoModel"></param>
  5185. /// <returns></returns>
  5186. public string LOTCheckDelete(List<ICSCheck> infoModel)
  5187. {
  5188. List<ICSCheck> model = new List<ICSCheck>();
  5189. DataTable dt = null;
  5190. conn.Open();
  5191. SqlTransaction sqlTran = conn.BeginTransaction();
  5192. SqlCommand cmd = new SqlCommand();
  5193. cmd.Transaction = sqlTran;
  5194. cmd.Connection = conn;
  5195. int resultInfo = 0;
  5196. try
  5197. {
  5198. foreach (var item in infoModel)
  5199. {
  5200. foreach (var itemInfo in item.detail)
  5201. {
  5202. ///先删除主表在删除子表
  5203. sql = @"DELETE FROM ICSCheck where CheckCode=(select CheckCode from ICSCheckDetail where LotNo='{0}')
  5204. DELETE FROM ICSCheckDetail where LotNo='{0}' and WorkPoint='{1}'";
  5205. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint);
  5206. cmd.CommandText = sql;
  5207. resultInfo = cmd.ExecuteNonQuery();//返回条数
  5208. }
  5209. }
  5210. }
  5211. catch (Exception ex)
  5212. {
  5213. cmd.Transaction.Rollback();
  5214. log.Error(ex.Message);
  5215. throw new Exception(ex.Message);
  5216. }
  5217. finally
  5218. {
  5219. if (conn.State == ConnectionState.Open)
  5220. {
  5221. conn.Close();
  5222. }
  5223. conn.Dispose();
  5224. }
  5225. return resultInfo.ToString();
  5226. }
  5227. #endregion
  5228. #region 审核
  5229. /// <summary>
  5230. /// 审核
  5231. /// </summary>
  5232. /// <param name="infoModel"></param>
  5233. /// <returns></returns>
  5234. public string MOIssueDocNegativeApplyApprove(List<ICSMOApplyNeg> infoModel)
  5235. {
  5236. List<ICSMOApplyNeg> model = new List<ICSMOApplyNeg>();
  5237. conn.Open();
  5238. SqlTransaction sqlTran = conn.BeginTransaction();
  5239. SqlCommand cmd = new SqlCommand();
  5240. cmd.Transaction = sqlTran;
  5241. cmd.Connection = conn;
  5242. int resultInfo = 0;
  5243. string num = "审核成功!";
  5244. try
  5245. {
  5246. foreach (var item in infoModel)
  5247. {
  5248. foreach (var itemInfo in item.detail)
  5249. {
  5250. //先查询是否已经审核过
  5251. sql = @"select * from ICSMOApplyNeg where status='2' and id='{0}' and WorkPoint='{1}'";
  5252. sql = string.Format(sql, item.ID, itemInfo.WorkPoint);
  5253. DataTable dataTable = DBHelper.SQlReturnData(sql, cmd);
  5254. if (dataTable.Rows.Count > 0)
  5255. {
  5256. throw new Exception("已经审核过,请重复审核");
  5257. }
  5258. else
  5259. {
  5260. string sqlInfo = @"update ICSMOApplyNeg set status ='1' where id='{0}' and WorkPoint='{1}'";
  5261. sqlInfo = string.Format(sqlInfo, item.ID, itemInfo.WorkPoint);
  5262. DataTable data = DBHelper.SQlReturnData(sqlInfo, cmd);
  5263. if (data.Rows.Count > 0)
  5264. {
  5265. return num;
  5266. }
  5267. }
  5268. }
  5269. }
  5270. }
  5271. catch (Exception ex)
  5272. {
  5273. cmd.Transaction.Rollback();
  5274. log.Error(ex.Message);
  5275. throw new Exception(ex.Message);
  5276. }
  5277. finally
  5278. {
  5279. if (conn.State == ConnectionState.Open)
  5280. {
  5281. conn.Close();
  5282. }
  5283. conn.Dispose();
  5284. }
  5285. return num;
  5286. }
  5287. #endregion
  5288. #region 生产退料
  5289. /// <summary>
  5290. /// 查询
  5291. /// </summary>
  5292. /// <param name="infoModel"></param>
  5293. /// <returns></returns>
  5294. public List<ICSMOApplyNeg> MOIssueDocNegativeApplyGet(ICSMOApplyNeg infoModel)
  5295. {
  5296. List<ICSMOApplyNeg> model = new List<ICSMOApplyNeg>();
  5297. conn.Open();
  5298. SqlTransaction sqlTran = conn.BeginTransaction();
  5299. SqlCommand cmd = new SqlCommand();
  5300. cmd.Transaction = sqlTran;
  5301. cmd.Connection = conn;
  5302. int resultInfo = 0;
  5303. try
  5304. {
  5305. sql = @"select
  5306. a.id,
  5307. a.ApplyNegCode,
  5308. c.WarehouseCode,
  5309. c.WarehouseName,
  5310. a.MUSER,
  5311. a.MUSERName,
  5312. a.MTIME,
  5313. a.WorkPoint,
  5314. a.Sequence,
  5315. a.InvCode,
  5316. a.Quantity,
  5317. a.Amount,
  5318. a.SourceDetailID,
  5319. b.ID
  5320. from ICSMOApplyNegDetail a
  5321. left join ICSMOApplyNeg b on b.ApplyNegCode = a.ApplyNegCode and a.WorkPoint=b.WorkPoint
  5322. left join ICSWarehouse c on b.WHCode = c.WarehouseCode and b.WorkPoint=c.WorkPoint
  5323. where a.ApplyNegCode='{0}' and a.MUSER='{1}' and a.MTIME='{2}'";
  5324. sql = string.Format(sql, infoModel.MOApplyNegCode, infoModel.User, infoModel.MTime);
  5325. table = DBHelper.SQlReturnData(sql, cmd);
  5326. string json = JsonConvert.SerializeObject(table);
  5327. model = JsonConvert.DeserializeObject<List<ICSMOApplyNeg>>(json);//<List<WMSSourceDocumentModel>>
  5328. cmd.Transaction.Commit();
  5329. }
  5330. catch (Exception ex)
  5331. {
  5332. cmd.Transaction.Rollback();
  5333. log.Error(ex.Message);
  5334. throw new Exception(ex.Message);
  5335. }
  5336. finally
  5337. {
  5338. if (conn.State == ConnectionState.Open)
  5339. {
  5340. conn.Close();
  5341. }
  5342. conn.Dispose();
  5343. }
  5344. return model;
  5345. }
  5346. /// <summary>
  5347. /// 添加
  5348. /// </summary>
  5349. /// <param name="infoModel"></param>
  5350. /// <returns></returns>
  5351. public string MOIssueDocNegativeApplyCreate(List<ICSMOApplyNeg> infoModel)
  5352. {
  5353. List<ICSMOApplyNeg> model = new List<ICSMOApplyNeg>();
  5354. conn.Open();
  5355. SqlTransaction sqlTran = conn.BeginTransaction();
  5356. SqlCommand cmd = new SqlCommand();
  5357. cmd.Transaction = sqlTran;
  5358. cmd.Connection = conn;
  5359. int resultInfo = 0;
  5360. int resultInfowater = 0;
  5361. string Pre;
  5362. string water = "001";
  5363. try
  5364. {
  5365. Random Rdm = new Random();
  5366. foreach (var item in infoModel)
  5367. {
  5368. foreach (var itemInfo in item.detail)
  5369. {
  5370. string Date = DateTime.Now.ToString("yy");
  5371. Pre = "MOISSUENEGAPPLY" + item.WHCode + Rdm.Next(0, 100) + Date;
  5372. Pre += 1;
  5373. sql = @"INSERT INTO ICSMOApplyNeg ([ID],[ApplyNegCode],[WHCode],[Status],[MUSER],[MTIME],[WorkPoint],type,CreatePerson,MUSERName,CreateDateTime)
  5374. VALUES (newid(),'{0}','{1}','','{2}','{3}','{4}','','{2}','{2}','{3}')";
  5375. sql = string.Format(sql, Pre, item.WHCode, item.User, item.MTime, itemInfo.WorkPoint);
  5376. cmd.CommandText = sql;
  5377. resultInfo = cmd.ExecuteNonQuery();//返回条数
  5378. //cmd.Transaction.Commit();
  5379. if (resultInfo <= 0)
  5380. {
  5381. throw new Exception("添加主表失败");
  5382. }
  5383. sqlInfo = @" INSERT INTO ICSMOApplyNegDetail ([ID],[ApplyNegCode],[Sequence],[SourceDetailID],[InvCode],[Quantity],[Amount],[ExtensionID],[MUSER],MUSERName,[MTIME],[WorkPoint],[EATTRIBUTE])
  5384. VALUES( newid(),'{0}','{1}','{2}','{3}',{4},{5},'0','{6}','{6}','{7}','{8}','0') ";
  5385. if (itemInfo.Amount == "")
  5386. {
  5387. itemInfo.Amount = "0";
  5388. }
  5389. sqlInfo = string.Format(sqlInfo, Pre, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, item.User, item.MTime, itemInfo.WorkPoint);
  5390. cmd.CommandText = sqlInfo;
  5391. resultInfo = cmd.ExecuteNonQuery();//返回条数
  5392. cmd.Transaction.Commit();
  5393. }
  5394. }
  5395. }
  5396. catch (Exception ex)
  5397. {
  5398. cmd.Transaction.Rollback();
  5399. log.Error(ex.Message);
  5400. throw new Exception(ex.Message);
  5401. }
  5402. finally
  5403. {
  5404. if (conn.State == ConnectionState.Open)
  5405. {
  5406. conn.Close();
  5407. }
  5408. conn.Dispose();
  5409. }
  5410. return resultInfo.ToString();
  5411. }
  5412. /// <summary>
  5413. /// 修改
  5414. /// </summary>
  5415. /// <param name="infoModel"></param>
  5416. /// <returns></returns>
  5417. public int MOIssueDocNegativeApplyUpdate(List<ICSMOApplyNeg> infoModel)
  5418. {
  5419. List<ICSMOApplyNeg> model = new List<ICSMOApplyNeg>();
  5420. conn.Open();
  5421. SqlTransaction sqlTran = conn.BeginTransaction();
  5422. SqlCommand cmd = new SqlCommand();
  5423. cmd.Transaction = sqlTran;
  5424. cmd.Connection = conn;
  5425. int resultInfo = 0;
  5426. int ApplyNeg = 0;
  5427. string Pre;
  5428. try
  5429. {
  5430. foreach (var item in infoModel)
  5431. {
  5432. foreach (var itemInfo in item.detail)
  5433. {
  5434. //当id不为空的时候执行修改,当id为空的时候执行添加
  5435. sql = @"select * from ICSMOApplyNeg where id='{0}' and WorkPoint='{1}'";
  5436. sql = string.Format(sql, item.ID, itemInfo.WorkPoint);
  5437. cmd.CommandText = sql;
  5438. cmd.Transaction.Commit();
  5439. resultInfo = cmd.ExecuteNonQuery();
  5440. if (resultInfo > 0)
  5441. {
  5442. sql = @"update ICSMOApplyNeg set WHCode='{0}',MUSER='{1}' ,MUSERName='{2}' where id='{3}' and WorkPoint='{4}'";
  5443. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.ID, itemInfo.WorkPoint);
  5444. cmd.CommandText = sql;
  5445. ApplyNeg = cmd.ExecuteNonQuery();
  5446. cmd.Transaction.Commit();
  5447. if (ApplyNeg > 0)
  5448. {
  5449. //修改子表
  5450. sqlInfo = @"update ICSMOApplyNegDetail set InvCode='{0}' Quantity={1} Amount={2} where id='{3}' and WorkPoint='{4}'";
  5451. if (itemInfo.Amount == "")
  5452. {
  5453. itemInfo.Amount = "0";
  5454. }
  5455. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.DetailID, itemInfo.WorkPoint);
  5456. cmd.CommandText = sql;
  5457. ApplyNeg = cmd.ExecuteNonQuery();
  5458. cmd.Transaction.Commit();
  5459. }
  5460. }
  5461. else
  5462. {
  5463. MOIssueDocNegativeApplyCreate(infoModel);
  5464. }
  5465. }
  5466. }
  5467. return ApplyNeg + resultInfo;
  5468. }
  5469. catch (Exception ex)
  5470. {
  5471. cmd.Transaction.Rollback();
  5472. log.Error(ex.Message);
  5473. throw new Exception(ex.Message);
  5474. }
  5475. finally
  5476. {
  5477. if (conn.State == ConnectionState.Open)
  5478. {
  5479. conn.Close();
  5480. }
  5481. conn.Dispose();
  5482. }
  5483. }
  5484. /// <summary>
  5485. /// 删除
  5486. /// </summary>
  5487. /// <param name="infoModel"></param>
  5488. /// <returns></returns>
  5489. public int MOIssueDocNegativeApplyDelete(List<ICSMOApplyNeg> infoModel)
  5490. {
  5491. List<ICSMOApplyNeg> model = new List<ICSMOApplyNeg>();
  5492. conn.Open();
  5493. SqlTransaction sqlTran = conn.BeginTransaction();
  5494. SqlCommand cmd = new SqlCommand();
  5495. cmd.Transaction = sqlTran;
  5496. cmd.Connection = conn;
  5497. int resultInfo = 0;
  5498. try
  5499. {
  5500. foreach (var item in infoModel)
  5501. {
  5502. foreach (var itemInfo in item.detail)
  5503. {
  5504. //删除子表
  5505. sql = @"delete ICSMOApplyNegDetail where ID='{0}' and WorkPoint='{1}'";
  5506. sql = string.Format(sql, itemInfo.DetailID, itemInfo.WorkPoint);
  5507. cmd.CommandText = sql;
  5508. cmd.Transaction.Commit();
  5509. resultInfo = cmd.ExecuteNonQuery();//返回条数
  5510. if (resultInfo <= 0)
  5511. {
  5512. throw new Exception("删除失败");
  5513. }
  5514. sqlInfo = @"delete ICSMOApplyNeg where ID='{0}'and WorkPoint='{1}'";
  5515. sqlInfo = string.Format(sqlInfo, item.ID, itemInfo.WorkPoint);
  5516. cmd.CommandText = sqlInfo;
  5517. resultInfo = cmd.ExecuteNonQuery();//返回条数
  5518. }
  5519. }
  5520. }
  5521. catch (Exception ex)
  5522. {
  5523. if (conn.State == ConnectionState.Open)
  5524. {
  5525. conn.Close();
  5526. }
  5527. conn.Dispose();
  5528. }
  5529. finally
  5530. {
  5531. if (conn.State == ConnectionState.Open)
  5532. {
  5533. conn.Close();
  5534. }
  5535. conn.Dispose();
  5536. }
  5537. return resultInfo;
  5538. }
  5539. #endregion
  5540. #region 采购到货单/拒收
  5541. /// <summary>
  5542. /// 到货单添加
  5543. /// </summary>
  5544. /// <param name="infoModel"></param>
  5545. /// <returns></returns>
  5546. public string DeliveryNoticeCreate(List<ICSDeliveryNotice> infoModel, string DNType)
  5547. {
  5548. DataTable dt = null;
  5549. DataTable dtInfo = null;
  5550. conn.Open();
  5551. SqlTransaction sqlTran = conn.BeginTransaction();
  5552. SqlCommand cmd = new SqlCommand();
  5553. cmd.Transaction = sqlTran;
  5554. cmd.Connection = conn;
  5555. int num = 0;
  5556. int numInfo = 0;
  5557. string sqlDetail;
  5558. string json;
  5559. double numtable = 0;
  5560. double numASN = 0;
  5561. ///ERP
  5562. string sqlERP = string.Empty;//ERP的表头
  5563. string sqlERPDetil = string.Empty;//ERP的表体
  5564. string jsonERP = string.Empty;///erpjson
  5565. string IstrErp = string.Empty;
  5566. string iresult = string.Empty;//接口调用
  5567. string ASNCode = string.Empty;
  5568. string WorkPoint = string.Empty;
  5569. string Sequences = string.Empty;
  5570. try
  5571. {
  5572. if (infoModel.Count <= 0)
  5573. {
  5574. throw new Exception("传送数据为空!");
  5575. }
  5576. List<ICSDeliveryNotice> model = new List<ICSDeliveryNotice>();
  5577. foreach (var item in infoModel)
  5578. {
  5579. ASNCode = item.ASNCode;
  5580. WorkPoint = item.WorkPoint;
  5581. string Pre;
  5582. int i = 0;
  5583. Random Rdm = new Random();
  5584. int iRdm = Rdm.Next(0, 100);
  5585. if (DNType == "到货")
  5586. {
  5587. string Date = DateTime.Now.ToString("yy");
  5588. Pre = "DN" + item.VenCode + iRdm + Date;
  5589. if (!string.IsNullOrEmpty(item.ASNCode))
  5590. {
  5591. sql = @"select * from ICSASN a inner join ICSASNDetail b on a.ASNCode=b.ASNCode where a.ASNCode='{0}' and a.Status='2' and a.WorkPoint='{1}'";
  5592. sql = string.Format(sql, item.ASNCode, item.WorkPoint);
  5593. table = DBHelper.SQlReturnData(sql, cmd);
  5594. }
  5595. else
  5596. {
  5597. throw new Exception("送货单号为空!");
  5598. }
  5599. #region 验证送货单数据是否存在
  5600. //是否送货单是否存在是否已经审核
  5601. if (table.Rows.Count <= 0)
  5602. {
  5603. throw new Exception("该送货单单没有审核或没有该单据请核对!");
  5604. }
  5605. #endregion
  5606. #region 验证送货单数据是否存在
  5607. //是否送货单是否存在是否已经审核
  5608. else
  5609. {
  5610. #region 修改子表的信息
  5611. foreach (var itemInfo in item.detail)
  5612. {
  5613. //WorkPoint = itemInfo.WorkPoint;
  5614. Sequences = itemInfo.Sequence;
  5615. ///修改送货单子表信息
  5616. sqlDetail = @" update ICSASNDetail set DNQuantity='{2}' where ASNCode='{0}' and WorkPoint='{1}' and LotNo='{3}'";
  5617. sqlDetail = string.Format(sqlDetail, item.ASNCode, item.WorkPoint, itemInfo.Quantity, itemInfo.LotNo);
  5618. //DBHelper.CmdExecuteNonQuery(sqlDetail, cmd, "成功");
  5619. cmd.CommandText = sqlDetail;
  5620. int numInfoL = cmd.ExecuteNonQuery();
  5621. #endregion
  5622. #region Add到货单
  5623. string sqlnum = @"select * from ICSDeliveryNotice where WorkPoint='{0}' and ASNCode='{1}' and DNType='1' ";
  5624. sqlnum = string.Format(sqlnum, item.WorkPoint, item.ASNCode);
  5625. DataTable data = DBHelper.SQlReturnData(sqlnum, cmd);
  5626. if (data.Rows.Count > 0)
  5627. {
  5628. throw new Exception("已到货,不能重复到货!");
  5629. }
  5630. else
  5631. {
  5632. string sqlasn = @"select isnull(Quantity,0) as Quantity from ICSASN a inner join ICSASNDetail b on a.ASNCode=b.ASNCode where b.LotNo='{0}' and a.Status='2' and a.WorkPoint='{1}'";
  5633. sqlasn = string.Format(sqlasn, itemInfo.LotNo, item.WorkPoint);
  5634. DataTable dasn = DBHelper.SQlReturnData(sqlasn, cmd);
  5635. numASN = Convert.ToDouble(dasn.Rows[0][0]);
  5636. if (Convert.ToDouble(itemInfo.Quantity) > numASN)
  5637. {
  5638. throw new Exception("到货数量大于送货数量,请查看数量!");
  5639. }
  5640. }
  5641. }
  5642. //添加到到货单新数据
  5643. sqlInfo = @"INSERT INTO [ICSDeliveryNotice]
  5644. ([ID]
  5645. ,[DNCode]
  5646. ,[Sequence]
  5647. ,[VenCode]
  5648. ,[DepCode]
  5649. ,[DNType]
  5650. ,[InvCode]
  5651. ,[Quantity]
  5652. ,[Amount]
  5653. ,[RCVQuantity]
  5654. ,[UnitPrice]
  5655. ,[Currency]
  5656. ,[Status]
  5657. ,[CreatePerson]
  5658. ,[CreateDateTime]
  5659. ,[POID]
  5660. ,[PODetailID]
  5661. ,[DNID]
  5662. ,[DNDetailID]
  5663. ,[ExtensionID]
  5664. ,[MUSER]
  5665. ,[MUSERName]
  5666. ,[MTIME]
  5667. ,[WorkPoint]
  5668. ,[EATTRIBUTE1]
  5669. ,[ASNCode])
  5670. (SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,'1',b.InvCode,SUM(a.DNQuantity),'0','0',d.UnitPrice,d.Currency,'2'
  5671. ,'{1}',GETDATE(),d.POID,d.PODetailID,'0','0',b.ExtensionID,'{1}',e.F_RealName,GETDATE(),'{2}','',a.ASNCode
  5672. FROM ICSASNDetail a
  5673. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  5674. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  5675. INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  5676. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  5677. WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}'
  5678. GROUP BY d.POID,d.PODetailID,d.VenCode,d.UnitPrice,d.Currency,d.DepCode,b.ExtensionID,b.InvCode,a.ASNCode,e.F_RealName)";
  5679. sqlInfo = string.Format(sqlInfo, Pre, item.User, item.WorkPoint, item.ASNCode);
  5680. cmd.CommandText = sqlInfo;
  5681. num = cmd.ExecuteNonQuery();
  5682. #endregion
  5683. }
  5684. #endregion
  5685. }
  5686. else
  5687. {
  5688. ///拒收
  5689. Random RdmInfo = new Random();
  5690. int iRdmInfo = Rdm.Next(0, 100);
  5691. string Date = DateTime.Now.ToString("yy");
  5692. Pre = "RJT" + item.VenCode + iRdmInfo + Date;
  5693. if (!string.IsNullOrEmpty(item.DNCode))
  5694. {
  5695. sql = @"select count(DNCode) from ICSDeliveryNotice where DNCode='{0}' and Status='2' and DNType='1' and WorkPoint='{1}'";
  5696. sql = string.Format(sql, item.DNCode, item.WorkPoint);
  5697. table = DBHelper.SQlReturnData(sql, cmd);
  5698. }
  5699. else
  5700. {
  5701. throw new Exception("送货单号为空!");
  5702. }
  5703. #region 验证送货单数据是否存在
  5704. //是否送货单是否存在是否已经审核
  5705. if (table.Rows.Count > 0)
  5706. {
  5707. #region Add拒收单
  5708. foreach (var itemInfo in item.detail)
  5709. {
  5710. int Sequence = i++;
  5711. //添加拒收新数据
  5712. sqlInfo = @" IF EXISTS(
  5713. select EATTRIBUTE1 from ICSDeliveryNotice
  5714. where EATTRIBUTE1 = '{14}' and DNType = '3' and WorkPoint = '{13}')
  5715. RAISERROR('{14}', 16, 1)
  5716. INSERT INTO [ICSDeliveryNotice]
  5717. ([ID]
  5718. ,[DNCode]
  5719. ,[Sequence]
  5720. ,[VenCode]
  5721. ,[DepCode]
  5722. ,[DNType]
  5723. ,[InvCode]
  5724. ,[Quantity]
  5725. ,[Amount]
  5726. ,[RCVQuantity]
  5727. ,[UnitPrice]
  5728. ,[Currency]
  5729. ,[Status]
  5730. ,[CreatePerson]
  5731. ,[CreateDateTime]
  5732. ,[POID]
  5733. ,[PODetailID]
  5734. ,[DNID]
  5735. ,[DNDetailID]
  5736. ,[ExtensionID]
  5737. ,[MUSER]
  5738. ,[MUSERName]
  5739. ,[MTIME]
  5740. ,[WorkPoint]
  5741. ,[EATTRIBUTE1]
  5742. ,[ASNCode])
  5743. select newid(),'{0}', '{1}', '{2}', '{3}', '3', '{4}', '{5}', '{6}', 0, '{7}', '{8}' , '2', '{9}', '{10}', '{11}', '{12}', '0','0', b.ExtensionID, '{9}',a.F_RealName, '{10}', '{13}', '{14} ',' '
  5744. from Sys_SRM_User a
  5745. left join ICSDeliveryNotice b on b.DNCode='{15}'and b.DNType=1
  5746. where F_Account='{9}' and F_Location='{13}' ";
  5747. if (itemInfo.Amount == "")
  5748. {
  5749. int numInfoList = 0;
  5750. sqlInfo = string.Format(sqlInfo, Pre, Sequence, item.VenCode, item.DepCode, itemInfo.InvCode, itemInfo.Quantity, numInfoList, itemInfo.UnitPrice, itemInfo.Currency, item.User, DateTime.Now, item.ID, itemInfo.DNDetailID, itemInfo.WorkPoint, itemInfo.LotNo, item.DNCode);
  5751. cmd.CommandText = sqlInfo;
  5752. }
  5753. // DBHelper.CmdExecuteNonQuery(sqlInfo, cmd, "成功");
  5754. num = cmd.ExecuteNonQuery();
  5755. }
  5756. #endregion
  5757. }
  5758. else
  5759. {
  5760. throw new Exception("该送货单单没有审核或没有该单据请核对!");
  5761. }
  5762. #endregion
  5763. }
  5764. }
  5765. if (num > 0)
  5766. {
  5767. string numm = "成功";
  5768. #region ERP
  5769. sqlERP = @"select VenCode,DepCode,POID,MUSER,(getdate())as Mtime from ICSDeliveryNotice
  5770. where ASNCode='{0}' and WorkPoint='{1}' ";
  5771. sqlERP = string.Format(sqlERP, ASNCode, WorkPoint);
  5772. table = DBHelper.SQlReturnData(sqlERP, cmd);
  5773. sqlERPDetil = @"select Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,PODetailID, cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from ICSDeliveryNotice A
  5774. LEFT JOIN ICSExtension B ON A.ASNCode=B.ID where A.ASNCode='{0}' and A.WorkPoint='{1}' ";
  5775. sqlERPDetil = string.Format(sqlERPDetil, ASNCode, WorkPoint);
  5776. DataTable ERPtable = DBHelper.SQlReturnData(sqlERPDetil, cmd);
  5777. List<ERPDeliveryNotice> docmodel = new List<ERPDeliveryNotice>();
  5778. foreach (DataRow dtIn in table.Rows)
  5779. {
  5780. ERPDeliveryNotice doc = new ERPDeliveryNotice();
  5781. doc.VenCode = dtIn["VenCode"].ToString();
  5782. doc.DepCode = dtIn["DepCode"].ToString();
  5783. doc.POCode = dtIn["POID"].ToString();
  5784. doc.User = dtIn["MUSER"].ToString();
  5785. doc.MTime = dtIn["Mtime"].ToString();
  5786. List<ERPDeliveryNoticeList> list = new List<ERPDeliveryNoticeList>();
  5787. foreach (DataRow dtList in ERPtable.Rows)
  5788. {
  5789. ERPDeliveryNoticeList docc = new ERPDeliveryNoticeList();
  5790. docc.Sequence = dtList["Sequence"].ToString();
  5791. docc.InvCode = dtList["InvCode"].ToString();
  5792. docc.Quantity = dtList["Quantity"].ToString();
  5793. docc.Amount = dtList["Amount"].ToString();
  5794. docc.Currency = dtList["Currency"].ToString();
  5795. docc.UnitPrice = dtList["UnitPrice"].ToString();
  5796. docc.PODetailID = dtList["PODetailID"].ToString();
  5797. docc.cFree1 = dtList["cFree1"].ToString();
  5798. docc.cFree2 = dtList["cFree2"].ToString();
  5799. docc.cFree3 = dtList["cFree3"].ToString();
  5800. docc.cFree4 = dtList["cFree4"].ToString();
  5801. docc.cFree5 = dtList["cFree5"].ToString();
  5802. docc.cFree6 = dtList["cFree6"].ToString();
  5803. docc.cFree7 = dtList["cFree7"].ToString();
  5804. docc.cFree8 = dtList["cFree8"].ToString();
  5805. docc.cFree9 = dtList["cFree9"].ToString();
  5806. docc.cFree10 = dtList["cFree10"].ToString();
  5807. list.Add(docc);
  5808. }
  5809. doc.details = list;
  5810. docmodel.Add(doc);
  5811. }
  5812. IstrErp = JsonConvert.SerializeObject(docmodel);
  5813. iresult = HttpPost("采购到货", ERPUrl.CreatePOArrivURL, IstrErp);
  5814. Result OtherOutResult = new Result();
  5815. OtherOutResult = JsonConvert.DeserializeObject<Result>(iresult);
  5816. if (OtherOutResult.Success == false)
  5817. {
  5818. throw new Exception(OtherOutResult.Message);
  5819. }
  5820. else
  5821. {
  5822. List<ERPJsonRetun> list = new List<ERPJsonRetun>();
  5823. //string nn = OtherOutResult.Data.ToString();//LOTStockModel
  5824. list = JsonConvert.DeserializeObject<List<ERPJsonRetun>>(OtherOutResult.Data.ToString());
  5825. foreach (var items in list)
  5826. {
  5827. string ERPupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}',DNType='1'
  5828. where ASNCode='{4}' and Sequence ='{5}'";
  5829. ERPupdate = string.Format(ERPupdate, items.DNCode, items.Sequence, items.ID, items.DetailID, ASNCode, Sequences);
  5830. cmd.CommandText = ERPupdate;
  5831. num = cmd.ExecuteNonQuery();
  5832. }
  5833. }
  5834. #endregion
  5835. cmd.Transaction.Commit();
  5836. //提交成功之后传ERP
  5837. return numm;
  5838. }
  5839. else
  5840. {
  5841. cmd.Transaction.Rollback();
  5842. }
  5843. return null;
  5844. }
  5845. catch (Exception ex)
  5846. {
  5847. cmd.Transaction.Rollback();
  5848. log.Error(ex.Message);
  5849. throw new Exception(ex.Message);
  5850. }
  5851. finally
  5852. {
  5853. if (conn.State == ConnectionState.Open)
  5854. {
  5855. conn.Close();
  5856. }
  5857. conn.Dispose();
  5858. }
  5859. }
  5860. /// <summary>
  5861. /// 到货单查询
  5862. /// </summary>
  5863. /// <param name="infoModel"></param>
  5864. /// <returns></returns>
  5865. public string DeliveryNoticeGet(List<ICSDeliveryNotice> infoModel, string DNType)
  5866. {
  5867. DataTable dt = null;
  5868. DataTable dtInfo = null;
  5869. conn.Open();
  5870. SqlTransaction sqlTran = conn.BeginTransaction();
  5871. SqlCommand cmd = new SqlCommand();
  5872. cmd.Transaction = sqlTran;
  5873. cmd.Connection = conn;
  5874. int num = 0;
  5875. int numInfo = 0;
  5876. string sqlDetail;
  5877. string json;
  5878. try
  5879. {
  5880. return null;
  5881. }
  5882. catch (Exception ex)
  5883. {
  5884. // cmd.Transaction.Rollback();
  5885. log.Error(ex.Message);
  5886. throw new Exception(ex.Message);
  5887. }
  5888. finally
  5889. {
  5890. if (conn.State == ConnectionState.Open)
  5891. {
  5892. conn.Close();
  5893. }
  5894. conn.Dispose();
  5895. }
  5896. }
  5897. #endregion
  5898. #region 委外到货/拒收
  5899. public string DeliveryNoticeODNCreate(List<ICSDeliveryNotice> infoModel, string DNType)
  5900. {
  5901. Random Rdm = new Random();
  5902. int iRdm = Rdm.Next(0, 100);
  5903. DataTable dt = null;
  5904. DataTable dtInfo = null;
  5905. conn.Open();
  5906. SqlTransaction sqlTran = conn.BeginTransaction();
  5907. SqlCommand cmd = new SqlCommand();
  5908. cmd.Transaction = sqlTran;
  5909. cmd.Connection = conn;
  5910. int num = 0;
  5911. int numInfo = 0;
  5912. string sqlDetail;
  5913. string json;
  5914. string TYPE;
  5915. try
  5916. {
  5917. if (infoModel.Count <= 0)
  5918. {
  5919. throw new Exception("传送数据为空!");
  5920. }
  5921. List<ICSDeliveryNotice> model = new List<ICSDeliveryNotice>();
  5922. int i = 1;
  5923. foreach (var item in infoModel)
  5924. {
  5925. string Pre;
  5926. if (DNType == "到货")
  5927. {
  5928. string Date = DateTime.Now.ToString("yy");
  5929. Pre = "ODN" + item.VenCode + iRdm + Date;
  5930. TYPE = "1";
  5931. #region 验证送货单数据是否存在
  5932. if (!string.IsNullOrEmpty(item.ASNCode))
  5933. {
  5934. sql = @"select * from ICSOASN where OASNCode='{0}' and Status='2' and WorkPoint='{1}'";
  5935. sql = string.Format(sql, item.ASNCode, item.WorkPoint);
  5936. table = DBHelper.SQlReturnData(sql, cmd);
  5937. }
  5938. else
  5939. {
  5940. return json = "委外送货单号为空!";
  5941. }
  5942. // 是否送货单是否存在是否已经审核
  5943. if (table.Rows.Count <= 0)
  5944. {
  5945. return json = "该送货单单没有审核或没有该单据请核对!";
  5946. }
  5947. #endregion
  5948. #region Add到货单
  5949. foreach (var itemInfo in item.detail)
  5950. {
  5951. //添加到到货单新数据
  5952. sqlInfo = @"INSERT INTO [ICSODeliveryNotice]
  5953. ([ID]
  5954. ,[ODNCode]
  5955. ,[Sequence]
  5956. ,[VenCode]
  5957. ,[DepCode]
  5958. ,[ODNType]
  5959. ,[InvCode]
  5960. ,[Quantity]
  5961. ,[Amount]
  5962. ,[RCVQuantity]
  5963. ,[UnitPrice]
  5964. ,[Currency]
  5965. ,[Status]
  5966. ,[CreatePerson]
  5967. ,[CreateDateTime]
  5968. ,[POID]
  5969. ,[PODetailID]
  5970. ,[ODNID]
  5971. ,[ODNDetailID]
  5972. ,[ExtensionID]
  5973. ,[MUSER]
  5974. ,[MUSERName]
  5975. ,[MTIME]
  5976. ,[WorkPoint]
  5977. ,[EATTRIBUTE1]
  5978. )
  5979. (SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,'1',b.InvCode,SUM(a.ODNQuantity),'0','0',d.UnitPrice,d.Currency,'2'
  5980. ,'{1}',GETDATE(),d.POID,d.PODetailID,newid(),newid(),b.ExtensionID,'{1}',e.F_RealName,GETDATE(),'{2}','',a.OASNCode
  5981. FROM ICSOASNDetail a
  5982. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  5983. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  5984. INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  5985. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  5986. WHERE a.OASNCode='{3}' AND a.WorkPoint='{2}'
  5987. GROUP BY d.POID,d.PODetailID,d.VenCode,d.UnitPrice,d.Currency,d.DepCode,b.ExtensionID,b.InvCode,a.OASNCode,e.F_RealName)";
  5988. if (itemInfo.RCVQuantity == null)
  5989. {
  5990. int VQuantity = 0;
  5991. int Price = 0;
  5992. sqlInfo = string.Format(sqlInfo, Pre, item.User, item.WorkPoint, item.OASNCode);
  5993. //sqlInfo = string.Format(sqlInfo, Pre, itemInfo.Sequence, item.VenCode, item.DepCode, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, VQuantity, Price, itemInfo.Currency, item.User, item.MTime, itemInfo.PODetailID, itemInfo.LotNo, item.WorkPoint, TYPE);
  5994. cmd.CommandText = sqlInfo;
  5995. }
  5996. else
  5997. {
  5998. sqlInfo = string.Format(sqlInfo, Pre, itemInfo.Sequence, item.VenCode, item.DepCode, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.RCVQuantity, itemInfo.UnitPrice, itemInfo.Currency, item.User, item.MTime, itemInfo.PODetailID, itemInfo.LotNo, item.WorkPoint, TYPE);
  5999. cmd.CommandText = sqlInfo;
  6000. }
  6001. }
  6002. num = cmd.ExecuteNonQuery();//返回条数
  6003. #endregion
  6004. if (num <= 0)
  6005. {
  6006. return json = "添加失败";
  6007. }
  6008. else
  6009. {
  6010. #region 修改子表的信息
  6011. foreach (var itemInfo in item.detail)
  6012. {
  6013. ///修改送货单子表信息
  6014. sqlDetail = @"
  6015. update ICSASNDetail set DNQuantity=((select SUM(DNQuantity) from ICSASNDetail where LotNo='{0}' and WorkPoint='{1}') +(select SUM(Quantity) from ICSDeliveryNotice where DNCode='{2}' and DNType='2' and WorkPoint='{1}' ))
  6016. where LotNo='{0}' and WorkPoint='{1}'";
  6017. sqlDetail = string.Format(sqlDetail, itemInfo.LotNo, item.WorkPoint, Pre);
  6018. cmd.CommandText = sqlDetail;
  6019. numInfo = cmd.ExecuteNonQuery();//返回条数
  6020. }
  6021. if (numInfo <= 0)
  6022. {
  6023. return json = "修改送货单失败";
  6024. }
  6025. #endregion
  6026. }
  6027. }
  6028. else
  6029. {
  6030. ///拒收
  6031. Random RdmInfo = new Random();
  6032. int iRdmInfo = Rdm.Next(0, 100);
  6033. string Date = DateTime.Now.ToString("yy");
  6034. Pre = "ORJT" + item.VenCode + iRdm + Date;
  6035. if (!string.IsNullOrEmpty(item.ODNCode))
  6036. {
  6037. sql = @"select count(ODNCode) from ICSODeliveryNotice where ODNCode='{0}' and Status='2' and ODNType='1' and WorkPoint='{1}'";
  6038. sql = string.Format(sql, item.ODNCode, item.WorkPoint);
  6039. table = DBHelper.SQlReturnData(sql, cmd);
  6040. }
  6041. else
  6042. {
  6043. throw new Exception("到货单不存在!");
  6044. }
  6045. #region 验证送货单数据是否存在
  6046. //是否送货单是否存在是否已经审核
  6047. if (table.Rows.Count > 0)
  6048. {
  6049. #region Add拒收单
  6050. foreach (var itemInfo in item.detail)
  6051. {
  6052. int Sequence = i++;
  6053. //添加拒收新数据
  6054. sqlInfo = @"IF EXISTS(
  6055. select EATTRIBUTE1 from ICSODeliveryNotice
  6056. where EATTRIBUTE1 = '{14}' and ODNType = '3' and WorkPoint = '{13}')
  6057. RAISERROR('{14}', 16, 1)
  6058. INSERT INTO [ICSODeliveryNotice]
  6059. ([ID]
  6060. ,[ODNCode]
  6061. ,[Sequence]
  6062. ,[VenCode]
  6063. ,[DepCode]
  6064. ,[ODNType]
  6065. ,[InvCode]
  6066. ,[Quantity]
  6067. ,[Amount]
  6068. ,[RCVQuantity]
  6069. ,[UnitPrice]
  6070. ,[Currency]
  6071. ,[Status]
  6072. ,[CreatePerson]
  6073. ,[CreateDateTime]
  6074. ,[POID]
  6075. ,[PODetailID]
  6076. ,[ODNID]
  6077. ,[ODNDetailID]
  6078. ,[ExtensionID]
  6079. ,[MUSER]
  6080. ,[MUSERName]
  6081. ,[MTIME]
  6082. ,[WorkPoint]
  6083. ,[EATTRIBUTE1]
  6084. ,[OASNCode])
  6085. select newid(),'{0}', '{1}', '{2}', '{3}', '3', '{4}', '{5}', '{6}', 0, '{7}', '{8}' , '2', '{9}', '{10}', '{11}', '{12}', '0', '0', a.ExtensionID, '{9}',c.F_RealName, '{10}', '{13}', '{14} ',' '
  6086. from ICSODeliveryNotice a
  6087. left join ICSOASNDetail b on a.OASNCode=b.OASNCode
  6088. LEFT JOIN Sys_SRM_User c ON c.F_Account='{9}' and c.F_Location='{13}'
  6089. where a.odncode='{15}' and B.LOTNO='{14}' ";
  6090. if (itemInfo.Amount == "")
  6091. {
  6092. int numInfoList = 0;
  6093. sqlInfo = string.Format(sqlInfo, Pre, Sequence, item.VenCode, item.DepCode, itemInfo.InvCode, itemInfo.Quantity, numInfoList, itemInfo.UnitPrice, itemInfo.Currency, item.User, DateTime.Now, item.ID, itemInfo.ODNDetailID, itemInfo.WorkPoint, itemInfo.LotNo, item.ODNCode);
  6094. cmd.CommandText = sqlInfo;
  6095. }
  6096. // DBHelper.CmdExecuteNonQuery(sqlInfo, cmd, "成功");
  6097. num = cmd.ExecuteNonQuery();
  6098. }
  6099. #endregion
  6100. }
  6101. else
  6102. {
  6103. throw new Exception("该送货单单没有审核或没有该单据请核对!");
  6104. }
  6105. #endregion
  6106. }
  6107. }
  6108. if (num > 0)
  6109. {
  6110. cmd.Transaction.Commit();
  6111. }
  6112. else
  6113. {
  6114. cmd.Transaction.Rollback();
  6115. }
  6116. return num.ToString();
  6117. }
  6118. catch (Exception ex)
  6119. {
  6120. cmd.Transaction.Rollback();
  6121. log.Error(ex.Message);
  6122. throw new Exception(ex.Message);
  6123. }
  6124. finally
  6125. {
  6126. if (conn.State == ConnectionState.Open)
  6127. {
  6128. conn.Close();
  6129. }
  6130. conn.Dispose();
  6131. }
  6132. }
  6133. #endregion
  6134. #region 仓库/库位
  6135. /// <summary>
  6136. /// 仓库/库位
  6137. /// </summary>
  6138. /// <param name="JsonData"></param>
  6139. /// <returns></returns>
  6140. public List<ICSLocation> LocationGet(ICSLocation JsonData)
  6141. {
  6142. List<ICSLocation> model = new List<ICSLocation>();
  6143. conn.Open();
  6144. SqlTransaction sqlTran = conn.BeginTransaction();
  6145. SqlCommand cmd = new SqlCommand();
  6146. cmd.Transaction = sqlTran;
  6147. cmd.Connection = conn;
  6148. try
  6149. {
  6150. sqlInfo = @"SELECT
  6151. LocationCode,
  6152. LocationName ,
  6153. WarehouseCode,
  6154. WarehouseName
  6155. FROM ICSLocation a
  6156. left join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode='{0}' and b.Enable='0'";
  6157. sqlInfo = string.Format(sqlInfo, JsonData.LocationCode);
  6158. table = DBHelper.SQlReturnData(sqlInfo, cmd);
  6159. if (table.Rows.Count > 0)
  6160. {
  6161. throw new Exception("仓库不存在!");
  6162. }
  6163. else
  6164. {
  6165. sql = @"SELECT
  6166. LocationCode,
  6167. LocationName ,
  6168. WarehouseCode,
  6169. WarehouseName
  6170. FROM ICSLocation a
  6171. left join ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode='{0}' and b.Enable='1'";
  6172. sql = string.Format(sql, JsonData.LocationCode);
  6173. table = DBHelper.SQlReturnData(sql, cmd);
  6174. if (table.Rows.Count <= 0)
  6175. {
  6176. throw new Exception("仓库未启用,请先启用仓库!");
  6177. }
  6178. string json = JsonConvert.SerializeObject(table);
  6179. model = JsonConvert.DeserializeObject<List<ICSLocation>>(json);//<List<WMSSourceDocumentModel>>
  6180. cmd.Transaction.Commit();
  6181. return model;
  6182. }
  6183. }
  6184. catch (Exception ex)
  6185. {
  6186. cmd.Transaction.Rollback();
  6187. log.Error(ex.Message);
  6188. throw new Exception(ex.Message);
  6189. }
  6190. finally
  6191. {
  6192. if (conn.State == ConnectionState.Open)
  6193. {
  6194. conn.Close();
  6195. }
  6196. conn.Dispose();
  6197. }
  6198. }
  6199. #endregion
  6200. #region 委外退料 /OutsourcingIssueDoNegativeApply
  6201. public ICSOApplyNegModel OutsourcingIssueDoNegativeApplyGet(ICSOApplyNeg JsonData)
  6202. {
  6203. List<ICSOApplyNegModel> deliveryNotrModel = new List<ICSOApplyNegModel>();
  6204. ICSOApplyNegModel model = new ICSOApplyNegModel();
  6205. DataTable dt = null;
  6206. DataTable dtInfo = null;
  6207. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  6208. conn.Open();
  6209. SqlTransaction sqlTran = conn.BeginTransaction();
  6210. SqlCommand cmd = new SqlCommand();
  6211. cmd.Transaction = sqlTran;
  6212. cmd.Connection = conn;
  6213. try
  6214. {
  6215. string sql = string.Empty;
  6216. string sqlInfo = string.Empty;
  6217. //foreach (var item in deliveryNotrModel)
  6218. //{
  6219. sql = @"select
  6220. a.ID as ID,
  6221. a.OApplyNegCode as OApplyNegCode,
  6222. a.WHCode as WHCode,
  6223. c.WarehouseName as WHName,
  6224. a.MUSER as MUSER,
  6225. a.MTIME as MTime
  6226. from ICSOApplyNeg a
  6227. left join ICSWarehouse c on c.WarehouseCode=a.WHCode and a.WorkPoint=b.WorkPoint
  6228. where 1=1";
  6229. if (!string.IsNullOrWhiteSpace(JsonData.OApplyNegCode))
  6230. {
  6231. sql += " and a.OApplyNegCode='{0}'";
  6232. }
  6233. if (!string.IsNullOrWhiteSpace(JsonData.User))
  6234. {
  6235. sql += " and a.MUSER='{1}'";
  6236. }
  6237. if (!string.IsNullOrWhiteSpace(JsonData.MTime))
  6238. {
  6239. sql += " and a.MTIME='{2}'";
  6240. }
  6241. sql = string.Format(sql, JsonData.OApplyNegCode, JsonData.User, JsonData.MTime);
  6242. sqlInfo = @"select
  6243. ID as DetailID,
  6244. Sequence as Sequence ,
  6245. InvCode as InvCode,
  6246. Quantity as Quantity,
  6247. Amount as Amount,
  6248. SourceDetailID as SourceDetailID
  6249. from ICSOApplyNegDetail
  6250. where OApplyNegCode=(select OApplyNegCode from ICSOApplyNeg where OApplyNegCode='{0}' and WorkPoint='{1}')";
  6251. sqlInfo = string.Format(sqlInfo, JsonData.OApplyNegCode, JsonData.WorkPoint);
  6252. //}
  6253. dt = DBHelper.SQlReturnData(sql, cmd);
  6254. dtInfo = DBHelper.SQlReturnData(sqlInfo, cmd);
  6255. string json = JsonConvert.SerializeObject(dt);
  6256. string jsonInfo = JsonConvert.SerializeObject(dtInfo);
  6257. string jsonlist = null;
  6258. if (dt.Rows.Count > 0)
  6259. {
  6260. foreach (DataRow dr in dt.Rows)
  6261. {
  6262. ICSOApplyNegModel main = new ICSOApplyNegModel();
  6263. main.ID = dr["ID"].ToString();
  6264. main.OApplyNegCode = dr["OApplyNegCode"].ToString();
  6265. main.WHCode = dr["WHCode"].ToString();
  6266. main.WHName = dr["WHName"].ToString();
  6267. main.User = dr["MUSER"].ToString();
  6268. main.MTime = dr["MTime"].ToString();
  6269. List<ICSOApplyNegModelInfo> list = new List<ICSOApplyNegModelInfo>();
  6270. foreach (DataRow info in dtInfo.Rows)
  6271. {
  6272. ICSOApplyNegModelInfo detail = new ICSOApplyNegModelInfo();
  6273. detail.DetailID = info["DetailID"].ToString();
  6274. detail.Sequence = info["Sequence"].ToString();
  6275. detail.InvCode = info["InvCode"].ToString();
  6276. detail.Quantity = info["Quantity"].ToString();
  6277. detail.Amount = info["Amount"].ToString();
  6278. detail.SourceDetailID = info["SourceDetailID"].ToString();
  6279. list.Add(detail);
  6280. }
  6281. main.detail = list;
  6282. jsonlist = JsonConvert.SerializeObject(main);
  6283. }
  6284. var deliveryNotrModelInfo = JsonConvert.DeserializeObject<ICSOApplyNegModel>(jsonlist);
  6285. cmd.Transaction.Commit();
  6286. return deliveryNotrModelInfo;
  6287. }
  6288. else
  6289. {
  6290. throw new Exception("数据为空");
  6291. }
  6292. }
  6293. catch (Exception ex)
  6294. {
  6295. cmd.Transaction.Rollback();
  6296. log.Error(ex.Message);
  6297. throw new Exception(ex.Message);
  6298. }
  6299. finally
  6300. {
  6301. if (conn.State == ConnectionState.Open)
  6302. {
  6303. conn.Close();
  6304. }
  6305. conn.Dispose();
  6306. }
  6307. }
  6308. /// <summary>
  6309. /// 委外退料 新建
  6310. /// </summary>
  6311. /// <param name="JsonData"></param>
  6312. /// <returns></returns>
  6313. public int OutsourcingIssueDoNegativeApplyCreate(List<ICSOApplyNeg> JsonData)
  6314. {
  6315. Random Rdm = new Random();
  6316. int iRdm = Rdm.Next(0, 100);
  6317. List<ICSOApplyNegModel> deliveryNotrModel = new List<ICSOApplyNegModel>();
  6318. ICSOApplyNegModel model = new ICSOApplyNegModel();
  6319. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  6320. conn.Open();
  6321. SqlTransaction sqlTran = conn.BeginTransaction();
  6322. SqlCommand cmd = new SqlCommand();
  6323. cmd.Transaction = sqlTran;
  6324. cmd.Connection = conn;
  6325. int num = 0;
  6326. int numInfo = 0;
  6327. try
  6328. {
  6329. string sql = string.Empty;
  6330. string sqlInfo = string.Empty;
  6331. string Pre = "";
  6332. foreach (var item in JsonData)
  6333. {
  6334. foreach (var itemInfo in item.detail)
  6335. {
  6336. //主表新建数据
  6337. string Date = DateTime.Now.ToString("yy");
  6338. Pre = "OOISSUENEGAPPLY" + item.WHCode + iRdm + Date;//新的委外退料申请号
  6339. sql = @"INSERT INTO ICSOApplyNeg
  6340. ([ID]
  6341. ,[OApplyNegCode]
  6342. ,[WHCode]
  6343. ,[Status]
  6344. ,[Type]
  6345. ,[Memo]
  6346. ,[CreatePerson]
  6347. ,[CreateDateTime]
  6348. ,[MUSER]
  6349. ,[MUSERName]
  6350. ,[MTIME]
  6351. ,[WorkPoint]
  6352. ,[EATTRIBUTE1])
  6353. VALUES
  6354. (newid(),'{0}','{1}','','',' ','{2}','{3}','{2}','{2}','{3}','{4}',' ')";
  6355. sql = string.Format(sql, Pre, item.WHCode, item.User, item.MTime, itemInfo.WorkPoint);
  6356. cmd.CommandText = sql;
  6357. //cmd.Transaction.Commit();
  6358. num = cmd.ExecuteNonQuery();//返回条数
  6359. sqlInfo = @"INSERT INTO [ICSOApplyNegDetail]
  6360. ([ID]
  6361. ,[OApplyNegCode]
  6362. ,[Sequence]
  6363. ,[SourceDetailID]
  6364. ,[InvCode]
  6365. ,[Quantity]
  6366. ,[Amount]
  6367. ,[IssueNegQuantity]
  6368. ,[ExtensionID]
  6369. ,[MUSER]
  6370. ,[MUSERName]
  6371. ,[MTIME]
  6372. ,[WorkPoint]
  6373. ,[EATTRIBUTE])
  6374. VALUES
  6375. (newid(),'{0}'
  6376. ,'{1}','{2}','{3}',{4},{5},0,'','{6}','{6}','{7}','{8}','')";
  6377. sqlInfo = string.Format(sqlInfo, Pre, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, item.User, item.MTime, itemInfo.WorkPoint);
  6378. cmd.CommandText = sqlInfo;
  6379. //cmd.Transaction.Commit();
  6380. numInfo = cmd.ExecuteNonQuery();//返回条数
  6381. }
  6382. cmd.Transaction.Commit();
  6383. }
  6384. if (num > 0 && numInfo > 0)
  6385. {
  6386. return num + numInfo;
  6387. }
  6388. return num;
  6389. }
  6390. catch (Exception ex)
  6391. {
  6392. cmd.Transaction.Rollback();
  6393. log.Error(ex.Message);
  6394. throw new Exception(ex.Message);
  6395. }
  6396. finally
  6397. {
  6398. if (conn.State == ConnectionState.Open)
  6399. {
  6400. conn.Close();
  6401. }
  6402. conn.Dispose();
  6403. }
  6404. }
  6405. /// <summary>
  6406. /// 委外退料 修改
  6407. /// </summary>
  6408. /// <param name="JsonData"></param>
  6409. /// <returns></returns>
  6410. public int OutsourcingIssueDoNegativeApplyUpdate(List<ICSOApplyNeg> JsonData)
  6411. {
  6412. List<ICSOApplyNegModel> deliveryNotrModel = new List<ICSOApplyNegModel>();
  6413. ICSOApplyNegModel model = new ICSOApplyNegModel();
  6414. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  6415. conn.Open();
  6416. SqlTransaction sqlTran = conn.BeginTransaction();
  6417. SqlCommand cmd = new SqlCommand();
  6418. cmd.Transaction = sqlTran;
  6419. cmd.Connection = conn;
  6420. int num = 0;
  6421. int numInfo = 0;
  6422. try
  6423. {
  6424. string sql = string.Empty;
  6425. string sqlInfo = string.Empty;
  6426. string Pre = "";
  6427. foreach (var item in JsonData)
  6428. {
  6429. //主表修改
  6430. sql = @"update ICSOApplyNeg set WHCode='{0}' ,MUSER='{1}',MTIME='{2}'where ID='{3}' and WorkPoint='{4}' ";
  6431. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.id, item.WorkPoint);
  6432. cmd.CommandText = sql;
  6433. cmd.Transaction.Commit();
  6434. num = cmd.ExecuteNonQuery();
  6435. foreach (var itemInfo in item.detail)
  6436. {
  6437. sql = @"update ICSOApplyNegDetail set InvCode='{0}' ,Quantity='{1}',Amount='{2}' where ID='{3}'and SourceDetailID='{4}' and WorkPoint='{5}'";
  6438. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.DetailID, itemInfo.SourceDetailID, itemInfo.WorkPoint);
  6439. cmd.CommandText = sql;
  6440. //cmd.Transaction.Commit();
  6441. numInfo = cmd.ExecuteNonQuery();
  6442. }
  6443. }
  6444. if (num > 0 && numInfo > 0)
  6445. {
  6446. return numInfo + num;
  6447. }
  6448. return num + numInfo;
  6449. }
  6450. catch (Exception ex)
  6451. {
  6452. cmd.Transaction.Rollback();
  6453. log.Error(ex.Message);
  6454. throw new Exception(ex.Message);
  6455. }
  6456. finally
  6457. {
  6458. if (conn.State == ConnectionState.Open)
  6459. {
  6460. conn.Close();
  6461. }
  6462. conn.Dispose();
  6463. }
  6464. }
  6465. /// <summary>
  6466. /// 委外退料 删除
  6467. /// </summary>
  6468. /// <param name="JsonData"></param>
  6469. /// <returns></returns>
  6470. public int OutsourcingIssueDoNegativeApplyDelete(List<ICSOApplyNeg> JsonData)
  6471. {
  6472. List<ICSOApplyNegModel> deliveryNotrModel = new List<ICSOApplyNegModel>();
  6473. ICSOApplyNegModel model = new ICSOApplyNegModel();
  6474. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  6475. conn.Open();
  6476. SqlTransaction sqlTran = conn.BeginTransaction();
  6477. SqlCommand cmd = new SqlCommand();
  6478. cmd.Transaction = sqlTran;
  6479. cmd.Connection = conn;
  6480. int num = 0;
  6481. int numInfo = 0;
  6482. try
  6483. {
  6484. string sql = string.Empty;
  6485. string sqlInfo = string.Empty;
  6486. string Pre = "";
  6487. foreach (var item in JsonData)
  6488. {
  6489. foreach (var itemInfo in item.detail)
  6490. {
  6491. sqlInfo = @"DELETE FROM ICSOApplyNegDetail where ID='{0}' and WorkPoint='{1}' ";
  6492. sqlInfo = string.Format(sqlInfo, itemInfo.DetailID, itemInfo.WorkPoint);
  6493. cmd.CommandText = sqlInfo;
  6494. cmd.Transaction.Commit();
  6495. numInfo = cmd.ExecuteNonQuery();
  6496. }
  6497. if (numInfo > 0)
  6498. {
  6499. //主表删除
  6500. sql = @"DELETE FROM [ICSOApplyNeg] where ID='{0}' and WorkPoint='{3}'";
  6501. if (!string.IsNullOrEmpty(item.User))
  6502. {
  6503. sql = "and MUSER = '{1}' ";
  6504. }
  6505. if (!string.IsNullOrEmpty(item.MTime))
  6506. {
  6507. sql = " and MTIME = '{2}'";
  6508. }
  6509. sql = string.Format(sql, item.id, item.User, item.MTime, item.WorkPoint);
  6510. cmd.CommandText = sql;
  6511. // cmd.Transaction.Commit();
  6512. num = cmd.ExecuteNonQuery();
  6513. }
  6514. }
  6515. if (num > 0 && numInfo > 0)
  6516. {
  6517. return numInfo + num;
  6518. }
  6519. return num + numInfo;
  6520. }
  6521. catch (Exception ex)
  6522. {
  6523. cmd.Transaction.Rollback();
  6524. log.Error(ex.Message);
  6525. throw new Exception(ex.Message);
  6526. }
  6527. finally
  6528. {
  6529. if (conn.State == ConnectionState.Open)
  6530. {
  6531. conn.Close();
  6532. }
  6533. conn.Dispose();
  6534. }
  6535. }
  6536. #endregion
  6537. #region 库存盘点单
  6538. public object CheckGet(ICSCheck JsonData)
  6539. {
  6540. List<ICSCheck> deliveryNotrModel = new List<ICSCheck>();
  6541. ICSCheck model = new ICSCheck();
  6542. DataTable dt = null;
  6543. DataTable dtInfo = null;
  6544. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  6545. conn.Open();
  6546. SqlTransaction sqlTran = conn.BeginTransaction();
  6547. SqlCommand cmd = new SqlCommand();
  6548. cmd.Transaction = sqlTran;
  6549. cmd.Connection = conn;
  6550. try
  6551. {
  6552. string sql = string.Empty;
  6553. string sqlInfo = string.Empty;
  6554. string sqlList = string.Empty;
  6555. //foreach (var item in JsonData)
  6556. //{
  6557. sqlList = @" select * from ICSCheck where CheckCode='{0}' and WorkPoint='{1}'";
  6558. sql = string.Format(sqlList, JsonData.CheckCode, JsonData.WorkPoint);
  6559. dt = DBHelper.SQlReturnData(sql, cmd);
  6560. if (dt.Rows.Count > 0)
  6561. {
  6562. sql = @"select
  6563. a.ID as ID,
  6564. a.CheckCode as CheckCode,
  6565. a.WHCode as WHCode,
  6566. b.WarehouseName as WHName,
  6567. a.InvCode as InvCode,
  6568. a.Quantity as Quantity,
  6569. a.ActualQuantity as ActualQuantity,
  6570. a.MUSER as MUSER,
  6571. a.MTIME as MTime
  6572. from ICSCheck a
  6573. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  6574. where 1=1 and Status='2'";
  6575. if (!string.IsNullOrWhiteSpace(JsonData.CheckCode))
  6576. {
  6577. sql += "and a.CheckCode='{0}'";
  6578. }
  6579. if (!string.IsNullOrWhiteSpace(JsonData.User))
  6580. {
  6581. sql += " and a.MUSER='{1}'";
  6582. }
  6583. if (!string.IsNullOrWhiteSpace(JsonData.MTime))
  6584. {
  6585. sql += " and a.MTIME='{2}'";
  6586. }
  6587. sql = string.Format(sql, JsonData.CheckCode, JsonData.User, JsonData.MTime);
  6588. sqlInfo = @" select
  6589. a.ID as DetailID ,
  6590. c.TransSequence as Sequence,
  6591. a.LotNo as LotNo,
  6592. a.Quantity as LotQuantity,
  6593. a.ActualQuantity as LotActualQuantity
  6594. from ICSCheckDetail a
  6595. left join ICSCheck b on a.CheckCode=b.CheckCode and a.WorkPoint=b.WorkPoint
  6596. left join ICSInventoryLotDetail c on a.LotNo=c.LotNo and c.WorkPoint=a.WorkPoint
  6597. where 1=1 and a.CheckCode='{0}' ";
  6598. sqlInfo = string.Format(sqlInfo, JsonData.CheckCode);
  6599. //}
  6600. dt = DBHelper.SQlReturnData(sql, cmd);
  6601. dtInfo = DBHelper.SQlReturnData(sqlInfo, cmd);
  6602. //string json = JsonConvert.SerializeObject(dt);
  6603. //string jsonInfo = JsonConvert.SerializeObject(dtInfo);
  6604. string jsonlist = null;
  6605. if (dt.Rows.Count > 0)
  6606. {
  6607. foreach (DataRow dr in dt.Rows)
  6608. {
  6609. ICSCheckInfo main = new ICSCheckInfo();
  6610. main.ID = dr["ID"].ToString();
  6611. main.CheckCode = dr["CheckCode"].ToString();
  6612. main.WHCode = dr["WHCode"].ToString();
  6613. main.WHName = dr["WHName"].ToString();
  6614. main.InvCode = dr["InvCode"].ToString();
  6615. main.Quantity = dr["Quantity"].ToString();
  6616. main.ActualQuantity = dr["ActualQuantity"].ToString();
  6617. main.User = dr["MUSER"].ToString();
  6618. main.MTime = dr["MTime"].ToString();
  6619. List<ICSCheckInfoModel> list = new List<ICSCheckInfoModel>();
  6620. foreach (DataRow info in dtInfo.Rows)
  6621. {
  6622. ICSCheckInfoModel detail = new ICSCheckInfoModel();
  6623. detail.DetailID = info["DetailID"].ToString();
  6624. detail.Sequence = info["Sequence"].ToString();
  6625. detail.LotNo = info["LotNo"].ToString();
  6626. detail.LotQuantity = info["LotQuantity"].ToString();
  6627. detail.LotActualQuantity = info["LotActualQuantity"].ToString();
  6628. //detail.SourceDetailID = info["SourceDetailID"].ToString();
  6629. list.Add(detail);
  6630. }
  6631. main.detail = list;
  6632. jsonlist = JsonConvert.SerializeObject(main);
  6633. }
  6634. var deliveryNotrModelInfo = JsonConvert.DeserializeObject(jsonlist);
  6635. cmd.Transaction.Commit();
  6636. return deliveryNotrModelInfo;
  6637. }
  6638. else
  6639. {
  6640. throw new Exception("数据未审核,请先审核");
  6641. }
  6642. }
  6643. else
  6644. {
  6645. throw new Exception("单据不存在");
  6646. }
  6647. }
  6648. catch (Exception ex)
  6649. {
  6650. cmd.Transaction.Rollback();
  6651. log.Error(ex.Message);
  6652. throw new Exception(ex.Message);
  6653. }
  6654. finally
  6655. {
  6656. if (conn.State == ConnectionState.Open)
  6657. {
  6658. conn.Close();
  6659. }
  6660. conn.Dispose();
  6661. }
  6662. }
  6663. /// <summary>
  6664. /// 库存盘点
  6665. /// </summary>
  6666. /// <param name="JsonData"></param>
  6667. /// <returns></returns>
  6668. public object CheckCreate(List<ICSCheck> JsonData, string type)
  6669. {
  6670. List<ICSCheck> deliveryNotrModel = new List<ICSCheck>();
  6671. List<ICSCheckInfo> iCs = new List<ICSCheckInfo>();
  6672. ICSCheck model = new ICSCheck();
  6673. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  6674. conn.Open();
  6675. SqlTransaction sqlTran = conn.BeginTransaction();
  6676. SqlCommand cmd = new SqlCommand();
  6677. cmd.Transaction = sqlTran;
  6678. cmd.Connection = conn;
  6679. DataTable dt;
  6680. int num = 0;
  6681. Random Rdm = new Random();
  6682. int iRdm = Rdm.Next(0, 100);
  6683. try
  6684. {
  6685. string Pre = "";
  6686. string sql = string.Empty;
  6687. string sqlInfo = string.Empty;
  6688. foreach (var item in JsonData)
  6689. {
  6690. foreach (var itemInfo in item.detail)
  6691. {
  6692. if (type == "库存盘点")
  6693. {
  6694. string Date = DateTime.Now.ToString("yy");
  6695. Pre = "CHK" + itemInfo.WHCode + iRdm + Date;//库存盘点单号
  6696. sqlInfo = @"select * from ICSWarehouse a
  6697. left join ICSWareHouseLotInfo b on a.WarehouseCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  6698. where a.Enable=1 and a.WarehouseCode='{0}' and a.WorkPoint='{1}'";
  6699. sqlInfo = string.Format(sqlInfo, itemInfo.WHCode, itemInfo.WorkPoint);
  6700. cmd.CommandText = sqlInfo;
  6701. dt = DBHelper.SQlReturnData(sqlInfo, cmd);
  6702. if (dt.Rows.Count > 0)
  6703. {
  6704. sql = @"INSERT INTO [ICSCheck]
  6705. ([ID]
  6706. ,[CheckCode]
  6707. ,[WHCode]
  6708. ,[InvCode]
  6709. ,[Status]
  6710. ,[Quantity]
  6711. ,[MUSER]
  6712. ,[MTIME]
  6713. ,MUSERName
  6714. ,[WorkPoint])
  6715. (SELECT newid(),'{0}','{1}',a.InvCode,'1',SUM(a.Quantity),'{2}','{3}',b.F_RealName,'{4}'
  6716. FROM ICSWareHouseLotInfo a
  6717. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{4}'
  6718. where WarehouseCode='{1}' and WorkPoint='{4}'
  6719. GROUP BY InvCode ,b.F_RealName)";
  6720. sql = string.Format(sql, Pre, itemInfo.WHCode, item.User, DateTime.Now, itemInfo.WorkPoint);
  6721. cmd.CommandText = sql;
  6722. num = cmd.ExecuteNonQuery();//返回条数
  6723. if (num > 0)
  6724. {
  6725. string sqlCheck = @"select * from ICSCheck where CheckCode='{0}' and WorkPoint='{1}'";
  6726. sqlCheck = string.Format(sqlCheck, Pre, itemInfo.WorkPoint);
  6727. DataTable data = DBHelper.SQlReturnData(sqlCheck, cmd);
  6728. string json = JsonConvert.SerializeObject(data);
  6729. iCs = JsonConvert.DeserializeObject<List<ICSCheckInfo>>(json);
  6730. //List<ICSCheckInfo> docmodel = new List<ICSCheckInfo>();
  6731. //foreach (DataRow row in data.Rows)
  6732. //{
  6733. // ICSCheckInfo doc = new ICSCheckInfo();
  6734. // doc.ID = row["ID"].ToString();
  6735. // doc.CheckCode = row["CheckCode"].ToString();
  6736. // doc.WHCode = row["WHCode"].ToString();
  6737. // doc.WHName = "";
  6738. // doc.InvCode = row["InvCode"].ToString();
  6739. // doc.Quantity = row["Quantity"].ToString();
  6740. // doc.ActualQuantity = row["ActualQuantity"].ToString();
  6741. // doc.User = row["User"].ToString();
  6742. // doc.MTime = row["MTime"].ToString();
  6743. // docmodel.Add(doc);
  6744. //}
  6745. //List<ICSCheckInfoModel> list = new List<ICSCheckInfoModel>();
  6746. //foreach (DataRow dtList in ERPtable.Rows)
  6747. //{
  6748. // IssueDocList docc = new IssueDocList();
  6749. // docc.Sequence = dtList["TransSequence"].ToString();
  6750. // docc.InvCode = dtList["InvCode"].ToString();
  6751. // docc.Quantity = dtList["Quantity"].ToString();
  6752. // docc.Amount = dtList["Amount"].ToString();
  6753. // docc.SourceDetailID = dtList["PickID"].ToString();
  6754. // list.Add(docc);
  6755. //}
  6756. cmd.Transaction.Commit();
  6757. }
  6758. else
  6759. {
  6760. cmd.Transaction.Rollback();
  6761. }
  6762. }
  6763. else
  6764. {
  6765. throw new Exception("仓库未启用或仓库不存在!");
  6766. }
  6767. }
  6768. else if (type == "条码库存")
  6769. {
  6770. string Date = DateTime.Now.ToString("yy");
  6771. Pre = "LOTCHKdsk" + item.WHCode + Date;//条码盘点
  6772. sqlInfo = @"select * from ICSWarehouse a
  6773. left join ICSWareHouseLotInfo b on a.WarehouseCode=b.WarehouseCode
  6774. where a.Enable=1 and b.LotNo='{0}' and WorkPoint='{1}'";
  6775. sqlInfo = string.Format(sqlInfo, itemInfo.WHCode, item.WorkPoint);
  6776. DataTable dtInfo = DBHelper.SQlReturnData(sqlInfo, cmd);
  6777. if (dtInfo.Rows.Count > 0)
  6778. {
  6779. sql = @"INSERT INTO [ICSCheckDetail]
  6780. ([ID]
  6781. ,[CheckCode]
  6782. ,[LotNo]
  6783. ,[Quantity]
  6784. ,[ActualQuantity]
  6785. ,[MUSER]
  6786. ,[MUSERName]
  6787. ,[MTIME]
  6788. ,[WorkPoint])
  6789. VALUES
  6790. (newid(),'{0}','{1}', (select Quantity from ICSWareHouseLotInfo where LotNo='{1}' and WorkPoint='{4}' ),
  6791. (select Quantity from ICSWareHouseLotInfo where LotNo='{1}' and WorkPoint='{4}' ),'{2}','{2}','{3}','{4}' )";
  6792. sql = string.Format(sql, Pre, itemInfo.WHCode, item.User, item.MTime, item.WorkPoint);
  6793. cmd.CommandText = sql;
  6794. num = cmd.ExecuteNonQuery();//返回条数
  6795. if (num > 0)
  6796. {
  6797. cmd.Transaction.Commit();
  6798. }
  6799. else
  6800. {
  6801. cmd.Transaction.Rollback();
  6802. }
  6803. }
  6804. else
  6805. {
  6806. throw new Exception("仓库未启用或仓库不存在!");
  6807. }
  6808. }
  6809. }
  6810. }
  6811. return iCs;
  6812. }
  6813. catch (Exception ex)
  6814. {
  6815. //cmd.Transaction.Rollback();
  6816. log.Error(ex.Message);
  6817. throw new Exception(ex.Message);
  6818. }
  6819. finally
  6820. {
  6821. if (conn.State == ConnectionState.Open)
  6822. {
  6823. conn.Close();
  6824. }
  6825. conn.Dispose();
  6826. }
  6827. }
  6828. /// <summary>
  6829. /// 盘点单审核
  6830. /// </summary>
  6831. /// <param name="JsonData"></param>
  6832. /// <returns></returns>
  6833. public bool CreateApprove(ICSCheck JsonData)
  6834. {
  6835. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  6836. conn.Open();
  6837. SqlTransaction sqlTran = conn.BeginTransaction();
  6838. SqlCommand cmd = new SqlCommand();
  6839. cmd.Transaction = sqlTran;
  6840. cmd.Connection = conn;
  6841. DataTable dt;
  6842. int num = 0;
  6843. Random Rdm = new Random();
  6844. int iRdm = Rdm.Next(0, 100);
  6845. try
  6846. {
  6847. sql = @"select * from ICSCheck where CheckCode='{0}' and WorkPoint='{1}' ";
  6848. sql = string.Format(sql, JsonData.CheckCode, JsonData.WorkPoint);
  6849. dt = DBHelper.SQlReturnData(sql, cmd);
  6850. if (dt.Rows.Count <= 0)
  6851. {
  6852. throw new Exception("盘点单不存在!");
  6853. }
  6854. else
  6855. {
  6856. string sqlInfo = @"upadte ICSCheck set Status='2' ,MUSER ='{2}', MUSERName=(select F_RealName from Sys_SRM_User where F_Account ='{2}' and F_Location='{1}' ) , MTIME='{3}' where CheckCode='{0}' and WorkPoint='{1}'";
  6857. sqlInfo = string.Format(sqlInfo, JsonData.CheckCode, JsonData.WorkPoint, JsonData.User, DateTime.Now);
  6858. cmd.CommandText = sql;
  6859. num = cmd.ExecuteNonQuery();//返回条数
  6860. if (num > 0)
  6861. {
  6862. cmd.Transaction.Commit();
  6863. }
  6864. else
  6865. {
  6866. cmd.Transaction.Rollback();
  6867. }
  6868. }
  6869. return true;
  6870. }
  6871. catch (Exception ex)
  6872. {
  6873. //cmd.Transaction.Rollback();
  6874. log.Error(ex.Message);
  6875. throw new Exception(ex.Message);
  6876. }
  6877. finally
  6878. {
  6879. if (conn.State == ConnectionState.Open)
  6880. {
  6881. conn.Close();
  6882. }
  6883. conn.Dispose();
  6884. }
  6885. }
  6886. /// <summary>
  6887. /// PDA库存盘点
  6888. /// </summary>
  6889. /// <param name="JsonData"></param>
  6890. /// <returns></returns>
  6891. public int PDACheckCreate(List<ICSCheck> JsonData, string type)
  6892. {
  6893. List<ICSCheck> deliveryNotrModel = new List<ICSCheck>();
  6894. ICSCheck model = new ICSCheck();
  6895. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  6896. conn.Open();
  6897. SqlTransaction sqlTran = conn.BeginTransaction();
  6898. SqlCommand cmd = new SqlCommand();
  6899. cmd.Transaction = sqlTran;
  6900. cmd.Connection = conn;
  6901. DataTable dt;
  6902. int num = 0;
  6903. try
  6904. {
  6905. string Pre = "";
  6906. string sql = string.Empty;
  6907. string sqlInfo = string.Empty;
  6908. foreach (var item in JsonData)
  6909. {
  6910. foreach (var itemInfo in item.detail)
  6911. {
  6912. if (item.isChecked == "1")
  6913. {
  6914. string sqlICSCheck = @"update ICSCheck set Quantity=(select SUM(Quantity) from ICSCheck WHERE InvCode='{5}' AND WHCode='{6}') + '{0}' ,MUSER='{1}'
  6915. ,MUSERName=(SELECT F_RealName FROM Sys_SRM_User WHERE F_Account='{1}' and F_Location='{3}')
  6916. ,MTIME='{2}' where WorkPoint='{3}' and CheckCode='{4}' and InvCode='{5}' AND WHCode='{6}'";
  6917. sqlICSCheck = string.Format(sqlICSCheck, itemInfo.ActualQuantity, item.User, DateTime.Now, item.WorkPoint, item.CheckCode, item.InvCode, item.WHCode);
  6918. cmd.CommandText = sqlICSCheck;
  6919. num = cmd.ExecuteNonQuery();
  6920. string SQLDetail = @" SELECT * FROM ICSCheckDetail WHERE LotNo='{0}' and WorkPoint='{1}'";
  6921. SQLDetail = string.Format(SQLDetail, itemInfo.LotNo, item.WorkPoint);
  6922. DataTable data = DBHelper.SQlReturnData(SQLDetail, cmd);
  6923. if (data.Rows.Count <= 0)
  6924. {
  6925. string SQLInertDetail = @"insert into ICSCheckDetail( ID,CheckCode,LotNo,Quantity,ActualQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  6926. (select newid(),'{0}','{1}' ,a.Quantity,'{2}','{3}',b.F_RealName,'{4}','{5}',''
  6927. from ICSWareHouseLotInfo a
  6928. left join Sys_SRM_User b on F_Account='{3}' and F_Location='{5}'
  6929. where a.LotNo='{1}' and a.WorkPoint='{5}')";
  6930. SQLInertDetail = string.Format(SQLInertDetail, item.CheckCode, itemInfo.LotNo, itemInfo.ActualQuantity, item.User, DateTime.Now, item.WorkPoint);
  6931. cmd.CommandText = SQLInertDetail;
  6932. num = cmd.ExecuteNonQuery();
  6933. }
  6934. else
  6935. {
  6936. sql = @"update ICSCheckDetail set ActualQuantity=(select ActualQuantity from ICSCheckDetail where CheckCode='{2}' and LotNo='{3}') +'{0}',MUSER='{4}'
  6937. ,MUSERName=(SELECT F_RealName FROM Sys_SRM_User WHERE F_Account='{4}' and F_Location='{1}')
  6938. ,MTIME='{5}'
  6939. where WorkPoint='{1}' and CheckCode='{2}' and LotNo='{3}'";
  6940. sql = string.Format(sql, itemInfo.ActualQuantity, item.WorkPoint, item.CheckCode, itemInfo.LotNo, item.User, DateTime.Now);
  6941. cmd.CommandText = sql;
  6942. num = cmd.ExecuteNonQuery();
  6943. }
  6944. string LotInfo = @"update ICSWareHouseLotInfo set Quantity= (select sum(Quantity) from ICSWareHouseLotInfo where LotNo='{3}'and WorkPoint='{4}')+'{0}',MUSER='{1}',
  6945. MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{1}' and F_Location='{4}') ,MTIME='{2}' where LotNo='{3}' and WorkPoint='{4}'";
  6946. LotInfo = string.Format(LotInfo, itemInfo.ActualQuantity, item.User, DateTime.Now, itemInfo.LotNo, item.WorkPoint);
  6947. cmd.CommandText = LotInfo;
  6948. num = cmd.ExecuteNonQuery();
  6949. string sqlLog = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  6950. ([ID]
  6951. ,[TransCode]
  6952. ,[TransSequence]
  6953. ,[LotNo]
  6954. ,[InvCode]
  6955. ,[FromWarehouseCode]
  6956. ,[FromLocationCode]
  6957. ,[ToWarehouseCode]
  6958. ,[ToLocationCode]
  6959. ,[Quantity]
  6960. ,[Memo]
  6961. ,[Lock]
  6962. ,[TransType]
  6963. ,[BusinessCode]
  6964. ,[ERPID]
  6965. ,[ERPDetailID]
  6966. ,[ERPCode]
  6967. ,[ERPSequence]
  6968. ,[MUSER]
  6969. ,[MUSERName]
  6970. ,[MTIME]
  6971. ,[WorkPoint]
  6972. ,[EATTRIBUTE1])
  6973. VALUES
  6974. (newid()
  6975. ,'{5}'
  6976. ,''
  6977. ,'{0}'
  6978. ,'{6}'
  6979. ,(SELECT WarehouseCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
  6980. ,(SELECT LocationCode FROM ICSWareHouseLotInfo WHERE LotNo='{0}')
  6981. ,''
  6982. ,''
  6983. ,'{1}'
  6984. ,''
  6985. ,''
  6986. ,'19'
  6987. ,''
  6988. ,''
  6989. ,''
  6990. ,''
  6991. ,''
  6992. ,'{2}'
  6993. ,(select F_RealName from Sys_SRM_User where F_Account='{2}' and F_Location='{4}')
  6994. ,'{3}'
  6995. ,'{4}'
  6996. ,'')";
  6997. sqlLog = string.Format(sqlLog, itemInfo.LotNo, itemInfo.ActualQuantity, item.User, DateTime.Now, item.WorkPoint, item.CheckCode, item.InvCode);
  6998. cmd.CommandText = sqlLog;
  6999. num = cmd.ExecuteNonQuery();
  7000. if (num > 0)
  7001. {
  7002. cmd.Transaction.Commit();
  7003. }
  7004. else
  7005. {
  7006. cmd.Transaction.Rollback();
  7007. }
  7008. }
  7009. else
  7010. {
  7011. string SQLDetail = @" SELECT * FROM ICSCheckDetail WHERE LotNo='{0}' and WorkPoint='{1}'";
  7012. SQLDetail = string.Format(SQLDetail, itemInfo.LotNo, item.WorkPoint);
  7013. DataTable data = DBHelper.SQlReturnData(SQLDetail, cmd);
  7014. if (data.Rows.Count <= 0)
  7015. {
  7016. string SQLInertDetail = @"insert into ICSCheckDetail( ID,CheckCode,LotNo,Quantity,ActualQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  7017. (select newid(),'{0}','{1}' ,a.Quantity,'{2}','{3}',b.F_RealName,'{4}','{5}',''
  7018. from ICSWareHouseLotInfo a
  7019. left join Sys_SRM_User b on F_Account='{3}' and F_Location='{5}'
  7020. where a.LotNo='{1}' and a.WorkPoint='{5}')";
  7021. SQLInertDetail = string.Format(SQLInertDetail, item.CheckCode, itemInfo.LotNo, itemInfo.ActualQuantity, item.User, DateTime.Now, item.WorkPoint);
  7022. cmd.CommandText = SQLInertDetail;
  7023. num = cmd.ExecuteNonQuery();
  7024. }
  7025. else
  7026. {
  7027. sql = @"update ICSCheckDetail set ActualQuantity=(select ActualQuantity from ICSCheckDetail where CheckCode='{2}' and LotNo='{3}') +'{0}',MUSER='{4}'
  7028. ,MUSERName=(SELECT F_RealName FROM Sys_SRM_User WHERE F_Account='{4}' and F_Location='{1}')
  7029. ,MTIME='{5}'
  7030. where WorkPoint='{1}' and CheckCode='{2}' and LotNo='{3}'";
  7031. sql = string.Format(sql, itemInfo.ActualQuantity, item.WorkPoint, item.CheckCode, itemInfo.LotNo, item.User, DateTime.Now);
  7032. cmd.CommandText = sql;
  7033. num = cmd.ExecuteNonQuery();
  7034. }
  7035. if (num > 0)
  7036. {
  7037. cmd.Transaction.Commit();
  7038. }
  7039. else
  7040. {
  7041. cmd.Transaction.Rollback();
  7042. }
  7043. }
  7044. }
  7045. }
  7046. return num;
  7047. }
  7048. catch (Exception ex)
  7049. {
  7050. //cmd.Transaction.Rollback();
  7051. log.Error(ex.Message);
  7052. throw new Exception(ex.Message);
  7053. }
  7054. finally
  7055. {
  7056. if (conn.State == ConnectionState.Open)
  7057. {
  7058. conn.Close();
  7059. }
  7060. conn.Dispose();
  7061. }
  7062. }
  7063. #endregion
  7064. #region 调拨单
  7065. public string TransferDocupdte(TransferDoc JsonData)
  7066. {
  7067. List<ICSCheck> deliveryNotrModel = new List<ICSCheck>();
  7068. ICSCheck model = new ICSCheck();
  7069. DataTable dt = null;
  7070. DataTable dtInfo = null;
  7071. DataTable dtInfoModel = null;
  7072. string sqlInsert;
  7073. string sqlNum;
  7074. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  7075. conn.Open();
  7076. SqlTransaction sqlTran = conn.BeginTransaction();
  7077. SqlCommand cmd = new SqlCommand();
  7078. cmd.Transaction = sqlTran;
  7079. cmd.Connection = conn;
  7080. int num;
  7081. try
  7082. {
  7083. string sql = string.Empty;
  7084. string sqlInfo = string.Empty;
  7085. string sqlList = string.Empty;
  7086. //验证数量是否大于调拨数量
  7087. sql = @"select Quantity from ICSWareHouseLotInfo where LotNo='{0}' and WorkPoint='{1}'";
  7088. sql = string.Format(sql, JsonData.Lotno, JsonData.WorkPoint);
  7089. dt = DBHelper.SQlReturnData(sql, cmd);
  7090. if (dt.Rows.Count <= 0)
  7091. {
  7092. throw new Exception("查无数据!");
  7093. }
  7094. foreach (DataRow dr in dt.Rows)
  7095. {
  7096. TransferDoc main = new TransferDoc();
  7097. main.Quantity = Convert.ToInt32(dr["Quantity"]);
  7098. if (main.Quantity < JsonData.Quantity)
  7099. {
  7100. throw new Exception("输入数量小于库存数量不能调拨!");
  7101. }
  7102. }
  7103. ///查询调拨的库位是否存在
  7104. sqlInfo = @"select * from ICSLocation where LocationCode='{0}' and WorkPoint='{1}' ";
  7105. sqlInfo = string.Format(sqlInfo, JsonData.LocationCode, JsonData.WorkPoint);
  7106. dtInfo = DBHelper.SQlReturnData(sqlInfo, cmd);
  7107. if (dtInfo.Rows.Count <= 0)
  7108. {
  7109. throw new Exception("目标库位不存在,请输入正确的目标库位!");
  7110. }
  7111. sqlNum = @"select * from ICSWareHouseLotInfo where LotNo='{0}' and WorkPoint='{1}' ";
  7112. sqlNum = string.Format(sqlNum, JsonData.Lotno, JsonData.WorkPoint);
  7113. dtInfoModel = DBHelper.SQlReturnData(sqlNum, cmd);
  7114. if (dtInfoModel.Rows.Count < 0)
  7115. {
  7116. throw new Exception("条码不存在!");
  7117. }
  7118. bool isTransfer = verification.isTransfer(JsonData.TransCode, JsonData.TransSequence, JsonData.Quantity, JsonData.Lotno, JsonData.WarehouseCode, JsonData.LocationCode, JsonData.WorkPoint);
  7119. if (isTransfer == true)
  7120. {
  7121. string updateSql = @"update ICSTransfer set TransferQuantity ='{0}' where TransferNO='{1}' and Sequence='{2}' and WorkPoint='{3}'";
  7122. updateSql = string.Format(updateSql, JsonData.Quantity, JsonData.TransCode, JsonData.TransSequence, JsonData.WorkPoint);
  7123. cmd.CommandText = updateSql;
  7124. num = cmd.ExecuteNonQuery();
  7125. string HouseSql = @" update ICSWareHouseLotInfo set WarehouseCode='{0}',LocationCode='{1}' where LotNo='{2}' and WorkPoint='{3}' ";
  7126. HouseSql = string.Format(HouseSql, JsonData.WarehouseCode, JsonData.LocationCode, JsonData.Lotno, JsonData.WorkPoint);
  7127. cmd.CommandText = HouseSql;
  7128. num = cmd.ExecuteNonQuery();
  7129. sqlInsert = @"INSERT INTO [dbo].[ICSWareHouseLotInfoLog]
  7130. ([ID]
  7131. ,[TransCode]
  7132. ,[TransSequence]
  7133. ,[LotNo]
  7134. ,[InvCode]
  7135. ,[FromWarehouseCode]
  7136. ,[FromLocationCode]
  7137. ,[ToWarehouseCode]
  7138. ,[ToLocationCode]
  7139. ,[Quantity]
  7140. ,[Memo]
  7141. ,[Lock]
  7142. ,[TransType]
  7143. ,[BusinessCode]
  7144. ,[ERPID]
  7145. ,[ERPDetailID]
  7146. ,[ERPCode]
  7147. ,[ERPSequence]
  7148. ,[MUSER]
  7149. ,[MUSERName]
  7150. ,[MTIME]
  7151. ,[WorkPoint]
  7152. ,[EATTRIBUTE1])
  7153. VALUES
  7154. (newid()
  7155. ,'{0}'--TransCode
  7156. ,'null'
  7157. ,'{1}'
  7158. ,(select InvCode from ICSWareHouseLotInfo where LotNo='{1}' )
  7159. ,(select WarehouseCode from ICSWareHouseLotInfo where LotNo='{1}')
  7160. ,(select LocationCode from ICSWareHouseLotInfo where LotNo='{1}')
  7161. ,'null'--LocationCode
  7162. ,'{2}'--LocationCode
  7163. ,'{3}'--Quantity
  7164. ,'null'
  7165. ,0
  7166. ,6
  7167. ,'13'
  7168. ,'null'
  7169. ,'null'
  7170. ,'null'
  7171. ,'null'
  7172. ,'{4}'
  7173. ,'{4}'
  7174. ,'{5}'
  7175. ,'{6}'
  7176. ,'null')";
  7177. sqlInsert = string.Format(sqlInsert, JsonData.TransCode, JsonData.Lotno, JsonData.LocationCode, JsonData.Quantity, JsonData.User, DateTime.Now, JsonData.WorkPoint);
  7178. cmd.CommandText = sqlInsert;
  7179. num = cmd.ExecuteNonQuery();
  7180. if (num > 0)
  7181. {
  7182. //throw new Exception("");
  7183. cmd.Transaction.Commit();
  7184. string ing = "成功 ";
  7185. return ing;
  7186. }
  7187. else
  7188. {
  7189. cmd.Transaction.Rollback();
  7190. }
  7191. }
  7192. return null;
  7193. }
  7194. catch (Exception ex)
  7195. {
  7196. // cmd.Transaction.Rollback();
  7197. log.Error(ex.Message);
  7198. throw new Exception(ex.Message);
  7199. }
  7200. finally
  7201. {
  7202. if (conn.State == ConnectionState.Open)
  7203. {
  7204. conn.Close();
  7205. }
  7206. conn.Dispose();
  7207. }
  7208. }
  7209. #endregion
  7210. #region 接口调用
  7211. public static string HttpPost(string apiName, string url, string body)
  7212. {
  7213. try
  7214. {
  7215. Encoding encoding = Encoding.UTF8;
  7216. System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
  7217. request.Method = "POST";
  7218. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  7219. request.ContentType = "application/json; charset=utf-8";
  7220. // request.ContentType = "text/html, application/xhtml+xml";
  7221. byte[] buffer = encoding.GetBytes(body);
  7222. request.ContentLength = buffer.Length;
  7223. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  7224. System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
  7225. using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream(), encoding))
  7226. {
  7227. return reader.ReadToEnd();
  7228. }
  7229. }
  7230. catch (System.Net.WebException ex)
  7231. {
  7232. throw new Exception(apiName + "调用失败," + ex.Message);
  7233. }
  7234. }
  7235. #endregion
  7236. #region logIn
  7237. public object CheckLogin(Sys_SRM_User userModel)
  7238. {
  7239. List<Sys_SRM_User> userLogOnEntity = new List<Sys_SRM_User>();
  7240. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  7241. conn.Open();
  7242. SqlTransaction sqlTran = conn.BeginTransaction();
  7243. SqlCommand cmd = new SqlCommand();
  7244. cmd.Transaction = sqlTran;
  7245. cmd.Connection = conn;
  7246. DataTable dt;
  7247. try
  7248. {
  7249. sql = @"select * from Sys_SRM_User where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";//已经启用的账号
  7250. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  7251. dt = DBHelper.SQlReturnData(sql, cmd);
  7252. if (dt.Rows.Count > 0)//查询的数据不为空
  7253. {
  7254. sqlInfo = @" select a.[F_Id] as UserId
  7255. ,[F_Account] as userCode
  7256. ,[F_RealName] as UserName
  7257. ,[F_NickName]
  7258. ,b.F_UserPassword
  7259. ,b.F_UserSecretkey
  7260. ,[F_HeadIcon]
  7261. ,[F_Gender]
  7262. ,[F_Birthday]
  7263. ,[F_MobilePhone]
  7264. ,[F_Email]
  7265. ,[F_WeChat]
  7266. ,[F_ManagerId]
  7267. ,[F_SecurityLevel]
  7268. ,[F_Signature]
  7269. ,[F_OrganizeId]
  7270. ,[F_DepartmentId]
  7271. ,[F_RoleId]
  7272. ,[F_DutyId]
  7273. ,[F_IsAdministrator]
  7274. ,[F_SortCode]
  7275. ,[F_DeleteMark]
  7276. ,[F_EnabledMark]
  7277. ,[F_Description]
  7278. ,[F_CreatorTime]
  7279. ,[F_CreatorUserId]
  7280. ,[F_LastModifyTime]
  7281. ,[F_LastModifyUserId]
  7282. ,[F_DeleteTime]
  7283. ,[F_DeleteUserId]
  7284. ,[F_Location] as WorkPoint
  7285. ,[F_VenCode]
  7286. from Sys_SRM_User a
  7287. left join Sys_SRM_UserLogOn b on b.F_UserId=a.F_Id
  7288. where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";
  7289. sqlInfo = string.Format(sqlInfo, userModel.UserCode, userModel.WorkPoint);
  7290. dt = DBHelper.SQlReturnData(sqlInfo, cmd);
  7291. IList<UserLogOnEntity> users = DBHelper.ModelConvertHelper<UserLogOnEntity>.ConvertToModel(dt);
  7292. // string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  7293. foreach (var item in users)
  7294. {
  7295. //string UserPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower()),16).ToLower();
  7296. string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  7297. if (dbPassword == item.F_UserPassword)
  7298. {
  7299. string json = JsonConvert.SerializeObject(dt);
  7300. userLogOnEntity = JsonConvert.DeserializeObject<List<Sys_SRM_User>>(json);
  7301. return userLogOnEntity;
  7302. }
  7303. else
  7304. {
  7305. throw new Exception("密码不正确,请重新输入");
  7306. }
  7307. }
  7308. }
  7309. else
  7310. {
  7311. throw new Exception("用户名不存在,请重新输入!");
  7312. }
  7313. //cmd.CommandText = sql;
  7314. //int num = cmd.ExecuteNonQuery();
  7315. }
  7316. catch (Exception ex)
  7317. {
  7318. log.Error(ex.Message);
  7319. throw new Exception(ex.Message);
  7320. }
  7321. finally
  7322. {
  7323. if (conn.State == ConnectionState.Open)
  7324. {
  7325. conn.Close();
  7326. }
  7327. conn.Dispose();
  7328. }
  7329. return null;
  7330. }
  7331. #endregion
  7332. }
  7333. }