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

博文

管理信息系统软件生产线源码95-97

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

版本1

95.源码95,部件程序,设计与生成打印数据库中表单式标签报表格式文件。表单式标签指多个结构相同的表单打印在同一打印纸上,结构重复,内容可以根据记录变化,可以全相同。表单可包括文本文件与图形文件。前者例如人事卡片、商品标签,后者例如名片、广告卡片。

/*

 * 程序文件名:printFormat7.java

 * 作者:程学先

 * 本程序用于辅助生成打印数据库中单数据表的单记录标签式报表格式文件。

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

 * 内容可以全相同,可以根据记录变化。

 * 本程序首先要求设计单个单记录式报表格式作为基本块,再说明标签特性,

 * 包括每行模块数、行间间隔、每列模块数、列间间隔。

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

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

 * 操作者输入时可将所有参数以字符个数为单位计算并输入,点击辅助计算后变换为象素单位。

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

 * 操作时只需要填写第一块的数据及标签属性部分数据,辅助计算后同时完成从一块到多块的设置。

 * 操作结果将替代已经输入的所有边距、宽度、高度、到顶距等数字。

 * 要求先按从上到下、从左到右输入第一块的各数据的名字、行号

 * 与列号、字体、字号、有无下表格线、有无右表格线。

 * 行号以字符为单位,也许大数据类型会连续占据多行位置,但依然按字符个数依次排号。

 * 如果快速输入,每个字段值需要点击列表框中字段名,修改标签内容,填入行号、列号后就可加入表格。

 * 文本域、图形字段还需要输入宽度、高度。左边距与到顶距无需输入。

 * 字体与字号建议全表统一,保持一致。

 * 行号从1起计数。

 * 列号指一行内控件个数序号,例如一行内有2个非大数据类型字段、2个大数据类型字段,

 * 则列号分别为1234。又例如,一行内有2个大数据类型字段,之后有1个非大数据类型字段,

 * 列号分别为123号。注意大数据类型可能占据多行,则每行它们都按其位置分配一个列号。

 * 例如,一个大数据类型字段从第4行起占据1号位置,其高度为4个字符,则在4567行中

 * 它都占据列号1(其后字段从2起安排列号,不过,在加入该大数据字段时自动写入的是0号)。

 * 又例如,第2行内有2个非大数据类型字段、2个大数据类型字段,要求2个大数据类型等高,

 * 假如均为4个字符高,则在第2345行它们都占据列号,不过本程序自动给它编为0号。

 * 要求全表数据统一字号。

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

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

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

 * (中间除标签外没有其他控件)。 非大数据类型数据要不全在左边,列号从1起计数;

 * 要不全在右边,从23起开始计数。

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

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

 * 如果不是第一个字段,当行安排不下,就移到下一行安排,如果仍然安排不下,请手工控制。

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

 * 如果已经无法通过调整面板宽度解决,请手工控制。

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

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

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

 * 高度超过1个字符的文本域控件的字段的数据类型必须为ntexttext

 * 所有数据保存在一个文件中,包括打印模板部分、标签属性等二组内容

 * 每组内容第一个数据标志组类型,1表示打印模板部分,属性包括:标签内容、字段名称、行号、列号、

 * 标签宽、字段宽、高度、左边距、到顶距、字体、字号等11个参数

 * 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.DatabaseMetaData;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

 

public class printFormat7 extends JFrame {

   private static printFormat7 frame2 = new printFormat7();

   private static JPanel panel2 = new JPanel();

   private static DefaultTableModel 表格模型2;

   private static JTable 表格2;

   private static JScrollPane scrollPane2 = new JScrollPane();

   private static List list2 = new List();

   private static JLabel fl0, fl10, fla1, fla2, fla3, fla4, fla5, fla6, fla7,

        fla8, fla9, fla10, fla11, fla12, fla13, fla14, fla15;

  private static JTextField fa0, fa10, faa1, faa2, faa3, faa4, faa5, faa6,

        faa7, faa8, faa9, faa10, faa11, faa12, faa13, faa14, faa15;

   private static JButton structureButton1;

   private static String 当前值;

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

   private static int 字段序号 = 0;

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

   private static String[] 标签属性;

   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 字段名表 = "";

 

   public static void means(String[] parameter) {

     frame2 = new printFormat7();

     panel2 = new JPanel();

     scrollPane2 = new JScrollPane();

     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";

     frame2.setTitle("单记录标签式报表格式文件设计页。                                                                                                                                                                                                                                                                                       作者:程学先");

     frame2.setBounds(10, 10, 980, 660);

      frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

     panel2.setBounds(10, 10, 980, 660);

     panel2.setLayout(null);

     String[] 列名02 = { "标签内容", "字段名称", "行号", "列号", "标签宽", "字段宽", "高度",

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

     main1.driver1();

     String 表名 = parameter[4];

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

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

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

     panel2.add(fl0);

     fa0 = new JTextField("");

     fa0.setText(表名);

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

     panel2.add(fa0);

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

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 0;

           list2.removeAll();

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

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

        }

     });

 

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

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

     panel2.add(fl10);

     fa10 = new JTextField("", 20);

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

     panel2.add(fa10);

     fa10.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {

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

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

             fc.showOpenDialog(null);

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

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

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

                try {

                   if (file1.exists()) {

                      FileReader fr = new FileReader(file1);

                      BufferedReader br = new BufferedReader(fr);

                      String tempStr = null;

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

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

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

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

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

                              "2,")) {

                           标签属性 = (tempStr.substring(2,

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

                        }

                      }

                   }

                } catch (IOException e2) {

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

                }

                faa10.setEnabled(true);

                faa13.setEnabled(true);

                faa14.setEnabled(true);

                faa15.setEnabled(true);

                structureButton1.setEnabled(true);

             }

           }

        }

     });

 

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

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

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

     scrollPane2.setViewportView(表格2);

     panel2.add(scrollPane2, BorderLayout.CENTER);

     fla1 = new JLabel("标签内容");

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

     panel2.add(fla1);

     faa1 = new JTextField("", 20);

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

     panel2.add(faa1);

     faa1.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 1;

           list2.removeAll();

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

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

           }

        }

     });

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

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

     panel2.add(fla2);

     faa2 = new JTextField("", 20);

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

     panel2.add(faa2);

     faa2.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 2;

           list2.removeAll();

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

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

           }

        }

     });

 

     fla11 = new JLabel("行号");

     fla11.setBounds(340, 460, 40, 20);

     panel2.add(fla11);

     faa11 = new JTextField("", 20);

     faa11.setBounds(380, 460, 60, 20);

     panel2.add(faa11);

     faa11.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 11;

           list2.removeAll();

        }

     });

 

     fla12 = new JLabel("列号");

     fla12.setBounds(440, 460, 40, 20);

     panel2.add(fla12);

     faa12 = new JTextField("", 20);

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

     panel2.add(faa12);

     faa12.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 12;

           list2.removeAll();

        }

     });

 

     fla3 = new JLabel("标签宽度");

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

     panel2.add(fla3);

     faa3 = new JTextField("", 20);

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

     panel2.add(faa3);

     faa3.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 3;

           list2.removeAll();

        }

     });

 

     fla4 = new JLabel("字段宽度");

     fla4.setBounds(680, 460, 60, 20);

     panel2.add(fla4);

     faa4 = new JTextField("", 20);

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

      panel2.add(faa4);

     faa4.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 4;

           list2.removeAll();

        }

     });

 

     fla5 = new JLabel("高度");

     fla5.setBounds(20, 500, 60, 20);

     panel2.add(fla5);

     faa5 = new JTextField("", 20);

     faa5.setBounds(80, 500, 100, 20);

     panel2.add(faa5);

     faa5.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 5;

           list2.removeAll();

        }

     });

 

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

     fla6.setBounds(200, 500, 40, 20);

     panel2.add(fla6);

     faa6 = new JTextField("", 20);

     faa6.setBounds(240, 500, 80, 20);

     panel2.add(faa6);

     faa6.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 6;

          list2.removeAll();

        }

     });

 

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

     fla7.setBounds(340, 500, 40, 20);

     panel2.add(fla7);

     faa7 = new JTextField("", 20);

     faa7.setBounds(380, 500, 80, 20);

     panel2.add(faa7);

     faa7.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 7;

           list2.removeAll();

        }

     });

 

     fla8 = new JLabel("字体");

     panel2.add(fla8);

     faa8 = new JTextField("", 20);

     panel2.add(faa8);

     fla8.setBounds(480, 500, 40, 20);

     faa8.setBounds(520, 500, 80, 20);

     faa8.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 8;

           list2.removeAll();

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

             list2.add(字体[i]);

           }

        }

     });

 

     fla9 = new JLabel("字号");

     panel2.add(fla9);

     faa9 = new JTextField("", 20);

     panel2.add(faa9);

     fla9.setBounds(620, 500, 40, 20);

     faa9.setBounds(660, 500, 80, 20);

     faa9.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 9;

           list2.removeAll();

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

             list2.add(字号[i]);

           }

        }

     });

 

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

     panel2.add(fla10);

     faa10 = new JTextField("", 20);

     panel2.add(faa10);

     fla10.setBounds(20, 540, 100, 20);

     faa10.setBounds(120, 540, 60, 20);

     faa10.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 10;

           list2.removeAll();

        }

     });

 

     fla13 = new JLabel("列模块间距");

     panel2.add(fla13);

     faa13 = new JTextField("", 20);

     panel2.add(faa13);

     fla13.setBounds(180, 540, 80, 20);

     faa13.setBounds(260, 540, 60, 20);

     faa13.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 13;

           list2.removeAll();

        }

     });

 

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

     panel2.add(fla14);

     faa14 = new JTextField("", 20);

     panel2.add(faa14);

     fla14.setBounds(320, 540, 100, 20);

     faa14.setBounds(420, 540, 60, 20);

     faa14.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 14;

           list2.removeAll();

        }

     });

 

     fla15 = new JLabel("行模块间距");

     panel2.add(fla15);

     faa15 = new JTextField("", 20);

     panel2.add(faa15);

     fla15.setBounds(480, 540, 80, 20);

     faa15.setBounds(560, 540, 60, 20);

     faa15.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           当前列号 = 15;

           list2.removeAll();

        }

     });

 

     faa1.setText("");

     faa2.setText("");

     faa3.setText("0");// 所有文本框清空

     faa4.setText("0");

     faa5.setText("0");

     faa6.setText("0");

     faa7.setText("0");

     faa8.setText("宋体");

     faa9.setText("0");

     faa10.setText("0");

     faa11.setText("0");

     faa12.setText("0");

     faa13.setText("5");

     faa14.setText("0");

     faa15.setText("5");

     faa10.setEnabled(false);

     faa13.setEnabled(false);

     faa14.setEnabled(false);

     faa15.setEnabled(false);

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

     panel2.add(list2);

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

        public void mouseClicked(MouseEvent e) {

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

             int w1, w2, h1, h2;

             String s0 = "";

             switch (当前列号) {

             case 0: // 表名

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

                   s0 = list2.getSelectedItem();

                else

                   s0 = fa0.getText() + "," + list2.getSelectedItem();

                fa0.setText(s0);

                数据表查询结构(s0);

                break;

             case 1:

                faa1.setText(list2.getSelectedItem());

                faa2.setText(list2.getSelectedItem());

                字段序号 = list2.getSelectedIndex();

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

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

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

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

                   faa5.setText("1");

                }

                faa8.setText("宋体");

                faa9.setText("12");

                break;

             case 2:

                faa2.setText(list2.getSelectedItem());

                break;

             case 3:

                faa3.setText(list2.getSelectedItem());

                break;

             case 4:

                faa4.setText(list2.getSelectedItem());

                break;

             case 5:

                faa5.setText(list2.getSelectedItem());

                break;

             case 6:

                faa6.setText(list2.getSelectedItem());

                break;

             case 7:

                faa7.setText(list2.getSelectedItem());

                break;

             case 8:

                faa8.setText(list2.getSelectedItem());

                break;

             case 9:

                faa9.setText(list2.getSelectedItem());

                break;

             case 11:

                faa11.setText(list2.getSelectedItem());

                break;

             case 12:

                faa12.setText(list2.getSelectedItem());

                break;

             }

           }

        }

     });

 

     表格2.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {

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

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

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

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

             else

                当前值 = "";

             switch (j) {

             case 0:

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

                break;

             case 2:

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

                break;

             case 3:

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

                break;

             case 1:

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

                break;

             case 4:

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

                break;

             case 5:

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

                break;

             case 6:

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

                break;

             case 7:

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

                break;

             case 8:

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

                break;

             case 9:

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

                break;

             case 10:

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

                break;

             }

           }

        }

     });

 

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

     addButton1.setBounds(20, 580, 120, 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 < 表格模型2.getRowCount(); i++) {

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

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

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

                选中行号 = i;

                break;

             }

           }

           if (选中行号 < 0) {

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

                   faa11.getText(), faa12.getText(), faa3.getText(),

                   faa4.getText(), faa5.getText(), faa6.getText(),

                   faa7.getText(), faa8.getText(), faa9.getText() };

             表格模型2.addRow(rowValues);

             faa1.setText("");

             faa2.setText("");

             faa3.setText("0");

             faa4.setText("0");

             faa5.setText("0");

             faa6.setText("0");

             faa7.setText("0");

             faa8.setText("宋体");

             faa9.setText("0");

             faa10.setText("0");

             faa11.setText("0");

             faa12.setText("0");

             faa13.setText("5");

             faa14.setText("0");

             faa15.setText("5");

           } else

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

        }

     });

     panel2.add(addButton1);

 

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

     updButton1.setBounds(140, 580, 120, 20);

     updButton1.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(faa1.getText().trim()))) {

                选中行号 = i;

                break;

             }

           }

           if (选中行号 >= 0) {

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

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

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

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

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

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

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

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

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

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

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

           } else

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

        }

     });

     panel2.add(updButton1);

 

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

     delButton1.setBounds(260, 580, 120, 20);

     delButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

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

           if (选中行号 != -1)

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

        }

     });

     panel2.add(delButton1);

 

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

     countButton1.setBounds(380, 580, 100, 20);

     countButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

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

           int = 0, = 0, = 0;

           int 总行数 = 0;

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

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

           int 标签宽度 = 0;

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

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

              if (( == 1)

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

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

                标签宽度 = Integer.valueOf(表格模型2.getValueAt(i, 4)

                      .toString());

           }

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

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

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

             }

           }

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

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

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

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

             if ( > 总行数)

                总行数 = ;

             if ( > 1) {

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

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

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

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

                      i行标志1[] = 1;

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

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

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

                      if ( + j > 总行数)

                        总行数 = + j;

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

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

                   }

                } else {

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

                      i行标志1[] = + 1;

                   i行标志2[] = ;

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

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

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

                      i行标志2[ + j] = ;

                      if ( + j > 总行数)

                        总行数 = + j;

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

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

                   }

                }

             }

           }

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

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

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

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

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

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

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

                } else

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

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

                   数据[i][12] = " ";

                else

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

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

                if ((j > 1) && (j < 9) || (j == 10))

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

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

                   else

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

             }

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

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

           }

           String trim = "";

           int trim1 = 0;

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

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

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

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

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

                      trim = 数据[j][k];

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

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

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

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

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

                   }

                }

             }

           }

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

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

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

           int kuand = 0;

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

             = 数据1[i][1];

             = 数据1[i][2];

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

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

                   if ( > i行列数[]) {

                      i行列数[] = ;

                      i行末列序号[] = i + 1;

                   }

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

                   if (i行宽度[] > kuand)

                      kuand = i行宽度[];

                }

             }

           }

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

             = 数据1[i][1];

             = 数据1[i][2];

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

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

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

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

                      break;

                  }

                }

             }

           }

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

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

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

           kuand = 0;

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

             = 数据1[i][1];

             = 数据1[i][2];

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

                i行列数[] = ;

                i行末列序号[] = i + 1;

             }

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

             if (i行宽度[] > kuand)

                kuand = i行宽度[];

           }

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

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

             if (k3 > 0) {

                k3 = k3 - 1;

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

             }

           }

           int m1 = 0;

           = 0;

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

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

                = 数据1[i][1];

                m1 = 0;

             }

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

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

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

           }

           表格模型2.setRowCount(0);

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

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

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

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

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

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

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

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

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

             }

           }

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

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

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

                   一条记录[j] = 数据[i][j - 1];

                }

                一条记录[0] = 数据[i][12];

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

             }

           }

           faa10.setEnabled(true);

           faa13.setEnabled(true);

           faa14.setEnabled(true);

           faa15.setEnabled(true);

           structureButton1.setEnabled(true);

        }

     });

     panel2.add(countButton1);

 

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

     clearButton1.setBounds(480, 580, 120, 20);

     clearButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           faa1.setText("");

           faa2.setText("");

           faa3.setText("0");

           faa4.setText("0");

           faa5.setText("0");

           faa6.setText("0");

           faa7.setText("0");

           faa8.setText("宋体");

           faa9.setText("0");

           faa10.setText("0");

           faa11.setText("0");

           faa12.setText("0");

           faa13.setText("5");

           faa14.setText("0");

           faa15.setText("5");

        }

     });

     panel2.add(clearButton1);

 

     structureButton1 = new JButton("标签结构设计");

     structureButton1.setBounds(600, 580, 120, 20);

     structureButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           int 行模块数 = Integer.valueOf(faa10.getText());

           int 行块间距 = Integer.valueOf(faa13.getText());

           int 列模块数 = Integer.valueOf(faa14.getText());

           int 列块间距 = Integer.valueOf(faa15.getText());

           int 模块宽度 = 0;

           int 模块高度 = 0;

           String[][] 项目 = new String[表格模型2.getRowCount()][11];

           int 到顶距0 = 0;

           int[][] 项目数据 = new int[表格模型2.getRowCount()][11];

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

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

                项目[i][j] = 表格模型2.getValueAt(i, j).toString();

                if ("019".lastIndexOf("" + j) < 0)

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

             }

           }

           int 左边距 = 0;

           int 左边距0 = 0;

           int 到顶距 = 0;

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

           for (int k1 = 0; k1 < 列模块数; k1++) { // 纵向复制

             for (int k2 = 0; k2 < 行模块数; k2++) { // 横向复制

                if ((k1 == 0) && (k2 == 0)) { // 最左上角一块,复制的底版

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

                      if ((项目数据[k3][7] + 项目数据[k3][4] + 项目数据[k3][5]) > 模块宽度) // 最大宽度

                        模块宽度 = 项目数据[k3][7] + 项目数据[k3][4]+ 项目数据[k3][5];

                      if ((项目数据[k3][8] + 项目数据[k3][6]) > 模块高度) // 最大高度

                        模块高度 = 项目数据[k3][8] + 项目数据[k3][6];

                   }

                   continue;

                }

                if ((k1 == 0) && (k2 == 1)) {

                   到顶距 = 0;

                   左边距 = 模块宽度 + 行块间距;

                } else if ((k1 == 1) && (k2 == 行模块数 - 1)) {

 

                }

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

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

                      if (j == 7)

                        记录[j] = "" + (项目数据[i][j] + 左边距); // 复制时修改左边距

                      else if (j == 8)

                        记录[j] = "" + (项目数据[i][j] + 到顶距); // 复制时修改到顶距

                      else

                        记录[j] = 项目[i][j]; // 其他各项复制

                   }

                   表格模型2.addRow(记录);

                }

                左边距 = 左边距 + 行块间距 + 模块宽度;

             } // 横向复制

             到顶距 = 到顶距 + 列块间距 + 模块高度;

             左边距 = 0;

           } // 纵向复制

        }

     });

     structureButton1.setEnabled(false);

     panel2.add(structureButton1);

 

     final JButton saveButton1 = new JButton("保存到文件");

     saveButton1.setBounds(720, 580, 120, 20);

     saveButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           char x1 = 10;

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

           FileOutputStream fs;

           try {

             fs = new FileOutputStream(file1);

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

                String s3 = "1,";

                for (int j = 0; j < 11; 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.write(("2," + faa10.getText() + "").getBytes());

             fs.write((faa13.getText() + "").getBytes());

             fs.write((faa14.getText() + "").getBytes());

             fs.write((faa15.getText() + " " + x1).getBytes());

             fs.close();

           } catch (IOException e2) {

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

           }

        }

     });

     panel2.add(saveButton1);

 

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

     exitButton1.setBounds(840, 580, 110, 20);

     exitButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           panel2.setVisible(false);

           frame2.setVisible(false);

           frame2.dispose();

        }

     });

     panel2.add(exitButton1);

     frame2.add(panel2);

     frame2.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, "读取数据库数据出错!");

     }

   }

}

 

 

96.源码96,部件程序,表单式标签报表打印预览程序。根据单表或多表的内容按照printFormat7.java程序生成的打印格式文件打印预览。

/**

 * 程序文件名:dataPreview4.java

 * 完成时间:20131127

 * 部件功能:表单式标签报表打印预览程序。

 * 根据单表或多表的内容按照printFormat7.java程序生成的打印格式文件打印预览。

 * 调用语句:dataPreview4.means(parameter);

 * 必须提供的参数:数据表表名格式文件名

 */

 

import java.awt.*;

import java.awt.event.*;

import java.awt.font.FontRenderContext;

import java.awt.font.TextLayout;

import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;

import javax.swing.*;

import javax.swing.table.*;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.IOException;

import java.io.InputStream;

import java.sql.*;

import java.util.ArrayList;

 

public class dataPreview4 extends JFrame {

   static dataPreview4 frame = new dataPreview4();

   static String 表名 = "";

   static DefaultTableModel tableModel;

   static JTable table;

   static JScrollPane scrollPane = new JScrollPane();

   static JScrollPane scrollPane1;

   static JTextField aTextField;

   static JButton previewButton2;

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

   static ResultSet rs;

   static int 列数;

   static String[] 列名;

   static String[] 列数据类型;

   static int[] 列数据宽度;

   static int[] 表列数据宽度;

   static int 记录条数, 行号 = -1;

   static String[][] 表格数据;

   static String 打印格式文件名;

   private static ArrayList<struct3> table1 = null;

   private static ArrayList<struct4> table2 = null;

   static Connection cont4;

   static ResultSetMetaData rsmd4;

   static Statement stat4;

   static int 窗口宽 = 1400, 窗口高 = 600, 页高 = 600;

   private static Graphics2D g3;

   private static Graphics g;

   private static Font font;

   private static TextLayout layout;

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

   static String[] 按钮集 = null;

   static String 要求按钮号表;

   static int 按钮数 = 0, 按钮宽 = 0;

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

   private static int kuand = 0, gaod = 0;

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

   private static String 连接条件 = "";

   private static String 字段名表 = "";

   private static struct3[] 表体=null;

   private static struct4[] 标签=null;

   private static int[] w10 = null,w20 = null,h10 = null,h20 = null;

   private static int[] t10 = null,l10 = null,le0 = null,f0 = null;

   private static int w01=0, w02=0, h01=0, l01=0, le01=0, le02=0;

   private static int w2 = 0,高度 = 0, 右边 = 0;

 

   static void print1() {

     g3 = (Graphics2D) g;

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

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

        if (行号 >= 记录条数)

           return;

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

        w10[i] = Integer.valueOf(表体[i].table1[4]); // 标签宽度

        w20[i] = Integer.valueOf(表体[i].table1[5]); // 字段宽度

        h10[i] = Integer.valueOf(表体[i].table1[6]); // 高度

        h20[i] = Integer.valueOf(表体[i].table1[10]); // 字号

        t10[i] = Integer.valueOf(表体[i].table1[8]); // 到顶

        l10[i] = Integer.valueOf(表体[i].table1[2]); // 行号

        le0[i] = Integer.valueOf(表体[i].table1[7]); // 左边距

        if (表体[i].table1[1].indexOf(".")>0)

           表体[i].table1[1]=表体[i].table1[1].substring(表体[i].table1[1].indexOf(".")+1);

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

           if (列名[j].indexOf(".")>0)

             列名[j]=列名[j].substring(列名[j].indexOf(".")+1);

           if (列名[j].equalsIgnoreCase(表体[i].table1[1])) {

             f0[i] = j;

             break;

           }

        }

     }

 

     FontRenderContext frc = new FontRenderContext(null, false, false);

     char p1 = 10, p2 = 13;

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

     int 左边 = 40, 到顶 = 50, 左边0 = 40,  高度=0;

       if (行号<0) 行号=0;

     y1 = 到顶;

     x1 = 左边;

     int 本块顶 = 0;

     int k = 0;

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

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

           本块顶=到顶;

           if ((打印相同记录 > 0) && ((i1 > 0) || (l > 0)))

             行号++;

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

             x1 = le0[i] + 左边;

             y1 = t10[i] + 到顶;

             w1 = w10[i];

             w2 = w20[i];

             h1 = h10[i];

             if (l10[i] == 1) {

                g3.drawLine(x1, y1, x1 + w1 + w2, y1);

             }

             if (行号 >= 记录条数)  return;

             g3.drawLine(x1, y1, x1, y1 + h1); // 行号为0的控件的最左边竖线

             g3.setFont(new Font(表体[i].table1[9], Font.PLAIN, Integer

                   .valueOf(表体[i].table1[10])));// 设置字体

             g3.drawLine(x1 + w10[i], y1, x1 + w1, y1 + h1);

             if (表格数据[行号][f0[i]] == null)

                表格数据[行号][f0[i]] = " ";

             font = new Font(表体[i].table1[9], Font.PLAIN,

                   Integer.valueOf(表体[i].table1[10]));// 设置字体字号

             g3.setFont(font);

             g3.drawString(表体[i].table1[0], x1 + 2, y1 + h20[i]);

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

                   + 列数据类型[i] + ",") >= 0)|| (h1 > h20[i] * 2)) {

                if (行号 >= 记录条数)

                   return;

                if (main1.图形数据类型.indexOf("," + 列数据类型[i] + ",") >= 0) {

                   x1 = le0[i] + 左边;

                   y1 = t10[i] + 到顶;

                   w2 = w20[i];

                   h1 = h10[i];

                   try {

                      cont4 = main1.getConn();

                      stat4 = cont4.createStatement(

                           ResultSet.TYPE_SCROLL_INSENSITIVE,

                           ResultSet.CONCUR_UPDATABLE);

                      String sql = "select " + 列名[i] + " from " + 表名;

                      if (表名.indexOf(",") > 0)

                        s1 = s1 + 连接条件;

                      rs = stat4.executeQuery(sql);

                      rs.absolute(行号 + 1);

                      InputStream image = rs.getBinaryStream(列名[i]);

                      String image0 = image.toString();

                      long length = image0.length();

                      byte[] buffer = new byte[(int) length / 7];

                      File file = new File("a1.jpg");

                      int ch = 0;

                      if (file.exists()) {

                        file.delete();

                      }

                      file.createNewFile();

                      FileOutputStream file1 = new FileOutputStream(

                           file, true);

                      boolean go = true;

                      while (go) {

                        while ((ch = image.read(buffer)) != -1) {

                           file1.write(buffer);

                        }

                        go = false;

                      }

                      BufferedImage image1 = ImageIO.read(file);

                      g.drawImage(image1, x1 + w1 + 2, y1, w2, h1,null);

                      rs.close();

                      file1.close();

                      stat4.close();

                      cont4.close();

                   } catch (Exception e) {

                      e.printStackTrace();

                   }

                }

                else {

                   int j = 0;

                   y2 = y1;

                   float j1 = 0f;

                   s2 = 表格数据[行号][f0[i]];

                   s3 = "";

                   if ((s2.lastIndexOf("" + p1) < s2.length())

                        && (s2.lastIndexOf("" + p1) > 0))

                      s2 = s2 + p1;

                   for (k = 0; k < s2.length(); k++) {

                      if ((j1 < w2)

                           && (!s2.substring(k, k + 1)

                                .equalsIgnoreCase("" + p1))

                           && (!s2.substring(k, k + 1)

                                .equalsIgnoreCase("" + p2))

                           && (k != s2.length() - 1)) {

                        s3 = s3 + s2.substring(k, k + 1);

                        if (s2.substring(k, k + 1).compareTo("z") < 0) {

                           if (s2.substring(k, k + 1).compareTo("0") < 0)

                              j1 = j1 + h20[i] * 0.43f;

                           else

                              j1 = j1 + h20[i] * 0.64f;

                        } else

                           j1 = j1 + h20[i];

                      } else {

                        if (j1 >= w2)

                           s3 = s3 + s2.substring(k, k + 1);

                        j = j + h20[i];

                        if (j1 >= w2 - 2) {

                           layout = new TextLayout(s3, font, frc)

                                .getJustifiedLayout(w2 - 2);

                           layout.draw(g3, x1 + w1 + 2, y2+ h20[i]);

                        } else {

                           g3.drawString(s3, x1 + w1 + 2, y2+ h20[i]);

                        }

                        y2 = y2 + h20[i] + 5;

                        s3 = "";

                        j1 = 0;

                      }

                      if (j >= h1)

                        break;

                   }

                }

             } else {

                g3.drawString(表格数据[行号][f0[i]], x1 + w1 + 2, y1 + h20[i]);

             }

             g3.drawLine(x1, y1 + h1, x1 + w1 + w2, y1 + h1);

             if (y1 + h1 > 高度)

                高度 = y1 + h1;

             if ((i < table1.size() - 1) && (f0[i + 1] == 0)) {

                g3.drawLine(x1 + w1 + w2, 本块顶, x1 + w1 + w2, 高度);

             }

           }

                右边=左边 + kuand;

           g3.drawLine(右边, 本块顶, 右边, 高度);

           左边 = 左边 + kuand + 行间间隔;

           本块顶 = 到顶;

        }

        左边 = 左边0;

        到顶 = 到顶 + gaod + 列间间隔;

        本块顶 = 到顶;

     }

     if (打印相同记录 > 0) 行号++;

   }

 

   public static void means(String[] parameter) {

     s1 = "";

     s2 = "";

     记录条数 = 0;

     列数 = 0;

     表体=null;

     标签=null;

     table1 = new ArrayList<struct3>();

     table2 = new ArrayList<struct4>();

     页高 = 600;

     打印相同记录 = 0;

     w2 = 0;

     高度 = 0;

     右边 = 0;

     每行模块数 = 0;

     行间间隔 = 0;

     每列模块数 = 0;

     列间间隔 = 0;

     kuand = 0;gaod = 0;

     frame = new dataPreview4();

     表名 = "";

     scrollPane = new JScrollPane();

     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];

     连接条件 = parameter[20];

     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, "打开文件错!");

     }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

     w01=0; w02=0; h01=0; l01=0; le01=0; le02=0;

     le02 = Integer.valueOf(table1.get(0).table1[7]); // 第一个元素左边距

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

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

        w01 = Integer.valueOf(表体[i].table1[4]); // 标签宽度

        w02 = Integer.valueOf(表体[i].table1[5]); // 字段宽度

        h01 = Integer.valueOf(表体[i].table1[6]); // 高度

        l01 = Integer.valueOf(表体[i].table1[2]); // 行号

        le01 = Integer.valueOf(表体[i].table1[7]); // 左边距

        if (l01 == 1)

           kuand = kuand + w01 + w02;

        if (le01 == le02)

           gaod = gaod + h01;

     }

     字段名表 = "";

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

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

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

        else

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

     }

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

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

     frame.setLayout(null);

     frame.setTitle("单记录式报表预览程序         作者:程学先");

     frame.setBounds(10, 10, 窗口宽 - 10, 1000);

     final JPanel panel = new JPanel();

     panel.setBounds(10, 10, 窗口宽 - 50, 1000);

     panel.setLayout(null);

     frame.getContentPane().add(panel);

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

     table = new JTable(tableModel);

      table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

     table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

     scrollPane.getViewport().add(table, null);

     scrollPane.setBounds(30, 50, 窗口宽 - 100, 窗口高 - 150);

     panel.add(scrollPane);

     table.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {

           行号 = table.getSelectedRow();

        }

     });

     int 左边距 = 100;

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

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

    previewButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           打印相同记录 = 0;

           if (行号 < 0) {

             JOptionPane.showMessageDialog(null, "未在表格中选择某条记录,请重新操作!");

             return;

           } else {

             panel.remove(scrollPane);

             g = panel.getGraphics();

             panel.paint(g);

             print1();

           }

        }

     });

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

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

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

        panel.add(previewButton1);

     }

 

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

    previewButton2.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           打印相同记录 = 1;

           if (行号 < 0) {

             JOptionPane.showMessageDialog(null, "未在表格中选择某条记录,请重新操作!");

             return;

           } else {

             panel.remove(scrollPane);

             g = panel.getGraphics();

             panel.paint(g);

             print1();

           }

        }

     });

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

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

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

        panel.add(previewButton2);

     }

 

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

     exitButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           panel.setVisible(false);

           frame.setVisible(false);

           frame.dispose();

        }

     });

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

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

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

        panel.add(exitButton);

     }

     frame.setVisible(true);

      frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

   }

 

   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);

           rsmd4 = rs.getMetaData();

           列数 = rsmd4.getColumnCount();

           列名 = new String[列数];

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

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

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

             列名[i] = rsmd4.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);

             rsmd4 = rs.getMetaData();

             列数 = rsmd4.getColumnCount();

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

                s2 = rsmd4.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);

        rsmd4 = rs.getMetaData();

        列数 = rsmd4.getColumnCount();

        列名 = new String[列数];

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

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

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

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

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

           列数据宽度[i1] = rsmd4.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, "读取数据库数据出错!");

     }

   }

   }

97.源码97,部件程序,表单式标签报表打印程序。根据单表或多表的内容按照printFormat7.java程序生成的打印格式文件打印报表。

/**

 * 程序文件名:dataPrint4.java

 * 作者:程学先

 * 完成时间:20131127

 * 部件功能:表单式标签报表打印程序。

 * 根据单表或多表的内容按照printFormat7.java程序生成的打印格式文件打印报表。

 */

import java.awt.*;

import java.awt.event.*;

import java.awt.font.FontRenderContext;

import java.awt.font.TextLayout;

import java.awt.image.BufferedImage;

import java.awt.print.PageFormat;

import java.awt.print.Printable;

import java.awt.print.PrinterException;

import java.awt.print.PrinterJob;

import javax.imageio.ImageIO;

import javax.swing.*;

import javax.swing.table.*;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.IOException;

import java.io.InputStream;

import java.sql.*;

import java.util.ArrayList;

public class dataPrint4 extends JFrame {

   static dataPrint4 frame = new dataPrint4();

   static String 表名="";

   static DefaultTableModel tableModel;

    static JTable table;

    static JScrollPane scrollPane = new JScrollPane();

    static JScrollPane scrollPane1 ;

    static JTextField aTextField;

    static JButton previewButton2;

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

   static ResultSet rs;

    static int 列数;

    static String[] 列名;

    static String[] 列数据类型;

    static int[] 列数据宽度

    static int[] 表列数据宽度;

    static int 记录条数, 行号=-1;

    static String[][] 表格数据;

    static byte 图像[];

   static String 打印格式文件名;

   private static ArrayList<struct1> title=new ArrayList<struct1>();

   private static ArrayList<struct2> tableTitle=new ArrayList<struct2>();

   private static PrinterJob job = PrinterJob.getPrinterJob();

    static Connection cont4;

    static ResultSetMetaData rsmd4;

    static Statement stat4;

    static int 窗口宽 = 1000, 窗口高 = 600, 页高=600;

   private static Graphics2D g3;

   private static Graphics g;

   private static Font font;  

   private static TextLayout layout

    public static String [] sw=new String[11];

   static String [] 按钮集=null;

   static String 要求按钮号表;

   static int 按钮数=0,按钮宽=0;

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

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

    private static int kuand=0,gaod=0;

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

    private static String 连接条件="";

    private static String 字段名表="";

   private static int w2=0,高度=0,右边=0;

   private static struct1[] 表体=null;

   private static struct2[] 标签=null;

   private static int[] w10 = null,w20 = null,h10 = null,h20 = null;

   private static int[] t10 = null,l10 = null,le0 = null,f0 = null;

  

   static void  printa1() {

     行号 = table.getSelectedRow();

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

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

            w10[i]=Integer.valueOf(表体[i].title[4]);  //标签宽度

           w20[i]=Integer.valueOf(表体[i].title[5]); //字段宽度

           h10[i]=Integer.valueOf(表体[i].title[6]); //高度

            h20[i]=Integer.valueOf(表体[i].title[10]); // 字号

           t10[i]=Integer.valueOf(表体[i].title[8]);//到顶

           l10[i]=Integer.valueOf(表体[i].title[2]);//行号

            le0[i]=Integer.valueOf(表体[i].title[7]); //左边距

        if (表体[i].title[1].indexOf(".")>0)

           表体[i].title[1]=表体[i].title[1].substring(表体[i].title[1].indexOf(".")+1);

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

           if (列名[j].indexOf(".")>0)

             列名[j]=列名[j].substring(列名[j].indexOf(".")+1);

            if(列名[j].trim().equalsIgnoreCase(表体[i].title[1].trim()))

            {

              f0[i]=j;

              break;

            }  

        }

        }

      FontRenderContext frc=new FontRenderContext(null,false,false);

     char p1=10,p2=13;

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

     int 左边=40,到顶=50,左边0=40,高度=0;

     if (行号<0) 行号=0;

    y1=到顶;

    x1=左边;

    int 本块顶=0;

    int k=0;

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

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

        本块顶=到顶;

        if ((打印相同记录>0)&&((i1>0)||(l>0)))

            行号++;

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

       x1=le0[i]+左边;

       y1=t10[i]+到顶;

       w1=w10[i]; 

       w2=w20[i];

       h1=h10[i];

       if (l10[i]==1){

          g3.drawLine(x1, y1, x1+w1+w2, y1);

       }

       if (行号>=记录条数) return;

       g3.drawLine(x1, y1, x1, y1+h1);//行号为0的控件的最左边竖线

         g3.setFont(new Font(表体[i].title[9],Font.PLAIN,Integer.valueOf(表体[i].title[10])));

       g3.drawLine(x1+w10[i], y1, x1+w1, y1+h1);

       if (表格数据[行号][f0[i]]==null) 表格数据[行号][f0[i]]=" ";

         font=new Font(表体[i].title[9],Font.PLAIN,Integer.valueOf(表体[i].title[10]));

         g3.setFont(font);

         g3.drawString(表体[i].title[0],x1+2, y1+h20[i]);

   if (((main1.文本数据类型+main1.图形数据类型).lastIndexOf(","+列数据类型[i]+",") >= 0)||

         (h1>h20[i]*2)){ 

     if (行号>=记录条数) return;

   if (main1.图形数据类型.indexOf(","+列数据类型[i]+",")>=0){

             x1=le0[i]+左边;

             y1=t10[i]+到顶

             w2=w20[i];

             h1=h10[i];

             try{

                cont4=main1.getConn();

                stat4 = cont4.createStatement(

                      ResultSet.TYPE_SCROLL_INSENSITIVE,

                      ResultSet.CONCUR_UPDATABLE);

                        String sql="select "+列名[i]+" from "+表名;

                  if (表名.indexOf(",")>0)

                     sql=sql+连接条件;

                        rs=stat4.executeQuery(sql);

                        rs.absolute(行号+1);

                   InputStream image = rs.getBinaryStream(列名[i]);                                         

                  String image0=image.toString();

               long length=image0.length();

                 byte[] buffer = new byte[(int)length/7];

                 File file=new File("a1.jpg");

                 int ch = 0;

                 if ( file.exists()){

                    file.delete();

                 }

                 file.createNewFile();

                 FileOutputStream file1=new FileOutputStream(file,true);

                    boolean go = true;

                    while(go)

                    {

                    while((ch = image.read(buffer))!=-1)

                    {

                     file1.write(buffer);

                    }

                    go=false;

                    }

                    BufferedImage image1=ImageIO.read(file);

                    g.drawImage(image1,x1+w1+2,y1,w2,h1,null);

                    rs.close();

                    file1.close();

                    stat4.close();

                    cont4.close();

             }catch(Exception e)

               {e.printStackTrace(); }

             }

       else {

           int j=0;

           y2=y1;

           float j1=0f;

           s2=表格数据[行号][f0[i]];

           s3="";

           if ((s2.lastIndexOf(""+p1)<s2.length())&&

           (s2.lastIndexOf(""+p1)>0))

           s2=s2+p1;

   for (k=0;k<s2.length();k++){

     if ((j1 < w2)

           && (!s2.substring(k, k + 1)

                .equalsIgnoreCase("" + p1))

           && (!s2.substring(k, k + 1)

                .equalsIgnoreCase("" + p2))

           && (k != s2.length() - 1)) {

         s3=s3+s2.substring(k,k+1);

        if (s2.substring(k,k+1).compareTo("z")<0){

           if (s2.substring(k,k+1).compareTo("0")<0)

                  j1=j1+h20[i]*0.37f;

           else  j1=j1+h20[i]*0.57f; 

        }

        else j1=j1+h20[i];

     }

     else {

        if (j1 >= w2)

           s3 = s3 + s2.substring(k, k + 1);

         j=j+h20[i];

         if (j1>=w2-2){

        layout=new TextLayout(s3,font,frc).getJustifiedLayout(w2-2);;

        layout.draw(g3,x1+w1+2,y2+h20[i]);

         }

         else g3.drawString(s3,x1+w1+2, y2+h20[i]);

        y2=y2+h20[i];

        s3="";

        j1=0;

     }

     if (j>=h1) break;

   }

   }

    }

         else {

             g3.drawString(表格数据[行号][f0[i]],x1+w1+2, y1+h20[i]);

         }

          g3.drawLine(x1, y1+h1,x1+w1+w2, y1+h1);

          if (y1+h1>高度) 高度=y1+h1;

     if ((i < title.size() - 1) && (f0[i + 1] == 0))

     g3.drawLine(x1 + w1 + w2, 本块顶, x1 + w1 + w2, 高度);

      }

      右边=左边 + kuand;

     g3.drawLine(右边,本块顶 ,右边, 高度);

     左边=左边+kuand+行间间隔;

     本块顶=到顶;

     }

     左边=左边0;

     到顶=到顶+gaod+列间间隔;

     本块顶=到顶;

     }

     if (打印相同记录 > 0) 行号++;

   } 

 

   public static void means(String [] parameter) {

     sw=new String [11];

       sw[1]=main1.sw1+"";sw[2]=main1.sw2;sw[3]=main1.sw3;

       sw[4]=main1.sw4;sw[5]=main1.sw5;sw[6]=main1.sw6;

       sw[7]=main1.sw7;sw[8]=main1.sw8;sw[9]=main1.sw9;

       sw[10]=main1.sw10;

       main1.sw1=0;main1.sw2="";main1.sw3="";

       main1.sw4="";main1.sw5="";main1.sw6="";

       main1.sw7="";main1.sw8="";main1.sw9="";main1.sw10="";

       frame = new dataPrint4();

       表名="";

       scrollPane = new JScrollPane();

       s1="";s2="";s3=""; 行号=-1;

     kuand = 0;gaod = 0;

       title=new ArrayList<struct1>();

       tableTitle=new ArrayList<struct2>();

       窗口宽 = 1000; 窗口高 = 600; 页高=600;

       w2=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] ;

     连接条件=parameter[20] ;

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

           

                 title.add(new struct1(tempStr.substring(2,tempStr.length()).split("")));

              }

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

           

                 tableTitle.add(new struct2(tempStr.substring(2,tempStr.length()).split("")));

              }

              }

            }

        }catch(IOException e2) { 

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

        }

        表体=new struct1[title.size()];

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

        w20=new int[title.size()]; 

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

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

        t10=new int[title.size()];

        l10=new int[title.size()];

        le0=new int[title.size()];

        f0=new int[title.size()];

      struct2 [] 标签=new struct2[tableTitle.size()];

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

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

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

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

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

        int w01,w02,h01,l01,le01,le02;

         le02=Integer.valueOf(title.get(0).title[7]);   //第一个元素左边距

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

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

            w01=Integer.valueOf(表体[i].title[4]);   //标签宽度

           w02=Integer.valueOf(表体[i].title[5]);   //字段宽度

           h01=Integer.valueOf(表体[i].title[6]);   //高度

           l01=Integer.valueOf(表体[i].title[2]);   //行号

            le01=Integer.valueOf(表体[i].title[7]);   //左边距

           if (l01==1) kuand=kuand+w01+w02;

           if (le01==le02) gaod=gaod+h01;

         }

 

      main1.driver1();

     字段名表 = "";

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

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

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

        else

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

     }

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

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

   frame.show();

   frame.setLayout(null);

   frame.setTitle("单记录式报表程序                                                                                                                                                                                                                                                                                         作者程学先");

   frame.setBounds(10, 10,窗口宽-10,1000);  

    frame.getContentPane().setLayout(null);  

    final JPanel panel = new JPanel();  

    panel.setBounds(10, 10,窗口宽-50,1000);

    panel.setLayout(null);     

    frame.getContentPane().add(panel);

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

    table = new JTable(tableModel);

    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    scrollPane.getViewport().add(table, null);

    scrollPane.setBounds(30, 50,窗口宽-100,窗口高-150);  

    panel.add(scrollPane); 

    table.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {

               行号 = table.getSelectedRow();

        }

    });

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

   int 左边距=30;

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

    previewButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

          打印相同记录=0;

            if (行号<0) {

              JOptionPane.showMessageDialog( null, "未在表格中选择某条记录请重新操作");

              return;

            }

            else {

                job = PrinterJob.getPrinterJob();

               if (!job.printDialog())

                   return;

                

             job.setPrintable(new Printable() {

                   public int print(Graphics graphics, PageFormat pageFormat,

                           int pageIndex) throws PrinterException {

                      dataPrint4.g=graphics;

                        if (pageIndex < 1) {

                            g3 = (Graphics2D)g;

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

                            printa1();

                          return Printable.PAGE_EXISTS;

                      } else {

                          return Printable.NO_SUCH_PAGE;

                     }

                   }

                });

             try {

                   job.print();

               } catch (Exception e1) {

                    e1.printStackTrace();

              }

              }

      }

     });

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

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

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

        panel.add(previewButton1);

    }

 

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

    previewButton2.addActionListener(new ActionListener() {

         public void actionPerformed(ActionEvent e) {

          打印相同记录=1;

              if (行号<0) {

                 JOptionPane.showMessageDialog( null, "未在表格中选择某条记录,请重新操作!");

                 return;

               }

               else {

                job = PrinterJob.getPrinterJob();

                  if (!job.printDialog())

                      return;

                  job.setPrintable(new Printable() {

                      public int print(Graphics graphics, PageFormat pageFormat,

                              int pageIndex) throws PrinterException {

                         g=graphics;

                       if (pageIndex < 1) {

                               g3 = (Graphics2D)g;

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

                              printa1();

                                return Printable.PAGE_EXISTS;

                         } else {

                             return Printable.NO_SUCH_PAGE;

                        }

                      }

                   });

                  try {

                     job.print();

                    } catch (Exception e1) {

                      e1.printStackTrace();

                  }

               }

          }

     });

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

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

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

        panel.add(previewButton2);

    }

 

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

    exitButton.addActionListener(new ActionListener() {

         public void actionPerformed(ActionEvent e) {

         if ((sw[2].length()>0)&&(sw[3].length()>0)&&(sw[4].length()>0))

           WorkflowDrivek1.means(sw);

           panel.setVisible(false);

          frame.setVisible(false);

          frame.dispose();

         }

     });

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

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

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

        panel.add(exitButton);

    }

    frame.setVisible(true);   

    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

   }

   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);

           rsmd4 = rs.getMetaData();

           列数 = rsmd4.getColumnCount();

           列名 = new String[列数];

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

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

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

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

           }

           rs.close();

           stat4.close();

           cont4.close();

        } catch (SQLException e1) {

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

        }

     } else { // 多表

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

        String  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);

             rsmd4 = rs.getMetaData();

             列数 = rsmd4.getColumnCount();

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

                s2 = rsmd4.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);

        rsmd4 = rs.getMetaData();

        列数 = rsmd4.getColumnCount();

        列名 = new String[列数];

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

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

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

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

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

           列数据宽度[i1] = rsmd4.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

95.源码95,部件程序,设计与生成打印数据库中表单式标签报表格式文件。表单式标签指多个结构相同的表单打印在同一打印纸上,结构重复,内容可以根据记录变化,可以全相同。表单可包括文本文件与图形文件。前者例如人事卡片、商品标签,后者例如名片、广告卡片。

/*

 * 程序文件名:printFormat7.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.DatabaseMetaData;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

 

public class printFormat7 extends JFrame {

   private static printFormat7 frame2 = new printFormat7();

   private static JPanel panel2 = new JPanel();

   private static DefaultTableModel variabl19652;

   private static JTable variabl26552;

   private static JScrollPane scrollPane2 = new JScrollPane();

   private static List list2 = new List();

   private static JLabel fl0, fl10, fla1, fla2, fla3, fla4, fla5, fla6, fla7,

        fla8, fla9, fla10, fla11, fla12, fla13, fla14, fla15;

  private static JTextField fa0, fa10, faa1, faa2, faa3, faa4, faa5, faa6,

        faa7, faa8, faa9, faa10, faa11, faa12, faa13, faa14, faa15;

   private static JButton structureButton1;

   private static String variabl2327;

   private static int variabl1739 = 0, variabl2651 = 0;

   private static int variabl2127 = 0;

   private static String[][] variabl2197;

   private static String[] variabl1905;

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

     frame2 = new printFormat7();

     panel2 = new JPanel();

     scrollPane2 = new JScrollPane();

     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";

     frame2.setTitle("单记录标签式报表格式文件设计页。                                                                                                                                                                                                                                                                                       作者:程学先");

     frame2.setBounds(10, 10, 980, 660);

      frame2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

     panel2.setBounds(10, 10, 980, 660);

     panel2.setLayout(null);

     String[] variabl251702 = { "标签内容", "字段名称", "行号", "列号", "标签宽", "字段宽",

           "高度", "左边距", "到顶距", "字体", "字号" };

     main1.driver1();

     String variabl2603 = parameter[4];

     数据表查询结构(variabl2603);

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

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

     panel2.add(fl0);

     fa0 = new JTextField("");

     fa0.setText(variabl2603);

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

     panel2.add(fa0);

     fa0.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 0;

           list2.removeAll();

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

             list2.add(variabl26031[i]);

        }

     });

 

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

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

     panel2.add(fl10);

     fa10 = new JTextField("", 20);

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

     panel2.add(fa10);

     fa10.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {

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

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

             fc.showOpenDialog(null);

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

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

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

                try {

                   if (file1.exists()) {

                      FileReader fr = new FileReader(file1);

                      BufferedReader br = new BufferedReader(fr);

                      String tempStr = null;

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

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

                           variabl19652.addRow(tempStr.substring(

                                2, tempStr.length()).split(""));

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

                              "2,")) {

                           variabl1905 = (tempStr.substring(2,

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

                        }

                      }

                   }

                } catch (IOException e2) {

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

                }

                faa10.setEnabled(true);

                faa13.setEnabled(true);

                faa14.setEnabled(true);

                faa15.setEnabled(true);

                structureButton1.setEnabled(true);

             }

           }

        }

     });

 

     variabl19652 = new DefaultTableModel(variabl2197, variabl251702);

     variabl26552 = new JTable(variabl19652);

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

     scrollPane2.setViewportView(variabl26552);

     panel2.add(scrollPane2, BorderLayout.CENTER);

     fla1 = new JLabel("标签内容");

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

     panel2.add(fla1);

     faa1 = new JTextField("", 20);

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

     panel2.add(faa1);

     faa1.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 1;

           list2.removeAll();

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

             list2.add(variabl25171[i]);

           }

        }

     });

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

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

     panel2.add(fla2);

     faa2 = new JTextField("", 20);

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

     panel2.add(faa2);

     faa2.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 2;

           list2.removeAll();

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

             list2.add(variabl25171[i]);

           }

        }

     });

 

     fla11 = new JLabel("行号");

     fla11.setBounds(340, 460, 40, 20);

     panel2.add(fla11);

     faa11 = new JTextField("", 20);

     faa11.setBounds(380, 460, 60, 20);

     panel2.add(faa11);

     faa11.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 11;

           list2.removeAll();

        }

     });

 

     fla12 = new JLabel("列号");

     fla12.setBounds(440, 460, 40, 20);

     panel2.add(fla12);

     faa12 = new JTextField("", 20);

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

     panel2.add(faa12);

     faa12.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 12;

           list2.removeAll();

        }

     });

 

     fla3 = new JLabel("标签宽度");

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

     panel2.add(fla3);

     faa3 = new JTextField("", 20);

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

     panel2.add(faa3);

     faa3.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 3;

           list2.removeAll();

        }

     });

 

     fla4 = new JLabel("字段宽度");

     fla4.setBounds(680, 460, 60, 20);

     panel2.add(fla4);

     faa4 = new JTextField("", 20);

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

     panel2.add(faa4);

     faa4.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 4;

           list2.removeAll();

        }

     });

 

     fla5 = new JLabel("高度");

     fla5.setBounds(20, 500, 60, 20);

     panel2.add(fla5);

     faa5 = new JTextField("", 20);

     faa5.setBounds(80, 500, 100, 20);

     panel2.add(faa5);

     faa5.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 5;

           list2.removeAll();

        }

     });

 

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

     fla6.setBounds(200, 500, 40, 20);

     panel2.add(fla6);

     faa6 = new JTextField("", 20);

     faa6.setBounds(240, 500, 80, 20);

     panel2.add(faa6);

     faa6.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 6;

           list2.removeAll();

        }

     });

 

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

     fla7.setBounds(340, 500, 40, 20);

     panel2.add(fla7);

     faa7 = new JTextField("", 20);

     faa7.setBounds(380, 500, 80, 20);

     panel2.add(faa7);

     faa7.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 7;

           list2.removeAll();

        }

     });

 

     fla8 = new JLabel("字体");

     panel2.add(fla8);

     faa8 = new JTextField("", 20);

     panel2.add(faa8);

     fla8.setBounds(480, 500, 40, 20);

     faa8.setBounds(520, 500, 80, 20);

     faa8.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 8;

           list2.removeAll();

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

             list2.add(variabl2629[i]);

           }

        }

     });

 

     fla9 = new JLabel("字号");

     panel2.add(fla9);

     faa9 = new JTextField("", 20);

     panel2.add(faa9);

     fla9.setBounds(620, 500, 40, 20);

     faa9.setBounds(660, 500, 80, 20);

     faa9.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 9;

           list2.removeAll();

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

             list2.add(variabl2607[i]);

           }

        }

     });

 

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

     panel2.add(fla10);

     faa10 = new JTextField("", 20);

     panel2.add(faa10);

     fla10.setBounds(20, 540, 100, 20);

     faa10.setBounds(120, 540, 60, 20);

     faa10.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 10;

           list2.removeAll();

        }

     });

 

     fla13 = new JLabel("列模块间距");

     panel2.add(fla13);

     faa13 = new JTextField("", 20);

     panel2.add(faa13);

     fla13.setBounds(180, 540, 80, 20);

     faa13.setBounds(260, 540, 60, 20);

     faa13.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 13;

           list2.removeAll();

        }

     });

 

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

     panel2.add(fla14);

     faa14 = new JTextField("", 20);

     panel2.add(faa14);

     fla14.setBounds(320, 540, 100, 20);

     faa14.setBounds(420, 540, 60, 20);

     faa14.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 14;

           list2.removeAll();

        }

     });

 

     fla15 = new JLabel("行模块间距");

     panel2.add(fla15);

     faa15 = new JTextField("", 20);

     panel2.add(faa15);

     fla15.setBounds(480, 540, 80, 20);

     faa15.setBounds(560, 540, 60, 20);

     faa15.addFocusListener(new FocusAdapter() {

        public void focusGained(final FocusEvent arg0) {

           variabl1739 = 15;

           list2.removeAll();

        }

     });

     faa1.setText("");

     faa2.setText("");

     faa3.setText("0");

     faa4.setText("0");

     faa5.setText("0");

     faa6.setText("0");

     faa7.setText("0");

     faa8.setText("宋体");

     faa9.setText("0");

     faa10.setText("0");

     faa11.setText("0");

     faa12.setText("0");

     faa13.setText("5");

     faa14.setText("0");

     faa15.setText("5");

     faa10.setEnabled(false);

     faa13.setEnabled(false);

     faa14.setEnabled(false);

     faa15.setEnabled(false);

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

     panel2.add(list2);

     list2.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {

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

             int w1, w2, h1, h2;

             String s0 = "";

             switch (variabl1739) {

             case 0:

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

                   s0 = list2.getSelectedItem();

                else

                   s0 = fa0.getText() + "," + list2.getSelectedItem();

                fa0.setText(s0);

                数据表查询结构(s0);

                break;

             case 1:

                faa1.setText(list2.getSelectedItem());

                faa2.setText(list2.getSelectedItem());

                variabl2127 = list2.getSelectedIndex();

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

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

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

                   faa3.setText(""

                        + variabl25171[variabl2127].length());

                   faa5.setText("1");

                }

                faa8.setText("宋体");

                faa9.setText("12");

                break;

             case 2:

                faa2.setText(list2.getSelectedItem());

                break;

             case 3:

                faa3.setText(list2.getSelectedItem());

                break;

             case 4:

                faa4.setText(list2.getSelectedItem());

                break;

             case 5:

                faa5.setText(list2.getSelectedItem());

                break;

             case 6:

                faa6.setText(list2.getSelectedItem());

                break;

             case 7:

                faa7.setText(list2.getSelectedItem());

                break;

             case 8:

                faa8.setText(list2.getSelectedItem());

                break;

             case 9:

                faa9.setText(list2.getSelectedItem());

                break;

             case 11:

                faa11.setText(list2.getSelectedItem());

                break;

             case 12:

                faa12.setText(list2.getSelectedItem());

                break;

             }

           }

        }

     });

 

     variabl26552.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {

           int variabl1823 = variabl26552.getSelectedRow();

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

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

                variabl2327 = variabl19652.getValueAt(variabl1823, j)

                      .toString();

             else

                variabl2327 = "";

             switch (j) {

             case 0:

                faa1.setText(variabl2327.toString());

                break;

             case 2:

                faa11.setText(variabl2327.toString());

                break;

             case 3:

                faa12.setText(variabl2327.toString());

                break;

             case 1:

                faa2.setText(variabl2327.toString());

                break;

             case 4:

                faa3.setText(variabl2327.toString());

                break;

             case 5:

                faa4.setText(variabl2327.toString());

                break;

             case 6:

                faa5.setText(variabl2327.toString());

                break;

             case 7:

                faa6.setText(variabl2327.toString());

                break;

             case 8:

                faa7.setText(variabl2327.toString());

                break;

             case 9:

                faa8.setText(variabl2327.toString());

                break;

             case 10:

                faa9.setText(variabl2327.toString());

                break;

             }

           }

        }

     });

 

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

     addButton1.setBounds(20, 580, 120, 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 < variabl19652.getRowCount(); i++) {

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

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

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

                variabl1823 = i;

                break;

             }

           }

           if (variabl1823 < 0) {

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

                   faa11.getText(), faa12.getText(), faa3.getText(),

                   faa4.getText(), faa5.getText(), faa6.getText(),

                   faa7.getText(), faa8.getText(), faa9.getText() };

             variabl19652.addRow(rowValues);

             faa1.setText("");

             faa2.setText("");

             faa3.setText("0");

             faa4.setText("0");

             faa5.setText("0");

             faa6.setText("0");

             faa7.setText("0");

             faa8.setText("宋体");

             faa9.setText("0");

             faa10.setText("0");

             faa11.setText("0");

             faa12.setText("0");

              faa13.setText("5");

             faa14.setText("0");

             faa15.setText("5");

           } else

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

        }

     });

     panel2.add(addButton1);

 

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

     updButton1.setBounds(140, 580, 120, 20);

     updButton1.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(faa1.getText().trim()))) {

                variabl1823 = i;

                break;

             }

           }

           if (variabl1823 >= 0) {

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

             variabl19652.setValueAt(faa11.getText(), variabl1823, 2);

             variabl19652.setValueAt(faa12.getText(), variabl1823, 3);

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

             variabl19652.setValueAt(faa3.getText(), variabl1823, 4);

             variabl19652.setValueAt(faa4.getText(), variabl1823, 5);

             variabl19652.setValueAt(faa5.getText(), variabl1823, 6);

             variabl19652.setValueAt(faa6.getText(), variabl1823, 7);

             variabl19652.setValueAt(faa7.getText(), variabl1823, 8);

             variabl19652.setValueAt(faa8.getText(), variabl1823, 9);

             variabl19652.setValueAt(faa9.getText(), variabl1823, 10);

           } else

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

        }

     });

     panel2.add(updButton1);

 

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

     delButton1.setBounds(260, 580, 120, 20);

     delButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           int variabl1823 = variabl26552.getSelectedRow();

           if (variabl1823 != -1)

             variabl19652.removeRow(variabl1823);

        }

     });

     panel2.add(delButton1);

 

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

     countButton1.setBounds(380, 580, 100, 20);

     countButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           String[] variabl1919 = new String[11];

           int variabl2707 = 0, variabl2705 = 0, variabl2703 = 0;

           int variabl2243 = 0;

           int[] variabl13611 = new int[150];

           int[] variabl13612 = new int[150];

           int variabl2027 = 0;

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

             variabl2703 = Integer.valueOf(variabl19652.getValueAt(i, 3)

                   .toString());

             if ((variabl2703 == 1)

                   && (Integer.valueOf(variabl19652.getValueAt(i, 4)

                        .toString()) > variabl2027))

                variabl2027 = Integer.valueOf(variabl19652.getValueAt(

                      i, 4).toString());

           }

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

             if (Integer.valueOf(variabl19652.getValueAt(i, 3)

                   .toString()) == 1) {

               variabl19652.setValueAt("" + variabl2027, i, 4);

             }

           }

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

             variabl2707 = Integer.valueOf(variabl19652.getValueAt(i, 6)

                   .toString());

             variabl2705 = Integer.valueOf(variabl19652.getValueAt(i, 2)

                   .toString());

             variabl2703 = Integer.valueOf(variabl19652.getValueAt(i, 3)

                   .toString());

             if (variabl2705 > variabl2243)

                variabl2243 = variabl2705;

             if (variabl2707 > 1) {

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

                   variabl1919[j] = variabl19652.getValueAt(i, j)

                        .toString();

                if ((variabl2703 == 1)

                      || (variabl2703 == 2 && variabl13611[variabl2705] == 1)) {

                   if (variabl13611[variabl2705] == 0)

                      variabl13611[variabl2705] = 1;

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

                      variabl1919[3] = "0";

                      variabl1919[2] = (variabl2705 + j) + "";

                      if (variabl2705 + j > variabl2243)

                        variabl2243 = variabl2705 + j;

                      variabl1919[6] = "1";

                      variabl19652.addRow(variabl1919);

                   }

                } else {

                   if (variabl13611[variabl2705] == 0)

                      variabl13611[variabl2705] = variabl2705 + 1;

                   variabl13612[variabl2705] = variabl2707;

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

                      variabl1919[3] = "98";

                      variabl1919[2] = (variabl2705 + j) + "";

                      variabl13612[variabl2705 + j] = variabl2707;

                      if (variabl2705 + j > variabl2243)

                        variabl2243 = variabl2705 + j;

                      variabl1919[6] = "1";

                      variabl19652.addRow(variabl1919);

                   }

                }

             }

           }

           int variabl2059 = variabl19652.getRowCount();

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

           int[][] variabl26491 = new int[variabl2059][15];

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

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

                if (variabl19652.getValueAt(i, j) != null) {

                   variabl2649[i][j - 1] = variabl19652.getValueAt(i,

                        j).toString();

                } else

                   variabl2649[i][j - 1] = "0";

                if (variabl19652.getValueAt(i, 0) == null)

                   variabl2649[i][12] = " ";

                else

                   variabl2649[i][12] = variabl19652.getValueAt(i, 0)

                        .toString();

                s2 = variabl2649[i][j - 1].trim();

                if ((j > 1) && (j < 9) || (j == 10))

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

                      variabl26491[i][j - 1] = 0;

                   else

                      variabl26491[i][j - 1] = Integer.valueOf(s2);

             }

             variabl2649[i][11] = "" + i;

             variabl26491[i][11] = i;

           }

           String trim = "";

           int trim1 = 0;

           for (int i = 0; i < variabl2059 - 1; i++) {

             for (int j = 0; j < variabl2059 - 1 - i; j++) {

                if (variabl26491[j][1] * 100 + variabl26491[j][2] > variabl26491[j + 1][1]

                      * 100 + variabl26491[j + 1][2]) {

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

                      trim = variabl2649[j][k];

                      trim1 = variabl26491[j][k];

                      variabl2649[j][k] = variabl2649[j + 1][k];

                      variabl26491[j][k] = variabl26491[j + 1][k];

                      variabl2649[j + 1][k] = trim;

                      variabl26491[j + 1][k] = trim1;

                   }

                }

             }

           }

           int[] variabl1341 = new int[variabl2243 + 1];

           int[] variabl1471 = new int[variabl2243 + 1];

           int[] variabl1063 = new int[variabl26491.length];

           int kuand = 0;

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

             variabl2705 = variabl26491[i][1];

             variabl2703 = variabl26491[i][2];

             if (variabl13612[variabl2705] > 0) {

               if ((variabl2703 < 98) && (variabl26491[i][5] < 2)) {

                   if (variabl2703 > variabl1341[variabl2705]) {

                      variabl1341[variabl2705] = variabl2703;

                      variabl1063[variabl2705] = i + 1;

                   }

                   variabl1471[variabl2705] = variabl1471[variabl2705]

                        + variabl26491[i][3] + variabl26491[i][4];

                   if (variabl1471[variabl2705] > kuand)

                      kuand = variabl1471[variabl2705];

                }

             }

           }

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

             variabl2705 = variabl26491[i][1];

             variabl2703 = variabl26491[i][2];

             if (variabl13612[variabl2705] > 0) {

                for (int k1 = 1; k1 <= variabl2243; k1++) {

                   if ((variabl1063[k1] > 0)

                        && (variabl1063[k1] == i + 1)) {

                      variabl26491[i][4] = variabl26491[i][4] + kuand

                           - variabl1471[k1];

                      break;

                   }

                }

             }

           }

           variabl1341 = new int[variabl2243 + 1];

           variabl1471 = new int[variabl2243 + 1];

           variabl1063 = new int[variabl26491.length];

           kuand = 0;

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

             variabl2705 = variabl26491[i][1];

             variabl2703 = variabl26491[i][2];

             if (variabl2703 >= variabl1341[variabl2705]) {

                variabl1341[variabl2705] = variabl2703;

                variabl1063[variabl2705] = i + 1;

             }

             variabl1471[variabl2705] = variabl1471[variabl2705]

                   + variabl26491[i][3] + variabl26491[i][4];

             if (variabl1471[variabl2705] > kuand)

                kuand = variabl1471[variabl2705];

          }

           for (int k1 = 0; k1 <= variabl2243; k1++) {

             int k3 = variabl1063[k1];

             if (k3 > 0) {

                k3 = k3 - 1;

                variabl26491[k3][4] = variabl26491[k3][4] + kuand

                      - variabl1471[k1];

             }

           }

           int m1 = 0;

           variabl2705 = 0;

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

             if (variabl26491[i][1] != variabl2705) {

                variabl2705 = variabl26491[i][1];

                m1 = 0;

             }

             variabl26491[i][6] = m1;

             m1 = m1 + variabl26491[i][3] + variabl26491[i][4];

             variabl26491[i][7] = variabl26491[i][1] - 1;

           }

           variabl19652.setRowCount(0);

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

             if ((variabl26491[i][2] > 0) && (variabl26491[i][2] < 98)) {

                variabl2649[i][1] = variabl26491[i][1] + "";

                variabl2649[i][2] = variabl26491[i][2] + "";

                variabl2649[i][3] = variabl26491[i][3]

                      * variabl26491[i][9] + "";

                variabl2649[i][4] = variabl26491[i][4]

                      * variabl26491[i][9] + "";

                variabl2649[i][5] = (int) (variabl26491[i][5]

                      * variabl26491[i][9] * 2)

                      + "";

                variabl2649[i][6] = variabl26491[i][6]

                      * variabl26491[i][9] + "";

                variabl2649[i][7] = (int) (variabl26491[i][7]

                      * variabl26491[i][9] * 2)

                      + "";

             }

           }

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

             if ((variabl26491[i][2] > 0) && (variabl26491[i][2] < 98)) {

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

                   variabl1919[j] = variabl2649[i][j - 1];

                }

                variabl1919[0] = variabl2649[i][12];

                variabl19652.addRow(variabl1919);

             }

           }

           faa10.setEnabled(true);

           faa13.setEnabled(true);

           faa14.setEnabled(true);

           faa15.setEnabled(true);

           structureButton1.setEnabled(true);

        }

     });

     panel2.add(countButton1);

 

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

     clearButton1.setBounds(480, 580, 120, 20);

     clearButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           faa1.setText("");

           faa2.setText("");

           faa3.setText("0");

           faa4.setText("0");

           faa5.setText("0");

           faa6.setText("0");

           faa7.setText("0");

           faa8.setText("宋体");

           faa9.setText("0");

           faa10.setText("0");

           faa11.setText("0");

           faa12.setText("0");

           faa13.setText("5");

           faa14.setText("0");

           faa15.setText("5");

        }

     });

     panel2.add(clearButton1);

 

     structureButton1 = new JButton("标签结构设计");

     structureButton1.setBounds(600, 580, 120, 20);

     structureButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           int variabl2083 = Integer.valueOf(faa10.getText());

           int variabl2219 = Integer.valueOf(faa13.getText());

           int variabl1863 = Integer.valueOf(faa14.getText());

           int variabl2133 = Integer.valueOf(faa15.getText());

           int 模块宽度 = 0;

           int 模块高度 = 0;

           String[][] variabl2595 = new String[variabl19652.getRowCount()][11];

           int variabl24410 = 0;

           int[][] variabl2009 = new int[variabl19652.getRowCount()][11];

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

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

                variabl2595[i][j] = variabl19652.getValueAt(i, j)

                      .toString();

                if ("019".lastIndexOf("" + j) < 0)

                   variabl2009[i][j] = Integer

                        .valueOf(variabl2595[i][j]);

             }

           }

           int variabl2337 = 0;

           int variabl23370 = 0;

           int variabl2441 = 0;

           String[] variabl2615 = new String[11];

           for (int k1 = 0; k1 < variabl1863; k1++) {

             for (int k2 = 0; k2 < variabl2083; k2++) {

                if ((k1 == 0) && (k2 == 0)) {

                   for (int k3 = 0; k3 < variabl19652.getRowCount(); k3++) {

                      if ((variabl2009[k3][7] + variabl2009[k3][4] + variabl2009[k3][5]) > 模块宽度)

                        模块宽度 = variabl2009[k3][7]

                              + variabl2009[k3][4]

                              + variabl2009[k3][5];

                      if ((variabl2009[k3][8] + variabl2009[k3][6]) > 模块高度)

                        模块高度 = variabl2009[k3][8]

                              + variabl2009[k3][6];

                   }

                   continue;

                }

                if ((k1 == 0) && (k2 == 1)) {

                   variabl2441 = 0;

                   variabl2337 = 模块宽度 + variabl2219;

                } else if ((k1 == 1) && (k2 == variabl2083 - 1)) {

 

                }

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

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

                      if (j == 7)

                        variabl2615[j] = ""

                              + (variabl2009[i][j] + variabl2337);

                      else if (j == 8)

                        variabl2615[j] = ""

                              + (variabl2009[i][j] + variabl2441);

                      else

                        variabl2615[j] = variabl2595[i][j];

                   }

                   variabl19652.addRow(variabl2615);

                }

                variabl2337 = variabl2337 + variabl2219 + 模块宽度;

             }

             variabl2441 = variabl2441 + variabl2133 + 模块高度;

             variabl2337 = 0;

           }

        }

     });

     structureButton1.setEnabled(false);

     panel2.add(structureButton1);

 

     final JButton saveButton1 = new JButton("保存到文件");

     saveButton1.setBounds(720, 580, 120, 20);

     saveButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           char x1 = 10;

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

           FileOutputStream fs;

           try {

             fs = new FileOutputStream(file1);

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

                String s3 = "1,";

                for (int j = 0; j < 11; 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.write(("2," + faa10.getText() + "").getBytes());

             fs.write((faa13.getText() + "").getBytes());

             fs.write((faa14.getText() + "").getBytes());

             fs.write((faa15.getText() + " " + x1).getBytes());

             fs.close();

           } catch (IOException e2) {

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

           }

        }

     });

     panel2.add(saveButton1);

 

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

     exitButton1.setBounds(840, 580, 110, 20);

     exitButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           panel2.setVisible(false);

           frame2.setVisible(false);

           frame2.dispose();

        }

     });

     panel2.add(exitButton1);

     frame2.add(panel2);

     frame2.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, "读取数据库数据出错!");

     }

   }

}

 

 

96.源码96,部件程序,表单式标签报表打印预览程序。根据单表或多表的内容按照printFormat7.java程序生成的打印格式文件打印预览。

/**

 * 程序文件名:dataPreview4.java

 * 完成时间:20131127

 * 部件功能:表单式标签报表打印预览程序。

 * 根据单表或多表的内容按照printFormat7.java程序生成的打印格式文件打印预览。

 */

 

import java.awt.*;

import java.awt.event.*;

import java.awt.font.FontRenderContext;

import java.awt.font.TextLayout;

import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;

import javax.swing.*;

import javax.swing.table.*;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.IOException;

import java.io.InputStream;

import java.sql.*;

import java.util.ArrayList;

 

public class dataPreview4 extends JFrame {

   static dataPreview4 frame = new dataPreview4();

   static String variabl2603 = "";

   static DefaultTableModel tableModel;

   static JTable table;

   static JScrollPane scrollPane = new JScrollPane();

   static JScrollPane scrollPane1;

   static JTextField aTextField;

   static JButton previewButton2;

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

   static ResultSet rs;

   static int variabl2651;

   static String[] variabl2517;

   static String[] variabl1501;

   static int[] variabl1489;

   static int[] variabl1119;

   static int variabl1853, variabl2593 = -1;

   static String[][] variabl2197;

   static String variabl1079;

   private static ArrayList<struct3> table1 = null;

   private static ArrayList<struct4> table2 = null;

   static Connection cont4;

   static ResultSetMetaData rsmd4;

   static Statement stat4;

   static int variabl2483 = 1400, variabl2503 = 600, variabl2681 = 600;

   private static Graphics2D g3;

   private static Graphics g;

   private static Font font;

   private static TextLayout layout;

   private static int variabl1139 = 0;

   static String[] variabl2405 = null;

   static String variabl1187;

   static int variabl2851 = 0, variabl2339 = 0;

   private static int variabl1441 = 0, variabl1703 = 0, variabl1599 = 0,

        variabl2155 = 0;

   private static int kuand = 0, gaod = 0;

   static String[][] variabl21970;

   private static String variabl2049 = "";

   private static String variabl1633 = "";

   private static struct3[] variabl2685 = null;

   private static struct4[] variabl2533 = null;

   private static int[] w10 = null, w20 = null, h10 = null, h20 = null;

   private static int[] t10 = null, l10 = null, le0 = null, f0 = null;

   private static int w01 = 0, w02 = 0, h01 = 0, l01 = 0, le01 = 0, le02 = 0;

   private static int w2 = 0, variabl2631 = 0, variabl2623 = 0;

 

   static void print1() {

     g3 = (Graphics2D) g;

     variabl2685 = new struct3[table1.size()];

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

        if (variabl2593 >= variabl1853)

           return;

        variabl2685[i] = table1.get(i);

        w10[i] = Integer.valueOf(variabl2685[i].table1[4]);

        w20[i] = Integer.valueOf(variabl2685[i].table1[5]);

        h10[i] = Integer.valueOf(variabl2685[i].table1[6]);

        h20[i] = Integer.valueOf(variabl2685[i].table1[10]);

        t10[i] = Integer.valueOf(variabl2685[i].table1[8]);

        l10[i] = Integer.valueOf(variabl2685[i].table1[2]);

        le0[i] = Integer.valueOf(variabl2685[i].table1[7]);

        if (variabl2685[i].table1[1].indexOf(".") > 0)

           variabl2685[i].table1[1] = variabl2685[i].table1[1]

                .substring(variabl2685[i].table1[1].indexOf(".") + 1);

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

           if (variabl2517[j].indexOf(".") > 0)

             variabl2517[j] = variabl2517[j].substring(variabl2517[j]

                   .indexOf(".") + 1);

           if (variabl2517[j].equalsIgnoreCase(variabl2685[i].table1[1])) {

             f0[i] = j;

             break;

           }

        }

     }

 

     FontRenderContext frc = new FontRenderContext(null, false, false);

     char p1 = 10, p2 = 13;

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

     int variabl2661 = 40, variabl2657 = 50, variabl26610 = 40, variabl2631 = 0;

     if (variabl2593 < 0)

        variabl2593 = 0;

     y1 = variabl2657;

     x1 = variabl2661;

     int variabl2461 = 0;

     int k = 0;

     for (int l = 0; l < variabl1599; l++) {

        for (int i1 = 0; i1 < variabl1441; i1++) {

           variabl2461 = variabl2657;

           if ((variabl1139 > 0) && ((i1 > 0) || (l > 0)))

             variabl2593++;

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

             x1 = le0[i] + variabl2661;

             y1 = t10[i] + variabl2657;

             w1 = w10[i];

             w2 = w20[i];

             h1 = h10[i];

             if (l10[i] == 1) {

                g3.drawLine(x1, y1, x1 + w1 + w2, y1);

             }

             if (variabl2593 >= variabl1853)

                return;

             g3.drawLine(x1, y1, x1, y1 + h1);

            g3.setFont(new Font(variabl2685[i].table1[9], Font.PLAIN,

                   Integer.valueOf(variabl2685[i].table1[10])));

             g3.drawLine(x1 + w10[i], y1, x1 + w1, y1 + h1);

             if (variabl2197[variabl2593][f0[i]] == null)

                variabl2197[variabl2593][f0[i]] = " ";

             font = new Font(variabl2685[i].table1[9], Font.PLAIN,

                   Integer.valueOf(variabl2685[i].table1[10]));

             g3.setFont(font);

             g3.drawString(variabl2685[i].table1[0], x1 + 2, y1 + h20[i]);

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

                   .lastIndexOf("," + variabl1501[i] + ",") >= 0)

                   || (h1 > h20[i] * 2)) {

                if (variabl2593 >= variabl1853)

                   return;

                if (main1.variabl1539.indexOf("," + variabl1501[i]

                      + ",") >= 0) {

                   x1 = le0[i] + variabl2661;

                   y1 = t10[i] + variabl2657;

                   w2 = w20[i];

                   h1 = h10[i];

                   try {

                      cont4 = main1.getConn();

                      stat4 = cont4.createStatement(

                           ResultSet.TYPE_SCROLL_INSENSITIVE,

                           ResultSet.CONCUR_UPDATABLE);

                      String sql = "select " + variabl2517[i]

                           + " from " + variabl2603;

                      if (variabl2603.indexOf(",") > 0)

                        s1 = s1 + variabl2049;

                      rs = stat4.executeQuery(sql);

                      rs.absolute(variabl2593 + 1);

                      InputStream image = rs

                           .getBinaryStream(variabl2517[i]);

                      String image0 = image.toString();

                      long length = image0.length();

                      byte[] buffer = new byte[(int) length / 7];

                      File file = new File("a1.jpg");

                      int ch = 0;

                      if (file.exists()) {

                        file.delete();

                      }

                      file.createNewFile();

                      FileOutputStream file1 = new FileOutputStream(

                           file, true);

                      boolean go = true;

                      while (go) {

                        while ((ch = image.read(buffer)) != -1) {

                           file1.write(buffer);

                        }

                        go = false;

                      }

                      BufferedImage image1 = ImageIO.read(file);

                      g.drawImage(image1, x1 + w1 + 2, y1, w2, h1,

                           null);

                      rs.close();

                     file1.close();

                      stat4.close();

                      cont4.close();

                   } catch (Exception e) {

                      e.printStackTrace();

                   }

                } else {

                   int j = 0;

                   y2 = y1;

                   float j1 = 0f;

                   s2 = variabl2197[variabl2593][f0[i]];

                   s3 = "";

                   if ((s2.lastIndexOf("" + p1) < s2.length())

                        && (s2.lastIndexOf("" + p1) > 0))

                      s2 = s2 + p1;

                   for (k = 0; k < s2.length(); k++) {

                      if ((j1 < w2)

                           && (!s2.substring(k, k + 1)

                                .equalsIgnoreCase("" + p1))

                           && (!s2.substring(k, k + 1)

                                .equalsIgnoreCase("" + p2))

                           && (k != s2.length() - 1)) {

                        s3 = s3 + s2.substring(k, k + 1);

                        if (s2.substring(k, k + 1).compareTo("z") < 0) {

                           if (s2.substring(k, k + 1).compareTo(

                                "0") < 0)

                              j1 = j1 + h20[i] * 0.43f;

                           else

                              j1 = j1 + h20[i] * 0.64f;

                        } else

                           j1 = j1 + h20[i];

                      } else {

                        if (j1 >= w2)

                           s3 = s3 + s2.substring(k, k + 1);

                        j = j + h20[i];

                        if (j1 >= w2 - 2) {

                           layout = new TextLayout(s3, font, frc)

                                .getJustifiedLayout(w2 - 2);

                           layout.draw(g3, x1 + w1 + 2, y2

                                + h20[i]);

                        } else {

                           g3.drawString(s3, x1 + w1 + 2, y2

                                + h20[i]);

                        }

                        y2 = y2 + h20[i] + 5;

                        s3 = "";

                        j1 = 0;

                      }

                      if (j >= h1)

                        break;

                   }

                }

             } else {

                g3.drawString(variabl2197[variabl2593][f0[i]], x1 + w1

                      + 2, y1 + h20[i]);

             }

             g3.drawLine(x1, y1 + h1, x1 + w1 + w2, y1 + h1);

             if (y1 + h1 > variabl2631)

                variabl2631 = y1 + h1;

             if ((i < table1.size() - 1) && (f0[i + 1] == 0)) {

                g3.drawLine(x1 + w1 + w2, variabl2461, x1 + w1 + w2,

                      variabl2631);

             }

           }

           variabl2623 = variabl2661 + kuand;

           g3.drawLine(variabl2623, variabl2461, variabl2623, variabl2631);

           variabl2661 = variabl2661 + kuand + variabl1703;

           variabl2461 = variabl2657;

        }

        variabl2661 = variabl26610;

        variabl2657 = variabl2657 + gaod + variabl2155;

        variabl2461 = variabl2657;

     }

     if (variabl1139 > 0)

        variabl2593++;

   }

 

   public static void means(String[] parameter) {

     s1 = "";

     s2 = "";

     variabl1853 = 0;

     variabl2651 = 0;

      variabl2685 = null;

     variabl2533 = null;

     table1 = new ArrayList<struct3>();

     table2 = new ArrayList<struct4>();

     variabl2681 = 600;

     variabl1139 = 0;

     w2 = 0;

     variabl2631 = 0;

     variabl2623 = 0;

     variabl1441 = 0;

     variabl1703 = 0;

     variabl1599 = 0;

     variabl2155 = 0;

     kuand = 0;

     gaod = 0;

     frame = new dataPreview4();

     variabl2603 = "";

     scrollPane = new JScrollPane();

     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];

     variabl1079 = parameter[15];

     variabl2049 = parameter[20];

     File file1 = new File(variabl1079);

     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, "打开文件错!");

     }

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

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

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

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

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

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

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

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

     variabl2533 = new struct4[table2.size()];

     variabl2533[0] = table2.get(0);

     variabl1441 = Integer.valueOf(variabl2533[0].table2[0].trim());

     variabl1703 = Integer.valueOf(variabl2533[0].table2[1].trim());

     variabl1599 = Integer.valueOf(variabl2533[0].table2[2].trim());

     variabl2155 = Integer.valueOf(variabl2533[0].table2[3].trim());

     struct3[] variabl2685 = new struct3[table1.size()];

     w01 = 0;

     w02 = 0;

     h01 = 0;

     l01 = 0;

     le01 = 0;

     le02 = 0;

     le02 = Integer.valueOf(table1.get(0).table1[7]);

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

        variabl2685[i] = table1.get(i);

        w01 = Integer.valueOf(variabl2685[i].table1[4]);

        w02 = Integer.valueOf(variabl2685[i].table1[5]);

        h01 = Integer.valueOf(variabl2685[i].table1[6]);

        l01 = Integer.valueOf(variabl2685[i].table1[2]);

        le01 = Integer.valueOf(variabl2685[i].table1[7]);

        if (l01 == 1)

           kuand = kuand + w01 + w02;

        if (le01 == le02)

           gaod = gaod + h01;

     }

     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);

     frame.setLayout(null);

     frame.setTitle("单记录式报表预览程序         作者:程学先");

     frame.setBounds(10, 10, variabl2483 - 10, 1000);

     final JPanel panel = new JPanel();

     panel.setBounds(10, 10, variabl2483 - 50, 1000);

     panel.setLayout(null);

     frame.getContentPane().add(panel);

     tableModel = new DefaultTableModel(variabl2197, variabl2517);

     table = new JTable(tableModel);

      table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

     table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

     scrollPane.getViewport().add(table, null);

     scrollPane.setBounds(30, 50, variabl2483 - 100, variabl2503 - 150);

     panel.add(scrollPane);

     table.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {

           variabl2593 = table.getSelectedRow();

        }

     });

     int variabl2337 = 100;

     variabl2339 = (variabl2483 - variabl2337 - 30) / variabl2851;

     final JButton previewButton1 = new JButton(variabl2405[0]);

    previewButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           variabl1139 = 0;

           if (variabl2593 < 0) {

             JOptionPane.showMessageDialog(null, "未在表格中选择某条记录,请重新操作!");

             return;

           } else {

             panel.remove(scrollPane);

             g = panel.getGraphics();

             panel.paint(g);

             print1();

           }

        }

     });

    previewButton1.setBounds(variabl2337, 20, variabl2339, 20);

     if (variabl1187.indexOf(",0,") >= 0) {

        variabl2337 = variabl2337 + variabl2339;

        panel.add(previewButton1);

     }

 

     previewButton2 = new JButton(variabl2405[1]);

    previewButton2.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           variabl1139 = 1;

           if (variabl2593 < 0) {

             JOptionPane.showMessageDialog(null, "未在表格中选择某条记录,请重新操作!");

             return;

           } else {

             panel.remove(scrollPane);

             g = panel.getGraphics();

             panel.paint(g);

             print1();

           }

        }

     });

    previewButton2.setBounds(variabl2337, 20, variabl2339, 20);

     if (variabl1187.indexOf(",1,") >= 0) {

        variabl2337 = variabl2337 + variabl2339;

        panel.add(previewButton2);

     }

 

     final JButton exitButton = new JButton(variabl2405[2]);

     exitButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           panel.setVisible(false);

           frame.setVisible(false);

           frame.dispose();

        }

     });

     exitButton.setBounds(variabl2337, 20, variabl2339, 20);

     if (variabl1187.indexOf(",2,") >= 0) {

        variabl2337 = variabl2337 + variabl2339;

        panel.add(exitButton);

     }

     frame.setVisible(true);

      frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

   }

 

   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);

           rsmd4 = rs.getMetaData();

           variabl2651 = rsmd4.getColumnCount();

           variabl2517 = new String[variabl2651];

           variabl1501 = new String[variabl2651];

           variabl1489 = new int[variabl2651];

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

             variabl2517[i] = rsmd4.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);

             rsmd4 = rs.getMetaData();

             variabl2651 = rsmd4.getColumnCount();

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

                s2 = rsmd4.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);

        rsmd4 = rs.getMetaData();

        variabl2651 = rsmd4.getColumnCount();

        variabl2517 = new String[variabl2651];

        variabl1501 = new String[variabl2651];

        variabl1489 = new int[variabl2651];

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

           variabl2517[i1] = rsmd4.getColumnName(i1 + 1);

           variabl1501[i1] = rsmd4.getColumnTypeName(i1 + 1);

           variabl1489[i1] = rsmd4.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, "读取数据库数据出错!");

     }

   }

}

 

97.源码97,部件程序,表单式标签报表打印程序。根据单表或多表的内容按照printFormat7.java程序生成的打印格式文件打印报表。

/**

 * 程序文件名:dataPrint4.java

 * 作者:程学先

 * 完成时间:20131127

 * 部件功能:表单式标签报表打印程序。

 */

import java.awt.*;

import java.awt.event.*;

import java.awt.font.FontRenderContext;

import java.awt.font.TextLayout;

import java.awt.image.BufferedImage;

import java.awt.print.PageFormat;

import java.awt.print.Printable;

import java.awt.print.PrinterException;

import java.awt.print.PrinterJob;

import javax.imageio.ImageIO;

import javax.swing.*;

import javax.swing.table.*;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.IOException;

import java.io.InputStream;

import java.sql.*;

import java.util.ArrayList;

 

public class dataPrint4 extends JFrame {

   static dataPrint4 frame = new dataPrint4();

   static String variabl2603 = "";

   static DefaultTableModel tableModel;

   static JTable table;

   static JScrollPane scrollPane = new JScrollPane();

   static JScrollPane scrollPane1;

   static JTextField aTextField;

   static JButton previewButton2;

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

   static ResultSet rs;

   static int variabl2651;

   static String[] variabl2517;

   static String[] variabl1501;

   static int[] variabl1489;

   static int[] variabl1119;

   static int variabl1853, variabl2593 = -1;

   static String[][] variabl2197;

   static byte variabl2585[];

   static String variabl1079;

   private static ArrayList<struct1> title = new ArrayList<struct1>();

   private static ArrayList<struct2> tableTitle = new ArrayList<struct2>();

   static Connection cont4;

   static ResultSetMetaData rsmd4;

   static Statement stat4;

   static int variabl2483 = 1000, variabl2503 = 600, variabl2681 = 600;

   private static Graphics2D g3;

   private static Graphics g;

   private static Font font;

   private static TextLayout layout;

   public static String[] sw = new String[11];

   static String[] variabl2405 = null;

   static String variabl1187;

   static int variabl2851 = 0, variabl2339 = 0;

   private static int variabl1441 = 0, variabl1703 = 0, variabl1599 = 0,

        variabl2155 = 0;

   private static int variabl1139 = 0;

   private static int kuand = 0, gaod = 0;

   static String[][] variabl21970;

   private static String variabl2049 = "";

   private static String variabl1633 = "";

   private static int w2 = 0, variabl2631 = 0, variabl2623 = 0;

 

   static void print1() {

     g3 = (Graphics2D) g;

     struct1[] variabl2685 = new struct1[title.size()];

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

     int[] w20 = new int[title.size()];

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

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

     int[] t10 = new int[title.size()];

     int[] l10 = new int[title.size()];

     int[] le0 = new int[title.size()];

     int[] f0 = new int[title.size()];

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

        variabl2685[i] = title.get(i);

        w10[i] = Integer.valueOf(variabl2685[i].title[4]);

        w20[i] = Integer.valueOf(variabl2685[i].title[5]);

        h10[i] = Integer.valueOf(variabl2685[i].title[6]);

        h20[i] = Integer.valueOf(variabl2685[i].title[10]);

        t10[i] = Integer.valueOf(variabl2685[i].title[8]);

        l10[i] = Integer.valueOf(variabl2685[i].title[2]);

        le0[i] = Integer.valueOf(variabl2685[i].title[7]);

        if (variabl2685[i].title[1].indexOf(".") > 0)

           variabl2685[i].title[1] = variabl2685[i].title[1]

                .substring(variabl2685[i].title[1].indexOf(".") + 1);

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

           if (variabl2517[j].indexOf(".") > 0)

             variabl2517[j] = variabl2517[j].substring(variabl2517[j]

                   .indexOf(".") + 1);

           if (variabl2517[j].trim().equalsIgnoreCase(

                variabl2685[i].title[1].trim())) {

             f0[i] = j;

             break;

           }

        }

     }

     FontRenderContext frc = new FontRenderContext(null, false, false);

     char p1 = 10, p2 = 13;

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

     int variabl2661 = 40, variabl2657 = 50, variabl26610 = 40, variabl2631 = 0;

     if (variabl2593 < 0)

        variabl2593 = 0;

     y1 = variabl2657;

     x1 = variabl2661;

     int variabl2461 = 0;

     int k = 0;

     for (int l = 0; l < variabl1599; l++) {

        for (int i1 = 0; i1 < variabl1441; i1++) {

           variabl2461 = variabl2657;

           if ((variabl1139 > 0) && ((i1 > 0) || (l > 0)))

             variabl2593++;

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

             x1 = le0[i] + variabl2661;

             y1 = t10[i] + variabl2657;

             w1 = w10[i];

             w2 = w20[i];

             h1 = h10[i];

             if (l10[i] == 1) {

                g3.drawLine(x1, y1, x1 + w1 + w2, y1);

             }

             if (variabl2593 >= variabl1853)

                return;

             g3.drawLine(x1, y1, x1, y1 + h1);

             g3.setFont(new Font(variabl2685[i].title[9], Font.PLAIN,

                   Integer.valueOf(variabl2685[i].title[10])));

             g3.drawLine(x1 + w10[i], y1, x1 + w1, y1 + h1);

             if (variabl2197[variabl2593][f0[i]] == null)

                variabl2197[variabl2593][f0[i]] = " ";

             font = new Font(variabl2685[i].title[9], Font.PLAIN,

                   Integer.valueOf(variabl2685[i].title[10]));

             g3.setFont(font);

            g3.drawString(variabl2685[i].title[0], x1 + 2, y1 + h20[i]);

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

                   .lastIndexOf("," + variabl1501[i] + ",") >= 0)

                   || (h1 > h20[i] * 2)) {

                if (variabl2593 >= variabl1853)

                   return;

                if (main1.variabl1539.indexOf("," + variabl1501[i]

                      + ",") >= 0) {

                   x1 = le0[i] + variabl2661;

                   y1 = t10[i] + variabl2657;

                   w2 = w20[i];

                   h1 = h10[i];

                   try {

                      cont4 = main1.getConn();

                      stat4 = cont4.createStatement(

                           ResultSet.TYPE_SCROLL_INSENSITIVE,

                           ResultSet.CONCUR_UPDATABLE);

                      String sql = "select " + variabl2517[i]

                           + " from " + variabl2603;

                      if (variabl2603.indexOf(",") > 0)

                        sql = sql + " where " + variabl2049;

                      if ((sw[3].length() > 0)

                           && (sw[4].length() > 0))

                        if (sql.indexOf("where") > 0)

                           sql = sql + " and " + sw[4] + " = '"

                                + sw[5] + "'";

                        else

                           sql = sql + " where " + sw[4] + " = '"

                                + sw[5] + "'";

                      rs = stat4.executeQuery(sql);

                      rs.absolute(variabl2593 + 1);

                      InputStream image = rs

                           .getBinaryStream(variabl2517[i]);

                      String image0 = image.toString();

                      long length = image0.length();

                      byte[] buffer = new byte[(int) length / 7];

                      File file = new File("a1.jpg");

                      int ch = 0;

                      if (file.exists()) {

                        file.delete();

                      }

                      file.createNewFile();

                      FileOutputStream file1 = new FileOutputStream(

                           file, true);

                      boolean go = true;

                      while (go) {

                        while ((ch = image.read(buffer)) != -1) {

                           file1.write(buffer);

                        }

                        go = false;

                      }

                      BufferedImage image1 = ImageIO.read(file);

                      g.drawImage(image1, x1 + w1 + 2, y1, w2, h1,

                           null);

                      rs.close();

                      file1.close();

                      stat4.close();

                      cont4.close();

                   } catch (Exception e) {

                      e.printStackTrace();

                   }

                } else {

                   int j = 0;

                   y2 = y1;

                   float j1 = 0f;

                   s2 = variabl2197[variabl2593][f0[i]];

                   s3 = "";

                   if ((s2.lastIndexOf("" + p1) < s2.length())

                        && (s2.lastIndexOf("" + p1) > 0))

                      s2 = s2 + p1;

                   for (k = 0; k < s2.length(); k++) {

                      if ((j1 < w2)

                           && (!s2.substring(k, k + 1)

                                .equalsIgnoreCase("" + p1))

                           && (!s2.substring(k, k + 1)

                                .equalsIgnoreCase("" + p2))) {

                        s3 = s3 + s2.substring(k, k + 1);

                        if (s2.substring(k, k + 1).compareTo("z") < 0) {

                           if (s2.substring(k, k + 1).compareTo(

                                "0") < 0)

                              j1 = j1 + h20[i] * 0.37f;

                           else

                              j1 = j1 + h20[i] * 0.57f;

                        } else

                           j1 = j1 + h20[i];

                      } else {

                        j = j + h20[i];

                        if (j1 >= w2 - 2) {

                           layout = new TextLayout(s3, font, frc)

                                .getJustifiedLayout(w2 - 2);

                           ;

                           layout.draw(g3, x1 + w1 + 2, y2

                                + h20[i]);

                        } else

                           g3.drawString(s3, x1 + w1 + 2, y2

                                + h20[i]);

                        y2 = y2 + h20[i];

                        s3 = "";

                        j1 = 0;

                      }

                      if (j >= h1)

                        break;

                   }

                }

             } else

                g3.drawString(variabl2197[variabl2593][f0[i]], x1 + w1

                      + 2, y1 + h20[i]);

             g3.drawLine(x1, y1 + h1, x1 + w1 + w2, y1 + h1);

             if (y1 + h1 > variabl2631)

                variabl2631 = y1 + h1;

           }

           variabl2623 = variabl2661 + kuand;

           g3.drawLine(variabl2623, variabl2461, variabl2623, variabl2631);

           variabl2661 = variabl2661 + kuand + variabl1703;

           variabl2461 = variabl2657;

        }

        variabl2661 = variabl26610;

        variabl2657 = variabl2657 + gaod + variabl2155;

        variabl2461 = variabl2657;

     }

     if (variabl1139 > 0)

        variabl2593++;

   }

 

   public static void means(String[] parameter) {

     sw = new String[11];

     sw[1] = main1.sw1 + "";

     sw[2] = main1.sw2;

     sw[3] = main1.sw3;

     sw[4] = main1.sw4;

     sw[5] = main1.sw5;

     sw[6] = main1.sw6;

     sw[7] = main1.sw7;

     sw[8] = main1.sw8;

     sw[9] = main1.sw9;

     sw[10] = main1.sw10;

     main1.sw1 = 0;

     main1.sw2 = "";

     main1.sw3 = "";

     main1.sw4 = "";

     main1.sw5 = "";

     main1.sw6 = "";

     main1.sw7 = "";

     main1.sw8 = "";

     main1.sw9 = "";

     main1.sw10 = "";

     frame = new dataPrint4();

     variabl2603 = "";

     scrollPane = new JScrollPane();

     s1 = "";

     s2 = "";

     s3 = "";

     variabl2593 = -1;

     kuand = 0;

     gaod = 0;

     title = new ArrayList<struct1>();

     tableTitle = new ArrayList<struct2>();

     variabl2483 = 1000;

     variabl2503 = 600;

     variabl2681 = 600;

     w2 = 0;

     variabl2631 = 0;

     variabl2623 = 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];

     variabl1079 = parameter[15];

     variabl2049 = parameter[20];

     File file1 = new File(variabl1079);

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

                title.add(new struct1(tempStr.substring(2,

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

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

                tableTitle.add(new struct2(tempStr.substring(2,

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

             }

           }

        }

     } catch (IOException e2) {

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

     }

     struct2[] variabl2533 = new struct2[tableTitle.size()];

     variabl2533[0] = tableTitle.get(0);

     variabl1441 = Integer.valueOf(variabl2533[0].tableTitle[0].trim());

     variabl1703 = Integer.valueOf(variabl2533[0].tableTitle[1].trim());

     variabl1599 = Integer.valueOf(variabl2533[0].tableTitle[2].trim());

     variabl2155 = Integer.valueOf(variabl2533[0].tableTitle[3].trim());

     struct1[] variabl2685 = new struct1[title.size()];

     int w01, w02, h01, l01, le01, le02;

     le02 = Integer.valueOf(title.get(0).title[7]);

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

        variabl2685[i] = title.get(i);

        w01 = Integer.valueOf(variabl2685[i].title[4]);

        w02 = Integer.valueOf(variabl2685[i].title[5]);

        h01 = Integer.valueOf(variabl2685[i].title[6]);

        l01 = Integer.valueOf(variabl2685[i].title[2]);

        le01 = Integer.valueOf(variabl2685[i].title[7]);

        if (l01 == 1)

           kuand = kuand + w01 + w02;

        if (le01 == le02)

           gaod = gaod + h01;

     }

     main1.driver1();

     variabl1633 = "";

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

        if (variabl1633.length() == 0)

           variabl1633 = title.get(i).title[1];

        else

           variabl1633 = variabl1633 + "," + title.get(i).title[1];

     }

     数据表查询结构(variabl2603);

     数据表查询数据(variabl2603);

     frame.show();

     frame.setLayout(null);

     frame.setTitle("单记录式报表程序                                                                                                                                                                                                                                                                                         作者程学先");

     frame.setBounds(10, 10, variabl2483 - 10, 1000);

     frame.getContentPane().setLayout(null);

     final JPanel panel = new JPanel();

     panel.setBounds(10, 10, variabl2483 - 50, 1000);

     panel.setLayout(null);

     frame.getContentPane().add(panel);

     tableModel = new DefaultTableModel(variabl2197, variabl2517);

     table = new JTable(tableModel);

      table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

     table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

     scrollPane.getViewport().add(table, null);

      scrollPane.setBounds(30, 50, variabl2483 - 100, variabl2503 - 150);

     panel.add(scrollPane);

     table.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {

           variabl2593 = table.getSelectedRow();

        }

     });

     variabl2339 = (variabl2483 - 100) / variabl2851;

     int variabl2337 = 30;

     final JButton previewButton1 = new JButton(variabl2405[0]);

    previewButton1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           variabl1139 = 0;

           if (variabl2593 < 0) {

             JOptionPane.showMessageDialog(null, "未在表格中选择某条记录,请重新操作!");

             return;

           } else {

             final PrinterJob job = PrinterJob.getPrinterJob();

             if (!job.printDialog())

                return;

             job.setPrintable(new Printable() {

                public int print(Graphics graphics,

                      PageFormat pageFormat, int pageIndex)

                      throws PrinterException {

                   dataPrint4.g = graphics;

                   if (pageIndex < 1) {

                      g3 = (Graphics2D) g;

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

                      print1();

                      return Printable.PAGE_EXISTS;

                   } else {

                      return Printable.NO_SUCH_PAGE;

                   }

                }

             });

             try {

                job.print();

             } catch (Exception e1) {

                e1.printStackTrace();

             }

           }

        }

     });

    previewButton1.setBounds(variabl2337, 20, variabl2339, 20);

     if (variabl1187.indexOf(",0,") >= 0) {

        variabl2337 = variabl2337 + variabl2339;

        panel.add(previewButton1);

     }

 

     previewButton2 = new JButton(variabl2405[1]);

    previewButton2.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           variabl1139 = 1;

           if (variabl2593 < 0) {

             JOptionPane.showMessageDialog(null, "未在表格中选择某条记录,请重新操作!");

             return;

           } else {

             final PrinterJob job = PrinterJob.getPrinterJob();

             if (!job.printDialog())

                return;

             job.setPrintable(new Printable() {

                public int print(Graphics graphics,

                      PageFormat pageFormat, int pageIndex)

                      throws PrinterException {

                   dataPrint4.g = graphics;

                   if (pageIndex < 1) {

                      g3 = (Graphics2D) g;

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

                      print1();

                      return Printable.PAGE_EXISTS;

                   } else {

                      return Printable.NO_SUCH_PAGE;

                   }

                }

             });

             try {

                job.print();

             } catch (Exception e1) {

                e1.printStackTrace();

             }

           }

        }

     });

    previewButton2.setBounds(variabl2337, 20, variabl2339, 20);

     if (variabl1187.indexOf(",1,") >= 0) {

        variabl2337 = variabl2337 + variabl2339;

        panel.add(previewButton2);

     }

 

     final JButton exitButton = new JButton(variabl240501[2]);

     exitButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

           if ((sw[2].length() > 0) && (sw[3].length() > 0)

                && (sw[4].length() > 0))

             WorkflowDrivek1.means(sw);

           panel.setVisible(false);

           frame.setVisible(false);

           frame.dispose();

        }

     });

     exitButton.setBounds(variabl2337, 20, variabl2339, 20);

     if (variabl1187.indexOf(",2,") >= 0) {

        variabl2337 = variabl2337 + variabl2339;

        panel.add(exitButton);

     }

     frame.setVisible(true);

      frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

   }

 

   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);

           rsmd4 = rs.getMetaData();

           variabl2651 = rsmd4.getColumnCount();

           variabl2517 = new String[variabl2651];

           variabl1501 = new String[variabl2651];

           variabl1489 = new int[variabl2651];

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

             variabl2517[i] = rsmd4.getColumnName(i + 1);

           }

           rs.close();

           stat4.close();

           cont4.close();

        } catch (SQLException e1) {

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

        }

     } else {

        s10 = variabl2217.split(",");

        String 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);

             rsmd4 = rs.getMetaData();

             variabl2651 = rsmd4.getColumnCount();

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

                s2 = rsmd4.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);

        rsmd4 = rs.getMetaData();

        variabl2651 = rsmd4.getColumnCount();

        variabl2517 = new String[variabl2651];

        variabl1501 = new String[variabl2651];

        variabl1489 = new int[variabl2651];

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

           variabl2517[i1] = rsmd4.getColumnName(i1 + 1);

           variabl1501[i1] = rsmd4.getColumnTypeName(i1 + 1);

           variabl1489[i1] = rsmd4.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-1122698.html

上一篇:管理信息系统软件生产线源码92-94
下一篇:管理信息系统软件生产线源码98-100
收藏 IP: 183.94.47.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-29 02:24

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部