第十六周个人作业
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十六周个人作业相关的知识,希望对你有一定的参考价值。
计划:
估计这个任务需要多少时间完成:7天
开发:
需求分析:作为一名排球比赛的观众,我希望知道每场比赛的得分,以便掌握比赛的赛程。(精确到每局得分)
设计文档:①排球计分程序的加分②比赛结果的查询
具体设计:
具体编码:
主页面代码:
public partial class Form1 : Form { Action action = new Action(); public Form1() { InitializeComponent(); } int i = 1; 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(); if (H >= 24 && (H - L) > 1) { 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(); if (L>= 24&&(L-H )>1) { 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 button1_Click(object sender, EventArgs e) { Form2 f2 = new Form2(); f2.Show(); } 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(); action.InsertPK(M); } }
查询页面代码:
public partial class Form2 : Form { Action action = new Action(); public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { dataGridView1.DataSource = action.DataGridViewLoad(); } }
model:
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 class Action { public DataTable DataGridViewLoad() { string sql = "select * from ballgeren"; //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 ballgeren values(@IDA,@IDB,@ONE,@TWO,@THREE,@FOUR,@FIVE,@SUM)"; 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)}; int count = SqlHelper.ExecuteNonQuery(sql, pms); return count; } }
其余任务暂时还未完成
以上是关于第十六周个人作业的主要内容,如果未能解决你的问题,请参考以下文章