addhw.jsp
上传用户:helenhuo66
上传日期:2007-06-01
资源大小:865k
文件大小:12k
源码类别:

百货/超市行业

开发平台:

Java

  1. <%@ page contentType="text/html;charset=GBK" language="java" import="java.sql.*,java.util.Date" errorPage="" %>
  2. <%@ include file="conn.jsp"%>
  3. <%!
  4. String encode(String str)
  5.  {
  6.     String result;
  7.     int l;
  8.     if(str=="")
  9. {
  10.        result="";
  11. }
  12.     else
  13.     {
  14.     l=str.length();
  15. char[] chr=new char[l];
  16. str.getChars(0,l,chr,0);
  17.     result="";
  18. int i;
  19. for(i=0;i<=l-1;i++)
  20.   {
  21.     
  22.                switch(chr[i])
  23.     {
  24.     
  25.            case '<':
  26.                 result=result+"&lt;";
  27. break;
  28.            case '>':
  29.                 result=result+"&gt;";
  30.    break;
  31.               case 10:
  32.                 result=result+"<br>";
  33.   break;
  34.   case 13:
  35.                 result=result+"<br>";
  36.   break;
  37.            case 34:
  38.                 result=result+"&quot;";
  39.    break;
  40.            case '&':
  41.                 result=result+"&amp;";
  42.    break;
  43.               case ' ':
  44.         result=result+"&nbsp;";
  45.   break;
  46.                
  47.           case 9:
  48.                 result=result+"    ";
  49.    break;
  50.            default:
  51.                 result=result+String.valueOf(chr[i]);
  52. }
  53.   } 
  54. }
  55.     return result;
  56.   }
  57.  
  58. %>
  59. <html>
  60. <head>
  61. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  62. <link href=../css.css rel=STYLESHEET type=text/css>
  63. </head>
  64. <%
  65. if(request.getParameter("action")!=null)
  66.  {//-----------------------------------action=save-----------------------------------------------------
  67.    if(request.getParameter("action").equals("save"))
  68.    {
  69.         String hw_name=request.getParameter("hw_name");
  70.     String hw_content=encode(request.getParameter("hw_content"));
  71. String hw_content2=encode(request.getParameter("hw_content2"));
  72.     String hw_cashs=request.getParameter("hw_cash");
  73.     String hw_pic=request.getParameter("hw_pic");
  74. String chubsh=request.getParameter("chubsh");
  75. String zhuang=request.getParameter("zhuang");
  76. String yeshu=request.getParameter("yeshu");
  77.  String isbn=request.getParameter("isbn");
  78.     String sort_ids=request.getParameter("sort_id");
  79.   String Nsort_ids=request.getParameter("Nsort_id");
  80.     String company=request.getParameter("company");
  81.    String pifas=request.getParameter("pifa");
  82. String dailis=request.getParameter("daili");
  83. String hwsn=request.getParameter("hwsn");
  84. String data=request.getParameter("data");
  85.   data=data.trim();
  86.   Date datas=new Date();
  87. String kaiben=request.getParameter("kaiben");
  88. String tuijian=request.getParameter("tuijian");
  89. String jia=request.getParameter("jia");
  90. String errmsg="输入有错!";
  91. boolean founderr=false;
  92.     if(Cint(hw_cashs)==0)
  93. {
  94.         errmsg="<br>"+"<li>价格应该为数字";
  95.         founderr=true;
  96.     }
  97.     if(hw_name=="")
  98. {
  99.         errmsg=errmsg+"<br>"+"<li>名称不能为空";
  100.         founderr=true;
  101.     }
  102.     if(hw_content=="")
  103. {
  104.         errmsg=errmsg+"<Br>"+"<li>介绍不能为空";
  105.         founderr=true;
  106.     }
  107.     if(sort_ids=="" )
  108. {
  109.         errmsg=errmsg+"<br>"+"<li>类别不能为空";
  110.         founderr=true;
  111.     }
  112.    
  113.       if(Nsort_ids=="") 
  114.   {
  115.         errmsg=errmsg+"<br>"+"<li>类别不能为空";
  116.         founderr=true;
  117.       }
  118.   if(data.length()!=10){
  119.     errmsg=errmsg+"<br>"+"<li>产品生产日期格式不正确";
  120.         founderr=true;
  121.   }else
  122.   {
  123.     if(data.indexOf('-')!=4||data.lastIndexOf('-')!=7){
  124.   errmsg=errmsg+"<br>"+"<li>产品生产日期格式不正确";
  125.           founderr=true;
  126. }
  127. else
  128. {
  129. int year=Cint(data.substring(0,4));
  130. int month=Cint(data.substring(5,7));
  131. int day=Cint(data.substring(8));
  132.   if(month>12||day>31||month<=0||day<=0){
  133.       errmsg=errmsg+"<br>"+"<li>产品生产日期格式不正确";
  134.              founderr=true;
  135.    }else{
  136.     datas=new Date(year-1900,month-1,day);
  137.    }
  138. }
  139.   }
  140.  if(hw_pic==""){ hw_pic="img/noimage.gif";}
  141.      if(chubsh==""|zhuang==""|yeshu==""|isbn==""|company==""|pifas==""|dailis==""|hwsn==""|data==""|kaiben==""|jia==""){
  142.    founderr=true;
  143.    }
  144.     if (founderr==true)
  145. {
  146.         out.print(errmsg);
  147.         out.print("<br>");
  148.         out.print("<a href=addhw.jsp>返回</a>");
  149.       }else
  150.  {
  151.         hw_name=getStr(hw_name);
  152.         company=getStr(company);
  153. hw_content2=encode(getStr(hw_content2));
  154.         hw_content=encode(getStr(hw_content));
  155. boolean btuijian=false,bjia=false;
  156. if(tuijian.equals("1")){ btuijian=true;}
  157. if(jia.equals("1")){ bjia=true;}
  158.         sql="insert into hw (hw_name,hw_content,hw_content2,hw_cash,sort_id,Nsort_id,company,daili,pifa,hw_sn,chubsh,kaiben,yeshu,";    
  159.         sql=sql+"data,isbn,zhuang,hw_pic,tuijian,jia)";
  160. sql=sql+"values('"+hw_name+"','"+hw_content+"','"+hw_content2+"',"+Cint(hw_cashs)+","+Cint(sort_ids)+","+Cint(Nsort_ids);
  161.         sql=sql+",'"+company+"',"+Cint(dailis)+","+Cint(pifas)+",'"+hwsn+"','"+chubsh+"','"+kaiben+"','"+yeshu+"','"+datas.toLocaleString()+"','"+isbn;
  162.         sql=sql+"','"+zhuang+"','"+hw_pic+"',"+btuijian+","+bjia+")";
  163. mdb.executeInsert(sql);
  164. out.print("货物添加成功");
  165.         out.print("<br>");
  166.         out.print("<a href=addhw.jsp>返回</a>");
  167.     
  168.     }
  169.     
  170.     
  171.   }
  172. }
  173. else{
  174. //-----------------------------------action!=save-----------------------------------------------------
  175. %>
  176. <html>
  177. <head>
  178. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  179. <meta name="GENERATOR" content="Microsoft FrontPage 6.0">
  180. <title>添 加 商 品</title>
  181. <link rel="stylesheet" type="text/css" href="style.css">
  182. <%
  183. int count=0;
  184. sql = "select * from  Nsort  order by Nsort_id asc";
  185. rs=mdb.executeQuery(sql);
  186. %>
  187. <script language = "JavaScript">
  188. var onecount;
  189. onecount=0;
  190. subcat = new Array();
  191.         <%
  192.         while(rs.next()) 
  193. {
  194.         %>
  195. subcat[<%=count%>] = new Array("<%=rs.getString("Nsort_name")%>","<%=rs.getInt("sort_id")%>","<%=rs.getInt("Nsort_id")%>");
  196.         <%
  197.         count = count + 1;
  198.         }
  199. rs.close();
  200.         %>
  201. onecount=<%=count%>;
  202. function changelocation(locationid)
  203.     {
  204.     document.myform.Nsort_id.length = 0; 
  205.     var locationid=locationid;
  206.     var i;
  207.     for (i=0;i < onecount; i++)
  208.         {
  209.             if (subcat[i][1] == locationid)
  210.             { 
  211.                 document.myform.Nsort_id.options[document.myform.Nsort_id.length] = new Option(subcat[i][0], subcat[i][2]);
  212.             }        
  213.         }
  214.         
  215.     }    
  216. </script>
  217. </head>
  218. <body>
  219. <tr>
  220.     <td>
  221.       <div align="center"><b>所有选项都必须填写</b></div>
  222.     </td>
  223.   </tr>
  224. <form method="POST" name="myform" action="addhw.jsp?action=save">
  225.   <table class="border" cellspacing="0" width="80%" border="0" cellpadding="4" cellspacing="0" >
  226.     
  227.     <tr align="center">
  228.       <td class="tdbg" width="100%">
  229. <table border="0" cellspacing="1" width="100%">
  230.         
  231.                 <td width="85%">
  232. <%       int selclass=0;
  233.         sql = "select * from sort";
  234.        rs=mdb.executeQuery(sql);
  235. if(!rs.next())
  236. {
  237.   out.print("请先添加栏目。");
  238.  }else
  239.  {
  240.  rs.previous();
  241.  if(rs.next())
  242.    {
  243.       selclass=rs.getInt("sort_id");
  244.  %>
  245. <select name="sort_id" onChange="changelocation(document.myform.sort_id.options[document.myform.sort_id.selectedIndex].value)" size="1">
  246.         <option selected value="<%=selclass%>"><%=rs.getString("sort_name")%></option>
  247. <%       
  248.            while(rs.next())
  249.   {
  250. %> <option value="<%=rs.getInt("sort_id")%>"><%=rs.getString("sort_name")%></option>
  251. <%
  252.           }
  253.    }
  254. }
  255.        rs.close();
  256. %></select> 
  257. <select name="Nsort_id">                  
  258. <%
  259. sql="select * from Nsort where sort_id="+selclass;
  260. rs=mdb.executeQuery(sql);
  261. if(rs.next())
  262. {
  263. %>
  264.         <option selected value="<%=rs.getInt("Nsort_ID")%>"><%=rs.getString("Nsort_name")%></option>
  265. <% 
  266. while(rs.next())
  267.   {%>
  268.         <option value="<%=rs.getInt("Nsort_ID")%>"><%=rs.getString("Nsort_name")%></option>
  269. <% 
  270.    }
  271. }
  272. rs.close();
  273. %>
  274. </td>
  275.   </tr>
  276. </table>
  277. <table border="0" width="500" cellspacing="1" height="392" align="left">
  278.   <tr>
  279.     <td width="100%" height="395"> 
  280.       
  281.             <table border="0" width="100%" cellspacing="1">
  282.               <tr> 
  283.                 <td colspan="2"><font color="#FF0000">型号名称</font> 
  284.                   <input type="text" name="hw_name" size="20" class=input>
  285.                   <font color="#FF0000"> &nbsp;&nbsp;&nbsp;&nbsp; </font> </td>
  286.               </tr>
  287.               <tr> 
  288.                 <td colspan="2"><font color="#FF0000">市场价</font> 
  289.                   <input type="text" name="pifa" size="7" class=input>
  290.                   元 <font color="#FF0000">&nbsp;&nbsp;&nbsp;会员价</font> 
  291.                   <input type="text" name="hw_cash" size="7" class=input>
  292.                   元 <font color="#FF0000">&nbsp;&nbsp;&nbsp;&nbsp;VIP价</font> 
  293.                   <input type="text" name="daili" size="7" class=input>
  294.                   元 </td>
  295.               </tr>
  296.               <tr> 
  297.                 <td height="5" colspan="2"> 
  298.                   <hr noshade size="1">
  299.                 </td>
  300.               </tr>
  301.               <tr> 
  302.                 <td><font color="#000000">录入</font> 
  303.                   <input type="text" name="hwsn" size="10" class=input value="不详">
  304.                 </td>
  305.                 <td width="63%"><font color="#000000">出品公司</font> 
  306.                   <input type="text" name="chubsh" size="30" class=input value="不详">
  307.                 </td>
  308.               </tr>
  309.               <tr> 
  310.                 <td><font color="#000000">尺码</font> 
  311.                   <input type="text" name="kaiben" size="10" class=input value="16">
  312.                 </td>
  313.                 <td width="63%"><font color="#000000">出品日期</font> 
  314.                   <input type="text" name="data" size="24" class=input value="2002-10-10">
  315.                   格式:2002-01-01</td>
  316.               </tr>
  317.               <tr> 
  318.                 <td><font color="#000000">颜色</font> 
  319.                   <input type="text" name="yeshu" size="10" class=input value="100">
  320.                 </td>
  321.                 <td width="63%"><font color="#000000">编号</font> 
  322.                   <input type="text" name="isbn" size="30" class=input value="不详">
  323.                 </td>
  324.               </tr>
  325.               <tr> 
  326.                 <td height="5" colspan="2"> 
  327.                   <hr noshade size="1">
  328.                 </td>
  329.               </tr>
  330.               <tr> 
  331.                 <td colspan="2"> <font color="#000000">包装类型</font> 
  332.                   <input type="text" name="zhuang" size="30" class=input value="普通">
  333.                 </td>
  334.               </tr>
  335.               <tr> 
  336.                 <td colspan="2"> <font color="#FF0000">简单内容介绍</font></td>
  337.               </tr>
  338.               <tr> 
  339.                 <td valign="top" colspan="2"> 
  340.                   <textarea rows="3" name="hw_content" cols="50" class=input>暂时没有……</textarea>
  341.                 </td>
  342.               </tr>
  343.               <tr>
  344.                 <td valign="top" colspan="2"><font color="#FF0000">详细内容介绍</font></td>
  345.               </tr>
  346.               <tr>
  347.                 <td valign="top" colspan="2">
  348.                   <textarea rows="10" name="hw_content2" cols="50" class=input>暂时没有……</textarea>
  349.                 </td>
  350.               </tr>
  351.               <tr> 
  352.                 <td colspan="2"> <font color="#FF0000">商品图片</font> 
  353.                   <input type="text" name="hw_pic" size="46" class=input value="pic/"> <a href="up.jsp" target="_blank">上传图片</a></td>
  354.               </tr>
  355.             </table>
  356.             <table width="372" border="0" cellspacing="0" cellpadding="0" height="24">
  357.               <tr>
  358.                 <td>推荐此商品
  359.                   <input type="radio" name="tuijian" value="1">
  360.                   不推荐 
  361.                   <input type="radio" name="tuijian" value="0" checked>
  362.                   <br>
  363.                   否特价 
  364.                   <input name="jia" type="radio" value="0" checked>
  365.                   &nbsp;&nbsp; 是特价
  366.                   <input type="radio" name="jia" value="1"> 
  367.                 </td>
  368.               </tr>
  369.             </table>
  370.             <p>
  371.               <input type="submit" value="提交" name="B1" class=input>
  372.               <input type="reset" value="全部重写" name="B2" class=input>
  373.             </p>
  374.     
  375.       
  376.     </td>
  377.   </tr>
  378. </table>
  379. </form>
  380. </body>
  381. </html>
  382. <%}
  383. //--------------------------------------end action check----------------------------------------------
  384. %>