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

94 lines
3.8 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. 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. string json = "";
  29. if (infos.Count <= 0)
  30. {
  31. throw new Exception("传送数据为空!");
  32. }
  33. string res = string.Empty;
  34. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  35. conn.Open();
  36. SqlTransaction sqlTran = conn.BeginTransaction();
  37. SqlCommand cmd = new SqlCommand();
  38. cmd.Transaction = sqlTran;
  39. cmd.Connection = conn;
  40. try
  41. {
  42. string sql = string.Empty;
  43. foreach (ICSSalesReturnBack info in infos)
  44. {
  45. if (info.MTime < new DateTime(2000, 01, 01))
  46. throw new Exception("请输入正确的操作时间:" + info.MTime);
  47. sql = @" select a.DLID ,a.cDLCode ,a.cCusCode,c.cCusName,a.cDepCode ,
  48. d.cDepName,b.cordercode ,a.cMaker ,a.dcreatesystime ,
  49. b.AutoID ,b.irowno,b.cInvCode ,b.iQuantity ,b.iNum ,b.iSOsID
  50. FROM dbo.DispatchList a
  51. INNER JOIN dbo.DispatchLists b ON a.DLID = b.DLID
  52. LEFT JOIN dbo.Customer c ON a.cCusCode = c.cCusCode
  53. left join Department d on a.cDepCode=d.cDepCode where b.iQuantity<0";
  54. if (!string.IsNullOrWhiteSpace(info.SDNRTCode))
  55. {
  56. sql += " and a.cDLCode='{0}'";
  57. }
  58. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  59. {
  60. sql += " and ISNULL(a.dnmodifytime ,ISNULL(a.dverifydate , ISNULL(a.dnmodifytime , a.dcreatesystime )))>='{1}'";
  61. }
  62. if (!string.IsNullOrWhiteSpace(info.User))
  63. {
  64. sql += "and a.CMAKER='{2}'";
  65. }
  66. sql = string.Format(sql, info.SDNRTCode, info.MTime, info.User);
  67. dt = DBHelper.SQlReturnData(sql, cmd);
  68. if (dt.Rows.Count <= 0 || dt == null)
  69. throw new Exception("销售发货单号:" + info.SDNRTCode + ",无信息!");
  70. json = JsonConvert.SerializeObject(dt);
  71. }
  72. cmd.Transaction.Commit();
  73. return json;
  74. }
  75. catch (Exception ex)
  76. {
  77. cmd.Transaction.Rollback();
  78. log.Error(ex.Message);
  79. throw new Exception(ex.Message);
  80. }
  81. finally
  82. {
  83. if (conn.State == ConnectionState.Open)
  84. {
  85. conn.Close();
  86. }
  87. conn.Dispose();
  88. }
  89. }
  90. }
  91. }