发展部件技术分享 http://blog.sciencenet.cn/u/求新 研究方向:数据库、MIS,教育部教指委计算机分委会专家工作组成员

博文

管理信息系统软件生产线源码74-77

已有 1536 次阅读 2018-6-24 23:13 |个人分类:生活点滴|系统分类:科研笔记| 软件生产线, 软部件, 数据库, 管理信息系统, JAVA

版本1

74.源码74,公共程序,求解条件表达式宏替换程序。

/**

 * 程序文件名:tenanceEval.java

 * 作者:程学先 

 * 功能:求解条件表达式宏替换程序 。

 * 如果一个条件表达式由数字数据类型常量、括号、逻辑运算符、关系运算符、某

 * 些函数、四则运算符构成的条件表达式,可以求得真或假的结果。

 * 设计思想:类是方法与数据的集成,部件是程序模块、构件、组件、类的集成。

 * 面向对象的秘诀或创新是多工作“集成”或"冗余","冗余"指在设计时不只是根据当前的需求

 * 设计一对一的代码,而是再加上类似界面、类似功能的其他代码,封装在一起,

 * 在每次应用时选择部分方法与数据为当前任务服务,不一定用到其全部的方法和数据。

 * 其他的方法与数据将在其他类似界面、类似任务重调用。

 * 例如“文本框”类,将数据显示、录入、修改、字体、字号、颜色等操作方法与有关数据都集成到同一个类中,

 * 在其子类中还包括密码框。在实际使用时往往只根据录入或显示的需求选用其部分方法和数据。

 * 这样的冗余设计使其复用粒度加大,复用范围拓广,开创了软件设计的面向对象时代。

 * 软部件的设计思想也是集成或冗余,

 * 将用于某一类界面和完成某一类具体的工作的程序模块、构件、组件、中间件、类等集成到一个封装体中。

 * 这样的冗余设计目的是提高软件复用粒度,扩大软件复用范围,

 * 在每次调用时通过选择数据表、选择布局、选择字段与按钮及其他参数使其用作某种模块或构件,完成一种应用。

 * 就能用较少的软部件覆盖或满足更多的应用,只有这样的设计才能成为软件生产线的设计基础,

 * 才有可能更好地实现软件设计自动化。

 * 需要说明的是,软件复用有利于提高编码效率,有利于实现软件生产自动化,可以降低软件设计难度,减少直接的代码量。

 * 但它是以降低软件运行效率、缩小软件应用范围为代价的,

 * 因此需要根据应用需要恰当地选取软件复用度,不要一味追求高复用,对于对时间要求高的软件和一些有特殊要求的软件,

 * 只能用复用度低的软件,例如使用用C语言甚至汇编语言编写的程序。

 * 由于JAVA中无宏替换语句,在设计复用度较高、要求较高自适应性的的软件时比较有挑战性的就是如何在JAVA中实现宏替换。

 * 本程序是实现条件表达式宏替换的一种方法。

 * 完成时间 2018.6.5 

 * 条件表达式中运算符可包括:+、-、*、/、%、>、>=、<、<=、]、 [ 、! 、|、||、 &、&&、 =、(、)、

 * 支持函数:sqrt,square,ceil,sin,cos,asin,acon.tan.atan,log,exp。不支持NOT运算。 

 * 调用:tenanceEval.tenanceeval(String 条件表达式)

 * 返回布尔值真或假

 */

import java.util.Stack;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

import javax.swing.JOptionPane;


public class tenanceEval {

public static tenanceEval be = new tenanceEval(); // 对每个表达式计算其值

public static String 运算符号 = "+-*/%><][!|&=#";

public static String 运算符号1 = "^([a-zA-Z0-9_]+)\\(([a-zA-Z0-9_.()]+)\\)$";

public static String 算术表达式 = "", 算术表达式0 = "";

public static String 算术表达式1 = "", 算术表达式2 = "";

public static boolean 布尔变量 = false;

public static Object retp = null;

public static Exception e0;


protected static int 字符串个数(String s, String s0) {

int n = 0;

for (int i = 0; i < s.length() - s0.length() + 1; i++) {

if (s.substring(i, i + s0.length()).equals(s0))

n++;

}

return n;

}


public static boolean tenanceeval(String 算术表达式) { // 构造函数

String[] s1 = null;

boolean 返回关系值2 = true;

String s2 = "and";

算术表达式 = 算术表达式.toLowerCase(); // 全部变小写

算术表达式 = 算术表达式.replaceAll("&&", "&");

算术表达式 = 算术表达式.replaceAll("&", "and");

算术表达式 = 算术表达式.replaceAll("\\|\\|", "or");

算术表达式 = 算术表达式.replaceAll("\\|", "or");

int k1 = 0, k2 = 0, k3 = 0, k4 = 0, bz = 0, bz1 = 0;

String x1 = 算术表达式;

boolean b0 = true, bl2 = true;

x1 = x1.replaceAll("(sqrt)|(square)|(ceil)|(sin)|(cos)|(asin)|"

+ "(acon)|(tan)|(atan)|(log)|(exp)(sqrt)|(square)|(ceil)|"

+ "(sin)|(cos)|(asin)|(acon)|(tan)|(atan)|(log)|(exp)", "¥");

if (x1.length() != 算术表达式.length()) { // 通过变换后长度变化测试表达式中是否有函数表达式

算术表达式 = be.函数数据计算(x1, 算术表达式); // 首先做函数计算

}

Stack 堆栈数据1 = new Stack();

Stack 堆栈数据2 = new Stack();

算术表达式 = 算术表达式.replaceAll(" ", ""); // 去空格

if ((算术表达式.indexOf("and") > 0) || (算术表达式.indexOf("or") > 0)) {

算术表达式 = 算术表达式.replaceAll("or", "or "); // 统一为三个字符长

x1 = 算术表达式.replaceAll("(and)|(or )", "¥¥¥");

String[] s01 = x1.split("¥¥¥"), s02 = null, s03 = null; // 分块

int[] n1 = new int[s01.length]; // 准备存每块开始位置

k1 = 0;

String s10 = "", s11 = "", s12, s13, s14;

boolean bl1 = true;

for (int i = 0; i < s01.length; i++) { // 按块个数循环

n1[i] = k1;

if (算术表达式.length() > k1 + s01[i].length() + 3) {

堆栈数据1.push(算术表达式.substring(k1, k1 + s01[i].length() + 3)); // 将块内容连同逻辑运算符压入堆栈

} else {

堆栈数据1.push(s01[i]); // 将块内容、逻辑符号压入堆栈

}

k1 = k1 + 3 + s01[i].length();

}

int i = 0;

s11 = "";

a1: for (i = s01.length - 1; i >= 0; i--) { // 按块个数循环,倒数

if (堆栈数据1.size() > 0)

s10 = 堆栈数据1.pop().toString();

else

s10 = "";

if (be.字符串个数(s10, "(") > be.字符串个数(s10, ")")) {// 从右向左找左括号较多的块

k1 = 0;

s11 = "";

for (int j = s10.length() - 1; j >= 0; j--) {

if (s10.substring(j, j + 1).equals(")")) {

k1--;

}

if (s10.substring(j, j + 1).equals("(")) {

k1++;

}

if (k1 == 1) { // 找到左边第一个左括号

堆栈数据1.push(s10.substring(0, j));

i++;

s11 = s11 + s10.substring(j + 1, s10.length());

break;

}

}

a2: while (堆栈数据2.size() > 0) {

s10 = 堆栈数据2.pop().toString();

if (be.字符串个数(s10, "(") < be.字符串个数(s10, ")")) {// 从左向右找右括号较多的块

k1 = 0;

for (int j1 = 0; j1 < s10.length(); j1++) {

if (s10.substring(j1, j1 + 1).equals("(")) {

k1--;

}

if (s10.substring(j1, j1 + 1).equals(")")) {

k1++;

}

if (k1 == 1) { // 找到右边第一个右括号

s11 = s11 + s10.substring(0, j1);

堆栈数据2.push(s10.substring(j1 + 1,

s10.length()));// 第一个右括号右边部分

j1++;

bl2 = be.逻辑运算(s11);

堆栈数据2.push(bl2);// 逻辑运算计算结果

j1++;

break a2;

}

}

} else

s11 = s11 + s10;

}

} else {

s11 = s11 + s10;

堆栈数据2.push(s10); // 不是左括号块,再压入堆栈2

}

if (i == 0) {

s11 = "";

k1 = 堆栈数据2.size();

for (int j2 = 0; j2 < k1; j2++)

s11 = s11 + 堆栈数据2.pop();

if (s11.length() > 0){

bl2 = be.逻辑运算(s11);

}

if ((i == 0) && (堆栈数据1.size() == 0) && (堆栈数据2.size() == 0))

break a1;

}

}

} else {

bl2 = 关系分析1(算术表达式);

}

return bl2;

}


protected boolean 逻辑运算(String s) { // 处理不涉及括号问题的逻辑运算

s = s.replaceAll("or", "or "); // 统一为三个字符长

String x1 = s.replaceAll("(and)|(or )", "¥¥¥");

String[] s01 = x1.split("¥¥¥"), s02 = null, s03 = null; // 分块

int[] n1 = new int[s01.length]; // 准备存每块开始位置

int k1 = 0;

String s10 = "", s11 = "", s12, s13, s14;

boolean bl1 = true, bl2 = true;

for (int i = 0; i < s01.length; i++) { // 按块个数循环

if (i == 0) {

bl1 = 关系分析1(s01[i]);

k1 = k1 + s01[i].length();

} else {

s10 = s.substring(k1, k1 + 3);

if (s10.indexOf("and") >= 0) {

bl2 = 关系分析1(s01[i]);

bl1 = bl1 && bl2;

} else if (s10.indexOf("or") >= 0) {

bl2 = 关系分析1(s01[i]);

bl1 = bl1 || bl2;

}

k1 = k1 + s01[i].length() + 3;

}

}

return bl1;

}


public static boolean 关系分析1(String sq1) { // 对分离并、或符号后表达式分开处理

boolean bo3 = true;

String s1[] = null;

String sq2 = sq1.replaceAll("(>=)|(<>)|(>)|(==)|(<=)|(<)|(!=)|(=)",

"###");

if (sq2.indexOf("#") > 0) {

s1 = sq2.split("###");

double w1 = 0.0;

double w2 = 0.0;

String sq3 = s1[0], sq4 = s1[1];

if (s1[0].indexOf(")") > 0)

sq3 = be.去括号计算1(s1[0]);

else {

if ((s1[0].indexOf("+") > 0) || (s1[0].indexOf("-") > 0)

|| (s1[0].indexOf("*") > 0) || (s1[0].indexOf("/") > 0)

|| (s1[0].indexOf("%") > 0))

sq3 = 四则运算(s1[0]);

}

if (s1[1].indexOf(")") > 0)

sq4 = be.去括号计算1(s1[1]);

else {

if ((s1[1].indexOf("+") > 0) || (s1[1].indexOf("-") > 0)

|| (s1[1].indexOf("*") > 0) || (s1[1].indexOf("/") > 0)

|| (s1[1].indexOf("%") > 0))

sq4 = 四则运算(s1[1]);

}

w1 = Double.parseDouble(sq3);

w2 = Double.parseDouble(sq4);

if (sq1.indexOf(">=") >= 0) {

bo3 = w1 >= w2;

} else if (sq1.indexOf(">") >= 0) {

bo3 = w1 > w2;

} else if (sq1.indexOf("<=") >= 0) {

bo3 = w1 <= w2;

} else if (sq1.indexOf("<") >= 0) {

bo3 = w1 < w2;

} else if (sq1.indexOf("==") >= 0) {

bo3 = w1 == w2;

} else if (sq1.indexOf("=") >= 0) {

bo3 = w1 == w2;

} else if (sq1.indexOf("!=") >= 0) {

bo3 = w1 != w2;

} else if (sq1.indexOf("<>") >= 0) {

bo3 = w1 != w2;

}

} else {

if (sq1.indexOf("true") >= 0)

bo3 = true;

else if (sq1.indexOf("false") >= 0)

bo3 = false;

}

return bo3;

}


protected String 去括号计算1(String s) {// 处理内无NOT、AND、OR的括号,为纯粹四则运算式

String[] s0 = s.split("\\(");

String[] s1 = s0[s0.length - 1].split("\\)");

int n1 = 0, n2 = 0;

String s2 = "", s3 = "";

for (int i = 0; i < s0.length - 1; i++) {

n1 = n1 + s0[i].length() + 1;

s2 = s2 + s0[i];

if (i < s0.length - 2)

s2 = s2 + "(";

}

n2 = n1 + s1[0].length() + 1;

s3 = s.substring(n2, s.length());

s = s.substring(n1 - 1, n2);

n1--;

s = s.replaceAll("(\\()|(\\))", "");

if ((s.indexOf("+") > 0) || (s.indexOf("-") > 0)

|| (s.indexOf("*") > 0) || (s.indexOf("/") > 0)

|| (s.indexOf("%") > 0))

四则运算(s);

算术表达式 = s2 + 算术表达式 + s3;

return 算术表达式;

}


public static String 四则运算(String s) {

String s1 = s.replaceAll("[-/%]", "*");

s1 = s1.replaceAll("[\\+]", "*");

String[] s0 = s1.split("\\*");

int[] l0 = new int[s0.length]; // 每一块长度

String[] s01 = new String[s0.length]; // 准备存乘除法之后中间结果

String[] l1 = new String[s0.length]; // 准备存符号

String[] l2 = new String[s0.length]; // 准备存乘除法之后中间结果符号

Stack 堆栈数据1 = new Stack();

Stack 堆栈数据2 = new Stack();

Stack 堆栈数据3 = new Stack();

Stack 堆栈数据4 = new Stack();

String sm1 = "", sm2 = "", sn1, sn2, sn3, sn4;

int n = 0, n1 = 0;

double d1 = 0.0, d2 = 0.0;

l2[0] = "";

for (int i = 0; i < s0.length; i++) { // 初始化

l0[i] = s0[i].length();

n = n + s0[i].length();

s01[i] = s0[i];

if (i < s0.length - 1) {

l2[i + 1] = s.substring(n, n + 1);

n++;

}

}

for (int i = s0.length - 1; i >= 0; i--) {

堆栈数据1.push(s0[i]); // 压入数据

堆栈数据2.push(l2[i]);// 压入符号

}

n = 堆栈数据1.size(); // 处理乘法除法

for (int i = 0; i < n; i++) {

sn1 = 堆栈数据1.pop().toString();

sn2 = 堆栈数据2.pop().toString();

if (sn2.equals("*")) {

d1 = Double.parseDouble(sm1) * Double.parseDouble(sn1);

sm1 = d1 + "";

s01[i] = sm1;

s01[i - 1] = "";

l2[i] = l2[i - 1];

l2[i - 1] = "";

} else if (sn2.equals("/")) {

d1 = Double.parseDouble(sm1) / Double.parseDouble(sn1);

sm1 = d1 + "";

s01[i] = sm1;

s01[i - 1] = "";

l2[i] = l2[i - 1];

l2[i - 1] = "";

} else if (sn2.equals("%")) {

d1 = Double.parseDouble(sm1) % Double.parseDouble(sn1);

sm1 = d1 + "";

s01[i] = sm1;

l2[i] = l2[i - 1];

s01[i - 1] = "";

l2[i - 1] = "";

} else

sm1 = sn1;

算术表达式 = d1 + "";

}

for (int i = s01.length - 1; i >= 0; i--) {

if (s01[i].length() > 0) {

堆栈数据3.push(s01[i]); // 压入数据

堆栈数据4.push(l2[i]);// 压入符号

}

}

if (堆栈数据3.size() > 1) { // 处理加法、减法

d1 = 0.0;

sm1 = "";

n = 堆栈数据3.size();

for (int i = 0; i < n; i++) {

sn1 = 堆栈数据3.pop().toString();

sn2 = 堆栈数据4.pop().toString();

if (sn2.equals("+")) {

d1 = Double.parseDouble(sm1) + Double.parseDouble(sn1);

sm1 = d1 + "";

s01[i] = sm1;

s01[i - 1] = "";

l2[i] = l2[i - 1];

l2[i - 1] = "";

} else if (sn2.equals("-")) {

d1 = Double.parseDouble(sm1) - Double.parseDouble(sn1);

sm1 = d1 + "";

s01[i] = sm1;

s01[i - 1] = "";

l2[i] = l2[i - 1];

l2[i - 1] = "";

} else {

sm1 = sn1; // 上一个元素

}

}

算术表达式 = d1 + "";

}

return 算术表达式;

}


protected String 函数数据计算(String 算术表达式1, String 变量值3) {

String[] s1 = 算术表达式1.split("¥"); // 根据函数式的函数名分块

String 变量值4 = "", 变量值5 = "", 变量值6 = "", 变量值7 = "", x1;

int n1 = 0, n2 = 0, n3 = 0;

double db = 0.0;

for (int i = 0; i < s1.length; i++) { // 本程序暂不考虑函数嵌套问题

n3 = n1 + s1[i].length(); // 在算术表达式中函数式前面部分长度

n1 = 变量值3.indexOf("(", n2 + s1[i].length());// 在算术表达式中函数后面左括号位置

if (n1 < 0)

break;

n2 = 变量值3.indexOf(")", n1); // 函数右括号位置

变量值4 = 变量值3.substring(n1 + 1, n2); // 待进行函数运算的表达式

变量值5 = 变量值3.substring(n3, n1); // 函数名

变量值7 = 变量值3.substring(n3, n2 + 1); // 原来变量值3中完整的函数表达式

if (变量值4.indexOf("(") > 0)

变量值4 = be.去括号计算1(变量值4); // 求待进行函数运算的表达式的值

else {

x1 = 变量值4;

x1 = x1.replaceAll("[-/%]", "");

x1 = x1.replaceAll("[\\+]", "");

x1 = x1.replaceAll("[\\*]", "");

if (x1.length() != 变量值4.length())

if ((变量值4.indexOf("+") > 0) || (变量值4.indexOf("-") > 0)

|| (变量值4.indexOf("*") > 0)

|| (变量值4.indexOf("/") > 0)

|| (变量值4.indexOf("%") > 0))

变量值4 = 四则运算(变量值4);

}

try {

db = Double.valueOf(变量值4).doubleValue();

if (变量值5.equals("log")) {

变量值6 = Math.log(db) + "";

} else if (变量值5.equals("square")) {

变量值6 = Math.pow(db, 2) + "";

} else if (变量值5.equals("sqrt")) {

变量值6 = Math.sqrt(db) + "";

} else if (变量值5.equals("sin")) {

变量值6 = Math.sin(db) + "";

} else if (变量值5.equals("asin")) {

变量值6 = Math.asin(db) + "";

} else if (变量值5.equals("cos")) {

变量值6 = Math.cos(db) + "";

} else if (变量值5.equals("tan")) {

变量值6 = Math.tan(db) + "";

} else if (变量值5.equals("atan")) {

变量值6 = Math.atan(db) + "";

} else if (变量值5.equals("ceil")) {

变量值6 = Math.ceil(db) + "";

} else if (变量值5.equals("exp")) {

变量值6 = Math.exp(db) + "";

}

} catch (Exception e) {

}

int l1 = 变量值3.indexOf(变量值7); // 变量值7位置

int l2 = 变量值7.length(); // 变量值7长度

变量值3 = 变量值3.substring(0, l1)

+ (变量值6 + "               ").substring(0, l2)

+ 变量值3.substring(l1 + l2, 变量值3.length());

变量值3 = 变量值3.replaceAll(" ", "");

n2--;

}

算术表达式 = 变量值3;

return 变量值3;

}

  }



75.源码75,公共程序,为数据维护程序设置完整性控制条件。

/*

 * 程序文件名:completeTool.java

 * 作者:程学先 

 * 功能:为数据维护程序设置完整性控制条件。

 * 设置数据完整性一条记录包括:字段名称、最大值、最小值、值域、条件表达式等5个参数

 * 最大值、最小值指该字段在数据输入时能够填入的最大值或最小值。越限将不能录入。

 * 由于0也是有限数字,因此没有最大、最小数据条件时不要留0,请保持空。

 * 最大值、最小值、条件表达式只对数字数据各类型检查并控制。

 * 值域可对数字数据类型,也可对各字符数据类型。本程序允许有三种格式

 * 1)最小值-最大值,只对数字数据类型。

 * 2)值1,值2,……,值n,    表示只能是其中之一

 * 3)[值1,值2,……,值n,]   表示只要包含其中之一。在值前可以加^,表示该值不得包含在内。

 * 条件表达式指该字段数据必须满足的条件,例如:年龄>=18 and 年龄<=60,表示数据有效范围

 * 所有数据保存在一个文件中,该文件可以包括控件位置大小参数、安全性要求参数、完整性参数等三组内容,

 * 每组内容第一个数据标志类型,1表示控件位置大小参数;2表示安全性要求参数;3表示完整性参数。

 */

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;

import javax.swing.tree.DefaultMutableTreeNode;

import java.io.*;

import java.sql.Connection;

import java.sql.DatabaseMetaData;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.Vector;


public class completeTool extends JFrame {

private static completeTool frame3 = new completeTool();

private static JPanel panel3 = new JPanel(); // 定义面板

private static DefaultTableModel 表格模型; // 定义表格模型对象

private static JTable 表格; // 定义表格对象

private static JScrollPane scrollPane = new JScrollPane(); // 定义表格滚动条

private static JScrollPane scrollPane1 = new JScrollPane(); // 定义列表框滚动条

private static List list1 = new List();

private static JLabel fl0, fl1, fl2, fl3, fl4, fl5, fl9;

private static JTextField fa0, fa1, fa2, fa3, fa4, fa5, fa9; // 定义文本框用来放存入、修改数据

private static String 当前值;

private static int 选中行号 = -1, 当前行号 = 0, 表格行数 = 0, 当前列号 = 0, 列数 = 0;

private static int 字段序号 = 0;

private static String[][] 表格数据;

private static ArrayList<String> 读入数据 = new ArrayList();

private static String[] 列名1; // 数据表中列名

private static String[] 列名 = { "字段名称", "最大值", "最小值", "值域", "条件表达式" }; // 定义表格列名数组

private static int[] 列数据宽度;

private static String[] 一行数据 = new String[5];

private static File file1;

private static ArrayList<String> list = new ArrayList<String>();

static Connection con; // 连接数据库

private static Statement sta; // 连接数据库

static String s1 = "", s2 = ""; // 临时变量

private static ResultSet rs; // 数据库数据集

private static ResultSetMetaData rsmd;

private static ArrayList 表名1 = new ArrayList();


public static void main(String args[]) {

frame3 = new completeTool();

panel3 = new JPanel();

scrollPane = new JScrollPane();

scrollPane1 = new JScrollPane();

list1 = new List();

选中行号 = -1;

当前行号 = 0;

表格行数 = 0;

当前列号 = 0;

列数 = 0;

字段序号 = 0;

读入数据 = new ArrayList();

列名[0] = "字段名称";

列名[1] = "最大值";

列名[2] = "最小值";

列名[3] = "值域";

列名[4] = "条件表达式";

一行数据 = new String[5];

list = new ArrayList<String>();

s1 = "";

s2 = "";

表名1 = new ArrayList();

frame3.setTitle("最大值、最小值指该字段输入极限,值域指所填数据只能在该域内数据中选取,条件表达式指该字段数据必须满足的条件。   作者:程学先");

frame3.setBounds(10, 10, 880, 660); // 窗口位置大小

frame3.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // 设置窗体的默认关闭模式

panel3.setBounds(10, 10, 880, 660); // 定义面板大小与位置

panel3.setLayout(null); // 关闭面板布局管理器

表格模型 = new DefaultTableModel(表格数据, 列名); // 创建表格模型

表格 = new JTable(表格模型); // 创建指定表格模型的表格

表格.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);// 设置表格的选择模式为单选

main1.driver1(); // 接jdbc驱动

fl0 = new JLabel("数据表名");

fl0.setBounds(40, 10, 80, 20);

panel3.add(fl0); // 定义文本框的标签

fa0 = new JTextField(""); // 定义文本框,预设值

fa0.setBounds(130, 10, 100, 20);

panel3.add(fa0); // 加入文本框

fa0.addFocusListener(new FocusAdapter() { // 加入监听

public void focusGained(final FocusEvent arg0) { // 获得焦点

当前列号 = 0;

list1.removeAll();

if (表名1.size() < 1) {

try {

con = main1.getConn();// 连接数据库

String[] tableType = { "TABLE" };

DatabaseMetaData databaseMetaData = con.getMetaData(); // 获取DatabaseMetaData实例

ResultSet resultSet = databaseMetaData.getTables(null,

null, "%", tableType);// 获取数据库中所有数据表集合

while (resultSet.next()) { // 遍历集合

表名1.add(resultSet.getString("TABLE_NAME"));

}

} catch (Exception e) {

e.printStackTrace();

}

}

for (int i = 0; i < 表名1.size(); i++)

list1.add(表名1.get(i).toString());

}

});

fl9 = new JLabel("文件名");

fl9.setBounds(250, 10, 50, 20);

panel3.add(fl9); // 定义文本框的标签

fa9 = new JTextField("", 20); // 定义文本框,预设值

fa9.setBounds(300, 10, 100, 20);

panel3.add(fa9); // 加入文本框

fa9.addMouseListener(new MouseAdapter() { // 为表格添加鼠标事件监听器

public void mouseClicked(MouseEvent e) {

if (fa9.getText().length() < 1) {

final JFileChooser fc = new JFileChooser(".\\"); // 文件夹对话框

fc.showOpenDialog(null); // 打开文件夹对话框

if (fc.getSelectedFile() != null)// 如果选择了具体文件

fa9.setText(fc.getSelectedFile().toString());

}

}

});

fa9.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

file1 = new File(fa9.getText()); // 建立接口参数表文件对象

try { // 读取文件中的内容,如果不空,就初建有关表格

if (file1.exists()) { // 如果文件存在

FileReader fr = new FileReader(file1);// 读方式打开文件

BufferedReader br = new BufferedReader(fr);// 建立文件输入字符流

String tempStr = null;

读入数据.clear(); // 清空列表队列

表格模型 = new DefaultTableModel(表格数据, 列名);

for (int i = 0; (tempStr = br.readLine()) != null; i++) {// 读文件

if ((tempStr != null) && (tempStr.length() > 3)) {

if (tempStr.substring(0, 2).equals("3,")) {

表格模型.addRow(tempStr.substring(2,

tempStr.length()).split("。"));

} else

读入数据.add(tempStr);

}

}

} else {

if (fa9.getText().length() > 0)

file1.createNewFile();// 创建文件

}

} catch (IOException e2) {

JOptionPane.showMessageDialog(null, "打开文件错!");

}

表格 = new JTable(表格模型);

表格.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

scrollPane.setBounds(10, 40, 700, 400);

scrollPane.setViewportView(表格);

scrollPane.getViewport().add(表格, null);

panel3.add(scrollPane, BorderLayout.CENTER);

}

});

表格.addMouseListener(new MouseAdapter() { // 为表格添加鼠标事件监听器

public void mouseClicked(MouseEvent e) { // 发生了点击事件

int 选中行号 = 表格.getSelectedRow(); // 获得被选中行的索引

for (int j = 0; j < 5; j++) {

if (表格模型.getValueAt(选中行号, j) != null)

当前值 = 表格模型.getValueAt(选中行号, j).toString();

else

当前值 = "";

switch (j) {

case 0:

fa1.setText(当前值.toString());

break;

case 1:

fa2.setText(当前值.toString());

break;

case 2:

fa3.setText(当前值.toString());

break;

case 3:

fa4.setText(当前值.toString());

break;

case 4:

fa5.setText(当前值.toString());

break;

}

}

}

});

fl1 = new JLabel("字段名称");

fl1.setBounds(30, 460, 80, 20);

panel3.add(fl1); // 定义文本框的标签

fa1 = new JTextField("", 20); // 定义文本框,预设值

fa1.setBounds(110, 460, 100, 20);

panel3.add(fa1); // 加入文本框

fa1.addFocusListener(new FocusAdapter() { // 加入监听

public void focusGained(final FocusEvent arg0) { // 获得焦点

if ((fa0.getText().toString().length() > 0) && (列数 < 1)) {// 如果已经输入了数据表表名

try {

con = main1.getConn();// 连接数据库

sta = con.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

s1 = "select * from " + fa0.getText(); // 查取全表数据

rs = sta.executeQuery(s1);

rs.last();

rsmd = rs.getMetaData();

列数 = rsmd.getColumnCount(); // 获取列数

列名1 = new String[列数]; // 定义列名数组

列数据宽度 = new int[列数];

当前列号 = 1;

list1.removeAll();

for (int i = 0; i < 列数; i++) {

列名1[i] = rsmd.getColumnName(i + 1); // 获取列名存到数组中

列数据宽度[i] = rsmd.getColumnDisplaySize(i + 1);

list1.add(列名1[i]);

}

rs.close();

sta.close();

con.close();

} catch (SQLException e) {

JOptionPane.showMessageDialog(null, "连接数据库出错!" + s1);

}

} else {

当前列号 = 1;

list1.removeAll();

for (int i = 0; i < 列数; i++) {

list1.add(列名1[i]);

}

}

}

});

fl2 = new JLabel("最大值");

fl2.setBounds(240, 460, 60, 20);

panel3.add(fl2); // 定义文本框的标签

fa2 = new JTextField("", 20); // 定义文本框,预设值

fa2.setBounds(300, 460, 100, 20);

panel3.add(fa2); // 加入文本框

fa2.addFocusListener(new FocusAdapter() { // 加入监听

public void focusGained(final FocusEvent arg0) { // 获得焦点

当前列号 = 2;

list1.removeAll();

}

});

fl3 = new JLabel("最小值");

fl3.setBounds(430, 460, 60, 20);

panel3.add(fl3); // 定义文本框的标签

fa3 = new JTextField("", 20); // 定义文本框,预设值

fa3.setBounds(490, 460, 100, 20);

panel3.add(fa3); // 加入文本框

fa3.addFocusListener(new FocusAdapter() { // 加入监听

public void focusGained(final FocusEvent arg0) { // 获得焦点

当前列号 = 3;

list1.removeAll();

}

});

fl4 = new JLabel("值域");

fl4.setBounds(620, 460, 60, 20);

panel3.add(fl4); // 定义文本框的标签

fa4 = new JTextField("", 20); // 定义文本框,预设值

fa4.setBounds(680, 460, 100, 20);

panel3.add(fa4); // 加入文本框

fa4.addFocusListener(new FocusAdapter() { // 加入监听

public void focusGained(final FocusEvent arg0) { // 获得焦点

当前列号 = 4;

list1.removeAll();

}

});

fl5 = new JLabel("条件表达式");

panel3.add(fl5); // 定义文本框的标签

fa5 = new JTextField("", 20); // 定义文本框,预设值

panel3.add(fa5); // 加入文本框

fl5.setBounds(30, 500, 80, 20);

fa5.setBounds(110, 500, 100, 20);

fa5.addFocusListener(new FocusAdapter() { // 加入监听

public void focusGained(final FocusEvent arg0) { // 获得焦点

当前列号 = 5;

list1.removeAll();

for (int i = 0; i < 列数; i++) {

list1.add(列名1[i]);

}

}

});

list1.setBounds(720, 10, 120, 430); // 列表框大小位置

panel3.add(list1);

list1.addMouseListener(new MouseAdapter() { // 添加鼠标事件监听器

public void mouseClicked(MouseEvent e) {

int w1, w2, h1, h2;

switch (当前列号) { // 根据当前列号确定焦点

case 0: // 表名

fa0.setText(list1.getSelectedItem());

break;

case 1: // 字段名

fa1.setText(list1.getSelectedItem());

字段序号 = list1.getSelectedIndex();

break;

case 2: // 最大值

fa2.setText(list1.getSelectedItem());

break;

case 3: // 最小值

fa3.setText(list1.getSelectedItem());

break;

case 4: // 值域

fa4.setText(list1.getSelectedItem());

break;

case 5: // 条件表达式

fa5.setText(list1.getSelectedItem());

break;

}


}

});

final JButton addButton = new JButton("添加到表格中");

addButton.setBounds(20, 540, 140, 20);

addButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int 选中行号 = -1;

for (int i = 0; i < 表格模型.getRowCount(); i++) {

if ((表格模型.getValueAt(i, 0) != null)

&& (表格模型.getValueAt(i, 0).equals(fa1.getText()))) {

选中行号 = i;

break;

}

}

if (选中行号 < 0) {

String[] rowValues = { fa1.getText(), fa2.getText(),

fa3.getText(), fa4.getText(), fa5.getText() };

表格模型.addRow(rowValues);

int rowCount = 表格.getRowCount() + 1;

fa1.setText("");

fa2.setText("");

fa3.setText("");

fa4.setText("");

fa5.setText("");

} else

JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");

}

});

panel3.add(addButton);

final JButton updButton = new JButton("修改表格数据");

updButton.setBounds(160, 540, 140, 20);

updButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int 选中行号 = -1; // 重复标志

for (int i = 0; i < 表格模型.getRowCount(); i++) {

if ((表格模型.getValueAt(i, 0) != null)

&& (表格模型.getValueAt(i, 0).equals(fa1.getText()))) {

选中行号 = i;

break;

}

}

if (选中行号 >= 0) {

表格模型.setValueAt(fa1.getText(), 选中行号, 0);

表格模型.setValueAt(fa2.getText(), 选中行号, 1);

表格模型.setValueAt(fa3.getText(), 选中行号, 2);

表格模型.setValueAt(fa4.getText(), 选中行号, 3);

表格模型.setValueAt(fa5.getText(), 选中行号, 4);

} else

JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");

}

});

panel3.add(updButton);

final JButton delButton = new JButton("从表格中删除");

delButton.setBounds(300, 540, 130, 20);

delButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int 选中行号 = 表格.getSelectedRow();

if (选中行号 != -1)

表格模型.removeRow(选中行号);

}

});

panel3.add(delButton);

final JButton creButton = new JButton("表格内容存盘");

creButton.setBounds(430, 540, 130, 20);

creButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

char x1 = 10, x2 = 13, x3 = '"', x4 = ',';

file1 = new File(fa9.getText());

FileOutputStream fs;

try {

if (!file1.exists()) {// 如果文件不存在

file1.createNewFile();// 创建文件

}

fs = new FileOutputStream(file1);

for (int i = 0; i < 读入数据.size(); i++) {

fs.write((读入数据.get(i) + x1).getBytes());

}

for (int i = 0; i < 表格模型.getRowCount(); i++) {

String s1 = "3,";

for (int j = 0; j < 5; j++) {

if (表格模型.getValueAt(i, j) != null)

s1 = s1 + 表格模型.getValueAt(i, j).toString()

+ "。";

else

s1 = s1 + "。";

}

fs.write((s1 + x1).getBytes());

}

fs.close();

} catch (IOException e2) {

JOptionPane.showMessageDialog(null, "写文件错。");

}

}

});

panel3.add(creButton);

final JButton clearButton = new JButton("清参数文本框");

clearButton.setBounds(560, 540, 130, 20);

clearButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

fa1.setText("");

fa2.setText("");

fa3.setText("");

fa4.setText("");

fa5.setText("");

}

});

panel3.add(clearButton);

final JButton exitButton = new JButton("退出");

exitButton.setBounds(690, 540, 130, 20);

exitButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

panel3.setVisible(false);

frame3.setVisible(false);

System.exit(0);

}

});

panel3.add(exitButton);

frame3.add(panel3);

frame3.setVisible(true);

}

   }



76.源码76,公共程序,为数据维护部件设置控件选择与布局数据。

/*

 * 程序文件名:deviseTool.java

 * 作者:程学先 

 * 功能:为数据维护部件设置控件选择与布局数据。

 * 所有参数以字符个数为单位,辅助计算后变换为象素单位。

 * 在程序中设置的宽、高、左边距、到顶距等待填入字符单位数据再根据字号计算其象素单位值

 * 除大数据类型外,一般字段高都应填:1,即1个字符高,实际象素高要根据字号计算

 * 标签宽、字段宽应当为所定义的字符个数,实际象素宽约等于字号。

 * 所有数据保存在一个文件中,该文件可以包括控件位置大小参数、安全性要求参数、完整性参数等三组内容,

 * 每组内容第一个数据标志组类型,1表示控件位置大小参数;2表示安全性要求参数;3表示完整性参数。

 * 参数部分每行填该组一条记录数据,参数间用逗号分隔

 * 设置各控件位置大小参数一条记录包括:

 *   0     1    2   3      4    5    6    7    8   9

 * 字段名称、行号、列号、标签宽、字段宽度  高、左边距、到顶距、字体、字号、

 *  10    11

 * 颜色、原纪录序号等11个参数

 * 程序提供辅助布局功能,如果按下“辅助布局”按钮,操作结果将替代已经输入的所有边距、宽、高、到顶距等数字。

 * 因此,如果准备辅助布局,请事先不要输入上述数据。

 * 辅助布局要求先按从上到下、从左到右输入各字段的名字、行号与列号、字号。

 * 大数据类型还得输入自己的高、宽。仍以字符个数为单位。布局之后各参数改以象素点数为单位。

 * 在一行内如果安排大数据类型的控件且不只一个,要求等高、等到顶距、等字号且连在一起。

 * (二个大数据类型的控件中间除标签外没有其他控件)

 * 要求每行内数据统一字号。如果非大数据类型控件与大数据类型控件同行,要求统一字号,

 * 如果非大数据类型数据在大数据类型数据左边,列号从1起计数;

 * 如果非大数据类型数据在大数据类型数据右边,列号从2或3起开始计数。

 * 操作自动布局前,请一定检查上述内容都已经输入后再点击辅助计算。

 * 本算法优先考虑大数据类型字段数据位置与大小,之后将其他字段顺序填入

 * 从上到下安排,一个字段如果不是当行第一个字段并且安排得下就予安排。

 * 如果不是第一个字段,当行安排不下,就移到下一行安排,如果仍然安排不下,将截取到能安排为止。

 * 当全部安排之后,首先将第一列标签统一宽,使某些行总宽可能加大,通过调整面板宽解决。

 * 如果已经无法通过调整面板宽解决,将要求修改设置。

 * 最后,统一每一行右边对齐,将每行最右一个字段宽加大使总的行宽等于最大行宽。

 * 设计完成存盘之前,请检查每行最大宽、高要在屏幕范围内,避免超出屏幕范围。

 * 实际窗口大小将依照输入数据情况自动设置。

 * 采用高超过1个字符的文本域控件的字段的数据类型必须为ntext或text(建议采用text,否则易见乱码)。

 * 本布局可在单记录数据维护6中使用。

 * 格式文件格式例如:

 * 1,学号。1。1。39。90。18。0。0。宋体。9。5。

 * 1,姓名。1。2。39。90。18。129。0。宋体。9。5。

 * 1,相片。1。3。19。540。180。258。0。宋体。9。5。

 * 1,性别。2。1。39。18。18。0。18。宋体。9。5。

 * 1,简历。11。1。39。778。54。0。180。宋体。9。5。

 * 3,性别。。。男,女。。

 * 3,年龄。0。0。。年龄<60 and 年龄>20。

 * 2,SA。。i,u,q,。

 * 最前面(逗号前)数字表示该行数据意义,1为布局数据;2为完整性约束;3为安全性设置

 * 数据除第一个逗号外用中文句号分隔,布局数据依次为:字段名,行号,列号,标签宽度,

 * 字段宽度,高度,左边距,到顶距,字体,字号,颜色

 * 2为安全性约束,数据依次为用户名、字段名、权限:i读u改q删a全部s查

 * 3为完整性约束,数据依次为:字段名、最大值、最小值、值域、条件表达式。

 */

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;

import javax.swing.tree.DefaultMutableTreeNode;

import java.io.*;

import java.sql.Connection;

import java.sql.DatabaseMetaData;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.Vector;


public class deviseTool extends JFrame {

private static deviseTool frame1 = new deviseTool();

private static JPanel panel1 = new JPanel(); // 定义面板

private static DefaultTableModel 表格模型; // 定义表格模型对象

private static JTable 表格; // 定义表格对象

private static JScrollPane scrollPane = new JScrollPane(); // 定义表格滚动条

private static List list1 = new List();

private static JLabel fl0, fl1, fl2, fl3, fl4, fl5, fl6, fl7, fl8, fl9,

fl10, fl11, fl12;

private static JTextField fa0, fa1, fa2, fa3, fa4, fa5, fa6, fa7, fa8, fa9,

fa10, fa11, fa12;

private static String 文件名 = "";

private static String 数据表名 = "";

private static String 当前值;

private static int 当前列号 = 0, 列数 = 0;

private static int 字段序号 = 0;

private static String[][] 表格数据;

private static String[][] 表格数据1 = new String[100][11];

private static String[] 列名1; // 数据表中列名

private static String[] 列数据类型;

private static int[] 列数据宽;

private static int[][] 允许最大宽度;

private static File file1;

static Connection con; // 连接数据库

static String url;

static String DBMS系统 = "sqlserver";

static String ODBC数据源 = "sql1";

private static Statement sta; // 连接数据库

static String s1 = "", s2 = "";

static int[] 每行总宽, 大类前宽;

private static ResultSet rs; // 数据库数据集

private static ResultSetMetaData rsmd;

private static ArrayList 表名1 = new ArrayList();

private static String[] 列名 = { "字段名称", "行号", "列号", "标签宽", "字段宽", "高",

"左边距", "到顶距", "字体", "字号", "颜色" };


public static void main(String args[]) {

文件名 = "";

数据表名 = "";

frame1.setTitle("请先填字段名、行号、字号,非文本框类需填宽、高,高填其中第一行高,再按辅助计算,高、宽以字符个数为单位。距离以象素为单位。 作者:程学先");

frame1.setBounds(10, 10, 1000, 660);

frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);


panel1.setBounds(10, 10, 1000, 660);

panel1.setLayout(null);


main1.driver1();

fl0 = new JLabel("数据表名");

fl0.setBounds(40, 10, 80, 20);

panel1.add(fl0);

fa0 = new JTextField(数据表名);

fa0.setBounds(130, 10, 100, 20);

panel1.add(fa0);

fa0.addFocusListener(new FocusAdapter() { // 加入数据表名监听

public void focusGained(final FocusEvent arg0) {

当前列号 = 0;

list1.removeAll();

if (表名1.size() < 1) {

try {

con = main1.getConn();// 连接数据库

String[] tableType = { "TABLE" };


DatabaseMetaData databaseMetaData = con.getMetaData();

ResultSet resultSet = databaseMetaData.getTables(null,

null, "%", tableType);

while (resultSet.next()) {

表名1.add(resultSet.getString("TABLE_NAME"));

}

} catch (Exception e) {

e.printStackTrace();

}

}

for (int i = 0; i < 表名1.size(); i++)

list1.add(表名1.get(i).toString());

}

});


fl10 = new JLabel("文件名");

fl10.setBounds(250, 10, 50, 20);

panel1.add(fl10);

fa10 = new JTextField(文件名, 20);

fa10.setBounds(300, 10, 100, 20);

panel1.add(fa10);


fa10.addMouseListener(new MouseAdapter() {// 如果未先指定文件名

public void mouseClicked(MouseEvent e) {

int c = 0;

int k = 表格模型.getRowCount(); // 如果表格中已经有内容

for (int i = 0; i < k; i++) { // 先清除全部内容

表格模型.removeRow(0);

}

final JFileChooser fc = new JFileChooser(".\\");

fc.showOpenDialog(null);

if (fc.getSelectedFile() != null) {

fa10.setText(fc.getSelectedFile().toString());

file1 = new File(fa10.getText());

try {

if (file1.exists()) {

FileReader fr = new FileReader(file1);

BufferedReader br = new BufferedReader(fr);

String tempStr = null;

String[] s0;

for (int i = 0; (tempStr = br.readLine()) != null; i++) {// 读文件

if ((tempStr != null) && (tempStr.length() > 3)) {

if (tempStr.substring(0, 2).equals("1,")) {

s0 = tempStr.substring(2,

tempStr.length()).split("。");

表格模型.addRow(tempStr.substring(2,

tempStr.length()).split("。"));

}

}

c = i;

}

}

} catch (IOException e2) {

JOptionPane.showMessageDialog(null, "打开文件错!");

}

}

}

});


表格模型 = new DefaultTableModel(表格数据, 列名);

表格 = new JTable(表格模型);

表格.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);// 设置表格的选择模式为单选


读取文件内容();

表格.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

int 选中行号 = 表格.getSelectedRow();

for (int j = 0; j < 11; j++) {

if (表格模型.getValueAt(选中行号, j) != null)

当前值 = 表格模型.getValueAt(选中行号, j).toString(); // 从表格模型中获得指定值

else

当前值 = "";

switch (j) {

case 0:

fa1.setText(当前值.toString());

break;

case 1:

fa11.setText(当前值.toString());

break;

case 2:

fa12.setText(当前值.toString());

break;

case 3:

fa2.setText(当前值.toString());

break;

case 4:

fa3.setText(当前值.toString());

break;

case 5:

fa4.setText(当前值.toString());

break;

case 6:

fa5.setText(当前值.toString());

break;

case 7:

fa6.setText(当前值.toString());

break;

case 8:

fa7.setText(当前值.toString());

break;

case 9:

fa8.setText(当前值.toString());

break;

case 10:

fa9.setText(当前值.toString());

break;

}

}

}

});

scrollPane.setBounds(10, 40, 800, 400);

scrollPane.setViewportView(表格);

panel1.add(scrollPane, BorderLayout.CENTER);


fl1 = new JLabel("字段名称");

fl1.setBounds(30, 460, 80, 20);

panel1.add(fl1);

fa1 = new JTextField("", 20);

fa1.setBounds(110, 460, 100, 20);

panel1.add(fa1);

fa1.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

if ((fa0.getText().toString().length() > 0) && (列数 < 1)) {

try {

con = main1.getConn();// 连接数据库


sta = con.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);


s1 = "select * from " + fa0.getText();

rs = sta.executeQuery(s1);


rs.last();

rsmd = rs.getMetaData();


列数 = rsmd.getColumnCount();

列名1 = new String[列数];

列数据类型 = new String[列数];

列数据宽 = new int[列数];

当前列号 = 1;

list1.removeAll();


for (int i = 0; i < 列数; i++) {

列名1[i] = rsmd.getColumnName(i + 1);

列数据类型[i] = rsmd.getColumnTypeName(i + 1);

列数据宽[i] = rsmd.getColumnDisplaySize(i + 1);

list1.add(列名1[i]);

}

rs.close();

sta.close();

con.close();

} catch (SQLException e) {

JOptionPane.showMessageDialog(null, "连接数据库出错!" + s1);

}


} else {

当前列号 = 1;

list1.removeAll();

for (int i = 0; i < 列数; i++) {

list1.add(列名1[i]);

}

}

}

});


fl11 = new JLabel("行号");

fl11.setBounds(220, 460, 60, 20);

panel1.add(fl11);

fa11 = new JTextField("", 20);

fa11.setBounds(280, 460, 60, 20);

panel1.add(fa11);

fa11.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 10;

list1.removeAll();

}

});


fl12 = new JLabel("列号");

fl12.setBounds(350, 460, 60, 20);

panel1.add(fl12);

fa12 = new JTextField("", 20);

fa12.setBounds(410, 460, 60, 20);

panel1.add(fa12);

fa12.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 11;

list1.removeAll();

}

});


fl2 = new JLabel("标签宽");

fl2.setBounds(480, 460, 60, 20);

panel1.add(fl2);

fa2 = new JTextField("", 20);

fa2.setBounds(540, 460, 60, 20);

panel1.add(fa2);

fa2.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 2;

list1.removeAll();

s2 = ",";

for (int i = 0; i < 表格模型.getRowCount(); i++) {

if (表格模型.getValueAt(i, 当前列号) != null)

if (s2.lastIndexOf(","

+ 表格模型.getValueAt(i, 当前列号).toString() + ",") < 0) {

list1.add(表格模型.getValueAt(i, 当前列号).toString());

s2 = s2 + 表格模型.getValueAt(i, 当前列号).toString() + ",";

}

}

}

});


fl3 = new JLabel("字段宽");

fl3.setBounds(610, 460, 60, 20);

panel1.add(fl3);

fa3 = new JTextField("", 20);

fa3.setBounds(670, 460, 60, 20);

panel1.add(fa3);

fa3.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 3;

list1.removeAll();

}

});


fl4 = new JLabel("  高");

fl4.setBounds(740, 460, 60, 20);

panel1.add(fl4);

fa4 = new JTextField("", 20);

fa4.setBounds(800, 460, 60, 20);

panel1.add(fa4);

fa4.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 4;

list1.removeAll();

}

});


fl5 = new JLabel(" 左边距");

fl5.setBounds(30, 500, 80, 20);

panel1.add(fl5);

fa5 = new JTextField("", 20);

fa5.setBounds(110, 500, 100, 20);

panel1.add(fa5);

fa5.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 5;

list1.removeAll();

}

});


fl6 = new JLabel("到顶距");

panel1.add(fl6);

fa6 = new JTextField("", 20);

panel1.add(fa6);

fl6.setBounds(220, 500, 60, 20);

fa6.setBounds(280, 500, 60, 20);

fa6.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 6;

list1.removeAll();

}

});


fl7 = new JLabel(" 字体");

panel1.add(fl7);

fa7 = new JTextField("", 20);

panel1.add(fa7);

fl7.setBounds(350, 500, 60, 20);

fa7.setBounds(410, 500, 120, 20);

final String[] 字体 = { "宋体", "楷体", "黑体", "仿宋_GB2312" };

fa7.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 7;

list1.removeAll();

for (int i = 0; i < 字体.length; i++) {

list1.add(字体[i]);

}

}

});


fl8 = new JLabel("字号");

panel1.add(fl8);

fa8 = new JTextField("", 20);

panel1.add(fa8);

fl8.setBounds(540, 500, 60, 20);

fa8.setBounds(600, 500, 100, 20);

fa8.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 8;

list1.removeAll();

final String[] 字号 = { "5", "6", "7", "8", "9", "10", "11",

"12", "14", "16", "18", "20", "22", "24", "26", "28",

"36", "48", "72" };

for (int i = 0; i < 字号.length; i++) {

list1.add(字号[i]);

}

}

});


fl9 = new JLabel("颜色");

panel1.add(fl9);

fa9 = new JTextField("", 20);

panel1.add(fa9);

fl9.setBounds(710, 500, 60, 20);

fa9.setBounds(770, 500, 90, 20);

final String[] color1 = { "1        red红色", "2     blue蓝色",

"3    green绿色", "4     white白色", "5    black黑色",

"6   darkGray深灰色", "7     cyan青色", "8     yellow黄色",

"9   gray灰色", "10    lightGray浅灰色", "11    magenta品红",

"12    orange桔黄色" };

fa9.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 9;

list1.removeAll();

for (int i = 0; i < color1.length; i++) {

list1.add(color1[i]);

}

}

});

fa1.setText("");

fa2.setText("0");

fa3.setText("0");

fa4.setText("0");

fa5.setText("0");

fa6.setText("0");

fa7.setText("宋体");

fa8.setText("0");

fa9.setText("");

fa11.setText("0");

fa12.setText("0");

每行总宽 = new int[100];

大类前宽 = new int[100];


list1.setBounds(840, 10, 120, 430);

panel1.add(list1);

list1.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

switch (当前列号) {

case 0:

fa0.setText(list1.getSelectedItem());

break;

case 1:

fa1.setText(list1.getSelectedItem());

字段序号 = list1.getSelectedIndex();

fa2.setText("" + 列名1[字段序号].length());

if ((",ntext,text,memo,image,long,lob,blob,clob,ole,varbinary,varchar,nvarchar,xml"

.lastIndexOf("," + 列数据类型[字段序号])) < 0) {

fa3.setText("" + 列数据宽[字段序号]);

fa4.setText("1");

}

fa7.setText("宋体");

fa8.setText("12");

fa9.setText("5");

break;

case 2:

fa2.setText(list1.getSelectedItem());

break;

case 3:

fa3.setText(list1.getSelectedItem());

break;

case 4:

fa4.setText(list1.getSelectedItem());

break;

case 5:

fa5.setText(list1.getSelectedItem());

break;

case 6:

fa6.setText(list1.getSelectedItem());

break;

case 7:

fa7.setText(list1.getSelectedItem());

break;

case 8:

fa8.setText(list1.getSelectedItem());

break;

case 9:

fa9.setText(list1.getSelectedItem().substring(0, 5).trim());

break;

case 10:

fa11.setText(list1.getSelectedItem());

break;

case 11:

fa12.setText(list1.getSelectedItem());

break;

}


}

});

final JButton addButton = new JButton("添加到表格中");

addButton.setBounds(50, 540, 120, 20);

addButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {


int 选中行号 = -1;

if ((fa11.getText().compareTo("0") < 1)

|| (fa12.getText().compareTo("0") < 1)) {

JOptionPane.showMessageDialog(null, "请填全行号与列号!");

return;

}

if ((((",ntext,text,memo,image,long,lob,blob,clob,ole,varbinary,varchar,nvarchar,xml"

.lastIndexOf("," + 列数据类型[字段序号])) > 0) || (列数据宽[字段序号] > 50))

&& ((fa3.getText().compareTo("0") < 1) || (fa4

.getText().compareTo("0") < 1))) {

JOptionPane.showMessageDialog(null, "大数据类型需要填宽与高字符数!");

return;

}

for (int i = 0; i < 表格模型.getRowCount(); i++) {

if ((表格模型.getValueAt(i, 0) != null)

&& (表格模型.getValueAt(i, 0).equals(fa1.getText()))) {

选中行号 = i;

break;

}

}

int 当前行号 = Integer.valueOf(fa11.getText());

int w1 = Integer.valueOf(fa2.getText());

int w2 = Integer.valueOf(fa3.getText());

int no1 = Integer.valueOf(fa8.getText());

int h1 = Integer.valueOf(fa4.getText());

if ((每行总宽[当前行号] + w1 + w2) * no1 > 1500) {

JOptionPane.showMessageDialog(null,

"本行总宽设计将超过1500,请检查并限制其宽!");

return;

}

if (选中行号 < 0) {

String[] rowValues = { fa1.getText(), fa11.getText(),

fa12.getText(), fa2.getText(), fa3.getText(),

fa4.getText(), fa5.getText(), fa6.getText(),

fa7.getText(), fa8.getText(), fa9.getText() };

if ((h1 > 1) && (Integer.valueOf(fa12.getText()) > 1)) {


if (大类前宽[当前行号] < 1) {

大类前宽[当前行号] = 每行总宽[当前行号];


for (int k = 1; k < h1; k++) {

大类前宽[当前行号 + k] = 大类前宽[当前行号];

}

}

}


表格模型.addRow(rowValues);


每行总宽[当前行号] = 每行总宽[当前行号] + w1 + w2;

fa1.setText("");

fa2.setText("0");

fa3.setText("0");

fa4.setText("0");

fa5.setText("0");

fa6.setText("0");

fa7.setText("宋体");

fa8.setText("0");

fa9.setText("");

fa11.setText("0");

fa12.setText("0");

} else

JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");

}

});

panel1.add(addButton);


final JButton updButton = new JButton("修改表格数据");

updButton.setBounds(170, 540, 120, 20);

updButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int 选中行号 = -1;

for (int i = 0; i < 表格模型.getRowCount(); i++) {

if ((表格模型.getValueAt(i, 0) != null)

&& (表格模型.getValueAt(i, 0).equals(fa1.getText()))) {

选中行号 = i;

break;

}

}

if (选中行号 >= 0) {


表格模型.setValueAt(fa1.getText(), 选中行号, 0);

表格模型.setValueAt(fa11.getText(), 选中行号, 1);

表格模型.setValueAt(fa12.getText(), 选中行号, 2);

表格模型.setValueAt(fa2.getText(), 选中行号, 3);

表格模型.setValueAt(fa3.getText(), 选中行号, 4);

表格模型.setValueAt(fa4.getText(), 选中行号, 5);

表格模型.setValueAt(fa5.getText(), 选中行号, 6);

表格模型.setValueAt(fa6.getText(), 选中行号, 7);

表格模型.setValueAt(fa7.getText(), 选中行号, 8);

表格模型.setValueAt(fa8.getText(), 选中行号, 9);

表格模型.setValueAt(fa9.getText(), 选中行号, 10);

} else

JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");

}

});

panel1.add(updButton);


final JButton delButton = new JButton("从表格中删除");

delButton.setBounds(290, 540, 120, 20);

delButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int 选中行号 = 表格.getSelectedRow();

if (选中行号 != -1)

表格模型.removeRow(选中行号);

}

});

panel1.add(delButton);


final JButton countButton = new JButton("辅助计算");

countButton.setBounds(410, 540, 120, 20);

countButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String[] 一条记录 = new String[11];

int 高 = 0, 行 = 0, 列 = 0;

int 大数据高度 = 0;

int 总行数 = 0;

int[] 第i行标志1 = new int[150];

int[] 第i行标志2 = new int[150];

int 标签宽度 = 0;

for (int i = 0; i < 表格模型.getRowCount(); i++) {

列 = Integer.valueOf(表格模型.getValueAt(i, 2).toString());

if ((列 == 1)

&& (Integer.valueOf(表格模型.getValueAt(i, 3)

.toString()) > 标签宽度))

标签宽度 = Integer

.valueOf(表格模型.getValueAt(i, 3).toString());

}

for (int i = 0; i < 表格模型.getRowCount(); i++) {

if (Integer.valueOf(表格模型.getValueAt(i, 2).toString()) == 1) {

表格模型.setValueAt("" + 标签宽度, i, 3);

}

}


for (int i = 0; i < 表格模型.getRowCount(); i++) {

高 = Integer.valueOf(表格模型.getValueAt(i, 5).toString());

行 = Integer.valueOf(表格模型.getValueAt(i, 1).toString());

列 = Integer.valueOf(表格模型.getValueAt(i, 2).toString());

if (行 > 总行数)

总行数 = 行;

if (高 > 1) {

for (int j = 1; j < 11; j++)

一条记录[j] = 表格模型.getValueAt(i, j).toString();

if ((列 == 1) || (列 == 2 && 第i行标志1[行] == 1)) {

if (第i行标志1[行] == 0)

第i行标志1[行] = 1;

for (int j = 1; j < 高; j++) {

一条记录[2] = "0";

一条记录[1] = (行 + j) + "";

if (行 + j > 总行数)

总行数 = 行 + j;

一条记录[5] = "1";

表格模型.addRow(一条记录);

}

} else {

if (第i行标志1[行] == 0)

第i行标志1[行] = 行 + 1;

第i行标志2[行] = 高;

for (int j = 1; j < 高; j++) {

一条记录[2] = "98";

一条记录[1] = (行 + j) + "";

第i行标志2[行 + j] = 高;

if (行 + j > 总行数)

总行数 = 行 + j;

一条记录[5] = "1";

表格模型.addRow(一条记录);

}

}

}

}


int 数据条数 = 表格模型.getRowCount();

String[][] 数据 = new String[数据条数][15];

int[][] 数据1 = new int[数据条数][15];

int n1 = 0;

for (int i = 0; i < 数据条数; i++) {

for (int j = 0; j < 11; j++) {

if (表格模型.getValueAt(i, j) != null) {

数据[i][j] = 表格模型.getValueAt(i, j).toString();

} else

数据[i][j] = "0";

s2 = 数据[i][j].trim();

if ((j > 0) && (j < 8) || (j == 9))

if ((s2 == null) || (s2.length() < 1))

数据1[i][j] = 0;

else

数据1[i][j] = Integer.valueOf(s2);

;

}

数据[i][11] = "" + i;

数据1[i][11] = i;

}


String trim = "";

int trim1 = 0;

for (int i = 0; i < 数据条数 - 1; i++) {

for (int j = 0; j < 数据条数 - 1 - i; j++) {

if (数据1[j][1] * 100 + 数据1[j][2] > 数据1[j + 1][1] * 100

+ 数据1[j + 1][2]) {

for (int k = 0; k < 15; k++) {

trim = 数据[j][k];

trim1 = 数据1[j][k];

数据[j][k] = 数据[j + 1][k];

数据1[j][k] = 数据1[j + 1][k];

数据[j + 1][k] = trim;

数据1[j + 1][k] = trim1;

}

}

}

}


int[] 第i行列数 = new int[总行数 + 1];

int[] 第i行宽度 = new int[总行数 + 1];

int[] 第i行末列序号 = new int[数据1.length];

int kuand = 0;

for (int i = 0; i < 数据1.length; i++) {

行 = 数据1[i][1];

列 = 数据1[i][2];

if (第i行标志2[行] > 0) {

if ((列 < 98) && (数据1[i][5] < 2)) {

if (列 > 第i行列数[行]) {

第i行列数[行] = 列;

第i行末列序号[行] = i;

}

第i行宽度[行] = 第i行宽度[行] + 数据1[i][3] + 数据1[i][4];

if (第i行宽度[行] > kuand)

kuand = 第i行宽度[行];

}

}

}


for (int i = 0; i < 数据1.length; i++) {

行 = 数据1[i][1];

列 = 数据1[i][2];

if (第i行标志2[行] > 0) {

for (int k1 = 1; k1 <= 总行数; k1++) {

if ((第i行末列序号[k1] > 0) && (第i行末列序号[k1] == i)) {

数据1[i][4] = 数据1[i][4] + kuand - 第i行宽度[k1];

break;

}

}

}

}


第i行列数 = new int[总行数 + 1];

第i行宽度 = new int[总行数 + 1];

第i行末列序号 = new int[数据1.length];

kuand = 0;

for (int i = 0; i < 数据1.length; i++) {

行 = 数据1[i][1];

列 = 数据1[i][2];

if (列 >= 第i行列数[行]) {

第i行列数[行] = 列;

第i行末列序号[行] = i;

}

第i行宽度[行] = 第i行宽度[行] + 数据1[i][3] + 数据1[i][4];

if (第i行宽度[行] > kuand) {

kuand = 第i行宽度[行];

}

}


for (int k1 = 0; k1 <= 总行数; k1++) {

int k3 = 第i行末列序号[k1];

if (k3 > 0) {

数据1[k3][4] = 数据1[k3][4] + kuand - 第i行宽度[k1];

}


}


int m1 = 0;

行 = 0;

for (int i = 0; i < 数据1.length; i++) {

if (数据1[i][1] != 行) {

行 = 数据1[i][1];

m1 = 0;

}

数据1[i][6] = m1;

m1 = m1 + 数据1[i][3] + 数据1[i][4];

数据1[i][7] = 数据1[i][1] - 1;

}


表格模型.setRowCount(0);

for (int i = 0; i < 数据1.length; i++) {

if ((数据1[i][2] > 0) && (数据1[i][2] < 98)) {

数据[i][1] = 数据1[i][1] + "";

数据[i][2] = 数据1[i][2] + "";

数据[i][3] = 数据1[i][3] * 数据1[i][9] + "";

数据[i][4] = 数据1[i][4] * 数据1[i][9] + "";

数据[i][5] = (int) (数据1[i][5] * 数据1[i][9] * 2) + "";

数据[i][6] = 数据1[i][6] * 数据1[i][9] + "";

数据[i][7] = (int) (数据1[i][7] * 数据1[i][9] * 2) + "";

表格模型.addRow(数据[i]);

}

}

}

});

panel1.add(countButton);


final JButton creButton = new JButton("表格内容存盘");

creButton.setBounds(530, 540, 120, 20);

creButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

char x1 = 10; // 回车

file1 = new File(fa10.getText());

if (!file1.exists()) {// 如果文件不存在

try {

file1.createNewFile();// 创建文件

} catch (IOException e1) {

e1.printStackTrace();

}

}

try {

int k1 = 0;

String[] s6 = new String[100];

FileReader fr = new FileReader(file1);

BufferedReader br = new BufferedReader(fr);

String tempStr = null;

for (int i = 0; (tempStr = br.readLine()) != null; i++) {// 读文件

if (!tempStr.substring(0, 2).equals("1,")) {

s6[k1] = tempStr;

k1++;

}

}

FileOutputStream fs;

fs = new FileOutputStream(file1);

for (int i = 0; i < k1; i++)

fs.write((s6[i] + x1).getBytes());

for (int i = 0; i < 表格模型.getRowCount(); i++) {

String s3 = "1,";

for (int j = 0; j < 11; j++) {

if ((表格模型.getValueAt(i, j) != null)

&& (表格模型.getValueAt(i, j).toString()

.length() > 0))

s3 = s3 + 表格模型.getValueAt(i, j).toString()

+ "。";

else

s3 = s3 + " 。";

}

fs.write((s3 + x1).getBytes());

}

fs.close();

} catch (IOException e2) {

JOptionPane.showMessageDialog(null, "写文件错。");

}

}

});

panel1.add(creButton);


final JButton clearButton = new JButton("清参数文本框");

clearButton.setBounds(650, 540, 120, 20);

clearButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

fa1.setText("");

fa2.setText("0");

fa3.setText("0");

fa4.setText("0");

fa5.setText("0");

fa6.setText("0");

fa7.setText("宋体");

fa8.setText("0");

fa9.setText("");

fa11.setText("0");

fa12.setText("0");

}

});

panel1.add(clearButton);


final JButton exitButton = new JButton("退出");

exitButton.setBounds(770, 540, 120, 20);

exitButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

panel1.setVisible(false);

frame1.setVisible(false);

System.exit(0);

}

});


panel1.add(exitButton);


frame1.add(panel1);

frame1.setVisible(true); // 安装窗口

}


public static void 读取文件内容() {

if (fa10.getText().length() > 0) {

file1 = new File(fa10.getText());

try {

if (file1.exists()) {

FileReader fr = new FileReader(file1);

BufferedReader br = new BufferedReader(fr);

String tempStr = null;

String[] s0;

for (int i = 0; (tempStr = br.readLine()) != null; i++) {// 读文件

if (tempStr.substring(0, 2).equals("1,")) {

s0 = tempStr.substring(2, tempStr.length()).split(

"。");

表格模型.addRow(tempStr.substring(2, tempStr.length())

.split("。"));

}

}

}

} catch (IOException e2) {

JOptionPane.showMessageDialog(null, "打开文件错!");

}

}

}

  }

77.源码77,公共程序,为数据维护程序设置安全性控制条件。

/*

 * 程序文件名:secureTool.java

 * 作者:程学先 

 * 功能:为数据维护程序设置安全性控制条件。

 * 设置安全性控制一条记录包括:用户名称、字段号、权限等3个参数

 * 用户名称根据登录程序输入的名字检查。以数据表为控制单位。

 * 字段号填写该用户对该表所不能操作的字段的顺序号。

 * 权限标志包括:i、u、d、q、a等分别标志拥有录入、修改、删除、查询、全部权限。

 * 2为安全性约束,数据依次为用户名、字段名、权限:i录入、u改、d删、a全部、q查

 * 注意一个字段可以有多个权限,之间用逗号分隔,例如i,u,表示有录入和修改权,

 * 一个字段全部权限必须写在一行内

 * 字段号内容为空表示所有字段,也就是对全部表控制,将控制选择按钮

 * 所有数据保存在一个文件中,该文件可以包括控件位置大小参数、安全性要求参数、完整性参数等三组内容,

 * 每组内容第一个数据标志类型,1表示控件位置大小参数;2表示安全性要求参数

 * 3表示完整性参数。

 * 如果定义了安全性控制条件,就将针对登录者进行权限检查并给以控制。

 * 注意必须给每一位操作者授予权限。

 * 如果针对表定义权限,将屏蔽登录者无权操作的按钮。

 * 如果针对字段定义权限,将在存盘时检查权限并给予控制。

 * 如果接口参数表中没有安全性控制条件,则将不与控制。

 * 需要说明的是,这一组程序采用本地文件保存有关参数,文件本身易被读取,因此,

 * 具体应用系统建议由数据库保存有关参数。

 */

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;

import javax.swing.tree.DefaultMutableTreeNode;

import java.io.*;

import java.sql.Connection;

import java.sql.DatabaseMetaData;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.Vector;


public class secureTool extends JFrame {

private static secureTool frame2 = new secureTool();

private static JPanel panel2 = new JPanel(); // 定义面板

private static DefaultTableModel 表格模型; // 定义表格模型对象

private static JTable 表格;

private static JScrollPane scrollPane = new JScrollPane();

private static JScrollPane scrollPane1 = new JScrollPane();

private static List list1 = new List();

private static JLabel fl0, fl1, fl2, fl3, fl9;

private static JTextField fa0, fa1, fa2, fa3, fa9;

private static String 当前值;

private static int 选中行号 = -1, 当前行号 = 0, 表格行数 = 0, 当前列号 = 0, 列数 = 0;

private static int 字段序号 = 0;

private static String[][] 表格数据;

private static ArrayList<String> 读入数据 = new ArrayList();

private static String[] 列名1;

private static int[] 列数据宽度;

private static String[] 一行数据 = new String[3];

private static File file1;

private static ArrayList<String> list = new ArrayList<String>();

static Connection con;

static String url;

static String DBMS系统 = "sqlserver";

static String ODBC数据源 = "sql1";

private static Statement sta;

static String s1 = "", s2 = "";

private static ResultSet rs;

private static ResultSetMetaData rsmd;

private static ArrayList 表名1 = new ArrayList();


public static void main(String args[]) {

frame2 = new secureTool();

panel2 = new JPanel(); // 定义面板

scrollPane = new JScrollPane();

scrollPane1 = new JScrollPane();

list1 = new List();

选中行号 = -1;

当前行号 = 0;

表格行数 = 0;

当前列号 = 0;

列数 = 0;

字段序号 = 0;

读入数据 = new ArrayList();

一行数据 = new String[3];

list = new ArrayList<String>();

DBMS系统 = "sqlserver";

ODBC数据源 = "sql1";

s1 = "";

s2 = "";

表名1 = new ArrayList();

frame2.setTitle("许可字段号填写该用户对该表所能操作的字段的顺序号。权限标志包括:i、u、d、q、a等。    作者:程学先");

frame2.setBounds(10, 10, 880, 660);

frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

panel2.setBounds(10, 10, 880, 660);

panel2.setLayout(null);

String[] 列名 = { "用户名称", "表名或字段号", "权限" };

main1.driver1();

fl0 = new JLabel("数据表名");

fl0.setBounds(40, 10, 80, 20);

panel2.add(fl0);

fa0 = new JTextField("");

fa0.setBounds(130, 10, 100, 20);

panel2.add(fa0);

fa0.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 0;

list1.removeAll();

if (表名1.size() < 1) {

try {

con = main1.getConn();

String[] tableType = { "TABLE" };

DatabaseMetaData databaseMetaData = con.getMetaData();

ResultSet resultSet = databaseMetaData.getTables(null,

null, "%", tableType);

while (resultSet.next()) {

表名1.add(resultSet.getString("TABLE_NAME"));

}

} catch (Exception e) {

e.printStackTrace();

}

}

for (int i = 0; i < 表名1.size(); i++)

list1.add(表名1.get(i).toString());

}

});

fl9 = new JLabel("文件名");

fl9.setBounds(250, 10, 50, 20);

panel2.add(fl9);

fa9 = new JTextField("", 20);

fa9.setBounds(300, 10, 100, 20);

panel2.add(fa9);

fa9.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

if (fa9.getText().length() < 1) {

final JFileChooser fc = new JFileChooser(".\\");

fc.showOpenDialog(null);

if (fc.getSelectedFile() != null)

fa9.setText(fc.getSelectedFile().toString());

}

}

});

fa9.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

file1 = new File(fa9.getText());

try {

if (file1.exists()) { // 如果文件存在

FileReader fr = new FileReader(file1);

BufferedReader br = new BufferedReader(fr);

String tempStr = null;

读入数据.clear();

for (int i = 0; (tempStr = br.readLine()) != null; i++) {

if ((tempStr != null) && (tempStr.length() > 3)) {

if (tempStr.substring(0, 2).equals("2,")) {

表格模型.addRow(tempStr.substring(2,

tempStr.length()).split("。"));

} else

读入数据.add(tempStr);

}

}

} else if (fa9.getText().length() > 0)

file1.createNewFile();// 创建文件

} catch (IOException e2) {

JOptionPane.showMessageDialog(null, "打开文件错!");

}

}

});

表格模型 = new DefaultTableModel(表格数据, 列名);

表格 = new JTable(表格模型);

表格.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

表格.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

int 选中行号 = 表格.getSelectedRow();

for (int j = 0; j < 3; j++) {

if (表格模型.getValueAt(选中行号, j) != null)

当前值 = 表格模型.getValueAt(选中行号, j).toString();

else

当前值 = "";

switch (j) {

case 1:

fa1.setText(当前值.toString());

break;

case 2:

fa2.setText(当前值.toString());

break;

case 3:

fa3.setText(当前值.toString());

break;

}

}

}

});

scrollPane.setBounds(10, 40, 700, 400);

scrollPane.setViewportView(表格);

panel2.add(scrollPane, BorderLayout.CENTER);

fl1 = new JLabel("用户名称");

fl1.setBounds(30, 460, 80, 20);

panel2.add(fl1);

fa1 = new JTextField("", 20);

fa1.setBounds(110, 460, 100, 20);

panel2.add(fa1);

fa1.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 1;

list1.removeAll();

try {

con = main1.getConn();


sta = con.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);


s1 = "select * from  用户表";

rs = sta.executeQuery(s1);

rs.last();

rsmd = rs.getMetaData();

int row = rs.getRow();

rs.first();

列数 = rsmd.getColumnCount();

列名1 = new String[列数];

for (int i = 0; i < 列数; i++) {

列名1[i] = rsmd.getColumnName(i + 1);

}

String s0 = "";

for (int j = 1; j <= row; j++) {

rs.absolute(j);

for (int i = 0; i < 列数; i++) {

if (列名1[i].equals("用户名")) {

s0 = rs.getString(i + 1).trim();

list1.add(s0);

}

}

}

rs.close();

sta.close();

con.close();

} catch (SQLException e) {

JOptionPane.showMessageDialog(null, "连接数据库出错!" + s1);

}

}

});

列名1 = new String[0];

fl2 = new JLabel("表名或字段号");

fl2.setBounds(240, 460, 80, 20);

panel2.add(fl2);

fa2 = new JTextField("", 20);

fa2.setBounds(320, 460, 100, 20);

panel2.add(fa2);

fa2.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 2;

list1.removeAll();

try {

con = main1.getConn();


sta = con.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

s1 = "select * from " + fa0.getText();

rs = sta.executeQuery(s1);

rs.last();

rsmd = rs.getMetaData();

列数 = rsmd.getColumnCount();

列名1 = new String[列数];

当前列号 = 2;

for (int i = 0; i < 列数; i++) {

列名1[i] = rsmd.getColumnName(i + 1);

}

rs.close();

sta.close();

con.close();

} catch (SQLException e) {

JOptionPane.showMessageDialog(null, "连接数据库出错!" + s1);

}

list1.add("*"); // 星号或表名均表示对全界面控制按钮

list1.add(fa0.getText()); // 星号或表名均表示对全界面控制按钮

for (int i = 0; i < 列名1.length; i++)

list1.add(列名1[i]);

}

});

fl3 = new JLabel("  权限");

fl3.setBounds(450, 460, 60, 20);

panel2.add(fl3);

fa3 = new JTextField("", 20);

fa3.setBounds(510, 460, 100, 20);

panel2.add(fa3);

final String[] power1 = { "i        录入权限", "u        修改权限",

"d       删除权限", "q       查询显示权限", "a       全部权限" };

fa3.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 3;

list1.removeAll();

for (int i = 0; i < power1.length; i++) {

list1.add(power1[i]);

}

}

});

list1.setBounds(720, 10, 120, 430);

panel2.add(list1);

list1.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

int w1, w2, h1, h2;

switch (当前列号) {

case 0:

fa0.setText(list1.getSelectedItem());

break;

case 1:

fa1.setText(list1.getSelectedItem());

字段序号 = list1.getSelectedIndex();

break;

case 2:

s2 = fa2.getText();

if (list1.getSelectedIndex() < 2)

fa2.setText(list1.getSelectedItem());

else if ((s2.trim().indexOf(fa0.getText()) >= 0)

|| (s2.trim().indexOf("*") >= 0))

fa2.setText((list1.getSelectedIndex() - 2) + ",");

else

fa2.setText(s2 + (list1.getSelectedIndex() - 2) + ",");

break;

case 3:

s2 = fa3.getText();

fa3.setText(s2

+ list1.getSelectedItem().substring(0, 5).trim()

+ ",");

break;

}

}

});

final JButton addButton = new JButton("添加到表格中");

addButton.setBounds(20, 540, 140, 20);

addButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int 选中行号 = -1;

for (int i = 0; i < 表格模型.getRowCount(); i++) {

if (表格模型.getValueAt(i, 0) != null)

if (表格模型.getValueAt(i, 0).equals(fa1.getText())) {

选中行号 = i;

break;

}

}

if (选中行号 < 0) {

String[] rowValues = { fa1.getText(), fa2.getText(),

fa3.getText() };

表格模型.addRow(rowValues);

int rowCount = 表格.getRowCount() + 1;

fa1.setText("");

fa2.setText("");

fa3.setText("");

} else

JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");

}

});

panel2.add(addButton);

final JButton updButton = new JButton("修改表格数据");

updButton.setBounds(160, 540, 140, 20);

updButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int 选中行号 = -1;

for (int i = 0; i < 表格模型.getRowCount(); i++) {

if ((表格模型.getValueAt(i, 0) != null)

&& (表格模型.getValueAt(i, 0).equals(fa1.getText()))) {

选中行号 = i;

break;

}

}

if (选中行号 >= 0) {

表格模型.setValueAt(fa1.getText(), 选中行号, 0);

表格模型.setValueAt(fa2.getText(), 选中行号, 1);

表格模型.setValueAt(fa3.getText(), 选中行号, 2);

} else

JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");

}

});

panel2.add(updButton);

final JButton delButton = new JButton("从表格中删除");

delButton.setBounds(300, 540, 130, 20);

delButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int 选中行号 = 表格.getSelectedRow();

if (选中行号 != -1)

表格模型.removeRow(选中行号);

}

});

panel2.add(delButton);

final JButton creButton = new JButton("表格内容存盘");

creButton.setBounds(430, 540, 130, 20);

creButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

char x1 = 10, x2 = 13, x3 = '"', x4 = ',';

file1 = new File(fa9.getText());

FileOutputStream fs;

try {

if (!file1.exists()) {// 如果文件不存在

file1.createNewFile();// 创建文件

}

fs = new FileOutputStream(file1);

for (int i = 0; i < 读入数据.size(); i++) {

fs.write((读入数据.get(i) + x1).getBytes());

}

for (int i = 0; i < 表格模型.getRowCount(); i++) {

String s2 = "2,";

for (int j = 0; j < 3; j++) {

if (表格模型.getValueAt(i, j) != null)

s2 = s2 + 表格模型.getValueAt(i, j).toString()

+ "。";

else

s2 = s2 + "。";

}

fs.write((s2 + x1).getBytes());

}

fs.close();

} catch (IOException e2) {

JOptionPane.showMessageDialog(null, "写文件错。");

}

}

});

panel2.add(creButton);

final JButton clearButton = new JButton("清参数文本框");

clearButton.setBounds(560, 540, 130, 20);

clearButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

fa1.setText("");

fa2.setText("");

fa3.setText("");

}

});

panel2.add(clearButton);

final JButton exitButton = new JButton("退出");

exitButton.setBounds(690, 540, 130, 20);

exitButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

panel2.setVisible(false);

frame2.setVisible(false);

System.exit(0);

}

});

panel2.add(exitButton);

frame2.add(panel2);

frame2.setVisible(true); // 安装窗口

}

   }

版本2

74.源码74,公共程序,求解条件表达式宏替换程序。

     /** 

      * 程序文件名:tenanceEval.java 

      * 作者:程学先  

      * 功能:求解条件表达式宏替换程序 。 

      * 如果一个条件表达式由数字数据类型常量、括号、逻辑运算符、关系运算符、某 

      * 些函数、四则运算符构成的条件表达式,可以求得真或假的结果。 

      * 设计思想:类是方法与数据的集成,部件是程序模块、构件、组件、类的集成。 

      * 面向对象的秘诀或创新是多工作“集成”或"冗余","冗余"指在设计时不只是根据当前的需求 

      * 设计一对一的代码,而是再加上类似界面、类似功能的其他代码,封装在一起, 

      * 在每次应用时选择部分方法与数据为当前任务服务,不一定用到其全部的方法和数据。 

      * 其他的方法与数据将在其他类似界面、类似任务重调用。 

      * 例如“文本框”类,将数据显示、录入、修改、字体、字号、颜色等操作方法与有关数据都集成到同一个类中, 

      * 在其子类中还包括密码框。在实际使用时往往只根据录入或显示的需求选用其部分方法和数据。 

      * 这样的冗余设计使其复用粒度加大,复用范围拓广,开创了软件设计的面向对象时代。 

      * 软部件的设计思想也是集成或冗余, 

      * 将用于某一类界面和完成某一类具体的工作的程序模块、构件、组件、中间件、类等集成到一个封装体中。 

      * 这样的冗余设计目的是提高软件复用粒度,扩大软件复用范围, 

      * 在每次调用时通过选择数据表、选择布局、选择字段与按钮及其他参数使其用作某种模块或构件,完成一种应用。 

      * 就能用较少的软部件覆盖或满足更多的应用,只有这样的设计才能成为软件生产线的设计基础, 

      * 才有可能更好地实现软件设计自动化。 

      * 需要说明的是,软件复用有利于提高编码效率,有利于实现软件生产自动化,可以降低软件设计难度,减少直接的代码量。 

      * 但它是以降低软件运行效率、缩小软件应用范围为代价的, 

      * 因此需要根据应用需要恰当地选取软件复用度,不要一味追求高复用,对于对时间要求高的软件和一些有特殊要求的软件, 

      * 只能用复用度低的软件,例如使用用C语言甚至汇编语言编写的程序。 

      * 由于JAVA中无宏替换语句,在设计复用度较高、要求较高自适应性的的软件时比较有挑战性的就是如何在JAVA中实现宏替换。 

      * 本程序是实现条件表达式宏替换的一种方法。 

      * 完成时间 2018.6.5  

      * 条件表达式中运算符可包括:+、-、*、/、%、>、>=、<、<=、]、 [ 、! 、|、||、 &、&&、 =、(、)、 

      * 支持函数:sqrt,square,ceil,sin,cos,asin,acon.tan.atan,log,exp。不支持NOT运算。  

      * 调用:tenanceEval.tenanceeval(String variabl1413) 

      * 返回布尔值真或假 

      */ 

     import java.util.Stack; 

     import java.util.regex.Matcher; 

     import java.util.regex.Pattern; 

     import javax.swing.JOptionPane; 

      

     public class tenanceEval { 

      public static tenanceEval be = new tenanceEval(); 

      public static String variabl1559 = "+-*/%><][!|&=#"; 

      public static String variabl15591 = "^([a-zA-Z0-9_]+)\\(([a-zA-Z0-9_.()]+)\\)$"; 

      public static String variabl1563 = "", variabl15630 = ""; 

      public static String variabl15631 = "", variabl15632 = ""; 

      public static boolean 布尔变量 = false; 

      public static Object retp = null; 

      public static Exception e0; 

      

      protected static int variabl1563(String s, String s0) { 

      int n = 0; 

      for (int i = 0; i < s.length() - s0.length() + 1; i++) { 

      if (s.substring(i, i + s0.length()).equals(s0)) 

      n++; 

     

      return n; 

     

      

      public static boolean tenanceeval(String variabl1563) { 

      String[] s1 = null; 

      boolean variabl15572 = true; 

      String s2 = "and"; 

      variabl1563 = variabl1563.toLowerCase(); 

      variabl1563 = variabl1563.replaceAll("&&", "&"); 

      variabl1563 = variabl1563.replaceAll("&", "and"); 

      variabl1563 = variabl1563.replaceAll("\\|\\|", "or"); 

      variabl1563 = variabl1563.replaceAll("\\|", "or"); 

      int k1 = 0, k2 = 0, k3 = 0, k4 = 0, bz = 0, bz1 = 0; 

      String x1 = variabl1563; 

      boolean b0 = true, bl2 = true; 

      x1 = x1.replaceAll("(sqrt)|(square)|(ceil)|(sin)|(cos)|(asin)|" 

      + "(acon)|(tan)|(atan)|(log)|(exp)(sqrt)|(square)|(ceil)|" 

      + "(sin)|(cos)|(asin)|(acon)|(tan)|(atan)|(log)|(exp)", "¥"); 

      if (x1.length() != variabl1563.length()) { 

      variabl1563 = be.variabl1567(x1, variabl1563); 

     

      Stack variabl15671 = new Stack(); 

      Stack variabl15672 = new Stack(); 

      variabl1563 = variabl1563.replaceAll(" ", ""); 

      if ((variabl1563.indexOf("and") > 0) || (variabl1563.indexOf("or") > 0)) { 

      variabl1563 = variabl1563.replaceAll("or", "or "); 

      x1 = variabl1563.replaceAll("(and)|(or )", "¥¥¥"); 

      String[] s01 = x1.split("¥¥¥"), s02 = null, s03 = null; 

      int[] n1 = new int[s01.length]; 

      k1 = 0; 

      String s10 = "", s11 = "", s12, s13, s14; 

      boolean bl1 = true; 

      for (int i = 0; i < s01.length; i++) { 

      n1[i] = k1; 

      if (variabl1563.length() > k1 + s01[i].length() + 3) { 

      variabl15671.push(variabl1563.substring(k1, k1 + s01[i].length() + 3)); 

      } else { 

      variabl15671.push(s01[i]); 

     

      k1 = k1 + 3 + s01[i].length(); 

     

      int i = 0; 

      s11 = ""; 

      a1: for (i = s01.length - 1; i >= 0; i--) { 

      if (variabl15671.size() > 0) 

      s10 = variabl15671.pop().toString(); 

      else 

      s10 = ""; 

      if (be.variabl1563(s10, "(") > be.variabl1563(s10, ")")) {

      k1 = 0; 

      s11 = ""; 

      for (int j = s10.length() - 1; j >= 0; j--) { 

      if (s10.substring(j, j + 1).equals(")")) { 

      k1--; 

     

      if (s10.substring(j, j + 1).equals("(")) { 

      k1++; 

     

      if (k1 == 1) { 

      variabl15671.push(s10.substring(0, j)); 

      i++; 

      s11 = s11 + s10.substring(j + 1, s10.length()); 

      break; 

     

     

      a2: while (variabl15672.size() > 0) { 

      s10 = variabl15672.pop().toString(); 

      if (be.variabl1563(s10, "(") < be.variabl1563(s10, ")")) {

      k1 = 0; 

      for (int j1 = 0; j1 < s10.length(); j1++) { 

      if (s10.substring(j1, j1 + 1).equals("(")) { 

      k1--; 

     

      if (s10.substring(j1, j1 + 1).equals(")")) { 

      k1++; 

     

      if (k1 == 1) { 

      s11 = s11 + s10.substring(0, j1); 

      variabl15672.push(s10.substring(j1 + 1, 

      s10.length()));

      j1++; 

      bl2 = be.逻辑运算(s11); 

      variabl15672.push(bl2);

      j1++; 

      break a2; 

     

     

      } else 

      s11 = s11 + s10; 

     

      } else { 

      s11 = s11 + s10; 

      variabl15672.push(s10); 

     

      if (i == 0) { 

      s11 = ""; 

      k1 = variabl15672.size(); 

      for (int j2 = 0; j2 < k1; j2++) 

      s11 = s11 + variabl15672.pop(); 

      if (s11.length() > 0){ 

      bl2 = be.逻辑运算(s11); 

     

      if ((i == 0) && (variabl15671.size() == 0) && (variabl15672.size() == 0)) 

      break a1; 

     

     

      } else { 

      bl2 = 关系分析1(variabl1563); 

     

      return bl2; 

     

      

      protected boolean 逻辑运算(String s) { 

      s = s.replaceAll("or", "or "); 

      String x1 = s.replaceAll("(and)|(or )", "¥¥¥"); 

      String[] s01 = x1.split("¥¥¥"), s02 = null, s03 = null; 

      int[] n1 = new int[s01.length]; 

      int k1 = 0; 

      String s10 = "", s11 = "", s12, s13, s14; 

      boolean bl1 = true, bl2 = true; 

      for (int i = 0; i < s01.length; i++) { 

      if (i == 0) { 

      bl1 = 关系分析1(s01[i]); 

      k1 = k1 + s01[i].length(); 

      } else { 

      s10 = s.substring(k1, k1 + 3); 

      if (s10.indexOf("and") >= 0) { 

      bl2 = 关系分析1(s01[i]); 

      bl1 = bl1 && bl2; 

      } else if (s10.indexOf("or") >= 0) { 

      bl2 = 关系分析1(s01[i]); 

      bl1 = bl1 || bl2; 

     

      k1 = k1 + s01[i].length() + 3; 

     

     

      return bl1; 

     

      

      public static boolean 关系分析1(String sq1) { 

      boolean bo3 = true; 

      String s1[] = null; 

      String sq2 = sq1.replaceAll("(>=)|(<>)|(>)|(==)|(<=)|(<)|(!=)|(=)", 

      "###"); 

      if (sq2.indexOf("#") > 0) { 

      s1 = sq2.split("###"); 

      double w1 = 0.0; 

      double w2 = 0.0; 

      String sq3 = s1[0], sq4 = s1[1]; 

      if (s1[0].indexOf(")") > 0) 

      sq3 = be.variabl15651(s1[0]); 

      else { 

      if ((s1[0].indexOf("+") > 0) || (s1[0].indexOf("-") > 0) 

      || (s1[0].indexOf("*") > 0) || (s1[0].indexOf("/") > 0) 

      || (s1[0].indexOf("%") > 0)) 

      sq3 = variabl1563(s1[0]); 

     

      if (s1[1].indexOf(")") > 0) 

      sq4 = be.variabl15651(s1[1]); 

      else { 

      if ((s1[1].indexOf("+") > 0) || (s1[1].indexOf("-") > 0) 

      || (s1[1].indexOf("*") > 0) || (s1[1].indexOf("/") > 0) 

      || (s1[1].indexOf("%") > 0)) 

      sq4 = variabl1563(s1[1]); 

     

      w1 = Double.parseDouble(sq3); 

      w2 = Double.parseDouble(sq4); 

      if (sq1.indexOf(">=") >= 0) { 

      bo3 = w1 >= w2; 

      } else if (sq1.indexOf(">") >= 0) { 

      bo3 = w1 > w2; 

      } else if (sq1.indexOf("<=") >= 0) { 

      bo3 = w1 <= w2; 

      } else if (sq1.indexOf("<") >= 0) { 

      bo3 = w1 < w2; 

      } else if (sq1.indexOf("==") >= 0) { 

      bo3 = w1 == w2; 

      } else if (sq1.indexOf("=") >= 0) { 

      bo3 = w1 == w2; 

      } else if (sq1.indexOf("!=") >= 0) { 

      bo3 = w1 != w2; 

      } else if (sq1.indexOf("<>") >= 0) { 

      bo3 = w1 != w2; 

     

      } else { 

      if (sq1.indexOf("true") >= 0) 

      bo3 = true; 

      else if (sq1.indexOf("false") >= 0) 

      bo3 = false; 

     

      return bo3; 

     

      

      protected String variabl15651(String s) {

      String[] s0 = s.split("\\("); 

      String[] s1 = s0[s0.length - 1].split("\\)"); 

      int n1 = 0, n2 = 0; 

      String s2 = "", s3 = ""; 

      for (int i = 0; i < s0.length - 1; i++) { 

      n1 = n1 + s0[i].length() + 1; 

      s2 = s2 + s0[i]; 

      if (i < s0.length - 2) 

      s2 = s2 + "("; 

     

      n2 = n1 + s1[0].length() + 1; 

      s3 = s.substring(n2, s.length()); 

      s = s.substring(n1 - 1, n2); 

      n1--; 

      s = s.replaceAll("(\\()|(\\))", ""); 

      if ((s.indexOf("+") > 0) || (s.indexOf("-") > 0) 

      || (s.indexOf("*") > 0) || (s.indexOf("/") > 0) 

      || (s.indexOf("%") > 0)) 

      variabl1563(s); 

      variabl1563 = s2 + variabl1563 + s3; 

      return variabl1563; 

     

      

      public static String variabl1563(String s) { 

      String s1 = s.replaceAll("[-/%]", "*"); 

      s1 = s1.replaceAll("[\\+]", "*"); 

      String[] s0 = s1.split("\\*"); 

      int[] l0 = new int[s0.length]; 

      String[] s01 = new String[s0.length]; 

      String[] l1 = new String[s0.length]; 

      String[] l2 = new String[s0.length]; 

      Stack variabl15671 = new Stack(); 

      Stack variabl15672 = new Stack(); 

      Stack variabl15673 = new Stack(); 

      Stack variabl15674 = new Stack(); 

      String sm1 = "", sm2 = "", sn1, sn2, sn3, sn4; 

      int n = 0, n1 = 0; 

      double d1 = 0.0, d2 = 0.0; 

      l2[0] = ""; 

      for (int i = 0; i < s0.length; i++) { 

      l0[i] = s0[i].length(); 

      n = n + s0[i].length(); 

      s01[i] = s0[i]; 

      if (i < s0.length - 1) { 

      l2[i + 1] = s.substring(n, n + 1); 

      n++; 

     

     

      for (int i = s0.length - 1; i >= 0; i--) { 

      variabl15671.push(s0[i]); 

      variabl15672.push(l2[i]);

     

      n = variabl15671.size(); 

      for (int i = 0; i < n; i++) { 

      sn1 = variabl15671.pop().toString(); 

      sn2 = variabl15672.pop().toString(); 

      if (sn2.equals("*")) { 

      d1 = Double.parseDouble(sm1) * Double.parseDouble(sn1); 

      sm1 = d1 + ""; 

      s01[i] = sm1; 

      s01[i - 1] = ""; 

      l2[i] = l2[i - 1]; 

      l2[i - 1] = ""; 

      } else if (sn2.equals("/")) { 

      d1 = Double.parseDouble(sm1) / Double.parseDouble(sn1); 

      sm1 = d1 + ""; 

      s01[i] = sm1; 

      s01[i - 1] = ""; 

      l2[i] = l2[i - 1]; 

      l2[i - 1] = ""; 

      } else if (sn2.equals("%")) { 

      d1 = Double.parseDouble(sm1) % Double.parseDouble(sn1); 

      sm1 = d1 + ""; 

      s01[i] = sm1; 

      l2[i] = l2[i - 1]; 

      s01[i - 1] = ""; 

      l2[i - 1] = ""; 

      } else 

      sm1 = sn1; 

      variabl1563 = d1 + ""; 

     

      for (int i = s01.length - 1; i >= 0; i--) { 

      if (s01[i].length() > 0) { 

      variabl15673.push(s01[i]); 

      variabl15674.push(l2[i]);

     

     

      if (variabl15673.size() > 1) { 

      d1 = 0.0; 

      sm1 = ""; 

      n = variabl15673.size(); 

      for (int i = 0; i < n; i++) { 

      sn1 = variabl15673.pop().toString(); 

      sn2 = variabl15674.pop().toString(); 

      if (sn2.equals("+")) { 

      d1 = Double.parseDouble(sm1) + Double.parseDouble(sn1); 

      sm1 = d1 + ""; 

      s01[i] = sm1; 

      s01[i - 1] = ""; 

      l2[i] = l2[i - 1]; 

      l2[i - 1] = ""; 

      } else if (sn2.equals("-")) { 

      d1 = Double.parseDouble(sm1) - Double.parseDouble(sn1); 

      sm1 = d1 + ""; 

      s01[i] = sm1; 

      s01[i - 1] = ""; 

      l2[i] = l2[i - 1]; 

      l2[i - 1] = ""; 

      } else { 

      sm1 = sn1; 

     

     

      variabl1563 = d1 + ""; 

     

      return variabl1563; 

     

      

      protected String variabl1567(String variabl15631, String variabl15633) { 

      String[] s1 = variabl15631.split("¥"); 

      String variabl15634 = "", variabl15635 = "", variabl15636 = "", variabl15637 = "", x1; 

      int n1 = 0, n2 = 0, n3 = 0; 

      double db = 0.0; 

      for (int i = 0; i < s1.length; i++) { 

      n3 = n1 + s1[i].length(); 

      n1 = variabl15633.indexOf("(", n2 + s1[i].length());

      if (n1 < 0) 

      break; 

      n2 = variabl15633.indexOf(")", n1); 

      variabl15634 = variabl15633.substring(n1 + 1, n2); 

      variabl15635 = variabl15633.substring(n3, n1); 

      variabl15637 = variabl15633.substring(n3, n2 + 1); 

      if (variabl15634.indexOf("(") > 0) 

      variabl15634 = be.variabl15651(variabl15634); 

      else { 

      x1 = variabl15634; 

      x1 = x1.replaceAll("[-/%]", ""); 

      x1 = x1.replaceAll("[\\+]", ""); 

      x1 = x1.replaceAll("[\\*]", ""); 

      if (x1.length() != variabl15634.length()) 

      if ((variabl15634.indexOf("+") > 0) || (variabl15634.indexOf("-") > 0) 

      || (variabl15634.indexOf("*") > 0) 

      || (variabl15634.indexOf("/") > 0) 

      || (variabl15634.indexOf("%") > 0)) 

      variabl15634 = variabl1563(variabl15634); 

     

      try { 

      db = Double.valueOf(variabl15634).doubleValue(); 

      if (variabl15635.equals("log")) { 

      variabl15636 = Math.log(db) + ""; 

      } else if (variabl15635.equals("square")) { 

      variabl15636 = Math.pow(db, 2) + ""; 

      } else if (variabl15635.equals("sqrt")) { 

      variabl15636 = Math.sqrt(db) + ""; 

      } else if (variabl15635.equals("sin")) { 

      variabl15636 = Math.sin(db) + ""; 

      } else if (variabl15635.equals("asin")) { 

      variabl15636 = Math.asin(db) + ""; 

      } else if (variabl15635.equals("cos")) { 

      variabl15636 = Math.cos(db) + ""; 

      } else if (variabl15635.equals("tan")) { 

      variabl15636 = Math.tan(db) + ""; 

      } else if (variabl15635.equals("atan")) { 

      variabl15636 = Math.atan(db) + ""; 

      } else if (variabl15635.equals("ceil")) { 

      variabl15636 = Math.ceil(db) + ""; 

      } else if (variabl15635.equals("exp")) { 

      variabl15636 = Math.exp(db) + ""; 

     

      } catch (Exception e) { 

     

      int l1 = variabl15633.indexOf(variabl15637); 

      int l2 = variabl15637.length(); 

      variabl15633 = variabl15633.substring(0, l1) 

      + (variabl15636 + "               ").substring(0, l2) 

      + variabl15633.substring(l1 + l2, variabl15633.length()); 

      variabl15633 = variabl15633.replaceAll(" ", ""); 

      n2--; 

     

      variabl1563 = variabl15633; 

      return variabl15633; 

     

       } 


75.源码75,公共程序,为数据维护程序设置完整性控制条件。

     /* 

      * 程序文件名:completeTool.java 

      * 作者:程学先  

      * 功能:为数据维护程序设置完整性控制条件。 

      * 设置数据完整性一条记录包括:字段名称、最大值、最小值、值域、条件表达式等5个参数 

      * 最大值、最小值指该字段在数据输入时能够填入的最大值或最小值。越限将不能录入。 

      * 由于0也是有限数字,因此没有最大、最小数据条件时不要留0,请保持空。 

      * 最大值、最小值、条件表达式只对数字数据各类型检查并控制。 

      * 值域可对数字数据类型,也可对各字符数据类型。本程序允许有三种格式 

      * 1)最小值-最大值,只对数字数据类型。 

      * 2)值1,variabl27092,……,值n,    表示只能是其中之一 

      * 3)[variabl27091,variabl27092,……,值n,]   表示只要包含其中之一。在值前可以加^,表示该值不得包含在内。 

      * 条件表达式指该字段数据必须满足的条件,例如:年龄>=18 and 年龄<=60,表示数据有效范围 

      * 所有数据保存在一个文件中,该文件可以包括控件位置大小参数、安全性要求参数、完整性参数等三组内容, 

      * 每组内容第一个数据标志类型,1表示控件位置大小参数;2表示安全性要求参数;3表示完整性参数。 

      */ 

     import java.awt.*; 

     import java.awt.event.*; 

     import javax.swing.*; 

     import javax.swing.table.*; 

     import javax.swing.tree.DefaultMutableTreeNode; 

     import java.io.*; 

     import java.sql.Connection; 

     import java.sql.DatabaseMetaData; 

     import java.sql.DriverManager; 

     import java.sql.ResultSet; 

     import java.sql.ResultSetMetaData; 

     import java.sql.SQLException; 

     import java.sql.Statement; 

     import java.util.ArrayList; 

     import java.util.Vector; 

      

     public class completeTool extends JFrame { 

      private static completeTool frame3 = new completeTool(); 

      private static JPanel panel3 = new JPanel(); 

      private static DefaultTableModel variabl1965; 

      private static JTable variabl2655; 

      private static JScrollPane scrollPane = new JScrollPane(); 

      private static JScrollPane scrollPane1 = new JScrollPane(); 

      private static List list1 = new List(); 

      private static JLabel fl0, fl1, fl2, fl3, fl4, fl5, fl9; 

      private static JTextField fa0, fa1, fa2, fa3, fa4, fa5, fa9; 

      private static String variabl2327; 

      private static int variabl1823 = -1, variabl1947 = 0, variabl2193 = 0, variabl1739 = 0, variabl2651 = 0; 

      private static int variabl2127 = 0; 

      private static String[][] variabl2197; 

      private static ArrayList<String> variabl1665 = new ArrayList(); 

      private static String[] variabl25171; 

      private static String[] variabl2517 = { "字段名称", "最大值", "最小值", "值域", "条件表达式" }; 

      private static int[] variabl1489; 

      private static String[] variabl2157 = new String[5]; 

      private static File file1; 

      private static ArrayList<String> list = new ArrayList<String>(); 

      static Connection con; 

      private static Statement sta; 

      static String s1 = "", s2 = ""; 

      private static ResultSet rs; 

      private static ResultSetMetaData rsmd; 

      private static ArrayList variabl26031 = new ArrayList(); 

      

      public static void main(String args[]) { 

      frame3 = new completeTool(); 

      panel3 = new JPanel(); 

      scrollPane = new JScrollPane(); 

      scrollPane1 = new JScrollPane(); 

      list1 = new List(); 

      variabl1823 = -1; 

      variabl1947 = 0; 

      variabl2193 = 0; 

      variabl1739 = 0; 

      variabl2651 = 0; 

      variabl2127 = 0; 

      variabl1665 = new ArrayList(); 

      variabl2517[0] = "字段名称"; 

      variabl2517[1] = "最大值"; 

      variabl2517[2] = "最小值"; 

      variabl2517[3] = "值域"; 

      variabl2517[4] = "条件表达式"; 

      variabl2157 = new String[5]; 

      list = new ArrayList<String>(); 

      s1 = ""; 

      s2 = ""; 

      variabl26031 = new ArrayList(); 

      frame3.setTitle("最大值、最小值指该字段输入极限,值域指所填数据只能在该域内数据中选取,条件表达式指该字段数据必须满足的条件。   作者:程学先"); 

      frame3.setBounds(10, 10, 880, 660); 

      frame3.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 

      panel3.setBounds(10, 10, 880, 660); 

      panel3.setLayout(null); 

      variabl1965 = new DefaultTableModel(variabl2197, variabl2517); 

      variabl2655 = new JTable(variabl1965); 

      variabl2655.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

      main1.driver1(); 

      fl0 = new JLabel("数据表名"); 

      fl0.setBounds(40, 10, 80, 20); 

      panel3.add(fl0); 

      fa0 = new JTextField(""); 

      fa0.setBounds(130, 10, 100, 20); 

      panel3.add(fa0); 

      fa0.addFocusListener(new FocusAdapter() { 

      public void focusGained(final FocusEvent arg0) { 

      variabl1739 = 0; 

      list1.removeAll(); 

      if (variabl26031.size() < 1) { 

      try { 

      con = main1.getConn();

      String[] tableType = { "TABLE" }; 

      DatabaseMetaData databaseMetaData = con.getMetaData(); 

      ResultSet resultSet = databaseMetaData.getTables(null, 

      null, "%", tableType);

      while (resultSet.next()) { 

      variabl26031.add(resultSet.getString("TABLE_NAME")); 

     

      } catch (Exception e) { 

      e.printStackTrace(); 

     

     

      for (int i = 0; i < variabl26031.size(); i++) 

      list1.add(variabl26031.get(i).toString()); 

     

      }); 

      fl9 = new JLabel("文件名"); 

      fl9.setBounds(250, 10, 50, 20); 

      panel3.add(fl9); 

      fa9 = new JTextField("", 20); 

      fa9.setBounds(300, 10, 100, 20); 

      panel3.add(fa9); 

      fa9.addMouseListener(new MouseAdapter() { 

      public void mouseClicked(MouseEvent e) { 

      if (fa9.getText().length() < 1) { 

      final JFileChooser fc = new JFileChooser(".\\"); 

      fc.showOpenDialog(null); 

      if (fc.getSelectedFile() != null)

      fa9.setText(fc.getSelectedFile().toString()); 

     

     

      }); 

      fa9.addMouseListener(new MouseAdapter() { 

      public void mouseClicked(MouseEvent e) { 

      file1 = new File(fa9.getText()); 

      try { 

      if (file1.exists()) { 

      FileReader fr = new FileReader(file1);

      BufferedReader br = new BufferedReader(fr);

      String tempStr = null; 

      variabl1665.clear(); 

      variabl1965 = new DefaultTableModel(variabl2197, variabl2517); 

      for (int i = 0; (tempStr = br.readLine()) != null; i++) {

      if ((tempStr != null) && (tempStr.length() > 3)) { 

      if (tempStr.substring(0, 2).equals("3,")) { 

      variabl1965.addRow(tempStr.substring(2, 

      tempStr.length()).split("。")); 

      } else 

      variabl1665.add(tempStr); 

     

     

      } else { 

      if (fa9.getText().length() > 0) 

      file1.createNewFile();

     

      } catch (IOException e2) { 

      JOptionPane.showMessageDialog(null, "打开文件错!"); 

     

      variabl2655 = new JTable(variabl1965); 

      variabl2655.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 

      scrollPane.setBounds(10, 40, 700, 400); 

      scrollPane.setViewportView(variabl2655); 

      scrollPane.getViewport().add(variabl2655, null); 

      panel3.add(scrollPane, BorderLayout.CENTER); 

     

      }); 

      variabl2655.addMouseListener(new MouseAdapter() { 

      public void mouseClicked(MouseEvent e) { 

      int variabl1823 = variabl2655.getSelectedRow(); 

      for (int j = 0; j < 5; j++) { 

      if (variabl1965.getValueAt(variabl1823, j) != null) 

      variabl2327 = variabl1965.getValueAt(variabl1823, j).toString(); 

      else 

      variabl2327 = ""; 

      switch (j) { 

      case 0: 

      fa1.setText(variabl2327.toString()); 

      break; 

      case 1: 

      fa2.setText(variabl2327.toString()); 

      break; 

      case 2: 

      fa3.setText(variabl2327.toString()); 

      break; 

      case 3: 

      fa4.setText(variabl2327.toString()); 

      break; 

      case 4: 

      fa5.setText(variabl2327.toString()); 

      break; 

     

     

     

      }); 

      fl1 = new JLabel("字段名称"); 

      fl1.setBounds(30, 460, 80, 20); 

      panel3.add(fl1); 

      fa1 = new JTextField("", 20); 

      fa1.setBounds(110, 460, 100, 20); 

      panel3.add(fa1); 

      fa1.addFocusListener(new FocusAdapter() { 

      public void focusGained(final FocusEvent arg0) { 

      if ((fa0.getText().toString().length() > 0) && (variabl2651 < 1)) {

      try { 

      con = main1.getConn();

      sta = con.createStatement( 

      ResultSet.TYPE_SCROLL_INSENSITIVE, 

      ResultSet.CONCUR_UPDATABLE); 

      s1 = "select * from " + fa0.getText(); 

      rs = sta.executeQuery(s1); 

      rs.last(); 

      rsmd = rs.getMetaData(); 

      variabl2651 = rsmd.getColumnCount(); 

      variabl25171 = new String[variabl2651]; 

      variabl1489 = new int[variabl2651]; 

      variabl1739 = 1; 

      list1.removeAll(); 

      for (int i = 0; i < variabl2651; i++) { 

      variabl25171[i] = rsmd.getColumnName(i + 1); 

      variabl1489[i] = rsmd.getColumnDisplaySize(i + 1); 

      list1.add(variabl25171[i]); 

     

      rs.close(); 

      sta.close(); 

      con.close(); 

      } catch (SQLException e) { 

      JOptionPane.showMessageDialog(null, "连接数据库出错!" + s1); 

     

      } else { 

      variabl1739 = 1; 

      list1.removeAll(); 

      for (int i = 0; i < variabl2651; i++) { 

      list1.add(variabl25171[i]); 

     

     

     

      }); 

      fl2 = new JLabel("最大值"); 

      fl2.setBounds(240, 460, 60, 20); 

      panel3.add(fl2); 

      fa2 = new JTextField("", 20); 

      fa2.setBounds(300, 460, 100, 20); 

      panel3.add(fa2); 

      fa2.addFocusListener(new FocusAdapter() { 

      public void focusGained(final FocusEvent arg0) { 

      variabl1739 = 2; 

      list1.removeAll(); 

     

      }); 

      fl3 = new JLabel("最小值"); 

      fl3.setBounds(430, 460, 60, 20); 

      panel3.add(fl3); 

      fa3 = new JTextField("", 20); 

      fa3.setBounds(490, 460, 100, 20); 

      panel3.add(fa3); 

      fa3.addFocusListener(new FocusAdapter() { 

      public void focusGained(final FocusEvent arg0) { 

      variabl1739 = 3; 

      list1.removeAll(); 

     

      }); 

      fl4 = new JLabel("值域"); 

      fl4.setBounds(620, 460, 60, 20); 

      panel3.add(fl4); 

      fa4 = new JTextField("", 20); 

      fa4.setBounds(680, 460, 100, 20); 

      panel3.add(fa4); 

      fa4.addFocusListener(new FocusAdapter() { 

      public void focusGained(final FocusEvent arg0) { 

      variabl1739 = 4; 

      list1.removeAll(); 

     

      }); 

      fl5 = new JLabel("条件表达式"); 

      panel3.add(fl5); 

      fa5 = new JTextField("", 20); 

      panel3.add(fa5); 

      fl5.setBounds(30, 500, 80, 20); 

      fa5.setBounds(110, 500, 100, 20); 

      fa5.addFocusListener(new FocusAdapter() { 

      public void focusGained(final FocusEvent arg0) { 

      variabl1739 = 5; 

      list1.removeAll(); 

      for (int i = 0; i < variabl2651; i++) { 

      list1.add(variabl25171[i]); 

     

     

      }); 

      list1.setBounds(720, 10, 120, 430); 

      panel3.add(list1); 

      list1.addMouseListener(new MouseAdapter() { 

      public void mouseClicked(MouseEvent e) { 

      int w1, w2, h1, h2; 

      switch (variabl1739) { 

      case 0: 

      fa0.setText(list1.getSelectedItem()); 

      break; 

      case 1: 

      fa1.setText(list1.getSelectedItem()); 

      variabl2127 = list1.getSelectedIndex(); 

      break; 

      case 2: 

      fa2.setText(list1.getSelectedItem()); 

      break; 

      case 3: 

      fa3.setText(list1.getSelectedItem()); 

      break; 

      case 4: 

      fa4.setText(list1.getSelectedItem()); 

      break; 

      case 5: 

      fa5.setText(list1.getSelectedItem()); 

      break; 

     

      

     

      }); 

      final JButton addButton = new JButton("添加到表格中"); 

      addButton.setBounds(20, 540, 140, 20); 

      addButton.addActionListener(new ActionListener() { 

      public void actionPerformed(ActionEvent e) { 

      int variabl1823 = -1; 

      for (int i = 0; i < variabl1965.getRowCount(); i++) { 

      if ((variabl1965.getValueAt(i, 0) != null) 

      && (variabl1965.getValueAt(i, 0).equals(fa1.getText()))) { 

      variabl1823 = i; 

      break; 

     

     

      if (variabl1823 < 0) { 

      String[] rowValues = { fa1.getText(), fa2.getText(), 

      fa3.getText(), fa4.getText(), fa5.getText() }; 

      variabl1965.addRow(rowValues); 

      int rowCount = variabl2655.getRowCount() + 1; 

      fa1.setText(""); 

      fa2.setText(""); 

      fa3.setText(""); 

      fa4.setText(""); 

      fa5.setText(""); 

      } else 

      JOptionPane.showMessageDialog(null, "存在重复,请改按修改!"); 

     

      }); 

      panel3.add(addButton); 

      final JButton updButton = new JButton("修改表格数据"); 

      updButton.setBounds(160, 540, 140, 20); 

      updButton.addActionListener(new ActionListener() { 

      public void actionPerformed(ActionEvent e) { 

      int variabl1823 = -1; 

      for (int i = 0; i < variabl1965.getRowCount(); i++) { 

      if ((variabl1965.getValueAt(i, 0) != null) 

      && (variabl1965.getValueAt(i, 0).equals(fa1.getText()))) { 

      variabl1823 = i; 

      break; 

     

     

      if (variabl1823 >= 0) { 

      variabl1965.setValueAt(fa1.getText(), variabl1823, 0); 

      variabl1965.setValueAt(fa2.getText(), variabl1823, 1); 

      variabl1965.setValueAt(fa3.getText(), variabl1823, 2); 

      variabl1965.setValueAt(fa4.getText(), variabl1823, 3); 

      variabl1965.setValueAt(fa5.getText(), variabl1823, 4); 

      } else 

      JOptionPane.showMessageDialog(null, "为新数据,请改按添加!"); 

     

      }); 

      panel3.add(updButton); 

      final JButton delButton = new JButton("从表格中删除"); 

      delButton.setBounds(300, 540, 130, 20); 

      delButton.addActionListener(new ActionListener() { 

      public void actionPerformed(ActionEvent e) { 

      int variabl1823 = variabl2655.getSelectedRow(); 

      if (variabl1823 != -1) 

      variabl1965.removeRow(variabl1823); 

     

      }); 

      panel3.add(delButton); 

      final JButton creButton = new JButton("表格内容存盘"); 

      creButton.setBounds(430, 540, 130, 20); 

      creButton.addActionListener(new ActionListener() { 

      public void actionPerformed(ActionEvent e) { 

      char x1 = 10, x2 = 13, x3 = '"', x4 = ','; 

      file1 = new File(fa9.getText()); 

      FileOutputStream fs; 

      try { 

      if (!file1.exists()) {

      file1.createNewFile();

     

      fs = new FileOutputStream(file1); 

      for (int i = 0; i < variabl1665.size(); i++) { 

      fs.write((variabl1665.get(i) + x1).getBytes()); 

     

      for (int i = 0; i < variabl1965.getRowCount(); i++) { 

      String s1 = "3,"; 

      for (int j = 0; j < 5; j++) { 

      if (variabl1965.getValueAt(i, j) != null) 

      s1 = s1 + variabl1965.getValueAt(i, j).toString() 

      + "。"; 

      else 

      s1 = s1 + "。"; 

     

      fs.write((s1 + x1).getBytes()); 

     

      fs.close(); 

      } catch (IOException e2) { 

      JOptionPane.showMessageDialog(null, "写文件错。"); 

     

     

      }); 

      panel3.add(creButton); 

      final JButton clearButton = new JButton("清参数文本框"); 

      clearButton.setBounds(560, 540, 130, 20); 

      clearButton.addActionListener(new ActionListener() { 

      public void actionPerformed(ActionEvent e) { 

      fa1.setText(""); 

      fa2.setText(""); 

      fa3.setText(""); 

      fa4.setText(""); 

      fa5.setText(""); 

     

      }); 

      panel3.add(clearButton); 

      final JButton exitButton = new JButton("退出"); 

      exitButton.setBounds(690, 540, 130, 20); 

      exitButton.addActionListener(new ActionListener() { 

      public void actionPerformed(ActionEvent e) { 

      panel3.setVisible(false); 

      frame3.setVisible(false); 

      System.exit(0); 

     

      }); 

      panel3.add(exitButton); 

      frame3.add(panel3); 

      frame3.setVisible(true); 

     

        } 

      

      

76.源码76,公共程序,为数据维护部件设置控件选择与布局数据。

/* 

 * 程序文件名:deviseTool.java 

 * 作者:程学先  

 * 功能:deviseTool程序用于单记录数据维护部件设置各控件位置与大小参数。 

 */

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;

import javax.swing.tree.DefaultMutableTreeNode;

import java.io.*;

import java.sql.Connection;

import java.sql.DatabaseMetaData;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.Vector;


public class deviseTool extends JFrame {

private static deviseTool frame1 = new deviseTool();

private static JPanel panel1 = new JPanel();

private static DefaultTableModel variabl1965;

private static JTable variabl2655;

private static JScrollPane scrollPane = new JScrollPane();

private static List list1 = new List();

private static JLabel fl0, fl1, fl2, fl3, fl4, fl5, fl6, fl7, fl8, fl9,

fl10, fl11, fl12;

private static JTextField fa0, fa1, fa2, fa3, fa4, fa5, fa6, fa7, fa8, fa9,

fa10, fa11, fa12;

private static String variabl2447 = "";

private static String variabl2217 = "";

private static String variabl2327;

private static int variabl1739 = 0, variabl2651 = 0;

private static int variabl2127 = 0;

private static String[][] variabl2197;

private static String[][] variabl21971 = new String[100][11];

private static String[] variabl25171;

private static String[] variabl1501;

private static int[] variabl2135;

private static int[][] variabl1183;

private static File file1;

static Connection con;

static String url;

static String variabl1275 = "sqlserver";

static String variabl1091 = "sql1";

private static Statement sta;

static String s1 = "", s2 = "";

static int[] variabl1737, variabl1769;

private static ResultSet rs;

private static ResultSetMetaData rsmd;

private static ArrayList variabl26031 = new ArrayList();

private static String[] variabl2517 = { "字段名称", "行号", "列号", "标签宽", "字段宽",

"高", "左边距", "到顶距", "字体", "字号", "颜色" };


public static void main(String args[]) {

variabl2447 = "";

variabl2217 = "";

frame1.setTitle("请先填字段名、行号、字号,非文本框类需填宽、高,高填其中第一行高,再按辅助计算,高、宽以字符个数为单位。距离以象素为单位。 作者:程学先");

frame1.setBounds(10, 10, 1000, 660);

frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

panel1.setBounds(10, 10, 1000, 660);

panel1.setLayout(null);

main1.driver1();

fl0 = new JLabel("数据表名");

fl0.setBounds(40, 10, 80, 20);

panel1.add(fl0);

fa0 = new JTextField(variabl2217);

fa0.setBounds(130, 10, 100, 20);

panel1.add(fa0);

fa0.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 0;

list1.removeAll();

if (variabl26031.size() < 1) {

try {

con = main1.getConn();

String[] tableType = { "TABLE" };


DatabaseMetaData databaseMetaData = con.getMetaData();

ResultSet resultSet = databaseMetaData.getTables(null,

null, "%", tableType);

while (resultSet.next()) {

variabl26031.add(resultSet.getString("TABLE_NAME"));

}

} catch (Exception e) {

e.printStackTrace();

}

}

for (int i = 0; i < variabl26031.size(); i++)

list1.add(variabl26031.get(i).toString());

}

});


fl10 = new JLabel("文件名");

fl10.setBounds(250, 10, 50, 20);

panel1.add(fl10);

fa10 = new JTextField(variabl2447, 20);

fa10.setBounds(300, 10, 100, 20);

panel1.add(fa10);


fa10.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

int c = 0;

int k = variabl1965.getRowCount();

for (int i = 0; i < k; i++) {

variabl1965.removeRow(0);

}

final JFileChooser fc = new JFileChooser(".\\");

fc.showOpenDialog(null);

if (fc.getSelectedFile() != null) {

fa10.setText(fc.getSelectedFile().toString());

file1 = new File(fa10.getText());

try {

if (file1.exists()) {

FileReader fr = new FileReader(file1);

BufferedReader br = new BufferedReader(fr);

String tempStr = null;

String[] s0;

for (int i = 0; (tempStr = br.readLine()) != null; i++) {

if ((tempStr != null) && (tempStr.length() > 3)) {

if (tempStr.substring(0, 2).equals("1,")) {

s0 = tempStr.substring(2,

tempStr.length()).split("。");

variabl1965.addRow(tempStr.substring(2,

tempStr.length()).split("。"));

}

}

c = i;

}

}

} catch (IOException e2) {

JOptionPane.showMessageDialog(null, "打开文件错!");

}

}

}

});


variabl1965 = new DefaultTableModel(variabl2197, variabl2517);

variabl2655 = new JTable(variabl1965);

variabl2655.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

variabl1563();

variabl2655.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

int variabl1823 = variabl2655.getSelectedRow();

for (int j = 0; j < 11; j++) {

if (variabl1965.getValueAt(variabl1823, j) != null)

variabl2327 = variabl1965.getValueAt(variabl1823, j)

.toString();

else

variabl2327 = "";

switch (j) {

case 0:

fa1.setText(variabl2327.toString());

break;

case 1:

fa11.setText(variabl2327.toString());

break;

case 2:

fa12.setText(variabl2327.toString());

break;

case 3:

fa2.setText(variabl2327.toString());

break;

case 4:

fa3.setText(variabl2327.toString());

break;

case 5:

fa4.setText(variabl2327.toString());

break;

case 6:

fa5.setText(variabl2327.toString());

break;

case 7:

fa6.setText(variabl2327.toString());

break;

case 8:

fa7.setText(variabl2327.toString());

break;

case 9:

fa8.setText(variabl2327.toString());

break;

case 10:

fa9.setText(variabl2327.toString());

break;

}

}

}

});

scrollPane.setBounds(10, 40, 800, 400);

scrollPane.setViewportView(variabl2655);

panel1.add(scrollPane, BorderLayout.CENTER);

fl1 = new JLabel("字段名称");

fl1.setBounds(30, 460, 80, 20);

panel1.add(fl1);

fa1 = new JTextField("", 20);

fa1.setBounds(110, 460, 100, 20);

panel1.add(fa1);

fa1.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

if ((fa0.getText().toString().length() > 0)

&& (variabl2651 < 1)) {

try {

con = main1.getConn();


sta = con.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

s1 = "select * from " + fa0.getText();

rs = sta.executeQuery(s1);

rs.last();

rsmd = rs.getMetaData();

variabl2651 = rsmd.getColumnCount();

variabl25171 = new String[variabl2651];

variabl1501 = new String[variabl2651];

variabl2135 = new int[variabl2651];

variabl1739 = 1;

list1.removeAll();


for (int i = 0; i < variabl2651; i++) {

variabl25171[i] = rsmd.getColumnName(i + 1);

variabl1501[i] = rsmd.getColumnTypeName(i + 1);

variabl2135[i] = rsmd.getColumnDisplaySize(i + 1);

list1.add(variabl25171[i]);

}

rs.close();

sta.close();

con.close();

} catch (SQLException e) {

JOptionPane.showMessageDialog(null, "连接数据库出错!" + s1);

}

} else {

variabl1739 = 1;

list1.removeAll();

for (int i = 0; i < variabl2651; i++) {

list1.add(variabl25171[i]);

}

}

}

});

fl11 = new JLabel("行号");

fl11.setBounds(220, 460, 60, 20);

panel1.add(fl11);

fa11 = new JTextField("", 20);

fa11.setBounds(280, 460, 60, 20);

panel1.add(fa11);

fa11.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 10;

list1.removeAll();

}

});


fl12 = new JLabel("列号");

fl12.setBounds(350, 460, 60, 20);

panel1.add(fl12);

fa12 = new JTextField("", 20);

fa12.setBounds(410, 460, 60, 20);

panel1.add(fa12);

fa12.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 11;

list1.removeAll();

}

});


fl2 = new JLabel("标签宽");

fl2.setBounds(480, 460, 60, 20);

panel1.add(fl2);

fa2 = new JTextField("", 20);

fa2.setBounds(540, 460, 60, 20);

panel1.add(fa2);

fa2.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 2;

list1.removeAll();

s2 = ",";

for (int i = 0; i < variabl1965.getRowCount(); i++) {

if (variabl1965.getValueAt(i, variabl1739) != null)

if (s2.lastIndexOf(","

+ variabl1965.getValueAt(i, variabl1739)

.toString() + ",") < 0) {

list1.add(variabl1965.getValueAt(i, variabl1739)

.toString());

s2 = s2

+ variabl1965.getValueAt(i, variabl1739)

.toString() + ",";

}

}

}

});


fl3 = new JLabel("字段宽");

fl3.setBounds(610, 460, 60, 20);

panel1.add(fl3);

fa3 = new JTextField("", 20);

fa3.setBounds(670, 460, 60, 20);

panel1.add(fa3);

fa3.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 3;

list1.removeAll();

}

});


fl4 = new JLabel("  高");

fl4.setBounds(740, 460, 60, 20);

panel1.add(fl4);

fa4 = new JTextField("", 20);

fa4.setBounds(800, 460, 60, 20);

panel1.add(fa4);

fa4.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 4;

list1.removeAll();

}

});


fl5 = new JLabel(" 左边距");

fl5.setBounds(30, 500, 80, 20);

panel1.add(fl5);

fa5 = new JTextField("", 20);

fa5.setBounds(110, 500, 100, 20);

panel1.add(fa5);

fa5.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 5;

list1.removeAll();

}

});


fl6 = new JLabel("到顶距");

panel1.add(fl6);

fa6 = new JTextField("", 20);

panel1.add(fa6);

fl6.setBounds(220, 500, 60, 20);

fa6.setBounds(280, 500, 60, 20);

fa6.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 6;

list1.removeAll();

}

});


fl7 = new JLabel(" 字体");

panel1.add(fl7);

fa7 = new JTextField("", 20);

panel1.add(fa7);

fl7.setBounds(350, 500, 60, 20);

fa7.setBounds(410, 500, 120, 20);

final String[] variabl2629 = { "宋体", "楷体", "黑体", "仿宋_GB2312" };

fa7.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 7;

list1.removeAll();

for (int i = 0; i < variabl2629.length; i++) {

list1.add(variabl2629[i]);

}

}

});


fl8 = new JLabel("字号");

panel1.add(fl8);

fa8 = new JTextField("", 20);

panel1.add(fa8);

fl8.setBounds(540, 500, 60, 20);

fa8.setBounds(600, 500, 100, 20);

fa8.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 8;

list1.removeAll();

final String[] variabl2607 = { "5", "6", "7", "8", "9", "10",

"11", "12", "14", "16", "18", "20", "22", "24", "26",

"28", "36", "48", "72" };

for (int i = 0; i < variabl2607.length; i++) {

list1.add(variabl2607[i]);

}

}

});


fl9 = new JLabel("颜色");

panel1.add(fl9);

fa9 = new JTextField("", 20);

panel1.add(fa9);

fl9.setBounds(710, 500, 60, 20);

fa9.setBounds(770, 500, 90, 20);

final String[] color1 = { "1        red红色", "2     blue蓝色",

"3    green绿色", "4     white白色", "5    black黑色",

"6   darkGray深灰色", "7     cyan青色", "8     yellow黄色",

"9   gray灰色", "10    lightGray浅灰色", "11    magenta品红",

"12    orange桔黄色" };

fa9.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 9;

list1.removeAll();

for (int i = 0; i < color1.length; i++) {

list1.add(color1[i]);

}

}

});

fa1.setText("");

fa2.setText("0");

fa3.setText("0");

fa4.setText("0");

fa5.setText("0");

fa6.setText("0");

fa7.setText("宋体");

fa8.setText("0");

fa9.setText("");

fa11.setText("0");

fa12.setText("0");

variabl1737 = new int[100];

variabl1769 = new int[100];


list1.setBounds(840, 10, 120, 430);

panel1.add(list1);

list1.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

switch (variabl1739) {

case 0:

fa0.setText(list1.getSelectedItem());

break;

case 1:

fa1.setText(list1.getSelectedItem());

variabl2127 = list1.getSelectedIndex();

fa2.setText("" + variabl25171[variabl2127].length());

if ((",ntext,text,memo,image,long,lob,blob,clob,ole,varbinary,varchar,nvarchar,xml"

.lastIndexOf("," + variabl1501[variabl2127])) < 0) {

fa3.setText("" + variabl2135[variabl2127]);

fa4.setText("1");

}

fa7.setText("宋体");

fa8.setText("12");

fa9.setText("5");

break;

case 2:

fa2.setText(list1.getSelectedItem());

break;

case 3:

fa3.setText(list1.getSelectedItem());

break;

case 4:

fa4.setText(list1.getSelectedItem());

break;

case 5:

fa5.setText(list1.getSelectedItem());

break;

case 6:

fa6.setText(list1.getSelectedItem());

break;

case 7:

fa7.setText(list1.getSelectedItem());

break;

case 8:

fa8.setText(list1.getSelectedItem());

break;

case 9:

fa9.setText(list1.getSelectedItem().substring(0, 5).trim());

break;

case 10:

fa11.setText(list1.getSelectedItem());

break;

case 11:

fa12.setText(list1.getSelectedItem());

break;

}


}

});

final JButton addButton = new JButton("添加到表格中");

addButton.setBounds(50, 540, 120, 20);

addButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {


int variabl1823 = -1;

if ((fa11.getText().compareTo("0") < 1)

|| (fa12.getText().compareTo("0") < 1)) {

JOptionPane.showMessageDialog(null, "请填全行号与列号!");

return;

}

if ((((",ntext,text,memo,image,long,lob,blob,clob,ole,varbinary,varchar,nvarchar,xml"

.lastIndexOf("," + variabl1501[variabl2127])) > 0) || (variabl2135[variabl2127] > 50))

&& ((fa3.getText().compareTo("0") < 1) || (fa4

.getText().compareTo("0") < 1))) {

JOptionPane.showMessageDialog(null, "大数据类型需要填宽与高字符数!");

return;

}

for (int i = 0; i < variabl1965.getRowCount(); i++) {

if ((variabl1965.getValueAt(i, 0) != null)

&& (variabl1965.getValueAt(i, 0).equals(fa1

.getText()))) {

variabl1823 = i;

break;

}

}

int variabl1947 = Integer.valueOf(fa11.getText());

int w1 = Integer.valueOf(fa2.getText());

int w2 = Integer.valueOf(fa3.getText());

int no1 = Integer.valueOf(fa8.getText());

int h1 = Integer.valueOf(fa4.getText());

if ((variabl1737[variabl1947] + w1 + w2) * no1 > 1500) {

JOptionPane.showMessageDialog(null,

"本行总宽设计将超过1500,请检查并限制其宽!");

return;

}

if (variabl1823 < 0) {

String[] rowValues = { fa1.getText(), fa11.getText(),

fa12.getText(), fa2.getText(), fa3.getText(),

fa4.getText(), fa5.getText(), fa6.getText(),

fa7.getText(), fa8.getText(), fa9.getText() };

if ((h1 > 1) && (Integer.valueOf(fa12.getText()) > 1)) {


if (variabl1769[variabl1947] < 1) {

variabl1769[variabl1947] = variabl1737[variabl1947];


for (int k = 1; k < h1; k++) {

variabl1769[variabl1947 + k] = variabl1769[variabl1947];

}

}

}


variabl1965.addRow(rowValues);


variabl1737[variabl1947] = variabl1737[variabl1947] + w1

+ w2;

fa1.setText("");

fa2.setText("0");

fa3.setText("0");

fa4.setText("0");

fa5.setText("0");

fa6.setText("0");

fa7.setText("宋体");

fa8.setText("0");

fa9.setText("");

fa11.setText("0");

fa12.setText("0");

} else

JOptionPane.showMessageDialog(null, "存在重复,请改按修改!");

}

});

panel1.add(addButton);


final JButton updButton = new JButton("修改表格数据");

updButton.setBounds(170, 540, 120, 20);

updButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int variabl1823 = -1;

for (int i = 0; i < variabl1965.getRowCount(); i++) {

if ((variabl1965.getValueAt(i, 0) != null)

&& (variabl1965.getValueAt(i, 0).equals(fa1

.getText()))) {

variabl1823 = i;

break;

}

}

if (variabl1823 >= 0) {


variabl1965.setValueAt(fa1.getText(), variabl1823, 0);

variabl1965.setValueAt(fa11.getText(), variabl1823, 1);

variabl1965.setValueAt(fa12.getText(), variabl1823, 2);

variabl1965.setValueAt(fa2.getText(), variabl1823, 3);

variabl1965.setValueAt(fa3.getText(), variabl1823, 4);

variabl1965.setValueAt(fa4.getText(), variabl1823, 5);

variabl1965.setValueAt(fa5.getText(), variabl1823, 6);

variabl1965.setValueAt(fa6.getText(), variabl1823, 7);

variabl1965.setValueAt(fa7.getText(), variabl1823, 8);

variabl1965.setValueAt(fa8.getText(), variabl1823, 9);

variabl1965.setValueAt(fa9.getText(), variabl1823, 10);

} else

JOptionPane.showMessageDialog(null, "为新数据,请改按添加!");

}

});

panel1.add(updButton);


final JButton delButton = new JButton("从表格中删除");

delButton.setBounds(290, 540, 120, 20);

delButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int variabl1823 = variabl2655.getSelectedRow();

if (variabl1823 != -1)

variabl1965.removeRow(variabl1823);

}

});

panel1.add(delButton);


final JButton countButton = new JButton("辅助计算");

countButton.setBounds(410, 540, 120, 20);

countButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String[] variabl1919 = new String[11];

int variabl2707 = 0, variabl2705 = 0, variabl2703 = 0;

int variabl1397 = 0;

int variabl2243 = 0;

int[] variabl13611 = new int[150];

int[] variabl13612 = new int[150];

int variabl2027 = 0;

for (int i = 0; i < variabl1965.getRowCount(); i++) {

variabl2703 = Integer.valueOf(variabl1965.getValueAt(i, 2)

.toString());

if ((variabl2703 == 1)

&& (Integer.valueOf(variabl1965.getValueAt(i, 3)

.toString()) > variabl2027))

variabl2027 = Integer.valueOf(variabl1965.getValueAt(i,

3).toString());

}

for (int i = 0; i < variabl1965.getRowCount(); i++) {

if (Integer

.valueOf(variabl1965.getValueAt(i, 2).toString()) == 1) {

variabl1965.setValueAt("" + variabl2027, i, 3);

}

}


for (int i = 0; i < variabl1965.getRowCount(); i++) {

variabl2707 = Integer.valueOf(variabl1965.getValueAt(i, 5)

.toString());

variabl2705 = Integer.valueOf(variabl1965.getValueAt(i, 1)

.toString());

variabl2703 = Integer.valueOf(variabl1965.getValueAt(i, 2)

.toString());

if (variabl2705 > variabl2243)

variabl2243 = variabl2705;

if (variabl2707 > 1) {

for (int j = 1; j < 11; j++)

variabl1919[j] = variabl1965.getValueAt(i, j)

.toString();

if ((variabl2703 == 1)

|| (variabl2703 == 2 && variabl13611[variabl2705] == 1)) {

if (variabl13611[variabl2705] == 0)

variabl13611[variabl2705] = 1;

for (int j = 1; j < variabl2707; j++) {

variabl1919[2] = "0";

variabl1919[1] = (variabl2705 + j) + "";

if (variabl2705 + j > variabl2243)

variabl2243 = variabl2705 + j;

variabl1919[5] = "1";

variabl1965.addRow(variabl1919);

}

} else {

if (variabl13611[variabl2705] == 0)

variabl13611[variabl2705] = variabl2705 + 1;

variabl13612[variabl2705] = variabl2707;

for (int j = 1; j < variabl2707; j++) {

variabl1919[2] = "98";

variabl1919[1] = (variabl2705 + j) + "";

variabl13612[variabl2705 + j] = variabl2707;

if (variabl2705 + j > variabl2243)

variabl2243 = variabl2705 + j;

variabl1919[5] = "1";

variabl1965.addRow(variabl1919);

}

}

}

}


int variabl2059 = variabl1965.getRowCount();

String[][] variabl2649 = new String[variabl2059][15];

int[][] variabl26491 = new int[variabl2059][15];

int n1 = 0;

for (int i = 0; i < variabl2059; i++) {

for (int j = 0; j < 11; j++) {

if (variabl1965.getValueAt(i, j) != null) {

variabl2649[i][j] = variabl1965.getValueAt(i, j)

.toString();

} else

variabl2649[i][j] = "0";

s2 = variabl2649[i][j].trim();

if ((j > 0) && (j < 8) || (j == 9))

if ((s2 == null) || (s2.length() < 1))

variabl26491[i][j] = 0;

else

variabl26491[i][j] = Integer.valueOf(s2);

;

}

variabl2649[i][11] = "" + i;

variabl26491[i][11] = i;

}


String trim = "";

int trim1 = 0;

for (int i = 0; i < variabl2059 - 1; i++) {

for (int j = 0; j < variabl2059 - 1 - i; j++) {

if (variabl26491[j][1] * 100 + variabl26491[j][2] > variabl26491[j + 1][1]

* 100 + variabl26491[j + 1][2]) {

for (int k = 0; k < 15; k++) {

trim = variabl2649[j][k];

trim1 = variabl26491[j][k];

variabl2649[j][k] = variabl2649[j + 1][k];

variabl26491[j][k] = variabl26491[j + 1][k];

variabl2649[j + 1][k] = trim;

variabl26491[j + 1][k] = trim1;

}

}

}

}


int[] variabl1341 = new int[variabl2243 + 1];

int[] variabl1471 = new int[variabl2243 + 1];

int[] variabl1063 = new int[variabl26491.length];

int kuand = 0;

for (int i = 0; i < variabl26491.length; i++) {

variabl2705 = variabl26491[i][1];

variabl2703 = variabl26491[i][2];

if (variabl13612[variabl2705] > 0) {

if ((variabl2703 < 98) && (variabl26491[i][5] < 2)) {

if (variabl2703 > variabl1341[variabl2705]) {

variabl1341[variabl2705] = variabl2703;

variabl1063[variabl2705] = i;

}

variabl1471[variabl2705] = variabl1471[variabl2705]

+ variabl26491[i][3] + variabl26491[i][4];

if (variabl1471[variabl2705] > kuand)

kuand = variabl1471[variabl2705];

}

}

}


for (int i = 0; i < variabl26491.length; i++) {

variabl2705 = variabl26491[i][1];

variabl2703 = variabl26491[i][2];

if (variabl13612[variabl2705] > 0) {

for (int k1 = 1; k1 <= variabl2243; k1++) {

if ((variabl1063[k1] > 0) && (variabl1063[k1] == i)) {

variabl26491[i][4] = variabl26491[i][4] + kuand

- variabl1471[k1];

break;

}

}

}

}


variabl1341 = new int[variabl2243 + 1];

variabl1471 = new int[variabl2243 + 1];

variabl1063 = new int[variabl26491.length];

kuand = 0;

for (int i = 0; i < variabl26491.length; i++) {

variabl2705 = variabl26491[i][1];

variabl2703 = variabl26491[i][2];

if (variabl2703 >= variabl1341[variabl2705]) {

variabl1341[variabl2705] = variabl2703;

variabl1063[variabl2705] = i;

}

variabl1471[variabl2705] = variabl1471[variabl2705]

+ variabl26491[i][3] + variabl26491[i][4];

if (variabl1471[variabl2705] > kuand) {

kuand = variabl1471[variabl2705];

}

}


for (int k1 = 0; k1 <= variabl2243; k1++) {

int k3 = variabl1063[k1];

if (k3 > 0) {

variabl26491[k3][4] = variabl26491[k3][4] + kuand

- variabl1471[k1];

}


}


int m1 = 0;

variabl2705 = 0;

for (int i = 0; i < variabl26491.length; i++) {

if (variabl26491[i][1] != variabl2705) {

variabl2705 = variabl26491[i][1];

m1 = 0;

}

variabl26491[i][6] = m1;

m1 = m1 + variabl26491[i][3] + variabl26491[i][4];

variabl26491[i][7] = variabl26491[i][1] - 1;

}


variabl1965.setRowCount(0);

for (int i = 0; i < variabl26491.length; i++) {

if ((variabl26491[i][2] > 0) && (variabl26491[i][2] < 98)) {

variabl2649[i][1] = variabl26491[i][1] + "";

variabl2649[i][2] = variabl26491[i][2] + "";

variabl2649[i][3] = variabl26491[i][3]

* variabl26491[i][9] + "";

variabl2649[i][4] = variabl26491[i][4]

* variabl26491[i][9] + "";

variabl2649[i][5] = (int) (variabl26491[i][5]

* variabl26491[i][9] * 2)

+ "";

variabl2649[i][6] = variabl26491[i][6]

* variabl26491[i][9] + "";

variabl2649[i][7] = (int) (variabl26491[i][7]

* variabl26491[i][9] * 2)

+ "";

variabl1965.addRow(variabl2649[i]);

}

}

}

});

panel1.add(countButton);


final JButton creButton = new JButton("表格内容存盘");

creButton.setBounds(530, 540, 120, 20);

creButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

char x1 = 10;

file1 = new File(fa10.getText());

if (!file1.exists()) {

try {

file1.createNewFile();

} catch (IOException e1) {

e1.printStackTrace();

}

}

try {

int k1 = 0;

String[] s6 = new String[100];

FileReader fr = new FileReader(file1);

BufferedReader br = new BufferedReader(fr);

String tempStr = null;

for (int i = 0; (tempStr = br.readLine()) != null; i++) {

if (!tempStr.substring(0, 2).equals("1,")) {

s6[k1] = tempStr;

k1++;

}

}

FileOutputStream fs;

fs = new FileOutputStream(file1);

for (int i = 0; i < k1; i++)

fs.write((s6[i] + x1).getBytes());

for (int i = 0; i < variabl1965.getRowCount(); i++) {

String s3 = "1,";

for (int j = 0; j < 11; j++) {

if ((variabl1965.getValueAt(i, j) != null)

&& (variabl1965.getValueAt(i, j).toString()

.length() > 0))

s3 = s3

+ variabl1965.getValueAt(i, j)

.toString() + "。";

else

s3 = s3 + " 。";

}

fs.write((s3 + x1).getBytes());

}

fs.close();

} catch (IOException e2) {

JOptionPane.showMessageDialog(null, "写文件错。");

}

}

});

panel1.add(creButton);


final JButton clearButton = new JButton("清参数文本框");

clearButton.setBounds(650, 540, 120, 20);

clearButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

fa1.setText("");

fa2.setText("0");

fa3.setText("0");

fa4.setText("0");

fa5.setText("0");

fa6.setText("0");

fa7.setText("宋体");

fa8.setText("0");

fa9.setText("");

fa11.setText("0");

fa12.setText("0");

}

});

panel1.add(clearButton);


final JButton exitButton = new JButton("退出");

exitButton.setBounds(770, 540, 120, 20);

exitButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

panel1.setVisible(false);

frame1.setVisible(false);

System.exit(0);

}

});


panel1.add(exitButton);


frame1.add(panel1);

frame1.setVisible(true);

}


public static void variabl1563() {

if (fa10.getText().length() > 0) {

file1 = new File(fa10.getText());

try {

if (file1.exists()) {

FileReader fr = new FileReader(file1);

BufferedReader br = new BufferedReader(fr);

String tempStr = null;

String[] s0;

for (int i = 0; (tempStr = br.readLine()) != null; i++) {

if (tempStr.substring(0, 2).equals("1,")) {

s0 = tempStr.substring(2, tempStr.length()).split(

"。");

variabl1965.addRow(tempStr.substring(2,

tempStr.length()).split("。"));

}

}

}

} catch (IOException e2) {

JOptionPane.showMessageDialog(null, "打开文件错!");

}

}

}

}

77.源码77,公共程序,为数据维护程序设置安全性控制条件。

     /* 

      * 程序文件名:secureTool.java 

      * 作者:程学先  

      * 功能:用于单记录数据维护部件设置安全性控制条件。 

      */ 

     import java.awt.*; 

     import java.awt.event.*; 

     import javax.swing.*; 

     import javax.swing.table.*; 

     import javax.swing.tree.DefaultMutableTreeNode; 

     import java.io.*; 

     import java.sql.Connection; 

     import java.sql.DatabaseMetaData; 

     import java.sql.DriverManager; 

     import java.sql.ResultSet; 

     import java.sql.ResultSetMetaData; 

     import java.sql.SQLException; 

     import java.sql.Statement; 

     import java.util.ArrayList; 

     import java.util.Vector; 

      

     public class secureTool extends JFrame { 

      private static secureTool frame2 = new secureTool(); 

      private static JPanel panel2 = new JPanel(); 

      private static DefaultTableModel variabl1965; 

      private static JTable variabl2655; 

      private static JScrollPane scrollPane = new JScrollPane(); 

      private static JScrollPane scrollPane1 = new JScrollPane(); 

      private static List list1 = new List(); 

      private static JLabel fl0, fl1, fl2, fl3, fl9; 

      private static JTextField fa0, fa1, fa2, fa3, fa9; 

      private static String variabl2327; 

      private static int variabl1823 = -1, variabl1947 = 0, variabl2193 = 0, variabl1739 = 0, variabl2651 = 0; 

      private static int variabl2127 = 0; 

      private static String[][] variabl2197; 

      private static ArrayList<String> variabl1665 = new ArrayList(); 

      private static String[] variabl25171; 

      private static int[] variabl1489; 

      private static String[] variabl2157 = new String[3]; 

      private static File file1; 

      private static ArrayList<String> list = new ArrayList<String>(); 

      static Connection con; 

      static String url; 

      static String variabl1275 = "sqlserver"; 

      static String variabl1091 = "sql1"; 

      private static Statement sta; 

      static String s1 = "", s2 = ""; 

      private static ResultSet rs; 

      private static ResultSetMetaData rsmd; 

      private static ArrayList variabl26031 = new ArrayList(); 

      

      public static void main(String args[]) { 

      frame2 = new secureTool(); 

      panel2 = new JPanel(); 

      scrollPane = new JScrollPane(); 

      scrollPane1 = new JScrollPane(); 

      list1 = new List(); 

      variabl1823 = -1; 

      variabl1947 = 0; 

      variabl2193 = 0; 

      variabl1739 = 0; 

      variabl2651 = 0; 

      variabl2127 = 0; 

      variabl1665 = new ArrayList(); 

      variabl2157 = new String[3]; 

      list = new ArrayList<String>(); 

      variabl1275 = "sqlserver"; 

      variabl1091 = "sql1"; 

      s1 = ""; 

      s2 = ""; 

      variabl26031 = new ArrayList(); 

      frame2.setTitle("许可字段号填写该用户对该表所能操作的字段的顺序号。权限标志包括:i、u、d、q、a等。    作者:程学先"); 

      frame2.setBounds(10, 10, 880, 660); 

      frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 

      panel2.setBounds(10, 10, 880, 660); 

      panel2.setLayout(null); 

      String[] variabl2517 = { "用户名称", "表名或字段号", "权限" }; 

      main1.driver1(); 

      fl0 = new JLabel("数据表名"); 

      fl0.setBounds(40, 10, 80, 20); 

      panel2.add(fl0); 

      fa0 = new JTextField(""); 

      fa0.setBounds(130, 10, 100, 20); 

      panel2.add(fa0); 

      fa0.addFocusListener(new FocusAdapter() { 

      public void focusGained(final FocusEvent arg0) { 

      variabl1739 = 0; 

      list1.removeAll(); 

      if (variabl26031.size() < 1) { 

      try { 

      con = main1.getConn(); 

      String[] tableType = { "TABLE" }; 

      DatabaseMetaData databaseMetaData = con.getMetaData(); 

      ResultSet resultSet = databaseMetaData.getTables(null, 

      null, "%", tableType); 

      while (resultSet.next()) { 

      variabl26031.add(resultSet.getString("TABLE_NAME")); 

     

      } catch (Exception e) { 

      e.printStackTrace(); 

     

     

      for (int i = 0; i < variabl26031.size(); i++) 

      list1.add(variabl26031.get(i).toString()); 

     

      }); 

      fl9 = new JLabel("文件名"); 

      fl9.setBounds(250, 10, 50, 20); 

      panel2.add(fl9); 

      fa9 = new JTextField("", 20); 

      fa9.setBounds(300, 10, 100, 20); 

      panel2.add(fa9); 

      fa9.addMouseListener(new MouseAdapter() { 

      public void mouseClicked(MouseEvent e) { 

      if (fa9.getText().length() < 1) { 

      final JFileChooser fc = new JFileChooser(".\\"); 

      fc.showOpenDialog(null); 

      if (fc.getSelectedFile() != null) 

      fa9.setText(fc.getSelectedFile().toString()); 

     

     

      }); 

      fa9.addMouseListener(new MouseAdapter() { 

      public void mouseClicked(MouseEvent e) { 

      file1 = new File(fa9.getText()); 

      try { 

      if (file1.exists()) { 

      FileReader fr = new FileReader(file1); 

      BufferedReader br = new BufferedReader(fr); 

      String tempStr = null; 

      variabl1665.clear(); 

      for (int i = 0; (tempStr = br.readLine()) != null; i++) { 

      if ((tempStr != null) && (tempStr.length() > 3)) { 

      if (tempStr.substring(0, 2).equals("2,")) { 

      variabl1965.addRow(tempStr.substring(2, 

      tempStr.length()).split("。")); 

      } else 

      variabl1665.add(tempStr); 

     

     

      } else if (fa9.getText().length() > 0) 

      file1.createNewFile();

      } catch (IOException e2) { 

      JOptionPane.showMessageDialog(null, "打开文件错!"); 

     

     

      }); 

      variabl1965 = new DefaultTableModel(variabl2197, variabl2517); 

      variabl2655 = new JTable(variabl1965); 

      variabl2655.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 

      variabl2655.addMouseListener(new MouseAdapter() { 

      public void mouseClicked(MouseEvent e) { 

      int variabl1823 = variabl2655.getSelectedRow(); 

      for (int j = 0; j < 3; j++) { 

      if (variabl1965.getValueAt(variabl1823, j) != null) 

      variabl2327 = variabl1965.getValueAt(variabl1823, j).toString(); 

      else 

      variabl2327 = ""; 

      switch (j) { 

      case 1: 

      fa1.setText(variabl2327.toString()); 

      break; 

      case 2: 

      fa2.setText(variabl2327.toString()); 

      break; 

      case 3: 

      fa3.setText(variabl2327.toString()); 

      break; 

     

     

     

      }); 

      scrollPane.setBounds(10, 40, 700, 400); 

      scrollPane.setViewportView(variabl2655); 

      panel2.add(scrollPane, BorderLayout.CENTER); 

      fl1 = new JLabel("用户名称"); 

      fl1.setBounds(30, 460, 80, 20); 

      panel2.add(fl1); 

      fa1 = new JTextField("", 20); 

      fa1.setBounds(110, 460, 100, 20); 

      panel2.add(fa1); 

      fa1.addFocusListener(new FocusAdapter() { 

      public void focusGained(final FocusEvent arg0) { 

      variabl1739 = 1; 

      list1.removeAll(); 

      try { 

      con = main1.getConn(); 

      

      sta = con.createStatement( 

      ResultSet.TYPE_SCROLL_INSENSITIVE, 

      ResultSet.CONCUR_UPDATABLE); 

      

      s1 = "select * from  用户表"; 

      rs = sta.executeQuery(s1); 

      rs.last(); 

      rsmd = rs.getMetaData(); 

      int row = rs.getRow(); 

      rs.first(); 

      variabl2651 = rsmd.getColumnCount(); 

      variabl25171 = new String[variabl2651]; 

      for (int i = 0; i < variabl2651; i++) { 

      variabl25171[i] = rsmd.getColumnName(i + 1); 

     

      String s0 = ""; 

      for (int j = 1; j <= row; j++) { 

      rs.absolute(j); 

      for (int i = 0; i < variabl2651; i++) { 

      if (variabl25171[i].equals("用户名")) { 

      s0 = rs.getString(i + 1).trim(); 

      list1.add(s0); 

     

     

     

      rs.close(); 

      sta.close(); 

      con.close(); 

      } catch (SQLException e) { 

      JOptionPane.showMessageDialog(null, "连接数据库出错!" + s1); 

     

     

      }); 

      variabl25171 = new String[0]; 

      fl2 = new JLabel("表名或字段号"); 

      fl2.setBounds(240, 460, 80, 20); 

      panel2.add(fl2); 

      fa2 = new JTextField("", 20); 

      fa2.setBounds(320, 460, 100, 20); 

      panel2.add(fa2); 

      fa2.addFocusListener(new FocusAdapter() { 

      public void focusGained(final FocusEvent arg0) { 

      variabl1739 = 2; 

      list1.removeAll(); 

      try { 

      con = main1.getConn(); 

      

      sta = con.createStatement( 

      ResultSet.TYPE_SCROLL_INSENSITIVE, 

      ResultSet.CONCUR_UPDATABLE); 

      s1 = "select * from " + fa0.getText(); 

      rs = sta.executeQuery(s1); 

      rs.last(); 

      rsmd = rs.getMetaData(); 

      variabl2651 = rsmd.getColumnCount(); 

      variabl25171 = new String[variabl2651]; 

      variabl1739 = 2; 

      for (int i = 0; i < variabl2651; i++) { 

      variabl25171[i] = rsmd.getColumnName(i + 1); 

     

      rs.close(); 

      sta.close(); 

      con.close(); 

      } catch (SQLException e) { 

      JOptionPane.showMessageDialog(null, "连接数据库出错!" + s1); 

     

      list1.add("*"); 

      list1.add(fa0.getText()); 

      for (int i = 0; i < variabl25171.length; i++) 

      list1.add(variabl25171[i]); 

     

      }); 

      fl3 = new JLabel("  权限"); 

      fl3.setBounds(450, 460, 60, 20); 

      panel2.add(fl3); 

      fa3 = new JTextField("", 20); 

      fa3.setBounds(510, 460, 100, 20); 

      panel2.add(fa3); 

      final String[] power1 = { "i        录入权限", "u        修改权限", 

      "d       删除权限", "q       查询显示权限", "a       全部权限" }; 

      fa3.addFocusListener(new FocusAdapter() { 

      public void focusGained(final FocusEvent arg0) { 

      variabl1739 = 3; 

      list1.removeAll(); 

      for (int i = 0; i < power1.length; i++) { 

      list1.add(power1[i]); 

     

     

      }); 

      list1.setBounds(720, 10, 120, 430); 

      panel2.add(list1); 

      list1.addMouseListener(new MouseAdapter() { 

      public void mouseClicked(MouseEvent e) { 

      int w1, w2, h1, h2; 

      switch (variabl1739) { 

      case 0: 

      fa0.setText(list1.getSelectedItem()); 

      break; 

      case 1: 

      fa1.setText(list1.getSelectedItem()); 

      variabl2127 = list1.getSelectedIndex(); 

      break; 

      case 2: 

      s2 = fa2.getText(); 

      if (list1.getSelectedIndex() < 2) 

      fa2.setText(list1.getSelectedItem()); 

      else if ((s2.trim().indexOf(fa0.getText()) >= 0) 

      || (s2.trim().indexOf("*") >= 0)) 

      fa2.setText((list1.getSelectedIndex() - 2) + ","); 

      else 

      fa2.setText(s2 + (list1.getSelectedIndex() - 2) + ","); 

      break; 

      case 3: 

      s2 = fa3.getText(); 

      fa3.setText(s2 

      + list1.getSelectedItem().substring(0, 5).trim() 

      + ","); 

      break; 

     

     

      }); 

      final JButton addButton = new JButton("添加到表格中"); 

      addButton.setBounds(20, 540, 140, 20); 

      addButton.addActionListener(new ActionListener() { 

      public void actionPerformed(ActionEvent e) { 

      int variabl1823 = -1; 

      for (int i = 0; i < variabl1965.getRowCount(); i++) { 

      if (variabl1965.getValueAt(i, 0) != null) 

      if (variabl1965.getValueAt(i, 0).equals(fa1.getText())) { 

      variabl1823 = i; 

      break; 

     

     

      if (variabl1823 < 0) { 

      String[] rowValues = { fa1.getText(), fa2.getText(), 

      fa3.getText() }; 

      variabl1965.addRow(rowValues); 

      int rowCount = variabl2655.getRowCount() + 1; 

      fa1.setText(""); 

      fa2.setText(""); 

      fa3.setText(""); 

      } else 

      JOptionPane.showMessageDialog(null, "存在重复,请改按修改!"); 

     

      }); 

      panel2.add(addButton); 

      final JButton updButton = new JButton("修改表格数据"); 

      updButton.setBounds(160, 540, 140, 20); 

      updButton.addActionListener(new ActionListener() { 

      public void actionPerformed(ActionEvent e) { 

      int variabl1823 = -1; 

      for (int i = 0; i < variabl1965.getRowCount(); i++) { 

      if ((variabl1965.getValueAt(i, 0) != null) 

      && (variabl1965.getValueAt(i, 0).equals(fa1.getText()))) { 

      variabl1823 = i; 

      break; 

     

     

      if (variabl1823 >= 0) { 

      variabl1965.setValueAt(fa1.getText(), variabl1823, 0); 

      variabl1965.setValueAt(fa2.getText(), variabl1823, 1); 

      variabl1965.setValueAt(fa3.getText(), variabl1823, 2); 

      } else 

      JOptionPane.showMessageDialog(null, "为新数据,请改按添加!"); 

     

      }); 

      panel2.add(updButton); 

      final JButton delButton = new JButton("从表格中删除"); 

      delButton.setBounds(300, 540, 130, 20); 

      delButton.addActionListener(new ActionListener() { 

      public void actionPerformed(ActionEvent e) { 

      int variabl1823 = variabl2655.getSelectedRow(); 

      if (variabl1823 != -1) 

      variabl1965.removeRow(variabl1823); 

     

      }); 

      panel2.add(delButton); 

      final JButton creButton = new JButton("表格内容存盘"); 

      creButton.setBounds(430, 540, 130, 20); 

      creButton.addActionListener(new ActionListener() { 

      public void actionPerformed(ActionEvent e) { 

      char x1 = 10, x2 = 13, x3 = '"', x4 = ','; 

      file1 = new File(fa9.getText()); 

      FileOutputStream fs; 

      try { 

      if (!file1.exists()) {

      file1.createNewFile();

     

      fs = new FileOutputStream(file1); 

      for (int i = 0; i < variabl1665.size(); i++) { 

      fs.write((variabl1665.get(i) + x1).getBytes()); 

     

      for (int i = 0; i < variabl1965.getRowCount(); i++) { 

      String s2 = "2,"; 

      for (int j = 0; j < 3; j++) { 

      if (variabl1965.getValueAt(i, j) != null) 

      s2 = s2 + variabl1965.getValueAt(i, j).toString() 

      + "。"; 

      else 

      s2 = s2 + "。"; 

     

      fs.write((s2 + x1).getBytes()); 

     

      fs.close(); 

      } catch (IOException e2) { 

      JOptionPane.showMessageDialog(null, "写文件错。"); 

     

     

      }); 

      panel2.add(creButton); 

      final JButton clearButton = new JButton("清参数文本框"); 

      clearButton.setBounds(560, 540, 130, 20); 

      clearButton.addActionListener(new ActionListener() { 

      public void actionPerformed(ActionEvent e) { 

      fa1.setText(""); 

      fa2.setText(""); 

      fa3.setText(""); 

     

      }); 

      panel2.add(clearButton); 

      final JButton exitButton = new JButton("退出"); 

      exitButton.setBounds(690, 540, 130, 20); 

      exitButton.addActionListener(new ActionListener() { 

      public void actionPerformed(ActionEvent e) { 

      panel2.setVisible(false); 

      frame2.setVisible(false); 

      System.exit(0); 

     

      }); 

      panel2.add(exitButton); 

      frame2.add(panel2); 

      frame2.setVisible(true); 

     

        } 




https://blog.sciencenet.cn/blog-2551-1120678.html

上一篇:管理信息系统软件生产线源码71-73
下一篇:管理信息系统软件生产线源码78-79
收藏 IP: 183.94.47.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-23 16:55

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部