排球计分
需求分析:作为一名记分员,我需要记录比赛现场比分情况,以便观众及运动员、教练员及时掌握比赛状况
计划:估计此次工作需要两周的时间。
设计文档: 可以看到每个球员的得分情况,还可以看出每个队员在所在队伍的地位。
public static class SqlHelper
{
private static readonly string constr = ConfigurationManager.ConnectionStrings["itcast"].ConnectionString;
public static int ExecuteNonQuery(string sql, params SqlParameter[] pms)
{
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(sql, con))
{
if (pms != null)
{
cmd.Parameters.AddRange(pms);
}
con.Open();
return cmd.ExecuteNonQuery();
}
}
}
public static object ExecuteScalar(string sql, params SqlParameter[] pms)
{
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(sql, con))
{
if (pms != null)
{
cmd.Parameters.AddRange(pms);
}
con.Open();
return cmd.ExecuteScalar();
}
}
}
public static SqlDataReader ExecuteReader(string sql, params SqlParameter[] pms)
{
SqlConnection con = new SqlConnection(constr);
using (SqlCommand cmd = new SqlCommand(sql, con))
{
if (pms != null)
{
cmd.Parameters.AddRange(pms);
}
try
{
con.Open();
return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
}
catch (Exception)
{
con.Close();
con.Dispose();
throw;
}
}
}
public static DataTable ExecuteDataTable(string sql, params SqlParameter[] pms)
{
DataTable dt = new DataTable();
using (SqlDataAdapter adapter = new SqlDataAdapter(sql, constr))
{
if (pms != null)
{
adapter.SelectCommand.Parameters.AddRange(pms);
}
adapter.Fill(dt);
}
return dt;
}
}
private void btnD2_Click(object sender, EventArgs e)
{
int D1 = Convert.ToInt32(txtD1.Text);
int D2 = Convert.ToInt32(txtD2.Text);
int DD1 = Convert.ToInt32(txtDD1.Text);
int DD2 = Convert.ToInt32(txtDD2.Text);
txtD2.Text = (b++).ToString();
if (D2>= 24&&(D2-D1 )>1)
{
txtDD2.Text = (Convert.ToInt32(txtDD2.Text) + 1).ToString();
txtD1.Text = "0";
txtD2.Text = "0";
txtCount.Text += "第" + (i++)+ "局:" + txtDD1.Text + ":" + txtDD2.Text + "\r\n";
b= 1;
if (txtDD2.Text=="3")
{
MessageBox.Show("一队胜利");
txtD1.Text = "0";
txtDD1.Text = "0";
txtD2.Text = "0";
txtDD2.Text = "0";
txtCount.Clear();
}
}
if(DD1+DD2>3)
{
if (D2 >= 14 && (D2 - D1) > 1)
{
txtDD2.Text = (Convert.ToInt32(txtDD2.Text) + 1).ToString();
txtD1.Text = "0";
txtD2.Text = "0";
txtCount.Text += "第" + (i++) + "局:" + txtDD1.Text + ":" + txtDD2.Text + "\r\n";
b = 1;
if (txtDD2.Text == "3")
{
MessageBox.Show("二队胜利");
txtD1.Text = "0";
txtDD1.Text = "0";
txtD2.Text = "0";
txtDD2.Text = "0";
txtCount.Clear();
i = 1;
}
}
}
}
private void btnD1_Click(object sender, EventArgs e)
{
int D1 = Convert.ToInt32(txtD1.Text);
int D2 = Convert.ToInt32(txtD2.Text);
int DD1 = Convert.ToInt32(txtDD1.Text);
int DD2 = Convert.ToInt32(txtDD2.Text);
txtD1.Text = (a++).ToString();
if (D1 >= 24 && (D1 - D2) > 1)
{
txtDD1.Text = (Convert.ToInt32(txtDD1.Text) + 1).ToString();
txtD1.Text = "0";
txtD2.Text = "0";
txtCount.Text += "第" + (i++) + "局:" + txtDD1.Text + ":" + txtDD2.Text + "\r\n";
a = 1;
if (txtDD1.Text == "3")
{
MessageBox.Show("一队胜利");
txtD1.Text = "0";
txtDD1.Text = "0";
txtD2.Text = "0";
txtDD2.Text = "0";
txtCount.Clear();
}
}
if (DD1 + DD2 > 3)
{
if (D1 >= 14 && (D1 - D2) > 1)
{
txtDD1.Text = (Convert.ToInt32(txtDD1.Text) + 1).ToString();
txtD1.Text = "0";
txtD2.Text = "0";
txtCount.Text += "第" + (i++) + "局:" + txtDD1.Text + ":" + txtDD2.Text + "\r\n";
a = 1;
if (txtDD1.Text == "3")
{
MessageBox.Show("二队胜利");
txtD1.Text = "0";
txtDD1.Text = "0";
txtD2.Text = "0";
txtDD2.Text = "0";
txtCount.Clear();
i = 1;
}
}
}
}