<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<%@ page import="com.bjsxt.drp.util.*" %>
<%@ page import="com.bjsxt.drp.basedata.domain.*" %>
<%@page import="com.bjsxt.drp.util.datadict.domain.ClientLevel"%>
<%@page import="com.bjsxt.drp.basedata.manager.ClientManager"%>
<%@page import="com.bjsxt.drp.util.datadict.manager.*"%>
<%@page import="java.util.*"%>
<%
//ajax 发起请求
request.setCharacterEncoding("GBK");
int pid = Integer.parseInt(request.getParameter("pid"));
List<ClientLevel> clientLevelList = DataDictManager.getInstance().getClientLevelList();
if(Constant.COMMAND_ADD.equals(request.getParameter("command"))) {
//out.println(request.getParameter("clientName"));
Client client = new Client();
client.setClientId(request.getParameter("clientId"));
client.setName(request.getParameter("clientName"));
client.setBankAcctNo(request.getParameter("bankAcctNo"));
client.setContactTel(request.getParameter("contactTel"));
client.setAddress(request.getParameter("address"));
client.setZipCode(request.getParameter("zipCode"));
ClientLevel clientLevel = new ClientLevel();
String clientLevelId = request.getParameter("clientLevel");
clientLevel.setId(clientLevelId);
client.setClientLevel(clientLevel);
ClientManager.getInstance().addClient(client, pid);
out.println("添加分销商成功!");
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>添加分销商</title>
<link rel="stylesheet" href="../style/drp.css">
<script src="../script/client_validate.js"></script>
<script type="text/javascript">
function addClient() {
if(trim(document.getElementById("clientId").value).length == 0) {
document.getElementById("spanClientId").innerHTML = "<font color='red'>请输入分销商代码!</font>";
document.getElementById("clientId").focus();
return;
}
if(trim(document.getElementById("clientName").value).length == 0) {
document.getElementById("spanClientName").innerHTML = "<font color='red'>请输入分销商名称!</font>";
document.getElementById("clientName").focus();
return;
}
with(document.getElementById("form1")) {
action = "client_add.jsp?pid=<%=pid%>";
method = "post";
submit();
}
}
function clientIdValidate(field) {
var xmlHttpReq;
if(window.ActiveXObject) {
xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
} else {
xmlHttpReq = new XMLHttpRequest();
}
var url = "../servlet/ClientIdValidateServlet?clientId=" + trim(field.value) + "&time=" + new Date().getTime();
xmlHttpReq.open("get", url);
xmlHttpReq.send();
xmlHttpReq.onreadystatechange = function() {
if(xmlHttpReq.readyState == 4) {
if(xmlHttpReq.status == 200) {
document.getElementById("spanClientId").innerHTML = "<font color='red'>" + xmlHttpReq.responseText + "</font>";
} else {
alert("请求失败!错误码:" + xmlHttpReq.status);
}
}
};
}
function init() {
document.getElementById("clientId").focus();
}
</script>
</head>
<body class="body1" οnlοad="init()">
<form name="form1">
<input type="hidden" name="command" value="<%= Constant.COMMAND_ADD %>"/>
<div align="center">
<table width="95%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td>
</td>
</tr>
</table>
<table width="95%" border="0" cellspacing="0" cellpadding="0"
height="8">
<tr>
<td width="522" class="p1" height="2" nowrap>
<img src="../images/mark_arrow_03.gif" width="14" height="14">
<b>基础数据管理>>分销商维护>>添加分销商</b>
</td>
</tr>
</table>
<hr width="97%" align="center" size=0>
<table width="95%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="22%" height="29">
<div align="right">
<font color="#FF0000">*</font>分销商代码:
</div>
</td>
<td width="78%">
<input name="clientId" type="text" class="text1" id="clientId"
size="10" maxlength="10" οnblur="clientIdValidate(this)">
<span id="spanClientId"></span>
</td>
</tr>
<tr>
<td height="26">
<div align="right">
<font color="#FF0000">*</font>分销商名称:
</div>
</td>
<td>
<input name="clientName" type="text" class="text1"
id="clientName" size="40" maxlength="40">
<span id="spanClientName"></span>
</td>
</tr>
<tr>
<td height="15">
<div align="right">
<font color="#FF0000">*</font>分销商类型:
</div>
</td>
<td>
<select name="clientLevel" class="select1" id="clientLevel">
<%
for(Iterator<ClientLevel> iter = clientLevelList.iterator(); iter.hasNext();) {
ClientLevel cl = iter.next();
%>
<option value="<%=cl.getId() %>">
<%=cl.getName() %>
</option>
<%
}
%>
</select>
</td>
</tr>
<tr>
<td height="26">
<div align="right">
银行帐号:
</div>
</td>
<td>
<input name="bankAcctNo" type="text" class="text1"
id="bankAcctNo" size="10" maxlength="10">
</td>
</tr>
<tr>
<td height="26">
<div align="right">
联系电话:
</div>
</td>
<td>
<input name="contactTel" type="text" class="text1"
id="contactTel" size="10" maxlength="10">
</td>
</tr>
<tr>
<td height="26">
<div align="right">
地址:
</div>
</td>
<td>
<input name="address" type="text" class="text1" id="address"
size="10" maxlength="10">
</td>
</tr>
<tr>
<td height="26">
<div align="right">
邮编:
</div>
</td>
<td>
<input name="zipCode" type="text" class="text1" id="zipCode"
size="10" maxlength="10">
</td>
</tr>
</table>
<hr width="97%" align="center" size=0>
<div align="center">
<input name="btnAdd" class="button1" type="button" id="btnAdd"
value="添加" onClick="addClient()">
<input name="btnBack" class="button1" type="button" id="btnBack"
value="返回" οnclick="history.go(-1)" />
</div>
</div>
</form>
</body>
</html>
package com.bjsxt.drp.util.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.bjsxt.drp.basedata.manager.ClientManager;
public class ClientIdValidateServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=GBK");
String clientId = request.getParameter("clientId");
boolean flag = ClientManager.getInstance().findClientId(clientId);
if(flag) {
response.getWriter().print("分销商代码已存在");
}
}
@Override
public void init() throws ServletException {
}
}