(环境搭建,运行部署,软件修改,代码定制,源码获取,可有偿私信)
import com.work.LoginService.Login;
import java.text.ParseException;
import java.util.Date;
public class Item {
private Integer itemId;
private String itemName;
private Double itemPrice;
private Integer itemNumber;
private Warehouse warehouse;
private Date createdTime;
@Override
public String toString() {
return "Item{" +
"itemId=" + itemId +
", itemName='" + itemName + '\'' +
", itemPrice=" + itemPrice +
", itemNumber=" + itemNumber +
", warehouseName=" + warehouse.getWarehouseName() +
", createdTime=" + createdTime +
'}';
}
public Item(Integer itemId, String itemName, Double itemPrice, Integer itemNumber, Warehouse warehouse, String createdTime) throws ParseException {
this.itemId = itemId;
this.itemName = itemName;
this.itemPrice = itemPrice;
this.itemNumber = itemNumber;
this.warehouse = warehouse;
this.createdTime = Login.sdf.parse(createdTime);
}
public Integer getItemId() {
return itemId;
}
public void setItemId(Integer itemId) {
this.itemId = itemId;
}
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public Double getItemPrice() {
return itemPrice;
}
public void setItemPrice(Double itemPrice) {
this.itemPrice = itemPrice;
}
public Integer getItemNumber() {
return itemNumber;
}
public void setItemNumber(Integer itemNumber) {
this.itemNumber = itemNumber;
}
public Warehouse getWarehouse() {
return warehouse;
}
public void setWarehouseId(Warehouse warehouse) {
this.warehouse = warehouse;
}
public String getCreatedTime() {
return Login.sdf.format(createdTime);
}
public void setCreatedTime(Date createdTime) {
this.createdTime = createdTime;
}
}
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;
public class InquireGoodsList extends JFrame {
private InquireGoodsList inquireGoodsList;
private static DefaultTableModel model = null;
private static JTable table;
public InquireGoodsList(String title) {
// 创建内容面板
inquireGoodsList = this;
JPanel panel = new JPanel();
JPanel panel1=new JPanel();
JLabel lbl1=new JLabel("货物查询",JLabel.CENTER);
JLabel lbl2=new JLabel(" ");
lbl1.setFont(new Font(null, Font.BOLD, 20));
JButton btn1=new JButton("返回");
JButton btn2=new JButton("刷新");
btn1.setFont(new Font(null, Font.BOLD, 20));
btn2.setFont(new Font(null, Font.BOLD, 20));
String[] columnNames = {"仓库名称", "货物名称", "单价", "数量", "入库时间"};
String[][] rowData = {};
// 创建一个表格,指定 表头 和 所有行数据
// table = new JTable(rowData, columnNames);
model = new DefaultTableModel(rowData, columnNames);
table = new JTable(model);
table.setRowHeight(30);
table.getColumnModel().getColumn(0).setPreferredWidth(80);// 第一列列宽设置为80
table.getColumnModel().getColumn(2).setPreferredWidth(40);// 第一列列宽设置为80
table.getColumnModel().getColumn(3).setPreferredWidth(40);// 第一列列宽设置为80
table.getColumnModel().getColumn(4).setPreferredWidth(150);// 最后一列列宽设置为150
table.setPreferredScrollableViewportSize(new Dimension(500, 300));// 设置滚动面板视口大小(超过该大小的行数据,需要拖动滚动条才能看到)*/
table.setSelectionForeground(Color.DARK_GRAY);// 选中后字体颜色
// 设置 内容面板 到 窗口
this.setLayout(new BorderLayout());
this.add(lbl1,BorderLayout.NORTH);
this.add(new JScrollPane(table),BorderLayout.CENTER);
this.pack();
this.setTitle(title);
this.setLocationRelativeTo(null);
this.setVisible(true);
panel1.add(btn1);
panel1.add(lbl2);
panel1.add(btn2);
this.add(panel1,BorderLayout.SOUTH);
initItemMap();
btn1.addActionListener(new ExitGoodsInquireService());
btn2.addActionListener(new FlushGoodsListButton());
}
public class FlushGoodsListButton implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
initItemMap();
}
}
public static void initItemMap(){
model.setRowCount(0);
Login.initWHMap();
Login.initItemMap();
for(Map.Entry<Integer, Item> entry: Login.itemMap.entrySet()){
model.addRow(new String[] { entry.getValue().getWarehouse().getWarehouseName(),
entry.getValue().getItemName(), String.valueOf(entry.getValue().getItemPrice()),
String.valueOf(entry.getValue().getItemNumber()), entry.getValue().getCreatedTime()});
}
}
public class ExitGoodsInquireService implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
inquireGoodsList.dispose();
InquireFunction.inquireFunction.setVisible(true);
}
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Date;
public class InputGoods extends JFrame {
private JLabel label0,label1,label2,label3,label4,label5,label6;
private JButton button1, button2;
private JPanel panel1, panel2,panel3,panel4,panel5,panel6;
private JTextField text1,text2,text3,text4;
private InputGoods inputGoods;
public InputGoods(String title){
inputGoods = this;
Font font = new Font("", Font.BOLD, 22);
label0=new JLabel("仓库进货",JLabel.CENTER);
label0.setFont(new Font("", Font.BOLD, 30));
label1=new JLabel("货物名称");
label1.setFont(font);
text1= new JTextField(10);
label2=new JLabel("货物价格");
label2.setFont(font);
text2= new JTextField(10);
label3=new JLabel("货物数量");
label3.setFont(font);
text3= new JTextField(10);
label4=new JLabel("存储仓库");
label4.setFont(font);
text4= new JTextField(10);
button1=new JButton("确认");
button1.setFont(font);
label5 =new JLabel(" ");
button2=new JButton("取消");
button2.setFont(font);
panel1=new JPanel();
panel1.add(label1);
panel1.add(text1);
panel1=new JPanel();
panel1.add(label1);
panel1.add(text1);
panel2=new JPanel();
panel2.add(label2);
panel2.add(text2);
panel3=new JPanel();
panel3.add(label3);
panel3.add(text3);
panel4=new JPanel();
panel4.add(label4);
panel4.add(text4);
panel5=new JPanel();
panel5.add(button1);
panel5.add(label5);
panel5.add(button2);
label6 =new JLabel(" ");
panel6=new JPanel();
panel6.add(panel1); panel6.add(panel2);
panel6.add(panel3); panel6.add(panel4);
panel6.add(label6); panel6.add(panel5);
this.setLayout(new BorderLayout());
this.add(label0,BorderLayout.NORTH);
this.add(panel6,BorderLayout.CENTER);
setSize(330, 400);
setLocationRelativeTo(null);
setTitle(title);
setVisible(true);
this.setLayout(new BorderLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//按关闭的操作
button1.addActionListener(new InputGoodsFunction());
button2.addActionListener(new ExitWarehouseButton());
}
public class ExitWarehouseButton implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
inputGoods.dispose();
}
}
public class InputGoodsFunction implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
String textFiled1 = text1.getText();
String textFiled2 = text2.getText();
String textFiled3 = text3.getText();
String textFiled4 = text4.getText();
if(textFiled1.equals("") || textFiled2.equals("") || textFiled3.equals("") || textFiled4.equals("")){
System.out.println("请填写完整的货物信息!");
/*
获取当前时间java.sql.Date
java.sql.Date sqlDate=new java.sql.Date(new java.util.Date().getTime());
System.out.println(sqlDate);
java.sql.Time sTime=new java.sql.Time(new java.util.Date().getTime());
System.out.println(sTime);
java.sql.Timestamp stp=new java.sql.Timestamp(new java.util.Date().getTime());
System.out.println(stp);*/
}else{
if(Login.warehouseMap.get(textFiled4) == null){
System.out.println("抱歉,该仓库不存在!");
}else{
try{
//存入数据库item_item表格
String sql = "INSERT INTO item_item(itemName,itemPrice,itemNumber,warehouseId,createdTime) VALUES(?,?,?,?,?)";
Main.stmt = Main.conn.prepareStatement(sql);
Main.stmt.setString(1, textFiled1);
Main.stmt.setDouble(2, Double.valueOf(textFiled2));
Main.stmt.setInt(3, Integer.valueOf(textFiled3));
Main.stmt.setInt(4, Login.warehouseMap.get(textFiled4).getWarehouseId());
Main.stmt.setTimestamp(5, new java.sql.Timestamp(new java.util.Date().getTime()));
Main.stmt.executeUpdate();
//更新itemMap
Login.itemMap.put(Login.itemCount+1, new Item(Login.itemCount+1, textFiled1, Double.valueOf(textFiled2), Integer.valueOf(textFiled3), Login.warehouseMap.get(textFiled4), Login.sdf.format(new java.util.Date()))); //切记,保证数据库是呈有序变化
Login.itemCount++;
System.out.println("入库成功.");
text1.setText("");
text2.setText("");
text3.setText("");
text4.setText("");
}catch (Exception e1){
System.out.println(e1);
}
}
}
}
}
}