zoukankan      html  css  js  c++  java
  • ASP.NET MVC 排球计分程序 (二)一些排球计分的基本实现方式

    一、连接数据库

    新建一个MVC应用程序(基本)

    建一个HomeController

    为Index添加视图

     

    @{
    
        ViewBag.Title = "Index";
    
    }
    
     
    
    <h2>Index</h2>
    
    @using(Html.BeginForm("Indexa","Home")) {
    
     
    
      <b>id:</b>  @Html.TextBox("id",1);
    
      <b>name:</b> @Html.TextBox("name");
    
     
    
    <button type="submit">提交</button>
    
    }

    在HomeController里新建一个Action 写入连接数据库的代码

    public ActionResult Indexa()
    
            {
    
                SqlConnection conn = new SqlConnection();
    
                conn.ConnectionString = @"Data Source=.;Initial Catalog=paiqiu;Integrated Security=True";
    
                SqlCommand comm = new SqlCommand();
    
                comm.Connection = conn;
    
                string aa=Request["id"].ToString();
    
                int c = int.Parse(aa);
    
                string aaa = Request["name"].ToString();
    
             
    
                comm.CommandText = "insert into yifu (id,name) values ("+c+",'"+aaa+"')";
    
                conn.Open();
    
                int a = comm.ExecuteNonQuery();
    
                conn.Close();
    
                if (a > 0)
    
                {
    
                    ViewBag.S = "插入成功";
    
                    ViewBag.J = "插入结果为";
    
                    comm.CommandText = "select *from yifu";
    
                    conn.Open();
    
                    SqlDataReader dr = comm.ExecuteReader();
    
                    if (dr.HasRows)
    
                    {
    
                        ViewBag.a = "<table><tr><td>编号</td><td>名字</td></tr>";
    
                        while (dr.Read())
    
                        {
    
                            ViewBag.a += "<tr><td>" + dr["id"] + "</td><td>" + dr["name"] + "</td></tr>";
    
                        }
    
                    }
    
                    ViewBag.a += "</table>";
    
     
    
     
    
                }
    
                else
    
                {
    
                    ViewBag.a += "插入失败";
    
                    ViewBag.S = "";
    
                    ViewBag.J = "";
    
                }
    
                return View();
    
            }

    二 、 基本得分的实现方法

    新建一个Action

    public ActionResult Indexb()
            {
                
                return View();
            }

    为它添加视图

    @{
        ViewBag.Title = "Indexb";
    }
    
    <h2>Indexb</h2>
    @using (Html.BeginForm("Indexc", "Home"))
    { 
        string str=ViewBag.ccc;
        if (string.IsNullOrEmpty(str))
        {
            str = "0";
        }
        @Html.TextBox("number",str);
        <button type="submit">得分</button>
    }

    再添加一个Action

       

       public ActionResult Indexc()
    
            {
    
               int a=int.Parse( Request["number"]);
    
    
    
               if (a < 5)
    
               {
    
                   a++;
    
               }
    
                ViewBag.ccc = a.ToString();
    
                return View("Indexb");
    
            }

    这是这个排球计分程序的基本得分的技术实现

    经过一系列判断就会是一个比较复杂的程序

    @{

        ViewBag.Title = "Indexb";

    }

     

    <h2>Indexb</h2>

    @using (Html.BeginForm("Indexc", "Home"))

    {

        string str=ViewBag.ccc;

        if (string.IsNullOrEmpty(str))

        {

            str = "0";

        }

        @Html.TextBox("number",str);

        <buttontype="submit">得分</button>

    }

    再添加一个Action

          publicActionResult Indexc()

            {

               int a=int.Parse( Request["number"]);

     

               if (a < 5)

               {

                   a++;

               }

                ViewBag.ccc = a.ToString();

                return View("Indexb");

            }

  • 相关阅读:
    sql两个字段相加减,第三个字段没有值的原因.
    CF 447B(DZY Loves Strings-贪心)
    Appium AndroidKeyCode
    初探Java多线程
    模拟实现Spring IoC功能
    Cordova 5 架构学习 Weinre远程调试技术
    快学Scala习题解答—第三章 数组相关操作
    org.hibernate.AssertionFailure: null id in com.you.model.User entry (don&#39;t flush the Session after a
    Swift3.0语言教程替换子字符串
    DHCP欺骗(DHCP Sproofing)
  • 原文地址:https://www.cnblogs.com/zyadmin/p/7074190.html
Copyright © 2011-2022 走看看