private static void LoadCaches() { var stationBll = new BaseStationBll(); var trainNoBll = new TrainNoBll(); _stationCaches = stationBll.QueryList("IsDelete=0").ToList(); _trainNoCaches = trainNoBll.QueryList("IsDelete=0").ToList(); }
/// <summary> /// 将车次信息写入数据库 /// </summary> /// <param name="table"></param> private static void WriteTrainNo(TimeTable table) { var trainNoBll = new TrainNoBll(); table.TrainNo = trainNoBll.Insert(table.TrainNo); DataUpdateLog.SingleUpdate(nameof(TrainNo), table.TrainNo.Id, DataUpdateType.Insert); // 将数据更新记录同步到DbUpdataLog表中 _trainNoCaches.Add(table.TrainNo); }
/// <summary> /// 清空基础数据,将对如下表格执行 TUNCATE 操作: /// TrainMoment, TrainNoLine, LineStations, BaseStation, BaseLine, TrainNo /// 并将删除 DbUpdateLog 表中与以上表格相关的数据 /// </summary> public static void ClearBaseData() { var tables = new List <string> { "TrainMoment", "TrainNoLine", "LineStations", "BaseStation", "BaseLine", "TrainNo" }; var truncate = $"TRUNCATE TABLE {string.Join("; TRUNCATE TABLE ", tables)};"; var delete = $"DELETE FROM DbUpdateLog WHERE TableName IN( {string.Join(", ", tables.Select(s => $"'{s}'"))} );"; var bll = new TrainNoBll(); bll.ExecuteSql(truncate + delete); }
public JsonResult GetTrainNos() { var json = JqueryDataTableAjaxHelper.GetPageListJson( Request, (pageIndex, pageSize) => { var stationBll = new TrainNoBll(); int totalCount; var data = stationBll.QueryPageList(pageIndex, pageSize, "UpdateTime", true, out totalCount); return(new KeyValuePair <int, object>(totalCount, data)); } ); return(Json(json)); }
public JsonResult GetTrainNo(int id) { var trainNoBll = new TrainNoBll(); var trainNo = trainNoBll.QuerySingle("IsDelete=0 AND Id=" + id); if (trainNo == null) { return(Json(ErrorModel.GetDataFailed)); } var viewLineBll = new ViewTrainNoLIneBll(); var lines = viewLineBll.QueryList("Id=" + id); var json = ErrorModel.GetDataSuccess(new { trainNo, lines }); return(Json(json)); }
public ActionResult TrainMoment(int?trainNoId) { if (trainNoId == null) { return(RedirectToAction("TrainNo")); } var trainNoBll = new TrainNoBll(); var trainMomentBll = new ViewTrainMomentBll(); var trainNo = trainNoBll.QuerySingle(trainNoId); if (trainNo == null) { return(RedirectToAction("TrainNo")); } var moments = trainMomentBll.QueryList("TrainNoId=" + trainNoId, null, null, "Sort").ToList(); var trainMomentHasAdded = true; if (!moments.Any()) { trainMomentHasAdded = false; var lineStationBll = new LineStationsBll(); var viewTrainNoLineBll = new ViewTrainNoLIneBll(); var lines = viewTrainNoLineBll.QueryList("Id=" + trainNoId, null, null, "Sort"); var lineIds = lines.Select(item => item.LineId); var condition = string.Format("LineId IN({0})", string.Join(",", lineIds)); var stations = lineStationBll.QueryList(condition); var lineStationDic = new List <KeyValuePair <ViewTrainNoLIne, List <LineStations> > >(); lines.ForEach(line => { // 将线路与其经过的车站以键值对的方式按顺序归到一起 var theStations = stations.Where(item => item.LineId == line.LineId).OrderBy(item => item.Sort); lineStationDic.Add(new KeyValuePair <ViewTrainNoLIne, List <LineStations> >(line, theStations.ToList())); }); // 构造一个ViewTrainMoment集合以便在前台统一展示 var lineCounter = 0; var stationOrder = 0; moments = new List <ViewTrainMoment>(); lineStationDic.ForEach(item => { lineCounter++; var tempLine = item.Key; var tempSations = item.Value; var stationCounter = 0; tempSations.ForEach(t => { stationCounter++; if (lineCounter > 1 && stationCounter == 1) { // 由于上一条线的终点站与下一站的终点站相同,此处去掉后一条线的起点站 return; } stationOrder++; var model = new ViewTrainMoment(); model.FullName = trainNo.FullName; model.Sort = stationOrder; model.StationName = t.StationName; model.TrainNoId = trainNo.Id; model.TrainNoLineId = tempLine.TrainNoLineId; model.TrainStationId = t.StationId; model.LineId = t.LineId; model.LineName = tempLine.LineName; moments.Add(model); }); }); } ViewBag.Id = trainNoId; ViewBag.TrainNo = trainNo; ViewBag.Moments = moments.ToList(); ViewBag.IsFirstTime = !trainMomentHasAdded; return(View()); }
public JsonResult SaveTrainNo() { var trainNoJson = Request["trainNo"]; var trainNo = JsonHelper.Deserialize <TrainNo>(trainNoJson); if (trainNo == null) { return(Json(ErrorModel.InputError)); } var updateType = trainNo.Id > 0 ? DataUpdateType.Update : DataUpdateType.Insert; var trainNoBll = new TrainNoBll(); var updateSuccess = false; if (trainNo.Id > 0) { updateSuccess = trainNoBll.Update(trainNo); } else { // 验证是否存在相同的车次 var condition = string.Format("FullName='{0}' AND IsDelete=0", trainNo.FullName); if (trainNoBll.Exists(condition)) { return(Json(ErrorModel.ExistSameItem)); } var insertedTrainNo = trainNoBll.Insert(trainNo); updateSuccess = insertedTrainNo.Id > 0; } if (!updateSuccess) { return(Json(ErrorModel.OperateFailed)); } DataUpdateLog.SingleUpdate(typeof(TrainNo).Name, trainNo.Id, updateType); var linesJson = Request["lines"]; var lines = JsonHelper.Deserialize <TrainNoLine[]>(linesJson); if (lines == null || !lines.Any()) { return(Json(ErrorModel.InputError)); } var linesToInsert = lines.Where(line => line.Id == 0).ToArray(); if (linesToInsert.Any()) { linesToInsert.ForEach(line => { line.TrainNoId = trainNo.Id; }); var trainNoLineBll = new TrainNoLineBll(); var maxId = (int)trainNoLineBll.GetMaxId(); trainNoLineBll.BulkInsert(linesToInsert); DataUpdateLog.BulkUpdate(typeof(TrainNoLine).Name, maxId); } return(Json(ErrorModel.OperateSuccess)); }