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

269 lines
11 KiB

3 years ago
  1. using Newtonsoft.Json;
  2. using NFine.Application.ProductManage;
  3. using NFine.Code;
  4. using NFine.Code.Excel;
  5. using NFine.Domain.Entity.ProductManage;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Web.Mvc;
  12. namespace NFine.Web.Areas.ProductManage.Controllers
  13. {
  14. public class OrderManageController : ControllerBase
  15. {
  16. private MaintainApp maintainApp = new MaintainApp();
  17. private PreSellApp presellApp = new PreSellApp();
  18. private PreSellDetailApp preselldetailApp = new PreSellDetailApp();
  19. [HttpGet]
  20. [HandlerAjaxOnly]
  21. public ActionResult GetGridJson(Pagination pagination, string keyword, string keyword2)
  22. {
  23. //var data = maintainAppApp.GetList(keyword);
  24. var data = new
  25. {
  26. rows = presellApp.GetListZS(pagination, keyword, keyword2),
  27. total = pagination.total,
  28. page = pagination.page,
  29. records = pagination.records
  30. };
  31. return Content(data.ToJson());
  32. }
  33. [HttpGet]
  34. [HandlerAjaxOnly]
  35. public ActionResult GetGridJsonMX(string keyValue, string keyword)
  36. {
  37. var data = preselldetailApp.GetList2(keyValue, keyword);
  38. return Content(data.ToJson());
  39. }
  40. [HttpGet]
  41. [HandlerAjaxOnly]
  42. public ActionResult GetFormJson(string keyValue)
  43. {
  44. var data = maintainApp.GetForm(keyValue);
  45. return Content(data.ToJson());
  46. }
  47. [HttpPost]
  48. public void Export(string keyValue, string keyword)
  49. {
  50. var data = preselldetailApp.GetList2(keyValue, keyword);
  51. DataTable dt = (DataTable)data;
  52. if (dt != null && dt.Rows.Count > 0)
  53. {
  54. string PreSellNo = presellApp.GetPreSellNo(dt.Rows[0]["F_Id"].ToString());
  55. dt.Columns.Remove("F_Id");
  56. dt.Columns.Remove("Product_Id");
  57. GridViewExportUtil.Export(dt, PreSellNo);
  58. }
  59. }
  60. [HttpPost]
  61. [HandlerAjaxOnly]
  62. [ValidateAntiForgeryToken]
  63. public ActionResult ConfirmOrders(string keyValue)
  64. {
  65. string confirmUserID = NFine.Code.OperatorProvider.Provider.GetCurrent().UserId;
  66. string[] array = keyValue.Split(',');
  67. List<ICSProductPreSellEntity> ppsList = new List<ICSProductPreSellEntity>();
  68. List<ICSProductEntity> pList = new List<ICSProductEntity>();
  69. ICSProductPreSellEntity entity = null;
  70. foreach (string id in array)
  71. {
  72. entity = new ICSProductPreSellEntity();
  73. entity.F_Id = keyValue;
  74. entity.IsConfirm = true;
  75. entity.ConfirmUserId = confirmUserID;
  76. entity.ConfirmTime = DateTime.Now;
  77. ppsList.Add(entity);
  78. List<string> PIDs = presellApp.GetProductID(keyValue);
  79. if (PIDs != null)
  80. {
  81. foreach (string pid in PIDs)
  82. {
  83. ICSProductEntity model = new ICSProductEntity();
  84. model = maintainApp.GetForm(pid);
  85. if (model != null)
  86. {
  87. model.F_Id = pid;
  88. model.IsLock = true;
  89. pList.Add(model);
  90. }
  91. }
  92. }
  93. }
  94. presellApp.UpdateForm(ppsList, pList, keyValue);
  95. #region 调用WebService,创建销售订单
  96. string idList = "";
  97. for (int i = 0; i < ppsList.Count; i++)
  98. {
  99. if (i == 0)
  100. idList = "'" + ppsList[i].F_Id + "'";
  101. else
  102. idList += ",'" + ppsList[i].F_Id + "'";
  103. }
  104. DataTable dt = preselldetailApp.GetListForWebService(idList);
  105. List<ServiceReference1.SO_SOMain> contextList = new List<ServiceReference1.SO_SOMain>();
  106. List<ServiceReference1.SO_SODetails> contextLists = new List<ServiceReference1.SO_SODetails>();
  107. ServiceReference1.SO_SOMain context = new ServiceReference1.SO_SOMain();
  108. ServiceReference1.SO_SODetails contexts = new ServiceReference1.SO_SODetails();
  109. string PreSellNo = "";//单据号
  110. for (int i = 0; i < dt.Rows.Count; i++)
  111. {
  112. if (PreSellNo != dt.Rows[i]["PreSellNo"].ToString())
  113. {
  114. if (i > 0)
  115. {
  116. context.bodyList = contextLists.ToArray();
  117. contextList.Add(context);
  118. }
  119. context = new ServiceReference1.SO_SOMain();
  120. PreSellNo = dt.Rows[i]["PreSellNo"].ToString();
  121. context.cSOCode = PreSellNo;
  122. context.cCusCode = dt.Rows[i]["F_CusCode"].ToString();
  123. context.isDel = false;
  124. context.UserCode = dt.Rows[i]["UserCode"].ToString();
  125. contextLists = new List<ServiceReference1.SO_SODetails>();
  126. }
  127. contexts = new ServiceReference1.SO_SODetails();
  128. contexts.cInvCode = dt.Rows[i]["ProductSN"].ToString();
  129. contexts.iPrice = string.IsNullOrEmpty(dt.Rows[i]["Amount"].ToString()) ?
  130. 0 : Convert.ToDecimal(dt.Rows[i]["Amount"].ToString());
  131. contextLists.Add(contexts);
  132. if (i == dt.Rows.Count - 1)
  133. {
  134. context.bodyList = contextLists.ToArray();
  135. contextList.Add(context);
  136. }
  137. }
  138. ServiceReference1.U8ERP5Client client = new ServiceReference1.U8ERP5Client();
  139. ServiceReference1.Result cresult = new ServiceReference1.Result();
  140. cresult = client.InsertRd32(contextList.ToArray());
  141. if (cresult.IsSuccess == false)
  142. {
  143. throw new Exception(cresult.MESSAGE);
  144. }
  145. #endregion
  146. return Success("Pre sale order confirmed successfully.");
  147. }
  148. [HttpPost]
  149. [HandlerAjaxOnly]
  150. [ValidateAntiForgeryToken]
  151. public ActionResult CancelConfirmOrders(string keyValue)
  152. {
  153. string confirmUserID = NFine.Code.OperatorProvider.Provider.GetCurrent().UserId;
  154. string[] array = keyValue.Split(',');
  155. List<ICSProductPreSellEntity> ppsList = new List<ICSProductPreSellEntity>();
  156. List<ICSProductEntity> pList = new List<ICSProductEntity>();
  157. ICSProductPreSellEntity entity = null;
  158. foreach (string id in array)
  159. {
  160. entity = new ICSProductPreSellEntity();
  161. entity.F_Id = keyValue;
  162. entity.IsConfirm = false;
  163. entity.ConfirmUserId = null;
  164. entity.ConfirmTime = null;
  165. ppsList.Add(entity);
  166. List<string> PIDs = presellApp.GetProductID(keyValue);
  167. if (PIDs != null)
  168. {
  169. foreach (string pid in PIDs)
  170. {
  171. ICSProductEntity model = new ICSProductEntity();
  172. model = maintainApp.GetForm(pid);
  173. if (model != null)
  174. {
  175. model.F_Id = pid;
  176. model.IsLock = false;
  177. pList.Add(model);
  178. }
  179. }
  180. }
  181. }
  182. presellApp.UpdateFormC(ppsList, pList);
  183. #region 调用WebService,删除销售订单
  184. string idList = "";
  185. for (int i = 0; i < ppsList.Count; i++)
  186. {
  187. if (i == 0)
  188. idList = "'" + ppsList[i].F_Id + "'";
  189. else
  190. idList += ",'" + ppsList[i].F_Id + "'";
  191. }
  192. DataTable dt = preselldetailApp.GetListForWebService(idList);
  193. List<ServiceReference1.SO_SOMain> contextList = new List<ServiceReference1.SO_SOMain>();
  194. List<ServiceReference1.SO_SODetails> contextLists = new List<ServiceReference1.SO_SODetails>();
  195. ServiceReference1.SO_SOMain context = new ServiceReference1.SO_SOMain();
  196. ServiceReference1.SO_SODetails contexts = new ServiceReference1.SO_SODetails();
  197. string PreSellNo = "";//单据号
  198. for (int i = 0; i < dt.Rows.Count; i++)
  199. {
  200. if (PreSellNo != dt.Rows[i]["PreSellNo"].ToString())
  201. {
  202. if (i > 0)
  203. {
  204. context.bodyList = contextLists.ToArray();
  205. contextList.Add(context);
  206. }
  207. context = new ServiceReference1.SO_SOMain();
  208. PreSellNo = dt.Rows[i]["PreSellNo"].ToString();
  209. context.cSOCode = PreSellNo;
  210. context.cCusCode = dt.Rows[i]["F_CusCode"].ToString();
  211. context.isDel = true;
  212. context.UserCode = dt.Rows[i]["UserCode"].ToString();
  213. contextLists = new List<ServiceReference1.SO_SODetails>();
  214. }
  215. contexts = new ServiceReference1.SO_SODetails();
  216. contexts.cInvCode = dt.Rows[i]["ProductSN"].ToString();
  217. contexts.iPrice = Convert.ToDecimal(dt.Rows[i]["Amount"].ToString());
  218. contextLists.Add(contexts);
  219. if (i == dt.Rows.Count - 1)
  220. {
  221. context.bodyList = contextLists.ToArray();
  222. contextList.Add(context);
  223. }
  224. }
  225. ServiceReference1.U8ERP5Client client = new ServiceReference1.U8ERP5Client();
  226. ServiceReference1.Result cresult = new ServiceReference1.Result();
  227. cresult = client.InsertRd32(contextList.ToArray());
  228. if (cresult.IsSuccess == false)
  229. {
  230. throw new Exception(cresult.MESSAGE);
  231. }
  232. #endregion
  233. return Success("Pre sale order cancel confirmed successfully.");
  234. }
  235. [HttpPost]
  236. [HandlerAjaxOnly]
  237. [ValidateAntiForgeryToken]
  238. public ActionResult SubmitForm(ICSProductEntity productEntity, string keyValue)
  239. {
  240. maintainApp.SubmitForm(productEntity, keyValue);
  241. return Success("Successful operation.");
  242. }
  243. [HttpPost]
  244. [HandlerAjaxOnly]
  245. [HandlerAuthorize]
  246. [ValidateAntiForgeryToken]
  247. public ActionResult DeleteForm(string keyValue)
  248. {
  249. maintainApp.DeleteForm(keyValue);
  250. return Success("Delete success.");
  251. }
  252. }
  253. }