纽威
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.5 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. string json = "";
  26. if (infos.Count <= 0)
  27. {
  28. throw new Exception("传送数据为空!");
  29. }
  30. string res = string.Empty;
  31. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  32. conn.Open();
  33. SqlTransaction sqlTran = conn.BeginTransaction();
  34. SqlCommand cmd = new SqlCommand();
  35. cmd.Transaction = sqlTran;
  36. cmd.Connection = conn;
  37. try
  38. {
  39. string sql = string.Empty;
  40. foreach (ICSOutsourcingOrder info in infos)
  41. {
  42. if (info.MTime < new DateTime(2000, 01, 01))
  43. throw new Exception("请输入正确的操作时间:" + info.MTime);
  44. sql = @" select a.MOID,b.iVouchRowNo ,b.cInvCode,b.iQuantity,c.ID,
  45. c.iopseq ,c.cInvCode,c.iQuantity,c.cWhCode,d.cWhName
  46. FROM dbo.OM_MOMain a
  47. INNER JOIN dbo.OM_MODetails b ON a.MOID=b.MOID
  48. left join MaterialAppVouchs c on b.MODetailsID =c.iOMoDID
  49. left join Warehouse d on c.cWhCode=d.cWhCode ";
  50. if (!string.IsNullOrWhiteSpace(info.OOCode))
  51. {
  52. sql += " and a.cCode='{0}'";
  53. }
  54. if (!string.IsNullOrWhiteSpace(info.MTime.ToString()))
  55. {
  56. sql += " and ISNULL(a.cModifyTime,ISNULL(a.cAuditTime, ISNULL(a.cModifyTime, a.cmaketime)))>='{2}'";
  57. }
  58. if (!string.IsNullOrWhiteSpace(info.User))
  59. {
  60. sql += "and a.CMAKER='{3}'";
  61. }
  62. sql = string.Format(sql, info.OOCode, info.MTime, info.User);
  63. dt = DBHelper.SQlReturnData(sql, cmd);
  64. if (dt.Rows.Count <= 0 || dt == null)
  65. throw new Exception("委外订单号:" + info.OOCode + ",无信息!");
  66. json = JsonConvert.SerializeObject(dt);
  67. }
  68. cmd.Transaction.Commit();
  69. return json;
  70. }
  71. catch (Exception ex)
  72. {
  73. cmd.Transaction.Rollback();
  74. log.Error(ex.Message);
  75. throw new Exception(ex.Message);
  76. }
  77. finally
  78. {
  79. if (conn.State == ConnectionState.Open)
  80. {
  81. conn.Close();
  82. }
  83. conn.Dispose();
  84. }
  85. }
  86. }
  87. }