dhtmlxGrid分页查询,条件查询实例
使用jquery的ajax get将页面条件请求到后台,取得数据库数据,分页查询,返回前台grid中。
引入所需文件:
- <script>window.dhx_globalImgPath = "dhtmlxCombo/codebase/imgs/";</script>
- <link rel="stylesheet" href="css/dhtmlxgrid.css" type="text/css"></link>
- <link rel="stylesheet" type="text/css"
- href="js/pagination/jquery.pagination/pagination.css" />
- <script type="text/javascript" src="js/jquery-1.6.1.js"></script>
- <script type="text/javascript"
- src="js/pagination/jquery.pagination/jquery.pagination.js"></script>
- <script type="text/javascript" src="js/dhtmlxgrid.js"></script>
- <link rel="stylesheet" href="css/dhtmlxcalendar.css" type="text/css"></link>
- <link rel="stylesheet" href="css/dhtmlxcalendar_dhx_blue.css"
- type="text/css"></link>
- <link rel="stylesheet" type="text/css"
- href="dhtmlxCombo/codebase/dhtmlxcombo.css" />
- <link rel="stylesheet" type="text/css"
- href="css/dhtmlxgrid_dhx_custom.css" />
- <link href="css/storemanage.css" type="text/css" rel="stylesheet" />
- <link rel="stylesheet" href="css/dhtmlxgrid.css" type="text/css"></link>
- <script type="text/javascript"
- src="dhtmlxGrid/codebase/excells/dhtmlxgrid_excell_cntr.js"></script>
- <script type="text/javascript"
- src="dhtmlxGrid/codebase/ext/dhtmlxgrid_filter.js"></script>
- <script type="text/javascript"
- src="dhtmlxGrid/codebase/ext/dhtmlxgrid_validation.js"></script>
- <script type="text/javascript" src="js/dhtmlxcalendar.js"></script>
- <script type="text/javascript" src="js/wpCalendar.js"></script>
<script>window.dhx_globalImgPath = "dhtmlxCombo/codebase/imgs/";</script>
<link rel="stylesheet" href="css/dhtmlxgrid.css" type="text/css"></link>
<link rel="stylesheet" type="text/css"
href="js/pagination/jquery.pagination/pagination.css" />
<script type="text/javascript" src="js/jquery-1.6.1.js"></script>
<script type="text/javascript"
src="js/pagination/jquery.pagination/jquery.pagination.js"></script>
<script type="text/javascript" src="js/dhtmlxgrid.js"></script>
<link rel="stylesheet" href="css/dhtmlxcalendar.css" type="text/css"></link>
<link rel="stylesheet" href="css/dhtmlxcalendar_dhx_blue.css"
type="text/css"></link>
<link rel="stylesheet" type="text/css"
href="dhtmlxCombo/codebase/dhtmlxcombo.css" />
<link rel="stylesheet" type="text/css"
href="css/dhtmlxgrid_dhx_custom.css" />
<link href="css/storemanage.css" type="text/css" rel="stylesheet" />
<link rel="stylesheet" href="css/dhtmlxgrid.css" type="text/css"></link>
<script type="text/javascript"
src="dhtmlxGrid/codebase/excells/dhtmlxgrid_excell_cntr.js"></script>
<script type="text/javascript"
src="dhtmlxGrid/codebase/ext/dhtmlxgrid_filter.js"></script>
<script type="text/javascript"
src="dhtmlxGrid/codebase/ext/dhtmlxgrid_validation.js"></script>
<script type="text/javascript" src="js/dhtmlxcalendar.js"></script>
<script type="text/javascript" src="js/wpCalendar.js"></script>
js代码
- <script>
- var mygrid;
- var combo_unite;
- var myCalendar;
- var combo_intype;
- var intype='';
- var insheetno='';
- var date1='';
- var date2='';
- var unitname='';
- var sheetmname='';
- var checkmname='';
- $(document).ready(function(){
- adjustDisp();
- mygrid = new dhtmlXGridObject('grid_storein');
- mygrid.enableAutoWidth(true);
- mygrid.setImagePath("dhtmlxGrid/codebase/imgs/");
- mygrid.setSkin("dhx_custom");
- mygrid.setHeader("入库单号,往来单位,入库类型,制单人,制单日期,金额,审核人,审核时间,记账人,记账日期,备注");
- mygrid.setInitWidths("*,*,*,*,*,*,*,*,*,*,*");
- mygrid.setColTypes("ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro");
- mygrid.setColAlign("left,left,left,left,left,left,left,left,left,left,left");
- mygrid.init();
- combo_intype = new dhtmlXCombo("combo_zone1", "alfa1", 105);
- combo_intype.enableFilteringMode(true);
- //combo_intype.attachEvent("comboFilter",comboFilter(13, json, 'combo_intype', 'py', true, true));
- combo_unite = new dhtmlXCombo("combo_zone2", "alfa2", 155);
- combo_unite.enableFilteringMode(true);
- //combo_unite.attachEvent("comboFilter",comboFilter(13, json, 'combo_intype', 'py', true, true));
- // y.addOption([[1, 'aaaa', "color:red"], [2, 'bbbb'], [3, 'cccc'], [4, 'dddd'], [5, 'eeee']]);
- combo1();
- combo2();
- //alert('1');
- myCalendar = new dhtmlXCalendarObject(["date1", "date2"]);
- loadCount_no();
- });
- function loadCount_no(){
- intype=combo_intype.getComboText();// 取得页面上条件,入库类型 作为查询条件传到后台
- insheetno=$('#insheetno').val();// 取得页面上条件,入库单号 作为查询条件传到后台
- date1=$('#date1').val();// 取得页面上条件,入库日期1 作为查询条件传到后台
- date2=$('#date2').val();// 取得页面上条件,入库日期2 作为查询条件传到后台
- unitname=combo_unite.getComboText();//
- // alert($('#sheetmname').val());
- sheetmname=$('#sheetmname').val();// 取得页面上条件,制单人
- checkmname=$('#checkmname').val();// 取得页面上条件,审核人
- if(intype==''||intype==null){
- intype='';
- }
- if(insheetno==''||insheetno==null){
- insheetno='';
- }
- if(date1==''||insheetno==null){
- date1='';
- }
- if(date2==''||insheetno==null){
- date2='';
- }
- if(unitname==''||unitname==null){
- unitname='';
- }
- if(sheetmname==''||sheetmname==null){
- sheetmname='';
- }
- if(checkmname==''||checkmname==null){
- checkmname='';
- }
- //intype = encodeURI(encodeURI(intype));
- //insheetno = encodeURI(encodeURI(insheetno));
- //unitname = encodeURI(encodeURI(unitname));
- //date1 = encodeURI(encodeURI(date1));
- //date2 = encodeURI(encodeURI(date2));
- //sheetmname = encodeURI(encodeURI(sheetmname));
- //checkmname = encodeURI(encodeURI(checkmname));
- intype=encodeURIComponent(intype);
- insheetno=encodeURIComponent(insheetno);
- unitname=encodeURIComponent(unitname);
- date1=encodeURIComponent(date1);
- date2=encodeURIComponent(date2);
- sheetmname=encodeURIComponent(sheetmname);
- checkmname=encodeURIComponent(checkmname);
- $.ajax({
- async:false,
- cache:false,
- type:"GET",
- url:"sick3/getCounttnb.htm?intype="+intype+"&insheetno="+insheetno+"&unitname="+unitname+"&date1="+date1+"&date2="+date2+"&sheetmname="+sheetmname+"&checkmname="+checkmname,
- error:function(){
- alert("服务器内部错误!");
- },
- success:function(data){
- if(data=='fail'){
- alert("获取数据失败!");
- }else{
- //alert(data);
- createPagination_no(data);
- }
- }
- });
- }
- var pageSize = 10;
- var pageIndex = 0;
- function createPagination_no(pageCount){//创建分页标签,pageCount为返回的记录数
- if(pageCount==0){
- pageCount=0;
- }
- //分页,pageCount是总条目数,这是必选参数,其它参数都是可选
- $("#pagination").pagination(pageCount, {
- callback: pageCallback_no,
- prev_text: '上一页', //上一页按钮里text
- next_text: '下一页', //下一页按钮里text
- items_per_page: pageSize, //显示条数
- num_display_entries: 6, //连续分页主体部分分页条目数
- current_page: pageIndex, //当前页索引
- num_edge_entries: 2 //两侧首尾分页条目数
- });
- }
- function pageCallback_no(index, jq){//翻页回调
- pageIndex = index; //当前页索引
- loadgrid_no(index);
- return false;
- }
- //条件查询获取当前页未处理报表
- function loadgrid_no(index){
- intype=combo_intype.getComboText();
- insheetno=$('#insheetno').val();
- date1=$('#date1').val();
- date2=$('#date2').val();
- unitname=combo_unite.getComboText();
- sheetmname=$('#sheetmname').val();
- checkmname=$('#checkmname').val();
- if(intype==''||intype==null){
- intype='';
- }
- if(insheetno==''||insheetno==null){
- insheetno='';
- }
- if(date1==''||insheetno==null){
- date1='';
- }
- if(date2==''||insheetno==null){
- date2='';
- }
- if(unitname==''||unitname==null){
- unitname='';
- }
- if(sheetmname==''||sheetmname==null){
- sheetmname='';
- }
- if(checkmname==''||checkmname==null){
- checkmname='';
- }
- //intype = encodeURI(encodeURI(intype));
- //insheetno = encodeURI(encodeURI(insheetno));
- //unitname = encodeURI(encodeURI(unitname));
- //date1 = encodeURI(encodeURI(date1));
- //date2 = encodeURI(encodeURI(date2));
- //sheetmname = encodeURI(encodeURI(sheetmname));
- //checkmname = encodeURI(encodeURI(checkmname));
- intype=encodeURIComponent(intype);
- insheetno=encodeURIComponent(insheetno);
- unitname=encodeURIComponent(unitname);
- date1=encodeURIComponent(date1);
- date2=encodeURIComponent(date2);
- sheetmname=encodeURIComponent(sheetmname);
- checkmname=encodeURIComponent(checkmname);
- if(index!=0){
- index = pageIndex;
- }
- //mygrid.clearAndLoad("sick3/loadtnb.htm");
- //alert('3');
- //alert(intype);
- mygrid.clearAndLoad("sick3/loadtnb.htm?index="+index+"&size="+pageSize+"&intype="+intype+"&insheetno="+insheetno+"&unitname="+unitname+"&date1="+date1+"&date2="+date2+"&sheetmname="+sheetmname+"&checkmname="+checkmname);
- }
- function adjustDisp(){//高度自适应,取相应的数据
- var avalibleHeight = $(window).height()-250;
- if(avalibleHeight>260){
- pageSize = Math.floor((avalibleHeight-27)/26);
- $("#grid_newApply").css("height",avalibleHeight);
- }
- }
- function combo1(){
- $.ajax({
- type:"post",
- url: "sick3/hellohello.htm",
- cache: false,
- error:function(){
- // alert("没有该病人记录!");
- },
- success: function(data){
- if(data=="fail"){
- alert("错误");
- }else{
- //alert(data[0].contents);
- var json = eval("{" + data + "}");
- //alert(json[0].contents);
- for(var i=0;i<json.length;i++){
- // alert(json[i].contents);
- combo_intype.addOption(i,json[i].contents);
- }
- }
- }
- });
- }
- function combo2(){
- $.ajax({
- type:"post",
- url: "sick3/combo2.htm",
- cache: false,
- error:function(){
- //alert("没有该病人记录!");
- },
- success: function(data){
- if(data=="fail"){
- alert("错误");
- }else{
- //alert(data[0].contents);
- var json = eval("{" + data + "}");
- //alert(json[0].contents);
- for(var i=0;i<json.length;i++){
- //alert(json[i].contents);
- combo_unite.addOption(i,json[i].contents);
- }
- }
- }
- });
- }
- function dosearch(){
- loadCount_no();
- }
<script>
var mygrid;
var combo_unite;
var myCalendar;
var combo_intype;
var intype='';
var insheetno='';
var date1='';
var date2='';
var unitname='';
var sheetmname='';
var checkmname='';
$(document).ready(function(){
adjustDisp();
mygrid = new dhtmlXGridObject('grid_storein');
mygrid.enableAutoWidth(true);
mygrid.setImagePath("dhtmlxGrid/codebase/imgs/");
mygrid.setSkin("dhx_custom");
mygrid.setHeader("入库单号,往来单位,入库类型,制单人,制单日期,金额,审核人,审核时间,记账人,记账日期,备注");
mygrid.setInitWidths("*,*,*,*,*,*,*,*,*,*,*");
mygrid.setColTypes("ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro");
mygrid.setColAlign("left,left,left,left,left,left,left,left,left,left,left");
mygrid.init();
combo_intype = new dhtmlXCombo("combo_zone1", "alfa1", 105);
combo_intype.enableFilteringMode(true);
//combo_intype.attachEvent("comboFilter",comboFilter(13, json, 'combo_intype', 'py', true, true));
combo_unite = new dhtmlXCombo("combo_zone2", "alfa2", 155);
combo_unite.enableFilteringMode(true);
//combo_unite.attachEvent("comboFilter",comboFilter(13, json, 'combo_intype', 'py', true, true));
// y.addOption([[1, 'aaaa', "color:red"], [2, 'bbbb'], [3, 'cccc'], [4, 'dddd'], [5, 'eeee']]);
combo1();
combo2();
//alert('1');
myCalendar = new dhtmlXCalendarObject(["date1", "date2"]);
loadCount_no();
}); function loadCount_no(){
intype=combo_intype.getComboText();// 取得页面上条件,入库类型 作为查询条件传到后台
insheetno=$('#insheetno').val();// 取得页面上条件,入库单号 作为查询条件传到后台
date1=$('#date1').val();// 取得页面上条件,入库日期1 作为查询条件传到后台
date2=$('#date2').val();// 取得页面上条件,入库日期2 作为查询条件传到后台
unitname=combo_unite.getComboText();//
// alert($('#sheetmname').val());
sheetmname=$('#sheetmname').val();// 取得页面上条件,制单人
checkmname=$('#checkmname').val();// 取得页面上条件,审核人
if(intype==''||intype==null){
intype='';
}
if(insheetno==''||insheetno==null){
insheetno='';
}
if(date1==''||insheetno==null){
date1='';
}
if(date2==''||insheetno==null){
date2='';
}
if(unitname==''||unitname==null){
unitname='';
}
if(sheetmname==''||sheetmname==null){
sheetmname='';
}
if(checkmname==''||checkmname==null){
checkmname='';
}
//intype = encodeURI(encodeURI(intype));
//insheetno = encodeURI(encodeURI(insheetno));
//unitname = encodeURI(encodeURI(unitname));
//date1 = encodeURI(encodeURI(date1));
//date2 = encodeURI(encodeURI(date2));
//sheetmname = encodeURI(encodeURI(sheetmname));
//checkmname = encodeURI(encodeURI(checkmname)); intype=encodeURIComponent(intype);
insheetno=encodeURIComponent(insheetno);
unitname=encodeURIComponent(unitname);
date1=encodeURIComponent(date1);
date2=encodeURIComponent(date2);
sheetmname=encodeURIComponent(sheetmname);
checkmname=encodeURIComponent(checkmname);
$.ajax({
async:false,
cache:false,
type:"GET",
url:"sick3/getCounttnb.htm?intype="+intype+"&insheetno="+insheetno+"&unitname="+unitname+"&date1="+date1+"&date2="+date2+"&sheetmname="+sheetmname+"&checkmname="+checkmname,
error:function(){
alert("服务器内部错误!");
},
success:function(data){
if(data=='fail'){
alert("获取数据失败!");
}else{
//alert(data);
createPagination_no(data);
}
}
});
} var pageSize = 10;
var pageIndex = 0;
function createPagination_no(pageCount){//创建分页标签,pageCount为返回的记录数
if(pageCount==0){
pageCount=0;
}
//分页,pageCount是总条目数,这是必选参数,其它参数都是可选
$("#pagination").pagination(pageCount, {
callback: pageCallback_no,
prev_text: '上一页', //上一页按钮里text
next_text: '下一页', //下一页按钮里text
items_per_page: pageSize, //显示条数
num_display_entries: 6, //连续分页主体部分分页条目数
current_page: pageIndex, //当前页索引
num_edge_entries: 2 //两侧首尾分页条目数
});
}
function pageCallback_no(index, jq){//翻页回调
pageIndex = index; //当前页索引
loadgrid_no(index);
return false;
} //条件查询获取当前页未处理报表
function loadgrid_no(index){
intype=combo_intype.getComboText();
insheetno=$('#insheetno').val();
date1=$('#date1').val();
date2=$('#date2').val();
unitname=combo_unite.getComboText();
sheetmname=$('#sheetmname').val();
checkmname=$('#checkmname').val();
if(intype==''||intype==null){
intype='';
}
if(insheetno==''||insheetno==null){
insheetno='';
}
if(date1==''||insheetno==null){
date1='';
}
if(date2==''||insheetno==null){
date2='';
}
if(unitname==''||unitname==null){
unitname='';
}
if(sheetmname==''||sheetmname==null){
sheetmname='';
}
if(checkmname==''||checkmname==null){
checkmname='';
}
//intype = encodeURI(encodeURI(intype));
//insheetno = encodeURI(encodeURI(insheetno));
//unitname = encodeURI(encodeURI(unitname));
//date1 = encodeURI(encodeURI(date1));
//date2 = encodeURI(encodeURI(date2));
//sheetmname = encodeURI(encodeURI(sheetmname));
//checkmname = encodeURI(encodeURI(checkmname)); intype=encodeURIComponent(intype);
insheetno=encodeURIComponent(insheetno);
unitname=encodeURIComponent(unitname);
date1=encodeURIComponent(date1);
date2=encodeURIComponent(date2);
sheetmname=encodeURIComponent(sheetmname);
checkmname=encodeURIComponent(checkmname); if(index!=0){
index = pageIndex;
} //mygrid.clearAndLoad("sick3/loadtnb.htm");
//alert('3');
//alert(intype);
mygrid.clearAndLoad("sick3/loadtnb.htm?index="+index+"&size="+pageSize+"&intype="+intype+"&insheetno="+insheetno+"&unitname="+unitname+"&date1="+date1+"&date2="+date2+"&sheetmname="+sheetmname+"&checkmname="+checkmname);
}
function adjustDisp(){//高度自适应,取相应的数据
var avalibleHeight = $(window).height()-250;
if(avalibleHeight>260){
pageSize = Math.floor((avalibleHeight-27)/26);
$("#grid_newApply").css("height",avalibleHeight);
}
} function combo1(){
$.ajax({
type:"post",
url: "sick3/hellohello.htm",
cache: false,
error:function(){
// alert("没有该病人记录!");
},
success: function(data){
if(data=="fail"){
alert("错误");
}else{
//alert(data[0].contents);
var json = eval("{" + data + "}");
//alert(json[0].contents);
for(var i=0;i<json.length;i++){
// alert(json[i].contents);
combo_intype.addOption(i,json[i].contents);
}
}
}
});
}
function combo2(){
$.ajax({
type:"post",
url: "sick3/combo2.htm",
cache: false,
error:function(){
//alert("没有该病人记录!");
},
success: function(data){
if(data=="fail"){
alert("错误");
}else{
//alert(data[0].contents);
var json = eval("{" + data + "}");
//alert(json[0].contents);
for(var i=0;i<json.length;i++){
//alert(json[i].contents);
combo_unite.addOption(i,json[i].contents);
}
}
}
});
}
function dosearch(){
loadCount_no();
}
文本框,combo的html略,放table里设计界面更整洁,
- <div id="grid_storein" style="height: 389px; width: 900px;"></div>
- <div id="pagination" style="position: relative; margin-left: 580px"></div>
<div id="grid_storein" style="height: 389px; width: 900px;"></div>
<div id="pagination" style="position: relative; margin-left: 580px"></div>
后台action代码(传中文get请求需要转码)
- @RequestMapping(value = "getCounttnb", method = RequestMethod.GET)
- public void getCount(HttpServletRequest request,HttpServletResponse response,String status) throws IOException {
- response.setContentType("text/html;charset=utf-8");
- request.setCharacterEncoding("utf-8");
- List<Map> list = null;
- DBOperator db = null;
- PrintWriter pw = response.getWriter();
- int count = 0;
- String intype = request.getParameter("intype");
- // System.out.println(intype);
- String insheetno = request.getParameter("insheetno");
- String date1 = request.getParameter("date1");
- String date2 = request.getParameter("date2");
- String unitname = request.getParameter("unitname");
- String sheetmname = request.getParameter("sheetmname");
- String checkmname = request.getParameter("checkmname");
- try {
- db = new DBOperator();
- String sql="select count(*) as count from (" +
- "select s.insheetno,s.unitname,s.intype,s.sheetmname," +
- "to_char(s.sheetdate, 'yyyy-MM-dd'),d.inqty * d.pprice as price," +
- "s.checkmname,to_char(s.checkdate, 'yyyy-MM-dd'),s.regmname,to_char(s.regdate, 'yyyy-MM-dd'),s.comments " +
- "from mw_insheets s, mw_insheets_details d where s.insheetno = d.insheetid ";
- if(insheetno!=null &&!"".equals(insheetno)){
- // insheetno=URLEncoder.encode(insheetno, "utf-8");
- insheetno=new String(insheetno.getBytes("iso-8859-1"), "utf-8");
- sql+=" and s.insheetno='"+insheetno+"'";
- }
- if(intype!=null &&!"".equals(intype)){
- // intype=URLEncoder.encode(intype, "utf-8");
- intype=new String(intype.getBytes("iso-8859-1"), "utf-8");
- sql+=" and s.intype='"+intype+"'";
- System.out.println(intype);
- }
- if(date1!=null &&!"".equals(date1)){
- sql += " and to_char(s.sheetdate,'yyyy-mm-dd')>='"+date1+"'";
- }
- if(date2!=null &&!"".equals(date2)){
- sql += " and to_char(s.sheetdate,'yyyy-mm-dd')<='"+date2+"'";
- }
- if(unitname!=null &&!"".equals(unitname)){
- // unitname=URLEncoder.encode(unitname, "utf-8");
- unitname=new String(unitname.getBytes("iso-8859-1"), "utf-8");
- sql+=" and s.unitname='"+unitname+"'";
- }
- if(sheetmname!=null &&!"".equals(sheetmname)){
- // sheetmname=URLEncoder.encode(sheetmname, "utf-8");
- sheetmname=new String(sheetmname.getBytes("iso-8859-1"), "utf-8");
- sql+=" and s.sheetmname='"+sheetmname+"'";
- }
- if(checkmname!=null &&!"".equals(checkmname)){
- // checkmname=URLEncoder.encode(checkmname, "utf-8");
- checkmname=new String(checkmname.getBytes("iso-8859-1"), "utf-8");
- sql+=" and s.checkmname='"+checkmname+"'";
- }
- sql+=")";
- list = db.find(sql);
- db.commit();
- count=Integer.valueOf(String.valueOf(list.get(0).get("count")));
- pw.print(count);
- }catch(Exception e){
- e.printStackTrace();
- pw.print("fail");
- }finally{
- db.freeCon();
- }
- pw.flush();
- pw.close();
- }
- //返回疾病结果
- @RequestMapping(value = "loadtnb", method = RequestMethod.GET)
- public void loadGrid(HttpServletRequest request,HttpServletResponse response,String status) throws IOException {
- response.setContentType("text/html;charset=utf-8");
- request.setCharacterEncoding("utf-8");
- int Pagesize = Integer.parseInt(request.getParameter("size"));
- int index = Integer.parseInt(request.getParameter("index"));
- String intype = request.getParameter("intype");
- String insheetno = request.getParameter("insheetno");
- String date1 = request.getParameter("date1");
- String date2 = request.getParameter("date2");
- String unitname = request.getParameter("unitname");
- String sheetmname = request.getParameter("sheetmname");
- String checkmname = request.getParameter("checkmname");
- String pagingSql1 = "select OHYEAH.* from (select OHNO.*,rownum no from ("; // 用于分页// 段1
- String pagingSql2 = ") OHNO where rownum <= ?) OHYEAH where no > ?"; // 用于分页段2
- String sql = "select s.insheetno,s.unitname,s.intype,s.sheetmname,to_char(s.sheetdate,'yyyy-MM-dd') as sheetdate," +
- "d.inqty*d.pprice as price,s.checkmname,to_char(s.checkdate,'yyyy-MM-dd') as checkdate,s.regmname,to_char(s.regdate,'yyyy-MM-dd') as regdate,s.comments " +
- "from mw_insheets s,mw_insheets_details d where s.insheetno=d.insheetid ";
- if(insheetno!=null &&!"".equals(insheetno)){
- // insheetno=URLEncoder.encode(insheetno, "utf-8");
- insheetno=new String(insheetno.getBytes("iso-8859-1"), "utf-8");
- sql+=" and s.insheetno='"+insheetno+"'";
- }
- if(intype!=null &&!"".equals(intype)){
- // intype=URLEncoder.encode(intype, "utf-8");
- intype=new String(intype.getBytes("iso-8859-1"), "utf-8");
- sql+=" and s.intype='"+intype+"'";
- System.out.println(intype);
- }
- if(date1!=null &&!"".equals(date1)){
- sql += " and to_char(s.sheetdate,'yyyy-mm-dd')>='"+date1+"'";
- }
- if(date2!=null &&!"".equals(date2)){
- sql += " and to_char(s.sheetdate,'yyyy-mm-dd')<='"+date2+"'";
- }
- if(unitname!=null &&!"".equals(unitname)){
- // unitname=URLEncoder.encode(unitname, "utf-8");
- unitname=new String(unitname.getBytes("iso-8859-1"), "utf-8");
- sql+=" and s.unitname='"+unitname+"'";
- }
- if(sheetmname!=null &&!"".equals(sheetmname)){
- // sheetmname=URLEncoder.encode(sheetmname, "utf-8");
- sheetmname=new String(sheetmname.getBytes("iso-8859-1"), "utf-8");
- sql+=" and s.sheetmname='"+sheetmname+"'";
- }
- if(checkmname!=null &&!"".equals(checkmname)){
- // checkmname=URLEncoder.encode(checkmname, "utf-8");
- checkmname=new String(checkmname.getBytes("iso-8859-1"), "utf-8");
- sql+=" and s.checkmname='"+checkmname+"'";
- }
- DBOperator db = null;
- try {
- db = new DBOperator();
- List list = db.find(pagingSql1+sql+pagingSql2,new Object[]{Pagesize*index+Pagesize,Pagesize*index});
- response.setContentType("text/xml;charset=utf-8");
- PrintWriter pw = null;
- pw = response.getWriter();
- String vmpagckage = "com/cpinfo/learn/template/";
- String vmname = "hello.vm";
- String vm = VelocityUtils.generateGridVm(vmpagckage, vmname,"MW_hello", list);
- pw.print(vm);
- pw.flush();
- pw.close();
- }catch(Exception e){
- e.printStackTrace();
- }finally{
- db.freeCon();
- }
- }
@RequestMapping(value = "getCounttnb", method = RequestMethod.GET)
public void getCount(HttpServletRequest request,HttpServletResponse response,String status) throws IOException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
List<Map> list = null;
DBOperator db = null;
PrintWriter pw = response.getWriter();
int count = 0;
String intype = request.getParameter("intype");
// System.out.println(intype);
String insheetno = request.getParameter("insheetno");
String date1 = request.getParameter("date1");
String date2 = request.getParameter("date2");
String unitname = request.getParameter("unitname");
String sheetmname = request.getParameter("sheetmname");
String checkmname = request.getParameter("checkmname");
try {
db = new DBOperator();
String sql="select count(*) as count from (" +
"select s.insheetno,s.unitname,s.intype,s.sheetmname," +
"to_char(s.sheetdate, 'yyyy-MM-dd'),d.inqty * d.pprice as price," +
"s.checkmname,to_char(s.checkdate, 'yyyy-MM-dd'),s.regmname,to_char(s.regdate, 'yyyy-MM-dd'),s.comments " +
"from mw_insheets s, mw_insheets_details d where s.insheetno = d.insheetid ";
if(insheetno!=null &&!"".equals(insheetno)){
// insheetno=URLEncoder.encode(insheetno, "utf-8");
insheetno=new String(insheetno.getBytes("iso-8859-1"), "utf-8");
sql+=" and s.insheetno='"+insheetno+"'";
}
if(intype!=null &&!"".equals(intype)){
// intype=URLEncoder.encode(intype, "utf-8");
intype=new String(intype.getBytes("iso-8859-1"), "utf-8");
sql+=" and s.intype='"+intype+"'";
System.out.println(intype);
}
if(date1!=null &&!"".equals(date1)){
sql += " and to_char(s.sheetdate,'yyyy-mm-dd')>='"+date1+"'";
}
if(date2!=null &&!"".equals(date2)){
sql += " and to_char(s.sheetdate,'yyyy-mm-dd')<='"+date2+"'";
}
if(unitname!=null &&!"".equals(unitname)){
// unitname=URLEncoder.encode(unitname, "utf-8");
unitname=new String(unitname.getBytes("iso-8859-1"), "utf-8");
sql+=" and s.unitname='"+unitname+"'";
}
if(sheetmname!=null &&!"".equals(sheetmname)){
// sheetmname=URLEncoder.encode(sheetmname, "utf-8");
sheetmname=new String(sheetmname.getBytes("iso-8859-1"), "utf-8");
sql+=" and s.sheetmname='"+sheetmname+"'";
}
if(checkmname!=null &&!"".equals(checkmname)){
// checkmname=URLEncoder.encode(checkmname, "utf-8");
checkmname=new String(checkmname.getBytes("iso-8859-1"), "utf-8");
sql+=" and s.checkmname='"+checkmname+"'";
}
sql+=")";
list = db.find(sql);
db.commit();
count=Integer.valueOf(String.valueOf(list.get(0).get("count")));
pw.print(count);
}catch(Exception e){
e.printStackTrace();
pw.print("fail");
}finally{
db.freeCon();
}
pw.flush();
pw.close();
}
//返回疾病结果
@RequestMapping(value = "loadtnb", method = RequestMethod.GET)
public void loadGrid(HttpServletRequest request,HttpServletResponse response,String status) throws IOException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
int Pagesize = Integer.parseInt(request.getParameter("size"));
int index = Integer.parseInt(request.getParameter("index"));
String intype = request.getParameter("intype");
String insheetno = request.getParameter("insheetno");
String date1 = request.getParameter("date1");
String date2 = request.getParameter("date2");
String unitname = request.getParameter("unitname");
String sheetmname = request.getParameter("sheetmname");
String checkmname = request.getParameter("checkmname");
String pagingSql1 = "select OHYEAH.* from (select OHNO.*,rownum no from ("; // 用于分页// 段1
String pagingSql2 = ") OHNO where rownum <= ?) OHYEAH where no > ?"; // 用于分页段2
String sql = "select s.insheetno,s.unitname,s.intype,s.sheetmname,to_char(s.sheetdate,'yyyy-MM-dd') as sheetdate," +
"d.inqty*d.pprice as price,s.checkmname,to_char(s.checkdate,'yyyy-MM-dd') as checkdate,s.regmname,to_char(s.regdate,'yyyy-MM-dd') as regdate,s.comments " +
"from mw_insheets s,mw_insheets_details d where s.insheetno=d.insheetid ";
if(insheetno!=null &&!"".equals(insheetno)){
// insheetno=URLEncoder.encode(insheetno, "utf-8");
insheetno=new String(insheetno.getBytes("iso-8859-1"), "utf-8");
sql+=" and s.insheetno='"+insheetno+"'";
}
if(intype!=null &&!"".equals(intype)){
// intype=URLEncoder.encode(intype, "utf-8");
intype=new String(intype.getBytes("iso-8859-1"), "utf-8");
sql+=" and s.intype='"+intype+"'";
System.out.println(intype);
}
if(date1!=null &&!"".equals(date1)){
sql += " and to_char(s.sheetdate,'yyyy-mm-dd')>='"+date1+"'";
}
if(date2!=null &&!"".equals(date2)){
sql += " and to_char(s.sheetdate,'yyyy-mm-dd')<='"+date2+"'";
}
if(unitname!=null &&!"".equals(unitname)){
// unitname=URLEncoder.encode(unitname, "utf-8");
unitname=new String(unitname.getBytes("iso-8859-1"), "utf-8");
sql+=" and s.unitname='"+unitname+"'";
}
if(sheetmname!=null &&!"".equals(sheetmname)){
// sheetmname=URLEncoder.encode(sheetmname, "utf-8");
sheetmname=new String(sheetmname.getBytes("iso-8859-1"), "utf-8");
sql+=" and s.sheetmname='"+sheetmname+"'";
}
if(checkmname!=null &&!"".equals(checkmname)){
// checkmname=URLEncoder.encode(checkmname, "utf-8");
checkmname=new String(checkmname.getBytes("iso-8859-1"), "utf-8");
sql+=" and s.checkmname='"+checkmname+"'";
}
DBOperator db = null;
try {
db = new DBOperator();
List list = db.find(pagingSql1+sql+pagingSql2,new Object[]{Pagesize*index+Pagesize,Pagesize*index});
response.setContentType("text/xml;charset=utf-8");
PrintWriter pw = null;
pw = response.getWriter();
String vmpagckage = "com/cpinfo/learn/template/";
String vmname = "hello.vm";
String vm = VelocityUtils.generateGridVm(vmpagckage, vmname,"MW_hello", list);
pw.print(vm);
pw.flush();
pw.close();
}catch(Exception e){
e.printStackTrace();
}finally{
db.freeCon();
}
}
dhtmlxGrid分页查询,条件查询实例的更多相关文章
- EF:分页查询 + 条件查询 + 排序
/// <summary> /// linq扩展类---zxh /// </summary> /// <typeparam name="T">& ...
- jqGrid jqGrid分页参数+条件查询
HTML <div class="row"> <div class="col-sm-20"> <form id="for ...
- MongoTemplate 分组分页复合条件查询
一.前言 最近项目使用MongoDB作为数据主要存取的地方 又是第一次接触MongoDB,也是踩了不少坑... 维护数据无非就是增删改查,而里面最复杂的就是查询了 所以来总结一下有关MongoDB的查 ...
- 18 12 06 sql 的 基本语句 查询 条件查询 逻辑运算符 模糊查询 范围查询 排序 聚合函数 分组 分页 连接查询 自关联 子查询
-- 数据的准备 -- 创建一个数据库 create database python_test charset=utf8; -- 使用一个数据库 use python_test; -- 显示使用的当前 ...
- 【JPA】Spring Data JPA 实现分页和条件查询
文章目录 1.在`Repository`层继承两个接口 2.在Service层进行查询操作 3.Page的方法 1.在Repository层继承两个接口 JpaRepository<Admin, ...
- 分页离线条件查询 页面响应500 后端未报异常 list集合有数据
如果 使用同一个Hibernate的DetachedCriteria离线条件查询对象同时查询“过滤后条数” 和 “过滤后的数据集合”,那么查询记录数时需要设置聚合函数条件并且 使用聚合函数 代码要在 ...
- Activiti5 待审 待批任务 TaskQuery查询 条件查询 like查询
TaskQuery查询API 有两种方法可以从引擎中查询数据:查询API和原生查询.查询API提供了完全类型安全的API. 你可以为自己的查询条件添加很多条件 (所以条件都以AND组合)和精确的排序条 ...
- Hibernate 笔记 HQL查询 条件查询,聚集函数,子查询,导航查询
在hibernate中进行多表查询,每个表中各取几个字段,也就是说查询出来的结果集并没有一个实体类与之对应,如何解决这个问题? 解决方案一,按照Object[]数据取出数据,然后自己组bean 解决方 ...
- MySQL单表查询 条件查询,分组
目录 1 where 条件查询 between like not in 2 group by 分组 聚合函数:max min sum avg count 3 having 过滤 4 distinct ...
- 13-MySQL-Ubuntu-数据表的查询-条件查询(二)
条件查询 1,比较查询(>,<,>=,<=,=)注:SQL查询语句的等于号(=) (1)查询学生表中年龄大于18岁的学生姓名和性别信息 select name,gender f ...
随机推荐
- MySQL explain key_len 大小的计算
总结: 变长字段需要额外的2个字节,固定长度字段不需要额外的字节.而null都需要1个字节的额外空间,所以以前有个说法:索引字段最好不要为NULL,因为NULL让统计更加复杂,并且需要额外一个字节的存 ...
- IRedisClient 常用方法说明
事实上,IRedisClient里面的很多方法,其实就是Redis的命令名.只要对Redis的命令熟悉一点就能够非常快速地理解和掌握这些方法,趁着现在对Redis不是特别了解,我也对着命令来了解一下这 ...
- 剑指offer系列36----二叉搜索树的第k个节点
[题目]给定一颗二叉搜索树,请找出其中的第k大的结点. * 例如, 5 * / \ * 3 7 * / \ / \ * 2 4 6 8 中,按结点数值大小顺序第三个结点的值为4. 中序遍历:2 3 4 ...
- Maven 和 Ant 的区别?
Maven 和 Ant 有什么不同呢?在回答这个问题以前,首先要强调一点:Maven 和 Ant 针对构建问题的两个不同方面.Ant 为 Java 技术开发项目提供跨平台构建任务.Maven 本身描述 ...
- 【转】分析Redis架构设计
一.前言 因为近期项目中开始使用Redis,为了更好的理解Redis并应用在适合的业务场景,需要对Redis设计与实现深入的理解. 我分析流程是按照从main进入,逐步深入分析Redis的启动流程.同 ...
- 常用JS
window.opener.location.reload(); 刷新上一个页面 window.opener=null;window.open('','_self');window.close(); ...
- 求助:为什么我用360浏览器和UC浏览器打不开JAVA中的index.html文件? 一打开就显示浏览器首界页
如下图,在oracle官网下载了一个JAVA的API文档,双击index.html时打开是浏览器的首页,不知道为什么?请问怎样才能以chm文档格式显示?
- Java I/O学习(附实例和详解)
原文地址:http://blog.csdn.net/u013142781/article/details/50814649 一.Java I/O类结构以及流的基本概念 在阅读Java I/O的实例之前 ...
- OC知识点
1.@autoreleasepool why1 2.retain O-C内存管理和点语法1>OC内存管理正常情况要使用大量的retain和relrese操作2>点语法可以减少使用retai ...
- VALGRIND
系统编程中一个重要的方面就是有效地处理与内存相关的问题.你的工作越接近系统,你就需要面对越多的内存问题.有时这些问题非常琐碎,而更多时候它会演变成一个调试内存问题的恶梦.所以,在实践中会用到很多工具来 ...