暑假实训 Estore 系统记录

环境

数据库: Oracle XE

数据库连接软件: Navicat

Java: JDK1.8.0_171

IDE: Eclipse Photon June 2018

Servers: Tomcat 8.0.53

数据建模

Book {id, name, price, type}

Customer [name, passwd, zip, address, telephone, email]

OrederFrom [id, cost, orderDate, customer, shipadress]

OrderLine [id, num, orderForm, book]

ShipAddress [id, shipuName, adres, phone, customer]

数据库连接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package xyz.ffshine.common;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBUtil {
/**
* 连接数据库
* AND
*对 一些数据库基本的执行封装
*
*/
private static String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
private static String username = "8607";
private static String passwd = "8607";
public static Connection connection = null;

// 创建connection
public static Connection connect() {
String driver = "oracle.jdbc.OracleDriver";
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
connection = DriverManager.getConnection(url, username, passwd);
} catch (SQLException e) {
System.out.println("连接失败");
e.printStackTrace();
}
return connection;
}

// statement
public static Statement statement() {
Connection connection = connect();
// 创建statement对象
Statement statement = null;
try {
statement = connection.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
return statement;
}

// 查询数据库
public static ResultSet selectDB(Statement statement, String command) {
ResultSet resultSet = null;
try {
resultSet = statement.executeQuery(command);
} catch (SQLException e) {
System.out.println("数据库查询失败");
e.printStackTrace();
}
return resultSet;
}

// 数据库执行语句
public static void exeCommand(Statement statement, String command) {
try {
statement.execute(command);
} catch (SQLException e) {
System.out.println("语句执行失败");
e.printStackTrace();
}
}
}

注册

service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package xyz.ffshine.service.impl;

import xyz.ffshine.bean.Customer;
import xyz.ffshine.dao.CheckDB;
import xyz.ffshine.dao.CustomerDao;
import xyz.ffshine.service.CustomerService;

public class CustomerServiceImpl implements CustomerService {

/**
* 判断数据
* 储存数据
*/

private CustomerDao dao = new CustomerDao();


public boolean trySave(Customer customer) {
/**
* 试图储存
* 储存之前检查 NAME
* NAME没有问题 调用保存方法
*/

if(!new CheckDB().check("*", "CUSTOMER", "NAME", customer.getName())) {
dao.saveCustomer(customer);
return true;
}
return false;
}

public boolean tryLogin(String name, String passwd) {
/**
* 检查是否能登陆
*/
if(new CheckDB().loginCheck(name, passwd)) {
return true;
}
return false;
}

public Customer getCustomer(String name, String passwd) {
return dao.getCustomer(name, passwd);
}

@Override
public Customer getCustomerById(Long id) {
return dao.getCustomerById(id);
}

}

servlet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("utf-8");

String name = request.getParameter("name");
String password = request.getParameter("password");
String zip = request.getParameter("zip");
String address = request.getParameter("address");
String telephone = request.getParameter("telephone");
String email = request.getParameter("email");

CustomerServiceImpl customerService = new CustomerServiceImpl();
Customer customer = new Customer(name, password, zip, address, telephone, email);
if(customerService.trySave(customer)) {
response.sendRedirect("./index.jsp");
} else {
response.sendRedirect("./register.jsp?token=false");
}
}

登陆

servlet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("utf-8");

String name = request.getParameter("name");
String passwd = request.getParameter("password");
Customer customer = null;
//创建一个空购物车 存入 customerId
OrderFormService oService = new OrderFormServiceImpl();
CustomerServiceImpl service = new CustomerServiceImpl();

Long time = System.currentTimeMillis();
Date date = new Date(time);
//登陆
if(service.tryLogin(name, passwd)) {
//把用户信息存入 session

customer = service.getCustomer(name, passwd);
oService.createOrderForm(customer.getId(), date);
OrderForm orderForm = oService.getOrderFormByCusId(customer.getId());
HttpSession session = request.getSession();
session.setAttribute("customer", customer);
session.setAttribute("orderForm", orderForm);
response.sendRedirect("./index.jsp");
}else {
response.sendRedirect("./login.jsp?token=false");
}
}

把数据库中的Book 传入首页

listener

1
2
3
4
5
public void sessionCreated(HttpSessionEvent hse) {
HttpSession session = hse.getSession();
List<Book> books = new BookServiceImpl().findAllBook();
session.setAttribute("books", books);
}

bookService

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package xyz.ffshine.service.impl;

import java.util.List;

import xyz.ffshine.bean.Book;
import xyz.ffshine.dao.BookDao;
import xyz.ffshine.service.BookService;

public class BookServiceImpl implements BookService{
@Override
public List<Book> findAllBook() {
return new BookDao().findAllBook();
}

@Override
public Book getBookById(Long id) {
return new BookDao().getBookById(id);
}
}

在页面展示穿入的Book

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<c:forEach items="${sessionScope.books}" var="book">
<li>
<div class="c3_b2_txt">
<a href="viewBook.jsp?name=${book.name}&price=${book.price}&cus_id=${customer.id}&book_id=${book.id}"> <img alt=""
src="images/book_index/book${book.id}.jpg"></a>
<h1>${book.name}</h1>
<h2>分类:${book.type}</h2>
<h2>价格:¥${book.price}</h2>
<h2>畅销书籍</h2>
<h2>覆盖java基础及全新内容</h2>
<p>
<a href="#">更多精彩,点击进入</a>
</p>
</div>
</li>
</c:forEach>

其中

1
<a href="viewBook.jsp?name=${book.name}&price=${book.price}&cus_id=${customer.id}&book_id=${book.id}">

把本书的信息传入ViewBook页面

ViewBook

数据获取

1
2
3
4
5
6
<%
String name = request.getParameter("name");
String price = request.getParameter("price");
String cus_id = request.getParameter("cus_id");
String book_id = request.getParameter("book_id");
%>

数据展示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 	<div id="demo" class="cn5topy_1">
<div id="small-box" class="cn5topy_imgview">
<div id="mark"></div>
<div id="float-box"></div>
<img src="images/book_view/book<%=book_id %>.jpg"/>
<ul class="cn5topy_imglist">
<li><a href="#"><img src="images/viewBook.jpg"></a></li>
<li class="current"><a href="#"><img src="images/book4_1.jpg"></a></li>
<li><a href="#"><img src="images/book4_2.jpg"></a></li>
<li><a href="#"><img src="images/book4_3.jpg"></a></li>
<li><a href="#"><img src="images/book4_4.jpg"></a></li>
</ul>
</div>
<div id="big-box">
<img src="images/book_view/book<%=book_id%>2.jpg"/>
</div>
</div>
<div class="cn5topy_2">
<h1 id="bookName" class="pro_title font15"><%=name %></h1>
<h1 id="cus_id" style="display: none;"><%=cus_id %></h1>
<h1 id="book_id" style="display: none;"><%=book_id %></h1>
<h1 id="orederForm" style="display: none;">${orderForm.id }</h1>
<div class="pro_price">
<div class="pro_price_x">
<p> 单价:¥<b><%=price %></b> <a href="#">(降价通知)</a></p>
</div>

</div>

其中属性为”display: none” 的标签是为了更好地用js构建向下一页的跳转链接

跳转链接构建

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function addShopCart(){
var bookname = document.getElementById("bookName").innerText
var num = document.getElementById("num").value;
var cus_id = document.getElementById("cus_id").innerText;
var book_id = document.getElementById("book_id").innerText;
var orederForm_id = document.getElementById("orederForm").innerText;
if(cus_id ==""){
alert("请先登录");
window.location.href="./login.jsp";
return;
}
alert("加入购物车成功!");
window.location.href="./AddShopCar?name=" + bookname + "&num=" + num +"&cus_id=" + cus_id + "&book_id=" + book_id + "&orederForm_id=" + orederForm_id;
}

购物车

加入购物车

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("utf-8");

Long num = Long.parseLong(request.getParameter("num"));
Long bookId = Long.parseLong(request.getParameter("book_id"));
Long orederFormId = Long.parseLong(request.getParameter("orederForm_id"));

//根据book_id 获取 book对象
Book book = new BookServiceImpl().getBookById(bookId);
OrderForm orderForm = new OrderFormServiceImpl().getOrderFormById(orederFormId);;
OrderLine orderLine = new OrderLine();
orderLine.setNum(num);
orderLine.setBook(book);
orderLine.setOrderForm(orderForm);
OrderLineService oLService = new OrderLineServiceImpl();
oLService.trySave(orderLine); //把书的信息存入数据库
List<OrderLine> orLines = oLService.getAllOfOrderLineByOFId(orederFormId); //从数据库中取出所有属于订单的订单项 包装成 列表

HttpSession session = request.getSession();
session.setAttribute("orLines", orLines);
response.sendRedirect("./shopCar.jsp");
}

购物车展示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<c:forEach items="${sessionScope.orLines}" var="orLine">
<div class="bb">
<input class="checkbox" onclick="checkEvent(this)" type="checkbox">
<img src="images/book_shopCart/book${orLine.book.id}.jpg"> <span>
${orLine.book.name} <br>
</span> <span class="price" style="display: none">${orLine.book.price}</span>
<span style="display: none" class="bookId">${orLine.book.id}</span>
<span class="bookNum" style="display: none">${orLine.num}</span>
<div class="mm">
<span>¥ ${orLine.book.price}</span>
</div>
<div>
<dl>
<dd class="dd1" onclick="numReduce(this)">-</dd> <!-- 商品减少 TODO num减少 返回页面 -->
</dl>
<input type="text" value="${orLine.num}"
onblur="numChange(this)" />
<dl>
<dd class="dd2" onclick="numAdd(this)">+</dd>
</dl>
</div>
<div class="ri">¥ ${orLine.book.price}</div>
<div class="righ">
<div class="rig" style="cursor: pointer;"
onclick="delShopCart('1')">删除</div>
</div>
</div>
</c:forEach>

用jQuery 实现购物车增与减 全选与取消全选(删除还未实现)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//+ 的功能
function numAdd(which) {
var price = $(which).parents("div").siblings('.price').text()*1;
var bookNum = parseInt($(which).parents("div").siblings('.bookNum').text());
var chcek = $(which).parents("div").siblings('.checkbox');
if(bookNum>10) {
alert("数量达到上限");
}else{
bookNum++;
if(chcek.prop("checked")) {
toPrice += price
$("#toprice").text(toPrice.toFixed(2))
}

}
$(which).parent().siblings('input').val(bookNum);
$(which).parents("div").siblings('.bookNum').text(bookNum);

}
//- 的功能实现
function numReduce(which) {
var price = $(which).parents("div").siblings('.price').text()*1;
var bookNum = parseInt($(which).parents("div").siblings('.bookNum').text());
var chcek = $(which).parents("div").siblings('.checkbox');
if(bookNum<2) {
alert("数量至少为1");
}else{
bookNum--;
if(chcek.prop("checked")) {
toPrice -= price
$("#toprice").text(toPrice.toFixed(2))
}

}
$(which).parent().siblings('input').val(bookNum);
$(which).parents("div").siblings('.bookNum').text(bookNum);

}

//修改数量功能实现
function numChange(which) {
var nBookNum = $(which).val()*1
var price = $(which).parents("div").siblings('.price').text()*1;
var bookNum = parseInt($(which).parents("div").siblings('.bookNum').text());
var chcek = $(which).parents("div").siblings('.checkbox');
if(nBookNum>11) {
alert("数量达到上限");
$(which).val(bookNum)
return;
}else if(nBookNum<1){
alert("数量至少为1")
$(which).val(bookNum)
return;
}else {
if(chcek.prop("checked")) {
toPrice -= price*(bookNum-nBookNum)
$("#toprice").text(toPrice.toFixed(2))
}

}
$(which).parents("div").siblings('.bookNum').text(nBookNum);

}
//假如被选择了 修改显示价格
function checkEvent(which) {
var price = $(which).siblings('.price').text() * 1;
var bookNum = parseInt($(which).siblings('.bookNum').text());
var allPrice = price * bookNum
if ($(which).prop("checked")) {
num++
toPrice = allPrice + toPrice
} else {
num--
toPrice = toPrice - allPrice
}

$("#num").text(num)
$("#toprice").text(toPrice.toFixed(2))
}

//全选 与取消全选
function sele() {
if ($(this).prop("checked") != true) {
$("input[type='checkbox']").each(function () {
if ($(this).prop("checked") != true) {
$(this).prop('checked', true);
if($(this).siblings('.bookNum').text()){
checkEvent(this);
}
}
});
$(this).prop("checked", true);
} else {
$("input[type='checkbox']").each(function () {
if ($(this).prop("checked") == true) {
$(this).prop('checked', false);
if($(this).siblings('.bookNum').text()){
checkEvent(this);
}
}
});
$(this).prop("checked", false);
}
}

构建跳转链接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function jump() {
var bookId = "";
var toBookNum = "";
var cusId = $("#cus_id").text()
var orderForm = $("#orF_id").text()
$("input[type='checkbox']").each(function () {
if ($(this).prop("checked") == true) {
if($(this).siblings('.bookNum').text()){
bookId = bookId + "a" + $(this).siblings('.bookId').text();
toBookNum = toBookNum + 'a' + $(this).siblings('.bookNum').text();
}
}
});

if(bookId=="" || toBookNum == ""){
alert("您还没有选择商品")
}else{
window.location.href="./ComfireServlet?cus_id=" + cusId + "&bookId=" + bookId + "&bookNum=" + toBookNum + "&orderFormId=" + orderForm; //cusid bookid booknum
}
}

bookId, bookNum 拼装成一个String 中间用a隔开 在servlet 中再解开

显示订单(待结算界面)

servlet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("utf-8");

Long cusId =Long.parseLong(request.getParameter("cus_id"));
String strBookIds = request.getParameter("bookId");
String strBookNums = request.getParameter("bookNum");
String orderFormId = request.getParameter("orderFormId");
String[] bookIds = strBookIds.split("a"); //分割string
String[] bookNum = strBookNums.split("a"); //分割String
List<OrderLine> lines = new ArrayList<>();
Long num = 0L;
for(int i=1; i<bookIds.length; i++) { //第一个数据为NULL 所以下标从1开始
OrderLine orLine = new OrderLine();
orLine.setBook(new BookServiceImpl().getBookById(Long.parseLong(bookIds[i])));
orLine.setNum(Long.parseLong(bookNum[i]));
orLine.setOrderForm(new OrderFormServiceImpl().getOrderFormById(Long.parseLong(orderFormId)));
lines.add(orLine);
num +=Long.parseLong(bookNum[i]);
}
OrderLineService oLService = new OrderLineServiceImpl();
oLService.trySaveLines(lines, Long.parseLong(orderFormId));//将选的书存入数据库
Double price = oLService.SumOfPrice(lines);
//new OrderFormServiceImpl().updateCost(Long.parseLong(orderFormId), price); //将总价存入数据库

HttpSession session = request.getSession();
List<ShipAddress> addrs = new ShipAddressServiceImpl().findAllAddrByCusId(cusId);

session.setAttribute("addrs", addrs);
session.setAttribute("orderLines", lines);
session.setAttribute("price", price); //此时这个总价还没有存入数据库 因为订单还没有结算
session.setAttribute("allNum", num);
response.sendRedirect("./confirm.jsp");
}

将购物车传入的数据写入数据库 并取出所有相关数据(数据库已存在地址,订单) 传出页面

结算页面展示订单信息

1
2
3
4
5
6
7
8
9
10
11
12
<c:forEach items="${sessionScope.orderLines}" var="order">
<ul class="oneUL">
<li>
<img src="images/book_shopCart/book${order.book.id }.jpg" class="pic">
<p>${order.book.type }&nbsp;&nbsp;${order.book.name }&nbsp;&nbsp;</p>
<p><font>¥ ${order.book.price }</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;×${order.num}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;有货</p>
<p><img src="images/sureLogo_14.png" alt=""><span>七天无理由退换货</span></p>

</li>
<li><pre>【赠品】 高级定制干花书签 随机 ×1</pre></li>
</ul>
</c:forEach>

展示地址

1
2
3
4
5
6
7
8
9
<c:forEach items="${sessionScope.addrs}" var="addr">
<p style="font-size:15px;color:red">
<input type="radio" name="address" onclick="addShipaddress('${addr.shipuName}','${addr.adres }','${addr.phone}',${addr.id})">
${addr.shipuName}
${addr.adres }
${addr.phone}
<br><br>
</p>
</c:forEach>

选择地址

1
2
3
4
5
6
function addShipaddress(name,address,phone,id){
document.getElementById('addName').value = name;
document.getElementById('addAdd').value = address;
document.getElementById('addPhone').value = phone;
sid = id;
}

添加地址

1
2
3
4
5
6
7
8
9
10
11
12
13
//确认新增收货地址
function addAddr(){
document.getElementById('divDialog').style.display='none'
var addr_name= document.getElementById('addr_name').value;
var addr_phone= document.getElementById('addr_phone').value;
var addr_detail= document.getElementById('addr_detail').value;

document.getElementById('addName').value = addr_name;
document.getElementById('addAdd').value = addr_detail;
document.getElementById('addPhone').value = addr_phone;

window.location.href="AddShipaddressServlet?name="+addr_name+"&address="+addr_detail+"&telephone="+addr_phone+"&customerId="+${customer.id};
}//end 确认新增收货地址

AddShipaddressServlet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("utf-8");

String name = request.getParameter("name");
String address = request.getParameter("address");
String telephone = request.getParameter("telephone");
String id = request.getParameter("customerId");
Long customerId = (long) Integer.parseInt(id);

ShipAddressServiceImpl service = new ShipAddressServiceImpl();
Customer customer = new CustomerServiceImpl().getCustomerById(customerId);

ShipAddress shipaddress = new ShipAddress(name, address, telephone, customer);


if(service.trySave(shipaddress)) {
System.out.println("保存成功");
}else {
System.out.println("保存失败");
}
//更新地址
HttpSession session = request.getSession();
List<ShipAddress> addrs = new ShipAddressServiceImpl().findAllAddrByCusId(customerId);
session.setAttribute("addrs", addrs);
response.sendRedirect("./confirm.jsp");
}

跳转

1
2
3
function confirmOrder(cus_id, cost, or_id) {
window.location.href="ConfirmSucServlet?cusId=" + cus_id + "&addrId=" + sid + "&cost=" + cost + "&or_id=" + or_id;
}

##订单详情

ConfirmSucServlet

根据 cus_id 和 sid 获得相关订单和地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("utf-8");

Long cusId = Long.parseLong(request.getParameter("cusId"));
Long addrId = Long.parseLong(request.getParameter("addrId"));
Double cost = Double.parseDouble(request.getParameter("cost"));
Long orderFormId = Long.parseLong(request.getParameter("or_id"));
Customer customer = new CustomerServiceImpl().getCustomerById(cusId);
ShipAddress addr = new ShipAddressServiceImpl().getAddrById(addrId);

new OrderFormServiceImpl().updateCost(orderFormId, cost);//cost 存入数据库

HttpSession session = request.getSession();
session.setAttribute("customer", customer);
session.setAttribute("addr", addr);
session.setAttribute("cost", cost); //cost发送到页面 表示订单完成
response.sendRedirect("./confirmSuc.jsp");
}

在页面展示

1
2
3
4
5
6
7
8
9
<span style="font-size:15px;color: red">
订单提交成功!订单详情:<br>
用户:${customer.name}<br>
费用:${cost}<br>
收货人:${addr.shipuName }
收货地址:${addr.adres }<br>

<a href="index.jsp">继续购物</a>
</span>

我的订单

根据已有信息展示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<tr>
<th colspan="2"><input type="checkbox" name="orderid" value="">
<b>${orderForm.orderDate }</b>
<span>订单编号:${orderForm.id }</span>
</th>
<th colspan="1">
briup自营
</th>
<th>
<a href="DelOrderServlet?orderid=121"><img alt="" src="images/del.png" style="float: right"></a>
</th>
</tr>
<span style="display: none" id="cost">${cost }</span>
<c:forEach items="${sessionScope.orLines}" var="orLine">
<tr class="trDis" style="display: none">
<td>
<img alt="" src="images/book_shopCart/book${orLine.book.id }.jpg" style="float:left;">
<p style="padding-top: 30px;">${orLine.book.name }</p>
</td>
<td>${orLine.book.price }</td>
<td>${orLine.num }</td>
<td>

总价值:${orLine.book.price * orLine.num }<br/>
(含运费:¥0.0元)

</td>
</tr>
</c:forEach>

判断数据库中订单是否为已结算订单

判断是否有总价 有的话显示 否则不显示

1
2
3
4
5
6
7
8
9

$(function() {
var cost = $("#cost").text()
if(cost) {
$(".trDis").each(function() {
$(this).css("display", "block");
});
}
});
------ end ------