<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@page import="java.sql.*"%>
<!-- author:Evangelion 除select外都已经完成了功能
1 定义了sql_info、sql_info1 后者是为了统计符合模糊查询条件的全部数据计算出行数和页数从而可以显示出所有页数。
前者是为了查询出模糊查询出的结果并且按每页10行来显示。(我这个写的有些麻烦其实可以定义一个sql语句,查询出来所有页数,然后加个where条件让其显示也10条)
2 js中写了选中行的操作用的是jquery封装的select的点击方法每次点击加一个样式selected
3 delWindow是将选中的行删除,在js中用tr.selected>td.eq(1).text()选出单元格数据,执行window.location = 'index.jsp?px=' + s_boss_code;将单元格数据传到index.jsp中的px中,然后index.jsp执行sql语句将其删除。
4 addWindow是先定义了button click=js中的函数,js中的函数使用window.open("add.jsp")然后window.jsp中定义form action=“index.jsp”将参数传递到index.jsp中。实现添加功能。
5 editWindow是先定了button js函数 js中使用的是window.location = "edit.jsp?s_plan_name=" + s_plan_name
+ "&s_boss_code=" + s_boss_code + "&s_start_time="
+ s_start_time + "&s_end_time=" + s_end_time;将选中行的字段参数传递过去,这样,打开edit.jsp显示的就是这些字段,然后进行修改的时候使用的是form action 在index中使用update set语句实现修改功能
-->
<%
String strPlanName = request.getParameter("plan_name");
%>
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css"
href="http://www.jeasyui.com/easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css"
href="http://www.jeasyui.com/easyui/themes/icon.css" />
<link rel="stylesheet" type="text/css"
href="http://www.jeasyui.com/easyui/demo/demo.css" />
<link rel="stylesheet" type="text/css" href="CSS/editTable.css">
<!-- <script type="text/javascript" >
$(document).ready(function() {
$("#pager").pager({ pagenumber: 1, pagecount: 15, buttonClickCallback: PageClick });
});
PageClick = function(pageclickednumber) {
$("#pager").pager({ pagenumber: pageclickednumber, pagecount: 15, buttonClickCallback: PageClick });
$("#result").html("Clicked Page " + pageclickednumber);
}
</script>-->
</head>
<body>
<div>
<form action=index.jsp method="get">
套餐名称:
<input type="text" name="plan_name" />
BOSS编码:
<input type="text" name="boss_code" />
套餐类型:
<select name="plan_type"></select>
品牌:
<select name="brand_id"></select>
开始时间:
<input name="plan_startdate" class="Wdate" type="text"
οnfοcus="WdatePicker()" />
结束时间:
<input name="plan_enddate" class="Wdate" type="text"
οnfοcus="WdatePicker()" />
<input name="info" type="submit" value="查询" />
<input name="edit" type="button" value="修改" οnclick=
editWindow();;;
/>
<input name="del" type="button" value="删除" οnclick=
delWindow();;;
/>
<input name="add" type="button" value="添加" οnclick=
addWindow();
>
</form>
</div>
<table border="1">
<thead>
<tr>
<th width="200">
套餐名称
</th>
<th width="200">
BOSS编码
</th>
<th width="200">
套餐类型
</th>
<th width="200">
品牌
</th>
<th width="200">
开始时间
</th>
<th width="200">
结束时间
</th>
</tr>
</thead>
<%
//System.out.println(request.getParameter("plan_name_edit"));
//System.out.println(request.getParameter("plan_name_edit"));
//System.out.println(request.getParameter("boss_code_edit"));
String s_boss_code = request.getParameter("px");
//System.out.println(s_boss_code);
//System.out.println(request.getParameter("end_date_add"));
//System.out.println(request.getParameter("plan_name"));
//System.out.println(s_boss_code);
int pageSize = 10;
int pageNow = 1;
int rowCount = 0;
int pageCount = 0;
String s_pageNow = request.getParameter("pageNow");
if (s_pageNow != null) {
pageNow = Integer.parseInt(s_pageNow);
}
Connection conn = null;
Statement stmt = null, stmt1 = null, stmt2 = null, stmt3 = null, stmt5 = null, stmt6 = null;
PreparedStatement stmt4 = null;
//ResultSet rs = null;
ResultSet rsCount = null;
ResultSet rsRownum = null;
ResultSet rsInfo = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@10.19.115.131:1521:orcl", "raop",
"raop12345");
//stmt = conn.createStatement();\
String sql_info1="select * from pmp_plan where 1=1";
String sql_info = "select plan_name,boss_code,plan_type,brand_id,plan_startdate,plan_enddate from(select rownum rown,plan_name,boss_code,plan_type,brand_id,plan_startdate,plan_enddate from pmp_plan t where rownum<=";
sql_info += +pageNow * pageSize + ")where ( rown>"
+ (pageNow - 1) * pageSize+")";
if (request.getParameter("plan_name")!=null) {
sql_info += "and (plan_name like '%"
+ request.getParameter("plan_name") + "%')";
sql_info1 += "and (plan_name like '%"
+ request.getParameter("plan_name") + "%')";
}
if (request.getParameter("boss_code") !=null) {
sql_info += "and (boss_code like '%"
+ request.getParameter("boss_code") + "%')";
sql_info1 += "and (boss_code like '%"
+ request.getParameter("boss_code") + "%')";
}
if (request.getParameter("plan_startdate") !=null) {
sql_info += "and ( plan_startdate like '%"
+ request.getParameter("plan_startdate") + "%')";
sql_info1 += "and ( plan_startdate like '%"
+ request.getParameter("plan_startdate") + "%')";
}
if (request.getParameter("plan_enddate") != null) {
sql_info += "and( plan_enddate like '%"
+ request.getParameter("plan_enddate") + "%')";
sql_info1 += "and( plan_enddate like '%"
+ request.getParameter("plan_enddate") + "%')"; }
//System.out.println(request.getParameter("plan_name"));
//System.out.println(request.getParameter("boss_code"));
System.out.println(sql_info);
stmt1 = conn.createStatement();
stmt2 = conn.createStatement();
stmt3 = conn.createStatement();
stmt5 = conn.createStatement();
stmt6= conn.createStatement();
stmt4 = conn
.prepareStatement("insert into pmp_plan (plan_name,boss_code,plan_startdate,plan_enddate) values (?,?,?,?)");
if (request.getParameter("plan_name_edit") != null) {
stmt5.executeUpdate("update pmp_plan set plan_name='"
+ request.getParameter("plan_name_edit")
+ "',plan_startdate='"
+ request.getParameter("start_date_edit")
+ "',plan_enddate='"
+ request.getParameter("end_date_edit")
+ "'where boss_code='"
+ request.getParameter("boss_code_edit") + "'");
}
if (request.getParameter("plan_name_add") != null) {
stmt4.setString(1, request.getParameter("plan_name_add"));
stmt4.setString(2, request.getParameter("boss_code_add"));
stmt4.setString(3, request.getParameter("start_date_add"));
stmt4.setString(4, request.getParameter("end_date_add"));
stmt4.executeUpdate();
}
if (request.getParameter("px") != null) {
stmt3
.executeUpdate("delete from pmp_plan t where boss_code='"
+ s_boss_code + "'");
}
//rs = stmt.executeQuery("select plan_name,boss_code,plan_type,brand_id,plan_startdate,plan_enddate from pmp_plan t ");
rsCount = stmt1
.executeQuery("select count(*) from ("+sql_info1 +")");
rsRownum = stmt2
.executeQuery("select plan_name,boss_code,plan_type,brand_id,plan_startdate,plan_enddate from(select rownum rown,plan_name,boss_code,plan_type,brand_id,plan_startdate,plan_enddate from pmp_plan t where rownum<="
+ pageNow
* pageSize
+ ")where rown>"
+ (pageNow - 1) * pageSize);
rsInfo=stmt6.executeQuery(sql_info);
// System.out.println(sql_info);
// rsInfo= stmt.executeQuery(sql_info);
// System.out.println(rsInfo);
out.println("<tbody>");
if (rsCount.next()) {
rowCount = rsCount.getInt(1);
}
//System.out.println(rsRownum.next());
//System.out.println(rowCount);
//System.out.println(rsRownum.next());
while (rsInfo.next()) {
out.println("<tr>");
out.println("<td >" + rsInfo.getString("plan_name")
+ "</td>");
out.println("<td >" + rsInfo.getString("boss_code")
+ "</td>");
out.println("<td >" + rsInfo.getString("plan_type")
+ "</td>");
out.println("<td >" + rsInfo.getString("brand_id")
+ "</td>");
out.println("<td >" + rsInfo.getString("plan_startdate")
+ "</td>");
out.println("<td >" + rsInfo.getString("plan_enddate")
+ "</td>");
out.println("</tr>");
}
} catch (Exception ex) {
out.println(ex.toString());
} finally {
//rs.close();
//rsCount.close();
//rsRownum.close();这一行不被注释的话有错误报出
//stmt.close();
//rsRownum.close();
stmt1.close();
stmt2.close();
stmt3.close();
stmt4.close();
stmt5.close();
stmt6.close();
conn.close();
}
out.println("</tbody>");
//上一页
%>
</table>
<%
if (rowCount % pageSize == 0) {
pageCount = rowCount / pageSize;
} else {
pageCount = rowCount / pageSize + 1;
}
if (pageNow != 1) {
out.println("<a href=index.jsp?pageNow=" + (pageNow - 1)
+ ">上一页</a>");
}
for (int i = 1; i <= pageCount; i++) {
out.println("<a href=index.jsp?pageNow=" + i + ">[" + i
+ "]</a>");
}
if (pageNow != pageCount) {
out.println("<a href=index.jsp?pageNow=" + (pageNow + 1)
+ ">下一页</a>");
}
%>
<!-- </table>
<div id="toolbar">
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" οnclick="newUser()">增加</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" οnclick="editUser()">编辑</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" οnclick="destroyUser()">删除</a> </div>
</div>
-->
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.6.min.js"></script>
<script type="text/javascript"
src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="scripts/Jq/jquery-1.6.4.js"></script>
<script type="text/javascript" src="scripts/js/WdatePicker.js"></script>
<script type="text/javascript">
$(function() {
$("tbody>tr").click(function() {
$(this).addClass("selected").siblings().removeClass("selected");
});
})
</script>
<script type="text/javascript">
function addWindow() {
window
.open(
"add.jsp",
"Sample",
"fullscreen=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no, copyhistory=no,width=350,height=140,left=200,top=300");
}
function editWindow() {
// alert($("tr.selected>td").eq(5).text());
if (!$("tr.selected").text()) {
alert("没有行被选中");
return;
}
s_plan_name = $("tr.selected>td").eq(0).text();
s_boss_code = $("tr.selected>td").eq(1).text();
s_start_time = $("tr.selected>td").eq(4).text();
s_end_time = $("tr.selected>td").eq(5).text();
//window.open ("edit.jsp");
window.location = "edit.jsp?s_plan_name=" + s_plan_name
+ "&s_boss_code=" + s_boss_code + "&s_start_time="
+ s_start_time + "&s_end_time=" + s_end_time;
}
function delWindow() {
//alert($("tr.selected>td").eq(1).text());
if (!$("tr.selected").text()) {
alert("没有行被选中");
return;
}
if (!confirm("是否将此信息删除?"))
return;
var s_boss_code = $("tr.selected>td").eq(1).text();
$("tr.selected").remove();
alert("删除成功!")
// alert(s_boss_code); //正确显示
window.location = 'index.jsp?px=' + s_boss_code;
}
</script>
</body>
</html>