就是通过打开一个csv文件,在lisbox里显示数据(已完成)、在picturebox里作图(已完成)。但是问题是现在题目要求:create a method called GetSeatColor which is passed the type of person("Adult" or "child") and returns back the correct seat color.实际上我现在的代码已经完整地把这道题做了出来,但是并没有采用并达到上面这个要求。请各位帮忙看看,如何完成上述要求。
private void fileToolStripMenuItem1_Click(object sender, EventArgs e)
{
Graphics paper = pictureBoxCinema.CreateGraphics();
DrawCinema(paper);
openFileDialog1.Filter = "CSV Files|*.CSV|ALL Files|*.*";
openFileDialog1.ShowDialog();
string[] csvArray;
string line;
//use try/catch stucture
try
{
StreamReader Readfile = File.OpenText(openFileDialog1.FileName);
while (Readfile.Peek() != -1)
{
int seat, row;
string name;
string type;
line = Readfile.ReadLine();
csvArray = line.Split(',');
seat = Convert.ToInt32(csvArray[0]);
row = Convert.ToInt32(csvArray[1]);
name = Convert.ToString(csvArray[2]);
type = Convert.ToString(csvArray[3]);
//show the content in the listBox
listBoxBookings.Items.Add(seat + " " + row + " " + name.PadRight(15) + " " + type);
//show the color of adults' and children's seats
if (type == "Adult")
{
DrawASeat(paper, (row - 1) * SeatSize, (seat - 1) * SeatSize, Color.Gold); }
if (type == "Child")
{
DrawASeat(paper, (row - 1) * SeatSize, (seat - 1) * SeatSize, Color.Purple); }
} Readfile.Close();
}
catch (Exception)
{
}
}
private void fileToolStripMenuItem1_Click(object sender, EventArgs e)
{
Graphics paper = pictureBoxCinema.CreateGraphics();
DrawCinema(paper);
openFileDialog1.Filter = "CSV Files|*.CSV|ALL Files|*.*";
openFileDialog1.ShowDialog();
string[] csvArray;
string line;
//use try/catch stucture
try
{
StreamReader Readfile = File.OpenText(openFileDialog1.FileName);
while (Readfile.Peek() != -1)
{
int seat, row;
string name;
string type;
line = Readfile.ReadLine();
csvArray = line.Split(',');
seat = Convert.ToInt32(csvArray[0]);
row = Convert.ToInt32(csvArray[1]);
name = Convert.ToString(csvArray[2]);
type = Convert.ToString(csvArray[3]);
//show the content in the listBox
listBoxBookings.Items.Add(seat + " " + row + " " + name.PadRight(15) + " " + type);
//show the color of adults' and children's seats
if (type == "Adult")
{
DrawASeat(paper, (row - 1) * SeatSize, (seat - 1) * SeatSize, Color.Gold); }
if (type == "Child")
{
DrawASeat(paper, (row - 1) * SeatSize, (seat - 1) * SeatSize, Color.Purple); }
} Readfile.Close();
}
catch (Exception)
{
}
}
解决方案 »
- 求一个sql server2005可以使用的下载连接?
- C# 仿WINDOWS
- C# 怎样循环类里面的属性?
- 解决SQL注入问题!
- 我这册CSDN近一年了,以前我发的帖子在"我的帖子"里面找不到了,怎样才能看到我以前发过得帖子?
- 怎样设定文字达到我规定的长度时自动折行?
- 奇怪的错误,请高人给看看
- 怎么把这段vb sript写的wmi脚本改写成c#语法的程序?
- 100分求13个数字(全由数字3、1或0组成)中连续3,连续1,连续0的个数的算法???
- 怎样在C#中调用AddForm这个api函数???
- 如何避免出现“未将对象引用设置到对象的实例”?
- 风生水起才知天高云淡,沧海横流方显英雄本色 百万商业圈云平台免费发布,几十万台电脑变成一台不是梦, 浮云不在浮
{
if (typeOfPerson == "Adult")
return Color.Gold;
else if (typeOfPerson == "Child")
return Color.Purple;
else
throw new Exception("invalid type of person");
}// ------------ 把你的程序中的下面这段代码改掉:
//show the color of adults' and children's seats
if (type == "Adult")
{
DrawASeat(paper, (row - 1) * SeatSize, (seat - 1) * SeatSize, Color.Gold);
}
if (type == "Child")
{
DrawASeat(paper, (row - 1) * SeatSize, (seat - 1) * SeatSize, Color.Purple);
}// ------- 改成: //show the color of adults' and children's seats
DrawASeat(paper, (row - 1) * SeatSize, (seat - 1) * SeatSize, GetSeatColor(type));