123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- using Ant.Data;
- using Ant.ORM;
- using Ant.Service.Common;
- using Ant.Service.Common.Enums;
- using MES.Production.Entity;
- using MES.Production.Entity.Entity;
- using ChangFa.Machinery.WebPage.Controllers;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using JsonHelper = Ant.Service.Common.JsonHelper;
- namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
- {
- public class UserDistributorsController : BaseController
- {
- // GET: SysManage/UserDistributors
- [UserAuthorize(ModuleAlias = "SalesDealersList", OperaAction = "View")]
- public ActionResult Index()
- {
- string distributorsID = string.Empty;
- if (!Request.QueryString["distributorsid"].IsEmpty())
- {
- distributorsID = Request.QueryString["distributorsid"].ToString();
- }
- ViewData["distributorsid"] = distributorsID;
- PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<UserProudctLine>()));
- List<UserProudctLine> userlist = new List<UserProudctLine>();
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- };
- IQuery<En_SYS_USER> userquery = orm.Queryable<En_SYS_USER>();
- IQuery<EntYW_UserDistributor> userdis = orm.Queryable<EntYW_UserDistributor>();
- IJoiningQuery<En_SYS_USER, EntYW_UserDistributor> user_dis = userquery.LeftJoin(userdis, (user, city) => user.ID == city.userId);
- var qq = user_dis.Select((user, city) => new { Users = user, Citys = city }).Where(a => a.Citys.distributorId == distributorsID);
- var reslut = qq.ToList(res);
- if (reslut.IsSuccess)
- {
- foreach (var mod in reslut.ResultModel)
- {
- En_SYS_USER user = mod.Users; EntYW_UserDistributor useridmod = mod.Citys;
- UserProudctLine proudctLine = new UserProudctLine();
- proudctLine.id = useridmod.ID.ToString();
- proudctLine.name = user.NAME;
- string productlinestr = string.Empty;
- if (useridmod.ProductLine.IfNotNull())
- {
- if (useridmod.ProductLine == 601)
- {
- productlinestr = productlinestr + "轮拖、";
- }
- }
- if (useridmod.ProductLine1.IfNotNull())
- {
- if (useridmod.ProductLine1 == 615)
- {
- productlinestr = productlinestr + "轮式收、";
- }
- }
- if (useridmod.ProductLine2.IfNotNull())
- {
- if (useridmod.ProductLine2 == 612)
- {
- productlinestr = productlinestr + "履带收、";
- }
- }
- if (useridmod.ProductLine3.IfNotNull())
- {
- if (useridmod.ProductLine3 == 611)
- {
- productlinestr = productlinestr + "插秧机、";
- }
- }
- if (useridmod.ProductLine4.IfNotNull())
- {
- if (useridmod.ProductLine4 == 622)
- {
- productlinestr = productlinestr + "玉米收、";
- }
- }
- if (useridmod.ProductLine5.IfNotNull())
- {
- if (useridmod.ProductLine5 == 628)
- {
- productlinestr = productlinestr + "花生机、";
- }
- }
- if (productlinestr.Length > 0)
- proudctLine.proudctLine = productlinestr.Substring(0, productlinestr.Length - 1);
- proudctLine.addName = useridmod.add_name;
- proudctLine.addTime = useridmod.add_time;
- userlist.Add(proudctLine);
- pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(userlist));
- }
- }
- }
- return View(pageInfo);
- }
- public ActionResult Detail(string distributorsid)
- {
- EntYW_UserDistributor mod = new EntYW_UserDistributor();
- ViewData["distributorsid"] = distributorsid;
- return View(mod);
- }
- /// <summary>
- /// 删除部门
- /// </summary>
- [UserAuthorizeAttribute(ModuleAlias = "SalesDealersList", OperaAction = "Remove")]
- public ActionResult Delete(string idList)
- {
- JsonHelper json = new JsonHelper() { Msg = "删除经产品线负责人", ReUrl = "/UserDistributors/index", Status = "n" };
- try
- {
- if (!string.IsNullOrEmpty(idList))
- {
- idList = idList.TrimEnd(',');
- //判断是否有下属部门
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- foreach (string id in idList.Split(','))
- {
- RequestModel request = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" },
- Oid = id.ToString()
- };
- Guid guid = new Guid(id);
- var disreult = orm.DeleteByLambda<EntYW_UserDistributor>(p => p.ID == guid, request);
- }
- }
- json.Status = "y";
- }
- else
- {
- json.Msg = "未找到要删除的记录";
- }
- WriteLog(enumOperator.Remove, "删除产品线负责人:" + json.Msg, enumLog4net.WARN);
- }
- catch (Exception e)
- {
- json.Msg = "删除产品线负责人发生内部错误!";
- WriteLog(enumOperator.Remove, "删除产品线负责人:", e);
- }
- return Json(json);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [UserAuthorize(ModuleAlias = "SalesDealersList", OperaAction = "Add,Edit")]
- [ValidateInput(false)]
- [HttpPost]
- public ActionResult Save(string distributorsid, Ent_YW_Notice entity)
- {
- JsonHelper json = new JsonHelper() { Msg = "经销商产品负责人添加成功", Status = "n", ReUrl = "/UserDistributors/Index" };
- try
- {
- var productLine = string.Empty; int ProductLine = 0; int ProductLine1 = 0; int ProductLine2 = 0; int ProductLine3 = 0; int ProductLine4 = 0; int ProductLine5 = 0;
- if (!Request["productline"].IsEmpty())
- {
- productLine = Request["productline"].ToString();
- }
- var useridstr = Request.Form["hidsendUserid"]; int userid = 0;
- if (!useridstr.IsEmpty())
- {
- userid = useridstr.ToInt32();
- }
- foreach (var s in productLine.Split(','))
- {
- if (s == "601")
- {
- ProductLine = 601;
- }
- if (s == "615")
- {
- ProductLine1 = 615;
- }
- if (s == "612")
- {
- ProductLine2 = 612;
- }
- if (s == "611")
- {
- ProductLine3 = 611;
- }
- if (s == "622")
- {
- ProductLine4 = 622;
- }
- if (s == "628")
- {
- ProductLine5 = 628;
- }
- }
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
- };
- var reslut = orm.Queryable<EntYW_UserDistributor>().Where(p => p.distributorId == distributorsid && p.userId == userid).FirstOrDefault(res);
- if (reslut.IsSuccess)
- {
- 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);
- }
- else
- {
- EntYW_UserDistributor usemod = new EntYW_UserDistributor();
- usemod.ID = Guid.NewGuid();
- usemod.ProductLine = ProductLine;
- usemod.ProductLine1 = ProductLine1;
- usemod.ProductLine2 = ProductLine2;
- usemod.ProductLine3 = ProductLine3;
- usemod.ProductLine4 = ProductLine4;
- usemod.ProductLine5 = ProductLine5;
- usemod.userId = userid;
- usemod.distributorId = distributorsid;
- usemod.add_name = CurrentUser.Name;
- usemod.add_time = DateTime.Now;
- usemod.distype = 0;
- var ress = orm.Save(usemod, res);
- if (ress.IsSuccess)
- {
- json.Status = "y";
- }
- }
- }
- }
- catch (Exception ex)
- {
- }
- return Json(json);
- }
- }
- }
|