UserDistributorsController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. using Ant.Data;
  2. using Ant.ORM;
  3. using Ant.Service.Common;
  4. using Ant.Service.Common.Enums;
  5. using MES.Production.Entity;
  6. using MES.Production.Entity.Entity;
  7. using ChangFa.Machinery.WebPage.Controllers;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Web;
  12. using System.Web.Mvc;
  13. using JsonHelper = Ant.Service.Common.JsonHelper;
  14. namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
  15. {
  16. public class UserDistributorsController : BaseController
  17. {
  18. // GET: SysManage/UserDistributors
  19. [UserAuthorize(ModuleAlias = "SalesDealersList", OperaAction = "View")]
  20. public ActionResult Index()
  21. {
  22. string distributorsID = string.Empty;
  23. if (!Request.QueryString["distributorsid"].IsEmpty())
  24. {
  25. distributorsID = Request.QueryString["distributorsid"].ToString();
  26. }
  27. ViewData["distributorsid"] = distributorsID;
  28. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<UserProudctLine>()));
  29. List<UserProudctLine> userlist = new List<UserProudctLine>();
  30. using (AntORM orm = new AntORM())
  31. {
  32. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  33. RequestModel res = new RequestModel
  34. {
  35. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  36. };
  37. IQuery<En_SYS_USER> userquery = orm.Queryable<En_SYS_USER>();
  38. IQuery<EntYW_UserDistributor> userdis = orm.Queryable<EntYW_UserDistributor>();
  39. IJoiningQuery<En_SYS_USER, EntYW_UserDistributor> user_dis = userquery.LeftJoin(userdis, (user, city) => user.ID == city.userId);
  40. var qq = user_dis.Select((user, city) => new { Users = user, Citys = city }).Where(a => a.Citys.distributorId == distributorsID);
  41. var reslut = qq.ToList(res);
  42. if (reslut.IsSuccess)
  43. {
  44. foreach (var mod in reslut.ResultModel)
  45. {
  46. En_SYS_USER user = mod.Users; EntYW_UserDistributor useridmod = mod.Citys;
  47. UserProudctLine proudctLine = new UserProudctLine();
  48. proudctLine.id = useridmod.ID.ToString();
  49. proudctLine.name = user.NAME;
  50. string productlinestr = string.Empty;
  51. if (useridmod.ProductLine.IfNotNull())
  52. {
  53. if (useridmod.ProductLine == 601)
  54. {
  55. productlinestr = productlinestr + "轮拖、";
  56. }
  57. }
  58. if (useridmod.ProductLine1.IfNotNull())
  59. {
  60. if (useridmod.ProductLine1 == 615)
  61. {
  62. productlinestr = productlinestr + "轮式收、";
  63. }
  64. }
  65. if (useridmod.ProductLine2.IfNotNull())
  66. {
  67. if (useridmod.ProductLine2 == 612)
  68. {
  69. productlinestr = productlinestr + "履带收、";
  70. }
  71. }
  72. if (useridmod.ProductLine3.IfNotNull())
  73. {
  74. if (useridmod.ProductLine3 == 611)
  75. {
  76. productlinestr = productlinestr + "插秧机、";
  77. }
  78. }
  79. if (useridmod.ProductLine4.IfNotNull())
  80. {
  81. if (useridmod.ProductLine4 == 622)
  82. {
  83. productlinestr = productlinestr + "玉米收、";
  84. }
  85. }
  86. if (useridmod.ProductLine5.IfNotNull())
  87. {
  88. if (useridmod.ProductLine5 == 628)
  89. {
  90. productlinestr = productlinestr + "花生机、";
  91. }
  92. }
  93. if (productlinestr.Length > 0)
  94. proudctLine.proudctLine = productlinestr.Substring(0, productlinestr.Length - 1);
  95. proudctLine.addName = useridmod.add_name;
  96. proudctLine.addTime = useridmod.add_time;
  97. userlist.Add(proudctLine);
  98. pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(userlist));
  99. }
  100. }
  101. }
  102. return View(pageInfo);
  103. }
  104. public ActionResult Detail(string distributorsid)
  105. {
  106. EntYW_UserDistributor mod = new EntYW_UserDistributor();
  107. ViewData["distributorsid"] = distributorsid;
  108. return View(mod);
  109. }
  110. /// <summary>
  111. /// 删除部门
  112. /// </summary>
  113. [UserAuthorizeAttribute(ModuleAlias = "SalesDealersList", OperaAction = "Remove")]
  114. public ActionResult Delete(string idList)
  115. {
  116. JsonHelper json = new JsonHelper() { Msg = "删除经产品线负责人", ReUrl = "/UserDistributors/index", Status = "n" };
  117. try
  118. {
  119. if (!string.IsNullOrEmpty(idList))
  120. {
  121. idList = idList.TrimEnd(',');
  122. //判断是否有下属部门
  123. using (AntORM orm = new AntORM())
  124. {
  125. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  126. foreach (string id in idList.Split(','))
  127. {
  128. RequestModel request = new RequestModel
  129. {
  130. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" },
  131. Oid = id.ToString()
  132. };
  133. Guid guid = new Guid(id);
  134. var disreult = orm.DeleteByLambda<EntYW_UserDistributor>(p => p.ID == guid, request);
  135. }
  136. }
  137. json.Status = "y";
  138. }
  139. else
  140. {
  141. json.Msg = "未找到要删除的记录";
  142. }
  143. WriteLog(enumOperator.Remove, "删除产品线负责人:" + json.Msg, enumLog4net.WARN);
  144. }
  145. catch (Exception e)
  146. {
  147. json.Msg = "删除产品线负责人发生内部错误!";
  148. WriteLog(enumOperator.Remove, "删除产品线负责人:", e);
  149. }
  150. return Json(json);
  151. }
  152. /// <summary>
  153. ///
  154. /// </summary>
  155. /// <param name="content"></param>
  156. /// <returns></returns>
  157. [UserAuthorize(ModuleAlias = "SalesDealersList", OperaAction = "Add,Edit")]
  158. [ValidateInput(false)]
  159. [HttpPost]
  160. public ActionResult Save(string distributorsid, Ent_YW_Notice entity)
  161. {
  162. JsonHelper json = new JsonHelper() { Msg = "经销商产品负责人添加成功", Status = "n", ReUrl = "/UserDistributors/Index" };
  163. try
  164. {
  165. var productLine = string.Empty; int ProductLine = 0; int ProductLine1 = 0; int ProductLine2 = 0; int ProductLine3 = 0; int ProductLine4 = 0; int ProductLine5 = 0;
  166. if (!Request["productline"].IsEmpty())
  167. {
  168. productLine = Request["productline"].ToString();
  169. }
  170. var useridstr = Request.Form["hidsendUserid"]; int userid = 0;
  171. if (!useridstr.IsEmpty())
  172. {
  173. userid = useridstr.ToInt32();
  174. }
  175. foreach (var s in productLine.Split(','))
  176. {
  177. if (s == "601")
  178. {
  179. ProductLine = 601;
  180. }
  181. if (s == "615")
  182. {
  183. ProductLine1 = 615;
  184. }
  185. if (s == "612")
  186. {
  187. ProductLine2 = 612;
  188. }
  189. if (s == "611")
  190. {
  191. ProductLine3 = 611;
  192. }
  193. if (s == "622")
  194. {
  195. ProductLine4 = 622;
  196. }
  197. if (s == "628")
  198. {
  199. ProductLine5 = 628;
  200. }
  201. }
  202. using (AntORM orm = new AntORM())
  203. {
  204. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  205. RequestModel res = new RequestModel
  206. {
  207. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  208. };
  209. var reslut = orm.Queryable<EntYW_UserDistributor>().Where(p => p.distributorId == distributorsid && p.userId == userid).FirstOrDefault(res);
  210. if (reslut.IsSuccess)
  211. {
  212. var updatereslut = orm.UpdateByLambda<EntYW_UserDistributor>(p => new EntYW_UserDistributor { ProductLine = ProductLine, ProductLine1 = ProductLine1, ProductLine2 = ProductLine2, ProductLine3 = ProductLine3, ProductLine4 = ProductLine4, ProductLine5 = ProductLine5 }, p => p.distributorId == distributorsid && p.userId == userid, res);
  213. }
  214. else
  215. {
  216. EntYW_UserDistributor usemod = new EntYW_UserDistributor();
  217. usemod.ID = Guid.NewGuid();
  218. usemod.ProductLine = ProductLine;
  219. usemod.ProductLine1 = ProductLine1;
  220. usemod.ProductLine2 = ProductLine2;
  221. usemod.ProductLine3 = ProductLine3;
  222. usemod.ProductLine4 = ProductLine4;
  223. usemod.ProductLine5 = ProductLine5;
  224. usemod.userId = userid;
  225. usemod.distributorId = distributorsid;
  226. usemod.add_name = CurrentUser.Name;
  227. usemod.add_time = DateTime.Now;
  228. usemod.distype = 0;
  229. var ress = orm.Save(usemod, res);
  230. if (ress.IsSuccess)
  231. {
  232. json.Status = "y";
  233. }
  234. }
  235. }
  236. }
  237. catch (Exception ex)
  238. {
  239. }
  240. return Json(json);
  241. }
  242. }
  243. }