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

1041 lines
36 KiB

3 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace ICSSoft.Common
  9. {
  10. /// <summary>
  11. /// 公共验证方法
  12. /// </summary>
  13. public class VerificationMethod
  14. {
  15. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  16. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
  17. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  18. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  19. /// <summary>
  20. /// 库存验证物料
  21. /// </summary>
  22. /// <param name="LotNo">条码</param>
  23. /// <param name="WorkPoint">站点</param>
  24. /// <param name="TransCode">源头单据</param>
  25. /// <returns></returns>
  26. public string HouseLotInvCode(string LotNo, string WorkPoint,string TransCode)
  27. {
  28. if (conn.State == ConnectionState.Open)
  29. {
  30. conn.Close();
  31. }
  32. conn.Open();
  33. SqlTransaction sqlTran = conn.BeginTransaction();
  34. SqlCommand cmd = new SqlCommand();
  35. cmd.Transaction = sqlTran;
  36. cmd.Connection = conn;
  37. DataTable table;
  38. try
  39. {
  40. //验证条码物料是否相同
  41. string sql = @"select * from ICSWareHouseLotInfo where LotNo='{0}' and WorkPoint='{2}' and InvCode in (select A.InvCode from ICSMOPick a left join ICSMO b on b.id=a.MODetailID where b.MOCode='{1}' AND B.WorkPoint='{2}')";
  42. sql = string.Format(sql, LotNo, TransCode, WorkPoint);
  43. table = DBHelper.SQlReturnData(sql, cmd);
  44. if (table.Rows.Count <= 0)
  45. {
  46. throw new Exception("条码对应物料不符!");
  47. }
  48. else
  49. {
  50. //验证仓库
  51. // HouseLotWHCode(LotNo, WorkPoint);
  52. }
  53. }
  54. catch (Exception ex)
  55. {
  56. //cmd.Transaction.Rollback();
  57. log.Error(ex.Message);
  58. throw new Exception(ex.Message);
  59. }
  60. finally
  61. {
  62. if (conn.State == ConnectionState.Open)
  63. {
  64. conn.Close();
  65. }
  66. conn.Dispose();
  67. }
  68. return null;
  69. }
  70. /// <summary>
  71. /// 库存验证仓库
  72. /// </summary>
  73. /// <param name="LotNo">条码</param>
  74. /// <param name="WorkPoint">站点</param>
  75. /// <param name="TransCode">源头单据</param>
  76. /// <returns></returns>
  77. public string HouseLotWHCode(string LotNo, string WorkPoint)
  78. {
  79. // conn.Open();
  80. SqlTransaction sqlTran = conn.BeginTransaction();
  81. SqlCommand cmd = new SqlCommand();
  82. cmd.Transaction = sqlTran;
  83. cmd.Connection = conn;
  84. DataTable table;
  85. try
  86. {
  87. //验证条码仓库是否相同
  88. string sql = @"select * from ICSWarehouse where WorkPoint='{1}' and WarehouseCode in (select WarehouseCode from ICSWareHouseLotInfo where LotNo='{0}' AND WorkPoint='{1}')";
  89. sql = string.Format(sql, LotNo, WorkPoint);
  90. table = DBHelper.SQlReturnData(sql, cmd);
  91. if (table.Rows.Count <= 0)
  92. {
  93. throw new Exception("条码对应仓库不符!");
  94. }
  95. else
  96. {
  97. //验证项目号
  98. HouseLotProjectCode(LotNo, WorkPoint);
  99. }
  100. }
  101. catch (Exception ex)
  102. {
  103. //cmd.Transaction.Rollback();
  104. log.Error(ex.Message);
  105. throw new Exception(ex.Message);
  106. }
  107. finally
  108. {
  109. if (conn.State == ConnectionState.Open)
  110. {
  111. conn.Close();
  112. }
  113. conn.Dispose();
  114. }
  115. return null;
  116. }
  117. /// <summary>
  118. /// 库存验证项目号
  119. /// </summary>
  120. /// <param name="LotNo">条码</param>
  121. /// <param name="WorkPoint">站点</param>
  122. /// <param name="TransCode">源头单据</param>
  123. /// <returns></returns>
  124. public string HouseLotProjectCode(string LotNo, string WorkPoint)
  125. {
  126. // conn.Open();
  127. SqlTransaction sqlTran = conn.BeginTransaction();
  128. SqlCommand cmd = new SqlCommand();
  129. cmd.Transaction = sqlTran;
  130. cmd.Connection = conn;
  131. DataTable table;
  132. try
  133. {
  134. //验证条码项目号是否相同
  135. string sql = @"select ProjectCode from ICSExtension where WorkPoint='{1}' and id in (select ExtensionID from ICSInventoryLot where WorkPoint='{1}' and LotNo='{0}' )";
  136. sql = string.Format(sql, LotNo, WorkPoint);
  137. table = DBHelper.SQlReturnData(sql, cmd);
  138. if (table.Rows.Count <= 0)
  139. {
  140. throw new Exception("条码对应项目号不符!");
  141. }
  142. else
  143. {
  144. //验证批次
  145. HouseLotBatchCode(LotNo, WorkPoint);
  146. }
  147. }
  148. catch (Exception ex)
  149. {
  150. //cmd.Transaction.Rollback();
  151. log.Error(ex.Message);
  152. throw new Exception(ex.Message);
  153. }
  154. finally
  155. {
  156. if (conn.State == ConnectionState.Open)
  157. {
  158. conn.Close();
  159. }
  160. }
  161. return null;
  162. }
  163. /// <summary>
  164. /// 库存验证批次
  165. /// </summary>
  166. /// <param name="LotNo">条码</param>
  167. /// <param name="WorkPoint">站点</param>
  168. /// <param name="TransCode">源头单据</param>
  169. /// <returns></returns>
  170. public string HouseLotBatchCode(string LotNo, string WorkPoint)
  171. {
  172. // conn.Open();
  173. SqlTransaction sqlTran = conn.BeginTransaction();
  174. SqlCommand cmd = new SqlCommand();
  175. cmd.Transaction = sqlTran;
  176. cmd.Connection = conn;
  177. DataTable table;
  178. try
  179. {
  180. //验证条码批次是否相同
  181. string sql = @"select BatchCode from ICSExtension where WorkPoint='{1}' and id in (select ExtensionID from ICSInventoryLot where WorkPoint='{1}' and LotNo='{0}' )";
  182. sql = string.Format(sql, LotNo, WorkPoint);
  183. table = DBHelper.SQlReturnData(sql, cmd);
  184. if (table.Rows.Count <= 0)
  185. {
  186. throw new Exception("条码对应批次不符!");
  187. }
  188. else
  189. {
  190. //验证自由项
  191. HouseLotcFree(LotNo, WorkPoint);
  192. }
  193. }
  194. catch (Exception ex)
  195. {
  196. //cmd.Transaction.Rollback();
  197. log.Error(ex.Message);
  198. throw new Exception(ex.Message);
  199. }
  200. finally
  201. {
  202. if (conn.State == ConnectionState.Open)
  203. {
  204. conn.Close();
  205. }
  206. }
  207. return null;
  208. }
  209. /// <summary>
  210. /// 库存验证自由项
  211. /// </summary>
  212. /// <param name="LotNo">条码</param>
  213. /// <param name="WorkPoint">站点</param>
  214. /// <param name="TransCode">源头单据</param>
  215. /// <returns></returns>
  216. public string HouseLotcFree(string LotNo, string WorkPoint)
  217. {
  218. //conn.Open();
  219. SqlTransaction sqlTran = conn.BeginTransaction();
  220. SqlCommand cmd = new SqlCommand();
  221. cmd.Transaction = sqlTran;
  222. cmd.Connection = conn;
  223. DataTable table;
  224. try
  225. {
  226. //验证条码自由项是否相同
  227. string sql = @"select ProjectCode from ICSExtension where WorkPoint='{1}' and id in (select ExtensionID from ICSInventoryLot where WorkPoint='{1}' and LotNo='{0}' )";
  228. sql = string.Format(sql, LotNo, WorkPoint);
  229. table = DBHelper.SQlReturnData(sql, cmd);
  230. if (table.Rows.Count <= 0)
  231. {
  232. throw new Exception("条码对应自由项不符!");
  233. }
  234. else
  235. {
  236. //验证批次
  237. }
  238. }
  239. catch (Exception ex)
  240. {
  241. //cmd.Transaction.Rollback();
  242. log.Error(ex.Message);
  243. throw new Exception(ex.Message);
  244. }
  245. finally
  246. {
  247. if (conn.State == ConnectionState.Open)
  248. {
  249. conn.Close();
  250. }
  251. }
  252. return null;
  253. }
  254. /// <summary>
  255. /// 入库条码验证
  256. /// </summary>
  257. /// <param name="LotNo"></param>
  258. /// <param name="WorkPoint"></param>
  259. /// <param name="TransCode"></param>
  260. /// <returns></returns>
  261. public string HouseLotoOut(string LotNo, string WorkPoint)
  262. {
  263. if (conn.State == ConnectionState.Open)
  264. {
  265. conn.Close();
  266. }
  267. conn.Open();
  268. SqlTransaction sqlTran = conn.BeginTransaction();
  269. SqlCommand cmd = new SqlCommand();
  270. cmd.Transaction = sqlTran;
  271. cmd.Connection = conn;
  272. DataTable table;
  273. try
  274. {
  275. string sqllist = @" select * from ICSWareHouseLotInfo where lotno ='{0}' and WorkPoint='{1}'";
  276. sqllist = string.Format(sqllist, LotNo, WorkPoint);
  277. table = DBHelper.SQlReturnData(sqllist, cmd);
  278. if (table.Rows.Count >0)
  279. {
  280. throw new Exception("条码已入库!");
  281. }
  282. }
  283. catch (Exception ex)
  284. {
  285. //cmd.Transaction.Rollback();
  286. log.Error(ex.Message);
  287. throw new Exception(ex.Message);
  288. }
  289. finally
  290. {
  291. if (conn.State == ConnectionState.Open)
  292. {
  293. conn.Close();
  294. }
  295. conn.Dispose();
  296. }
  297. return null;
  298. }
  299. /// <summary>
  300. /// 检验物料是否需要检验
  301. /// </summary>
  302. /// <param name="InvCode">物料</param>
  303. /// <param name="WorkPoint">站点</param>
  304. /// <returns></returns>
  305. public Double LotoTest(string Lotno, string WorkPoint)
  306. {
  307. if (conn.State == ConnectionState.Open)
  308. {
  309. conn.Close();
  310. }
  311. conn.Open();
  312. SqlTransaction sqlTran = conn.BeginTransaction();
  313. SqlCommand cmd = new SqlCommand();
  314. cmd.Transaction = sqlTran;
  315. cmd.Connection = conn;
  316. DataTable table;
  317. string Info;
  318. int InvIQC = 0;
  319. ///根据物料+站点查询数据
  320. string sql = @"select InvIQC from ICSInventory where InvCode=(SELECT InvCode FROM ICSInventoryLot WHERE LOTNO='{0}' and WorkPoint='{1}') and WorkPoint='{1}' ";
  321. sql = string.Format(sql, Lotno, WorkPoint);
  322. table = DBHelper.SQlReturnData(sql, cmd);
  323. if (table.Rows.Count > 0)
  324. {
  325. foreach (DataRow item in table.Rows)
  326. {
  327. InvIQC = Convert.ToInt32(item["InvIQC"]);
  328. }
  329. if (InvIQC == 1)
  330. {
  331. Double num = QualifiedQuantity(Lotno, WorkPoint);
  332. return num;
  333. }
  334. else
  335. {
  336. //查询条码数量
  337. return 0.0;
  338. }
  339. }
  340. else
  341. {
  342. throw new Exception("该物料没有数据!");
  343. }
  344. }
  345. /// <summary>
  346. /// 需要检验的取检验表的数量
  347. /// </summary>
  348. /// <param name="Lotno"></param>
  349. /// <param name="WorkPoint"></param>
  350. /// <param name="InvCode"></param>
  351. /// <returns></returns>
  352. public double QualifiedQuantity(string Lotno, string WorkPoint)
  353. {
  354. if (conn.State == ConnectionState.Open)
  355. {
  356. conn.Close();
  357. }
  358. conn.Open();
  359. SqlTransaction sqlTran = conn.BeginTransaction();
  360. SqlCommand cmd = new SqlCommand();
  361. cmd.Transaction = sqlTran;
  362. cmd.Connection = conn;
  363. DataTable table;
  364. double qualifiedQuantity = 0;//合格数量
  365. double waiveQuantity = 0;//特采数量
  366. double totalQuantity = 0;//总数量
  367. string sql = @"select * from ICSInspection where Lotno='{0}' and WorkPoint='{1}' and InvCode=(SELECT InvCode FROM ICSInventoryLot WHERE LOTNO='{0}' and WorkPoint='{1}')";
  368. sql = string.Format(sql, Lotno, WorkPoint);
  369. table = DBHelper.SQlReturnData(sql, cmd);
  370. if (table.Rows.Count <= 0)
  371. {
  372. throw new Exception("该条码没有检验!");
  373. }
  374. else
  375. {
  376. foreach (DataRow item in table.Rows)
  377. {
  378. qualifiedQuantity = Convert.ToDouble(item["QualifiedQuantity"]);
  379. waiveQuantity = Convert.ToDouble(item["WaiveQuantity"]);
  380. totalQuantity = qualifiedQuantity + waiveQuantity;
  381. }
  382. return totalQuantity;
  383. }
  384. }
  385. /// <summary>
  386. /// 验证是否到货
  387. /// </summary>
  388. /// <param name="POID"></param>
  389. /// <param name="WorkPoint"></param>
  390. /// <returns></returns>
  391. public bool DeliveryNotice(string LOTNO, string WorkPoint)
  392. {
  393. if (conn.State == ConnectionState.Open)
  394. {
  395. conn.Close();
  396. }
  397. conn.Open();
  398. SqlTransaction sqlTran = conn.BeginTransaction();
  399. SqlCommand cmd = new SqlCommand();
  400. cmd.Transaction = sqlTran;
  401. cmd.Connection = conn;
  402. DataTable table;
  403. string sql = @"select
  404. a.ID,
  405. H.ContainerCODE,
  406. H.ContainerName,
  407. A.InvCode,
  408. F.InvName,
  409. F.InvStd,
  410. a.Quantity,
  411. F.InvUnit,
  412. F.AmountUnit,
  413. E.ProjectCode,
  414. E.BatchCode,
  415. E.Version,
  416. E.Brand,
  417. c.POCode as TransCode,--
  418. c.Sequence as TransSequence,--
  419. A.LotNo,
  420. E.cFree1,
  421. E.cFree2,
  422. E.cFree3,
  423. E.cFree4,
  424. E.cFree5,
  425. E.cFree6,
  426. E.cFree7,
  427. E.cFree8,
  428. E.cFree9,
  429. E.cFree10
  430. FROM ICSInventoryLot A
  431. LEFT JOIN ICSInventoryLotDetail B ON A.LotNo =B.LotNo
  432. LEFT JOIN ICSPurchaseOrder C ON b.TransCode=C.POCode AND C.Sequence=B.TransSequence
  433. LEFT JOIN ICSExtension E ON E.ID=A.ExtensionID
  434. LEFT JOIN ICSInventory F ON A.InvCode=F.InvCode
  435. LEFT JOIN ICSContainerLot G ON A.LotNo =G.LotNo
  436. LEFT JOIN ICSContainer H ON H.ContainerID=G.ID where a.lotno='{0}' and a.WorkPoint ='{1}'";
  437. sql = string.Format(sql, LOTNO, WorkPoint);
  438. DataTable dataTable = DBHelper.SQlReturnData(sql, cmd);
  439. if (dataTable.Rows.Count <= 0)
  440. {
  441. throw new Exception("请先到货" + LOTNO);
  442. }
  443. else
  444. {
  445. bool ttt = true;
  446. return ttt;
  447. }
  448. }
  449. /// <summary>
  450. /// 查询送货单是否存在
  451. /// </summary>
  452. /// <param name="LotNo"></param>
  453. /// <param name="WorkPoint"></param>
  454. /// <returns></returns>
  455. public bool SNDetail(string LotNo, string WorkPoint)
  456. {
  457. if (conn.State == ConnectionState.Open)
  458. {
  459. conn.Close();
  460. }
  461. conn.Open();
  462. SqlTransaction sqlTran = conn.BeginTransaction();
  463. SqlCommand cmd = new SqlCommand();
  464. cmd.Transaction = sqlTran;
  465. cmd.Connection = conn;
  466. DataTable table;
  467. string sql = @"select * from ICSASNDetail where LotNo='{0}' and WorkPoint='{1}'";
  468. sql = string.Format(sql, LotNo, WorkPoint);
  469. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  470. if (data.Rows.Count <= 0)
  471. {
  472. throw new Exception("送货单不存在!");
  473. }
  474. else
  475. {
  476. bool num = DeliveryNotice(LotNo, WorkPoint);
  477. return num;
  478. }
  479. }
  480. #region 验证库存是否存在
  481. /// <summary>
  482. /// 验证库存是否存在
  483. /// </summary>
  484. /// <param name="LotNo"></param>
  485. /// <param name="WorkPoint"></param>
  486. /// <returns></returns>
  487. public bool HouseLotInfo(string LotNo, string WorkPoint, string type)
  488. {
  489. if (conn.State == ConnectionState.Open)
  490. {
  491. conn.Close();
  492. }
  493. conn.Open();
  494. SqlTransaction sqlTran = conn.BeginTransaction();
  495. SqlCommand cmd = new SqlCommand();
  496. cmd.Transaction = sqlTran;
  497. cmd.Connection = conn;
  498. DataTable table;
  499. string sql = @"select * from ICSWareHouseLotInfo where LotNo='{0}' and WorkPoint='{1}'";
  500. sql = string.Format(sql, LotNo, WorkPoint);
  501. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  502. if (data.Rows.Count < 0) {
  503. switch (type)
  504. {
  505. case "退货":
  506. throw new Exception("该条码已入库!");
  507. case "发货":
  508. throw new Exception("该条码无库存!");
  509. case "其它入库":
  510. throw new Exception("该条码已入库!");
  511. case "委外发料":
  512. throw new Exception("该条码不存在!");
  513. }
  514. }
  515. //else
  516. //{
  517. // throw new Exception("该条码不存在!");
  518. //}
  519. return true;
  520. }
  521. #endregion
  522. public bool PurchaseOrder(string LotNo, string WorkPoint)
  523. {
  524. if (conn.State == ConnectionState.Open)
  525. {
  526. conn.Close();
  527. }
  528. conn.Open();
  529. SqlTransaction sqlTran = conn.BeginTransaction();
  530. SqlCommand cmd = new SqlCommand();
  531. cmd.Transaction = sqlTran;
  532. cmd.Connection = conn;
  533. DataTable table;
  534. string sql = @"select* from ICSPurchaseOrder where POCode=( select TransCode from ICSInventoryLotDetail where lotno='{0}' and WorkPoint='{1}')
  535. and Sequence=( select TransSequence from ICSInventoryLotDetail where lotno='{0}' and WorkPoint='{1}') and Status=1";
  536. sql = string.Format(sql, LotNo, WorkPoint);
  537. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  538. if (data.Rows.Count > 0)
  539. {
  540. throw new Exception("该条码没有审核,请先审核!");
  541. }
  542. return true;
  543. }
  544. /// <summary>
  545. /// 库存是否存在/是否审核
  546. /// </summary>
  547. /// <param name="CheckCode"></param>
  548. /// <returns></returns>
  549. public bool isCheck(string CheckCode, string WorkPoint)
  550. {
  551. if (conn.State == ConnectionState.Open)
  552. {
  553. conn.Close();
  554. }
  555. conn.Open();
  556. SqlTransaction sqlTran = conn.BeginTransaction();
  557. SqlCommand cmd = new SqlCommand();
  558. cmd.Transaction = sqlTran;
  559. cmd.Connection = conn;
  560. DataTable table;
  561. int num;
  562. try
  563. {
  564. string sql = @"select * from ICSCheck where CheckCode='{0}' and WorkPoint='{1}'";
  565. sql = string.Format(sql, CheckCode, WorkPoint);
  566. table = DBHelper.SQlReturnData(sql, cmd);
  567. if (table.Rows.Count > 0)
  568. {
  569. string sqlInfro = @"select * from ICSCheck where CheckCode='{0}' and WorkPoint='{1}' and Status='2'";
  570. sqlInfro = string.Format(sqlInfro, CheckCode, WorkPoint);
  571. DataTable dataTable = DBHelper.SQlReturnData(sqlInfro, cmd);
  572. if (dataTable.Rows.Count <= 0)
  573. {
  574. throw new Exception("该盘点没有审核,请先审核!");
  575. }
  576. }
  577. else
  578. {
  579. throw new Exception("该盘点不存在!");
  580. }
  581. return true;
  582. }
  583. catch (Exception)
  584. {
  585. throw;
  586. }
  587. }
  588. /// <summary>
  589. /// 目标仓库是否一致
  590. /// </summary>
  591. /// <returns></returns>
  592. public bool iSLocationCode(string lotno, string WorkPoint)
  593. {
  594. if (conn.State == ConnectionState.Open)
  595. {
  596. conn.Close();
  597. }
  598. conn.Open();
  599. SqlTransaction sqlTran = conn.BeginTransaction();
  600. SqlCommand cmd = new SqlCommand();
  601. cmd.Transaction = sqlTran;
  602. cmd.Connection = conn;
  603. DataTable table;
  604. int num;
  605. try
  606. {
  607. //库存仓库库位和调拨单是否一致
  608. string sql = @"select * from ICSTransfer where fromWarehouseCode in (select WarehouseCode from ICSWareHouseLotInfo where lotno='{0}' and WorkPoint='{1}')";
  609. sql = string.Format(sql, lotno, WorkPoint);
  610. table = DBHelper.SQlReturnData(sql, cmd);
  611. string sqliNFO = @"select * from ICSTransfer where InvCode in (select InvCode from ICSWareHouseLotInfo where lotno='{0}' and WorkPoint='{1}')";
  612. sqliNFO = string.Format(sqliNFO, lotno, WorkPoint);
  613. DataTable tableiNFO = DBHelper.SQlReturnData(sqliNFO, cmd);
  614. if (table.Rows.Count > 0)
  615. {
  616. if (tableiNFO.Rows.Count > 0)
  617. {
  618. string sqlInfro = @"select * from ICSWareHouseLotInfo where lotno='{0}' and WorkPoint='{1}' and Quantity>0";
  619. sqlInfro = string.Format(sqlInfro, lotno, WorkPoint);
  620. DataTable dataTable = DBHelper.SQlReturnData(sqlInfro, cmd);
  621. if (dataTable.Rows.Count <= 0)
  622. {
  623. throw new Exception("调拨单库存为0!");
  624. }
  625. else
  626. {
  627. return true;
  628. }
  629. }
  630. else
  631. {
  632. throw new Exception("物料不一致!");
  633. }
  634. }
  635. else
  636. {
  637. throw new Exception("仓库不一致!");
  638. }
  639. }
  640. catch (Exception)
  641. {
  642. throw;
  643. }
  644. return true;
  645. }
  646. /// <summary>
  647. /// 调拨单
  648. /// </summary>
  649. /// <param name="TransCode"></param>
  650. /// <param name="TransSequence"></param>
  651. /// <param name="CurrentQuantity"></param>
  652. /// <param name="LotNo"></param>
  653. /// <returns></returns>
  654. public bool isTransfer(string TransCode, string TransSequence, double CurrentQuantity, string LotNo, string WarehouseCode, string LocationCode, string WorkPoint)
  655. {
  656. if (conn.State == ConnectionState.Open)
  657. {
  658. conn.Close();
  659. }
  660. conn.Open();
  661. SqlTransaction sqlTran = conn.BeginTransaction();
  662. SqlCommand cmd = new SqlCommand();
  663. cmd.Transaction = sqlTran;
  664. cmd.Connection = conn;
  665. DataTable table;
  666. int num;
  667. ///调拨单是否关闭
  668. string sql = @"select * from ICSTransfer where TransferNO='{0}' and Sequence='{1}' and Status='3'";
  669. sql = string.Format(sql, TransCode, TransSequence);
  670. DataTable dataTable = DBHelper.SQlReturnData(sql, cmd);
  671. if (dataTable.Rows.Count <= 0)
  672. {
  673. string sqlInfo = @" select * from ICSWareHouseLotInfo where {0}<=Quantity and LotNo='{1}' ";
  674. sqlInfo = string.Format(sqlInfo, CurrentQuantity, LotNo);
  675. DataTable data = DBHelper.SQlReturnData(sqlInfo, cmd);
  676. if (data.Rows.Count <= 0)
  677. {
  678. throw new Exception("输入数量大于库存数量!");
  679. }
  680. else
  681. {
  682. string sqlInfoList = @" select * from ICSWareHouseLotInfo where WarehouseCode='{0}' and LocationCode='{1}' and LotNo='{2}' and WorkPoint='{3}'";
  683. sqlInfoList = string.Format(sqlInfoList, WarehouseCode, LocationCode, LotNo, WorkPoint);
  684. DataTable dataList = DBHelper.SQlReturnData(sqlInfoList, cmd);
  685. if (dataList.Rows.Count > 0)
  686. {
  687. throw new Exception("调拨库位/仓库 跟目标库位/仓库一致无需调拨");
  688. }
  689. }
  690. }
  691. else
  692. {
  693. throw new Exception("调拨单已关闭,不可提交!");
  694. }
  695. return true;
  696. }
  697. /// <summary>
  698. /// 条码验证
  699. /// </summary>
  700. /// <param name="LotNo"></param>
  701. /// <param name="WorkPoint"></param>
  702. /// <param name="TransCode"></param>
  703. /// <returns></returns>
  704. public string LotoOut(string LotNo, string WorkPoint)
  705. {
  706. if (conn.State == ConnectionState.Open)
  707. {
  708. conn.Close();
  709. }
  710. conn.Open();
  711. SqlTransaction sqlTran = conn.BeginTransaction();
  712. SqlCommand cmd = new SqlCommand();
  713. cmd.Transaction = sqlTran;
  714. cmd.Connection = conn;
  715. DataTable table;
  716. try
  717. {
  718. string sqllist = @" select * from ICSInventoryLot where lotno ='{0}' and WorkPoint='{1}'";
  719. sqllist = string.Format(sqllist, LotNo, WorkPoint);
  720. table = DBHelper.SQlReturnData(sqllist, cmd);
  721. if (table.Rows.Count <= 0)
  722. {
  723. throw new Exception("条码不存在!");
  724. }
  725. }
  726. catch (Exception ex)
  727. {
  728. //cmd.Transaction.Rollback();
  729. log.Error(ex.Message);
  730. throw new Exception(ex.Message);
  731. }
  732. finally
  733. {
  734. if (conn.State == ConnectionState.Open)
  735. {
  736. conn.Close();
  737. }
  738. //conn.Dispose();
  739. }
  740. return null;
  741. }
  742. /// <summary>
  743. /// 其它入库单据是否存在
  744. /// </summary>
  745. /// <param name="TransCode"></param>
  746. /// <param name="WorkPoint"></param>
  747. /// <returns></returns>
  748. public bool IsOtherOut(string TransCode, string WorkPoint)
  749. {
  750. if (conn.State == ConnectionState.Open)
  751. {
  752. conn.Close();
  753. }
  754. conn.Open();
  755. SqlTransaction sqlTran = conn.BeginTransaction();
  756. SqlCommand cmd = new SqlCommand();
  757. cmd.Transaction = sqlTran;
  758. cmd.Connection = conn;
  759. DataTable table;
  760. try
  761. {
  762. string sqllist = @" select * from ICSOtherOut where OutCode ='{0}' and WorkPoint='{1}'";
  763. sqllist = string.Format(sqllist, TransCode, WorkPoint);
  764. table = DBHelper.SQlReturnData(sqllist, cmd);
  765. if (table.Rows.Count <= 0)
  766. {
  767. throw new Exception("单据不存在!");
  768. }
  769. }
  770. catch (Exception ex)
  771. {
  772. //cmd.Transaction.Rollback();
  773. log.Error(ex.Message);
  774. throw new Exception(ex.Message);
  775. }
  776. finally
  777. {
  778. if (conn.State == ConnectionState.Open)
  779. {
  780. conn.Close();
  781. }
  782. //conn.Dispose();
  783. }
  784. return true;
  785. }
  786. /// <summary>
  787. /// 库存是否为0
  788. /// </summary>
  789. /// <returns></returns>
  790. public bool isStockZero(string LotNo, string WorkPoint)
  791. {
  792. if (conn.State == ConnectionState.Open)
  793. {
  794. conn.Close();
  795. }
  796. conn.Open();
  797. SqlTransaction sqlTran = conn.BeginTransaction();
  798. SqlCommand cmd = new SqlCommand();
  799. cmd.Transaction = sqlTran;
  800. cmd.Connection = conn;
  801. DataTable table;
  802. try
  803. {
  804. string sqllist = @" select * from ICSWareHouseLotInfo where LotNo ='{0}' and WorkPoint='{1}' and Quantity>0";
  805. sqllist = string.Format(sqllist, LotNo, WorkPoint);
  806. table = DBHelper.SQlReturnData(sqllist, cmd);
  807. if (table.Rows.Count <= 0)
  808. {
  809. throw new Exception("库存数量为0!");
  810. }
  811. }
  812. catch (Exception ex)
  813. {
  814. //cmd.Transaction.Rollback();
  815. log.Error(ex.Message);
  816. throw new Exception(ex.Message);
  817. }
  818. finally
  819. {
  820. if (conn.State == ConnectionState.Open)
  821. {
  822. conn.Close();
  823. }
  824. //conn.Dispose();
  825. }
  826. return true;
  827. }
  828. /// <summary>
  829. /// 其它出库验证
  830. /// </summary>
  831. /// <returns></returns>
  832. public bool iSNullLocationCode(string lotno, string WorkPoint)
  833. {
  834. if (conn.State == ConnectionState.Open)
  835. {
  836. conn.Close();
  837. }
  838. conn.Open();
  839. SqlTransaction sqlTran = conn.BeginTransaction();
  840. SqlCommand cmd = new SqlCommand();
  841. cmd.Transaction = sqlTran;
  842. cmd.Connection = conn;
  843. DataTable table;
  844. int num;
  845. try
  846. {
  847. //库存仓库库位和调拨单是否一致
  848. string sql = @"select * from ICSOtherOut where WHCode in (select WarehouseCode from ICSWareHouseLotInfo where lotno='{0}' and WorkPoint='{1}')";
  849. sql = string.Format(sql, lotno, WorkPoint);
  850. table = DBHelper.SQlReturnData(sql, cmd);
  851. string sqliNFO = @"select * from ICSOtherOut where InvCode in (select InvCode from ICSWareHouseLotInfo where lotno='{0}' and WorkPoint='{1}')";
  852. sqliNFO = string.Format(sqliNFO, lotno, WorkPoint);
  853. DataTable tableiNFO = DBHelper.SQlReturnData(sqliNFO, cmd);
  854. if (table.Rows.Count > 0)
  855. {
  856. if (tableiNFO.Rows.Count > 0)
  857. {
  858. string sqlInfro = @"select * from ICSWareHouseLotInfo where lotno='{0}' and WorkPoint='{1}' and Quantity>0";
  859. sqlInfro = string.Format(sqlInfro, lotno, WorkPoint);
  860. DataTable dataTable = DBHelper.SQlReturnData(sqlInfro, cmd);
  861. if (dataTable.Rows.Count <= 0)
  862. {
  863. throw new Exception("库存为0!");
  864. }
  865. else
  866. {
  867. return true;
  868. }
  869. }
  870. else
  871. {
  872. throw new Exception("物料不一致!");
  873. }
  874. }
  875. else
  876. {
  877. throw new Exception("仓库不一致!");
  878. }
  879. }
  880. catch (Exception)
  881. {
  882. throw;
  883. }
  884. }
  885. /// <summary>
  886. /// 验证拆卸单是否存在
  887. /// </summary>
  888. /// <returns></returns>
  889. public bool isBoolDisassemblyDoc(string DABDOCCode ,string WorkPoint)
  890. {
  891. if (conn.State == ConnectionState.Open)
  892. {
  893. conn.Close();
  894. }
  895. conn.Open();
  896. SqlTransaction sqlTran = conn.BeginTransaction();
  897. SqlCommand cmd = new SqlCommand();
  898. cmd.Transaction = sqlTran;
  899. cmd.Connection = conn;
  900. DataTable table;
  901. bool num = true;
  902. try
  903. {
  904. string sql = @"select * from ICSDisassemblyDoc where DABDOCCode ='{0}' and WorkPoint='{1}')";
  905. sql = string.Format(sql, DABDOCCode, WorkPoint);
  906. table = DBHelper.SQlReturnData(sql, cmd);
  907. if (table.Rows.Count>0)
  908. {
  909. return num;
  910. }
  911. else
  912. {
  913. throw new Exception("拆卸单不存在!");
  914. }
  915. }
  916. catch (Exception ex)
  917. {
  918. }
  919. return false;
  920. }
  921. /// <summary>
  922. /// 委外发料
  923. /// </summary>
  924. /// <param name="LotNo"></param>
  925. /// <param name="WorkPoint"></param>
  926. /// <returns></returns>
  927. public bool Outsourcing(string LotNo, string WorkPoint, string TransCode)
  928. {
  929. if (conn.State == ConnectionState.Open)
  930. {
  931. conn.Close();
  932. }
  933. conn.Open();
  934. SqlTransaction sqlTran = conn.BeginTransaction();
  935. SqlCommand cmd = new SqlCommand();
  936. cmd.Transaction = sqlTran;
  937. cmd.Connection = conn;
  938. DataTable table;
  939. string sql = @"select * from ICSWareHouseLotInfo where LotNo='{0}' and WorkPoint='{1}' and InvCode in (select A.InvCode from ICSOOPick a where LotNo='{0}')";
  940. ///*left join ICSOutsourcingOrder b on a.OODetailID =b.OODetailID where OOcode='{1}' AND a.WorkPoint='{2}'*/)
  941. sql = string.Format(sql, LotNo, WorkPoint);
  942. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  943. if (data.Rows.Count <0)
  944. {
  945. throw new Exception("条码与物料不符!");
  946. }
  947. return true;
  948. }
  949. /// <summary>
  950. /// 委外到货
  951. /// </summary>
  952. /// <param name="LotNo"></param>
  953. /// <param name="WorkPoint"></param>
  954. /// <param name="TransCode"></param>
  955. /// <returns></returns>
  956. public bool OutsourcingChre(string LotNo, string WorkPoint, string TransCode)
  957. {
  958. if (conn.State == ConnectionState.Open)
  959. {
  960. conn.Close();
  961. }
  962. conn.Open();
  963. SqlTransaction sqlTran = conn.BeginTransaction();
  964. SqlCommand cmd = new SqlCommand();
  965. cmd.Transaction = sqlTran;
  966. cmd.Connection = conn;
  967. DataTable table;
  968. string sql = @"select * from ICSODeliveryNotice where OASNCode='{0}' and WorkPoint='{1}' ";
  969. sql = string.Format(sql, TransCode, WorkPoint);
  970. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  971. if (data.Rows.Count > 0)
  972. {
  973. throw new Exception("条码与物料不符!");
  974. }
  975. return true;
  976. }
  977. }
  978. }