我是编程新手,需要您的帮助。我正在使用 C# Visual Studio 2010,我需要能够从文件中读取数据并将数据显示到相关的文本框中。文本文件是足球队的列表,我必须显示、编辑、删除和保存文件。我做了一些研究,并使用 YouTube 创建了使用 Stream Readers 的程序,但他们没有做我想让他们做的事情。我了解流式阅读器如何读取数据,但在相关框中逐行显示数据时遇到困难 IE:团队名称、团队经理、团队体育场等。我已经为团队制作了下面列出的课程以及我遇到问题的表单代码。任何帮助将非常感激。
我的班级:使用系统的团队;使用 System.Collections.Generic;使用 System.Linq;使用 System.Text;
namespace The_F.A__Soft130_Assignment_
{
class Team
{
private string Name;
private string League;
private string Manager;
private string Nickname;
private string Stadium;
private int Position;
private int Points;
private int GamesPlayed;
private int GoalDiff;
private string Logo;
private int NumberPlayers;
// constructor
public Team(string theName, string theLeague, string theManager,
string theNickname, string theStadium, string thePosition,
string thePoints, string theGamesPlayed,string theGoalDiff,
string theLogo, string theNumberPlayers)
{
Name = theName;
League = theLeague;
Manager = theManager;
Nickname = theNickname;
Stadium = theStadium;
setPosition(thePosition);
setPoints(thePoints);
setGamesPlayed(theGamesPlayed);
setGoalDiff(theGoalDiff);
Logo = theLogo;
setNumberPlayers(theNumberPlayers);
}
public Team(string theName, string theLeague, string theManager,
string theNickname, string theStadium,
string theLogo, string theNumberPlayers)
{
Name = theName;
League = theLeague;
Manager = theManager;
Nickname = theNickname;
Stadium = theStadium;
Logo = theLogo;
setNumberPlayers(theNumberPlayers);
}
//The getter methods
public string getName()
{
return Name;
}
public string getLeague()
{
return League;
}
public string getManager()
{
return Manager;
}
public string getNickname()
{
return Nickname;
}
public string getStadium()
{
return Stadium;
}
public int getPosition()
{
return Position;
}
public int getPoints()
{
return Points;
}
public int getGamesPlayed()
{
return GamesPlayed;
}
public int getGoalDiff()
{
return GoalDiff;
}
public string getLogo()
{
return Logo;
}
public int getNumberPlayers()
{
return NumberPlayers;
}
// all the Class setter methods
public void setName(string theName)
{
Name = theName;
}
public void setLeague(string theLeague)
{
League = theLeague;
}
public void setManager(string theManager)
{
Manager = theManager;
}
public void setNickname(string theNickname)
{
Nickname = theNickname;
}
public void setStadium(string theStadium)
{
Stadium = theStadium;
}
public void setPosition(string thePosition)
{
try
{
Position = Convert.ToInt32(thePosition);
}
catch (FormatException e)
{
System.Windows.Forms.MessageBox.Show("Error:" + e.Message
+ "Please input a valid of number");
}
}
public void setPoints(string thePoints)
{
try
{
Points = Convert.ToInt32(thePoints);
}
catch (FormatException e)
{
System.Windows.Forms.MessageBox.Show("Error:" + e.Message
+ "Please input a valid number");
}
}
public void setGamesPlayed(string theGamesPlayed)
{
try
{
GamesPlayed = Convert.ToInt32(theGamesPlayed);
}
catch (FormatException e)
{
System.Windows.Forms.MessageBox.Show("Error:" + e.Message
+ "Please in put valid number");
}
}
public void setGoalDiff(string theGoalDiff)
{
try
{
GoalDiff = Convert.ToInt32(theGoalDiff);
}
catch (FormatException e)
{
System.Windows.Forms.MessageBox.Show("Error:" + e.Message
+ "Please input valid number");
}
}
public void setLogo(string theLogo)
{
Logo = theLogo;
}
public void setNumberPlayers(string theNumberPlayers)
{
try
{
NumberPlayers = Convert.ToInt32(theNumberPlayers);
}
catch (FormatException e)
{
System.Windows.Forms.MessageBox.Show("Error:" + e.Message
+ "Please input Valid Number");
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;
namespace The_F.A__Soft130_Assignment_
{
public partial class frmEditTeam : Form
{
public frmEditTeam()
{
InitializationComponent();
}
private void InitializationComponent()
{
throw new NotImplementedException();
}
//EDIT Team --- EDIT Team --- EDIT Team --- EDIT Team --- EDIT Team --- EDIT
private void btnEdit_Click(object sender, EventArgs e)
{
bool allInputOK = false;
League whichLeague = (League)frmFA.Leagues[frmFA.leagueSelected];
//get inputs - Team ORDER = Author Title Year Copies Isbn
string tempName = txtEditTeamName.Text;
string tempLeague = txtEditTeamLeague.Text;
string tempManager = txtEditTeamManager.Text;
string tempNickname = txtEditTeamNickname.Text;
string tempStadium = txtEditTeamStadium.Text;
string templogo = txtEditTeamlogo.Text;
int tempNoOfPlayers = txtEditTeamNoofPlayers.Text;
int tempPosition;
int tempPoints;
int tempGamePlayed;
int tempGoalDiff;
//final validation check
allInputOK = Utilities.notNullTextBox(txtEditTeamName, "Team name") && Utilities.notNullTextBox(txtEditTeamLeague, "Team league")
&& Utilities.notNullTextBox(txtEditTeamManager, "Team manager") && Utilities.notNullTextBox(txtEditTeamNickname, "Team Nickname")
&& Utilities.notNullTextBox(txtEditTeamStadium, "Team stadium") && Utilities.notNullTextBox(txtEditTeamlogo, "Team logo")
&& Utilities.notNullTextBox(txtEditTeamNoofPlayers, "Team number of players")
&& Utilities.validNumber(txtTeamPosition, "The Teams Position")
&& Utilities.validNumber(txtTeamPoints, " The Teams Points") && Utilities.validNumber(txtTeamGamesPlayed, "Games Played")
&& Utilities.validNumber(txtTeamGoalDiff, " The Goal Differance");
//create Team if all ok
if (allInputOK)
{
Team temp = new Team(tempName, tempLeague, tempManager, tempNickname, tempStadium, tempPosition, tempPoints, tempGamePlayed, tempGoalDiff, templogo, tempNoOfPlayers);
whichLeague.replaceTeam(whichLeague.getleagueAllTeams(), temp,frmFA.teamselected);
Utilities.WriteAllLeagueTeams(frmFA.inputDataFile1, frmFA.Leagues);// update file
MessageBox.Show("Success: Team " + tempName + " edited in " + whichLeague.getleagueName());//finish up
resetForm();
}
}
//LOAD Team DETAILS --- LOAD Team DETAILS --- LOAD Team DETAILS --- LOAD Team DETAILS ---
private void getTeamDetails()
{
//convert this to the corrcet team reference
//int selected team = frmFA.Team Selected;
int selectedTeam = frmFA.teamSelected;
int selectedLeague = frmFA.leagueSelected;
//GET Team
//starting out with access to all the leagues
ArrayList allLeagues = frmFA.Leagues;
//narrow it down to which League you want
League currentLeague = (League)allLeagues[selectedLeague];
//narrow it down to which Team you want form that League
Team currentTeam = (Team)currentLeague.getleagueAllTeams()[selectedTeam];
//get Team details
txtEditTeamName.Text = currentTeam.getName();
txtEditTeamManager = currentTeam.getManager();
txtEditTeamStadium.Text = currentTeam.getStadium();
txtEditTeamNoofPlayers.Text = currentTeam.getNoOfPlayers();
txtEditTeamLeague.Text = currentTeam.getTeamLeague();
txtEditTeamLogo.Text = currentTeam.getTeamlogo();
}
// event procedure
private void btnHomeAdd_Team_Click(object sender, EventArgs e)
{
frmFA form = new frmFA(); form.Show();
this.Hide();
}
private void btnRefreshClick(object sender, EventArgs e)
{
Refresh();
}
private void btnEditTeamUpdate_Click(object sender, EventArgs e)
{
frmEditTeam form = new frmEditTeam();
form.Show();
this.Hide();
}
private void txtEditTeamName_TextChanged(object sender, EventArgs e)
{
getTeamName();
}
private void txtEditTeamLeague_TextChanged(object sender, EventArgs e)
{
getTeamLeague();
}
private void txtEditTeamManager_TextChanged(object sender, EventArgs e)
{
getTeamManager();
}
private void txtEditTeamNickName_TextChanged(object sender, EventArgs e)
{
getTeamNickName();
}
private void txtEditTeamStadium_TextChanged(object sender, EventArgs e)
{
getTeamStadium();
}
private void txtEditTeamLogo_TextChanged(object sender, EventArgs e)
{
getLogo();
}
private void txtEditTeamNoofPlayers_TextChanged(object sender, EventArgs e)
{
getNoOfPlayers();
}
private void txtEditTeamNickname_TextChanged_1(object sender, EventArgs e)
{
getTeamNickname();
}
private void resetForm()
{
txtName.Text = "";
txtLeague.Text = "";
txtManager.Text = "";
txtNickname.Text = "";
txtStadium.Text = "";
txtPosition.Text = "";
txtPoints.Points = "";
txtGamesPlayed.GamesPlayed = "";
txtGoalDiff.GoalDiff = "";
txtLogo.Logo = "";
txtNoOfPlayers = "";
txtName.Focus();
}
private void btnEditTeamUpdate_Click_1(object sender, EventArgs e)
{
}
private void frmEditTeam_Load(object sender, EventArgs e)
{
}
}
}