最近我们已经接手了我们传承的的ITOO项目,虽然现在还是学习阶段,但是总是还有一些可以完成的东西的。通过需求学习阶段,对照给的原型,逐渐的我们发现了各种各样的问题,有的是根据个人性格有关,有的是对需求的理解有关。而对于我们负责的新生这面来说,我看到了需求没有看到作品,最为我第一独立完成在ITOO里面的项目,很想分享一下。
需求:我们有学院报表,专业报表和新生报表。但是对于我们的新生报表,我就是认为它不是最好的,通过跟组长协商,我自己确定了一版临时的报表:
前台界面:
@{ ViewBag.Title = "Index"; } @*<h2>Index</h2>*@ <html> <head> <title>学生报表</title> <script src="../../Scripts/MyScripts/FreshStudent.js"></script> </head> <body> <div style="margin-top:30px;margin-left:20px;"> <div class="easyui-panel" title="查询" style="1250px;"> <div style="margin:10px 20px;float:left"> @*加载搜索框*@ 请输入要查询的内容: <input class="easyui-textbox" id="txtSearch" name="BidProjectId" onkeydown="Enter();" maxlength="20" style="150px;"> <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="stuSearch()" >查询</a> <a id="download" href="javascript:void(0)" class="easyui-linkbutton" style="margin-left :720px";data-options="iconCls:'',plain:true" onclick="ExportScoreSummary()" >导出Excel</a> </div> </div> </div> <div id="ContentAreas" style="margin-top: 15px; margin-left: 20px; 960px;"> <table id="dt" class="easyui-datagrid" title="学生报表" style=" 1250px; height: auto" data-options=" iconCls: 'icon-edit', singleSelect: true, rownumbers:true, toolbar: '#tb', url: '', method: 'get', @*onClickRow: onClickRow*@"> <thead> <tr> <th data-options="field:'StudentCode',150,align:'center'" >学号</th> <th data-options="field:'StudentName',120,align:'center'">姓名</th> <th data-options="field:'StudentSex',120,align:'center'">性别</th> <th data-options="field:'StudentScore',120,align:'center'">分数</th> <th data-options="field:'Education',120,align:'center'">学历</th> <th data-options="field:'MajorName',150,align:'center'">专业名称</th> <th data-options="field:'DepName',150,align:'center'">学院名称</th> <th data-options="field:'StudentTel',150,align:'center'">联系方式</th> <th data-options="field:'IsCheck',120,align:'center'">是否报道</th> </tr> </thead> </table> </div> </body> </html>
JavaScript:<span style="font-size:18px;">$(function () { $("#ContentAreas").css('display', 'block'); document.getElementById('txtSearch').value = " "; $("#a").css({ "display": "block", "position": "fixed", "top": "20px", "left": "10px", "width": "400px", "margin-bottom": "0px" }); $("#footer").css('display', 'none'); $.ajax({ url: '/FreshStudent/SelectAllStu', success: function (data) { var array = new Array; //alert(data.length); if (data.length != 0) { for (var i = 0; i < data.length; i++) { var obj = new Object(); obj.StudentCode = data[i].StudentCode; obj.StudentName = data[i].Name; obj.StudentSex = data[i].strSex; obj.StudentScore = data[i].Score; obj.Education = data[i].Level; obj.MajorName = data[i].FreshMajorName; obj.DepName = data[i].FreshDepartmentName; obj.StudentTel = data[i].TelNum; obj.IsCheck = data[i].strCheckIn; array.push(obj); } } else { $.messager.alert('提示', '没有搜索到学生信息!', 'warnning'); } $('#dt').datagrid('loadData', array); } }) }) function stuSearch() { var txtSearch = $('#txtSearch').val(); txtSearch =$.trim(txtSearch); if (txtSearch == "" || txtSearch == null) { //李卫中 查询所有学生 $.ajax({ url: '/FreshStudent/SelectAllStu', success: function (data) { var array = new Array; //alert(data.length); if (data.length != 0) { for (var i = 0; i < data.length; i++) { var obj = new Object(); obj.StudentCode = data[i].StudentCode; obj.StudentName = data[i].Name; obj.StudentSex = data[i].strSex; obj.StudentScore = data[i].Score; obj.Education = data[i].Level; obj.MajorName = data[i].FreshMajorName; obj.DepName = data[i].FreshDepartmentName; obj.StudentTel = data[i].TelNum; obj.IsCheck = data[i].strCheckIn; array.push(obj); } } else { $.messager.alert('提示', '没有搜索到学生信息!', 'warnning'); } $('#dt').datagrid('loadData', array); } }) } else { $.ajax({ url: '/FreshStudent/SelectStu?strlike=' + txtSearch, success: function (data) { //alert(data.length); var array = new Array; //alert(data.length); if (data.length != 0) { for (var i = 0; i < data.length; i++) { var obj = new Object(); obj.StudentCode = data[i].StudentCode; obj.StudentName = data[i].Name; obj.StudentSex = data[i].strSex; obj.StudentScore = data[i].Score; obj.Education = data[i].Level; obj.MajorName = data[i].FreshMajorName; obj.DepName = data[i].FreshDepartmentName; obj.StudentTel = data[i].TelNum; obj.IsCheck = data[i].strCheckIn; array.push(obj); } } else { $.messager.alert('提示', '没有搜索到学生信息!', 'warnning'); } $('#dt').datagrid('loadData', array); } }) } //$('#dg').datagrid('reload', {//重新加载表信息datagrid // strLike: searchName //参数名称 //}); } function Enter() { var event = window.event || arguments.callee.caller.arguments[0]; if (event.keyCode == 13) { stuSearch(); }; }</span>
Controller:<span style="font-size:18px;"> #region 模糊查询的结果+ProcessRequest() /// <summary> /// 模糊查询的结果 /// </summary> /// <returns></returns> public string ProcessRequest() { Response.ContentType = "text/plain"; string strLike = Server.UrlDecode(Request.QueryString["strLike"]); //查询结果 List<FreshStudentViewModel> SeriesResult = stuService.LoadStrLikeEntities(strLike); string[] results = { "CandidateID", "Name", "Level" }; return GetLikeStr<FreshStudentViewModel>(SeriesResult, results).ToString(); } #endregion #region GetLikeStr+联想-获得查询出来的字符串+李卫中+2015年12月29日12:08:11 //<summary> //模糊查询-获得查询出来的字符串 //</summary> //<typeparam name="T">泛型</typeparam> //<param name="lsobject">传入的具体list</param> //<param name="results">字符串数组,起重包含要查询的字段名称</param> //<returns>拼接的字符串</returns> public StringBuilder GetLikeStr<T>(List<T> lsobject, string[] results) { StringBuilder sb = new StringBuilder(); if (lsobject.Count != 0) { for (int i = 0; i < lsobject.Count; i++) { var item = lsobject.ElementAt(i); for (int j = 0; j < results.Length; j++) { System.Reflection.PropertyInfo pi = item.GetType().GetProperty(results[j]); if (pi.GetValue(item, null) != null) { string querryCondititon = pi.GetValue(item, null).ToString(); sb.Append(querryCondititon).Append(","); } } } sb.Remove(sb.Length - 1, 1); } return sb; } #endregion #region 学生报表查询所有学生SelectAllStu() ---李卫中--2015-12-30 /// <summary> /// 学生报表查询所有学生 /// </summary> /// <returns></returns> public ActionResult SelectAllStu() { List<FreshStudentViewModel> stuList = new List<FreshStudentViewModel>(); stuList = stuService.SelectAllStu(); return Json(stuList,JsonRequestBehavior.AllowGet); } #endregion #region 学生报表根据输入条件查询所有学生SelectAllStu(strlike) ---李卫中--2015-12-30 /// <summary> /// 学生报表查询所有学生 /// </summary> /// <returns></returns> public ActionResult SelectStu(string strlike) { //strlike = Request["txtSearch"].ToString(); ; List<FreshStudentViewModel> stuList = new List<FreshStudentViewModel>(); stuList = stuService.SelectStu(strlike); return Json(stuList, JsonRequestBehavior.AllowGet); } #endregion </span>
至于后台的服务端的界面,就没有什么好看的了,实现了模糊查询,效果很好!(数据库原因,效果贴图,另行补发)
总结:
学习,就是这样,一步通,步步通。学习的时候不能只是看,最终还是要动手看,没有动手,就永远没有真正的发言权!