📄 processionrecordjpanel.java
字号:
package file1;
/*
* @Author:
* Create Time:2008-2-22
* Description:货品损益记录处理情况记录的显示界面
*/
import javax.swing.*;
import java.awt.FlowLayout;
import java.sql.*;
import sun.jdbc.rowset.*;
public class ProcessionRecordJPanel extends JPanel {
private JTable recTable = null;
private JScrollPane recScrollPane = null;
private String[] head = { "记录编号", "货品损益记录编号", "操作人", "操作时间", "建议" };// 表格的标题
private String[][] data = null;// 表格的数据
private int headNum = 0;// 表格标题的列数
private DBConnection con = null;// 数据库联接操作类
private String[] ids = null;// 存储所有货品损益记录的id
private int totalRecordCount = 0;// 存储所有记录总数的变量
public ProcessionRecordJPanel(int id) {
headNum = head.length;
con = new DBConnection();
this.setLayout(new FlowLayout());
getRecords(id);// 调用从数据库中读取指定字段数据的方法
}
public int getRecords(int id) {// 从数据库中读取指定的字段数据并显示到表格中
String sqlStr = "";
if (id == 0) {// 总体查询
sqlStr = "select * from ProcessionRecord ";
}
if (id > 0) {// 条件查询
sqlStr = "select * from ProcessionRecord where GoodNotEqualID="
+ id;
}
try{
CachedRowSet crs = con.getResultSet(sqlStr);
int totalRecord = 0;// 记录总的记录数
while (crs.next()) {
totalRecord++;
}
totalRecordCount = totalRecord;// 用以变量临时存储记录数
data = new String[totalRecord][headNum];
ids = new String[totalRecord];
crs.beforeFirst();
totalRecord = 0;
while (crs.next()) {
data[totalRecord][0] = String.valueOf(crs.getInt(1));
data[totalRecord][1] = String.valueOf(crs.getInt(2));
data[totalRecord][2] = crs.getString(3).trim();
data[totalRecord][3] = crs.getString(4).trim();
totalRecord++;
}
recTable = new JTable(data, head);
recScrollPane = new JScrollPane(recTable);
this.add(recScrollPane);
this.validate();
} catch (ClassNotFoundException cnfe) {
JOptionPane.showMessageDialog(null, "发生ClassNotFound错误!", "",
JOptionPane.INFORMATION_MESSAGE);
return 0;
} catch (SQLException sqle) {
JOptionPane.showMessageDialog(null, "发生Sql错误!", "",
JOptionPane.INFORMATION_MESSAGE);
return 0;
}
return totalRecordCount;
}
public String[] getIDS() {// 取得存储所有货品损益记录的id的数组
return ids;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -