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

453 lines
18 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 MaintainApp
  13. {
  14. private IICSProductRepository service = new MaintainRepository();
  15. public List<ICSProductEntity> GetList(Pagination pagination, string queryJson)
  16. {
  17. var expression = ExtLinq.True<ICSProductEntity>();
  18. var queryParam = queryJson.ToJObject();
  19. if (!queryParam["keyword"].IsEmpty())
  20. {
  21. string keyword = queryParam["keyword"].ToString();
  22. expression = expression.And(t => t.ProductSN.Contains(keyword));
  23. }
  24. if (!queryParam["warehouse"].IsEmpty())
  25. {
  26. string warehouse = queryParam["warehouse"].ToString();
  27. switch (warehouse)
  28. {
  29. case "0": break;
  30. case "10":
  31. case "12":
  32. case "18":
  33. expression = expression.And(t => t.WhCode == warehouse);
  34. break;
  35. default:
  36. break;
  37. }
  38. }
  39. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleFullName == "客户")
  40. {
  41. expression = expression.And(t => t.WhCode == "10");
  42. }
  43. //return service.IQueryable(expression).OrderBy(t => t.ProductSN).ToList();
  44. return service.FindList(expression, pagination).OrderBy(t => t.Weight).ToList();
  45. }
  46. public List<ICSProductEntity> GetList(string keyword = "", string keyword2 = "")
  47. {
  48. var expression = ExtLinq.True<ICSProductEntity>();
  49. if (!string.IsNullOrEmpty(keyword) && !string.IsNullOrEmpty(keyword2))
  50. {
  51. expression = expression.And(t => t.ProductSN.Contains(keyword));
  52. expression = expression.And(t => t.ProductSN.Contains(keyword2));
  53. }
  54. return service.IQueryable(expression).OrderBy(t => t.ProductSN).ToList();
  55. }
  56. public DataTable GetList2(string invIDs)
  57. {
  58. DataTable dt = new DataTable();
  59. string sql = @"SELECT F_Id,ProductSN,Measurement,Other AS Sort,Location,Price,
  60. CAST(InvQty AS INT) AS Qty,Weight AS FinishedWeight,GrossWeight AS RoughWeight,
  61. Shape,CertificateNo,Color,Clarity,Polish
  62. FROM ICSProduct WHERE F_Id IN ({0})";
  63. sql = string.Format(sql, invIDs);
  64. dt = SqlHelper.GetDataTableBySql(sql);
  65. if (dt == null || dt.Rows.Count <= 0)
  66. throw new Exception("No exportable data.");
  67. return dt;
  68. }
  69. public DataTable GetList2All()
  70. {
  71. DataTable dt = new DataTable();
  72. string sql = @"SELECT F_Id,ProductSN,Measurement,Other AS Sort,Location,Price,
  73. CAST(InvQty AS INT) AS Qty,Weight AS FinishedWeight,GrossWeight AS RoughWeight,
  74. Shape,CertificateNo,Color,Clarity,Polish,(case when WHCode ='12' then '' when WHCode ='10' then '' else '' end ) as WHCode
  75. FROM ICSProduct";
  76. dt = SqlHelper.GetDataTableBySql(sql);
  77. if (dt == null || dt.Rows.Count <= 0)
  78. throw new Exception("No exportable data.");
  79. return dt;
  80. }
  81. public List<ICSProductEntity> GetListPS(Pagination pagination, string queryJson)
  82. {
  83. var expression = ExtLinq.True<ICSProductEntity>();
  84. var queryParam = queryJson.ToJObject();
  85. if (!queryParam["weight"].IsEmpty())
  86. {
  87. string weight = queryParam["weight"].ToString();
  88. decimal start = 0;
  89. decimal end = 0;
  90. switch (weight)
  91. {
  92. case "0":
  93. break;
  94. case "1":
  95. start = decimal.Parse("0.5"); end = decimal.Parse("0.5");
  96. //expression = expression.And(t => t.Weight >= start && t.Weight <= end);
  97. expression = expression.And(t => t.Weight <= end);
  98. break;
  99. case "2":
  100. start = decimal.Parse("0.5"); end = decimal.Parse("0.69");
  101. expression = expression.And(t => t.Weight >= start && t.Weight <= end);
  102. break;
  103. case "3":
  104. start = decimal.Parse("07"); end = decimal.Parse("089");
  105. expression = expression.And(t => t.Weight >= start && t.Weight <= end);
  106. break;
  107. case "4":
  108. start = decimal.Parse("0.9"); end = decimal.Parse("0.99");
  109. expression = expression.And(t => t.Weight >= start && t.Weight <= end);
  110. break;
  111. case "5":
  112. start = decimal.Parse("1.0"); end = decimal.Parse("1.49");
  113. expression = expression.And(t => t.Weight >= start && t.Weight <= end);
  114. break;
  115. case "6":
  116. start = decimal.Parse("1.5"); end = decimal.Parse("1.99");
  117. expression = expression.And(t => t.Weight >= start && t.Weight <= end);
  118. break;
  119. case "7":
  120. start = decimal.Parse("2.0"); end = decimal.Parse("2.99");
  121. expression = expression.And(t => t.Weight >= start && t.Weight <= end);
  122. break;
  123. case "8":
  124. start = decimal.Parse("3.0"); end = decimal.Parse("3.99");
  125. expression = expression.And(t => t.Weight >= start && t.Weight <= end);
  126. break;
  127. case "9":
  128. start = decimal.Parse("4.0"); end = decimal.Parse("4.99");
  129. expression = expression.And(t => t.Weight >= start && t.Weight <= end);
  130. break;
  131. case "10":
  132. start = decimal.Parse("5.0"); end = decimal.Parse("5.99");
  133. expression = expression.And(t => t.Weight >= start && t.Weight <= end);
  134. break;
  135. default:
  136. break;
  137. }
  138. }
  139. if (!queryParam["shape"].IsEmpty())
  140. {
  141. string shape = queryParam["shape"].ToString();
  142. switch (shape)
  143. {
  144. case "0":
  145. break;
  146. case "1":
  147. expression = expression.And(t => t.Shape == "Round");
  148. break;
  149. case "2":
  150. expression = expression.And(t => t.Shape == "Pear");
  151. break;
  152. case "3":
  153. expression = expression.And(t => t.Shape == "Oval");
  154. break;
  155. case "4":
  156. expression = expression.And(t => t.Shape == "Heart");
  157. break;
  158. case "5":
  159. expression = expression.And(t => t.Shape == "Emerald");
  160. break;
  161. case "6":
  162. expression = expression.And(t => t.Shape == "Radiant");
  163. break;
  164. case "7":
  165. expression = expression.And(t => t.Shape == "Asscher");
  166. break;
  167. case "8":
  168. expression = expression.And(t => t.Shape == "Princess");
  169. break;
  170. case "9":
  171. expression = expression.And(t => t.Shape == "Cushion");
  172. break;
  173. default:
  174. break;
  175. }
  176. }
  177. if (!queryParam["color"].IsEmpty())
  178. {
  179. string color = queryParam["color"].ToString();
  180. switch (color)
  181. {
  182. case "0":
  183. break;
  184. case "1":
  185. expression = expression.And(t => t.Color.Contains("D"));
  186. break;
  187. case "2":
  188. expression = expression.And(t => t.Color.Contains("E"));
  189. break;
  190. case "3":
  191. expression = expression.And(t => t.Color.Contains("F"));
  192. break;
  193. case "4":
  194. expression = expression.And(t => t.Color.Contains("G"));
  195. break;
  196. case "5":
  197. expression = expression.And(t => t.Color.Contains("H"));
  198. break;
  199. case "6":
  200. expression = expression.And(t => t.Color.Contains("I"));
  201. break;
  202. case "7":
  203. expression = expression.And(t => t.Color.Contains("J"));
  204. break;
  205. case "8":
  206. expression = expression.And(t => t.Color.Contains("K"));
  207. break;
  208. case "9":
  209. expression = expression.And(t => t.Color.Contains("L"));
  210. break;
  211. case "10":
  212. expression = expression.And(t => t.Color.Contains("M"));
  213. break;
  214. case "11":
  215. expression = expression.And(t => t.Color.Contains("N"));
  216. break;
  217. default:
  218. break;
  219. }
  220. }
  221. if (!queryParam["clarity"].IsEmpty())
  222. {
  223. string clarity = queryParam["clarity"].ToString();
  224. switch (clarity)
  225. {
  226. case "0":
  227. break;
  228. case "1":
  229. expression = expression.And(t => t.Clarity == "IF");
  230. break;
  231. case "2":
  232. expression = expression.And(t => t.Clarity == "VVS1");
  233. break;
  234. case "3":
  235. expression = expression.And(t => t.Clarity == "VVS2");
  236. break;
  237. case "4":
  238. expression = expression.And(t => t.Clarity == "VS1");
  239. break;
  240. case "5":
  241. expression = expression.And(t => t.Clarity == "VS2");
  242. break;
  243. case "6":
  244. expression = expression.And(t => t.Clarity == "SI1");
  245. break;
  246. case "7":
  247. expression = expression.And(t => t.Clarity == "SI2");
  248. break;
  249. case "8":
  250. expression = expression.And(t => t.Clarity == "SI3");
  251. break;
  252. case "9":
  253. expression = expression.And(t => t.Clarity == "I1");
  254. break;
  255. case "10":
  256. expression = expression.And(t => t.Clarity == "I2");
  257. break;
  258. case "11":
  259. expression = expression.And(t => t.Clarity == "I3");
  260. break;
  261. default:
  262. break;
  263. }
  264. }
  265. //if (!queryParam["lab"].IsEmpty())
  266. //{
  267. // string lab = queryParam["lab"].ToString();
  268. // switch (lab)
  269. // {
  270. // case "0":
  271. // break;
  272. // case "1":
  273. // expression = expression.And(t => t.Lab == "FL");
  274. // break;
  275. // case "2":
  276. // expression = expression.And(t => t.Shape == "IF");
  277. // break;
  278. // default:
  279. // break;
  280. // }
  281. // //expression = expression.And(t => t.F_Date >= startTime && t.F_Date <= endTime);
  282. //}
  283. if (!queryParam["polish"].IsEmpty())
  284. {
  285. string polish = queryParam["polish"].ToString();
  286. switch (polish)
  287. {
  288. case "0":
  289. break;
  290. case "1":
  291. expression = expression.And(t => t.Polish == "EX");
  292. break;
  293. case "2":
  294. expression = expression.And(t => t.Polish == "VG");
  295. break;
  296. case "3":
  297. expression = expression.And(t => t.Polish == "G");
  298. break;
  299. case "4":
  300. expression = expression.And(t => t.Polish == "F");
  301. break;
  302. case "5":
  303. expression = expression.And(t => t.Polish == "P");
  304. break;
  305. case "6":
  306. expression = expression.And(t => t.Polish == "N/A");
  307. break;
  308. default:
  309. break;
  310. }
  311. }
  312. if (!queryParam["symmerty"].IsEmpty())
  313. {
  314. string symmerty = queryParam["symmerty"].ToString();
  315. switch (symmerty)
  316. {
  317. case "0":
  318. break;
  319. case "1":
  320. expression = expression.And(t => t.Symmetry == "EX");
  321. break;
  322. case "2":
  323. expression = expression.And(t => t.Symmetry == "VG");
  324. break;
  325. case "3":
  326. expression = expression.And(t => t.Symmetry == "G");
  327. break;
  328. case "4":
  329. expression = expression.And(t => t.Symmetry == "F");
  330. break;
  331. case "5":
  332. expression = expression.And(t => t.Symmetry == "P");
  333. break;
  334. case "6":
  335. expression = expression.And(t => t.Symmetry == "N/A");
  336. break;
  337. default:
  338. break;
  339. }
  340. }
  341. if (!queryParam["cut"].IsEmpty())
  342. {
  343. string cut = queryParam["cut"].ToString();
  344. switch (cut)
  345. {
  346. case "0":
  347. break;
  348. case "1":
  349. expression = expression.And(t => t.Cut == "EX");
  350. break;
  351. case "2":
  352. expression = expression.And(t => t.Cut == "VG");
  353. break;
  354. case "3":
  355. expression = expression.And(t => t.Cut == "G");
  356. break;
  357. case "4":
  358. expression = expression.And(t => t.Cut == "F");
  359. break;
  360. case "5":
  361. expression = expression.And(t => t.Cut == "P");
  362. break;
  363. case "6":
  364. expression = expression.And(t => t.Cut == "N/A");
  365. break;
  366. default:
  367. break;
  368. }
  369. }
  370. if (!queryParam["location"].IsEmpty())
  371. {
  372. string location = queryParam["location"].ToString();
  373. switch (location)
  374. {
  375. case "0":
  376. break;
  377. case "1":
  378. expression = expression.And(t => t.Location == "ShangHai Warehouse");
  379. break;
  380. case "2":
  381. expression = expression.And(t => t.Location == "HongKong Warehouse");
  382. break;
  383. case "3":
  384. expression = expression.And(t => t.Location == "U.S.A Warehouse");
  385. break;
  386. default:
  387. break;
  388. }
  389. }
  390. if (!queryParam["sort"].IsEmpty())
  391. {
  392. string sort = queryParam["sort"].ToString();
  393. switch (sort)
  394. {
  395. case "0":
  396. break;
  397. case "1":
  398. expression = expression.And(t => t.Other == "Rough");
  399. break;
  400. case "2":
  401. expression = expression.And(t => t.Other == "Polished");
  402. break;
  403. default:
  404. break;
  405. }
  406. }
  407. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleFullName == "客户")
  408. {
  409. expression = expression.And(t => t.WhCode == "10");
  410. }
  411. expression = expression.And(t => t.IsLock == false);
  412. return service.FindList(expression, pagination).OrderBy(t => t.Weight).ToList();
  413. }
  414. public ICSProductEntity GetForm(string keyValue)
  415. {
  416. return service.FindEntity(keyValue);
  417. }
  418. public void DeleteForm(string keyValue)
  419. {
  420. service.Delete(t => t.F_Id == keyValue);
  421. }
  422. public void SubmitForm(ICSProductEntity productEntity, string keyValue)
  423. {
  424. if (!string.IsNullOrEmpty(keyValue))
  425. {
  426. productEntity.Modify(keyValue);
  427. service.Update(productEntity);
  428. }
  429. else
  430. {
  431. productEntity.Create();
  432. service.Insert(productEntity);
  433. }
  434. }
  435. public void PrsSell(List<ICSProductEntity> ProductEntityList)
  436. {
  437. foreach (ICSProductEntity ProductEntity in ProductEntityList)
  438. {
  439. service.Update(ProductEntity);
  440. }
  441. }
  442. }
  443. }