<%@ page language="java" import="com.crm.product.*,java.util.regex.*" pageEncoding="GBK"%>
<%@ page import="java.util.*,java.sql.Date"%><%@include file="_SessionCheck.jsp"%><%
List<Stock> stocks = Stock.getStocks2();
%>
<%
request.setCharacterEncoding("GBK"); String action = request.getParameter("action");
String Regexp = request.getParameter("Regexp");
String Regexp0 = request.getParameter("Regexp0"); if (action != null && action.trim().equals("add")) {
String strId = request.getParameter("id");
String[] str = strId.split(",");
int id = Integer.parseInt(str[2]);
String productname = request.getParameter("productname");
String model = request.getParameter("model");
String color = request.getParameter("color");
String price = request.getParameter("price");
String pdate = request.getParameter("pdate");
Pattern pattern = Pattern.compile("[0-9]*" );
Matcher matcher= pattern.matcher(price);
if(productname == "" ||color=="" || price=="" || pdate == ""){
String validate0="*Please complete all information";
response.sendRedirect("ProductAdd.jsp?Regexp0="+validate0);

}else if(matcher.matches()==false ){
String validate="*  Format Error!";
response.sendRedirect("ProductAdd.jsp?Regexp="+validate);
}else{

Product p = new Product();
p.setId(id);
p.setProductname(productname);
p.setModel(model);
p.setColor(color);
p.setPrice(price);
p.setPdate(pdate);
p.add(p);
response.sendRedirect("ProductList.jsp");
}
}
%>
<html>
<head>
<title>添加产品</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" href="script/style1.css" type="text/css">
<script type="text/javascript">
    function change(p) {
var product = p.value;
var products = new Array();
products = product.split(",");
var name = document.getElementById("productname");
var pcount = document.getElementById("pcount");
name.value = products[0];
pcount.value = products[1];
 }
       </script>
</head>
<body leftmargin="0" rightmargin="0" topmargin="0">
<br>
<br>
<table style="table-layout: fixed;" align="center" border="0"
cellpadding="0" cellspacing="0" width="97%">
<tbody>
<tr>
<td class="nav" align="left" nowrap="nowrap" width="90%">
&nbsp;客户关系管理系统 &raquo;
<br>
</td> </tr>
</tbody>
</table>
<br>
<form method="post" name="register" action="ProductAdd.jsp"
onSubmit="this.regsubmit.disabled=false;">
<input type="hidden" name="action" value="add" /> <table class="tableborder" align="center" cellpadding="4"
cellspacing="1" width="97%">
<tbody>
<tr>
<td colspan="2" class="header">
添加产品- 必填内容
</td>
</tr>
<tr>
<td class="altbg1" valign="top">
产品编号:
</td>
<td class="altbg2"> <select name="id" onchange="change(this);">
<%
for (int i = 0; i < stocks.size(); i++) {
Stock s = stocks.get(i);
%>
<option
value="<%=s.getProductname()%>,<%=s.getStock_volume()%>,<%=s.getId()%>">
<%=s.getId()%>
</option>
<%
}
%>
</select>
</td> </tr>
<tr>
<td class="altbg1" valign="top">
产品名称:
</td>
<td class="altbg2">
<input id="productname" name="productname" size="25"
maxlength="25" type="text" value="">
</td>
</tr> <tr>
<td class="altbg1" valign="top">
产品型号:
</td>
<td class="altbg2">
<input name="model" size="25" maxlength="25" type="text" value="">
</td>
</tr>
<tr>
<td class="altbg1" valign="top">
产品颜色:
</td>
<td class="altbg2">
<input name="color" size="25" maxlength="25" type="text" value="">
</td>
</tr>
<tr>
<td class="altbg1" valign="top">
产品单价:
</td>
<td class="altbg2">
<input name="price" size="25" maxlength="25" type="text" value=""><font color="red"><%=Regexp %></font>
</td>
</tr>
<tr>
<td class="altbg1" valign="top">
生产日期:
</td>
<td class="altbg2">
<input name="pdate" size="25" maxlength="25" type="text" value="">
</td>
</tr>
</tbody>
</table>
<br>
<center>
<input name="regsubmit" value="提 &nbsp; 交" type="submit"><font color="red"><%=Regexp0%></font>
</center>
</form>
</body>
</html>