+ -
当前位置:首页 → 问答吧 → 散尽276分,求一段asp+sql 自动完成功能。真诚感谢大家的帮助!

散尽276分,求一段asp+sql 自动完成功能。真诚感谢大家的帮助!

时间:2010-10-12

来源:互联网

散尽276分,求一段asp+sql 自动完成功能。真诚感谢大家的帮助!
管理员请不要再删我的贴了,我真的需要这个功能。谢谢~!
自动完成的功能(自动完成)应该很多人都知道。类似于百度首页输入的时候 自动完成的功能。
具体要求如下:
1、 当录入客户名称的时候 根据数据库的记录 能够自动完成。带有模糊的功能(而不是从第一个字开始),比如数据库里面有一个客户名称为“海南陈老板”,那么当录入“海南”的时候 就开始自动完成“海南陈老板”等,包含有“海南”这两个字的记录,供录入员选择,或者录入中间的字符 “陈”,也可以出现“海南陈老板”等记录供录入员选择。
2、 还要带有联动功能:联动菜单,很多人都知道,不过网上大多都是下拉单选择的类型。当数据量非常大的时候就根本都不能用了。这里要求联动,并且用自动完成的形式来实现。比如当输入客户名称“海南陈老板”然后到输入电话的时候根据数据库中的记录,自动完成“海南陈老板”的电话。(最好当光标移动到“电话”文本框的时候,根据客户名称自动列出客户的电话号码,而不是等录入部分信息的时候才自动完成。)
3、 跟上面的要求一样,当录入产品名称的时候,根据数据库记录,自动完成 产品名称的内容,当输入规格的时候,联动+自动完成 这个产品名称 的规格(最好在还没有录入的时候就自动列出该产品的规格,),再然后是自动完成 “单位”,最后,如果这位顾客购买过这个产品,那么就自动完成价格。
4、 最后真心感谢每一位帮助我的人。



数据库及代码如下:

客户表(Customers)
Userid 客户id
Company 公司名称
Lianxiren 联系人
Sheng 省份
Shi 市
Zhen 镇
Dizhi 地址
Youbian 邮编
Tel 电话
Tel2 电话
Tel3 电话
Beizhu beizhu



仓库表(cangku) 
Id 产品 id
Chanpinname 产品名称
Guie 产品规格
Danwei 单位
Shuliang 数量
Danjia 单价
Zonger 总额
Beizhu 备注


销售记录的表(chuhuo)
Id
Chuhuodan 出货单号
Userid 客户的id
Company 客户名称
Tel 电话
Chanpinid 产品id
Chanpinname 产品名称
Guige 规格
Danwei 单位
Danjia 单价
Shuliang 数量
Zonger 总额
Chuhuodate 出货日期
Beizhu 备注



网页主体代码如下


Xiaoshou.asp


<!--#include file="../Conn3.asp"-->

<html>
<head>
<title>管理中心</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK href="../Image/style.css" type=text/css rel=stylesheet>
<script language="JavaScript" src="../Image/js.js"></SCRIPT>
</head>


<% 
if Session("ManageName")="" then
  response.write "<script language='javascript'>"
  response.write "alert('用户超时,请重新登录!!!');"
  response.write "history.go(-1);"
  response.write "</script>"
  response.end
end if

company=request("company")
sdate=request("sdate")
if sdate="" then
sdate=date()
end if
tel=request("tel")
chuhuodan=request("chuhuodan")


%>
<table width="98%" border="0" align=center cellpadding="6" cellspacing="1" class="tableBorder" id="form1">
  <form onSubmit="return checkxiaoshou()" action="savexiaoshou.asp" method=post id=form1 name=form1 >
  <tr bgcolor=ffffff>
  <th height=25 colspan="6" align="center">销售录入</th>
  </tr>
  <tr bgcolor=ffffff>
  <td colspan="6" class=forumrow><label></label></td>
  </tr>
   
  <tr bgcolor=ffffff>
  <td colspan="6" class=forumrow>出货日期&nbsp;
   
  <input name="sdate" type="text" id="sdate" value=<%=sdate%>>
   
  &nbsp;&nbsp;销售单号 &nbsp;
  <input name="chuhuodan" type="text" id="chuhuodan" value=<%=chuhuodan%>>
  &nbsp;&nbsp;
  客户名称
  &nbsp;
  <input name="company" type="text" id="company" value=<%=company%>>
  &nbsp;&nbsp;联系电话&nbsp;
  <input name="tel" type="text" id="tel" value=<%=tel%>>
  </label></td>
  </tr>
<tr bgcolor=ffffff>
<td width="25%" align="center" class=forumrow>产品名称 </td>
  <td width="15%" align="center" class=forumrow>规格</td>
  <td width="15%" align="center" class=forumrow>单位</td>
  <td width="20%" align="center" class=forumrow>数量</td>
  <td width="20%" align="center" class=forumrow>单价</td>
  <td width="20%" align="center" class=forumrow>备注</td>
</tr>
<tr bgcolor=ffffff>
  <td align="center" class=forumrow><label>
  <input name="chanpinname" type="text" id="chanpinname" size="20" > 
  </label></td>
<td align="center" class=forumrow><input name="guige" type="text" id="guige" size="15"></td>
<td align="center" class=forumrow><label>
  <input name="danwei" type="text" id="danwei">
  </label></td>
<td align="center" class=forumrow><label>
<input name="shuliang" type="text" id="shuliang" onKeypress="JHshNumberText()">
  </label></td>
<td align="center" class=forumrow><label>
<input name="danjia" type="text" id="danjia" onKeypress="JHshNumberText()">
</label></td>
<td align="center" class=forumrow><label>
  <input name="beizhu" type="text" id="beizhu">
  </label></td>
  </tr>
<tr bgcolor=ffffff>
<td colspan="6" class=forumrow>&nbsp;</td>
  </tr>
<tr bgcolor=ffffff>
  <td colspan="6" align="center" class=forumrow><label>
  <input type="submit" name="Submit" value="提交" >
  </label></td>
  </tr>
  </form>
</table>

<p>&nbsp;</p>

<% 
 
 
  set rs=server.CreateObject("adodb.recordset")
rs.open "select top 30 * from chuhuo order by id desc",conn,1,1
  if rs.eof And rs.bof then
  response.End()

  else  

%>
<table width="100%" border="1" align="center" cellspacing="0">


  <tr>
  <td width="8%" align="center">出货日期</td>
  <td width="7%" align="center">销售单</td>
  <td width="11%" align="center">客户名称</td>
  <td width="11%" align="center">产品名称</td>
  <td width="13%" align="center">规格</td>
  <td width="5%" align="center">单位</td>
  <td width="6%" align="center">数量</td>
  <td width="7%" align="center">单价</td>
  <td width="11%" align="center">总额</td>
  <td width="12%" align="center">联系电话</td>
  <td width="9%" align="center">备注</td>
  </tr>
  <% do while not rs.eof%>
  <tr onMouseOver=mouseOver(this,'999999'); onMouseOut=mouseOut(this,'#ced7f7');>
  <td align="center"> <a href="#" onClick="javascript:window.open('editxiaoshou.asp?id=<%=rs("id")%>','','scrollbars=no,resizable=no,width=600,height=600,top=100,left=400')"> 
<%=rs("chuhuodate")%></a></td>
  <td align="center"><%=rs("chuhuodan")%></td>
  <td align="center"><%=rs("company")%></td>
  <td align="center"><%=rs("chanpinname")%></td>
  <td align="center"><%=rs("guige")%></td>
  <td align="center"><%=rs("danwei")%></td>
  <td align="center"><%=rs("shuliang")%></td>
  <td align="center"><%=rs("danjia")%></td>
  <td align="center"><%=rs("zonger")%></td>
  <td align="center"><%=rs("tel")%></td>
  <td align="center"><a href=# title=<%=rs("beizhu")%>><%=left(rs("beizhu"),10)%></a> 
&nbsp;</td>
  </tr>
  <% rs.movenext
loop

rs.close
set rs=nothing %>

  <tr>
  <td align="center">&nbsp;</td>
  <td align="center">&nbsp;</td>
  <td align="center">&nbsp;</td>
  <td align="center">&nbsp;</td>
  <td align="center">&nbsp;</td>
  <td align="center">&nbsp;</td>
  <td align="center">&nbsp;</td>
  <td align="center">合计</td>
  <td align="center"><%=sum1%></td>
  <td align="center">&nbsp;</td>
  <td align="center">&nbsp;</td>
  </tr>
</table>

<%end if %>
<p>&nbsp;</p>
</html>

作者: yacity   发布时间: 2010-10-12

数据库连接
Conn3.Asp

页面如下


<%

set conn=server.createobject("adodb.connection") 
connstr="driver=sql server;server=PC2010092900MCT;database=dzqfsl;uid=sa;pwd=123456" 
conn.open connstr 

If Err Then
err.Clear
Set Conn = Nothing
Response.Write " Error......"
Response.End
End If




%>
  


js.js 页面如下

<!--Design By www.99top.com
var StarTime_S,EndTime_S
var now1 =new Date()
StarTime_S =now1.getTime()
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);}
//-->

//***********默认设置定义.*********************
tPopWait=5;//停留tWait豪秒后显示提示。
tPopShow=5000;//显示tShow豪秒后关闭提示
showPopStep=20;
popOpacity=99;

//***************内部变量定义*****************
sPop=null;
curShow=null;
tFadeOut=null;
tFadeIn=null;
tFadeWaiting=null;

document.write("<style type='text/css'id='defaultPopStyle'>");
document.write(".cPopText { background-color: #ffffff;color:#800000; border: 1px #6595D6 solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}");
document.write("</style>");
document.write("<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");

function showPopupText(){
var o=event.srcElement;
MouseX=event.x;
MouseY=event.y;
if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
  if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
if(o.dypop!=sPop) {
sPop=o.dypop;
clearTimeout(curShow);
clearTimeout(tFadeOut);
clearTimeout(tFadeIn);
clearTimeout(tFadeWaiting);
if(sPop==null || sPop=="") {
dypopLayer.innerHTML="";
dypopLayer.style.filter="Alpha()";
dypopLayer.filters.Alpha.opacity=0;
}
else {
if(o.dyclass!=null) popStyle=o.dyclass 
else popStyle="cPopText";
curShow=setTimeout("showIt()",tPopWait);
}

}
}

function showIt(){
dypopLayer.className=popStyle;
dypopLayer.innerHTML=sPop;
popWidth=dypopLayer.clientWidth;
popHeight=dypopLayer.clientHeight;
if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
else popLeftAdjust=0;
if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
else popTopAdjust=0;
dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;
dypopLayer.style.filter="Alpha(Opacity=0)";
fadeOut();
}

function fadeOut(){
if(dypopLayer.filters.Alpha.opacity<popOpacity) {
dypopLayer.filters.Alpha.opacity+=showPopStep;
tFadeOut=setTimeout("fadeOut()",1);
}
else {
dypopLayer.filters.Alpha.opacity=popOpacity;
tFadeWaiting=setTimeout("fadeIn()",tPopShow);
}
}


//表格样式

function mouseOver(obj,color){  
  obj.bgColor=color;  
  }  
   
  function mouseOut(obj,color){  
  obj.bgColor=color;  
  }  
  
function JHshNumberText()
{
if ( !(((window.event.keyCode >= 48) && (window.event.keyCode <= 57)) 
|| (window.event.keyCode == 13) || (window.event.keyCode == 46) 
|| (window.event.keyCode == 45)))
{
window.event.keyCode = 0 ;
}

}

//表格样式结束






//检测日期开始
function CheckDate(INDate){ 

if (INDate==""){return false;}

if(INDate.indexOf('-',0)!=-1){ separate="-"}

else{

  if(INDate.indexOf('/',0)!=-1){separate="/"}

  else {return true;}

  }

  area=INDate.indexOf(separate,0)

  //获取年份

  subYY=INDate.substr(0,area)

  if(isNaN(subYY) || subYY<=0){

  return true;

  }

  //转换月份

  subMM=INDate.substr(area+1,INDate.indexOf(separate,area+1)-(area+1))

  if(isNaN(subMM) || subMM<=0){

  return true;

  }

  if(subMM.length<2){subMM="0"+subMM}

  //转换日

  area=INDate.lastIndexOf(separate)

  subDD=INDate.substr(area+1,INDate.length-area-1)

  if(isNaN(subDD) || subDD<=0){

  return true;

  }

  if(eval(subDD)<10){subDD="0"+eval(subDD)}

  NewDate=subYY+"-"+subMM+"-"+subDD

  if(NewDate.length!=10){return true;}

  if(NewDate.substr(4,1)!="-"){return true;}

  if(NewDate.substr(7,1)!="-"){return true;}

  var MM=NewDate.substr(5,2);

  var DD=NewDate.substr(8,2);

  if((subYY%4==0 && subYY%100!=0)||subYY%400==0){ //判断是否为闰年

  if(parseInt(MM)==2){

  if(DD>29){return true;}

  }

  }else{

  if(parseInt(MM)==2){

  if(DD>28){return true;}

  }  

  }

  var mm=new Array(1,3,5,7,8,10,12); //判断每月中的最大天数

  for(i=0;i< mm.length;i++){

  if (parseInt(MM) == mm[i]){

  if(parseInt(DD)>31){

  return true;

  }else{

  return false;

  }

  }

  }

  if(parseInt(DD)>30){return true;}

  if(parseInt(MM)>12){return true;}

  return false;

  }






//检测销售表单 

function checkxiaoshou() {

  if (document.form1.sdate.value=="")
  {
  alert("请输入销售日期!");
  return false;
  }
  
  
  
  if(CheckDate(document.form1.sdate.value))
  {
  alert("您输入的销售日期不正确!");document.form1.sdate.focus();return false;

  }
   
  
  if (document.form1.chuhuodan.value=="")
  {
  alert("请输入销售单号!");
  return false;
  }
 
if(isNaN(document.form1.chuhuodan.value))
{
alert("销售单号不正确!");
return false;
}
 
if (document.form1.company.value=="")
  {
  alert("请输入客户名称!");
  return false;
  }
 
if (document.form1.tel.value=="")
  {
  alert("请输入客户电话!");
  return false;
  }
 
if(isNaN(document.form1.tel.value))
{
alert("电话号码格式不正确!");
return false;
}
 
 
if (document.form1.chanpinname.value=="")
  {
  alert("请输入商品名称!");
  return false;
  }
 
if (document.form1.guige.value=="")
  {
  alert("请输入规格!");
  return false;
  }
 
if (document.form1.danwei.value=="")
  {
  alert("请输入单位!");
  return false;
  }
 
if (document.form1.shuliang.value=="")
  {
  alert("请输入数量!");
  return false;
  }
 
if (document.form1.danjia.value=="")
  {
  alert("请输入单价!");
  return false;
  }
}
//检测销售表单结束




document.onmouseover=showPopupText;


//完

以下为参考资料
第一个带有模糊自动完成功能
http://www.winu.cn/space-14160-do-blog-id-27263.html

第二个不带有模糊自动完成功能

http://www.111cn.net/js_a/javascript/35405.htm

作者: yacity   发布时间: 2010-10-12