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

105 lines
4.2 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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 MOIssueApplyDoc
  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<ICSMaterialAppVouch> infos)
  23. {
  24. List<ICSMaterialAppVouch> szJson = new List<ICSMaterialAppVouch>();
  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 (ICSMaterialAppVouch 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";
  56. if (!string.IsNullOrWhiteSpace(info.MOApplyCode))
  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.MOApplyCode, info.MTime, info.User);
  69. dt = DBHelper.SQlReturnData(sql, cmd);
  70. if (dt.Rows.Count <= 0 || dt == null)
  71. throw new Exception(":" + info.MOApplyCode + ",无信息!");
  72. if (dtNew == null)
  73. dtNew = dt;
  74. else
  75. dtNew.Merge(dt);
  76. cmd.Transaction.Commit();
  77. }
  78. catch (Exception ex)
  79. {
  80. cmd.Transaction.Rollback();
  81. log.Error(ex.Message);
  82. throw new Exception(ex.Message);
  83. }
  84. finally
  85. {
  86. if (conn.State == ConnectionState.Open)
  87. {
  88. conn.Close();
  89. }
  90. conn.Dispose();
  91. }
  92. }
  93. json = JsonConvert.SerializeObject(dtNew);
  94. return json;
  95. }
  96. }
  97. }