#求大神解决
//文件路径
string fileName = @"D:\c#\workspace\myAssignment\chepiao2.txt";
Console.WriteLine("\n\t简单客车售票系统" + "\n");
string[,] zuo = new string[9, 4];
for (int i = 0; i < 9; i++)
{
//Console.WriteLine();
for (int j = 0; j < 4; j++)
{
zuo[i,j] = "【有票】";
//Console.Write(zuo[i, j]);
}
}
string s = string.Empty;//这个是标识退出或座位的。
//读取文件中的数据
while (true)
{
using (StreamReader sr = new StreamReader(fileName))
{
//一次读取一行
string line;
while ((line = sr.ReadLine()) != null)
{
//读取到的数据输出到控制台
Console.WriteLine(line);
}
}
Console.Write("请输入作为行号和列号(例如:0,2)按q退出!");
s = Console.ReadLine();//读取输入的值。
if (s == "q") break;
try
{
string[] str = s.Split(',');//以逗号分隔。
int one = int.Parse(str[0]);
int two = int.Parse(str[1]);
while (true)
{
if (one >= zuo.GetLength(0) || two < 0
|| one >= zuo.GetLength(0) || two < 0)
{
Console.WriteLine("输入的座位号有误请重新输入");
break;
}
else if (zuo[one, two] == "【已售】" )
{
//zuo[one, two] = "【已售】";
Console.WriteLine("输入座位票已售出,请重新输入");
//zuo[one, two] = "【已售】";
break;
}
else
{
zuo[one, two] = "【已售】";
Console.WriteLine("售票成功!");
break;
}
}
}
catch (Exception)
{
Console.WriteLine("异常错误!");
}
if (s != "q")
{
//将控制台的数据写到文件中去
using (StreamWriter sw = new StreamWriter(fileName))
{
for (int i = 0; i < 9; i++)
{
string str = " ";
for (int j = 0; j < 4; j++)
{
str += zuo[i, j] + ",";
}
sw.WriteLine(str);
}
}
}
else
{
break;
}
}
Console.ReadKey();