首页 > 其他 > 详细

个人作业(18)

时间:2017-01-06 21:43:42      阅读:374      评论:0      收藏:0      [点我收藏+]

计划

        估计此程序需要5-7天。

  • 开发
  • 需求分析

   用户故事:作为一个赛事管理人员,我希望知道每场比赛队伍得分和积分情况,以便给每队进行排名。

  从分析用例故事可以知道完成此程序需要这两项任务:选择任务和查询队伍的比分和积分情况。

 

     .设计复审:

                    将编写的程序进行生成,进行设计复审。看看是否生成错误,如果错误进行修改。

     .代码规范:

                   利用VS对该程序进行代码规范。

    .活动图

技术分享

部分代码如下:

using System;

using System.Collections.Generic;

using System.Linq; using System.Text;

using System.Data.SqlClient;

using System.Data;

using System.Configuration;

namespace VolleyballDal

{     public static class SqlHelper   

  {         private static readonly string constr = ConfigurationManager.ConnectionStrings["connectionStr"].ConnectionString;   

      public static int ExecuteNonQuery(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.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();  

               }    

         }    

     }     

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

         con.Close();      

               con.Dispose();    

                 throw;      

           }

       }

  }        

         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;

        }  

   }

}

namespace VolleyballBll {     public class volleyBll  

   {         private volleyDal dal = new volleyDal();   

      public DataTable SelectScore(string team)   

      {             return dal.SelectScore(team);   

      }    

     public bool SelectScoreCount(string team)    

     {             return dal.SelectScoreCount(team);

        }  

   }

}

namespace volleyball

{     public partial class SelectScore : Form

    {         public SelectScore()   

      {             InitializeComponent();    

     }     

    private volleyBll bll = new volleyBll();

        private void dgvload(string team)  

       {             if (bll.SelectScoreCount(team))    

         {                 dgvScore.DataSource = bll.SelectScore(team);    

         }     

        else     

        {                 MessageBox.Show("找不到这个队伍的比赛记录");

             dgvScore.DataSource = bll.SelectScore(team);   

          }  

       }  

       private void SelectScore_Load(object sender, EventArgs e)  

       {

        }

        private void btnSelect_Click(object sender, EventArgs e)   

      {             string team = txtTeam.Text.Trim();   

          if (!String.IsNullOrEmpty(team))    

         {                 dgvload(team);          

                  }     

        else      

       {                 MessageBox.Show("输入队名不能为空");  

           }   

      }

    }

}

namespace VolleyballDal {    public class volleyDal   

  {        public DataTable SelectScore(string team)    

    {            string sql = "select * from VolleybalScore where Teams like ‘%"+team+"%‘";   

         DataTable dt = SqlHelper.ExecuteDataTable(sql);       

     return dt;    

    }     

   public bool SelectScoreCount(string team)   

     {            string sql = "select count(*) from VolleybalScore where Teams like ‘%" + team + "%‘";   

         int count = (int)SqlHelper.ExecuteScalar(sql);     

       return count>0;
       }

     }
  }

  

页面如下:

技术分享

个人作业(18)

原文:http://www.cnblogs.com/1243933010tt/p/6256863.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!