using Ant.Service.Common; using Ant.Service.Common.Enums; using Central.Control.Domain; using MES.Production.Entity; using MES.Production.Service.IService; using MES.Production.Service.ServiceImp; using ChangFa.Machinery.WebPage.Controllers; using Ant.Data; using Ant.ORM; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using MongoDB.Driver.Builders; using Ant.Service.Mongodb; using System.Text; using System.Net; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using Ant.Service.Utility; using Ant.SuperSocket.Common; using MES.Production.Entity.Enum; using System.IO; using System.Diagnostics; using System.Data; using MES.Production.Entity.Entity; using JsonHelper = Ant.Service.Common.JsonHelper; using JsonConverter = Ant.Service.Common.JsonConverter; using WebApiHelp = Ant.Service.Common.WebApiHelp; using YW_CarParamDetails = Central.Control.Domain.YW_CarParamDetails; using YW_UserCar = Central.Control.Domain.YW_UserCar; using YW_CarPurchaser = Central.Control.Domain.YW_CarPurchaser; namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers { public class CarController : BaseController { /// /// 字典编码 /// ICodeManage CodeManage = new CodeManage(); /// /// 经销商 /// IDepartmentManage DepartmentManage = new DepartmentManage(); /// /// 加载列表 /// /// [UserAuthorizeAttribute(ModuleAlias = "carList", OperaAction = "View")] public ActionResult Index() { try { #region 处理查询参数 string posttype = Request.QueryString["posttype"]; string FK_DPTID = Request.QueryString["FK_DPTID"]; string CarSate = Request.QueryString["CarSate"]; string carType = Request.QueryString["LeaseStatus"]; int state = -1; if (!CarSate.IsEmpty()) { state = CarSate.ToInt32(); } #endregion #region 加载列表 var result = BindList(carType.ToInt32(), FK_DPTID, state); ViewBag.Search = base.keywords; // ViewData["PostType"] = this.CodeManage.GetCode("POSTTYPE"); //ViewData["post"] = posttype; ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList(); ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew(); ViewData["dptid"] = FK_DPTID; ViewData["CarSate"] = CarSate; ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList(); ViewData["typecar"] = carType; #endregion if (result.IsNull()) { return View(); } else { return View(result); } } catch (Exception e) { WriteLog(enumOperator.Select, "加载岗位列表:", e); throw e.InnerException; } } /// /// 导出申请审核数据 /// /// public FileResult CarReturnOutExcel() { try { NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); //添加一个sheet NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1"); //给sheet1添加第一行的头部标题 NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0); row1.CreateCell(0).SetCellValue("农机IMEI号"); row1.CreateCell(1).SetCellValue("农机名称"); row1.CreateCell(2).SetCellValue("农机型号"); row1.CreateCell(3).SetCellValue("车架号"); row1.CreateCell(4).SetCellValue("出厂日期"); row1.CreateCell(5).SetCellValue("出厂编号"); row1.CreateCell(6).SetCellValue("所属经销商"); row1.CreateCell(7).SetCellValue("调拨后经销商"); row1.CreateCell(8).SetCellValue("申请类型"); row1.CreateCell(9).SetCellValue("申请人"); row1.CreateCell(10).SetCellValue("申请时间"); row1.CreateCell(11).SetCellValue("审核状态"); #region 加载列表 List carlist = new List(); using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel(); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" }; var usercarlist = orm.Queryable() .InnerJoin((user, city) => user.carid == city.CarID); var views = usercarlist.Select((strip, sbicycle) => new { Users = sbicycle, trip = strip }); views = views.Where(p => p.Users.CarID != "" && p.trip.state == 1); var reslut = views.OrderBy(p => p.trip.state).ToList(res); if (reslut.IsSuccess) { int i = 0; foreach (var list in reslut.ResultModel) { yw_machinery_return mod = list.trip; EntYW_Bicycle carmod = list.Users; //Entity.YW_CarPurchaser purchser = list.userpurch; i++; NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i); rowtemp.CreateCell(0).SetCellValue(carmod.CarID); rowtemp.CreateCell(1).SetCellValue(carmod.CarName); rowtemp.CreateCell(2).SetCellValue(carmod.CarModel); rowtemp.CreateCell(3).SetCellValue(carmod.carBar); rowtemp.CreateCell(4).SetCellValue(carmod.productionDate.ToString()); rowtemp.CreateCell(5).SetCellValue(carmod.FactoryNumber); rowtemp.CreateCell(6).SetCellValue(carmod.DistributorsName); rowtemp.CreateCell(7).SetCellValue(mod.distributorsName); var applytype = ""; if (mod.apply_type == 1) { applytype = "退货申请"; } if (mod.apply_type == 2) { applytype = "返厂申请"; } if (mod.apply_type == 3) { applytype = "调拨申请"; } rowtemp.CreateCell(8).SetCellValue(applytype); rowtemp.CreateCell(9).SetCellValue(mod.add_name); rowtemp.CreateCell(10).SetCellValue(mod.add_time.ToString()); var strstate = ""; if (mod.state == 0) { strstate = "未审核"; } if (mod.state == 1) { strstate = "已通过"; } if (mod.state == 2) { strstate = "未通过"; } rowtemp.CreateCell(11).SetCellValue(strstate); } } } #endregion // 写入到客户端 System.IO.MemoryStream ms = new System.IO.MemoryStream(); book.Write(ms); ms.Seek(0, SeekOrigin.Begin); return File(ms, "application/vnd.ms-excel", "农机申请审核.xls"); } catch (Exception e) { throw e.InnerException; } } /// /// 加载列表 /// /// [UserAuthorizeAttribute(ModuleAlias = "carReturn", OperaAction = "View")] public ActionResult CarReturnList() { try { PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, Ant.Service.Common.JsonConverter.JsonClass(new List())); #region 处理查询参数 var posttype = Request.QueryString["PostType"]; string FK_DPTID = Request.QueryString["FK_DPTID"]; int carType = Request.QueryString["LeaseStatus"].ToInt32(); string CarSate = Request.QueryString["CarSate"]; string barcode = Request.QueryString["txt_barcode"]; string imei = Request.QueryString["txt_imei"]; string factoryNumber = Request.QueryString["txt_factoryNumber"]; int state = -1; if (!CarSate.IsEmpty()) { state = CarSate.ToInt32(); } #endregion #region 加载列表 List carlist = new List(); using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel(); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" }; var usercarlist = orm.Queryable() .InnerJoin((user, city) => user.carid == city.CarID); // .InnerJoin((user, city, province) => city.CarID == province.carId); int pageno = (base.page - 1) * base.pagesize; var views = usercarlist.Select((strip, sbicycle) => new { Users = sbicycle, trip = strip }); if (posttype != "-1" && !posttype.IsEmpty()) { var type = posttype.ToInt32(); views = views.Where(p => p.trip.apply_type == type); } if (state > 0) { views = views.Where(p => p.Users.CarSate == state); } if (!factoryNumber.IsEmpty()) { views = views.Where(p => p.Users.FactoryNumber.Contains(factoryNumber)); } if (!imei.IsEmpty()) { views = views.Where(p => p.Users.CarID.Contains(imei)); } views = views.Where(p => p.Users.CarID != ""); var reslut = views.OrderBy(p => p.trip.state).ThenByDesc(p => p.trip.add_time).Skip(pageno).Top(pagesize).ToList(res); //.Where(p => p.Users.UserId == usermod.userInfo.uid) if (reslut.IsSuccess) { reslut.RecordNum = views.Count(); foreach (var list in reslut.ResultModel) { CarReturnModel carReturn = new CarReturnModel(); yw_machinery_return mod = list.trip; EntYW_Bicycle carmod = list.Users; //Entity.YW_CarPurchaser purchser = list.userpurch; carReturn.bicycle = carmod; carReturn.carreturn = mod; carlist.Add(carReturn); } pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(carlist)); } } ViewBag.Search = base.keywords; ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList(); ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew(); ViewData["dptid"] = FK_DPTID; ViewData["CarSate"] = CarSate; ViewData["PostType"] = posttype; ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList(); ViewData["typecar"] = carType; ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList(); //ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").ToList(); ViewData["factoryNumber"] = factoryNumber; ViewBag.Search = base.keywords; ViewData["barcode"] = barcode; ViewData["imei"] = imei; return View(pageInfo); #endregion } catch (Exception e) { WriteLog(enumOperator.Select, "加载岗位列表:", e); throw e.InnerException; } } /// /// 解除电子围栏 /// /// /// public ActionResult LiftedCarFence(string idList) { Ant.Service.Common.JsonHelper json = new Ant.Service.Common.JsonHelper() { Status = "n", Msg = "解除围栏成功" }; using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel request = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" } }; string id = idList.Split(';')[0]; string carid = idList.Split(';')[1]; int carstate = CarState.Sales.ToInt32(); Guid guid = new Guid(id); var reslut = orm.UpdateByLambda(p => new EntYW_Bicycle { CarSate = carstate }, f => f.ID == guid, request); if (reslut.IsSuccess) { json.Status = "y"; WriteLog(enumOperator.Remove, "解除围栏:" + json.Msg, enumLog4net.WARN); try { //SocketClient client = new SocketClient(); //var str = DataHelper.sendRemoveFence(Convert.ToInt64(carid)); //var body = DataHelper.HexToByte(str); //string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString(); //int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32(); //client.Connect(ip, port); //var flag = client.SendData(body); //client.Disconnect(); } catch (Exception ex) { } } } return Json(json); } /// /// 删除农机 /// /// 编码ID字符串 public ActionResult Delete(string idList) { Ant.Service.Common.JsonHelper json = new JsonHelper() { Status = "n", Msg = "删除农机成功" }; try { //是否为空 if (string.IsNullOrEmpty(idList)) { json.Msg = "未找到要删除的农机"; return Json(json); } string[] id = idList.Trim(',').Split(','); for (int i = 0; i < id.Length; i++) { var userId = (id[i]); using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel request = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" }, Oid = userId.ToString() }; var reslut = orm.DeleteById(request); if (reslut.IsSuccess) { json.Status = "y"; WriteLog(enumOperator.Remove, "删除农机:" + json.Msg, enumLog4net.WARN); } } } } catch (Exception e) { json.Msg = "删除农机发生内部错误!"; WriteLog(enumOperator.Remove, "删除农机:", e); } return Json(json); } /// /// 加载列表 /// /// [UserAuthorizeAttribute(ModuleAlias = "carReturn", OperaAction = "View")] public ActionResult CarReturnFactory() { try { PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List())); #region 处理查询参数 string posttype = Request.QueryString["posttype"]; string FK_DPTID = Request.QueryString["FK_DPTID"]; string CarSate = Request.QueryString["CarSate"]; int state = -1; if (!CarSate.IsEmpty()) { state = CarSate.ToInt32(); } #endregion #region 加载列表 List carlist = new List(); using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel(); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" }; var resultList = new ResponseApplyCarList(); resultList.resultList = new List(); var usercarlist = orm.Queryable() .InnerJoin((user, city) => user.carid == city.CarID) .InnerJoin((user, city, province) => city.CarID == province.carId); int pageno = (base.page - 1) * base.pagesize; var views = usercarlist.Select((strip, sbicycle, purchser) => new { Users = sbicycle, trip = strip, userpurch = purchser }).Where(f => f.trip.apply_type == 2).OrderByDesc(p => p.Users.ID).ToList(res); //.Where(p => p.Users.UserId == usermod.userInfo.uid) if (views.IsSuccess) { foreach (var list in views.ResultModel) { CarReturnModel carReturn = new CarReturnModel(); yw_machinery_return mod = list.trip; EntYW_Bicycle carmod = list.Users; YW_CarPurchaser purchser = list.userpurch; carReturn.bicycle = carmod; carReturn.carreturn = mod; carlist.Add(carReturn); } pageInfo = new PageInfo(base.page, base.pagesize, views.RecordNum, JsonConverter.JsonClass(carlist)); } } ViewBag.Search = base.keywords; ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").ToList(); ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetail(); ViewData["dptid"] = FK_DPTID; ViewData["CarSate"] = CarSate; return View(pageInfo); #endregion } catch (Exception e) { WriteLog(enumOperator.Select, "加载岗位列表:", e); throw e.InnerException; } } public ActionResult CarAllocate(string id) { ResponseApplyCarInfo userCar = new ResponseApplyCarInfo(); using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel(); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" }; Guid carid = new Guid(id); var reslut = orm.Queryable().Where(p => p.ID == carid).FirstOrDefault(res); if (reslut.IsSuccess) { EntYW_Bicycle carmod = reslut.ResultModel; //Entity.YW_CarPurchaser purchser = views.ResultModel.userpurch; userCar.imei = carmod.CarID; userCar.apply_id = carmod.ID.ToString(); userCar.productBarCode = carmod.carBar; userCar.productModel = carmod.CarModel; userCar.productName = carmod.CarName; userCar.carType = carmod.carType.ToInt32(); userCar.orgDistributorsName = carmod.DistributorsName; userCar.carState = GetCarState.getCarStateStr(carmod.CarSate.ToInt32()); userCar.FactoryNumber = carmod.FactoryNumber; userCar.isOnLine = carmod.LeaseStatus.ToInt32(); } } int uid = 0; if (CurrentUser.USERTYPE == 2) { uid = CurrentUser.Id; } ViewBag.dpt = this.DepartmentManage.GetDepartmentByDetailNew(uid); return View(userCar); } /// /// 保存审核结果 /// /// public ActionResult SaveApplyCheck(string apply_id) { JsonHelper json = new JsonHelper() { Msg = "农机申请审核成功", Status = "n", ReUrl = "/Car/DistributorCarList" }; var notes = Request["notes"]; var state = Request["checkstate"]; if (state == "1") { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel(); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" }; Guid guid = new Guid(apply_id); var reslut = orm.Queryable().Where(p => p.id == guid).FirstOrDefault(res); if (reslut.IsSuccess) { yw_machinery_return mod = reslut.ResultModel; if (mod.apply_type == 1)//退货 { int carstate = CarState.Storage.ToInt32(); var reslutcar = orm.UpdateByLambda(p => new EntYW_Bicycle { CarSate = carstate }, f => f.CarID == mod.carid, res); { var reslutapply = orm.UpdateByLambda(p => new yw_machinery_return { state = 1, check_time = DateTime.Now }, f => f.id == mod.id, res); if (reslutapply.IsSuccess) { json.Status = "y"; json.Msg = "退货审核通过"; } var usersalereslut = orm.DeleteByLambda(p => p.imei == mod.carid, res); if (usersalereslut.IsSuccess) { } var userbindreslut = orm.DeleteByLambda(p => p.carId == mod.carid, res); if (userbindreslut.IsSuccess) { } var alarmreslut = orm.DeleteByLambda(p => p.CarId == mod.carid, res); if (alarmreslut.IsSuccess) { } } } if (mod.apply_type == 2)//返厂 { int carstate = CarState.carBind.ToInt32(); var reslutcar = orm.UpdateByLambda(p => new EntYW_Bicycle { CarSate = carstate, DistributorsID = "", DistributorsName = "" }, f => f.CarID == mod.carid, res); { var reslutapply = orm.UpdateByLambda(p => new yw_machinery_return { state = 1 }, f => f.id == mod.id, res); if (reslutapply.IsSuccess) { json.Status = "y"; json.Msg = "返厂审核通过"; } var usersalereslut = orm.DeleteByLambda(p => p.imei == mod.carid, res); if (usersalereslut.IsSuccess) { } var userbindreslut = orm.DeleteByLambda(p => p.carId == mod.carid, res); if (userbindreslut.IsSuccess) { } var alarmreslut = orm.DeleteByLambda(p => p.CarId == mod.carid, res); if (alarmreslut.IsSuccess) { } } } if (mod.apply_type == 3)//调拨 { int carstate = CarState.OutStock.ToInt32(); var reslutcar = orm.UpdateByLambda(p => new EntYW_Bicycle { CarSate = carstate, DistributorsID = mod.distributorsID, DistributorsName = mod.distributorsName }, f => f.CarID == mod.carid, res); { var reslutapply = orm.UpdateByLambda(p => new yw_machinery_return { state = 1 }, f => f.id == mod.id, res); if (reslutapply.IsSuccess) { json.Status = "y"; json.Msg = "调拨审核通过"; } var usersalereslut = orm.DeleteByLambda(p => p.imei == mod.carid, res); if (usersalereslut.IsSuccess) { } var userbindreslut = orm.DeleteByLambda(p => p.carId == mod.carid, res); if (userbindreslut.IsSuccess) { } var alarmreslut = orm.DeleteByLambda(p => p.CarId == mod.carid, res); if (alarmreslut.IsSuccess) { } } } if (mod.apply_type == 4) { //var str = DataHelper.sendLockHexStr(Convert.ToInt64(mod.carid.Trim())); //var body = DataHelper.HexToByte(str); //SocketClient client = new SocketClient(); //try //{ // string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString(); // int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32(); // client.Connect(ip, port); // var flag = client.SendData(body); // var reslutlock = orm.UpdateByLambda(p => new YW_Apply_CarLock { state = 2 }, f => f.carid == mod.carid && f.state == 0, res); // if (reslutlock.IsSuccess) // { // } // var reslutapply = orm.UpdateByLambda(p => new yw_machinery_return { state = 1 }, f => f.id == mod.id, res); // if (reslutapply.IsSuccess) // { // json.Status = "y"; // json.Msg = "审核通过"; // } // client.Disconnect(); //} //catch (Exception ex) //{ //} } if (mod.apply_type == 5) { //var str = DataHelper.sendUnLockHexStr(Convert.ToInt64(mod.carid.Trim())); //var body = DataHelper.HexToByte(str); //SocketClient client = new SocketClient(); //try //{ // string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString(); // int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32(); // client.Connect(ip, port); // var flag = client.SendData(body); // var reslutlock = orm.UpdateByLambda(p => new YW_Apply_CarLock { state = 2 }, f => f.carid == mod.carid && f.state == 0, res); // if (reslutlock.IsSuccess) // { // } // var reslutapply = orm.UpdateByLambda(p => new yw_machinery_return { state = 1 }, f => f.id == mod.id, res); // if (reslutapply.IsSuccess) // { // json.Status = "y"; // json.Msg = "审核通过"; // } // client.Disconnect(); //} //catch (Exception ex) //{ //} } } } } else { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel(); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" }; Guid guid = new Guid(apply_id); var reslutapply = orm.UpdateByLambda(p => new yw_machinery_return { state = 2, noPassNote = notes }, f => f.id == guid, res); if (reslutapply.IsSuccess) { var reslutmod = orm.Queryable().Where(p => p.id == guid).FirstOrDefault(res); if (reslutmod.IsSuccess) { yw_machinery_return mod = reslutmod.ResultModel; orm.UpdateByLambda(p => new EntYW_Bicycle { CarSate = mod.carState }, f => f.CarID == mod.carid, res); json.Status = "n"; json.Msg = "审核不通过"; } } } } return Json(json); } /// /// 保存调拨数据 /// /// /// public ActionResult SaveCarAllocate(ResponseApplyCarInfo info) { JsonHelper json = new JsonHelper() { Msg = "农机申请成功", Status = "n", ReUrl = "/Car/DistributorCarList" }; var applytype = Request["apply_type"].ToInt32(); using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel(); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" }; Guid carid = new Guid(info.apply_id); var reslut = orm.Queryable().Where(p => p.ID == carid).FirstOrDefault(res); if (reslut.IsSuccess) { EntYW_Bicycle carmod = reslut.ResultModel; if (carmod.CarSate > 40 && applytype == 3) { json.Msg = "已销售无法做调拨!"; return Json(json); } if (applytype == 4)//锁车 { if (carmod.LockState.ToBool()) { json.Msg = "已锁车,不能重复申请锁车操作!"; return Json(json); } var count = orm.Queryable().Where(p => p.carid == carmod.CarID && p.state == 0).Count(); if (count > 0) { json.Msg = "已申请锁车,不能重复申请锁车,等待审核!"; return Json(json); } } if (applytype == 5)//解锁 { if (!carmod.LockState.ToBool()) { json.Msg = "已解锁,不能重复申请!"; return Json(json); } var count = orm.Queryable().Where(p => p.carid == carmod.CarID && p.state == 0).Count(); if (count > 0) { json.Msg = "已申请解锁,不能重复申请解锁,等待审核!"; return Json(json); } } SYS_USER usermod = new SYS_USER(); EntSYS_DISTRIBUTORS dis = new EntSYS_DISTRIBUTORS(); //var qq = orm.Queryable().LeftJoin((diss, us) => diss.ID == us.DPTID); //var views = qq.Select((disname, userinfo) => new { DisName = disname, UserInfo = userinfo }).OrderByDesc(p => p.DisName.ID).Where(p => p.DisName.ID == info.distributorsId).FirstOrDefault(res); //if (views.IsSuccess) //{ // dis = views.ResultModel.DisName; usermod = views.ResultModel.UserInfo; //} yw_machinery_return mod = new yw_machinery_return(); mod.id = Guid.NewGuid(); mod.carid = carmod.CarID; mod.note = Request["notes"];//申请原因 if (applytype == 0) { json.Msg = "申请类型不能为空!"; return Json(json); } if (applytype == 1)//退货 { } if (applytype == 2)//返厂 { } if (applytype == 3)//调拨 { var str = string.Empty; if (info.note == "10") { str = "一级商到一级商(有调拨手续)"; } if (info.note == "20") { str = "一级商到一级商(无调拨手续)"; } if (info.note == "30") { str = "一级经销商内部调拨"; } if (info.note == "40") { str = "其它"; } if (str.IsEmpty()) { json.Msg = "调拨申请调拨原因不能为空!"; return Json(json); } if (info.distributorsId.IsEmpty()) { json.Msg = "调拨申请经销商不能为空!选择调拨经销商!"; return Json(json); } var qq = orm.Queryable().Where(p => p.ID == info.distributorsId).FirstOrDefault(res); dis = qq.ResultModel; mod.reason = str; mod.distributorsID = info.distributorsId; mod.distributorsName = dis.NAME; mod.distributorsContact = dis.BUSINESSLEVEL.ToString(); } mod.distributorsContact = usermod.NAME; mod.distributorsTel = usermod.PHONE; mod.carState = mod.carState; mod.apply_type = Request["apply_type"].ToInt32(); mod.orgDistributorsID = carmod.DistributorsID; mod.orgDistributorsName = carmod.DistributorsName; mod.add_name = CurrentUser.Name; mod.add_time = DateTime.Now; mod.userId = CurrentUser.Id.ToString(); var reslutmachinery = orm.Save(mod, res); if (reslutmachinery.IsSuccess) { json.Status = "y"; //var reslutcar = orm.UpdateByLambda(p => new EntYW_Bicycle { DistributorsID = info.distributorsId, DistributorsName = dis.NAME }, f => f.CarID == mod.carid, res); //if (reslutcar.IsSuccess) //{ // json.Status = "y"; //} //else //{ // json.Msg = "保存失败"; ; //} } else { json.Msg = "保存失败"; } } } return Json(json); } /// /// 车辆调拨 /// /// public ActionResult CarAllocation(string id) { ResponseApplyCarInfo userCar = new ResponseApplyCarInfo(); try { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel(); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" }; var usercarlist = orm.Queryable() .InnerJoin((user, city) => user.carid == city.CarID); //.InnerJoin((user, city, province) => city.CarID == province.carId); Guid guid = new Guid(id); //var views = usercarlist.Select((strip, sbicycle, purchser) => new { Users = sbicycle, trip = strip, userpurch = purchser }).Where(p => p.trip.id == guid).FirstOrDefault(res); var views = usercarlist.Select((strip, sbicycle) => new { Users = sbicycle, trip = strip }).Where(p => p.trip.id == guid).FirstOrDefault(res); //.Where(p => p.Users.UserId == usermod.userInfo.uid) if (views.IsSuccess) { yw_machinery_return mod = views.ResultModel.trip; EntYW_Bicycle carmod = views.ResultModel.Users; //Entity.YW_CarPurchaser purchser = views.ResultModel.userpurch; userCar.imei = carmod.CarID; userCar.productBarCode = carmod.carBar; userCar.productModel = carmod.CarModel; userCar.productName = carmod.CarName; userCar.FactoryNumber = carmod.FactoryNumber; userCar.apply_type = mod.apply_type.ToString(); userCar.apply_state = mod.state.ToString(); userCar.carType = carmod.carType.ToInt32(); userCar.orgDistributorsID = mod.orgDistributorsID; userCar.orgDistributorsName = mod.orgDistributorsName; var purrchreslut = orm.Queryable().Where(p => p.carId == carmod.CarID).FirstOrDefault(res); if (purrchreslut.IsSuccess) { MES.Production.Entity.YW_CarPurchaser purchser = purrchreslut.ResultModel; userCar.name = purchser.userName; userCar.tel = purchser.userTel; userCar.saleDate = purchser.addDate.ToDateTime(); } userCar.note = mod.note; userCar.reason = mod.reason; userCar.applyName = mod.add_name; userCar.apply_id = mod.id.ToString(); userCar.carState = GetCarState.getCarStateStr(carmod.CarSate.ToInt32()); userCar.isOnLine = carmod.LeaseStatus.ToInt32(); if (mod.apply_type == 3) { var distributorsreslut = orm.Queryable().Where(p => p.ID == mod.distributorsID).FirstOrDefault(res); if (distributorsreslut.IsSuccess) { EntSYS_DISTRIBUTORS dismod = distributorsreslut.ResultModel; userCar.distributorsAddress = dismod.Address; userCar.distributorsName = dismod.NAME; userCar.distributorsContact = ""; userCar.distributorsTel = ""; } } //userCar.productionDate = DateTimeUtility.ConvertDateTimeInt(carmod.productionDate.ToDateTime()); } } return View(userCar); } catch (Exception e) { WriteLog(enumOperator.Select, "加载岗位列表:", e); throw e.InnerException; } } /// public ActionResult atouCarMapList() { ViewData["provincecode"] = Request["provincecode"]; ViewData["strprovince"] = Request["strprovince"]; ViewData["strcode"] = Request["strcode"]; ViewData["strname"] = Request["strname"]; return View(); } /// /// /// /// [UserAuthorizeAttribute(ModuleAlias = "mapList", OperaAction = "View")] public ActionResult mapList() { ViewData["provincecode"] = Request["provincecode"]; ViewData["strprovince"] = Request["strprovince"]; ViewData["strcode"] = Request["strcode"]; ViewData["strname"] = Request["strname"]; return View(); } public ActionResult CarParamList(string id) { PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List())); using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取车辆信息" } }; var q = orm.Queryable(); if (id.IsEmpty()) { return View(pageInfo); } q = q.Where(p => p.imei == id); int pageno = (page - 1) * pagesize; var tripreslut = q.OrderByDesc(p => p.add_time).Skip(pageno).Top(pagesize).ToList(res); if (tripreslut.IsSuccess) { tripreslut.RecordNum = q.Count(); pageInfo = new PageInfo(base.page, base.pagesize, tripreslut.RecordNum, JsonConverter.JsonClass(tripreslut.ResultModel)); } } return View(pageInfo); } [UserAuthorizeAttribute(ModuleAlias = "machineryList", OperaAction = "List")] public ActionResult CarTripList(string id) { PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0,JsonConverter.JsonClass(new List())); var startdate = Request.Params["startdate"]; var enddate = Request.Params["enddate"]; using (AntORM orm = new AntORM()) { int pageno = (page - 1) * pagesize; StringBuilder strsql = new StringBuilder(); strsql.AppendFormat("SELECT top {0} [T].[ID] AS [ID],[T].[IMEI] AS [IMEI],[T].[StartDate] AS [StartDate],[T].[EndDate] AS [EndDate],[T].[WorkingHours] AS [WorkingHours] ,t.num,t.total FROM (", pagesize); strsql.AppendFormat("SELECT[YW_CarTrip].[ID] AS[ID],[YW_CarTrip].[IMEI] AS[IMEI],[YW_CarTrip].[StartDate] AS[StartDate],[YW_CarTrip].[EndDate] AS[EndDate],[YW_CarTrip].[WorkingHours] AS[WorkingHours],"); strsql.AppendFormat("ROW_NUMBER() OVER(ORDER BY[YW_CarTrip].[StartDate] DESC) AS num,count(1) over() as total FROM [YW_CarTrip] AS[YW_CarTrip] WHERE [YW_CarTrip].[IMEI] = '{0}'", id); if (!startdate.IsEmpty() && enddate.IsEmpty()) { var fromdate = startdate.ToDateTime(); strsql.AppendFormat("[YW_CarTrip].[StartDate]={0}", fromdate); } if (!enddate.IsEmpty() && startdate.IsEmpty()) { var todate = enddate.ToDateTime(); strsql.AppendFormat("[YW_CarTrip].[StartDate]={0}", todate); } if (!startdate.IsEmpty() && !enddate.IsEmpty()) { var fromdate = startdate.ToDateTime(); var todate = enddate.ToDateTime(); strsql.AppendFormat(" and ([YW_CarTrip].[StartDate]>'{0}' and [YW_CarTrip].[StartDate]<'{1}') ", fromdate, todate); } strsql.AppendFormat(") AS[T] WHERE [T].num > {0} order by num asc", pageno); RequestItemSqlModel requestItemSql = new RequestItemSqlModel(); requestItemSql.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取农机行程列表" }; requestItemSql.db = DataAccessFactory.CreateDataConnection("CyclingItemLog"); requestItemSql.StrSql = strsql.ToString(); var tripreslut = orm.GetDataTableList(requestItemSql); if (tripreslut.IsSuccess) { DataTable dtt = tripreslut.DataTable; tripreslut.RecordNum = dtt.Rows[0]["total"].ToInt32(); var jsondata = JsonConverter.ConvertJson(JsonConverter.ToJson(dtt)); pageInfo = new PageInfo(base.page, base.pagesize, tripreslut.RecordNum, jsondata); } } ViewData["startdate"] = startdate; ViewData["enddate"] = enddate; ViewData["imei"] = id; return View(pageInfo); } /// /// 生成定位信息JSON文件 /// /// [HttpGet] public JsonResult salesMakeMapJsonFile() { string lat = ""; string lng = ""; string onlinetime = ""; using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取车辆信息" } }; var carreslut = orm.Queryable().Where(p => p.CarSate == 1).ToList(res); if (carreslut.IsSuccess) { List carlist = new List(); foreach (EntYW_Bicycle mod in carreslut.ResultModel) { CarGPSModel car = new CarGPSModel(); car.imei = mod.CarID; car.barCode = mod.carBar; var reslut = orm.Queryable().Where(p => p.imei == mod.CarID && p.locationtype == 2).OrderByDesc(p => p.add_time).FirstOrDefault(res); if (reslut.IsSuccess) { YW_CarHeartbeat beatenty = reslut.ResultModel; var carTrack = new ResponseCarTrack(); if (beatenty.locationtype == 2) { var GPS = Ant.SuperSocket.Common.ToolGPSamap.GPSToGDGPS(beatenty.lng.ToDou(), beatenty.lat.ToDou()); lat = GPS.Split(',')[1]; lng = GPS.Split(',')[0]; car.onlineTime = beatenty.add_time.ToDateTime().ToString("yyyy-MM-dd hh:mm:ss"); car.postType = "GPS位置"; //enty.isOnline = (mod.LeaseStatus == 1); } else { var lbsreslut = orm.Queryable().Where(p => p.imei == mod.CarID && p.locationtype == 1).OrderByDesc(p => p.add_time).FirstOrDefault(res); if (lbsreslut.IsSuccess) { YW_CarHeartbeat lbsmod = lbsreslut.ResultModel; if (lbsmod.mcc > 0) { var gps = WebApiHelp.getLocationGPS("", lbsmod.mcc.ToInt32(), lbsmod.mnc.ToInt32(), lbsmod.lac.ToInt32(), lbsmod.cellID.ToInt32(), lbsmod.rssi.ToInt32()); lbsmod.lng = gps.result.location.Split(',')[0].ToDec(); lbsmod.lat = gps.result.location.Split(',')[1].ToDec(); var GPS = Ant.SuperSocket.Common.ToolGPSamap.GPSToGDGPS(lbsmod.lng.ToDou(), lbsmod.lat.ToDou()); lat = GPS.Split(',')[1]; lng = GPS.Split(',')[0]; car.onlineTime = lbsmod.add_time.ToDateTime().ToString("yyyy-MM-dd hh:mm:ss"); car.postType = "LBS位置"; //enty.isOnline = (mod.LeaseStatus == 1); } } } } car.id = mod.ID.ToString(); car.pic = "http://localhost:7907/upload/20170705135420_87460.jpg"; car.name = mod.CarName + "(" + mod.CarModel + ")"; car.latitude = lat; car.longitude = lng; car.online = (mod.LeaseStatus == 1) ? "在线" : "不在线"; //car.voltage = "14.095 V"; //car.hydraulic = "368 KPa"; //car.temperature = "40 ℃"; //car.speed = "849 转"; string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString(); MongoDbHelper mh = new MongoDbHelper(ip, "1000"); var query = Query.And(Query.EQ("carId", mod.CarID), MongoDB.Driver.Builders.Query.EQ("carReslut", 1)); string[] order = new string[] { "operatDate" }; var modstate = mh.FindOneToIndexMax(query, order); if (modstate.IfNotNull()) { car.hydraulic = modstate.hydraulic + " KPa"; car.speed = modstate.speed + " 转"; car.temperature = modstate.temperature + " ℃"; car.voltage = modstate.voltage + " mV"; } else { car.hydraulic = "0 KPa"; car.temperature = "0 ℃"; car.speed = "0 转"; car.voltage = "0 V"; } car.address = ToolGPSamap.GPSToPositionString(car.longitude.ToDou(), car.latitude.ToDou()); carlist.Add(car); } //var strjs = Newtonsoft.Json.JsonConvert.SerializeObject(carlist); //string localPath = Path.Combine(HttpRuntime.AppDomainAppPath, "Upload\\hotfix\\test.json"); //FileOperate.FileDel(localPath); //FileOperate.WriteFile(localPath, strjs); return Json(carlist, JsonRequestBehavior.AllowGet); } } return null; } /// /// 获取自动驾驶农机 /// /// [HttpGet] public JsonResult AtouCarMapJsonFile() { List carlist = new List(); using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取车辆信息" } }; var reslut = orm.Queryable().ToList(res); if (reslut.IsSuccess) { foreach (YW_AntoCarList antoCarList in reslut.ResultModel) { CarGPSModel carGPS = new CarGPSModel(); carGPS.address = antoCarList.Address; carGPS.imei = antoCarList.CarID; carGPS.name = "自动驾驶农机"; carGPS.latitude = antoCarList.latitude.ToString(); carGPS.longitude = antoCarList.longitude.ToString(); carGPS.voltage = antoCarList.voltage; carGPS.temperature = antoCarList.temperature; carGPS.speed = antoCarList.speed; carGPS.online = "在线"; carGPS.onlineTime = antoCarList.add_time.ToString(); carGPS.pic = ""; carGPS.barCode = ""; carGPS.id = antoCarList.ID.ToString(); carGPS.workingHours = ""; carlist.Add(carGPS); } } } return Json(carlist, JsonRequestBehavior.AllowGet); } /// /// 生成定位信息JSON文件 /// /// [HttpGet] public JsonResult makeMapJsonFile(string strcode, string strname) { string lat = ""; string lng = ""; string onlinetime = ""; ViewData["provincecode"] = Request["provincecode"]; ViewData["strprovince"] = Request["strprovince"]; using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取车辆信息" } }; var q = orm.Queryable(); if (CurrentUser.USERTYPE == 3)//销售员 { int saleid = CurrentUser.Id; var qq = orm.Queryable().LeftJoin((city, province) => city.ID == province.distributorId).RightJoin((dis, udis, car) => udis.distributorId == car.DistributorsID); var views = qq.Select((dis, udis, car) => new { Car = car, UDis = udis }).OrderByDesc(p => p.UDis.ID).Where(p => p.UDis.userId == saleid).ToList(res); if (views.IsSuccess) { var listdis = views.ResultModel; List carlist = new List(); //List Names = new List(); foreach (var enty in listdis) { EntYW_Bicycle mod = enty.Car; CarGPSModel car = new CarGPSModel(); car.imei = mod.CarID; car.barCode = mod.carBar; string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString(); MongoDbHelper mh = new MongoDbHelper(ip, "1000"); var query = Query.And(Query.EQ("imei", mod.CarID)); var modgps = mh.FindOne(query); if (modgps.IfNotNull()) { var GPS = Ant.SuperSocket.Common.ToolGPSamap.GPSToGDGPS(modgps.lng.ToDou(), modgps.lat.ToDou()); lat = GPS.Split(',')[1]; lng = GPS.Split(',')[0]; car.onlineTime = modgps.add_time.ToDateTime().ToString("yyyy-MM-dd HH:mm:ss"); car.postType = "GPS位置"; } else { var reslut = orm.Queryable().Where(p => p.IMEI == mod.CarID).FirstOrDefault(res); if (reslut.IsSuccess) { DeviceManage beatenty = reslut.ResultModel; lat = beatenty.latitude.ToString(); lng = beatenty.longitude.ToString(); } } orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); string sql = "SELECT CAST(SUM(WorkingHours) AS INT) AS [C] FROM YW_CarTrip where imei='" + mod.CarID + "'"; var sum = orm.db.ExecuteScalar(sql); string workhours = DateTimeUtility.MinuteToHour(sum.ToDou()); car.workingHours = workhours; car.id = mod.ID.ToString(); string url = Request.Url.ToString(); string parm = Request.RawUrl; url = url.Replace(parm, ""); car.pic = url + "/upload/20170705135420_87460.jpg"; car.name = mod.CarName + "(" + mod.CarModel + ")"; car.latitude = lat; car.longitude = lng; car.online = (mod.LeaseStatus == 1) ? "在线" : "不在线"; orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" }; var reslutcar = orm.Queryable().Where(p => p.imei == mod.CarID).FirstOrDefault(res); if (reslutcar.IsSuccess) { YW_CarParamDetails locatmod = reslutcar.ResultModel; car.hydraulic = locatmod.hydraulic + " KPa"; car.speed = locatmod.speed + " 转"; car.temperature = locatmod.temperature + " ℃"; var v = (locatmod.voltage.ToDou()).ToString("0.00"); car.voltage = v + " V"; } else { orm.db = DataAccessFactory.CreateDataConnection("CyclingItemLog"); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" }; var reslutparm = orm.Queryable().Where(p => p.imei == mod.CarID).FirstOrDefault(res); if (reslutparm.IsSuccess) { YW_CarParamDetails locatmod = reslutparm.ResultModel; car.hydraulic = locatmod.hydraulic + " KPa"; car.speed = locatmod.speed + " 转"; car.temperature = locatmod.temperature + " ℃"; var v = (locatmod.voltage.ToDou()).ToString("0.00"); car.voltage = v + " V"; } else { car.hydraulic = "0 KPa"; car.temperature = "0 ℃"; car.speed = "0 转"; car.voltage = "0 V"; } } car.address = ToolGPSamap.GPSToPositionString(car.longitude.ToDou(), car.latitude.ToDou()); carlist.Add(car); } carlist = carlist.OrderBy(p => p.onlineTime).ToList(); return Json(carlist, JsonRequestBehavior.AllowGet); } } else { List carlist = new List(); var qq = orm.Queryable().LeftJoin((city, province) => city.CarID == province.IMEI); var views = qq.Select((car, device) => new { Device = device, Car = car }).OrderByDesc(p => p.Car.ID).Where(p => p.Device.City == strname).ToList(res); if (views.IsSuccess) { foreach (var enty in views.ResultModel) { EntYW_Bicycle mod = enty.Car; CarGPSModel car = new CarGPSModel(); car.imei = mod.CarID; car.barCode = mod.carBar; //string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString(); //MongoDbHelper mh = new MongoDbHelper(ip, "1000"); orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); var reslut = orm.Queryable().Where(p => p.IMEI == mod.CarID).FirstOrDefault(res); if (reslut.IsSuccess) { DeviceManage beatenty = reslut.ResultModel; lat = beatenty.latitude.ToString(); lng = beatenty.longitude.ToString(); car.onlineTime = beatenty.LastOnlineTime.ToDateTime().ToString("yyyy-MM-dd hh:mm:ss"); } string sql = "SELECT CAST(SUM(WorkingHours) AS INT) AS [C] FROM YW_CarTrip where imei='" + mod.CarID + "'"; var sum = orm.db.ExecuteScalar(sql); string workhours = DateTimeUtility.MinuteToHour(sum.ToDou()); car.workingHours = workhours; car.id = mod.ID.ToString(); car.pic = "http://localhost:7907/upload/20170705135420_87460.jpg"; car.name = mod.CarName + "(" + mod.CarModel + ")"; car.latitude = lat; car.longitude = lng; car.online = (mod.LeaseStatus == 1) ? "在线" : "不在线"; orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" }; var reslutcar = orm.Queryable().Where(p => p.imei == mod.CarID).FirstOrDefault(res); if (reslutcar.IsSuccess) { YW_CarParamDetails locatmod = reslutcar.ResultModel; car.hydraulic = locatmod.hydraulic + " KPa"; car.speed = locatmod.speed + " 转"; car.temperature = locatmod.temperature + " ℃"; var v = (locatmod.voltage.ToDou()).ToString("0.00"); car.voltage = v + " V"; } else { orm.db = DataAccessFactory.CreateDataConnection("CyclingItemLog"); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" }; var reslutparm = orm.Queryable().Where(p => p.imei == mod.CarID).FirstOrDefault(res); if (reslutparm.IsSuccess) { YW_CarParamDetails locatmod = reslutparm.ResultModel; car.hydraulic = locatmod.hydraulic + " KPa"; car.speed = locatmod.speed + " 转"; car.temperature = locatmod.temperature + " ℃"; var v = (locatmod.voltage.ToDou()).ToString("0.00"); car.voltage = v + " V"; } else { car.hydraulic = "0 KPa"; car.temperature = "0 ℃"; car.speed = "0 转"; car.voltage = "0 V"; } } //var querywhere = MongoDB.Driver.Builders.Query.Where(xx => xx.carId == mod.CarID); //var locatmod = mh.FindOne(querywhere); //if (locatmod.IfNotNull()) //{ // car.hydraulic = locatmod.hydraulic + " KPa"; // car.speed = locatmod.speed + " 转"; // car.temperature = locatmod.temperature + " ℃"; // var v = (locatmod.voltage.ToDou() / 1000).ToString("0.00"); // car.voltage = v + " V"; //} //else //{ // car.hydraulic = "0 KPa"; // car.temperature = "0 ℃"; // car.speed = "0 转"; // car.voltage = "0 V"; //} car.address = ToolGPSamap.GPSToPositionString(car.longitude.ToDou(), car.latitude.ToDou()); if (car.longitude.ToDou() > 0 && car.latitude.ToDou() > 0) carlist.Add(car); } } carlist = carlist.OrderBy(p => p.onlineTime).ToList(); return Json(carlist, JsonRequestBehavior.AllowGet); } } return null; } public ActionResult mapDrivingTrack(string id) { ViewData["carid"] = id; return View(); } /// /// 加载列表 /// /// [UserAuthorizeAttribute(ModuleAlias = "carList", OperaAction = "View")] public ActionResult CarList() { try { string userid = string.Empty; string distributorsID = string.Empty; PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List())); if (!Request.QueryString["userid"].IsEmpty()) { userid = Request.QueryString["userid"].ToString(); } if (!Request.QueryString["distributorsid"].IsEmpty()) { distributorsID = Request.QueryString["distributorsid"].ToString(); } if (!userid.IsEmpty()) { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; IQuery dis = orm.Queryable(); IQuery bicycle = orm.Queryable(); IJoiningQuery user_city = dis.LeftJoin(bicycle, (strip, sbicycle) => strip.carId == sbicycle.CarID); var views = user_city.Select((strip, sbicycle) => new { carInfo = sbicycle, trip = strip }).Where(p => p.trip.userId == userid).OrderByDesc(p => p.carInfo.ID).ToList(); if (views.IsSuccess) { List listcar = new List(); foreach (var item in views.ResultModel) { EntYW_Bicycle mod = item.carInfo; YW_UserCar userCar = item.trip; mod.lang = (userCar.userIdentity == 1) ? "机主" : "机手"; listcar.Add(mod); } pageInfo = new PageInfo(base.page, base.pagesize, views.RecordNum, JsonConverter.JsonClass(listcar)); } } } else { if (!distributorsID.IsEmpty()) { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; var reslut = orm.Queryable().Where(p => p.DistributorsID == distributorsID).ToList(res); if (reslut.IsSuccess) { pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel)); } } } } return View(pageInfo); } catch (Exception e) { WriteLog(enumOperator.Select, "加载岗位列表:", e); throw e.InnerException; } } /// /// 加载列表 /// /// [UserAuthorizeAttribute(ModuleAlias = "machineryList", OperaAction = "View")] public ActionResult MachineryList() { try { string posttype = Request.QueryString["posttype"]; string FK_DPTID = Request.QueryString["FK_DPTID"]; string CarSate = Request.QueryString["CarSate"]; int carType = Request.QueryString["LeaseStatus"].ToInt32(); string barcode = Request.QueryString["txt_barcode"]; string imei = Request.QueryString["txt_imei"]; string factoryNumber = Request.QueryString["txt_factoryNumber"]; string factoryDate = Request.QueryString["txt_factoryDate"]; int prov = Request.QueryString["hkprov"].ToInt32(); int state = -1; if (!CarSate.IsEmpty()) { state = CarSate.ToInt32(); } int FenceState = -1; if (!Request.QueryString["FenceState"].IsEmpty()) { FenceState = Request.QueryString["FenceState"].ToInt32(); } string distributorsID = string.Empty; PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List())); if (CurrentUser.USERTYPE == 0 || CurrentUser.USERTYPE == 8) { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; IQuery dis = orm.Queryable(); IQuery carquery = orm.Queryable(); var cardis = carquery.LeftJoin(dis, (d, c) => d.DistributorsID == c.ID); var qq = cardis.Select((cars, disname) => new { Car = cars, Dis = disname }).Where(a => a.Car.CarSate > 0); if (carType > 0) qq = qq.Where(p => p.Car.ProductLine == carType); if (!FK_DPTID.IsEmpty()) qq = qq.Where(p => p.Car.DistributorsID == FK_DPTID); if (!barcode.IsEmpty()) { qq = qq.Where(p => p.Car.carBar.Contains(barcode)); } if (!imei.IsEmpty()) { qq = qq.Where(p => p.Car.CarID.Contains(imei)); } if (FenceState >= 0) { qq = qq.Where(p => p.Car.FenceState == FenceState); } if (CurrentUser.USERTYPE == 8) { qq = qq.Where(p => p.Car.DistributorsID != "fc674ffb-3044-4f5f-a40d-cf496fac52f7"); } if (state >= 0) { qq = qq.Where(p => p.Car.CarSate == state); } if (prov > 0) { qq = qq.Where(p => p.Dis.Province == prov); } if (!factoryNumber.IsEmpty()) { qq = qq.Where(p => p.Car.FactoryNumber == factoryNumber); } if (!factoryDate.IsEmpty()) { DateTime dateTime = factoryDate.ToDateTime(); DateTime dates = dateTime.AddDays(1); qq = qq.Where(p => p.Car.OutDate >= dateTime && p.Car.OutDate < dates); } int pageno = (page - 1) * pagesize; var bicycleList = qq.OrderBy(a => a.Car.carBar).Skip(pageno).Top(pagesize).ToList(); if (bicycleList.IsSuccess) { bicycleList.RecordNum = qq.Count(); List listcar = new List(); foreach (var item in bicycleList.ResultModel) { EntYW_Bicycle mod = item.Car; listcar.Add(mod); } pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, JsonConverter.JsonClass(listcar)); } } } else { //if (CurrentUser.DptInfo.IfNotNull()) //{ // if (!CurrentUser.DptInfo.ID.IsEmpty()) // { // distributorsID = CurrentUser.DptInfo.ID; // } //} //else //{ int saleid = CurrentUser.Id; using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; var q = orm.Queryable(); if (!FK_DPTID.IsEmpty()) { q = q.Where(p => p.DistributorsID == FK_DPTID); if (carType > 0) { q = q.Where(p => p.ProductLine == carType); } if (!barcode.IsEmpty()) { q = q.Where(p => p.carBar.Contains(barcode)); } if (!imei.IsEmpty()) { q = q.Where(p => p.CarID.Contains(imei)); } if (FenceState >= 0) { q = q.Where(p => p.FenceState == FenceState); } if (state >= 0) { q = q.Where(p => p.CarSate == state); } if (!factoryNumber.IsEmpty()) { q = q.Where(p => p.FactoryNumber == factoryNumber); } int pageno = (page - 1) * pagesize; var bicycleList = q.Skip(pageno).Top(pagesize).ToList(); if (bicycleList.IsSuccess) { bicycleList.RecordNum = q.Count(); List listcar = new List(); foreach (EntYW_Bicycle item in bicycleList.ResultModel) { listcar.Add(item); } pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, JsonConverter.JsonClass(listcar)); } } else { IQuery car = orm.Queryable(); var dis = orm.Queryable(); IQuery userdis = orm.Queryable(); IJoiningQuery user_city; if (CurrentUser.USERTYPE == 10) { user_city = car.LeftJoin(userdis, (user, city) => user.DistributorsID == city.distributorId); } else { 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)); } IJoiningQuery user_city_province = user_city.InnerJoin(dis, (user, city, province) => (city.distributorId == province.ID)); var qq = user_city_province.Select((user, city, disname) => new { Users = user, Citys = city, Dis = disname }).Where(a => a.Citys.userId == saleid); if (!Request.QueryString["CarSate"].IsEmpty()) { int carstate = CarState.Storage.ToInt32(); } if (carType > 0) { qq = qq.Where(p => p.Users.carType == carType); } if (prov > 0) { qq = qq.Where(p => p.Dis.Province == prov); } if (!barcode.IsEmpty()) { qq = qq.Where(p => p.Users.carBar.Contains(barcode)); } if (!imei.IsEmpty()) { qq = qq.Where(p => p.Users.CarID.Contains(imei)); } if (FenceState >= 0) { qq = qq.Where(p => p.Users.FenceState == FenceState); } if (state >= 0) { qq = qq.Where(p => p.Users.CarSate == state); } if (!factoryNumber.IsEmpty()) { qq = qq.Where(p => p.Users.FactoryNumber == factoryNumber); } if (!factoryDate.IsEmpty()) { DateTime dateTime = factoryDate.ToDateTime(); DateTime dates = dateTime.AddDays(1); qq = qq.Where(p => p.Users.OutDate >= dateTime && p.Users.OutDate < dates); } int pageno = (page - 1) * pagesize; var bicycleList = qq.OrderByDesc(p => p.Users.DistributorsID).Skip(pageno).Top(pagesize).ToList(); if (bicycleList.IsSuccess) { bicycleList.RecordNum = qq.Count(); List listcar = new List(); foreach (var item in bicycleList.ResultModel) { EntYW_Bicycle carmode = item.Users; listcar.Add(carmode); } pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, JsonConverter.JsonClass(listcar)); } } } //} } if (!distributorsID.IsEmpty()) { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; var q = orm.Queryable().Where(p => p.DistributorsID == distributorsID); if (!Request.QueryString["CarSate"].IsEmpty()) { int carstate = CarState.Storage.ToInt32(); q = q.Where(p => p.CarSate == carstate); } if (!barcode.IsEmpty()) { q = q.Where(p => p.carBar.Contains(barcode)); } if (!imei.IsEmpty()) { q = q.Where(p => p.CarID.Contains(imei)); } int pageno = (page - 1) * pagesize; var reslut = q.OrderBy(a => a.carBar).Skip(pageno).Top(pagesize).ToList(res); if (reslut.IsSuccess) { reslut.RecordNum = q.Count(); pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel)); } } } int uid = 0; if (CurrentUser.USERTYPE == 0 || CurrentUser.USERTYPE == 8) { uid = 0; } else { uid = CurrentUser.Id; } if (!Request.QueryString["hkprov"].IsEmpty()) { ViewData["hkprov"] = Request.QueryString["hkprov"]; } ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew(uid, prov); ViewData["dptid"] = FK_DPTID; ViewData["CarSate"] = CarSate; ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList(); ViewData["typecar"] = carType; ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList(); //ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").ToList(); ViewData["factoryNumber"] = factoryNumber; ViewData["factoryDate"] = factoryDate; ViewData["FenceState"] = FenceState; ViewBag.Search = base.keywords; ViewData["barcode"] = barcode; ViewData["imei"] = imei; return View(pageInfo); } catch (Exception e) { WriteLog(enumOperator.Select, "加载岗位列表:", e); throw e.InnerException; } } /// /// 加载列表 /// /// [UserAuthorizeAttribute(ModuleAlias = "salesCarList", OperaAction = "View")] public ActionResult SalesCarList() { try { string posttype = Request.QueryString["posttype"]; string FK_DPTID = Request.QueryString["FK_DPTID"]; string CarSate = Request.QueryString["CarSate"]; string barcode = Request.QueryString["txt_barcode"]; string imei = Request.QueryString["txt_imei"]; string factoryNumber = Request.QueryString["txt_factoryNumber"]; int FenceState = -1; if (!Request.QueryString["FenceState"].IsEmpty()) { FenceState = Request.QueryString["FenceState"].ToInt32(); } int carType = Request.QueryString["LeaseStatus"].ToInt32(); int state = -1; if (!CarSate.IsEmpty()) { state = CarSate.ToInt32(); } string distributorsID = string.Empty; PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List())); if (CurrentUser.USERTYPE == 0 || CurrentUser.USERTYPE == 8) { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; IQuery dis = orm.Queryable(); IQuery carquery = orm.Queryable(); var cardis = carquery.LeftJoin(dis, (d, c) => d.DistributorsID == c.ID); var qq = cardis.Select((cars, disname) => new { Car = cars, Dis = disname }).Where(a => a.Car.CarSate > 0); if (carType > 0) qq = qq.Where(p => p.Car.ProductLine == carType); if (!FK_DPTID.IsEmpty()) qq = qq.Where(p => p.Car.DistributorsID == FK_DPTID); if (!barcode.IsEmpty()) { qq = qq.Where(p => p.Car.carBar.Contains(barcode)); } if (!imei.IsEmpty()) { qq = qq.Where(p => p.Car.CarID.Contains(imei)); } if (FenceState >= 0) { qq = qq.Where(p => p.Car.FenceState == FenceState); } if (CurrentUser.USERTYPE == 8) { qq = qq.Where(p => p.Car.DistributorsID != "fc674ffb-3044-4f5f-a40d-cf496fac52f7"); } if (state >= 0) { qq = qq.Where(p => p.Car.CarSate == state); } if (!factoryNumber.IsEmpty()) { qq = qq.Where(p => p.Car.FactoryNumber == factoryNumber); } int pageno = (page - 1) * pagesize; var bicycleList = qq.OrderBy(a => a.Car.carBar).Skip(pageno).Top(pagesize).ToList(); if (bicycleList.IsSuccess) { bicycleList.RecordNum = qq.Count(); List listcar = new List(); foreach (var item in bicycleList.ResultModel) { EntYW_Bicycle mod = item.Car; listcar.Add(mod); } pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, JsonConverter.JsonClass(listcar)); } } } else { //if (CurrentUser.DptInfo.IfNotNull()) //经销商 //{ // if (!CurrentUser.DptInfo.ID.IsEmpty()) // { // distributorsID = CurrentUser.DptInfo.ID; // } //} //else //{ int saleid = CurrentUser.Id; //业务员 using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; var q = orm.Queryable(); if (!FK_DPTID.IsEmpty()) { q = q.Where(p => p.DistributorsID == FK_DPTID); if (carType > 0) { q = q.Where(p => p.ProductLine == carType); } if (!barcode.IsEmpty()) { q = q.Where(p => p.carBar.Contains(barcode)); } if (!imei.IsEmpty()) { q = q.Where(p => p.CarID.Contains(imei)); } if (FenceState >= 0) { q = q.Where(p => p.FenceState == FenceState); } if (state >= 0) { q = q.Where(p => p.CarSate == state); } if (!factoryNumber.IsEmpty()) { q = q.Where(p => p.FactoryNumber == factoryNumber); } int pageno = (page - 1) * pagesize; var bicycleList = q.Skip(pageno).Top(pagesize).ToList(); if (bicycleList.IsSuccess) { bicycleList.RecordNum = q.Count(); List listcar = new List(); foreach (EntYW_Bicycle item in bicycleList.ResultModel) { listcar.Add(item); } pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, JsonConverter.JsonClass(listcar)); } } else { IQuery car = orm.Queryable(); IQuery userdis = orm.Queryable(); IQuery dis = orm.Queryable(); IJoiningQuery user_city; if (CurrentUser.USERTYPE == 10) { user_city = car.LeftJoin(userdis, (user, city) => user.DistributorsID == city.distributorId); } else { 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)); } IJoiningQuery user_city_province = user_city.InnerJoin(dis, (user, city, province) => (city.distributorId == province.ID)); var qq = user_city_province.Select((user, city, disname) => new { Users = user, Citys = city, Dis = disname }).Where(a => a.Citys.userId == saleid); if (!Request.QueryString["CarSate"].IsEmpty()) { int carstate = CarState.Storage.ToInt32(); } if (carType > 0) { qq = qq.Where(p => p.Users.ProductLine == carType); } if (!barcode.IsEmpty()) { qq = qq.Where(p => p.Users.carBar.Contains(barcode)); } if (!imei.IsEmpty()) { qq = qq.Where(p => p.Users.CarID.Contains(imei)); } if (FenceState >= 0) { qq = qq.Where(p => p.Users.FenceState == FenceState); } if (state >= 0) { qq = qq.Where(p => p.Users.CarSate == state); } if (!factoryNumber.IsEmpty()) { qq = qq.Where(p => p.Users.FactoryNumber == factoryNumber); } int pageno = (page - 1) * pagesize; var bicycleList = qq.OrderByDesc(p => p.Users.DistributorsID).Skip(pageno).Top(pagesize).ToList(); if (bicycleList.IsSuccess) { bicycleList.RecordNum = qq.Count(); List listcar = new List(); foreach (var item in bicycleList.ResultModel) { EntYW_Bicycle carmode = item.Users; EntSYS_DISTRIBUTORS dismod = item.Dis; carmode.DistributorsName = dismod.NAME; listcar.Add(carmode); } pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, JsonConverter.JsonClass(listcar)); } } } //} } if (!distributorsID.IsEmpty()) { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; var q = orm.Queryable().Where(p => p.DistributorsID == distributorsID); if (!Request.QueryString["CarSate"].IsEmpty()) { int carstate = CarState.Storage.ToInt32(); q = q.Where(p => p.CarSate == carstate); } if (!barcode.IsEmpty()) { q = q.Where(p => p.carBar.Contains(barcode)); } if (!imei.IsEmpty()) { q = q.Where(p => p.CarID.Contains(imei)); } if (state >= 0) { q = q.Where(p => p.CarSate == state); } if (!factoryNumber.IsEmpty()) { q = q.Where(p => p.FactoryNumber == factoryNumber); } int pageno = (page - 1) * pagesize; var reslut = q.Skip(pageno).Top(pagesize).ToList(); if (reslut.IsSuccess) { pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel)); } } } int uid = 0; if (CurrentUser.USERTYPE == 0 || CurrentUser.USERTYPE == 8) { uid = 0; } else { uid = CurrentUser.Id; } ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew(uid); ViewData["dptid"] = FK_DPTID; ViewData["CarSate"] = CarSate; ViewData["FenceState"] = FenceState; ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList(); ViewData["typecar"] = carType; ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList(); ViewData["barcode"] = barcode; ViewData["factoryNumber"] = factoryNumber; ViewData["imei"] = imei; return View(pageInfo); } catch (Exception e) { WriteLog(enumOperator.Select, "加载岗位列表:", e); throw e.InnerException; } } /// /// 锁车列表 /// /// public ActionResult CarLockList(string id) { try { PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List())); using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; var reslut = orm.Queryable().Where(p => p.IMEI == "356802033785329").ToList(res); if (reslut.IsSuccess) { pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel)); } } return View(pageInfo); } catch (Exception e) { WriteLog(enumOperator.Select, "加载岗位列表:", e); throw e.InnerException; } } /// /// 加载列表 /// /// [UserAuthorizeAttribute(ModuleAlias = "SalesCarList", OperaAction = "View,Add,Edit,Export")] public ActionResult DistributorCarList() { try { string userid = string.Empty; string CarSate = Request.QueryString["CarSate"]; string distributorsID = string.Empty; string LEVEL = string.Empty; string distributorName = string.Empty; string saleId = string.Empty; PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List())); if (!Request.QueryString["distributorsid"].IsEmpty()) { distributorsID = Request.QueryString["distributorsid"].ToString(); } if (!Request.QueryString["distributorLEVEL"].IsEmpty()) { LEVEL = Request.QueryString["distributorLEVEL"].ToString(); } if (!Request.QueryString["distributorsName"].IsEmpty()) { distributorName = Request.QueryString["distributorsName"].ToString(); } if (!Request.QueryString["saleid"].IsEmpty()) { saleId = Request.QueryString["saleid"].ToString(); } if (!distributorsID.IsEmpty()) { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; var q = orm.Queryable(); if (!CarSate.IsEmpty() && CarSate != "-1") { int state = CarSate.ToInt32(); if (LEVEL == "2") { q = q.Where(p => p.DistributorsID == distributorsID && p.CarSate == state); } else { q = q.Where(p => p.WarehouseID == distributorsID && p.CarSate == state); } } else { if (LEVEL == "2") { q = q.Where(p => p.DistributorsID == distributorsID); } else { q = q.Where(p => p.WarehouseID == distributorsID); } } int pageno = (page - 1) * pagesize; var reslut = q.OrderByDesc(p => p.CreateDate).Skip(pageno).Top(pagesize).ToList(res); if (reslut.IsSuccess) { reslut.RecordNum = q.Count(); pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel)); } } } //ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").ToList(); ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList(); ViewData["CarSate"] = CarSate; ViewData["distributorsid"] = distributorsID; ViewData["distributorName"] = distributorName; ViewData["saleid"] = saleId; return View(pageInfo); } catch (Exception e) { WriteLog(enumOperator.Select, "加载岗位列表:", e); throw e.InnerException; } } /// /// 加载列表 /// /// [UserAuthorizeAttribute(ModuleAlias = "Department", OperaAction = "View,Export")] public ActionResult DistributorInventoryCarList() { try { string userid = string.Empty; string distributorsID = string.Empty; string CarSate = Request.QueryString["CarSate"]; PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List())); if (!Request.QueryString["distributorsid"].IsEmpty()) { distributorsID = Request.QueryString["distributorsid"].ToString(); } if (!distributorsID.IsEmpty()) { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; var q = orm.Queryable(); if (!CarSate.IsEmpty()) { int state = CarSate.ToInt32(); q = q.Where(p => p.DistributorsID == distributorsID && p.CarSate == state); } else { q = q.Where(p => p.DistributorsID == distributorsID); } var reslut = q.ToList(res); if (reslut.IsSuccess) { pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel)); } } } ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList(); //ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").ToList(); ViewData["CarSate"] = CarSate; ViewData["distributorsid"] = distributorsID; return View(pageInfo); } catch (Exception e) { WriteLog(enumOperator.Select, "加载岗位列表:", e); throw e.InnerException; } } /// /// 申请审校不通过 /// /// [HttpGet] public ActionResult CheckApplyCarPass(string applyid) { var json = new JsonHelper() { Status = "y", Msg = "Success" }; using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel(); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" }; Guid guid = new Guid(applyid); var reslut = orm.Queryable().Where(p => p.id == guid).FirstOrDefault(res); if (reslut.IsSuccess) { yw_machinery_return mod = reslut.ResultModel; if (mod.apply_type == 1)//退货 { int carstate = CarState.OutStock.ToInt32(); var reslutcar = orm.UpdateByLambda(p => new EntYW_Bicycle { CarSate = carstate }, f => f.CarID == mod.carid, res); { var reslutapply = orm.UpdateByLambda(p => new yw_machinery_return { state = 1, check_time = DateTime.Now }, f => f.id == mod.id, res); if (reslutapply.IsSuccess) { json.Status = "y"; json.Msg = "退货审核通过"; } var usersalereslut = orm.DeleteByLambda(p => p.imei == mod.carid, res); if (usersalereslut.IsSuccess) { } var userbindreslut = orm.DeleteByLambda(p => p.carId == mod.carid, res); if (userbindreslut.IsSuccess) { } var alarmreslut = orm.DeleteByLambda(p => p.CarId == mod.carid, res); if (alarmreslut.IsSuccess) { } } } if (mod.apply_type == 2)//返厂 { int carstate = CarState.carBind.ToInt32(); var reslutcar = orm.UpdateByLambda(p => new EntYW_Bicycle { CarSate = carstate, DistributorsID = "", DistributorsName = "" }, f => f.CarID == mod.carid, res); { var reslutapply = orm.UpdateByLambda(p => new yw_machinery_return { state = 1 }, f => f.id == mod.id, res); if (reslutapply.IsSuccess) { json.Status = "y"; json.Msg = "返厂审核通过"; } var usersalereslut = orm.DeleteByLambda(p => p.imei == mod.carid, res); if (usersalereslut.IsSuccess) { } var userbindreslut = orm.DeleteByLambda(p => p.carId == mod.carid, res); if (userbindreslut.IsSuccess) { } var alarmreslut = orm.DeleteByLambda(p => p.CarId == mod.carid, res); if (alarmreslut.IsSuccess) { } } } if (mod.apply_type == 3)//调拨 { int carstate = CarState.OutStock.ToInt32(); var reslutcar = orm.UpdateByLambda(p => new EntYW_Bicycle { CarSate = carstate, DistributorsID = mod.distributorsID, DistributorsName = mod.distributorsName }, f => f.CarID == mod.carid, res); { var reslutapply = orm.UpdateByLambda(p => new yw_machinery_return { state = 1 }, f => f.id == mod.id, res); if (reslutapply.IsSuccess) { json.Status = "y"; json.Msg = "调拨审核通过"; } var usersalereslut = orm.DeleteByLambda(p => p.imei == mod.carid, res); if (usersalereslut.IsSuccess) { } var userbindreslut = orm.DeleteByLambda(p => p.carId == mod.carid, res); if (userbindreslut.IsSuccess) { } var alarmreslut = orm.DeleteByLambda(p => p.CarId == mod.carid, res); if (alarmreslut.IsSuccess) { } } } if (mod.apply_type == 4) { //SendLockCarCmd(mod.carid); } if (mod.apply_type == 5) { //SendUnlockCarCmd(mod.carid); } } } return Json(json, JsonRequestBehavior.AllowGet); } /// /// 审核不通过 /// /// /// [HttpGet] public ActionResult CheckApplyCarNoPass(string applyid) { var json = new JsonHelper() { Status = "y", Msg = "Success" }; using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel(); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" }; Guid guid = new Guid(applyid); var reslutapply = orm.UpdateByLambda(p => new yw_machinery_return { state = 2 }, f => f.id == guid, res); if (reslutapply.IsSuccess) { var reslutmod = orm.Queryable().Where(p => p.id == guid).FirstOrDefault(res); if (reslutmod.IsSuccess) { yw_machinery_return mod = reslutmod.ResultModel; orm.UpdateByLambda(p => new EntYW_Bicycle { CarSate = mod.carState }, f => f.CarID == mod.carid, res); } } } return Json(json, JsonRequestBehavior.AllowGet); } /// /// 发送锁车指令 /// [HttpGet] public ActionResult SendLockCarCmd(string carid) { var json = new JsonHelper() { Status = "y", Msg = "Success" }; var applyName = Request["applyName"]; var applyReason = Request["applyReason"]; var applypwd = Request["applyPwd"]; if (applypwd == "changfa123") { var str = DataHelper.sendLockHexStr(Convert.ToInt64(carid.Trim())); var body = DataHelper.HexToByte(str); SocketClient client = new SocketClient(); try { string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString(); int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32(); client.Connect(ip, port); var flag = client.SendData(body); //string mip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString(); //MongoDbHelper mh = new MongoDbHelper(mip, "1000"); //var querywhere = MongoDB.Driver.Builders.Query.Where(xx => xx.carid == carid); //var locatmod = mh.FindOne(querywhere); //if (locatmod.IsNull()) //{ // ApplyCarLock userCar = new ApplyCarLock(); // userCar.carid = carid; // userCar.apply_type = 1; //发送锁车指令 // userCar.state = 0; // userCar.add_name = "服务"; // userCar.created_at = DateTime.Now; // var carflag = mh.Insert(userCar); //} //else //{ // var update = new MongoDB.Driver.UpdateDocument { { "$set", new MongoDB.Driver.QueryDocument { { "apply_type", 1 }, { "state", 0 } } } }; // var querystr = MongoDB.Driver.Builders.Query.Where(xx => xx.carid == carid); // if (mh.Update(querystr, update)) // { // } //} using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; var reslutlock = orm.UpdateByLambda(p => new YW_Apply_CarLock { state = 2 }, f => f.carid == carid && f.state == 0, res); if (reslutlock.IsSuccess) { } YW_Apply_CarLock apply_CarLock = new YW_Apply_CarLock(); apply_CarLock.ID = Guid.NewGuid(); apply_CarLock.apply_type = 1; apply_CarLock.apply_name = applyName; apply_CarLock.reason = applyReason; apply_CarLock.carid = carid; apply_CarLock.add_time = DateTime.Now; apply_CarLock.state = 0; apply_CarLock.add_name = "管理员"; orm.Save(apply_CarLock, res); } client.Disconnect(); } catch (Exception ex) { } } else { json.Msg = "申请密码不正确!"; json.Status = "n"; } //json.Data = Common.JsonConverter.Serialize(this.CodeAreaManage.LoadListAll(p => p.LEVELS == 1)); return Json(json, JsonRequestBehavior.AllowGet); } /// /// 发送开锁指令 /// [HttpGet] public ActionResult SendUnlockCarCmd(string carid) { var json = new JsonHelper() { Status = "y", Msg = "Success" }; var applyName = Request["applyName"]; var applyReason = Request["applyReason"]; var applypwd = Request["applyPwd"]; if (applypwd == "changfa123") { var str = DataHelper.sendUnLockHexStr(Convert.ToInt64(carid.Trim())); var body = DataHelper.HexToByte(str); SocketClient client = new SocketClient(); try { string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString(); int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32(); client.Connect(ip, port); var flag = client.SendData(body); //string mip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString(); //MongoDbHelper mh = new MongoDbHelper(mip, "1000"); //var querywhere = MongoDB.Driver.Builders.Query.Where(xx => xx.carid == carid); //var applymod = mh.FindOne(querywhere); //if (applymod.IsNull()) //{ // ApplyCarLock userCar = new ApplyCarLock(); // userCar.carid = carid; // userCar.apply_type = 2; // userCar.state = 0; // userCar.add_name = "服务"; // var carflag = mh.Insert(userCar); //} //else //{ // var update = new MongoDB.Driver.UpdateDocument { { "$set", new MongoDB.Driver.QueryDocument { { "apply_type", 2 }, { "state", 0 } } } }; // var querystr = MongoDB.Driver.Builders.Query.Where(xx => xx.carid == carid); // if (mh.Update(querystr, update)) // { // } //} using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; var reslutlock = orm.UpdateByLambda(p => new YW_Apply_CarLock { state = 2 }, f => f.carid == carid && f.state == 0, res); if (reslutlock.IsSuccess) { } YW_Apply_CarLock apply_CarLock = new YW_Apply_CarLock(); apply_CarLock.ID = Guid.NewGuid(); apply_CarLock.apply_type = 2; apply_CarLock.apply_name = applyName; apply_CarLock.reason = applyReason; apply_CarLock.carid = carid; apply_CarLock.add_time = DateTime.Now; apply_CarLock.state = 0; apply_CarLock.add_name = "管理员"; orm.Save(apply_CarLock, res); } client.Disconnect(); } catch (Exception ex) { } } else { json.Msg = "申请密码不正确!"; json.Status = "n"; } //json.Data = Common.JsonConverter.Serialize(this.CodeAreaManage.LoadListAll(p => p.LEVELS == 1)); return Json(json, JsonRequestBehavior.AllowGet); } /// /// 导出excel /// /// [HttpGet] [UserAuthorizeAttribute(ModuleAlias = "carList", OperaAction = "View")] public FileResult Excel() { //获取list数据 List list = new List(); //创建Excel文件的对象 NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); string distributorsID = string.Empty; string CarSate = Request.QueryString["CarSate"]; //添加一个sheet NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1"); //给sheet1添加第一行的头部标题 NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0); row1.CreateCell(0).SetCellValue("农机IMEI号"); row1.CreateCell(1).SetCellValue("农机名称"); row1.CreateCell(2).SetCellValue("车架号"); row1.CreateCell(3).SetCellValue("所属经销商"); row1.CreateCell(4).SetCellValue("车辆状态"); row1.CreateCell(5).SetCellValue("出厂日期"); //将数据逐步写入sheet1各个行 if (!Request.QueryString["distributorsid"].IsEmpty()) { distributorsID = Request.QueryString["distributorsid"].ToString(); } if (!distributorsID.IsEmpty()) { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; var q = orm.Queryable(); if (!CarSate.IsEmpty()) { int state = CarSate.ToInt32(); q = q.Where(p => p.DistributorsID == distributorsID && p.CarSate == state); } else { q = q.Where(p => p.DistributorsID == distributorsID); } var reslut = q.ToList(res); if (reslut.IsSuccess) { List modlist = reslut.ResultModel; for (int i = 0; i < modlist.Count; i++) { NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1); rowtemp.CreateCell(0).SetCellValue(modlist[i].CarID); rowtemp.CreateCell(1).SetCellValue(modlist[i].CarName); rowtemp.CreateCell(2).SetCellValue(modlist[i].CarNumber); rowtemp.CreateCell(3).SetCellValue(modlist[i].DistributorsName); rowtemp.CreateCell(4).SetCellValue(GetCarState.getCarStateStr(modlist[i].CarSate.ToInt32())); rowtemp.CreateCell(5).SetCellValue(modlist[i].productionDate.ToString()); //rowtemp.CreateCell(5).SetCellValue(list[i].iName); //rowtemp.CreateCell(6).SetCellValue(list[i].iPhone); //rowtemp.CreateCell(7).SetCellValue(list[i].IntegralSum); //rowtemp.CreateCell(8).SetCellValue(list[i].IntegralSy); //rowtemp.CreateCell(9).SetCellValue(list[i].IntegralKy); } } } } // 写入到客户端 System.IO.MemoryStream ms = new System.IO.MemoryStream(); book.Write(ms); ms.Seek(0, SeekOrigin.Begin); return File(ms, "application/vnd.ms-excel", "经销商库存信息.xls"); } /// /// 导出excel /// /// [HttpGet] [UserAuthorizeAttribute(ModuleAlias = "carList", OperaAction = "View")] public FileResult AllCarExcel() { //获取list数据 List list = new List(); //创建Excel文件的对象 NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); string distributorsID = string.Empty; string CarSate = Request.QueryString["CarSate"]; List namelist = new List(); //添加一个sheet NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1"); //给sheet1添加第一行的头部标题 NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0); row1.CreateCell(0).SetCellValue("农机IMEI号"); row1.CreateCell(1).SetCellValue("农机名称"); row1.CreateCell(2).SetCellValue("车架号"); row1.CreateCell(3).SetCellValue("所属经销商"); row1.CreateCell(4).SetCellValue("车辆状态"); row1.CreateCell(5).SetCellValue("出厂日期"); //将数据逐步写入sheet1各个行 if (!Request.QueryString["distributorsid"].IsEmpty()) { distributorsID = Request.QueryString["distributorsid"].ToString(); } using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; var q = orm.Queryable(); if (!Request.QueryString["hkprovid"].IsEmpty()) { int provid = Request.QueryString["hkprovid"].ToInt32(); q = q.Where(p => p.Province == provid); } if (!Request.QueryString["hkcityid"].IsEmpty()) { int provid = Request.QueryString["hkcityid"].ToInt32(); q = q.Where(p => p.City == provid); } var reslutd = q.ToList(res); if (reslutd.IsSuccess) { var modellist = reslutd.ResultModel; foreach (EntSYS_DISTRIBUTORS md in modellist) { namelist.Add(md.ID); } } } if (namelist.Count > 0) { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; var q = orm.Queryable(); if (!CarSate.IsEmpty()) { int state = CarSate.ToInt32(); q = q.Where(p => namelist.Contains(p.DistributorsID) && p.CarSate == state); } else { q = q.Where(p => namelist.Contains(p.DistributorsID)); } var reslut = q.ToList(res); if (reslut.IsSuccess) { List modlist = reslut.ResultModel; for (int i = 0; i < modlist.Count; i++) { NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1); rowtemp.CreateCell(0).SetCellValue(modlist[i].CarID); rowtemp.CreateCell(1).SetCellValue(modlist[i].CarName); rowtemp.CreateCell(2).SetCellValue(modlist[i].carBar); rowtemp.CreateCell(3).SetCellValue(modlist[i].DistributorsName); rowtemp.CreateCell(4).SetCellValue(GetCarState.getCarStateStr(modlist[i].CarSate.ToInt32())); rowtemp.CreateCell(5).SetCellValue(modlist[i].productionDate.ToString()); //rowtemp.CreateCell(5).SetCellValue(list[i].iName); //rowtemp.CreateCell(6).SetCellValue(list[i].iPhone); //rowtemp.CreateCell(7).SetCellValue(list[i].IntegralSum); //rowtemp.CreateCell(8).SetCellValue(list[i].IntegralSy); //rowtemp.CreateCell(9).SetCellValue(list[i].IntegralKy); } } } } // 写入到客户端 System.IO.MemoryStream ms = new System.IO.MemoryStream(); book.Write(ms); ms.Seek(0, SeekOrigin.Begin); return File(ms, "application/vnd.ms-excel", "经销商库存信息.xls"); } /// /// 导出电子围栏内外的数据 /// /// public FileResult FenceExcel() { //获取list数据 List list = new List(); //创建Excel文件的对象 NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); string distributorsID = string.Empty; string CarSate = Request.QueryString["CarSate"]; var cartype = Request.QueryString["cartype"]; var fencetype = Request.QueryString["fencetype"]; var dptid = Request.QueryString["dptid"]; //添加一个sheet NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1"); //给sheet1添加第一行的头部标题 NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0); row1.CreateCell(0).SetCellValue("农机IMEI号"); row1.CreateCell(1).SetCellValue("农机名称"); row1.CreateCell(2).SetCellValue("农机型号"); row1.CreateCell(3).SetCellValue("车架号"); row1.CreateCell(4).SetCellValue("所属经销商"); row1.CreateCell(5).SetCellValue("围栏状态"); row1.CreateCell(6).SetCellValue("出厂日期"); row1.CreateCell(7).SetCellValue("出厂编号"); //将数据逐步写入sheet1各个行 if (!Request.QueryString["distributorsid"].IsEmpty()) { distributorsID = Request.QueryString["distributorsid"].ToString(); } using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; var q = orm.Queryable(); if (!cartype.IsEmpty()) { int typecar = cartype.ToInt32(); q = q.Where(p => p.carType == typecar); } if (!fencetype.IsEmpty()) { int typefence = fencetype.ToInt32(); if (typefence >= 0) q = q.Where(p => p.FenceState == typefence); } if (!dptid.IsEmpty()) { q = q.Where(p => p.DistributorsID == dptid); } var reslut = q.ToList(res); if (reslut.IsSuccess) { List modlist = reslut.ResultModel; for (int i = 0; i < modlist.Count; i++) { NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1); rowtemp.CreateCell(0).SetCellValue(modlist[i].CarID); rowtemp.CreateCell(1).SetCellValue(modlist[i].CarName); rowtemp.CreateCell(2).SetCellValue(modlist[i].CarModel); rowtemp.CreateCell(3).SetCellValue(modlist[i].carBar); rowtemp.CreateCell(4).SetCellValue(modlist[i].DistributorsName); string carstatestr = ""; switch (modlist[i].FenceState) { case 0: carstatestr = "未点火"; break; case 1: carstatestr = "围栏内"; break; case 2: carstatestr = "围栏外"; break; } rowtemp.CreateCell(5).SetCellValue(carstatestr); rowtemp.CreateCell(6).SetCellValue(modlist[i].productionDate.ToString()); rowtemp.CreateCell(7).SetCellValue(modlist[i].FactoryNumber.ToString()); //rowtemp.CreateCell(5).SetCellValue(list[i].iName); //rowtemp.CreateCell(6).SetCellValue(list[i].iPhone); //rowtemp.CreateCell(7).SetCellValue(list[i].IntegralSum); //rowtemp.CreateCell(8).SetCellValue(modlist[i].OutFenceDate.ToDateTime().ToString()); //var num = DateTimeUtility.DateTimeDifference(Convert.ToDateTime(modlist[i].OutFenceDate), DateTime.Now); //rowtemp.CreateCell(9).SetCellValue(num); //orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); //string sql = "select count(1) as num from YW_AlarmInformation where CarId='" + modlist[i].CarID + "' group by CarId"; //var sum = orm.db.ExecuteScalar(sql); //rowtemp.CreateCell(10).SetCellValue(sum.ToDou()); } } } // 写入到客户端 System.IO.MemoryStream ms = new System.IO.MemoryStream(); book.Write(ms); ms.Seek(0, SeekOrigin.Begin); return File(ms, "application/vnd.ms-excel", "农机信息.xls"); } /// /// 导出电子围栏内外的数据 /// /// [UserAuthorizeAttribute(ModuleAlias = "machineryList", OperaAction = "List")] public FileResult CarTripExcel() { //获取list数据 List list = new List(); //创建Excel文件的对象 NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); string distributorsID = string.Empty; string CarSate = Request.QueryString["CarSate"]; var cartype = Request.QueryString["cartype"]; var fencetype = Request.QueryString["fencetype"]; var dptid = Request.QueryString["dptid"]; var carid = Request.QueryString["carid"]; //添加一个sheet NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1"); //给sheet1添加第一行的头部标题 NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0); row1.CreateCell(0).SetCellValue("农机IMEI号"); row1.CreateCell(1).SetCellValue("开始时间"); row1.CreateCell(2).SetCellValue("线束时间"); row1.CreateCell(3).SetCellValue("工作时长"); //将数据逐步写入sheet1各个行 using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItemLog"); RequestModel res = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" } }; var q = orm.Queryable(); if (!carid.IsEmpty()) { q = q.Where(p => p.IMEI == carid); } var reslut = q.ToList(res); if (reslut.IsSuccess) { List modlist = reslut.ResultModel; for (int i = 0; i < modlist.Count; i++) { NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1); rowtemp.CreateCell(0).SetCellValue(modlist[i].IMEI); rowtemp.CreateCell(1).SetCellValue(modlist[i].StartDate.ToString()); rowtemp.CreateCell(2).SetCellValue(modlist[i].EndDate.ToString()); rowtemp.CreateCell(3).SetCellValue(modlist[i].WorkingHours.ToString()); } } } // 写入到客户端 System.IO.MemoryStream ms = new System.IO.MemoryStream(); book.Write(ms); ms.Seek(0, SeekOrigin.Begin); return File(ms, "application/vnd.ms-excel", "农机工作时长记录.xls"); } [UserAuthorizeAttribute(ModuleAlias = "SalesCarList", OperaAction = "View")] public ActionResult carmap(string id) { UserCarMapModel userCar = new UserCarMapModel(); EntYW_Bicycle mod = new EntYW_Bicycle(); string imageUrl = string.Empty; if (!id.IsEmpty()) { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel request = new RequestModel(); request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" }; // Guid guid = new Guid(id); //YW_CarHeartbeat beatmod = new YW_CarHeartbeat(); var reslut = orm.Queryable().Where(p => p.CarID == id).FirstOrDefault(request); if (reslut.IsSuccess) { mod = reslut.ResultModel; var qq = orm.Queryable().Where(p => p.carId == id).FirstOrDefault(request); if (qq.IsSuccess) { YW_CarPurchaser purchaser = qq.ResultModel; userCar.purchaserName = purchaser.userName; userCar.purchaserTel = purchaser.userTel; userCar.purchaserTime = purchaser.addDate.ToDateTime(); } DateTime onlineDate = DateTime.Now; var beatreslut = orm.Queryable().Where(p => p.IMEI == mod.CarID).FirstOrDefault(); if (beatreslut.IsSuccess) { DeviceManage devmod = beatreslut.ResultModel; onlineDate = devmod.LastOnlineTime.ToDateTime(); var GPS = Ant.SuperSocket.Common.ToolGPSamap.GPSToGDGPS(devmod.longitude.ToDou(), devmod.latitude.ToDou()); userCar.lat = GPS.Split(',')[1]; userCar.lng = GPS.Split(',')[0]; userCar.LBS = devmod.IsLBS.ToBool(); } //else //{ // var lbsreslut = orm.Queryable().Where(p => p.imei == mod.CarID && p.locationtype == 1).OrderByDesc(p => p.add_time).FirstOrDefault(); // if (lbsreslut.IsSuccess) // { // beatmod = lbsreslut.ResultModel; // var gps = Ant.SuperSocket.Common.WebApiHelp.getLocationGPS(mod.CarID, beatmod.mcc.ToInt32(), beatmod.mnc.ToInt32(), beatmod.lac.ToInt32(), beatmod.cellID.ToInt32(), beatmod.rssi.ToInt32()); // beatmod.lng = gps.result.location.Split(',')[0].ToDec(); // beatmod.lat = gps.result.location.Split(',')[1].ToDec(); // var GPS = Ant.SuperSocket.Common.ToolGPSamap.GPSToGDGPS(beatmod.lng.ToDou(), beatmod.lat.ToDou()); // userCar.lat = GPS.Split(',')[1]; // userCar.lng = GPS.Split(',')[0]; // userCar.LBS = true; // } //} userCar.distributorsName = mod.DistributorsName; userCar.barCode = mod.carBar; userCar.carId = mod.CarID; userCar.isOnLine = mod.LeaseStatus.ToInt32(); userCar.carName = mod.CarName; userCar.FactoryNumber = mod.FactoryNumber; userCar.CarModel = mod.CarModel; StringBuilder sb = new StringBuilder("当前车辆的"); userCar.carState = mod.CarSate.ToInt32(); userCar.carNote = GetCarState.getCarStateStr(mod.CarSate.ToInt32()); userCar.LockState = mod.LockState.ToBool(); userCar.onlineDate = "最后上报时间:" + onlineDate.ToString("yyyy-MM-dd HH:mm:ss"); string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString(); MongoDbHelper mh = new MongoDbHelper(ip, "1000"); var querywhere = MongoDB.Driver.Builders.Query.Where(xx => xx.carId == mod.CarID); var modstate = mh.FindOne(querywhere); if (modstate.IfNotNull()) { userCar.hydraulic = modstate.hydraulic; userCar.speed = modstate.speed; userCar.temperature = modstate.temperature; userCar.voltage = modstate.voltage; if (userCar.hydraulic.ToInt32() > 0) { sb.AppendFormat("油压:" + userCar.hydraulic + "KPa"); } if (userCar.temperature.ToInt32() > 0) { sb.AppendFormat("水温:" + userCar.temperature + "℃"); } if (userCar.speed.ToInt32() > 0) { sb.AppendFormat("转速:" + userCar.speed); } if (userCar.voltage.ToInt32() > 0) { userCar.voltage = (userCar.voltage.ToDou()).ToString("0.00"); sb.AppendFormat("蓄电池电压:" + userCar.voltage + "V"); } if (userCar.lat.ToDou() > 0 && userCar.lng.ToDou() > 0) { var resaddress = Ant.SuperSocket.Common.ToolGPSamap.GPSToPositionString(userCar.lng.ToDou(), userCar.lat.ToDou()); if (resaddress.Length > 0) { if (userCar.LBS) userCar.address = "LBS位置:" + resaddress; else userCar.address = "GPS位置:" + resaddress; } } } else { userCar.hydraulic = "0"; userCar.temperature = "0"; userCar.speed = "0"; userCar.voltage = "0"; } userCar.carType = mod.carType.ToInt32(); userCar.Note = sb.ToString(); var strurl = ((System.Web.HttpRequestWrapper)Request).Url.Authority; var proudctline = mod.ProductLine; switch (proudctline) { case 601://轮式拖拉机 { imageUrl = "http://47.96.20.14:8086/upload/png/轮式拖拉机.png"; } break; case 615://轮式收割机 { imageUrl = "http://47.96.20.14:8086/upload/png/轮式收割机.png"; } break; case 61101://手扶插秧机 { imageUrl = "http://47.96.20.14:8086/upload/png/手扶插秧机.png"; } break; case 61102://高速插秧机 { imageUrl = "http://47.96.20.14:8086/upload/png/高速插秧机.png"; } break; case 628://花生收获机 { imageUrl = "http://47.96.20.14:8086/upload/png/花生收获机.png"; } break; case 612://履带收割机 { imageUrl = "http://47.96.20.14:8086/upload/png/履带收割机.png"; } break; case 622://轮式玉米收 { imageUrl = "http://47.96.20.14:8086/upload/png/轮式玉米收.png"; } break; default: { imageUrl = "http://47.96.20.14:8086/Content/map/map-marker-icon.png"; } break; } userCar.imageUrl = imageUrl; //switch (mod.carType.ToInt32()) //{ // case 1: // { // if (mod.LeaseStatus == 0) // imageUrl = "http://47.96.20.14:8086/Content/map/tuolaji_hui_default.png"; // else // imageUrl = "http://47.96.20.14:8086/Content/map/tlj.png"; // } // break; // case 2: // { // if (mod.LeaseStatus == 0) // imageUrl = "http://47.96.20.14:8086/Content/map/shougeji_hui_default.png"; // else // imageUrl = "http://47.96.20.14:8086/Content/map/sgj.png"; // } // break; // case 3: // { // if (mod.LeaseStatus == 0) // imageUrl = "http://47.96.20.14:8086/Content/map/chayangji_hui_default.png"; // else // imageUrl = "http://47.96.20.14:8086/Content/map/cyj.png"; // } // break; //} //userCar.imageUrl = imageUrl; } } } return View(userCar); } //[UserAuthorizeAttribute(ModuleAlias = "machineryList", OperaAction = "View")] public ActionResult machinerymap(string id) { UserCarMapModel userCar = new UserCarMapModel(); EntYW_Bicycle mod = new EntYW_Bicycle(); string imageUrl = string.Empty; if (!id.IsEmpty()) { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel request = new RequestModel { newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" } }; // Guid guid = new Guid(id); //YW_CarHeartbeat beatmod = new YW_CarHeartbeat(); var reslut = orm.Queryable().Where(p => p.CarID == id).FirstOrDefault(request); if (reslut.IsSuccess) { mod = reslut.ResultModel; var qq = orm.Queryable().Where(p => p.carId == id).FirstOrDefault(request); if (qq.IsSuccess) { YW_CarPurchaser purchaser = qq.ResultModel; userCar.purchaserName = purchaser.userName; userCar.purchaserTel = purchaser.userTel; userCar.purchaserTime = purchaser.addDate.ToDateTime(); } //string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString(); //MongoDbHelper mh = new MongoDbHelper(ip, "1000"); //var query = Query.And(Query.EQ("imei", mod.CarID)); //var modgps = mh.FindOne(query); //if (modgps.IfNotNull()) //{ // var GPS = Ant.SuperSocket.Common.ToolGPSamap.GPSToGDGPS(modgps.lng.ToDou(), modgps.lat.ToDou()); // userCar.lat = GPS.Split(',')[1]; // userCar.lng = GPS.Split(',')[0]; // beatmod.add_time = modgps.add_time; // userCar.LBS = false; //} var reslutgps = orm.Queryable().Where(p => p.IMEI == mod.CarID).FirstOrDefault(request); if (reslutgps.IsSuccess) { DeviceManage beatenty = reslutgps.ResultModel; userCar.lat = beatenty.latitude.ToString(); userCar.lng = beatenty.longitude.ToString(); userCar.LBS = beatenty.IsLBS.ToBool(); // userCar.onlineDate = beatenty.LastOnlineTime.ToDateTime().ToString("yyyy-MM-dd hh:mm:ss"); userCar.onlineDate = "最后上报时间:" + beatenty.LastOnlineTime.ToDateTime().ToString("yyyy-MM-dd HH:mm:ss"); } userCar.FactoryNumber = mod.FactoryNumber; userCar.distributorsName = mod.DistributorsName; userCar.barCode = mod.carBar; userCar.carId = mod.CarID; userCar.isOnLine = mod.LeaseStatus.ToInt32(); userCar.carName = mod.CarName; StringBuilder sb = new StringBuilder("当前车辆的"); userCar.carState = mod.CarSate.ToInt32(); userCar.carNote = GetCarState.getCarStateStr(mod.CarSate.ToInt32()); userCar.LockState = mod.LockState.ToBool(); userCar.CarModel = mod.CarModel; //string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString(); //MongoDbHelper mh = new MongoDbHelper(ip, "1000"); //var querywhere = MongoDB.Driver.Builders.Query.Where(xx => xx.carId == mod.CarID); //var modstate = mh.FindOne(querywhere); //if (modstate.IfNotNull()) //{ // userCar.hydraulic = modstate.hydraulic; // userCar.speed = modstate.speed; // userCar.temperature = modstate.temperature; // userCar.voltage = modstate.voltage; // if (userCar.hydraulic.ToInt32() > 0) // { // sb.AppendFormat("油压:" + userCar.hydraulic + "KPa"); // } // if (userCar.temperature.ToInt32() > 0) // { // sb.AppendFormat("水温:" + userCar.temperature + "℃"); // } // if (userCar.speed.ToInt32() > 0) // { // sb.AppendFormat("转速:" + userCar.speed); // } // if (userCar.voltage.ToInt32() > 0) // { // userCar.voltage = (userCar.voltage.ToDou() / 1000).ToString("0.00"); // sb.AppendFormat("蓄电池电压:" + userCar.voltage + "V"); // } // orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); // string sql = "SELECT CAST(SUM(WorkingHours) AS INT) AS [C] FROM YW_CarTrip where imei='" + mod.CarID + "'"; // var sum = orm.db.ExecuteScalar(sql); // string workhours = DateTimeUtility.MinuteToHour(sum.ToDou()); // //sb.AppendFormat("工作时长:" + workhours); // userCar.workHours = "工作时长:" + workhours; //} //else //{ // userCar.hydraulic = "0"; // userCar.temperature = "0"; // userCar.speed = "0"; // userCar.voltage = "0"; //} orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" }; var reslutcar = orm.Queryable().Where(p => p.imei == mod.CarID).FirstOrDefault(request); if (reslutcar.IsSuccess) { YW_CarParamDetails locatmod = reslutcar.ResultModel; userCar.hydraulic = locatmod.hydraulic + " KPa"; userCar.speed = locatmod.speed + " 转"; userCar.temperature = locatmod.temperature + " ℃"; var v = (locatmod.voltage.ToDou()).ToString("0.00"); userCar.voltage = v + " V"; } else { orm.db = DataAccessFactory.CreateDataConnection("CyclingItemLog"); request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" }; var reslutparm = orm.Queryable().Where(p => p.imei == mod.CarID).FirstOrDefault(request); if (reslutparm.IsSuccess) { YW_CarParamDetails locatmod = reslutparm.ResultModel; userCar.hydraulic = locatmod.hydraulic + " KPa"; userCar.speed = locatmod.speed + " 转"; userCar.temperature = locatmod.temperature + " ℃"; var v = (locatmod.voltage.ToDou()).ToString("0.00"); userCar.voltage = v + " V"; } else { userCar.hydraulic = "0 KPa"; userCar.temperature = "0 ℃"; userCar.speed = "0 转"; userCar.voltage = "0 V"; } } if (userCar.lat.ToDou() > 0 && userCar.lng.ToDou() > 0) { var resaddress = ToolGPSamap.GPSToPositionString(userCar.lng.ToDou(), userCar.lat.ToDou()); if (resaddress.Length > 0) { if (userCar.LBS) userCar.address = "LBS位置:" + resaddress; else userCar.address = "GPS位置:" + resaddress; } } userCar.carType = mod.carType.ToInt32(); userCar.Note = sb.ToString(); var strurl = ((System.Web.HttpRequestWrapper)Request).Url.Authority; var proudctline = mod.ProductLine; switch (proudctline) { case 601://轮式拖拉机 { imageUrl = "http://47.96.20.14:8086/upload/png/轮式拖拉机.png"; } break; case 615://轮式收割机 { imageUrl = "http://47.96.20.14:8086/upload/png/轮式收割机.png"; } break; case 61101://手扶插秧机 { imageUrl = "http://47.96.20.14:8086/upload/png/手扶插秧机.png"; } break; case 61102://高速插秧机 { imageUrl = "http://47.96.20.14:8086/upload/png/高速插秧机.png"; } break; case 628://花生收获机 { imageUrl = "http://47.96.20.14:8086/upload/png/花生收获机.png"; } break; case 612://履带收割机 { imageUrl = "http://47.96.20.14:8086/upload/png/履带收割机.png"; } break; case 622://轮式玉米收 { imageUrl = "http://47.96.20.14:8086/upload/png/轮式玉米收.png"; } break; default: { imageUrl = "http://47.96.20.14:8086/Content/map/map-marker-icon.png"; } break; } userCar.imageUrl = imageUrl; // switch (mod.carType.ToInt32()) // { // case 1: // { // if (mod.LeaseStatus == 0) // imageUrl = "http://47.96.20.14:8086/Content/map/tuolaji_hui_default.png"; // else // imageUrl = "http://47.96.20.14:8086/Content/map/tlj.png"; // } // break; // case 2: // { // if (mod.LeaseStatus == 0) // imageUrl = "http://47.96.20.14:8086/Content/map/shougeji_hui_default.png"; // else // imageUrl = "http://47.96.20.14:8086/Content/map/sgj.png"; // } // break; // case 3: // { // if (mod.LeaseStatus == 0) // imageUrl = "http://47.96.20.14:8086/Content/map/chayangji_hui_default.png"; // else // imageUrl = "http://47.96.20.14:8086/Content/map/cyj.png"; // } // break; // } // userCar.imageUrl = imageUrl; } } } return View(userCar); } /// /// 加载用户详情信息(基本) /// [UserAuthorizeAttribute(ModuleAlias = "salesCarList", OperaAction = "Detail")] public ActionResult Detail(string id) { try { ViewData["distributorsid"] = Request["distributorsid"]; ViewData["distributorName"] = Request["distributorName"]; Ent_YW_Bicycle mod = new Ent_YW_Bicycle(); if (!id.IsEmpty()) { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel request = new RequestModel(); request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" }; mod.ID = new Guid(id); var reslut = orm.GetEntity(mod, request); if (reslut.IsSuccess) { mod = reslut.ResultModel; } } } ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").ToList(); ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList(); int uid = 0; if (CurrentUser.USERTYPE == 2) { uid = CurrentUser.Id; } ViewBag.dpt = this.DepartmentManage.GetDepartmentByDetailNew(uid); return View(mod); } catch (Exception e) { WriteLog(enumOperator.Select, "加载用户详情发生错误:", e); throw e.InnerException; } } /// /// 保存农机车辆 /// [UserAuthorizeAttribute(ModuleAlias = "salesCarList", OperaAction = "Add,Edit")] public ActionResult Save(Ent_YW_Bicycle entity) { bool isEdit = false; string disid = Request.Form["distributorsid"]; string disname = Request.Form["distributorName"]; //var mod = this.DepartmentManage.Get(p => p.ID == disid); JsonHelper json = new JsonHelper() { Msg = "保存车辆成功", Status = "n", ReUrl = "/Car/Index" }; try { if (entity != null) { var _entity = new Ent_YW_Bicycle(); using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); if (entity.ID.IsNull()) { var count = orm.Queryable().Where(p => p.CarID == entity.CarID).Count(); if (count > 0) { json.Msg = "二维码不能重复绑定!"; } else { var num = orm.Queryable().Where(p => p.carBar == entity.carBar).Count(); if (num > 0) { json.Msg = "条码不能重复绑定!"; } else { _entity = entity; _entity.ID = Guid.NewGuid(); _entity.CreateDate = DateTime.Now; _entity.Createper = CurrentUser.Name; _entity.UpdateDate = DateTime.Now; _entity.UpdateUser = this.CurrentUser.Name; _entity.DistributorsID = disid; _entity.DistributorsName = disname; //_entity.CarSate = 4; _entity.LockState = false; RequestModel res = new RequestModel(); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" }; orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); var reslutsave = orm.Save(_entity, res); if (reslutsave.IsSuccess) { json.Status = "y"; } else { json.Msg = "保存失败"; } } } } else { RequestModel request = new RequestModel(); request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" }; _entity.ID = entity.ID; var reslut = orm.GetEntity(_entity, request); if (reslut.IsSuccess) { _entity = reslut.ResultModel; _entity.CarName = entity.CarName; _entity.FactoryNumber = entity.FactoryNumber; _entity.UpdateDate = DateTime.Now; _entity.UpdateUser = this.CurrentUser.Name; _entity.CarID = entity.CarID; _entity.CarModel = entity.CarModel; _entity.CarSate = entity.CarSate; _entity.LeaseStatus = entity.LeaseStatus; _entity.lang = entity.lang; _entity.DistributorsID = disid; _entity.carType = entity.carType; _entity.DistributorsName = disname; } _entity.LockState = false; RequestModel res = new RequestModel(); res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" }; orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); var reslutsave = orm.Save(_entity, res); if (reslutsave.IsSuccess) { json.Status = "y"; } else { json.Msg = "保存失败"; } } } //判断岗位是否重名 //if (!this.PostManage.IsExist(p => p.POSTNAME == entity.POSTNAME && p.ID != entity.ID)) //{ // if (PostManage.SaveOrUpdate(entity, isEdit)) // { // json.Status = "y"; // } // else // { // json.Msg = "保存失败"; // } //} //else //{ // json.Msg = "岗位" + entity.POSTNAME + "已存在,不能重复添加"; //} } else { json.Msg = "未找到需要保存的车辆信息"; } if (isEdit) { WriteLog(enumOperator.Edit, "修改车辆信息,结果:" + json.Msg, enumLog4net.INFO); } else { WriteLog(enumOperator.Add, "添加车辆信息,结果:" + json.Msg, enumLog4net.INFO); } } catch (Exception e) { json.Msg = "保存车辆信息发生内部错误!"; WriteLog(enumOperator.None, "保存车辆信息:", e); } return Json(json); } /// /// /// /// /// public ActionResult CarAllocateList(string id) { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel request = new RequestModel(); request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" }; var q = orm.Queryable().Where(p => p.carid == id); int pageno = (page - 1) * pagesize; var reslut = q.OrderByDesc(a => a.add_time).Skip(pageno).Top(pagesize).ToList(request); if (reslut.IsSuccess) { reslut.RecordNum = q.Count(); return View(new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel))); } var mod = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(new List())); return View(mod); } } /// /// 绑定页面需要的属性 /// public PageInfo BindList(int posttype, string FK_DPTID, int CarSate) { using (AntORM orm = new AntORM()) { orm.db = DataAccessFactory.CreateDataConnection("CyclingItem"); RequestModel request = new RequestModel(); request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" }; var q = orm.Queryable(); if (!FK_DPTID.IsEmpty()) { var resultdd = orm.Queryable().Where(p => p.ID == FK_DPTID && p.BUSINESSLEVEL == 1).Count(); if (resultdd == 0) { q = q.Where(a => a.DistributorsID == FK_DPTID);//|| a.ScenicID == FK_DPTID } } if (CarSate >= 0) { q = q.Where(a => a.CarSate == CarSate); } if (!string.IsNullOrEmpty(keywords)) { q = q.Where(p => p.CarName.Contains(keywords)); } if (posttype > 0) { q = q.Where(p => p.carType == posttype); } int pageno = (page - 1) * pagesize; var reslut = q.OrderBy(a => a.ID).Skip(pageno).Top(pagesize).ToList(request); //var reslut= orm.SqlQuery(string.Format("select top {0} * from YW_Bicycle where Id>@Id", 1), new { Id = "sfdfdfdf" }).ToList(); if (reslut.IsSuccess) { reslut.RecordNum = q.Count(); List carlist = new List(); foreach (EntYW_Bicycle mod in reslut.ResultModel) { int num = orm.Queryable().Where(p => p.carId == mod.CarID).Count(); if (num > 0) { mod.lang = "已绑定用户"; } else { mod.lang = "未绑定用户"; } carlist.Add(mod); } return new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(carlist)); } else { return new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(new List())); } } //return new PageInfo(result.Index, result.PageSize, result.Count, JsonConverter.JsonClass(list)); } } }