DistributorsController.cs 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576
  1. using Ant.Data;
  2. using Ant.ORM;
  3. using Ant.Service.Common;
  4. using Ant.Service.Common.Enums;
  5. using Central.Control.Domain;
  6. using MES.Production.Entity;
  7. using MES.Production.Entity.Entity;
  8. using MES.Production.Entity.Enum;
  9. using MES.Production.Service.IService;
  10. using MES.Production.Service.ServiceImp;
  11. using Ant.Service.Utility;
  12. using ChangFa.Machinery.WebPage.Controllers;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Data;
  16. using System.IO;
  17. using System.Linq;
  18. using System.Web;
  19. using System.Web.Mvc;
  20. using JsonHelper = Ant.Service.Common.JsonHelper;
  21. using Ant.SuperSocket.Common;
  22. namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
  23. {
  24. public class DistributorsController : BaseController
  25. {
  26. /// <summary>
  27. /// 字典编码
  28. /// </summary>
  29. ICodeManage CodeManage = new CodeManage();
  30. /// <summary>
  31. /// 部门
  32. /// </summary>
  33. IDepartmentManage DepartmentManage = new DepartmentManage();
  34. /// <summary>
  35. /// 用户部门
  36. /// </summary>
  37. IUserDepartmentManage UserDepartmentManage = new UserDepartmentManage();
  38. /// <summary>
  39. /// 岗位人员
  40. /// </summary>
  41. IPostUserManage PostUserManage { get; set; }
  42. /// <summary>
  43. /// 岗位部门
  44. /// </summary>
  45. IPostDepartmentManage PostDepartmentManage = new PostDepartmentManage();
  46. /// <summary>
  47. /// 加载列表
  48. /// </summary>
  49. /// <returns></returns>
  50. [UserAuthorizeAttribute(ModuleAlias = "Department", OperaAction = "View")]
  51. public ActionResult Index()
  52. {
  53. try
  54. {
  55. #region 处理查询参数
  56. string posttype = Request.QueryString["posttype"];
  57. string FK_DPTID = Request.QueryString["FK_DPTID"];
  58. #endregion
  59. #region 加载列表
  60. var result = BindList(posttype, FK_DPTID, CurrentUser.USERTYPE);
  61. ViewBag.Search = base.keywords;
  62. // ViewData["PostType"] = this.CodeManage.GetCode("POSTTYPE");
  63. //ViewData["post"] = posttype;
  64. ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetail();
  65. ViewData["dptid"] = FK_DPTID;
  66. #endregion
  67. if (result.IsNull())
  68. {
  69. return View();
  70. }
  71. else
  72. {
  73. return View(result);
  74. }
  75. }
  76. catch (Exception e)
  77. {
  78. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  79. throw e.InnerException;
  80. }
  81. }
  82. /// <summary>
  83. /// 导出经销商excel
  84. /// </summary>
  85. /// <returns></returns>
  86. [HttpGet]
  87. [UserAuthorizeAttribute(ModuleAlias = "SalesDealersList", OperaAction = "Export")]
  88. public FileResult AllDistributorExcel()
  89. {
  90. //获取list数据
  91. List<string> list = new List<string>();
  92. //创建Excel文件的对象
  93. NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); string distributorsID = string.Empty; string CarSate = Request.QueryString["CarSate"];
  94. List<string> namelist = new List<string>();
  95. //添加一个sheet
  96. NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
  97. //给sheet1添加第一行的头部标题
  98. NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
  99. row1.CreateCell(0).SetCellValue("经销商类型");
  100. row1.CreateCell(1).SetCellValue("经销商编号");
  101. row1.CreateCell(2).SetCellValue("经销商名称");
  102. row1.CreateCell(3).SetCellValue("所在省");
  103. row1.CreateCell(4).SetCellValue("所在市");
  104. row1.CreateCell(5).SetCellValue("所在区");
  105. row1.CreateCell(6).SetCellValue("经销商地址");
  106. row1.CreateCell(7).SetCellValue("电子围栏范围");
  107. row1.CreateCell(8).SetCellValue("经纬度");
  108. row1.CreateCell(9).SetCellValue("经销商手机号");
  109. row1.CreateCell(10).SetCellValue("经销商联系人");
  110. row1.CreateCell(11).SetCellValue("销售产品");
  111. row1.CreateCell(12).SetCellValue("轮拖轮式收条线联系人");
  112. row1.CreateCell(13).SetCellValue("轮拖轮式收条线手机号");
  113. row1.CreateCell(14).SetCellValue("履带插秧条线联系人");
  114. row1.CreateCell(15).SetCellValue("履带插秧条线手机号");
  115. row1.CreateCell(16).SetCellValue("玉米收花生机条线联系人");
  116. row1.CreateCell(17).SetCellValue("玉米收花生机条线手机号");
  117. //将数据逐步写入sheet1各个行
  118. if (!Request.QueryString["distributorsid"].IsEmpty())
  119. {
  120. distributorsID = Request.QueryString["distributorsid"].ToString();
  121. }
  122. using (AntORM orm = new AntORM())
  123. {
  124. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  125. RequestModel res = new RequestModel
  126. {
  127. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  128. };
  129. var q = orm.Queryable<EntSYS_DISTRIBUTORS>();
  130. if (!Request.QueryString["hkprovid"].IsEmpty())
  131. {
  132. int provid = Request.QueryString["hkprovid"].ToInt32();
  133. q = q.Where(p => p.Province == provid);
  134. }
  135. if (!Request.QueryString["hkcityid"].IsEmpty())
  136. {
  137. int provid = Request.QueryString["hkcityid"].ToInt32();
  138. q = q.Where(p => p.City == provid);
  139. }
  140. q = q.Where(p => p.BUSINESSLEVEL > 1);
  141. var reslutd = q.ToList(res);
  142. if (reslutd.IsSuccess)
  143. {
  144. var modellist = reslutd.ResultModel; int i = 0;
  145. foreach (EntSYS_DISTRIBUTORS md in modellist)
  146. {
  147. i++; int j = 0;
  148. NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i);
  149. string saletype = (md.BUSINESSLEVEL == 2) ? "一级经销商" : "经销商仓库";
  150. rowtemp.CreateCell(j).SetCellValue(saletype);
  151. j++;
  152. rowtemp.CreateCell(j).SetCellValue(md.DealerNumber);
  153. j++;
  154. rowtemp.CreateCell(j).SetCellValue(md.NAME);
  155. j++;
  156. string Province = ""; string pro = md.Province.ToString();
  157. var resluts = orm.Queryable<MES.Production.Entity.SYS_CODE_AREA>().Where(p => p.ID == pro).FirstOrDefault(res);
  158. if (resluts.IsSuccess)
  159. {
  160. MES.Production.Entity.SYS_CODE_AREA mod = resluts.ResultModel;
  161. Province = mod.NAME;
  162. }
  163. rowtemp.CreateCell(j).SetCellValue(Province);//省
  164. j++;
  165. string City = ""; pro = md.Province.ToString();
  166. resluts = orm.Queryable<MES.Production.Entity.SYS_CODE_AREA>().Where(p => p.ID == pro).FirstOrDefault(res);
  167. if (resluts.IsSuccess)
  168. {
  169. MES.Production.Entity.SYS_CODE_AREA mod = resluts.ResultModel;
  170. City = mod.NAME;
  171. }
  172. rowtemp.CreateCell(j).SetCellValue(City);//市
  173. j++;
  174. string Area = ""; pro = md.Province.ToString();
  175. resluts = orm.Queryable<MES.Production.Entity.SYS_CODE_AREA>().Where(p => p.ID == pro).FirstOrDefault(res);
  176. if (resluts.IsSuccess)
  177. {
  178. MES.Production.Entity.SYS_CODE_AREA mod = resluts.ResultModel;
  179. Area = mod.NAME;
  180. }
  181. rowtemp.CreateCell(j).SetCellValue(Area);//区
  182. j++;
  183. rowtemp.CreateCell(j).SetCellValue(md.Address);//经销商地址
  184. j++;
  185. rowtemp.CreateCell(j).SetCellValue(md.FenceRadius);//围栏半径
  186. j++;
  187. rowtemp.CreateCell(j).SetCellValue(md.Theodolite);//围栏经纬度
  188. j++;
  189. resluts = orm.Queryable<MES.Production.Entity.Entity.En_SYS_USER>().Where(p => p.DPTID == md.ID).FirstOrDefault(res);//经销商负责人和手机
  190. if (resluts.IsSuccess)
  191. {
  192. En_SYS_USER usermod = resluts.ResultModel;
  193. rowtemp.CreateCell(j).SetCellValue(usermod.NAME);
  194. j++;
  195. rowtemp.CreateCell(j).SetCellValue(usermod.PHONE);
  196. j++;
  197. }
  198. else
  199. {
  200. rowtemp.CreateCell(j).SetCellValue("");
  201. j++;
  202. rowtemp.CreateCell(j).SetCellValue("");
  203. j++;
  204. }
  205. rowtemp.CreateCell(j).SetCellValue("");
  206. j++;
  207. var reslut = orm.Queryable<EntYW_UserDistributor>().Where(p => p.distributorId == md.ID).FirstOrDefault(res);//产品线负责人和手机
  208. if (reslut.IsSuccess)
  209. {
  210. string strid = string.Empty; string strname = string.Empty;
  211. EntYW_UserDistributor mod = reslut.ResultModel;
  212. int userid = mod.userId.ToInt32();
  213. var userreslut = orm.Queryable<En_SYS_USER>().Where(p => p.ID == userid).FirstOrDefault(res);
  214. if (userreslut.IsSuccess)
  215. {
  216. En_SYS_USER usermod = userreslut.ResultModel;
  217. if (mod.ProductLine == 601)
  218. {
  219. rowtemp.CreateCell(j).SetCellValue(usermod.NAME);
  220. j++;
  221. rowtemp.CreateCell(j).SetCellValue(usermod.PHONE);
  222. j++;
  223. }
  224. else
  225. {
  226. rowtemp.CreateCell(j).SetCellValue("");
  227. j++;
  228. rowtemp.CreateCell(j).SetCellValue("");
  229. j++;
  230. }
  231. if (mod.ProductLine2 == 612)
  232. {
  233. rowtemp.CreateCell(j).SetCellValue(usermod.NAME);
  234. j++;
  235. rowtemp.CreateCell(j).SetCellValue(usermod.PHONE);
  236. j++;
  237. }
  238. else
  239. {
  240. rowtemp.CreateCell(j).SetCellValue("");
  241. j++;
  242. rowtemp.CreateCell(j).SetCellValue("");
  243. j++;
  244. }
  245. if (mod.ProductLine4 == 622)
  246. {
  247. rowtemp.CreateCell(j).SetCellValue(usermod.NAME);
  248. j++;
  249. rowtemp.CreateCell(j).SetCellValue(usermod.PHONE);
  250. j++;
  251. }
  252. else
  253. {
  254. rowtemp.CreateCell(j).SetCellValue("");
  255. j++;
  256. rowtemp.CreateCell(j).SetCellValue("");
  257. j++;
  258. }
  259. }
  260. #region 不用
  261. //foreach (EntYW_UserDistributor mod in reslut.ResultModel)
  262. //{
  263. // int userid = mod.userId.ToInt32();
  264. // var userreslut = orm.Queryable<En_SYS_USER>().Where(p => p.ID == userid).FirstOrDefault(res);
  265. // if (userreslut.IsSuccess)
  266. // {
  267. // En_SYS_USER usermod = userreslut.ResultModel;
  268. // if (mod.ProductLine == 601)
  269. // {
  270. // rowtemp.CreateCell(j).SetCellValue(usermod.NAME);
  271. // j++;
  272. // rowtemp.CreateCell(j).SetCellValue(usermod.PHONE);
  273. // j++;
  274. // }
  275. // else
  276. // {
  277. // rowtemp.CreateCell(j).SetCellValue("");
  278. // j++;
  279. // rowtemp.CreateCell(j).SetCellValue("");
  280. // j++;
  281. // }
  282. // if (mod.ProductLine2 == 612)
  283. // {
  284. // rowtemp.CreateCell(j).SetCellValue(usermod.NAME);
  285. // j++;
  286. // rowtemp.CreateCell(j).SetCellValue(usermod.PHONE);
  287. // j++;
  288. // }
  289. // else
  290. // {
  291. // rowtemp.CreateCell(j).SetCellValue("");
  292. // j++;
  293. // rowtemp.CreateCell(j).SetCellValue("");
  294. // j++;
  295. // }
  296. // if (mod.ProductLine4 == 622)
  297. // {
  298. // rowtemp.CreateCell(j).SetCellValue(usermod.NAME);
  299. // j++;
  300. // rowtemp.CreateCell(j).SetCellValue(usermod.PHONE);
  301. // j++;
  302. // }
  303. // else
  304. // {
  305. // rowtemp.CreateCell(j).SetCellValue("");
  306. // j++;
  307. // rowtemp.CreateCell(j).SetCellValue("");
  308. // j++;
  309. // }
  310. // }
  311. //}
  312. #endregion
  313. }
  314. else
  315. {
  316. rowtemp.CreateCell(j).SetCellValue("");
  317. j++;
  318. rowtemp.CreateCell(j).SetCellValue("");
  319. j++;
  320. rowtemp.CreateCell(j).SetCellValue("");
  321. j++;
  322. rowtemp.CreateCell(j).SetCellValue("");
  323. j++;
  324. rowtemp.CreateCell(j).SetCellValue("");
  325. j++;
  326. rowtemp.CreateCell(j).SetCellValue("");
  327. j++;
  328. }
  329. }
  330. }
  331. }
  332. if (namelist.Count > 0)
  333. {
  334. using (AntORM orm = new AntORM())
  335. {
  336. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  337. RequestModel res = new RequestModel
  338. {
  339. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  340. };
  341. var q = orm.Queryable<EntYW_Bicycle>();
  342. if (!CarSate.IsEmpty())
  343. {
  344. int state = CarSate.ToInt32();
  345. q = q.Where(p => namelist.Contains(p.DistributorsID) && p.CarSate == state);
  346. }
  347. else
  348. {
  349. q = q.Where(p => namelist.Contains(p.DistributorsID));
  350. }
  351. var reslut = q.ToList(res);
  352. if (reslut.IsSuccess)
  353. {
  354. List<EntYW_Bicycle> modlist = reslut.ResultModel;
  355. for (int i = 0; i < modlist.Count; i++)
  356. {
  357. NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1);
  358. rowtemp.CreateCell(0).SetCellValue(modlist[i].CarID);
  359. rowtemp.CreateCell(1).SetCellValue(modlist[i].CarName);
  360. rowtemp.CreateCell(2).SetCellValue(modlist[i].carBar);
  361. rowtemp.CreateCell(3).SetCellValue(modlist[i].DistributorsName);
  362. string carstatestr = "";
  363. switch (modlist[i].CarSate)
  364. {
  365. case 0:
  366. carstatestr = "未绑定"; break;
  367. case 1:
  368. carstatestr = "已绑定"; break;
  369. case 2:
  370. carstatestr = "已出库"; break;
  371. case 3:
  372. carstatestr = "在途中"; break;
  373. case 4:
  374. carstatestr = "已入库"; break;
  375. case 5:
  376. carstatestr = "已销售"; break;
  377. case 6:
  378. carstatestr = "退货中"; break;
  379. case 7:
  380. carstatestr = "调拨中"; break;
  381. case 8:
  382. carstatestr = "返厂中"; break;
  383. }
  384. rowtemp.CreateCell(4).SetCellValue(carstatestr);
  385. rowtemp.CreateCell(5).SetCellValue(modlist[i].productionDate.ToString());
  386. //rowtemp.CreateCell(5).SetCellValue(list[i].iName);
  387. //rowtemp.CreateCell(6).SetCellValue(list[i].iPhone);
  388. //rowtemp.CreateCell(7).SetCellValue(list[i].IntegralSum);
  389. //rowtemp.CreateCell(8).SetCellValue(list[i].IntegralSy);
  390. //rowtemp.CreateCell(9).SetCellValue(list[i].IntegralKy);
  391. }
  392. }
  393. }
  394. }
  395. // 写入到客户端
  396. System.IO.MemoryStream ms = new System.IO.MemoryStream();
  397. book.Write(ms);
  398. ms.Seek(0, SeekOrigin.Begin);
  399. return File(ms, "application/vnd.ms-excel", "经销商库存信息.xls");
  400. }
  401. /// <summary>
  402. /// 获取经纬度地址
  403. /// </summary>
  404. /// <param name="id"></param>
  405. /// <returns></returns>
  406. public ActionResult getLatLntAdderss(string latlntstr)
  407. {
  408. var json = new JsonHelper() { Status = "y", Msg = "Success" };
  409. if (latlntstr.IndexOf(',') > 0)
  410. {
  411. try
  412. {
  413. var lng = latlntstr.Split(',')[0]; var lat = latlntstr.Split(',')[1];
  414. var resaddress = ToolGPSamap.GPSToPositionString(lng.ToDou(), lat.ToDou());
  415. json.Data = resaddress;
  416. }
  417. catch (Exception ex)
  418. {
  419. json.Status = "n";
  420. json.Msg = "经纬度必须用英文的逗分隔开,经度在前,纬度在后!";
  421. }
  422. }
  423. else
  424. {
  425. json.Status = "n";
  426. json.Msg = "经纬度必须用英文的逗分隔开,经度在前,纬度在后!";
  427. }
  428. return Json(json);
  429. }
  430. /// <summary>
  431. /// 加载详情页
  432. /// </summary>
  433. [HttpGet]
  434. [UserAuthorizeAttribute(ModuleAlias = "SalesDealersList", OperaAction = "Detail")]
  435. public ActionResult Detail(string id)
  436. {
  437. try
  438. {
  439. string filePathName = string.Empty;
  440. DistributorUser distributorUser = new DistributorUser();
  441. SYS_DISTRIBUTORS entity = new SYS_DISTRIBUTORS();
  442. int uid = 0;
  443. if (CurrentUser.USERTYPE == 2)
  444. {
  445. uid = CurrentUser.Id;
  446. ViewData["usertype"] = CurrentUser.USERTYPE.ToString();
  447. }
  448. else
  449. {
  450. ViewData["usertype"] = "0";
  451. }
  452. ViewBag.moduleparent = this.DepartmentManage.GetDepartmentByDetailNew(uid);
  453. //添加子部门
  454. string parentId = Request.QueryString["parentId"];
  455. if (!string.IsNullOrEmpty(parentId))
  456. {
  457. //entity.PARENTID = parentId;
  458. distributorUser.distributorInfo.PARENTID = parentId;
  459. return View(distributorUser);
  460. }
  461. if (!string.IsNullOrEmpty(id))
  462. {
  463. entity = this.DepartmentManage.Get(p => p.ID == id);
  464. distributorUser.distributorInfo = entity;
  465. using (AntORM orm = new AntORM())
  466. {
  467. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  468. RequestModel res = new RequestModel
  469. {
  470. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  471. };
  472. if (CurrentUser.USERTYPE == 2)
  473. {
  474. int userid = CurrentUser.Id;
  475. var reslut = orm.Queryable<EntYW_UserDistributor>().Where(p => p.distributorId == id && p.userId == userid).FirstOrDefault(res);
  476. if (reslut.IsSuccess)
  477. {
  478. EntYW_UserDistributor mod = reslut.ResultModel;
  479. if (mod.ProductLine == 601)
  480. {
  481. ViewData["line1"] = true;
  482. }
  483. if (mod.ProductLine == 615)
  484. {
  485. ViewData["line2"] = true;
  486. }
  487. if (mod.ProductLine == 612)
  488. {
  489. ViewData["line3"] = true;
  490. }
  491. if (mod.ProductLine == 611)
  492. {
  493. ViewData["line4"] = true;
  494. }
  495. if (mod.ProductLine == 622)
  496. {
  497. ViewData["line5"] = true;
  498. }
  499. if (mod.ProductLine == 628)
  500. {
  501. ViewData["line6"] = true;
  502. }
  503. }
  504. }
  505. else
  506. {
  507. //IQuery<EntYW_UserDistributor> q = orm.Queryable<EntYW_UserDistributor>();
  508. //IGroupingQuery<EntYW_UserDistributor> group = q.Where(a => a.distributorId == id).GroupBy(a => a.userId);
  509. //var re = group.Select(a => new { a.userId }).ToList(res);
  510. //if (re.IsSuccess)
  511. //{
  512. // string strid = string.Empty; string strname = string.Empty;
  513. // foreach (var mod in re.ResultModel)
  514. // {
  515. // int userid = mod.userId;
  516. // var userreslut = orm.Queryable<En_SYS_USER>().Where(p => p.ID == userid).FirstOrDefault(res);
  517. // if (userreslut.IsSuccess)
  518. // {
  519. // En_SYS_USER usermod = userreslut.ResultModel;
  520. // if (strid.IsEmpty())
  521. // {
  522. // strid += usermod.ID;
  523. // strname += usermod.NAME;
  524. // }
  525. // else
  526. // {
  527. // strid += ";" + usermod.ID;
  528. // strname += ";" + usermod.NAME;
  529. // }
  530. // }
  531. // }
  532. // ViewData["userid"] = strid + "|" + strname;
  533. //}
  534. }
  535. var usereslut = orm.Queryable<En_SYS_USER>().Where(p => p.DPTID == entity.ID).FirstOrDefault(res);
  536. if (usereslut.IsSuccess)
  537. {
  538. distributorUser.userInfo = usereslut.ResultModel;
  539. }
  540. }
  541. }
  542. else
  543. {
  544. distributorUser.distributorInfo = new SYS_DISTRIBUTORS();
  545. distributorUser.distributorInfo.PARENTID = "32f7a4bd-84de-4587-be29-734d65ad6f70";
  546. distributorUser.userInfo = new En_SYS_USER() { ISCANLOGIN = false };
  547. }
  548. // ViewData["line1"] = true;
  549. return View(distributorUser);
  550. }
  551. catch (Exception e)
  552. {
  553. WriteLog(enumOperator.Select, "经销商管理加载详情页:", e);
  554. throw e.InnerException;
  555. }
  556. }
  557. /// <summary>
  558. /// 保存部门
  559. /// </summary>
  560. [ValidateInput(false)]
  561. [UserAuthorizeAttribute(ModuleAlias = "SalesDealersList", OperaAction = "Add,Edit")]
  562. public ActionResult Save(DistributorUser entity)
  563. {
  564. bool isEdit = false; bool bz = true;
  565. var fileid = Request.Form["hidfileid"];
  566. var fileurl = Request.Form["hidfilename"];
  567. var paretid = Request.Form["PARENTID"];
  568. int userid = 0;
  569. var citystr = Request.Form["hkprov"] + "," + Request.Form["hkcity"] + "," + Request.Form["hkcountry"];
  570. var json = new JsonHelper() { Msg = "保存成功", Status = "n" };
  571. //先取消电子围栏
  572. if (entity.distributorInfo.Theodolite.IsEmpty())
  573. {
  574. json.Msg = "经纬度不能为空";
  575. return Json(json);
  576. }
  577. if (entity.distributorInfo.Theodolite.IndexOf(',') <= 0)
  578. {
  579. json.Msg = "经纬度必须用英文的逗分隔开,经度在前,纬度在后!";
  580. return Json(json);
  581. }
  582. if (Request.Form["hkprov"].IsEmpty())
  583. {
  584. json.Msg = "所属省不能为空!";
  585. return Json(json);
  586. }
  587. if (Request.Form["hkcity"].IsEmpty())
  588. {
  589. json.Msg = "所属市不能为空!";
  590. return Json(json);
  591. }
  592. if (Request.Form["hkcountry"].IsEmpty())
  593. {
  594. json.Msg = "所属区不能为空!";
  595. return Json(json);
  596. }
  597. var lng = entity.distributorInfo.Theodolite.Split(',')[0]; var lat = entity.distributorInfo.Theodolite.Split(',')[1];
  598. var resaddress = ToolGPSamap.GPSToPositionString(lng.ToDou(), lat.ToDou());
  599. if (resaddress.IsEmpty())
  600. {
  601. json.Msg = "经纬度不正确!";
  602. return Json(json);
  603. }
  604. try
  605. {
  606. var parententity = new SYS_DISTRIBUTORS();
  607. if (!string.IsNullOrEmpty(paretid))
  608. {
  609. parententity = this.DepartmentManage.Get(p => p.ID == paretid);
  610. }
  611. var _entity = new SYS_DISTRIBUTORS(); var _userenty = new En_SYS_USER(); //当前经销商和用户
  612. string guid = Guid.NewGuid().ToString();
  613. using (AntORM orm = new AntORM())
  614. {
  615. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  616. RequestModel res = new RequestModel
  617. {
  618. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  619. };
  620. if (entity.distributorInfo != null)
  621. {
  622. if (!string.IsNullOrEmpty(entity.distributorInfo.ID))
  623. {
  624. guid = entity.distributorInfo.ID;
  625. // var disreult = orm.DeleteByLambda<EntYW_UserDistributor>(p => p.distributorId == entity.distributorInfo.ID, res);
  626. }
  627. else
  628. {
  629. guid = Guid.NewGuid().ToString();
  630. }
  631. }
  632. else
  633. {
  634. guid = Guid.NewGuid().ToString();
  635. }
  636. }
  637. if (entity.distributorInfo != null)
  638. {
  639. if (!string.IsNullOrEmpty(entity.distributorInfo.ID))
  640. {
  641. #region 修改
  642. _entity = this.DepartmentManage.Get(p => p.ID == entity.distributorInfo.ID);
  643. entity.distributorInfo.CREATEDATE = _entity.CREATEDATE;
  644. entity.distributorInfo.CREATEPERID = _entity.CREATEPERID;
  645. entity.distributorInfo.PARENTID = paretid;
  646. entity.distributorInfo.UPDATEDATE = DateTime.Now;
  647. entity.distributorInfo.UPDATEUSER = this.CurrentUser.Name;
  648. entity.distributorInfo.Address = Request.Form["distributorInfo.Address"];
  649. entity.distributorInfo.FenceRadius = Request.Form["example_length"].ToInt32();
  650. entity.distributorInfo.LICENSEURL = fileurl;
  651. entity.distributorInfo.LICENSEVALUE = fileid;
  652. entity.distributorInfo.ProvinceCity = citystr;
  653. entity.distributorInfo.Province = Request.Form["hkprov"].ToInt32();
  654. entity.distributorInfo.City = Request.Form["hkcity"].ToInt32();
  655. entity.distributorInfo.Area = Request.Form["hkcountry"].ToInt32();
  656. if (entity.distributorInfo.PARENTID != _entity.PARENTID)
  657. {
  658. entity.distributorInfo.CODE = this.DepartmentManage.CreateCode(entity.distributorInfo.PARENTID);
  659. }
  660. else
  661. {
  662. entity.distributorInfo.CODE = _entity.CODE;
  663. }
  664. isEdit = true;
  665. //获取父级记录
  666. if (string.IsNullOrEmpty(paretid))
  667. {
  668. //业务等级
  669. entity.distributorInfo.BUSINESSLEVEL = 1;
  670. entity.distributorInfo.PARENTCODE = null;
  671. }
  672. else
  673. {
  674. entity.distributorInfo.BUSINESSLEVEL = parententity.BUSINESSLEVEL + 1;
  675. entity.distributorInfo.PARENTCODE = parententity.CODE;
  676. entity.distributorInfo.ParentName = parententity.NAME;
  677. if (entity.distributorInfo.BUSINESSLEVEL == 2)
  678. {
  679. _userenty = entity.userInfo;
  680. _userenty.ACCOUNT = _userenty.PHONE;
  681. _userenty.USERTYPE = 3;
  682. using (AntORM orm = new AntORM())
  683. {
  684. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  685. RequestModel res = new RequestModel
  686. {
  687. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  688. };
  689. var resuser = orm.UpdateById(_userenty, res);
  690. }
  691. }
  692. else
  693. {
  694. using (AntORM orm = new AntORM())
  695. {
  696. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  697. RequestModel res = new RequestModel
  698. {
  699. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  700. };
  701. var disreult = orm.Queryable<EntYW_UserDistributor>().Where(p => p.distributorId == paretid).ToList();
  702. foreach (EntYW_UserDistributor usermod in disreult.ResultModel)
  703. {
  704. var count = orm.Queryable<EntYW_UserDistributor>().Where(p => p.distributorId == usermod.distributorId && p.userId == usermod.userId).Count();
  705. if (count == 0)
  706. {
  707. EntYW_UserDistributor entdis = new EntYW_UserDistributor();
  708. entdis.userId = usermod.userId;
  709. entdis.distributorId = guid;
  710. entdis.ID = Guid.NewGuid();
  711. var reslutdis = orm.Save(entdis, res);
  712. }
  713. }
  714. }
  715. }
  716. }
  717. #endregion
  718. _entity = entity.distributorInfo;
  719. }
  720. else
  721. {
  722. if (entity.distributorInfo.PARENTID == "32f7a4bd-84de-4587-be29-734d65ad6f70")
  723. {
  724. if (entity.userInfo.PHONE.IsEmpty())
  725. {
  726. json.Msg = "经销商联系人和电话不能为空!";
  727. return Json(json);
  728. }
  729. using (AntORM orm = new AntORM())
  730. {
  731. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  732. var disnum = orm.Queryable<EntSYS_DISTRIBUTORS>().Where(p => p.DealerNumber == entity.distributorInfo.DealerNumber && p.PARENTID == "32f7a4bd-84de-4587-be29-734d65ad6f70").Count();
  733. if (disnum > 0)
  734. {
  735. json.Msg = "经销商一级点只能添加一个!";
  736. return Json(json);
  737. }
  738. }
  739. }
  740. using (AntORM orm = new AntORM())
  741. {
  742. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  743. var disnum = orm.Queryable<EntSYS_DISTRIBUTORS>().Where(p => p.NAME == entity.distributorInfo.NAME).Count();
  744. if (disnum > 0)
  745. {
  746. json.Msg = "经销商名称已经存不能添加";
  747. return Json(json);
  748. }
  749. }
  750. #region 添加
  751. _entity = entity.distributorInfo;
  752. _entity.ID = guid;
  753. _entity.CREATEDATE = DateTime.Now;
  754. _entity.CREATEPERID = this.CurrentUser.Name;
  755. _entity.PARENTID = paretid;
  756. _entity.UPDATEDATE = DateTime.Now;
  757. _entity.UPDATEUSER = this.CurrentUser.Name;
  758. _entity.Address = entity.distributorInfo.Address;
  759. _entity.FenceRadius = Request.Form["example_length"].ToInt32();
  760. _entity.LICENSEURL = fileurl;
  761. _entity.LICENSEVALUE = fileid;
  762. _entity.ProvinceCity = citystr;
  763. _entity.Province = Request.Form["hkprov"].ToInt32();
  764. _entity.City = Request.Form["hkcity"].ToInt32();
  765. _entity.Area = Request.Form["hkcountry"].ToInt32();
  766. //根据上级部门的ID确定当前部门的CODE
  767. _entity.CODE = this.DepartmentManage.CreateCode(_entity.PARENTID);
  768. //获取父级记录
  769. if (string.IsNullOrEmpty(_entity.PARENTID))
  770. {
  771. //业务等级
  772. entity.distributorInfo.BUSINESSLEVEL = 1;
  773. entity.distributorInfo.PARENTCODE = null;
  774. }
  775. else
  776. {
  777. entity.distributorInfo.BUSINESSLEVEL = parententity.BUSINESSLEVEL + 1;
  778. entity.distributorInfo.PARENTCODE = parententity.CODE;
  779. entity.distributorInfo.ParentName = parententity.NAME;
  780. if (entity.distributorInfo.BUSINESSLEVEL == 2)
  781. {
  782. if (!_userenty.PHONE.IsEmpty())
  783. {
  784. _userenty = entity.userInfo;
  785. _userenty.DPTID = _entity.ID;
  786. var pwd = PasswordUtils.MD5_Encrypt("111111", 32);
  787. _userenty.USERTYPE = 3;
  788. _userenty.ACCOUNT = _userenty.PHONE;
  789. _userenty.PASSWORD = pwd;
  790. _userenty.CREATEDATE = DateTime.Now;
  791. _userenty.CREATEPER = this.CurrentUser.Name;
  792. _userenty.UPDATEDATE = DateTime.Now;
  793. _userenty.UPDATEUSER = this.CurrentUser.Name;
  794. using (AntORM orm = new AntORM())
  795. {
  796. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  797. RequestModel res = new RequestModel
  798. {
  799. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  800. };
  801. var resuser = orm.SaveHaveNull(_userenty, res);
  802. }
  803. }
  804. }
  805. }
  806. #endregion
  807. }
  808. if (entity.userInfo.ID.IfNotNull())
  809. {
  810. EntSYS_USER_ROLE roleMod = new EntSYS_USER_ROLE();
  811. using (AntORM orm = new AntORM())
  812. {
  813. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  814. RequestModel res = new RequestModel
  815. {
  816. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  817. };
  818. int uid = _userenty.ID.ToInt32();
  819. var reslutrolse = orm.Queryable<EntSYS_USER_ROLE>().Where(p => p.FK_USERID == uid && p.FK_ROLEID == 3).FirstOrDefault(res);
  820. if (reslutrolse.IsSuccess)
  821. {
  822. }
  823. else
  824. {
  825. int ROLEID = 0; var usertype = CurrentUser.USERTYPE;
  826. switch ((PostType)usertype)
  827. {
  828. case PostType.SalesClerk:
  829. {
  830. ROLEID = 2;
  831. }
  832. break;
  833. case PostType.Distributors:
  834. {
  835. ROLEID = 3;
  836. }
  837. break;
  838. case PostType.Warehouse:
  839. {
  840. ROLEID = 4;
  841. }
  842. break;
  843. case PostType.ThreePacksStaff:
  844. {
  845. ROLEID = 6;
  846. }
  847. break;
  848. case PostType.MarketingAdmin:
  849. {
  850. ROLEID = 7;
  851. }
  852. break;
  853. }
  854. //roleMod.FK_ROLEID = ROLEID;
  855. roleMod.FK_ROLEID = 3;
  856. roleMod.FK_USERID = uid;
  857. orm.Save(roleMod, res);
  858. }
  859. }
  860. }
  861. }
  862. //先取消电子围栏
  863. if (entity.distributorInfo.Theodolite.IsEmpty())
  864. {
  865. var addressmod = AddressToGPS(entity.distributorInfo.Address);
  866. if (addressmod.Geocodes.Count > 0)
  867. {
  868. foreach (Geocode mod in addressmod.Geocodes)
  869. {
  870. string lnglatstr = mod.Location;
  871. _entity.Theodolite = lnglatstr;
  872. }
  873. }
  874. }
  875. else
  876. {
  877. _entity.Theodolite = entity.distributorInfo.Theodolite;
  878. }
  879. //判断同一个部门下,是否重名
  880. var predicate = PredicateBuilder.True<SYS_DISTRIBUTORS>();
  881. predicate = predicate.And(p => p.PARENTID == _entity.PARENTID);
  882. predicate = predicate.And(p => p.NAME == _entity.NAME);
  883. predicate = predicate.And(p => p.ID != _entity.ID);
  884. if (!this.DepartmentManage.IsExist(predicate))
  885. {
  886. if (this.DepartmentManage.SaveOrUpdate(_entity, isEdit))
  887. {
  888. json.Status = "y";
  889. try
  890. {
  891. if (CurrentUser.USERTYPE == 2)
  892. {
  893. var productline1 = Request.Form["ckb_per"];
  894. using (AntORM orm = new AntORM())
  895. {
  896. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  897. RequestModel res = new RequestModel
  898. {
  899. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  900. };
  901. var count = orm.Queryable<EntYW_UserDistributor>().Where(p => p.distributorId == guid && p.userId == CurrentUser.Id).Count();
  902. if (count == 0)
  903. {
  904. EntYW_UserDistributor userdismod = new EntYW_UserDistributor();
  905. userdismod.ID = Guid.NewGuid();
  906. userdismod.userId = CurrentUser.Id;
  907. userdismod.distributorId = guid;
  908. if (productline1.IndexOf("601") >= 0)
  909. userdismod.ProductLine = 601;
  910. if (productline1.IndexOf("615") >= 0)
  911. userdismod.ProductLine1 = 615;
  912. if (productline1.IndexOf("612") >= 0)
  913. userdismod.ProductLine2 = 612;
  914. if (productline1.IndexOf("611") >= 0)
  915. userdismod.ProductLine3 = 611;
  916. if (productline1.IndexOf("622") >= 0)
  917. userdismod.ProductLine4 = 622;
  918. if (productline1.IndexOf("628") >= 0)
  919. userdismod.ProductLine5 = 628;
  920. userdismod.add_name = "系统导入";
  921. var reslut1 = orm.Save(userdismod, res);
  922. }
  923. }
  924. }
  925. //string imei = "356802032734930";
  926. string imei = "333333333333333";
  927. string discode = Ant.SuperSocket.Common.DataHelper.StringToHex(_entity.CODE);
  928. var str = Ant.SuperSocket.Common.DataHelper.sendCarData(Convert.ToInt64(imei), "9922" + discode);
  929. var body = Ant.SuperSocket.Common.DataHelper.HexToByte(str);
  930. SocketClient client = new SocketClient();
  931. string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString();
  932. // string ip = "";
  933. int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32();
  934. client.Connect(ip, port);
  935. var flag = client.SendData(body);
  936. client.Disconnect();
  937. }
  938. catch (Exception ex) { }
  939. }
  940. else
  941. {
  942. json.Msg = "保存失败";
  943. }
  944. }
  945. else
  946. {
  947. json.Msg = "经销商" + entity.distributorInfo.NAME + "已存在,不能重复添加";
  948. }
  949. if (isEdit)
  950. {
  951. WriteLog(enumOperator.Edit, "修改经销商信息,结果:" + json.Msg, enumLog4net.INFO);
  952. }
  953. else
  954. {
  955. WriteLog(enumOperator.Add, "添加经销商信息,结果:" + json.Msg, enumLog4net.INFO);
  956. }
  957. }
  958. catch (Exception e)
  959. {
  960. json.Msg = "保存经销商信息发生内部错误!";
  961. WriteLog(enumOperator.None, "保存经销商信息:", e);
  962. }
  963. return Json(json);
  964. }
  965. /// <summary>
  966. /// 将地址转GPS
  967. /// </summary>
  968. /// <param name="address"></param>
  969. /// <returns></returns>
  970. private AddressGPS AddressToGPS(string address)
  971. {
  972. System.Net.WebClient server = new System.Net.WebClient();
  973. string url = String.Format("http://restapi.amap.com/v3/geocode/geo?key={0}&address={1}&city={2}", "fa36ec6323075f37020083ceffe8eb24", address, "");
  974. var replyBuffer = server.DownloadData(url);
  975. var reply = System.Text.Encoding.UTF8.GetString(replyBuffer);
  976. var mod = Newtonsoft.Json.JsonConvert.DeserializeObject<AddressGPS>(reply);
  977. return mod;
  978. }
  979. /// <summary>
  980. /// 删除部门
  981. /// </summary>
  982. [UserAuthorizeAttribute(ModuleAlias = "SalesDealersList", OperaAction = "Remove")]
  983. public ActionResult Delete(string idList)
  984. {
  985. JsonHelper json = new JsonHelper() { Msg = "删除经销商成功", ReUrl = "/Distributors/SalesDealersList", Status = "n" };
  986. try
  987. {
  988. if (!string.IsNullOrEmpty(idList))
  989. {
  990. idList = idList.TrimEnd(',');
  991. //判断是否有下属部门
  992. if (!this.DepartmentManage.DepartmentIsExists(idList))
  993. {
  994. //判断是否有用户归属该部门
  995. if (!this.UserDepartmentManage.IsExist(p => idList.Contains(p.DEPARTMENT_ID)))
  996. {
  997. //判断该部门是否有岗位
  998. if (!this.PostDepartmentManage.IsExist(p => idList.Contains(p.FK_DEPARTMENT_ID)))
  999. {
  1000. var idList1 = idList.Split(',').ToList();
  1001. this.DepartmentManage.Delete(p => idList.Contains(p.ID));
  1002. using (AntORM orm = new AntORM())
  1003. {
  1004. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1005. foreach (string id in idList.Split(','))
  1006. {
  1007. RequestModel request = new RequestModel
  1008. {
  1009. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" },
  1010. Oid = id.ToString()
  1011. };
  1012. var disreult = orm.DeleteByLambda<EntYW_UserDistributor>(p => p.distributorId == id, request);
  1013. var userreult = orm.Queryable<En_SYS_USER>().Where(p => p.DPTID == id).FirstOrDefault(request);
  1014. if (userreult.IsSuccess)
  1015. {
  1016. En_SYS_USER moduser = userreult.ResultModel;
  1017. var rolereult = orm.DeleteByLambda<EntSYS_USER_ROLE>(p => p.FK_USERID == moduser.ID, request);
  1018. var usreult = orm.DeleteByLambda<En_SYS_USER>(p => p.DPTID == id, request);
  1019. }
  1020. }
  1021. }
  1022. json.Status = "y";
  1023. }
  1024. else
  1025. {
  1026. json.Msg = "该经销商有岗位信息不能删除,请先取消岗位分配";
  1027. }
  1028. }
  1029. else
  1030. {
  1031. json.Msg = "该经销商存在用户不能删除";
  1032. }
  1033. }
  1034. else
  1035. {
  1036. json.Msg = "该经销商有下属部门不能删除";
  1037. }
  1038. }
  1039. else
  1040. {
  1041. json.Msg = "未找到要删除的部门记录";
  1042. }
  1043. WriteLog(enumOperator.Remove, "删除部门:" + json.Msg, enumLog4net.WARN);
  1044. }
  1045. catch (Exception e)
  1046. {
  1047. json.Msg = "删除经销商发生内部错误!";
  1048. WriteLog(enumOperator.Remove, "删除部门:", e);
  1049. }
  1050. return Json(json);
  1051. }
  1052. /// <summary>
  1053. ///
  1054. /// </summary>
  1055. /// <returns></returns>
  1056. public ActionResult FenceInfo(string id)
  1057. {
  1058. EntSYS_DISTRIBUTORS mod = new EntSYS_DISTRIBUTORS();
  1059. using (AntORM orm = new AntORM())
  1060. {
  1061. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1062. RequestModel res = new RequestModel
  1063. {
  1064. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1065. };
  1066. var q = orm.Queryable<EntSYS_DISTRIBUTORS>();
  1067. if (!id.IsEmpty())
  1068. {
  1069. var reslut = q.Where(p => p.ID == id).FirstOrDefault(res);
  1070. if (reslut.IsSuccess)
  1071. {
  1072. mod = reslut.ResultModel;
  1073. }
  1074. }
  1075. }
  1076. return View(mod);
  1077. }
  1078. /// <summary>
  1079. /// 加载列表
  1080. /// </summary>
  1081. /// <returns></returns>
  1082. [UserAuthorizeAttribute(ModuleAlias = "Department", OperaAction = "View")]
  1083. public ActionResult InventoryList()
  1084. {
  1085. try
  1086. {
  1087. #region 处理查询参数
  1088. string posttype = Request.QueryString["posttype"];
  1089. string FK_DPTID = Request.QueryString["FK_DPTID"];
  1090. #endregion
  1091. #region 加载列表
  1092. var result = BindList(posttype, FK_DPTID, CurrentUser.USERTYPE);
  1093. ViewBag.Search = base.keywords;
  1094. // ViewData["PostType"] = this.CodeManage.GetCode("POSTTYPE");
  1095. //ViewData["post"] = posttype;
  1096. ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew();
  1097. ViewData["dptid"] = FK_DPTID;
  1098. #endregion
  1099. if (result.IsNull())
  1100. {
  1101. return View();
  1102. }
  1103. else
  1104. {
  1105. if (!Request.QueryString["hkprov"].IsEmpty())
  1106. {
  1107. ViewData["hkprov"] = Request.QueryString["hkprov"];
  1108. }
  1109. if (!Request.QueryString["hkcity"].IsEmpty())
  1110. {
  1111. ViewData["hkcity"] = Request.QueryString["hkcity"];
  1112. }
  1113. if (!Request.QueryString["hkcountry"].IsEmpty())
  1114. {
  1115. ViewData["hkcountry"] = Request.QueryString["hkcountry"];
  1116. }
  1117. return View(result);
  1118. }
  1119. }
  1120. catch (Exception e)
  1121. {
  1122. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  1123. throw e.InnerException;
  1124. }
  1125. }
  1126. /// <summary>
  1127. ///
  1128. /// </summary>
  1129. [UserAuthorizeAttribute(ModuleAlias = "SalesDealersList", OperaAction = "View")]
  1130. public ActionResult SalesDealersList()
  1131. {
  1132. try
  1133. {
  1134. #region 处理查询参数
  1135. string posttype = Request.QueryString["posttype"];
  1136. string FK_DPTID = Request.QueryString["FK_DPTID"];
  1137. #endregion
  1138. #region 加载列表
  1139. var result = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<EntSYS_DISTRIBUTORS>()));
  1140. int uid = 0;
  1141. if (CurrentUser.USERTYPE == 0 || CurrentUser.USERTYPE == 8)
  1142. {
  1143. result = BindList(posttype, FK_DPTID, CurrentUser.USERTYPE);
  1144. }
  1145. else
  1146. {
  1147. uid = CurrentUser.Id;
  1148. result = SalesDistributionBindList(posttype, FK_DPTID);
  1149. }
  1150. ViewBag.Search = base.keywords;
  1151. // ViewData["PostType"] = this.CodeManage.GetCode("POSTTYPE");
  1152. //ViewData["post"] = posttype;
  1153. ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew(uid);
  1154. ViewData["dptid"] = FK_DPTID;
  1155. ViewData["saleId"] = CurrentUser.Id.ToString();
  1156. #endregion
  1157. if (!Request.QueryString["hkprov"].IsEmpty())
  1158. {
  1159. ViewData["hkprov"] = Request.QueryString["hkprov"];
  1160. }
  1161. if (!Request.QueryString["hkcity"].IsEmpty())
  1162. {
  1163. ViewData["hkcity"] = Request.QueryString["hkcity"];
  1164. }
  1165. if (!Request.QueryString["hkcountry"].IsEmpty())
  1166. {
  1167. ViewData["hkcountry"] = Request.QueryString["hkcountry"];
  1168. }
  1169. if (result.IsNull())
  1170. {
  1171. return View();
  1172. }
  1173. else
  1174. {
  1175. return View(result);
  1176. }
  1177. }
  1178. catch (Exception e)
  1179. {
  1180. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  1181. throw e.InnerException;
  1182. }
  1183. }
  1184. /// <summary>
  1185. /// 修改密码页面窗体
  1186. /// </summary>
  1187. // [UserAuthorizeAttribute(ModuleAlias = "Department", OperaAction = "UserPassword")]
  1188. public ActionResult PasswordSet()
  1189. {
  1190. if (!string.IsNullOrEmpty(this.CurrentUser.Name))
  1191. {
  1192. var entity = this.UserManage.Get(p => p.ID == CurrentUser.Id);
  1193. return View(entity);
  1194. }
  1195. return View();
  1196. }
  1197. /// <summary>
  1198. /// 修改密码功能实现函数
  1199. /// </summary>
  1200. public ActionResult PasswordSave()
  1201. {
  1202. JsonHelper json = new JsonHelper() { Msg = "修改密码完成", Status = "n" };
  1203. var ID = Request.Form["ID"] ?? "";
  1204. if (string.IsNullOrEmpty(ID))
  1205. {
  1206. json.Msg = "请登录";
  1207. return Json(json);
  1208. }
  1209. string OldPassword = Request.Form["oldpass"];
  1210. string NewPassword = Request.Form["newpass"];
  1211. string confPassword = Request.Form["confpass"];
  1212. int newid = int.Parse(ID);
  1213. var entity = this.UserManage.Get(p => p.ID == newid);
  1214. var pwd = PasswordUtils.MD5_Encrypt(NewPassword, 32);// Ant.Service.Common.CryptHelper.DESCrypt.Encrypt("111111")
  1215. entity.PASSWORD = pwd;
  1216. //entity.PASSWORD = Ant.Service.Common.CryptHelper.DESCrypt.Encrypt(NewPassword);
  1217. try
  1218. {
  1219. this.UserManage.Update(entity);
  1220. json.Status = "y";
  1221. WriteLog(enumOperator.Edit, "修改密码:" + json.Msg, enumLog4net.INFO);
  1222. return Json(json);
  1223. }
  1224. catch (Exception e)
  1225. {
  1226. json.Msg = e.Message;
  1227. WriteLog(enumOperator.Edit, "修改密码错误:", e);
  1228. return Json(json);
  1229. }
  1230. }
  1231. /// <summary>
  1232. /// 修改密码前检测旧密码是否正确
  1233. /// </summary>
  1234. public ActionResult CheckoldPass(string oldPassword)
  1235. {
  1236. JsonHelper json = new JsonHelper() { Msg = "Success", Status = "n" };
  1237. string id = Request.Form["ID"];
  1238. string oldpass = Request.Form["oldpass"];
  1239. if (string.IsNullOrEmpty(id))
  1240. {
  1241. json.Msg = "未找到要处理的用户";
  1242. return Json(json);
  1243. }
  1244. var pass = PasswordUtils.MD5_Encrypt(oldpass, 32);
  1245. //var pass = Ant.Service.Common.CryptHelper.DESCrypt.Encrypt(oldpass);
  1246. int newid = int.Parse(id);
  1247. var result = this.UserManage.IsExist(p => p.ID == newid && p.PASSWORD.Equals(pass));
  1248. if (!result)
  1249. {
  1250. json.Msg = "原始密码错误";
  1251. return Json(json);
  1252. }
  1253. json.Status = "y";
  1254. return Json(json);
  1255. }
  1256. /// <summary>
  1257. /// 绑定页面需要的属性
  1258. /// </summary>
  1259. public PageInfo SalesDistributionBindList(string posttype, string FK_DPTID)
  1260. {
  1261. //var citystr = Request.QueryString["hkprov"] + "," + Request.QueryString["hkcity"] + "," + Request.QueryString["hkcountry"];
  1262. string saleid = CurrentUser.Id.ToString();
  1263. using (AntORM orm = new AntORM())
  1264. {
  1265. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1266. RequestModel request = new RequestModel();
  1267. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  1268. var dis = orm.Queryable<EntSYS_DISTRIBUTORS>();
  1269. var userdis = orm.Queryable<EntYW_UserDistributor>();
  1270. IJoiningQuery<EntSYS_DISTRIBUTORS, EntYW_UserDistributor> view = dis.LeftJoin(userdis, (user, city) => user.ID == city.distributorId);
  1271. int uid = saleid.ToInt32();
  1272. var q = view.Select((user, city) => new { Users = user, Citys = city }).Where(a => a.Citys.userId == uid);
  1273. //var q = orm.Queryable<EntSYS_DISTRIBUTORS>();
  1274. if (!keywords.IsEmpty())
  1275. {
  1276. q = q.Where(p => p.Users.NAME.Contains(keywords) && p.Users.BUSINESSLEVEL > 1);
  1277. }
  1278. else
  1279. {
  1280. q = q.Where(p => p.Users.BUSINESSLEVEL > 1);
  1281. }
  1282. if (!Request.QueryString["hkprov"].IsEmpty())
  1283. {
  1284. int Province = Request.QueryString["hkprov"].ToInt32();
  1285. q = q.Where(p => p.Users.Province == Province);
  1286. }
  1287. if (!Request.QueryString["hkcity"].IsEmpty())
  1288. {
  1289. int City = Request.QueryString["hkcity"].ToInt32();
  1290. q = q.Where(p => p.Users.City == City);
  1291. }
  1292. if (!Request.QueryString["hkcountry"].IsEmpty())
  1293. {
  1294. int Area = Request.QueryString["hkcountry"].ToInt32();
  1295. q = q.Where(p => p.Users.Area == Area);
  1296. }
  1297. int pageno = (page - 1) * pagesize;
  1298. var disreslut = q.OrderBy(a => a.Users.CODE).Skip(pageno).Top(pagesize).ToList(request);
  1299. if (disreslut.IsSuccess)
  1300. {
  1301. disreslut.RecordNum = q.Count();
  1302. List<EntSYS_DISTRIBUTORS> modlist = new List<EntSYS_DISTRIBUTORS>();
  1303. foreach (var item in disreslut.ResultModel)
  1304. {
  1305. modlist.Add(item.Users);
  1306. }
  1307. return new PageInfo(base.page, base.pagesize, disreslut.RecordNum, JsonConverter.JsonClass(modlist));
  1308. }
  1309. else
  1310. {
  1311. return new PageInfo(base.page, base.pagesize, disreslut.RecordNum, JsonConverter.JsonClass(new List<EntSYS_DISTRIBUTORS>()));
  1312. }
  1313. }
  1314. //return new PageInfo(result.Index, result.PageSize, result.Count, JsonConverter.JsonClass(list));
  1315. }
  1316. /// <summary>
  1317. /// 绑定页面需要的属性
  1318. /// </summary>
  1319. public PageInfo BindList(string posttype, string FK_DPTID, int usertype)
  1320. {
  1321. //var citystr = Request.QueryString["hkprov"] + "," + Request.QueryString["hkcity"] + "," + Request.QueryString["hkcountry"];
  1322. using (AntORM orm = new AntORM())
  1323. {
  1324. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1325. RequestModel request = new RequestModel();
  1326. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  1327. var q = orm.Queryable<EntSYS_DISTRIBUTORS>();
  1328. if (!keywords.IsEmpty())
  1329. {
  1330. q = q.Where(p => p.NAME.Contains(keywords) && p.BUSINESSLEVEL > 1);
  1331. }
  1332. else
  1333. {
  1334. q = q.Where(p => p.BUSINESSLEVEL > 1);
  1335. }
  1336. if (!Request.QueryString["hkprov"].IsEmpty())
  1337. {
  1338. int Province = Request.QueryString["hkprov"].ToInt32();
  1339. q = q.Where(p => p.Province == Province);
  1340. }
  1341. if (!Request.QueryString["hkcity"].IsEmpty())
  1342. {
  1343. int City = Request.QueryString["hkcity"].ToInt32();
  1344. q = q.Where(p => p.City == City);
  1345. }
  1346. if (!Request.QueryString["hkcountry"].IsEmpty())
  1347. {
  1348. int Area = Request.QueryString["hkcountry"].ToInt32();
  1349. q = q.Where(p => p.Area == Area);
  1350. }
  1351. if (usertype == 8)//风控管理员
  1352. {
  1353. q = q.Where(p => p.FenceRadius > 0);
  1354. }
  1355. int pageno = (page - 1) * pagesize;
  1356. var reslut = q.OrderBy(a => a.CODE).Skip(pageno).Top(pagesize).ToList(request);
  1357. //foreach (EntSYS_DISTRIBUTORS mod in reslut.ResultModel)
  1358. //{
  1359. // //mod.NAME = GetModuleName(mod.NAME, mod.BUSINESSLEVEL - 1).ToString();
  1360. // mod.NAME = mod.NAME;
  1361. // modlist.Add(mod);
  1362. //}
  1363. //var reslut= orm.SqlQuery<YW_Bicycle>(string.Format("select top {0} * from YW_Bicycle where Id>@Id", 1), new { Id = "sfdfdfdf" }).ToList();
  1364. if (reslut.IsSuccess)
  1365. {
  1366. reslut.RecordNum = q.Count();
  1367. List<EntSYS_DISTRIBUTORS> modlist = new List<EntSYS_DISTRIBUTORS>();
  1368. modlist = reslut.ResultModel;
  1369. return new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(modlist));
  1370. }
  1371. else
  1372. {
  1373. return new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(new List<EntSYS_DISTRIBUTORS>()));
  1374. }
  1375. }
  1376. //return new PageInfo(result.Index, result.PageSize, result.Count, JsonConverter.JsonClass(list));
  1377. }
  1378. /// <summary>
  1379. /// 显示错层方法
  1380. /// </summary>
  1381. private object GetModuleName(string name, decimal? level)
  1382. {
  1383. if (level > 0)
  1384. {
  1385. string nbsp = "&nbsp;&nbsp;";
  1386. for (int i = 0; i < level; i++)
  1387. {
  1388. nbsp += "&nbsp;&nbsp;";
  1389. }
  1390. name = nbsp + " |--" + name;
  1391. }
  1392. return name;
  1393. }
  1394. }
  1395. }