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

📄 formchecked.java

📁 学员信息管理系统
💻 JAVA
字号:
package com.javasme.util;

import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import com.javasme.data.SQLOperate;

public class FormChecked {
    private static ImageIcon Error    = new ImageIcon("Error.dll");

    private static ImageIcon Success  = new ImageIcon("Success.dll");

    private static ImageIcon Lose     = new ImageIcon("Lose.dll");

    private static ImageIcon Question = new ImageIcon("Question.dll");

    /**
     * 非空验证
     * 
     * @param formName
     * @param str
     * @return
     */
    public static boolean mustNotNull(String formName, String str) {
        if (str.equals("")) {
            JOptionPane.showMessageDialog(null, "错误信息:[" + formName + "]\n错误提示:不能为空!", "验证出错", JOptionPane.ERROR_MESSAGE, Error);
            return false;
        }
        return true;
    }

    /**
     * 必需为数字
     * 
     * @param formName
     * @param str
     * @return
     */
    public static boolean mustNumber(String formName, String str) {
        for (int i = 0; i < str.length(); i++) {
            if ((str.charAt(i) < '0') || (str.charAt(i) > '9')) {
                JOptionPane.showMessageDialog(null, "错误信息:[" + formName + "]\n错误提示:不能填写除数字以外的其他字符!", "验证出错", JOptionPane.ERROR_MESSAGE, Error);
                return false;
            }
        }
        return true;
    }

    /**
     * 必须选择
     * 
     * @param formName
     * @param str
     * @return
     */
    public static boolean mustSelect(String formName, String str) {
        if (str.equals("请选择...")) {
            JOptionPane.showMessageDialog(null, "错误信息:[" + formName + "]\n错误提示:请选择!", "验证出错", JOptionPane.ERROR_MESSAGE, Error);
            return false;
        }
        return true;
    }

    public static boolean charCheck(String formName, String str) {
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == '\'') {
                JOptionPane.showMessageDialog(null, "错误信息:[" + formName + "]\n错误提示:不能填写非法字符!", "验证出错", JOptionPane.ERROR_MESSAGE, Error);
                return false;
            }
        }
        return true;
    }

    /**
     * 字符个数
     * 
     * @param formName
     * @param str
     * @param beginNumber
     * @param endNumber
     * @return
     */
    /* 之间 */
    public static boolean charBetweenNumber(String formName, String str, int beginNumber, int endNumber) {
        if (str.length() < beginNumber || str.length() > endNumber) {
            JOptionPane.showMessageDialog(null, "错误信息:[" + formName + "]\n错误提示:必需在" + beginNumber + "~" + endNumber + "个字符以内!", "验证出错", JOptionPane.ERROR_MESSAGE, Error);
            return false;
        }
        return true;
    }

    /* 小于 */
    public static boolean charLittleNumber(String formName, String str, int number) {
        if (str.length() > number) {
            JOptionPane.showMessageDialog(null, "错误信息:[" + formName + "]\n错误提示:不能多于" + number + "个字符!", "验证出错", JOptionPane.ERROR_MESSAGE, Error);
            return false;
        }
        return true;
    }

    /* 大于 */
    public static boolean charBigNumber(String formName, String str, int number) {
        if (str.length() < number) {
            JOptionPane.showMessageDialog(null, "错误信息:[" + formName + "]\n错误提示:不能少于" + number + "个字符!", "验证出错", JOptionPane.ERROR_MESSAGE, Error);
            return false;
        }
        return true;
    }

    /* 等于 */
    public static boolean charEqualNumber(String formName, String str, int number) {
        if (str.length() != number) {
            JOptionPane.showMessageDialog(null, "错误信息:[" + formName + "]\n错误提示:必需为" + number + "个字符!", "验证出错", JOptionPane.ERROR_MESSAGE, Error);
            return false;
        }
        return true;
    }

    /**
     * 唯一检查
     * 
     * @param formName
     * @param str
     * @param tableName
     * @param columnName
     * @return
     */
    public static boolean mustNotRepeat(String formName, String str, String tableName, String columnName) {
        String sqlStr = "Select * from " + tableName + " where " + columnName + " = '" + str + "'";
        // System.out.println(sqlStr);
        ResultSet rs = SQLOperate.getResultSet(sqlStr);
        try {
            if (rs.next()) {
                JOptionPane.showMessageDialog(null, "错误信息:[" + formName + "]\n错误提示:[" + str + "]已被使用,请更换!", "验证出错", JOptionPane.ERROR_MESSAGE, Error);
                SQLOperate.closeRS();
                return false;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        SQLOperate.closeRS();
        return true;
    }

    /**
     * 操作成功提示信息
     * 
     * @param operateName
     * @param message
     */
    public static void success(String operateName, String message) {
        JOptionPane.showMessageDialog(null, "操作信息:[" + operateName + "]\n操作提示:" + message, "操作成功", JOptionPane.INFORMATION_MESSAGE, Success);
    }

    /**
     * 操作失败提示信息
     * 
     * @param operateName
     * @param message
     */
    public static void lose(String operateName, String message) {
        JOptionPane.showMessageDialog(null, "操作信息:[" + operateName + "]\n操作提示:" + message, "操作失败", JOptionPane.ERROR_MESSAGE, Lose);
    }

    public static boolean question(String operateName, String message) {
        int isSelected = JOptionPane.showConfirmDialog(null, "操作信息:[" + operateName + "]\n操作提示:" + message, "操作确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, Question);
        if (isSelected == JOptionPane.YES_OPTION) {
            return true;
        } else {
            return false;
        }
    }
}

⌨️ 快捷键说明

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