1.计划
估计需要一周
2.需求分析
作为一名排球比赛的现场工作人员,我希望能精确统计每一名队员的得分及技术统计,以便颁发每场比赛最有价值球员奖,以及确定赛会的最佳阵容
3.设计文档
当用户进入程序时,可以看到以往队员的分数,和得分类型。可以输入球衣号,或者姓名,查询球员信息。或者点击最佳MVP按钮,会按得分高低排列,得分最高的为mvp,或者点击最佳阵容,会在文本区域显示本场最佳阵容。双击表格,可以删除所选的表格。点击编辑球员信息按钮,可以编辑球员信息。
>界面设计
活动图
具体代码:
main.cs
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 System.Data.SqlClient;
namespace 排球程序
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“volleyDataSet.Score”中。您可以根据需要移动或删除它。
this.scoreTableAdapter.Fill(this.volleyDataSet.Score);
DataGridView1DateLoad();
}
private void DataGridView1DateLoad(string sql = "select * from Score")
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Volley;Integrated Security=True");
SqlDataAdapter adapter = new SqlDataAdapter(sql,con);
DataSet ds = new DataSet();
con.Open();
adapter.Fill(ds);
con.Close();
dataGridView1.DataSource=ds.Tables[0];
}
private void butMVP_Click(object sender, EventArgs e)
{
StringBuilder sql = new StringBuilder("Select * from Score order by score desc");
DataGridView1DateLoad(sql.ToString());
}
private void buttonSelect_Click(object sender, EventArgs e)
{
string id = textBoxId.Text.Trim();
string name = textBoxName.Text.Trim();
StringBuilder sql = new StringBuilder("Select * from Score where 1=1");
if (!string .IsNullOrEmpty(id))
{
sql.Append(" and id="+id);
}
if (!string .IsNullOrEmpty(name))
{
sql.Append(" and name like '%"+name+"%'");
}
DataGridView1DateLoad(sql.ToString());
}
private void butTeamer_Click(object sender, EventArgs e)
{
StringBuilder sql = new StringBuilder("Select * from Score where scorestyle='拦网'or scorestyle='发球' or scorestyle='扣球'order by score desc");
DataGridView1DateLoad(sql.ToString());
}
private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
DialogResult result = MessageBox.Show("确定删除数据?","确定删除",MessageBoxButtons.OKCancel);
if (result==DialogResult.OK)
{
int id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value);
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Volley;Integrated Security=True");
string sql = " delect Score where id=" + id;
SqlCommand cmd = new SqlCommand(sql,con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
DataGridView1DateLoad();
}
}
private void buttonEdit_Click(object sender, EventArgs e)
{
Edit E = new Edit();
E.Show();
this.Hide();
}
}
}
Edit.cs
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 System.Data.SqlClient;
namespace 排球程序
{
public partial class Edit : Form
{
public Edit()
{
InitializeComponent();
}
private void buttonClear_Click(object sender, EventArgs e)
{
textBoxId.Text = "";
textBoxName.Text = "";
textBoxScore.Text = "";
textBoxScorestyle.Text = "";
textBoxTeam.Text = "";
}
private void buttonCofirm_Click(object sender, EventArgs e)
{
string id = textBoxId.Text.Trim();
string name = textBoxName.Text.Trim();
string team = textBoxTeam.Text.Trim();
string score = textBoxScore.Text.Trim();
string scorestyle = textBoxScorestyle.Text.Trim();
if (string .IsNullOrEmpty(id)||(string .IsNullOrEmpty(name)||(string .IsNullOrEmpty(team))||(string .IsNullOrEmpty(scorestyle))||(string .IsNullOrEmpty(score))))
{
MessageBox.Show("球衣号,姓名,队伍,得分,得分类型都不能为空");
}
else
{
SqlConnection con=new SqlConnection ("Data Source=.;Initial Catalog=Volley;Integrated Security=True") ;
string sql=string .Format(" insert into Score value('{0}','{1}','{2}','{3}','{4}')",id,name,team,score,scorestyle);
SqlCommand cmd=new SqlCommand (sql,con);
con.Open();
int count=cmd.ExecuteNonQuery();
con.Close();
if (count>0)
{
MessageBox.Show("插入队员数据成功");
}
this.Close();
}
}
}
}
代码复审:
暂未发现错误
测试:
查询功能块能够使用,编辑功能块能够使用,删除功能块可以使用
事后总结:我发现算法很重要,就像mvp的算法,我用的是得分排列的从高到低,得分最高的是第一个,也就是mvp,但是这种算法毕竟太简单了,也不太符合现实生活的情况,以后要多多学习算法。