㈠、计划
①估计这个任务需要多少时间:3天
㈡、开发
①需求分析:0.5h
作为一个排球爱好者(运动员,观众)
希望得知比赛的得分,
以便掌握比赛的赛况。(胜负的结果精确到比分)
(只查询结果,不用累计加分)
表现层:①观众
(代码实现方式:winform窗体)
业务层: 判断
数据源:——→DB
②生成设计文档:3h
③设计复审(和同事审核设计文档)0.5h
④代码规范(为目前的开发制定合适的规范)
⑤具体设计:1h
把每一场的比分存到数据库中,在窗体控件中选择某一场,显示比分。
因为不会使用代码也没办法写出一个完整的程序。所以这篇博客内容只能说是一份作业,称不上是程序。
⑥具体编码:1day
class SqlHelper
{//获取连接字符串
private static readonly string constr = ConfigurationManager.ConnectionStrings["connectionStr"].ConnectionString;
//ExecuteNonQuery()方法
//ExecuteScalar()方法
//ExecuteReader()方法
//ExecuteDataTable()方法
public static int ExecuteNonQuery(string sql, params SqlParameter[] pms)
{
//使用using关键字定义一个范围,在范围结束时骸自动调用这个类实例的Dispose处理对象
using (SqlConnection con = new SqlConnection(constr))
{
//创建执行DSql命令对象
using (SqlCommand cmd = new SqlCommand(sql, con))
{
//判断是否传递了sql参数
if (pms != null)
{
//讲参数添加到Parameters集合中
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();
}
}
}
//执行返回SqlDataReader
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;
}
}
}
//执行返回DataTable
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;
}
}
class Info
{
public string Name { get; set; }
public int First { get; set; }
public int Second { get; set; }
public int Third { get; set; }
public int Fourth { get; set; }
public int Fifth { get; set; }
public int Score { get; set; }
}
private void Select1_Click_1(object sender, EventArgs e)
{
string sql = "select * from Bifen where [email protected]";
SqlParameter[] paras = new SqlParameter[]
{
new SqlParameter("@Name",Name);
};
using (SqlDataReader reader = SqlHelper.ExecuteReader(sql, paras))
{
if (reader.Read())
{
Info bf = new Info();
bf.Name = (string)reader["Name"];
bf.Second = reader.GetInt32(1);
bf.Third = reader.GetInt32(2);
bf.Fourth = reader.GetInt32(3);
bf.Fifth = reader.GetInt32(4);
bf.Score = reader.GetInt32(5);
}
}
}
}
private void button1_Click(object sender, EventArgs e)
{
if(comboBox1.selectIndex==0)
{
txtbox1.Text = bf.first.ToString();
}
if(comboBox1.selectIndex==1)
{
txtbox1.Text = bf.second.ToString();
}
if(comboBox1.selectIndex=2)
{
txtbox1.Text = bf.third.ToString();
}
if(comboBox1.selectIndex=3)
{
txtbox1.Text = bf.fourth.ToString();
}
if(comboBox1.selectIndex=4)
{
txtbox1.Text = bf.fifth.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
txtbox2.Text = bf.score.ToString();
}
⑦代码复审:30min
⑧测试(自测、修改代码、提交代码):40min
㈢、报告
①测试报告:30min
②计算工作量:20min
③事后总结,并提出过程改进计划:2h