📄 billoutframe.java
字号:
package yarn;
import java.awt.BorderLayout;
import javax.swing.JInternalFrame;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JButton;
import java.awt.Dimension;
import javax.swing.JToolBar;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JSpinner;
import javax.swing.BorderFactory;
import java.awt.Color;
import javax.swing.border.TitledBorder;
import javax.swing.JLabel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Font;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.SystemColor;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import java.util.Date;
import javax.swing.event.ChangeEvent;
import javax.swing.event.CellEditorListener;
import java.awt.event.MouseEvent;
import javax.swing.event.DocumentEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseListener;
import javax.swing.event.DocumentListener;
import java.awt.event.ItemEvent;
import javax.swing.DefaultCellEditor;
import javax.swing.SpinnerDateModel;
import java.sql.ResultSet;
import java.util.Vector;
import java.sql.Statement;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class BillOutFrame extends JInternalFrame {
JDBCFile jf = null;
Statement st = null;
XYLayout xYLayout1 = new XYLayout();
JToolBar jToolBar1 = new JToolBar();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JTextField jTextField3 = new JTextField();
JCheckBox jCheckBox1 = new JCheckBox();
JComboBox jComboBox1 = new JComboBox();
JComboBox jComboBox3 = new JComboBox();
JSpinner jSpinner1 = new JSpinner();
JTextField jTextField4 = new JTextField();
TitledBorder titledBorder1 = new TitledBorder("");
TitledBorder titledBorder2 = new TitledBorder("");
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JLabel jLabel7 = new JLabel();
JLabel jLabel8 = new JLabel();
JPanel jPanel1 = new JPanel();
JScrollPane jScrollPane1 = new JScrollPane();
XYLayout xYLayout2 = new XYLayout();
JTable jTable1 = new JTable();
JTextField jTextField5 = new JTextField();
JLabel jLabel10 = new JLabel();
Border border3 = BorderFactory.createEtchedBorder(Color.white,
new Color(165, 169, 174));
Border border4 = new TitledBorder(border3, "纱线查询");
JButton jButton3 = new JButton();
JPanel jPanel2 = new JPanel();
Border border5 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
Color.white, new Color(165, 169, 174));
Border border6 = new TitledBorder(border5, "入库明细");
XYLayout xYLayout3 = new XYLayout();
JScrollPane jScrollPane2 = new JScrollPane();
JTable jTable2 = new JTable();
JToolBar jToolBar2 = new JToolBar();
JButton jButton4 = new JButton();
JButton jButton5 = new JButton();
JPanel jPanel3 = new JPanel();
JLabel jLabel9 = new JLabel();
XYLayout xYLayout4 = new XYLayout();
JTextField jTextField6 = new JTextField();
JTextField jTextField7 = new JTextField();
JTextField jTextField8 = new JTextField();
JLabel jLabel11 = new JLabel();
JLabel jLabel12 = new JLabel();
JComboBox yarnIDJComboBox = new JComboBox();
JButton jButton6 = new JButton();
public BillOutFrame() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public BillOutFrame(JDBCFile jf) {
this.jf = jf;
st = jf.getStatement();
try {
jbInit();
newBuild();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
border6 = new TitledBorder(BorderFactory.createEtchedBorder(
EtchedBorder.RAISED, Color.white, new Color(165, 169, 174)),
"入库明细");
border4 = new TitledBorder(BorderFactory.createEtchedBorder(
EtchedBorder.RAISED, Color.white, new Color(165, 169, 174)),
"纱线查询");
this.setVisible(true);
this.setSize(new Dimension(800,600));
getContentPane().setLayout(xYLayout1);
this.setClosable(true);
this.setMaximizable(true);
this.setResizable(true);
xYLayout1.setWidth(800);
xYLayout1.setHeight(600);
jButton1.setText("保存");
jButton2.setText("打印");
jTextField1.setText("jTextField1");
jTextField2.setText("jTextField2");
jTextField3.setText("jTextField3");
jCheckBox1.setBorder(BorderFactory.createEtchedBorder());
jCheckBox1.setText(" 红单标记");
jTextField4.setText("jTextField4");
jToolBar1.setBorder(BorderFactory.createEtchedBorder());
jLabel1.setText("入库单号");
jLabel2.setText("入库仓库");
jLabel3.setText("仓库余量");
jLabel4.setText("原始单号");
jLabel5.setText("客户");
jLabel6.setText("入库日期");
jLabel7.setText("制单人ID");
jLabel8.setFont(new java.awt.Font("方正舒体", Font.PLAIN, 40));
jLabel8.setForeground(SystemColor.desktop);
jLabel8.setText("入库单");
jPanel1.setBorder(border4);
jPanel1.setLayout(xYLayout2);
jTextField5.setText("jTextField5");
jLabel10.setText("请输入纱线ID");
jButton3.setSelectedIcon(null);
jButton3.setText("录新纱");
jPanel2.setBorder(border6);
jPanel2.setLayout(xYLayout3);
jButton4.setText("新增明细");
jButton5.setText("删除明细");
jToolBar2.setBorder(BorderFactory.createEtchedBorder());
jPanel3.setBorder(BorderFactory.createEtchedBorder());
jPanel3.setLayout(xYLayout4);
jLabel9.setText("备注");
jTextField6.setText("jTextField6");
jLabel11.setText("总重量");
jLabel12.setText("总金额");
jButton6.setText("刷新");
jButton6.addActionListener(new BillOutFrame_jButton6_actionAdapter(this));
jToolBar1.add(jButton1);
jToolBar1.add(jButton2);
jPanel1.add(jLabel10, new XYConstraints(9, 61, -1, -1));
jPanel1.add(jTextField5, new XYConstraints(6, 83, -1, -1));
jPanel1.add(jButton3, new XYConstraints(6, 26, 77, -1));
jScrollPane1.getViewport().add(jTable1);
this.getContentPane().add(jTextField2,
new XYConstraints(87, 92, 107, -1));
this.getContentPane().add(jLabel6, new XYConstraints(588, 68, -1, -1));
this.getContentPane().add(jLabel1, new XYConstraints(33, 43, -1, -1));
this.getContentPane().add(jTextField1,
new XYConstraints(87, 41, 107, -1));
this.getContentPane().add(jComboBox1, new XYConstraints(87, 66, 107, 20));
this.getContentPane().add(jLabel2, new XYConstraints(33, 68, -1, -1));
this.getContentPane().add(jLabel4, new XYConstraints(219, 96, -1, -1));
this.getContentPane().add(jTextField3,
new XYConstraints(273, 92, 109, -1));
this.getContentPane().add(jLabel3, new XYConstraints(33, 95, -1, -1));
this.getContentPane().add(jTextField4,
new XYConstraints(641, 92, 109, -1));
this.getContentPane().add(jComboBox3,
new XYConstraints(457, 92, 107, 20));
this.getContentPane().add(jLabel5, new XYConstraints(424, 94, -1, -1));
this.getContentPane().add(jSpinner1, new XYConstraints(641, 66, 109, -1));
this.getContentPane().add(jCheckBox1, new XYConstraints(638, 41, 92, 20));
this.getContentPane().add(jLabel7, new XYConstraints(588, 94, -1, -1));
this.getContentPane().add(jLabel8, new XYConstraints(354, 32, 127, 46));
this.getContentPane().add(jPanel1, new XYConstraints(24, 117, 726, 135));
jPanel1.add(jScrollPane1, new XYConstraints(93, 0, 616, 103));
jToolBar2.add(jButton4);
jToolBar2.add(jButton5);
jPanel2.add(jLabel12, new XYConstraints(579, 6, -1, -1));
jPanel2.add(jLabel11, new XYConstraints(454, 6, -1, -1));
jPanel2.add(jScrollPane2, new XYConstraints(5, 30, 703, 206));
jPanel2.add(jToolBar2, new XYConstraints(5, 0, 115, 26));
this.getContentPane().add(jPanel3, new XYConstraints(27, 530, 723, 34));
jPanel3.add(jLabel9, new XYConstraints(6, 6, -1, -1));
jPanel3.add(jTextField6, new XYConstraints(37, 5, 672, -1));
this.getContentPane().add(jToolBar1, new XYConstraints(10, 10, 777, -1));
jScrollPane2.getViewport().add(jTable2);
this.getContentPane().add(jPanel2, new XYConstraints(24, 253, 726, 270));
jPanel2.add(jTextField7, new XYConstraints(493, 3, 78, -1));
jPanel2.add(jTextField8, new XYConstraints(618, 3, 75, -1));
this.getContentPane().add(jButton6, new XYConstraints(201, 41, -1, 20));
}
public void newBuild()
{
//设置各项的默认数据
jComboBox1.addItem("SX1");
jComboBox1.addItem("SX2");
jSpinner1.setModel(new SpinnerDateModel());
//为增加明细按钮添加活动监听
jButton4.addActionListener(new BillOutFrame_jButton4_actionAdapter(this));
//为仓库选择文本框添加物品监听
jComboBox1.addItemListener(new BillOutFrame_jComboBox1_itemAdapter(this));
//为文本查询栏添加文档监听
jTextField5.getDocument().addDocumentListener(new BillOutFrame_jTextField5_DocumentAdapter(this));
//为查询纱线列表添加鼠标双击监听
jTable1.addMouseListener(new BillOutFrame_tableDoubleClick_MouseListener(this));
//为明细表设置表格模式
String[] itemColumnName = {"明细项","纱线ID","色名","品种规格","缸号","尾纱","重量","单价"};
YarnTableModel billInItemModel = new YarnTableModel(new Vector(),itemColumnName,2);
jTable2.setModel(billInItemModel);
//增加明细栏的明细数
((YarnTableModel)jTable2.getModel()).addTableItem();
//查找最大单号加1并且填进单号的填写栏,即新建单据令单号加1
refurbish();
//将在登陆时的用户填进制表人栏
jTextField4.setText(LogOn.EID);
//将storageRemain()方法得到的结果以字符串显示在剩余库存栏
jTextField2.setText(String.valueOf(storageRemain()));
//在数据库总查找纱线资料
ResultSet rs = lookUpYarn_ID(jTextField3.getText());
//j是对ResultSet进行遍历时用的变量
String[] findColumnName = {"纱线ID", "色号", "色名", "品种规格", "客户", "客户色号"};
tableDisplay(rs,findColumnName);
//设置表格的纱线ID填写栏的编辑器为组合框,并且设置组合框的基本信息
Vector comboBoxItem = new Vector();
try//从数据库查找组合框的基本信息
{
rs = jf.executeQuery("select YID from Yarn");
while(rs.next())
{
comboBoxItem.addElement(rs.getString(1));
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
yarnIDJComboBox = new JComboBox(comboBoxItem);
yarnIDJComboBox.setEditable(true);
//yarnIDJComboBox.getEditor().addActionListener(new BillPane_yarnIDJComboBoxEditor_ActionListener(this));
//yarnIDJComboBox.addFocusListener(new BillPane_yarnIDJComboBoxFocus_FocusListener(this));
//yarnIDJComboBox.addItemListener(new BillPane_yarnIDJComboBoxItem_ItemListener(this));
//设置明细表的纱线ID编辑器为JComboBox
jTable2.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(yarnIDJComboBox));
//加入表格的第二栏的单元改变监听
jTable2.getColumnModel().getColumn(1).getCellEditor().addCellEditorListener(new BillOutFrame_yarnIDJComboBoxCell_CellListener(this));
//jTable2.getColumnModel().getColumn(5).setCellEditor(new DefaultCellEditor(new JCheckBox()));
jTable2.getColumnModel().getColumn(4).setCellEditor(new DefaultCellEditor(new JTextField()));
jTable2.getColumnModel().getColumn(6).setCellEditor(new DefaultCellEditor(new JTextField()));
jTable2.getColumnModel().getColumn(7).setCellEditor(new DefaultCellEditor(new JTextField()));
jTable2.getColumnModel().getColumn(6).getCellEditor().addCellEditorListener(new BillOutFrame_yarnMWJTextFieldCell_CellListener(this));
jTable2.getColumnModel().getColumn(7).getCellEditor().addCellEditorListener(new BillOutFrame_yarnMWJTextFieldCell_CellListener(this));
}
//查找剩余库存方法,需要把输入查询仓库条件的JComboBox作参数
private float storageRemain()
{
float temp = 0; //临时变量temp存储在数据库查找的最大容量
//查找库存的剩余库存并显示在剩余容量栏
try {
ResultSet rs = st.executeQuery(
"select Mcontent from Storage where SID ='" +
(String) jComboBox1.getSelectedItem() + "'");
rs.next();
temp = rs.getFloat(1);
//查找入库仓库栏的默认仓库的总货物重量
rs = st.executeQuery("select SUM(YWeight) from Goods where SID ='" +
(String) jComboBox1.getSelectedItem() + "'");
rs.next();
//System.out.print(rs.getFloat(1));
temp = temp - (float) rs.getFloat(1); //将最大容量减去库存容量得到剩余容量
}
catch (Exception ex)
{
ex.printStackTrace();
}
return temp;
}
//按纱线ID号对纱线进行查找的方法,需要输入查询条件
private ResultSet lookUpYarn_ID(String condition)
{
ResultSet rs = null;
try {
rs = st.executeQuery(
"select YID,YColorID,YColorName,YVariety,Client,CColor from YarnIn where YID like '" +
condition + "%'");
}
catch (Exception ex)
{
ex.printStackTrace();
}
return rs;
}
//将数据集结果写进表格的方法
private void tableDisplay(ResultSet rs,String[] columnName)
{
//将数据库得到的结果放进rowData中
try {
Vector rowData = new Vector();
if(rs.next())
do
{
//临时Object数组对象,保存ResultSet读取的单行数据
Object[] temp = new Object[rs.getMetaData().getColumnCount()];
for (int i = 0; i < rs.getMetaData().getColumnCount();
i++)
{
temp[i] = rs.getString(i + 1);
}
rowData.addElement(temp);
}
while(rs.next());
//为纱线查询框设置TableModel
YarnTableModel yarnInModel = new YarnTableModel(
rowData,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -