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

90 lines
3.7 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 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. string json = "";
  27. if (infos.Count <= 0)
  28. {
  29. throw new Exception("传送数据为空!");
  30. }
  31. string res = string.Empty;
  32. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  33. conn.Open();
  34. SqlTransaction sqlTran = conn.BeginTransaction();
  35. SqlCommand cmd = new SqlCommand();
  36. cmd.Transaction = sqlTran;
  37. cmd.Connection = conn;
  38. try
  39. {
  40. string sql = string.Empty;
  41. foreach (ICSOutsourcingReturnBack info in infos)
  42. {
  43. if (info.MTime < new DateTime(2000, 01, 01))
  44. throw new Exception("请输入正确的操作时间:" + info.MTime);
  45. 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,
  46. B.Autoid,B.irowno ,B.cInvCode ,B.INUM,B.iQuantity,B.fValidInQuan,B.iPOsID
  47. FROM PU_ArrivalVouch A
  48. INNER JOIN PU_ArrivalVouchs B ON A.ID=B.ID
  49. INNER JOIN DEPARTMENT C ON A.CDEPCODE=C.CDEPCODE
  50. INNER JOIN VENDOR D ON A.CVENCODE=D.CVENCODE WHERE 1=1 and iQuantity<0 and A.cBusType=''";
  51. if (!string.IsNullOrWhiteSpace(info.ODNRTCode))
  52. {
  53. sql += " and a.cCode='{0}'";
  54. }
  55. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  56. {
  57. sql += " and ISNULL(a.cModifyTime,ISNULL(a.cAuditTime, ISNULL(a.cModifyTime, a.cmaketime)))>='{1}'";
  58. }
  59. if (!string.IsNullOrWhiteSpace(info.User))
  60. {
  61. sql += "and a.CMAKER='{2}'";
  62. }
  63. sql = string.Format(sql, info.ODNRTCode, info.MTime, info.User);
  64. dt = DBHelper.SQlReturnData(sql, cmd);
  65. if (dt.Rows.Count <= 0 || dt == null)
  66. throw new Exception("委外采购退货单:" + info.ODNRTCode + ",无信息!");
  67. json = JsonConvert.SerializeObject(dt);
  68. }
  69. cmd.Transaction.Commit();
  70. return json;
  71. }
  72. catch (Exception ex)
  73. {
  74. cmd.Transaction.Rollback();
  75. log.Error(ex.Message);
  76. throw new Exception(ex.Message);
  77. }
  78. finally
  79. {
  80. if (conn.State == ConnectionState.Open)
  81. {
  82. conn.Close();
  83. }
  84. conn.Dispose();
  85. }
  86. }
  87. }
  88. }