master
王城 2 months ago
parent 2d7557e547
commit b66f340354

@ -1,9 +1,8 @@
<component name="libraryTable">
<library name="junit-4.12" type="repository">
<properties maven-id="junit:junit:4.13.1" />
<library name="junit-4.12">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.12.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

Binary file not shown.

@ -7,142 +7,69 @@ public class DML {
// 使用相对路径
private static final String URL = "jdbc:sqlite:db/dbuml.db3";
@Test
public void createInboundTable() {
public void create() {
try (Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement()) {
// 创建入库记录表
String sql = "CREATE TABLE IF NOT EXISTS inbound_records (" +
"id TEXT PRIMARY KEY NOT NULL," +
"goods_id TEXT NOT NULL," +
"quantity INTEGER NOT NULL," +
"supplier TEXT," +
"inbound_time TIMESTAMP," +
"operator TEXT," +
"remark TEXT" +
// 创建数据表的 SQL 语句
String sql = "create table if not exists xslist (" +
"id integer primary key AUTOINCREMENT not null ," +
"sno text not null," +
"sname text," +
"lx1 integer," +
"lx2 integer" +
");";
// 执行 SQL 语句
stmt.execute(sql);
System.out.println("入库记录表创建成功");
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void createWarehouseTable() {
try (Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement()) {
// 创建仓库存放数据表
String sql = "CREATE TABLE IF NOT EXISTS warehouse (" +
"id TEXT PRIMARY KEY NOT NULL," +
"goods_id TEXT NOT NULL," +
"goods_name TEXT NOT NULL," +
"quantity INTEGER NOT NULL," +
"operation_type TEXT NOT NULL," +
"operator TEXT," +
"operation_time TIMESTAMP," +
"supplier TEXT," +
"customer TEXT," +
"remark TEXT" +
");";
stmt.execute(sql);
System.out.println("仓库数据表创建成功");
System.out.println("数据表 创建成功");
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void createLogTable() {
try (Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement()) {
// 创建操作日志数据表
String sql = "CREATE TABLE IF NOT EXISTS operation_logs (" +
"日志id TEXT PRIMARY KEY NOT NULL," + //日志id
"operation_type TEXT NOT NULL," + // 操作类型(入库、出库、修改等)
"operation_target TEXT NOT NULL," + // 操作对象货物ID或名称
"operator TEXT," + // 操作人
"operation_time TIMESTAMP," + // 操作时间
"details TEXT" + // 操作详情
");";
stmt.execute(sql);
System.out.println("日志数据表创建成功");
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void clearTable() {
try (Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement()) {
String sql = "DELETE FROM 表名";
int result = stmt.executeUpdate(sql);
System.out.println("已清空数据表,删除了 " + result + " 条记录");
} catch (SQLException e) {
e.printStackTrace();
}
} //清空指定数据表数据
@Test
public void dropTable() {
public void deleteAll() {
try (Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement()) {
// 删除表的SQL 语句
String sql = "DROP TABLE IF EXISTS 表名";
// 删除所有记录的 SQL 语句
String sql = "DELETE FROM xslist";
// 执行 SQL 语句
stmt.execute(sql);
System.out.println(" 表删除成功");
int result = stmt.executeUpdate(sql);
System.out.println("删除了 " + result + " 条记录");
} catch (SQLException e) {
e.printStackTrace();
}
} //删除指定数据表
}
@Test
public void createGoodsTable() {
public void createInboundTable() {
try (Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement()) {
// 创建货物信息
String sql = "CREATE TABLE IF NOT EXISTS goods (" +
// 创建入库记录表
String sql = "CREATE TABLE IF NOT EXISTS inbound_records (" +
"id TEXT PRIMARY KEY NOT NULL," +
"name TEXT NOT NULL," +
"specification TEXT," +
"unit TEXT," +
"price REAL," +
"category TEXT," +
"quantity INTEGER," +
"remark TEXT," +
"goods_id TEXT NOT NULL," +
"quantity INTEGER NOT NULL," +
"supplier TEXT," +
"inbound_time TIMESTAMP," +
"operator TEXT," +
"supplier TEXT" +
"remark TEXT" +
");";
stmt.execute(sql);
System.out.println("货物信息表创建成功");
System.out.println("入库记录表创建成功");
} catch (Exception e) {
e.printStackTrace();
}
}
}

@ -45,10 +45,6 @@ public class Main extends Application {
primaryStage.setTitle("仓库管理系统");
primaryStage.show();
// 创建 goods 表
DML dml = new DML();
dml.createGoodsTable();
} catch (Exception e) {
e.printStackTrace();
}

@ -1,10 +1,6 @@
package model;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Goods {
private String id;
@ -57,48 +53,6 @@ public class Goods {
this.supplier = "";
}
public static void insertIntoDatabase(Connection conn, Goods goods) throws SQLException {
String sql = "INSERT INTO goods (id, name, specification, unit, price, category, quantity, remark, inbound_time, operator, supplier) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
try {
pstmt.setString(1, goods.getId());
} catch (SQLException e) {
throw new RuntimeException(e);
}
pstmt.setString(2, goods.getName());
pstmt.setString(3, goods.getSpecification());
pstmt.setString(4, goods.getUnit());
pstmt.setDouble(5, goods.getPrice());
pstmt.setString(6, goods.getCategory());
pstmt.setInt(7, goods.getQuantity());
pstmt.setString(8, goods.getRemark());
pstmt.setString(9, goods.getInboundTime() != null ? goods.getInboundTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) : null);
pstmt.setString(10, goods.getOperator());
pstmt.setString(11, goods.getSupplier());
pstmt.executeUpdate();
}
}
public static void updateInDatabase(Connection conn, Goods goods) throws SQLException {
String sql = "UPDATE goods SET name = ?, specification = ?, unit = ?, price = ?, category = ?, " +
"quantity = ?, remark = ?, inbound_time = ?, operator = ?, supplier = ? WHERE id = ?";
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, goods.getName());
pstmt.setString(2, goods.getSpecification());
pstmt.setString(3, goods.getUnit());
pstmt.setDouble(4, goods.getPrice());
pstmt.setString(5, goods.getCategory());
pstmt.setInt(6, goods.getQuantity());
pstmt.setString(7, goods.getRemark());
pstmt.setString(8, goods.getInboundTime() != null ? goods.getInboundTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) : null);
pstmt.setString(9, goods.getOperator());
pstmt.setString(10, goods.getSupplier());
pstmt.setString(11, goods.getId());
pstmt.executeUpdate();
}
}
// Getters and Setters
public String getId() { return id; }
public void setId(String id) { this.id = id; }

@ -1,81 +1,15 @@
package util;
import java.sql.*;
import java.time.LocalDateTime;
import model.InboundRecord;
import model.OutboundRecord;
import model.OperationLog;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DatabaseUtil {
private static final String URL = "jdbc:sqlite:db/dbuml.db3";
// 记录入库操作
public static void recordInbound(InboundRecord record) {
try (Connection conn = DriverManager.getConnection(URL)) {
String sql = "INSERT INTO warehouse (id, goods_id, goods_name, quantity, operation_type, " +
"operator, operation_time, supplier, remark) " +
"VALUES (?, ?, ?, ?, 'IN', ?, ?, ?, ?)";
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, record.getId());
pstmt.setString(2, record.getGoodsId());
pstmt.setString(3, ""); // 需要从Goods获取名称
pstmt.setInt(4, record.getQuantity());
pstmt.setString(5, record.getOperator());
pstmt.setString(6, record.getInboundTime().toString());
pstmt.setString(7, record.getSupplier());
pstmt.setString(8, record.getRemark());
pstmt.executeUpdate();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
// 记录出库操作
public static void recordOutbound(OutboundRecord record) {
try (Connection conn = DriverManager.getConnection(URL)) {
String sql = "INSERT INTO warehouse (id, goods_id, goods_name, quantity, operation_type, " +
"operator, operation_time, customer, remark) " +
"VALUES (?, ?, ?, ?, 'OUT', ?, ?, ?, ?)";
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, record.getId());
pstmt.setString(2, record.getGoodsId());
pstmt.setString(3, ""); // 需要从Goods获取名称
pstmt.setInt(4, record.getQuantity());
pstmt.setString(5, record.getOperator());
pstmt.setString(6, record.getOutboundTime().toString());
pstmt.setString(7, record.getCustomer());
pstmt.setString(8, record.getRemark());
pstmt.executeUpdate();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
// 记录操作日志
public static void recordOperationLog(OperationLog log) {
try (Connection conn = DriverManager.getConnection(URL)) {
String sql = "INSERT INTO operation_logs (id, operation_type, operation_target, " +
"operator, operation_time, details) " +
"VALUES (?, ?, ?, ?, ?, ?)";
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, log.getId());
pstmt.setString(2, log.getOperationType());
pstmt.setString(3, log.getOperationTarget());
pstmt.setString(4, log.getOperator());
pstmt.setString(5, log.getOperationTime().toString());
pstmt.setString(6, log.getDetails());
pstmt.executeUpdate();
}
} catch (SQLException e) {
e.printStackTrace();
}
public static Connection getConnection() throws SQLException {
return DriverManager.getConnection(URL);
}
// ... 其他代码保持不变 ...
}

@ -5,6 +5,7 @@ import javafx.collections.ObservableList;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.layout.AnchorPane;
import model.DataManager;
import model.Goods;
public class CategoryManagementView extends AnchorPane {

@ -6,14 +6,12 @@ import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.control.cell.PropertyValueFactory;
import model.DataManager;
import model.Goods;
import model.InventoryManager;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.time.format.DateTimeFormatter;
import java.util.List;
public class GoodsManagementView extends BorderPane {
@ -66,6 +64,7 @@ public class GoodsManagementView extends BorderPane {
Label idLabel = new Label("货物ID");
idField = new TextField();
idField.setPromptText("请输入货物ID");
idField.setEditable(false); // ID 不可编辑
Label nameLabel = new Label("货物名称:");
nameField = new TextField();
@ -120,7 +119,7 @@ public class GoodsManagementView extends BorderPane {
buttonBox.setAlignment(Pos.CENTER_RIGHT);
buttonBox.setPadding(new Insets(10, 0, 0, 0));
Button saveButton = new Button("保存");
Button saveButton = new Button("修改");
saveButton.setOnAction(e -> handleSave());
Button clearButton = new Button("清空");
@ -176,34 +175,7 @@ public class GoodsManagementView extends BorderPane {
}
private void loadGoodsData() {
String url = "jdbc:sqlite:db/dbuml.db3";
List<Goods> goodsList = new ArrayList<>();
try (Connection conn = DriverManager.getConnection(url)) {
String sql = "SELECT * FROM goods";
try (Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
while (rs.next()) {
Goods goods = new Goods(
rs.getString("id"),
rs.getString("name"),
rs.getString("specification"),
rs.getString("unit"),
rs.getDouble("price"),
rs.getString("category"),
rs.getInt("quantity"),
rs.getString("remark")
);
goods.setInboundTime(LocalDateTime.parse(rs.getString("inbound_time")));
goods.setOperator(rs.getString("operator"));
goods.setSupplier(rs.getString("supplier"));
goodsList.add(goods);
}
}
} catch (Exception e) {
e.printStackTrace();
showAlert("错误", "加载货物信息失败:" + e.getMessage());
}
List<Goods> goodsList = DataManager.getInstance().getAllGoods();
tableView.setItems(FXCollections.observableArrayList(goodsList));
}
@ -251,24 +223,20 @@ public class GoodsManagementView extends BorderPane {
// 查找货物对象
Goods existingGoods = DataManager.getInstance().getGoods(id);
if (existingGoods == null) {
// 插入新货物
Goods newGoods = new Goods(id, name, specification, unit, price, category, quantity, "");
newGoods.setInboundTime(LocalDateTime.now());
newGoods.setOperator("当前用户");
DataManager.getInstance().addGoodsToDatabase(newGoods);
} else {
// 更新现有货物
existingGoods.setName(name);
existingGoods.setSpecification(specification);
existingGoods.setUnit(unit);
existingGoods.setPrice(price);
existingGoods.setCategory(category);
existingGoods.setQuantity(quantity);
DataManager.getInstance().updateGoodsInDatabase(existingGoods);
showAlert("错误", "货物ID不存在");
return;
}
// 更新货物对象
existingGoods.setName(name);
existingGoods.setSpecification(specification);
existingGoods.setUnit(unit);
existingGoods.setPrice(price);
existingGoods.setCategory(category);
existingGoods.setQuantity(quantity);
// 更新表格
loadGoodsData();
tableView.refresh();
// 清空输入
handleClear();
@ -277,7 +245,6 @@ public class GoodsManagementView extends BorderPane {
} catch (Exception e) {
showAlert("错误", "保存失败:" + e.getMessage());
e.printStackTrace(); // 添加堆栈跟踪以便调试
}
}
@ -308,6 +275,4 @@ public class GoodsManagementView extends BorderPane {
alert.setContentText(content);
alert.showAndWait();
}
}

@ -6,9 +6,13 @@ import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.control.cell.PropertyValueFactory;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import model.InboundRecord;
import model.DataManager;
import model.Goods;
import javafx.collections.FXCollections;
import java.util.List;
import java.util.stream.Collectors;
import java.sql.*;
public class InboundView extends BorderPane {

@ -1,12 +1,13 @@
package view;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.control.cell.PropertyValueFactory;
import model.InventoryReport;
import model.DataManager;
import java.util.List;
public class InventoryReportView extends BorderPane {

@ -5,6 +5,7 @@ import javafx.geometry.Insets;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.control.cell.PropertyValueFactory;
import model.DataManager;
import model.OperationLog;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@ -6,8 +6,13 @@ import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.control.cell.PropertyValueFactory;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import model.OutboundRecord;
import model.DataManager;
import model.Goods;
import javafx.collections.FXCollections;
import java.util.List;
import java.util.stream.Collectors;
public class OutboundView extends BorderPane {

Loading…
Cancel
Save