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

博文

管理信息系统软件生产线源码92-94

已有 1154 次阅读 2018-7-5 15:57 |个人分类:生活点滴|系统分类:科研笔记| 软件生产线, 软部件, 数据库, 管理信息系统, JAVA

版本1

92.源码92,部件程序,设计与生成打印数据库中表格式标签报表格式文件。表格式标签指多个结构相同的表格打印在同一打印纸上,结构重复,内容可以根据记录变化,可以全相同。前者例如工资条、成绩单,后者例如数据通报。

/*

 * 程序文件名:printFormat6.java

 * 作者:程学先

 * 功能:设计与生成打印数据库中表格式标签报表格式文件。

 * 表格式标签指多个结构相同的表格打印在同一打印纸上,结构重复,

 * 内容可以根据记录变化,可以全相同。前者例如工资条、成绩单,后者例如空白工具条。

 * 本程序首先要求设计单个表格作为基本块,再说明标签特性,包括每行模块数、行间间隔、每列模块数、

 * 列间间隔、横向或纵向、每块是否包括列名

 * 其中,每行模块数指按打印纸横向有多少个重复结构的表格。

 * 每列模块数指按打印纸纵向每一页有多少个重复结构的表格。

 * 横向或纵向指打印的内容相对原数据表,一条记录是横向展开还是纵向展开。

 * 例如,打印工资条,其项目包括基本工资、职务工资、……等内容,这些内容是横向展开(允许的字段较少,

 * 有些还需要换行,分几行打印一个人的工资),也可以纵向展开,每人工资条为一竖条,数据纵向展开,

 * 允许一行内有更多的字段,但是,打印前需要做行、列倒置的操作。

 * 每块是否包括列名指例如工资条、成绩单,每一小表由标识数据和一条记录数据组成,要求回答是。

 * 也有的标签每个表格直接是数据表中某行或某几行,重复打印多份。

 * 描述表格的参数有:"标签名称", "字段名称","行号","宽度", "每行高度","字体","字号"

 * 行号指横向打印时每条记录可能分布在多行内,安排在字段名下第一行的各字段请填1,

 * 以下依次填2、3等。宽度为标签名称与字段宽度中较大者,在选字段时会自动加入参考值,请做检查。

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

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

 * 所有数据分二组保存在一个文件中,每组内容第一个数据标志组类型,

 * 1表示表格内容(根据记录情况重复),包括标签名称、字段名称、行号、……等。

 * 2表示标签特性,包括每行模块数、行间间隔、每列模块数、列间间隔、……等。

 */

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;

import java.io.*;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;


public class printFormat6 extends JFrame {

private static printFormat6 frame1 = new printFormat6();

private static printFormat6 frame2 = new printFormat6();

private static JPanel panel1 = new JPanel();

private static JPanel panel2 = new JPanel();

private static DefaultTableModel 表格模型1;

private static DefaultTableModel 表格模型2;

private static JTable 表格1;

private static JTable 表格2;

private static JScrollPane scrollPane1 = new JScrollPane();

private static JScrollPane scrollPane2 = new JScrollPane();

private static List list1 = new List();

private static List list2 = new List();

private static JLabel fl0, fl10;

private static JLabel fla1, fla2, fla3, fla4, fla5, fla6, fla7;

private static JTextField faa0, faa1, faa2, faa3, faa4, faa5, faa6, faa7, faa10;

private static JLabel flb1, flb2, flb3, flb4, flb5, flb6;

private static JTextField fab1, fab2, fab3, fab4, fab5, fab6;

private static String 当前值;

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

private static int 字段序号 = 0;

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

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

private static int[] 列数据宽度;

private static File file1;

static Connection con; // 连接数据库

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

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

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

private static ResultSetMetaData rsmd;

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

"14", "16", "18", "20", "22", "24", "26", "28", "36", "48", "72" };

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

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

private static String 连接条件 = "";

private static String 字段名表 = "";


public static void means(String[] parameter) {

frame1 = new printFormat6();

frame2 = new printFormat6();

panel1 = new JPanel();

panel2 = new JPanel();

scrollPane1 = new JScrollPane();

scrollPane2 = new JScrollPane();

list1 = new List();

list2 = new List();

当前列号 = 0;

列数 = 0;

字段序号 = 0;

s1 = "";

s2 = ""; // 临时变量

String 表名表 = parameter[0];

final String [] 表名1 = 表名表.split(",");

字号 = new String[19];

字体 = new String[4];

字号[0] = "5";

字号[1] = "6";

字号[2] = "7";

字号[3] = "8";

字号[4] = "9";

字号[5] = "10";

字号[6] = "11";

字号[7] = "12";

字号[8] = "14";

字号[9] = "16";

字号[10] = "18";

字号[11] = "20";

字号[12] = "22";

字号[13] = "24";

字号[14] = "26";

字号[15] = "28";

字号[16] = "36";

字号[17] = "48";

字号[18] = "72";

字体[0] = "宋体";

字体[1] = "楷体";

字体[2] = "黑体";

字体[3] = "仿宋_GB2312";

frame1.setTitle("报表表体内容设计页,每条记录打印一次。                                                                                                                                                                                                                                                                                                                                                      作者:程学先");

frame2.setTitle("打印报表页尾设计页,每页打印一次。                                                                                                                                                                                                                                                                                                                                                                                                                     作者:程学先");

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

frame2.setBounds(200, 10, 1000, 500);

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

frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

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

panel2.setBounds(200, 10, 800, 300);

panel1.setLayout(null);

panel2.setLayout(null);

String[] 列名01 = { "标签名称", "字段名称", "行号", "宽度", "每行高度", "字体", "字号" };

String[] 列名02 = { "每行模块数", "行间间隔", "每列模块数", "列间间隔", "横向或纵向", "每块是否包括列名" };

main1.driver1();

String 表名 = parameter[4];

数据表查询结构(表名);

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

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

panel1.add(fl0);

faa0 = new JTextField("");

faa0.setText(表名);

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

panel1.add(faa0);

faa0.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 0;

list1.removeAll();

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

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

}

});


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

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

panel1.add(fl10);

faa10 = new JTextField("", 20);

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

panel1.add(faa10);

faa10.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

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

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

fc.showOpenDialog(null);

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

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

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

try {

if (file1.exists()) {

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,")) {

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

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


}


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


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

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

}

}


}

} catch (IOException e2) {

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

}

}

}

}

});

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

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

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

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

表格1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

表格2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

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

scrollPane2.setBounds(10, 40, 800, 300);

scrollPane1.setViewportView(表格1);

scrollPane2.setViewportView(表格2);

panel1.add(scrollPane1, BorderLayout.CENTER);

panel2.add(scrollPane2, BorderLayout.CENTER);

fla1 = new JLabel("标签名称");

fla1.setBounds(10, 460, 60, 20);

panel1.add(fla1);

faa1 = new JTextField("", 20);

faa1.setBounds(70, 460, 100, 20);

panel1.add(faa1);

faa1.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 1;

list1.removeAll();

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

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

}

}

});


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

fla2.setBounds(170, 460, 60, 20);

panel1.add(fla2);

faa2 = new JTextField("", 20);

faa2.setBounds(230, 460, 100, 20);

panel1.add(faa2);

faa2.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 2;

list1.removeAll();

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

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

}

}

});


fla3 = new JLabel("行号");

fla3.setBounds(330, 460, 40, 20);

panel1.add(fla3);

faa3 = new JTextField("1", 20);

faa3.setBounds(370, 460, 60, 20);

panel1.add(faa3);

faa3.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 3;

list1.removeAll();

}

});


fla4 = new JLabel("宽度");

fla4.setBounds(430, 460, 40, 20);

panel1.add(fla4);

faa4 = new JTextField("0", 20);

faa4.setBounds(470, 460, 60, 20);

panel1.add(faa4);

faa4.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 4;

list1.removeAll();

}

});


fla5 = new JLabel("每行高度");

panel1.add(fla5);

faa5 = new JTextField("0", 20);

panel1.add(faa5);

fla5.setBounds(530, 460, 60, 20);

faa5.setBounds(590, 460, 60, 20);

faa5.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 5;

list1.removeAll();

}

});


fla6 = new JLabel("字体");

panel1.add(fla6);

faa6 = new JTextField("宋体", 20);

panel1.add(faa6);

fla6.setBounds(650, 460, 40, 20);

faa6.setBounds(690, 460, 80, 20);

faa6.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 6;

list1.removeAll();

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

list1.add(字体[i]);

}

}

});


fla7 = new JLabel("字号");

panel1.add(fla7);

faa7 = new JTextField("12", 20);

panel1.add(faa7);

fla7.setBounds(770, 460, 40, 20);

faa7.setBounds(810, 460, 80, 20);

faa7.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 7;

list1.removeAll();

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

list1.add(字号[i]);

}

}

});


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

panel1.add(list1);

list1.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

if (list1.getSelectedIndex() >= 0) {

int w1, w2, h1, h2;

String s0 = "";

switch (当前列号) {

case 0: // 表名

if (faa0.getText().length() == 0)

s0 = list1.getSelectedItem();

else

s0 = faa0.getText() + "," + list1.getSelectedItem();

faa0.setText(s0);

数据表查询结构(s0);

break;

case 1:

faa1.setText(list1.getSelectedItem());

faa2.setText(list1.getSelectedItem());

字段序号 = list1.getSelectedIndex();

if (((main1.文本数据类型 + main1.图形数据类型).lastIndexOf(","

+ 列数据类型[字段序号])) < 0) {

if (列数据宽度[字段序号] > 列名1[字段序号].length())

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

else

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


}

faa3.setText("1");

faa5.setText("1");

faa6.setText("宋体");

faa7.setText("12");

break;

case 2:

faa2.setText(list1.getSelectedItem());

break;

case 3:

faa3.setText(list1.getSelectedItem());

break;

case 4:

faa4.setText(list1.getSelectedItem());

break;

case 5:

faa5.setText(list1.getSelectedItem());

break;

case 6:

faa6.setText(list1.getSelectedItem());

break;

case 7:

faa7.setText(list1.getSelectedItem());

break;

}

}

}

});


表格1.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

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

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

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

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

else

当前值 = "";

switch (j) {

case 0:

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

break;

case 1:

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

break;

case 2:

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

break;

case 3:

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

break;

case 4:

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

break;

case 5:

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

break;

case 6:

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

break;

}

}

}

});


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

addButton1.setBounds(30, 510, 150, 20);

addButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int 选中行号 = -1, m = 0, n1 = 0, n2 = 0, n3 = 0;

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

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

&& (表格模型1.getValueAt(i, 0).toString().trim()

.equalsIgnoreCase(faa1.getText().trim()))) {

选中行号 = i;

break;

}

}

if (选中行号 < 0) { // 新行

String[] rowValues = { faa1.getText(), faa2.getText(),

faa3.getText(), faa4.getText(), faa5.getText(),

faa6.getText(), faa7.getText() };

表格模型1.addRow(rowValues);

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

faa1.setText("");

faa2.setText("");

faa3.setText("1");

faa4.setText("0");

faa5.setText("1");

faa6.setText("宋体");

faa7.setText("12");

} else

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

}

});

panel1.add(addButton1);


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

updButton1.setBounds(180, 510, 150, 20);

updButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int 选中行号 = -1;

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

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

&& (表格模型1.getValueAt(i, 0).toString().trim()

.equalsIgnoreCase(faa1.getText().trim()))) {

选中行号 = i;

break;

}

}

if (选中行号 >= 0) {

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

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

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

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

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

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

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

} else

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

}

});

panel1.add(updButton1);


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

delButton1.setBounds(330, 510, 150, 20);

delButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

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

if (选中行号 != -1)

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

}

});

panel1.add(delButton1);


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

countButton1.setBounds(480, 510, 150, 20);

countButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

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

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

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

for (int i = 0; i < 数据条数; i++) { // 保存为表格数据

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

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

}

for (int j = 2; j < 7; j++) {

if (j != 5) {

if (数据[i][j].length() > 0)

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

else

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

}

}

数据1[i][3] = 数据1[i][3] * 数据1[i][6]; // 宽度

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

数据1[i][4] = 数据1[i][4] * 数据1[i][6]; // 行高

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

}

表格模型1.setRowCount(0);

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

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

}

});

panel1.add(countButton1);


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

clearButton1.setBounds(630, 510, 150, 20);

clearButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

faa1.setText("");

faa2.setText("");

faa3.setText("1");

faa4.setText("0");

faa5.setText("1");

faa6.setText("宋体");

faa7.setText("12");

}

});

panel1.add(clearButton1); // 加入清参数文本框按钮


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

exitButton.setBounds(780, 510, 150, 20);

exitButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

panel1.setVisible(false);

frame1.setVisible(false);

frame1.dispose();

frame2.setVisible(false);

frame2.dispose();

}

});

panel1.add(exitButton);


flb1 = new JLabel("每行模块数");

flb1.setBounds(20, 360, 80, 20);

panel2.add(flb1);

fab1 = new JTextField("", 20);

fab1.setBounds(100, 360, 100, 20);

panel2.add(fab1);

fab1.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 1;

list2.removeAll();

}

});


flb2 = new JLabel("行间间隔");

flb2.setBounds(200, 360, 80, 20);

panel2.add(flb2);

fab2 = new JTextField("", 20);

fab2.setBounds(280, 360, 60, 20);

panel2.add(fab2);

fab2.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 2;

list2.removeAll();

}

});


flb3 = new JLabel("每列模块数");

flb3.setBounds(340, 360, 80, 20);

panel2.add(flb3);

fab3 = new JTextField("", 20);

fab3.setBounds(420, 360, 60, 20);

panel2.add(fab3);

fab3.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 3;

list2.removeAll();

}

});


flb4 = new JLabel("列间间隔");

flb4.setBounds(480, 360, 80, 20);

panel2.add(flb4);

fab4 = new JTextField("", 20);

fab4.setBounds(560, 360, 60, 20);

panel2.add(fab4);

fab4.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 4;

list2.removeAll();

}

});


flb5 = new JLabel("横向或纵向");

flb5.setBounds(620, 360, 80, 20);

panel2.add(flb5);

fab5 = new JTextField("", 20);

fab5.setBounds(700, 360, 60, 20);

panel2.add(fab5);

fab5.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 5;

list2.removeAll();

}

});


flb6 = new JLabel("每块是否包括列名");

flb6.setBounds(760, 360, 120, 20);

panel2.add(flb6);

fab6 = new JTextField("", 20);

fab6.setBounds(880, 360, 60, 20);

panel2.add(fab6);

fab6.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

当前列号 = 6;

list2.removeAll();

}

});

fab1.setText("1");

fab2.setText("2");

fab3.setText("1");

fab4.setText("2");

fab5.setText("横");

fab6.setText("是");

list2.setBounds(840, 10, 120, 330);

panel2.add(list2);

list2.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

if (list2.getSelectedIndex() >= 0) {

int w1, w2, h1, h2;

switch (当前列号) {

case 1:

fab1.setText(list2.getSelectedItem());

break;

case 2:

fab2.setText(list2.getSelectedItem());

break;

case 3:

fab3.setText(list2.getSelectedItem());

break;

case 4:

fab4.setText(list2.getSelectedItem());

break;

case 5:

fab5.setText(list2.getSelectedItem());

break;

case 6:

fab6.setText(list2.getSelectedItem());

break;

}

}

}

});


表格2.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

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

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

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

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

else

当前值 = "";

switch (j) {

case 0:

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

break;

case 1:

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

break;

case 2:

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

break;

case 3:

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

break;

case 4:

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

break;

case 5:

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

break;

}

}

}

});


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

addButton2.setBounds(30, 400, 150, 20);

addButton2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int 选中行号 = -1, m = 0, n1 = 0, n2 = 0, n3 = 0;

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

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

&& (表格模型2.getValueAt(i, 0).toString().trim()

.equalsIgnoreCase(fab1.getText().trim()))) {

选中行号 = i;

break;

}

}

if (选中行号 < 0) {

String[] rowValues = { fab1.getText(), fab2.getText(),

fab3.getText(), fab4.getText(), fab5.getText(),

fab6.getText() };

表格模型2.addRow(rowValues);

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

fab1.setText("1");

fab2.setText("2");

fab3.setText("1");

fab4.setText("2");

fab5.setText("横");

fab6.setText("是");

} else

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

}

});

panel2.add(addButton2);


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

updButton2.setBounds(180, 400, 150, 20);

updButton2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int 选中行号 = -1;

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

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

&& (表格模型2.getValueAt(i, 0).toString().trim()

.equalsIgnoreCase(fab1.getText().trim()))) {

选中行号 = i;

break;

}

}

if (选中行号 >= 0) {

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

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

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

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

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

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

} else

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

}

});

panel2.add(updButton2);


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

delButton2.setBounds(330, 400, 150, 20);

delButton2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

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

if (选中行号 != -1)

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

}

});

panel2.add(delButton2);


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

clearButton2.setBounds(480, 400, 150, 20);

clearButton2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

fab1.setText("1");

fab2.setText("2");

fab3.setText("1");

fab4.setText("2");

fab5.setText("横");

fab6.setText("是");

}

});

panel2.add(clearButton2);


final JButton creButton = new JButton("存入文件");

creButton.setBounds(630, 400, 150, 20);

creButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

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

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

FileOutputStream fs;

try {

fs = new FileOutputStream(file1);

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

String s3 = "1,", s4 = "";

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

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

&& (表格模型1.getValueAt(i, j).toString().length() > 0))

s3 = s3 + 表格模型1.getValueAt(i, j).toString()+ "。";

else

s3 = s3 + " 。";

}

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

}

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

String s3 = "2,", s4 = "";

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

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

&& (表格模型2.getValueAt(i, j).toString().length() > 0))

s3 = s3 + 表格模型2.getValueAt(i, j).toString()+ "。";

else

s3 = s3 + " 。";

}

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

}

fs.close();

} catch (IOException e2) {

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

}

}

});

panel2.add(creButton);


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

exitButton2.setBounds(780, 400, 150, 20);

exitButton2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

panel2.setVisible(false);

frame2.setVisible(false);

frame2.dispose();

frame1.setVisible(false);

frame1.dispose();

}

});

panel2.add(exitButton2);

frame2.add(panel2);

frame1.add(panel1);

frame2.setVisible(true);

frame1.setVisible(true);

}


static void 数据表查询结构(String 数据表名) {

String[] s10 = null;

String[] sk = new String[300];

int n1 = 0, n2 = 0;

字段名表 = "";

连接条件 = "";

if (数据表名.indexOf(",") < 0) { // 单表

try {

con = main1.getConn();

sta = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

String s1 = "select * from " + 数据表名;

rs = sta.executeQuery(s1);

rsmd = rs.getMetaData();

列数 = rsmd.getColumnCount();

列名1 = new String[列数];

字段名表 = "";

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

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

sk[i] = 列名1[i];

n1++;

if (字段名表.length() == 0)

字段名表 = 列名1[i];

else

字段名表 = 字段名表 + "," + 列名1[i];

}

rs.close();

sta.close();

con.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

} else { // 多表

s10 = 数据表名.split(",");

String s0 = "", s1 = "", s2 = "";

int k = 0;

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

try {

con = main1.getConn();

sta = con.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

s1 = "select * from " + s10[i];

rs = sta.executeQuery(s1);

rsmd = rs.getMetaData();

列数 = rsmd.getColumnCount();

for (int j = 0; j < 列数; j++) { // 读取所有表的列名,同名的加表名

s2 = rsmd.getColumnName(j + 1).toLowerCase(); // 列名

n2 = n1;

if (i > 0) { // 加入第2个表之后字段出现同名字段

k = 0;

for (int j1 = 0; j1 < n2; j1++) {

if (sk[j1].equals(s2)) {

sk[j1] = s10[i - 1] + "." + sk[j1];

if (连接条件.length() == 0) // 连接条件

连接条件 = " where " + s10[i - 1] + "."

+ s2 + " = " + s10[i] + "."+ s2;

else

连接条件 = 连接条件 + " and " + s10[i - 1]

+ "." + s2 + " = " + s10[i]+ "." + s2;

sk[n1] = s10[i] + "." + s2 + " as "+ (s2 + i);

n1++;

k = 1;

break;

}

}

if (k == 0) {

sk[n1] = s2;

n1++;

}

} else {

sk[n1] = s2;

n1++;

}

}

rs.close();

sta.close();

con.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

}

字段名表 = "";

for (int j1 = 0; j1 < n1; j1++)

if (字段名表.length() == 0)

字段名表 = sk[j1];

else

字段名表 = 字段名表 + "," + sk[j1];

}

try {

con = main1.getConn();

sta = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

s1 = "select " + 字段名表 + "  from " + 数据表名 + 连接条件;

rs = sta.executeQuery(s1);

rsmd = rs.getMetaData();

列数 = rsmd.getColumnCount();

列名1 = new String[列数];

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

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

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

列名1[i] = sk[i];

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

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

}

rs.close();

sta.close();

con.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

}

}

93.源码93,部件程序,表格式标签报表预览程序。根据printFormat6.java生成的格式文件打印预览。

/*

 * 程序文件名:dataPreview3.java

 * 作者:程学先

 * 功能:表格式标签报表预览程序。根据printFormat6.java生成的格式文件打印预览。

 * 必须输入的参数:数据表名、打印格式文件名。

 */

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Font;

import java.awt.GradientPaint;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.Rectangle;

import java.awt.RenderingHints;

import java.awt.Shape;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.awt.geom.GeneralPath;

import java.awt.geom.Point2D;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.LinkedList;

import java.util.List;

import java.util.Random;


import javax.swing.JButton;

import javax.swing.JComponent;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.ListSelectionModel;

import javax.swing.SwingUtilities;

import javax.swing.Timer;

import javax.swing.UIManager;

import javax.swing.table.DefaultTableModel;


public class dataPreview3 extends JComponent {

private static JFrame frame1;

private static JFrame frame2;

private static JPanel panel1 = new JPanel();

private static DefaultTableModel 表格模型1;

private static JTable 表格1;

private static JScrollPane scrollPane1 = new JScrollPane();

private static Connection cont4;

private static Statement stat4;

private static ResultSetMetaData rsmdt4;

private static ResultSet rs;

private static String 表名;

private static String 接口文件名;

private static String s1 = "";

private static int 记录条数 = 0, 列数 = 0, 选中行号 = -1;

private static String[] 列名;

private static String[] 列数据类型;

private static int[] 列数据宽度;

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

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

private static ArrayList<struct3> table1 = new ArrayList<struct3>();

private static ArrayList<struct4> table2 = new ArrayList<struct4>();

private static Graphics2D g3;

private static Graphics g;

private static int 每行模块数 = 0, 行间间隔 = 0, 每列模块数 = 0, 列间间隔 = 0;

private static String 横向或纵向 = "", 每块是否包括列名 = "";

private static int[] line;

private static int[] w10;

private static int[] h10;

private static int[] h20;

private static String[] f10;

private static String 字体 = "";

private static int 字号 = 0;

private static int 打印相同记录 = 0;

static String[] 按钮集 = null;

static String 要求按钮号表;

static int 窗口宽 = 0, 窗口高 = 0, 按钮数 = 0, 按钮宽 = 0;

private static String 连接条件 = "";

private static String 字段名表 = "";


protected void paintComponent(Graphics g1) {

g = g1;

g3 = (Graphics2D) g;

int x1 = 0, x2 = 0, y1 = 0, y2 = 0, y3 = 0;

int 左边 = 40, 到顶 = 30;

boolean b1 = true;

while (b1)

if (选中行号 < 0) {

选中行号 = 1;

} else

b1 = false;

y1 = 到顶;

x1 = 左边;

g3.setFont(new Font(字体, Font.PLAIN, 字号));

int k = 0;

k = 选中行号;

String s0 = "";

if (k <= 记录条数) {

if (横向或纵向.equals("横向")) {

for (int l = 0; l < 每列模块数; l++) {

y2 = y1;

for (int i = 0; i < 每行模块数; i++) {

x2 = x1;

for (int j = 0; j < 列名.length; j++) {

if ((k >= 记录条数) || (表格数据[k][j] == null))

s0 = "";

else

s0 = 表格数据[k][j];

g3.drawLine(x1, y1, x1 + w10[j], y1);

g3.drawLine(x1, y1, x1, y1 + h10[j]);

if (每块是否包括列名.equals("是"))

g3.drawString(f10[j], x1 + 2, y1 + h10[j]);

else

g3.drawString(表格数据[k][j], x1 + 2, y1 + h10[j]);

g3.drawLine(x1 + w10[j], y1, x1 + w10[j], y1+ h10[j]);

g3.drawLine(x1, y1 + h10[j], x1 + w10[j], y1+ h10[j]);

y3 = y1 + h10[j];

if (每块是否包括列名.equals("是")) {

g3.drawLine(x1, y1 + h10[j], x1, y1 + h10[j]* 2);

g3.drawString(表格数据[k][j], x1 + 2, y1 + h10[j]* 2);

g3.drawLine(x1 + w10[j], y1 + h10[j], x1

+ w10[j], y1 + h10[j] * 2);

g3.drawLine(x1, y1 + h10[j] * 2, x1 + w10[j],

y1 + h10[j] * 2);

y3 = y1 + h10[j] * 2;

}

x1 = x1 + w10[j];

if ((j < 列名.length - 1) && (line[j + 1] > 选中行号)) {

x1 = x2;

if (每块是否包括列名.equals("是"))

y1 = y1 + h10[列名.length - 1] * 2;

else

y1 = y1 + h10[列名.length - 1];

}

}

x1 = x1 + 行间间隔;

if (打印相同记录 == 1){

k++;

}

y1 = y2;

}

if (每块是否包括列名.equals("是"))

y1 = y1 + h10[列名.length - 1] * 2 + 列间间隔;

else

y1 = y1 + h10[列名.length - 1] + 列间间隔;

y1 = y3 + 列间间隔;

x1 = 左边;

}

   }

else {

int 标签宽 = 0;

int 字段宽 = 0;

for (int j = 0; j < 列名.length; j++) {

if (f10[j].length() > 标签宽)

标签宽 = f10[j].length();

if (w10[j] > 字段宽)

字段宽 = w10[j];

}

标签宽 = 标签宽 * 字号 + 2;

s0 = "";

if (k <= 记录条数) {

for (int l = 0; l < 每列模块数; l++) {

for (int i = 0; i < 每行模块数; i++) {

y2 = y1;

for (int j = 0; j < 列名.length; j++) {

if ((k >= 记录条数) || (表格数据[k][j] == null))

s0 = "";

else

s0 = 表格数据[k][j];

g3.drawLine(x1, y1, x1 + 标签宽, y1);

g3.drawLine(x1, y1, x1, y1 + h10[j]);

g3.drawString(f10[j], x1 + 2, y1 + h10[j]);

g3.drawLine(x1, y1 + h10[j], x1 + 标签宽, y1+ h10[j]);

g3.drawLine(x1 + 标签宽, y1, x1 + 标签宽 + 字段宽, y1);

g3.drawLine(x1 + 标签宽, y1, x1 + 标签宽, y1 + h10[j]);

g3.drawString(s0, x1 + 标签宽 + 2, y1 + h10[j]);

g3.drawLine(x1 + 标签宽 + 字段宽, y1, x1 + 标签宽 + 字段宽,

y1 + h10[j]);

g3.drawLine(x1 + 标签宽, y1 + h10[j], x1 + 标签宽

+ 字段宽, y1 + h10[j]);

y1 = y1 + h10[j];

}

if (打印相同记录 == 1){

k++;

}

y3 = y1;

y1 = y2;

x1 = x1 + 标签宽 + 字段宽 + 行间间隔;

}

y1 = y3 + 列间间隔;

x1 = 左边;

}

  } 

    }

}


static void means(String[] parameter) {

s1 = "";

记录条数 = 0;

列数 = 0;

table1 = new ArrayList<struct3>();

table2 = new ArrayList<struct4>();

panel1 = new JPanel();

scrollPane1 = new JScrollPane();

每行模块数 = 0;

行间间隔 = 0;

每列模块数 = 0;

列间间隔 = 0;

横向或纵向 = "";

每块是否包括列名 = "";

字体 = "";

字号 = 0;

打印相同记录 = 0;

String[] 按钮集01 = { "预览相同记录", "依次预览记录", "退出" };

按钮集 = new String[按钮集01.length];

按钮数 = 0;

for (int i0 = 0; i0 < 按钮集01.length; i0++)

按钮集[i0] = 按钮集01[i0];

if (parameter[11].length() > 0) {

要求按钮号表 = parameter[11];

要求按钮号表 = 要求按钮号表.replaceAll(";", ";");

要求按钮号表 = 要求按钮号表.replaceAll("。", ";");

要求按钮号表 = 要求按钮号表.replaceAll(":", ";");

要求按钮号表 = 要求按钮号表.replaceAll(":", ";");

if (要求按钮号表.indexOf(";") > 0) { // 如果有按钮更名要求

String s601[] = 要求按钮号表.split(",");

要求按钮号表 = "";

for (int i01 = 0; i01 < s601.length; i01++) {

if (s601[i01].indexOf(";") > 0) {

String s602[] = s601[i01].split(";");

按钮集[Integer.parseInt((s602[0]))] = s602[1];

要求按钮号表 = 要求按钮号表 + "," + s602[0];// 只留号,去更名

按钮数++;

} else {

要求按钮号表 = 要求按钮号表 + "," + s601[i01];// 只留号,原无更名

按钮数++;

}

}

else {

String s601[] = 要求按钮号表.split(",");

要求按钮号表 = "";

for (int i01 = 0; i01 < s601.length; i01++) {

if (i01 == 0)

要求按钮号表 = s601[i01];

else

要求按钮号表 = 要求按钮号表 + "," + s601[i01];

按钮数++;

}

}


} else {

要求按钮号表 = ""; // 没输入要求按钮号,定全部按钮号

for (int i1 = 0; i1 < 按钮集.length; i1++) {

if (i1 == 0)

要求按钮号表 = 要求按钮号表 + i1;

else

要求按钮号表 = 要求按钮号表 + "," + i1;

按钮数++;

}

}

要求按钮号表 = "," + 要求按钮号表 + ",";

窗口宽 = main1.窗口宽;

窗口高 = main1.窗口高;

int m1, m2;

try {

if (parameter[17].length() == 0) {

m1 = 0;

m2 = 0;

} else {

m1 = Integer.parseInt(parameter[17]);// 宽度参数

m2 = Integer.parseInt(parameter[18]);

}

if (m1 > 0) {

if (m2 < 80) {

m1 = m1 * 10;

m2 = m2 * 10;

}

窗口宽 = m1;

窗口高 = m2;

}

} catch (Exception e2) {

}

表名 = parameter[4];

接口文件名 = parameter[15];

frame1 = new JFrame("表格标签式报表预览程序                           作者:程学先");

frame1.setBounds(10, 10, 1200, 600);

File file1 = new File(接口文件名);

try {

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

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,")) {

table1.add(new struct3(tempStr.substring(2,

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

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

table2.add(new struct4(tempStr.substring(2,

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

}

}

}

} catch (IOException e2) {

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

}

struct3[] 表体 = new struct3[table1.size()];

line = new int[table1.size()];

w10 = new int[table1.size()];

h10 = new int[table1.size()];

h20 = new int[table1.size()];

f10 = new String[table1.size()];

for (int i = 0; i < table1.size(); i++) {

表体[i] = table1.get(i);

line[i] = Integer.valueOf(表体[i].table1[2]);

w10[i] = Integer.valueOf(表体[i].table1[3]);

h10[i] = (int) (Integer.valueOf(表体[i].table1[4]) * 1.5);

h20[i] = Integer.valueOf(表体[i].table1[6]);

f10[i] = 表体[i].table1[0];

}

字体 = 表体[0].table1[5];

字号 = Integer.valueOf(表体[0].table1[6]);

struct4[] 标签 = new struct4[table2.size()];

标签[0] = table2.get(0);

每行模块数 = Integer.valueOf(标签[0].table2[0]);

行间间隔 = Integer.valueOf(标签[0].table2[1]);

每列模块数 = Integer.valueOf(标签[0].table2[2]);

列间间隔 = Integer.valueOf(标签[0].table2[3]);

横向或纵向 = 标签[0].table2[4];

每块是否包括列名 = 标签[0].table2[5];

字段名表 = "";

for (int i = 0; i < table1.size(); i++) {

if (字段名表.length() == 0)

字段名表 = table1.get(i).table1[1];

else

字段名表 = 字段名表 + "," + table1.get(i).table1[1];

}

数据表查询结构(表名);

数据表查询数据(表名);

panel1.setBounds(50, 260, 1000, 500);

panel1.setLayout(null);

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

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

表格1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

scrollPane1.setBounds(50, 60, 1000, 400);

scrollPane1.setViewportView(表格1);

panel1.add(scrollPane1, BorderLayout.CENTER);

表格1.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

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

}

});

int 左边距 = 100;

按钮宽 = (窗口宽 - 左边距 - 30) / 按钮数;

final JButton printButton1 = new JButton(按钮集[0]);

printButton1.setBounds(左边距, 460, 按钮宽, 20);

printButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

打印相同记录 = 0;

frame2.setVisible(false);

frame2.add(new dataPreview3());

frame2.setVisible(true);

}

});

if (要求按钮号表.indexOf(",0,") >= 0) {

左边距 = 左边距 + 按钮宽;

panel1.add(printButton1);

}


final JButton printButton2 = new JButton(按钮集[1]);

printButton2.setBounds(左边距, 460, 按钮宽, 20);

printButton2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

打印相同记录 = 1;

frame2.setVisible(false);

frame2.add(new dataPreview3());

frame2.setVisible(true);

}

});

if (要求按钮号表.indexOf(",1,") >= 0) {

左边距 = 左边距 + 按钮宽;

panel1.add(printButton2);

}


final JButton exitButton = new JButton(按钮集[2]);

exitButton.setBounds(左边距, 460, 按钮宽, 20);

exitButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

panel1.setVisible(false);

frame1.setVisible(false);

}

});

if (要求按钮号表.indexOf(",2,") >= 0) {

左边距 = 左边距 + 按钮宽;

panel1.add(exitButton);

}


frame2 = new JFrame("表格标签式报表预览  ");

frame2.setBounds(10, 10, 1300, 700);

frame1.add(panel1);

frame1.setVisible(true);

}


static void 数据表查询结构(String 数据表名) {

String[] s10 = null;

String[] sk = new String[300];

int n1 = 0, n2 = 0;

连接条件 = "";

if (数据表名.indexOf(",") < 0) { // 单表

try {

cont4 = main1.getConn();

stat4 = cont4.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

String s1 = "select * from " + 数据表名;

rs = stat4.executeQuery(s1);

rsmdt4 = rs.getMetaData();

列数 = rsmdt4.getColumnCount();

列名 = new String[列数];

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

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

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

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

}

rs.close();

stat4.close();

cont4.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

} else { // 多表

s10 = 数据表名.split(",");

String s0 = "", s1 = "", s2 = "";

int k = 0;

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

try {

cont4 = main1.getConn();

stat4 = cont4.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

s1 = "select * from " + s10[i];

rs = stat4.executeQuery(s1);

rsmdt4 = rs.getMetaData();

列数 = rsmdt4.getColumnCount();

for (int j = 0; j < 列数; j++) { // 读取所有表的列名,同名的加表名

s2 = rsmdt4.getColumnName(j + 1).toLowerCase(); // 列名

n2 = n1;

if (i > 0) { // 加入第2个表之后字段出现同名字段

k = 0;

for (int j1 = 0; j1 < n2; j1++) {

if (sk[j1].equals(s2)) {

sk[j1] = s10[i - 1] + "." + sk[j1];

if (连接条件.length() == 0) // 连接条件

连接条件 = " where " + s10[i - 1] + "."

+ s2 + " = " + s10[i] + "."+ s2;

else

连接条件 = 连接条件 + " and " + s10[i - 1]

+ "." + s2 + " = " + s10[i]+ "." + s2;

sk[n1] = s10[i] + "." + s2 + " as "+ (s2 + i);

n1++;

k = 1;

break;

}

}

if (k == 0) {

sk[n1] = s2;

n1++;

}

} else {

sk[n1] = s2;

n1++;

}

}

rs.close();

stat4.close();

cont4.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

}

}

}


static void 数据表查询数据(String 数据表名) {

int c = 0;

int b = 0;

try {

cont4 = main1.getConn();

stat4 = cont4.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

s1 = "select " + 字段名表 + "  from " + 数据表名 + 连接条件;

rs = stat4.executeQuery(s1);

rsmdt4 = rs.getMetaData();

列数 = rsmdt4.getColumnCount();

列名 = new String[列数];

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

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

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

列名[i1] = rsmdt4.getColumnName(i1 + 1);

列数据类型[i1] = rsmdt4.getColumnTypeName(i1 + 1);

列数据宽度[i1] = rsmdt4.getColumnDisplaySize(i1 + 1);

}

rs.last();

记录条数 = rs.getRow();

表格数据 = new String[记录条数][列数];

表格数据0 = new String[记录条数][列数];

while (c < 记录条数) {

rs.absolute(c + 1);

while (b < 列数) {

表格数据0[c][b] = rs.getString(b + 1);

if ((main1.数字数据类型.lastIndexOf("," + 列数据类型[b] + ",")) > 0)

if ((表格数据0[c][b] == null)

|| (表格数据0[c][b].trim().length() == 0))

表格数据0[c][b] = "0";

else if (表格数据0[c][b] == null)

表格数据0[c][b] = "";

表格数据[c][b] = 表格数据0[c][b];

b++;

}

c++;

b = 0;

}

rs.close();

stat4.close();

cont4.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

}

   }



94.源码94,部件程序,表格式标签报表打印程序。根据printFormat6.java生成的格式文件打印。

/*

 * 程序文件名:dataPrint3.java

 * 作者:程学先

 * 功能:表格式标签报表打印程序。根据printFormat6.java生成的格式文件打印。

 * 必须输入的参数:数据表名、打印格式文件名。

 * 调用命令:dataPrint3.means(parameter)

 */

import java.awt.BasicStroke;

import java.awt.BorderLayout;

import java.awt.Color;  

import java.awt.Font;

import java.awt.GradientPaint;  

import java.awt.Graphics;  

import java.awt.Graphics2D;  

import java.awt.event.ActionEvent;  

import java.awt.event.ActionListener;  

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.awt.print.PageFormat;

import java.awt.print.Printable;

import java.awt.print.PrinterException;

import java.awt.print.PrinterJob;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import javax.swing.JButton;

import javax.swing.JComponent;  

import javax.swing.JFrame;  

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.ListSelectionModel;

import javax.swing.table.DefaultTableModel;


public class dataPrint3 extends JComponent{  

private static JFrame frame1;

private static JFrame frame2;

    private static JPanel panel1 = new JPanel();    

    private static DefaultTableModel 表格模型1;

    private static JTable 表格1; 

    private static JScrollPane scrollPane1 = new JScrollPane(); 

private static Connection cont4; 

private static Statement stat4;

private static ResultSetMetaData rsmdt4; 

private static ResultSet rs;  

private static String 表名 ; 

private static String 接口文件名;

private static String s1="";

private static int 记录条数 = 0,列数 = 0,选中行号=-1;

private static String [] 列名; 

private static String [] 列数据类型;

private static int [] 列数据宽度; 

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

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

private static ArrayList<struct3> table1=new ArrayList<struct3>();

private static ArrayList<struct4> table2=new ArrayList<struct4>();

private static Graphics2D g3;

private static Graphics g;

private static PageFormat pf;

private static PrinterJob job;

private static int 每行模块数=0,行间间隔=0,每列模块数=0,列间间隔=0;

private static String 横向或纵向="",每块是否包括列名="";

private static int [] line;

private static int [] w10; 

private static int [] h10; 

private static int [] h20;

    private static String[] f10; 

    private static String 字体="";

    private static int 字号=0;

    private static int 打印相同记录=0;

static String [] 按钮集=null;

static String 要求按钮号表;

static int 窗口宽=0,窗口高=0,按钮数=0,按钮宽=0;

static String 连接条件="";

static String 字段名表="";

    static void means(String [] parameter){

    panel1 = new JPanel();    

    scrollPane1 = new JScrollPane(); 

    s1="";记录条数 = 0;列数 = 0;选中行号=-1;

    table1=new ArrayList<struct3>();

    table2=new ArrayList<struct4>();

    每行模块数=0;行间间隔=0;每列模块数=0;列间间隔=0;

    横向或纵向="";每块是否包括列名="";字体="";字号=0;打印相同记录=0;

    String [] 按钮集01={"打印相同记录","依次打印记录","退出"};

        按钮集=new String[按钮集01.length];

        按钮数=0;

        for (int i0=0;i0<按钮集01.length;i0++)

          按钮集[i0]= 按钮集01[i0];

if (parameter[11].length()>0){

要求按钮号表=parameter[11] ;

要求按钮号表=要求按钮号表.replaceAll(";",";");

要求按钮号表=要求按钮号表.replaceAll("。",";");

要求按钮号表=要求按钮号表.replaceAll(":",";");

要求按钮号表=要求按钮号表.replaceAll(":",";");

if (要求按钮号表.indexOf(";")>0){   //如果有按钮更名要求

String s601[]=要求按钮号表.split(",");

要求按钮号表="";

for (int i01=0;i01<s601.length;i01++){

if (s601[i01].indexOf(";")>0){

String s602[]=s601[i01].split(";");

按钮集[Integer.parseInt((s602[0]))]=s602[1];

要求按钮号表=要求按钮号表+","+s602[0];//只留号,去更名

按钮数++;

}

else {

要求按钮号表=要求按钮号表+","+s601[i01];//只留号,原无更名

按钮数++;

}

}

}  

else {

String s601[]=要求按钮号表.split(",");

要求按钮号表="";

for (int i01=0;i01<s601.length;i01++){

               if (i01==0) 要求按钮号表=s601[i01];

               else 要求按钮号表=要求按钮号表+s601[i01];

               按钮数++;

   }

}

}

else {

要求按钮号表="";  //没输入要求按钮号,定全部按钮号

for (int i1=0;i1<按钮集.length;i1++){

if (i1==0) 要求按钮号表=要求按钮号表+i1;

else 要求按钮号表=要求按钮号表+","+i1;

    按钮数++;

}

}

要求按钮号表=","+要求按钮号表+",";

窗口宽=main1.窗口宽;  窗口高=main1.窗口高;

int m1,m2;

try{

if (parameter[17].length()==0) {

m1=0;m2=0;

}

else {

m1=Integer.parseInt(parameter[17]) ;//宽度参数

m2=Integer.parseInt(parameter[18]) ;

}

if (m1>0){

if (m2<80){

m1=m1*10;

m2=m2*10;

}

   窗口宽=m1 ;

   窗口高=m2 ;

}

}catch(Exception e2){}

    表名=parameter[4];

    接口文件名=parameter[15];

        frame1 = new JFrame();  

        frame1.setTitle("表格标签式报表程序                                                                                                                                                                                                                                                                                                                                                    作者:程学先"); 

        frame1.setBounds(10,10,1200, 600); 

    File file1 = new File(接口文件名);

        try{  

          if (file1.exists()) { 

           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,")){ 

        table1.add(new struct3(tempStr.substring(2,tempStr.length()).split("。")));

      }

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

      table2.add(new struct4(tempStr.substring(2,tempStr.length()).split("。")));

      }

      }

      }

        }catch(IOException e2) {  

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

        }

        struct3 [] 表体=new struct3[table1.size()];

        line=new int[table1.size()]; 

        w10=new int[table1.size()]; 

        h10=new int[table1.size()]; 

        h20=new int[table1.size()]; 

        f10=new String[table1.size()];  

        for(int i=0;i<table1.size();i++){

                     表体[i]=table1.get(i);

            line[i]=Integer.valueOf(表体[i].table1[2]);

           w10[i]=Integer.valueOf(表体[i].table1[3]);

           h10[i]=(int)(Integer.valueOf(表体[i].table1[4])*1.5);

           h20[i]=Integer.valueOf(表体[i].table1[6]); 

           f10[i]=表体[i].table1[0];

        }

              字体=表体[0].table1[5];

              字号=Integer.valueOf(表体[0].table1[6]);

      struct4 [] 标签=new struct4[table2.size()];

    标签[0]=table2.get(0);

    每行模块数=Integer.valueOf(标签[0].table2[0]);

    行间间隔=Integer.valueOf(标签[0].table2[1]);

    每列模块数=Integer.valueOf(标签[0].table2[2]);

    列间间隔=Integer.valueOf(标签[0].table2[3]);

    横向或纵向=标签[0].table2[4];

    每块是否包括列名=标签[0].table2[5];

        字段名表="";

        for (int i=0;i<table1.size();i++){

        if (字段名表.length()==0) 字段名表=table1.get(i).table1[1];

        else 

        字段名表=字段名表+","+table1.get(i).table1[1]; 

        }

        数据表查询结构(表名);

        数据表查询数据(表名);

        panel1.setBounds(50, 260, 1000, 500);      

        panel1.setLayout(null);        

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

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

        表格1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        scrollPane1.setBounds(50, 60,1000, 400);  

        scrollPane1.setViewportView(表格1); 

        panel1.add(scrollPane1, BorderLayout.CENTER); 

        pf = new PageFormat();

        pf.setOrientation(PageFormat.LANDSCAPE);

        表格1.addMouseListener(new MouseAdapter() {

            public void mouseClicked(MouseEvent e) { 

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

        }});

按钮宽=(窗口宽-60)/按钮数;

int 左边距=30;

        final JButton printButton1 = new JButton(按钮集[0]);  

        printButton1.setBounds(左边距,460,按钮宽, 20);

        printButton1.addActionListener(new ActionListener() { 

            public void actionPerformed(ActionEvent e) {  

            打印相同记录=0;

                try {

                    if (!job.printDialog())

                        return;

                   dataPrint3.job.print();

                 } catch (Exception e1) {  

                     e1.printStackTrace();

                 }

          }

        });

        if (要求按钮号表.indexOf(",0,")>=0) {

        左边距=左边距+按钮宽;

            panel1.add(printButton1);  

        }


        final JButton printButton2 = new JButton(按钮集[1]);  

        printButton2.setBounds(左边距,460,按钮宽, 20);

        printButton2.addActionListener(new ActionListener() {  

            public void actionPerformed(ActionEvent e) {  

            打印相同记录=1;

                 try {

                    if (!job.printDialog())

                        return;

                   dataPrint3.job.print();

                 } catch (Exception e1) {

                     e1.printStackTrace();

                 }

           }

        });

        if (要求按钮号表.indexOf(",1,")>=0) {

        左边距=左边距+按钮宽;

            panel1.add(printButton2);  

        }


        final JButton exitButton = new JButton(按钮集[2]); 

        exitButton.setBounds(左边距,460,按钮宽, 20);

        exitButton.addActionListener(new ActionListener() { 

            public void actionPerformed(ActionEvent e) { 

            panel1.setVisible(false); 

            frame1.setVisible(false);

    frame1.dispose();

           }

        });

        if (要求按钮号表.indexOf(",2,")>=0) {

        左边距=左边距+按钮宽;

             panel1.add(exitButton);  

        }

       job = PrinterJob.getPrinterJob(); 

       job.setPrintable(new Printable() {

           public int print(Graphics graphics, PageFormat pageFormat,

                   int pageIndex) throws PrinterException {

            dataPrint3.g=graphics;

                if (pageIndex < 1) {

                g3 = (Graphics2D)g; 

                    g3.setStroke(new BasicStroke(1f));

                    int x1=0,x2=0,y1=0,y2=0,y3=0,w1=0,h1=0;

                int 左边=40,到顶=30,行号=0;

                    boolean b1=true;

                    while (b1)

                    if (选中行号<0)  {

                    JOptionPane.showMessageDialog( null,"请在表格中选中一行记录!");

                    }

                    else b1=false;

                y1=到顶;

                    x1=左边;

                  g3.setFont(new Font(字体,Font.PLAIN,字号));

                    int 打印行号=1;

                  int k=0;  

                  k=选中行号;

                       String s0="";

                  if (k<=记录条数)  {

                    if (横向或纵向.equals("横向")) {

                   for (int l=0;l<每列模块数;l++){

                  y2=y1;    

                 for(int i=0;i<每行模块数;i++){

                  x2=x1;

                    for(int j=0;j<列名.length;j++){

                      if ((k>=记录条数)||(表格数据[k][j]==null)) 

                      s0="";

                      else   s0=表格数据[k][j];

                  g3.drawLine(x1, y1, x1+  w10[j], y1);

                  g3.drawLine(x1, y1, x1, y1+h10[j]);

                  if (每块是否包括列名.equals("是"))

                  g3.drawString(f10[j],x1+2, y1+h10[j]);

                  else g3.drawString(s0,x1+2, y1+h10[j]);

                  g3.drawLine(x1+w10[j],y1,x1+w10[j],y1+h10[j]);

                  g3.drawLine(x1,y1+h10[j], x1+w10[j],y1+h10[j]);

                  y3=y1+h10[j];

                  if (每块是否包括列名.equals("是")){

                  g3.drawLine(x1, y1+h10[j], x1, y1+h10[j]*2);

                  g3.drawString(s0,x1+2, y1+h10[j]*2);

                  g3.drawLine(x1+w10[j],y1+h10[j],x1+w10[j],y1+h10[j]*2);

                  g3.drawLine(x1,y1+h10[j]*2, x1+w10[j],y1+h10[j]*2);

                  y3=y1+h10[j]*2;

                  }

                           x1=x1+w10[j];

                        if ((j<列名.length-1)&&(line[j+1]>打印行号)){  

                         打印行号++;

                        x1=x2;

                            if (每块是否包括列名.equals("是"))

                            y1=y1+h10[列名.length-1]*2;

                        else

                        y1=y1+h10[列名.length-1];

                        }

                        }

                      x1=x1+行间间隔;

if (打印相同记录 == 1){

k++;

}

                                                 打印行号=1;

                      y1=y2;

                }

                 if (每块是否包括列名.equals("是"))

                  y1=y1+h10[列名.length-1]*2+列间间隔;

                 else

                  y1=y1+h10[列名.length-1]+列间间隔;

                y1=y3+列间间隔;

                     x1=左边;

                   }

                    }

                     else {   

                       int 标签宽=0;

                       int 字段宽=0;

                       for(int j=0;j<列名.length;j++){

                      if (f10[j].length()>标签宽)  标签宽=f10[j].length();

                      if (w10[j]>字段宽)  字段宽=w10[j];

                       }

                                                           标签宽=标签宽*字号+2;

                        s0="";

                      if (k<=记录条数)  {

                      for (int l=0;l<每列模块数;l++){

                       for(int i=0;i<每行模块数;i++){

                           y2=y1;

                      for(int j=0;j<列名.length;j++){

                      if ((k>=记录条数)||(表格数据[k][j]==null)) 

                      s0="";

                      else   s0=表格数据[k][j];

                  g3.drawLine(x1, y1, x1+标签宽, y1);

                  g3.drawLine(x1, y1, x1, y1+h10[j]);

                  g3.drawString(f10[j],x1+2, y1+h10[j]);

                  g3.drawLine(x1,y1+h10[j], x1+标签宽,y1+h10[j]);

                  g3.drawLine(x1+标签宽, y1, x1+标签宽+字段宽, y1);

                  g3.drawLine(x1+标签宽, y1, x1+标签宽, y1+h10[j]);

                  g3.drawString(s0,x1+标签宽+2, y1+h10[j]);

                  g3.drawLine(x1+标签宽+字段宽,y1,x1+标签宽+字段宽,y1+h10[j]);

                  g3.drawLine(x1+标签宽,y1+h10[j], x1+标签宽+字段宽,y1+h10[j]);

                  y1=y1+h10[j];

                        }

if (打印相同记录 == 1){

k++;

}

                       y3=y1;

                     y1=y2;

                        x1=x1+标签宽+字段宽+行间间隔;

                     }

                           y1=y3+列间间隔;

                           x1=左边;

                   }

                    } 

           

                }

                return Printable.PAGE_EXISTS;

              } else {

                  return Printable.NO_SUCH_PAGE;

             }

           }

       });

       

        frame2 = new JFrame("表格标签式报表打印");  

        frame2.setBounds(10,10,1200, 600); 

       frame1.add(panel1); 

       frame1.setVisible(true);  

    }  

static void 数据表查询结构(String 数据表名) {

String [] s10=null;

String [] sk=new String[300];

int n1=0,n2=0;

连接条件="";

if (数据表名.indexOf(",")<0){    //单表

try {

cont4 = main1.getConn();

stat4 = cont4.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

String s1 = "select * from " + 数据表名;

rs = stat4.executeQuery(s1);

rsmdt4 = rs.getMetaData();

列数 = rsmdt4.getColumnCount();

列名 = new String[列数];

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

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

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

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

}

rs.close();

stat4.close();

cont4.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

 }

else {       //多表

s10=数据表名.split(",");

String s0="",s1="",s2="";

int k=0;

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

try {

cont4 = main1.getConn();

stat4 = cont4.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

s1 = "select * from " + s10[i];

rs = stat4.executeQuery(s1);

rsmdt4 = rs.getMetaData();

列数 = rsmdt4.getColumnCount();

for (int j = 0; j < 列数; j++) {  //读取所有表的列名,同名的加表名

s2 = rsmdt4.getColumnName(j + 1).toLowerCase();   //列名

n2=n1;

if (i>0){  //加入第2个表之后字段出现同名字段

k=0;

  for (int j1=0;j1<n2;j1++){

  if (sk[j1].equals(s2)){

  sk[j1]=s10[i-1]+"."+sk[j1];

  if (连接条件.length()==0)  //连接条件

  连接条件=" where "+s10[i-1]+"."+s2+" = "+s10[i]+"."+s2;

  else 连接条件=连接条件+" and "+s10[i-1]+"."+s2+" = "+s10[i]+"."+s2;

sk[n1]=s10[i]+"."+s2+" as "+(s2+i);

n1++;

k=1;

break;

  }

  }

if (k==0) {

sk[n1]=s2;

n1++;

  }

}

else {

sk[n1]=s2;

n1++;

}

}

rs.close();

stat4.close();

cont4.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

}

   }

}

static void 数据表查询数据(String 数据表名) {

int c = 0;

int b = 0;

try {

cont4 = main1.getConn();

stat4 = cont4.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

s1 = "select " + 字段名表 + "  from " + 数据表名 + 连接条件;

            rs = stat4.executeQuery(s1);

            rsmdt4 = rs.getMetaData();

            列数 = rsmdt4.getColumnCount();

            列名 = new String[列数];

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

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

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

            列名[i1]=rsmdt4.getColumnName(i1+1);

  列数据类型[i1] = rsmdt4.getColumnTypeName(i1+1);

列数据宽度[i1] = rsmdt4.getColumnDisplaySize(i1+1);

            }

rs.last();

记录条数=rs.getRow();

表格数据=new String[记录条数][列数];

表格数据0=new String[记录条数][列数];

 while (c < 记录条数) {

rs.absolute(c + 1);

while (b < 列数) {

表格数据0[c][b] = rs.getString(b + 1); 

if ((main1.数字数据类型.lastIndexOf("," + 列数据类型[b] + ",")) > 0)

if ((表格数据0[c][b] == null)

|| (表格数据0[c][b].trim().length() == 0))

表格数据0[c][b] = "0";

else if (表格数据0[c][b] == null)

表格数据0[c][b] = "";

表格数据[c][b] = 表格数据0[c][b];

b++;

}

c++;

b = 0;

}

rs.close();

stat4.close();

cont4.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

   }  

    }  

版本2

92.源码92,部件程序,设计与生成打印数据库中表格式标签报表格式文件。表格式标签指多个结构相同的表格打印在同一打印纸上,结构重复,内容可以根据记录变化,可以全相同。前者例如工资条、成绩单,后者例如空白工具条。

/* 

 * 程序文件名:printFormat6.java 

 * 作者:程学先 

 * 功能:辅助生成打印数据库中表格式标签报表格式文件。 

 * 表格式标签指多个结构相同的表格打印在同一打印纸上,结构重复, 

 * 内容可以根据记录变化,可以全相同。前者例如工资条、成绩单,后者例如数据通报。 

  */

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;

import java.io.*;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;


public class printFormat6 extends JFrame {

private static printFormat6 frame1 = new printFormat6();

private static printFormat6 frame2 = new printFormat6();

private static JPanel panel1 = new JPanel();

private static JPanel panel2 = new JPanel();

private static DefaultTableModel variabl19651;

private static DefaultTableModel variabl19652;

private static JTable variabl26551;

private static JTable variabl26552;

private static JScrollPane scrollPane1 = new JScrollPane();

private static JScrollPane scrollPane2 = new JScrollPane();

private static List list1 = new List();

private static List list2 = new List();

private static JLabel fl0, fl10;

private static JLabel fla1, fla2, fla3, fla4, fla5, fla6, fla7;

private static JTextField faa0, faa1, faa2, faa3, faa4, faa5, faa6, faa7,

faa10;

private static JLabel flb1, flb2, flb3, flb4, flb5, flb6;

private static JTextField fab1, fab2, fab3, fab4, fab5, fab6;

private static String variabl2327;

private static int variabl1739 = 0, variabl2651 = 0;

private static int variabl2127 = 0;

private static String[][] variabl2197;

private static String[] variabl25171;

private static String[] variabl1501;

private static int[] variabl1489;

private static File file1;

static Connection con;

private static Statement sta;

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

private static ResultSet rs;

private static ResultSetMetaData rsmd;

private static String[] variabl2607 = { "5", "6", "7", "8", "9", "10",

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

"48", "72" };

private static String[] variabl2629 = { "宋体", "楷体", "黑体", "仿宋_GB2312" };

private static String variabl2049 = "";

private static String variabl1633 = "";


public static void means(String[] parameter) {

frame1 = new printFormat6();

frame2 = new printFormat6();

panel1 = new JPanel();

panel2 = new JPanel();

scrollPane1 = new JScrollPane();

scrollPane2 = new JScrollPane();

list1 = new List();

list2 = new List();

variabl1739 = 0;

variabl2651 = 0;

variabl2127 = 0;

s1 = "";

s2 = "";

String variabl2429 = parameter[0];

final String[] variabl26031 = variabl2429.split(",");

variabl2607 = new String[19];

variabl2629 = new String[4];

variabl2607[0] = "5";

variabl2607[1] = "6";

variabl2607[2] = "7";

variabl2607[3] = "8";

variabl2607[4] = "9";

variabl2607[5] = "10";

variabl2607[6] = "11";

variabl2607[7] = "12";

variabl2607[8] = "14";

variabl2607[9] = "16";

variabl2607[10] = "18";

variabl2607[11] = "20";

variabl2607[12] = "22";

variabl2607[13] = "24";

variabl2607[14] = "26";

variabl2607[15] = "28";

variabl2607[16] = "36";

variabl2607[17] = "48";

variabl2607[18] = "72";

variabl2629[0] = "宋体";

variabl2629[1] = "楷体";

variabl2629[2] = "黑体";

variabl2629[3] = "仿宋_GB2312";

frame1.setTitle("报表表体内容设计页,每条记录打印一次。                                                                                                                                                                                                                                                                                                                                                      作者:程学先");

frame2.setTitle("打印报表页尾设计页,每页打印一次。                                                                                                                                                                                                                                                                                                                                                                                                                     作者:程学先");

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

frame2.setBounds(200, 10, 1000, 500);

frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

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

panel2.setBounds(200, 10, 800, 300);

panel1.setLayout(null);

panel2.setLayout(null);

String[] variabl251701 = { "标签名称", "字段名称", "行号", "宽度", "每行高度", "字体",

"字号" };

String[] variabl251702 = { "每行模块数", "行间间隔", "每列模块数", "列间间隔", "横向或纵向",

"每块是否包括列名" };

main1.driver1();

String variabl2603 = parameter[4];

数据表查询结构(variabl2603);

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

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

panel1.add(fl0);

faa0 = new JTextField("");

faa0.setText(variabl2603);

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

panel1.add(faa0);

faa0.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 0;

list1.removeAll();

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

list1.add(variabl26031[i]);

}

});


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

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

panel1.add(fl10);

faa10 = new JTextField("", 20);

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

panel1.add(faa10);

faa10.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

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

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

fc.showOpenDialog(null);

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

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

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

try {

if (file1.exists()) {

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,")) {

variabl19651.addRow(tempStr.substring(2, tempStr.length()).split("。"));

}

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

variabl19652.addRow(tempStr.substring(2, tempStr.length()).split("。"));

}

}

}

} catch (IOException e2) {

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

}

}

}

}

});

variabl19651 = new DefaultTableModel(variabl2197, variabl251701);

variabl19652 = new DefaultTableModel(variabl2197, variabl251702);

variabl26551 = new JTable(variabl19651);

variabl26552 = new JTable(variabl19652);

variabl26551.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

variabl26552.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

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

scrollPane2.setBounds(10, 40, 800, 300);

scrollPane1.setViewportView(variabl26551);

scrollPane2.setViewportView(variabl26552);

panel1.add(scrollPane1, BorderLayout.CENTER);

panel2.add(scrollPane2, BorderLayout.CENTER);

fla1 = new JLabel("标签名称");

fla1.setBounds(10, 460, 60, 20);

panel1.add(fla1);

faa1 = new JTextField("", 20);

faa1.setBounds(70, 460, 100, 20);

panel1.add(faa1);

faa1.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 1;

list1.removeAll();

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

list1.add(variabl25171[i]);

}

}

});


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

fla2.setBounds(170, 460, 60, 20);

panel1.add(fla2);

faa2 = new JTextField("", 20);

faa2.setBounds(230, 460, 100, 20);

panel1.add(faa2);

faa2.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 2;

list1.removeAll();

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

list1.add(variabl25171[i]);

}

}

});


fla3 = new JLabel("行号");

fla3.setBounds(330, 460, 40, 20);

panel1.add(fla3);

faa3 = new JTextField("1", 20);

faa3.setBounds(370, 460, 60, 20);

panel1.add(faa3);

faa3.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 3;

list1.removeAll();

}

});


fla4 = new JLabel("宽度");

fla4.setBounds(430, 460, 40, 20);

panel1.add(fla4);

faa4 = new JTextField("0", 20);

faa4.setBounds(470, 460, 60, 20);

panel1.add(faa4);

faa4.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 4;

list1.removeAll();

}

});


fla5 = new JLabel("每行高度");

panel1.add(fla5);

faa5 = new JTextField("0", 20);

panel1.add(faa5);

fla5.setBounds(530, 460, 60, 20);

faa5.setBounds(590, 460, 60, 20);

faa5.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 5;

list1.removeAll();

}

});


fla6 = new JLabel("字体");

panel1.add(fla6);

faa6 = new JTextField("宋体", 20);

panel1.add(faa6);

fla6.setBounds(650, 460, 40, 20);

faa6.setBounds(690, 460, 80, 20);

faa6.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 6;

list1.removeAll();

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

list1.add(variabl2629[i]);

}

}

});


fla7 = new JLabel("字号");

panel1.add(fla7);

faa7 = new JTextField("12", 20);

panel1.add(faa7);

fla7.setBounds(770, 460, 40, 20);

faa7.setBounds(810, 460, 80, 20);

faa7.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 7;

list1.removeAll();

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

list1.add(variabl2607[i]);

}

}

});


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

panel1.add(list1);

list1.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

if (list1.getSelectedIndex() >= 0) {

int w1, w2, h1, h2;

String s0 = "";

switch (variabl1739) {

case 0:

if (faa0.getText().length() == 0)

s0 = list1.getSelectedItem();

else

s0 = faa0.getText() + "," + list1.getSelectedItem();

faa0.setText(s0);

数据表查询结构(s0);

break;

case 1:

faa1.setText(list1.getSelectedItem());

faa2.setText(list1.getSelectedItem());

variabl2127 = list1.getSelectedIndex();

if (((main1.variabl1537 + main1.variabl1539)

.lastIndexOf("," + variabl1501[variabl2127])) < 0) {

if (variabl1489[variabl2127] > variabl25171[variabl2127].length())

faa4.setText("" + variabl1489[variabl2127]);

else

faa4.setText(""+ variabl25171[variabl2127].length());


}

faa3.setText("1");

faa5.setText("1");

faa6.setText("宋体");

faa7.setText("12");

break;

case 2:

faa2.setText(list1.getSelectedItem());

break;

case 3:

faa3.setText(list1.getSelectedItem());

break;

case 4:

faa4.setText(list1.getSelectedItem());

break;

case 5:

faa5.setText(list1.getSelectedItem());

break;

case 6:

faa6.setText(list1.getSelectedItem());

break;

case 7:

faa7.setText(list1.getSelectedItem());

break;

}

}

}

});


variabl26551.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

int variabl1823 = variabl26551.getSelectedRow();

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

if (variabl19651.getValueAt(variabl1823, j) != null)

variabl2327 = variabl19651.getValueAt(variabl1823, j).toString();

else

variabl2327 = "";

switch (j) {

case 0:

faa1.setText(variabl2327.toString());

break;

case 1:

faa2.setText(variabl2327.toString());

break;

case 2:

faa3.setText(variabl2327.toString());

break;

case 3:

faa4.setText(variabl2327.toString());

break;

case 4:

faa5.setText(variabl2327.toString());

break;

case 5:

faa6.setText(variabl2327.toString());

break;

case 6:

faa7.setText(variabl2327.toString());

break;

}

}

}

});


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

addButton1.setBounds(30, 510, 150, 20);

addButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int variabl1823 = -1, m = 0, n1 = 0, n2 = 0, n3 = 0;

for (int i = 0; i < variabl19651.getRowCount(); i++) {

if ((variabl19651.getValueAt(i, 0) != null)

&& (variabl19651.getValueAt(i, 0).toString().trim()

.equalsIgnoreCase(faa1.getText().trim()))) {

variabl1823 = i;

break;

}

}

if (variabl1823 < 0) {

String[] rowValues = { faa1.getText(), faa2.getText(),

faa3.getText(), faa4.getText(), faa5.getText(),

faa6.getText(), faa7.getText() };

variabl19651.addRow(rowValues);

int rowCount = variabl26551.getRowCount() + 1;

faa1.setText("");

faa2.setText("");

faa3.setText("1");

faa4.setText("0");

faa5.setText("1");

faa6.setText("宋体");

faa7.setText("12");

} else

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

}

});

panel1.add(addButton1);


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

updButton1.setBounds(180, 510, 150, 20);

updButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int variabl1823 = -1;

for (int i = 0; i < variabl19651.getRowCount(); i++) {

if ((variabl19651.getValueAt(i, 0) != null)

&& (variabl19651.getValueAt(i, 0).toString().trim()

.equalsIgnoreCase(faa1.getText().trim()))) {

variabl1823 = i;

break;

}

}

if (variabl1823 >= 0) {

variabl19651.setValueAt(faa1.getText(), variabl1823, 0);

variabl19651.setValueAt(faa2.getText(), variabl1823, 1);

variabl19651.setValueAt(faa3.getText(), variabl1823, 2);

variabl19651.setValueAt(faa4.getText(), variabl1823, 3);

variabl19651.setValueAt(faa5.getText(), variabl1823, 4);

variabl19651.setValueAt(faa6.getText(), variabl1823, 5);

variabl19651.setValueAt(faa7.getText(), variabl1823, 6);

} else

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

}

});

panel1.add(updButton1);


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

delButton1.setBounds(330, 510, 150, 20);

delButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int variabl1823 = variabl26551.getSelectedRow();

if (variabl1823 != -1)

variabl19651.removeRow(variabl1823);

}

});

panel1.add(delButton1);


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

countButton1.setBounds(480, 510, 150, 20);

countButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int variabl2059 = variabl19651.getRowCount();

String[][] variabl2649 = new String[variabl2059][11];

int[][] variabl26491 = new int[variabl2059][11];

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

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

variabl2649[i][j] = variabl19651.getValueAt(i, j).toString().trim();

}

for (int j = 2; j < 7; j++) {

if (j != 5) {

if (variabl2649[i][j].length() > 0)

variabl26491[i][j] = Integer.valueOf(variabl2649[i][j]);

else

variabl26491[i][j] = 0;

}

}

variabl26491[i][3] = variabl26491[i][3]* variabl26491[i][6];

variabl2649[i][3] = "" + variabl26491[i][3];

variabl26491[i][4] = variabl26491[i][4]* variabl26491[i][6];

variabl2649[i][4] = "" + variabl26491[i][4];

}

variabl19651.setRowCount(0);

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

variabl19651.addRow(variabl2649[i]);

}

});

panel1.add(countButton1);


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

clearButton1.setBounds(630, 510, 150, 20);

clearButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

faa1.setText("");

faa2.setText("");

faa3.setText("1");

faa4.setText("0");

faa5.setText("1");

faa6.setText("宋体");

faa7.setText("12");

}

});

panel1.add(clearButton1);


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

exitButton.setBounds(780, 510, 150, 20);

exitButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

panel1.setVisible(false);

frame1.setVisible(false);

frame1.dispose();

frame2.setVisible(false);

frame2.dispose();

}

});

panel1.add(exitButton);


flb1 = new JLabel("每行模块数");

flb1.setBounds(20, 360, 80, 20);

panel2.add(flb1);

fab1 = new JTextField("", 20);

fab1.setBounds(100, 360, 100, 20);

panel2.add(fab1);

fab1.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 1;

list2.removeAll();

}

});


flb2 = new JLabel("行间间隔");

flb2.setBounds(200, 360, 80, 20);

panel2.add(flb2);

fab2 = new JTextField("", 20);

fab2.setBounds(280, 360, 60, 20);

panel2.add(fab2);

fab2.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 2;

list2.removeAll();

}

});


flb3 = new JLabel("每列模块数");

flb3.setBounds(340, 360, 80, 20);

panel2.add(flb3);

fab3 = new JTextField("", 20);

fab3.setBounds(420, 360, 60, 20);

panel2.add(fab3);

fab3.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 3;

list2.removeAll();

}

});


flb4 = new JLabel("列间间隔");

flb4.setBounds(480, 360, 80, 20);

panel2.add(flb4);

fab4 = new JTextField("", 20);

fab4.setBounds(560, 360, 60, 20);

panel2.add(fab4);

fab4.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 4;

list2.removeAll();

}

});


flb5 = new JLabel("横向或纵向");

flb5.setBounds(620, 360, 80, 20);

panel2.add(flb5);

fab5 = new JTextField("", 20);

fab5.setBounds(700, 360, 60, 20);

panel2.add(fab5);

fab5.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 5;

list2.removeAll();

}

});


flb6 = new JLabel("每块是否包括列名");

flb6.setBounds(760, 360, 120, 20);

panel2.add(flb6);

fab6 = new JTextField("", 20);

fab6.setBounds(880, 360, 60, 20);

panel2.add(fab6);

fab6.addFocusListener(new FocusAdapter() {

public void focusGained(final FocusEvent arg0) {

variabl1739 = 6;

list2.removeAll();

}

});

fab1.setText("1");

fab2.setText("2");

fab3.setText("1");

fab4.setText("2");

fab5.setText("横");

fab6.setText("是");

list2.setBounds(840, 10, 120, 330);

panel2.add(list2);

list2.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

if (list2.getSelectedIndex() >= 0) {

int w1, w2, h1, h2;

switch (variabl1739) {

case 1:

fab1.setText(list2.getSelectedItem());

break;

case 2:

fab2.setText(list2.getSelectedItem());

break;

case 3:

fab3.setText(list2.getSelectedItem());

break;

case 4:

fab4.setText(list2.getSelectedItem());

break;

case 5:

fab5.setText(list2.getSelectedItem());

break;

case 6:

fab6.setText(list2.getSelectedItem());

break;

}

}

}

});


variabl26552.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

int variabl1823 = variabl26552.getSelectedRow();

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

if (variabl19652.getValueAt(variabl1823, j) != null)

variabl2327 = variabl19652.getValueAt(variabl1823, j).toString();

else

variabl2327 = "";

switch (j) {

case 0:

fab1.setText(variabl2327.toString());

break;

case 1:

fab2.setText(variabl2327.toString());

break;

case 2:

fab3.setText(variabl2327.toString());

break;

case 3:

fab4.setText(variabl2327.toString());

break;

case 4:

fab5.setText(variabl2327.toString());

break;

case 5:

fab6.setText(variabl2327.toString());

break;

}

}

}

});


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

addButton2.setBounds(30, 400, 150, 20);

addButton2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int variabl1823 = -1, m = 0, n1 = 0, n2 = 0, n3 = 0;

for (int i = 0; i < variabl19652.getRowCount(); i++) {

if ((variabl19652.getValueAt(i, 0) != null)

&& (variabl19652.getValueAt(i, 0).toString().trim()

.equalsIgnoreCase(fab1.getText().trim()))) {

variabl1823 = i;

break;

}

}

if (variabl1823 < 0) {

String[] rowValues = { fab1.getText(), fab2.getText(),

fab3.getText(), fab4.getText(), fab5.getText(),

fab6.getText() };

variabl19652.addRow(rowValues);

int rowCount = variabl26552.getRowCount() + 1;

fab1.setText("1");

fab2.setText("2");

fab3.setText("1");

fab4.setText("2");

fab5.setText("横");

fab6.setText("是");

} else

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

}

});

panel2.add(addButton2);


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

updButton2.setBounds(180, 400, 150, 20);

updButton2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int variabl1823 = -1;

for (int i = 0; i < variabl19652.getRowCount(); i++) {

if ((variabl19652.getValueAt(i, 0) != null)

&& (variabl19652.getValueAt(i, 0).toString().trim()

.equalsIgnoreCase(fab1.getText().trim()))) {

variabl1823 = i;

break;

}

}

if (variabl1823 >= 0) {

variabl19652.setValueAt(fab1.getText(), variabl1823, 0);

variabl19652.setValueAt(fab2.getText(), variabl1823, 1);

variabl19652.setValueAt(fab3.getText(), variabl1823, 2);

variabl19652.setValueAt(fab4.getText(), variabl1823, 3);

variabl19652.setValueAt(fab5.getText(), variabl1823, 4);

variabl19652.setValueAt(fab6.getText(), variabl1823, 5);

} else

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

}

});

panel2.add(updButton2);


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

delButton2.setBounds(330, 400, 150, 20);

delButton2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

int variabl1823 = variabl26552.getSelectedRow();

if (variabl1823 != -1)

variabl19652.removeRow(variabl1823);

}

});

panel2.add(delButton2);


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

clearButton2.setBounds(480, 400, 150, 20);

clearButton2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

fab1.setText("1");

fab2.setText("2");

fab3.setText("1");

fab4.setText("2");

fab5.setText("横");

fab6.setText("是");

}

});

panel2.add(clearButton2);


final JButton creButton = new JButton("存入文件");

creButton.setBounds(630, 400, 150, 20);

creButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

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

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

FileOutputStream fs;

try {

fs = new FileOutputStream(file1);

for (int i = 0; i < variabl19651.getRowCount(); i++) {

String s3 = "1,", s4 = "";

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

if ((variabl19651.getValueAt(i, j) != null)

&& (variabl19651.getValueAt(i, j).toString().length() > 0))

s3 = s3

+ variabl19651.getValueAt(i, j).toString() + "。";

else

s3 = s3 + " 。";

}

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

}

for (int i = 0; i < variabl19652.getRowCount(); i++) {

String s3 = "2,", s4 = "";

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

if ((variabl19652.getValueAt(i, j) != null)

&& (variabl19652.getValueAt(i, j).toString().length() > 0))

s3 = s3

+ variabl19652.getValueAt(i, j).toString() + "。";

else

s3 = s3 + " 。";

}

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

}

fs.close();

} catch (IOException e2) {

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

}

}

});

panel2.add(creButton);


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

exitButton2.setBounds(780, 400, 150, 20);

exitButton2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

panel2.setVisible(false);

frame2.setVisible(false);

frame2.dispose();

frame1.setVisible(false);

frame1.dispose();

}

});

panel2.add(exitButton2);

frame2.add(panel2);

frame1.add(panel1);

frame2.setVisible(true);

frame1.setVisible(true);

}


static void 数据表查询结构(String variabl2217) {

String[] s10 = null;

String[] sk = new String[300];

int n1 = 0, n2 = 0;

variabl1633 = "";

variabl2049 = "";

if (variabl2217.indexOf(",") < 0) {

try {

con = main1.getConn();

sta = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

String s1 = "select * from " + variabl2217;

rs = sta.executeQuery(s1);

rsmd = rs.getMetaData();

variabl2651 = rsmd.getColumnCount();

variabl25171 = new String[variabl2651];

variabl1633 = "";

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

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

sk[i] = variabl25171[i];

n1++;

if (variabl1633.length() == 0)

variabl1633 = variabl25171[i];

else

variabl1633 = variabl1633 + "," + variabl25171[i];

}

rs.close();

sta.close();

con.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

} else {

s10 = variabl2217.split(",");

String s0 = "", s1 = "", s2 = "";

int k = 0;

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

try {

con = main1.getConn();

sta = con.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

s1 = "select * from " + s10[i];

rs = sta.executeQuery(s1);

rsmd = rs.getMetaData();

variabl2651 = rsmd.getColumnCount();

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

s2 = rsmd.getColumnName(j + 1).toLowerCase();

n2 = n1;

if (i > 0) {

k = 0;

for (int j1 = 0; j1 < n2; j1++) {

if (sk[j1].equals(s2)) {

sk[j1] = s10[i - 1] + "." + sk[j1];

if (variabl2049.length() == 0)

variabl2049 = " where " + s10[i - 1]

+ "." + s2 + " = " + s10[i]+ "." + s2;

else

variabl2049 = variabl2049 + " and "+ s10[i - 1] 

+ "." + s2 + " = "+ s10[i] + "." + s2;

sk[n1] = s10[i] + "." + s2 + " as "+ (s2 + i);

n1++;

k = 1;

break;

}

}

if (k == 0) {

sk[n1] = s2;

n1++;

}

} else {

sk[n1] = s2;

n1++;

}

}

rs.close();

sta.close();

con.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

}

variabl1633 = "";

for (int j1 = 0; j1 < n1; j1++)

if (variabl1633.length() == 0)

variabl1633 = sk[j1];

else

variabl1633 = variabl1633 + "," + sk[j1];

}

try {

con = main1.getConn();

sta = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

s1 = "select " + variabl1633 + "  from " + variabl2217

+ variabl2049;

rs = sta.executeQuery(s1);

rsmd = rs.getMetaData();

variabl2651 = rsmd.getColumnCount();

variabl25171 = new String[variabl2651];

variabl1501 = new String[variabl2651];

variabl1489 = new int[variabl2651];

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

variabl25171[i] = sk[i];

variabl1501[i] = rsmd.getColumnTypeName(i + 1);

variabl1489[i] = rsmd.getColumnDisplaySize(i + 1);

}

rs.close();

sta.close();

con.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

}

}


93.源码93,部件程序,表格式标签报表预览程序。根据printFormat6.java生成的格式文件打印预览。

/* 

 * 程序文件名:dataPreview3.java 

 * 作者:程学先 

 * 功能:表格式标签报表预览程序。根据printFormat6.java生成的格式文件打印预览。 

 * 必须输入的参数:数据表名、打印格式文件名。 

 */

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Font;

import java.awt.GradientPaint;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.Rectangle;

import java.awt.RenderingHints;

import java.awt.Shape;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import javax.swing.JButton;

import javax.swing.JComponent;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.ListSelectionModel;

import javax.swing.table.DefaultTableModel;


public class dataPreview3 extends JComponent {

private static JFrame frame1;

private static JFrame frame2;

private static JPanel panel1 = new JPanel();

private static DefaultTableModel variabl19651;

private static JTable variabl26551;

private static JScrollPane scrollPane1 = new JScrollPane();

private static Connection cont4;

private static Statement stat4;

private static ResultSetMetaData rsmdt4;

private static ResultSet rs;

private static String variabl2603;

private static String variabl3645;

private static String s1 = "";

private static int variabl1853 = 0, variabl2651 = 0, variabl1823 = -1;

private static String[] variabl2517;

private static String[] variabl1501;

private static int[] variabl1489;

private static String[][] variabl2197;

private static String[][] variabl21970;

private static ArrayList<struct3> table1 = new ArrayList<struct3>();

private static ArrayList<struct4> table2 = new ArrayList<struct4>();

private static Graphics2D g3;

private static Graphics g;

private static int variabl1441 = 0, variabl1703 = 0, variabl1599 = 0,

variabl2155 = 0;

private static String variabl1353 = "", variabl1051 = "";

private static int[] line;

private static int[] w10;

private static int[] h10;

private static int[] h20;

private static String[] f10;

private static String variabl2629 = "";

private static int variabl2607 = 0;

private static int variabl1139 = 0;

static String[] variabl2405 = null;

static String variabl1187;

static int variabl2483 = 0, variabl2503 = 0, variabl2851 = 0,

variabl2339 = 0;

private static String variabl2049 = "";

private static String variabl1633 = "";


protected void paintComponent(Graphics g1) {

g = g1;

g3 = (Graphics2D) g;

int x1 = 0, x2 = 0, y1 = 0, y2 = 0, y3 = 0;

int variabl2661 = 40, variabl2657 = 30;

boolean b1 = true;

while (b1)

if (variabl1823 < 0) {

variabl1823 = 1;

} else

b1 = false;

y1 = variabl2657;

x1 = variabl2661;

g3.setFont(new Font(variabl2629, Font.PLAIN, variabl2607));

int variabl2035 = 1;

int k = 0;

k = variabl1823;

String s0 = "";

if (k <= variabl1853) {

if (variabl1353.equals("横向")) {

for (int l = 0; l < variabl1599; l++) {

y2 = y1;

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

x2 = x1;

for (int j = 0; j < variabl2517.length; j++) {

if ((k >= variabl1853)

|| (variabl2197[k][j] == null))

s0 = "";

else

s0 = variabl2197[k][j];

g3.drawLine(x1, y1, x1 + w10[j], y1);

g3.drawLine(x1, y1, x1, y1 + h10[j]);

if (variabl1051.equals("是"))

g3.drawString(f10[j], x1 + 2, y1 + h10[j]);

else

g3.drawString(s0, x1 + 2, y1

+ h10[j]);

g3.drawLine(x1 + w10[j], y1, x1 + w10[j], y1

+ h10[j]);

g3.drawLine(x1, y1 + h10[j], x1 + w10[j], y1

+ h10[j]);

y3 = y1 + h10[j];

if (variabl1051.equals("是")) {

g3.drawLine(x1, y1 + h10[j], x1, y1 + h10[j]

* 2);

g3.drawString(s0, x1 + 2, y1

+ h10[j] * 2);

g3.drawLine(x1 + w10[j], y1 + h10[j], x1

+ w10[j], y1 + h10[j] * 2);

g3.drawLine(x1, y1 + h10[j] * 2, x1 + w10[j],

y1 + h10[j] * 2);

y3 = y1 + h10[j] * 2;

}

x1 = x1 + w10[j];

if ((j < variabl2517.length - 1)

&& (line[j + 1] > variabl2035)) {

variabl2035++;

x1 = x2;

if (variabl1051.equals("是"))

y1 = y1 + h10[variabl2517.length - 1] * 2;

else

y1 = y1 + h10[variabl2517.length - 1];

}

}

x1 = x1 + variabl1703;

if (variabl1139 == 1)

k++;

variabl2035 = 1;

y1 = y2;

}

if (variabl1051.equals("是"))

y1 = y1 + h10[variabl2517.length - 1] * 2 + variabl2155;

else

y1 = y1 + h10[variabl2517.length - 1] + variabl2155;

y1 = y3 + variabl2155;

x1 = variabl2661;

}

} else {

int variabl2497 = 0;

int variabl2321 = 0;

for (int j = 0; j < variabl2517.length; j++) {

if (f10[j].length() > variabl2497)

variabl2497 = f10[j].length();

if (w10[j] > variabl2321)

variabl2321 = w10[j];

}

variabl2497 = variabl2497 * variabl2607 + 2;

k = variabl1823;

s0 = "";

if (k <= variabl1853) {

for (int l = 0; l < variabl1599; l++) {

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

y2 = y1;

for (int j = 0; j < variabl2517.length; j++) {

if ((k >= variabl1853)

|| (variabl2197[k][j] == null))

s0 = "";

else

s0 = variabl2197[k][j];

g3.drawLine(x1, y1, x1 + variabl2497, y1);

g3.drawLine(x1, y1, x1, y1 + h10[j]);

g3.drawString(f10[j], x1 + 2, y1 + h10[j]);

g3.drawLine(x1, y1 + h10[j], x1 + variabl2497,y1 + h10[j]);

g3.drawLine(x1 + variabl2497, y1, x1

+ variabl2497 + variabl2321, y1);

g3.drawLine(x1 + variabl2497, y1, x1

+ variabl2497, y1 + h10[j]);

g3.drawString(s0, x1 + variabl2497 + 2, y1+ h10[j]);

g3.drawLine(x1 + variabl2497 + variabl2321, y1,

x1 + variabl2497 + variabl2321, y1+ h10[j]);

g3.drawLine(x1 + variabl2497, y1 + h10[j], x1

+ variabl2497 + variabl2321, y1+ h10[j]);

y1 = y1 + h10[j];

}

if (variabl1139 == 1)

k++;

y3 = y1;

y1 = y2;

x1 = x1 + variabl2497 + variabl2321 + variabl1703;

}

y1 = y3 + variabl2155;

x1 = variabl2661;

}

}

}

}

}


static void means(String[] parameter) {

s1 = "";

variabl1853 = 0;

variabl2651 = 0;

table1 = new ArrayList<struct3>();

table2 = new ArrayList<struct4>();

panel1 = new JPanel();

scrollPane1 = new JScrollPane();

variabl1441 = 0;

variabl1703 = 0;

variabl1599 = 0;

variabl2155 = 0;

variabl1353 = "";

variabl1051 = "";

variabl2629 = "";

variabl2607 = 0;

variabl1139 = 0;

String[] variabl240501 = { "预览相同记录", "依次预览记录", "退出" };

variabl2405 = new String[variabl240501.length];

variabl2851 = 0;

for (int i0 = 0; i0 < variabl240501.length; i0++)

variabl2405[i0] = variabl240501[i0];

if (parameter[11].length() > 0) {

variabl1187 = parameter[11];

variabl1187 = variabl1187.replaceAll(";", ";");

variabl1187 = variabl1187.replaceAll("。", ";");

variabl1187 = variabl1187.replaceAll(":", ";");

variabl1187 = variabl1187.replaceAll(":", ";");

if (variabl1187.indexOf(";") > 0) {

String s601[] = variabl1187.split(",");

variabl1187 = "";

for (int i01 = 0; i01 < s601.length; i01++) {

if (s601[i01].indexOf(";") > 0) {

String s602[] = s601[i01].split(";");

variabl2405[Integer.parseInt((s602[0]))] = s602[1];

variabl1187 = variabl1187 + "," + s602[0];

variabl2851++;

} else {

variabl1187 = variabl1187 + "," + s601[i01];

variabl2851++;

}

}

} else {

String s601[] = variabl1187.split(",");

variabl1187 = "";

for (int i01 = 0; i01 < s601.length; i01++) {

if (i01 == 0)

variabl1187 = s601[i01];

else

variabl1187 = variabl1187 + "," + s601[i01];

variabl2851++;

}

}

} else {

variabl1187 = "";

for (int i1 = 0; i1 < variabl2405.length; i1++) {

if (i1 == 0)

variabl1187 = variabl1187 + i1;

else

variabl1187 = variabl1187 + "," + i1;

variabl2851++;

}

}

variabl1187 = "," + variabl1187 + ",";

variabl2483 = main1.variabl2483;

variabl2503 = main1.variabl2503;

int m1, m2;

try {

if (parameter[17].length() == 0) {

m1 = 0;

m2 = 0;

} else {

m1 = Integer.parseInt(parameter[17]);

m2 = Integer.parseInt(parameter[18]);

}

if (m1 > 0) {

if (m2 < 80) {

m1 = m1 * 10;

m2 = m2 * 10;

}

variabl2483 = m1;

variabl2503 = m2;

}

} catch (Exception e2) {

}

variabl2603 = parameter[4];

variabl3645 = parameter[15];

frame1 = new JFrame("表格标签式报表预览程序                           作者:程学先");

frame1.setBounds(10, 10, 1200, 600);

File file1 = new File(variabl3645);

try {

if (file1.exists()) {

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,")) {

table1.add(new struct3(tempStr.substring(2,

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

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

table2.add(new struct4(tempStr.substring(2,

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

}

}

}

} catch (IOException e2) {

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

}

struct3[] variabl2685 = new struct3[table1.size()];

line = new int[table1.size()];

w10 = new int[table1.size()];

h10 = new int[table1.size()];

h20 = new int[table1.size()];

f10 = new String[table1.size()];

for (int i = 0; i < table1.size(); i++) {

variabl2685[i] = table1.get(i);

line[i] = Integer.valueOf(variabl2685[i].table1[2]);

w10[i] = Integer.valueOf(variabl2685[i].table1[3]);

h10[i] = (int) (Integer.valueOf(variabl2685[i].table1[4]) * 1.5);

h20[i] = Integer.valueOf(variabl2685[i].table1[6]);

f10[i] = variabl2685[i].table1[0];

}

variabl2629 = variabl2685[0].table1[5];

variabl2607 = Integer.valueOf(variabl2685[0].table1[6]);

struct4[] variabl2533 = new struct4[table2.size()];

variabl2533[0] = table2.get(0);

variabl1441 = Integer.valueOf(variabl2533[0].table2[0]);

variabl1703 = Integer.valueOf(variabl2533[0].table2[1]);

variabl1599 = Integer.valueOf(variabl2533[0].table2[2]);

variabl2155 = Integer.valueOf(variabl2533[0].table2[3]);

variabl1353 = variabl2533[0].table2[4];

variabl1051 = variabl2533[0].table2[5];

variabl1633 = "";

for (int i = 0; i < table1.size(); i++) {

if (variabl1633.length() == 0)

variabl1633 = table1.get(i).table1[1];

else

variabl1633 = variabl1633 + "," + table1.get(i).table1[1];

}

数据表查询结构(variabl2603);

数据表查询数据(variabl2603);

panel1.setBounds(50, 260, 1000, 500);

panel1.setLayout(null);

variabl19651 = new DefaultTableModel(variabl2197, variabl2517);

variabl26551 = new JTable(variabl19651);

variabl26551.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

scrollPane1.setBounds(50, 60, 1000, 400);

scrollPane1.setViewportView(variabl26551);

panel1.add(scrollPane1, BorderLayout.CENTER);

variabl26551.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

variabl1823 = variabl26551.getSelectedRow();

}

});

int variabl2337 = 100;

variabl2339 = (variabl2483 - variabl2337 - 30) / variabl2851;

final JButton printButton1 = new JButton(variabl2405[0]);

printButton1.setBounds(variabl2337, 460, variabl2339, 20);

printButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

variabl1139 = 0;

frame2.setVisible(false);

frame2.add(new dataPreview3());

frame2.setVisible(true);

}

});

if (variabl1187.indexOf(",0,") >= 0) {

variabl2337 = variabl2337 + variabl2339;

panel1.add(printButton1);

}


final JButton printButton2 = new JButton(variabl2405[1]);

printButton2.setBounds(variabl2337, 460, variabl2339, 20);

printButton2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

variabl1139 = 1;

frame2.setVisible(false);

frame2.add(new dataPreview3());

frame2.setVisible(true);

}

});

if (variabl1187.indexOf(",1,") >= 0) {

variabl2337 = variabl2337 + variabl2339;

panel1.add(printButton2);

}


final JButton exitButton = new JButton(variabl2405[2]);

exitButton.setBounds(variabl2337, 460, variabl2339, 20);

exitButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

panel1.setVisible(false);

frame1.setVisible(false);

}

});

if (variabl1187.indexOf(",2,") >= 0) {

variabl2337 = variabl2337 + variabl2339;

panel1.add(exitButton);

}

frame2 = new JFrame("表格标签式报表预览  ");

frame2.setBounds(10, 10, 1300, 700);

frame1.add(panel1);

frame1.setVisible(true);

}


static void 数据表查询结构(String variabl2217) {

String[] s10 = null;

String[] sk = new String[300];

int n1 = 0, n2 = 0;

variabl2049 = "";

if (variabl2217.indexOf(",") < 0) {

try {

cont4 = main1.getConn();

stat4 = cont4.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

String s1 = "select * from " + variabl2217;

rs = stat4.executeQuery(s1);

rsmdt4 = rs.getMetaData();

variabl2651 = rsmdt4.getColumnCount();

variabl2517 = new String[variabl2651];

variabl1501 = new String[variabl2651];

variabl1489 = new int[variabl2651];

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

variabl2517[i] = rsmdt4.getColumnName(i + 1);

}

rs.close();

stat4.close();

cont4.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

} else {

s10 = variabl2217.split(",");

String s0 = "", s1 = "", s2 = "";

int k = 0;

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

try {

cont4 = main1.getConn();

stat4 = cont4.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

s1 = "select * from " + s10[i];

rs = stat4.executeQuery(s1);

rsmdt4 = rs.getMetaData();

variabl2651 = rsmdt4.getColumnCount();

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

s2 = rsmdt4.getColumnName(j + 1).toLowerCase();

n2 = n1;

if (i > 0) {

k = 0;

for (int j1 = 0; j1 < n2; j1++) {

if (sk[j1].equals(s2)) {

sk[j1] = s10[i - 1] + "." + sk[j1];

if (variabl2049.length() == 0)

variabl2049 = " where " + s10[i - 1]

+ "." + s2 + " = " + s10[i]

+ "." + s2;

else

variabl2049 = variabl2049 + " and "

+ s10[i - 1] + "." + s2 + " = "

+ s10[i] + "." + s2;

sk[n1] = s10[i] + "." + s2 + " as "

+ (s2 + i);

n1++;

k = 1;

break;

}

}

if (k == 0) {

sk[n1] = s2;

n1++;

}

} else {

sk[n1] = s2;

n1++;

}

}

rs.close();

stat4.close();

cont4.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

}

}

}


static void 数据表查询数据(String variabl2217) {

int c = 0;

int b = 0;

try {

cont4 = main1.getConn();

stat4 = cont4.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

s1 = "select " + variabl1633 + "  from " + variabl2217

+ variabl2049;

rs = stat4.executeQuery(s1);

rsmdt4 = rs.getMetaData();

variabl2651 = rsmdt4.getColumnCount();

variabl2517 = new String[variabl2651];

variabl1501 = new String[variabl2651];

variabl1489 = new int[variabl2651];

for (int i1 = 0; i1 < variabl2651; i1++) {

variabl2517[i1] = rsmdt4.getColumnName(i1 + 1);

variabl1501[i1] = rsmdt4.getColumnTypeName(i1 + 1);

variabl1489[i1] = rsmdt4.getColumnDisplaySize(i1 + 1);

}

rs.last();

variabl1853 = rs.getRow();

variabl2197 = new String[variabl1853][variabl2651];

variabl21970 = new String[variabl1853][variabl2651];

while (c < variabl1853) {

rs.absolute(c + 1);

while (b < variabl2651) {

variabl21970[c][b] = rs.getString(b + 1);

if ((main1.variabl1545.lastIndexOf("," + variabl1501[b]

+ ",")) > 0)

if ((variabl21970[c][b] == null)

|| (variabl21970[c][b].trim().length() == 0))

variabl21970[c][b] = "0";

else if (variabl21970[c][b] == null)

variabl21970[c][b] = "";

variabl2197[c][b] = variabl21970[c][b];

b++;

}

c++;

b = 0;

}

rs.close();

stat4.close();

cont4.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

}

  }


94.源码94,部件程序,表格式标签报表打印程序。根据printFormat6.java生成的格式文件打印。

/* 

 * 程序文件名:dataPrint3.java 

 * 作者:程学先 

 * 功能:表格式标签报表打印程序。根据printFormat6.java生成的格式文件打印。 

 * 必须输入的参数:数据表名、打印格式文件名。 

 * 调用命令:dataPrint3.means(parameter) 

 */

import java.awt.BasicStroke;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Font;

import java.awt.GradientPaint;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.awt.print.PageFormat;

import java.awt.print.Printable;

import java.awt.print.PrinterException;

import java.awt.print.PrinterJob;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import javax.swing.JButton;

import javax.swing.JComponent;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.ListSelectionModel;

import javax.swing.table.DefaultTableModel;


public class dataPrint3 extends JComponent {

private static JFrame frame1;

private static JFrame frame2;

private static JPanel panel1 = new JPanel();

private static DefaultTableModel variabl19651;

private static JTable variabl26551;

private static JScrollPane scrollPane1 = new JScrollPane();

private static Connection cont4;

private static Statement stat4;

private static ResultSetMetaData rsmdt4;

private static ResultSet rs;

private static String variabl2603;

private static String variabl3645;

private static String s1 = "";

private static int variabl1853 = 0, variabl2651 = 0, variabl1823 = -1;

private static String[] variabl2517;

private static String[] variabl1501;

private static int[] variabl1489;

private static String[][] variabl2197;

private static String[][] variabl21970;

private static ArrayList<struct3> table1 = new ArrayList<struct3>();

private static ArrayList<struct4> table2 = new ArrayList<struct4>();

private static Graphics2D g3;

private static Graphics g;

private static PageFormat pf;

private static PrinterJob job;

private static int variabl1441 = 0, variabl1703 = 0, variabl1599 = 0,

variabl2155 = 0;

private static String variabl1353 = "", variabl1051 = "";

private static int[] line;

private static int[] w10;

private static int[] h10;

private static int[] h20;

private static String[] f10;

private static String variabl2629 = "";

private static int variabl2607 = 0;

private static int variabl1139 = 0;

static String[] variabl2405 = null;

static String variabl1187;

static int variabl2483 = 0, variabl2503 = 0, variabl2851 = 0,

variabl2339 = 0;

static String variabl2049 = "";

static String variabl1633 = "";


static void means(String[] parameter) {

panel1 = new JPanel();

scrollPane1 = new JScrollPane();

s1 = "";

variabl1853 = 0;

variabl2651 = 0;

variabl1823 = -1;

table1 = new ArrayList<struct3>();

table2 = new ArrayList<struct4>();

variabl1441 = 0;

variabl1703 = 0;

variabl1599 = 0;

variabl2155 = 0;

variabl1353 = "";

variabl1051 = "";

variabl2629 = "";

variabl2607 = 0;

variabl1139 = 0;

String[] variabl240501 = { "打印相同记录", "依次打印记录", "退出" };

variabl2405 = new String[variabl240501.length];

variabl2851 = 0;

for (int i0 = 0; i0 < variabl240501.length; i0++)

variabl2405[i0] = variabl240501[i0];

if (parameter[11].length() > 0) {

variabl1187 = parameter[11];

variabl1187 = variabl1187.replaceAll(";", ";");

variabl1187 = variabl1187.replaceAll("。", ";");

variabl1187 = variabl1187.replaceAll(":", ";");

variabl1187 = variabl1187.replaceAll(":", ";");

if (variabl1187.indexOf(";") > 0) {

String s601[] = variabl1187.split(",");

variabl1187 = "";

for (int i01 = 0; i01 < s601.length; i01++) {

if (s601[i01].indexOf(";") > 0) {

String s602[] = s601[i01].split(";");

variabl2405[Integer.parseInt((s602[0]))] = s602[1];

variabl1187 = variabl1187 + "," + s602[0];

variabl2851++;

} else {

variabl1187 = variabl1187 + "," + s601[i01];

variabl2851++;

}

}

} else {

String s601[] = variabl1187.split(",");

variabl1187 = "";

for (int i01 = 0; i01 < s601.length; i01++) {

if (i01 == 0)

variabl1187 = s601[i01];

else

variabl1187 = variabl1187 + s601[i01];

variabl2851++;

}

}

} else {

variabl1187 = "";

for (int i1 = 0; i1 < variabl2405.length; i1++) {

if (i1 == 0)

variabl1187 = variabl1187 + i1;

else

variabl1187 = variabl1187 + "," + i1;

variabl2851++;

}

}

variabl1187 = "," + variabl1187 + ",";

variabl2483 = main1.variabl2483;

variabl2503 = main1.variabl2503;

int m1, m2;

try {

if (parameter[17].length() == 0) {

m1 = 0;

m2 = 0;

} else {

m1 = Integer.parseInt(parameter[17]);

m2 = Integer.parseInt(parameter[18]);

}

if (m1 > 0) {

if (m2 < 80) {

m1 = m1 * 10;

m2 = m2 * 10;

}

variabl2483 = m1;

variabl2503 = m2;

}

} catch (Exception e2) {

}

variabl2603 = parameter[4];

variabl3645 = parameter[15];

frame1 = new JFrame();

frame1.setTitle("表格标签式报表程序                                                                                                                                                                                                                                                                                                                                                    作者:程学先");

frame1.setBounds(10, 10, 1200, 600);

File file1 = new File(variabl3645);

try {

if (file1.exists()) {

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,")) {

table1.add(new struct3(tempStr.substring(2,

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

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

table2.add(new struct4(tempStr.substring(2,

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

}

}

}

} catch (IOException e2) {

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

}

struct3[] variabl2685 = new struct3[table1.size()];

line = new int[table1.size()];

w10 = new int[table1.size()];

h10 = new int[table1.size()];

h20 = new int[table1.size()];

f10 = new String[table1.size()];

for (int i = 0; i < table1.size(); i++) {

variabl2685[i] = table1.get(i);

line[i] = Integer.valueOf(variabl2685[i].table1[2]);

w10[i] = Integer.valueOf(variabl2685[i].table1[3]);

h10[i] = (int) (Integer.valueOf(variabl2685[i].table1[4]) * 1.5);

h20[i] = Integer.valueOf(variabl2685[i].table1[6]);

f10[i] = variabl2685[i].table1[0];

}

variabl2629 = variabl2685[0].table1[5];

variabl2607 = Integer.valueOf(variabl2685[0].table1[6]);

struct4[] variabl2533 = new struct4[table2.size()];

variabl2533[0] = table2.get(0);

variabl1441 = Integer.valueOf(variabl2533[0].table2[0]);

variabl1703 = Integer.valueOf(variabl2533[0].table2[1]);

variabl1599 = Integer.valueOf(variabl2533[0].table2[2]);

variabl2155 = Integer.valueOf(variabl2533[0].table2[3]);

variabl1353 = variabl2533[0].table2[4];

variabl1051 = variabl2533[0].table2[5];

variabl1633 = "";

for (int i = 0; i < table1.size(); i++) {

if (variabl1633.length() == 0)

variabl1633 = table1.get(i).table1[1];

else

variabl1633 = variabl1633 + "," + table1.get(i).table1[1];

}

数据表查询结构(variabl2603);

数据表查询数据(variabl2603);

panel1.setBounds(50, 260, 1000, 500);

panel1.setLayout(null);

variabl19651 = new DefaultTableModel(variabl2197, variabl2517);

variabl26551 = new JTable(variabl19651);

variabl26551.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

scrollPane1.setBounds(50, 60, 1000, 400);

scrollPane1.setViewportView(variabl26551);

panel1.add(scrollPane1, BorderLayout.CENTER);

pf = new PageFormat();

pf.setOrientation(PageFormat.LANDSCAPE);

variabl26551.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent e) {

variabl1823 = variabl26551.getSelectedRow();

}

});

variabl2339 = (variabl2483 - 60) / variabl2851;

int variabl2337 = 30;

final JButton printButton1 = new JButton(variabl2405[0]);

printButton1.setBounds(variabl2337, 460, variabl2339, 20);

printButton1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

variabl1139 = 0;

try {

if (!job.printDialog())

return;

dataPrint3.job.print();

} catch (Exception e1) {

e1.printStackTrace();

}

}

});

if (variabl1187.indexOf(",0,") >= 0) {

variabl2337 = variabl2337 + variabl2339;

panel1.add(printButton1);

}


final JButton printButton2 = new JButton(variabl2405[1]);

printButton2.setBounds(variabl2337, 460, variabl2339, 20);

printButton2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

variabl1139 = 1;

try {

if (!job.printDialog())

return;

dataPrint3.job.print();

} catch (Exception e1) {

e1.printStackTrace();

}

}

});

if (variabl1187.indexOf(",1,") >= 0) {

variabl2337 = variabl2337 + variabl2339;

panel1.add(printButton2);

}


final JButton exitButton = new JButton(variabl2405[2]);

exitButton.setBounds(variabl2337, 460, variabl2339, 20);

exitButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

panel1.setVisible(false);

frame1.setVisible(false);

frame1.dispose();

}

});

if (variabl1187.indexOf(",2,") >= 0) {

variabl2337 = variabl2337 + variabl2339;

panel1.add(exitButton);

}

job = PrinterJob.getPrinterJob();

job.setPrintable(new Printable() {

public int print(Graphics graphics, PageFormat pageFormat,

int pageIndex) throws PrinterException {

dataPrint3.g = graphics;

if (pageIndex < 1) {

g3 = (Graphics2D) g;

g3.setStroke(new BasicStroke(1f));

int x1 = 0, x2 = 0, y1 = 0, y2 = 0, y3 = 0, w1 = 0, h1 = 0;

int variabl2661 = 40, variabl2657 = 30, variabl2593 = 0;

boolean b1 = true;

while (b1)

if (variabl1823 < 0) {

JOptionPane.showMessageDialog(null, "请在表格中选中一行记录!");

} else

b1 = false;

y1 = variabl2657;

x1 = variabl2661;

g3.setFont(new Font(variabl2629, Font.PLAIN, variabl2607));

int variabl2035 = 1;

int k = 0;

k = variabl1823;

String s0 = "";

if (k <= variabl1853) {

if (variabl1353.equals("横向")) {

for (int l = 0; l < variabl1599; l++) {

y2 = y1;

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

x2 = x1;

for (int j = 0; j < variabl2517.length; j++) {

if ((k >= variabl1853)

|| (variabl2197[k][j] == null))

s0 = "";

else

s0 = variabl2197[k][j];

g3.drawLine(x1, y1, x1 + w10[j], y1);

g3.drawLine(x1, y1, x1, y1 + h10[j]);

if (variabl1051.equals("是"))

g3.drawString(f10[j], x1 + 2, y1+ h10[j]);

else

g3.drawString(s0,x1 + 2, y1 + h10[j]);

g3.drawLine(x1 + w10[j], y1, x1+ w10[j], y1 + h10[j]);

g3.drawLine(x1, y1 + h10[j], x1+ w10[j], y1 + h10[j]);

y3 = y1 + h10[j];

if (variabl1051.equals("是")) {

g3.drawLine(x1, y1 + h10[j], x1, y1+ h10[j] * 2);

g3.drawString(s0, x1 + 2, y1+ h10[j] * 2);

g3.drawLine(x1 + w10[j], y1

+ h10[j], x1 + w10[j], y1+ h10[j] * 2);

g3.drawLine(x1, y1 + h10[j] * 2, x1

+ w10[j], y1 + h10[j] * 2);

y3 = y1 + h10[j] * 2;

}

x1 = x1 + w10[j];

if ((j < variabl2517.length - 1)

&& (line[j + 1] > variabl2035)) {

variabl2035++;

x1 = x2;

if (variabl1051.equals("是"))

y1 = y1+ h10[variabl2517.length - 1]* 2;

else

y1 = y1+ h10[variabl2517.length - 1];

}

}

x1 = x1 + variabl1703;

if (variabl1139 == 1)

k++;

variabl2035 = 1;

y1 = y2;

}

if (variabl1051.equals("是"))

y1 = y1 + h10[variabl2517.length - 1] * 2+ variabl2155;

else

y1 = y1 + h10[variabl2517.length - 1]+ variabl2155;

y1 = y3 + variabl2155;

x1 = variabl2661;

}

} else {

int variabl2497 = 0;

int variabl2321 = 0;

for (int j = 0; j < variabl2517.length; j++) {

if (f10[j].length() > variabl2497)

variabl2497 = f10[j].length();

if (w10[j] > variabl2321)

variabl2321 = w10[j];

}

variabl2497 = variabl2497 * variabl2607 + 2;

k = variabl1823;

s0 = "";

if (k <= variabl1853) {

for (int l = 0; l < variabl1599; l++) {

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

y2 = y1;

for (int j = 0; j < variabl2517.length; j++) {

if ((k >= variabl1853)

|| (variabl2197[k][j] == null))

s0 = "";

else

s0 = variabl2197[k][j];

g3.drawLine(x1, y1, x1+ variabl2497, y1);

g3.drawLine(x1, y1, x1, y1 + h10[j]);

g3.drawString(f10[j], x1 + 2, y1+ h10[j]);

g3.drawLine(x1, y1 + h10[j], x1+ variabl2497, y1 + h10[j]);

g3.drawLine(x1 + variabl2497, y1,

x1 + variabl2497+ variabl2321, y1);

g3.drawLine(x1 + variabl2497, y1,

x1 + variabl2497, y1+ h10[j]);

g3.drawString(s0, x1

+ variabl2497 + 2, y1+ h10[j]);

g3.drawLine(x1 + variabl2497

+ variabl2321, y1,x1 + variabl2497

+ variabl2321, y1+ h10[j]);

g3.drawLine(x1 + variabl2497, y1

+ h10[j], x1 + variabl2497

+ variabl2321, y1 + h10[j]);

y1 = y1 + h10[j];

}

if (variabl1139 == 1)

k++;

y3 = y1;

y1 = y2;

x1 = x1 + variabl2497 + variabl2321+ variabl1703;

}

y1 = y3 + variabl2155;

x1 = variabl2661;

}

}

}

}

return Printable.PAGE_EXISTS;

} else {

return Printable.NO_SUCH_PAGE;

}

}

});


frame2 = new JFrame("表格标签式报表打印");

frame2.setBounds(10, 10, 1200, 600);

frame1.add(panel1);

frame1.setVisible(true);

}


static void 数据表查询结构(String variabl2217) {

String[] s10 = null;

String[] sk = new String[300];

int n1 = 0, n2 = 0;

variabl2049 = "";

if (variabl2217.indexOf(",") < 0) {

try {

cont4 = main1.getConn();

stat4 = cont4.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

String s1 = "select * from " + variabl2217;

rs = stat4.executeQuery(s1);

rsmdt4 = rs.getMetaData();

variabl2651 = rsmdt4.getColumnCount();

variabl2517 = new String[variabl2651];

variabl1501 = new String[variabl2651];

variabl1489 = new int[variabl2651];

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

variabl2517[i] = rsmdt4.getColumnName(i + 1);

}

rs.close();

stat4.close();

cont4.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

} else {

s10 = variabl2217.split(",");

String s0 = "", s1 = "", s2 = "";

int k = 0;

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

try {

cont4 = main1.getConn();

stat4 = cont4.createStatement(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

s1 = "select * from " + s10[i];

rs = stat4.executeQuery(s1);

rsmdt4 = rs.getMetaData();

variabl2651 = rsmdt4.getColumnCount();

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

s2 = rsmdt4.getColumnName(j + 1).toLowerCase();

n2 = n1;

if (i > 0) {

k = 0;

for (int j1 = 0; j1 < n2; j1++) {

if (sk[j1].equals(s2)) {

sk[j1] = s10[i - 1] + "." + sk[j1];

if (variabl2049.length() == 0)

variabl2049 = " where " + s10[i - 1]

+ "." + s2 + " = " + s10[i]+ "." + s2;

else

variabl2049 = variabl2049 + " and "

+ s10[i - 1] + "." + s2 + " = "+ s10[i] + "." + s2;

sk[n1] = s10[i] + "." + s2 + " as "+ (s2 + i);

n1++;

k = 1;

break;

}

}

if (k == 0) {

sk[n1] = s2;

n1++;

}

} else {

sk[n1] = s2;

n1++;

}

}

rs.close();

stat4.close();

cont4.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

}

}

}


static void 数据表查询数据(String variabl2217) {

int c = 0;

int b = 0;

try {

cont4 = main1.getConn();

stat4 = cont4.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

s1 = "select " + variabl1633 + "  from " + variabl2217+ variabl2049;

rs = stat4.executeQuery(s1);

rsmdt4 = rs.getMetaData();

variabl2651 = rsmdt4.getColumnCount();

variabl2517 = new String[variabl2651];

variabl1501 = new String[variabl2651];

variabl1489 = new int[variabl2651];

for (int i1 = 0; i1 < variabl2651; i1++) {

variabl2517[i1] = rsmdt4.getColumnName(i1 + 1);

variabl1501[i1] = rsmdt4.getColumnTypeName(i1 + 1);

variabl1489[i1] = rsmdt4.getColumnDisplaySize(i1 + 1);

}

rs.last();

variabl1853 = rs.getRow();

variabl2197 = new String[variabl1853][variabl2651];

variabl21970 = new String[variabl1853][variabl2651];

while (c < variabl1853) {

rs.absolute(c + 1);

while (b < variabl2651) {

variabl21970[c][b] = rs.getString(b + 1);

if ((main1.variabl1545.lastIndexOf("," + variabl1501[b]+ ",")) > 0)

if ((variabl21970[c][b] == null)

|| (variabl21970[c][b].trim().length() == 0))

variabl21970[c][b] = "0";

else if (variabl21970[c][b] == null)

variabl21970[c][b] = "";

variabl2197[c][b] = variabl21970[c][b];

b++;

}

c++;

b = 0;

}

rs.close();

stat4.close();

cont4.close();

} catch (SQLException e1) {

JOptionPane.showMessageDialog(null, "读取数据库数据出错!");

}

}

   }





https://blog.sciencenet.cn/blog-2551-1122406.html

上一篇:管理信息系统软件生产线源码90-91
下一篇:管理信息系统软件生产线源码95-97
收藏 IP: 183.94.46.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-27 23:18

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部