开发流程如下:
·项目计划
完成这个项目需要的时间:7天
·项目开发
·需求分析:
·作为一名排球计分员,我希望在观看比赛过程中能实时记录并显示比赛双方的每一次的得分情况,以便于我能更好的去记录比赛得分,并将每一次得分实时的显示给观众(精确到每一次得分)。
·设计文档
·由排球比赛用户故事的需求分析可知,此程序是用来准确记录比赛双方的每一次得分情况,并及时显示给观众,且显示比赛的胜负结果的。
·计划复审
·正在进一步的商讨中。
·代码规范
·根据Visual Studio 2010规范去写。
·具体设计
·UML活动图:
·UML类图:
·具体编码
·部分代码如下
//Model
public class TuanDui
{ public int ID { get; set; } public string Name { get; set; } }public class JiFen
{ public int Num { get; set; } public string NameA { get; set; } public string NameB { get; set; } public int JuNum { get; set; } public int JuFenA { get; set; } public int JuFenB { get; set; } public int ZongA { get; set; } public int ZongB { get; set; } }
//volleyballDAL层
public class volleyballDAL
{public TuanDui SelectTuanDui()
{ string sql = "select * from tuandui"; TuanDui td = null; using (SqlDataReader reader = SqlHelper.ExecuteReader(sql)) { if (reader.HasRows) { while (reader.Read()) { td = new TuanDui(); td.ID = (int)reader["Id"]; td.Name = reader["Name"].ToString(); } } } return td; }
public JiFen SelectJiFen()
{ string sql = "select * from JiFen"; JiFen jf = null; using (SqlDataReader reader = SqlHelper.ExecuteReader(sql)) { if (reader.HasRows) { while (reader.Read()) { jf = new JiFen(); jf.Num = (int)reader["Num"]; jf.NameA = reader["NameA"].ToString(); jf.NameB = reader["NameB"].ToString(); jf.JuNum = (int)reader["JuNum"]; jf.JuFenA = (int)reader["JuFenA"]; jf.JuFenB = (int)reader["JuFenA"]; jf.ZongA = (int)reader["ZongA"]; jf.ZongB = (int)reader["ZongB"]; } } } return jf ;}
}SqlHelper类
public static class SqlHelper
{ //1.连接字符串 private static readonly string constr = ConfigurationManager.ConnectionStrings["itcast"].ConnectionString;//4.执行返回多个值,多行
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; } } }
//volleyballBLL层
public class volleyballBLL
{ private volleyballDAL dal = new volleyballDAL();public TuanDui GetSelectTuanDui()
{ return dal.SelectTuanDui(); }public JiFen GetSelectJiFen()
{ return dal.SelectJiFen(); }}
//volleyballUI层
public partial class volleyball : System.Web.UI.Page
{ private JuFen jf = new JuFen();private volleyballDAL dal = new volleyballDAL();
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack) { } }public void Add(string add)
{ jf.JuFenA = Convert.ToInt32(txtJuFenA.Text); jf.JuFenB = Convert.ToInt32(txtJuFenB.Text); jf.ZongA = Convert.ToInt32(txtZongA.Text); jf.ZongB = Convert.ToInt32(txtZongB.Text); jf.Num = jf.ZongA = jf.ZongB; if(add=="A1") { jf.JuFenA += 1; txtJuFenA.Text = jf.JuFenA.ToString(); PanDuan(); } else if(add=="B1") { jf.JuFenB += 1; txtJuFenB.Text=jf.JuFenB .ToString(); PanDuan(); } }public void Jian(string sub)
{ jf.JuFenA = Convert.ToInt32(txtJuFenA.Text); jf.JuFenB = Convert.ToInt32(txtJuFenB.Text); jf.ZongA = Convert.ToInt32(txtZongA.Text); jf.ZongB = Convert.ToInt32(txtZongB.Text); jf.Num = jf.ZongA +jf.ZongB; if(sub=="A2") { if (Convert.ToInt32(txtJuFenA.Text) == 0) { jf.JuFenA =0; txtJuFenA.Text = jf.JuFenA.ToString(); } else { jf.JuFenA -= 1; txtJuFenA.Text = jf.JuFenA.ToString(); }}
else if(sub == "B2") { if (Convert.ToInt32(txtJuFenB.Text) == 0) { jf.JuFenB = 0; txtJuFenB.Text = jf.JuFenB.ToString(); } else { jf.JuFenB -= 1; txtJuFenB.Text = jf.JuFenB.ToString(); } } }protected void Button1_Click(object sender, EventArgs e)
{ string add="A1"; Add(add); }protected void Button3_Click(object sender, EventArgs e)
{ string sub = "A2"; Jian(sub); }protected void Button2_Click(object sender, EventArgs e)
{ string add = "B1"; Add(add); }protected void Button4_Click(object sender, EventArgs e)
{ string sub = "B2"; Jian(sub); }public void PanDuan()
{ if (Convert.ToInt32(txtJuFenA.Text) == 25) { jf.ZongA += 1; txtZongA.Text = jf.ZongA.ToString(); txtJuFenXianShi.Text += "第" + (jf.JuNum) + "局:" + Convert.ToInt32(txtJuFenA.Text) + ":" + Convert.ToInt32(txtJuFenB.Text) + "\r\n"; } else if (Convert.ToInt32(txtJuFenB.Text) == 25) { jf.ZongB += 1; txtZongB.Text = jf.ZongB.ToString(); txtJuFenXianShi.Text += "第" + (jf.JuNum) + "局:" + Convert.ToInt32(txtJuFenA.Text) + ":" + Convert.ToInt32(txtJuFenB.Text) + "\r\n"; } }}
界面效果如下:
数据库中数据表结构如下: