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

160 lines
9.3 KiB

3 years ago
  1. using NFine.Code;
  2. using NFine.Data.Extensions;
  3. using NFine.Domain.Entity.ProductManage;
  4. using NFine.Domain.IRepository.ProductManage;
  5. using NFine.Repository.ProductManage;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Linq;
  10. namespace NFine.Application.ProductManage
  11. {
  12. public class PreSellDetailApp
  13. {
  14. private IICSProductRepository servicePro = new MaintainRepository();
  15. //private IICSProductPreSellRepository service = new PreSellRepository();
  16. private IICSProductPreSellDetailRepository service = new PreSellDetailRepository();
  17. public List<ICSProductPreSellDetailEntity> GetList(string itemId, string keyword = "")
  18. {
  19. var expression = ExtLinq.True<ICSProductPreSellDetailEntity>();
  20. if (!string.IsNullOrEmpty(itemId))
  21. {
  22. expression = expression.And(t => t.PreSell_Id == itemId);
  23. }
  24. if (!string.IsNullOrEmpty(keyword))
  25. {
  26. expression = expression.And(t => t.Product_Id.Contains(keyword));
  27. }
  28. return service.IQueryable(expression).OrderBy(t => t.PreSellTime).ToList();
  29. }
  30. public DataTable GetList2(string itemId, string keyword)
  31. {
  32. DataTable dt = new DataTable();
  33. #region
  34. //string sql = @"SELECT DISTINCT a.F_Id,a.Product_Id,c.ProductSN,a.PreSellTime,c.Weight,c.GrossWeight,c.Measurement,c.Shape,
  35. // c.CertificateNo,(case when c.WHCode ='12' then '评估仓' when c.WHCode ='10' then '成品仓' else '' end ) as WHCodes,
  36. // (CASE WHEN c.WHCode = '10' THEN c.Price WHEN c.WHCode = '12' THEN c.BasePrice ELSE 0 END ) AS RapaPrice,
  37. // (CASE WHEN c.WHCode = '10' THEN c.Price WHEN c.WHCode = '12' THEN c.Weight*c.BasePrice ELSE 0 END ) AS Price,
  38. // (CAST((e.Discount*100) AS VARCHAR(50))+'%') AS Discount,
  39. // (CASE WHEN c.WHCode = '10' THEN c.Price*e.Discount
  40. // WHEN c.WHCode = '12' THEN c.Weight*c.BasePrice*(1+e.Discount) ELSE 0 END ) AS Amount,
  41. // c.Location,c.Other
  42. // FROM ICSProductPreSellDetail a
  43. // LEFT JOIN ICSProductPreSell b ON a.PreSell_Id = b.F_Id
  44. // LEFT JOIN ICSProduct c ON a.Product_Id = c.F_Id
  45. // LEFT JOIN Sys_Customer d ON b.CustomerId = d.F_Id
  46. // LEFT JOIN WMS_ZHENGSHI.dbo.ICSPriceRule e ON d.F_CusCode = e.CusCode AND c.WHCode = e.cWHType
  47. // AND (c.Weight >= e.StartValue AND c.Weight <= e.EndValue)
  48. // WHERE b.F_Id = '{0}'";
  49. #endregion
  50. string sql = @"SELECT DISTINCT a.F_Id,a.Product_Id,c.ProductSN,a.PreSellTime,c.Weight,c.GrossWeight,c.Measurement,c.Shape,
  51. c.CertificateNo,(CASE WHEN c.WHCode ='12' THEN '' WHEN c.WHCode ='10' THEN '' ELSE '' END ) AS WHCodes,
  52. (CASE WHEN c.WHCode = '10' THEN c.Price WHEN c.WHCode = '12' THEN f.Discount ELSE 0 END ) AS RapaPrice,
  53. (CASE WHEN c.WHCode = '10' THEN c.Price WHEN c.WHCode = '12' THEN c.Weight*f.Discount ELSE 0 END ) AS Price,
  54. (CAST((e.Discount*100) AS VARCHAR(50))+'%') AS Discount,
  55. (CASE WHEN c.WHCode = '10' THEN c.Price*e.Discount
  56. WHEN c.WHCode = '12' THEN c.Weight*c.BasePrice*(1+e.Discount) ELSE 0 END ) AS Amount,
  57. c.Location,c.Other,f.Discount
  58. FROM ICSProductPreSellDetail a
  59. LEFT JOIN ICSProductPreSell b ON a.PreSell_Id = b.F_Id
  60. LEFT JOIN ICSProduct c ON a.Product_Id = c.F_Id
  61. LEFT JOIN Sys_Customer d ON b.CustomerId = d.F_Id
  62. LEFT JOIN ICSDiscountRate e ON d.F_CusCode = e.CusCode AND c.WHCode = e.WHType
  63. AND (c.Weight >= e.StartValue AND c.Weight <= e.EndValue) AND e.CusCode <> 'RapaPort'
  64. LEFT JOIN (SELECT x.Discount,x.WHType,x.StartValue,x.EndValue FROM ICSDiscountRate x WHERE x.CusCode = 'RapaPort' ) f
  65. ON f.WHType= c.WHCode AND (c.Weight >= f.StartValue AND c.Weight <= f.EndValue)
  66. WHERE b.F_Id = '{0}'";
  67. sql = string.Format(sql, itemId);
  68. if (!string.IsNullOrEmpty(keyword))
  69. {
  70. sql = sql + " AND c.ProductSN LIKE '%{0}%' ";
  71. sql = string.Format(sql, keyword);
  72. }
  73. dt = SqlHelper.GetDataTableBySql(sql);
  74. if (dt == null || dt.Rows.Count <= 0)
  75. throw new Exception("No exportable data.");
  76. return dt;
  77. //return DbHelper.GetDataTable(sql);
  78. }
  79. public DataTable GetListForWebService(string idList)
  80. {
  81. DataTable dt = new DataTable();
  82. string sql = @"SELECT DISTINCT b.PreSellNo,d.F_CusCode,c.ProductSN,g.F_Account AS UserCode,
  83. (CASE WHEN c.WHCode = '10' THEN c.Price WHEN c.WHCode = '12' THEN f.Discount ELSE 0 END ) AS RapaPrice,
  84. (CASE WHEN c.WHCode = '10' THEN c.Price WHEN c.WHCode = '12' THEN c.Weight*f.Discount ELSE 0 END ) AS Price,
  85. (CAST((e.Discount*100) AS VARCHAR(50))+'%') AS Discount,
  86. (CASE WHEN c.WHCode = '10' THEN c.Price*e.Discount
  87. WHEN c.WHCode = '12' THEN c.Weight*c.BasePrice*(1+e.Discount) ELSE 0 END ) AS Amount
  88. FROM ICSProductPreSellDetail a
  89. LEFT JOIN ICSProductPreSell b ON a.PreSell_Id = b.F_Id
  90. LEFT JOIN ICSProduct c ON a.Product_Id = c.F_Id
  91. LEFT JOIN Sys_Customer d ON b.CustomerId = d.F_Id
  92. LEFT JOIN ICSDiscountRate e ON d.F_CusCode = e.CusCode AND c.WHCode = e.WHType
  93. AND (c.Weight >= e.StartValue AND c.Weight <= e.EndValue) AND e.CusCode <> 'RapaPort'
  94. LEFT JOIN (SELECT x.Discount,x.WHType,x.StartValue,x.EndValue FROM ICSDiscountRate x WHERE x.CusCode = 'RapaPort' ) f
  95. ON f.WHType= c.WHCode AND (c.Weight >= f.StartValue AND c.Weight <= f.EndValue)
  96. LEFT JOIN Sys_User g ON g.F_Id = b.F_CreatorUserId
  97. WHERE b.F_Id IN ({0})";
  98. sql = string.Format(sql, idList);
  99. dt = SqlHelper.GetDataTableBySql(sql);
  100. return dt;
  101. }
  102. public ICSProductPreSellDetailEntity GetForm(string keyValue)
  103. {
  104. return service.FindEntity(keyValue);
  105. }
  106. public void DeleteForm(string[] keyValues, List<ICSProductEntity> entityList)
  107. {
  108. foreach (string keyValue in keyValues)
  109. {
  110. string sql = @"SELECT b.IsConfirm FROM ICSProductPreSellDetail a
  111. LEFT JOIN ICSProductPreSell b ON a.PreSell_Id = b.F_Id
  112. WHERE a.F_Id='{0}'";
  113. sql = string.Format(sql, keyValue);
  114. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  115. if (dt != null && dt.Rows.Count > 0)
  116. {
  117. if (!string.IsNullOrEmpty(dt.Rows[0][0].ToString()))
  118. {
  119. bool isConfirm = bool.Parse(dt.Rows[0][0].ToString());
  120. if (isConfirm)
  121. {
  122. throw new Exception("Confirmed order cannot be cancelled.");
  123. }
  124. }
  125. }
  126. service.Delete(t => t.F_Id == keyValue);
  127. }
  128. foreach (ICSProductEntity model in entityList)
  129. {
  130. model.Modify(model.F_Id);
  131. servicePro.Update(model);
  132. }
  133. }
  134. public DataTable GetSODetails(string keyword)
  135. {
  136. DataTable dt = new DataTable();
  137. string sql = @"SELECT a.AutoID,a.cInvCode,b.Measurement,a.cInvCName,b.Weight,b.GrossWeight,
  138. (CASE a.bgift WHEN '0' THEN '否' ELSE '是' END) AS ,b.Price,a.iMoney,a.iTax,a.iSum,a.iDisCount,
  139. 100.00 AS ,a.iNatSum,c.cInvDefine1 AS Color,c.cInvDefine3 AS Clarity,100.00 AS 2,
  140. c.cInvDefine2 AS Shape,a.cMemo,c.cInvDefine4 AS Cut,c.cInvDefine5 AS Polish,c.cInvDefine6 AS Symmetry,
  141. c.cInvDefine10 AS Discount,c.cInvDefine11 AS Rapport,a.cFree1 AS zColor,a.cFree2 AS zShape,
  142. a.cFree3 AS zClarity,a.cFree4 AS zDiscount,a.cFree5 AS zPolish,a.cFree6 AS zRapport,
  143. a.cFree7 AS zRoughWeight,a.cFree8 AS zFinishedWeight,a.cFree9 AS zPrice,a.cFree10 AS zSize
  144. FROM WMS_ZHENGSHI.dbo.SO_SODetails a
  145. LEFT JOIN WMS_ZHENGSHI.dbo.ICSProduct b ON a.cInvCode = b.ProductSN
  146. LEFT JOIN WMS_ZHENGSHI.dbo.Inventory c ON c.cInvCode = a.cInvCode
  147. WHERE a.cSOCode = '{0}'";
  148. sql = string.Format(sql, keyword);
  149. dt = SqlHelper.GetDataTableBySql(sql);
  150. return dt;
  151. }
  152. }
  153. }