首页 > 代码库 > 本学期最后作业

本学期最后作业

           排球计分

 用户故事:作为一个赛事管理人员,我希望知道每场比赛双方队伍的比分情况和整场比赛各个队伍的比分,

 以便对其进行排名。

      规则:五局三胜制

计划:大概用了一周的时间,才能实现所需要的基本功能

 技术分享

具体代码:

public BeginForm()
{
InitializeComponent();
}

//定义必要的字段,记录比赛的数据
int scoreA = 0;
int scoreB = 0;
int juANum = 0;
int juBNum = 0;
int juCount = 1;
string ju = "第一局";

private void BeginForm_Load(object sender, EventArgs e)
{
//设置窗体的位置
this.Location = new Point(0, 0);

CurrentTime.Text = (DateTime.Now).ToString();//显示系统当前时间
timer1.Start();
}

private void btnRegister_Click(object sender, EventArgs e)
{
//切换到下一个选项卡
this.tabControl1.SelectedIndex = this.tabControl1.SelectedIndex + 1;
}

TheAction action = new TheAction();

 

private void btnSubmit_Click(object sender, EventArgs e)
{
//切换到下一个选项卡
this.tabControl1.SelectedIndex = this.tabControl1.SelectedIndex + 1;

}
private void btnLogin_Click(object sender, EventArgs e)
{
MessageBox.Show("会根据登录者的身份跳转到添加或积分页面");
}


//点击添加的保存按钮时:
private void btnSave_Click(object sender, EventArgs e)
{
Members m = new Members();
m.MName = txtMName.Text.Trim();
m.TName = txtTName.Text.Trim();
m.Number = txtNumber.Text.Trim();
m.Position = txtPosition.Text.Trim();
m.Weight = txtWeight.Text.Trim();
m.Height = txtHeight.Text.Trim();

m.Age = 0;
try
{
m.Age = int.Parse(txtAge.Text.Trim());
}
catch ( ArgumentNullException )
{
MessageBox.Show("确认输入的年龄是数字吗?");
}
m.NickName = txtNickName.Text.Trim();
m.Strength = txtStrength.Text.Trim();


if (String.IsNullOrEmpty(m.MName) || String.IsNullOrEmpty(m.TName) || String.IsNullOrEmpty(m.Number)||String.IsNullOrEmpty(m.Position) ||
String.IsNullOrEmpty(m.Weight) || String.IsNullOrEmpty(m.Height))
{
MessageBox.Show("请检查是否有没填的项?");
}
else
{

//string sql0 = "select MName from Members where Number=" + m.Number + " and TName=" + m.TName;
string sql0 = string.Format("select MName from Members where Number=‘{0}‘ and TName=‘{1}‘",m.Number,m.TName);
//if (SqlHelper.ExecuteScalar(sql0).ToString()==m.MName) //这里出错了
//{
// MessageBox.Show("队员信息已经存在了呦!" + SqlHelper.ExecuteScalar(sql0).ToString());
//}
//else if (action.InsertMInfo(m)==1)
//{
if (action.InsertMInfo(m) == 1)
{
MessageBox.Show("插入成功");
}

//}

}
}
private void btnClear_Click(object sender, EventArgs e)
{

txtMName.Text = "";
txtNumber.Text = "";
txtPosition.Text = "";
txtWeight.Text = "";
txtHeight.Text = "";
txtNickName.Text = "";
txtStrength.Text = "";
}
private void btnAlter_Click(object sender, EventArgs e)
{

}

 

showForm F = null;
private void ShowScoreOnF()
{

if (F == null || F.IsDisposed) 
{
F = new showForm();
}
string[] biFen = { cmbTeamA.Text,cmbTeamB.Text,ju,
juANum.ToString(),juBNum.ToString(),
scoreA.ToString(),scoreB.ToString()};

F.DisplayScore(biFen);

F.Show();
}
private void BathDisplay()
{

gBoxNowResult.Text = ju;
juA.Text = juANum.ToString();
juB.Text = juBNum.ToString();
SA.Text = scoreA.ToString();
SB.Text = scoreB.ToString();

ShowScoreOnF();
}
private void btnStart_Click(object sender, EventArgs e)
{
BathDisplay();

}

private void ScoreDeal(string team, ref int score1, int score0, ref int juNum1,int a=1)
{
if (juCount < 5)
{
if (a == 1)
{
score1++;
}
else { score1--; }

if (!(score1 > 24 && Math.Abs(score1 - score0) >= 2))
{
BathDisplay();
}
else
{
juNum1++;
BathDisplay();
MessageBox.Show("第" + juCount + "局结束:\n " + team + "胜!");

score1 = 0;
score0 = 0;
juCount++;
ju = "第" + juCount + "局";
BathDisplay();

}
}
else//是第五局
{
score1++;
if (score1 >= 15 && Math.Abs(score1 - score0) == 2)
{
BathDisplay();
MessageBox.Show("比赛结束:\n " + team + "胜!");


}
else
{
BathDisplay();
}

}
}
private void btnAddA_Click(object sender, EventArgs e)
{
string teamA = cmbTeamA.SelectedItem.ToString();
string teamB = cmbTeamB.SelectedItem.ToString();
ScoreDeal(teamA, ref scoreA, scoreB, ref juANum);
}
private void btnAddB_Click(object sender, EventArgs e)
{
string teamA = cmbTeamA.SelectedItem.ToString();
string teamB = cmbTeamB.SelectedItem.ToString();
ScoreDeal(teamB, ref scoreB, scoreA, ref juBNum);
}
private void btnSubA_Click(object sender, EventArgs e)
{
string teamA = cmbTeamA.SelectedItem.ToString();
string teamB = cmbTeamB.SelectedItem.ToString();

ScoreDeal(teamA, ref scoreA, scoreB, ref juANum,0);
}
private void btnSubB_Click(object sender, EventArgs e)
{
string teamA = cmbTeamA.SelectedItem.ToString();
string teamB = cmbTeamB.SelectedItem.ToString();

ScoreDeal(teamB, ref scoreB, scoreA, ref juBNum,0);
}

 


private void tabControl1_Selected(object sender, TabControlEventArgs e)
{

cmbTeam.Items.Clear();
cmbTeam.Items.Add("<--请选择队伍(必选)-->");
cmbTeam.Items.Add("查全部队伍");
cmbTeam.SelectedIndex = 0;
cmbTeamA.Items.Clear();
cmbTeamA.Items.Add("<--请选择队伍(必选)-->");
cmbTeamA.SelectedIndex = 0;
string sql = "select distinct TName from Members ";
using(SqlDataReader reader = SqlHelper.ExecuteReader(sql))
{
if (reader.HasRows)
{
while (reader.Read())
{
cmbTeam.Items.Add(reader[0]);
cmbTeamA.Items.Add(reader[0]);
}
}
}


}


private void cmbTeam_SelectedIndexChanged(object sender, EventArgs e)
{
cmbMember.Items.Clear();
cmbMember.Items.Add("<--选择队员(可不选)-->");
string cmbTeam = this.cmbTeam.SelectedItem.ToString();
string sql = "select MName from Members where TName=@cmbTeam";
using(SqlDataReader reader=SqlHelper.ExecuteReader(sql,new SqlParameter("@cmbTeam",cmbTeam)))
{
if (reader.HasRows)
{
while (reader.Read())
{
cmbMember.Items.Add(reader[0]);
}
}

}
cmbMember.SelectedIndex = 0;

}


private void cmbTeamA_SelectedIndexChanged(object sender, EventArgs e)
{
string TeamA = cmbTeamA.SelectedItem.ToString();
cmbTeamB.Items.Clear();
cmbTeamB.Items.Add("<--选择队伍(必选)-->");
cmbTeamB.SelectedIndex = 0; //设置提示信息为默认选择;
string sqlB = "select distinct TName from Members where TName not in(@TeamA)";
using (SqlDataReader reader = SqlHelper.ExecuteReader(sqlB, new SqlParameter("@TeamA", TeamA)))
{
if (reader.HasRows)
{
while (reader.Read())
{
cmbTeamB.Items.Add(reader[0]);
}
}
}

}



private void btnSelect_Click(object sender, EventArgs e)
{
int teamIndex = cmbTeam.SelectedIndex;
int memberIndex = cmbMember.SelectedIndex;
string team = cmbTeam.SelectedItem.ToString();
string member = cmbMember.SelectedItem.ToString();
DataTable dt=action.SelectInfo(teamIndex, memberIndex, team, member);
//dataGridView1.DataSource = dt;

if (F != null)
{
F.txtTip.Visible = false;
}
dataGridView1.Columns.Clear();//清空列
F.dgv1.Columns.Clear();
string[] arr团队 = { "ID", "队名", "胜场", "负场", "积分", "胜局", "负局", "3-0", "3-1", "3-2", "2-3", "1-3", "0-3" };
string[] arr队员信息 = { "ID","姓名","队伍","球衣号","位置","体重","身高","年龄","外号","特长"};

string[] arr赛事记录 = {"ID","主场","客场","比赛时间","第一局","第二局","第三局","第四局","第五局","地点" };

int i = 0;
foreach (DataColumn column in dt.Columns)
{
if (dt.Columns.Count == 13)//是WFCcount的表
{

dataGridView1.Columns.Add(column.ColumnName, arr团队[i]);
F.dgv1.Columns.Add(column.ColumnName, arr团队[i]);
i++;
}


else if (dt.Columns.Count == 10)
{
dataGridView1.Columns.Add(column.ColumnName, arr队员信息[i]);
F.dgv1.Columns.Add(column.ColumnName, arr队员信息[i]);
i++;
}
else
{
dataGridView1.Columns.Add(column.ColumnName, arr赛事记录[i]);
F.dgv1.Columns.Add(column.ColumnName, arr赛事记录[i]);
i++;
}
}
dataGridView1.Rows.Clear();//清空行
F.dgv1.Rows.Clear();
foreach (DataRow line in dt.Rows)
{
dataGridView1.Rows.Add(line.ItemArray);
F.dgv1.Rows.Add(line.ItemArray);
}
dataGridView1.Columns["ID"].Visible = false;
F.dgv1.Columns["ID"].Visible = false;


}

本学期最后作业