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

105 lines
4.0 KiB

3 years ago
  1. using ICSSoft.Entity;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using Newtonsoft.Json;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using ICSSoft.Common;
  11. namespace ICSSoft.DataProject
  12. {
  13. namespace ICSSoft.DataProject
  14. {
  15. public class CreatePOTest
  16. {
  17. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  18. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
  19. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  20. //参数示例
  21. //[{
  22. // "LotNO": "PO200224008100011",
  23. // "YLOTQTY": "11",
  24. // "NLOTQTY": "11",
  25. // "BadCause": "破损",
  26. // "User": "CC001",
  27. // "MTime": "2021-08-26 17:20:13"
  28. //}]
  29. //返回参数
  30. //{
  31. //"Success": true,
  32. //"Message": "接口调用成功!",
  33. //"Data": null
  34. //}
  35. /// <summary>
  36. /// 生成物料检验单
  37. /// </summary>
  38. /// <param name="infos"></param>
  39. /// <returns></returns>
  40. public string Create(List<ICSPOTest> infos)
  41. {
  42. if (infos.Count <= 0)
  43. {
  44. throw new Exception("传送数据为空!");
  45. }
  46. string res = string.Empty;
  47. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  48. conn.Open();
  49. SqlTransaction sqlTran = conn.BeginTransaction();
  50. SqlCommand cmd = new SqlCommand();
  51. cmd.Transaction = sqlTran;
  52. cmd.Connection = conn;
  53. try
  54. {
  55. string sql = string.Empty;
  56. foreach (ICSPOTest info in infos)
  57. {
  58. if (info.MTime < new DateTime(2000, 01, 01))
  59. throw new Exception("请输入正确的操作时间:" + info.MTime);
  60. sql = @" IF EXISTS(SELECT LotNO FROM ICSINSPECTION WHERE LotNO='{0}' )
  61. RAISERROR('{0}',16,1)
  62. else
  63. insert into ICSINSPECTION(ID,TransNO,TransLine,LotNO,INVCODE,VENDORITEMCODE,VENDORCODE,VenderLotNO,PRODUCTDATE,
  64. LOTQTY,YLOTQTY,NLOTQTY,BadCause,MUSER,MUSERName,MTIME,WorkPoint
  65. )
  66. select newid(),c.cCode,c.irowno,'{0}',c.cInvCode,b.ITEMCODE,a.VENDORCODE,c.Batch,getdate(),c.iQuantity ,'{1}','{2}','{3}','{4}',UserName ,'{5}',b.WorkPoint from ICSASN a
  67. left join dbo.ICSASNDETAIL b on a.STNO=b.STNO
  68. left join ICSPOArrive c on b.STNO=c.STNO
  69. left join ICSINVENTORY d on b.itemcode=d.INVCODE
  70. inner join dbo. Sys_User on USERCODE='{4}'
  71. where b.lotno='{0}'";
  72. sql = string.Format(sql, info.LotNO, info.YLOTQTY, info.NLOTQTY, info.BadCause, info.User, info.MTime);
  73. DBHelper.CmdExecuteNonQuery(sql, cmd, "条码:" + info.LotNO + "未查询到对应数据!");
  74. }
  75. cmd.Transaction.Commit();
  76. return res;
  77. }
  78. catch (Exception ex)
  79. {
  80. cmd.Transaction.Rollback();
  81. log.Error(ex.Message);
  82. throw new Exception(ex.Message);
  83. }
  84. finally
  85. {
  86. if (conn.State == ConnectionState.Open)
  87. {
  88. conn.Close();
  89. }
  90. conn.Dispose();
  91. }
  92. }
  93. }
  94. }
  95. }