欢迎大家访问我的BLOG,我会多多的出原创文章,希望大家支持我,为我祈祷,让我实现我的三个梦想!再30岁能成为一个名优秀的软件架构师!

Reg.aspx.cs

  1using System;
  2using System.Collections;
  3using System.ComponentModel;
  4using System.Data;
  5using System.Drawing;
  6using System.Web;
  7using System.Web.SessionState;
  8using System.Web.UI;
  9using System.Web.UI.WebControls;
 10using System.Web.UI.HtmlControls;
 11using System.Data.SqlClient;
 12using System.Configuration;
 13
 14namespace JJS_OMT.Member
 15{
 16    /// <summary>
 17    /// reg 的摘要说明。
 18    /// </summary>

 19    public class reg : System.Web.UI.Page
 20    {
 21        protected System.Web.UI.WebControls.Image ImageCheck;
 22        protected System.Web.UI.WebControls.TextBox UserName;
 23        protected System.Web.UI.WebControls.DropDownList CityList;
 24        protected System.Web.UI.WebControls.Button BtnSubmit;
 25        JJS_BMT.NetTVLocation Loca=new JJS_BMT.NetTVLocation();
 26        protected System.Web.UI.WebControls.RequiredFieldValidator UserNameValid;
 27        protected System.Web.UI.WebControls.RequiredFieldValidator PassWordValid;
 28        protected System.Web.UI.WebControls.RequiredFieldValidator RePassWordValid;
 29        protected System.Web.UI.WebControls.RequiredFieldValidator CheckCodeValid;
 30        protected System.Web.UI.WebControls.TextBox PassWord;
 31        protected System.Web.UI.WebControls.TextBox RePassWord;
 32        protected System.Web.UI.WebControls.TextBox CheckCode;
 33        protected System.Web.UI.WebControls.TextBox Email;
 34        protected System.Web.UI.WebControls.RequiredFieldValidator EmailValid;
 35        protected System.Web.UI.WebControls.RegularExpressionValidator EmailValidTwo;
 36        protected System.Web.UI.WebControls.DropDownList ProvinceList;
 37        protected System.Web.UI.WebControls.CustomValidator CustomValidator1;
 38        protected System.Web.UI.WebControls.CustomValidator Customvalidator2;
 39        protected System.Web.UI.HtmlControls.HtmlForm Form1;
 40        protected System.Web.UI.WebControls.Literal ChangeLoction;
 41    
 42        private void Page_Load(object sender, System.EventArgs e)
 43        {
 44            // 在此处放置用户代码以初始化页面
 45            if(!Page.IsPostBack)
 46            {
 47                string connStr=ConfigurationSettings.AppSettings["connStr"];
 48                SqlConnection conn=new SqlConnection(connStr);
 49                string sqlStr="SELECT a.fProvinceName,a.fProvinceId,b.fCityName,b.fCityId FROM tProvince a INNER JOIN tCity b ON a.fProvinceId = b.fProvinceID ORDER BY a.fProvinceId";
 50                SqlCommand com=new SqlCommand(sqlStr,conn);
 51                SqlDataAdapter da=new SqlDataAdapter();
 52                da.SelectCommand=com;
 53                DataSet ds=new DataSet();
 54                conn.Open();
 55                da.Fill(ds);
 56                da.Dispose();
 57                conn.Close();
 58                for(int i = 0;i <ds.Tables[0].Rows.Count ;i++)//循环遍历Table,主要是为了实现关联下拉列表无刷新联动
 59                {
 60                    DataRow dr = ds.Tables[0].Rows[i];
 61                    //↓把省,市,写入数组,并显示在Literal控件上,如:Group[Groupcount++] = new Array("上海","1001","上海市","1370");
 62                    ChangeLoction.Text += String.Format("Group[Groupcount++] = new Array(\"{0}\",\"{1}\",\"{2}\",\"{3}\");\n",dr["fProvinceName"],dr["fProvinceId"],dr["fCityName"],dr["fCityId"].ToString());
 63                    if (ProvinceList.Items.FindByText(dr["fProvinceName"].ToString()) == null)//如果指定当前记录ProvinceList的Item为空的话,添加Item
 64                    {
 65                        ProvinceList.Items.Add(new ListItem(dr["fProvinceName"].ToString(),dr["fProvinceId"].ToString()));
 66                    }

 67                }

 68                ProvinceList.Items.Insert(0,new ListItem("==全部省级==","0"));//添加"==全部省级=="为第0个位置
 69            }

 70        }

 71
 72        Web 窗体设计器生成的代码
 93
 94        private void BtnSubmit_Click(object sender, System.EventArgs e)
 95        {
 96            AddUser();
 97        }

 98
 99        private void AddUser()//用户输入注册信息,并提交的时候迢用此方法
100        {
101            if(Page.IsValid)
102            {
103                if(CheckCode.Text.Trim()!=Session["CheckCode"].ToString())
104                {
105                    Response.Write("<script language=javascript>alert('输入验证码有误,请查正后再试!');history.go(-1)</script>");
106                    return;
107                }

108                string connStr=ConfigurationSettings.AppSettings["connStr"];
109                SqlConnection conn=new SqlConnection(connStr);
110                string strSql="select count(*) as counts from TV_User where UserName=@UserName";
111                SqlCommand comm=new SqlCommand(strSql,conn);
112                comm.Parameters.Add("@UserName",SqlDbType.VarChar,50);
113                comm.Parameters["@UserName"].Value=UserName.Text.Trim();
114                conn.Open();
115                int counts=Convert.ToInt32(comm.ExecuteScalar());
116                conn.Close();
117                if (counts>0)
118                {
119                    Response.Write("<script language=javascript>alert('用户已经被人注册!');history.go(-1)</script>");
120                    return;
121                }

122                string userID=JJS_BMT.NetTVFunction.GetRndID();
123                string userName=UserName.Text.Trim();
124                strSql="insert into TV_User(UserID,UserName,UserPassword,Location,Email,CheckNum,RegDate) values(@UserID,@UserName,@UserPassword,@Location,@Email,@CheckNum,@RegDate)";
125                comm=new SqlCommand(strSql,conn);
126                comm.Parameters.Add("@UserID",SqlDbType.VarChar,18);
127                comm.Parameters.Add("@UserName",SqlDbType.VarChar,50);
128                comm.Parameters.Add("@UserPassword",SqlDbType.VarChar,50);
129                comm.Parameters.Add("@Location",SqlDbType.VarChar,9);
130                comm.Parameters.Add("@Email",SqlDbType.VarChar,50);
131                comm.Parameters.Add("@CheckNum",SqlDbType.VarChar,10);
132                comm.Parameters.Add("@RegDate",SqlDbType.DateTime,8);
133                comm.Parameters["@UserID"].Value=userID;
134                comm.Parameters["@UserName"].Value=userName;
135                comm.Parameters["@UserPassword"].Value=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(PassWord.Text.Trim(),"MD5"); 
136                comm.Parameters["@Location"].Value=Request.Params["ProvinceList"].Trim()+"|"+Request.Params["CityList"].Trim();
137                comm.Parameters["@Email"].Value=Email.Text.Trim();
138                comm.Parameters["@CheckNum"].Value=CheckCode.Text.Trim();
139                comm.Parameters["@RegDate"].Value=DateTime.Now;
140                conn.Open();
141                comm.ExecuteNonQuery();
142                conn.Close();
143                Session["UserID"]=userID;
144                Session["UserName"]=userName;
145                Response.Write("<script language=javascript>alert('恭喜您,成功注册!');location.href='/Default.aspx';</script>");
146            }

147        }

148        public void ServerValidation (object source, ServerValidateEventArgs arguments)//自定义验证控件CustomValidator
149        {
150         
151            int i = int.Parse(arguments.Value);
152            arguments.IsValid = (i!=0);
153
154        }

155    }

156}

157
Reg.aspx
  1<%@ Page language="c#" Codebehind="reg.aspx.cs" AutoEventWireup="false" Inherits="JJS_OMT.Member.reg" enableViewState="False" %>
  2<!--#include file="../inc/PublicHead.inc"-->
  3<script language="javascript">
  4        var Groupcount;
  5        Groupcount=0;
  6        Group = new Array();
  7        
  8        <asp:Literal id="ChangeLoction" runat="server"></asp:Literal>    
  9        function changelocation(locationid)
 10        {
 11            document.Form1.CityList.length = 0;
 12            var locationid=locationid;
 13            var i;
 14            var flag;
 15            var j;
 16            for (i=0;i<Groupcount; i++)
 17            {
 18                if (Group[i][1== locationid)
 19                {
 20                    flag = true;
 21                    for (j =0;j<document.Form1.CityList.length;j++)
 22                        if (document.Form1.CityList[j].value == Group[i][3])
 23                            {
 24                                flag = false;
 25                                break;
 26                            }

 27                    if (flag)
 28                        document.Form1.CityList.options[document.Form1.CityList.length]
 29                        = new Option(Group[i][2], Group[i][3]);
 30                }

 31            }

 32            var optionnew=new Option("==全部市级==","0",true,true);
 33            document.Form1.CityList.add(optionnew,0);
 34        }

 35   function ClientValidate(source, arguments)
 36   {
 37      if ((arguments.Value) == "0")
 38         arguments.IsValid=false;
 39      else
 40         arguments.IsValid=true;
 41   }

 42
</script>
 43<table cellSpacing="0" cellPadding="0" width="960" align="center" border="0">
 44    <tr>
 45        <td height="4"></td>
 46    </tr>
 47</table>
 48<table cellSpacing="0" cellPadding="0" width="960" align="center" border="0">
 49    <tr>
 50        <td width="28"><IMG height="50" src="/images/zhuce1.GIF" width="28"></td>
 51        <td vAlign="bottom" background="/images/index_center-02.gif"><IMG height="50" src="/images/zhuce.GIF" width="348"></td>
 52        <td width="20" background="/images/zhuce1-02.GIF">&nbsp;</td>
 53    </tr>
 54</table>
 55<table cellSpacing="0" cellPadding="0" width="960" align="center" border="0">
 56    <tr>
 57        <td width="8" background="/images/index_center-08.gif" height="300">&nbsp;</td>
 58        <td width="8" background="/images/index_center-09.gif">&nbsp;</td>
 59        <td>
 60            <form id="Form1" method="post" runat="server">
 61                <table cellSpacing="0" cellPadding="3" width="100%" align="center">
 62                    <tr>
 63                        <td align="right" width="30%" height="36"><FONT color="#ff0000">**</FONT> 用 户 名:</td>
 64                        <td height="36">&nbsp;
 65                            <asp:textbox id="UserName" runat="server" CssClass="TextBox"></asp:textbox>&nbsp;<asp:requiredfieldvalidator id="UserNameValid" ControlToValidate="UserName" Display="Dynamic" Text="<img src='/images/iconx.GIF' align='absmiddle' /> <font color='red'>请输入用户名!</font>"
 66                                Runat="server"></asp:requiredfieldvalidator></td>
 67                    </tr>
 68                    <tr>
 69                        <td align="right" height="32"><FONT color="#ff0000">**</FONT> 密&nbsp;&nbsp;&nbsp;&nbsp;码:</td>
 70                        <td>&nbsp;
 71                            <asp:textbox id="PassWord" runat="server" TextMode="Password" CssClass="TextBox"></asp:textbox>&nbsp;<asp:requiredfieldvalidator id="PassWordValid" ControlToValidate="PassWord" Display="Dynamic" Text="<img src='/images/iconx.GIF' align='absmiddle' /> <font color='red'>请输入密码!</font>"
 72                                Runat="server"></asp:requiredfieldvalidator></td>
 73                    </tr>
 74                    <tr>
 75                        <td align="right" height="32"><FONT color="#ff0000">**</FONT> 确认密码:</td>
 76                        <td>&nbsp;
 77                            <asp:textbox id="RePassWord" runat="server" TextMode="Password" CssClass="TextBox"></asp:textbox>&nbsp;<asp:requiredfieldvalidator id="RePassWordValid" ControlToValidate="RePassWord" Display="Dynamic" Text="<img src='/images/iconx.GIF' align='absmiddle' /> <font color='red'>输入确认密码!</font>"
 78                                Runat="server"></asp:requiredfieldvalidator></td>
 79                    </tr>
 80                    <tr>
 81                        <td align="right" height="32"><FONT color="#ff0000">**</FONT> 验 证 码:</td>
 82                        <td>&nbsp;
 83                            <asp:textbox id="CheckCode" runat="server" CssClass="TextBox"></asp:textbox>&nbsp;<asp:image id="ImageCheck" Runat="server" ImageAlign="AbsMiddle" ImageUrl="CheckCode.aspx"></asp:image>
 84                            <asp:requiredfieldvalidator id="CheckCodeValid" Runat="server" Text="<img src='/images/iconx.GIF' /> <font color='red'>请输入验证!</font>"
 85                                Display="Dynamic" ControlToValidate="CheckCode"></asp:requiredfieldvalidator></td>
 86                    </tr>
 87                    <tr>
 88                        <td align="right" height="43"><FONT color="#ff0000">**</FONT> 所在地区:</td>
 89                        <td height="43">&nbsp;
 90                            <asp:dropdownlist id="ProvinceList" runat="server" onchange="changelocation(document.Form1.ProvinceList.options[document.Form1.ProvinceList.selectedIndex].value);"
 91                                EnableViewState="False"></asp:dropdownlist>&nbsp;<asp:dropdownlist id="CityList" runat="server" EnableViewState="False" Width="95px"></asp:dropdownlist>
 92                            <asp:CustomValidator id="CustomValidator1" ControlToValidate="ProvinceList" ClientValidationFunction="ClientValidate"
 93                                OnServerValidate="ServerValidation" Display="Dynamic" ErrorMessage="<img src='/images/iconx.GIF' align='absmiddle'/> <font color='red'>请选择省份!</font>"
 94                                Font-Size="10pt" runat="server" />
 95                            <asp:CustomValidator id="Customvalidator2" ControlToValidate="CityList" ClientValidationFunction="ClientValidate"
 96                                OnServerValidate="ServerValidation" Display="Dynamic" ErrorMessage="<img src='/images/iconx.GIF' align='absmiddle'/> <font color='red'>请选择城市!</font>"
 97                                ForeColor="green" Font-Name="verdana" Font-Size="10pt" runat="server" />
 98                        </td>
 99                    </tr>
100                    <tr>
101                        <td align="right" height="32"><FONT color="#ff0000">**</FONT> Email地址:</td>
102                        <td>&nbsp;
103                            <asp:textbox id="Email" runat="server" CssClass="TextBox"></asp:textbox>
104                            <asp:requiredfieldvalidator id="EmailValid" Runat="server" Text="<img src='/images/iconx.GIF' align='absmiddle'/> <font color='red'>请输入邮箱地址!</font>"
105                                Display="Dynamic" ControlToValidate="Email"></asp:requiredfieldvalidator><asp:regularexpressionvalidator id="EmailValidTwo" Runat="server" Text="<img src='/images/iconx.GIF' align='absmiddle'/> <font color='red'>电子邮件格式不正确</font>"
106                                ControlToValidate="Email" ValidationExpression="\w+@\w+(\.\w+)*" ErrorMessage="电子邮件格式不正确"></asp:regularexpressionvalidator></td>
107                    </tr>
108                    <tr>
109                        <td align="center" colSpan="2" height="32"><asp:button id="BtnSubmit" runat="server" Text="同意以上条款,确定注册"></asp:button></td>
110                    </tr>
111                </table>
112                <script language="javascript">
113       changelocation(document.Form1.ProvinceList.options[document.Form1.ProvinceList.selectedIndex].value);
114                
</script>
115            </form>
116        </td>
117        <td width="11" background="/images/index_center-10.gif">&nbsp;</td>
118        <td width="9" background="/images/index_center0.gif">&nbsp;</td>
119    </tr>
120</table>
121<table width="960" border="0" align="center" cellpadding="0" cellspacing="0">
122    <tr>
123        <td width="8" height="24" background="/images/index_center-11.gif">&nbsp;</td>
124        <td width="8" background="/images/index_center-12.gif">&nbsp;</td>
125        <td background="/images/index_center-13.gif">&nbsp;</td>
126        <td width="11" background="/images/index_center-14.gif">&nbsp;</td>
127        <td width="9" background="/images/index_center-15.gif">&nbsp;</td>
128    </tr>
129</table>
130<table width="960" border="0" align="center" cellpadding="0" cellspacing="0">
131    <tr>
132        <td height="4"></td>
133    </tr>
134</table>
135<table width="960" border="0" align="center" cellpadding="0" cellspacing="0">
136    <tr>
137        <td width="27" height="16"><img src="/images/center.gif" width="27" height="16"></td>
138        <td width="913" background="/images/center-02.gif"></td>
139        <td width="20"><img src="/images/center-03.gif" width="20" height="16"></td>
140    </tr>
141    <tr>
142        <td width="27" height="100" background="/images/center-04.gif"></td>
143        <td width="913"></td>
144        <td width="20" background="/images/center-05.gif"></td>
145    </tr>
146    <tr>
147        <td width="27" background="/images/center-07.gif"><img src="/images/center-06.gif" width="21" height="14"></td>
148        <td width="913" background="/images/center-07.gif"></td>
149        <td width="20" background="/images/center-08.gif"></td>
150    </tr>
151</table>
152<table width="960" border="0" align="center" cellpadding="0" cellspacing="0">
153    <tr>
154        <td height="4"></td>
155    </tr>
156</table>
157<!--#include file="../inc/DownLoadTV.inc"-->
158<!--#include file="../inc/PublicEnd.inc"-->
159

posted on 2006-07-12 10:40  程序缘  阅读(719)  评论(2)    收藏  举报

导航