作业个人

计划:

    估计该项目所用时间:   6天

开发:

  需求分析:作为一名排球比赛的观众,我希望知道每场比赛的得分,以便掌握比赛的赛程。(精确到每局得分)

  计划文档:比赛结果的查询。

 

 

 

 

 

 

  

 

 

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();
        }
    }


 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;
       }
    }

 

posted @ 2016-12-25 18:53  JM丶  阅读(144)  评论(0编辑  收藏  举报