⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showformaction.java

📁 医院信息系统(Hospital Information System
💻 JAVA
字号:
/*
 * Copyright 2007 The Apache Software Foundation
 *
 * 本类用来生成用户所要填写的表单
 *
 */

package hospital.Controller.Actions.GeneralFunction;

import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
import hospital.*;
import hospital.Foundation.DataFixing;
import hospital.View.*;

public class ShowFormAction extends Action {

    private String menuID = "";
    private String modified = "";
    private String keyNames = "";
    private String baseTableName = "";
    private String superTableName = "";
    private String pageShowType = "";

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {

        String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
        String dbURL = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=hospital";
        String userName = "sa";
        String userPwd = "";

        //用来存放每一个输入用的文本框和他的标题
        ArrayList listInputItem = new ArrayList();

        //从保存的表单中得到整个表单的名值对
        Hashtable hashRowContent = (Hashtable) request.getAttribute("hashRowContent");

        try {
            Connection dbConn;
            Class.forName(driverName);
            dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
            Statement stmt = dbConn.createStatement();

            //初始化页面的所有参数
            initPageParameters(form, request, stmt, hashRowContent);

            //生成整个表单的HTML代码,并得到该表单的关键字名
            createFormHTML(listInputItem, stmt, hashRowContent);

            stmt.close();
            dbConn.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        //将参数和查询结果发往结果页面
        returnPageParameters(request, listInputItem);

        //转到表单页面
        return mapping.findForward("customform");
    }

    //将所有成员变量归为初始值
    private void setPropertyToOrginate() {
        menuID = "";
        modified = "";
        keyNames = "";
        baseTableName = "";
        superTableName = "";
        pageShowType = "";
    }

    //初始化页面的所有参数
    private void initPageParameters(ActionForm form, HttpServletRequest request, Statement stmt, Hashtable hashRowContent) throws Exception {
        //将所有成员变量归为初始值
        setPropertyToOrginate();

        //从地址栏得到menuid的值,或者从保存的表单中得到该值
        menuID = request.getParameter("menuid");
        if (menuID == null) {
            menuID = (String) request.getAttribute("menuID");
        }

        //modified表示该页面是否为通过修改补录按钮所显示的页面
        modified = request.getParameter("modified");
        if (modified == null) {
            modified = "";
        }

        //从保存的表单中得到基本数据表名和影射数据表名
        baseTableName = (String) request.getAttribute("baseTableName");
        superTableName = (String) request.getAttribute("superTableName");

        //如果不能从保存的表单中得到baseTableName和superTableName
        //则通过menuID查询数据库,得到对应的baseTableName和superTableName
        if (baseTableName == null || superTableName == null) {
            getInfoFromMenuID(stmt);
        }
    }

    //将参数和查询结果发往结果页面
    private void returnPageParameters(HttpServletRequest request, ArrayList listInputItem) {
        //得到当前页面的保存状态,如果没有保存状态,则赋为0表示尚未保存过
        String saveStatus = (String) request.getAttribute("newSaveStatus");
        if (saveStatus == null) {
            request.setAttribute("newSaveStatus", "0");
        }

        //将所用参数发送到表单页面
        request.setAttribute("listInputItem", listInputItem);
        request.setAttribute("menuID", menuID);
        request.setAttribute("baseTableName", baseTableName);
        request.setAttribute("superTableName", superTableName);
        request.setAttribute("keyNames", keyNames);
        request.setAttribute("pageShowType", pageShowType);
    }

    private void getInfoFromMenuID(Statement stmt) throws SQLException {
        String sql = "select * from sys菜单基本表 where 菜单id='" + menuID + "'";
        ResultSet rs = stmt.executeQuery(sql);
        if (rs.next()) {
            baseTableName = rs.getString("表名");
            pageShowType = rs.getString("界面表现规则");
            superTableName = rs.getString("映射表名");
        }
    }

    private void createFormHTML(ArrayList listInputItem, Statement stmt, Hashtable hashRowContent) throws
        SQLException {
        String sql = "select * from sys字典表 where tableName='" + baseTableName + "' order by sequenceNO";
        ResultSet rs = stmt.executeQuery(sql);

        String columnValue = "";
        String fieldName = "";
        String maxLength = "";
        String dispLength = "";
        String isKey = "";
        String notNullFlag = "";
        String fieldType = "";
        String inputEnable = "";
        String codeType = "";
        String codeCascade = "";

        while (rs.next()) {
            String[] contentRow = new String[2];
            contentRow[0] = rs.getString("caption");
            if (hashRowContent != null) {
                columnValue = (String) hashRowContent.get(contentRow[0]);
            }

            fieldName = DataFixing.trimNULL(rs.getString("fieldName"));
            maxLength = DataFixing.trimNULL(rs.getString("maxLength"));
            dispLength = DataFixing.trimNULL(rs.getString("dispLength"));
            isKey = DataFixing.trimNULL(rs.getString("isKey"));
            notNullFlag = DataFixing.trimNULL(rs.getString("notNullFlag"));
            fieldType = DataFixing.trimNULL(rs.getString("fieldType"));
            inputEnable = DataFixing.trimNULL(rs.getString("inputEnable"));
            codeType = DataFixing.trimNULL(rs.getString("codeType"));
            codeCascade = DataFixing.trimNULL(rs.getString("codeCascade"));

            SuperInput superInput = new SuperInput();

            superInput.setInputFieldType(fieldType);
            superInput.setInputID(fieldName);
            superInput.setInputInputEnable(inputEnable);
            superInput.setInputIsKey(isKey);
            superInput.setInputMaxLength(maxLength);
            superInput.setInputName(fieldName);
            superInput.setInputNotNullFlag(notNullFlag);
            superInput.setInputSize(dispLength);
            superInput.setInputValue(columnValue);
            superInput.setInputCodeType(codeType);
            superInput.setInputCodeCascade(codeCascade);

            superInput.setModified(modified);

            contentRow[1] = superInput.getInputString();
            if (!superInput.getKeyNames().equals("")) {
                keyNames = superInput.getKeyNames();
            }
            //System.out.println(contentRow[1]);
            listInputItem.add(contentRow);
        }
        //System.out.println("!!!!!!!!!!!!!:"+modified);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -