<link href="~/Content/bootstrap.css" rel="stylesheet" />
<script src="~/Content/jquery-3.3.1.js"></script>
<h4>后台管理>学生管理>学生列表</h4>
学生名称:<input id="tbName" type="text" />
<select id="slClass"></select>
<input id="Button1" type="button" value="查询" οnclick="btnSel()" class="btn btn-primary" />
<form action="/Student/ImportFile" method="post" enctype="multipart/form-data">
<div>
请选择文件<input id="ExcelFile" type="file" name="ExcelFile" />
<input id="Submit1" type="submit" value="导入信息..." class="btn btn-default" />
<input id="Button1" type="button" value="导出信息..." class="btn btn-default" οnclick="exportfile()" />
</div>
</form>
<table class="table table-bordered" style="background-color:white">
<thead>
<tr>
<th>学号</th>
<th>姓名</th>
<th>性别</th>
<th>班级</th>
<th>QQ</th>
<th>电话</th>
<th>操作</th>
</tr>
</thead>
<tbody id="tab"></tbody>
</table>
<div>
<input id="Button1" type="button" value="首页" class="btn btn-primary" οnclick="showPage('First')" />
<input id="Button1" type="button" value="上一页" class="btn btn-primary" οnclick="showPage('Preve')" />
当前第<label id="PageIndex">1</label>页/共<label id="PageCount"></label>页--
每页<label id="PageSize">3</label>条/共<label id="TotalCount"></label>条
<input id="Button1" type="button" value="下一页" class="btn btn-primary" οnclick="showPage('Next')" />
<input id="Button1" type="button" value="尾页" class="btn btn-primary" οnclick="showPage('Last')" />
</div>
<script>
$(function () {
dropClass();
show();
})
function show() {
var sname = $("#tbName").val();
var cId = $("#slClass").val();
$.ajax({
url: "https://localhost:44313/api/student/ShowStudent?sname=" + sname + "&&cId="+cId+"&&pageIndex="+$("#PageIndex").text()+"&&pageSize="+$("#PageSize").text(),
dataType: "json",
type: "get",
async:false,
success: function (data) {
$("#tab").empty();
$(data).each(function () {
if (data != undefined) {
$("#TotalCount").text(data[0].TotalCount);
$("#PageCount").text(data[0].PageCount);
}
else {
$("#TotalCount").text(0);
$("#PageCount").text(1);
}
var str = '<tr>'
+ '<td>' + this.SNo + '</td>'
+ '<td>' + this.SName + '</td>'
+ '<td>' + (this.SSex ? "男" : "女") + '</td>'
+ '<td>' + this.CName + '</td>'
+ '<td>' + this.Sqq + '</td>'
+ '<td>' + this.SPhone + '</td>'
+ '<td><a href="javascript:DelStudent(' + this.SNo + ')" style="margin-right:10px">删除</a>'
+ '<a href="javascript:UpdStudent(' + this.SNo + ')">修改</a></td>'
+ '</tr>';
$("#tab").append(str);
})
}
})
}
function dropClass() {
$.ajax({
url: "https://localhost:44313/api/Student/ShowClass",
dataType:"json",
type: "get",
async: false,
success: function (data) {
$("#slClass").empty();
$("#slClass").append('<option value="0">==请选择==</option>')
$(data).each(function () {
$("#slClass").append('<option value="' + this.CId + '">' + this.CName + '</option>')
})
}
})
}
function DelStudent(sId) {
if (confirm("确认要删除吗?")) {
$.ajax({
url: "https://localhost:44313/api/student/DelStudent?sId=" + sId,
dataType: "json",
type: "post",
success: function (data) {
if (data > 0) {
alert("删除成功!");
show();
}
else {
alert("删除失败!");
}
}
})
}
}
function showPage(optype) {
var pIndex = $("#PageIndex").text();
var pCount = $("#PageCount").text();
switch (optype) {
case "First":
pIndex=1
break;
case "Preve":
if (pIndex-1>0) {
pIndex--;
}
break;
case "Next":
if (pIndex+1<=pCount) {
pIndex++;
}
break;
case "Last":
pIndex = pCount;
break;
}
$("#PageIndex").text(pIndex);
show();
}
function UpdStudent(sId) {
location.href = "/Student/UpdStudent?sId=" + sId;
}
function exportfile() {
location.href = "/Student/ExportFile";
}
function btnSel() {
show();
}
</script>