1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576 |
- using Ant.Data;
- using Ant.ORM;
- using Ant.Service.Common;
- using Ant.Service.Common.Enums;
- using Central.Control.Domain;
- using MES.Production.Entity;
- using MES.Production.Entity.Entity;
- using MES.Production.Entity.Enum;
- using MES.Production.Service.IService;
- using MES.Production.Service.ServiceImp;
- using Ant.Service.Utility;
- using ChangFa.Machinery.WebPage.Controllers;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using JsonHelper = Ant.Service.Common.JsonHelper;
- using Ant.SuperSocket.Common;
- namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
- {
- public class DistributorsController : BaseController
- {
- /// <summary>
- /// 字典编码
- /// </summary>
- ICodeManage CodeManage = new CodeManage();
- /// <summary>
- /// 部门
- /// </summary>
- IDepartmentManage DepartmentManage = new DepartmentManage();
- /// <summary>
- /// 用户部门
- /// </summary>
- IUserDepartmentManage UserDepartmentManage = new UserDepartmentManage();
- /// <summary>
- /// 岗位人员
- /// </summary>
- IPostUserManage PostUserManage { get; set; }
- /// <summary>
- /// 岗位部门
- /// </summary>
- IPostDepartmentManage PostDepartmentManage = new PostDepartmentManage();
- /// <summary>
- /// 加载列表
- /// </summary>
- /// <returns></returns>
- [UserAuthorizeAttribute(ModuleAlias = "Department", OperaAction = "View")]
- public ActionResult Index()
- {
- try
- {
- #region 处理查询参数
- string posttype = Request.QueryString["posttype"];
- string FK_DPTID = Request.QueryString["FK_DPTID"];
- #endregion
- #region 加载列表
- var result = BindList(posttype, FK_DPTID, CurrentUser.USERTYPE);
- ViewBag.Search = base.keywords;
- // ViewData["PostType"] = this.CodeManage.GetCode("POSTTYPE");
- //ViewData["post"] = posttype;
- ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetail();
- ViewData["dptid"] = FK_DPTID;
- #endregion
- if (result.IsNull())
- {
- return View();
- }
- else
- {
- return View(result);
- }
- }
- catch (Exception e)
- {
- WriteLog(enumOperator.Select, "加载岗位列表:", e);
- throw e.InnerException;
- }
- }
- /// <summary>
- /// 导出经销商excel
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- [UserAuthorizeAttribute(ModuleAlias = "SalesDealersList", OperaAction = "Export")]
- public FileResult AllDistributorExcel()
- {
- //获取list数据
- List<string> list = new List<string>();
- //创建Excel文件的对象
- NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); string distributorsID = string.Empty; string CarSate = Request.QueryString["CarSate"];
- List<string> namelist = new List<string>();
- //添加一个sheet
- NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
- //给sheet1添加第一行的头部标题
- NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
- row1.CreateCell(0).SetCellValue("经销商类型");
- row1.CreateCell(1).SetCellValue("经销商编号");
- row1.CreateCell(2).SetCellValue("经销商名称");
- row1.CreateCell(3).SetCellValue("所在省");
- row1.CreateCell(4).SetCellValue("所在市");
- row1.CreateCell(5).SetCellValue("所在区");
- row1.CreateCell(6).SetCellValue("经销商地址");
- row1.CreateCell(7).SetCellValue("电子围栏范围");
- row1.CreateCell(8).SetCellValue("经纬度");
- row1.CreateCell(9).SetCellValue("经销商手机号");
- row1.CreateCell(10).SetCellValue("经销商联系人");
- row1.CreateCell(11).SetCellValue("销售产品");
- row1.CreateCell(12).SetCellValue("轮拖轮式收条线联系人");
- row1.CreateCell(13).SetCellValue("轮拖轮式收条线手机号");
- row1.CreateCell(14).SetCellValue("履带插秧条线联系人");
- row1.CreateCell(15).SetCellValue("履带插秧条线手机号");
- row1.CreateCell(16).SetCellValue("玉米收花生机条线联系人");
- row1.CreateCell(17).SetCellValue("玉米收花生机条线手机号");
- //将数据逐步写入sheet1各个行
- if (!Request.QueryString["distributorsid"].IsEmpty())
- {
- distributorsID = Request.QueryString["distributorsid"].ToString();
- }
- 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 q = orm.Queryable<EntSYS_DISTRIBUTORS>();
- if (!Request.QueryString["hkprovid"].IsEmpty())
- {
- int provid = Request.QueryString["hkprovid"].ToInt32();
- q = q.Where(p => p.Province == provid);
- }
- if (!Request.QueryString["hkcityid"].IsEmpty())
- {
- int provid = Request.QueryString["hkcityid"].ToInt32();
- q = q.Where(p => p.City == provid);
- }
- q = q.Where(p => p.BUSINESSLEVEL > 1);
- var reslutd = q.ToList(res);
- if (reslutd.IsSuccess)
- {
- var modellist = reslutd.ResultModel; int i = 0;
- foreach (EntSYS_DISTRIBUTORS md in modellist)
- {
- i++; int j = 0;
- NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i);
- string saletype = (md.BUSINESSLEVEL == 2) ? "一级经销商" : "经销商仓库";
- rowtemp.CreateCell(j).SetCellValue(saletype);
- j++;
- rowtemp.CreateCell(j).SetCellValue(md.DealerNumber);
- j++;
- rowtemp.CreateCell(j).SetCellValue(md.NAME);
- j++;
- string Province = ""; string pro = md.Province.ToString();
- var resluts = orm.Queryable<MES.Production.Entity.SYS_CODE_AREA>().Where(p => p.ID == pro).FirstOrDefault(res);
- if (resluts.IsSuccess)
- {
- MES.Production.Entity.SYS_CODE_AREA mod = resluts.ResultModel;
- Province = mod.NAME;
- }
- rowtemp.CreateCell(j).SetCellValue(Province);//省
- j++;
- string City = ""; pro = md.Province.ToString();
- resluts = orm.Queryable<MES.Production.Entity.SYS_CODE_AREA>().Where(p => p.ID == pro).FirstOrDefault(res);
- if (resluts.IsSuccess)
- {
- MES.Production.Entity.SYS_CODE_AREA mod = resluts.ResultModel;
- City = mod.NAME;
- }
- rowtemp.CreateCell(j).SetCellValue(City);//市
- j++;
- string Area = ""; pro = md.Province.ToString();
- resluts = orm.Queryable<MES.Production.Entity.SYS_CODE_AREA>().Where(p => p.ID == pro).FirstOrDefault(res);
- if (resluts.IsSuccess)
- {
- MES.Production.Entity.SYS_CODE_AREA mod = resluts.ResultModel;
- Area = mod.NAME;
- }
- rowtemp.CreateCell(j).SetCellValue(Area);//区
- j++;
- rowtemp.CreateCell(j).SetCellValue(md.Address);//经销商地址
- j++;
- rowtemp.CreateCell(j).SetCellValue(md.FenceRadius);//围栏半径
- j++;
- rowtemp.CreateCell(j).SetCellValue(md.Theodolite);//围栏经纬度
- j++;
- resluts = orm.Queryable<MES.Production.Entity.Entity.En_SYS_USER>().Where(p => p.DPTID == md.ID).FirstOrDefault(res);//经销商负责人和手机
- if (resluts.IsSuccess)
- {
- En_SYS_USER usermod = resluts.ResultModel;
- rowtemp.CreateCell(j).SetCellValue(usermod.NAME);
- j++;
- rowtemp.CreateCell(j).SetCellValue(usermod.PHONE);
- j++;
- }
- else
- {
- rowtemp.CreateCell(j).SetCellValue("");
- j++;
- rowtemp.CreateCell(j).SetCellValue("");
- j++;
- }
- rowtemp.CreateCell(j).SetCellValue("");
- j++;
- var reslut = orm.Queryable<EntYW_UserDistributor>().Where(p => p.distributorId == md.ID).FirstOrDefault(res);//产品线负责人和手机
- if (reslut.IsSuccess)
- {
- string strid = string.Empty; string strname = string.Empty;
- EntYW_UserDistributor mod = reslut.ResultModel;
- int userid = mod.userId.ToInt32();
- var userreslut = orm.Queryable<En_SYS_USER>().Where(p => p.ID == userid).FirstOrDefault(res);
- if (userreslut.IsSuccess)
- {
- En_SYS_USER usermod = userreslut.ResultModel;
- if (mod.ProductLine == 601)
- {
- rowtemp.CreateCell(j).SetCellValue(usermod.NAME);
- j++;
- rowtemp.CreateCell(j).SetCellValue(usermod.PHONE);
- j++;
- }
- else
- {
- rowtemp.CreateCell(j).SetCellValue("");
- j++;
- rowtemp.CreateCell(j).SetCellValue("");
- j++;
- }
- if (mod.ProductLine2 == 612)
- {
- rowtemp.CreateCell(j).SetCellValue(usermod.NAME);
- j++;
- rowtemp.CreateCell(j).SetCellValue(usermod.PHONE);
- j++;
- }
- else
- {
- rowtemp.CreateCell(j).SetCellValue("");
- j++;
- rowtemp.CreateCell(j).SetCellValue("");
- j++;
- }
- if (mod.ProductLine4 == 622)
- {
- rowtemp.CreateCell(j).SetCellValue(usermod.NAME);
- j++;
- rowtemp.CreateCell(j).SetCellValue(usermod.PHONE);
- j++;
- }
- else
- {
- rowtemp.CreateCell(j).SetCellValue("");
- j++;
- rowtemp.CreateCell(j).SetCellValue("");
- j++;
- }
- }
- #region 不用
- //foreach (EntYW_UserDistributor mod in reslut.ResultModel)
- //{
- // int userid = mod.userId.ToInt32();
- // var userreslut = orm.Queryable<En_SYS_USER>().Where(p => p.ID == userid).FirstOrDefault(res);
- // if (userreslut.IsSuccess)
- // {
- // En_SYS_USER usermod = userreslut.ResultModel;
- // if (mod.ProductLine == 601)
- // {
- // rowtemp.CreateCell(j).SetCellValue(usermod.NAME);
- // j++;
- // rowtemp.CreateCell(j).SetCellValue(usermod.PHONE);
- // j++;
- // }
- // else
- // {
- // rowtemp.CreateCell(j).SetCellValue("");
- // j++;
- // rowtemp.CreateCell(j).SetCellValue("");
- // j++;
- // }
- // if (mod.ProductLine2 == 612)
- // {
- // rowtemp.CreateCell(j).SetCellValue(usermod.NAME);
- // j++;
- // rowtemp.CreateCell(j).SetCellValue(usermod.PHONE);
- // j++;
- // }
- // else
- // {
- // rowtemp.CreateCell(j).SetCellValue("");
- // j++;
- // rowtemp.CreateCell(j).SetCellValue("");
- // j++;
- // }
- // if (mod.ProductLine4 == 622)
- // {
- // rowtemp.CreateCell(j).SetCellValue(usermod.NAME);
- // j++;
- // rowtemp.CreateCell(j).SetCellValue(usermod.PHONE);
- // j++;
- // }
- // else
- // {
- // rowtemp.CreateCell(j).SetCellValue("");
- // j++;
- // rowtemp.CreateCell(j).SetCellValue("");
- // j++;
- // }
- // }
- //}
- #endregion
- }
- else
- {
- rowtemp.CreateCell(j).SetCellValue("");
- j++;
- rowtemp.CreateCell(j).SetCellValue("");
- j++;
- rowtemp.CreateCell(j).SetCellValue("");
- j++;
- rowtemp.CreateCell(j).SetCellValue("");
- j++;
- rowtemp.CreateCell(j).SetCellValue("");
- j++;
- rowtemp.CreateCell(j).SetCellValue("");
- j++;
- }
- }
- }
- }
- if (namelist.Count > 0)
- {
- 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 q = orm.Queryable<EntYW_Bicycle>();
- if (!CarSate.IsEmpty())
- {
- int state = CarSate.ToInt32();
- q = q.Where(p => namelist.Contains(p.DistributorsID) && p.CarSate == state);
- }
- else
- {
- q = q.Where(p => namelist.Contains(p.DistributorsID));
- }
- var reslut = q.ToList(res);
- if (reslut.IsSuccess)
- {
- List<EntYW_Bicycle> modlist = reslut.ResultModel;
- for (int i = 0; i < modlist.Count; i++)
- {
- NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1);
- rowtemp.CreateCell(0).SetCellValue(modlist[i].CarID);
- rowtemp.CreateCell(1).SetCellValue(modlist[i].CarName);
- rowtemp.CreateCell(2).SetCellValue(modlist[i].carBar);
- rowtemp.CreateCell(3).SetCellValue(modlist[i].DistributorsName);
- string carstatestr = "";
- switch (modlist[i].CarSate)
- {
- case 0:
- carstatestr = "未绑定"; break;
- case 1:
- carstatestr = "已绑定"; break;
- case 2:
- carstatestr = "已出库"; break;
- case 3:
- carstatestr = "在途中"; break;
- case 4:
- carstatestr = "已入库"; break;
- case 5:
- carstatestr = "已销售"; break;
- case 6:
- carstatestr = "退货中"; break;
- case 7:
- carstatestr = "调拨中"; break;
- case 8:
- carstatestr = "返厂中"; break;
- }
- rowtemp.CreateCell(4).SetCellValue(carstatestr);
- rowtemp.CreateCell(5).SetCellValue(modlist[i].productionDate.ToString());
- //rowtemp.CreateCell(5).SetCellValue(list[i].iName);
- //rowtemp.CreateCell(6).SetCellValue(list[i].iPhone);
- //rowtemp.CreateCell(7).SetCellValue(list[i].IntegralSum);
- //rowtemp.CreateCell(8).SetCellValue(list[i].IntegralSy);
- //rowtemp.CreateCell(9).SetCellValue(list[i].IntegralKy);
- }
- }
- }
- }
- // 写入到客户端
- System.IO.MemoryStream ms = new System.IO.MemoryStream();
- book.Write(ms);
- ms.Seek(0, SeekOrigin.Begin);
- return File(ms, "application/vnd.ms-excel", "经销商库存信息.xls");
- }
- /// <summary>
- /// 获取经纬度地址
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public ActionResult getLatLntAdderss(string latlntstr)
- {
- var json = new JsonHelper() { Status = "y", Msg = "Success" };
- if (latlntstr.IndexOf(',') > 0)
- {
- try
- {
- var lng = latlntstr.Split(',')[0]; var lat = latlntstr.Split(',')[1];
- var resaddress = ToolGPSamap.GPSToPositionString(lng.ToDou(), lat.ToDou());
- json.Data = resaddress;
- }
- catch (Exception ex)
- {
- json.Status = "n";
- json.Msg = "经纬度必须用英文的逗分隔开,经度在前,纬度在后!";
- }
- }
- else
- {
- json.Status = "n";
- json.Msg = "经纬度必须用英文的逗分隔开,经度在前,纬度在后!";
- }
- return Json(json);
- }
- /// <summary>
- /// 加载详情页
- /// </summary>
- [HttpGet]
- [UserAuthorizeAttribute(ModuleAlias = "SalesDealersList", OperaAction = "Detail")]
- public ActionResult Detail(string id)
- {
- try
- {
- string filePathName = string.Empty;
- DistributorUser distributorUser = new DistributorUser();
- SYS_DISTRIBUTORS entity = new SYS_DISTRIBUTORS();
- int uid = 0;
- if (CurrentUser.USERTYPE == 2)
- {
- uid = CurrentUser.Id;
- ViewData["usertype"] = CurrentUser.USERTYPE.ToString();
- }
- else
- {
- ViewData["usertype"] = "0";
- }
- ViewBag.moduleparent = this.DepartmentManage.GetDepartmentByDetailNew(uid);
- //添加子部门
- string parentId = Request.QueryString["parentId"];
- if (!string.IsNullOrEmpty(parentId))
- {
- //entity.PARENTID = parentId;
- distributorUser.distributorInfo.PARENTID = parentId;
- return View(distributorUser);
- }
- if (!string.IsNullOrEmpty(id))
- {
- entity = this.DepartmentManage.Get(p => p.ID == id);
- distributorUser.distributorInfo = entity;
- 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 = "获取公告信息" }
- };
- if (CurrentUser.USERTYPE == 2)
- {
- int userid = CurrentUser.Id;
- var reslut = orm.Queryable<EntYW_UserDistributor>().Where(p => p.distributorId == id && p.userId == userid).FirstOrDefault(res);
- if (reslut.IsSuccess)
- {
- EntYW_UserDistributor mod = reslut.ResultModel;
- if (mod.ProductLine == 601)
- {
- ViewData["line1"] = true;
- }
- if (mod.ProductLine == 615)
- {
- ViewData["line2"] = true;
- }
- if (mod.ProductLine == 612)
- {
- ViewData["line3"] = true;
- }
- if (mod.ProductLine == 611)
- {
- ViewData["line4"] = true;
- }
- if (mod.ProductLine == 622)
- {
- ViewData["line5"] = true;
- }
- if (mod.ProductLine == 628)
- {
- ViewData["line6"] = true;
- }
- }
- }
- else
- {
- //IQuery<EntYW_UserDistributor> q = orm.Queryable<EntYW_UserDistributor>();
- //IGroupingQuery<EntYW_UserDistributor> group = q.Where(a => a.distributorId == id).GroupBy(a => a.userId);
- //var re = group.Select(a => new { a.userId }).ToList(res);
- //if (re.IsSuccess)
- //{
- // string strid = string.Empty; string strname = string.Empty;
- // foreach (var mod in re.ResultModel)
- // {
- // int userid = mod.userId;
- // var userreslut = orm.Queryable<En_SYS_USER>().Where(p => p.ID == userid).FirstOrDefault(res);
- // if (userreslut.IsSuccess)
- // {
- // En_SYS_USER usermod = userreslut.ResultModel;
- // if (strid.IsEmpty())
- // {
- // strid += usermod.ID;
- // strname += usermod.NAME;
- // }
- // else
- // {
- // strid += ";" + usermod.ID;
- // strname += ";" + usermod.NAME;
- // }
- // }
- // }
- // ViewData["userid"] = strid + "|" + strname;
- //}
- }
- var usereslut = orm.Queryable<En_SYS_USER>().Where(p => p.DPTID == entity.ID).FirstOrDefault(res);
- if (usereslut.IsSuccess)
- {
- distributorUser.userInfo = usereslut.ResultModel;
- }
- }
- }
- else
- {
- distributorUser.distributorInfo = new SYS_DISTRIBUTORS();
- distributorUser.distributorInfo.PARENTID = "32f7a4bd-84de-4587-be29-734d65ad6f70";
- distributorUser.userInfo = new En_SYS_USER() { ISCANLOGIN = false };
- }
- // ViewData["line1"] = true;
- return View(distributorUser);
- }
- catch (Exception e)
- {
- WriteLog(enumOperator.Select, "经销商管理加载详情页:", e);
- throw e.InnerException;
- }
- }
- /// <summary>
- /// 保存部门
- /// </summary>
- [ValidateInput(false)]
- [UserAuthorizeAttribute(ModuleAlias = "SalesDealersList", OperaAction = "Add,Edit")]
- public ActionResult Save(DistributorUser entity)
- {
- bool isEdit = false; bool bz = true;
- var fileid = Request.Form["hidfileid"];
- var fileurl = Request.Form["hidfilename"];
- var paretid = Request.Form["PARENTID"];
- int userid = 0;
- var citystr = Request.Form["hkprov"] + "," + Request.Form["hkcity"] + "," + Request.Form["hkcountry"];
- var json = new JsonHelper() { Msg = "保存成功", Status = "n" };
- //先取消电子围栏
- if (entity.distributorInfo.Theodolite.IsEmpty())
- {
- json.Msg = "经纬度不能为空";
- return Json(json);
- }
- if (entity.distributorInfo.Theodolite.IndexOf(',') <= 0)
- {
- json.Msg = "经纬度必须用英文的逗分隔开,经度在前,纬度在后!";
- return Json(json);
- }
- if (Request.Form["hkprov"].IsEmpty())
- {
- json.Msg = "所属省不能为空!";
- return Json(json);
- }
- if (Request.Form["hkcity"].IsEmpty())
- {
- json.Msg = "所属市不能为空!";
- return Json(json);
- }
- if (Request.Form["hkcountry"].IsEmpty())
- {
- json.Msg = "所属区不能为空!";
- return Json(json);
- }
- var lng = entity.distributorInfo.Theodolite.Split(',')[0]; var lat = entity.distributorInfo.Theodolite.Split(',')[1];
- var resaddress = ToolGPSamap.GPSToPositionString(lng.ToDou(), lat.ToDou());
- if (resaddress.IsEmpty())
- {
- json.Msg = "经纬度不正确!";
- return Json(json);
- }
- try
- {
- var parententity = new SYS_DISTRIBUTORS();
- if (!string.IsNullOrEmpty(paretid))
- {
- parententity = this.DepartmentManage.Get(p => p.ID == paretid);
- }
- var _entity = new SYS_DISTRIBUTORS(); var _userenty = new En_SYS_USER(); //当前经销商和用户
- string guid = Guid.NewGuid().ToString();
- 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 = "获取公告信息" }
- };
- if (entity.distributorInfo != null)
- {
- if (!string.IsNullOrEmpty(entity.distributorInfo.ID))
- {
- guid = entity.distributorInfo.ID;
- // var disreult = orm.DeleteByLambda<EntYW_UserDistributor>(p => p.distributorId == entity.distributorInfo.ID, res);
- }
- else
- {
- guid = Guid.NewGuid().ToString();
- }
- }
- else
- {
- guid = Guid.NewGuid().ToString();
- }
- }
- if (entity.distributorInfo != null)
- {
- if (!string.IsNullOrEmpty(entity.distributorInfo.ID))
- {
- #region 修改
- _entity = this.DepartmentManage.Get(p => p.ID == entity.distributorInfo.ID);
- entity.distributorInfo.CREATEDATE = _entity.CREATEDATE;
- entity.distributorInfo.CREATEPERID = _entity.CREATEPERID;
- entity.distributorInfo.PARENTID = paretid;
- entity.distributorInfo.UPDATEDATE = DateTime.Now;
- entity.distributorInfo.UPDATEUSER = this.CurrentUser.Name;
- entity.distributorInfo.Address = Request.Form["distributorInfo.Address"];
- entity.distributorInfo.FenceRadius = Request.Form["example_length"].ToInt32();
- entity.distributorInfo.LICENSEURL = fileurl;
- entity.distributorInfo.LICENSEVALUE = fileid;
- entity.distributorInfo.ProvinceCity = citystr;
- entity.distributorInfo.Province = Request.Form["hkprov"].ToInt32();
- entity.distributorInfo.City = Request.Form["hkcity"].ToInt32();
- entity.distributorInfo.Area = Request.Form["hkcountry"].ToInt32();
- if (entity.distributorInfo.PARENTID != _entity.PARENTID)
- {
- entity.distributorInfo.CODE = this.DepartmentManage.CreateCode(entity.distributorInfo.PARENTID);
- }
- else
- {
- entity.distributorInfo.CODE = _entity.CODE;
- }
- isEdit = true;
- //获取父级记录
- if (string.IsNullOrEmpty(paretid))
- {
- //业务等级
- entity.distributorInfo.BUSINESSLEVEL = 1;
- entity.distributorInfo.PARENTCODE = null;
- }
- else
- {
- entity.distributorInfo.BUSINESSLEVEL = parententity.BUSINESSLEVEL + 1;
- entity.distributorInfo.PARENTCODE = parententity.CODE;
- entity.distributorInfo.ParentName = parententity.NAME;
- if (entity.distributorInfo.BUSINESSLEVEL == 2)
- {
- _userenty = entity.userInfo;
- _userenty.ACCOUNT = _userenty.PHONE;
- _userenty.USERTYPE = 3;
- 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 resuser = orm.UpdateById(_userenty, res);
- }
- }
- else
- {
- 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 disreult = orm.Queryable<EntYW_UserDistributor>().Where(p => p.distributorId == paretid).ToList();
- foreach (EntYW_UserDistributor usermod in disreult.ResultModel)
- {
- var count = orm.Queryable<EntYW_UserDistributor>().Where(p => p.distributorId == usermod.distributorId && p.userId == usermod.userId).Count();
- if (count == 0)
- {
- EntYW_UserDistributor entdis = new EntYW_UserDistributor();
- entdis.userId = usermod.userId;
- entdis.distributorId = guid;
- entdis.ID = Guid.NewGuid();
- var reslutdis = orm.Save(entdis, res);
- }
- }
- }
- }
- }
- #endregion
- _entity = entity.distributorInfo;
- }
- else
- {
- if (entity.distributorInfo.PARENTID == "32f7a4bd-84de-4587-be29-734d65ad6f70")
- {
- if (entity.userInfo.PHONE.IsEmpty())
- {
- json.Msg = "经销商联系人和电话不能为空!";
- return Json(json);
- }
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- var disnum = orm.Queryable<EntSYS_DISTRIBUTORS>().Where(p => p.DealerNumber == entity.distributorInfo.DealerNumber && p.PARENTID == "32f7a4bd-84de-4587-be29-734d65ad6f70").Count();
- if (disnum > 0)
- {
- json.Msg = "经销商一级点只能添加一个!";
- return Json(json);
- }
- }
- }
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- var disnum = orm.Queryable<EntSYS_DISTRIBUTORS>().Where(p => p.NAME == entity.distributorInfo.NAME).Count();
- if (disnum > 0)
- {
- json.Msg = "经销商名称已经存不能添加";
- return Json(json);
- }
- }
- #region 添加
- _entity = entity.distributorInfo;
- _entity.ID = guid;
- _entity.CREATEDATE = DateTime.Now;
- _entity.CREATEPERID = this.CurrentUser.Name;
- _entity.PARENTID = paretid;
- _entity.UPDATEDATE = DateTime.Now;
- _entity.UPDATEUSER = this.CurrentUser.Name;
- _entity.Address = entity.distributorInfo.Address;
- _entity.FenceRadius = Request.Form["example_length"].ToInt32();
- _entity.LICENSEURL = fileurl;
- _entity.LICENSEVALUE = fileid;
- _entity.ProvinceCity = citystr;
- _entity.Province = Request.Form["hkprov"].ToInt32();
- _entity.City = Request.Form["hkcity"].ToInt32();
- _entity.Area = Request.Form["hkcountry"].ToInt32();
- //根据上级部门的ID确定当前部门的CODE
- _entity.CODE = this.DepartmentManage.CreateCode(_entity.PARENTID);
- //获取父级记录
- if (string.IsNullOrEmpty(_entity.PARENTID))
- {
- //业务等级
- entity.distributorInfo.BUSINESSLEVEL = 1;
- entity.distributorInfo.PARENTCODE = null;
- }
- else
- {
- entity.distributorInfo.BUSINESSLEVEL = parententity.BUSINESSLEVEL + 1;
- entity.distributorInfo.PARENTCODE = parententity.CODE;
- entity.distributorInfo.ParentName = parententity.NAME;
- if (entity.distributorInfo.BUSINESSLEVEL == 2)
- {
- if (!_userenty.PHONE.IsEmpty())
- {
- _userenty = entity.userInfo;
- _userenty.DPTID = _entity.ID;
- var pwd = PasswordUtils.MD5_Encrypt("111111", 32);
- _userenty.USERTYPE = 3;
- _userenty.ACCOUNT = _userenty.PHONE;
- _userenty.PASSWORD = pwd;
- _userenty.CREATEDATE = DateTime.Now;
- _userenty.CREATEPER = this.CurrentUser.Name;
- _userenty.UPDATEDATE = DateTime.Now;
- _userenty.UPDATEUSER = this.CurrentUser.Name;
- 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 resuser = orm.SaveHaveNull(_userenty, res);
- }
- }
- }
- }
- #endregion
- }
- if (entity.userInfo.ID.IfNotNull())
- {
- EntSYS_USER_ROLE roleMod = new EntSYS_USER_ROLE();
- 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 = "获取公告信息" }
- };
- int uid = _userenty.ID.ToInt32();
- var reslutrolse = orm.Queryable<EntSYS_USER_ROLE>().Where(p => p.FK_USERID == uid && p.FK_ROLEID == 3).FirstOrDefault(res);
- if (reslutrolse.IsSuccess)
- {
- }
- else
- {
- int ROLEID = 0; var usertype = CurrentUser.USERTYPE;
- switch ((PostType)usertype)
- {
- case PostType.SalesClerk:
- {
- ROLEID = 2;
- }
- break;
- case PostType.Distributors:
- {
- ROLEID = 3;
- }
- break;
- case PostType.Warehouse:
- {
- ROLEID = 4;
- }
- break;
- case PostType.ThreePacksStaff:
- {
- ROLEID = 6;
- }
- break;
- case PostType.MarketingAdmin:
- {
- ROLEID = 7;
- }
- break;
- }
- //roleMod.FK_ROLEID = ROLEID;
- roleMod.FK_ROLEID = 3;
- roleMod.FK_USERID = uid;
- orm.Save(roleMod, res);
- }
- }
- }
- }
- //先取消电子围栏
- if (entity.distributorInfo.Theodolite.IsEmpty())
- {
- var addressmod = AddressToGPS(entity.distributorInfo.Address);
- if (addressmod.Geocodes.Count > 0)
- {
- foreach (Geocode mod in addressmod.Geocodes)
- {
- string lnglatstr = mod.Location;
- _entity.Theodolite = lnglatstr;
- }
- }
- }
- else
- {
- _entity.Theodolite = entity.distributorInfo.Theodolite;
- }
- //判断同一个部门下,是否重名
- var predicate = PredicateBuilder.True<SYS_DISTRIBUTORS>();
- predicate = predicate.And(p => p.PARENTID == _entity.PARENTID);
- predicate = predicate.And(p => p.NAME == _entity.NAME);
- predicate = predicate.And(p => p.ID != _entity.ID);
- if (!this.DepartmentManage.IsExist(predicate))
- {
- if (this.DepartmentManage.SaveOrUpdate(_entity, isEdit))
- {
- json.Status = "y";
- try
- {
- if (CurrentUser.USERTYPE == 2)
- {
- var productline1 = Request.Form["ckb_per"];
- 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 count = orm.Queryable<EntYW_UserDistributor>().Where(p => p.distributorId == guid && p.userId == CurrentUser.Id).Count();
- if (count == 0)
- {
- EntYW_UserDistributor userdismod = new EntYW_UserDistributor();
- userdismod.ID = Guid.NewGuid();
- userdismod.userId = CurrentUser.Id;
- userdismod.distributorId = guid;
- if (productline1.IndexOf("601") >= 0)
- userdismod.ProductLine = 601;
- if (productline1.IndexOf("615") >= 0)
- userdismod.ProductLine1 = 615;
- if (productline1.IndexOf("612") >= 0)
- userdismod.ProductLine2 = 612;
- if (productline1.IndexOf("611") >= 0)
- userdismod.ProductLine3 = 611;
- if (productline1.IndexOf("622") >= 0)
- userdismod.ProductLine4 = 622;
- if (productline1.IndexOf("628") >= 0)
- userdismod.ProductLine5 = 628;
- userdismod.add_name = "系统导入";
- var reslut1 = orm.Save(userdismod, res);
- }
- }
- }
- //string imei = "356802032734930";
- string imei = "333333333333333";
- string discode = Ant.SuperSocket.Common.DataHelper.StringToHex(_entity.CODE);
- var str = Ant.SuperSocket.Common.DataHelper.sendCarData(Convert.ToInt64(imei), "9922" + discode);
- var body = Ant.SuperSocket.Common.DataHelper.HexToByte(str);
- SocketClient client = new SocketClient();
- string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString();
- // string ip = "";
- int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32();
- client.Connect(ip, port);
- var flag = client.SendData(body);
- client.Disconnect();
- }
- catch (Exception ex) { }
- }
- else
- {
- json.Msg = "保存失败";
- }
- }
- else
- {
- json.Msg = "经销商" + entity.distributorInfo.NAME + "已存在,不能重复添加";
- }
- if (isEdit)
- {
- WriteLog(enumOperator.Edit, "修改经销商信息,结果:" + json.Msg, enumLog4net.INFO);
- }
- else
- {
- WriteLog(enumOperator.Add, "添加经销商信息,结果:" + json.Msg, enumLog4net.INFO);
- }
- }
- catch (Exception e)
- {
- json.Msg = "保存经销商信息发生内部错误!";
- WriteLog(enumOperator.None, "保存经销商信息:", e);
- }
- return Json(json);
- }
- /// <summary>
- /// 将地址转GPS
- /// </summary>
- /// <param name="address"></param>
- /// <returns></returns>
- private AddressGPS AddressToGPS(string address)
- {
- System.Net.WebClient server = new System.Net.WebClient();
- string url = String.Format("http://restapi.amap.com/v3/geocode/geo?key={0}&address={1}&city={2}", "fa36ec6323075f37020083ceffe8eb24", address, "");
- var replyBuffer = server.DownloadData(url);
- var reply = System.Text.Encoding.UTF8.GetString(replyBuffer);
- var mod = Newtonsoft.Json.JsonConvert.DeserializeObject<AddressGPS>(reply);
- return mod;
- }
- /// <summary>
- /// 删除部门
- /// </summary>
- [UserAuthorizeAttribute(ModuleAlias = "SalesDealersList", OperaAction = "Remove")]
- public ActionResult Delete(string idList)
- {
- JsonHelper json = new JsonHelper() { Msg = "删除经销商成功", ReUrl = "/Distributors/SalesDealersList", Status = "n" };
- try
- {
- if (!string.IsNullOrEmpty(idList))
- {
- idList = idList.TrimEnd(',');
- //判断是否有下属部门
- if (!this.DepartmentManage.DepartmentIsExists(idList))
- {
- //判断是否有用户归属该部门
- if (!this.UserDepartmentManage.IsExist(p => idList.Contains(p.DEPARTMENT_ID)))
- {
- //判断该部门是否有岗位
- if (!this.PostDepartmentManage.IsExist(p => idList.Contains(p.FK_DEPARTMENT_ID)))
- {
- var idList1 = idList.Split(',').ToList();
- this.DepartmentManage.Delete(p => idList.Contains(p.ID));
- 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()
- };
- var disreult = orm.DeleteByLambda<EntYW_UserDistributor>(p => p.distributorId == id, request);
- var userreult = orm.Queryable<En_SYS_USER>().Where(p => p.DPTID == id).FirstOrDefault(request);
- if (userreult.IsSuccess)
- {
- En_SYS_USER moduser = userreult.ResultModel;
- var rolereult = orm.DeleteByLambda<EntSYS_USER_ROLE>(p => p.FK_USERID == moduser.ID, request);
- var usreult = orm.DeleteByLambda<En_SYS_USER>(p => p.DPTID == id, request);
- }
- }
- }
- json.Status = "y";
- }
- else
- {
- json.Msg = "该经销商有岗位信息不能删除,请先取消岗位分配";
- }
- }
- else
- {
- json.Msg = "该经销商存在用户不能删除";
- }
- }
- else
- {
- json.Msg = "该经销商有下属部门不能删除";
- }
- }
- else
- {
- json.Msg = "未找到要删除的部门记录";
- }
- WriteLog(enumOperator.Remove, "删除部门:" + json.Msg, enumLog4net.WARN);
- }
- catch (Exception e)
- {
- json.Msg = "删除经销商发生内部错误!";
- WriteLog(enumOperator.Remove, "删除部门:", e);
- }
- return Json(json);
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public ActionResult FenceInfo(string id)
- {
- EntSYS_DISTRIBUTORS mod = new EntSYS_DISTRIBUTORS();
- 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 q = orm.Queryable<EntSYS_DISTRIBUTORS>();
- if (!id.IsEmpty())
- {
- var reslut = q.Where(p => p.ID == id).FirstOrDefault(res);
- if (reslut.IsSuccess)
- {
- mod = reslut.ResultModel;
- }
- }
- }
- return View(mod);
- }
- /// <summary>
- /// 加载列表
- /// </summary>
- /// <returns></returns>
- [UserAuthorizeAttribute(ModuleAlias = "Department", OperaAction = "View")]
- public ActionResult InventoryList()
- {
- try
- {
- #region 处理查询参数
- string posttype = Request.QueryString["posttype"];
- string FK_DPTID = Request.QueryString["FK_DPTID"];
- #endregion
- #region 加载列表
- var result = BindList(posttype, FK_DPTID, CurrentUser.USERTYPE);
- ViewBag.Search = base.keywords;
- // ViewData["PostType"] = this.CodeManage.GetCode("POSTTYPE");
- //ViewData["post"] = posttype;
- ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew();
- ViewData["dptid"] = FK_DPTID;
- #endregion
- if (result.IsNull())
- {
- return View();
- }
- else
- {
- if (!Request.QueryString["hkprov"].IsEmpty())
- {
- ViewData["hkprov"] = Request.QueryString["hkprov"];
- }
- if (!Request.QueryString["hkcity"].IsEmpty())
- {
- ViewData["hkcity"] = Request.QueryString["hkcity"];
- }
- if (!Request.QueryString["hkcountry"].IsEmpty())
- {
- ViewData["hkcountry"] = Request.QueryString["hkcountry"];
- }
- return View(result);
- }
- }
- catch (Exception e)
- {
- WriteLog(enumOperator.Select, "加载岗位列表:", e);
- throw e.InnerException;
- }
- }
- /// <summary>
- ///
- /// </summary>
- [UserAuthorizeAttribute(ModuleAlias = "SalesDealersList", OperaAction = "View")]
- public ActionResult SalesDealersList()
- {
- try
- {
- #region 处理查询参数
- string posttype = Request.QueryString["posttype"];
- string FK_DPTID = Request.QueryString["FK_DPTID"];
- #endregion
- #region 加载列表
- var result = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<EntSYS_DISTRIBUTORS>()));
- int uid = 0;
- if (CurrentUser.USERTYPE == 0 || CurrentUser.USERTYPE == 8)
- {
- result = BindList(posttype, FK_DPTID, CurrentUser.USERTYPE);
- }
- else
- {
- uid = CurrentUser.Id;
- result = SalesDistributionBindList(posttype, FK_DPTID);
- }
- ViewBag.Search = base.keywords;
- // ViewData["PostType"] = this.CodeManage.GetCode("POSTTYPE");
- //ViewData["post"] = posttype;
- ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew(uid);
- ViewData["dptid"] = FK_DPTID;
- ViewData["saleId"] = CurrentUser.Id.ToString();
- #endregion
- if (!Request.QueryString["hkprov"].IsEmpty())
- {
- ViewData["hkprov"] = Request.QueryString["hkprov"];
- }
- if (!Request.QueryString["hkcity"].IsEmpty())
- {
- ViewData["hkcity"] = Request.QueryString["hkcity"];
- }
- if (!Request.QueryString["hkcountry"].IsEmpty())
- {
- ViewData["hkcountry"] = Request.QueryString["hkcountry"];
- }
- if (result.IsNull())
- {
- return View();
- }
- else
- {
- return View(result);
- }
- }
- catch (Exception e)
- {
- WriteLog(enumOperator.Select, "加载岗位列表:", e);
- throw e.InnerException;
- }
- }
- /// <summary>
- /// 修改密码页面窗体
- /// </summary>
- // [UserAuthorizeAttribute(ModuleAlias = "Department", OperaAction = "UserPassword")]
- public ActionResult PasswordSet()
- {
- if (!string.IsNullOrEmpty(this.CurrentUser.Name))
- {
- var entity = this.UserManage.Get(p => p.ID == CurrentUser.Id);
- return View(entity);
- }
- return View();
- }
- /// <summary>
- /// 修改密码功能实现函数
- /// </summary>
- public ActionResult PasswordSave()
- {
- JsonHelper json = new JsonHelper() { Msg = "修改密码完成", Status = "n" };
- var ID = Request.Form["ID"] ?? "";
- if (string.IsNullOrEmpty(ID))
- {
- json.Msg = "请登录";
- return Json(json);
- }
- string OldPassword = Request.Form["oldpass"];
- string NewPassword = Request.Form["newpass"];
- string confPassword = Request.Form["confpass"];
- int newid = int.Parse(ID);
- var entity = this.UserManage.Get(p => p.ID == newid);
- var pwd = PasswordUtils.MD5_Encrypt(NewPassword, 32);// Ant.Service.Common.CryptHelper.DESCrypt.Encrypt("111111")
- entity.PASSWORD = pwd;
- //entity.PASSWORD = Ant.Service.Common.CryptHelper.DESCrypt.Encrypt(NewPassword);
- try
- {
- this.UserManage.Update(entity);
- json.Status = "y";
- WriteLog(enumOperator.Edit, "修改密码:" + json.Msg, enumLog4net.INFO);
- return Json(json);
- }
- catch (Exception e)
- {
- json.Msg = e.Message;
- WriteLog(enumOperator.Edit, "修改密码错误:", e);
- return Json(json);
- }
- }
- /// <summary>
- /// 修改密码前检测旧密码是否正确
- /// </summary>
- public ActionResult CheckoldPass(string oldPassword)
- {
- JsonHelper json = new JsonHelper() { Msg = "Success", Status = "n" };
- string id = Request.Form["ID"];
- string oldpass = Request.Form["oldpass"];
- if (string.IsNullOrEmpty(id))
- {
- json.Msg = "未找到要处理的用户";
- return Json(json);
- }
- var pass = PasswordUtils.MD5_Encrypt(oldpass, 32);
- //var pass = Ant.Service.Common.CryptHelper.DESCrypt.Encrypt(oldpass);
- int newid = int.Parse(id);
- var result = this.UserManage.IsExist(p => p.ID == newid && p.PASSWORD.Equals(pass));
- if (!result)
- {
- json.Msg = "原始密码错误";
- return Json(json);
- }
- json.Status = "y";
- return Json(json);
- }
- /// <summary>
- /// 绑定页面需要的属性
- /// </summary>
- public PageInfo SalesDistributionBindList(string posttype, string FK_DPTID)
- {
- //var citystr = Request.QueryString["hkprov"] + "," + Request.QueryString["hkcity"] + "," + Request.QueryString["hkcountry"];
- string saleid = CurrentUser.Id.ToString();
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel request = new RequestModel();
- request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
- var dis = orm.Queryable<EntSYS_DISTRIBUTORS>();
- var userdis = orm.Queryable<EntYW_UserDistributor>();
- IJoiningQuery<EntSYS_DISTRIBUTORS, EntYW_UserDistributor> view = dis.LeftJoin(userdis, (user, city) => user.ID == city.distributorId);
- int uid = saleid.ToInt32();
- var q = view.Select((user, city) => new { Users = user, Citys = city }).Where(a => a.Citys.userId == uid);
- //var q = orm.Queryable<EntSYS_DISTRIBUTORS>();
- if (!keywords.IsEmpty())
- {
- q = q.Where(p => p.Users.NAME.Contains(keywords) && p.Users.BUSINESSLEVEL > 1);
- }
- else
- {
- q = q.Where(p => p.Users.BUSINESSLEVEL > 1);
- }
- if (!Request.QueryString["hkprov"].IsEmpty())
- {
- int Province = Request.QueryString["hkprov"].ToInt32();
- q = q.Where(p => p.Users.Province == Province);
- }
- if (!Request.QueryString["hkcity"].IsEmpty())
- {
- int City = Request.QueryString["hkcity"].ToInt32();
- q = q.Where(p => p.Users.City == City);
- }
- if (!Request.QueryString["hkcountry"].IsEmpty())
- {
- int Area = Request.QueryString["hkcountry"].ToInt32();
- q = q.Where(p => p.Users.Area == Area);
- }
- int pageno = (page - 1) * pagesize;
- var disreslut = q.OrderBy(a => a.Users.CODE).Skip(pageno).Top(pagesize).ToList(request);
- if (disreslut.IsSuccess)
- {
- disreslut.RecordNum = q.Count();
- List<EntSYS_DISTRIBUTORS> modlist = new List<EntSYS_DISTRIBUTORS>();
- foreach (var item in disreslut.ResultModel)
- {
- modlist.Add(item.Users);
- }
- return new PageInfo(base.page, base.pagesize, disreslut.RecordNum, JsonConverter.JsonClass(modlist));
- }
- else
- {
- return new PageInfo(base.page, base.pagesize, disreslut.RecordNum, JsonConverter.JsonClass(new List<EntSYS_DISTRIBUTORS>()));
- }
- }
- //return new PageInfo(result.Index, result.PageSize, result.Count, JsonConverter.JsonClass(list));
- }
- /// <summary>
- /// 绑定页面需要的属性
- /// </summary>
- public PageInfo BindList(string posttype, string FK_DPTID, int usertype)
- {
- //var citystr = Request.QueryString["hkprov"] + "," + Request.QueryString["hkcity"] + "," + Request.QueryString["hkcountry"];
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel request = new RequestModel();
- request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
- var q = orm.Queryable<EntSYS_DISTRIBUTORS>();
- if (!keywords.IsEmpty())
- {
- q = q.Where(p => p.NAME.Contains(keywords) && p.BUSINESSLEVEL > 1);
- }
- else
- {
- q = q.Where(p => p.BUSINESSLEVEL > 1);
- }
- if (!Request.QueryString["hkprov"].IsEmpty())
- {
- int Province = Request.QueryString["hkprov"].ToInt32();
- q = q.Where(p => p.Province == Province);
- }
- if (!Request.QueryString["hkcity"].IsEmpty())
- {
- int City = Request.QueryString["hkcity"].ToInt32();
- q = q.Where(p => p.City == City);
- }
- if (!Request.QueryString["hkcountry"].IsEmpty())
- {
- int Area = Request.QueryString["hkcountry"].ToInt32();
- q = q.Where(p => p.Area == Area);
- }
- if (usertype == 8)//风控管理员
- {
- q = q.Where(p => p.FenceRadius > 0);
- }
- int pageno = (page - 1) * pagesize;
- var reslut = q.OrderBy(a => a.CODE).Skip(pageno).Top(pagesize).ToList(request);
- //foreach (EntSYS_DISTRIBUTORS mod in reslut.ResultModel)
- //{
- // //mod.NAME = GetModuleName(mod.NAME, mod.BUSINESSLEVEL - 1).ToString();
- // mod.NAME = mod.NAME;
- // modlist.Add(mod);
- //}
- //var reslut= orm.SqlQuery<YW_Bicycle>(string.Format("select top {0} * from YW_Bicycle where Id>@Id", 1), new { Id = "sfdfdfdf" }).ToList();
- if (reslut.IsSuccess)
- {
- reslut.RecordNum = q.Count();
- List<EntSYS_DISTRIBUTORS> modlist = new List<EntSYS_DISTRIBUTORS>();
- modlist = reslut.ResultModel;
- return new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(modlist));
- }
- else
- {
- return new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(new List<EntSYS_DISTRIBUTORS>()));
- }
- }
- //return new PageInfo(result.Index, result.PageSize, result.Count, JsonConverter.JsonClass(list));
- }
- /// <summary>
- /// 显示错层方法
- /// </summary>
- private object GetModuleName(string name, decimal? level)
- {
- if (level > 0)
- {
- string nbsp = " ";
- for (int i = 0; i < level; i++)
- {
- nbsp += " ";
- }
- name = nbsp + " |--" + name;
- }
- return name;
- }
- }
- }
|