ajax版学生管理

aspx:

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

<!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>
    <script src="JS/jquery-1.7.2.min.js"></script>
    <link href="CSS/StyleSheet.css" rel="stylesheet" />
    <script src="DatePicker/WdatePicker.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <input type="button" value="刷新" id="aa11" />
        <input type="button" value="添加" id="TJ" />
        <%--登录弹窗--%>
        <%--修改弹窗--%>
        <div id="tc" class="tc">
            <div id="tc-top" class="tc-top">
                学生信息修改
            </div>
            <div id="tc-main" class="tc-main">

                <div class="divc">
                    <div class="divcc1">编号:</div>
                    <div class="divcc2">
                        <asp:TextBox ID="tids" runat="server" ReadOnly="True"></asp:TextBox>
                    </div>
                </div>
                <div class="divc">
                    <div class="divcc1">姓名:</div>
                    <div class="divcc2">
                        <asp:TextBox ID="tname" runat="server"></asp:TextBox>
                    </div>
                </div>
                <div class="divc">
                    <div class="divcc1">性别:</div>
                    <div class="divcc2">
                        <asp:RadioButtonList ID="tsex" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
                            <asp:ListItem Text="" Value="true"></asp:ListItem>
                            <asp:ListItem Text="" Value="false"></asp:ListItem>
                        </asp:RadioButtonList>
                    </div>
                </div>
                <div class="divc">
                    <div class="divcc1">生日:</div>
                    <div class="divcc2">
                        <asp:TextBox ID="tbirthday" runat="server"></asp:TextBox>
                    </div>
                </div>
                <div class="divc">
                    <div class="divcc1">民族:</div>
                    <div class="divcc2">
                        <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
                    </div>
                </div>
                <div class="divc">
                    <div class="divcc1">班级:</div>
                    <div class="divcc2">
                        <asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>
                    </div>
                </div>
                <div class="divc">
                    <div class="divcc1">成绩:</div>
                    <div class="divcc2">
                        <asp:TextBox ID="tscore" runat="server"></asp:TextBox>
                    </div>
                </div>
            </div>
            <div id="tc-bottom" class="tc-bottom">
                <div οnclick="tcbtn1();" id="tc-btn1" class="tc-btn1">
                    修改
                </div>
            </div>
        </div>
        <div id="tc-zz" class="tc-zz">
        </div>
        <%--添加弹窗--%>
        <div id="tc1" class="tc">
            <div id="tc-top1" class="tc-top">
                学生信息添加
            </div>
            <div id="tc-main1" class="tc-main">
                <div class="divc">
                    <div class="divcc1">姓名:</div>
                    <div class="divcc2">
                        <asp:TextBox ID="tname1" runat="server"></asp:TextBox>
                    </div>
                </div>
                <div class="divc">
                    <div class="divcc1">性别:</div>
                    <div class="divcc2">
                        <asp:RadioButtonList ID="tsex1" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
                            <asp:ListItem Text="" Value="true" Selected="True"></asp:ListItem>
                            <asp:ListItem Text="" Value="false"></asp:ListItem>
                        </asp:RadioButtonList>
                    </div>
                </div>
                <div class="divc">
                    <div class="divcc1">生日:</div>
                    <div class="divcc2">
                        <asp:TextBox ID="tbirthday1" runat="server"></asp:TextBox>
                    </div>
                </div>
                <div class="divc">
                    <div class="divcc1">民族:</div>
                    <div class="divcc2">
                        <asp:DropDownList ID="DropDownList11" runat="server"></asp:DropDownList>
                    </div>
                </div>
                <div class="divc">
                    <div class="divcc1">班级:</div>
                    <div class="divcc2">
                        <asp:DropDownList ID="DropDownList22" runat="server"></asp:DropDownList>
                    </div>
                </div>
                <div class="divc">
                    <div class="divcc1">成绩:</div>
                    <div class="divcc2">
                        <asp:TextBox ID="tscore1" runat="server"></asp:TextBox>
                    </div>
                </div>
            </div>
            <div id="Div4" class="tc-bottom">
                <div οnclick="tcbtn2();" id="tcbtn2" class="tc-btn1">
                    添加
                </div>
            </div>
        </div>
        <div id="tc-zz1" class="tc-zz">
        </div>
        <div>
            <%-- 展示内容--%>
            <table style="width: 1000px; position: relative; margin: 0 auto; background-color: green; text-align: center;">
                <thead>
                    <tr style="color: white;">
                        <td>编号</td>
                        <td>姓名</td>
                        <td>性别</td>
                        <td>生日</td>
                        <td>民族</td>
                        <td>班级</td>
                        <td>成绩</td>
                        <td>操作</td>
                    </tr>
                </thead>
                <tbody id="tt"></tbody>
            </table>

        </div>
    </form>
</body>
</html>
<script type="text/ecmascript">
    //生日
    document.getElementById("tbirthday").onfocus = function () {
        WdatePicker({ readOnly: true, maxDate: '%y-%M-%d' });
    }
    document.getElementById("tbirthday1").onfocus = function () {
        WdatePicker({ readOnly: true, maxDate: '%y-%M-%d' });
    }
    //修改
    $("#XG").live("click", function () {

        var a = $(this).attr("class");
        $.ajax({
            url: "updata1.ashx",
            data: { "ids": a },
            type: "post",
            dataType: "json",
            success: function (m) {
                $("#tids").val(m[0].ids);
                $("#tname").val(m[0].name);
                if (m[0].sex == 'True')
                    $("#tsex").children("input:eq(0)").get(0).checked = true;
                else
                    $("#tsex").children("input:eq(1)").get(0).checked = true;
                $("#tbirthday").val(m[0].birthday);
                $("#DropDownList1").val(m[0].nation);
                $("#DropDownList2").val(m[0].class);
                $("#tscore").val(m[0].score);
            },
            error: function () { alert("数据错误!"); }
        });
        $("#tc").animate({ top: 100 }, 500);
        $("#tc-zz").css("display", "block");
    });
    function tcbtn1() {
        $.ajax({
            url: "updata2.ashx",
            data: { "ids": $("#tids").val(), "name": $("#tname").val(), "sex": $("#tsex").children("input:eq(0)").get(0).checked, "birthday": $("#tbirthday").val(), "nation": $("#DropDownList1").val(), "class": $("#DropDownList2").val(), "score": $("#tscore").val() },
            type: "post",
            dataType: "json",
            success: function (m) {
                $("#tt").text("");
                for (var a = 0; a < m.length; a++) {
                    var ee = " <tr style=\"background-color: white;\">";
                    ee += "<td id=\"tr" + a + "\">" + m[a].ids + "</td>";
                    ee += "<td>" + m[a].name + "</td>";
                    ee += "<td>" + m[a].sex + "</td>";
                    ee += "<td>" + m[a].birthday + "</td>";
                    ee += "<td>" + m[a].nation + "</td>";
                    ee += "<td>" + m[a].class + "</td>";
                    ee += "<td>" + m[a].score + "</td>";
                    ee += "<td>";
                    var cc = m[a].ids;
                    ee += "<input type=\"button\" class=\"" + cc + "\" value=\"修改\" id=\"XG\"/>";
                    ee += "<input type=\"button\" class=\"" + cc + "\" value=\"删除\" id=\"SC\"/>";
                    ee += "</td>";
                    ee += " </tr>}";
                    $("#tt").append(ee);
                }
            },
            error: function () { alert("数据错误!"); }
        });
        $("#tc").animate({ top: "110" }, 200).animate({ top: "-500" }, 500, function () {
            $("#tc-zz").css("display", "none");
        });
    }
    //刷新
    $("#aa11").click(function () {
        $.ajax({
            url: "Handler.ashx",
            data: {},
            type: "post",
            dataType: "json",
            success: function (m) {
                $("#tt").text("");
                for (var a = 0; a < m.length; a++) {
                    var ee = " <tr style=\"background-color: white;\">";
                    ee += "<td id=\"tr" + a + "\">" + m[a].ids + "</td>";
                    ee += "<td>" + m[a].name + "</td>";
                    ee += "<td>" + m[a].sex + "</td>";
                    ee += "<td>" + m[a].birthday + "</td>";
                    ee += "<td>" + m[a].nation + "</td>";
                    ee += "<td>" + m[a].class + "</td>";
                    ee += "<td>" + m[a].score + "</td>";
                    ee += "<td>";
                    var cc = m[a].ids;
                    ee += "<input type=\"button\" class=\"" + cc + "\" value=\"修改\" id=\"XG\"/>";
                    ee += "<input type=\"button\" class=\"" + cc + "\" value=\"删除\" id=\"SC\"/>";
                    ee += "</td>";
                    ee += " </tr>}";
                    $("#tt").append(ee);
                }
            },
            error: function () { alert("数据错误!"); }
        });
    });
    //删除
    $("#SC").live("click", function () {
        var a = $(this).attr("class");
        $.ajax({
            url: "delete.ashx",
            data: { "ids": a },
            type: "post",
            dataType: "json",
            success: function (m) {
                $("#tt").text("");
                for (var a = 0; a < m.length; a++) {
                    var ee = " <tr style=\"background-color: white;\">";
                    ee += "<td id=\"tr" + a + "\">" + m[a].ids + "</td>";
                    ee += "<td>" + m[a].name + "</td>";
                    ee += "<td>" + m[a].sex + "</td>";
                    ee += "<td>" + m[a].birthday + "</td>";
                    ee += "<td>" + m[a].nation + "</td>";
                    ee += "<td>" + m[a].class + "</td>";
                    ee += "<td>" + m[a].score + "</td>";
                    ee += "<td>";
                    var cc = m[a].ids;
                    ee += "<input type=\"button\" class=\"" + cc + "\" value=\"修改\" id=\"XG\"/>";
                    ee += "<input type=\"button\" class=\"" + cc + "\" value=\"删除\" id=\"SC\"/>";
                    ee += "</td>";
                    ee += " </tr>}";
                    $("#tt").append(ee);
                }
            },
            error: function () { alert("数据错误!"); }
        });
    });
    //添加
    $("#TJ").live("click", function () {
        $("#tc1").animate({ top: 100 }, 500);
        $("#tc-zz1").css("display", "block");
    });
    function tcbtn2() {
        $.ajax({
            url: "insert.ashx",
            data: { "ids": $("#tids1").val(), "name": $("#tname1").val(), "sex": $("#tsex1").children("input:eq(0)").get(0).checked, "birthday": $("#tbirthday1").val(), "nation": $("#DropDownList11").val(), "class": $("#DropDownList22").val(), "score": $("#tscore1").val() },
            type: "post",
            dataType: "json",
            success: function (m) {
                $("#tt").text("");
                for (var a = 0; a < m.length; a++) {
                    var ee = " <tr style=\"background-color: white;\">";
                    ee += "<td id=\"tr" + a + "\">" + m[a].ids + "</td>";
                    ee += "<td>" + m[a].name + "</td>";
                    ee += "<td>" + m[a].sex + "</td>";
                    ee += "<td>" + m[a].birthday + "</td>";
                    ee += "<td>" + m[a].nation + "</td>";
                    ee += "<td>" + m[a].class + "</td>";
                    ee += "<td>" + m[a].score + "</td>";
                    ee += "<td>";
                    var cc = m[a].ids;
                    ee += "<input type=\"button\" class=\"" + cc + "\" value=\"修改\" id=\"XG\"/>";
                    ee += "<input type=\"button\" class=\"" + cc + "\" value=\"删除\" id=\"SC\"/>";
                    ee += "</td>";
                    ee += " </tr>}";
                    $("#tt").append(ee);
                }
            },
            error: function () { alert("数据错误!"); }
        });
        $("#tc1").animate({ top: "110" }, 200).animate({ top: "-500" }, 500, function () {
            $("#tc-zz1").css("display", "none");
        });
    }
    //
</script>
View Code

css:

.tc {
    position: fixed;
    width: 400px;
    left: 50%;
    margin-left: -200px;
    top: -600px;
    border: 1px solid navy;
    box-shadow: 0 0 10px black;
    z-index: 1001;
    background-color: white;
}

.tc-top {
    width: 100%;
    height: 30px;
    background-color: navy;
    color: white;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    line-height: 30px;
}

.tc-main {
    padding: 20px;
    text-align: center;
}

.tc-bottom {
    position: relative;
    width: 100%;
    height: 40px;
}

.tc-btn1 {
    position: absolute;
    top: 5px;
    left: 50%;
    margin-left: -50px;
    width: 100px;
    height: 30px;
    background-color: navy;
    color: white;
    text-align: center;
    line-height: 30px;
    cursor: pointer;
}

.tc-zz {
    position: fixed;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
    background-color: black;
    opacity: 0.3;
    display: none;
    z-index: 1000;
}

.divc {
    height: 50px;
    width: 100%;
}

.divcc1 {
    text-align: right;
    height: 50px;
    width: 30%;
    float: left;
}

.divcc2 {
    text-align: left;
    height: 50px;
    width: 70%;
    float: left;
}
View Code

ashx:

1刷新:

 public void ProcessRequest(HttpContext context)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("[");
        using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
        {
            List<Stu> ss = con.Stu.ToList();
            int a = ss.Count;
            int cc = 0;
            foreach (Stu s in ss)
            {
                if (s == null) continue;
                cc++;
                if (cc < a)
                { sb.Append("{\"ids\":\"" + s.Ids + "\",\"name\":\"" + s.Name + "\",\"sex\":\"" + s.Sexx + "\",\"birthday\":\"" + s.Birth + "\",\"nation\":\"" + s.NName + "\",\"class\":\"" + s.CName + "\",\"score\":\"" + s.Score + "\"},"); }
                if (cc == a)
                { sb.Append("{\"ids\":\"" + s.Ids + "\",\"name\":\"" + s.Name + "\",\"sex\":\"" + s.Sexx + "\",\"birthday\":\"" + s.Birth + "\",\"nation\":\"" + s.NName + "\",\"class\":\"" + s.CName + "\",\"score\":\"" + s.Score + "\"}"); }
            }

        }
        sb.Append("]");
        context.Response.Write(sb);
        context.Response.End();
    }
View Code

2.修改1:

tringBuilder sb = new StringBuilder();
        sb.Append("[");
        using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
        {
            string s1 = context.Request["ids"];
            Stu sa = con.Stu.Where(r => r.Ids.ToString() == s1).FirstOrDefault();
            if (sa != null)
                sb.Append("{\"ids\":\"" + sa.Ids + "\",\"name\":\"" + sa.Name + "\",\"sex\":\"" + sa.Sex + "\",\"birthday\":\"" + Convert.ToDateTime(sa.Birthday).ToString("yyyy-MM-dd") + "\",\"nation\":\"" + sa.NationCode + "\",\"class\":\"" + sa.ClassCode + "\",\"score\":\"" + sa.Score + "\"}");
        }
        sb.Append("]");
        context.Response.Write(sb);
        context.Response.End();
View Code

修改2:

StringBuilder sb = new StringBuilder();
        sb.Append("[");
        string a = context.Request["ids"];
        string b = context.Request["name"];
        string c = context.Request["sex"];
        string d = context.Request["birthday"];
        string e = context.Request["nation"];
        string f = context.Request["class"];
        string g = context.Request["score"];
        using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
        {
            Stu s = con.Stu.Where(r => r.Ids.ToString() == a).FirstOrDefault();
            if (s != null)
            {
                s.Name = b;
                s.Sex = Convert.ToBoolean(c);
                s.Birthday = Convert.ToDateTime(d);
                s.NationCode = e;
                s.ClassCode = f;
                s.Score = Convert.ToInt32(g);
                con.SubmitChanges();
            }
            List<Stu> ss = con.Stu.ToList();
            int a1 = ss.Count;
            int cc = 0;
            foreach (Stu s1 in ss)
            {
                cc++;
                if (cc < a1)
                { sb.Append("{\"ids\":\"" + s1.Ids + "\",\"name\":\"" + s1.Name + "\",\"sex\":\"" + s1.Sexx + "\",\"birthday\":\"" + s1.Birth + "\",\"nation\":\"" + s1.NName + "\",\"class\":\"" + s1.CName + "\",\"score\":\"" + s1.Score + "\"},"); }
                if (cc == a1)
                { sb.Append("{\"ids\":\"" + s1.Ids + "\",\"name\":\"" + s1.Name + "\",\"sex\":\"" + s1.Sexx + "\",\"birthday\":\"" + s1.Birth + "\",\"nation\":\"" + s1.NName + "\",\"class\":\"" + s1.CName + "\",\"score\":\"" + s1.Score + "\"}"); }
            }
            sb.Append("]");
            context.Response.Write(sb);
            context.Response.End();
        }
View Code

3.添加:

 StringBuilder sb = new StringBuilder();
        sb.Append("[");
        string b = context.Request["name"];
        string c = context.Request["sex"];
        string d = context.Request["birthday"];
        string e = context.Request["nation"];
        string f = context.Request["class"];
        string g = context.Request["score"];
        using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
        {
            Stu s = new Stu();
            s.Name = b;
            s.Sex = Convert.ToBoolean(c);
            s.Birthday = Convert.ToDateTime(d);
            s.NationCode = e;
            s.ClassCode = f;
            s.Score = Convert.ToInt32(g);
            con.Stu.InsertOnSubmit(s);
            con.SubmitChanges();
            List<Stu> ss = con.Stu.ToList();
            int a1 = ss.Count;
            int cc = 0;
            foreach (Stu s1 in ss)
            {
                cc++;
                if (cc < a1)
                { sb.Append("{\"ids\":\"" + s1.Ids + "\",\"name\":\"" + s1.Name + "\",\"sex\":\"" + s1.Sexx + "\",\"birthday\":\"" + s1.Birth + "\",\"nation\":\"" + s1.NName + "\",\"class\":\"" + s1.CName + "\",\"score\":\"" + s1.Score + "\"},"); }
                if (cc == a1)
                { sb.Append("{\"ids\":\"" + s1.Ids + "\",\"name\":\"" + s1.Name + "\",\"sex\":\"" + s1.Sexx + "\",\"birthday\":\"" + s1.Birth + "\",\"nation\":\"" + s1.NName + "\",\"class\":\"" + s1.CName + "\",\"score\":\"" + s1.Score + "\"}"); }
            }
            sb.Append("]");
            context.Response.Write(sb);
            context.Response.End();
        }
View Code

4.删除:

 StringBuilder sb = new StringBuilder();
        sb.Append("[");
        using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
        {
            string s1 = context.Request["ids"];
            Stu sa = con.Stu.Where(r => r.Ids.ToString() == s1).FirstOrDefault();
            con.Stu.DeleteOnSubmit(sa);
            con.SubmitChanges();
            List<Stu> ss = con.Stu.ToList();
            int a = ss.Count;
            int cc = 0;
            foreach (Stu s in ss)
            {
                cc++;
                if (cc < a)
                { sb.Append("{\"ids\":\"" + s.Ids + "\",\"name\":\"" + s.Name + "\",\"sex\":\"" + s.Sexx + "\",\"birthday\":\"" + s.Birth + "\",\"nation\":\"" + s.NName + "\",\"class\":\"" + s.CName + "\",\"score\":\"" + s.Score + "\"},"); }
                if (cc == a)
                { sb.Append("{\"ids\":\"" + s.Ids + "\",\"name\":\"" + s.Name + "\",\"sex\":\"" + s.Sexx + "\",\"birthday\":\"" + s.Birth + "\",\"nation\":\"" + s.NName + "\",\"class\":\"" + s.CName + "\",\"score\":\"" + s.Score + "\"}"); }
            }
        }
        sb.Append("]");
        context.Response.Write(sb);
        context.Response.End();
View Code

 

转载于:https://www.cnblogs.com/zhangxin4477/p/6955186.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
学生信息管理系统是一个常见的应用场景,使用Spring Boot可以快速搭建和开发。下面是一个简单的学生信息管理系统的介绍: 1. 数据库设计:首先需要设计学生信息的数据库表,包括学生ID、姓名、年龄、性别等字段。可以使用MySQL或其他关系型数据库进行存储。 2. 后端开发:使用Spring Boot框架进行后端开发,可以使用Spring Data JPA来简化数据库操作。创建一个学生实体类,定义对应的属性和方法,并使用注解进行数据库映射。 3. 控制器层:创建一个学生控制器类,处理前端请求。可以使用@RestController注解来标识该类为控制器,并定义相应的请求映射和处理方法。 4. 服务层:创建一个学生服务类,处理业务逻辑。可以使用@Service注解来标识该类为服务类,并在其中定义相应的方法来实现学生信息的增删改查等操作。 5. 前端开发:使用HTML、CSS和JavaScript等前端技术进行页面设计和开发。可以使用Thymeleaf模板引擎来渲染动态页面,并通过Ajax技术与后端进行数据交互。 6. 页面展示:创建学生列表页面,用于展示所有学生的信息。可以通过调用后端接口获取学生数据,并使用表格或列表等方式展示。 7. 添加和编辑功能:创建添加和编辑学生信息的页面,可以通过表单来输入学生信息,并通过调用后端接口将数据保存到数据库中。 8. 删除功能:在学生列表页面中,为每个学生信息添加删除按钮,点击按钮时调用后端接口删除对应的学生数据。 9. 查询功能:在学生列表页面中,添加搜索框,可以根据学生姓名或其他条件进行查询,并通过调用后端接口获取符合条件的学生数据。 10. 部署和测试:将项目打包成可执行的jar文件,并部署到服务器上进行测试。可以使用Postman等工具来测试后端接口的功能和性能。 以上是一个简单的学生信息管理系统的介绍,具体的实现方式和细节可以根据实际需求进行调整和完善。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值