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

114 lines
4.9 KiB

  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace ICSSoft.DataProject
  12. {
  13. /// <summary>
  14. /// 采购退库
  15. /// </summary>
  16. public class PurchaseReturnBack
  17. {
  18. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  19. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
  20. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  21. private static string Type = System.Configuration.ConfigurationManager.AppSettings["Type"];
  22. public string Get(List<ICSPurchaseReturnBack> infos)
  23. {
  24. List<ICSPurchaseReturnBack> szJson = new List<ICSPurchaseReturnBack>();
  25. DataTable dt = null;
  26. DataTable dtNew = null;
  27. string connS = "";
  28. string json = "";
  29. if (infos.Count <= 0)
  30. {
  31. throw new Exception("传送数据为空!");
  32. }
  33. string res = string.Empty;
  34. SqlConnection conn = new SqlConnection();
  35. SqlCommand cmd = new SqlCommand();
  36. string sql = string.Empty;
  37. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  38. foreach (string WorkPoint in result)
  39. {
  40. try
  41. {
  42. connS = string.Format(connString, WorkPoint);
  43. conn = new System.Data.SqlClient.SqlConnection(connS);
  44. conn.Open();
  45. SqlTransaction sqlTran = conn.BeginTransaction();
  46. cmd = new SqlCommand();
  47. cmd.Transaction = sqlTran;
  48. cmd.Connection = conn;
  49. foreach (ICSPurchaseReturnBack info in infos)
  50. {
  51. if (WorkPoint != info.WorkPoint)
  52. continue;
  53. ICSUserInfo userInfo = new ICSUserInfo();
  54. userInfo = DBHelper.GetPersonInfo(info.User, cmd);
  55. if (info.MTime < new DateTime(2000, 01, 01))
  56. throw new Exception("请输入正确的操作时间:" + info.MTime);
  57. sql = @" SELECT iBillType,A.ID,A.cCode,A.cVenCode,D.cVenName,C.CDEPNAME,A.cDepCode,C.cDepName,A.cpocode,A.cMaker,A.cMakeTime,A.cverifier,A.caudittime,
  58. B.Autoid,B.irowno ,B.cInvCode ,B.INUM,B.iQuantity,B.fValidInQuan,B.iPOsID
  59. FROM PU_ArrivalVouch A
  60. INNER JOIN PU_ArrivalVouchs B ON A.ID=B.ID
  61. INNER JOIN DEPARTMENT C ON A.CDEPCODE=C.CDEPCODE
  62. INNER JOIN VENDOR D ON A.CVENCODE=D.CVENCODE WHERE 1=1 and iQuantity<0 and A.cBusType=''";
  63. if (!string.IsNullOrWhiteSpace(info.DNRTCode))
  64. {
  65. sql += " and a.cCode='{0}'";
  66. }
  67. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  68. {
  69. sql += " and ISNULL(a.cModifyTime,ISNULL(a.cAuditTime, ISNULL(a.cModifyTime, a.cmaketime)))>='{1}'";
  70. }
  71. if (!string.IsNullOrWhiteSpace(info.User))
  72. {
  73. sql += "and a.CMAKER='{2}'";
  74. }
  75. sql = string.Format(sql, info.DNRTCode, info.MTime, userInfo.UserName);
  76. dt = DBHelper.SQlReturnData(sql, cmd);
  77. if (dt.Rows.Count <= 0 || dt == null)
  78. throw new Exception("采购退货单:" + info.DNRTCode + ",无信息!");
  79. if (dtNew == null)
  80. dtNew = dt;
  81. else
  82. dtNew.Merge(dt);
  83. }
  84. cmd.Transaction.Commit();
  85. }
  86. catch (Exception ex)
  87. {
  88. cmd.Transaction.Rollback();
  89. log.Error(ex.Message);
  90. throw new Exception(ex.Message);
  91. }
  92. finally
  93. {
  94. if (conn.State == ConnectionState.Open)
  95. {
  96. conn.Close();
  97. }
  98. conn.Dispose();
  99. }
  100. }
  101. json = JsonConvert.SerializeObject(dtNew);
  102. return json;
  103. }
  104. }
  105. }