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

101 lines
4.1 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 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. /// <summary>
  14. /// 委外采购退货单
  15. /// </summary>
  16. public class OutsourcingReturnBack
  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<ICSOutsourcingReturnBack> infos)
  23. {
  24. List<ICSOutsourcingReturnBack> szJson = new List<ICSOutsourcingReturnBack>();
  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. foreach (ICSOutsourcingReturnBack info in infos)
  38. {
  39. try
  40. {
  41. connS = string.Format(connString, info.WorkPoint);
  42. conn = new System.Data.SqlClient.SqlConnection(connS);
  43. conn.Open();
  44. SqlTransaction sqlTran = conn.BeginTransaction();
  45. cmd = new SqlCommand();
  46. cmd.Transaction = sqlTran;
  47. cmd.Connection = conn;
  48. if (info.MTime < new DateTime(2000, 01, 01))
  49. throw new Exception("请输入正确的操作时间:" + info.MTime);
  50. 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,
  51. B.Autoid,B.irowno ,B.cInvCode ,B.INUM,B.iQuantity,B.fValidInQuan,B.iPOsID
  52. FROM PU_ArrivalVouch A
  53. INNER JOIN PU_ArrivalVouchs B ON A.ID=B.ID
  54. INNER JOIN DEPARTMENT C ON A.CDEPCODE=C.CDEPCODE
  55. INNER JOIN VENDOR D ON A.CVENCODE=D.CVENCODE WHERE 1=1 and iQuantity<0 and A.cBusType=''";
  56. if (!string.IsNullOrWhiteSpace(info.ODNRTCode))
  57. {
  58. sql += " and a.cCode='{0}'";
  59. }
  60. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  61. {
  62. sql += " and ISNULL(a.cModifyTime,ISNULL(a.cAuditTime, ISNULL(a.cModifyTime, a.cmaketime)))>='{1}'";
  63. }
  64. if (!string.IsNullOrWhiteSpace(info.User))
  65. {
  66. sql += "and a.CMAKER='{2}'";
  67. }
  68. sql = string.Format(sql, info.ODNRTCode, info.MTime, info.User);
  69. dt = DBHelper.SQlReturnData(sql, cmd);
  70. if (dt.Rows.Count <= 0 || dt == null)
  71. throw new Exception("委外采购退货单:" + info.ODNRTCode + ",无信息!");
  72. dtNew.Merge(dt);
  73. cmd.Transaction.Commit();
  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. json = JsonConvert.SerializeObject(dtNew);
  91. return json;
  92. }
  93. }
  94. }