现场计分员

计划:
大约需要两周。
需求分析:
作为一名现场记分员,我希望详细记录比赛现场比分增长情况,以便观众及运动员、教练员及时掌握比赛状况。
生成设计文档:
(1)记录每个队员的得分
(2)对发球,扣球,失误,等运动员情况进行记录。
(3)找出最佳得分球员。
(4)将个人得分,每场得分,每队的得分保存至数据库内。
设计复审:
和组成员审核设计文档。
代码规范:
以VS2010为开发环境。
具体代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

/// <summary>
///SqlHelper 的摘要说明
/// </summary>
public static class SqlHelper
{
//public SqlHelper()
//{
//
//TODO: 在此处添加构造函数逻辑
//
//private static readonly string constr = ConfigurationManager.ConnectionStrings["connectionStr"].ConnectionString;
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;
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using sceneJiFenDAL;

namespace sceneJiFenBLL
{
public class FenBLL
{
BeginDal dal = new BeginDal();
public bool Insert(Fen fen)
{

return dal.Insert(fen) > 0;
}
public List<Fen> GetAllFen()
{
return dal.SelectAllFen().Count > 0 ? dal.SelectAllFen() : null;
}
}
}

 

 

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 Model;
using sceneJiFenBLL;


namespace sceneJiFen
{
public partial class One : Form
{
public One()
{
InitializeComponent();
}
int Adefen=0;
int Bdefen = 0;
private FenBLL bll = new FenBLL();
private void button1_Click(object sender, EventArgs e)
{
Adefen++;
Fen fen=new Fen();
fen.TeamA=label1.Text;
fen.TeamB = label2.Text;
fen.ADeFen = Adefen.ToString();
if (radioBtn2.Checked == true)

fen.TeamAFenName = radioBtn2.Text;
}

if (radioButton2.Checked == true)
{
fen.TeamAFenName = radioButton2.Text;
}
if (radioButton3.Checked == true)
{
fen.TeamAFenName = radioButton3.Text;
}
if (radioButton14.Checked == true)
{
fen.TeamAFenName = radioButton14.Text;
}
if (radioButton6.Checked == true)
{
fen.TeamAFenName = radioButton6.Text;
}
if (radioButton5.Checked == true)
{
fen.TeamAFenName = radioButton5.Text;
}
if (radioButton4.Checked == true)
{
fen.TeamAFenName = radioButton4.Text;
}
if (radioButton13.Checked == true)
{
fen.TeamAFenName = radioButton13.Text;
}
//bool isOK = bll.Insert(fen);
//if(isOK)
//{
// MessageBox.Show("hhhhhh");
//}
}

private void button2_Click(object sender, EventArgs e)
{
Bdefen++;
Fen fen = new Fen();
fen.TeamA = label1.Text;
fen.TeamB = label2.Text;
fen.BDeFen = Bdefen.ToString();
if (radioButton12.Checked == true)
{
fen.TeamAFenName = radioButton12.Text;
}

if (radioButton11.Checked == true)
{
fen.TeamAFenName = radioButton11.Text;
}
if (radioButton10.Checked == true)
{
fen.TeamAFenName = radioButton10.Text;
}
if (radioButton9.Checked == true)
{
fen.TeamAFenName = radioButton9.Text;
}
if (radioButton8.Checked == true)
{
fen.TeamAFenName = radioButton8.Text;
}
if (radioButton7.Checked == true)
{
fen.TeamAFenName = radioButton7.Text;
}

}

private void One_Load(object sender, EventArgs e)
{

}
}
}

总结:用三层架构有困难。

posted @ 2017-03-17 22:53  起风了。  阅读(365)  评论(0编辑  收藏  举报