• 登录,注册页面练习


    数据库:

    create database aspnet
    go
    
    use aspnet
    go
    
    
    create table Umz
    (
       Umzz nvarchar(20) primary key,--民族代号,主键
       Ummz nvarchar(20)--民族
    )
    insert into Umz values('M1','汉族')
    insert into Umz values('M2','回族')
    insert into Umz values('M3','壮族')
    insert into Umz values('M4','满族')
    insert into Umz values('M5','傣族')
    
    
    
    create table Utb
    (
       Ucode nvarchar(20),--账号
       Umima nvarchar(20),--密码
       Uname nvarchar(20),--名字
       Usex bit,--性别
       Ubirth datetime,--生日
       Uminzu nvarchar(20)--民族,外键
    )
    insert into Utb values('S101','123','周杰棍','1','1990-3-5','M1')
    insert into Utb values('S102','123','双杰伦','1','1991-4-5','M2')
    insert into Utb values('S103','123','杨幂','0','1992-5-5','M3')
    insert into Utb values('S104','123','静香','0','1993-6-5','M4')
    insert into Utb values('S105','123','查理','1','1994-7-5','M5')

    数据库实体类:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data.SqlClient;
    
    /// <summary>
    /// User 的摘要说明
    /// </summary>
    public class User
    {
        SqlConnection conn = null;
        SqlCommand cmd = null;
        public User()
        {
            conn = new SqlConnection("server=.;database=aspnet;user=sa;pwd=123;");
            cmd = conn.CreateCommand();
        }
    
    
        //封装一个用户信息的实体类
        private string _Ucode;//账号
    
        public string Ucode
        {
            get { return _Ucode; }
            set { _Ucode = value; }
        }
    
    
        private string _Umima;//密码
    
        public string Umima
        {
            get { return _Umima; }
            set { _Umima = value; }
        }
        private string _Uname;//姓名
    
        public string Uname
        {
            get { return _Uname; }
            set { _Uname = value; }
        }
        private bool _Usex;//性别
    
        public bool Usex
        {
            get { return _Usex; }
            set { _Usex = value; }
        }
        public string sex //扩展字段
        {
            get { return Usex ? "" : ""; }
        }
        private DateTime _Ubirth;//生日
    
        public DateTime Ubirth
        {
            get { return _Ubirth; }
            set { _Ubirth = value; }
        }
        //public string birthday
        //{
        //    get { return Ubirth.ToString("yyyy年MM月dd日"); }
        //}
    
        private string _Uminzu;//民族
    
        public string Uminzu
        {
            get { return _Uminzu; }
            set { _Uminzu = value; }
        }
        /// <summary>
        /// 民族字段扩展
        /// </summary>
        public string Minzu
        {
            get
            {
                string Mz = "";
                cmd.CommandText = "select Ummz from Umz where Umzz=@Umzz";
                cmd.Parameters.Clear();
                cmd.Parameters.Add("@Umzz", _Uminzu);
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    dr.Read();
                    Mz = dr["Ummz"].ToString();
                }
                conn.Close();
                return Mz;
            }
        }
    
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    /// <summary>
    /// Minzu 的摘要说明
    /// </summary>
    public class Minzu
    {
        public Minzu()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        public string Umzz { get; set; }
        public string Ummz { get; set; }
    }

    数据库操作类:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data.SqlClient;
    
    /// <summary>
    /// UserData 的摘要说明
    /// </summary>
    public class UserData
    {
        SqlConnection conn = null;
        SqlCommand cmd = null;
        public UserData()
        {
            conn = new SqlConnection("server=.;database=aspnet;user=sa;pwd=123;");
            cmd = conn.CreateCommand();
        }
    
    
        /// <summary>
        /// 验证登录输入是否有此信息
        /// </summary>
        /// <param name="zh"></param>
        /// <param name="mm"></param>
        /// <returns></returns>
        public bool Denglu(string zh, string mm)
        {
            bool isok = false;
            cmd.CommandText = "select * from Utb where Ucode=@Ucode and Umima=@Umima";
            cmd.Parameters.Clear();
            cmd.Parameters.Add("Ucode", zh);
            cmd.Parameters.Add("Umima", mm);
            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                isok = true;
            }
            conn.Close();
    
            return isok;
        }
    
    
        /// <summary>
        /// 查询用户所有信息
        /// </summary>
        /// <returns></returns>
        public List<User> selectAll()
        {
            List<User> list = new List<User>();
            cmd.CommandText = "select * from Utb";
            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    User us = new User();
                    us.Ucode = dr["Ucode"].ToString();
                    us.Umima = dr["Umima"].ToString();
                    us.Uname = dr["Uname"].ToString();
                    us.Usex = Convert.ToBoolean(dr["Usex"]);
                    us.Ubirth = Convert.ToDateTime(dr["Ubirth"]);
                    us.Uminzu = dr["Uminzu"].ToString();
    
                    list.Add(us);
                }
            }
            conn.Close();
            return list;
        }
    
    
        /// <summary>
        /// 根据每个人的主键值删除个人信息
        /// </summary>
        /// <param name="code"></param>
        public bool delete(string code)
        {
            bool isok = false;
    
            cmd.CommandText = "delete from Utb where Ucode=@code";
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@code", code);
            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                isok = true;
            }
            catch
            {
                isok = false;
            }
            finally { conn.Close(); }
            return isok;
        }
    
    
        /// <summary>
        /// 根据修改按钮传过来的主键值将要修改的用户信息查出来
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public User selectall(string code)
        {
            User us = new User();
            cmd.CommandText = "select * from Utb where Ucode=@a";
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@a", code);
            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                us.Ucode = dr["Ucode"].ToString();
                us.Umima = dr["Umima"].ToString();
                us.Uname = dr["Uname"].ToString();
                us.Usex = Convert.ToBoolean(dr["Usex"]);
                us.Ubirth = Convert.ToDateTime(dr["Ubirth"]);
                us.Uminzu = dr["Uminzu"].ToString();
            }
            conn.Close();
            return us;
        }
    
    
        /// <summary>
        /// 修改用户信息
        /// </summary>
        /// <param name="ser"></param>
        /// <returns></returns>
        public bool Update(User ser) 
        {
            bool isok = false;
            cmd.CommandText = "update Utb set Umima=@mima,Uname=@name,Usex=@sex,Ubirth=@birth,Uminzu=@minzu where Ucode=@code ";
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@code", ser.Ucode);
            cmd.Parameters.Add("@mima", ser.Umima);
            cmd.Parameters.Add("@name", ser.Uname);
            cmd.Parameters.Add("@sex", ser.Usex);
            cmd.Parameters.Add("@birth", ser.Ubirth);
            cmd.Parameters.Add("@minzu", ser.Uminzu);
    
            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                isok = true;
            }
            catch { }
            finally
            {
                conn.Close();
            }
            return isok;
        }
    
    
    
        /// <summary>
        /// 用户注册,添加用户信息
        /// </summary>
        /// <param name="ser"></param>
        /// <returns></returns>
        public bool Insert(User ser) 
        {
            bool isok = false;
            cmd.CommandText = "insert into Utb values(@code,@mima,@name,@sex,@birth,@minzu) ";
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@code", ser.Ucode);
            cmd.Parameters.Add("@mima", ser.Umima);
            cmd.Parameters.Add("@name", ser.Uname);
            cmd.Parameters.Add("@sex", ser.Usex);
            cmd.Parameters.Add("@birth", ser.Ubirth);
            cmd.Parameters.Add("@minzu", ser.Uminzu);
            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                isok = true;
            }
            catch { }
            finally 
            {
                conn.Close();
            }
            return isok;
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data.SqlClient;
    
    /// <summary>
    /// MinzuData 的摘要说明
    /// </summary>
    public class MinzuData
    {
        SqlConnection conn = null;
        SqlCommand cmd = null;
        public MinzuData()
        {
            conn = new SqlConnection("server=.;database=aspnet;user=sa;pwd=123;");
            cmd = conn.CreateCommand();
        }
    
        public List<Minzu> selectl() 
        {
            List<Minzu> li = new List<Minzu>();
            cmd.CommandText = "select * from Umz";
            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows) 
            {
                while (dr.Read())
                {
                    Minzu mc = new Minzu();
                    mc.Umzz = dr["Umzz"].ToString();
                    mc.Ummz = dr["Ummz"].ToString();
                    li.Add(mc);
                }
            }
            conn.Close();
            return li;
        }
    }

    登录界面:

    前台:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Denglu.aspx.cs" Inherits="Denglu" %>
    
    <!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>
        <style type="text/css">
            body {
                background-image: url(images/dlbj.jpg);
                background-size: cover;
            }
    
            #Dz {
                position: relative;
                width: 500px;
                height: 400px;
                top: 50px;
                left: 10%;
                /*background-color:#3f8bf5;*/
                background-image: url(images/Dbj.jpg);
                background-size: cover;
            }
    
            #Dz1 {
                position: relative;
                height: 20%;
                /*background-color:#698df2;*/
                text-align: center;
            }
    
                #Dz1 span {
                    position: relative;
                    top: 15%;
                    font-family: 黑体;
                    font-size: 45px;
                    font-weight: 600;
                    color:#050f81;
                }
    
            #Dz2 {
                position: relative;
                height: 30%;
                /*background-color:#cba4a4;*/
                text-align: center;
            }
    
                #Dz2 span {
                    position: relative;
                    top: 40%;
                    font-family: 宋体;
                    font-size: 30px;
                    font-weight: 600;
                }
    
            #TextBox1 {
                position: relative;
                top: 35%;
                height: 30px;
                width: 180px;
                border: 2px solid;
            }
    
            #Dz3 {
                position: relative;
                height: 30%;
                /*background-color:#ff6a00;*/
                text-align: center;
            }
    
                #Dz3 span {
                    position: relative;
                    top: 20px;
                    font-family: 宋体;
                    font-size: 30px;
                    font-weight: 600;
                }
    
            #TextBox2 {
                position: relative;
                top: 15px;
                height: 30px;
                width: 180px;
                border: 2px solid;
            }
    
            .Check {
                position: relative;
                top: 30px;
            }
    
            #Dz4 {
                position: relative;
                height: 20%;
                /*background-color:#b6ff00;*/
                text-align:center;
            }
            .but {
            position:relative;
            top:30px;
            width:80px;
            height:30px;
            font-family:微软雅黑;
            font-size:20px;
            background-color:#ef2424;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
            <div id="Dz">
                <div id="Dz1"><span>&nbsp;&nbsp;&nbsp;</span></div>
                <div id="Dz2">
                    <span>账号:</span><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </div>
                <div id="Dz3">
                    <span>密码:</span><asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
                    <div class="Check">
                        <asp:CheckBox ID="CheckBox1" Text="7天自动登录" runat="server" /></div>
                </div>
                <div id="Dz4">
                    <asp:Button ID="Button1" CssClass="but" runat="server" Text="登 录" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Button ID="Button2" CssClass="but" runat="server" Text="注 册" />
                </div>
            </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;
    
    public partial class Denglu : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Button1.Click += Button1_Click;
            Button2.Click += Button2_Click;
            if (Session["good"] != null)
            {
                bool hasok = Convert.ToBoolean(Session["good"]);
                if (hasok)
                {
                    Response.Write("<script>alert('注册成功!');</script>");
                }
                else
                {
                    Response.Write("<script>alert('注册失败!');</script>");
                }
                Session["good"] = null;
            }
        }
    
        
        //登录按钮点击事件
        void Button1_Click(object sender, EventArgs e)
        {
            string zh=TextBox1.Text;
            string mm=TextBox2.Text;
            bool isok = new UserData().Denglu(zh, mm);
            if (isok == false)
            {
                TextBox1.Text = "此账号不存在";
            }
            else 
            {
                Response.Cookies["code"].Value = TextBox1.Text;
                if (CheckBox1.Checked) 
                {
                    Response.Cookies["code"].Expires = DateTime.Now.AddDays(7);   
                }
                Response.Redirect("Zhujiemian.aspx");
                Response.Write("<script>window.close();</script>");
            }
        }
        //注册按钮点击事件
        void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("Zhuce.aspx");
            Response.Write("<script>window.close();</script>");
        }
    }

    注册界面:

    前台:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Zhuce.aspx.cs" Inherits="Zhuce" %>
    
    <!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>
    <style type="text/css">
            * {
                margin: 0px;
                padding: 0px;
            }
    
            #Bj {
                position: relative;
                width: 100%;
                height: 660px;
                background-image:url(images/asas.jpg);
                background-size:cover;
            }
    
            #Zck {
                position: relative;
                width: 600px;
                height: 500px;
                top: 12%;
                left: 28%;
                background-color: #FFF68F;
            }
    
            #Bt {
                position: relative;
                width: 100%;
                height: 80px;
                text-align: center;
                background-color: #32CD32;
                background-image:url(images/bt.png);
            }
    
            #Bt_name {
                position: relative;
                top: 15px;
                font-family: 微软雅黑;
                font-size: 35px;
                font-weight:600;
                color: white;
                letter-spacing: 25px; /*字符间距*/
            }
    
            #Ym {
                position: relative;
                width: 100%;
                height: 360px;
                background-image:url(images/vipbgimg.jpg);
                background-size:cover;
            }
    
            #Ym_1 {
                position: relative;
                width: 100%;
                height: 60px;
                /*background-color: #8470FF;*/
                text-align: center;
            }
    
                #Ym_1 span {
                    position: relative;
                    font-family: 微软雅黑;
                    font-size: 20px;
                    top: 10px;
                }
    
            #TextBox1 {
                position: relative;
                height: 25px;
                width: 180px;
                top: 5px;
            }
    
            #Ym_2 {
                position: relative;
                width: 100%;
                height: 60px;
                /*background-color: #00CD66;*/
                text-align: center;
            }
    
                #Ym_2 span {
                    position: relative;
                    font-family: 微软雅黑;
                    font-size: 20px;
                    top: 10px;
                }
    
            #TextBox2 {
                position: relative;
                height: 25px;
                width: 180px;
                top: 5px;
            }
    
            #Ym_3 {
                position: relative;
                width: 100%;
                height: 60px;
                /*background-color: #7B68EE;*/
                text-align: center;
            }
    
                #Ym_3 span {
                    position: relative;
                    font-family: 微软雅黑;
                    font-size: 20px;
                    top: 10px;
                }
    
            #TextBox3 {
                position: relative;
                height: 25px;
                width: 180px;
                top: 5px;
            }
    
            #Ym_4 {
                position: relative;
                width: 100%;
                height: 60px;
                /*background-color: #00EE76;*/
            }
    
                #Ym_4 span {
                    position: relative;
                    font-family: 微软雅黑;
                    font-size: 20px;
                    top: 10px;
                    left: 170px;
                }
    
                #Ym_4 div {
                    position: relative;
                    bottom: 10px;
                    left: 255px;
                }
    
            #Ym_5 {
                position: relative;
                width: 100%;
                height: 60px;
                /*background-color: #6A5ACD;*/
                text-align: center;
            }
    
                #Ym_5 span {
                    position: relative;
                    font-family: 微软雅黑;
                    font-size: 20px;
                    top: 10px;
                }
            #DropDownList2 {
            position:relative;
            height:20px;
            top:8px;
            }
            #DropDownList3 {
            position:relative;
            height:20px;
            top:8px;}
            #DropDownList4 {
            position:relative;
            height:20px;
            top:8px;}
    
            #Ym_6 {
                position: relative;
                width: 100%;
                height: 60px;
                /*background-color: #8470FF;*/
                text-align: center;
            }
    
                #Ym_6 span {
                    position: relative;
                    font-family: 微软雅黑;
                    font-size: 20px;
                    top: 10px;
                }
    
            #DropDownList1 {
                position: relative;
                height: 25px;
                width: 183px;
                top: 5px;
            }
    
            #Dl {
                position: relative;
                width: 100%;
                height: 60px;
                background-image:url(images/Diwen.png);
                /*background-color: #FFFF00;*/
            }
    
            #Button1 {
                position: relative;
                width: 80px;
                height: 30px;
                top: 15px;
                left: 150px;
                font-family:微软雅黑;
                font-size:16px;
            }
    
            #Button2 {
                position: relative;
                width: 80px;
                height: 30px;
                top: 15px;
                left: 300px;
                font-family:微软雅黑;
                font-size:16px;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
            <div id="Bj">
                <div id="Zck">
                    <div id="Bt"><span id="Bt_name">用户注册</span></div>
                    <div id="Ym">
                        <div id="Ym_1"><span>账号:</span>&nbsp;<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
                        <div id="Ym_2"><span>密码:</span>&nbsp;<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox></div>
                        <div id="Ym_3"><span>姓名:</span>&nbsp;<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></div>
                        <div id="Ym_4">
                            <span>性别:</span>
                            <div>
                                <asp:RadioButton ID="RadioButton1" runat="server" GroupName="1"  Text="男" />&nbsp;&nbsp;
                                <asp:RadioButton ID="RadioButton2" runat="server" GroupName="1" Text="女" />
                            </div>
                        </div>
                        <div id="Ym_5">
                            <span>生日:</span><asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList><span></span><asp:DropDownList ID="DropDownList3" runat="server"></asp:DropDownList><span></span><asp:DropDownList ID="DropDownList4" runat="server"></asp:DropDownList><span></span>
                        </div>
                        <div id="Ym_6">
                            <span>民族:</span>&nbsp;<asp:DropDownList ID="DropDownList1" runat="server">
                                
                            </asp:DropDownList>
                        </div>
                    </div>
                    <div id="Dl">
                        <asp:Button ID="Button1" runat="server" Text="提  交" />
                        <asp:Button ID="Button2" runat="server" Text="取  消" />
                    </div>
                </div>
            </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;
    
    public partial class Zhuce : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Button1.Click += Button1_Click;
            Button2.Click += Button2_Click;
            if (IsPostBack == false)
            {
                BindDropDown();
                BingDD();
            }
        }
    
        
    
    
        //提交按钮点击事件
        void Button1_Click(object sender, EventArgs e)
        {
            User ur = new User();
            ur.Ucode = TextBox1.Text;
            ur.Umima = TextBox2.Text;
            ur.Uname = TextBox3.Text;
            if (RadioButton1.Checked == true)
            {
                ur.Usex = true;
            }
            else
            {
                ur.Usex = false;
            }
            ur.Ubirth = Convert.ToDateTime(DropDownList2.Text + "-" + DropDownList3.Text + "-" + DropDownList4.Text);
            ur.Uminzu = DropDownList1.SelectedItem.Value;
    
            bool isok = new UserData().Insert(ur);
            if (isok)
            {
                Session["good"] = isok;
                Response.Redirect("Denglu.aspx");
                Response.Write("<script>window.close();</script>");
            }
    
        }
    
        //取消按钮点击事件
        void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("Denglu.aspx");
            Response.Write("<script>window.close();</script>");
        }
    
    
    
    
    
    
        /// <summary>
        /// 生日下拉列表信息
        /// </summary>
        public void BindDropDown()
        {
            for (int i = 1990; i <= DateTime.Now.Year; i++) //年的下拉列表
            {
                ListItem li = new ListItem(i.ToString(), i.ToString());
                DropDownList2.Items.Add(li);
            }
            for (int i = 1; i <= 12; i++)//月的下拉列表
            {
                ListItem li = new ListItem(i.ToString(), i.ToString());
                DropDownList3.Items.Add(li);
            }
            for (int i = 1; i <= 31; i++)//日的下拉列表
            {
                ListItem li = new ListItem(i.ToString(), i.ToString());
                DropDownList4.Items.Add(li);
            }
        }
    
        /// <summary>
        /// 民族的下拉列表信息
        /// </summary>
        public void BingDD()
        {
            DropDownList1.DataSource = new MinzuData().selectl();
            DropDownList1.DataTextField = "Ummz";
            DropDownList1.DataValueField = "Umzz";
            DropDownList1.DataBind();
        }
    }

    主界面显示数据表格及修改删除功能:

    前台:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Zhujiemian.aspx.cs" Inherits="Zhujiemian" %>
    
    <!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>
        <style type="text/css">
            body {
                background-image: url(images/ssa.jpg);
                background-size: cover;
            }
    
            #Bt {
                
                height:70px;
                text-align:center;
            }
    
            #Bt1 {
                position: relative;
                font-family: 宋体;
                font-size: 35px;
                font-weight: 600;
                top: 20px;
            }
    
            #Tab {
                width: 100%;
                background-color: #0e1075;
            }
    
                #Tab tr {
                    height: 50px;
                }
    
            #S1 {
                text-align: center;
                font-family: 微软雅黑;
                font-size: 20px;
                color: white;
            }
    
            #L1 {
                width: 10%;
            }
    
            #L2 {
                width: 10%;
            }
    
            #L3 {
                width: 10%;
            }
    
            #L4 {
                width: 10%;
            }
    
            #L5 {
                width: 30%;
            }
    
            #L6 {
                width: 10%;
            }
    
            #S2 {
                text-align: center;
                font-family: 微软雅黑;
                font-size: 18px;
                background-color: white;
            }
    
            #S3 {
                text-align: center;
                font-family: 微软雅黑;
                font-size: 18px;
                background-color: #dbd4d4;
            }
        </style>
    </head>
    <body>
        <div id="Bt">
            
            <span id="Bt1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
        </div>
        <form id="form1" runat="server">
            <span>当前登录用户:<asp:Label ID="Label1" runat="server" Text="未选择"></asp:Label></span>&nbsp;
            <asp:LinkButton ID="LinkButton1" runat="server">注销</asp:LinkButton>
            <asp:Repeater ID="Repeater1" runat="server">
                <HeaderTemplate>
                    <table id="Tab">
                        <tr id="S1">
                            <td id="L1">账号</td>
                            <td id="L2">密码</td>
                            <td id="L3">姓名</td>
                            <td id="L4">性别</td>
                            <td id="L5">生日</td>
                            <td id="L6">民族</td>
                            <td>操作</td>
                        </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr id="S2">
                        <td><%#Eval("Ucode") %></td>
                        <td><%#Eval("Umima") %></td>
                        <td><%#Eval("Uname") %></td>
                        <td><%#Eval("sex") %></td>
                        <td><%#Eval("Ubirth","{0:yyyy年MM月dd日}") %></td>
                        <td><%#Eval("Minzu") %></td>
                        <td><a href="Update.aspx?aaa=<%#Eval("Ucode") %>" target="_blank">修改</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="Delete.aspx?aaa=<%#Eval("Ucode") %>">删除</a></td>
                    </tr>
                </ItemTemplate>
                <AlternatingItemTemplate>
                    <tr id="S3">
                        <td><%#Eval("Ucode") %></td>
                        <td><%#Eval("Umima") %></td>
                        <td><%#Eval("Uname") %></td>
                        <td><%#Eval("sex") %></td>
                        <td><%#Eval("Ubirth","{0:yyyy年MM月dd日}") %></td>
                        <td><%#Eval("Minzu") %></td>
                        <td><a href="Update.aspx?aaa=<%#Eval("Ucode") %>" target="_blank">修改</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="Delete.aspx?aaa=<%#Eval("Ucode") %>">删除</a></td>
                    </tr>
                </AlternatingItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:Repeater>
            <asp:LinkButton ID="LinkButton2" runat="server">返回登录页面</asp:LinkButton>
        </form>
    </body>
    </html>

    后台:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Zhujiemian : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LinkButton1.Click += LinkButton1_Click;
            LinkButton2.Click += LinkButton2_Click;
            if (Request.Cookies["code"] != null)
            {
                Label1.Text = Request.Cookies["code"].Value;
            }
            else 
            {
                Label1.Text = "未选择"; 
            }
            
            if (Session["has"] != null)
            {
                bool hasok = Convert.ToBoolean(Session["has"]);
                if (hasok)
                {
                    Response.Write("<script>alert('删除成功!');</script>");
                }
                else
                {
                    Response.Write("<script>alert('删除失败!');</script>");
                }
                Session["has"] = null;
            }
            
            if (Session["ok"] != null)
            {
                bool hasok = Convert.ToBoolean(Session["ok"]);
                if (hasok)
                {
                    Response.Write("<script>alert('修改成功!');</script>");
                }
                else
                {
                    Response.Write("<script>alert('修改失败!');</script>");
                }
                Session["ok"] = null;
            }
            Bind();
        }
    
        
    
    
        //注销按钮点击事件
        void LinkButton1_Click(object sender, EventArgs e)
        {
            Response.Cookies["code"].Expires = DateTime.Now.AddDays(-2);
            Label1.Text = "未选择";
        }
    
        //返回按钮点击事件
        void LinkButton2_Click(object sender, EventArgs e)
        {
            Response.Redirect("Denglu.aspx");
        }
    
    
    
        /// <summary>
        /// 写一个绑定数据的方法
        /// </summary>
        public void Bind()
        {
            Repeater1.DataSource = new UserData().selectAll();
            Repeater1.DataBind();
        }
    }

    删除窗口后台:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Delete : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string code = Request["aaa"];
            bool isok = false;
            if (!string.IsNullOrEmpty(code)) 
            {
                isok = new UserData().delete(code);
            }
            Session["has"] = isok;
            Response.Redirect("Zhujiemian.aspx");
        }
    }

    修改窗口前台:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Update.aspx.cs" Inherits="Update" %>
    
    <!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>
    <style type="text/css">
            * {
                margin: 0px;
                padding: 0px;
            }
    
            #Bj {
                position: relative;
                width: 100%;
                height: 660px;
                background-image:url(images/asas.jpg);
                background-size:cover;
            }
    
            #Zck {
                position: relative;
                width: 600px;
                height: 500px;
                top: 12%;
                left: 28%;
                background-color: #FFF68F;
            }
    
            #Bt {
                position: relative;
                width: 100%;
                height: 80px;
                text-align: center;
                background-color: #32CD32;
                background-image:url(images/bt.png);
            }
    
            #Bt_name {
                position: relative;
                top: 15px;
                font-family: 微软雅黑;
                font-size: 35px;
                font-weight:600;
                color: white;
                letter-spacing: 25px; /*字符间距*/
            }
    
            #Ym {
                position: relative;
                width: 100%;
                height: 360px;
                background-image:url(images/vipbgimg.jpg);
                background-size:cover;
            }
    
            #Ym_1 {
                position: relative;
                width: 100%;
                height: 60px;
                /*background-color: #8470FF;*/
                
            }
    
                #Ym_1 span {
                    position: relative;
                    font-family: 微软雅黑;
                    font-size: 20px;
                    top: 10px;
                    left:175px;
                }
    
            #TextBox1 {
                position: relative;
                height: 25px;
                width: 180px;
                top: 5px;
            }
    
            #Ym_2 {
                position: relative;
                width: 100%;
                height: 60px;
                /*background-color: #00CD66;*/
                text-align: center;
            }
    
                #Ym_2 span {
                    position: relative;
                    font-family: 微软雅黑;
                    font-size: 20px;
                    top: 10px;
                }
    
            #TextBox2 {
                position: relative;
                height: 25px;
                width: 180px;
                top: 5px;
            }
    
            #Ym_3 {
                position: relative;
                width: 100%;
                height: 60px;
                /*background-color: #7B68EE;*/
                text-align: center;
            }
    
                #Ym_3 span {
                    position: relative;
                    font-family: 微软雅黑;
                    font-size: 20px;
                    top: 10px;
                }
    
            #TextBox3 {
                position: relative;
                height: 25px;
                width: 180px;
                top: 5px;
            }
    
            #Ym_4 {
                position: relative;
                width: 100%;
                height: 60px;
                /*background-color: #00EE76;*/
            }
    
                #Ym_4 span {
                    position: relative;
                    font-family: 微软雅黑;
                    font-size: 20px;
                    top: 10px;
                    left: 170px;
                }
    
                #Ym_4 div {
                    position: relative;
                    bottom: 10px;
                    left: 255px;
                }
    
            #Ym_5 {
                position: relative;
                width: 100%;
                height: 60px;
                /*background-color: #6A5ACD;*/
                text-align: center;
            }
    
                #Ym_5 span {
                    position: relative;
                    font-family: 微软雅黑;
                    font-size: 20px;
                    top: 10px;
                }
            #DropDownList2 {
            position:relative;
            height:20px;
            top:8px;
            }
            #DropDownList3 {
            position:relative;
            height:20px;
            top:8px;}
            #DropDownList4 {
            position:relative;
            height:20px;
            top:8px;}
    
            #Ym_6 {
                position: relative;
                width: 100%;
                height: 60px;
                /*background-color: #8470FF;*/
                text-align: center;
            }
    
                #Ym_6 span {
                    position: relative;
                    font-family: 微软雅黑;
                    font-size: 20px;
                    top: 10px;
                }
    
            #DropDownList1 {
                position: relative;
                height: 25px;
                width: 183px;
                top: 5px;
            }
    
            #Dl {
                position: relative;
                width: 100%;
                height: 60px;
                background-image:url(images/Diwen.png);
                /*background-color: #FFFF00;*/
            }
    
            #Button1 {
                position: relative;
                width: 80px;
                height: 30px;
                top: 15px;
                left: 150px;
                font-family:微软雅黑;
                font-size:16px;
            }
    
            #Button2 {
                position: relative;
                width: 80px;
                height: 30px;
                top: 15px;
                left: 300px;
                font-family:微软雅黑;
                font-size:16px;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
            <div id="Bj">
                <div id="Zck">
                    <div id="Bt"><span id="Bt_name">用户修改</span></div>
                    <div id="Ym">
                        <div id="Ym_1"><span>账号:</span>&nbsp;<asp:Label ID="Label1" runat="server" Text=""></asp:Label></div>
                        <div id="Ym_2"><span>密码:</span>&nbsp;<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox></div>
                        <div id="Ym_3"><span>姓名:</span>&nbsp;<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></div>
                        <div id="Ym_4">
                            <span>性别:</span>
                            <div>
                                <asp:RadioButton ID="RadioButton1" runat="server" GroupName="1"  Text="男" />&nbsp;&nbsp;
                                <asp:RadioButton ID="RadioButton2" runat="server" GroupName="1" Text="女" />
                            </div>
                        </div>
                        <div id="Ym_5">
                            <span>生日:</span><asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList><span></span><asp:DropDownList ID="DropDownList3" runat="server"></asp:DropDownList><span></span><asp:DropDownList ID="DropDownList4" runat="server"></asp:DropDownList><span></span>
                        </div>
                        <div id="Ym_6">
                            <span>民族:</span>&nbsp;<asp:DropDownList ID="DropDownList1" runat="server">
                                
                            </asp:DropDownList>
                        </div>
                    </div>
                    <div id="Dl">
                        <asp:Button ID="Button1" runat="server" Text="提  交" />
                        <asp:Button ID="Button2" runat="server" Text="取  消" />
                    </div>
                </div>
            </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;
    
    public partial class Update : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Button1.Click += Button1_Click;
            Button2.Click += Button2_Click;
            string code = Request["aaa"];
    
            User us = new UserData().selectall(code);
    
            if (IsPostBack == false)
            {
                BindDropDown();
                BingDD();
    
    
                Label1.Text = us.Ucode;
                TextBox2.Text = us.Umima;
                TextBox3.Text = us.Uname;
                if (us.Usex)
                {
                    RadioButton1.Checked = true;
                }
                else
                {
                    RadioButton2.Checked = true;
                }
                DropDownList2.SelectedValue = us.Ubirth.Year.ToString();
                DropDownList3.SelectedValue = us.Ubirth.Month.ToString();
                DropDownList4.SelectedValue = us.Ubirth.Day.ToString();
                DropDownList1.SelectedValue = us.Uminzu;
            }  
        }
    
        
    
    
        //提交按钮点击事件
        void Button1_Click(object sender, EventArgs e)
        {
            User ur = new User();
            ur.Ucode = Label1.Text;
            ur.Umima = TextBox2.Text;
            ur.Uname = TextBox3.Text.Trim();
            if (RadioButton1.Checked == true)
            {
                ur.Usex = true;
            }
            else 
            {
                ur.Usex = false;
            }
            ur.Ubirth = Convert.ToDateTime(DropDownList2.Text + "-" + DropDownList3.Text + "-" + DropDownList4.Text);
            ur.Uminzu = DropDownList1.SelectedItem.Value;
    
            bool isok = new UserData().Update(ur);
            if (isok) 
            {
                Session["ok"] = isok;  
            }
            Response.Redirect("Zhujiemian.aspx");
            Response.Write("<script>window.close();</script>");
        }
    
        //取消按钮点击事件
        void Button2_Click(object sender, EventArgs e)
        {
            Response.Write("<script>window.close();</script>");
        }
    
        /// <summary>
        /// 生日下拉列表信息
        /// </summary>
        public void BindDropDown()
        {
            for (int i = 1990; i <= DateTime.Now.Year; i++) //年的下拉列表
            {
                ListItem li = new ListItem(i.ToString(), i.ToString());
                DropDownList2.Items.Add(li);
            }
            for (int i = 1; i <= 12; i++)//月的下拉列表
            {
                ListItem li = new ListItem(i.ToString(), i.ToString());
                DropDownList3.Items.Add(li);
            }
            for (int i = 1; i <= 31; i++)//日的下拉列表
            {
                ListItem li = new ListItem(i.ToString(), i.ToString());
                DropDownList4.Items.Add(li);
            }
        }
    
        /// <summary>
        /// 民族的下拉列表信息
        /// </summary>
        public void BingDD()
        {
            DropDownList1.DataSource = new MinzuData().selectl();
            DropDownList1.DataTextField = "Ummz";
            DropDownList1.DataValueField = "Umzz";
            DropDownList1.DataBind();
        }
    }

  • 相关阅读:
    全国疫情可视化地图(第三阶段)
    全国疫情可视化地图(第二阶段)
    JAVAWEB调用数据库显示图形化显示
    全国疫情可视化地图(第一阶段)
    第二周学习总结
    个人介绍及目前现状
    循环列表下练习循环子数组
    构建之法读书笔记(三)
    构建之法读书笔记(二)
    变叶木
  • 原文地址:https://www.cnblogs.com/zyg316/p/5690229.html
Copyright © 2020-2023  润新知