private static string GetTrains(string f, string t) { StringBuilder sb = new StringBuilder(); List <CStationInfo> csl = new List <CStationInfo>(); List <TrainInfo> tl = TrainFactory.GetTrains(f, t, out csl); if (tl.Count > 0) { sb.AppendLine("\t找到 " + tl.Count + " 趟列车"); sb.AppendLine(string.Format("{0,-8}\t{1,3}\t{2,3}\t{3,3}\t{4,3}\t{5,4}\t{6,4}\t{7,4}", "车次", "始发站", "终点站", "发站", "发时", "到站", "到时", "历时")); foreach (TrainInfo ti in tl) { sb.AppendLine(string.Format("{0,-10}\t{1,6}\t{2,6}\t{3,6}\t{4,6}\t{5,6}\t{6,6}\t{7,6}", ti.TId, ti.FirstStation.Station, ti.EndStation.Station, ti.StartStation.Station, TrainFactory.TimeSpanToString(ti.StartStation.StartTime, "{1:00}:{2:00}"), ti.EndStation.Station, TrainFactory.TimeSpanToString(ti.EndStation.EndTime, "{1:00}:{2:00}"), TrainFactory.TimeSpanToString(ti.LastTime, "{0:00}:{1:00}", ""))); } } else if (csl.Count > 0) { sb.AppendLine("\t无直达列车,找到中转站 " + csl.Count + " 个"); sb.AppendLine(string.Format("{0,3}\t{1,5}\t{2,5}\t{3,5}\t{4,4}\t{5,4}", "中转站", "中转前历时", "中转后历时", "总历时", "发车数", "到站车数")); foreach (CStationInfo csi in csl) { sb.AppendLine(string.Format("{0,3}\t{1,10}\t{2,10}\t{3,10}\t{4,6}\t{5,8}", csi.Station, TrainFactory.TimeSpanToString(csi.BeforeTime, "{0:00}:{1:00}"), TrainFactory.TimeSpanToString(csi.AfterTime, "{0:00}:{1:00}"), TrainFactory.TimeSpanToString(csi.TotalTime, "{0:00}:{1:00}"), csi.BeforeStations, csi.AfterStations)); } } else { return("没找到" + f + "到" + t + "之间的列车!"); } return(sb.ToString()); }
private static string GetTrains(string f, string t, string c) { StringBuilder sb = new StringBuilder(); //List<CStationInfo> csl = new List<CStationInfo>(); List <TrainInfo> tl = TrainFactory.GetTrains(f, c, t); if (tl.Count > 0) { sb.AppendLine("\t查询结果"); sb.AppendLine("\t车次\t始发站\t终点站\t发 站\t发时\t到站\t到时"); foreach (TrainInfo ti in tl) { sb.AppendLine(string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", ti.TId, ti.FirstStation.Station, ti.EndStation.Station, ti.StartStation.Station, TrainFactory.TimeSpanToString(ti.StartStation.StartTime, "{1:00}:{2:00}"), ti.EndStation.Station, TrainFactory.TimeSpanToString(ti.EndStation.StartTime, "{1:00}:{2:00}"))); } } else { return(string.Format("{0} 和 {1} 之间不能直接通过 {2}中转!", f, t, c)); } return(sb.ToString()); }