第一次迭代
![loading...](https://images2015.cnblogs.com/blog/813481/201612/813481-20161220214021042-2019142479.png)
![loading...](https://images2015.cnblogs.com/blog/813481/201612/813481-20161220214044026-647247286.png)
![loading...](https://images2015.cnblogs.com/blog/813481/201612/813481-20161220214105589-484389810.png)
![loading...](https://images2015.cnblogs.com/blog/813481/201612/813481-20161220214134995-1606948841.png)
图片循序为23451
脚本代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FootGame.aspx.cs" Inherits="FootGame" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td><asp:TextBox ID="txtAsum" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="txtBsum" runat="server"></asp:TextBox></td></tr>
<tr> <td><asp:Button ID="btnAsum" runat="server" Text="加分" OnClick="btnAsum_Click" /></td>
<td><asp:Button ID="btnBsum" runat="server" Text="加分" OnClick="btnBsum_Click" />
<asp:Button ID="btnSumClear" runat="server" Text="分数清除" OnClick="btnSumClear_Click" />
</td></tr>
</table>
</div>
</form>
</body>
</html>
后台代码:
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class FootGame : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!this.Page.IsPostBack)
{
InitGamePage();
}
}
public void InitGamePage()
{
string sql = "select FootMark from dbo.FootSum";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
sda.Fill(ds);
if(ds.Tables[0].Rows.Count>0)
{
txtAsum.Text = ds.Tables[0].Rows[0]["FootMark"].ToString();
txtBsum.Text = ds.Tables[0].Rows[1]["FootMark"].ToString();
}
}
protected void btnAsum_Click(object sender, EventArgs e)
{
string sql1 = "update dbo.FootSum set FootMark=FootMark+1 where FootID=1";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
SqlCommand cmd1 = new SqlCommand(sql1,con);
con.Open();
int flag = cmd1.ExecuteNonQuery();
con.Close();
string sql = "select FootMark from dbo.FootSum where FootID=1";
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
sda.Fill(ds);
int values = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
if (values >= 3)
{
Page.ClientScript.RegisterStartupScript(this.GetType(),"","<script>alert('巴西队获胜');</script>");
}
InitGamePage();
}
protected void btnBsum_Click(object sender, EventArgs e)
{
string sql1 = "update dbo.FootSum set FootMark=FootMark+1 where FootID=2";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
SqlCommand cmd1 = new SqlCommand(sql1, con);
con.Open();
int flag = cmd1.ExecuteNonQuery();
con.Close();
string sql = "select FootMark from dbo.FootSum where FootID=2";
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
sda.Fill(ds);
int values = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
if (values >= 3)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('阿根廷队获胜');</script>");
}
InitGamePage();
}
protected void btnSumClear_Click(object sender, EventArgs e)
{
string sql = "update dbo.FootSum set FootMark=0";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
int flag = cmd.ExecuteNonQuery();
con.Close();
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('分数清除成功');</script>");
InitGamePage();
}
}
数据库代码:创建数据库
create database FirstNum
go
use FirstNum
go
create table FootSum
( FootID int primary key identity(1,1),
FootName nvarchar(50),
FootMark int
)
insert into FootSum values('巴西足球队',0);
insert into FootSum values('阿根廷足球队',0);