zoukankan      html  css  js  c++  java
  • 排球计分程序之三层架构

    1.计划

    估计需要两周

    2.需求分析

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

    3.设计文档

    当用户进入程序时,可以看到以往队员的分数,和得分类型双击表格。

    数据库解释:

    id表示球员球衣号

    name表示球员姓名

    teamname表示球员队伍名

    status表示球员定位

    scoreplayer1表示中国队得分选手

    totalscore1表示中国队得分

    scoreplayer2表示塞尔维亚队得分选手

    totalscore2表示塞尔维亚队得分

    具体代码:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body>
        <form id="AddInfo" action="AddInfoHandler.ashx" method="post">
            <table>
                <tr>
                    <td>球衣号:</td>
                    <td>
                        <input type="text" id="id" />
                    </td>
                </tr>
                
                <tr>
                    <td>姓名:</td>
                    <td>
                        <input type="text" name="name" />
                    </td>
                </tr>
                <tr>
                    <td>队伍名:</td>
                    <td>
                        <input type="text" teamname="teamname" />
                    </td>
                </tr>
                <tr>
                    <td>定位:</td>
                    <td>
                        <input type="text" status="status" />
                    </td>
                </tr>
                <tr>
                    <td>得分队员:</td>
                    <td>
                        <input type="text" scoreplayer1="scoreplayer1" />
                    </td>
                </tr>
                <tr>
                    <td>得分:</td>
                    <td>
                        <input type="text" totalscore1="totalscore1" />
                    </td>
                </tr>
                <tr>
                    <td>得分队员:</td>
                    <td>
                        <input type="text" scoreplayer2="scoreplayer2" />
                    </td>
                </tr>
                <tr>
                    <td>得分队员:</td>
                    <td>
                        <input type="text" totalscore2="totalscore2" />
                    </td>
                </tr>
                
                <tr>
                    <td colspan="2">
                        <input type="submit" value="添加" />
                    </td>
                </tr>
            </table>
        </form>
     public static class SqlHelper
        {

            //1.连接字符串
            private static readonly string constr = ConfigurationManager.ConnectionStrings["player"].ConnectionString;

            //2.执行增删改的
            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();
                    }
                }
            }

            //3.执行返回单个值的
            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();
                    }
                }
            }

            //4.执行返回SqlDataReader
            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;
            }

         
            internal static void ExecuteDataTable()
            {
                throw new NotImplementedException();
            }
        }
    }

    代码测试:

    添加功能和删除功能能用

    事后总结:

    三层架构不会,要多练习使用。

  • 相关阅读:
    总结的反爬虫手段(持续更新)
    爬虫类编程笔记导航
    技术开发流程小公司
    敏捷开发学习笔记(一)
    .NET Framework各版本比较
    linux shell 之 cut
    Hive insert overwrite 出现错误解决方法
    hive join
    linux shell 之 grep
    hive实现not in
  • 原文地址:https://www.cnblogs.com/shiyufan/p/6568290.html
Copyright © 2011-2022 走看看