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

309 lines
12 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 PreSellApp
  13. {
  14. private IICSProductRepository servicePro = new MaintainRepository();
  15. private IICSProductPreSellRepository service = new PreSellRepository();
  16. private IICSProductPreSellDetailRepository serviceD = new PreSellDetailRepository();
  17. public List<ICSProductPreSellEntity> GetList(string keyword = "")
  18. {
  19. string username = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  20. string userID = NFine.Code.OperatorProvider.Provider.GetCurrent().UserId;
  21. string location = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  22. var expression = ExtLinq.True<ICSProductPreSellEntity>();
  23. if (!string.IsNullOrEmpty(keyword))
  24. {
  25. expression = expression.And(t => t.PreSellNo.Contains(keyword));
  26. }
  27. if (username != "超级管理员")
  28. {
  29. expression = expression.And(t => t.F_CreatorUserId == userID);
  30. expression = expression.And(t => t.F_Location == location);
  31. }
  32. return service.IQueryable(expression).OrderBy(t => t.PreSellNo).ToList();
  33. }
  34. public List<ICSProductPreSellEntity> GetListZS(Pagination pagination, string keyword, string keyword2)
  35. {
  36. string username = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  37. string userID = NFine.Code.OperatorProvider.Provider.GetCurrent().UserId;
  38. string location = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  39. var expression = ExtLinq.True<ICSProductPreSellEntity>();
  40. if (!string.IsNullOrEmpty(keyword))
  41. {
  42. expression = expression.And(t => t.PreSellNo.Contains(keyword));
  43. }
  44. if (!string.IsNullOrEmpty(keyword2))
  45. {
  46. expression = expression.And(t => t.CustomerName.Contains(keyword2));
  47. }
  48. if (username != "超级管理员")
  49. {
  50. expression = expression.And(t => t.F_CreatorUserId == userID);
  51. expression = expression.And(t => t.F_Location == location);
  52. }
  53. return service.FindList(expression, pagination);
  54. }
  55. public ICSProductPreSellEntity GetForm(string keyValue)
  56. {
  57. return service.FindEntity(keyValue);
  58. }
  59. public void DeleteForm(string keyValue)
  60. {
  61. service.Delete(t => t.F_Id == keyValue);
  62. }
  63. public void SubmitForm(List<ICSProductEntity> productList, ICSProductPreSellEntity ppsEntity, List<ICSProductPreSellDetailEntity> ppsdList)
  64. {
  65. if (ppsdList.Count <= 0)
  66. throw new Exception("Please select the product you want to buy");
  67. if (productList.Count >= 2)
  68. {
  69. ICSProductEntity model = productList[0];
  70. for (int i = 0; i < productList.Count; i++)
  71. {
  72. if (i != 0)
  73. {
  74. if (model.Other != productList[i].Other)
  75. {
  76. throw new Exception("Orders can only choose one type of diamond(Rough/Polished).");
  77. }
  78. }
  79. }
  80. }
  81. string sql = @"SELECT TOP 1 c.ProductSN,c.Other FROM ICSProductPreSellDetail a
  82. LEFT JOIN ICSProductPreSell b ON a.PreSell_Id = b.F_Id
  83. LEFT JOIN ICSProduct c ON c.F_Id = a.Product_Id
  84. WHERE b.F_Id = '{0}'
  85. ORDER BY a.PreSellTime";
  86. sql = string.Format(sql, ppsdList[0].PreSell_Id);
  87. DataTable d = SqlHelper.GetDataTableBySql(sql);
  88. if (d != null && d.Rows.Count > 0)
  89. {
  90. string other = d.Rows[0]["Other"].ToString();
  91. if (!string.IsNullOrEmpty(other))
  92. {
  93. foreach (ICSProductEntity item in productList)
  94. {
  95. if (other != item.Other)
  96. {
  97. throw new Exception("Orders can only choose one type of diamond(Rough/Polished).");
  98. }
  99. }
  100. }
  101. }
  102. if (ppsEntity != null)
  103. {
  104. if (ppsEntity.PreSellNo.Length <= 0)
  105. {
  106. throw new Exception("New order number can not be empty");
  107. }
  108. else
  109. {
  110. string strSql = @"SELECT PreSellNo FROM ICSProductPreSell WHERE PreSellNo = '{0}'";
  111. strSql = string.Format(strSql, ppsEntity.PreSellNo);
  112. DataTable dt = SqlHelper.GetDataTableBySql(strSql);
  113. if (dt != null && dt.Rows.Count > 0)
  114. {
  115. //if (!string.IsNullOrEmpty(dt.Rows[0]["PreSellNo"].ToString()))
  116. //{
  117. throw new Exception("Order number already exists");
  118. //}
  119. //else
  120. //{
  121. // service.Insert(ppsEntity);
  122. //}
  123. }
  124. else
  125. {
  126. service.Insert(ppsEntity);
  127. }
  128. }
  129. }
  130. foreach (ICSProductPreSellDetailEntity model in ppsdList)
  131. {
  132. string strSql = @"SELECT * FROM ICSProductPreSellDetail
  133. WHERE PreSell_Id = '{0}' AND Product_Id = '{1}'";
  134. strSql = string.Format(strSql, model.PreSell_Id, model.Product_Id);
  135. DataTable dt = SqlHelper.GetDataTableBySql(strSql);
  136. if (dt != null && dt.Rows.Count > 0)
  137. {
  138. throw new Exception("Data already exists");
  139. }
  140. else
  141. {
  142. model.Create();
  143. serviceD.Insert(model);
  144. }
  145. }
  146. foreach (ICSProductEntity model in productList)
  147. {
  148. model.Modify(model.F_Id);
  149. servicePro.Update(model);
  150. }
  151. }
  152. public void UpdateForm(ICSProductPreSellEntity ppsEntity)
  153. {
  154. service.Update(ppsEntity);
  155. }
  156. public void UpdateForm(List<ICSProductPreSellEntity> ppsList, List<ICSProductEntity> productList, string preSellId)
  157. {
  158. //if (ppsList.Count <= 0)
  159. //{
  160. // throw new Exception("No order, please choose the order first.");
  161. //}
  162. //if (productList.Count <= 0)
  163. //{
  164. // throw new Exception("There is no product information in the order and it cannot be confirmed.");
  165. //}
  166. //foreach (ICSProductPreSellEntity entity in ppsList)
  167. //{
  168. // service.Update(entity);
  169. //}
  170. //foreach (ICSProductEntity model in productList)
  171. //{
  172. // model.Modify(model.F_Id);
  173. // servicePro.Update(model);
  174. //}
  175. //string sql = @"DELETE FROM ICSProductPreSellDetail WHERE F_Id IN
  176. // (
  177. // SELECT b.F_Id FROM ICSProductPreSell a
  178. // LEFT JOIN ICSProductPreSellDetail b ON a.F_Id = b.PreSell_Id
  179. // WHERE b.PreSell_Id <> '{0}' AND b.Product_SN IN
  180. // (
  181. // SELECT b.Product_SN FROM ICSProductPreSell a
  182. // LEFT JOIN ICSProductPreSellDetail b ON a.F_Id = b.PreSell_Id
  183. // WHERE b.PreSell_Id = '{0}'
  184. // )
  185. // )";
  186. //sql = string.Format(sql, preSellId);
  187. //DbHelper.ExecuteSqlCommand(sql);
  188. }
  189. public void UpdateFormC(List<ICSProductPreSellEntity> ppsList, List<ICSProductEntity> productList)
  190. {
  191. if (ppsList.Count <= 0)
  192. {
  193. throw new Exception("No order, please choose the order first.");
  194. }
  195. if (productList.Count <= 0)
  196. {
  197. throw new Exception("There is no product information in the order and it cannot be confirmed.");
  198. }
  199. foreach (ICSProductPreSellEntity entity in ppsList)
  200. {
  201. service.Update(entity);
  202. }
  203. foreach (ICSProductEntity model in productList)
  204. {
  205. model.Modify(model.F_Id);
  206. servicePro.Update(model);
  207. }
  208. }
  209. public string GetExpiredDays(string typeName)
  210. {
  211. string ExpiredDays = "0";
  212. string sql = @"SELECT a.F_ItemCode FROM Sys_ItemsDetail a
  213. LEFT JOIN Sys_Items b ON a.F_ItemId = b.F_Id
  214. WHERE b.F_EnCode = '{0}'";
  215. sql = string.Format(sql, typeName);
  216. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  217. if (dt != null && dt.Rows.Count > 0)
  218. ExpiredDays = dt.Rows[0]["F_ItemCode"].ToString();
  219. return ExpiredDays;
  220. }
  221. public string GetPreSellNo(string presellDetialID)
  222. {
  223. string PreSellNo = string.Empty;
  224. string sql = @"SELECT a.PreSellNo
  225. FROM ICSProductPreSell a
  226. LEFT JOIN ICSProductPreSellDetail b ON a.F_Id = b.PreSell_Id
  227. WHERE b.F_Id='{0}'";
  228. sql = string.Format(sql, presellDetialID);
  229. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  230. if (dt != null && dt.Rows.Count > 0)
  231. PreSellNo = dt.Rows[0]["PreSellNo"].ToString();
  232. return PreSellNo;
  233. //return service.IQueryable(expression).OrderBy(t => t.PreSellTime).ToList();
  234. }
  235. public List<string> GetProductID(string preSellId)
  236. {
  237. List<string> PIDs = null;
  238. string sql = @"SELECT c.F_Id FROM ICSProductPreSell a
  239. LEFT JOIN ICSProductPreSellDetail b ON a.F_Id = b.PreSell_Id
  240. LEFT JOIN ICSProduct c ON b.Product_SN = c.ProductSN
  241. WHERE a.F_Id = '{0}'";
  242. sql = string.Format(sql, preSellId);
  243. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  244. if (dt != null && dt.Rows.Count > 0)
  245. {
  246. PIDs = new List<string>();
  247. foreach (DataRow row in dt.Rows)
  248. {
  249. string pid = row["F_Id"].ToString();
  250. PIDs.Add(pid);
  251. }
  252. }
  253. return PIDs;
  254. }
  255. public string GetOrderNo(string orderNoHead)
  256. {
  257. string sql = @"SELECT * FROM ICSProductPreSell WHERE PreSellNo LIKE '{0}%'";
  258. sql = string.Format(sql, orderNoHead);
  259. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  260. if (dt != null && dt.Rows.Count > 0)
  261. return dt.Rows[0]["PreSellNo"].ToString();
  262. else
  263. return "";
  264. }
  265. public DataTable GetSOMain(string keyword)
  266. {
  267. if (NFine.Code.OperatorProvider.Provider.GetCurrent().UserName == "超级管理员"
  268. || (NFine.Code.OperatorProvider.Provider.GetCurrent().UserName != "超级管理员" &&
  269. NFine.Code.OperatorProvider.Provider.GetCurrent().Location.ToUpper() == "SH")
  270. )
  271. {
  272. DataTable dt = new DataTable();
  273. string sql = @"SELECT cSOCode,dDate,cBusType,cSTName,cCusName,cDepName,iTaxRate,cexch_name,iExchRate,cMemo
  274. FROM WMS_ZHENGSHI.dbo.SO_SOMain WHERE 1=1";
  275. if (!string.IsNullOrEmpty(keyword))
  276. {
  277. sql = sql + " AND cSOCode = '{0}'";
  278. sql = string.Format(sql, keyword);
  279. }
  280. dt = SqlHelper.GetDataTableBySql(sql);
  281. return dt;
  282. }
  283. else
  284. return null;
  285. }
  286. }
  287. }