📄 bybus.cs
字号:
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Collections;
using System.IO;
using System.Windows.Forms;
namespace BYBUS
{
class ByBus
{
string pathline = Application.StartupPath + @"\公汽线路信息.txt";
public StreamReader sread = null;
public BusLine[] line;
public Dictionary<string,BusLine> hashLine;
public List<car> [] carStation;
public ByBus()
{
carStation = new List<car>[4000];
for (int i = 0; i < 4000; i++)
{
carStation[i] = new List<car>();
}
line = new BusLine[600];
for (int i = 0; i < 600; i++)
line[i] = new BusLine();
hashLine = new Dictionary<string,BusLine>();
}
public bool LoadFromFile()
{
// StringBuilder str = new StringBuilder();
StreamReader sreadLine = null;
//StreamReader sreadStation = null;
int i = 0;
int j = 0;
char[] delimit1 = new char[] { '-' };
char[] delimit2 = new char[] { ' ' };
//从文件TEST中读取信息存放到hashline中,存放line对应的站点
try
{
sreadLine = new StreamReader(pathline);
while (!sreadLine.EndOfStream)
{
car Car = new car();
string s = sreadLine.ReadLine().Trim();
// if (s.StartsWith("L") && line[i].StationCount != 0)
//{ hashLine.Add(line[i].LineName, line[i]); i++; }
if (s.StartsWith("L"))
{
//line[i].Stations.Clear();
line[i].LineName = s;
}
else if (s.StartsWith("R") || s.StartsWith("Y"))
{
line[i].PayWay = s;
}
else if (s.Contains("F"))
{
string ss;
int k = 0;
while ((ss = sreadLine.ReadLine().Trim()).Contains("S"))
{
foreach (string st in ss.Split(delimit1))
{
Car = new car();
line[i].FStations.Add(st);
Car.F_B = "F";
Car.line = line[i].LineName;
Car.order = k++;
carStation[Int32.Parse(st.Substring(1))].Add(Car);
}
}
k = 0;
while ((ss = sreadLine.ReadLine().Trim()).Contains("S"))
{
foreach (string st in ss.Split(delimit1))
{
Car = new car();
line[i].BStations.Add(st);
Car.F_B = "B";
Car.line = line[i].LineName;
Car.order = k++;
carStation[Int32.Parse(st.Substring(1))].Add(Car);
}
}
hashLine.Add(line[i].LineName, line[i]);
i++;
}
else if (s.StartsWith("X"))
{
string ss;
int k = 0;
while ((ss = sreadLine.ReadLine().Trim()).Contains("S"))
{
foreach (string st in ss.Split(delimit1))
{
Car = new car();
line[i].FStations.Add(st);
line[i].BStations.Add(st);
Car.F_B = "X";
Car.line = line[i].LineName;
Car.order = k++;
carStation[Int32.Parse(st.Substring(1))].Add(Car);
}
}
line[i].BStations.Reverse();
hashLine.Add(line[i].LineName, line[i]);
i++;
}
else if (s.StartsWith("C"))
{
string ss;
int k = 0;
while ((ss = sreadLine.ReadLine().Trim()).Contains("S"))
{
foreach (string st in ss.Split(delimit1))
{
Car = new car();
line[i].FStations.Add(st);
line[i].BStations.Add(st);
Car.F_B = "C";
Car.line = line[i].LineName;
Car.order = k++;
carStation[Int32.Parse(st.Substring(1))].Add(Car);
}
}
hashLine.Add(line[i].LineName, line[i]);
i++;
}
}
//hashLine.Add(line[i-2].LineName, line[i]);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
sreadLine.Close();
}
return true;
}
public bool change0station(string startstation, string finishstation, out List<int> time, out List<int> pay, out List<string> lineName, out List<string> lines)
{
time = new List<int>();
pay = new List<int>();
lineName = new List<string>();
lines = new List<string>();
List<car> arr = new List<car>();
string s = "";
int t = 0;
int f = 0;
List<car> S = carStation[Int32.Parse(startstation.Substring(1))];
List<car> F = carStation[Int32.Parse(finishstation.Substring(1))];
for (int i = 0; i < S.Count; i++)
for (int j = 0; j < F.Count; j++)
{
if (S[i].line == F[j].line && S[i].F_B == F[j].F_B)
{
if (S[i].F_B == "C" || S[i].order < F[j].order || S[i].F_B=="X")
{ arr.Add(S[i]); }
}
}
if (arr.Count == 0)
return false;
else
{
foreach (car c in arr)
{
bool FB = true;
BusLine bl = hashLine[c.line];
lineName.Add(c.line);
if (c.F_B == "F" || c.F_B == "B")
{
if (c.F_B == "F")
s += "(上行线)";
else
s += "(下行线)";
}
else if (c.F_B == "X")
{
s += "(往返线)";
}
if (c.F_B == "C")
{
s += "(环线)";
if (c.order < bl.FStations.IndexOf(finishstation))
{
t = bl.FStations.IndexOf(finishstation) - c.order;
if (bl.PayWay == "Y")
{
f = 1;
}
else
{
if (t > 40) f = 3;
else f = t / 20 + 1;
}
for (int i = c.order; i <= bl.FStations.IndexOf(finishstation); i++)
{
s += bl.FStations[i] + "-";
}
}
else
{
t = bl.FStations.Count - (c.order - bl.FStations.IndexOf(finishstation));
if (bl.PayWay == "Y")
{
f = 1;
}
else
{
if (t > 40) f = 3;
else f = t / 20 + 1;
}
for (int i = c.order; i < bl.FStations.Count; i++)
{
s += bl.FStations[i]+ "-";
}
for (int j = 0; j <= bl.FStations.IndexOf(finishstation); j++)
{
s += bl.FStations[j] + "-";
}
}
s = s.Remove(s.Length - 1, 1);
}
else if (c.F_B == "F" || c.F_B == "X")
{
t = bl.FStations.IndexOf(finishstation) - bl.FStations.IndexOf(startstation);
if (bl.PayWay == "Y")
{
f = 1;
}
else
{
if (t > 40) f = 3;
else f = t / 20 + 1;
}
for (int i = bl.FStations.IndexOf(startstation); i <= bl.FStations.IndexOf(finishstation); i++)
{
s += bl.FStations[i]+ "-";
}
if (t > 0)
{
s = s.Remove(s.Length - 1, 1);
FB = false;
}
else
FB = true;
}
if (FB && ( c.F_B == "B" || c.F_B == "X"))
{
t = bl.BStations.IndexOf(finishstation) - bl.BStations.IndexOf(startstation);
if (bl.PayWay == "Y")
{
f = 1;
}
else
{
if (t > 40) f = 3;
else f = t / 20 + 1;
}
for (int i = bl.BStations.IndexOf(startstation); i <= bl.BStations.IndexOf(finishstation); i++)
{
s += bl.BStations[i] + "-";
}
if(t>0)
s = s.Remove(s.Length - 1, 1);
}
s += "\n";
time.Add(t * 3);
pay.Add(f);
lines.Add(s);
s = "";
}
return true;
}
}
public bool change1station(string startstation, string finishstation, out List<int> T, out List<int> P, out List<string> LINENAME, out List<string> LINE, string repeatline)
{
T = new List<int>();
P = new List<int>();
LINENAME = new List<string>();
LINE = new List<string>();
List<string> lines;//存取要打印的路线
List<int> time, pay;//分别存取要打印的时间和费用
List<string> lineName;//存取路线名
string outtxt = "";
ArrayList finishline = new ArrayList();
int start = Int32.Parse(startstation.Substring(1));
int finish = Int32.Parse(finishstation.Substring(1));
List<car> carStart = carStation[start];
foreach (car sline in carStart)
{
if (finishline.Contains(sline.line) || sline.line == repeatline)
{ continue; }
else
{
finishline.Add(sline.line);
}
BusLine bl = hashLine[sline.line];
if ((bl.FStations.Contains(startstation) && bl.FStations.Contains(finishstation)) || (bl.BStations.Contains(startstation) && bl.BStations.Contains(finishstation)))
{
continue;
}
if (bl.FStations.Contains(startstation))
{
for (int i = 0; i < bl.FStations.Count; i++)
{
outtxt = "";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -