仓库管理系统入库出库实现swing编程
作者:互联网
入库界面的实现
InportRecordFrame.java
package com.java.view;
import java.awt.EventQueue;
import java.sql.Connection;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Vector;
import javax.swing.JInternalFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import com.java.dao.GoodsDao;
import com.java.dao.SupplierDao;
import com.java.model.Goods;
import com.java.model.InPortRecord;
import com.java.model.Supplier;
import com.java.util.DbUtil;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
public class InportRecordFrame extends JInternalFrame {
private JTable recordTable;
private JTextField goodsNameText_1;
private JTextField IdText;
private DbUtil dbUtil;
private JTextField goodsNameText_2;
private JTextField goodsPriceText;
private JTextField warehouseNameText;
private JTextField goodsNumberText;
private JTextField supplierNameText;
private JTextField textField;
private JTextField textField_2;
private JTextField textField_3;
private JTextField textField_4;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
InportRecordFrame frame = new InportRecordFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public InportRecordFrame() {
setIconifiable(true);
setClosable(true);
setTitle("入库记录管理");
setBounds(100, 100, 973, 759);
JScrollPane scrollPane = new JScrollPane();
JLabel lblNewLabel = new JLabel("商品名称:");
goodsNameText_1 = new JTextField();
goodsNameText_1.setColumns(10);
JButton btnNewButton = new JButton("查询入库记录");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
selectRecordActionPerformed(e);
}
});
JLabel lblNewLabel_1 = new JLabel("订单编号:");
IdText = new JTextField();
IdText.setColumns(10);
JButton button = new JButton("删除入库记录");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
delInportRecordActionPerformed(e);
}
});
JPanel panel = new JPanel();
panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
JPanel panel_1 = new JPanel();
panel_1.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
JLabel lblNewLabel_2_1 = new JLabel("商品名称");
textField = new JTextField();
textField.setColumns(10);
textField_2 = new JTextField();
textField_2.setColumns(10);
JLabel lblNewLabel_5_1 = new JLabel("仓库名称");
textField_3 = new JTextField();
textField_3.setColumns(10);
JButton button_1_1 = new JButton("修改入库记录");
JLabel lblNewLabel_6_1 = new JLabel("供应商");
JLabel lblNewLabel_4_1 = new JLabel("商品数量");
textField_4 = new JTextField();
textField_4.setColumns(10);
GroupLayout gl_panel_1 = new GroupLayout(panel_1);
gl_panel_1.setHorizontalGroup(
gl_panel_1.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel_1.createSequentialGroup()
.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel_1.createSequentialGroup()
.addContainerGap()
.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel_1.createSequentialGroup()
.addComponent(lblNewLabel_2_1)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGroup(gl_panel_1.createParallelGroup(Alignment.TRAILING)
.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGroup(gl_panel_1.createSequentialGroup()
.addComponent(lblNewLabel_5_1)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))))
.addGroup(gl_panel_1.createSequentialGroup()
.addContainerGap()
.addComponent(lblNewLabel_6_1))
.addGroup(gl_panel_1.createSequentialGroup()
.addContainerGap()
.addComponent(lblNewLabel_4_1)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(textField_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGroup(gl_panel_1.createSequentialGroup()
.addGap(99)
.addComponent(button_1_1)))
.addContainerGap(268, Short.MAX_VALUE))
);
gl_panel_1.setVerticalGroup(
gl_panel_1.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel_1.createSequentialGroup()
.addContainerGap()
.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_2_1)
.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(82)
.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_5_1)
.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_4_1)
.addComponent(textField_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(35)
.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_6_1)
.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(30)
.addComponent(button_1_1)
.addGap(34))
);
panel_1.setLayout(gl_panel_1);
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.TRAILING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(57)
.addComponent(lblNewLabel)
.addGap(47)
.addComponent(goodsNameText_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(30)
.addComponent(btnNewButton)
.addGap(91)
.addComponent(lblNewLabel_1)
.addGap(47)
.addComponent(IdText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(40)
.addComponent(button)
.addContainerGap(107, Short.MAX_VALUE))
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap(30, Short.MAX_VALUE)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 318, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 494, GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addComponent(scrollPane, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 927, GroupLayout.PREFERRED_SIZE)))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addGap(27)
.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel)
.addComponent(btnNewButton)
.addComponent(goodsNameText_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(button)
.addComponent(lblNewLabel_1)
.addComponent(IdText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addGap(18)
.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 251, GroupLayout.PREFERRED_SIZE)
.addGap(30)
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(panel, GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
.addGap(23))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 339, GroupLayout.PREFERRED_SIZE)
.addContainerGap())))
);
JLabel lblNewLabel_2 = new JLabel("商品名称:");
goodsNameText_2 = new JTextField();
goodsNameText_2.setColumns(10);
JLabel lblNewLabel_3 = new JLabel("商品价格:");
goodsPriceText = new JTextField();
goodsPriceText.setColumns(10);
JLabel lblNewLabel_5 = new JLabel("仓库名称:");
warehouseNameText = new JTextField();
warehouseNameText.setColumns(10);
JLabel lblNewLabel_4 = new JLabel("商品数量:");
goodsNumberText = new JTextField();
goodsNumberText.setColumns(10);
JLabel lblNewLabel_6 = new JLabel("供应商:");
supplierNameText = new JTextField();
supplierNameText.setColumns(10);
JButton button_1 = new JButton("添加入库记录");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addGoodsRecordsActionPerformed(e);
}
});
GroupLayout gl_panel = new GroupLayout(panel);
gl_panel.setHorizontalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addContainerGap()
.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addComponent(lblNewLabel_2)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(goodsNameText_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGroup(gl_panel.createSequentialGroup()
.addComponent(lblNewLabel_3)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(goodsPriceText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGroup(gl_panel.createSequentialGroup()
.addComponent(lblNewLabel_5)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(warehouseNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
.addGroup(gl_panel.createSequentialGroup()
.addContainerGap()
.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel_4)
.addComponent(lblNewLabel_6))
.addPreferredGap(ComponentPlacement.UNRELATED)
.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
.addComponent(supplierNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(goodsNumberText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addGroup(gl_panel.createSequentialGroup()
.addGap(33)
.addComponent(button_1)))
.addContainerGap(140, Short.MAX_VALUE))
);
gl_panel.setVerticalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addContainerGap()
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_2)
.addComponent(goodsNameText_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(32)
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_3)
.addComponent(goodsPriceText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(26)
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_5)
.addComponent(warehouseNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_4)
.addComponent(goodsNumberText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(supplierNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(lblNewLabel_6))
.addGap(18)
.addComponent(button_1)
.addGap(71))
);
panel.setLayout(gl_panel);
recordTable = new JTable();
recordTable.setModel(new DefaultTableModel(
new Object[][] {
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
},
new String[] {
"\u8BA2\u5355\u7F16\u53F7", "\u5E8F\u53F7", "\u5546\u54C1\u540D\u79F0", "\u4ED3\u5E93", "\u5546\u54C1\u4EF7\u683C", "\u5546\u54C1\u6570\u91CF", "\u4F9B\u5E94\u5546", "\u5165\u5E93\u65F6\u95F4"
}
) {
boolean[] columnEditables = new boolean[] {
false, false, false, false, false, false, false, false
};
public boolean isCellEditable(int row, int column) {
return columnEditables[column];
}
});
recordTable.getColumnModel().getColumn(0).setPreferredWidth(149);
recordTable.getColumnModel().getColumn(7).setPreferredWidth(158);
scrollPane.setViewportView(recordTable);
getContentPane().setLayout(groupLayout);
this.fillTable(new InPortRecord ());
}
private void selectRecordActionPerformed(ActionEvent e) {
String goodsName=goodsNameText_1.getText();
InPortRecord ipr=new InPortRecord();
ipr.setGoodsName(goodsName);
this.fillTable(ipr);
}
private void fillTable(InPortRecord ipr){
DefaultTableModel dtm=(DefaultTableModel) recordTable.getModel();
dtm.setRowCount(0);
Connection con=null;
dbUtil=new DbUtil();
try {
con=dbUtil.getCon();
ResultSet rs=GoodsDao.inputRecordList(con, ipr);
while(rs.next()){
Vector<Object> v=new Vector<Object>();
v.add(rs.getString("recordNumber"));
v.add(rs.getString("id"));
v.add(rs.getString("goodsName"));
v.add(rs.getString("warehouseName"));
v.add(rs.getString("goodsPrice"));
v.add(rs.getString("goodsNumber"));
v.add(rs.getString("supplierName"));
v.add(rs.getString("time"));
dtm.addRow(v);
}
} catch (Exception e) {
// TODO: handle exception
e.getStackTrace();
e.printStackTrace();
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
private void delInportRecordActionPerformed(ActionEvent e) {
int goodsId=Integer.parseInt(IdText.getText());
// String s=Integer.toString(goodsId);
// try {
// if(s.equals("")){
// JOptionPane.showMessageDialog(null, "订单编号不能为空!");
// }
// } catch (Exception e2) {
// e2.getStackTrace();
// e2.printStackTrace();
// JOptionPane.showMessageDialog(null, "订单编号不能为空!");
// }
InPortRecord inputPortRecord=new InPortRecord(goodsId);
Connection con=null;
dbUtil=new DbUtil();
try {
con=dbUtil.getCon();
int n=GoodsDao.delinputRecord(con, inputPortRecord);
if(n==1){
JOptionPane.showMessageDialog(null, "入库记录删除成功!");
}
else{
JOptionPane.showMessageDialog(null, "订单编号不存在!");
}
} catch (Exception e2) {
e2.getStackTrace();
e2.printStackTrace();
JOptionPane.showMessageDialog(null, "删除失败!");
}finally{
try {
dbUtil.closeCon(con);
System.out.println(con.isClosed());
} catch (Exception e3) {
e3.getStackTrace();
e3.printStackTrace();
}
}
}
private void addGoodsRecordsActionPerformed(ActionEvent e) {
String goodsName=this.goodsNameText_2.getText();
String warehouseName=this.warehouseNameText.getText();
String goodsPrice=this.goodsPriceText.getText();
Integer gp=Integer.parseInt(goodsPrice);
String goodsNumber=this.goodsNumberText.getText();
Integer gn=Integer.parseInt(goodsNumber);
// Integer goodsPrice=Integer.parseInt(this.goodsPriceText.getText());
// Integer goodsNumber=Integer.parseInt(this.goodsNumberText.getText());
String supplierName=this.supplierNameText.getText();
SimpleDateFormat myfmt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
SimpleDateFormat adf = new SimpleDateFormat("yyyyMMddhhmmss");
String time=myfmt.format(new java.util.Date()).toString();
String recordNumber="RK"+adf.format(new java.util.Date()).toString();
// try {
// Integer g=Integer.parseInt(this.goodsPriceText.getText());
// } catch (java.lang.NumberFormatException e2) {
// e2.getStackTrace();
// e2.printStackTrace();
// JOptionPane.showMessageDialog(null, "商品价格不能为空!");
// }
if(goodsName.isEmpty()){
JOptionPane.showMessageDialog(null, "商品名称不能为空!");
}
if(warehouseName.isEmpty()){
JOptionPane.showMessageDialog(null, "仓库名称不能为空!");
}
if("0".equals(String.valueOf(goodsPrice)) ){
JOptionPane.showMessageDialog(null, "商品价格不能为0!");
}
if(String.valueOf(goodsPrice).equals("")){
JOptionPane.showMessageDialog(null, "商品价格不能为空!");
}
if(gp <0){
JOptionPane.showMessageDialog(null, "商品价格不能小于0!");
}
if("0".equals(String.valueOf(goodsNumber))){
JOptionPane.showMessageDialog(null, "商品数量不能为0!");
}
if(gn <0){
JOptionPane.showMessageDialog(null, "商品数量不能为小于0!");
}
if(supplierName.isEmpty()){
JOptionPane.showMessageDialog(null, "供应商名称不能为空!");
}
if(time.isEmpty()){
JOptionPane.showMessageDialog(null, "商品名称不能为空!");
}
InPortRecord inputPortRecord=new InPortRecord( goodsName, warehouseName, gp, gn, supplierName,time,recordNumber);
Supplier supplier=new Supplier(supplierName,goodsName);
Connection con=null;
dbUtil=new DbUtil();
try {
con=dbUtil.getCon();
SupplierDao.addSupplier(con, supplier);
int n=GoodsDao.addinputRecord(con, inputPortRecord);
if(n==1){
JOptionPane.showMessageDialog(null, "入库记录添加成功!");
}
else{
JOptionPane.showMessageDialog(null, "入库记录添加失败!");
}
} catch (Exception e2) {
e2.getStackTrace();
e2.printStackTrace();
JOptionPane.showMessageDialog(null, "入库记录添加失败!数据不合法!");
}finally{
try {
dbUtil.closeCon(con);
System.out.println(con.isClosed());
} catch (Exception e1) {
e1.printStackTrace();
}
this.resetValues();
}
}
private void resetValues() {
this.goodsNameText_2.setText("");
this.goodsPriceText.setText("");
this.warehouseNameText.setText("");
this.goodsNumberText.setText("");
this.supplierNameText.setText("");
}
}
dao类
GoodsDao.java
package com.java.dao;
//商品信息dao类
//项数据库中插入商品信息
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.java.model.Goods;
import com.java.model.InPortRecord;
import com.java.model.OutPortRecord;
import com.java.util.StringUtil;
public class GoodsDao {
//添加商品信息
public static int add(Connection con,Goods goods) throws Exception{
String sql="insert into t_goods values(?,?,?)";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1,goods.getGoodsName());
pstmt.setInt(2, goods.getGoodsPrice());
pstmt.setInt(3, goods.getGoodsNumber());
return pstmt.executeUpdate();
}
// 添加入库订单记录
public static int addinputRecord(Connection con,InPortRecord inputPortRecord) throws Exception{
String sql="insert into t_inputRecord values(null,?,?,?,?,?,?,?)";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1,inputPortRecord.getGoodsName());
pstmt.setString(2,inputPortRecord.getWarehouseName());
pstmt.setInt(3,inputPortRecord.getGoodsPrice());
pstmt.setInt(4,inputPortRecord.getGoodsNumber());
pstmt.setString(5,inputPortRecord.getSupporterName());
pstmt.setString(6,inputPortRecord.getTime());
pstmt.setString(7,inputPortRecord.getRecordNumber());
return pstmt.executeUpdate();
}
// 删除入库订单记录
public static int delinputRecord(Connection con,InPortRecord inputPortRecord) throws Exception{
String sql = "delete from t_inputRecord where id=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setInt(1,inputPortRecord.getId());
return pstmt.executeUpdate();
}
// 添加出库订单记录
public static int addOutputRecord(Connection con, OutPortRecord outPortRecord) throws Exception{
String sql="insert into t_outputRecord values(null,?,?,?,?,?,?,?)";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1,outPortRecord.getGoodsName());
pstmt.setString(2,outPortRecord.getWarehouseName());
pstmt.setInt(3,outPortRecord.getGoodsPrice());
pstmt.setInt(4,outPortRecord.getGoodsNumber());
pstmt.setString(5,outPortRecord.getSupporterName());
pstmt.setString(6,outPortRecord.getTime());
pstmt.setString(7,outPortRecord.getRecordNumber());
return pstmt.executeUpdate();
}
// 删除出库订单记录
public static int deloutputRecord(Connection con,OutPortRecord outPortRecord) throws Exception{
String sql = "delete from t_outputRecord where id=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setInt(1,outPortRecord.getId());
return pstmt.executeUpdate();
}
// 删除商品信息
public static int delete(Connection con,Goods goods)throws Exception{
String sql = "delete from t_goods where goodsName=?";
PreparedStatement pstmt1=con.prepareStatement(sql);
pstmt1.setString(1, goods.getGoodsName());
return pstmt1.executeUpdate();
}
// 更改商品信息
public static int alter(Connection con,Goods goods)throws Exception{
String sql = "update t_goods set goodsName=? where goodsName=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, goods.getAlterName());
pstmt.setString(2, goods.getGoodsName());
System.out.println(goods.getGoodsPrice());
return pstmt.executeUpdate();
}
// 查询商品信息
public static ResultSet list(Connection con,Goods goods)throws Exception{
StringBuffer sb=new StringBuffer("select *from t_goods");
if(StringUtil.isNotEmpty(goods.getGoodsName())){
sb.append(" and goodsName like '%"+goods.getGoodsName()+"%'");
}
PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where"));
return pstmt.executeQuery();
}
// 查询入库信息
public static ResultSet inputRecordList(Connection con,InPortRecord ipr)throws Exception{
StringBuffer sb=new StringBuffer("select *from t_inputRecord");
if(StringUtil.isNotEmpty(ipr.getGoodsName())){
sb.append(" and goodsName like '%"+ipr.getGoodsName()+"%'");
// sb.append(" and warehouseName like '%"+ipr.getWarehouseName()+"%'");
}
PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where"));
return pstmt.executeQuery();
}
// 查询出库信息
public static ResultSet outputRecordList(Connection con,OutPortRecord opr)throws Exception{
StringBuffer sb=new StringBuffer("select *from t_outputRecord");
if(StringUtil.isNotEmpty(opr.getGoodsName())){
sb.append(" and goodsName like '%"+opr.getGoodsName()+"%'");
// sb.append(" and warehouseName like '%"+ipr.getWarehouseName()+"%'");
}
PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where"));
return pstmt.executeQuery();
}
}
实体类
InPortRecord.java
package com.java.model;
import java.sql.Date;
public class InPortRecord {
int id;
String recordNumber;
String goodsName;
String warehouseName;
int goodsPrice;
int goodsNumber;
String supporterName;
String time;
public String getRecordNumber() {
return recordNumber;
}
public void setRecordNumber(String recordNumber) {
this.recordNumber = recordNumber;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public String getWarehouseName() {
return warehouseName;
}
public void setWarehouseName(String warehouseName) {
this.warehouseName = warehouseName;
}
public int getGoodsPrice() {
return goodsPrice;
}
public void setGoodsPrice(int goodsPrice) {
this.goodsPrice = goodsPrice;
}
public int getGoodsNumber() {
return goodsNumber;
}
public void setGoodsNumber(int goodsNumber) {
this.goodsNumber = goodsNumber;
}
public String getSupporterName() {
return supporterName;
}
public void setSupporterName(String supporterName) {
this.supporterName = supporterName;
}
public InPortRecord(int id) {
super();
this.id = id;
}
public InPortRecord(String goodsName, String supporterName) {
super();
this.goodsName = goodsName;
this.supporterName = supporterName;
}
public InPortRecord(int id, String goodsName, String warehouseName, int goodsPrice, int goodsNumber,
String supporterName) {
super();
this.id = id;
this.goodsName = goodsName;
this.warehouseName = warehouseName;
this.goodsPrice = goodsPrice;
this.goodsNumber = goodsNumber;
this.supporterName = supporterName;
}
public InPortRecord(String goodsName, String warehouseName, int goodsPrice, int goodsNumber,
String supporterName , String time ) {
super();
this.goodsName = goodsName;
this.warehouseName = warehouseName;
this.goodsPrice = goodsPrice;
this.goodsNumber = goodsNumber;
this.supporterName = supporterName;
this.time=time;
}
public InPortRecord() {
super();
// TODO 自动生成的构造函数存根
}
public InPortRecord(String goodsName, String warehouseName, int goodsPrice, int goodsNumber,
String supporterName, String time,String recordNumber) {
super();
this.recordNumber = recordNumber;
this.goodsName = goodsName;
this.warehouseName = warehouseName;
this.goodsPrice = goodsPrice;
this.goodsNumber = goodsNumber;
this.supporterName = supporterName;
this.time = time;
}
}
Util类
DbUtil.java
package com.java.util;
import java.sql.Connection;
import java.sql.DriverManager;
public class DbUtil {
private String url="jdbc:mysql://localhost:3306/db_warehouse?useSSL=false&serverTimezone=CTT&allowPublicKeyRetrieval=true&autoReconnect=true";
private String user="root";
private String password="123456";
private String jdbcName="com.mysql.cj.jdbc.Driver";
public Connection getCon()throws Exception{
Class.forName(jdbcName);
Connection con = DriverManager.getConnection(url, user, password);
System.out.println(con);
return con;//一定要return con,默认return null 造成空指针的原因之一
}
public void closeCon(Connection con)throws Exception{
if(con!=null){
con.close();
}
}
public static void main(String[] args) {
DbUtil dbUtil=new DbUtil();
try {
dbUtil.getCon();
System.out.print("数据库连接成功!");
} catch (Exception e) {
System.out.print("数据库连接失败!");
}
}
}
界面截图
标签:null,addComponent,GroupLayout,panel,swing,new,出库,入库,SIZE 来源: https://blog.csdn.net/weixin_46052871/article/details/121815283