Beispiel #1
0
        public JsonResult LineEdit()
        {
            var lineJson = Request["line"];
            var line     = JsonHelper.Deserialize <BaseLine>(lineJson);

            var updateType = line.Id > 0 ? DataUpdateType.Update : DataUpdateType.Insert;

            // 更新线路
            var lineUpdateRes = false;
            var lineBll       = new BaseLineBll();

            if (line.Id > 0)
            {
                lineUpdateRes = lineBll.Update(line);
            }
            else
            {
                var condition = string.Format("LineName='{0}' AND IsDelete=0", line.LineName);
                if (lineBll.Exists(condition))
                {
                    return(Json(ErrorModel.ExistSameItem));
                }

                var insertedLine = lineBll.Insert(line);
                lineUpdateRes = insertedLine.Id > 0;
            }

            // 更新车站
            if (lineUpdateRes)
            {
                // 写入更新记录
                DataUpdateLog.SingleUpdate(typeof(BaseLine).Name, line.Id, updateType);

                var stationsJson = Request["stations"];
                var stations     = JsonHelper.Deserialize <LineStations[]>(stationsJson);
                if (!stations.Any())
                {
                    return(Json(ErrorModel.OperateSuccess));
                }

                stations.ForEach(f => { f.LineId = line.Id; });

                var stationsToInsert = stations.Where(f => f.Id == 0);
                var lineStationsBll  = new LineStationsBll();

                var maxId = (int)lineStationsBll.GetMaxId();

                lineStationsBll.BulkInsert(stationsToInsert);

                // 写入更新记录
                DataUpdateLog.BulkUpdate(typeof(LineStations).Name, maxId);

                return(Json(ErrorModel.OperateSuccess));
            }

            return(Json(ErrorModel.OperateFailed));
        }
Beispiel #2
0
        public JsonResult DeleteLineStation(int lineStationId)
        {
            if (lineStationId == 0)
            {
                return(Json(ErrorModel.OperateSuccess));
            }

            var lineStationBll = new LineStationsBll();
            var success        = lineStationBll.Delete(lineStationId);

            if (success)
            {
                DataUpdateLog.SingleUpdate(typeof(LineStations).Name, lineStationId, DataUpdateType.Delete);

                return(Json(ErrorModel.OperateSuccess));
            }

            return(Json(ErrorModel.OperateFailed));
        }
Beispiel #3
0
        public JsonResult GetLineInfo(int id)
        {
            var lineBll  = new BaseLineBll();
            var lineData = lineBll.QuerySingle(id);

            if (lineData == null)
            {
                return(Json(ErrorModel.GetDataFailed));
            }

            var lineStationBll = new LineStationsBll();
            var lineStations   = lineStationBll.QueryList("LineId=" + id);

            var data = new
            {
                line     = lineData,
                stations = lineStations
            };

            return(Json(ErrorModel.GetDataSuccess(data)));
        }
        /// <summary>
        /// 构造线路-车站关系并写入数据库
        /// </summary>
        /// <param name="table"></param>
        private static void WriteLineStaionRelation(TimeTable table)
        {
            // 构造线路-车站关系并写入数据库
            var lineStationRelation = new List <LineStations>();

            for (var i = 0; i < table.Stations.Count; i++)
            {
                lineStationRelation.Add(new LineStations
                {
                    LineId      = table.Line.Id,
                    Sort        = i,
                    StationId   = table.Stations[i].Id,
                    StationName = table.Stations[i].StationName
                });
            }
            var lineStationsBll = new LineStationsBll();

            var startId = (int)lineStationsBll.GetMaxId(); // 记录插入之前的最大ID

            lineStationsBll.BulkInsert(lineStationRelation);
            DataUpdateLog.BulkUpdate(nameof(LineStations), startId); // 将数据更新记录同步到DbUpdataLog表中
        }
Beispiel #5
0
        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());
        }