tmr.jsp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <%@ page contentType="text/html; charset=utf-8" session="false" %>
  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
  4. <head>
  5. <title>我的工作台</title>
  6. <%@ include file="../common/header.jsp" %>
  7. <script type="text/javascript">
  8. var mydata,operType;
  9. $(document).ready( function() {
  10. loadList(); //加载jqgrid
  11. $("#list").jqGrid("setGridHeight",$(window).height() - 105);
  12. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
  13. });
  14. $(window).resize(function(){
  15. $("#list").jqGrid("setGridHeight",$(window).height() - 105);
  16. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
  17. });
  18. //jqgrid初始化
  19. function loadList(){
  20. jQuery("#list").jqGrid({
  21. datatype: "local", //从服务器端返回的数据类型,(表格期望接收的数据类型)。可选类型:xml,xmlstring,json,local,function
  22. height: "70%", //高度
  23. colNames:['主键','TMR设备编号','数据采集卡编号', '顺序', '默认驾驶员', '最大搅料量(kg)', '是否启用'], //列名
  24. colModel:[
  25. {
  26. name: "ID",
  27. index: "ID",
  28. align: "center",
  29. sorttype: "string",
  30. editable: true,
  31. hidden: true
  32. //editoptions:{readonly:true} 如果要显示该列可以设置只读
  33. },
  34. {
  35. name: "TNAME",
  36. index: "TNAME",
  37. align: "center",
  38. sorttype: "string",
  39. editable: true,
  40. editrules:{
  41. required: true,
  42. custom: true,
  43. custom_func: checkName
  44. }
  45. },
  46. {
  47. name: "DataCaptureNo",
  48. index: "DataCaptureNo",
  49. align: "center",
  50. sorttype: "int",
  51. editable: true,
  52. editrules: {
  53. integer: true,
  54. custom: true,
  55. custom_func: checkDataCaptureNo
  56. }
  57. },
  58. {
  59. name: "SORT",
  60. index: "SORT",
  61. align: "center",
  62. sorttype: "int",
  63. editable: true,
  64. editrules:{
  65. required: true,
  66. integer: true
  67. }
  68. },
  69. {
  70. name: "DNAME",
  71. index: "DNAME",
  72. align: "center",
  73. sorttype: "int",
  74. editable: true,
  75. edittype: "select",
  76. editoptions:{
  77. dataUrl: "${contextPath }/admin/basicdata/tmrselect.html"
  78. }
  79. },
  80. {
  81. name: "maxStirFeed",
  82. index: "maxStirFeed",
  83. align: "center",
  84. sorttype: "number",
  85. editable: true,
  86. editrules: {number: true}
  87. },
  88. {
  89. name: "ENABLE",
  90. index: "ENABLE",
  91. align: "center",
  92. sorttype: "string",
  93. editable: true,
  94. edittype: "select",
  95. editoptions: {value:{"Yes":"是","No":"否"}}
  96. }
  97. ],
  98. caption: "TMR设备管理", //标题
  99. cellEdit: true,
  100. cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
  101. afterSaveCell: function(rowid,name,val,iRow,iCol) {
  102. var rowData = $("#list").jqGrid("getRowData",rowid);
  103. $.ajax({
  104. async: false,
  105. type: 'POST',
  106. dataType:'json', //返回类型jsond
  107. data: "ID="+rowData.ID+"&colName="+name+"&colValue="+val,
  108. url: "${contextPath }/admin/basicdata/tmrupdatedyg.html",
  109. error: function(){alert("系统错误");},
  110. success: function(json){
  111. }
  112. });
  113. },
  114. pager: "#page", //#page分页控件绑定的位置对象
  115. rowNum: 100, //每页显示条数
  116. rowList: [100,200,300,400], //分页下拉选项内容
  117. rownumbers: true, //是否显示行数
  118. viewrecords: true, //是否显示总条数
  119. emptyrecords: "无数据", //服务器返回空列表时显示的内容
  120. autowidth: true, //自动调节宽度
  121. sortname: 'SORT', //按SORT进行排序 默认asc
  122. altRows: true, //设置表格是否允许行交替变色值
  123. altclass:"tdbgmouseover" //自定义隔行变色的样式
  124. });
  125. //获取数据集
  126. mydata = getLists();
  127. if(mydata!=null){
  128. for(var i=0;i<=mydata.length;i++){
  129. jQuery("#list").jqGrid('addRowData',i+1,mydata[i]);
  130. }
  131. jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
  132. }
  133. //绑定、设置工具栏
  134. jQuery("#list").jqGrid("navGrid","#page",{
  135. add: true, addtext: "添加",
  136. edit: false, edittext: "编辑",
  137. del: true, deltext: "删除",refresh: false,
  138. addfunc: addRow, //自定义添加方法
  139. delfunc: deleteRow, //自定义删除方法
  140. searchtext: "搜索",
  141. refreshtext: "刷新",
  142. alerttext:"请选择一条记录!"
  143. });
  144. }
  145. //获取服务器数据
  146. function getLists(){
  147. $.ajax({
  148. async: false,
  149. type: 'POST',
  150. dataType:'json', //返回类型json
  151. url: "${contextPath }/admin/basicdata/tmrlist.html",
  152. error: function(){alert("系统错误");},
  153. success: function(json){
  154. mydata = json;
  155. }
  156. });
  157. return mydata;
  158. }
  159. //自定义添加方法
  160. function addRow(){
  161. var ids = $("#list").jqGrid("getDataIDs");
  162. $("#list").jqGrid("addRowData",ids.length+1,{},"first");
  163. $.ajax({
  164. async: false,
  165. type: "POST",
  166. dataType:"json", //返回类型jsond
  167. data: "oper=add&selId=",
  168. url: "${contextPath }/admin/basicdata/tmrupdate.html",
  169. error: function(){alert("系统错误");},
  170. success: function(json){
  171. $("#list").clearGridData(); //清空原grid数据
  172. loadList(); //重新载入服务器数据
  173. }
  174. });
  175. }
  176. //自定义删除方法
  177. function deleteRow(){
  178. var count = 0;
  179. var flag = confirm("您确定要删除吗?");
  180. if(flag){
  181. var row = $("#list").jqGrid("getGridParam","selrow");
  182. var selRow = $("#list").jqGrid("getRowData",row);
  183. $.ajax({
  184. async: false,
  185. type: "POST",
  186. dataType:"json", //返回类型jsond
  187. data: "selId="+selRow.ID,
  188. url: "${contextPath }/admin/basicdata/querytmrglxx.html",
  189. error: function(){alert("系统错误");},
  190. success: function(json){
  191. count = json.status;
  192. }
  193. });
  194. if(count == 0){
  195. $.ajax({
  196. async: false,
  197. type: "POST",
  198. dataType:"json", //返回类型jsond
  199. data: "oper=del&selId="+selRow.ID,
  200. url: "${contextPath }/admin/basicdata/tmrupdate.html",
  201. error: function(){alert("系统错误");},
  202. success: function(json){
  203. $("#list").clearGridData(); //清空原grid数据
  204. loadList(); //重新载入服务器数据
  205. }
  206. });
  207. }else{
  208. alert("该记录被引用、不能删除!!!");
  209. }
  210. }
  211. }
  212. //自定义验证名称是否存在方法
  213. function checkName(value, colname){
  214. var flag = 0;
  215. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  216. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  217. $.ajax({
  218. async: false,
  219. type: 'POST',
  220. data: "entityName="+value+"&type="+operType+"&entityId="+rowData.ID,
  221. dataType: 'json',
  222. url: "${contextPath}/admin/basicdata/tmrcheck.html",
  223. error: function(){alert("系统错误");},
  224. success: function(json){
  225. flag = json.status;
  226. }
  227. });
  228. if(flag == 0){
  229. return [true,""];
  230. }else{
  231. return [false,"TMR设备编号已经存在!"];
  232. }
  233. }
  234. //自定义验证数据采集卡编号是否存在方法
  235. function checkDataCaptureNo(value, colname){
  236. var flag = 0;
  237. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  238. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  239. $.ajax({
  240. async: false,
  241. type: 'POST',
  242. data: "entityName="+value+"&type="+operType+"&entityId="+rowData.ID,
  243. dataType: 'json',
  244. url: "${contextPath}/admin/basicdata/tmrCheckDataCaptureNo.html",
  245. error: function(){alert("系统错误");},
  246. success: function(json){
  247. flag = json.status;
  248. }
  249. });
  250. if(flag == 0){
  251. return [true,""];
  252. }else{
  253. return [false,"数据采集卡编号已经存在!"];
  254. }
  255. }
  256. </script>
  257. </head>
  258. <body style="background-color: #E0E0E0">
  259. <div>
  260. <div class="navfrm">
  261. <span>当前位置:</span>
  262. <span><a href="${contextPath }/admin/welcome.html">首页</a></span>
  263. <span>&nbsp;>>&nbsp;</span>
  264. <span>TMR设备管理</span>
  265. </div>
  266. <table id="list"></table>
  267. <div id="page"></div>
  268. </div>
  269. </body>
  270. </html>