【JSP开源代码栏目提醒】:网学会员--在 JSP开源代码编辑为广大网友搜集整理了:AdminUsersRecord.jsp绩等信息,祝愿广大网友取得需要的信息,参考学习。
<%@ include file="Common.jsp" %><%!
//
// Filename: AdminUsersRecord.jsp
static final String sFileName = "AdminUsersRecord.jsp";
static final String PageBODY = "bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#0000FF\" vlink=\"#800080\" alink=\"#FF0000\"";
static final String FormTABLE = "border=\"0\" cellspacing=\"0\" cellpadding=\"2\"";
static final String FormHeaderTD = "align=\"center\" bgcolor=\"#99CCFF\"";
static final String FormHeaderFONT = "style=\"font-size: 12pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica; font-weight: bold\"";
static final String FieldCaptionTD = "bgcolor=\"#FFFF99\"";
static final String FieldCaptionFONT = "style=\"font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica\"";
static final String DataTD = "bgcolor=\"#F5F5F5\"";
static final String DataFONT = "style=\"font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica\"";
static final String ColumnFONT = "style=\"font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica; font-weight: bold\"";
static final String ColumnTD = "bgcolor=\"#FFD9E5\"";
%><%
String cSec = checkSecurity(3, session, response, request);
if ("sendRedirect".equals(cSec) ) return;
boolean bDebug = false;
String sAction = getParam( request, "FormAction");
String sForm = getParam( request, "FormName");
String susersErr = "";
java.sql.Connection conn = null;
java.sql.Statement stat = null;
String sErr = loadDriver();
conn = cn();
stat = conn.createStatement();
if ( ! sErr.equals("") ) {
try {
out.println(sErr);
}
catch (Exception e) {}
}
if ( sForm.equals("users") ) {
susersErr = usersAction(request, response, session, out, sAction, sForm, conn, stat);
if ( "sendRedirect".equals(susersErr)) return;
}
%>
<html>
<head>
<title>YellowPages</title>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="expires" content="0"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<jsp:include page="Header.jsp" flush="true"/>
<table>
<tr>
<td valign="top">
<% users_Show(request, response, session, out, susersErr, sForm, sAction, conn, stat); %>
<SCRIPT Language="JavaScript">
if (document.forms["users"])
document.users.onsubmit=delconf;
function delconf() {
if (document.users.FormAction.value == 'delete')
return confirm('Delete record?');
}
</SCRIPT>
</td>
</tr>
</table>
</body>
</html>
<%%>
<%
if ( stat != null ) stat.close();
if ( conn != null ) conn.close();
%>
<%!
String usersAction(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpSession session, javax.servlet.jsp.JspWriter out, String sAction, String sForm, java.sql.Connection conn, java.sql.Statement stat) throws java.io.IOException {
String susersErr ="";
try {
if (sAction.equals("")) return "";
String sSQL="";
String transitParams = "";
String primaryKeyParams = "";
String sQueryString = "";
String sPage = "";
String sParams = "";
String sActionFileName = "AdminUsersGrid.jsp";
String sWhere = " ";
boolean bErr = false;
long iCount = 0;
String pPKuser_id = "";
if (sAction.equalsIgnoreCase("cancel") ) {
try {
if ( stat != null ) stat.close();
if ( conn != null ) conn.close();
}
catch ( java.sql.SQLException ignore ) {}
response.sendRedirect (sActionFileName);
return "sendRedirect";
}
final int iinsertAction = 1;
final int iupdateAction = 2;
final int ideleteAction = 3;
int iAction = 0;
if ( sAction.equalsIgnoreCase("insert") ) { iAction = iinsertAction; }
if ( sAction.equalsIgnoreCase("update") ) { iAction = iupdateAction; }
if ( sAction.equalsIgnoreCase("delete") ) { iAction = ideleteAction; }
// Create WHERE statement
if ( iAction == iupdateAction || iAction == ideleteAction ) {
pPKuser_id = getParam( request, "PK_user_id");
if ( isEmpty(pPKuser_id)) return susersErr;
sWhere = "user_id=" + toSQL(pPKuser_id, adNumber);
}
String flduser_login="";
String flduser_password="";
String flduser_level="";
String fldname="";
String fldemail="";
String flduser_id="";
// Load all form fields into variables
flduser_login = getParam(request, "user_login");
flduser_password = getParam(request, "user_password");
flduser_level = getParam(request, "user_level");
fldname = getParam(request, "name");
fldemail = getParam(request, "email");
// Validate fields
if ( iAction == iinsertAction || iAction == iupdateAction ) {
if ( isEmpty(flduser_login) ) {
susersErr = susersErr + "The value in field Login is required.<br>";
}
if ( isEmpty(flduser_password) ) {
susersErr = susersErr + "The value in field Password is required.<br>";
}
if ( isEmpty(flduser_level) ) {
susersErr = susersErr + "The value in field Level is required.<br>";
}
if ( isEmpty(fldname) ) {
susersErr = susersErr + "The value in field Name is required.<br>";
}
if ( ! isNumber(flduser_level)) {
susersErr = susersErr + "The value in field Level is incorrect.<br>";
}
if ( ! isEmpty(flduser_login)) {
iCount = 0;
if ( iAction == iinsertAction ) {
iCount = dCountRec(stat, "users", "user_login=" + toSQL(flduser_login, adText));
}
else {
if ( iAction == iupdateAction ) {
iCount = dCountRec( stat, "users", "user_login=" + toSQL(flduser_login, adText) + " and not(" + sWhere + ")");
}
}
if (iCount > 0) {
susersErr = susersErr + "The value in field Login is already in database.<br>";
}
}
if (susersErr.length() > 0 ) {
return (susersErr);
}
}
sSQL = "";
// Create SQL statement
switch (iAction) {
case iinsertAction :
sSQL = "insert into users (" +
"user_login," +
"user_password," +
"user_level," +
"name," +
"email)" +
" values (" +
toSQL(flduser_login, adText) + "," +
toSQL(flduser_password, adText) + "," +
toSQL(flduser_level, adNumber) + "," +
toSQL(fldname, adText) + "," +
toSQL(fldemail, adText) + ")";
break;
case iupdateAction:
sSQL = "update users set " +
"user_login=" + toSQL(flduser_login, adText) +
",user_password=" + toSQL(flduser_password, adText) +
",user_level=" + toSQL(flduser_level, adNumber) +
",name=" + toSQL(fldname, adText) +
",email=" + toSQL(fldemail, adText);
sSQL = sSQL + " where " + sWhere;
break;
case ideleteAction:
sSQL = "delete from users where " + sWhere;
break;
}
if ( susersErr.length() > 0 ) return susersErr;
try {
// Execute SQL statement
stat.executeUpdate(sSQL);
}
catch(java.sql.SQLException e) {
susersErr = e.toString(); return (susersErr);
}
try {
if ( stat != null ) stat.close();
if ( conn != null ) conn.close();
}
catch ( java.sql.SQLException ignore ) {}
response.sendRedirect (sActionFileName);
return "sendRedirect";
}
catch (Exception e) {out.println(e.toString()); }
return (susersErr);
}
void users_Show(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpSession sessio
上一篇:
AdminUsersGrid.jsp
下一篇:
临床前药物安全性评价中毒性病理学新技术的应用