AlarmController.cs 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641
  1. using Ant.Data;
  2. using Ant.ORM;
  3. using Ant.SuperSocket.Common;
  4. using ChangFa.Machinery.Common;
  5. using ChangFa.Machinery.Common.Enums;
  6. using ChangFa.Machinery.Entity;
  7. using ChangFa.Machinery.Entity.Enum;
  8. using ChangFa.Machinery.Service.IService;
  9. using ChangFa.Machinery.Service.ServiceImp;
  10. using ChangFa.Machinery.Utility;
  11. using ChangFa.Machinery.WebPage.Controllers;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Data;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Transactions;
  19. using System.Web;
  20. using System.Web.Mvc;
  21. namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
  22. {
  23. public class AlarmController : BaseController
  24. {
  25. /// <summary>
  26. /// 字典编码
  27. /// </summary>
  28. ICodeManage CodeManage = new CodeManage();
  29. /// <summary>
  30. /// 经销商
  31. /// </summary>
  32. IDepartmentManage DepartmentManage = new DepartmentManage();
  33. // GET: SysManage/Alarm
  34. // [UserAuthorizeAttribute(ModuleAlias = "CarAlarmList", OperaAction = "View")]
  35. public ActionResult Index()
  36. {
  37. string carid = string.Empty; PageInfo alrmreslut; DateTime fromdate, todate;
  38. if (!Request.QueryString["carid"].IsEmpty())
  39. {
  40. carid = Request.QueryString["carid"].ToString();
  41. }
  42. var startdate = Request.Params["startdate"]; var enddate = Request.Params["enddate"];
  43. using (AntORM orm = new AntORM())
  44. {
  45. orm.db = DataAccessFactory.CreateDataConnection("CyclingItemLog");
  46. RequestModel request = new RequestModel();
  47. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  48. var q = orm.Queryable<YW_AlarmInformation>();
  49. if (!carid.IsEmpty())
  50. {
  51. q = q.Where(p => p.CarId == carid);
  52. }
  53. if (!startdate.IsEmpty() && enddate.IsEmpty())
  54. {
  55. fromdate = startdate.ToDateTime();
  56. q = q.Where(p => p.Add_Time == fromdate);
  57. }
  58. if (!enddate.IsEmpty() && startdate.IsEmpty())
  59. {
  60. todate = enddate.ToDateTime();
  61. q = q.Where(p => p.Add_Time == todate);
  62. }
  63. if (!startdate.IsEmpty() && !enddate.IsEmpty())
  64. {
  65. fromdate = startdate.ToDateTime();
  66. todate = enddate.ToDateTime();
  67. q = q.Where(p => p.Add_Time >= fromdate && p.Add_Time <= todate);
  68. }
  69. int pageno = (page - 1) * pagesize;
  70. var reslut = q.OrderByDesc(a => a.Add_Time).Skip(pageno).Top(pagesize).ToList(request);
  71. List<YW_AlarmInformation> modlist = new List<YW_AlarmInformation>();
  72. if (reslut.IsSuccess)
  73. {
  74. int count = q.Count();
  75. alrmreslut = new PageInfo(base.page, base.pagesize, count, JsonConverter.JsonClass(reslut.ResultModel));
  76. }
  77. else
  78. {
  79. alrmreslut = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<EntSYS_DISTRIBUTORS>()));
  80. }
  81. }
  82. ViewData["startdate"] = startdate;
  83. ViewData["enddate"] = enddate;
  84. return View(alrmreslut);
  85. }
  86. /// <summary>
  87. /// 页面标记显示
  88. /// </summary>
  89. /// <param name="id"></param>
  90. /// <returns></returns>
  91. public ActionResult MarkFence(string id)
  92. {
  93. ResponseAlarmCheckInfo markmod = new ResponseAlarmCheckInfo();
  94. try
  95. {
  96. using (AntORM orm = new AntORM())
  97. {
  98. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  99. RequestModel res = new RequestModel();
  100. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
  101. var usercarlist = orm.Queryable<YW_MarkAlarmFence>()
  102. .InnerJoin<EntYW_Bicycle>((user, city) => user.imei == city.CarID);
  103. //.InnerJoin<Entity.YW_CarPurchaser>((user, city, province) => city.CarID == province.carId);
  104. Guid guid = new Guid(id.Split(';')[0]);
  105. //var views = usercarlist.Select((strip, sbicycle, purchser) => new { Users = sbicycle, trip = strip, userpurch = purchser }).Where(p => p.trip.id == guid).FirstOrDefault(res);
  106. var views = usercarlist.Select((strip, sbicycle) => new { Users = sbicycle, trip = strip }).Where(p => p.trip.id == guid).FirstOrDefault(res);
  107. //.Where(p => p.Users.UserId == usermod.userInfo.uid)
  108. if (views.IsSuccess)
  109. {
  110. YW_MarkAlarmFence mod = views.ResultModel.trip; EntYW_Bicycle carmod = views.ResultModel.Users; //Entity.YW_CarPurchaser purchser = views.ResultModel.userpurch;
  111. markmod.imei = carmod.CarID;
  112. markmod.productBarCode = carmod.carBar;
  113. markmod.productModel = carmod.CarModel;
  114. markmod.productName = carmod.CarName;
  115. markmod.FactoryNumber = carmod.FactoryNumber;
  116. markmod.MarkFenceType = mod.MarkFenceType.ToString();
  117. markmod.state = mod.state.ToString();
  118. markmod.carType = carmod.carType.ToInt32();
  119. markmod.backPayTime = mod.backPayTime.ToDateTime();
  120. markmod.startDate = mod.MarkStartDate.ToDateTime();
  121. markmod.endDate = mod.MarkEndDate.ToDateTime();
  122. var purrchreslut = orm.Queryable<Entity.YW_CarPurchaser>().Where(p => p.carId == carmod.CarID).FirstOrDefault(res);
  123. if (purrchreslut.IsSuccess)
  124. {
  125. Entity.YW_CarPurchaser purchser = purrchreslut.ResultModel;
  126. markmod.name = purchser.userName;
  127. markmod.tel = purchser.userTel;
  128. markmod.saleDate = purchser.SaleDate.ToDateTime();
  129. }
  130. markmod.note = mod.notes;
  131. markmod.applyName = mod.add_name;
  132. markmod.apply_id = mod.id.ToString();
  133. markmod.carState = ChangFa.Machinery.Entity.GetCarState.getCarStateStr(carmod.CarSate.ToInt32());
  134. markmod.isOnLine = carmod.LeaseStatus.ToInt32();
  135. //if (mod.MarkFenceType == 30)
  136. //{
  137. // var distributorsreslut = orm.Queryable<EntSYS_DISTRIBUTORS>().Where(p => p.ID == carmod.DistributorsID).FirstOrDefault(res);
  138. // if (distributorsreslut.IsSuccess)
  139. // {
  140. // EntSYS_DISTRIBUTORS dismod = distributorsreslut.ResultModel;
  141. // markmod.distributorsAddress = dismod.Address;
  142. // markmod.distributorsName = dismod.NAME;
  143. // markmod.distributorsContact = "";
  144. // markmod.distributorsTel = "";
  145. // }
  146. //}
  147. markmod.productionDate = DateTimeUtility.ConvertDateTimeInt(carmod.productionDate.ToDateTime());
  148. }
  149. }
  150. return View(markmod);
  151. }
  152. catch (Exception e)
  153. {
  154. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  155. throw e.InnerException;
  156. }
  157. }
  158. public ActionResult MarkFenceList(string id)
  159. {
  160. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, Common.JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
  161. using (AntORM orm = new AntORM())
  162. {
  163. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  164. RequestModel res = new RequestModel
  165. {
  166. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取车辆信息" }
  167. };
  168. var q = orm.Queryable<Entity.YW_MarkAlarmFence>();
  169. if (id.IsEmpty())
  170. {
  171. return View(pageInfo);
  172. }
  173. q = q.Where(p => p.imei == id);
  174. int pageno = (page - 1) * pagesize;
  175. var tripreslut = q.OrderByDesc(p => p.add_time).Skip(pageno).Top(pagesize).ToList(res);
  176. if (tripreslut.IsSuccess)
  177. {
  178. tripreslut.RecordNum = q.Count();
  179. pageInfo = new PageInfo(base.page, base.pagesize, tripreslut.RecordNum, Common.JsonConverter.JsonClass(tripreslut.ResultModel));
  180. }
  181. }
  182. return View(pageInfo);
  183. }
  184. /// <summary>
  185. /// 所有农机设置围栏内成功
  186. /// </summary>
  187. /// <returns></returns>
  188. public ActionResult updateAlarmFence()
  189. {
  190. ChangFa.Machinery.Common.JsonHelper json = new ChangFa.Machinery.Common.JsonHelper() { Msg = "所有农机设置围栏内成功!", Status = "n", ReUrl = "/Car/CarAlarmList" };
  191. using (AntORM orm = new AntORM())
  192. {
  193. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  194. RequestModel res = new RequestModel
  195. {
  196. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  197. };
  198. var reslut = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { FenceState = 1 }, f => f.FenceState == 2, res);
  199. if (reslut.IsSuccess)
  200. {
  201. json.Status = "y";
  202. }
  203. }
  204. return Json(json);
  205. }
  206. /// <summary>
  207. /// 标记电子围栏
  208. /// </summary>
  209. /// <param name="id"></param>
  210. /// <returns></returns>
  211. public ActionResult markAlarmFence(string id)
  212. {
  213. using (AntORM orm = new AntORM())
  214. {
  215. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  216. RequestModel request = new RequestModel();
  217. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" };
  218. string gid = id.Split(';')[0]; string carid = id.Split(';')[1];
  219. var reslut = orm.Queryable<EntYW_Bicycle>().Where(p => p.CarID == carid).FirstOrDefault();
  220. if (reslut.IsSuccess)
  221. {
  222. EntYW_Bicycle mod = reslut.ResultModel;
  223. ViewData["carname"] = mod.CarName;
  224. ViewData["FactoryNumber"] = mod.FactoryNumber;
  225. ViewData["CarBar"] = mod.carBar;
  226. ViewData["CarID"] = mod.CarID;
  227. }
  228. }
  229. return View();
  230. }
  231. /// <summary>
  232. /// 保存报警标记
  233. /// </summary>
  234. /// <param name="id"></param>
  235. /// <returns></returns>
  236. public ActionResult SaveMarkAlarm()
  237. {
  238. ChangFa.Machinery.Common.JsonHelper json = new ChangFa.Machinery.Common.JsonHelper() { Msg = "报警标记保存成功", Status = "n", ReUrl = "/Car/CarAlarmList" };
  239. DateTime markstartdate = new DateTime(); DateTime markenddate = new DateTime();
  240. var startdate = Request.Params["startdate"]; var enddate = Request.Params["enddate"]; var carid = Request["CarID"];
  241. if (!startdate.IsEmpty())
  242. {
  243. markstartdate = startdate.ToDateTime();
  244. }
  245. if (!enddate.IsEmpty())
  246. {
  247. markenddate = enddate.ToDateTime();
  248. }
  249. var marktype = Request["CarSate"];
  250. if (marktype.IsEmpty() || marktype == "0")
  251. {
  252. json.Status = "n";
  253. json.Msg = "标记类型不能为空!";
  254. return Json(json);
  255. }
  256. var buyTime = DateTime.Now;//购买时间
  257. string backPayTime = Request.Params["backPayTime"]; //回款时间
  258. using (AntORM orm = new AntORM())
  259. {
  260. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  261. RequestModel request = new RequestModel();
  262. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "保存围栏信息" };
  263. YW_MarkAlarmFence mod = new YW_MarkAlarmFence();
  264. var q = orm.Queryable<YW_AlarmInformation>().Where(p => p.CarId == carid).OrderByDesc(p => p.Add_Time).FirstOrDefault(request);
  265. if (q.IsSuccess)
  266. {
  267. YW_AlarmInformation yW_Alarm = q.ResultModel;
  268. buyTime = yW_Alarm.Add_Time.ToDateTime();
  269. }
  270. var username = Request.Params["username"]; //购买人
  271. var userTel = Request.Params["userTel"]; //购买电话
  272. var userAddress = Request.Params["userAddress"]; //购买地址
  273. if (marktype == "10")//外出参展
  274. {
  275. mod.MarkStartDate = markstartdate;
  276. mod.MarkEndDate = markenddate;
  277. }
  278. if (marktype == "20") //销售未回款
  279. {
  280. if (username.IsEmpty())
  281. {
  282. json.Status = "n";
  283. json.Msg = "购买人不能为空!";
  284. return Json(json);
  285. }
  286. if (userTel.IsEmpty())
  287. {
  288. json.Status = "n";
  289. json.Msg = "购买人手机不能为空!";
  290. return Json(json);
  291. }
  292. var count = orm.Queryable<YW_MarkAlarmFence>().Where(p => p.imei == carid && p.state == 0).Count(); //查看是否有回款记录
  293. if (count > 0)
  294. {
  295. json.Status = "n";
  296. json.Msg = "这台农机已申请解除围栏,等待审核!";
  297. return Json(json);
  298. }
  299. mod.backPayTime = buyTime.ToDateTime().AddDays(10);
  300. YW_CarPurchaser enty = new YW_CarPurchaser();
  301. enty.ID = Guid.NewGuid();
  302. enty.imei = Request["CarID"];
  303. enty.userName = username;
  304. enty.userTel = userTel;
  305. enty.userAddress = userAddress;
  306. enty.carId = Request["CarID"];
  307. enty.carBar = Request["CarBar"];
  308. enty.addName = CurrentUser.Name;
  309. enty.SaleDate = buyTime;
  310. enty.addDate = DateTime.Now;
  311. var reslutPurchaser = orm.Save(enty, request);
  312. }
  313. if (marktype == "30")//销售已回款
  314. {
  315. if (username.IsEmpty())
  316. {
  317. json.Status = "n";
  318. json.Msg = "购买人不能为空!";
  319. return Json(json);
  320. }
  321. if (userTel.IsEmpty())
  322. {
  323. json.Status = "n";
  324. json.Msg = "购买人手机不能为空!";
  325. return Json(json);
  326. }
  327. var count = orm.Queryable<YW_MarkAlarmFence>().Where(p => p.imei == carid && p.state == 0).Count(); //查看是否有回款记录
  328. if (count > 0)
  329. {
  330. json.Status = "n";
  331. json.Msg = "这台农机已申请解除围栏,等待审核!";
  332. return Json(json);
  333. }
  334. YW_CarPurchaser enty = new YW_CarPurchaser();
  335. enty.ID = Guid.NewGuid();
  336. enty.imei = Request["CarID"];
  337. enty.userName = username;
  338. enty.userTel = userTel;
  339. enty.userAddress = userAddress;
  340. enty.carId = Request["CarID"];
  341. enty.carBar = Request["CarBar"];
  342. enty.addName = CurrentUser.Name;
  343. enty.SaleDate = buyTime.ToDateTime();
  344. enty.addDate = DateTime.Now;
  345. var reslutPurchaser = orm.Save(enty, request);
  346. }
  347. if (marktype == "40")//其他
  348. {
  349. mod.MarkStartDate = markstartdate;
  350. mod.MarkEndDate = markenddate;
  351. }
  352. mod.id = Guid.NewGuid();
  353. mod.MarkFenceType = marktype.ToInt32();
  354. mod.notes = Request["notes"];
  355. mod.imei = Request["CarID"];
  356. mod.CarBar = Request["CarBar"];
  357. mod.add_name = CurrentUser.Name;
  358. mod.state = 0;
  359. var reslut = orm.Save(mod, request);
  360. if (reslut.IsSuccess)
  361. {
  362. json.Status = "y";
  363. }
  364. }
  365. return Json(json);
  366. }
  367. /// <summary>
  368. /// 保存审核结果
  369. /// </summary>
  370. /// <returns></returns>
  371. public ActionResult SaveApplyCheck(string apply_id)
  372. {
  373. ChangFa.Machinery.Common.JsonHelper json = new ChangFa.Machinery.Common.JsonHelper() { Msg = "标记审核成功", Status = "n", ReUrl = "/Car/DistributorCarList" };
  374. var notes = Request["notes"];
  375. var state = Request["checkstate"];
  376. try
  377. {
  378. if (state == "1")
  379. {
  380. using (AntORM orm = new AntORM())
  381. {
  382. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  383. RequestModel res = new RequestModel();
  384. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
  385. Guid guid = new Guid(apply_id);
  386. var reslut = orm.Queryable<YW_MarkAlarmFence>().Where(p => p.id == guid).FirstOrDefault(res);
  387. if (reslut.IsSuccess)
  388. {
  389. YW_MarkAlarmFence mod = reslut.ResultModel;
  390. if (mod.MarkFenceType == 10 || mod.MarkFenceType == 40)//外出参展 //其它
  391. {
  392. var reslutapply = orm.UpdateByLambda<YW_MarkAlarmFence>(p => new YW_MarkAlarmFence { state = 1 }, f => f.id == guid, res);
  393. json.Status = "y";
  394. }
  395. if (mod.MarkFenceType == 30 || mod.MarkFenceType == 20)//销售已回款//销售未回款
  396. {
  397. using (TransactionScope ts = new TransactionScope())
  398. {
  399. int carstate = CarState.Sales.ToInt32();
  400. var reslutcar = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { CarSate = carstate, FenceState = 1, UpdateDate = DateTime.Now }, f => f.CarID == mod.imei, res);
  401. if (reslutcar.IsSuccess)
  402. {
  403. string strdate = "审核通过时间:" + DateTime.Now;
  404. var reslutapply = orm.UpdateByLambda<YW_MarkAlarmFence>(p => new YW_MarkAlarmFence { state = 1, noPassNote = strdate }, f => f.id == guid, res);
  405. }
  406. ts.Complete(); //完成事务,这个必须加上,要不然事务不会有效
  407. json.Status = "y";
  408. WriteLog(enumOperator.Remove, "解除围栏:" + json.Msg, enumLog4net.WARN);
  409. try
  410. {
  411. Utility.SocketClient client = new Utility.SocketClient();
  412. var str = DataHelper.sendRemoveFence(Convert.ToInt64(mod.imei));
  413. var body = DataHelper.HexToByte(str);
  414. string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString();
  415. int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32();
  416. client.Connect(ip, port);
  417. var flag = client.SendData(body);
  418. client.Disconnect();
  419. }
  420. catch (Exception ex)
  421. {
  422. }
  423. }
  424. }
  425. }
  426. }
  427. }
  428. else
  429. {
  430. if (notes.IsEmpty())
  431. {
  432. json.Msg = "审核不通过,不通过原因必填!";
  433. json.Msg = "n";
  434. return Json(json);
  435. }
  436. using (AntORM orm = new AntORM())
  437. {
  438. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  439. RequestModel res = new RequestModel();
  440. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
  441. Guid guid = new Guid(apply_id);
  442. var reslutapply = orm.UpdateByLambda<YW_MarkAlarmFence>(p => new YW_MarkAlarmFence { state = 2, noPassNote = notes }, f => f.id == guid, res);
  443. if (reslutapply.IsSuccess)
  444. {
  445. json.Msg = "审核不通过!";
  446. json.Status = "y";
  447. return Json(json);
  448. }
  449. }
  450. }
  451. }
  452. catch (Exception ex)
  453. {
  454. json.Msg = "审核失败:" + ex.Message;
  455. }
  456. return Json(json);
  457. }
  458. /// <summary>
  459. /// 解除电子围栏作废
  460. /// </summary>
  461. /// <returns></returns>
  462. public ActionResult RemoveFence(string id)
  463. {
  464. RemoveFenceEntity model = new RemoveFenceEntity();
  465. model.bicycle = new EntYW_Bicycle();
  466. using (AntORM orm = new AntORM())
  467. {
  468. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  469. RequestModel request = new RequestModel();
  470. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" };
  471. string gid = id.Split(';')[0]; string carid = id.Split(';')[1];
  472. var reslut = orm.Queryable<EntYW_Bicycle>().Where(p => p.CarID == carid).FirstOrDefault();
  473. if (reslut.IsSuccess)
  474. {
  475. EntYW_Bicycle mod = reslut.ResultModel;
  476. model.bicycle = mod;
  477. model.bicycle.Createper = GetCarState(mod.CarSate.ToInt32());
  478. }
  479. }
  480. ViewBag.dpt = this.DepartmentManage.GetDepartmentByDetail();
  481. return View(model);
  482. }
  483. /// <summary>
  484. /// 解除电子围栏审核
  485. /// </summary>
  486. /// <param name="id"></param>
  487. /// <returns></returns>
  488. public ActionResult RemoveAlarmFenceCheck(string idList)
  489. {
  490. ChangFa.Machinery.Common.JsonHelper json = new ChangFa.Machinery.Common.JsonHelper() { Msg = "解除电子围栏成功", Status = "n", ReUrl = "/Car/CarAlarmList" };
  491. var idList1 = idList.Split(';').ToList();
  492. if (idList1.Count > 0)
  493. {
  494. string carid = idList1[1];
  495. Guid id = new Guid(idList1[0]);
  496. using (AntORM orm = new AntORM())
  497. {
  498. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  499. RequestModel res = new RequestModel();
  500. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  501. var reslut = orm.Queryable<YW_MarkAlarmFence>().Where(p => p.imei == carid).FirstOrDefault(res); //查看是否有回款记录
  502. if (reslut.IsSuccess)
  503. {
  504. YW_MarkAlarmFence mod = reslut.ResultModel;
  505. if (mod.MarkFenceType == 10)
  506. {
  507. }
  508. if (mod.MarkFenceType == 20)
  509. {
  510. }
  511. if (mod.MarkFenceType == 30)
  512. {
  513. int carstate = CarState.Sales.ToInt32();
  514. var reslutcar = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { CarSate = carstate, FenceState = 1 }, f => f.ID == id, res);
  515. if (reslutcar.IsSuccess)
  516. {
  517. json.Status = "y";
  518. WriteLog(enumOperator.Remove, "解除围栏:" + json.Msg, enumLog4net.WARN);
  519. try
  520. {
  521. Utility.SocketClient client = new Utility.SocketClient();
  522. var str = DataHelper.sendRemoveFence(Convert.ToInt64(carid));
  523. var body = DataHelper.HexToByte(str);
  524. string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString();
  525. int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32();
  526. client.Connect(ip, port);
  527. var flag = client.SendData(body);
  528. client.Disconnect();
  529. }
  530. catch (Exception ex)
  531. {
  532. }
  533. }
  534. }
  535. }
  536. else
  537. {
  538. json.Status = "n";
  539. json.Msg = "未回款的农机,无法解除电子围栏!";
  540. }
  541. }
  542. }
  543. else
  544. {
  545. json.Status = "n";
  546. json.Msg = "选择不正确,请重新选择!";
  547. }
  548. return Json(json);
  549. }
  550. public static string GetFenceMarkType(string carid)
  551. {
  552. string str = string.Empty;
  553. using (AntORM orm = new AntORM())
  554. {
  555. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  556. RequestModel res = new RequestModel();
  557. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  558. var reslut = orm.Queryable<YW_MarkAlarmFence>().Where(p => p.imei == carid).FirstOrDefault(res); //查看是否有回款记录
  559. if (reslut.IsSuccess)
  560. {
  561. YW_MarkAlarmFence markAlarmFence = reslut.ResultModel;
  562. switch (markAlarmFence.MarkFenceType)
  563. {
  564. case 10:
  565. {
  566. str = "外出参展";
  567. }
  568. break;
  569. case 20:
  570. {
  571. str = "销售未回款";
  572. }
  573. break;
  574. case 30:
  575. {
  576. str = "销售已回款";
  577. }
  578. break;
  579. case 40:
  580. {
  581. str = "其它";
  582. }
  583. break;
  584. }
  585. return str;
  586. }
  587. }
  588. return "";
  589. }
  590. /// <summary>
  591. /// 加载列表
  592. /// </summary>
  593. /// <returns></returns>
  594. [UserAuthorizeAttribute(ModuleAlias = "MarkCheckList", OperaAction = "View")]
  595. public ActionResult MarkCheckList()
  596. {
  597. try
  598. {
  599. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, Common.JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
  600. #region 处理查询参数
  601. var posttype = Request.QueryString["PostType"];
  602. string FK_DPTID = Request.QueryString["FK_DPTID"];
  603. string CarSate = Request.QueryString["CarSate"];
  604. string barcode = Request.QueryString["txt_barcode"];
  605. string imei = Request.QueryString["txt_imei"];
  606. string factoryNumber = Request.QueryString["txt_factoryNumber"];
  607. int markType = Request.QueryString["LeaseStatus"].ToInt32();
  608. int fenceCheck = Request.QueryString["FenceState"].ToInt32();
  609. int prov = Request.QueryString["hkprov"].ToInt32();
  610. int state = -1;
  611. if (!CarSate.IsEmpty())
  612. {
  613. state = CarSate.ToInt32();
  614. }
  615. #endregion
  616. #region 加载列表
  617. List<AlarmFenceModel> carlist = new List<AlarmFenceModel>();
  618. using (AntORM orm = new AntORM())
  619. {
  620. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  621. RequestModel res = new RequestModel();
  622. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
  623. var usercarlist = orm.Queryable<YW_MarkAlarmFence>()
  624. .LeftJoin<EntYW_Bicycle>((user, city) => user.imei == city.CarID)
  625. .LeftJoin<EntSYS_DISTRIBUTORS>((user, city, province) => city.DistributorsID == province.ID);
  626. int pageno = (base.page - 1) * base.pagesize;
  627. var views = usercarlist.Select((strip, sbicycle, sdis) => new { Users = sbicycle, trip = strip, dis = sdis });
  628. if (posttype != "-1" && !posttype.IsEmpty())
  629. {
  630. var type = posttype.ToInt32();
  631. views = views.Where(p => p.trip.MarkFenceType == type);
  632. }
  633. if (state > 0)
  634. {
  635. views = views.Where(p => p.Users.CarSate == state);
  636. }
  637. else
  638. {
  639. views = views.Where(p => p.Users.CarSate > 0);
  640. }
  641. if (!factoryNumber.IsEmpty())
  642. {
  643. views = views.Where(p => p.Users.FactoryNumber.Contains(factoryNumber));
  644. }
  645. if (!imei.IsEmpty())
  646. {
  647. views = views.Where(p => p.Users.CarID.Contains(imei));
  648. }
  649. if (prov > 0)
  650. {
  651. views = views.Where(p => p.dis.Province == prov);
  652. }
  653. if (!FK_DPTID.IsEmpty())
  654. {
  655. views = views.Where(p => p.Users.DistributorsID == FK_DPTID);
  656. }
  657. if (fenceCheck >= 0)
  658. {
  659. views = views.Where(p => p.trip.state == fenceCheck);
  660. }
  661. if (markType > 10)
  662. {
  663. views = views.Where(p => p.trip.MarkFenceType == markType);
  664. }
  665. views = views.Where(p => p.trip.imei != "");
  666. var reslut = views.OrderBy(p => p.trip.imei).ThenByDesc(p => p.trip.state).ThenByDesc(p => p.trip.add_time).Skip(pageno).Top(pagesize).ToList(res);
  667. //.Where(p => p.Users.UserId == usermod.userInfo.uid)
  668. if (reslut.IsSuccess)
  669. {
  670. reslut.RecordNum = views.Count();
  671. foreach (var list in reslut.ResultModel)
  672. {
  673. AlarmFenceModel carReturn = new AlarmFenceModel();
  674. YW_MarkAlarmFence mod = list.trip; EntYW_Bicycle carmod = list.Users; //Entity.YW_CarPurchaser purchser = list.userpurch;
  675. carReturn.bicycle = carmod;
  676. carReturn.fenceMark = mod;
  677. carlist.Add(carReturn);
  678. }
  679. pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, Common.JsonConverter.JsonClass(carlist));
  680. }
  681. }
  682. ViewBag.Search = base.keywords;
  683. ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList();
  684. ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew();
  685. ViewData["dptid"] = FK_DPTID;
  686. ViewData["CarSate"] = CarSate;
  687. ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList();
  688. ViewData["typecar"] = markType;
  689. ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList();
  690. ViewData["barcode"] = barcode;
  691. ViewData["factoryNumber"] = factoryNumber;
  692. ViewData["FenceState"] = fenceCheck;
  693. ViewData["imei"] = imei;
  694. if (!Request.QueryString["hkprov"].IsEmpty())
  695. {
  696. ViewData["hkprov"] = Request.QueryString["hkprov"];
  697. }
  698. return View(pageInfo);
  699. #endregion
  700. }
  701. catch (Exception e)
  702. {
  703. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  704. throw e.InnerException;
  705. }
  706. }
  707. /// <summary>
  708. /// 导出报警审核EXECL
  709. /// </summary>
  710. /// <returns></returns>
  711. public FileResult MarkChecExecl()
  712. {
  713. try
  714. {
  715. NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
  716. //添加一个sheet
  717. NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
  718. //给sheet1添加第一行的头部标题
  719. NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
  720. row1.CreateCell(0).SetCellValue("农机IMEI号");
  721. row1.CreateCell(1).SetCellValue("农机名称");
  722. row1.CreateCell(2).SetCellValue("农机型号");
  723. row1.CreateCell(3).SetCellValue("车架号");
  724. row1.CreateCell(4).SetCellValue("所属经销商");
  725. row1.CreateCell(5).SetCellValue("围栏状态");
  726. row1.CreateCell(6).SetCellValue("出厂日期");
  727. row1.CreateCell(7).SetCellValue("出厂编号");
  728. row1.CreateCell(8).SetCellValue("超出围栏时间");
  729. row1.CreateCell(9).SetCellValue("超出时长");
  730. //row1.CreateCell(10).SetCellValue("报警次数");
  731. //row1.CreateCell(11).SetCellValue("最后一次点火时间");
  732. //row1.CreateCell(12).SetCellValue("最后一次点火地址");
  733. row1.CreateCell(10).SetCellValue("标记类型");
  734. row1.CreateCell(11).SetCellValue("标记人");
  735. row1.CreateCell(12).SetCellValue("标记时间");
  736. row1.CreateCell(13).SetCellValue("审核状态");
  737. #region 处理查询参数
  738. //var posttype = Request.QueryString["PostType"];
  739. //string FK_DPTID = Request.QueryString["FK_DPTID"];
  740. string CarSate = Request.QueryString["CarSate"];
  741. int markType = Request.QueryString["fencetype"].ToInt32();
  742. int fenceCheck = Request.QueryString["checktype"].ToInt32();
  743. int prov = Request.QueryString["hkprov"].ToInt32();
  744. int state = -1;
  745. if (!CarSate.IsEmpty())
  746. {
  747. state = CarSate.ToInt32();
  748. }
  749. #endregion
  750. #region 加载列表
  751. List<AlarmFenceModel> carlist = new List<AlarmFenceModel>();
  752. using (AntORM orm = new AntORM())
  753. {
  754. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  755. RequestModel res = new RequestModel();
  756. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
  757. var usercarlist = orm.Queryable<YW_MarkAlarmFence>()
  758. .LeftJoin<EntYW_Bicycle>((user, city) => user.imei == city.CarID)
  759. .LeftJoin<EntSYS_DISTRIBUTORS>((alarm, car, dis) => car.DistributorsID == dis.ID)
  760. .LeftJoin<DeviceManage>((alarm, car, dis, device) => alarm.imei == device.IMEI);
  761. var views = usercarlist.Select((strip, sbicycle, sdis, sdevice) => new { Users = sbicycle, trip = strip, dis = sdis, device = sdevice });
  762. if (markType > 0)
  763. {
  764. views = views.Where(p => p.trip.MarkFenceType == markType);
  765. }
  766. if (state > 0)
  767. {
  768. views = views.Where(p => p.Users.CarSate == state);
  769. }
  770. else
  771. {
  772. views = views.Where(p => p.Users.CarSate > 0);
  773. }
  774. if (prov > 0)
  775. {
  776. views = views.Where(p => p.dis.Province == prov);
  777. }
  778. //if (!FK_DPTID.IsEmpty())
  779. //{
  780. // views = views.Where(p => p.Users.DistributorsID == FK_DPTID);
  781. //}
  782. if (fenceCheck >= 0)
  783. {
  784. views = views.Where(p => p.trip.state == fenceCheck);
  785. }
  786. if (markType > 10)
  787. {
  788. views = views.Where(p => p.trip.MarkFenceType == markType);
  789. }
  790. views = views.Where(p => p.trip.imei != "");
  791. var reslut = views.OrderBy(p => p.trip.imei).ThenByDesc(p => p.trip.state).ThenByDesc(p => p.trip.add_time).ToList(res);
  792. //.Where(p => p.Users.UserId == usermod.userInfo.uid)
  793. if (reslut.IsSuccess)
  794. {
  795. reslut.RecordNum = views.Count(); int i = 0;
  796. foreach (var list in reslut.ResultModel)
  797. {
  798. AlarmFenceModel carReturn = new AlarmFenceModel();
  799. YW_MarkAlarmFence mod = list.trip; EntYW_Bicycle carmod = list.Users; //Entity.YW_CarPurchaser purchser = list.userpurch;
  800. DeviceManage device = list.device;
  801. carReturn.bicycle = carmod;
  802. carReturn.fenceMark = mod;
  803. carlist.Add(carReturn);
  804. i++;
  805. NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i);
  806. rowtemp.CreateCell(0).SetCellValue(carmod.CarID);
  807. rowtemp.CreateCell(1).SetCellValue(carmod.CarName);
  808. rowtemp.CreateCell(2).SetCellValue(carmod.CarModel);
  809. rowtemp.CreateCell(3).SetCellValue(carmod.carBar);
  810. rowtemp.CreateCell(4).SetCellValue(carmod.DistributorsName);
  811. string carstatestr = "";
  812. switch (carmod.FenceState)
  813. {
  814. case 0:
  815. carstatestr = "未点火"; break;
  816. case 1:
  817. carstatestr = "围栏内"; break;
  818. case 2:
  819. carstatestr = "围栏外"; break;
  820. }
  821. rowtemp.CreateCell(5).SetCellValue(carstatestr);
  822. rowtemp.CreateCell(6).SetCellValue(carmod.productionDate.ToString());
  823. rowtemp.CreateCell(7).SetCellValue(carmod.FactoryNumber);
  824. rowtemp.CreateCell(8).SetCellValue(carmod.OutFenceDate.ToString());
  825. var num = Utility.DateTimeUtility.DateTimeDifference(Convert.ToDateTime(carmod.OutFenceDate), DateTime.Now);
  826. rowtemp.CreateCell(9).SetCellValue(num);
  827. //try
  828. //{
  829. // orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  830. // string sql = "select count(1) as num from YW_AlarmInformation where CarId='" + carmod.CarID + "' group by CarId";
  831. // var sum = orm.db.ExecuteScalar(sql).ToInt32();
  832. // rowtemp.CreateCell(10).SetCellValue(sum.ToString());
  833. //}
  834. //catch
  835. //{
  836. // rowtemp.CreateCell(10).SetCellValue(0);
  837. //}
  838. //var lng = device.longitude.ToDou(); var lat = device.latitude.ToDou();
  839. //var root = Utility.ToolGPSamap.GPS2Position(lng, lat);
  840. //string address = "";
  841. //if (root.IfNotNull())
  842. //{
  843. // address = root.formatted_address;
  844. // rowtemp.CreateCell(11).SetCellValue(device.LastOnlineTime.ToString());
  845. // rowtemp.CreateCell(12).SetCellValue(address);
  846. //}
  847. var mark = mod.MarkFenceType.ToString();
  848. if (mark == "20")
  849. {
  850. rowtemp.CreateCell(10).SetCellValue("销售未回款 ");
  851. }
  852. else
  853. {
  854. if (mark == "30")
  855. {
  856. rowtemp.CreateCell(10).SetCellValue("销售已回款 ");
  857. }
  858. }
  859. rowtemp.CreateCell(11).SetCellValue(mod.add_name.ToString());
  860. rowtemp.CreateCell(12).SetCellValue(mod.add_time.ToString());
  861. var states = mod.state.ToString();
  862. if (states == "1")
  863. {
  864. rowtemp.CreateCell(13).SetCellValue("已通过");
  865. }
  866. else
  867. {
  868. if (states == "2")
  869. {
  870. rowtemp.CreateCell(13).SetCellValue("未通过");
  871. }
  872. else
  873. rowtemp.CreateCell(13).SetCellValue("未审核");
  874. }
  875. }
  876. }
  877. }
  878. #endregion
  879. // 写入到客户端
  880. System.IO.MemoryStream ms = new System.IO.MemoryStream();
  881. book.Write(ms);
  882. ms.Seek(0, SeekOrigin.Begin);
  883. return File(ms, "application/vnd.ms-excel", "农机标记审核.xls");
  884. }
  885. catch (Exception e)
  886. {
  887. throw e.InnerException;
  888. }
  889. }
  890. /// <summary>
  891. /// 添加购买人的信息
  892. /// </summary>
  893. /// <param name="removeFence"></param>
  894. /// <returns></returns>
  895. public ActionResult Save(RemoveFenceEntity removeFence)
  896. {
  897. ChangFa.Machinery.Common.JsonHelper json = new ChangFa.Machinery.Common.JsonHelper() { Msg = "解除电子围栏成功", Status = "n", ReUrl = "/Car/CarAlarmList" };
  898. string carid = removeFence.bicycle.CarID;
  899. using (AntORM orm = new AntORM())
  900. {
  901. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  902. RequestModel res = new RequestModel();
  903. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  904. var datesale = removeFence.userCode.ToDateTime();
  905. YW_CarPurchaser mod = new YW_CarPurchaser();
  906. mod.ID = Guid.NewGuid();
  907. mod.imei = removeFence.bicycle.CarID;
  908. mod.userName = removeFence.userName;
  909. mod.userTel = removeFence.userTel;
  910. mod.userAddress = removeFence.userAddress;
  911. mod.carId = removeFence.bicycle.CarID;
  912. mod.carBar = removeFence.bicycle.carBar;
  913. mod.addName = CurrentUser.Name;
  914. mod.SaleDate = datesale;
  915. mod.addDate = DateTime.Now;
  916. var reslutPurchaser = orm.Save(mod, res);
  917. int carstate = CarState.Sales.ToInt32();
  918. var reslut = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { CarSate = carstate, SaleDate = datesale }, f => f.ID == removeFence.bicycle.ID, res);
  919. if (reslut.IsSuccess)
  920. {
  921. json.Status = "y";
  922. WriteLog(enumOperator.Remove, "解除围栏:" + json.Msg, enumLog4net.WARN);
  923. try
  924. {
  925. Utility.SocketClient client = new Utility.SocketClient();
  926. var str = DataHelper.sendRemoveFence(Convert.ToInt64(carid));
  927. var body = DataHelper.HexToByte(str);
  928. string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString();
  929. int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32();
  930. client.Connect(ip, port);
  931. var flag = client.SendData(body);
  932. client.Disconnect();
  933. }
  934. catch (Exception ex)
  935. {
  936. }
  937. }
  938. }
  939. return Json(json);
  940. }
  941. /// <summary>
  942. /// 加载农机报警列表
  943. /// </summary>
  944. /// <returns></returns>
  945. [UserAuthorizeAttribute(ModuleAlias = "carAlarmList", OperaAction = "View")]
  946. public ActionResult CarAlarmList()
  947. {
  948. try
  949. {
  950. string posttype = Request.QueryString["posttype"];
  951. string FK_DPTID = Request.QueryString["FK_DPTID"];
  952. string CarSate = Request.QueryString["CarSate"];
  953. int carType = Request.QueryString["LeaseStatus"].ToInt32();
  954. string barcode = Request.QueryString["txt_barcode"];
  955. string imei = Request.QueryString["txt_imei"];
  956. string factoryNumber = Request.QueryString["txt_factoryNumber"];
  957. string alarmDate = Request.QueryString["txt_AlarmDate"];
  958. int car_state = CarState.SalesNoReturned.GetHashCode();
  959. int prov = Request.QueryString["hkprov"].ToInt32();
  960. int FenceState = -1;
  961. if (!Request.QueryString["FenceState"].IsEmpty())
  962. {
  963. FenceState = Request.QueryString["FenceState"].ToInt32();
  964. }
  965. int state = -1;
  966. if (!CarSate.IsEmpty())
  967. {
  968. state = CarSate.ToInt32();
  969. }
  970. string distributorsID = string.Empty;
  971. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, Common.JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
  972. if (CurrentUser.USERTYPE == 0 || CurrentUser.USERTYPE == 8)
  973. {
  974. using (AntORM orm = new AntORM())
  975. {
  976. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  977. RequestModel res = new RequestModel
  978. {
  979. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  980. };
  981. var q = orm.Queryable<EntYW_Bicycle>().LeftJoin<EntSYS_DISTRIBUTORS>((car, dis) => car.DistributorsID == dis.ID);
  982. var view = q.Select((scar, sdis) => new { Car = scar, dis = sdis });
  983. view = view.Where(p => p.Car.CarSate < car_state);
  984. if (carType > 0)
  985. view = view.Where(p => p.Car.ProductLine == carType);
  986. if (!FK_DPTID.IsEmpty())
  987. view = view.Where(p => p.Car.DistributorsID == FK_DPTID);
  988. if (!barcode.IsEmpty())
  989. {
  990. view = view.Where(p => p.Car.carBar.Contains(barcode));
  991. }
  992. if (!imei.IsEmpty())
  993. {
  994. view = view.Where(p => p.Car.CarID.Contains(imei));
  995. }
  996. view = view.Where(p => p.Car.FenceState == 2);
  997. if (state >= 0)
  998. {
  999. view = view.Where(p => p.Car.CarSate == state);
  1000. }
  1001. if (!factoryNumber.IsEmpty())
  1002. {
  1003. view = view.Where(p => p.Car.FactoryNumber == factoryNumber);
  1004. }
  1005. if (prov > 0)
  1006. {
  1007. view = view.Where(p => p.dis.Province == prov);
  1008. }
  1009. if (!alarmDate.IsEmpty())
  1010. {
  1011. DateTime fromdate = alarmDate.ToDateTime().ToString("yyyy-MM-dd").ToDateTime().AddSeconds(-1);
  1012. DateTime todate = alarmDate.ToDateTime();
  1013. view = view.Where(p => p.Car.OutFenceDate > fromdate && p.Car.OutFenceDate < todate);
  1014. }
  1015. int pageno = (page - 1) * pagesize;
  1016. var bicycleList = view.OrderByDesc(a => a.Car.OutFenceDate).Skip(pageno).Top(pagesize).ToList();
  1017. if (bicycleList.IsSuccess)
  1018. {
  1019. bicycleList.RecordNum = view.Count();
  1020. List<EntYW_Bicycle> listcar = new List<EntYW_Bicycle>();
  1021. foreach (var item in bicycleList.ResultModel)
  1022. {
  1023. EntYW_Bicycle bicycle = item.Car;
  1024. listcar.Add(bicycle);
  1025. }
  1026. pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, Common.JsonConverter.JsonClass(listcar));
  1027. }
  1028. }
  1029. }
  1030. else
  1031. {
  1032. if (CurrentUser.USERTYPE == 2) //业务员
  1033. {
  1034. int saleid = CurrentUser.Id;
  1035. using (AntORM orm = new AntORM())
  1036. {
  1037. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1038. RequestModel res = new RequestModel
  1039. {
  1040. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1041. };
  1042. IQuery<EntYW_Bicycle> car = orm.Queryable<EntYW_Bicycle>();
  1043. IQuery<EntYW_UserDistributor> userdis = orm.Queryable<EntYW_UserDistributor>();
  1044. IJoiningQuery<EntYW_Bicycle, EntYW_UserDistributor> user_city = car.LeftJoin(userdis, (user, city) => user.DistributorsID == city.distributorId && (user.ProductLine == city.ProductLine || user.ProductLine == city.ProductLine1 || user.ProductLine == city.ProductLine2 || user.ProductLine == city.ProductLine3 || user.ProductLine == city.ProductLine4 || user.ProductLine == city.ProductLine5));
  1045. var qq = user_city.Select((user, city) => new { Users = user, Citys = city }).Where(a => a.Citys.userId == saleid);
  1046. if (!Request.QueryString["CarSate"].IsEmpty())
  1047. {
  1048. int carstate = CarState.Storage.ToInt32();
  1049. }
  1050. if (carType > 0)
  1051. {
  1052. qq = qq.Where(p => p.Users.ProductLine == carType);
  1053. }
  1054. if (!barcode.IsEmpty())
  1055. {
  1056. qq = qq.Where(p => p.Users.carBar.Contains(barcode));
  1057. }
  1058. if (!imei.IsEmpty())
  1059. {
  1060. qq = qq.Where(p => p.Users.CarID.Contains(imei));
  1061. }
  1062. qq = qq.Where(p => p.Users.FenceState == 2);
  1063. if (state >= 0)
  1064. {
  1065. qq = qq.Where(p => p.Users.CarSate == state);
  1066. }
  1067. qq = qq.Where(p => p.Users.CarSate < car_state && p.Users.FenceState == 2);
  1068. if (!factoryNumber.IsEmpty())
  1069. {
  1070. qq = qq.Where(p => p.Users.FactoryNumber == factoryNumber);
  1071. }
  1072. if (!alarmDate.IsEmpty())
  1073. {
  1074. DateTime fromdate = alarmDate.ToDateTime().ToString("yyyy-MM-dd").ToDateTime().AddSeconds(-1);
  1075. DateTime todate = alarmDate.ToDateTime();
  1076. qq = qq.Where(p => p.Users.OutFenceDate > fromdate && p.Users.OutFenceDate < todate);
  1077. }
  1078. int pageno = (page - 1) * pagesize;
  1079. var bicycleList = qq.OrderByDesc(p => p.Users.OutFenceDate).Skip(pageno).Top(pagesize).ToList();
  1080. if (bicycleList.IsSuccess)
  1081. {
  1082. bicycleList.RecordNum = qq.Count();
  1083. List<EntYW_Bicycle> listcar = new List<EntYW_Bicycle>();
  1084. foreach (var item in bicycleList.ResultModel)
  1085. {
  1086. EntYW_Bicycle carmode = item.Users;
  1087. listcar.Add(carmode);
  1088. }
  1089. pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, Common.JsonConverter.JsonClass(listcar));
  1090. }
  1091. }
  1092. }
  1093. }
  1094. int uid = 0;
  1095. if (CurrentUser.USERTYPE == 2)
  1096. {
  1097. uid = CurrentUser.Id;
  1098. }
  1099. ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew(uid, prov);
  1100. if (!Request.QueryString["hkprov"].IsEmpty())
  1101. {
  1102. ViewData["hkprov"] = Request.QueryString["hkprov"];
  1103. }
  1104. ViewData["dptid"] = FK_DPTID;
  1105. ViewData["CarSate"] = CarSate;
  1106. ViewData["FenceState"] = FenceState;
  1107. ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList();
  1108. ViewData["typecar"] = carType;
  1109. ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList();
  1110. ViewData["barcode"] = barcode;
  1111. ViewData["factoryNumber"] = factoryNumber;
  1112. ViewData["alarmDate"] = alarmDate;
  1113. ViewData["imei"] = imei;
  1114. return View(pageInfo);
  1115. }
  1116. catch (Exception e)
  1117. {
  1118. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  1119. throw e.InnerException;
  1120. }
  1121. }
  1122. /// <summary>
  1123. /// 加载农机报警列表
  1124. /// </summary>
  1125. /// <returns></returns>
  1126. [UserAuthorizeAttribute(ModuleAlias = "carAlarmList", OperaAction = "View")]
  1127. public ActionResult CarAlarmListbak()
  1128. {
  1129. try
  1130. {
  1131. string posttype = Request.QueryString["posttype"];
  1132. string FK_DPTID = Request.QueryString["FK_DPTID"];
  1133. string CarSate = Request.QueryString["CarSate"];
  1134. string barcode = Request.QueryString["txt_barcode"];
  1135. string imei = Request.QueryString["txt_imei"];
  1136. int FenceState = -1;
  1137. if (!Request.QueryString["FenceState"].IsEmpty())
  1138. {
  1139. FenceState = Request.QueryString["FenceState"].ToInt32();
  1140. }
  1141. int carType = Request.QueryString["LeaseStatus"].ToInt32();
  1142. int state = -1;
  1143. if (!CarSate.IsEmpty())
  1144. {
  1145. state = CarSate.ToInt32();
  1146. }
  1147. string distributorsID = string.Empty;
  1148. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, Common.JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
  1149. if (CurrentUser.USERTYPE == 0 || CurrentUser.USERTYPE == 8) //管理员
  1150. {
  1151. using (AntORM orm = new AntORM())
  1152. {
  1153. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1154. RequestModel res = new RequestModel
  1155. {
  1156. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1157. };
  1158. StringBuilder strsql = new StringBuilder(); //StringBuilder sqlcount = new StringBuilder();
  1159. strsql.AppendFormat("select top {0} * from ", pagesize);
  1160. strsql.Append("(select *,ROW_NUMBER() OVER(ORDER BY [OutFenceDate] desc) AS [ROW_NUMBER_0],count(1) over() as total from ");
  1161. //sqlcount.Append("select count(1) from ");
  1162. //sqlcount.Append("(select count(1) as num, CarId as imei from YW_AlarmInformation group by CarId) as a left join YW_Bicycle as b on a.imei = b.CarID where b.CarID <> ''");
  1163. var num = CarState.Sales.GetHashCode();
  1164. strsql.AppendFormat("(select count(1) as num, CarId as imei from YW_AlarmInformation group by CarId) as a right join YW_Bicycle as b on a.imei = b.CarID where b.CarID <> '' and b.FenceState=2 and b.CarSate<{0} ", num);
  1165. if (!barcode.IsEmpty())
  1166. {
  1167. strsql.AppendFormat(" and b.FactoryNumber like '%{0}%'", barcode);
  1168. }
  1169. if (!imei.IsEmpty())
  1170. {
  1171. strsql.AppendFormat(" and b.CarID like '%{0}%' ", imei);
  1172. }
  1173. if (carType > 0)
  1174. {
  1175. strsql.AppendFormat(" and b.carType = '{0}' ", carType);
  1176. }
  1177. if (!FK_DPTID.IsEmpty())
  1178. {
  1179. strsql.AppendFormat(" and b.DistributorsID = '{0}' ", FK_DPTID);
  1180. }
  1181. int pageno = (page - 1) * pagesize;
  1182. strsql.AppendFormat(" ) as T where[T].[ROW_NUMBER_0] > {0}", pageno);
  1183. RequestItemSqlModel requestItemSql = new RequestItemSqlModel();
  1184. requestItemSql.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取农机报警列表" };
  1185. requestItemSql.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1186. requestItemSql.StrSql = strsql.ToString();
  1187. var bicycleList = orm.GetDataTableList(requestItemSql);
  1188. if (bicycleList.IsSuccess)
  1189. {
  1190. DataTable dtt = bicycleList.DataTable;
  1191. bicycleList.RecordNum = dtt.Rows[0]["total"].ToInt32();
  1192. var jsondata = Common.JsonConverter.ConvertJson(Common.JsonConverter.ToJson(dtt));
  1193. pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, jsondata);
  1194. }
  1195. }
  1196. }
  1197. else
  1198. {
  1199. if (CurrentUser.DptInfo.IfNotNull()) //经销商
  1200. {
  1201. if (!CurrentUser.DptInfo.ID.IsEmpty())
  1202. {
  1203. distributorsID = CurrentUser.DptInfo.ID;
  1204. }
  1205. }
  1206. else
  1207. {
  1208. string saleid = CurrentUser.Id.ToString(); //业务员
  1209. using (AntORM orm = new AntORM())
  1210. {
  1211. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1212. RequestModel res = new RequestModel
  1213. {
  1214. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1215. };
  1216. var q = orm.Queryable<EntYW_Bicycle>();
  1217. StringBuilder strsql = new StringBuilder(); //StringBuilder sqlcount = new StringBuilder();
  1218. strsql.AppendFormat("select top {0} * from ", pagesize);
  1219. strsql.Append("(select b.*,a.num,ROW_NUMBER() OVER(ORDER BY [OutFenceDate] desc) AS [ROW_NUMBER_0],count(1) over() as total from ");
  1220. var num = CarState.Sales.GetHashCode();
  1221. strsql.AppendFormat("(select count(1) as num, CarId as imei from YW_AlarmInformation group by CarId) as a right join YW_Bicycle as b on a.imei = b.CarID left join [YW_UserDistributor] as c on (c.ProductLine=b.ProductLine or c.ProductLine1=b.ProductLine or c.ProductLine2=b.ProductLine or c.ProductLine4=b.ProductLine or c.ProductLine5=b.ProductLine) and c.distributorId=b.DistributorsID where b.CarID <> '' and b.FenceState=2 and b.CarSate<{0} ", num);
  1222. if (!barcode.IsEmpty())
  1223. {
  1224. strsql.AppendFormat(" and b.FactoryNumber like '%{0}%'", barcode);
  1225. }
  1226. if (!imei.IsEmpty())
  1227. {
  1228. strsql.AppendFormat(" and b.CarID like '%{0}%' ", imei);
  1229. }
  1230. if (carType > 0)
  1231. {
  1232. strsql.AppendFormat(" and b.carType = '{0}' ", carType);
  1233. }
  1234. if (!FK_DPTID.IsEmpty())
  1235. {
  1236. strsql.AppendFormat(" and b.DistributorsID = '{0}' ", FK_DPTID);
  1237. }
  1238. else
  1239. {
  1240. strsql.AppendFormat(" and c.userId ='{0}'", saleid);
  1241. }
  1242. int pageno = (page - 1) * pagesize;
  1243. strsql.AppendFormat(" ) as T where[T].[ROW_NUMBER_0] > {0}", pageno);
  1244. RequestItemSqlModel requestItemSql = new RequestItemSqlModel();
  1245. requestItemSql.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取农机报警列表" };
  1246. requestItemSql.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1247. requestItemSql.StrSql = strsql.ToString();
  1248. var bicycleList = orm.GetDataTableList(requestItemSql);
  1249. if (bicycleList.IsSuccess)
  1250. {
  1251. DataTable dtt = bicycleList.DataTable;
  1252. bicycleList.RecordNum = dtt.Rows[0]["total"].ToInt32();
  1253. var jsondata = Common.JsonConverter.ConvertJson(Common.JsonConverter.ToJson(dtt));
  1254. pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, jsondata);
  1255. }
  1256. }
  1257. }
  1258. }
  1259. ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew();
  1260. //ViewData["Department"] = new List<EntSYS_DISTRIBUTORS>();
  1261. //using (AntORM orm = new AntORM())
  1262. //{
  1263. // orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1264. // RequestModel res = new RequestModel
  1265. // {
  1266. // newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1267. // };
  1268. // string saleid = CurrentUser.Id.ToString();
  1269. // if (CurrentUser.USERTYPE == 3)
  1270. // {
  1271. // var reslut = orm.Queryable<YW_UserDistributor>().Where(p => p.userId == saleid).Select(p => new { p.distributorId }).ToList(res);
  1272. // if (reslut.IsSuccess)
  1273. // {
  1274. // var listdis = reslut.ResultModel;
  1275. // List<string> Names = new List<string>();
  1276. // foreach (var mod in listdis)
  1277. // {
  1278. // Names.Add(mod.distributorId);
  1279. // }
  1280. // var dq = orm.Queryable<EntSYS_DISTRIBUTORS>().Where(p => Names.Contains(p.ID)).ToList();
  1281. // if (dq.IsSuccess)
  1282. // {
  1283. // ViewData["Department"] = dq.ResultModel;
  1284. // }
  1285. // }
  1286. // }
  1287. // else
  1288. // {
  1289. // var reslut = orm.Queryable<YW_UserDistributor>().Select(p => new { p.distributorId }).ToList(res);
  1290. // if (reslut.IsSuccess)
  1291. // {
  1292. // var listdis = reslut.ResultModel;
  1293. // List<string> Names = new List<string>();
  1294. // foreach (var mod in listdis)
  1295. // {
  1296. // Names.Add(mod.distributorId);
  1297. // }
  1298. // var dq = orm.Queryable<EntSYS_DISTRIBUTORS>().Where(p => Names.Contains(p.ID)).ToList();
  1299. // if (dq.IsSuccess)
  1300. // {
  1301. // ViewData["Department"] = dq.ResultModel;
  1302. // }
  1303. // }
  1304. // }
  1305. //}
  1306. ViewData["dptid"] = FK_DPTID;
  1307. ViewData["CarSate"] = CarSate;
  1308. ViewData["FenceState"] = FenceState;
  1309. ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList();
  1310. ViewData["typecar"] = carType;
  1311. ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList();
  1312. //ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").ToList();
  1313. ViewData["barcode"] = barcode;
  1314. ViewData["imei"] = imei;
  1315. return View(pageInfo);
  1316. }
  1317. catch (Exception e)
  1318. {
  1319. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  1320. throw e.InnerException;
  1321. }
  1322. }
  1323. /// <summary>
  1324. /// 导出报警数据
  1325. /// </summary>
  1326. /// <returns></returns>
  1327. public FileResult ExportFenceExcel()
  1328. {
  1329. //获取list数据
  1330. List<string> list = new List<string>();
  1331. //创建Excel文件的对象
  1332. NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); string distributorsID = string.Empty; string CarSate = Request.QueryString["CarSate"];
  1333. var cartype = Request.QueryString["cartype"];
  1334. var fencetype = Request.QueryString["fencetype"];
  1335. var dptid = Request.QueryString["dptid"];
  1336. //添加一个sheet
  1337. NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
  1338. //给sheet1添加第一行的头部标题
  1339. NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
  1340. row1.CreateCell(0).SetCellValue("农机IMEI号");
  1341. row1.CreateCell(1).SetCellValue("农机名称");
  1342. row1.CreateCell(2).SetCellValue("农机型号");
  1343. row1.CreateCell(3).SetCellValue("车架号");
  1344. row1.CreateCell(4).SetCellValue("所属经销商");
  1345. row1.CreateCell(5).SetCellValue("围栏状态");
  1346. row1.CreateCell(6).SetCellValue("出厂日期");
  1347. row1.CreateCell(7).SetCellValue("出厂编号");
  1348. row1.CreateCell(8).SetCellValue("超出围栏时间");
  1349. row1.CreateCell(9).SetCellValue("超出时长");
  1350. row1.CreateCell(10).SetCellValue("报警次数");
  1351. row1.CreateCell(11).SetCellValue("最后一次点火时间");
  1352. row1.CreateCell(12).SetCellValue("最后一次点火地址");
  1353. //将数据逐步写入sheet1各个行
  1354. if (!Request.QueryString["distributorsid"].IsEmpty())
  1355. {
  1356. distributorsID = Request.QueryString["distributorsid"].ToString();
  1357. }
  1358. using (AntORM orm = new AntORM())
  1359. {
  1360. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1361. RequestModel res = new RequestModel
  1362. {
  1363. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1364. };
  1365. StringBuilder strsql = new StringBuilder(); //StringBuilder sqlcount = new StringBuilder();
  1366. strsql.AppendFormat("select * from YW_Bicycle as b left join DeviceManage as c on b.CarID=c.IMEI where b.CarID <> '' and b.CarSate<{0} and b.FenceState=2 ", CarState.Sales.GetHashCode());
  1367. RequestItemSqlModel requestItemSql = new RequestItemSqlModel();
  1368. requestItemSql.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取农机报警列表" };
  1369. requestItemSql.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1370. requestItemSql.StrSql = strsql.ToString();
  1371. var bicycleList = orm.GetDataTableList(requestItemSql);
  1372. if (bicycleList.IsSuccess)
  1373. {
  1374. DataTable dtt = bicycleList.DataTable; int i = 0;
  1375. foreach (DataRow dr in dtt.Rows)
  1376. {
  1377. i++;
  1378. NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i);
  1379. rowtemp.CreateCell(0).SetCellValue(dr["CarID"].ToString());
  1380. rowtemp.CreateCell(1).SetCellValue(dr["CarName"].ToString());
  1381. rowtemp.CreateCell(2).SetCellValue(dr["CarModel"].ToString());
  1382. rowtemp.CreateCell(3).SetCellValue(dr["carBar"].ToString());
  1383. rowtemp.CreateCell(4).SetCellValue(dr["DistributorsName"].ToString());
  1384. string carstatestr = "";
  1385. switch (dr["FenceState"].ToInt32())
  1386. {
  1387. case 0:
  1388. carstatestr = "未点火"; break;
  1389. case 1:
  1390. carstatestr = "围栏内"; break;
  1391. case 2:
  1392. carstatestr = "围栏外"; break;
  1393. }
  1394. rowtemp.CreateCell(5).SetCellValue(carstatestr);
  1395. rowtemp.CreateCell(6).SetCellValue(dr["productionDate"].ToString());
  1396. rowtemp.CreateCell(7).SetCellValue(dr["FactoryNumber"].ToString());
  1397. rowtemp.CreateCell(8).SetCellValue(dr["OutFenceDate"].ToDateTime().ToString());
  1398. var num = Utility.DateTimeUtility.DateTimeDifference(Convert.ToDateTime(dr["OutFenceDate"]), DateTime.Now);
  1399. rowtemp.CreateCell(9).SetCellValue(num);
  1400. //orm.db = DataAccessFactory.CreateDataConnection("CyclingItemLog");
  1401. //string sql = "select count(1) as num from YW_AlarmInformation where CarId='" + dr["CarID"].ToString() + "' group by CarId";
  1402. //var sum = orm.db.ExecuteScalar(sql);
  1403. //if (sum.IsNullOrEmpty())
  1404. //{
  1405. // rowtemp.CreateCell(10).SetCellValue(0);
  1406. //}
  1407. //else
  1408. //{
  1409. // rowtemp.CreateCell(10).SetCellValue(sum.ToString());
  1410. //}
  1411. var sum = 0;//BundleConfig.OutFenceNum(dr["CarID"].ToString());
  1412. rowtemp.CreateCell(10).SetCellValue(sum.ToString());
  1413. var lng = dr["longitude"].ToDou(); var lat = dr["latitude"].ToDou();
  1414. var root = Utility.ToolGPSamap.GPS2Position(lng, lat);
  1415. string address = "";
  1416. if (root.IfNotNull())
  1417. {
  1418. address = root.formatted_address;
  1419. rowtemp.CreateCell(11).SetCellValue(dr["LastOnlineTime"].ToString());
  1420. rowtemp.CreateCell(12).SetCellValue(address);
  1421. }
  1422. }
  1423. }
  1424. }
  1425. // 写入到客户端
  1426. System.IO.MemoryStream ms = new System.IO.MemoryStream();
  1427. book.Write(ms);
  1428. ms.Seek(0, SeekOrigin.Begin);
  1429. return File(ms, "application/vnd.ms-excel", "农机报警信息.xls");
  1430. }
  1431. /// <summary>
  1432. /// 获取车辆状态
  1433. /// </summary>
  1434. /// <param name="carState"></param>
  1435. /// <returns></returns>
  1436. private string GetCarState(int carState)
  1437. {
  1438. string strcar = "";
  1439. switch (carState)
  1440. {
  1441. case 1:
  1442. {
  1443. strcar = "已绑定";
  1444. }
  1445. break;
  1446. case 2:
  1447. {
  1448. strcar = "已出库";
  1449. }
  1450. break;
  1451. case 3:
  1452. {
  1453. strcar = "在途中";
  1454. }
  1455. break;
  1456. case 4:
  1457. {
  1458. strcar = "已入库";
  1459. }
  1460. break;
  1461. case 5:
  1462. {
  1463. strcar = "已销售";
  1464. }
  1465. break;
  1466. case 6:
  1467. {
  1468. strcar = "退货中";
  1469. }
  1470. break;
  1471. case 7:
  1472. {
  1473. strcar = "调拨中";
  1474. }
  1475. break;
  1476. case 8:
  1477. {
  1478. strcar = "返厂中";
  1479. }
  1480. break;
  1481. default:
  1482. {
  1483. strcar = "初始值";
  1484. }
  1485. break;
  1486. }
  1487. return strcar;
  1488. }
  1489. }
  1490. }