CarController.cs 182 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783
  1. using Ant.Service.Common;
  2. using Ant.Service.Common.Enums;
  3. using Central.Control.Domain;
  4. using MES.Production.Entity;
  5. using MES.Production.Service.IService;
  6. using MES.Production.Service.ServiceImp;
  7. using ChangFa.Machinery.WebPage.Controllers;
  8. using Ant.Data;
  9. using Ant.ORM;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Web;
  14. using System.Web.Mvc;
  15. using MongoDB.Driver.Builders;
  16. using Ant.Service.Mongodb;
  17. using System.Text;
  18. using System.Net;
  19. using Newtonsoft.Json.Linq;
  20. using Newtonsoft.Json;
  21. using Ant.Service.Utility;
  22. using Ant.SuperSocket.Common;
  23. using MES.Production.Entity.Enum;
  24. using System.IO;
  25. using System.Diagnostics;
  26. using System.Data;
  27. using MES.Production.Entity.Entity;
  28. using JsonHelper = Ant.Service.Common.JsonHelper;
  29. using JsonConverter = Ant.Service.Common.JsonConverter;
  30. using WebApiHelp = Ant.Service.Common.WebApiHelp;
  31. using YW_CarParamDetails = Central.Control.Domain.YW_CarParamDetails;
  32. using YW_UserCar = Central.Control.Domain.YW_UserCar;
  33. using YW_CarPurchaser = Central.Control.Domain.YW_CarPurchaser;
  34. namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
  35. {
  36. public class CarController : BaseController
  37. {
  38. /// <summary>
  39. /// 字典编码
  40. /// </summary>
  41. ICodeManage CodeManage = new CodeManage();
  42. /// <summary>
  43. /// 经销商
  44. /// </summary>
  45. IDepartmentManage DepartmentManage = new DepartmentManage();
  46. /// <summary>
  47. /// 加载列表
  48. /// </summary>
  49. /// <returns></returns>
  50. [UserAuthorizeAttribute(ModuleAlias = "carList", OperaAction = "View")]
  51. public ActionResult Index()
  52. {
  53. try
  54. {
  55. #region 处理查询参数
  56. string posttype = Request.QueryString["posttype"];
  57. string FK_DPTID = Request.QueryString["FK_DPTID"];
  58. string CarSate = Request.QueryString["CarSate"];
  59. string carType = Request.QueryString["LeaseStatus"];
  60. int state = -1;
  61. if (!CarSate.IsEmpty())
  62. {
  63. state = CarSate.ToInt32();
  64. }
  65. #endregion
  66. #region 加载列表
  67. var result = BindList(carType.ToInt32(), FK_DPTID, state);
  68. ViewBag.Search = base.keywords;
  69. // ViewData["PostType"] = this.CodeManage.GetCode("POSTTYPE");
  70. //ViewData["post"] = posttype;
  71. ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList();
  72. ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew();
  73. ViewData["dptid"] = FK_DPTID;
  74. ViewData["CarSate"] = CarSate;
  75. ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList();
  76. ViewData["typecar"] = carType;
  77. #endregion
  78. if (result.IsNull())
  79. {
  80. return View();
  81. }
  82. else
  83. {
  84. return View(result);
  85. }
  86. }
  87. catch (Exception e)
  88. {
  89. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  90. throw e.InnerException;
  91. }
  92. }
  93. /// <summary>
  94. /// 导出申请审核数据
  95. /// </summary>
  96. /// <returns></returns>
  97. public FileResult CarReturnOutExcel()
  98. {
  99. try
  100. {
  101. NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
  102. //添加一个sheet
  103. NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
  104. //给sheet1添加第一行的头部标题
  105. NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
  106. row1.CreateCell(0).SetCellValue("农机IMEI号");
  107. row1.CreateCell(1).SetCellValue("农机名称");
  108. row1.CreateCell(2).SetCellValue("农机型号");
  109. row1.CreateCell(3).SetCellValue("车架号");
  110. row1.CreateCell(4).SetCellValue("出厂日期");
  111. row1.CreateCell(5).SetCellValue("出厂编号");
  112. row1.CreateCell(6).SetCellValue("所属经销商");
  113. row1.CreateCell(7).SetCellValue("调拨后经销商");
  114. row1.CreateCell(8).SetCellValue("申请类型");
  115. row1.CreateCell(9).SetCellValue("申请人");
  116. row1.CreateCell(10).SetCellValue("申请时间");
  117. row1.CreateCell(11).SetCellValue("审核状态");
  118. #region 加载列表
  119. List<CarReturnModel> carlist = new List<CarReturnModel>();
  120. using (AntORM orm = new AntORM())
  121. {
  122. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  123. RequestModel res = new RequestModel();
  124. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
  125. var usercarlist = orm.Queryable<yw_machinery_return>()
  126. .InnerJoin<EntYW_Bicycle>((user, city) => user.carid == city.CarID);
  127. var views = usercarlist.Select((strip, sbicycle) => new { Users = sbicycle, trip = strip });
  128. views = views.Where(p => p.Users.CarID != "" && p.trip.state == 1);
  129. var reslut = views.OrderBy(p => p.trip.state).ToList(res);
  130. if (reslut.IsSuccess)
  131. {
  132. int i = 0;
  133. foreach (var list in reslut.ResultModel)
  134. {
  135. yw_machinery_return mod = list.trip; EntYW_Bicycle carmod = list.Users; //Entity.YW_CarPurchaser purchser = list.userpurch;
  136. i++;
  137. NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i);
  138. rowtemp.CreateCell(0).SetCellValue(carmod.CarID);
  139. rowtemp.CreateCell(1).SetCellValue(carmod.CarName);
  140. rowtemp.CreateCell(2).SetCellValue(carmod.CarModel);
  141. rowtemp.CreateCell(3).SetCellValue(carmod.carBar);
  142. rowtemp.CreateCell(4).SetCellValue(carmod.productionDate.ToString());
  143. rowtemp.CreateCell(5).SetCellValue(carmod.FactoryNumber);
  144. rowtemp.CreateCell(6).SetCellValue(carmod.DistributorsName);
  145. rowtemp.CreateCell(7).SetCellValue(mod.distributorsName);
  146. var applytype = "";
  147. if (mod.apply_type == 1)
  148. {
  149. applytype = "退货申请";
  150. }
  151. if (mod.apply_type == 2)
  152. {
  153. applytype = "返厂申请";
  154. }
  155. if (mod.apply_type == 3)
  156. {
  157. applytype = "调拨申请";
  158. }
  159. rowtemp.CreateCell(8).SetCellValue(applytype);
  160. rowtemp.CreateCell(9).SetCellValue(mod.add_name);
  161. rowtemp.CreateCell(10).SetCellValue(mod.add_time.ToString());
  162. var strstate = "";
  163. if (mod.state == 0)
  164. {
  165. strstate = "未审核";
  166. }
  167. if (mod.state == 1)
  168. {
  169. strstate = "已通过";
  170. }
  171. if (mod.state == 2)
  172. {
  173. strstate = "未通过";
  174. }
  175. rowtemp.CreateCell(11).SetCellValue(strstate);
  176. }
  177. }
  178. }
  179. #endregion
  180. // 写入到客户端
  181. System.IO.MemoryStream ms = new System.IO.MemoryStream();
  182. book.Write(ms);
  183. ms.Seek(0, SeekOrigin.Begin);
  184. return File(ms, "application/vnd.ms-excel", "农机申请审核.xls");
  185. }
  186. catch (Exception e)
  187. {
  188. throw e.InnerException;
  189. }
  190. }
  191. /// <summary>
  192. /// 加载列表
  193. /// </summary>
  194. /// <returns></returns>
  195. [UserAuthorizeAttribute(ModuleAlias = "carReturn", OperaAction = "View")]
  196. public ActionResult CarReturnList()
  197. {
  198. try
  199. {
  200. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, Ant.Service.Common.JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
  201. #region 处理查询参数
  202. var posttype = Request.QueryString["PostType"];
  203. string FK_DPTID = Request.QueryString["FK_DPTID"];
  204. int carType = Request.QueryString["LeaseStatus"].ToInt32();
  205. string CarSate = Request.QueryString["CarSate"];
  206. string barcode = Request.QueryString["txt_barcode"];
  207. string imei = Request.QueryString["txt_imei"];
  208. string factoryNumber = Request.QueryString["txt_factoryNumber"];
  209. int state = -1;
  210. if (!CarSate.IsEmpty())
  211. {
  212. state = CarSate.ToInt32();
  213. }
  214. #endregion
  215. #region 加载列表
  216. List<CarReturnModel> carlist = new List<CarReturnModel>();
  217. using (AntORM orm = new AntORM())
  218. {
  219. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  220. RequestModel res = new RequestModel();
  221. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
  222. var usercarlist = orm.Queryable<yw_machinery_return>()
  223. .InnerJoin<EntYW_Bicycle>((user, city) => user.carid == city.CarID);
  224. // .InnerJoin<Entity.YW_CarPurchaser>((user, city, province) => city.CarID == province.carId);
  225. int pageno = (base.page - 1) * base.pagesize;
  226. var views = usercarlist.Select((strip, sbicycle) => new { Users = sbicycle, trip = strip });
  227. if (posttype != "-1" && !posttype.IsEmpty())
  228. {
  229. var type = posttype.ToInt32();
  230. views = views.Where(p => p.trip.apply_type == type);
  231. }
  232. if (state > 0)
  233. {
  234. views = views.Where(p => p.Users.CarSate == state);
  235. }
  236. if (!factoryNumber.IsEmpty())
  237. {
  238. views = views.Where(p => p.Users.FactoryNumber.Contains(factoryNumber));
  239. }
  240. if (!imei.IsEmpty())
  241. {
  242. views = views.Where(p => p.Users.CarID.Contains(imei));
  243. }
  244. views = views.Where(p => p.Users.CarID != "");
  245. var reslut = views.OrderBy(p => p.trip.state).ThenByDesc(p => p.trip.add_time).Skip(pageno).Top(pagesize).ToList(res);
  246. //.Where(p => p.Users.UserId == usermod.userInfo.uid)
  247. if (reslut.IsSuccess)
  248. {
  249. reslut.RecordNum = views.Count();
  250. foreach (var list in reslut.ResultModel)
  251. {
  252. CarReturnModel carReturn = new CarReturnModel();
  253. yw_machinery_return mod = list.trip; EntYW_Bicycle carmod = list.Users; //Entity.YW_CarPurchaser purchser = list.userpurch;
  254. carReturn.bicycle = carmod;
  255. carReturn.carreturn = mod;
  256. carlist.Add(carReturn);
  257. }
  258. pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(carlist));
  259. }
  260. }
  261. ViewBag.Search = base.keywords;
  262. ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList();
  263. ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew();
  264. ViewData["dptid"] = FK_DPTID;
  265. ViewData["CarSate"] = CarSate;
  266. ViewData["PostType"] = posttype;
  267. ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList();
  268. ViewData["typecar"] = carType;
  269. ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList();
  270. //ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").ToList();
  271. ViewData["factoryNumber"] = factoryNumber;
  272. ViewBag.Search = base.keywords;
  273. ViewData["barcode"] = barcode;
  274. ViewData["imei"] = imei;
  275. return View(pageInfo);
  276. #endregion
  277. }
  278. catch (Exception e)
  279. {
  280. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  281. throw e.InnerException;
  282. }
  283. }
  284. /// <summary>
  285. /// 解除电子围栏
  286. /// </summary>
  287. /// <param name="id"></param>
  288. /// <returns></returns>
  289. public ActionResult LiftedCarFence(string idList)
  290. {
  291. Ant.Service.Common.JsonHelper json = new Ant.Service.Common.JsonHelper() { Status = "n", Msg = "解除围栏成功" };
  292. using (AntORM orm = new AntORM())
  293. {
  294. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  295. RequestModel request = new RequestModel
  296. {
  297. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" }
  298. };
  299. string id = idList.Split(';')[0]; string carid = idList.Split(';')[1];
  300. int carstate = CarState.Sales.ToInt32(); Guid guid = new Guid(id);
  301. var reslut = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { CarSate = carstate }, f => f.ID == guid, request);
  302. if (reslut.IsSuccess)
  303. {
  304. json.Status = "y";
  305. WriteLog(enumOperator.Remove, "解除围栏:" + json.Msg, enumLog4net.WARN);
  306. try
  307. {
  308. //SocketClient client = new SocketClient();
  309. //var str = DataHelper.sendRemoveFence(Convert.ToInt64(carid));
  310. //var body = DataHelper.HexToByte(str);
  311. //string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString();
  312. //int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32();
  313. //client.Connect(ip, port);
  314. //var flag = client.SendData(body);
  315. //client.Disconnect();
  316. }
  317. catch (Exception ex)
  318. {
  319. }
  320. }
  321. }
  322. return Json(json);
  323. }
  324. /// <summary>
  325. /// 删除农机
  326. /// </summary>
  327. /// <param name="idList">编码ID字符串</param>
  328. public ActionResult Delete(string idList)
  329. {
  330. Ant.Service.Common.JsonHelper json = new JsonHelper() { Status = "n", Msg = "删除农机成功" };
  331. try
  332. {
  333. //是否为空
  334. if (string.IsNullOrEmpty(idList)) { json.Msg = "未找到要删除的农机"; return Json(json); }
  335. string[] id = idList.Trim(',').Split(',');
  336. for (int i = 0; i < id.Length; i++)
  337. {
  338. var userId = (id[i]);
  339. using (AntORM orm = new AntORM())
  340. {
  341. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  342. RequestModel request = new RequestModel
  343. {
  344. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" },
  345. Oid = userId.ToString()
  346. };
  347. var reslut = orm.DeleteById<EntYW_Bicycle>(request);
  348. if (reslut.IsSuccess)
  349. {
  350. json.Status = "y";
  351. WriteLog(enumOperator.Remove, "删除农机:" + json.Msg, enumLog4net.WARN);
  352. }
  353. }
  354. }
  355. }
  356. catch (Exception e)
  357. {
  358. json.Msg = "删除农机发生内部错误!";
  359. WriteLog(enumOperator.Remove, "删除农机:", e);
  360. }
  361. return Json(json);
  362. }
  363. /// <summary>
  364. /// 加载列表
  365. /// </summary>
  366. /// <returns></returns>
  367. [UserAuthorizeAttribute(ModuleAlias = "carReturn", OperaAction = "View")]
  368. public ActionResult CarReturnFactory()
  369. {
  370. try
  371. {
  372. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
  373. #region 处理查询参数
  374. string posttype = Request.QueryString["posttype"];
  375. string FK_DPTID = Request.QueryString["FK_DPTID"];
  376. string CarSate = Request.QueryString["CarSate"];
  377. int state = -1;
  378. if (!CarSate.IsEmpty())
  379. {
  380. state = CarSate.ToInt32();
  381. }
  382. #endregion
  383. #region 加载列表
  384. List<CarReturnModel> carlist = new List<CarReturnModel>();
  385. using (AntORM orm = new AntORM())
  386. {
  387. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  388. RequestModel res = new RequestModel();
  389. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
  390. var resultList = new ResponseApplyCarList();
  391. resultList.resultList = new List<ResponseApplyCar>();
  392. var usercarlist = orm.Queryable<yw_machinery_return>()
  393. .InnerJoin<EntYW_Bicycle>((user, city) => user.carid == city.CarID)
  394. .InnerJoin<YW_CarPurchaser>((user, city, province) => city.CarID == province.carId);
  395. int pageno = (base.page - 1) * base.pagesize;
  396. 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);
  397. //.Where(p => p.Users.UserId == usermod.userInfo.uid)
  398. if (views.IsSuccess)
  399. {
  400. foreach (var list in views.ResultModel)
  401. {
  402. CarReturnModel carReturn = new CarReturnModel();
  403. yw_machinery_return mod = list.trip; EntYW_Bicycle carmod = list.Users; YW_CarPurchaser purchser = list.userpurch;
  404. carReturn.bicycle = carmod;
  405. carReturn.carreturn = mod;
  406. carlist.Add(carReturn);
  407. }
  408. pageInfo = new PageInfo(base.page, base.pagesize, views.RecordNum, JsonConverter.JsonClass(carlist));
  409. }
  410. }
  411. ViewBag.Search = base.keywords;
  412. ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").ToList();
  413. ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetail();
  414. ViewData["dptid"] = FK_DPTID;
  415. ViewData["CarSate"] = CarSate;
  416. return View(pageInfo);
  417. #endregion
  418. }
  419. catch (Exception e)
  420. {
  421. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  422. throw e.InnerException;
  423. }
  424. }
  425. public ActionResult CarAllocate(string id)
  426. {
  427. ResponseApplyCarInfo userCar = new ResponseApplyCarInfo();
  428. using (AntORM orm = new AntORM())
  429. {
  430. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  431. RequestModel res = new RequestModel();
  432. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
  433. Guid carid = new Guid(id);
  434. var reslut = orm.Queryable<EntYW_Bicycle>().Where(p => p.ID == carid).FirstOrDefault(res);
  435. if (reslut.IsSuccess)
  436. {
  437. EntYW_Bicycle carmod = reslut.ResultModel; //Entity.YW_CarPurchaser purchser = views.ResultModel.userpurch;
  438. userCar.imei = carmod.CarID;
  439. userCar.apply_id = carmod.ID.ToString();
  440. userCar.productBarCode = carmod.carBar;
  441. userCar.productModel = carmod.CarModel;
  442. userCar.productName = carmod.CarName;
  443. userCar.carType = carmod.carType.ToInt32();
  444. userCar.orgDistributorsName = carmod.DistributorsName;
  445. userCar.carState = GetCarState.getCarStateStr(carmod.CarSate.ToInt32());
  446. userCar.FactoryNumber = carmod.FactoryNumber;
  447. userCar.isOnLine = carmod.LeaseStatus.ToInt32();
  448. }
  449. }
  450. int uid = 0;
  451. if (CurrentUser.USERTYPE == 2)
  452. {
  453. uid = CurrentUser.Id;
  454. }
  455. ViewBag.dpt = this.DepartmentManage.GetDepartmentByDetailNew(uid);
  456. return View(userCar);
  457. }
  458. /// <summary>
  459. /// 保存审核结果
  460. /// </summary>
  461. /// <returns></returns>
  462. public ActionResult SaveApplyCheck(string apply_id)
  463. {
  464. JsonHelper json = new JsonHelper() { Msg = "农机申请审核成功", Status = "n", ReUrl = "/Car/DistributorCarList" };
  465. var notes = Request["notes"];
  466. var state = Request["checkstate"];
  467. if (state == "1")
  468. {
  469. using (AntORM orm = new AntORM())
  470. {
  471. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  472. RequestModel res = new RequestModel();
  473. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
  474. Guid guid = new Guid(apply_id);
  475. var reslut = orm.Queryable<yw_machinery_return>().Where(p => p.id == guid).FirstOrDefault(res);
  476. if (reslut.IsSuccess)
  477. {
  478. yw_machinery_return mod = reslut.ResultModel;
  479. if (mod.apply_type == 1)//退货
  480. {
  481. int carstate = CarState.Storage.ToInt32();
  482. var reslutcar = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { CarSate = carstate }, f => f.CarID == mod.carid, res);
  483. {
  484. var reslutapply = orm.UpdateByLambda<yw_machinery_return>(p => new yw_machinery_return { state = 1, check_time = DateTime.Now }, f => f.id == mod.id, res);
  485. if (reslutapply.IsSuccess)
  486. {
  487. json.Status = "y";
  488. json.Msg = "退货审核通过";
  489. }
  490. var usersalereslut = orm.DeleteByLambda<MES.Production.Entity.YW_CarPurchaser>(p => p.imei == mod.carid, res);
  491. if (usersalereslut.IsSuccess)
  492. {
  493. }
  494. var userbindreslut = orm.DeleteByLambda<MES.Production.Entity.YW_UserCar>(p => p.carId == mod.carid, res);
  495. if (userbindreslut.IsSuccess)
  496. {
  497. }
  498. var alarmreslut = orm.DeleteByLambda<YW_AlarmInformation>(p => p.CarId == mod.carid, res);
  499. if (alarmreslut.IsSuccess)
  500. {
  501. }
  502. }
  503. }
  504. if (mod.apply_type == 2)//返厂
  505. {
  506. int carstate = CarState.carBind.ToInt32();
  507. var reslutcar = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { CarSate = carstate, DistributorsID = "", DistributorsName = "" }, f => f.CarID == mod.carid, res);
  508. {
  509. var reslutapply = orm.UpdateByLambda<yw_machinery_return>(p => new yw_machinery_return { state = 1 }, f => f.id == mod.id, res);
  510. if (reslutapply.IsSuccess)
  511. {
  512. json.Status = "y";
  513. json.Msg = "返厂审核通过";
  514. }
  515. var usersalereslut = orm.DeleteByLambda<MES.Production.Entity.YW_CarPurchaser>(p => p.imei == mod.carid, res);
  516. if (usersalereslut.IsSuccess)
  517. {
  518. }
  519. var userbindreslut = orm.DeleteByLambda<MES.Production.Entity.YW_UserCar>(p => p.carId == mod.carid, res);
  520. if (userbindreslut.IsSuccess)
  521. {
  522. }
  523. var alarmreslut = orm.DeleteByLambda<YW_AlarmInformation>(p => p.CarId == mod.carid, res);
  524. if (alarmreslut.IsSuccess)
  525. {
  526. }
  527. }
  528. }
  529. if (mod.apply_type == 3)//调拨
  530. {
  531. int carstate = CarState.OutStock.ToInt32();
  532. var reslutcar = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { CarSate = carstate, DistributorsID = mod.distributorsID, DistributorsName = mod.distributorsName }, f => f.CarID == mod.carid, res);
  533. {
  534. var reslutapply = orm.UpdateByLambda<yw_machinery_return>(p => new yw_machinery_return { state = 1 }, f => f.id == mod.id, res);
  535. if (reslutapply.IsSuccess)
  536. {
  537. json.Status = "y";
  538. json.Msg = "调拨审核通过";
  539. }
  540. var usersalereslut = orm.DeleteByLambda<MES.Production.Entity.YW_CarPurchaser>(p => p.imei == mod.carid, res);
  541. if (usersalereslut.IsSuccess)
  542. {
  543. }
  544. var userbindreslut = orm.DeleteByLambda<MES.Production.Entity.YW_UserCar>(p => p.carId == mod.carid, res);
  545. if (userbindreslut.IsSuccess)
  546. {
  547. }
  548. var alarmreslut = orm.DeleteByLambda<YW_AlarmInformation>(p => p.CarId == mod.carid, res);
  549. if (alarmreslut.IsSuccess)
  550. {
  551. }
  552. }
  553. }
  554. if (mod.apply_type == 4)
  555. {
  556. //var str = DataHelper.sendLockHexStr(Convert.ToInt64(mod.carid.Trim()));
  557. //var body = DataHelper.HexToByte(str);
  558. //SocketClient client = new SocketClient();
  559. //try
  560. //{
  561. // string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString();
  562. // int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32();
  563. // client.Connect(ip, port);
  564. // var flag = client.SendData(body);
  565. // var reslutlock = orm.UpdateByLambda<YW_Apply_CarLock>(p => new YW_Apply_CarLock { state = 2 }, f => f.carid == mod.carid && f.state == 0, res);
  566. // if (reslutlock.IsSuccess)
  567. // {
  568. // }
  569. // var reslutapply = orm.UpdateByLambda<yw_machinery_return>(p => new yw_machinery_return { state = 1 }, f => f.id == mod.id, res);
  570. // if (reslutapply.IsSuccess)
  571. // {
  572. // json.Status = "y";
  573. // json.Msg = "审核通过";
  574. // }
  575. // client.Disconnect();
  576. //}
  577. //catch (Exception ex)
  578. //{
  579. //}
  580. }
  581. if (mod.apply_type == 5)
  582. {
  583. //var str = DataHelper.sendUnLockHexStr(Convert.ToInt64(mod.carid.Trim()));
  584. //var body = DataHelper.HexToByte(str);
  585. //SocketClient client = new SocketClient();
  586. //try
  587. //{
  588. // string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString();
  589. // int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32();
  590. // client.Connect(ip, port);
  591. // var flag = client.SendData(body);
  592. // var reslutlock = orm.UpdateByLambda<YW_Apply_CarLock>(p => new YW_Apply_CarLock { state = 2 }, f => f.carid == mod.carid && f.state == 0, res);
  593. // if (reslutlock.IsSuccess)
  594. // {
  595. // }
  596. // var reslutapply = orm.UpdateByLambda<yw_machinery_return>(p => new yw_machinery_return { state = 1 }, f => f.id == mod.id, res);
  597. // if (reslutapply.IsSuccess)
  598. // {
  599. // json.Status = "y";
  600. // json.Msg = "审核通过";
  601. // }
  602. // client.Disconnect();
  603. //}
  604. //catch (Exception ex)
  605. //{
  606. //}
  607. }
  608. }
  609. }
  610. }
  611. else
  612. {
  613. using (AntORM orm = new AntORM())
  614. {
  615. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  616. RequestModel res = new RequestModel();
  617. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
  618. Guid guid = new Guid(apply_id);
  619. var reslutapply = orm.UpdateByLambda<yw_machinery_return>(p => new yw_machinery_return { state = 2, noPassNote = notes }, f => f.id == guid, res);
  620. if (reslutapply.IsSuccess)
  621. {
  622. var reslutmod = orm.Queryable<yw_machinery_return>().Where(p => p.id == guid).FirstOrDefault(res);
  623. if (reslutmod.IsSuccess)
  624. {
  625. yw_machinery_return mod = reslutmod.ResultModel;
  626. orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { CarSate = mod.carState }, f => f.CarID == mod.carid, res);
  627. json.Status = "n";
  628. json.Msg = "审核不通过";
  629. }
  630. }
  631. }
  632. }
  633. return Json(json);
  634. }
  635. /// <summary>
  636. /// 保存调拨数据
  637. /// </summary>
  638. /// <param name="info"></param>
  639. /// <returns></returns>
  640. public ActionResult SaveCarAllocate(ResponseApplyCarInfo info)
  641. {
  642. JsonHelper json = new JsonHelper() { Msg = "农机申请成功", Status = "n", ReUrl = "/Car/DistributorCarList" };
  643. var applytype = Request["apply_type"].ToInt32();
  644. using (AntORM orm = new AntORM())
  645. {
  646. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  647. RequestModel res = new RequestModel();
  648. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
  649. Guid carid = new Guid(info.apply_id);
  650. var reslut = orm.Queryable<EntYW_Bicycle>().Where(p => p.ID == carid).FirstOrDefault(res);
  651. if (reslut.IsSuccess)
  652. {
  653. EntYW_Bicycle carmod = reslut.ResultModel;
  654. if (carmod.CarSate > 40 && applytype == 3)
  655. {
  656. json.Msg = "已销售无法做调拨!";
  657. return Json(json);
  658. }
  659. if (applytype == 4)//锁车
  660. {
  661. if (carmod.LockState.ToBool())
  662. {
  663. json.Msg = "已锁车,不能重复申请锁车操作!";
  664. return Json(json);
  665. }
  666. var count = orm.Queryable<yw_machinery_return>().Where(p => p.carid == carmod.CarID && p.state == 0).Count();
  667. if (count > 0)
  668. {
  669. json.Msg = "已申请锁车,不能重复申请锁车,等待审核!";
  670. return Json(json);
  671. }
  672. }
  673. if (applytype == 5)//解锁
  674. {
  675. if (!carmod.LockState.ToBool())
  676. {
  677. json.Msg = "已解锁,不能重复申请!";
  678. return Json(json);
  679. }
  680. var count = orm.Queryable<yw_machinery_return>().Where(p => p.carid == carmod.CarID && p.state == 0).Count();
  681. if (count > 0)
  682. {
  683. json.Msg = "已申请解锁,不能重复申请解锁,等待审核!";
  684. return Json(json);
  685. }
  686. }
  687. SYS_USER usermod = new SYS_USER();
  688. EntSYS_DISTRIBUTORS dis = new EntSYS_DISTRIBUTORS();
  689. //var qq = orm.Queryable<EntSYS_DISTRIBUTORS>().LeftJoin<SYS_USER>((diss, us) => diss.ID == us.DPTID);
  690. //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);
  691. //if (views.IsSuccess)
  692. //{
  693. // dis = views.ResultModel.DisName; usermod = views.ResultModel.UserInfo;
  694. //}
  695. yw_machinery_return mod = new yw_machinery_return();
  696. mod.id = Guid.NewGuid();
  697. mod.carid = carmod.CarID;
  698. mod.note = Request["notes"];//申请原因
  699. if (applytype == 0)
  700. {
  701. json.Msg = "申请类型不能为空!";
  702. return Json(json);
  703. }
  704. if (applytype == 1)//退货
  705. {
  706. }
  707. if (applytype == 2)//返厂
  708. {
  709. }
  710. if (applytype == 3)//调拨
  711. {
  712. var str = string.Empty;
  713. if (info.note == "10")
  714. {
  715. str = "一级商到一级商(有调拨手续)";
  716. }
  717. if (info.note == "20")
  718. {
  719. str = "一级商到一级商(无调拨手续)";
  720. }
  721. if (info.note == "30")
  722. {
  723. str = "一级经销商内部调拨";
  724. }
  725. if (info.note == "40")
  726. {
  727. str = "其它";
  728. }
  729. if (str.IsEmpty())
  730. {
  731. json.Msg = "调拨申请调拨原因不能为空!";
  732. return Json(json);
  733. }
  734. if (info.distributorsId.IsEmpty())
  735. {
  736. json.Msg = "调拨申请经销商不能为空!选择调拨经销商!";
  737. return Json(json);
  738. }
  739. var qq = orm.Queryable<EntSYS_DISTRIBUTORS>().Where(p => p.ID == info.distributorsId).FirstOrDefault(res);
  740. dis = qq.ResultModel;
  741. mod.reason = str;
  742. mod.distributorsID = info.distributorsId;
  743. mod.distributorsName = dis.NAME;
  744. mod.distributorsContact = dis.BUSINESSLEVEL.ToString();
  745. }
  746. mod.distributorsContact = usermod.NAME;
  747. mod.distributorsTel = usermod.PHONE;
  748. mod.carState = mod.carState;
  749. mod.apply_type = Request["apply_type"].ToInt32();
  750. mod.orgDistributorsID = carmod.DistributorsID;
  751. mod.orgDistributorsName = carmod.DistributorsName;
  752. mod.add_name = CurrentUser.Name;
  753. mod.add_time = DateTime.Now;
  754. mod.userId = CurrentUser.Id.ToString();
  755. var reslutmachinery = orm.Save(mod, res);
  756. if (reslutmachinery.IsSuccess)
  757. {
  758. json.Status = "y";
  759. //var reslutcar = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { DistributorsID = info.distributorsId, DistributorsName = dis.NAME }, f => f.CarID == mod.carid, res);
  760. //if (reslutcar.IsSuccess)
  761. //{
  762. // json.Status = "y";
  763. //}
  764. //else
  765. //{
  766. // json.Msg = "保存失败"; ;
  767. //}
  768. }
  769. else
  770. {
  771. json.Msg = "保存失败";
  772. }
  773. }
  774. }
  775. return Json(json);
  776. }
  777. /// <summary>
  778. /// 车辆调拨
  779. /// </summary>
  780. /// <returns></returns>
  781. public ActionResult CarAllocation(string id)
  782. {
  783. ResponseApplyCarInfo userCar = new ResponseApplyCarInfo();
  784. try
  785. {
  786. using (AntORM orm = new AntORM())
  787. {
  788. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  789. RequestModel res = new RequestModel();
  790. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
  791. var usercarlist = orm.Queryable<yw_machinery_return>()
  792. .InnerJoin<EntYW_Bicycle>((user, city) => user.carid == city.CarID);
  793. //.InnerJoin<Entity.YW_CarPurchaser>((user, city, province) => city.CarID == province.carId);
  794. Guid guid = new Guid(id);
  795. //var views = usercarlist.Select((strip, sbicycle, purchser) => new { Users = sbicycle, trip = strip, userpurch = purchser }).Where(p => p.trip.id == guid).FirstOrDefault(res);
  796. var views = usercarlist.Select((strip, sbicycle) => new { Users = sbicycle, trip = strip }).Where(p => p.trip.id == guid).FirstOrDefault(res);
  797. //.Where(p => p.Users.UserId == usermod.userInfo.uid)
  798. if (views.IsSuccess)
  799. {
  800. yw_machinery_return mod = views.ResultModel.trip; EntYW_Bicycle carmod = views.ResultModel.Users; //Entity.YW_CarPurchaser purchser = views.ResultModel.userpurch;
  801. userCar.imei = carmod.CarID;
  802. userCar.productBarCode = carmod.carBar;
  803. userCar.productModel = carmod.CarModel;
  804. userCar.productName = carmod.CarName;
  805. userCar.FactoryNumber = carmod.FactoryNumber;
  806. userCar.apply_type = mod.apply_type.ToString();
  807. userCar.apply_state = mod.state.ToString();
  808. userCar.carType = carmod.carType.ToInt32();
  809. userCar.orgDistributorsID = mod.orgDistributorsID;
  810. userCar.orgDistributorsName = mod.orgDistributorsName;
  811. var purrchreslut = orm.Queryable<MES.Production.Entity.YW_CarPurchaser>().Where(p => p.carId == carmod.CarID).FirstOrDefault(res);
  812. if (purrchreslut.IsSuccess)
  813. {
  814. MES.Production.Entity.YW_CarPurchaser purchser = purrchreslut.ResultModel;
  815. userCar.name = purchser.userName;
  816. userCar.tel = purchser.userTel;
  817. userCar.saleDate = purchser.addDate.ToDateTime();
  818. }
  819. userCar.note = mod.note;
  820. userCar.reason = mod.reason;
  821. userCar.applyName = mod.add_name;
  822. userCar.apply_id = mod.id.ToString();
  823. userCar.carState = GetCarState.getCarStateStr(carmod.CarSate.ToInt32());
  824. userCar.isOnLine = carmod.LeaseStatus.ToInt32();
  825. if (mod.apply_type == 3)
  826. {
  827. var distributorsreslut = orm.Queryable<EntSYS_DISTRIBUTORS>().Where(p => p.ID == mod.distributorsID).FirstOrDefault(res);
  828. if (distributorsreslut.IsSuccess)
  829. {
  830. EntSYS_DISTRIBUTORS dismod = distributorsreslut.ResultModel;
  831. userCar.distributorsAddress = dismod.Address;
  832. userCar.distributorsName = dismod.NAME;
  833. userCar.distributorsContact = "";
  834. userCar.distributorsTel = "";
  835. }
  836. }
  837. //userCar.productionDate = DateTimeUtility.ConvertDateTimeInt(carmod.productionDate.ToDateTime());
  838. }
  839. }
  840. return View(userCar);
  841. }
  842. catch (Exception e)
  843. {
  844. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  845. throw e.InnerException;
  846. }
  847. }
  848. /// <returns></returns>
  849. public ActionResult atouCarMapList()
  850. {
  851. ViewData["provincecode"] = Request["provincecode"];
  852. ViewData["strprovince"] = Request["strprovince"];
  853. ViewData["strcode"] = Request["strcode"];
  854. ViewData["strname"] = Request["strname"];
  855. return View();
  856. }
  857. /// <summary>
  858. ///
  859. /// </summary>
  860. /// <returns></returns>
  861. [UserAuthorizeAttribute(ModuleAlias = "mapList", OperaAction = "View")]
  862. public ActionResult mapList()
  863. {
  864. ViewData["provincecode"] = Request["provincecode"];
  865. ViewData["strprovince"] = Request["strprovince"];
  866. ViewData["strcode"] = Request["strcode"];
  867. ViewData["strname"] = Request["strname"];
  868. return View();
  869. }
  870. public ActionResult CarParamList(string id)
  871. {
  872. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
  873. using (AntORM orm = new AntORM())
  874. {
  875. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  876. RequestModel res = new RequestModel
  877. {
  878. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取车辆信息" }
  879. };
  880. var q = orm.Queryable<MES.Production.Entity.YW_CarParamDetails>();
  881. if (id.IsEmpty())
  882. {
  883. return View(pageInfo);
  884. }
  885. q = q.Where(p => p.imei == id);
  886. int pageno = (page - 1) * pagesize;
  887. var tripreslut = q.OrderByDesc(p => p.add_time).Skip(pageno).Top(pagesize).ToList(res);
  888. if (tripreslut.IsSuccess)
  889. {
  890. tripreslut.RecordNum = q.Count();
  891. pageInfo = new PageInfo(base.page, base.pagesize, tripreslut.RecordNum, JsonConverter.JsonClass(tripreslut.ResultModel));
  892. }
  893. }
  894. return View(pageInfo);
  895. }
  896. [UserAuthorizeAttribute(ModuleAlias = "machineryList", OperaAction = "List")]
  897. public ActionResult CarTripList(string id)
  898. {
  899. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0,JsonConverter.JsonClass(new List<Ent_YW_CarTrip>()));
  900. var startdate = Request.Params["startdate"]; var enddate = Request.Params["enddate"];
  901. using (AntORM orm = new AntORM())
  902. {
  903. int pageno = (page - 1) * pagesize;
  904. StringBuilder strsql = new StringBuilder();
  905. 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);
  906. 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],");
  907. 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);
  908. if (!startdate.IsEmpty() && enddate.IsEmpty())
  909. {
  910. var fromdate = startdate.ToDateTime();
  911. strsql.AppendFormat("[YW_CarTrip].[StartDate]={0}", fromdate);
  912. }
  913. if (!enddate.IsEmpty() && startdate.IsEmpty())
  914. {
  915. var todate = enddate.ToDateTime();
  916. strsql.AppendFormat("[YW_CarTrip].[StartDate]={0}", todate);
  917. }
  918. if (!startdate.IsEmpty() && !enddate.IsEmpty())
  919. {
  920. var fromdate = startdate.ToDateTime();
  921. var todate = enddate.ToDateTime();
  922. strsql.AppendFormat(" and ([YW_CarTrip].[StartDate]>'{0}' and [YW_CarTrip].[StartDate]<'{1}') ", fromdate, todate);
  923. }
  924. strsql.AppendFormat(") AS[T] WHERE [T].num > {0} order by num asc", pageno);
  925. RequestItemSqlModel requestItemSql = new RequestItemSqlModel();
  926. requestItemSql.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取农机行程列表" };
  927. requestItemSql.db = DataAccessFactory.CreateDataConnection("CyclingItemLog");
  928. requestItemSql.StrSql = strsql.ToString();
  929. var tripreslut = orm.GetDataTableList(requestItemSql);
  930. if (tripreslut.IsSuccess)
  931. {
  932. DataTable dtt = tripreslut.DataTable;
  933. tripreslut.RecordNum = dtt.Rows[0]["total"].ToInt32();
  934. var jsondata = JsonConverter.ConvertJson(JsonConverter.ToJson(dtt));
  935. pageInfo = new PageInfo(base.page, base.pagesize, tripreslut.RecordNum, jsondata);
  936. }
  937. }
  938. ViewData["startdate"] = startdate;
  939. ViewData["enddate"] = enddate;
  940. ViewData["imei"] = id;
  941. return View(pageInfo);
  942. }
  943. /// <summary>
  944. /// 生成定位信息JSON文件
  945. /// </summary>
  946. /// <returns></returns>
  947. [HttpGet]
  948. public JsonResult salesMakeMapJsonFile()
  949. {
  950. string lat = ""; string lng = ""; string onlinetime = "";
  951. using (AntORM orm = new AntORM())
  952. {
  953. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  954. RequestModel res = new RequestModel
  955. {
  956. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取车辆信息" }
  957. };
  958. var carreslut = orm.Queryable<EntYW_Bicycle>().Where(p => p.CarSate == 1).ToList(res);
  959. if (carreslut.IsSuccess)
  960. {
  961. List<CarGPSModel> carlist = new List<CarGPSModel>();
  962. foreach (EntYW_Bicycle mod in carreslut.ResultModel)
  963. {
  964. CarGPSModel car = new CarGPSModel();
  965. car.imei = mod.CarID;
  966. car.barCode = mod.carBar;
  967. var reslut = orm.Queryable<YW_CarHeartbeat>().Where(p => p.imei == mod.CarID && p.locationtype == 2).OrderByDesc(p => p.add_time).FirstOrDefault(res);
  968. if (reslut.IsSuccess)
  969. {
  970. YW_CarHeartbeat beatenty = reslut.ResultModel;
  971. var carTrack = new ResponseCarTrack();
  972. if (beatenty.locationtype == 2)
  973. {
  974. var GPS = Ant.SuperSocket.Common.ToolGPSamap.GPSToGDGPS(beatenty.lng.ToDou(), beatenty.lat.ToDou());
  975. lat = GPS.Split(',')[1];
  976. lng = GPS.Split(',')[0];
  977. car.onlineTime = beatenty.add_time.ToDateTime().ToString("yyyy-MM-dd hh:mm:ss");
  978. car.postType = "GPS位置";
  979. //enty.isOnline = (mod.LeaseStatus == 1);
  980. }
  981. else
  982. {
  983. var lbsreslut = orm.Queryable<YW_CarHeartbeat>().Where(p => p.imei == mod.CarID && p.locationtype == 1).OrderByDesc(p => p.add_time).FirstOrDefault(res);
  984. if (lbsreslut.IsSuccess)
  985. {
  986. YW_CarHeartbeat lbsmod = lbsreslut.ResultModel;
  987. if (lbsmod.mcc > 0)
  988. {
  989. var gps = WebApiHelp.getLocationGPS("", lbsmod.mcc.ToInt32(), lbsmod.mnc.ToInt32(), lbsmod.lac.ToInt32(), lbsmod.cellID.ToInt32(), lbsmod.rssi.ToInt32());
  990. lbsmod.lng = gps.result.location.Split(',')[0].ToDec();
  991. lbsmod.lat = gps.result.location.Split(',')[1].ToDec();
  992. var GPS = Ant.SuperSocket.Common.ToolGPSamap.GPSToGDGPS(lbsmod.lng.ToDou(), lbsmod.lat.ToDou());
  993. lat = GPS.Split(',')[1];
  994. lng = GPS.Split(',')[0];
  995. car.onlineTime = lbsmod.add_time.ToDateTime().ToString("yyyy-MM-dd hh:mm:ss");
  996. car.postType = "LBS位置";
  997. //enty.isOnline = (mod.LeaseStatus == 1);
  998. }
  999. }
  1000. }
  1001. }
  1002. car.id = mod.ID.ToString();
  1003. car.pic = "http://localhost:7907/upload/20170705135420_87460.jpg";
  1004. car.name = mod.CarName + "(" + mod.CarModel + ")";
  1005. car.latitude = lat;
  1006. car.longitude = lng;
  1007. car.online = (mod.LeaseStatus == 1) ? "在线" : "不在线";
  1008. //car.voltage = "14.095 V";
  1009. //car.hydraulic = "368 KPa";
  1010. //car.temperature = "40 ℃";
  1011. //car.speed = "849 转";
  1012. string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString();
  1013. MongoDbHelper mh = new MongoDbHelper(ip, "1000");
  1014. var query = Query.And(Query.EQ("carId", mod.CarID), MongoDB.Driver.Builders.Query.EQ("carReslut", 1));
  1015. string[] order = new string[] { "operatDate" };
  1016. var modstate = mh.FindOneToIndexMax<UserCarParamInfos>(query, order);
  1017. if (modstate.IfNotNull())
  1018. {
  1019. car.hydraulic = modstate.hydraulic + " KPa";
  1020. car.speed = modstate.speed + " 转";
  1021. car.temperature = modstate.temperature + " ℃";
  1022. car.voltage = modstate.voltage + " mV";
  1023. }
  1024. else
  1025. {
  1026. car.hydraulic = "0 KPa";
  1027. car.temperature = "0 ℃";
  1028. car.speed = "0 转";
  1029. car.voltage = "0 V";
  1030. }
  1031. car.address = ToolGPSamap.GPSToPositionString(car.longitude.ToDou(), car.latitude.ToDou());
  1032. carlist.Add(car);
  1033. }
  1034. //var strjs = Newtonsoft.Json.JsonConvert.SerializeObject(carlist);
  1035. //string localPath = Path.Combine(HttpRuntime.AppDomainAppPath, "Upload\\hotfix\\test.json");
  1036. //FileOperate.FileDel(localPath);
  1037. //FileOperate.WriteFile(localPath, strjs);
  1038. return Json(carlist, JsonRequestBehavior.AllowGet);
  1039. }
  1040. }
  1041. return null;
  1042. }
  1043. /// <summary>
  1044. /// 获取自动驾驶农机
  1045. /// </summary>
  1046. /// <returns></returns>
  1047. [HttpGet]
  1048. public JsonResult AtouCarMapJsonFile()
  1049. {
  1050. List<CarGPSModel> carlist = new List<CarGPSModel>();
  1051. using (AntORM orm = new AntORM())
  1052. {
  1053. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1054. RequestModel res = new RequestModel
  1055. {
  1056. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取车辆信息" }
  1057. };
  1058. var reslut = orm.Queryable<YW_AntoCarList>().ToList(res);
  1059. if (reslut.IsSuccess)
  1060. {
  1061. foreach (YW_AntoCarList antoCarList in reslut.ResultModel)
  1062. {
  1063. CarGPSModel carGPS = new CarGPSModel();
  1064. carGPS.address = antoCarList.Address;
  1065. carGPS.imei = antoCarList.CarID;
  1066. carGPS.name = "自动驾驶农机";
  1067. carGPS.latitude = antoCarList.latitude.ToString();
  1068. carGPS.longitude = antoCarList.longitude.ToString();
  1069. carGPS.voltage = antoCarList.voltage;
  1070. carGPS.temperature = antoCarList.temperature;
  1071. carGPS.speed = antoCarList.speed;
  1072. carGPS.online = "在线";
  1073. carGPS.onlineTime = antoCarList.add_time.ToString();
  1074. carGPS.pic = "";
  1075. carGPS.barCode = "";
  1076. carGPS.id = antoCarList.ID.ToString();
  1077. carGPS.workingHours = "";
  1078. carlist.Add(carGPS);
  1079. }
  1080. }
  1081. }
  1082. return Json(carlist, JsonRequestBehavior.AllowGet);
  1083. }
  1084. /// <summary>
  1085. /// 生成定位信息JSON文件
  1086. /// </summary>
  1087. /// <returns></returns>
  1088. [HttpGet]
  1089. public JsonResult makeMapJsonFile(string strcode, string strname)
  1090. {
  1091. string lat = ""; string lng = ""; string onlinetime = "";
  1092. ViewData["provincecode"] = Request["provincecode"];
  1093. ViewData["strprovince"] = Request["strprovince"];
  1094. using (AntORM orm = new AntORM())
  1095. {
  1096. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1097. RequestModel res = new RequestModel
  1098. {
  1099. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取车辆信息" }
  1100. };
  1101. var q = orm.Queryable<EntYW_Bicycle>();
  1102. if (CurrentUser.USERTYPE == 3)//销售员
  1103. {
  1104. int saleid = CurrentUser.Id;
  1105. var qq = orm.Queryable<SYS_DISTRIBUTORS>().LeftJoin<YW_UserDistributor>((city, province) => city.ID == province.distributorId).RightJoin<EntYW_Bicycle>((dis, udis, car) => udis.distributorId == car.DistributorsID);
  1106. 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);
  1107. if (views.IsSuccess)
  1108. {
  1109. var listdis = views.ResultModel;
  1110. List<CarGPSModel> carlist = new List<CarGPSModel>();
  1111. //List<string> Names = new List<string>();
  1112. foreach (var enty in listdis)
  1113. {
  1114. EntYW_Bicycle mod = enty.Car;
  1115. CarGPSModel car = new CarGPSModel();
  1116. car.imei = mod.CarID;
  1117. car.barCode = mod.carBar;
  1118. string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString();
  1119. MongoDbHelper mh = new MongoDbHelper(ip, "1000");
  1120. var query = Query.And(Query.EQ("imei", mod.CarID));
  1121. var modgps = mh.FindOne<userLatestLocation>(query);
  1122. if (modgps.IfNotNull())
  1123. {
  1124. var GPS = Ant.SuperSocket.Common.ToolGPSamap.GPSToGDGPS(modgps.lng.ToDou(), modgps.lat.ToDou());
  1125. lat = GPS.Split(',')[1];
  1126. lng = GPS.Split(',')[0];
  1127. car.onlineTime = modgps.add_time.ToDateTime().ToString("yyyy-MM-dd HH:mm:ss");
  1128. car.postType = "GPS位置";
  1129. }
  1130. else
  1131. {
  1132. var reslut = orm.Queryable<DeviceManage>().Where(p => p.IMEI == mod.CarID).FirstOrDefault(res);
  1133. if (reslut.IsSuccess)
  1134. {
  1135. DeviceManage beatenty = reslut.ResultModel;
  1136. lat = beatenty.latitude.ToString();
  1137. lng = beatenty.longitude.ToString();
  1138. }
  1139. }
  1140. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1141. string sql = "SELECT CAST(SUM(WorkingHours) AS INT) AS [C] FROM YW_CarTrip where imei='" + mod.CarID + "'";
  1142. var sum = orm.db.ExecuteScalar(sql);
  1143. string workhours = DateTimeUtility.MinuteToHour(sum.ToDou());
  1144. car.workingHours = workhours;
  1145. car.id = mod.ID.ToString();
  1146. string url = Request.Url.ToString(); string parm = Request.RawUrl;
  1147. url = url.Replace(parm, "");
  1148. car.pic = url + "/upload/20170705135420_87460.jpg";
  1149. car.name = mod.CarName + "(" + mod.CarModel + ")";
  1150. car.latitude = lat;
  1151. car.longitude = lng;
  1152. car.online = (mod.LeaseStatus == 1) ? "在线" : "不在线";
  1153. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1154. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  1155. var reslutcar = orm.Queryable<YW_CarParamDetails>().Where(p => p.imei == mod.CarID).FirstOrDefault(res);
  1156. if (reslutcar.IsSuccess)
  1157. {
  1158. YW_CarParamDetails locatmod = reslutcar.ResultModel;
  1159. car.hydraulic = locatmod.hydraulic + " KPa";
  1160. car.speed = locatmod.speed + " 转";
  1161. car.temperature = locatmod.temperature + " ℃";
  1162. var v = (locatmod.voltage.ToDou()).ToString("0.00");
  1163. car.voltage = v + " V";
  1164. }
  1165. else
  1166. {
  1167. orm.db = DataAccessFactory.CreateDataConnection("CyclingItemLog");
  1168. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  1169. var reslutparm = orm.Queryable<YW_CarParamDetails>().Where(p => p.imei == mod.CarID).FirstOrDefault(res);
  1170. if (reslutparm.IsSuccess)
  1171. {
  1172. YW_CarParamDetails locatmod = reslutparm.ResultModel;
  1173. car.hydraulic = locatmod.hydraulic + " KPa";
  1174. car.speed = locatmod.speed + " 转";
  1175. car.temperature = locatmod.temperature + " ℃";
  1176. var v = (locatmod.voltage.ToDou()).ToString("0.00");
  1177. car.voltage = v + " V";
  1178. }
  1179. else
  1180. {
  1181. car.hydraulic = "0 KPa";
  1182. car.temperature = "0 ℃";
  1183. car.speed = "0 转";
  1184. car.voltage = "0 V";
  1185. }
  1186. }
  1187. car.address = ToolGPSamap.GPSToPositionString(car.longitude.ToDou(), car.latitude.ToDou());
  1188. carlist.Add(car);
  1189. }
  1190. carlist = carlist.OrderBy(p => p.onlineTime).ToList();
  1191. return Json(carlist, JsonRequestBehavior.AllowGet);
  1192. }
  1193. }
  1194. else
  1195. {
  1196. List<CarGPSModel> carlist = new List<CarGPSModel>();
  1197. var qq = orm.Queryable<EntYW_Bicycle>().LeftJoin<DeviceManage>((city, province) => city.CarID == province.IMEI);
  1198. var views = qq.Select((car, device) => new { Device = device, Car = car }).OrderByDesc(p => p.Car.ID).Where(p => p.Device.City == strname).ToList(res);
  1199. if (views.IsSuccess)
  1200. {
  1201. foreach (var enty in views.ResultModel)
  1202. {
  1203. EntYW_Bicycle mod = enty.Car;
  1204. CarGPSModel car = new CarGPSModel();
  1205. car.imei = mod.CarID;
  1206. car.barCode = mod.carBar;
  1207. //string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString();
  1208. //MongoDbHelper mh = new MongoDbHelper(ip, "1000");
  1209. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1210. var reslut = orm.Queryable<DeviceManage>().Where(p => p.IMEI == mod.CarID).FirstOrDefault(res);
  1211. if (reslut.IsSuccess)
  1212. {
  1213. DeviceManage beatenty = reslut.ResultModel;
  1214. lat = beatenty.latitude.ToString();
  1215. lng = beatenty.longitude.ToString();
  1216. car.onlineTime = beatenty.LastOnlineTime.ToDateTime().ToString("yyyy-MM-dd hh:mm:ss");
  1217. }
  1218. string sql = "SELECT CAST(SUM(WorkingHours) AS INT) AS [C] FROM YW_CarTrip where imei='" + mod.CarID + "'";
  1219. var sum = orm.db.ExecuteScalar(sql);
  1220. string workhours = DateTimeUtility.MinuteToHour(sum.ToDou());
  1221. car.workingHours = workhours;
  1222. car.id = mod.ID.ToString();
  1223. car.pic = "http://localhost:7907/upload/20170705135420_87460.jpg";
  1224. car.name = mod.CarName + "(" + mod.CarModel + ")";
  1225. car.latitude = lat;
  1226. car.longitude = lng;
  1227. car.online = (mod.LeaseStatus == 1) ? "在线" : "不在线";
  1228. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1229. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  1230. var reslutcar = orm.Queryable<YW_CarParamDetails>().Where(p => p.imei == mod.CarID).FirstOrDefault(res);
  1231. if (reslutcar.IsSuccess)
  1232. {
  1233. YW_CarParamDetails locatmod = reslutcar.ResultModel;
  1234. car.hydraulic = locatmod.hydraulic + " KPa";
  1235. car.speed = locatmod.speed + " 转";
  1236. car.temperature = locatmod.temperature + " ℃";
  1237. var v = (locatmod.voltage.ToDou()).ToString("0.00");
  1238. car.voltage = v + " V";
  1239. }
  1240. else
  1241. {
  1242. orm.db = DataAccessFactory.CreateDataConnection("CyclingItemLog");
  1243. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  1244. var reslutparm = orm.Queryable<YW_CarParamDetails>().Where(p => p.imei == mod.CarID).FirstOrDefault(res);
  1245. if (reslutparm.IsSuccess)
  1246. {
  1247. YW_CarParamDetails locatmod = reslutparm.ResultModel;
  1248. car.hydraulic = locatmod.hydraulic + " KPa";
  1249. car.speed = locatmod.speed + " 转";
  1250. car.temperature = locatmod.temperature + " ℃";
  1251. var v = (locatmod.voltage.ToDou()).ToString("0.00");
  1252. car.voltage = v + " V";
  1253. }
  1254. else
  1255. {
  1256. car.hydraulic = "0 KPa";
  1257. car.temperature = "0 ℃";
  1258. car.speed = "0 转";
  1259. car.voltage = "0 V";
  1260. }
  1261. }
  1262. //var querywhere = MongoDB.Driver.Builders.Query<userNewCarECUInfos>.Where(xx => xx.carId == mod.CarID);
  1263. //var locatmod = mh.FindOne<userNewCarECUInfos>(querywhere);
  1264. //if (locatmod.IfNotNull())
  1265. //{
  1266. // car.hydraulic = locatmod.hydraulic + " KPa";
  1267. // car.speed = locatmod.speed + " 转";
  1268. // car.temperature = locatmod.temperature + " ℃";
  1269. // var v = (locatmod.voltage.ToDou() / 1000).ToString("0.00");
  1270. // car.voltage = v + " V";
  1271. //}
  1272. //else
  1273. //{
  1274. // car.hydraulic = "0 KPa";
  1275. // car.temperature = "0 ℃";
  1276. // car.speed = "0 转";
  1277. // car.voltage = "0 V";
  1278. //}
  1279. car.address = ToolGPSamap.GPSToPositionString(car.longitude.ToDou(), car.latitude.ToDou());
  1280. if (car.longitude.ToDou() > 0 && car.latitude.ToDou() > 0)
  1281. carlist.Add(car);
  1282. }
  1283. }
  1284. carlist = carlist.OrderBy(p => p.onlineTime).ToList();
  1285. return Json(carlist, JsonRequestBehavior.AllowGet);
  1286. }
  1287. }
  1288. return null;
  1289. }
  1290. public ActionResult mapDrivingTrack(string id)
  1291. {
  1292. ViewData["carid"] = id;
  1293. return View();
  1294. }
  1295. /// <summary>
  1296. /// 加载列表
  1297. /// </summary>
  1298. /// <returns></returns>
  1299. [UserAuthorizeAttribute(ModuleAlias = "carList", OperaAction = "View")]
  1300. public ActionResult CarList()
  1301. {
  1302. try
  1303. {
  1304. string userid = string.Empty; string distributorsID = string.Empty;
  1305. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
  1306. if (!Request.QueryString["userid"].IsEmpty())
  1307. {
  1308. userid = Request.QueryString["userid"].ToString();
  1309. }
  1310. if (!Request.QueryString["distributorsid"].IsEmpty())
  1311. {
  1312. distributorsID = Request.QueryString["distributorsid"].ToString();
  1313. }
  1314. if (!userid.IsEmpty())
  1315. {
  1316. using (AntORM orm = new AntORM())
  1317. {
  1318. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1319. RequestModel res = new RequestModel
  1320. {
  1321. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1322. };
  1323. IQuery<YW_UserCar> dis = orm.Queryable<YW_UserCar>();
  1324. IQuery<EntYW_Bicycle> bicycle = orm.Queryable<EntYW_Bicycle>();
  1325. IJoiningQuery<YW_UserCar, EntYW_Bicycle> user_city = dis.LeftJoin(bicycle, (strip, sbicycle) => strip.carId == sbicycle.CarID);
  1326. var views = user_city.Select((strip, sbicycle) => new { carInfo = sbicycle, trip = strip }).Where(p => p.trip.userId == userid).OrderByDesc(p => p.carInfo.ID).ToList();
  1327. if (views.IsSuccess)
  1328. {
  1329. List<EntYW_Bicycle> listcar = new List<EntYW_Bicycle>();
  1330. foreach (var item in views.ResultModel)
  1331. {
  1332. EntYW_Bicycle mod = item.carInfo;
  1333. YW_UserCar userCar = item.trip;
  1334. mod.lang = (userCar.userIdentity == 1) ? "机主" : "机手";
  1335. listcar.Add(mod);
  1336. }
  1337. pageInfo = new PageInfo(base.page, base.pagesize, views.RecordNum, JsonConverter.JsonClass(listcar));
  1338. }
  1339. }
  1340. }
  1341. else
  1342. {
  1343. if (!distributorsID.IsEmpty())
  1344. {
  1345. using (AntORM orm = new AntORM())
  1346. {
  1347. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1348. RequestModel res = new RequestModel
  1349. {
  1350. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1351. };
  1352. var reslut = orm.Queryable<EntYW_Bicycle>().Where(p => p.DistributorsID == distributorsID).ToList(res);
  1353. if (reslut.IsSuccess)
  1354. {
  1355. pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel));
  1356. }
  1357. }
  1358. }
  1359. }
  1360. return View(pageInfo);
  1361. }
  1362. catch (Exception e)
  1363. {
  1364. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  1365. throw e.InnerException;
  1366. }
  1367. }
  1368. /// <summary>
  1369. /// 加载列表
  1370. /// </summary>
  1371. /// <returns></returns>
  1372. [UserAuthorizeAttribute(ModuleAlias = "machineryList", OperaAction = "View")]
  1373. public ActionResult MachineryList()
  1374. {
  1375. try
  1376. {
  1377. string posttype = Request.QueryString["posttype"];
  1378. string FK_DPTID = Request.QueryString["FK_DPTID"];
  1379. string CarSate = Request.QueryString["CarSate"];
  1380. int carType = Request.QueryString["LeaseStatus"].ToInt32();
  1381. string barcode = Request.QueryString["txt_barcode"];
  1382. string imei = Request.QueryString["txt_imei"];
  1383. string factoryNumber = Request.QueryString["txt_factoryNumber"];
  1384. string factoryDate = Request.QueryString["txt_factoryDate"];
  1385. int prov = Request.QueryString["hkprov"].ToInt32();
  1386. int state = -1;
  1387. if (!CarSate.IsEmpty())
  1388. {
  1389. state = CarSate.ToInt32();
  1390. }
  1391. int FenceState = -1;
  1392. if (!Request.QueryString["FenceState"].IsEmpty())
  1393. {
  1394. FenceState = Request.QueryString["FenceState"].ToInt32();
  1395. }
  1396. string distributorsID = string.Empty;
  1397. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
  1398. if (CurrentUser.USERTYPE == 0 || CurrentUser.USERTYPE == 8)
  1399. {
  1400. using (AntORM orm = new AntORM())
  1401. {
  1402. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1403. RequestModel res = new RequestModel
  1404. {
  1405. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1406. };
  1407. IQuery<EntSYS_DISTRIBUTORS> dis = orm.Queryable<EntSYS_DISTRIBUTORS>();
  1408. IQuery<EntYW_Bicycle> carquery = orm.Queryable<EntYW_Bicycle>();
  1409. var cardis = carquery.LeftJoin(dis, (d, c) => d.DistributorsID == c.ID);
  1410. var qq = cardis.Select((cars, disname) => new { Car = cars, Dis = disname }).Where(a => a.Car.CarSate > 0);
  1411. if (carType > 0)
  1412. qq = qq.Where(p => p.Car.ProductLine == carType);
  1413. if (!FK_DPTID.IsEmpty())
  1414. qq = qq.Where(p => p.Car.DistributorsID == FK_DPTID);
  1415. if (!barcode.IsEmpty())
  1416. {
  1417. qq = qq.Where(p => p.Car.carBar.Contains(barcode));
  1418. }
  1419. if (!imei.IsEmpty())
  1420. {
  1421. qq = qq.Where(p => p.Car.CarID.Contains(imei));
  1422. }
  1423. if (FenceState >= 0)
  1424. {
  1425. qq = qq.Where(p => p.Car.FenceState == FenceState);
  1426. }
  1427. if (CurrentUser.USERTYPE == 8)
  1428. {
  1429. qq = qq.Where(p => p.Car.DistributorsID != "fc674ffb-3044-4f5f-a40d-cf496fac52f7");
  1430. }
  1431. if (state >= 0)
  1432. {
  1433. qq = qq.Where(p => p.Car.CarSate == state);
  1434. }
  1435. if (prov > 0)
  1436. {
  1437. qq = qq.Where(p => p.Dis.Province == prov);
  1438. }
  1439. if (!factoryNumber.IsEmpty())
  1440. {
  1441. qq = qq.Where(p => p.Car.FactoryNumber == factoryNumber);
  1442. }
  1443. if (!factoryDate.IsEmpty())
  1444. {
  1445. DateTime dateTime = factoryDate.ToDateTime(); DateTime dates = dateTime.AddDays(1);
  1446. qq = qq.Where(p => p.Car.OutDate >= dateTime && p.Car.OutDate < dates);
  1447. }
  1448. int pageno = (page - 1) * pagesize;
  1449. var bicycleList = qq.OrderBy(a => a.Car.carBar).Skip(pageno).Top(pagesize).ToList();
  1450. if (bicycleList.IsSuccess)
  1451. {
  1452. bicycleList.RecordNum = qq.Count();
  1453. List<EntYW_Bicycle> listcar = new List<EntYW_Bicycle>();
  1454. foreach (var item in bicycleList.ResultModel)
  1455. {
  1456. EntYW_Bicycle mod = item.Car;
  1457. listcar.Add(mod);
  1458. }
  1459. pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, JsonConverter.JsonClass(listcar));
  1460. }
  1461. }
  1462. }
  1463. else
  1464. {
  1465. //if (CurrentUser.DptInfo.IfNotNull())
  1466. //{
  1467. // if (!CurrentUser.DptInfo.ID.IsEmpty())
  1468. // {
  1469. // distributorsID = CurrentUser.DptInfo.ID;
  1470. // }
  1471. //}
  1472. //else
  1473. //{
  1474. int saleid = CurrentUser.Id;
  1475. using (AntORM orm = new AntORM())
  1476. {
  1477. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1478. RequestModel res = new RequestModel
  1479. {
  1480. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1481. };
  1482. var q = orm.Queryable<EntYW_Bicycle>();
  1483. if (!FK_DPTID.IsEmpty())
  1484. {
  1485. q = q.Where(p => p.DistributorsID == FK_DPTID);
  1486. if (carType > 0)
  1487. {
  1488. q = q.Where(p => p.ProductLine == carType);
  1489. }
  1490. if (!barcode.IsEmpty())
  1491. {
  1492. q = q.Where(p => p.carBar.Contains(barcode));
  1493. }
  1494. if (!imei.IsEmpty())
  1495. {
  1496. q = q.Where(p => p.CarID.Contains(imei));
  1497. }
  1498. if (FenceState >= 0)
  1499. {
  1500. q = q.Where(p => p.FenceState == FenceState);
  1501. }
  1502. if (state >= 0)
  1503. {
  1504. q = q.Where(p => p.CarSate == state);
  1505. }
  1506. if (!factoryNumber.IsEmpty())
  1507. {
  1508. q = q.Where(p => p.FactoryNumber == factoryNumber);
  1509. }
  1510. int pageno = (page - 1) * pagesize;
  1511. var bicycleList = q.Skip(pageno).Top(pagesize).ToList();
  1512. if (bicycleList.IsSuccess)
  1513. {
  1514. bicycleList.RecordNum = q.Count();
  1515. List<EntYW_Bicycle> listcar = new List<EntYW_Bicycle>();
  1516. foreach (EntYW_Bicycle item in bicycleList.ResultModel)
  1517. {
  1518. listcar.Add(item);
  1519. }
  1520. pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, JsonConverter.JsonClass(listcar));
  1521. }
  1522. }
  1523. else
  1524. {
  1525. IQuery<EntYW_Bicycle> car = orm.Queryable<EntYW_Bicycle>();
  1526. var dis = orm.Queryable<EntSYS_DISTRIBUTORS>();
  1527. IQuery<EntYW_UserDistributor> userdis = orm.Queryable<EntYW_UserDistributor>();
  1528. IJoiningQuery<EntYW_Bicycle, EntYW_UserDistributor> user_city;
  1529. if (CurrentUser.USERTYPE == 10)
  1530. {
  1531. user_city = car.LeftJoin(userdis, (user, city) => user.DistributorsID == city.distributorId);
  1532. }
  1533. else
  1534. {
  1535. 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));
  1536. }
  1537. IJoiningQuery<EntYW_Bicycle, EntYW_UserDistributor, EntSYS_DISTRIBUTORS> user_city_province = user_city.InnerJoin(dis, (user, city, province) => (city.distributorId == province.ID));
  1538. var qq = user_city_province.Select((user, city, disname) => new { Users = user, Citys = city, Dis = disname }).Where(a => a.Citys.userId == saleid);
  1539. if (!Request.QueryString["CarSate"].IsEmpty())
  1540. {
  1541. int carstate = CarState.Storage.ToInt32();
  1542. }
  1543. if (carType > 0)
  1544. {
  1545. qq = qq.Where(p => p.Users.carType == carType);
  1546. }
  1547. if (prov > 0)
  1548. {
  1549. qq = qq.Where(p => p.Dis.Province == prov);
  1550. }
  1551. if (!barcode.IsEmpty())
  1552. {
  1553. qq = qq.Where(p => p.Users.carBar.Contains(barcode));
  1554. }
  1555. if (!imei.IsEmpty())
  1556. {
  1557. qq = qq.Where(p => p.Users.CarID.Contains(imei));
  1558. }
  1559. if (FenceState >= 0)
  1560. {
  1561. qq = qq.Where(p => p.Users.FenceState == FenceState);
  1562. }
  1563. if (state >= 0)
  1564. {
  1565. qq = qq.Where(p => p.Users.CarSate == state);
  1566. }
  1567. if (!factoryNumber.IsEmpty())
  1568. {
  1569. qq = qq.Where(p => p.Users.FactoryNumber == factoryNumber);
  1570. }
  1571. if (!factoryDate.IsEmpty())
  1572. {
  1573. DateTime dateTime = factoryDate.ToDateTime(); DateTime dates = dateTime.AddDays(1);
  1574. qq = qq.Where(p => p.Users.OutDate >= dateTime && p.Users.OutDate < dates);
  1575. }
  1576. int pageno = (page - 1) * pagesize;
  1577. var bicycleList = qq.OrderByDesc(p => p.Users.DistributorsID).Skip(pageno).Top(pagesize).ToList();
  1578. if (bicycleList.IsSuccess)
  1579. {
  1580. bicycleList.RecordNum = qq.Count();
  1581. List<EntYW_Bicycle> listcar = new List<EntYW_Bicycle>();
  1582. foreach (var item in bicycleList.ResultModel)
  1583. {
  1584. EntYW_Bicycle carmode = item.Users;
  1585. listcar.Add(carmode);
  1586. }
  1587. pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, JsonConverter.JsonClass(listcar));
  1588. }
  1589. }
  1590. }
  1591. //}
  1592. }
  1593. if (!distributorsID.IsEmpty())
  1594. {
  1595. using (AntORM orm = new AntORM())
  1596. {
  1597. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1598. RequestModel res = new RequestModel
  1599. {
  1600. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1601. };
  1602. var q = orm.Queryable<EntYW_Bicycle>().Where(p => p.DistributorsID == distributorsID);
  1603. if (!Request.QueryString["CarSate"].IsEmpty())
  1604. {
  1605. int carstate = CarState.Storage.ToInt32();
  1606. q = q.Where(p => p.CarSate == carstate);
  1607. }
  1608. if (!barcode.IsEmpty())
  1609. {
  1610. q = q.Where(p => p.carBar.Contains(barcode));
  1611. }
  1612. if (!imei.IsEmpty())
  1613. {
  1614. q = q.Where(p => p.CarID.Contains(imei));
  1615. }
  1616. int pageno = (page - 1) * pagesize;
  1617. var reslut = q.OrderBy(a => a.carBar).Skip(pageno).Top(pagesize).ToList(res);
  1618. if (reslut.IsSuccess)
  1619. {
  1620. reslut.RecordNum = q.Count();
  1621. pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel));
  1622. }
  1623. }
  1624. }
  1625. int uid = 0;
  1626. if (CurrentUser.USERTYPE == 0 || CurrentUser.USERTYPE == 8)
  1627. {
  1628. uid = 0;
  1629. }
  1630. else
  1631. {
  1632. uid = CurrentUser.Id;
  1633. }
  1634. if (!Request.QueryString["hkprov"].IsEmpty())
  1635. {
  1636. ViewData["hkprov"] = Request.QueryString["hkprov"];
  1637. }
  1638. ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew(uid, prov);
  1639. ViewData["dptid"] = FK_DPTID;
  1640. ViewData["CarSate"] = CarSate;
  1641. ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList();
  1642. ViewData["typecar"] = carType;
  1643. ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList();
  1644. //ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").ToList();
  1645. ViewData["factoryNumber"] = factoryNumber;
  1646. ViewData["factoryDate"] = factoryDate;
  1647. ViewData["FenceState"] = FenceState;
  1648. ViewBag.Search = base.keywords;
  1649. ViewData["barcode"] = barcode;
  1650. ViewData["imei"] = imei;
  1651. return View(pageInfo);
  1652. }
  1653. catch (Exception e)
  1654. {
  1655. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  1656. throw e.InnerException;
  1657. }
  1658. }
  1659. /// <summary>
  1660. /// 加载列表
  1661. /// </summary>
  1662. /// <returns></returns>
  1663. [UserAuthorizeAttribute(ModuleAlias = "salesCarList", OperaAction = "View")]
  1664. public ActionResult SalesCarList()
  1665. {
  1666. try
  1667. {
  1668. string posttype = Request.QueryString["posttype"];
  1669. string FK_DPTID = Request.QueryString["FK_DPTID"];
  1670. string CarSate = Request.QueryString["CarSate"];
  1671. string barcode = Request.QueryString["txt_barcode"];
  1672. string imei = Request.QueryString["txt_imei"];
  1673. string factoryNumber = Request.QueryString["txt_factoryNumber"];
  1674. int FenceState = -1;
  1675. if (!Request.QueryString["FenceState"].IsEmpty())
  1676. {
  1677. FenceState = Request.QueryString["FenceState"].ToInt32();
  1678. }
  1679. int carType = Request.QueryString["LeaseStatus"].ToInt32();
  1680. int state = -1;
  1681. if (!CarSate.IsEmpty())
  1682. {
  1683. state = CarSate.ToInt32();
  1684. }
  1685. string distributorsID = string.Empty;
  1686. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
  1687. if (CurrentUser.USERTYPE == 0 || CurrentUser.USERTYPE == 8)
  1688. {
  1689. using (AntORM orm = new AntORM())
  1690. {
  1691. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1692. RequestModel res = new RequestModel
  1693. {
  1694. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1695. };
  1696. IQuery<EntSYS_DISTRIBUTORS> dis = orm.Queryable<EntSYS_DISTRIBUTORS>();
  1697. IQuery<EntYW_Bicycle> carquery = orm.Queryable<EntYW_Bicycle>();
  1698. var cardis = carquery.LeftJoin(dis, (d, c) => d.DistributorsID == c.ID);
  1699. var qq = cardis.Select((cars, disname) => new { Car = cars, Dis = disname }).Where(a => a.Car.CarSate > 0);
  1700. if (carType > 0)
  1701. qq = qq.Where(p => p.Car.ProductLine == carType);
  1702. if (!FK_DPTID.IsEmpty())
  1703. qq = qq.Where(p => p.Car.DistributorsID == FK_DPTID);
  1704. if (!barcode.IsEmpty())
  1705. {
  1706. qq = qq.Where(p => p.Car.carBar.Contains(barcode));
  1707. }
  1708. if (!imei.IsEmpty())
  1709. {
  1710. qq = qq.Where(p => p.Car.CarID.Contains(imei));
  1711. }
  1712. if (FenceState >= 0)
  1713. {
  1714. qq = qq.Where(p => p.Car.FenceState == FenceState);
  1715. }
  1716. if (CurrentUser.USERTYPE == 8)
  1717. {
  1718. qq = qq.Where(p => p.Car.DistributorsID != "fc674ffb-3044-4f5f-a40d-cf496fac52f7");
  1719. }
  1720. if (state >= 0)
  1721. {
  1722. qq = qq.Where(p => p.Car.CarSate == state);
  1723. }
  1724. if (!factoryNumber.IsEmpty())
  1725. {
  1726. qq = qq.Where(p => p.Car.FactoryNumber == factoryNumber);
  1727. }
  1728. int pageno = (page - 1) * pagesize;
  1729. var bicycleList = qq.OrderBy(a => a.Car.carBar).Skip(pageno).Top(pagesize).ToList();
  1730. if (bicycleList.IsSuccess)
  1731. {
  1732. bicycleList.RecordNum = qq.Count();
  1733. List<EntYW_Bicycle> listcar = new List<EntYW_Bicycle>();
  1734. foreach (var item in bicycleList.ResultModel)
  1735. {
  1736. EntYW_Bicycle mod = item.Car;
  1737. listcar.Add(mod);
  1738. }
  1739. pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, JsonConverter.JsonClass(listcar));
  1740. }
  1741. }
  1742. }
  1743. else
  1744. {
  1745. //if (CurrentUser.DptInfo.IfNotNull()) //经销商
  1746. //{
  1747. // if (!CurrentUser.DptInfo.ID.IsEmpty())
  1748. // {
  1749. // distributorsID = CurrentUser.DptInfo.ID;
  1750. // }
  1751. //}
  1752. //else
  1753. //{
  1754. int saleid = CurrentUser.Id; //业务员
  1755. using (AntORM orm = new AntORM())
  1756. {
  1757. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1758. RequestModel res = new RequestModel
  1759. {
  1760. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1761. };
  1762. var q = orm.Queryable<EntYW_Bicycle>();
  1763. if (!FK_DPTID.IsEmpty())
  1764. {
  1765. q = q.Where(p => p.DistributorsID == FK_DPTID);
  1766. if (carType > 0)
  1767. {
  1768. q = q.Where(p => p.ProductLine == carType);
  1769. }
  1770. if (!barcode.IsEmpty())
  1771. {
  1772. q = q.Where(p => p.carBar.Contains(barcode));
  1773. }
  1774. if (!imei.IsEmpty())
  1775. {
  1776. q = q.Where(p => p.CarID.Contains(imei));
  1777. }
  1778. if (FenceState >= 0)
  1779. {
  1780. q = q.Where(p => p.FenceState == FenceState);
  1781. }
  1782. if (state >= 0)
  1783. {
  1784. q = q.Where(p => p.CarSate == state);
  1785. }
  1786. if (!factoryNumber.IsEmpty())
  1787. {
  1788. q = q.Where(p => p.FactoryNumber == factoryNumber);
  1789. }
  1790. int pageno = (page - 1) * pagesize;
  1791. var bicycleList = q.Skip(pageno).Top(pagesize).ToList();
  1792. if (bicycleList.IsSuccess)
  1793. {
  1794. bicycleList.RecordNum = q.Count();
  1795. List<EntYW_Bicycle> listcar = new List<EntYW_Bicycle>();
  1796. foreach (EntYW_Bicycle item in bicycleList.ResultModel)
  1797. {
  1798. listcar.Add(item);
  1799. }
  1800. pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, JsonConverter.JsonClass(listcar));
  1801. }
  1802. }
  1803. else
  1804. {
  1805. IQuery<EntYW_Bicycle> car = orm.Queryable<EntYW_Bicycle>();
  1806. IQuery<EntYW_UserDistributor> userdis = orm.Queryable<EntYW_UserDistributor>();
  1807. IQuery<EntSYS_DISTRIBUTORS> dis = orm.Queryable<EntSYS_DISTRIBUTORS>();
  1808. IJoiningQuery<EntYW_Bicycle, EntYW_UserDistributor> user_city;
  1809. if (CurrentUser.USERTYPE == 10)
  1810. {
  1811. user_city = car.LeftJoin(userdis, (user, city) => user.DistributorsID == city.distributorId);
  1812. }
  1813. else
  1814. {
  1815. 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));
  1816. }
  1817. IJoiningQuery<EntYW_Bicycle, EntYW_UserDistributor, EntSYS_DISTRIBUTORS> user_city_province = user_city.InnerJoin(dis, (user, city, province) => (city.distributorId == province.ID));
  1818. var qq = user_city_province.Select((user, city, disname) => new { Users = user, Citys = city, Dis = disname }).Where(a => a.Citys.userId == saleid);
  1819. if (!Request.QueryString["CarSate"].IsEmpty())
  1820. {
  1821. int carstate = CarState.Storage.ToInt32();
  1822. }
  1823. if (carType > 0)
  1824. {
  1825. qq = qq.Where(p => p.Users.ProductLine == carType);
  1826. }
  1827. if (!barcode.IsEmpty())
  1828. {
  1829. qq = qq.Where(p => p.Users.carBar.Contains(barcode));
  1830. }
  1831. if (!imei.IsEmpty())
  1832. {
  1833. qq = qq.Where(p => p.Users.CarID.Contains(imei));
  1834. }
  1835. if (FenceState >= 0)
  1836. {
  1837. qq = qq.Where(p => p.Users.FenceState == FenceState);
  1838. }
  1839. if (state >= 0)
  1840. {
  1841. qq = qq.Where(p => p.Users.CarSate == state);
  1842. }
  1843. if (!factoryNumber.IsEmpty())
  1844. {
  1845. qq = qq.Where(p => p.Users.FactoryNumber == factoryNumber);
  1846. }
  1847. int pageno = (page - 1) * pagesize;
  1848. var bicycleList = qq.OrderByDesc(p => p.Users.DistributorsID).Skip(pageno).Top(pagesize).ToList();
  1849. if (bicycleList.IsSuccess)
  1850. {
  1851. bicycleList.RecordNum = qq.Count();
  1852. List<EntYW_Bicycle> listcar = new List<EntYW_Bicycle>();
  1853. foreach (var item in bicycleList.ResultModel)
  1854. {
  1855. EntYW_Bicycle carmode = item.Users;
  1856. EntSYS_DISTRIBUTORS dismod = item.Dis;
  1857. carmode.DistributorsName = dismod.NAME;
  1858. listcar.Add(carmode);
  1859. }
  1860. pageInfo = new PageInfo(base.page, base.pagesize, bicycleList.RecordNum, JsonConverter.JsonClass(listcar));
  1861. }
  1862. }
  1863. }
  1864. //}
  1865. }
  1866. if (!distributorsID.IsEmpty())
  1867. {
  1868. using (AntORM orm = new AntORM())
  1869. {
  1870. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1871. RequestModel res = new RequestModel
  1872. {
  1873. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1874. };
  1875. var q = orm.Queryable<EntYW_Bicycle>().Where(p => p.DistributorsID == distributorsID);
  1876. if (!Request.QueryString["CarSate"].IsEmpty())
  1877. {
  1878. int carstate = CarState.Storage.ToInt32();
  1879. q = q.Where(p => p.CarSate == carstate);
  1880. }
  1881. if (!barcode.IsEmpty())
  1882. {
  1883. q = q.Where(p => p.carBar.Contains(barcode));
  1884. }
  1885. if (!imei.IsEmpty())
  1886. {
  1887. q = q.Where(p => p.CarID.Contains(imei));
  1888. }
  1889. if (state >= 0)
  1890. {
  1891. q = q.Where(p => p.CarSate == state);
  1892. }
  1893. if (!factoryNumber.IsEmpty())
  1894. {
  1895. q = q.Where(p => p.FactoryNumber == factoryNumber);
  1896. }
  1897. int pageno = (page - 1) * pagesize;
  1898. var reslut = q.Skip(pageno).Top(pagesize).ToList();
  1899. if (reslut.IsSuccess)
  1900. {
  1901. pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel));
  1902. }
  1903. }
  1904. }
  1905. int uid = 0;
  1906. if (CurrentUser.USERTYPE == 0 || CurrentUser.USERTYPE == 8)
  1907. {
  1908. uid = 0;
  1909. }
  1910. else
  1911. {
  1912. uid = CurrentUser.Id;
  1913. }
  1914. ViewData["Department"] = this.DepartmentManage.GetDepartmentByDetailNew(uid);
  1915. ViewData["dptid"] = FK_DPTID;
  1916. ViewData["CarSate"] = CarSate;
  1917. ViewData["FenceState"] = FenceState;
  1918. ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList();
  1919. ViewData["typecar"] = carType;
  1920. ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList();
  1921. ViewData["barcode"] = barcode;
  1922. ViewData["factoryNumber"] = factoryNumber;
  1923. ViewData["imei"] = imei;
  1924. return View(pageInfo);
  1925. }
  1926. catch (Exception e)
  1927. {
  1928. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  1929. throw e.InnerException;
  1930. }
  1931. }
  1932. /// <summary>
  1933. /// 锁车列表
  1934. /// </summary>
  1935. /// <returns></returns>
  1936. public ActionResult CarLockList(string id)
  1937. {
  1938. try
  1939. {
  1940. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<MeterMaintenance>()));
  1941. using (AntORM orm = new AntORM())
  1942. {
  1943. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1944. RequestModel res = new RequestModel
  1945. {
  1946. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1947. };
  1948. var reslut = orm.Queryable<MeterMaintenance>().Where(p => p.IMEI == "356802033785329").ToList(res);
  1949. if (reslut.IsSuccess)
  1950. {
  1951. pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel));
  1952. }
  1953. }
  1954. return View(pageInfo);
  1955. }
  1956. catch (Exception e)
  1957. {
  1958. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  1959. throw e.InnerException;
  1960. }
  1961. }
  1962. /// <summary>
  1963. /// 加载列表
  1964. /// </summary>
  1965. /// <returns></returns>
  1966. [UserAuthorizeAttribute(ModuleAlias = "SalesCarList", OperaAction = "View,Add,Edit,Export")]
  1967. public ActionResult DistributorCarList()
  1968. {
  1969. try
  1970. {
  1971. 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;
  1972. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
  1973. if (!Request.QueryString["distributorsid"].IsEmpty())
  1974. {
  1975. distributorsID = Request.QueryString["distributorsid"].ToString();
  1976. }
  1977. if (!Request.QueryString["distributorLEVEL"].IsEmpty())
  1978. {
  1979. LEVEL = Request.QueryString["distributorLEVEL"].ToString();
  1980. }
  1981. if (!Request.QueryString["distributorsName"].IsEmpty())
  1982. {
  1983. distributorName = Request.QueryString["distributorsName"].ToString();
  1984. }
  1985. if (!Request.QueryString["saleid"].IsEmpty())
  1986. {
  1987. saleId = Request.QueryString["saleid"].ToString();
  1988. }
  1989. if (!distributorsID.IsEmpty())
  1990. {
  1991. using (AntORM orm = new AntORM())
  1992. {
  1993. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  1994. RequestModel res = new RequestModel
  1995. {
  1996. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  1997. };
  1998. var q = orm.Queryable<EntYW_Bicycle>();
  1999. if (!CarSate.IsEmpty() && CarSate != "-1")
  2000. {
  2001. int state = CarSate.ToInt32();
  2002. if (LEVEL == "2")
  2003. {
  2004. q = q.Where(p => p.DistributorsID == distributorsID && p.CarSate == state);
  2005. }
  2006. else
  2007. {
  2008. q = q.Where(p => p.WarehouseID == distributorsID && p.CarSate == state);
  2009. }
  2010. }
  2011. else
  2012. {
  2013. if (LEVEL == "2")
  2014. {
  2015. q = q.Where(p => p.DistributorsID == distributorsID);
  2016. }
  2017. else
  2018. {
  2019. q = q.Where(p => p.WarehouseID == distributorsID);
  2020. }
  2021. }
  2022. int pageno = (page - 1) * pagesize;
  2023. var reslut = q.OrderByDesc(p => p.CreateDate).Skip(pageno).Top(pagesize).ToList(res);
  2024. if (reslut.IsSuccess)
  2025. {
  2026. reslut.RecordNum = q.Count();
  2027. pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel));
  2028. }
  2029. }
  2030. }
  2031. //ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").ToList();
  2032. ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList();
  2033. ViewData["CarSate"] = CarSate;
  2034. ViewData["distributorsid"] = distributorsID;
  2035. ViewData["distributorName"] = distributorName;
  2036. ViewData["saleid"] = saleId;
  2037. return View(pageInfo);
  2038. }
  2039. catch (Exception e)
  2040. {
  2041. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  2042. throw e.InnerException;
  2043. }
  2044. }
  2045. /// <summary>
  2046. /// 加载列表
  2047. /// </summary>
  2048. /// <returns></returns>
  2049. [UserAuthorizeAttribute(ModuleAlias = "Department", OperaAction = "View,Export")]
  2050. public ActionResult DistributorInventoryCarList()
  2051. {
  2052. try
  2053. {
  2054. string userid = string.Empty; string distributorsID = string.Empty; string CarSate = Request.QueryString["CarSate"];
  2055. PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
  2056. if (!Request.QueryString["distributorsid"].IsEmpty())
  2057. {
  2058. distributorsID = Request.QueryString["distributorsid"].ToString();
  2059. }
  2060. if (!distributorsID.IsEmpty())
  2061. {
  2062. using (AntORM orm = new AntORM())
  2063. {
  2064. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  2065. RequestModel res = new RequestModel
  2066. {
  2067. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  2068. };
  2069. var q = orm.Queryable<EntYW_Bicycle>();
  2070. if (!CarSate.IsEmpty())
  2071. {
  2072. int state = CarSate.ToInt32();
  2073. q = q.Where(p => p.DistributorsID == distributorsID && p.CarSate == state);
  2074. }
  2075. else
  2076. {
  2077. q = q.Where(p => p.DistributorsID == distributorsID);
  2078. }
  2079. var reslut = q.ToList(res);
  2080. if (reslut.IsSuccess)
  2081. {
  2082. pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel));
  2083. }
  2084. }
  2085. }
  2086. ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").OrderBy(p => p.SHOWORDER).ToList();
  2087. //ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").ToList();
  2088. ViewData["CarSate"] = CarSate;
  2089. ViewData["distributorsid"] = distributorsID;
  2090. return View(pageInfo);
  2091. }
  2092. catch (Exception e)
  2093. {
  2094. WriteLog(enumOperator.Select, "加载岗位列表:", e);
  2095. throw e.InnerException;
  2096. }
  2097. }
  2098. /// <summary>
  2099. /// 申请审校不通过
  2100. /// </summary>
  2101. /// <returns></returns>
  2102. [HttpGet]
  2103. public ActionResult CheckApplyCarPass(string applyid)
  2104. {
  2105. var json = new JsonHelper() { Status = "y", Msg = "Success" };
  2106. using (AntORM orm = new AntORM())
  2107. {
  2108. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  2109. RequestModel res = new RequestModel();
  2110. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
  2111. Guid guid = new Guid(applyid);
  2112. var reslut = orm.Queryable<yw_machinery_return>().Where(p => p.id == guid).FirstOrDefault(res);
  2113. if (reslut.IsSuccess)
  2114. {
  2115. yw_machinery_return mod = reslut.ResultModel;
  2116. if (mod.apply_type == 1)//退货
  2117. {
  2118. int carstate = CarState.OutStock.ToInt32();
  2119. var reslutcar = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { CarSate = carstate }, f => f.CarID == mod.carid, res);
  2120. {
  2121. var reslutapply = orm.UpdateByLambda<yw_machinery_return>(p => new yw_machinery_return { state = 1, check_time = DateTime.Now }, f => f.id == mod.id, res);
  2122. if (reslutapply.IsSuccess)
  2123. {
  2124. json.Status = "y";
  2125. json.Msg = "退货审核通过";
  2126. }
  2127. var usersalereslut = orm.DeleteByLambda<YW_CarPurchaser>(p => p.imei == mod.carid, res);
  2128. if (usersalereslut.IsSuccess)
  2129. {
  2130. }
  2131. var userbindreslut = orm.DeleteByLambda<YW_UserCar>(p => p.carId == mod.carid, res);
  2132. if (userbindreslut.IsSuccess)
  2133. {
  2134. }
  2135. var alarmreslut = orm.DeleteByLambda<YW_AlarmInformation>(p => p.CarId == mod.carid, res);
  2136. if (alarmreslut.IsSuccess)
  2137. {
  2138. }
  2139. }
  2140. }
  2141. if (mod.apply_type == 2)//返厂
  2142. {
  2143. int carstate = CarState.carBind.ToInt32();
  2144. var reslutcar = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { CarSate = carstate, DistributorsID = "", DistributorsName = "" }, f => f.CarID == mod.carid, res);
  2145. {
  2146. var reslutapply = orm.UpdateByLambda<yw_machinery_return>(p => new yw_machinery_return { state = 1 }, f => f.id == mod.id, res);
  2147. if (reslutapply.IsSuccess)
  2148. {
  2149. json.Status = "y";
  2150. json.Msg = "返厂审核通过";
  2151. }
  2152. var usersalereslut = orm.DeleteByLambda<YW_CarPurchaser>(p => p.imei == mod.carid, res);
  2153. if (usersalereslut.IsSuccess)
  2154. {
  2155. }
  2156. var userbindreslut = orm.DeleteByLambda<YW_UserCar>(p => p.carId == mod.carid, res);
  2157. if (userbindreslut.IsSuccess)
  2158. {
  2159. }
  2160. var alarmreslut = orm.DeleteByLambda<YW_AlarmInformation>(p => p.CarId == mod.carid, res);
  2161. if (alarmreslut.IsSuccess)
  2162. {
  2163. }
  2164. }
  2165. }
  2166. if (mod.apply_type == 3)//调拨
  2167. {
  2168. int carstate = CarState.OutStock.ToInt32();
  2169. var reslutcar = orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { CarSate = carstate, DistributorsID = mod.distributorsID, DistributorsName = mod.distributorsName }, f => f.CarID == mod.carid, res);
  2170. {
  2171. var reslutapply = orm.UpdateByLambda<yw_machinery_return>(p => new yw_machinery_return { state = 1 }, f => f.id == mod.id, res);
  2172. if (reslutapply.IsSuccess)
  2173. {
  2174. json.Status = "y";
  2175. json.Msg = "调拨审核通过";
  2176. }
  2177. var usersalereslut = orm.DeleteByLambda<YW_CarPurchaser>(p => p.imei == mod.carid, res);
  2178. if (usersalereslut.IsSuccess)
  2179. {
  2180. }
  2181. var userbindreslut = orm.DeleteByLambda<YW_UserCar>(p => p.carId == mod.carid, res);
  2182. if (userbindreslut.IsSuccess)
  2183. {
  2184. }
  2185. var alarmreslut = orm.DeleteByLambda<YW_AlarmInformation>(p => p.CarId == mod.carid, res);
  2186. if (alarmreslut.IsSuccess)
  2187. {
  2188. }
  2189. }
  2190. }
  2191. if (mod.apply_type == 4)
  2192. {
  2193. //SendLockCarCmd(mod.carid);
  2194. }
  2195. if (mod.apply_type == 5)
  2196. {
  2197. //SendUnlockCarCmd(mod.carid);
  2198. }
  2199. }
  2200. }
  2201. return Json(json, JsonRequestBehavior.AllowGet);
  2202. }
  2203. /// <summary>
  2204. /// 审核不通过
  2205. /// </summary>
  2206. /// <param name="applyid"></param>
  2207. /// <returns></returns>
  2208. [HttpGet]
  2209. public ActionResult CheckApplyCarNoPass(string applyid)
  2210. {
  2211. var json = new JsonHelper() { Status = "y", Msg = "Success" };
  2212. using (AntORM orm = new AntORM())
  2213. {
  2214. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  2215. RequestModel res = new RequestModel();
  2216. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取用户车辆信息" };
  2217. Guid guid = new Guid(applyid);
  2218. var reslutapply = orm.UpdateByLambda<yw_machinery_return>(p => new yw_machinery_return { state = 2 }, f => f.id == guid, res);
  2219. if (reslutapply.IsSuccess)
  2220. {
  2221. var reslutmod = orm.Queryable<yw_machinery_return>().Where(p => p.id == guid).FirstOrDefault(res);
  2222. if (reslutmod.IsSuccess)
  2223. {
  2224. yw_machinery_return mod = reslutmod.ResultModel;
  2225. orm.UpdateByLambda<EntYW_Bicycle>(p => new EntYW_Bicycle { CarSate = mod.carState }, f => f.CarID == mod.carid, res);
  2226. }
  2227. }
  2228. }
  2229. return Json(json, JsonRequestBehavior.AllowGet);
  2230. }
  2231. /// <summary>
  2232. /// 发送锁车指令
  2233. /// </summary>
  2234. [HttpGet]
  2235. public ActionResult SendLockCarCmd(string carid)
  2236. {
  2237. var json = new JsonHelper() { Status = "y", Msg = "Success" };
  2238. var applyName = Request["applyName"];
  2239. var applyReason = Request["applyReason"];
  2240. var applypwd = Request["applyPwd"];
  2241. if (applypwd == "changfa123")
  2242. {
  2243. var str = DataHelper.sendLockHexStr(Convert.ToInt64(carid.Trim()));
  2244. var body = DataHelper.HexToByte(str);
  2245. SocketClient client = new SocketClient();
  2246. try
  2247. {
  2248. string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString();
  2249. int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32();
  2250. client.Connect(ip, port);
  2251. var flag = client.SendData(body);
  2252. //string mip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString();
  2253. //MongoDbHelper mh = new MongoDbHelper(mip, "1000");
  2254. //var querywhere = MongoDB.Driver.Builders.Query<ApplyCarLock>.Where(xx => xx.carid == carid);
  2255. //var locatmod = mh.FindOne<ApplyCarLock>(querywhere);
  2256. //if (locatmod.IsNull())
  2257. //{
  2258. // ApplyCarLock userCar = new ApplyCarLock();
  2259. // userCar.carid = carid;
  2260. // userCar.apply_type = 1; //发送锁车指令
  2261. // userCar.state = 0;
  2262. // userCar.add_name = "服务";
  2263. // userCar.created_at = DateTime.Now;
  2264. // var carflag = mh.Insert(userCar);
  2265. //}
  2266. //else
  2267. //{
  2268. // var update = new MongoDB.Driver.UpdateDocument { { "$set", new MongoDB.Driver.QueryDocument { { "apply_type", 1 }, { "state", 0 } } } };
  2269. // var querystr = MongoDB.Driver.Builders.Query<ApplyCarLock>.Where(xx => xx.carid == carid);
  2270. // if (mh.Update<ApplyCarLock>(querystr, update))
  2271. // {
  2272. // }
  2273. //}
  2274. using (AntORM orm = new AntORM())
  2275. {
  2276. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  2277. RequestModel res = new RequestModel
  2278. {
  2279. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  2280. };
  2281. var reslutlock = orm.UpdateByLambda<YW_Apply_CarLock>(p => new YW_Apply_CarLock { state = 2 }, f => f.carid == carid && f.state == 0, res);
  2282. if (reslutlock.IsSuccess)
  2283. {
  2284. }
  2285. YW_Apply_CarLock apply_CarLock = new YW_Apply_CarLock();
  2286. apply_CarLock.ID = Guid.NewGuid();
  2287. apply_CarLock.apply_type = 1;
  2288. apply_CarLock.apply_name = applyName;
  2289. apply_CarLock.reason = applyReason;
  2290. apply_CarLock.carid = carid;
  2291. apply_CarLock.add_time = DateTime.Now;
  2292. apply_CarLock.state = 0;
  2293. apply_CarLock.add_name = "管理员";
  2294. orm.Save(apply_CarLock, res);
  2295. }
  2296. client.Disconnect();
  2297. }
  2298. catch (Exception ex)
  2299. {
  2300. }
  2301. }
  2302. else
  2303. {
  2304. json.Msg = "申请密码不正确!";
  2305. json.Status = "n";
  2306. }
  2307. //json.Data = Common.JsonConverter.Serialize(this.CodeAreaManage.LoadListAll(p => p.LEVELS == 1));
  2308. return Json(json, JsonRequestBehavior.AllowGet);
  2309. }
  2310. /// <summary>
  2311. /// 发送开锁指令
  2312. /// </summary>
  2313. [HttpGet]
  2314. public ActionResult SendUnlockCarCmd(string carid)
  2315. {
  2316. var json = new JsonHelper() { Status = "y", Msg = "Success" };
  2317. var applyName = Request["applyName"];
  2318. var applyReason = Request["applyReason"];
  2319. var applypwd = Request["applyPwd"];
  2320. if (applypwd == "changfa123")
  2321. {
  2322. var str = DataHelper.sendUnLockHexStr(Convert.ToInt64(carid.Trim()));
  2323. var body = DataHelper.HexToByte(str);
  2324. SocketClient client = new SocketClient();
  2325. try
  2326. {
  2327. string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["ip"].ToString();
  2328. int port = System.Web.Configuration.WebConfigurationManager.AppSettings["port"].ToInt32();
  2329. client.Connect(ip, port);
  2330. var flag = client.SendData(body);
  2331. //string mip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString();
  2332. //MongoDbHelper mh = new MongoDbHelper(mip, "1000");
  2333. //var querywhere = MongoDB.Driver.Builders.Query<ApplyCarLock>.Where(xx => xx.carid == carid);
  2334. //var applymod = mh.FindOne<ApplyCarLock>(querywhere);
  2335. //if (applymod.IsNull())
  2336. //{
  2337. // ApplyCarLock userCar = new ApplyCarLock();
  2338. // userCar.carid = carid;
  2339. // userCar.apply_type = 2;
  2340. // userCar.state = 0;
  2341. // userCar.add_name = "服务";
  2342. // var carflag = mh.Insert(userCar);
  2343. //}
  2344. //else
  2345. //{
  2346. // var update = new MongoDB.Driver.UpdateDocument { { "$set", new MongoDB.Driver.QueryDocument { { "apply_type", 2 }, { "state", 0 } } } };
  2347. // var querystr = MongoDB.Driver.Builders.Query<ApplyCarLock>.Where(xx => xx.carid == carid);
  2348. // if (mh.Update<ApplyCarLock>(querystr, update))
  2349. // {
  2350. // }
  2351. //}
  2352. using (AntORM orm = new AntORM())
  2353. {
  2354. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  2355. RequestModel res = new RequestModel
  2356. {
  2357. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  2358. };
  2359. var reslutlock = orm.UpdateByLambda<YW_Apply_CarLock>(p => new YW_Apply_CarLock { state = 2 }, f => f.carid == carid && f.state == 0, res);
  2360. if (reslutlock.IsSuccess)
  2361. {
  2362. }
  2363. YW_Apply_CarLock apply_CarLock = new YW_Apply_CarLock();
  2364. apply_CarLock.ID = Guid.NewGuid();
  2365. apply_CarLock.apply_type = 2;
  2366. apply_CarLock.apply_name = applyName;
  2367. apply_CarLock.reason = applyReason;
  2368. apply_CarLock.carid = carid;
  2369. apply_CarLock.add_time = DateTime.Now;
  2370. apply_CarLock.state = 0;
  2371. apply_CarLock.add_name = "管理员";
  2372. orm.Save(apply_CarLock, res);
  2373. }
  2374. client.Disconnect();
  2375. }
  2376. catch (Exception ex)
  2377. {
  2378. }
  2379. }
  2380. else
  2381. {
  2382. json.Msg = "申请密码不正确!";
  2383. json.Status = "n";
  2384. }
  2385. //json.Data = Common.JsonConverter.Serialize(this.CodeAreaManage.LoadListAll(p => p.LEVELS == 1));
  2386. return Json(json, JsonRequestBehavior.AllowGet);
  2387. }
  2388. /// <summary>
  2389. /// 导出excel
  2390. /// </summary>
  2391. /// <returns></returns>
  2392. [HttpGet]
  2393. [UserAuthorizeAttribute(ModuleAlias = "carList", OperaAction = "View")]
  2394. public FileResult Excel()
  2395. {
  2396. //获取list数据
  2397. List<string> list = new List<string>();
  2398. //创建Excel文件的对象
  2399. NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); string distributorsID = string.Empty; string CarSate = Request.QueryString["CarSate"];
  2400. //添加一个sheet
  2401. NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
  2402. //给sheet1添加第一行的头部标题
  2403. NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
  2404. row1.CreateCell(0).SetCellValue("农机IMEI号");
  2405. row1.CreateCell(1).SetCellValue("农机名称");
  2406. row1.CreateCell(2).SetCellValue("车架号");
  2407. row1.CreateCell(3).SetCellValue("所属经销商");
  2408. row1.CreateCell(4).SetCellValue("车辆状态");
  2409. row1.CreateCell(5).SetCellValue("出厂日期");
  2410. //将数据逐步写入sheet1各个行
  2411. if (!Request.QueryString["distributorsid"].IsEmpty())
  2412. {
  2413. distributorsID = Request.QueryString["distributorsid"].ToString();
  2414. }
  2415. if (!distributorsID.IsEmpty())
  2416. {
  2417. using (AntORM orm = new AntORM())
  2418. {
  2419. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  2420. RequestModel res = new RequestModel
  2421. {
  2422. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  2423. };
  2424. var q = orm.Queryable<EntYW_Bicycle>();
  2425. if (!CarSate.IsEmpty())
  2426. {
  2427. int state = CarSate.ToInt32();
  2428. q = q.Where(p => p.DistributorsID == distributorsID && p.CarSate == state);
  2429. }
  2430. else
  2431. {
  2432. q = q.Where(p => p.DistributorsID == distributorsID);
  2433. }
  2434. var reslut = q.ToList(res);
  2435. if (reslut.IsSuccess)
  2436. {
  2437. List<EntYW_Bicycle> modlist = reslut.ResultModel;
  2438. for (int i = 0; i < modlist.Count; i++)
  2439. {
  2440. NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1);
  2441. rowtemp.CreateCell(0).SetCellValue(modlist[i].CarID);
  2442. rowtemp.CreateCell(1).SetCellValue(modlist[i].CarName);
  2443. rowtemp.CreateCell(2).SetCellValue(modlist[i].CarNumber);
  2444. rowtemp.CreateCell(3).SetCellValue(modlist[i].DistributorsName);
  2445. rowtemp.CreateCell(4).SetCellValue(GetCarState.getCarStateStr(modlist[i].CarSate.ToInt32()));
  2446. rowtemp.CreateCell(5).SetCellValue(modlist[i].productionDate.ToString());
  2447. //rowtemp.CreateCell(5).SetCellValue(list[i].iName);
  2448. //rowtemp.CreateCell(6).SetCellValue(list[i].iPhone);
  2449. //rowtemp.CreateCell(7).SetCellValue(list[i].IntegralSum);
  2450. //rowtemp.CreateCell(8).SetCellValue(list[i].IntegralSy);
  2451. //rowtemp.CreateCell(9).SetCellValue(list[i].IntegralKy);
  2452. }
  2453. }
  2454. }
  2455. }
  2456. // 写入到客户端
  2457. System.IO.MemoryStream ms = new System.IO.MemoryStream();
  2458. book.Write(ms);
  2459. ms.Seek(0, SeekOrigin.Begin);
  2460. return File(ms, "application/vnd.ms-excel", "经销商库存信息.xls");
  2461. }
  2462. /// <summary>
  2463. /// 导出excel
  2464. /// </summary>
  2465. /// <returns></returns>
  2466. [HttpGet]
  2467. [UserAuthorizeAttribute(ModuleAlias = "carList", OperaAction = "View")]
  2468. public FileResult AllCarExcel()
  2469. {
  2470. //获取list数据
  2471. List<string> list = new List<string>();
  2472. //创建Excel文件的对象
  2473. NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); string distributorsID = string.Empty; string CarSate = Request.QueryString["CarSate"];
  2474. List<string> namelist = new List<string>();
  2475. //添加一个sheet
  2476. NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
  2477. //给sheet1添加第一行的头部标题
  2478. NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
  2479. row1.CreateCell(0).SetCellValue("农机IMEI号");
  2480. row1.CreateCell(1).SetCellValue("农机名称");
  2481. row1.CreateCell(2).SetCellValue("车架号");
  2482. row1.CreateCell(3).SetCellValue("所属经销商");
  2483. row1.CreateCell(4).SetCellValue("车辆状态");
  2484. row1.CreateCell(5).SetCellValue("出厂日期");
  2485. //将数据逐步写入sheet1各个行
  2486. if (!Request.QueryString["distributorsid"].IsEmpty())
  2487. {
  2488. distributorsID = Request.QueryString["distributorsid"].ToString();
  2489. }
  2490. using (AntORM orm = new AntORM())
  2491. {
  2492. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  2493. RequestModel res = new RequestModel
  2494. {
  2495. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  2496. };
  2497. var q = orm.Queryable<EntSYS_DISTRIBUTORS>();
  2498. if (!Request.QueryString["hkprovid"].IsEmpty())
  2499. {
  2500. int provid = Request.QueryString["hkprovid"].ToInt32();
  2501. q = q.Where(p => p.Province == provid);
  2502. }
  2503. if (!Request.QueryString["hkcityid"].IsEmpty())
  2504. {
  2505. int provid = Request.QueryString["hkcityid"].ToInt32();
  2506. q = q.Where(p => p.City == provid);
  2507. }
  2508. var reslutd = q.ToList(res);
  2509. if (reslutd.IsSuccess)
  2510. {
  2511. var modellist = reslutd.ResultModel;
  2512. foreach (EntSYS_DISTRIBUTORS md in modellist)
  2513. {
  2514. namelist.Add(md.ID);
  2515. }
  2516. }
  2517. }
  2518. if (namelist.Count > 0)
  2519. {
  2520. using (AntORM orm = new AntORM())
  2521. {
  2522. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  2523. RequestModel res = new RequestModel
  2524. {
  2525. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  2526. };
  2527. var q = orm.Queryable<EntYW_Bicycle>();
  2528. if (!CarSate.IsEmpty())
  2529. {
  2530. int state = CarSate.ToInt32();
  2531. q = q.Where(p => namelist.Contains(p.DistributorsID) && p.CarSate == state);
  2532. }
  2533. else
  2534. {
  2535. q = q.Where(p => namelist.Contains(p.DistributorsID));
  2536. }
  2537. var reslut = q.ToList(res);
  2538. if (reslut.IsSuccess)
  2539. {
  2540. List<EntYW_Bicycle> modlist = reslut.ResultModel;
  2541. for (int i = 0; i < modlist.Count; i++)
  2542. {
  2543. NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1);
  2544. rowtemp.CreateCell(0).SetCellValue(modlist[i].CarID);
  2545. rowtemp.CreateCell(1).SetCellValue(modlist[i].CarName);
  2546. rowtemp.CreateCell(2).SetCellValue(modlist[i].carBar);
  2547. rowtemp.CreateCell(3).SetCellValue(modlist[i].DistributorsName);
  2548. rowtemp.CreateCell(4).SetCellValue(GetCarState.getCarStateStr(modlist[i].CarSate.ToInt32()));
  2549. rowtemp.CreateCell(5).SetCellValue(modlist[i].productionDate.ToString());
  2550. //rowtemp.CreateCell(5).SetCellValue(list[i].iName);
  2551. //rowtemp.CreateCell(6).SetCellValue(list[i].iPhone);
  2552. //rowtemp.CreateCell(7).SetCellValue(list[i].IntegralSum);
  2553. //rowtemp.CreateCell(8).SetCellValue(list[i].IntegralSy);
  2554. //rowtemp.CreateCell(9).SetCellValue(list[i].IntegralKy);
  2555. }
  2556. }
  2557. }
  2558. }
  2559. // 写入到客户端
  2560. System.IO.MemoryStream ms = new System.IO.MemoryStream();
  2561. book.Write(ms);
  2562. ms.Seek(0, SeekOrigin.Begin);
  2563. return File(ms, "application/vnd.ms-excel", "经销商库存信息.xls");
  2564. }
  2565. /// <summary>
  2566. /// 导出电子围栏内外的数据
  2567. /// </summary>
  2568. /// <returns></returns>
  2569. public FileResult FenceExcel()
  2570. {
  2571. //获取list数据
  2572. List<string> list = new List<string>();
  2573. //创建Excel文件的对象
  2574. NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); string distributorsID = string.Empty; string CarSate = Request.QueryString["CarSate"];
  2575. var cartype = Request.QueryString["cartype"];
  2576. var fencetype = Request.QueryString["fencetype"];
  2577. var dptid = Request.QueryString["dptid"];
  2578. //添加一个sheet
  2579. NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
  2580. //给sheet1添加第一行的头部标题
  2581. NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
  2582. row1.CreateCell(0).SetCellValue("农机IMEI号");
  2583. row1.CreateCell(1).SetCellValue("农机名称");
  2584. row1.CreateCell(2).SetCellValue("农机型号");
  2585. row1.CreateCell(3).SetCellValue("车架号");
  2586. row1.CreateCell(4).SetCellValue("所属经销商");
  2587. row1.CreateCell(5).SetCellValue("围栏状态");
  2588. row1.CreateCell(6).SetCellValue("出厂日期");
  2589. row1.CreateCell(7).SetCellValue("出厂编号");
  2590. //将数据逐步写入sheet1各个行
  2591. if (!Request.QueryString["distributorsid"].IsEmpty())
  2592. {
  2593. distributorsID = Request.QueryString["distributorsid"].ToString();
  2594. }
  2595. using (AntORM orm = new AntORM())
  2596. {
  2597. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  2598. RequestModel res = new RequestModel
  2599. {
  2600. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  2601. };
  2602. var q = orm.Queryable<EntYW_Bicycle>();
  2603. if (!cartype.IsEmpty())
  2604. {
  2605. int typecar = cartype.ToInt32();
  2606. q = q.Where(p => p.carType == typecar);
  2607. }
  2608. if (!fencetype.IsEmpty())
  2609. {
  2610. int typefence = fencetype.ToInt32();
  2611. if (typefence >= 0)
  2612. q = q.Where(p => p.FenceState == typefence);
  2613. }
  2614. if (!dptid.IsEmpty())
  2615. {
  2616. q = q.Where(p => p.DistributorsID == dptid);
  2617. }
  2618. var reslut = q.ToList(res);
  2619. if (reslut.IsSuccess)
  2620. {
  2621. List<EntYW_Bicycle> modlist = reslut.ResultModel;
  2622. for (int i = 0; i < modlist.Count; i++)
  2623. {
  2624. NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1);
  2625. rowtemp.CreateCell(0).SetCellValue(modlist[i].CarID);
  2626. rowtemp.CreateCell(1).SetCellValue(modlist[i].CarName);
  2627. rowtemp.CreateCell(2).SetCellValue(modlist[i].CarModel);
  2628. rowtemp.CreateCell(3).SetCellValue(modlist[i].carBar);
  2629. rowtemp.CreateCell(4).SetCellValue(modlist[i].DistributorsName);
  2630. string carstatestr = "";
  2631. switch (modlist[i].FenceState)
  2632. {
  2633. case 0:
  2634. carstatestr = "未点火"; break;
  2635. case 1:
  2636. carstatestr = "围栏内"; break;
  2637. case 2:
  2638. carstatestr = "围栏外"; break;
  2639. }
  2640. rowtemp.CreateCell(5).SetCellValue(carstatestr);
  2641. rowtemp.CreateCell(6).SetCellValue(modlist[i].productionDate.ToString());
  2642. rowtemp.CreateCell(7).SetCellValue(modlist[i].FactoryNumber.ToString());
  2643. //rowtemp.CreateCell(5).SetCellValue(list[i].iName);
  2644. //rowtemp.CreateCell(6).SetCellValue(list[i].iPhone);
  2645. //rowtemp.CreateCell(7).SetCellValue(list[i].IntegralSum);
  2646. //rowtemp.CreateCell(8).SetCellValue(modlist[i].OutFenceDate.ToDateTime().ToString());
  2647. //var num = DateTimeUtility.DateTimeDifference(Convert.ToDateTime(modlist[i].OutFenceDate), DateTime.Now);
  2648. //rowtemp.CreateCell(9).SetCellValue(num);
  2649. //orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  2650. //string sql = "select count(1) as num from YW_AlarmInformation where CarId='" + modlist[i].CarID + "' group by CarId";
  2651. //var sum = orm.db.ExecuteScalar(sql);
  2652. //rowtemp.CreateCell(10).SetCellValue(sum.ToDou());
  2653. }
  2654. }
  2655. }
  2656. // 写入到客户端
  2657. System.IO.MemoryStream ms = new System.IO.MemoryStream();
  2658. book.Write(ms);
  2659. ms.Seek(0, SeekOrigin.Begin);
  2660. return File(ms, "application/vnd.ms-excel", "农机信息.xls");
  2661. }
  2662. /// <summary>
  2663. /// 导出电子围栏内外的数据
  2664. /// </summary>
  2665. /// <returns></returns>
  2666. [UserAuthorizeAttribute(ModuleAlias = "machineryList", OperaAction = "List")]
  2667. public FileResult CarTripExcel()
  2668. {
  2669. //获取list数据
  2670. List<string> list = new List<string>();
  2671. //创建Excel文件的对象
  2672. NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); string distributorsID = string.Empty; string CarSate = Request.QueryString["CarSate"];
  2673. var cartype = Request.QueryString["cartype"];
  2674. var fencetype = Request.QueryString["fencetype"];
  2675. var dptid = Request.QueryString["dptid"];
  2676. var carid = Request.QueryString["carid"];
  2677. //添加一个sheet
  2678. NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
  2679. //给sheet1添加第一行的头部标题
  2680. NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
  2681. row1.CreateCell(0).SetCellValue("农机IMEI号");
  2682. row1.CreateCell(1).SetCellValue("开始时间");
  2683. row1.CreateCell(2).SetCellValue("线束时间");
  2684. row1.CreateCell(3).SetCellValue("工作时长");
  2685. //将数据逐步写入sheet1各个行
  2686. using (AntORM orm = new AntORM())
  2687. {
  2688. orm.db = DataAccessFactory.CreateDataConnection("CyclingItemLog");
  2689. RequestModel res = new RequestModel
  2690. {
  2691. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取公告信息" }
  2692. };
  2693. var q = orm.Queryable<Ent_YW_CarTrip>();
  2694. if (!carid.IsEmpty())
  2695. {
  2696. q = q.Where(p => p.IMEI == carid);
  2697. }
  2698. var reslut = q.ToList(res);
  2699. if (reslut.IsSuccess)
  2700. {
  2701. List<Ent_YW_CarTrip> modlist = reslut.ResultModel;
  2702. for (int i = 0; i < modlist.Count; i++)
  2703. {
  2704. NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1);
  2705. rowtemp.CreateCell(0).SetCellValue(modlist[i].IMEI);
  2706. rowtemp.CreateCell(1).SetCellValue(modlist[i].StartDate.ToString());
  2707. rowtemp.CreateCell(2).SetCellValue(modlist[i].EndDate.ToString());
  2708. rowtemp.CreateCell(3).SetCellValue(modlist[i].WorkingHours.ToString());
  2709. }
  2710. }
  2711. }
  2712. // 写入到客户端
  2713. System.IO.MemoryStream ms = new System.IO.MemoryStream();
  2714. book.Write(ms);
  2715. ms.Seek(0, SeekOrigin.Begin);
  2716. return File(ms, "application/vnd.ms-excel", "农机工作时长记录.xls");
  2717. }
  2718. [UserAuthorizeAttribute(ModuleAlias = "SalesCarList", OperaAction = "View")]
  2719. public ActionResult carmap(string id)
  2720. {
  2721. UserCarMapModel userCar = new UserCarMapModel();
  2722. EntYW_Bicycle mod = new EntYW_Bicycle(); string imageUrl = string.Empty;
  2723. if (!id.IsEmpty())
  2724. {
  2725. using (AntORM orm = new AntORM())
  2726. {
  2727. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  2728. RequestModel request = new RequestModel();
  2729. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" };
  2730. // Guid guid = new Guid(id);
  2731. //YW_CarHeartbeat beatmod = new YW_CarHeartbeat();
  2732. var reslut = orm.Queryable<EntYW_Bicycle>().Where(p => p.CarID == id).FirstOrDefault(request);
  2733. if (reslut.IsSuccess)
  2734. {
  2735. mod = reslut.ResultModel;
  2736. var qq = orm.Queryable<YW_CarPurchaser>().Where(p => p.carId == id).FirstOrDefault(request);
  2737. if (qq.IsSuccess)
  2738. {
  2739. YW_CarPurchaser purchaser = qq.ResultModel;
  2740. userCar.purchaserName = purchaser.userName;
  2741. userCar.purchaserTel = purchaser.userTel;
  2742. userCar.purchaserTime = purchaser.addDate.ToDateTime();
  2743. }
  2744. DateTime onlineDate = DateTime.Now;
  2745. var beatreslut = orm.Queryable<DeviceManage>().Where(p => p.IMEI == mod.CarID).FirstOrDefault();
  2746. if (beatreslut.IsSuccess)
  2747. {
  2748. DeviceManage devmod = beatreslut.ResultModel;
  2749. onlineDate = devmod.LastOnlineTime.ToDateTime();
  2750. var GPS = Ant.SuperSocket.Common.ToolGPSamap.GPSToGDGPS(devmod.longitude.ToDou(), devmod.latitude.ToDou());
  2751. userCar.lat = GPS.Split(',')[1];
  2752. userCar.lng = GPS.Split(',')[0];
  2753. userCar.LBS = devmod.IsLBS.ToBool();
  2754. }
  2755. //else
  2756. //{
  2757. // var lbsreslut = orm.Queryable<YW_CarHeartbeat>().Where(p => p.imei == mod.CarID && p.locationtype == 1).OrderByDesc(p => p.add_time).FirstOrDefault();
  2758. // if (lbsreslut.IsSuccess)
  2759. // {
  2760. // beatmod = lbsreslut.ResultModel;
  2761. // var gps = Ant.SuperSocket.Common.WebApiHelp.getLocationGPS(mod.CarID, beatmod.mcc.ToInt32(), beatmod.mnc.ToInt32(), beatmod.lac.ToInt32(), beatmod.cellID.ToInt32(), beatmod.rssi.ToInt32());
  2762. // beatmod.lng = gps.result.location.Split(',')[0].ToDec();
  2763. // beatmod.lat = gps.result.location.Split(',')[1].ToDec();
  2764. // var GPS = Ant.SuperSocket.Common.ToolGPSamap.GPSToGDGPS(beatmod.lng.ToDou(), beatmod.lat.ToDou());
  2765. // userCar.lat = GPS.Split(',')[1];
  2766. // userCar.lng = GPS.Split(',')[0];
  2767. // userCar.LBS = true;
  2768. // }
  2769. //}
  2770. userCar.distributorsName = mod.DistributorsName;
  2771. userCar.barCode = mod.carBar;
  2772. userCar.carId = mod.CarID;
  2773. userCar.isOnLine = mod.LeaseStatus.ToInt32();
  2774. userCar.carName = mod.CarName;
  2775. userCar.FactoryNumber = mod.FactoryNumber;
  2776. userCar.CarModel = mod.CarModel;
  2777. StringBuilder sb = new StringBuilder("当前车辆的");
  2778. userCar.carState = mod.CarSate.ToInt32();
  2779. userCar.carNote = GetCarState.getCarStateStr(mod.CarSate.ToInt32());
  2780. userCar.LockState = mod.LockState.ToBool();
  2781. userCar.onlineDate = "最后上报时间:" + onlineDate.ToString("yyyy-MM-dd HH:mm:ss");
  2782. string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString();
  2783. MongoDbHelper mh = new MongoDbHelper(ip, "1000");
  2784. var querywhere = MongoDB.Driver.Builders.Query<userNewCarECUInfos>.Where(xx => xx.carId == mod.CarID);
  2785. var modstate = mh.FindOne<userNewCarECUInfos>(querywhere);
  2786. if (modstate.IfNotNull())
  2787. {
  2788. userCar.hydraulic = modstate.hydraulic;
  2789. userCar.speed = modstate.speed;
  2790. userCar.temperature = modstate.temperature;
  2791. userCar.voltage = modstate.voltage;
  2792. if (userCar.hydraulic.ToInt32() > 0)
  2793. {
  2794. sb.AppendFormat("油压:" + userCar.hydraulic + "KPa");
  2795. }
  2796. if (userCar.temperature.ToInt32() > 0)
  2797. {
  2798. sb.AppendFormat("水温:" + userCar.temperature + "℃");
  2799. }
  2800. if (userCar.speed.ToInt32() > 0)
  2801. {
  2802. sb.AppendFormat("转速:" + userCar.speed);
  2803. }
  2804. if (userCar.voltage.ToInt32() > 0)
  2805. {
  2806. userCar.voltage = (userCar.voltage.ToDou()).ToString("0.00");
  2807. sb.AppendFormat("蓄电池电压:" + userCar.voltage + "V");
  2808. }
  2809. if (userCar.lat.ToDou() > 0 && userCar.lng.ToDou() > 0)
  2810. {
  2811. var resaddress = Ant.SuperSocket.Common.ToolGPSamap.GPSToPositionString(userCar.lng.ToDou(), userCar.lat.ToDou());
  2812. if (resaddress.Length > 0)
  2813. {
  2814. if (userCar.LBS)
  2815. userCar.address = "LBS位置:" + resaddress;
  2816. else
  2817. userCar.address = "GPS位置:" + resaddress;
  2818. }
  2819. }
  2820. }
  2821. else
  2822. {
  2823. userCar.hydraulic = "0";
  2824. userCar.temperature = "0";
  2825. userCar.speed = "0";
  2826. userCar.voltage = "0";
  2827. }
  2828. userCar.carType = mod.carType.ToInt32();
  2829. userCar.Note = sb.ToString();
  2830. var strurl = ((System.Web.HttpRequestWrapper)Request).Url.Authority;
  2831. var proudctline = mod.ProductLine;
  2832. switch (proudctline)
  2833. {
  2834. case 601://轮式拖拉机
  2835. {
  2836. imageUrl = "http://47.96.20.14:8086/upload/png/轮式拖拉机.png";
  2837. }
  2838. break;
  2839. case 615://轮式收割机
  2840. {
  2841. imageUrl = "http://47.96.20.14:8086/upload/png/轮式收割机.png";
  2842. }
  2843. break;
  2844. case 61101://手扶插秧机
  2845. {
  2846. imageUrl = "http://47.96.20.14:8086/upload/png/手扶插秧机.png";
  2847. }
  2848. break;
  2849. case 61102://高速插秧机
  2850. {
  2851. imageUrl = "http://47.96.20.14:8086/upload/png/高速插秧机.png";
  2852. }
  2853. break;
  2854. case 628://花生收获机
  2855. {
  2856. imageUrl = "http://47.96.20.14:8086/upload/png/花生收获机.png";
  2857. }
  2858. break;
  2859. case 612://履带收割机
  2860. {
  2861. imageUrl = "http://47.96.20.14:8086/upload/png/履带收割机.png";
  2862. }
  2863. break;
  2864. case 622://轮式玉米收
  2865. {
  2866. imageUrl = "http://47.96.20.14:8086/upload/png/轮式玉米收.png";
  2867. }
  2868. break;
  2869. default:
  2870. {
  2871. imageUrl = "http://47.96.20.14:8086/Content/map/map-marker-icon.png";
  2872. }
  2873. break;
  2874. }
  2875. userCar.imageUrl = imageUrl;
  2876. //switch (mod.carType.ToInt32())
  2877. //{
  2878. // case 1:
  2879. // {
  2880. // if (mod.LeaseStatus == 0)
  2881. // imageUrl = "http://47.96.20.14:8086/Content/map/tuolaji_hui_default.png";
  2882. // else
  2883. // imageUrl = "http://47.96.20.14:8086/Content/map/tlj.png";
  2884. // }
  2885. // break;
  2886. // case 2:
  2887. // {
  2888. // if (mod.LeaseStatus == 0)
  2889. // imageUrl = "http://47.96.20.14:8086/Content/map/shougeji_hui_default.png";
  2890. // else
  2891. // imageUrl = "http://47.96.20.14:8086/Content/map/sgj.png";
  2892. // }
  2893. // break;
  2894. // case 3:
  2895. // {
  2896. // if (mod.LeaseStatus == 0)
  2897. // imageUrl = "http://47.96.20.14:8086/Content/map/chayangji_hui_default.png";
  2898. // else
  2899. // imageUrl = "http://47.96.20.14:8086/Content/map/cyj.png";
  2900. // }
  2901. // break;
  2902. //}
  2903. //userCar.imageUrl = imageUrl;
  2904. }
  2905. }
  2906. }
  2907. return View(userCar);
  2908. }
  2909. //[UserAuthorizeAttribute(ModuleAlias = "machineryList", OperaAction = "View")]
  2910. public ActionResult machinerymap(string id)
  2911. {
  2912. UserCarMapModel userCar = new UserCarMapModel();
  2913. EntYW_Bicycle mod = new EntYW_Bicycle(); string imageUrl = string.Empty;
  2914. if (!id.IsEmpty())
  2915. {
  2916. using (AntORM orm = new AntORM())
  2917. {
  2918. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  2919. RequestModel request = new RequestModel
  2920. {
  2921. newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" }
  2922. };
  2923. // Guid guid = new Guid(id);
  2924. //YW_CarHeartbeat beatmod = new YW_CarHeartbeat();
  2925. var reslut = orm.Queryable<EntYW_Bicycle>().Where(p => p.CarID == id).FirstOrDefault(request);
  2926. if (reslut.IsSuccess)
  2927. {
  2928. mod = reslut.ResultModel;
  2929. var qq = orm.Queryable<YW_CarPurchaser>().Where(p => p.carId == id).FirstOrDefault(request);
  2930. if (qq.IsSuccess)
  2931. {
  2932. YW_CarPurchaser purchaser = qq.ResultModel;
  2933. userCar.purchaserName = purchaser.userName;
  2934. userCar.purchaserTel = purchaser.userTel;
  2935. userCar.purchaserTime = purchaser.addDate.ToDateTime();
  2936. }
  2937. //string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString();
  2938. //MongoDbHelper mh = new MongoDbHelper(ip, "1000");
  2939. //var query = Query.And(Query.EQ("imei", mod.CarID));
  2940. //var modgps = mh.FindOne<userLatestLocation>(query);
  2941. //if (modgps.IfNotNull())
  2942. //{
  2943. // var GPS = Ant.SuperSocket.Common.ToolGPSamap.GPSToGDGPS(modgps.lng.ToDou(), modgps.lat.ToDou());
  2944. // userCar.lat = GPS.Split(',')[1];
  2945. // userCar.lng = GPS.Split(',')[0];
  2946. // beatmod.add_time = modgps.add_time;
  2947. // userCar.LBS = false;
  2948. //}
  2949. var reslutgps = orm.Queryable<DeviceManage>().Where(p => p.IMEI == mod.CarID).FirstOrDefault(request);
  2950. if (reslutgps.IsSuccess)
  2951. {
  2952. DeviceManage beatenty = reslutgps.ResultModel;
  2953. userCar.lat = beatenty.latitude.ToString();
  2954. userCar.lng = beatenty.longitude.ToString();
  2955. userCar.LBS = beatenty.IsLBS.ToBool();
  2956. // userCar.onlineDate = beatenty.LastOnlineTime.ToDateTime().ToString("yyyy-MM-dd hh:mm:ss");
  2957. userCar.onlineDate = "最后上报时间:" + beatenty.LastOnlineTime.ToDateTime().ToString("yyyy-MM-dd HH:mm:ss");
  2958. }
  2959. userCar.FactoryNumber = mod.FactoryNumber;
  2960. userCar.distributorsName = mod.DistributorsName;
  2961. userCar.barCode = mod.carBar;
  2962. userCar.carId = mod.CarID;
  2963. userCar.isOnLine = mod.LeaseStatus.ToInt32();
  2964. userCar.carName = mod.CarName;
  2965. StringBuilder sb = new StringBuilder("当前车辆的");
  2966. userCar.carState = mod.CarSate.ToInt32();
  2967. userCar.carNote = GetCarState.getCarStateStr(mod.CarSate.ToInt32());
  2968. userCar.LockState = mod.LockState.ToBool();
  2969. userCar.CarModel = mod.CarModel;
  2970. //string ip = System.Web.Configuration.WebConfigurationManager.AppSettings["mongoip"].ToString();
  2971. //MongoDbHelper mh = new MongoDbHelper(ip, "1000");
  2972. //var querywhere = MongoDB.Driver.Builders.Query<userNewCarECUInfos>.Where(xx => xx.carId == mod.CarID);
  2973. //var modstate = mh.FindOne<userNewCarECUInfos>(querywhere);
  2974. //if (modstate.IfNotNull())
  2975. //{
  2976. // userCar.hydraulic = modstate.hydraulic;
  2977. // userCar.speed = modstate.speed;
  2978. // userCar.temperature = modstate.temperature;
  2979. // userCar.voltage = modstate.voltage;
  2980. // if (userCar.hydraulic.ToInt32() > 0)
  2981. // {
  2982. // sb.AppendFormat("油压:" + userCar.hydraulic + "KPa");
  2983. // }
  2984. // if (userCar.temperature.ToInt32() > 0)
  2985. // {
  2986. // sb.AppendFormat("水温:" + userCar.temperature + "℃");
  2987. // }
  2988. // if (userCar.speed.ToInt32() > 0)
  2989. // {
  2990. // sb.AppendFormat("转速:" + userCar.speed);
  2991. // }
  2992. // if (userCar.voltage.ToInt32() > 0)
  2993. // {
  2994. // userCar.voltage = (userCar.voltage.ToDou() / 1000).ToString("0.00");
  2995. // sb.AppendFormat("蓄电池电压:" + userCar.voltage + "V");
  2996. // }
  2997. // orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  2998. // string sql = "SELECT CAST(SUM(WorkingHours) AS INT) AS [C] FROM YW_CarTrip where imei='" + mod.CarID + "'";
  2999. // var sum = orm.db.ExecuteScalar(sql);
  3000. // string workhours = DateTimeUtility.MinuteToHour(sum.ToDou());
  3001. // //sb.AppendFormat("工作时长:" + workhours);
  3002. // userCar.workHours = "工作时长:" + workhours;
  3003. //}
  3004. //else
  3005. //{
  3006. // userCar.hydraulic = "0";
  3007. // userCar.temperature = "0";
  3008. // userCar.speed = "0";
  3009. // userCar.voltage = "0";
  3010. //}
  3011. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  3012. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  3013. var reslutcar = orm.Queryable<YW_CarParamDetails>().Where(p => p.imei == mod.CarID).FirstOrDefault(request);
  3014. if (reslutcar.IsSuccess)
  3015. {
  3016. YW_CarParamDetails locatmod = reslutcar.ResultModel;
  3017. userCar.hydraulic = locatmod.hydraulic + " KPa";
  3018. userCar.speed = locatmod.speed + " 转";
  3019. userCar.temperature = locatmod.temperature + " ℃";
  3020. var v = (locatmod.voltage.ToDou()).ToString("0.00");
  3021. userCar.voltage = v + " V";
  3022. }
  3023. else
  3024. {
  3025. orm.db = DataAccessFactory.CreateDataConnection("CyclingItemLog");
  3026. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  3027. var reslutparm = orm.Queryable<YW_CarParamDetails>().Where(p => p.imei == mod.CarID).FirstOrDefault(request);
  3028. if (reslutparm.IsSuccess)
  3029. {
  3030. YW_CarParamDetails locatmod = reslutparm.ResultModel;
  3031. userCar.hydraulic = locatmod.hydraulic + " KPa";
  3032. userCar.speed = locatmod.speed + " 转";
  3033. userCar.temperature = locatmod.temperature + " ℃";
  3034. var v = (locatmod.voltage.ToDou()).ToString("0.00");
  3035. userCar.voltage = v + " V";
  3036. }
  3037. else
  3038. {
  3039. userCar.hydraulic = "0 KPa";
  3040. userCar.temperature = "0 ℃";
  3041. userCar.speed = "0 转";
  3042. userCar.voltage = "0 V";
  3043. }
  3044. }
  3045. if (userCar.lat.ToDou() > 0 && userCar.lng.ToDou() > 0)
  3046. {
  3047. var resaddress = ToolGPSamap.GPSToPositionString(userCar.lng.ToDou(), userCar.lat.ToDou());
  3048. if (resaddress.Length > 0)
  3049. {
  3050. if (userCar.LBS)
  3051. userCar.address = "LBS位置:" + resaddress;
  3052. else
  3053. userCar.address = "GPS位置:" + resaddress;
  3054. }
  3055. }
  3056. userCar.carType = mod.carType.ToInt32();
  3057. userCar.Note = sb.ToString();
  3058. var strurl = ((System.Web.HttpRequestWrapper)Request).Url.Authority;
  3059. var proudctline = mod.ProductLine;
  3060. switch (proudctline)
  3061. {
  3062. case 601://轮式拖拉机
  3063. {
  3064. imageUrl = "http://47.96.20.14:8086/upload/png/轮式拖拉机.png";
  3065. }
  3066. break;
  3067. case 615://轮式收割机
  3068. {
  3069. imageUrl = "http://47.96.20.14:8086/upload/png/轮式收割机.png";
  3070. }
  3071. break;
  3072. case 61101://手扶插秧机
  3073. {
  3074. imageUrl = "http://47.96.20.14:8086/upload/png/手扶插秧机.png";
  3075. }
  3076. break;
  3077. case 61102://高速插秧机
  3078. {
  3079. imageUrl = "http://47.96.20.14:8086/upload/png/高速插秧机.png";
  3080. }
  3081. break;
  3082. case 628://花生收获机
  3083. {
  3084. imageUrl = "http://47.96.20.14:8086/upload/png/花生收获机.png";
  3085. }
  3086. break;
  3087. case 612://履带收割机
  3088. {
  3089. imageUrl = "http://47.96.20.14:8086/upload/png/履带收割机.png";
  3090. }
  3091. break;
  3092. case 622://轮式玉米收
  3093. {
  3094. imageUrl = "http://47.96.20.14:8086/upload/png/轮式玉米收.png";
  3095. }
  3096. break;
  3097. default:
  3098. {
  3099. imageUrl = "http://47.96.20.14:8086/Content/map/map-marker-icon.png";
  3100. }
  3101. break;
  3102. }
  3103. userCar.imageUrl = imageUrl;
  3104. // switch (mod.carType.ToInt32())
  3105. // {
  3106. // case 1:
  3107. // {
  3108. // if (mod.LeaseStatus == 0)
  3109. // imageUrl = "http://47.96.20.14:8086/Content/map/tuolaji_hui_default.png";
  3110. // else
  3111. // imageUrl = "http://47.96.20.14:8086/Content/map/tlj.png";
  3112. // }
  3113. // break;
  3114. // case 2:
  3115. // {
  3116. // if (mod.LeaseStatus == 0)
  3117. // imageUrl = "http://47.96.20.14:8086/Content/map/shougeji_hui_default.png";
  3118. // else
  3119. // imageUrl = "http://47.96.20.14:8086/Content/map/sgj.png";
  3120. // }
  3121. // break;
  3122. // case 3:
  3123. // {
  3124. // if (mod.LeaseStatus == 0)
  3125. // imageUrl = "http://47.96.20.14:8086/Content/map/chayangji_hui_default.png";
  3126. // else
  3127. // imageUrl = "http://47.96.20.14:8086/Content/map/cyj.png";
  3128. // }
  3129. // break;
  3130. // }
  3131. // userCar.imageUrl = imageUrl;
  3132. }
  3133. }
  3134. }
  3135. return View(userCar);
  3136. }
  3137. /// <summary>
  3138. /// 加载用户详情信息(基本)
  3139. /// </summary>
  3140. [UserAuthorizeAttribute(ModuleAlias = "salesCarList", OperaAction = "Detail")]
  3141. public ActionResult Detail(string id)
  3142. {
  3143. try
  3144. {
  3145. ViewData["distributorsid"] = Request["distributorsid"];
  3146. ViewData["distributorName"] = Request["distributorName"];
  3147. Ent_YW_Bicycle mod = new Ent_YW_Bicycle();
  3148. if (!id.IsEmpty())
  3149. {
  3150. using (AntORM orm = new AntORM())
  3151. {
  3152. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  3153. RequestModel request = new RequestModel();
  3154. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" };
  3155. mod.ID = new Guid(id);
  3156. var reslut = orm.GetEntity(mod, request);
  3157. if (reslut.IsSuccess)
  3158. {
  3159. mod = reslut.ResultModel;
  3160. }
  3161. }
  3162. }
  3163. ViewData["levels"] = this.CodeManage.LoadAll(p => p.CODETYPE == "CLLB").ToList();
  3164. ViewData["cartype"] = this.CodeManage.LoadAll(p => p.CODETYPE == "XMLX").ToList();
  3165. int uid = 0;
  3166. if (CurrentUser.USERTYPE == 2)
  3167. {
  3168. uid = CurrentUser.Id;
  3169. }
  3170. ViewBag.dpt = this.DepartmentManage.GetDepartmentByDetailNew(uid);
  3171. return View(mod);
  3172. }
  3173. catch (Exception e)
  3174. {
  3175. WriteLog(enumOperator.Select, "加载用户详情发生错误:", e);
  3176. throw e.InnerException;
  3177. }
  3178. }
  3179. /// <summary>
  3180. /// 保存农机车辆
  3181. /// </summary>
  3182. [UserAuthorizeAttribute(ModuleAlias = "salesCarList", OperaAction = "Add,Edit")]
  3183. public ActionResult Save(Ent_YW_Bicycle entity)
  3184. {
  3185. bool isEdit = false;
  3186. string disid = Request.Form["distributorsid"]; string disname = Request.Form["distributorName"];
  3187. //var mod = this.DepartmentManage.Get(p => p.ID == disid);
  3188. JsonHelper json = new JsonHelper() { Msg = "保存车辆成功", Status = "n", ReUrl = "/Car/Index" };
  3189. try
  3190. {
  3191. if (entity != null)
  3192. {
  3193. var _entity = new Ent_YW_Bicycle();
  3194. using (AntORM orm = new AntORM())
  3195. {
  3196. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  3197. if (entity.ID.IsNull())
  3198. {
  3199. var count = orm.Queryable<Ent_YW_Bicycle>().Where(p => p.CarID == entity.CarID).Count();
  3200. if (count > 0)
  3201. {
  3202. json.Msg = "二维码不能重复绑定!";
  3203. }
  3204. else
  3205. {
  3206. var num = orm.Queryable<Ent_YW_Bicycle>().Where(p => p.carBar == entity.carBar).Count();
  3207. if (num > 0)
  3208. {
  3209. json.Msg = "条码不能重复绑定!";
  3210. }
  3211. else
  3212. {
  3213. _entity = entity;
  3214. _entity.ID = Guid.NewGuid();
  3215. _entity.CreateDate = DateTime.Now;
  3216. _entity.Createper = CurrentUser.Name;
  3217. _entity.UpdateDate = DateTime.Now;
  3218. _entity.UpdateUser = this.CurrentUser.Name;
  3219. _entity.DistributorsID = disid;
  3220. _entity.DistributorsName = disname;
  3221. //_entity.CarSate = 4;
  3222. _entity.LockState = false;
  3223. RequestModel res = new RequestModel();
  3224. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" };
  3225. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  3226. var reslutsave = orm.Save(_entity, res);
  3227. if (reslutsave.IsSuccess)
  3228. {
  3229. json.Status = "y";
  3230. }
  3231. else
  3232. {
  3233. json.Msg = "保存失败";
  3234. }
  3235. }
  3236. }
  3237. }
  3238. else
  3239. {
  3240. RequestModel request = new RequestModel();
  3241. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" };
  3242. _entity.ID = entity.ID;
  3243. var reslut = orm.GetEntity(_entity, request);
  3244. if (reslut.IsSuccess)
  3245. {
  3246. _entity = reslut.ResultModel;
  3247. _entity.CarName = entity.CarName;
  3248. _entity.FactoryNumber = entity.FactoryNumber;
  3249. _entity.UpdateDate = DateTime.Now;
  3250. _entity.UpdateUser = this.CurrentUser.Name;
  3251. _entity.CarID = entity.CarID;
  3252. _entity.CarModel = entity.CarModel;
  3253. _entity.CarSate = entity.CarSate;
  3254. _entity.LeaseStatus = entity.LeaseStatus;
  3255. _entity.lang = entity.lang;
  3256. _entity.DistributorsID = disid;
  3257. _entity.carType = entity.carType;
  3258. _entity.DistributorsName = disname;
  3259. }
  3260. _entity.LockState = false;
  3261. RequestModel res = new RequestModel();
  3262. res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取单车信息" };
  3263. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  3264. var reslutsave = orm.Save(_entity, res);
  3265. if (reslutsave.IsSuccess)
  3266. {
  3267. json.Status = "y";
  3268. }
  3269. else
  3270. {
  3271. json.Msg = "保存失败";
  3272. }
  3273. }
  3274. }
  3275. //判断岗位是否重名
  3276. //if (!this.PostManage.IsExist(p => p.POSTNAME == entity.POSTNAME && p.ID != entity.ID))
  3277. //{
  3278. // if (PostManage.SaveOrUpdate(entity, isEdit))
  3279. // {
  3280. // json.Status = "y";
  3281. // }
  3282. // else
  3283. // {
  3284. // json.Msg = "保存失败";
  3285. // }
  3286. //}
  3287. //else
  3288. //{
  3289. // json.Msg = "岗位" + entity.POSTNAME + "已存在,不能重复添加";
  3290. //}
  3291. }
  3292. else
  3293. {
  3294. json.Msg = "未找到需要保存的车辆信息";
  3295. }
  3296. if (isEdit)
  3297. {
  3298. WriteLog(enumOperator.Edit, "修改车辆信息,结果:" + json.Msg, enumLog4net.INFO);
  3299. }
  3300. else
  3301. {
  3302. WriteLog(enumOperator.Add, "添加车辆信息,结果:" + json.Msg, enumLog4net.INFO);
  3303. }
  3304. }
  3305. catch (Exception e)
  3306. {
  3307. json.Msg = "保存车辆信息发生内部错误!";
  3308. WriteLog(enumOperator.None, "保存车辆信息:", e);
  3309. }
  3310. return Json(json);
  3311. }
  3312. /// <summary>
  3313. ///
  3314. /// </summary>
  3315. /// <param name="id"></param>
  3316. /// <returns></returns>
  3317. public ActionResult CarAllocateList(string id)
  3318. {
  3319. using (AntORM orm = new AntORM())
  3320. {
  3321. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  3322. RequestModel request = new RequestModel();
  3323. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  3324. var q = orm.Queryable<yw_machinery_return>().Where(p => p.carid == id);
  3325. int pageno = (page - 1) * pagesize;
  3326. var reslut = q.OrderByDesc(a => a.add_time).Skip(pageno).Top(pagesize).ToList(request);
  3327. if (reslut.IsSuccess)
  3328. {
  3329. reslut.RecordNum = q.Count();
  3330. return View(new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel)));
  3331. }
  3332. var mod = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(new List<yw_machinery_return>()));
  3333. return View(mod);
  3334. }
  3335. }
  3336. /// <summary>
  3337. /// 绑定页面需要的属性
  3338. /// </summary>
  3339. public PageInfo BindList(int posttype, string FK_DPTID, int CarSate)
  3340. {
  3341. using (AntORM orm = new AntORM())
  3342. {
  3343. orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
  3344. RequestModel request = new RequestModel();
  3345. request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询菜单的单个实体方法" };
  3346. var q = orm.Queryable<EntYW_Bicycle>();
  3347. if (!FK_DPTID.IsEmpty())
  3348. {
  3349. var resultdd = orm.Queryable<EntSYS_DISTRIBUTORS>().Where(p => p.ID == FK_DPTID && p.BUSINESSLEVEL == 1).Count();
  3350. if (resultdd == 0)
  3351. {
  3352. q = q.Where(a => a.DistributorsID == FK_DPTID);//|| a.ScenicID == FK_DPTID
  3353. }
  3354. }
  3355. if (CarSate >= 0)
  3356. {
  3357. q = q.Where(a => a.CarSate == CarSate);
  3358. }
  3359. if (!string.IsNullOrEmpty(keywords))
  3360. {
  3361. q = q.Where(p => p.CarName.Contains(keywords));
  3362. }
  3363. if (posttype > 0)
  3364. {
  3365. q = q.Where(p => p.carType == posttype);
  3366. }
  3367. int pageno = (page - 1) * pagesize;
  3368. var reslut = q.OrderBy(a => a.ID).Skip(pageno).Top(pagesize).ToList(request);
  3369. //var reslut= orm.SqlQuery<YW_Bicycle>(string.Format("select top {0} * from YW_Bicycle where Id>@Id", 1), new { Id = "sfdfdfdf" }).ToList();
  3370. if (reslut.IsSuccess)
  3371. {
  3372. reslut.RecordNum = q.Count();
  3373. List<EntYW_Bicycle> carlist = new List<EntYW_Bicycle>();
  3374. foreach (EntYW_Bicycle mod in reslut.ResultModel)
  3375. {
  3376. int num = orm.Queryable<YW_UserCar>().Where(p => p.carId == mod.CarID).Count();
  3377. if (num > 0)
  3378. {
  3379. mod.lang = "已绑定用户";
  3380. }
  3381. else
  3382. {
  3383. mod.lang = "未绑定用户";
  3384. }
  3385. carlist.Add(mod);
  3386. }
  3387. return new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(carlist));
  3388. }
  3389. else
  3390. {
  3391. return new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
  3392. }
  3393. }
  3394. //return new PageInfo(result.Index, result.PageSize, result.Count, JsonConverter.JsonClass(list));
  3395. }
  3396. }
  3397. }