【Java开源代码栏目提醒】:网学会员为广大网友收集整理了,BuyMaterial.java,希望对大家有所帮助!
package com.csbook.restaurant;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author pengtao
* @version 1.0
*/
public class BuyMaterial extends JInternalFrame {
JPanel panel1 = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
GridLayout gridLayout1 = new GridLayout(4,4);
JLabel jLabel1 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JTextField operator = new JTextField();
JLabel jLabel6 = new JLabel();
JLabel jLabel7 = new JLabel();
JPanel jPanel2 = new JPanel();
FlowLayout flowLayout1 = new FlowLayout();
JLabel jLabel8 = new JLabel();
JPanel jPanel3 = new JPanel();
JButton ok = new JButton();
JButton cancel = new JButton();
JTextField remark = new JTextField();
JTextField price = new JTextField();
JTextField discount = new JTextField();
JLabel jLabel2 = new JLabel();
JTextField amount = new JTextField();
String currentOper="";
JComboBox commodity = new JComboBox();
Hashtable foodSupplier=new Hashtable();
JTextField supplier = new JTextField();
public BuyMaterial(String title,boolean resizable,boolean closable,boolean maximizable,boolean iconifiable,String operator) {
super(title);
this.currentOper=operator;
try {
jbInit();
pack();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
panel1.setLayout(borderLayout1);
jPanel1.setLayout(gridLayout1);
jLabel1.setText("所进商品:");
jLabel3.setText("备注:");
jLabel4.setText("折扣:");
jLabel5.setText("经手人:");
jLabel6.setText("单价:");
jLabel7.setText("供应商:");
jPanel2.setLayout(flowLayout1);
jLabel8.setText("进货入库");
ok.setText("确定");
ok.addActionListener(new BuyMaterial_ok_actionAdapter(this));
cancel.setText("取消");
cancel.addActionListener(new BuyMaterial_cancel_actionAdapter(this));
remark.setText("");
operator.setText("");
price.setText("");
discount.setText("");
jLabel2.setText("数量:");
amount.setText("");
this.prepareShow();
commodity.setSelectedIndex(-1);
commodity.addActionListener(new BuyMaterial_commodity_actionAdapter(this));
getContentPane().add(panel1);
panel1.add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jLabel1, null);
jPanel1.add(commodity, null);
jPanel1.add(jLabel7, null);
jPanel1.add(supplier, null);
jPanel1.add(jLabel6, null);
jPanel1.add(price, null);
jPanel1.add(jLabel5, null);
jPanel1.add(operator, null);
jPanel1.add(jLabel4, null);
jPanel1.add(discount, null);
panel1.add(jPanel2, BorderLayout.NORTH);
jPanel2.add(jLabel8, null);
panel1.add(jPanel3, BorderLayout.SOUTH);
jPanel3.add(ok, null);
jPanel3.add(cancel, null);
jPanel1.add(jLabel2, null);
jPanel1.add(amount, null);
jPanel1.add(jLabel3, null);
jPanel1.add(remark, null);
jPanel1.add(remark, null);
operator.setText(currentOper);
operator.setEditable(false);
}
void ok_actionPerformed(ActionEvent e) {
if(price.getText().trim().equals("")||discount.getText().trim().equals("")||amount.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(this, "单价、数量和折扣不能为空,无折扣请输入1!", "警告",
JOptionPane.ERROR_MESSAGE);
return;
}
String temp=price.getText().trim();
try {
Float.parseFloat(temp);
}
catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(this, "您输入的数据不合法!", "警告",
JOptionPane.ERROR_MESSAGE);
return;
}
temp=discount.getText().trim();
try {
float disc=Float.parseFloat(temp);
if(disc>1||disc<0)
JOptionPane.showMessageDialog(this, "折扣率只能在0和1之间!", "警告",
JOptionPane.ERROR_MESSAGE);
}
catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(this, "您输入的数据不合法!", "警告",
JOptionPane.ERROR_MESSAGE);
}
temp=amount.getText().trim();
try {
Float.parseFloat(temp);
}
catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(this, "您输入的数据不合法!", "警告",
JOptionPane.ERROR_MESSAGE);
}
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
try{
conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Restaurant;user=user;passw