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

112 lines
4.8 KiB

3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 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 OutsourcingOrderPick
  14. {
  15. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  16. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
  17. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  18. public string Get(List<ICSOutsourcingOrderPick> infos)
  19. {
  20. List<ICSOutsourcingOrderPick> szJson = new List<ICSOutsourcingOrderPick>();
  21. DataTable dt = null;
  22. DataTable dtNew = null;
  23. string connS = "";
  24. string json = "";
  25. if (infos.Count <= 0)
  26. {
  27. throw new Exception("传送数据为空!");
  28. }
  29. string res = string.Empty;
  30. SqlConnection conn = new SqlConnection();
  31. SqlCommand cmd = new SqlCommand();
  32. string sql = string.Empty;
  33. List<string> result = infos.Select(t => t.WorkPoint).Distinct().ToList();
  34. foreach (string WorkPoint in result)
  35. {
  36. try
  37. {
  38. connS = string.Format(connString, WorkPoint);
  39. conn = new System.Data.SqlClient.SqlConnection(connS);
  40. conn.Open();
  41. SqlTransaction sqlTran = conn.BeginTransaction();
  42. cmd = new SqlCommand();
  43. cmd.Transaction = sqlTran;
  44. cmd.Connection = conn;
  45. foreach (ICSOutsourcingOrderPick info in infos)
  46. {
  47. if (WorkPoint != info.WorkPoint)
  48. continue;
  49. ICSUserInfo userInfo = new ICSUserInfo();
  50. userInfo = DBHelper.GetPersonInfo(info.User, cmd);
  51. if (info.MTime < new DateTime(2000, 01, 01))
  52. throw new Exception("请输入正确的操作时间:" + info.MTime);
  53. sql = @" SELECT a.MOID,a.cCode,a.cDepCode,e.cDepName, a.csrccode ,a.cMaker ,a.dCreateTime,a.cVerifier ,a.dVerifyTime
  54. ,b.MODetailsID ODetailsID ,b.iVouchRowNo ,b.cInvCode ,b.iQuantity ,b.iArrQTY ,b.dArriveDate ,b.iTaxPrice ,d.AutoID
  55. FROM dbo.OM_MOMain a
  56. INNER JOIN dbo.OM_MODetails b ON a.MOID=b.MOID
  57. left join PU_AppVouch c on a.csrccode=c.cCode
  58. left join PU_AppVouchs d on c.ID =d.ID
  59. left join Department e on a.cDepCode =e.cDepCode ";
  60. if (!string.IsNullOrWhiteSpace(info.OOCode))
  61. {
  62. sql += " and a.cCode='{0}'";
  63. }
  64. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  65. {
  66. sql += " and ISNULL(a.cModifyTime,ISNULL(a.cAuditTime, ISNULL(a.cModifyTime, a.cmaketime)))>='{2}'";
  67. }
  68. if (!string.IsNullOrWhiteSpace(info.User))
  69. {
  70. sql += "and a.CMAKER='{3}'";
  71. }
  72. sql = string.Format(sql, info.OOCode, info.MTime, userInfo.UserName);
  73. dt = DBHelper.SQlReturnData(sql, cmd);
  74. if (dt.Rows.Count <= 0 || dt == null)
  75. throw new Exception("委外订单号:" + info.OOCode + ",无信息!");
  76. if (dtNew == null)
  77. dtNew = dt;
  78. else
  79. dtNew.Merge(dt);
  80. }
  81. cmd.Transaction.Commit();
  82. }
  83. catch (Exception ex)
  84. {
  85. if (cmd.Transaction != null)
  86. cmd.Transaction.Rollback();
  87. log.Error(ex.Message);
  88. throw new Exception(ex.Message);
  89. }
  90. finally
  91. {
  92. if (conn.State == ConnectionState.Open)
  93. {
  94. conn.Close();
  95. }
  96. conn.Dispose();
  97. }
  98. }
  99. json = JsonConvert.SerializeObject(dtNew);
  100. return json;
  101. }
  102. }
  103. }