2017-5-21 项目实战( 小型人员管理系统)

Posted Zoe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2017-5-21 项目实战( 小型人员管理系统)相关的知识,希望对你有一定的参考价值。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// nation 的摘要说明
/// </summary>
public class nation
{
    public string nationcode { get; set; }
    public string nationname { get; set; }
}
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// nationdata 的摘要说明
/// </summary>
public class nationdata
{
    SqlConnection conn=null;
    SqlCommand cmd = null;

    public nationdata()
    {
        conn = new SqlConnection("server=.;database=data0216;user=sa;pwd=123;");
        cmd = conn.CreateCommand();
    }
    public List<nation> selectall() 
    {
        List<nation> nlist = new List<nation>();
        cmd.CommandText = "select * from nation";
        conn.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        while(dr.Read())
        {
            nation n = new nation();
            n.nationcode = dr[0].ToString();
            n.nationname = dr[1].ToString();
            nlist.Add(n);
        }
        conn.Close();
        return nlist;
    }

    public string selectnationname(string ncode)
    {
        string end = "暂无";
        cmd.CommandText = "select * from nation where nationcode=@a";
        cmd.Parameters.Clear();
        cmd.Parameters.AddWithValue("@a", ncode);
        conn.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            dr.Read();
            end = dr["nationname"].ToString();
        }
        conn.Close();
        return end;
    }

}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// user1 的摘要说明
/// </summary>
public class user1
{
    public int ids { get; set; }
    public string username { get; set; }
    public string password { get; set; }
    public string nickname { get; set; }
    public bool sex { get; set; }
    public string sexstr 
    {
        
        get 
    {
        return sex ? "" : "";

    }
    }
    public DateTime birthday { get; set; }
    public int age {
        get
        {
            return DateTime.Now.Year - birthday.Year;
        } 
    }
    public string nation { get; set; }

    public string whiteorred 
    {
        get
        {
            return age>16?"white":"red";
        }
    }
    public string nationname
    {
        get 
        {
            return new nationdata().selectnationname(nation);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// user1data 的摘要说明
/// </summary>
public class user1data
{
    SqlConnection conn=null;
    SqlCommand cmd=null;
    public user1data()
    {
        conn = new SqlConnection("server=.;database=data0216;user=sa;pwd=123;");
        cmd = conn.CreateCommand();
    }
    public List<user1> selectall() 
    {
        List<user1> ulist = new List<user1>();
        cmd.CommandText = "select * from user1";
        conn.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        while(dr.Read())
        {
            user1 u = new user1();
            u.ids = Convert.ToInt32(dr[0]);
            u.username = dr[1].ToString();
            u.password = dr[2].ToString();
            u.nickname = dr[3].ToString();
            u.sex = Convert.ToBoolean(dr[4]);
            u.birthday = Convert.ToDateTime(dr[5]);
            u.nation = dr[6].ToString();
            ulist.Add(u);
        }
        conn.Close();
        return ulist;
    }
    public user1 selectuser(string ids)
    {
        user1 u = null;
        cmd.CommandText = "select * from user1 where ids=@a";
        cmd.Parameters.Clear();
        cmd.Parameters.AddWithValue("@a",ids);
        conn.Open();
        SqlDataReader dr = cmd.ExecuteReader();
       if(dr.HasRows)
       {
           u = new user1();
           dr.Read();
            u.ids = Convert.ToInt32(dr[0]);
            u.username = dr[1].ToString();
            u.password = dr[2].ToString();
            u.nickname = dr[3].ToString();
            u.sex = Convert.ToBoolean(dr[4]);
            u.birthday = Convert.ToDateTime(dr[5]);
            u.nation = dr[6].ToString();
       }
      
        conn.Close();
        return u;
    }
    public user1 selectusername(string uname)
    {
        user1 u = null;
        cmd.CommandText = "select * from user1 where username=@a";
        cmd.Parameters.Clear();
        cmd.Parameters.AddWithValue("@a", uname);
        conn.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            u = new user1();
            dr.Read();
            u.ids = Convert.ToInt32(dr[0]);
            u.username = dr[1].ToString();
            u.password = dr[2].ToString();
            u.nickname = dr[3].ToString();
            u.sex = Convert.ToBoolean(dr[4]);
            u.birthday = Convert.ToDateTime(dr[5]);
            u.nation = dr[6].ToString();
        }

        conn.Close();
        return u;
    }
    public int insertuser(user1 u) 
    {
        int end = 0;
        cmd.CommandText = "insert into user1 values(@a,@b,@c,@d,@e,@f)";
        cmd.Parameters.Clear();
        cmd.Parameters.AddWithValue("@a",u.username);
        cmd.Parameters.AddWithValue("@b",u.password);
        cmd.Parameters.AddWithValue("@c",u.nickname);
        cmd.Parameters.AddWithValue("@d",u.sex);
        cmd.Parameters.AddWithValue("@e",u.birthday);
        cmd.Parameters.AddWithValue("@f",u.nation);
        conn.Open();
        end = cmd.ExecuteNonQuery();
        conn.Close();

        return end;
    }

    public int deleteuser(string id) 
    {
        int end = 0;
        cmd.CommandText = "delete from user1 where ids=@a";
        cmd.Parameters.Clear();
        cmd.Parameters.AddWithValue("@a",id);
        conn.Open();
        end = cmd.ExecuteNonQuery();
        conn.Close();
        return end;
    }

    public int updateuser(user1 u)
    {
        cmd.Parameters.Clear();
        int end = 0;
        if (u.password.Length > 0)
        {
            cmd.CommandText = "update user1 set password=@a,nickname=@b,sex=@c,birthday=@d,nation=@e where ids=@f";
            cmd.Parameters.AddWithValue("@a", u.password);
        }
        else { cmd.CommandText = "update user1 set nickname=@b,sex=@c,birthday=@d,nation=@e where ids=@f"; }
        cmd.Parameters.AddWithValue("@b",u.nickname);
        cmd.Parameters.AddWithValue("@c",u.sex);
        cmd.Parameters.AddWithValue("@d",u.birthday);
        cmd.Parameters.AddWithValue("@e",u.nation);
        cmd.Parameters.AddWithValue("@f",u.ids);
        conn.Open();
        end = cmd.ExecuteNonQuery();
        conn.Close();
        return end;
    }



    public bool hasuser (string uname,string password)
    {
        bool ok = false;
        cmd.CommandText = "select * from user1 where uname=@a and password=@b";
        cmd.Parameters.Clear();
        cmd.Parameters.AddWithValue("@a", uname);
        cmd.Parameters.AddWithValue("@b", password);
      
        conn.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.HasRows) { ok = true; }
        conn.Close();

        return ok;
    }

}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default1.aspx.cs" Inherits="Default1" %>

<!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">
    <table style="width:100%;text-align:center;background-color:navy;">
        <tr style="color:white;height:50px;">
            <td>编号</td>
             <td>用户名</td>
             <td>密码</td>
             <td>昵称</td>
             <td>性别</td>
             <td>生日</td>
            <td>年龄</td>
             <td>民族</td>
            <td>编辑</td>
        </tr>
        <asp:Repeater ID="Repeater1" runat="server">
           <ItemTemplate>
     <tr style="background-color:<%#Eval("whiteorred")%>;">
            <td><%#Eval("ids")%></td>
             <td><%#Eval("username")%></td>
             <td><%#Eval("password")%></td>
             <td><%#Eval("nickname")%></td>
             <td><%#Eval("sexstr")%></td>
             <td><%#Eval("birthday","{0:yyyy年MM月dd日}")%></td>
             <td><%#Eval("age") %></td>
             <td><%#Eval("nationname")%></td>
         <td>
             <input type="button" hehe="<%#Eval("ids")%>" class="btn1" value="编辑" />
             <a onclick="return confirm(\'是否要删除<%#Eval("nickname")%>?\');" href="delete.aspx?i=<%#Eval("ids") %>">删除</a>
         </td>
        </tr>
               </ItemTemplate>
            </asp:Repeater>
    </table>
        <a href="Insert.aspx" target="_blank"><input type="button" value="注册" style="width:100px;height:40px;"/></a>
    </form>
</body>
</html>
<script type="text/javascript">
    var btns = document.getElementsByClassName("btn1");
    for(var i=0;i<btns.length;i++)
    {
        btns[i].onclick = function () { window.open("update.aspx?i=" +this.getAttribute(\'hehe\'), "_blank", "toolbar=no menubar=no width=500 height=500") }
    }

   
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {

        }
        Repeater1.DataSource = new user1data().selectall();

        Repeater1.DataBind();
    }
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="delete.aspx.cs" Inherits="delete" %>

<!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>
        <asp:Literal ID="Literal1" runat="server"></asp:Literal>
    </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 delete : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string s = Request["i"];
        int a = new user1data().deleteuser(s);
        //if (a > 0) { Literal1.Text = "<script>alert(\'删除成功!\');window.location.href=\'Default1.aspx\';</script>"; }
        //else { Literal1.Text = "<script>alert(\'删除失败!\');window.location.href=\'Default1.aspx\';</script>"; }
        Response.Redirect("Default1.aspx");
    }
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="insert.aspx.cs" Inherits="insert" %>

<!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>
    <h1>用户注册</h1>
       用户名: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Label ID="uname_error" runat="server" Text=""></asp:Label><br />
        密码:<asp:TextBox ID="TextBox2" TextMode="Password" runat="server"></asp:TextBox><br />
        确认密码:<asp:TextBox ID="TextBox3" TextMode="Password" runat="server"></asp:TextBox><asp:Label ID="pwd_error" runat="server" Text=""></asp:Label><br />
        昵称:<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><asp:Label ID="nick_error" runat="server" Text=""></asp:Label><br />
       <span style="float:left;"> 性别:</span><asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
            <asp:ListItem Text="" Value="true" Selected="True"></asp:ListItem>
             <asp:ListItem Text="" Value="false"></asp:ListItem>
        </asp:RadioButtonList>

        生日:<asp:DropDownList ID="Dr_year"  runat="server"></asp:DropDownList><asp:DropDownList ID="Dr_month" runat="server"></asp:DropDownList><asp:DropDownList ID="Dr_day" runat="server"></asp:DropDownList>日<br />
       民族: <asp:DropDownList ID="Dr_nation" runat="server"></asp:DropDownList><br />
        <asp:Button OnClientClick="return go();" ID="Button1" runat="server" Text="注册" Style="width:200px;height:50px;" />
    </div>
    </form>
</body>
</html>
<script type="text/javascript">
    var pwdok = false;
    var nickok = false;
    var p1 = document.getElementById("TextBox2");
    var p2 = document.getElementById("TextBox3");
    p1.onkeyup = function () { pwdisok(p1,p2); }
    p2.onkeyup = function () { pwdisok(p1,p2); }
    function pwdisok(pwd1,pwd2)
    {
      
        if (pwd1.value != pwd2.value) {
            document.getElementById("pwd_error").innerText = "两次密码不一致!";
            document.getElementById("pwd_error").style.color = "red";
            pwdok = false;
        }
        else
        {
            document.getElementById("pwd_error").innerText = "正确";
            document.getElementById("pwd_error").style.color = "green";
            pwdok = true;
        }
    }
    document.getElementById("TextBox4").onkeyup = function ()
    {
        if (this.value.length > 0) { nickok = true; }
        else { nickok = false;}
    }
    function go()
    {
        return pwdok&&nickok;
    }

    document.getElementById("Dr_year").onchange = function ()
    {
        var mon = document.getElementById("Dr_month");
        var day = document.getElementById("Dr_day");
        if (mon.value == "2")
        {
            if (this.value % 4 == 0 && this.value % 100 != 0)
            {
                day.options.length = 0;
                for (var i = 1; i < 30; i++)
                {
                    var op = document.createElement("option");
                    op.value = i;
                    op.innerHTML = i;
                    day.appendChild(op);
                }
            }

            else
            {
                day.options.length = 0;
                for (var i = 1; i < 29; i++) {
                    var op = document.createElement("option");
                    op.value = i;
                    op.innerHTML = i;
                    day.appendChild(op);
                }
            }
        }
       
       
    }



    document.getElementById("Dr_month").onchange = function ()
    {
        var day = document.getElementById("Dr_day");
        if (this.value == "2")
        {
            if (this.value % 4 == 0 && this.value % 100 != 0) {
                day.options.length = 0;
                for (var i = 1; i < 30; i++) {
                    var op = document.createElement("option");
                    op.value = i;
                    op.innerHTML = i;
                    day.appendChild(op);
                }
            }

            else {
                day.options.length = 0;
                for (var i = 1; i < 29; i++) {
                    var op = document.createElement("option");
                    op.value = i;
                    op.innerHTML = i;
                    day.appendChild(op);
                }
            }
        }
        else if (this.value == "1" || this.value == "3" || this.value == "5" || thi

以上是关于2017-5-21 项目实战( 小型人员管理系统)的主要内容,如果未能解决你的问题,请参考以下文章

如何选择合适的小型项目管理工具?

Linux sudo权限管理项目实战

中小型局域网规划实战案例

vue项目实战-电商后台管理系统

2017-6-1 Linq 基础查询 (增删改查)

《API接口管理Swagger2实战教程》学习笔记