计划
估计此程序需要8天
- 开发
- 需求分析
用户故事:作为一个排球计分人员,我希望知道每场比赛队伍得分和积分情况,以便计分,让相关人员给每队进行排名。
从分析用例故事可以知道完成此程序需要这两项任务:选择任务和查询队伍的比分和积分情况。
.设计复审:
将编写的程序进行生成,进行设计复审。看看是否生成错误,如果错误进行修改。
代码规范
SQL server2008、Visual Studio2010
具体代码
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 System.Data.SqlClient;
using Model;
namespace sceneJiFenDAL
{
public class BeginDal
{
public int Insert(Fen fen)
{
string sql = "insert into Fen values(@TeamA,@ADeFen,@TeamAFenName,@TeamB,@BDeFen,@TeamBFenName)";
SqlParameter[] paras = new SqlParameter[]{
new SqlParameter("@TeamA",fen.TeamA),
new SqlParameter("@TeamAFenName",fen.TeamAFenName),
new SqlParameter("@TeamA",fen.TeamB),
new SqlParameter("@TeamAFenName",fen.TeamBFenName)
};
int count = SqlHelper.ExecuteNonQuery(sql,paras);
return count;
}
public List<Fen> SelectAllFen()
{
string sql = "select * from Fen";
List<Fen> fenlist = new List<Fen>();
using (SqlDataReader reader = SqlHelper.ExecuteReader(sql))
{
if(reader.HasRows)
{
while (reader.Read())
{
Fen fen = new Fen();
fen.TeamA = reader.GetString(1);
fen.ADeFen = reader.GetString(2);
fen.TeamAFenName = reader.GetString(3);
fen.TeamB = reader.GetString(4);
fen.BDeFen = reader.GetString(5);
fen.TeamBFenName = reader.GetString(6);
fenlist.Add(fen);
}
}
}
return fenlist;
}
}
}
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)
{
}
}
}
个人总结:有的代码还不规范,还需要修改。