Default.aspx

View Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="bbs_BbsEnrol_" %>
<!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>留言本用户注册</title>
    
    <style type="text/css">
        .style1
        {
            height: 2px;
            width: 17px;
        }
        .style2
        {
            width: 17px;
        }
        .style3
        {
            height: 8px;
            width: 17px;
        }
        .style4
        {
            height: 12px;
            width: 17px;
        }
        .style5
        {
            height: 10px;
            width: 17px;
        }
        .style6
        {
            height: 11px;
            width: 17px;
        }
        .style7
        {
            height: 16px;
            width: 17px;
        }
        .style15
        {
            height: 2px;
            width: 91px;
        }
        .style16
        {
            width: 91px;
        }
        .style17
        {
            height: 8px;
            width: 91px;
        }
        .style18
        {
            height: 12px;
            width: 91px;
        }
        .style19
        {
            height: 10px;
            width: 91px;
        }
        .style20
        {
            height: 11px;
            width: 91px;
        }
        .style21
        {
            height: 16px;
            width: 91px;
        }
        .style22
        {
            height: 2px;
            width: 87px;
        }
        .style23
        {
            width: 87px;
        }
        .style24
        {
            height: 8px;
            width: 87px;
        }
        .style25
        {
            height: 12px;
            width: 87px;
        }
        .style26
        {
            height: 10px;
            width: 87px;
        }
        .style27
        {
            height: 11px;
            width: 87px;
        }
        .style28
        {
            height: 16px;
            width: 87px;
        }
    </style>
    
</head>
<body>
    <form id="form1" runat="server">
                    <table cellpadding="0" cellspacing="0" style="width: 501px">
                        <tr>
                            <td style="width: 500px; height: 270px">
                    <table cellpadding="0" cellspacing="0">
                        <tr>
                            <td colspan="4" style="height: 34px">
                                <asp:Image ID="Image3" runat="server" ImageUrl="~/Images/header.bmp" />
                            </td>
                        </tr>
                        <tr>
                            <td class="style22">
                                <asp:Image ID="Image2" runat="server" ImageUrl="~/Images/zhuce.bmp" />
                            </td>
                            <td class="style15">
                                <asp:Label ID="Label1" runat="server" Font-Size="9pt" Text="用户名称:"></asp:Label></td>
                            <td align="left" class="style1">
                                <asp:TextBox ID="TextBox1" runat="server" Font-Size="9pt" Width="100px"></asp:TextBox></td>
                            <td style="width: 212px; height: 2px;">
                            </td>
                        </tr>
                        <tr>
                            <td class="style23">
                            </td>
                            <td class="style16">
                                <asp:Label ID="Label3" runat="server" Font-Size="9pt" Text="用户性别:" Width="64px"></asp:Label></td>
                            <td align="left" class="style2">
                                <asp:DropDownList ID="DropDownList2" runat="server" Width="106px">
                                    <asp:ListItem Selected="True">男</asp:ListItem>
                                    <asp:ListItem>女</asp:ListItem>
                                </asp:DropDownList></td>
                            <td style="width: 212px">
                            </td>
                        </tr>
                                        <tr>
                            <td class="style28">
                            </td>
                            <td class="style21">
                                <asp:Label ID="Label9" runat="server" Font-Size="9pt" Text="头像:" Width="46px"></asp:Label></td>
                            <td align="left" class="style7">
                                <asp:DropDownList ID="DropDownList1" runat="server" Font-Size="9pt" 
                                    Width="106px" AutoPostBack="True" 
                                    onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
                                    <asp:ListItem>男生头像</asp:ListItem>
                                    <asp:ListItem>女生头像</asp:ListItem>
                                    <asp:ListItem Selected="True">选择头像</asp:ListItem>
                                </asp:DropDownList>
                            </td>
                            <td style="width: 212px; height: 16px;">
                            </td>
                        </tr>
                        <tr>
                            <td class="style23">
                            </td>
                            <td class="style16">
                            </td>
                            <td align="left" class="style2">
                                <asp:Image ID="Image1" runat="server" Height="60px" Width="60px" /></td>
                            <td style="width: 212px">
                            </td>
                        </tr>
                        <tr>
                            <td class="style24">
                            </td>
                            <td class="style17">
                                <asp:Label ID="Label4" runat="server" Font-Size="9pt" Text="用户密码:" Width="62px"></asp:Label></td>
                            <td align="left" class="style3">
                                <asp:TextBox ID="TextBox3" runat="server" Font-Size="9pt" Width="100px" TextMode="Password"></asp:TextBox></td>
                            <td style="width: 212px; height: 8px;">
                            </td>
                        </tr>
                        <tr>
                            <td class="style24">
                            </td>
                            <td class="style17">
                                <asp:Label ID="Label2" runat="server" Font-Size="9pt" Text="确认密码:" Width="60px"></asp:Label></td>
                            <td align="left" class="style3">
                                <asp:TextBox ID="TextBox2" runat="server" TextMode="Password" Width="100px"></asp:TextBox></td>
                            <td style="width: 212px; height: 8px">
                            </td>
                        </tr>
                        <tr>
                            <td class="style25">
                            </td>
                            <td class="style18">
                                <asp:Label ID="Label6" runat="server" Font-Size="9pt" Text="密码问题:" Width="67px"></asp:Label></td>
                            <td align="left" class="style4">
                                <asp:TextBox ID="TextBox5" runat="server" Font-Size="9pt" Width="100px"></asp:TextBox></td>
                            <td style="width: 212px; height: 12px;">
                            </td>
                        </tr>
                        <tr>
                            <td class="style26">
                            </td>
                            <td class="style19">
                                <asp:Label ID="Label7" runat="server" Font-Size="9pt" Text="问题答案:" Width="69px" 
                                    Height="16px"></asp:Label></td>
                            <td align="left" class="style5">
                                <asp:TextBox ID="TextBox6" runat="server" Font-Size="9pt" Width="100px" 
                                    Height="21px"></asp:TextBox></td>
                            <td style="width: 212px; height: 10px;">
                            </td>
                        </tr>
                        <tr>
                            <td class="style27">
                            </td>
                            <td class="style20">
                                <asp:Label ID="Label8" runat="server" Font-Size="9pt" Text="E-mail:"></asp:Label></td>
                            <td align="left" class="style6">
                                <asp:TextBox ID="TextBox7" runat="server" Font-Size="9pt" Width="100px"></asp:TextBox></td>
                            <td style="width: 212px; height: 11px;">
                            </td>
                        </tr>
        
                        <tr>
                            <td class="style26">
                            </td>
                            <td class="style19">
                                <asp:Label ID="Label10" runat="server" Font-Size="9pt" Text="OICQ:"></asp:Label></td>
                            <td align="left" class="style5">
                                <asp:TextBox ID="TextBox8" runat="server" Font-Size="9pt" Width="100px"></asp:TextBox></td>
                            <td style="width: 212px; height: 10px;">
                            </td>
                        </tr>
                        <tr>
                            <td class="style27">
                            </td>
                            <td class="style20">
                                <asp:Label ID="Label11" runat="server" Font-Size="9pt" Text="真实姓名:"></asp:Label></td>
                            <td align="left" class="style6">
                                <asp:TextBox ID="TextBox9" runat="server" Font-Size="9pt" Width="100px"></asp:TextBox></td>
                            <td style="width: 212px; height: 11px;">
                            </td>
                        </tr>
                        <tr>
                            <td class="style27">
                            </td>
                            <td class="style20">
                                <asp:Label ID="Label12" runat="server" Font-Size="9pt" Text="联系电话:"></asp:Label></td>
                            <td align="left" class="style6">
                                <asp:TextBox ID="TextBox10" runat="server" Font-Size="9pt" Width="100px"></asp:TextBox></td>
                            <td style="width: 212px; height: 11px;">
                            </td>
                        </tr>
                        <tr>
                            <td class="style27">
                            </td>
                            <td class="style20">
                            </td>
                            <td align="left" class="style6">
                                <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/zc.gif" 
                                    onclick="ImageButton1_Click" />
                            </td>
                            <td style="width: 212px; height: 11px">
                                &nbsp;</td>
                        </tr>
                        <tr>
                            <td colspan="4">
                                <asp:Image ID="Image4" runat="server" ImageUrl="~/Images/foot.bmp" />
                            </td>
                        </tr>
                    </table>
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 100px;">
                            </td>
                        </tr>
                        </table>
    </form>
</body>
</html>

Default.aspx.cs

View Code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Data.SqlClient;

public partial class bbs_BbsEnrol_ : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Image1.ImageUrl = "HadPortrait/showimg.gif";
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        SqlConnection mycon = new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);
        mycon.Open();
        SqlCommand mycom = new SqlCommand("select count(*) from tb_UserData02 where username='" + TextBox1.Text + "'", mycon);
        int count = Convert.ToInt32(mycom.ExecuteScalar());
        if (count > 0)
        {
            Response.Write("<script>alert('该用户名已经存在!');location='javascript:history.go(-1)'</script>");
        }
        if (TextBox2.Text != TextBox3.Text)
        {
            Response.Write("<script>alert('两次输入的密码不一致,请重新输入!');location='javascript:history.go(-1)'</script>");
        }
        else
        {
            SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);
            con.Open();
            SqlTransaction st = con.BeginTransaction();
            //通过SqlConnection的BeginTransaction方法创建名为st的对象Transaction
            SqlCommand com = con.CreateCommand();
            //将SqlTransaction对象分配给SqlCommand对象的Transaction属性
            com.Transaction = st;
            try
            {
                //向用户表中插入注册信息
                com.CommandText = "insert into tb_UserData02(username,sex,userpwd,matter,resule,mail,headportraitID,oicq,name,del)values('" + TextBox1.Text + "','" + this.DropDownList2.SelectedValue.ToString() + "','" + TextBox3.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + this.DropDownList1.SelectedValue.ToString() + "','" + TextBox8.Text + "','" + TextBox9.Text + "','" + TextBox10.Text + "')";
                com.ExecuteNonQuery();
                //向日志表中插入数据
                com.CommandText = "insert into tb_UserLog02(UserIP,UserTime,UserName,UserDNS)values('" + Request.UserHostAddress + "','" + DateTime.Now + "','" + TextBox1.Text + "','" + Request.UserHostName + "')";
                com.ExecuteNonQuery();
                //提交事物
                st.Commit();
                Response.Write("<script>alert('注册成功!');location='javascript:history.go(-1)'</script>");
            }
            catch (Exception ex)
            {
                //回滚事物
                st.Rollback();
                Response.Write(ex.ToString());
            }
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.Image1.ImageUrl = "HadPortrait/" + this.DropDownList1.SelectedValue + ".jpg";
    }
}

 

posted on 2013-03-25 01:44  松竹梅  阅读(344)  评论(0编辑  收藏  举报