排球积分程序
Posted 一叶影秋
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了排球积分程序相关的知识,希望对你有一定的参考价值。
流程如下
任务:作为一个排球计分员,我需要知道每场比赛队伍的得分和积分情况,以便对队伍进行排名和反馈。
计划:此程序需要2-3周
设计文档
由排球比赛用户故事的需求分析可知,此程序是用来统计各个队伍的比分和积分情况,每一次比分的改变,都要形成一条记录。
计划复审
目前在进行中
代码规范
根据Visual Studio 2010规范去写。
具体代码如下
namespace dal
{
public static class SqlHelper
{
private static readonly string constr =
ConfigurationManager.ConnectionStrings["MyPC"].ConnectionString;
ExecuteNonQuery()
ExecuteScalar()
ExecuteReader()
ExecuteDataTable()
public static int ExecuteNonQuery(string sql, params SqlParameter[] pm
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;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VolleyballBll;
using Moudel;
namespace VolleyballUI
{
public partial class Index : System.Web.UI.Page
{
private TeamBll teamBll = new TeamBll();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDropDownList();
}
}
protected void btnSaveName_Click(object sender, EventArgs e)
{
Team team = new Team();
team.Name=TeamName.Text.Trim();
if (teamBll.GetInsertTeamName(team))
{
Response.Redirect("Index.aspx");
}
else
{
Response.Write("<script>alert(‘失败‘)</script>");
}
}
public void BindDropDownList()
{
DropDownListA.DataSource = teamBll.GetSelectAllTeams();
DropDownListA.DataTextField = "Name";
DropDownListA.DataValueField = "ID";
DropDownListA.DataBind();
DropDownListB.DataSource = teamBll.GetSelectAllTeams();
DropDownListB.DataTextField = "Name";
DropDownListB.DataValueField = "ID";
DropDownListB.DataBind();
}
protected void btnSave_Click(object sender, EventArgs e)
{
if (DropDownListA.SelectedItem.Text == DropDownListB.SelectedItem.Text)
{
Response.Write("<script>alert(‘不能与己方队伍比赛!‘)</script>");
}
else
{
Response.Redirect("Main.aspx?TeamA=" + DropDownListA.SelectedItem.Text + "&TeamB=" + DropDownListB.SelectedItem.Text);
}
}
protected void btnSelect_Click(object sender, EventArgs e)
{
if (DropDownListA.SelectedItem.Text == DropDownListB.SelectedItem.Text)
{
Response.Write("<script>alert(‘不能与己方队伍比赛!‘)</script>");
}
else
{
Response.Redirect("Select.aspx?TeamA=" + DropDownListA.SelectedItem.Text + "&TeamB=" + DropDownListB.SelectedItem.Text);
}
}
}
}
以上是关于排球积分程序的主要内容,如果未能解决你的问题,请参考以下文章