码迷,mamicode.com
首页 > 其他好文 > 详细

商城项目回顾整理(二)easyUi数据表格使用

时间:2017-09-19 22:51:01      阅读:436      评论:0      收藏:0      [点我收藏+]

标签:char   layout   post   reset   tty   splay   selection   输入   style   

后台主页:

商品的数据表格展示

引入用户表数据表格展示

引入日志表数据表格展示

引入订单表数据表格展示

后台主页代码:

  1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2     pageEncoding="UTF-8"
  3     import="com.hanqi.model.Log,java.net.UnknownHostException,java.net.InetAddress,java.util.*,com.hanqi.dal.MethodDal"%>
  4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5 <html>
  6 <head>
  7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  8 <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
  9 <script type="text/javascript"
 10     src="jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
 11     <link rel="shortcut icon" href="img/logo1.jpg"/>
 12 <link type="text/css" rel="stylesheet"
 13     href="jquery-easyui-1.5.1/themes/icon.css"></link>
 14 <link type="text/css" rel="stylesheet"
 15     href="jquery-easyui-1.5.1/themes/default/easyui.css"></link>
 16 <script type="text/javascript"
 17     src="jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
 18 <title>商城后台管理</title>
 19 
 20 <!-- <script type="text/javascript" src="js/index.js"></script> -->
 21 <style type="text/css">
 22 .datagrid-btable tr {
 23     height: 30px;
 24 }
 25 </style>
 26 </head>
 27     <%
 28     //验证session,防止直接进入该页面
 29     request.setCharacterEncoding("utf-8");
 30     response.setCharacterEncoding("utf-8");
 31     response.setContentType("text/html; charset=utf-8");
 32     
 33     Object obj = request.getSession().getAttribute("admin");//获取session对象
 34     
 35     if(obj == null) {
 36         response.sendRedirect("h_login_j.jsp");
 37     }  
 38     
 39     %>
 40 <%    //访问后台主页写入日志
 41     Object o=session.getAttribute("log");
 42     if(o==null){
 43         Log log = new Log();
 44         log.setPname("admin");
 45         log.setPugroup("超级管理员");
 46         InetAddress address = null;
 47         Date date = new Date();
 48         log.setPuptime(date.toLocaleString());
 49         try {
 50             address = InetAddress.getLocalHost();
 51         } catch (UnknownHostException e) {
 52             // TODO Auto-generated catch block
 53             e.printStackTrace();
 54         }
 55         log.setPip(address.getHostAddress());
 56         log.setPlog("后台主页");
 57         MethodDal m = new MethodDal();
 58         m.insertLog(log);
 59         session.setAttribute("log", log);
 60     }
 61     
 62 %>
 63 <body class="easyui-layout">
 64     <!-- 添加商品 -->
 65     <div data-options="region:‘north‘,split:true"
 66         style="height: 50px; background-color: cornflowerblue">
 67         <span style="height: 40px; line-height: 40px; vertical-align: center;">登录用户:<%
 68      Log l = (Log) session.getAttribute("log");
 69      out.print(l.getPname());
 70  %>&nbsp;|&nbsp;用户组:<%=l.getPugroup()%>&nbsp;|&nbsp;登录时间:<%=l.getPuptime()%>
 71             &nbsp;|&nbsp; 当前IP:<%=l.getPip()%>
 72         </span><br>
 73     </div>
 74     <!-- 对话框开始 -->
 75     <div data-options="region:‘center‘,split:true"
 76         style="padding: 5px; background: #eee">
 77         <div id="tabs" class="easyui-tabs" style="width: 100%; height: 100%;">
 78             <div title="主页" style="">
 79                 <table id="dg"></table>
 80                 <!-- 商品的表单 -->
 81                 <div id="zhong" style="display: none">
 82                     <form id="addGood" method="post"
 83                         style="width: 600px; padding: 20px">
 84                         商品名称:<input  name="gname" class="tb easyui-validatebox" type="text"
 85                             style="width: 200px"> <span style="margin-left: 50px">商品价格:</span><input  id="jiage"
 86                             name="gprice" class="tb easyui-numberbox" type="text" style="width: 150px;"><br>
 87                         商品品牌:<input name="gpinpai" class="tb easyui-validatebox" type="text"
 88                             style="width: 200px; margin-top: 10px"> <span
 89                             style="margin-left: 50px">商品类型:</span>
 90                             <input id="gleixing" style="width: 150px;"  class="easyui-combobox" name="gleixing"   
 91     data-options="valueField:‘id‘,textField:‘text‘,url:‘opdata.json‘" /> 
 92         <!-- <input name="gleixing" class="tb easyui-validatebox" type="text" style="width: 150px; margin-top: 10px"> -->
 93     <br>
 94                         商品图片:<input name="gpricture" class="tb" type="file"
 95                             style="width: 200px; margin-top: 10px"><br>
 96                         <!-- 加载编辑器的容器 -->
 97                         <script id="container" name="content" type="text/plain"
 98                             imagePathFormat="/upload/">
 99                              请输入商品描述
100                         </script>
101                         <input type="submit" name="" id="" value="提交" />
102                         <input type="reset" value="重置">
103                     </form>
104                 </div>
105                 <!-- 商品的表单 -->
106                 <div id="gai" style="display: none">
107                     <!-- <div id="gai" class="easyui-dialog" data-options="closed:true"> -->
108                     <form id="fromgai" action="GaiGoodsGoodst" method="post"
109                         style="width: 600px; padding: 20px">
110                         商品名称:<input name="gname" class="tb" type="text"
111                             style="width: 200px"> <span style="margin-left: 50px">商品价格:</span><input
112                             name="gprice" class="tb" type="text" style="width: 150px;"><br>
113                         商品品牌:<input name="gpinpai" class="tb" type="text"
114                             style="width: 200px; margin-top: 10px"> <span
115                             style="margin-left: 50px">商品类型:</span><input name="gleixing"
116                             class="tb" type="text" style="width: 150px"><br>
117                         商品图片:<input name="gpicture" class="tb" type="text"
118                             style="width: 200px; margin-top: 10px"><br> <input
119                             name="xpricture" class="tb" type="file"
120                             style="width: 200px; margin-top: 10px"><br>
121                         <!-- 加载编辑器的容器 -->
122                         <template> <input type="text" name="gdetails" id="" />
123                         </template>
124                         <script id="container1" name="gdetails" type="text/plain"
125                             imagePathFormat="/upload/">
126                               
127                         </script>
128                         <input type="submit" name="" id="" value="提交" />
129                     </form>
130                 </div>
131             </div>
132         </div>
133     </div>
134     <!-- 对话框结束 -->
135     <!-- 目录开始 -->
136     <div data-options="region:‘west‘,split:true" width=210>
137         <div id="aa" class="easyui-accordion"
138             style="width: 200px; height: 543px">
139             <div title="商品管理" style="overflow: auto; padding: 10px">
140                 <ul>
141                     <li class="lis"><a href="#" class="easyui-linkbutton ab abc"
142                         plain="true">添加商品</a></li>
143                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
144                         plain="true">待引进商品</a></li>
145                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
146                         plain="true">待审核商品</a></li>
147                 </ul>
148             </div>
149             <div title="订单管理" style="overflow: auto; padding: 10px">
150                 <ul>
151                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
152                         plain="true" id="neworder">新增订单</a></li>
153                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
154                         plain="true" id="oldorder">已确认订单</a></li>
155                 </ul>
156             </div>
157             <div title="用户管理" style="overflow: auto; padding: 10px">
158                 <ul>
159                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
160                         plain="true">添加用户</a></li>
161                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
162                         plain="true">删除用户</a></li>
163                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
164                         plain="true" id="userlook">查看用户</a></li>
165                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
166                         plain="true" id="userlog">日志记录</a></li>
167                 </ul>
168             </div>
169             <div title="促销管理" style="overflow: auto; padding: 10px"></div>
170             <div title="基础信息维护" style="overflow: auto; padding: 10px"></div>
171         </div>
172     </div>
173     <!-- 底部声明 -->
174     <div data-options="region:‘south‘,split:true"
175         style="height: 40px; line-height: 40px; vertical-align: center; text-align: center;">
176         玛雅网络版权声明</div>
177     <!-- 目录结束 -->
178 </body>
179 <!-- 配置文件 -->
180 <script type="text/javascript" src="ueditor.config.js"></script>
181 <!-- 编辑器源码文件 -->
182 <script type="text/javascript" src="ueditor.all.js"></script>
183 <!-- 实例化编辑器 -->
184 <script type="text/javascript">
185         var editor = UE.getEditor(container);
186         var editor1 = UE.getEditor(container1);
187 </script>
188 </html>
189 <script>
190 $(function() {  
191     $(#addGood).form({    
192         url:InserGoodst,
193         onSubmit: function(){
194             return $(#addGood).form(validate);//如果有为空则返回false阻止提交
195         },
196         success:function(data){    
197             if(data=="true"){
198                 alert("添加成功");
199             }else if(data=="false"){
200                 alert("请检查信息正确!");
201             }
202         }    
203     });
204 
205     $(#userlog).click(function(){
206         var content = <iframe scrolling="auto" frameborder="0" src="UserLog.jsp" style="width:100%;height:100%;"></iframe>;
207          $(#tabs).tabs(add,{    
208             title:用户日志,    
209             content:content,    
210             closable:true,    
211             tools:[{    
212                 iconCls:icon-mini-refresh,    
213                 handler:function(){    
214                 }    
215             }]    
216         });
217     });
218     $(#userlook).click(function(){
219         var content = <iframe scrolling="auto" frameborder="0" src="UserLook.jsp" style="width:100%;height:100%;"></iframe>;
220          $(#tabs).tabs(add,{    
221             title:用户日志,    
222             content:content,    
223             closable:true,    
224             tools:[{    
225                 iconCls:icon-mini-refresh,    
226                 handler:function(){    
227                 }    
228             }]    
229         });
230     });
231     
232     $(#neworder).click(function(){
233         var content = <iframe scrolling="auto" frameborder="0" src="ShowOrder.jsp" style="width:100%;height:100%;"></iframe>;
234          $(#tabs).tabs(add,{    
235             title:订单管理,    
236             content:content,    
237             closable:true,    
238             tools:[{    
239                 iconCls:icon-mini-refresh,    
240                 handler:function(){    
241                 }    
242             }]    
243         });
244     });
245     
246     $(#oldorder).click(function(){
247         var content = <iframe scrolling="auto" frameborder="0" src="ShowOrder1.jsp" style="width:100%;height:100%;"></iframe>;
248          $(#tabs).tabs(add,{    
249             title:订单管理,    
250             content:content,    
251             closable:true,    
252             tools:[{    
253                 iconCls:icon-mini-refresh,    
254                 handler:function(){    
255                 }    
256             }]    
257         });
258     });
259     
260     $(#dg).datagrid({    
261         url : ShowwAllServlet,
262         striped:true,//显示斑马线
263         autoRowHeight:false,//定义设置行的高度,根据该行的内容。设置为false可以提高负载性能。这里不设置,css中设置的行高无效
264         singleSelect:true,//只允许选择一行
265         pagination : true,
266         pageNumber : 1,
267         pageSize : 1,
268         pageList : [ 1, 3, 5 ],
269         
270         toolbar : [ {
271             iconCls : icon-edit,
272             text : "编辑",
273             handler : function() {
274                 //var gid=$(‘.datagrid-row-selected‘).find(‘.datagrid-cell-c1-gid‘).html();//获取当前被选中的行的gid
275                 var gid = $(#dg).datagrid("getSelected").gid;//获取当前被选中的行的gid
276                 //console.log("--------------"+gid1);
277                 var content = <iframe scrolling="auto" frameborder="0" src="EditGoods.jsp?gid=+gid+" style="width:100%;height:100%;"></iframe>;
278                 if(gid>-1){
279                     $(#tabs).tabs(add,{    
280                         title:修改商品,    
281                         content:content,    
282                         closable:true,    
283                         tools:[{    
284                             iconCls:icon-mini-refresh,    
285                             handler:function(){    
286                             }    
287                         }]    
288                     });  
289                 }else{
290                     alert("请选择您要修改的商品");
291                 }
292             }
293         }, -,{
294             iconCls : icon-edit,
295             text : "编辑2",
296             handler : function() {    
297                 var a = $(this).text();
298                 
299                 $(#gai).dialog({
300                     width : 800,
301                     height : 500,
302                     title : a,
303                     //closed : false,
304                     cache : false,
305                     modal : true
306                 });
307                 $(#gai).dialog("open");
308                 var r = $("#dg").datagrid("getSelected");//获取被选中的行,返回对象
309                 $("#fromgai").form("load", r);//将被选中的信息放到弹出的的表单中,富文本编辑器的内容无法显示
310             }
311         },  -,
312         {
313             iconCls : icon-cancel,
314             text : "删除",
315             handler : function() {
316                 //var gid = $(‘#dg‘).datagrid("getSelections");//获取当前被选中的行
317                 var gid=$(.datagrid-row-selected).find(.datagrid-cell-c1-gid).html();//获取当前被选中的行的gid
318                 if(gid>-1){
319                     var r1 = confirm("确定删除ID为  "+gid+" 的商品吗?");
320                     if(r1) {
321                         window.location.href="DelGoodServlet?gid="+gid;
322                         alert("删除成功");
323                     }
324                 }else{
325                     alert("请选中需要删除的商品");
326                 }
327                 
328             }
329         } ,-, {
330             iconCls : icon-help,
331             text : "帮助",
332             handler : function() {
333                 alert(帮助按钮)
334             }
335         } ],
336 
337          frozenColumns : [ [ {
338             field : ‘‘,
339             title : ‘‘,
340             width : 100,
341             checkbox : true
342         }, {
343             field : gid,
344             title : 商品代码,
345             width : 60
346         } ] ], 
347         columns : [ [ {
348             field : "gname",
349             title : "商品名称",
350             width:200
351         }, {
352             field : "gdetails",
353             title : "商品详情",
354             width:100
355         }, {
356             field : "gpicture",
357             title : "图片",
358             width:100
359         }, {
360             field : "gprice",
361             title : "价格",
362             width:50
363         }, {
364             field : "gleixing",
365             title : "类型",
366             width:50
367         }, {
368             field : "gpinpai",
369             title : "品牌",
370             width:100
371         }  ] ],
372         
373     }); 
374     $(.abc).click(function() {
375         var a = $(this).text();
376         // alert(a);
377         $(#zhong).dialog({
378             width : 800,
379             height : 500,
380             title : a,
381             closed : false,
382             cache : false,
383             modal : true
384         })
385     });
386 });
387 </script>

商品类:

 1 package com.hanqi.model;
 2 
 3 import java.sql.Clob;
 4 
 5 //商品类
 6 public class Goods {
 7     
 8     private Integer gid;//商品ID
 9 
10     private String gname;//商品名称
11     private String gdetails;//商品详情
12     private String gpicture;//商品图片
13     private int gprice;//商品价格
14     private int gleixing;//商品类型
15     private String gpinpai;//商品品牌
16     
17     public Goods() {
18         super();
19         // TODO Auto-generated constructor stub
20     }
21     public Goods(Integer gid, String gname, String gdetails, String gpicture, int gprice, int gleixing, String gpinpai) {
22         super();
23         this.gid = gid;
24         this.gname = gname;
25         this.gdetails = gdetails;
26         this.gpicture = gpicture;
27         this.gprice = gprice;
28         this.gleixing = gleixing;
29         this.gpinpai = gpinpai;
30     }
31     
32     public Integer getGid() {
33         return gid;
34     }
35     public void setGid(Integer gid) {
36         this.gid = gid;
37     }
38     public String getGname() {
39         return gname;
40     }
41     public void setGname(String gname) {
42         this.gname = gname;
43     }
44     public String getGdetails() {
45         return gdetails;
46     }
47     public void setGdetails(String gdetails) {
48         this.gdetails = gdetails;
49     }
50     public String getGpicture() {
51         return gpicture;
52     }
53     public void setGpicture(String gpicture) {
54         this.gpicture = gpicture;
55     }
56     public int getGprice() {
57         return gprice;
58     }
59     public void setGprice(int gprice) {
60         this.gprice = gprice;
61     }
62     public int getGleixing() {
63         return gleixing;
64     }
65     public void setGleixing(int gleixing) {
66         this.gleixing = gleixing;
67     }
68     public String getGpinpai() {
69         return gpinpai;
70     }
71     public void setGpinpai(String gpinpai) {
72         this.gpinpai = gpinpai;
73     }
74     @Override
75     public String toString() {
76         return "Goods [gid=" + gid + ", gname=" + gname + ", gdetails=" + gdetails + ", gpicture=" + gpicture
77                 + ", gprice=" + gprice + ", gleixing=" + gleixing + ", gpinpai=" + gpinpai + "]";
78     }
79     
80     
81     
82     
83 }

商品列表Servlet:

 1 package com.hanqi.servlet;
 2 
 3 import java.io.IOException;
 4 import java.util.List;
 5 
 6 import javax.servlet.ServletException;
 7 import javax.servlet.annotation.WebServlet;
 8 import javax.servlet.http.HttpServlet;
 9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11 
12 import com.alibaba.fastjson.JSONObject;
13 import com.hanqi.dal.MethodDal;
14 import com.hanqi.model.Goods;
15 
16 /**
17  * Servlet implementation class ShowwAllServlet
18  */
19 @WebServlet("/ShowwAllServlet")
20 public class ShowwAllServlet extends HttpServlet {
21     private static final long serialVersionUID = 1L;
22        
23     /**
24      * @see HttpServlet#HttpServlet()
25      */
26     public ShowwAllServlet() {
27         super();
28         // TODO Auto-generated constructor stub
29     }
30 
31     /**
32      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
33      */
34     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
35         request.setCharacterEncoding("utf-8");
36         response.setCharacterEncoding("utf-8");
37         response.setContentType("utf-8");
38         
39         MethodDal m=new MethodDal();
40 
41         List<Goods> list = m.getAllGoods();
42         
43         JSONObject jo = new JSONObject();
44         
45         jo.put("total", list.size());
46         jo.put("rows", list);
47         response.getWriter().append(jo.toJSONString());
48         
49         
50     }
51 
52     /**
53      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
54      */
55     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
56         // TODO Auto-generated method stub
57         doGet(request, response);
58     }
59 
60 }

 

订单页:

 1 <%@ page language="java" contentType="text/html; charset=utf-8"
 2     pageEncoding="utf-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 7 <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
 8 <script type="text/javascript"
 9     src="jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
10 <link type="text/css" rel="stylesheet"
11     href="jquery-easyui-1.5.1/themes/icon.css"></link>
12 <link type="text/css" rel="stylesheet"
13     href="jquery-easyui-1.5.1/themes/default/easyui.css"></link>
14 <script type="text/javascript"
15     src="jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
16 <title>订单管理</title>
17 <link rel="shortcut icon" href="img/logo1.jpg"/>
18 </head>
19 <body>
20 <table id="table"></table>
21 </body>
22 </html>
23 <script>
24 $(function() {
25     $(#table).datagrid({    
26         url : ShowOrderServlet,
27         striped:true,//显示斑马线
28         autoRowHeight:false,//定义设置行的高度,根据该行的内容。设置为false可以提高负载性能。这里不设置,css中设置的行高无效
29         singleSelect:true,//只允许选择一行
30         pagination : true,
31         pageNumber : 1,
32         pageSize : 1,
33         pageList : [ 1, 3, 5 ],
34         
35         toolbar : [ {
36             iconCls : icon-help,
37             text : "帮助",
38             handler : function() {
39                 alert(帮助按钮)
40             }
41         },{
42             iconCls : icon-ok,
43             text : "确认",
44             handler : function() {
45                 var r = $("#table").datagrid("getSelected");//获取被选中的行,返回对象
46                 if(r.sczt=="已确认"){
47                     alert("订单就不能再次确认");
48                 }else{
49                     //alert(r.sctime);
50                     var href=ShowOrder1.jsp?sctime=+r.sctime;
51                     location.href=href;
52                 }
53             }
54         } ],
55 
56          frozenColumns : [ [ {
57             field : scid,
58             title : 订单号,
59             width : 80
60         } ] ], 
61         columns : [ [ {
62             field : "scuser",
63             title : "用户",
64             width:110
65         }, {
66             field : "scgid",
67             title : "商品ID",
68             width:200
69         }, {
70             field : "scnum",
71             title : "商品数量",
72             width:130
73         }, {
74             field : "scmoney",
75             title : "订单总价",
76             width:130
77         }
78         , {
79             field : "sctime",
80             title : "下单时间",
81             width:180
82         } 
83         , {
84             field : "sczt",
85             title : "订单状态",
86             width:180
87         } ] ],
88         
89     }); 
90 });
91 </script>

订单类:

 1 package com.hanqi.model;
 2 
 3 public class Order {
 4     private String scid;//订单单号
 5     private String scuser;//用户名
 6     private String scgid;//商品id
 7     private int scnum;//所有商品数量
 8     private int scmoney;//商品总价
 9     private String sctime;//下单时间
10     private String sczt;//订单状态
11     public String getScid() {
12         return scid;
13     }
14     public void setScid(String scid) {
15         this.scid = scid;
16     }
17     public String getScuser() {
18         return scuser;
19     }
20     public void setScuser(String scuser) {
21         this.scuser = scuser;
22     }
23     public String getScgid() {
24         return scgid;
25     }
26     public void setScgid(String scgid) {
27         this.scgid = scgid;
28     }
29     public int getScnum() {
30         return scnum;
31     }
32     
33     public int getScmoney() {
34         return scmoney;
35     }
36     public void setScmoney(int scmoney) {
37         this.scmoney = scmoney;
38     }
39     public void setScnum(int scnum) {
40         this.scnum = scnum;
41     }
42     public String getSctime() {
43         return sctime;
44     }
45     public void setSctime(String sctime) {
46         this.sctime = sctime;
47     }
48     
49     public String getSczt() {
50         return sczt;
51     }
52     public void setSczt(String sczt) {
53         this.sczt = sczt;
54     }
55     @Override
56     public String toString() {
57         return "Order [scid=" + scid + ", scuser=" + scuser + ", scgid=" + scgid + ", scnum=" + scnum + ", sctime="
58                 + sctime + "]";
59     }
60     
61     
62 }

订单的Servlet:

 1 package com.hanqi.servlet;
 2 
 3 import java.io.IOException;
 4 import java.util.List;
 5 
 6 import javax.servlet.ServletException;
 7 import javax.servlet.annotation.WebServlet;
 8 import javax.servlet.http.HttpServlet;
 9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11 
12 import com.alibaba.fastjson.JSONObject;
13 import com.hanqi.dal.MethodDal;
14 import com.hanqi.model.Log;
15 import com.hanqi.model.Order;
16 
17 /**
18  * Servlet implementation class ShowOrderServlet
19  */
20 @WebServlet("/ShowOrderServlet")
21 public class ShowOrderServlet extends HttpServlet {
22     private static final long serialVersionUID = 1L;
23        
24     /**
25      * @see HttpServlet#HttpServlet()
26      */
27     public ShowOrderServlet() {
28         super();
29         // TODO Auto-generated constructor stub
30     }
31 
32     /**
33      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
34      */
35     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
36         request.setCharacterEncoding("utf-8");
37         response.setCharacterEncoding("utf-8");
38         response.setContentType("utf-8");
39         MethodDal m=new MethodDal();
40         
41         String scuser=request.getParameter("scuser");
42         String sc=request.getParameter("scuser");
43         
44         if(sc!=null){
45             int scmoney=Integer.parseInt(sc);
46             
47             
48             List<Order> l=m.getAllOrder(scuser);
49             
50             Order or=new Order();
51             
52             or.setScid(l.get(0).getScid());
53             or.setScuser(l.get(0).getScuser());
54             or.setSctime(l.get(0).getSctime());
55             or.setScmoney(scmoney);
56             String gid="";
57             int num=0;
58             
59             for(Order o:l){
60                 gid=o.getScgid()+","+gid;
61                 num=o.getScnum()+num;
62             }
63             or.setScgid(gid);
64             or.setScnum(num);
65             or.setSczt("待确认");
66             int a=m.insertOrder(or);
67         }
68         
69         
70         
71         List<Order> lo=m.getAllOrder();
72         
73         JSONObject jo = new JSONObject();
74         
75         jo.put("total", lo.size());
76         jo.put("rows", lo);
77         response.getWriter().append(jo.toJSONString());
78     }
79 
80     /**
81      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
82      */
83     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
84         // TODO Auto-generated method stub
85         doGet(request, response);
86     }
87 
88 }

 

日志页:

 1 <%@ page language="java" contentType="text/html; charset=utf-8"
 2     pageEncoding="utf-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 7 <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
 8 <script type="text/javascript"
 9     src="jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
10 <link type="text/css" rel="stylesheet"
11     href="jquery-easyui-1.5.1/themes/icon.css"></link>
12 <link type="text/css" rel="stylesheet"
13     href="jquery-easyui-1.5.1/themes/default/easyui.css"></link>
14 <script type="text/javascript"
15     src="jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
16 <title>操作日志</title>
17 <link rel="shortcut icon" href="img/logo1.jpg"/>
18 </head>
19 <body>
20 <table id="table"></table>
21 </body>
22 </html>
23 <script>
24 $(function() {
25     $(#table).datagrid({    
26         url : ShowLogServlet,
27         striped:true,//显示斑马线
28         autoRowHeight:false,//定义设置行的高度,根据该行的内容。设置为false可以提高负载性能。这里不设置,css中设置的行高无效
29         singleSelect:true,//只允许选择一行
30         pagination : true,
31         pageNumber : 1,
32         pageSize : 1,
33         pageList : [ 1, 3, 5 ],
34         
35         toolbar : [ {
36             iconCls : icon-help,
37             text : "帮助",
38             handler : function() {
39                 alert(帮助按钮)
40             }
41         } ],
42 
43          frozenColumns : [ [ {
44             field : pname,
45             title : 用户名,
46             width : 80
47         } ] ], 
48         columns : [ [ {
49             field : "pugroup",
50             title : "用户组",
51             width:110
52         }, {
53             field : "puptime",
54             title : "登陆时间",
55             width:200
56         }, {
57             field : "pip",
58             title : "IP",
59             width:130
60         }, {
61             field : "plog",
62             title : "操作",
63             width:180
64         }  ] ],
65         
66     }); 
67 });
68 </script>

日志类:

 1 package com.hanqi.model;
 2 
 3 import java.net.InetAddress;
 4 import java.net.UnknownHostException;
 5 
 6 public class Log {
 7     private String pname;
 8     private String pugroup;
 9     private String puptime;
10     private String pip;
11     private String plog;
12     
13     public Log(){
14         super();
15     }
16     public String getPugroup() {
17         return pugroup;
18     }
19     public void setPugroup(String pugroup) {
20         this.pugroup = pugroup;
21     }
22     public String getPlog() {
23         return plog;
24     }
25     public void setPlog(String plog) {
26         this.plog = plog;
27     }
28     public String getPname() {
29         return pname;
30     }
31     public void setPname(String pname) {
32         this.pname = pname;
33     }
34     public String getPuptime() {
35         return puptime;
36     }
37     public void setPuptime(String puptime) {
38         this.puptime = puptime;
39     }
40     public String getPip() {
41         return pip;
42     }
43     public void setPip(String pip) {
44         this.pip = pip;
45     }
46     @Override
47     public String toString() {
48         return "Log [pname=" + pname + ", puptime=" + puptime + ", pip=" + pip + "]";
49     }
50 }

日志的Servlet:

 1 package com.hanqi.servlet;
 2 
 3 import java.io.IOException;
 4 import java.util.List;
 5 
 6 import javax.servlet.ServletException;
 7 import javax.servlet.annotation.WebServlet;
 8 import javax.servlet.http.HttpServlet;
 9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11 
12 import com.alibaba.fastjson.JSONObject;
13 import com.hanqi.dal.MethodDal;
14 import com.hanqi.model.Goods;
15 import com.hanqi.model.Log;
16 
17 /**
18  * Servlet implementation class ShowwAllServlet
19  */
20 @WebServlet("/ShowLogServlet")
21 public class ShowLogServlet extends HttpServlet {
22     private static final long serialVersionUID = 1L;
23        
24     /**
25      * @see HttpServlet#HttpServlet()
26      */
27     public ShowLogServlet() {
28         super();
29         // TODO Auto-generated constructor stub
30     }
31 
32     /**
33      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
34      */
35     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
36         request.setCharacterEncoding("utf-8");
37         response.setCharacterEncoding("utf-8");
38         response.setContentType("utf-8");
39         
40         MethodDal m=new MethodDal();
41 
42         List<Log> list = m.getAllLogs();
43         
44         JSONObject jo = new JSONObject();
45         
46         jo.put("total", list.size());
47         jo.put("rows", list);
48         response.getWriter().append(jo.toJSONString());
49     }
50 
51     /**
52      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
53      */
54     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
55         // TODO Auto-generated method stub
56         doGet(request, response);
57     }
58 
59 }

 

用户页:

 1 <%@ page language="java" contentType="text/html; charset=utf-8"
 2     pageEncoding="utf-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 7 <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
 8 <script type="text/javascript"
 9     src="jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
10 <link type="text/css" rel="stylesheet"
11     href="jquery-easyui-1.5.1/themes/icon.css"></link>
12 <link type="text/css" rel="stylesheet"
13     href="jquery-easyui-1.5.1/themes/default/easyui.css"></link>
14 <script type="text/javascript"
15     src="jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
16 <title>用户查看</title>
17 <link rel="shortcut icon" href="img/logo1.jpg"/>
18 </head>
19 <body>
20 <table id="table"></table>
21 </body>
22 </html>
23 <script>
24 $(function() {
25     $(#table).datagrid({    
26         url : ShowUserServlet,
27         striped:true,//显示斑马线
28         autoRowHeight:false,//定义设置行的高度,根据该行的内容。设置为false可以提高负载性能。这里不设置,css中设置的行高无效
29         singleSelect:true,//只允许选择一行
30         pagination : true,
31         pageNumber : 1,
32         pageSize : 1,
33         pageList : [ 1, 3, 5 ],
34         
35         toolbar : [ {
36             iconCls : icon-help,
37             text : "帮助",
38             handler : function() {
39                 alert(帮助按钮)
40             }
41         } ],
42 
43          frozenColumns : [ [ {
44             field : userid,
45             title : 用户编号,
46             width : 80
47         } ] ], 
48         columns : [ [ {
49             field : "uname",
50             title : "用户名",
51             width:110
52         }, {
53             field : "upassword",
54             title : "用户密码",
55             width:200
56         }, {
57             field : "unickname",
58             title : "昵称",
59             width:130
60         }, {
61             field : "uemail",
62             title : "邮箱",
63             width:180
64         } , {
65             field : "utime",
66             title : "注册时间",
67             width:180
68         }  ] ],
69         
70     }); 
71 });
72 </script>

用户类:

  1 package com.hanqi.model;
  2 
  3 import java.util.Date;
  4 
  5 public class User {
  6    private int Userid;
  7    private String Uname;
  8    private String Upassword;
  9    private String Unickname;
 10    private String Uemail;
 11    private String utime;
 12    
 13 public String getUtime() {
 14     return utime;
 15 }
 16 public void setUtime(String utime) {
 17     this.utime = utime;
 18 }
 19 public int getUserid() {
 20     return Userid;
 21 }
 22 public void setUserid(int userid) {
 23     Userid = userid;
 24 }
 25 public String getUname() {
 26     return Uname;
 27 }
 28 public void setUname(String uname) {
 29     Uname = uname;
 30 }
 31 public String getUpassword() {
 32     return Upassword;
 33 }
 34 public void setUpassword(String upassword) {
 35     Upassword = upassword;
 36 }
 37 public String getUnickname() {
 38     return Unickname;
 39 }
 40 public void setUnickname(String unickname) {
 41     Unickname = unickname;
 42 }
 43 public String getUemail() {
 44     return Uemail;
 45 }
 46 public void setUemail(String uemail) {
 47     Uemail = uemail;
 48 }
 49 @Override
 50 public int hashCode() {
 51     final int prime = 31;
 52     int result = 1;
 53     result = prime * result + ((Uemail == null) ? 0 : Uemail.hashCode());
 54     result = prime * result + ((Uname == null) ? 0 : Uname.hashCode());
 55     result = prime * result + ((Unickname == null) ? 0 : Unickname.hashCode());
 56     result = prime * result + ((Upassword == null) ? 0 : Upassword.hashCode());
 57     result = prime * result + Userid;
 58     return result;
 59 }
 60 @Override
 61 public boolean equals(Object obj) {
 62     if (this == obj)
 63         return true;
 64     if (obj == null)
 65         return false;
 66     if (getClass() != obj.getClass())
 67         return false;
 68     User other = (User) obj;
 69     if (Uemail == null) {
 70         if (other.Uemail != null)
 71             return false;
 72     } else if (!Uemail.equals(other.Uemail))
 73         return false;
 74     if (Uname == null) {
 75         if (other.Uname != null)
 76             return false;
 77     } else if (!Uname.equals(other.Uname))
 78         return false;
 79     if (Unickname == null) {
 80         if (other.Unickname != null)
 81             return false;
 82     } else if (!Unickname.equals(other.Unickname))
 83         return false;
 84     if (Upassword == null) {
 85         if (other.Upassword != null)
 86             return false;
 87     } else if (!Upassword.equals(other.Upassword))
 88         return false;
 89     if (Userid != other.Userid)
 90         return false;
 91     return true;
 92 }
 93 public User(int userid, String uname, String upassword, String unickname, String uemail) {
 94     super();
 95     Userid = userid;
 96     Uname = uname;
 97     Upassword = upassword;
 98     Unickname = unickname;
 99     Uemail = uemail;
100 }
101 public User() {
102     super();
103     // TODO Auto-generated constructor stub
104 }
105 @Override
106 public String toString() {
107     return "User [Userid=" + Userid + ", Uname=" + Uname + ", Upassword=" + Upassword + ", Unickname=" + Unickname
108             + ", Uemail=" + Uemail + "]";
109 }
110    
111    
112    
113    
114 }

用户的Servlet:

 1 package com.hanqi.servlet;
 2 
 3 import java.io.IOException;
 4 import java.util.List;
 5 
 6 import javax.servlet.ServletException;
 7 import javax.servlet.annotation.WebServlet;
 8 import javax.servlet.http.HttpServlet;
 9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11 
12 import com.alibaba.fastjson.JSONObject;
13 import com.hanqi.dal.MethodDal;
14 import com.hanqi.model.Log;
15 import com.hanqi.model.User;
16 
17 /**
18  * Servlet implementation class ShowUserServlet
19  */
20 @WebServlet("/ShowUserServlet")
21 public class ShowUserServlet extends HttpServlet {
22     private static final long serialVersionUID = 1L;
23        
24     /**
25      * @see HttpServlet#HttpServlet()
26      */
27     public ShowUserServlet() {
28         super();
29         // TODO Auto-generated constructor stub
30     }
31 
32     /**
33      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
34      */
35     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
36         // TODO Auto-generated method stub
37         response.getWriter().append("Served at: ").append(request.getContextPath());
38     }
39 
40     /**
41      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
42      */
43     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
44         request.setCharacterEncoding("utf-8");
45         response.setCharacterEncoding("utf-8");
46         response.setContentType("utf-8");
47         
48         MethodDal m=new MethodDal();
49 
50         List<User> list = m.getAllUsers();
51         
52         JSONObject jo = new JSONObject();
53         
54         jo.put("total", list.size());
55         jo.put("rows", list);
56         response.getWriter().append(jo.toJSONString());
57     }
58 
59 }

 

数据库链接:

 1 package com.hanqi.util;
 2 
 3 import java.sql.Connection;
 4 import java.sql.DriverManager;
 5 import java.sql.ResultSet;
 6 import java.sql.SQLException;
 7 import java.sql.Statement;
 8 
 9 /**
10  * 数据库驱动连接类
11  * @author ZBK
12  */
13 public class DBHelper {
14     /**
15      * 数据库用户名
16      */
17     public static final String USERNAME = "test";
18     /**
19      * 数据库密码
20      */
21     public static final String PASSWORD = "test";
22     /**
23      * 数据库驱动类
24      */
25     public static final String DRIVER = "oracle.jdbc.OracleDriver";
26     /**
27      * 数据库地址URL
28      */
29     public static final String URL = "jdbc:oracle:thin:@localhost:1521:xe";
30 
31     /**
32      * 获取数据库连接
33      * @return
34      */
35     public static Connection getConnection() {
36         Connection conn = null;
37         try {
38             Class.forName(DRIVER);
39             conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
40         } catch (ClassNotFoundException e) {
41             e.printStackTrace();
42         } catch (SQLException e) {
43             e.printStackTrace();
44         }
45         return conn;
46     }
47     
48 
49     /**
50      * 释放资源
51      * @param conn 数据库连接对象
52      * @param sm Statement对象
53      * @param rs ResultSet结果集对象
54      */
55     public static void destroy(Connection conn, Statement sm, ResultSet rs) {
56         if (conn != null) {
57             try {
58                 conn.close();
59             } catch (SQLException e) {
60                 e.printStackTrace();
61             }
62             conn = null;
63         }
64         if (sm != null) {
65             try {
66                 sm.close();
67             } catch (SQLException e) {
68                 e.printStackTrace();
69             }
70             sm = null;
71         }
72         if (rs != null) {
73             try {
74                 rs.close();
75             } catch (SQLException e) {
76                 e.printStackTrace();
77             }
78             rs = null;
79         }
80     }
81 
82     /**
83      * 验证前台传入的参数是否为空
84      * @param args
85      * @return
86      */
87     public static boolean checkParam(String... args) {
88         for (String s : args) {
89             if (s == null || s.trim().length() < 1) {
90                 return false;
91             }
92         }
93         return true;
94     }
95 }

数据库方法:

  1 package com.hanqi.dal;
  2 
  3 import java.sql.Connection;
  4 import java.sql.PreparedStatement;
  5 import java.sql.ResultSet;
  6 import java.sql.SQLException;
  7 import java.util.ArrayList;
  8 import java.util.Date;
  9 import java.util.List;
 10 
 11 import com.hanqi.model.Goods;
 12 import com.hanqi.model.Log;
 13 import com.hanqi.model.Order;
 14 import com.hanqi.model.TradingStatusFile;
 15 import com.hanqi.model.User;
 16 import com.hanqi.util.DBHelper;
 17 
 18 public class MethodDal {
 19     private Connection conn;
 20     private PreparedStatement ps;
 21     private ResultSet rs;
 22     
 23     private static int scnum=1000;
 24     //初始化链接
 25     public void init(String sql) {
 26         conn = DBHelper.getConnection();
 27         try {
 28             ps = conn.prepareStatement(sql);
 29         } catch (SQLException e) {
 30             e.printStackTrace();
 31         }
 32     }
 33     //释放资源
 34     public void close(){
 35         DBHelper.destroy(conn, ps, rs);
 36     }
 37     //判断传入的参数有没有空的方法,只要有空的就返回false
 38     public boolean checkParam(String... args){//这样传参数代表参数个数不确定,传几个都可以
 39         for(String s : args){
 40             if("".equals(s)||s==null){
 41                 return false;
 42             }
 43         }
 44         return true;
 45     }
 46     /**
 47      * 返回所有商品
 48      * @return
 49      */
 50     public List<Goods> getAllGoods(){
 51         String sql = "select * from GOODS_TABLE g";
 52         init(sql);
 53         List<Goods> list = new ArrayList<Goods>();
 54         
 55         try {
 56             rs = ps.executeQuery();
 57             while (rs.next()) {
 58                 Goods good=new Goods(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getInt(5),rs.getInt(6),rs.getString(7));
 59                 list.add(good);
 60             }
 61         } catch (SQLException e) {
 62             e.printStackTrace();
 63         }
 64         return list;
 65     }
 66     /**
 67      * 增加一条商品信息
 68      * @param g
 69      * @return
 70      */
 71     public int insertGoods(Goods g) {
 72         String sql = "insert into GOODS_TABLE values(tablexulie.nextval,?,?,?,?,?,?)";
 73 
 74         init(sql);
 75         int a = -1;
 76         try {
 77             ps.setString(1, g.getGname());
 78             ps.setString(2, g.getGdetails());
 79             ps.setString(3, g.getGpicture());
 80             ps.setInt(4, g.getGprice());
 81             ps.setInt(5, g.getGleixing());
 82             ps.setString(6, g.getGpinpai());
 83             a = ps.executeUpdate();
 84         } catch (SQLException e) {
 85             e.printStackTrace();
 86         }
 87         return a;
 88     }
 89     /**
 90      * 删除商品信息
 91      */
 92     public int deleteGoods(int gid) {
 93         String sql = "delete from GOODS_TABLE g where g.gid=? ";
 94 
 95         init(sql);
 96         int a = -1;
 97         try {
 98             ps.setInt(1, gid);
 99             a = ps.executeUpdate();
100         } catch (SQLException e) {
101             e.printStackTrace();
102         }
103         return a;
104     }
105     //修改商品信息
106     public int UpdateGood(Goods g) {
107         String sql = "update GOODS_TABLE g set g.gname=?,g.gdetails=?,g.gpicture=?,g.gprice=?,g.gleixing=?,g.gpinpai=? where g.gid=?";
108         init(sql);
109         int a = -1;
110         try {
111             ps.setString(1, g.getGname());
112             ps.setString(2, g.getGdetails());
113             ps.setString(3, g.getGpicture());
114             ps.setInt(4, g.getGprice());
115             ps.setInt(5, g.getGleixing());
116             ps.setString(6, g.getGpinpai());
117             ps.setInt(7, g.getGid());
118             a = ps.executeUpdate();
119         } catch (SQLException e) {
120             e.printStackTrace();
121         }
122         return a;
123     }
124     public int UpdateGoodNP(Goods g) {
125         String sql = "update GOODS_TABLE g set g.gname=?,g.gdetails=?,g.gprice=?,g.gleixing=?,g.gpinpai=? where g.gid=?";
126         init(sql);
127         int a = -1;
128         try {
129             ps.setString(1, g.getGname());
130             ps.setString(2, g.getGdetails());
131             ps.setInt(3, g.getGprice());
132             ps.setInt(4, g.getGleixing());
133             ps.setString(5, g.getGpinpai());
134             ps.setInt(6, g.getGid());
135             
136             a = ps.executeUpdate();
137         } catch (SQLException e) {
138             e.printStackTrace();
139         }
140         return a;
141     }
142     
143     //获取数量
144     public int getGoodsSum(String scuser) {
145         String sql = "select s.scnum from SHOPPINGCAR s  where s.scuser=?";
146         int sum=0;
147         init(sql);
148         
149         try {
150             ps.setString(1, scuser);
151             rs = ps.executeQuery();
152             
153             while (rs.next()) {
154                 sum+=rs.getInt("scnum");
155             }
156         } catch (SQLException e) {
157             e.printStackTrace();
158         }
159         return sum;
160     }
161             
162     public Goods getGoods(String gid) {
163         String sql = "select * from GOODS_TABLE g where g.gid="+gid;
164         init(sql);
165         Goods good=new Goods();
166         try {
167             rs = ps.executeQuery();
168             while (rs.next()) {
169                 good=new Goods(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getInt(5),rs.getInt(6),rs.getString(7));
170             }
171         } catch (SQLException e) {
172             e.printStackTrace();
173         }
174         return good;
175     }
176     /**
177      * 增加日志记录
178      * @param g
179      * @return
180      */
181     public int insertLog(Log l) {
182         String sql = "insert into ShopLog values(?,?,?,?,?)";
183 
184         init(sql);
185         int a = -1;
186         try {
187             ps.setString(1, l.getPname());
188             ps.setString(2, l.getPugroup());
189             ps.setString(3, l.getPuptime());
190             ps.setString(4, l.getPip());
191             ps.setString(5, l.getPlog());
192             a = ps.executeUpdate();
193         } catch (SQLException e) {
194             e.printStackTrace();
195         }
196         return a;
197     }
198     /**
199      * 返回所有日志
200      * @return
201      */
202     public List<Log> getAllLogs(){
203         String sql = "select * from ShopLog s order by s.puptime desc";
204         init(sql);
205         List<Log> list = new ArrayList<Log>();
206         
207         try {
208             rs = ps.executeQuery();
209             while (rs.next()) {
210                 Log l=new Log();
211                 l.setPname(rs.getString(1));
212                 l.setPugroup(rs.getString(2));
213                 l.setPuptime(rs.getString(3));
214                 l.setPip(rs.getString(4));
215                 l.setPlog(rs.getString(5));
216                 
217                 list.add(l);
218             }
219         } catch (SQLException e) {
220             e.printStackTrace();
221         }
222         return list;
223     }
224     /**
225      * 返回购物车数据
226      * @return
227      */
228     public List<Order> getAllOrder(String username){
229         String sql = "select t.*  from SHOPPINGCAR t where t.scuser=?";
230         init(sql);
231         List<Order> list = new ArrayList<Order>();
232         
233         try {
234             ps.setString(1, username);
235             rs = ps.executeQuery();
236             while (rs.next()) {
237                 Order l=new Order();
238 
239                 l.setScid(rs.getString(1));
240                 l.setScuser(rs.getString(4));
241                 l.setScgid(rs.getString(5));
242                 l.setScnum(rs.getInt(3));
243                 l.setSctime((new Date()).toLocaleString());
244                 
245                 list.add(l);
246             }
247         } catch (SQLException e) {
248             e.printStackTrace();
249         }
250         return list;
251     }
252     /**
253      * 删除购物车已经提交的信息
254      */
255     public int deleteSCar(String username) {
256         String sql = "delete from SHOPPINGCAR g where g.scuser=? ";
257 
258         init(sql);
259         int a = -1;
260         try {
261             ps.setString(1, username);
262             a = ps.executeUpdate();
263         } catch (SQLException e) {
264             e.printStackTrace();
265         }
266         return a;
267     }
268     /**
269      * 增加订单记录
270      * @param g
271      * @return
272      */
273     public int insertOrder(Order l) {
274         String sql = "insert into SHOPORDER values(?,?,?,?,?,?,?)";
275 
276         init(sql);
277         int a = -1;
278         try {
279             ps.setString(1, l.getScid());
280             ps.setString(2, l.getScuser());
281             ps.setString(3, l.getScgid());
282             ps.setInt(4, l.getScnum());
283             ps.setInt(5, l.getScmoney());
284             ps.setString(6, l.getSctime());
285             ps.setString(7, l.getSczt());
286             a = ps.executeUpdate();
287         } catch (SQLException e) {
288             e.printStackTrace();
289         }
290         return a;
291     }
292     /**
293      * 返回未确认订单
294      * @return
295      */
296     public List<Order> getAllOrder(){
297         String sql = "select t.* from SHOPORDER t  where t.sczt=‘待确认‘ order by t.sctime desc";
298         init(sql);
299         List<Order> list = new ArrayList<Order>();
300         
301         try {
302             rs = ps.executeQuery();
303             while (rs.next()) {
304                 Order l=new Order();
305                 l.setScid(rs.getString(1));
306                 l.setScuser(rs.getString(2));
307                 l.setScgid(rs.getString(3));
308                 l.setScnum(rs.getInt(4));
309                 l.setScmoney(rs.getInt(5));
310                 l.setSctime(rs.getString(6));
311                 l.setSczt(rs.getString(7));
312                 list.add(l);
313             }
314         } catch (SQLException e) {
315             e.printStackTrace();
316         }
317         return list;
318     }
319     /**
320      * 返回确认订单
321      * @return
322      */
323     public List<Order> getAllOrder1(){
324         String sql = "select t.* from SHOPORDER t  where t.sczt=‘已确认‘ order by t.sctime desc";
325         init(sql);
326         List<Order> list = new ArrayList<Order>();
327         
328         try {
329             rs = ps.executeQuery();
330             while (rs.next()) {
331                 Order l=new Order();
332                 l.setScid(rs.getString(1));
333                 l.setScuser(rs.getString(2));
334                 l.setScgid(rs.getString(3));
335                 l.setScnum(rs.getInt(4));
336                 l.setScmoney(rs.getInt(5));
337                 l.setSctime(rs.getString(6));
338                 l.setSczt(rs.getString(7));
339                 list.add(l);
340             }
341         } catch (SQLException e) {
342             e.printStackTrace();
343         }
344         return list;
345     }
346     /**
347      * 修改订单状态
348      * @return
349      */
350     public void UpdateOrder(String sctime){
351         String sql = "update SHOPORDER s set s.sczt=‘已确认‘ where s.sctime=?";
352         init(sql);
353         try {
354             ps.setString(1, sctime);
355             ps.executeQuery();
356             
357         } catch (SQLException e) {
358             e.printStackTrace();
359         }
360     }
361     /**
362      * 返回用户信息
363      * @return
364      */
365     public List<User> getAllUsers(){
366         String sql = "select t.*, t.rowid from USER_TABLE t order by t.utime desc";
367         init(sql);
368         List<User> list = new ArrayList<User>();
369         
370         try {
371             rs = ps.executeQuery();
372             while (rs.next()) {
373                 User l=new User();
374 
375                 l.setUserid(rs.getInt(1));
376                 l.setUname(rs.getString(2));
377                 l.setUpassword(rs.getString(3));
378                 l.setUnickname(rs.getString(4));
379                 l.setUemail(rs.getString(5));
380                 l.setUtime(rs.getString(6));
381                 list.add(l);
382             }
383         } catch (SQLException e) {
384             e.printStackTrace();
385         }
386         return list;
387     }
388     
389 }

 

商城项目回顾整理(二)easyUi数据表格使用

标签:char   layout   post   reset   tty   splay   selection   输入   style   

原文地址:http://www.cnblogs.com/jiangwz/p/7543932.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!