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

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