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

120 lines
4.9 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
  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. public class SalesReturnBack
  14. {
  15. /// <summary>
  16. /// 获取销售发货
  17. /// </summary>
  18. /// <param name="infos"></param>
  19. /// <returns></returns>
  20. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  21. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
  22. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  23. private static string Type = System.Configuration.ConfigurationManager.AppSettings["Type"];
  24. public string Get(List<ICSSalesReturnBack> infos)
  25. {
  26. List<ICSSalesReturnBack> szJson = new List<ICSSalesReturnBack>();
  27. DataTable dt = null;
  28. DataTable dtNew = null;
  29. string connS = "";
  30. string json = "";
  31. if (infos.Count <= 0)
  32. {
  33. throw new Exception("传送数据为空!");
  34. }
  35. string res = string.Empty;
  36. SqlConnection conn = new SqlConnection();
  37. SqlCommand cmd = new SqlCommand();
  38. string sql = string.Empty;
  39. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  40. foreach (string WorkPoint in result)
  41. {
  42. try
  43. {
  44. connS = string.Format(connString, WorkPoint);
  45. conn = new System.Data.SqlClient.SqlConnection(connS);
  46. conn.Open();
  47. SqlTransaction sqlTran = conn.BeginTransaction();
  48. cmd = new SqlCommand();
  49. cmd.Transaction = sqlTran;
  50. cmd.Connection = conn;
  51. foreach (ICSSalesReturnBack info in infos)
  52. {
  53. if (WorkPoint != info.WorkPoint)
  54. continue;
  55. ICSUserInfo userInfo = new ICSUserInfo();
  56. userInfo = DBHelper.GetPersonInfo(info.User, cmd);
  57. if (info.MTime < new DateTime(2000, 01, 01))
  58. throw new Exception("请输入正确的操作时间:" + info.MTime);
  59. sql = @" select a.DLID ,a.cDLCode ,a.cCusCode,c.cCusName,a.cDepCode ,
  60. d.cDepName,b.cordercode ,a.cMaker ,a.dcreatesystime ,
  61. b.AutoID ,b.irowno,b.cInvCode ,b.iQuantity ,b.iNum ,b.iSOsID
  62. FROM dbo.DispatchList a
  63. INNER JOIN dbo.DispatchLists b ON a.DLID = b.DLID
  64. LEFT JOIN dbo.Customer c ON a.cCusCode = c.cCusCode
  65. left join Department d on a.cDepCode=d.cDepCode where b.iQuantity<0";
  66. if (!string.IsNullOrWhiteSpace(info.SDNRTCode))
  67. {
  68. sql += " and a.cDLCode='{0}'";
  69. }
  70. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  71. {
  72. sql += " and ISNULL(a.dnmodifytime ,ISNULL(a.dverifydate , ISNULL(a.dnmodifytime , a.dcreatesystime )))>='{1}'";
  73. }
  74. if (!string.IsNullOrWhiteSpace(info.User))
  75. {
  76. sql += "and a.CMAKER='{2}'";
  77. }
  78. sql = string.Format(sql, info.SDNRTCode, info.MTime, userInfo.UserName);
  79. dt = DBHelper.SQlReturnData(sql, cmd);
  80. if (dt.Rows.Count <= 0 || dt == null)
  81. throw new Exception("销售发货单号:" + info.SDNRTCode + ",无信息!");
  82. if (dtNew == null)
  83. dtNew = dt;
  84. else
  85. dtNew.Merge(dt);
  86. }
  87. cmd.Transaction.Commit();
  88. }
  89. catch (Exception ex)
  90. {
  91. if (cmd.Transaction != null)
  92. cmd.Transaction.Rollback();
  93. log.Error(ex.Message);
  94. throw new Exception(ex.Message);
  95. }
  96. finally
  97. {
  98. if (conn.State == ConnectionState.Open)
  99. {
  100. conn.Close();
  101. }
  102. conn.Dispose();
  103. }
  104. }
  105. json = JsonConvert.SerializeObject(dtNew);
  106. return json;
  107. }
  108. }
  109. }