考生录入,就是录入考生的准确信息,我们要怎样来完成这个功能点呢,下面和大家一起分享,如图
弹出模态框,还没有录入数据
已录入数据
没有保存的数据
已保存的数据
和录入的数据一模一样,这就是录入考生的信息,代码如下,首先在控制器这边写好代码
全部数据查询&多条件查询
public ActionResult SelectStudentAll(LayuiTablePage layuiTablePage, int AcademeID, int GradeID, int ClassID, string StudentInfo)
{
var listStu = from tbStudent in myModels.PW_Student//学生表
join tbAcademe in myModels.SYS_Academe on tbStudent.AcademeID equals tbAcademe.AcademeID//学院表
join tbSpcialty in myModels.SYS_Specialty on tbStudent.SpecialtyID equals tbSpcialty.SpecialtyID//专业表
join tbGrade in myModels.SYS_Grade on tbStudent.GradeID equals tbGrade.GradeID//年级表
join tbClass in myModels.SYS_Class on tbStudent.ClassID equals tbClass.ClassID//班级表
join tbUser in myModels.PW_User on tbStudent.UserID equals tbUser.UserID//用户表
orderby tbStudent.studentID descending
select new Student//构建的实体类
{
studentID = tbStudent.studentID,//学生ID
UserID = tbStudent.UserID,//用户ID
StudentNumber = tbStudent.StudentNumber,//学号
StudentName = tbStudent.StudentName,//姓名
StudentIDNum = tbStudent.StudentIDNum,//身份证号
StudentSex = tbStudent.StudentSex,//性别
AcademeName = tbAcademe.AcademeName,//学院
SpecialtyName = tbSpcialty.SpecialtyName,//专业
GradeName = tbGrade.GradeName,//年级
ClassName = tbClass.ClassName,//班级
UserNuber = tbUser.UserNuber,//账号
AcademeID = tbStudent.AcademeID,//学院ID
SpecialtyID = tbStudent.SpecialtyID,//专业ID
GradeID = tbStudent.GradeID,//年级ID
ClassID = tbStudent.ClassID//班级ID
};
if (AcademeID > 0)
{
//筛选学院数据
listStu = listStu.Where(m => m.AcademeID == AcademeID);
}
if (GradeID > 0)
{
listStu = listStu.Where(m => m.GradeID == GradeID);
}
if (ClassID > 0)
{
listStu = listStu.Where(m => m.ClassID == ClassID);
}
if (!string.IsNullOrEmpty(StudentInfo))
{
listStu = listStu.Where(m => m.StudentNumber.Contains(StudentInfo) || m.StudentName.Contains(StudentInfo));
}
//获取总数
var intTotalRow = listStu.Count();
List<Student> list = listStu
.Skip(layuiTablePage.GetStartIndex())
.Take(layuiTablePage.limit)
.ToList();
//调用分页封装类
LayuiTableData<Student> layuiTableData = new LayuiTableData<Student>(); ;
layuiTableData.count = intTotalRow;//行总数
layuiTableData.data = list;//具体显示数据
return Json(layuiTableData, JsonRequestBehavior.AllowGet);
}
查询对应学院下的专业信息(下拉框)--考生录入
public ActionResult SelectSpecialty(int AcademeID)
{
var listSpecialty = (from tbSpecialty in myModels.SYS_Specialty
where tbSpecialty.AcademeID == AcademeID//获取选中学院
select new Select
{
id = tbSpecialty.SpecialtyID,
text = tbSpecialty.SpecialtyName
}).ToList();
return Json(listSpecialty, JsonRequestBehavior.AllowGet);
}
查询对应年级和专业下的班级信息(下拉框)
public ActionResult SelectClass(int GradeID, int specialtyId)
{
List<Select> listClass = new List<Select>();
if (specialtyId == 0)
{
listClass = (from tbClass in myModels.SYS_Class
where tbClass.GradeID == GradeID
select new Select
{
id = tbClass.ClassID,
text = tbClass.ClassName
}).ToList();
}
else if (GradeID == 0)
{
listClass = (from tbClass in myModels.SYS_Class
where tbClass.SpecialtyID == specialtyId
select new Select
{
id = tbClass.ClassID,
text = tbClass.ClassName
}).ToList();
}
else
{
listClass = (from tbClass in myModels.SYS_Class
where tbClass.GradeID == GradeID
&& tbClass.SpecialtyID == specialtyId
select new Select
{
id = tbClass.ClassID,
text = tbClass.ClassName
}).ToList();
}
return Json(listClass, JsonRequestBehavior.AllowGet);
}
再到视图这边写代码
//打开考生录入模态框
function opneInsert() {
//重置表单
$("#formInsertExaminee").resetForm();
//清空下拉框
$("#IsSpecialty").empty();
$("#IsGrade").empty();
$("#IsClass").empty();
//清空图片
$("#IsImgStudentPicture").attr("src", "");
//学院下拉菜单数据的绑定
createSelect("IsAcademe", "SelectAcademe");
//学院下拉菜单数据绑定触发专业和年级下拉菜单数据的绑定
$("#IsAcademe").change(function () {
var academeId = $("#IsAcademe").val();
//专业下拉框数据绑定
createSelect("IsSpecialty", "/ExaminationManagement/SetExaminee/SelectSpecialty?AcademeID=" + academeId);
//年级下拉框数据绑定
createSelect("IsGrade", "/ExaminationManagement/SetExaminee/SelectGrade?AcademeID=" + academeId);
//清空班级数据
$("#IsClass").empty();
});
//年级 & 专业下拉框数据绑定触发班级下拉菜单数据的绑定
//专业
$("#IsSpecialty").change(function () {
var specialtyId = $("#IsSpecialty").val();
var gradeId = $("#IsGrade").val();
createSelect("IsClass", "/ExaminationManagement/SetExaminee/SelectClass?GradeID=" + gradeId + "&specialtyId=" + specialtyId);
});
//年级
$("#IsGrade").change(function () {
var specialtyId = $("#IsSpecialty").val();
var gradeId = $("#IsGrade").val();
createSelect("IsClass", "/ExaminationManagement/SetExaminee/SelectClass?GradeID=" + gradeId + "&specialtyId=" + specialtyId);
});
//弹出模态框
$("#modInsertExaminee").modal("show");
}
//新增考生录入保存
$("#btnSaveInsert").click(function () {
//获取页面数据
var AcademeID = $("#formInsertExaminee [name='AcademeID']").val();//学院ID
var SpecialtyID = $("#formInsertExaminee [name='SpecialtyID']").val();//专业ID
var GradeID = $("#formInsertExaminee [name='GradeID']").val();//年级ID
var ClassID = $("#formInsertExaminee [name='ClassID']").val();//班级ID
var StudentIDNum = $("#formInsertExaminee [name='StudentIDNum']").val();//身份证
var StudentNum = $("#formInsertExaminee [name='StudentNumber']").val();//学号
var UniformAuthenticationCode = $("#formInsertExaminee [name='UniformAuthenticationCode']").val();//统一认证码
var StudentName = $("#formInsertExaminee [name='StudentName']").val();//姓名
//必填项数据不能为空
if (AcademeID > 0 && SpecialtyID > 0 && GradeID > 0 && ClassID >
0 && StudentNum != "" && UniformAuthenticationCode != "" &&
StudentName != "") {
//显示加载层
var layerIndex = layer.load(0);
//ajaxSubmit()提交表单:我们直接通过form提交的话,提交后当前页面跳转到form的action所指向的页面。
//然而,很多时候我们并不希望提交表单后页面跳转,那么,我们就可以使用ajaxSubmit(obj)来提交数//ajaxSubmit(obj)方法是jQuery的一个插件
jquery.form.js里面的方法,所以使用此方法需要先引入这个插件
$("#formInsertExaminee").ajaxSubmit(function (returnJson) {
//关闭加载层
layer.close(layerIndex);
if (returnJson.State == true) {
//关闭模态框
$("#modInsertExaminee").modal("hide");
//刷新table
tabStudentSearch();
}
//提示
layer.alert(returnJson.Text, { icon: 0, title: '提示' });
});
}
else {
layer.alert('请填写完整信息', { icon: 0, title: '提示' });
}
})
每句代码的作用我都已经注释好了,慢慢的去分析就能懂了