一个页面实现增删改查代码
|
源代码网整理以下<%@ page contentType="text/html; charset=gbk"%> 源代码网整理以下<title></title> document.all.mobileBrandList.rows[index].cells(0).innerHTML= getAreaOptions(areaName); document.all.mobileBrandList.rows[index].cells(1).innerHTML= getBrandOptions(brandName); document.all.mobileBrandList.rows[index].cells(3).innerHTML= newOperateStr; } function updateData(index,itemId){ document.frm.action="mobileBrandMgr.jsp?action=update&itemId="+itemId; document.frm.submit(); } function resetData(index,areaName,brandName,mobile,itemId){ var operateStr=""; document.all.mobileBrandList.rows[index].cells(0).innerHTML= areaName; document.all.mobileBrandList.rows[index].cells(1).innerHTML= brandName; document.all.mobileBrandList.rows[index].cells(2).innerHTML= mobile; document.all.mobileBrandList.rows[index].cells(3).innerHTML= operateStr; } function deleteItem(id) { document.frm.action="mobileBrandMgr.jsp?action=delete&id="+id; document.frm.submit(); } function deleteBatch() { document.frm.action="mobileBrandMgr.jsp?action=deleteBatch"; document.frm.submit(); } function insertBatch() 源代码网整理以下 var optionStr="<select name=’update_areaId’>"; var areas = new Array(5) areas[0] = "禅城区"; areas[1] = "三水区"; areas[2] = "顺德区"; areas[3] = "南海区"; areas[4] = "高明区"; for(var i=0;i<areas.length;i++){ if(areaName.indexOf(areas[i])!=-1) optionStr+="<option value=’"+i+"’ selected>"+areas[i]+"</option>"; else optionStr+="<option value=’"+i+"’>"+areas[i]+"</option>"; } optionStr+="</select>"; return optionStr; } </script> </head> <% MobileDb mobileDb = new MobileDb(); MobileBrand mobileBrand = null; String action = request.getParameter("action"); action = action == null ? "" : action; if (action.equals("add")) { String add_areaId = request.getParameter("add_areaId"); String add_brandId = request.getParameter("add_brandId"); String add_mobile = request.getParameter("add_mobile"); mobileBrand = new MobileBrand(); mobileBrand.areaId = Integer.parseInt(add_areaId); mobileBrand.brandId = Integer.parseInt(add_brandId); mobileBrand.mobile = add_mobile; mobileDb.insert(mobileBrand); } //获取查询参数 String areaId = request.getParameter("areaId"); areaId = areaId == null ? "" : areaId; String brandId = request.getParameter("brandId"); brandId = brandId == null ? "" : brandId; String mobile = request.getParameter("mobile"); mobile = mobile == null ? "" : mobile; String term = ""; String strParm = ""; //组合查询条件 if (!areaId.equals("")) { term += " and area_id=" + areaId; } if (!brandId.equals("")) { term += " and brand_id=" + brandId; } if (!mobile.equals("")) { term += " and mobile like ’" + mobile + "%’"; } strParm += "&areaId=" + areaId; strParm += "&brandId=" + brandId; strParm += "&mobile=" + mobile; //////////////分页处理///////////// ServletContext context = getServletContext(); int pageSize = 10; String pageSizeStr = context.getInitParameter("pageSize"); if (pageSizeStr != null) { pageSize = Integer.parseInt(pageSizeStr); } int pageNum = 1; String pageStr = request.getParameter("pageNum"); if (pageStr != null) { pageNum = Integer.parseInt(pageStr); } int startRow = (pageNum - 1) * pageSize + 1; int endRow = (pageNum) * pageSize; int rowCount = 0; int i = startRow - 1; if (action.equals("delete")) { String id = request.getParameter("id"); id = id == null ? "0" : id; mobileDb.deleteById(Integer.parseInt(id)); response.sendRedirect("mobileBrandMgr.jsp?pageNum=" + pageNum + strParm); } if (action.equals("update")) { String itemId = request.getParameter("itemId"); String update_brandId = request.getParameter("update_brandId"); String update_areaId = request.getParameter("update_areaId"); mobileDb.update(Integer.parseInt(itemId),Integer.parseInt(update_brandId),Integer.parseInt(update_areaId)); response.sendRedirect("mobileBrandMgr.jsp?pageNum=" + pageNum+ strParm); } if (action.equals("deleteBatch")) { String delete_brandId = request.getParameter("delete_brandId"); String delete_areaId = request.getParameter("delete_areaId"); mobileDb.deleteByareaIdAndBrandId(Integer.parseInt(delete_areaId),Integer.parseInt(delete_brandId)); response.sendRedirect("mobileBrandMgr.jsp?pageNum=" + pageNum+ strParm); } if (action.equals("insertBatch")) { String insertBatch_areaId=request.getParameter("insertBatch_areaId"); String insertBatch_brandId=request.getParameter("insertBatch_brandId"); String mobiles=request.getParameter("mobiles"); String mobileArray[]=mobiles.trim().split(","); for(int b=0;b<mobileArray.length;b++){ mobileBrand=new MobileBrand(); mobileBrand.areaId=Integer.parseInt(insertBatch_areaId); 软件开发网 www.mscto.com mobileBrand.brandId=Integer.parseInt(insertBatch_brandId); mobileBrand.mobile=mobileArray[b].trim(); mobileDb.insert(mobileBrand); } response.sendRedirect("mobileBrandMgr.jsp?pageNum=" + pageNum+ strParm); } //查询操作 String areas[] = { "禅城区", "三水区", "顺德区", "南海区", "高明区" }; String brands[] = { "全球通", "移动公话", "顺风卡", "新顺风卡", "神州行", "大众卡", "动感地带" }; Collection col = mobileDb.findByTerm(term, startRow, endRow); rowCount = mobileDb.findByTerm(term, 1, -1).size(); int pageCount = rowCount % pageSize == 0 ? rowCount / pageSize : (rowCount / pageSize + 1); %> <body leftmargin="4" topmargin="4"> <form name="frm" method="post" action=""><!-- 搜索条件 --> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="td" bordercolordark=white align="center" height="30"> <tr> <td colspan="6" align="center" valign="middle"> <div align="left"><img src="/console/common/button/zhuangshi1.jpg" width="14" height="14" hspace="10" align="absmiddle"><strong>号码列表管理</strong></div> </td> </tr> </table> <table width="100%"> <tr> <td height="30">地区: <select name="areaId"> <option value="">全部</option> <option value="1" <%=areaId.equals("1")?"selected":""%>>禅城区</option> <option value="2" <%=areaId.equals("2")?"selected":""%>>三水区</option> <option value="3" <%=areaId.equals("3")?"selected":""%>>顺德区</option> <option value="4" <%=areaId.equals("4")?"selected":""%>>南海区</option> <option value="5" <%=areaId.equals("5")?"selected":""%>>高明区</option> </select> 品牌: <select name="brandId"> <option value="">全部</option> <option value="1" <%=brandId.equals("1")?"selected":""%>>全球通</option> <option value="2" <%=brandId.equals("2")?"selected":""%>>移动公话</option> <option value="3" <%=brandId.equals("3")?"selected":""%>>顺风卡</option> <option value="4" <%=brandId.equals("4")?"selected":""%>>新顺风卡</option> <option value="5" <%=brandId.equals("5")?"selected":""%>>神州行</option> <option value="6" <%=brandId.equals("6")?"selected":""%>>大众卡</option> <option value="7" <%=brandId.equals("7")?"selected":""%>>动感地带</option> </select> 号码: <input name="mobile" type="text" class="input" value="<%=mobile%>" size="16"> <img src="/console/common/button/search_p.jpg" alt="查找用户" width="51" height="23" border="0" align="absmiddle" onclick="javascript:find();"></td> </tr> </table> <br> <br> <!-- 号码段信息列表 --> <table width="100%" border="0" cellspacing="1" cellpadding="0" class="table" bordercolordark=white align="center" id="mobileBrandList"> <tr> <td width="15%" align="center" valign="middle" class="td_title">区域</td> <td width="15%" align="center" valign="middle" class="td_title">品牌</td> <td width="10%" align="center" valign="middle" class="td_title">号码</td> <td width="10%" align="center" valign="middle" class="td_title">修改</td> </tr> <% if(col.size()>0){ Iterator it = col.iterator(); mobileBrand = new MobileBrand(); int rowIndex = 0; while (it.hasNext()) { mobileBrand = (MobileBrand) it.next(); rowIndex++; %> <tr class="<%=(i%2 == 1)?"td1":"td2"%>" onmousemove="javascript:finout(true)" onMouseOut="javascript:finout(false)" id="<%=mobileBrand.id %>"> <td align="center" valign="middle" height="7"><%=areas[mobileBrand.areaId - 1]%> </td> <td align="center" valign="middle" height="7"><%=brands[mobileBrand.brandId - 1]%> </td> <td align="center" valign="middle" height="7"><%=mobileBrand.mobile%> </td> <td align="center" valign="middle" height="7"><input name="Submit2" type="button" class="button" value="删除" onClick="javascript:deleteItem(’<%=mobileBrand.id %>’);"> <input name="Submit2" type="button" class="button" value="编辑" onClick="javascript:editItem(’<%=rowIndex %>’,’<%=mobileBrand.id %>’);"> </td> </tr> <% } } 源代码网整理以下 else{ <a href="mobileBrandMgr.jsp?pageNum=<%=pageCount%><%=strParm%>">末页</a> </div> <% } %> </td> </tr> </table> <br> <br> <!-- 增加操作 --> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="td" bordercolordark=white align="center" height="30"> <tr> <td colspan="6" align="center" valign="middle"> <div align="left"><img src="/console/common/button/zhuangshi1.jpg" width="14" height="14" hspace="10" align="absmiddle"><strong>增加号段信息</strong></div> </td> </tr> </table> <table width="100%"> <tr> <td height="30">地区: <select name="add_areaId"> <option value="1">禅城区</option> <option value="2">三水区</option> <option value="3">顺德区</option> <option value="4">南海区</option> <option value="5">高明区</option> </select> 品牌: <select name="add_brandId"> <option value="1">全球通</option> <option value="2">移动公话</option> <option value="3">顺风卡</option> <option value="4">新顺风卡</option> <option value="5">神州行</option> <option value="6">大众卡</option> <option value="7">动感地带</option> 软件开发网 www.mscto.com </select> 号码: <input name="add_mobile" type="text" class="input" value="" size="16"> <input name="Submit2" type="button" class="button" value="添 加" onClick="addItem()"></td> </tr> </table> <br> <br> <!-- 批量删除 --> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="td" bordercolordark=white align="center" height="30"> <tr> <td colspan="6" align="center" valign="middle"> <div align="left"><img src="/console/common/button/zhuangshi1.jpg" width="14" height="14" hspace="10" align="absmiddle"><strong>批量删除号段信息</strong></div> </td> </tr> </table> <table width="100%"> <tr> <td height="30">地区: <select name="delete_areaId"> <option value="0">所有地区</option> <option value="1">禅城区</option> <option value="2">三水区</option> <option value="3">顺德区</option> <option value="4">南海区</option> <option value="5">高明区</option> </select> 品牌: <select name="delete_brandId"> <option value="0">所有名牌</option> <option value="1">全球通</option> <option value="2">移动公话</option> <option value="3">顺风卡</option> <option value="4">新顺风卡</option> <option value="5">神州行</option> <option value="6">大众卡</option> <option value="7">动感地带</option> </select> <input name="Submit2" type="button" class="button" value="删 除" onClick="deleteBatch()"></td> </tr> </table> <br> <br> <!-- 批量增加 --> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="td" bordercolordark=white align="center" height="30"> <tr> <td colspan="6" align="center" valign="middle"> <div align="left"><img src="/console/common/button/zhuangshi1.jpg" width="14" height="14" hspace="10" align="absmiddle"><strong>批量增加号段信息</strong></div> </td> </tr> </table> <table width="100%" height="32" border="0" cellpadding="0" cellspacing="0" id="beforeUpload"> <tr> <td>区域: <select name="insertBatch_areaId"> <option value="1">禅城区</option> <option value="2">三水区</option> <option value="3">顺德区</option> <option value="4">南海区</option> <option value="5">高明区</option> </select> 品牌: <select name="insertBatch_brandId"> <option value="1">全球通</option> <option value="2">移动公话</option> <option value="3">顺风卡</option> <option value="4">新顺风卡</option> <option value="5">神州行</option> <option value="6">大众卡</option> <option value="7">动感地带</option> </select></td> </tr> <tr> <td><textarea name="mobiles" style="font-size: 9pt" cols="80" rows="8" type="_moz"> </textarea></td> </tr> <tr> <td><input name="Submit2" type="button" class="button" value="添加" onclick="insertBatch()"></td> </tr> </table> </form> <script language="javascript" src="/console/common/js/trbg.js"></script> </body> </html> 源代码网推荐 源代码网供稿. |
