计划:
估计这个任务需要多少时间完成:10天
开发:
需求分析:作为一个排球记分员,我希望能够方便的记录分数(精确到每球的的分),以便及时的把分数反映给观众。
设计文档:①排球计分程序的加减分②比赛结果的查询③比赛详细记录的查询
具体设计:
具体编码:
主页面代码
public partial class Form1 : Form
{
Action action = new Action();
public void INSERT()
{
Model M = new Model();
M.IDA = textBox1.Text.Trim().ToString();
M.IDB = textBox2.Text.Trim().ToString();
M.ONE = txtCount1.Text.Trim().Substring(4, 4);
M.TWO = txtCount2.Text.Trim().Substring(4, 4);
M.THREE = txtCount3.Text.Trim().Substring(4, 4);
if (txtCount4.Text =="")
{
M.FOUR = null;
}
else
{
M.FOUR = txtCount4.Text.Trim().Substring(4, 4);
}
if (txtCount5.Text =="")
{
M.FIVE= null;
}
else
{
M.FIVE = txtCount5.Text.Trim().Substring(4, 4);
}
M.SUM = txtH1.Text.ToString() + ":" + txtL1.Text.ToString();
M.Detail = sb.ToString();
action.InsertPK(M);
}
public Form1()
{
InitializeComponent();
}
int i = 1;
StringBuilder sb = new StringBuilder();
private void btnH_Click(object sender, EventArgs e)
{
int H = Convert.ToInt32(txtH.Text);
int L = Convert.ToInt32(txtL.Text);
int H1 = Convert.ToInt32(txtH1.Text);
int L1 = Convert.ToInt32(txtL1.Text);
txtH.Text = (H+1).ToString();
sb.AppendFormat("第{0}个球 {1}:{2}\r\n",H+1,H+1,L);
if (H >= 24 && (H - L) > 0)
{
txtH1.Text = (Convert.ToInt32(txtH1.Text) + 1).ToString();
if((H1+L1)==0){
txtCount1.Text += "第" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
}
if ((H1 + L1) == 1)
{
txtCount2.Text += "第" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
}
if ((H1 + L1) == 2)
{
txtCount3.Text += "第" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
}
if ((H1 + L1) == 3)
{
txtCount4.Text += "第" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
}
if ((H1 + L1) == 4)
{
txtCount5.Text += "第" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
}
txtH.Text = "0";
txtL.Text = "0";
if (txtH1.Text == "3")
{
MessageBox.Show("红方胜利");
INSERT();
txtH.Text = "0";
txtH1.Text = "0";
txtL.Text = "0";
txtL1.Text = "0";
txtCount1.Clear();
txtCount2.Clear();
txtCount3.Clear();
txtCount4.Clear();
txtCount5.Clear();
}
}
if (H1 + L1 > 3)
{
if (H >= 14 && (H - L) > 1)
{
txtH1.Text = (Convert.ToInt32(txtH1.Text) + 1).ToString();
if ((H1 + L1) == 4)
{
txtCount5.Text += "第" + (i++) + "局:" + txtH.Text + ":" + txtL.Text + "\r\n";
}
txtH.Text = "0";
txtL.Text = "0";
if (txtH1.Text == "3")
{
MessageBox.Show("红方胜利");
INSERT();
txtH.Text = "0";
txtH1.Text = "0";
txtL.Text = "0";
txtL1.Text = "0";
txtCount1.Clear();
txtCount2.Clear();
txtCount3.Clear();
txtCount4.Clear();
txtCount5.Clear();
i = 1;
}
}
}
}
private void btnL_Click(object sender, EventArgs e)
{
int H = Convert.ToInt32(txtH.Text);
int L = Convert.ToInt32(txtL.Text);
int H1 = Convert.ToInt32(txtH1.Text);
int L1 = Convert.ToInt32(txtL1.Text);
txtL.Text = (L+1).ToString();
sb.AppendFormat("第{0}个球 {1}:{2}\r\n", L + 1, H, L+1);
if (L>= 24&&(L-H )>0)
{
txtL1.Text = (Convert.ToInt32(txtL1.Text) + 1).ToString();
if((H1+L1)==0){
txtCount1.Text += "第" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
} if ((H1 + L1) == 1)
{
txtCount2.Text += "第" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
}
if ((H1 + L1) == 2)
{
txtCount3.Text += "第" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
}
if ((H1 + L1) == 3)
{
txtCount4.Text += "第" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
}
if ((H1 + L1) == 4)
{
txtCount5.Text += "第" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
}
txtH.Text = "0";
txtL.Text = "0";
if (txtL1.Text=="3")
{
MessageBox.Show("蓝方胜利");
INSERT();
txtH.Text = "0";
txtH1.Text = "0";
txtL.Text = "0";
txtL1.Text = "0";
txtCount1.Clear();
txtCount2.Clear();
txtCount3.Clear();
txtCount4.Clear();
txtCount5.Clear();
}
}
if(H1+L1>3)
{
if (L >= 14 && (L - H) > 1)
{
txtL1.Text = (Convert.ToInt32(txtL1.Text) + 1).ToString();
if((H1+L1)==4){
txtCount5.Text += "第" + (i++) + "局:" + txtH.Text + ":" + txtL.Text;
}
txtH.Text = "0";
txtL.Text = "0";
if (txtL1.Text == "3")
{
MessageBox.Show("蓝方胜利");
INSERT();
txtH.Text = "0";
txtH1.Text = "0";
txtL.Text = "0";
txtL1.Text = "0";
txtCount1.Clear();
txtCount2.Clear();
txtCount3.Clear();
txtCount4.Clear();
txtCount5.Clear();
i = 1;
}
}
}
}
private void btnH1_Click(object sender, EventArgs e)
{
if (int.Parse(txtH.Text) > 0)
{
txtH.Text = (Convert.ToInt32(txtH.Text) - 1).ToString();
}
}
private void btnL1_Click(object sender, EventArgs e)
{
if (int.Parse(txtH.Text) > 0)
{
txtL.Text = (Convert.ToInt32(txtL.Text) - 1).ToString();
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnDetail_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
}
}
比赛记录代码:
public partial class Form2 : Form
{
Action action = new Action();
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = action.DataGridViewLoad();
}
private void tsmdetail_Click(object sender, EventArgs e)
{
Detail D = new Detail();
D.ID = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value);
D.Show();
}
}
详细记录代码:
public partial class Detail : Form
{
Action action = new Action();
public int ID;
public Detail()
{
InitializeComponent();
}
public string SelectDetail()
{
string sql = "select Detail from ball where ID=@ID";
SqlParameter[] pms = { new SqlParameter("@ID", ID) };
string count = SqlHelper.ExecuteScalar(sql, pms).ToString();
return count;
}
private void Detail_Load(object sender, EventArgs e)
{
txtDetail.Text = SelectDetail();
}
}
方法
public class Action
{
public DataTable DataGridViewLoad()
{
string sql = "select * from ball";
//SqlConnection con = new SqlConnection("server=.;database=itcast;Integrated Security=ture;");(海峰)筱
DataTable dt = SqlHelper.ExecuteDataTable(sql);
return dt;
}
public int InsertPK(Model M)
{
string sql = "insert into ball values(@IDA,@IDB,@ONE,@TWO,@THREE,@FOUR,@FIVE,@SUM,@Detail)";
SqlParameter[] pms = { new SqlParameter("@IDA",M.IDA),
new SqlParameter("@IDB",M.IDB),
new SqlParameter("@ONE",M.ONE),
new SqlParameter("@TWO",M.TWO),
new SqlParameter("@THREE",M.THREE),
new SqlParameter("@FOUR",M.FOUR==null?DBNull.Value.ToString():M.FOUR),
new SqlParameter("@FIVE",M.FIVE==null?DBNull.Value.ToString():M.FIVE),
new SqlParameter("@SUM",M.SUM),
new SqlParameter("@Detail",M.Detail)};
int count = SqlHelper.ExecuteNonQuery(sql,pms);
return count;
}
}
public class Model
{
public string IDA { get; set; }
public string IDB { get; set; }
public string ONE { get; set; }
public string TWO { get; set; }
public string THREE { get; set; }
public string FOUR { get; set; }
public string FIVE { get; set; }
public string SUM { get; set; }
public string Detail { get; set; }
}
测试用例暂时没有完成。