PurchasePlanController.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. using JCSoft.WX.Framework.Api;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.AspNetCore.Http;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using Common.Wechat;
  9. using Common;
  10. using CoreEntity.DAL;
  11. using Common.Model;
  12. using PublicLibrary.Model;
  13. using System.Data;
  14. using System.Data.SqlClient;
  15. using CoreEntity.Entity;
  16. using ZcPeng.PublicLibrary;
  17. using Newtonsoft.Json.Converters;
  18. using Newtonsoft.Json;
  19. using SupplierWeb.Codes.mvc;
  20. namespace SupplierWeb.Controllers
  21. {
  22. [Route("web/purchaseplan")]
  23. public class PurchasePlanController : Controller
  24. {
  25. public PurchasePlanController()
  26. {
  27. }
  28. ////查询采购计划(生成的)
  29. [AuthPermission]
  30. [HttpPost,Route("index")]
  31. public JsonResult index(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  32. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  33. {
  34. if (data != null)
  35. {
  36. //Newtonsoft.Json.Linq.JArray
  37. filters = data.filters.ToObject<QueryFilter[]>();
  38. pageIndex = data.pageIndex;
  39. pageSize = data.pageSize;
  40. sortField = data.sortField;
  41. sortDirection = data.sortDirection;
  42. sumFields = data.sumFields.ToObject<string[]>();
  43. }
  44. List<SqlParameter> parameters1 = new List<SqlParameter>();
  45. string filterstring = QueryFilter.getFilterSqlParam(filters, out parameters1,new PurPlanMTExt(), "A.");
  46. //filterstring += " and A.BillState !=1 ";
  47. filterstring = filterstring.Replace("A.AccountRealName", "B.AccountRealName");
  48. filterstring = filterstring.Replace("A.PurRealName", "C.AccountRealName");
  49. filterstring = filterstring.Replace("A.BusinessName", "E.BusinessName");
  50. filterstring = filterstring.Replace("A.IsPrepayI", " Case A.IsPrepay When 'Y' Then 1 Else 0 End ");
  51. #region 获取计划
  52. DataTable dt = new DataTable();
  53. string result = string.Empty;
  54. string direct = " desc ";
  55. if (sortDirection != 1)
  56. direct = " asc";
  57. int start = (pageIndex - 1) * pageSize;
  58. int end = (start + 1 + pageSize);
  59. string commandText0 = "select * from (";
  60. string commandText1 = "select A.*,Case A.IsPrepay When 'Y' Then 1 Else 0 End as IsPrepayI,B.AccountRealName,C.AccountRealName as PurRealName,E.BusinessName,row_number() over" +
  61. "( order by A."+ sortField + " " + direct + " ) as rownum" +
  62. " from PurPlanMT A " +
  63. " left join " + Config.TablePrefix + "Account B on A.SaleManId=B.PurStaffId" +
  64. " left join " + Config.TablePrefix + "Account C on A.PurObj=C.Id" +
  65. " left join BusinessDoc E on E.BusinessId=A.SuppliersId and E.Is_Supp = 'Y' and E.EntId = 'E1WB67UEYPG'" +
  66. " where 1=1 " +
  67. filterstring +
  68. ")AAA";
  69. string commandText2 =
  70. " where AAA.rownum>" + start + " and AAA.rownum<" + end
  71. ;
  72. string commandText = commandText0 + commandText1 + commandText2;
  73. bool result1 = DataAccess.GetValues(commandText, ref dt, parameters1.ToArray(), out result);
  74. IList<PurPlanMTExt> users = new List<PurPlanMTExt>();
  75. if (dt != null && dt.Rows.Count > 0)
  76. {
  77. // 把DataTable转换为IList<UserInfo>
  78. users = ModelConvertHelper<PurPlanMTExt>.ConvertToModel(dt);
  79. }
  80. #endregion
  81. string resultrow;
  82. string commandTextCount = "select count(*) from (" + commandText1;
  83. long totalcount = DataAccess.GetRowCountDefine(commandTextCount, parameters1.ToArray(), out resultrow);
  84. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  85. {
  86. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  87. };
  88. var jsonData = JsonConvert.SerializeObject(users, timejson);
  89. return Json(new
  90. {
  91. items = JsonConvert.DeserializeObject(jsonData),
  92. sum = new { },
  93. totalCount = totalcount
  94. });
  95. }
  96. ////查询采购计划明细(生成的)
  97. [AuthPermission]
  98. [HttpPost, Route("dt")]
  99. public JsonResult dt(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  100. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  101. {
  102. if (data != null)
  103. {
  104. //Newtonsoft.Json.Linq.JArray
  105. filters = data.filters.ToObject<QueryFilter[]>();
  106. pageIndex = data.pageIndex;
  107. pageSize = data.pageSize;
  108. sortField = data.sortField;
  109. sortDirection = data.sortDirection;
  110. sumFields = data.sumFields.ToObject<string[]>();
  111. }
  112. List<SqlParameter> parameters1 = new List<SqlParameter>();
  113. string filterstring = QueryFilter.getFilterSqlParam(filters, out parameters1,new PurPlanDtExt(),"A.");
  114. filterstring = filterstring.Replace("A.AccountRealName", "B.AccountRealName");
  115. filterstring = filterstring.Replace("A.PurRealName", "D.AccountRealName");
  116. filterstring = filterstring.Replace("A.GoodsName", "F.GoodsName");
  117. filterstring = filterstring.Replace("A.UniKey", "concat(A.BillNo, A.BillSn)");
  118. filterstring = filterstring.Replace("A.BillState", "C.BillState");
  119. sortField = "A."+ sortField;
  120. sortField = sortField.Replace("A.UniKey", "concat(A.BillNo, A.BillSn)");
  121. //string joinstring = " and C.BillState !=1 ";
  122. #region 获取计划
  123. DataTable dt = new DataTable();
  124. string result = string.Empty;
  125. string direct = " desc ";
  126. if (sortDirection != 1)
  127. direct = " asc";
  128. int start = (pageIndex - 1) * pageSize;
  129. int end = (start + 1 + pageSize);
  130. string commandText0 = "select * from (";
  131. string commandText1 =
  132. "select A.*,concat(A.BillNo ,A.BillSn) as UniKey,B.AccountRealName,D.AccountRealName as PurRealName,F.GoodsName,row_number() over" +
  133. "( order by " + sortField + " " + direct + " ) as rownum" +
  134. " from PurPlanDT A " +
  135. " left join PurPlanMT C on C.BillNo=A.BillNo and C.EntId = A.EntId "+
  136. //joinstring +
  137. " left join " + Config.TablePrefix + "Account B on C.SaleManId=B.PurStaffId" +
  138. " left join " + Config.TablePrefix + "Account D on C.PurObj=D.Id" +
  139. " left join GoodsDOC F on F.GoodsId=A.GoodsId and F.EntId = 'E1WB67UEYPG'" +
  140. " where 1=1 " +
  141. filterstring +
  142. ")AAA";
  143. string commandText2 =
  144. " where AAA.rownum>" + start + " and AAA.rownum<" + end
  145. ;
  146. string commandText = commandText0 + commandText1 + commandText2;
  147. bool result1 = DataAccess.GetValues(commandText, ref dt, parameters1.ToArray(), out result);
  148. IList<PurPlanDtExt> users = new List<PurPlanDtExt>();
  149. if (dt != null && dt.Rows.Count > 0)
  150. {
  151. // 把DataTable转换为IList<UserInfo>
  152. users = ModelConvertHelper<PurPlanDtExt>.ConvertToModel(dt);
  153. }
  154. #endregion
  155. string resultrow;
  156. string commandTextCount = "select count(*) from (" + commandText1;
  157. long totalcount = DataAccess.GetRowCountDefine(commandTextCount,parameters1.ToArray(), out resultrow);
  158. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  159. {
  160. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  161. };
  162. var jsonData = JsonConvert.SerializeObject(users, timejson);
  163. return Json(new
  164. {
  165. items = JsonConvert.DeserializeObject(jsonData),
  166. sum = new { },
  167. totalCount = totalcount
  168. });
  169. }
  170. ///////////////////
  171. ////查看供应商,业务员提交的新品种首营资料(品种首营、供应商首营) 下载首营资料
  172. [AuthPermission]
  173. [HttpGet,Route("newcategorydoc")]
  174. public ActionResult NewCategoryDoc(string echostr, string signature, string timestamp, string nonce)
  175. {
  176. #region 获取
  177. //WechatHelper.ReGetOpenId(HttpContext);
  178. #endregion
  179. return View();
  180. }
  181. ////查看供应商,业务员提交的新品种
  182. [AuthPermission]
  183. [HttpGet,Route("newcategory")]
  184. public ActionResult NewCategory(string echostr, string signature, string timestamp, string nonce)
  185. {
  186. #region 获取Openid
  187. //WechatHelper.ReGetOpenId(HttpContext);
  188. #endregion
  189. return View();
  190. }
  191. /////////////
  192. ///收货模式列表
  193. [HttpGet, Route("receiptmds")]
  194. public JsonResult ReceiptMds()
  195. {
  196. List<Option> options = PushRecordDAL.getOptionReceipt();
  197. return Json(options
  198. );
  199. }
  200. ///支付模式列表
  201. [HttpGet, Route("centpaymds")]
  202. public JsonResult CentPayMds()
  203. {
  204. List<Option> options = PushRecordDAL.getOptionCentPay();
  205. return Json(options
  206. );
  207. }
  208. ///机构列表
  209. [HttpGet, Route("orgs")]
  210. public JsonResult Orgs()
  211. {
  212. List<OrgDoc> roles = OrgDAL.getOrg();
  213. IList<Option> options = new List<Option>();
  214. foreach (OrgDoc role in roles)
  215. {
  216. var option = new Option() { label = role.ORGNAME, value = role.ORGID, disabled = (role.BEACTIVE.Equals("N")) };
  217. options.Add(option);
  218. }
  219. return Json(options
  220. );
  221. }
  222. ///部门列表
  223. [HttpGet, Route("depts")]
  224. public JsonResult Depts()
  225. {
  226. List<DeptDoc> roles = DeptDAL.getDept();
  227. IList<Option> options = new List<Option>();
  228. foreach (DeptDoc role in roles)
  229. {
  230. var option = new Option() { label = role.DEPARTMENT, value = role.DEPTID, disabled = (role.BEACTIVE.Equals("N")) };
  231. options.Add(option);
  232. }
  233. return Json(options
  234. );
  235. }
  236. }
  237. }