<%@ page language="java"
	import="java.sql.*,java.io.*,javax.servlet.*,javax.servlet.http.*,java.text.SimpleDateFormat,
	java.util.Date,java.text.NumberFormat,java.util.Locale;"
	pageEncoding="gb2312"%>
<%
Object userName=session.getAttribute("UserName");
if(userName==null||userName.toString().length()<=0){
	response.sendRedirect("login.jsp?tz=true");
}
//删除
String id=request.getParameter("ID");
if(id!=null&&id.length()>0){
	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//载入驱动程序类别
	String strUrl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="
		+ this.getServletContext().getRealPath("demodata/") + "\\demo.mdb";
	Connection conn = DriverManager.getConnection(strUrl);
	Statement stmt = conn.createStatement();
	int result=stmt.executeUpdate("delete from OrderMaster where ID="+id);
	if(result>0){
		result=stmt.executeUpdate("delete from OrderDetail where OrderID="+id);
		response.getWriter().write("<script>alert('删除成功！');location.href='OrderList.jsp'</script>");
	}else{
		response.getWriter().write("<script>alert('删除失败！');</script>");
	}
} 
 %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <link rel="stylesheet" href="css/style.css" type="text/css"></link>
    <!--[if lte IE 6]>
<script type="text/javascript" src="js/belatedPNG.js"></script>
<script type="text/javascript">
  DD_belatedPNG.fix('.png_bg,.png_bg a:hover,img,li');
</script>
<![endif]-->
    <title>登录列表</title>

    <script type="text/javascript">
        function Delete(id) {
            if (confirm("你确认要删除该客户信息及其相关订单信息吗？")) {
                location.href = "OrderList.jsp?ID=" + id;
                return true;
            }
            else {
                return false;
            }
        }
    </script>

</head>
<body>
    <!--header-->
    <div class="zz-headBox clearfix">
        <div class="zz-head mc">
            <!--logo-->
            <div class="logo fl">
                <a href="home.html">
                    <img src="images/logo.png" alt="" /></a></div>
            <!--logo end-->
            <ul class="head-rightUl fr">
                <li><a href="http://www.zhuozhengsoft.com" target="_blank">卓正网站</a></li>
                <li><a href="http://www.zhuozhengsoft.com/poask/index.asp" target="_blank">客户问吧</a></li>
                <li class="bor-0"><a href="http://www.zhuozhengsoft.com/contact-us.html" target="_blank">联系我们</a></li>
            </ul>
        </div>
    </div>
    <!--header end-->
    <!--a title-->
    <div class=" topTitle">
        <ul>
            <li class="pd-left">销售订单管理系统示例</li>
            <li><font>当前用户：</font><%= userName%></li>
            <li><font>当前系统日期：</font><%=new SimpleDateFormat("yyyy/MM/dd").format(new Date()) %></li>
            <li><font>当前模块：</font>订单列表</li>
        </ul>
    </div>
    <!--content-->
    <div class="zz-content mc clearfix pd-28">
        <!--left-->
        <div class="zz-contentLeft fl">
            <ul class="left-ul">
                <h2 class="fs-12">
                    用户功能区</h2>
                <li style="background: #d0eaf7; display: block;"><a href="OrderList.jsp">订单列表</a></li>
                <li><a href="NewOrder.jsp">新建订单</a></li>
                <li><a href="OrderStat.jsp">统计图表</a></li>
                <li><a href="OrderStat2.jsp">查询表</a></li>
                <li class="bo-n"><a href="logout.jsp">退出系统</a></li>
            </ul>
        </div>
        <div class="zz-contentRight fl">
            <!--表格内容-->
            <table class="zz-talbe">
                <thead>
                    <tr>
                        <th class="text-cent" style="width: 15%">
                            订单编号
                        </th>
                        <th class="text-cent" style="width: 11%">
                            日期
                        </th>
                        <th class="text-cent">
                            客户名称
                        </th>
                        <th class="text-cent" style="width: 9%">
                            业务员
                        </th>
                        <th class="text-cent" style="width: 12%">
                            订单金额
                        </th>
                        <th class="text-cent" style="width: 26%">
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody>
                <tr>
                <%
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//载入驱动程序类别
				String strUrl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="
					+ this.getServletContext().getRealPath("demodata/") + "\\demo.mdb";
				Connection conn = DriverManager.getConnection(strUrl);
				Statement stmt = conn.createStatement();
				ResultSet rs=stmt.executeQuery("select * from OrderMaster order by id desc");
				while(rs.next()){	
				%>				
                <td><%=rs.getString("OrderNum") %></td>
                <%
                String date=rs.getString("OrderDate");
                	if (date != null && date.length() > 0)
                {
                //设置日期格式
                %>
                    <td><%= new SimpleDateFormat("yyyy/MM/dd")
								.format(new SimpleDateFormat("yyyy-MM-dd")
										.parse(date))%></td>
                <%
                }
                else
                {
                %>
                    <td>&nbsp;</td>
                <%
                }
                %>
                <td><%=rs.getString("CustName") %></td>
                <td><%=rs.getString("SalesName") %></td>
                <%
                 String amount=rs.getString("Amount");
                 if(amount != null && amount.length() > 0){
                 NumberFormat formater = NumberFormat.getCurrencyInstance(Locale.CHINA);
                 %>
                 	<td><%=formater.format(Double.parseDouble(amount)) %></td>
				<%
				}else{
				%>
				<td>&nbsp;</td>
				<%
				}
                %>
                <td>
                <div class='ul-page'>
                <%
                String mid=rs.getString("ID");
                 %>
                <a href="OpenOrder.jsp?ID=<%=mid %>">修改</a>|<a href="ViewOrder.jsp?ID=<%=mid %>">只读查看^打印</a>|<a  onclick="Delete(<%=mid %>)" >删除</a>
                </div>
                </td>
  
                 </tr>
                 <%
                }
                rs.close();
                stmt.close();
                conn.close();
                 %>
                </tbody>
            </table>
        </div>
        <!--内容区-->
    </div>
    <!--content end-->
    <!--footer-->
    <div class="login-footer clearfix">
        Copyright copy 2012 北京卓正志远软件有限公司</div>
    <!--footer end-->
</body>
</html>
