62,025
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Roll.aspx.cs" Inherits="Banquet.Roll" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Super SMSer/我是短信王</title>
<link href="style/Stylesheet1.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div style="position:absolute; left:20px; top:90px;">
<img src="images/2010-03-25_945.jpg" />
</div>
<div style="position:absolute; right:5px; top:28px; width:800px; text-align:center;">
<asp:Label ID="Label3" runat="server" Text="三" CssClass="lblTest">
</asp:Label>
<asp:Label ID="Label6" runat="server" Text="" Width="85px"></asp:Label>
<asp:Label ID="Label4" runat="server" Text="等" CssClass="lblTest"></asp:Label>
<asp:Label ID="Label7" runat="server" Text="" Width="85px"></asp:Label>
<asp:Label ID="Label5" runat="server" Text="奖" CssClass="lblTest">
</asp:Label>
</div>
<div style="position:absolute; right:5px; top:180px;">
<table border="0" cellspacing="0" cellpadding="0"
style="background-repeat: no-repeat" align="right" height="400">
<tr>
<td valign="top">
<table width="740" border="0" cellspacing="0" cellpadding="0" align="right">
<tr>
<td align="center" valign="middle">
<!-- input beging-->
<asp:UpdatePanel ID="upnlGrid" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div style=" width: 740px;">
<asp:Panel ID="Panel1" runat="server" Visible="true">
<table style="width:100%; text-align:center;">
<tr>
<td><asp:Image ID="Image1" runat="server"
ImageUrl="~/images/31.jpg" />
<asp:Image ID="Image2" runat="server"
ImageUrl="~/images/32.jpg" />
<asp:Image ID="Image3" runat="server"
ImageUrl="~/images/33.jpg" />
</td>
</tr>
</table></asp:Panel>
</div>
<asp:Timer ID="TimerRepresentation" runat="server"
OnTick="TimerRepresentation_Tick" Enabled="False" Interval="50" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnStart" />
<asp:AsyncPostBackTrigger ControlID="btnEnd" />
</Triggers>
</asp:UpdatePanel>
<!-- input over-->
</td>
</tr>
</table>
</td>
</tr>
<tr style="height:20px;">
<td></td>
</tr>
</table>
</div>
<div style="position:absolute; right:5px; top:110px; width:720px;">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlGrid" runat="server" Visible="False" style="text-align:right;">
<table class="gridView">
<tr>
<td style="text-align:center; width:220px;">
<asp:Label ID="lblNum" runat="server" Text="号码/Number" Visible="false"></asp:Label>
</td>
<td style="text-align:left; width:500px;">
<asp:Label ID="Label2" runat="server" Text="内容/Content" Visible="false"></asp:Label>
</td>
<%--<td>
<asp:Label ID="Label3" runat="server" Text="时间/Time" Visible="false"></asp:Label>
</td>--%>
</tr>
<asp:Repeater ID="RepeaterMessage" runat="server">
<ItemTemplate>
<tr style="height:32px;">
<td style="width:220px; text-align:center;">
<asp:Label ID="lblMobile" runat="server" Text='<%#Eval("mobile") %>' Width="220px"></asp:Label>
</td>
<td style="width:500px; text-align:left;">
<%--<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("message")%>' CssClass="textBox" />--%>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("message") %>' Width="500px" CssClass="gridConten"></asp:Label>
</td>
<%--<td style="width:250px; text-align:center;">
<asp:Label ID="Label4" runat="server" Text='<%#Eval("RecieveTime") %>' Width="270px"></asp:Label>
</td>--%>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</asp:Panel>
</ContentTemplate><Triggers>
<asp:AsyncPostBackTrigger ControlID="btnStart" />
<asp:AsyncPostBackTrigger ControlID="btnEnd" />
<asp:AsyncPostBackTrigger ControlID="TimerRepresentation" />
</Triggers>
</asp:UpdatePanel>
</div>
<div style="position:fixed; right:5px; bottom:40px; text-align:center; width:740px;">
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<div style="text-align:center;">
<asp:Button ID="btnStart" runat="server" Text="Start"
onclick="btnStart_Click" CssClass="btnStart" />
<asp:Button ID="btnRedirect" runat="server" Text="抽取二等奖" CssClass="btnStart" onclick="btnRedirect_Click" Visible="false" />
<asp:Button ID="btnEnd" runat="server" Text="End" Enabled="False"
onclick="btnEnd_Click" CssClass="btnStart" />
<asp:Button ID="Button1" runat="server" Text="查看中奖号码" CssClass="btnStart" onclick="Button1_Click" Visible="false" />
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnStart" />
<asp:AsyncPostBackTrigger ControlID="btnEnd" />
</Triggers>
</asp:UpdatePanel>
</div>
<div style="position:fixed; right:5px; bottom:0px;">
<table style="text-align:right; vertical-align:middle;">
<tr><td>
<a class="ahref" href="RoolSecond.aspx">抽取二等奖</a></td></tr>
<tr><td><a class="ahref" href="Winner.aspx?flag=3">查看中奖号码</a></td></tr>
</table>
</div>
<div style="position:absolute; top:10px; right:5px; z-index:4;">
<asp:UpdatePanel ID="upnl" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Image ID="Image4" runat="server" Height="110px"
ImageUrl="~/images/31.jpg" Visible="false" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnStart" />
<asp:AsyncPostBackTrigger ControlID="btnEnd" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
namespace Banquet
{
public partial class Roll : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.TimerRepresentation.Interval = 50;
int count = Convert.ToInt32(SqlHelper.ExecuteScalar("select count(*) from Winner where WinnerLevel='3'"));
if (count == 0)
{
ViewState.Add("state", 0);
}
else if (count > 0 && count <= 10)
{
ViewState.Add("state", 1);
}
else if (count > 10 && count <= 20)
{
ViewState.Add("state", 2);
}
else
{
this.btnStart.Enabled = false;
this.btnStart.Visible = false;
this.btnEnd.Visible = false;
this.btnRedirect.Visible = true;
this.Button1.Visible = true;
}
}
}
protected void TimerRepresentation_Tick(object sender, EventArgs e)
{
DataTable dt = ViewState["vsDt"] as DataTable;
if (dt == null || dt.Rows.Count == 0)
{
string startTime = Convert.ToString(Session["startTime"]);
string endTime = Convert.ToString(Session["endTime"]);
dt = SqlHelper.ExecuteTable(
string.Format("[SMS].[dbo].[sp_SelectAllRecieveSMS] @StartTime='{0}', @EndTime='{1}'", startTime, endTime));
ViewState["vsDt"] = dt;
if (dt.Rows.Count == 0)
{
this.TimerRepresentation.Enabled = false;
return;
}
}
if (dt.Rows.Count == 0)
{
this.TimerRepresentation.Enabled = false;
return;
}
DataTable tmp = dt.Clone();
List<string> lstPhone = new List<string>();
Random r = new Random();
for (int i = 0; i < 10; i++)
{
int row = r.Next(0, dt.Rows.Count - 1);
while (lstPhone.Contains(dt.Rows[row]["Mobile"].ToString()))
{
row = r.Next(0, dt.Rows.Count - 1);
}
lstPhone.Add(dt.Rows[row]["Mobile"].ToString());
DataRow dr = tmp.NewRow();
for (int j = 0; j < dt.Rows[row].ItemArray.Length; j++)
{
dr[j] = dt.Rows[row].ItemArray[j];
}
tmp.Rows.Add(dr);
}
RepeaterMessage.DataSource = tmp;
RepeaterMessage.DataBind();
}
protected void btnStart_Click(object sender, EventArgs e)
{
Hide();
int state = 0;
if (ViewState["state"] == null)
{
ViewState.Add("state", 0);
}
else
{
state = Convert.ToInt32(ViewState["state"]);
}
state++;
ViewState["state"] = state;
switch (state)
{
case 1:
this.Image4.ImageUrl = "~/images/31.jpg";
break;
case 2:
this.Image4.ImageUrl = "~/images/32.jpg";
break;
case 3:
this.Image4.ImageUrl = "~/images/33.jpg";
break;
default:
this.Image4.Visible = false;
break;
}
this.TimerRepresentation.Enabled = true;
this.btnEnd.Enabled = true;
this.btnStart.Enabled = false;
string startTime = Convert.ToString(Session["startTime"]);
string endTime = Convert.ToString(Session["endTime"]);
DataTable dt = SqlHelper.ExecuteTable(
string.Format("sp_SelectAllRecieveSMS @StartTime='{0}', @EndTime='{1}'", startTime, endTime));
ViewState.Add("vsDt", dt);
if (dt.Rows.Count <= 10)
{
this.TimerRepresentation.Enabled = false;
this.btnEnd.Enabled = false;
}
}
protected void btnEnd_Click(object sender, EventArgs e)
{
int state = 0;
if (ViewState["state"] == null)
{
ViewState.Add("state", 0);
}
else
{
state = Convert.ToInt32(ViewState["state"]);
}
this.TimerRepresentation.Enabled = false;
this.btnEnd.Enabled = false;
this.btnStart.Enabled = true;
this.btnStart.Text = "Start";
List<string> lstPhone = new List<string>();
foreach (RepeaterItem ri in RepeaterMessage.Items)
{
Label lbl = ri.FindControl("lblMobile") as Label;
lstPhone.Add(lbl.Text);
}
int count = Convert.ToInt32(SqlHelper.ExecuteScalar("select count(*) from Winner where WinnerLevel='3'"));
foreach (string phone in lstPhone)
{
SqlHelper.ExecuteNonQuery(string.Format("INSERT INTO [SMS].[dbo].[Winner] ([WinnerMobile] ,[WinnerLevel]) VALUES ('{0}','3')", phone));
}
count = Convert.ToInt32(SqlHelper.ExecuteScalar("select count(*) from Winner where WinnerLevel='3'"));
if (count > 20)
{
this.btnStart.Enabled = false;
this.btnRedirect.Visible = true;
this.Button1.Visible = true;
this.btnStart.Visible = false;
this.btnEnd.Visible = false;
}
}
protected void btnRedirect_Click(object sender, EventArgs e)
{
Response.Redirect("RoolSecond.aspx",false);
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Winner.aspx?flag=3", false);
}
public void Hide()
{
this.Image1.Visible = false;
this.Image2.Visible = false;
this.Image3.Visible = false;
this.Image4.Visible = true;
this.lblNum.Visible = true;
this.Label2.Visible = true;
Panel1.Visible = false;
pnlGrid.Visible = true;
}
}
}