本周作业

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了本周作业相关的知识,希望对你有一定的参考价值。

           作为一名现场记分员,我希望详细记录比赛现场比分增长情况,以便观众及运动员、教练员及时掌握比赛状况。

      积分规则

   若为3:0或3:1,胜者得3分,负者不得分。

   若为3:2,胜者2分,负者1分。

技术分享

代码

   

namespace 排球程序
{
    public partial class BeginForm : Form
    {
        public BeginForm()
        {
            InitializeComponent();
        }

     
        int scoreA = 0;
        int scoreB = 0;
        int juANum = 0;
        int juBNum = 0;
        int juCount = 1;
        string ju = "第一局";
        int ballNum = 0;  

        showForm F = null;

        private void BeginForm_Load(object sender, EventArgs e)
        {
            
            this.Location = new Point(0, 0); //等价于: form1.Left=0; form1.Right=0;
         
            //this.BackgroundImage = Image.FromFile(@"张杰与谢娜.jpeg");
        
            //this.Size = new Size(1000, 800);

            //显示时间
            string hour = (DateTime.Now.Hour).ToString();
            string minute = (DateTime.Now.Minute).ToString();
            string secound = (DateTime.Now.Second).ToString();
            CurrentTime.Text = hour + ":" + minute+":" +secound;
            timer1.Start();

           
            cmbTeam.Items.Clear();
            cmbTeam.Items.Add("<--请选择队伍(必选)-->");
            cmbTeam.Items.Add("查全部队伍");
            cmbTeam.SelectedIndex = 1;
            cmbTeamA.Items.Clear();
            cmbTeamA.Items.Add("<--请选择队伍(必选)-->");
            cmbTeamA.SelectedIndex = 0;
          
            MembersBll membersbll = new MembersBll();
            
            List<string> allTeamList = membersbll.GetTeamBNameBll("null");
            for (int i = 0; i < allTeamList.Count; i++)
            {
                cmbTeam.Items.Add(allTeamList[i]);
                cmbTeamA.Items.Add(allTeamList[i]);
            }

        }
  private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Interval = 1000;
            string hour = (DateTime.Now.Hour).ToString();//显示系统当前时间
            string minute = (DateTime.Now.Minute).ToString();
            string secound = (DateTime.Now.Second).ToString();
            CurrentTime.Text = hour + ":" + minute + ":" + secound;
            if (!(F == null || F.IsDisposed))
            {
                F.DisplayTime(CurrentTime.Text);
            }
        }

        private void btnRegister_Click(object sender, EventArgs e)
        {
            //切换到下一个选项卡
            this.tabControl1.SelectedIndex = this.tabControl1.SelectedIndex + 1;
        }




        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //切换到下一个选项卡
            this.tabControl1.SelectedIndex = this.tabControl1.SelectedIndex + 1;

        }
namespace DAL
{
    public class MembersDAL
    {  
        /// <summary>
       
        /// </summary>
        /// <param name="m">Members</param>
        /// <returns>int</returns>
        public int InsertMemberDal(Members m)
        {
            for (int i = 0; i < 1; i++)
            {
       
                string sqlIsRepeat = "select MName from Members where Number=" +
                    m.Number + " and TName=" + m.TName;
                SqlDataReader reader = SqlHelper.ExecuteReader(sqlIsRepeat);
                if (reader.HasRows)
                {
                    return 0;   //return 用于退出循环和循环所在的函数。
                } 
            }


            string sql = "insert into Members values(@MName,@TName,@Number,@Position,@Weight," +
                    "@Height,@Age,@NickName,@Strength)";
            SqlParameter[] pms = { 
                                        new SqlParameter("@MName",m.MName),
                                        new SqlParameter("@TName",m.TName),
                                        new SqlParameter("@Number",m.Number),
                                        new SqlParameter("@Position",m.Position),
                                        new SqlParameter("@Weight",m.Weight),
                                        new SqlParameter("@Height",m.Height),
                                        new SqlParameter("@Age",m.Age),
                                        new SqlParameter("@NickName",m.NickName),
                                        new SqlParameter("@Strength",m.Strength),
                                     };
            return SqlHelper.ExecuteNonQuery(sql, pms);
        }

        /// <summary>
  
        /// </summary>
        /// <param name="s">左侧下拉框选中的队伍</param>
        /// <returns></returns>
        public List<string> GetTeamBName(string tname,string mname=null)
        {
            //string sql;
            //if (mname != null)//获得队名
            //{
            //    sql = "select distinct TName from Members where TName not in(@tname)";
            //}
            //else//获得某队里的某个人的信息
            //{
            //    sql = "select * from " + tname + " where MName =‘" + mname + "‘";
            //}
            string sql = "select distinct TName from Members where TName not in(@tname)";
            List<string> teamBList = null;
            using (SqlDataReader reader = SqlHelper.ExecuteReader(sql, new SqlParameter("@tname",tname)))
            {
                if (reader.HasRows)
                {
                    teamBList = new List<string>();
                    while (reader.Read())
                    {
                        teamBList.Add(reader[0].ToString());
                    }
                }
            }
            return teamBList;
        }


        public List<string> GetTeamMembersDal(string tname, string mname = null)
        {
             string sql = "select MName from Members where TName=‘" + tname + "‘";
            //SqlParameter[] pms = { 
            //                     new SqlParameter("@tname",tname),
            //                     new SqlParameter("@mname",mname),
            //                     };
            List<string> teamBList = null;
            using (SqlDataReader reader = SqlHelper.ExecuteReader(sql))
            {
                if (reader.HasRows)
                {
                    teamBList = new List<string>();
                    while (reader.Read())
                    {
                        teamBList.Add(reader[0].ToString());
                    }
                }
            }
            return teamBList;
        }

 

namespace DAL
{
    public static  class SqlHelper
    {
        //获取连接字符串,在机房的
        //private static readonly string constr =
        //    ConfigurationManager.ConnectionStrings["ClassroomPc"].ConnectionString;
    
        private static readonly string constr =
            ConfigurationManager.ConnectionStrings["MyPC"].ConnectionString;
        /*自定义以下方法:
         ExecuteNonQuery() 方法
         ExecuteScalar()  方法
         ExecuteReader()  方法
         ExecuteDataTable() 方法*/

        //执行增删改的
        public static int ExecuteNonQuery(string sql, params SqlParameter[] pms)
        {                       
            using (SqlConnection con = new SqlConnection(constr))
            {
                //创建执行SQL命令对象
                using (SqlCommand cmd = new SqlCommand(sql, con))
                {
                    //判断是否传递了SQL参数
                    if (pms != null)
                    {
                        
                        cmd.Parameters.AddRange(pms);  
                    con.Open();
                    return cmd.ExecuteNonQuery();
                }
            }
        }


        //查询单个数据,返回类型是object;
        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();
                    return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                   
                }
                catch (Exception)
                {
                    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;
        }
    }
}

以上是关于本周作业的主要内容,如果未能解决你的问题,请参考以下文章

作业09-集合与泛型

201621044079 韩烨作业09-集合与泛型

本周作业

201621123042《java程序设计》第九次作业

软件工程第三次作业 - 每周例行汇报

本周作业