|
|
|
@ -13,6 +13,7 @@ import model.Goods;
|
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.sql.*;
|
|
|
|
|
|
|
|
|
|
public class InboundView extends BorderPane {
|
|
|
|
|
|
|
|
|
@ -25,6 +26,7 @@ public class InboundView extends BorderPane {
|
|
|
|
|
|
|
|
|
|
public InboundView() {
|
|
|
|
|
initializeUI();
|
|
|
|
|
loadInboundRecords();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initializeUI() {
|
|
|
|
@ -181,12 +183,34 @@ public class InboundView extends BorderPane {
|
|
|
|
|
|
|
|
|
|
// 创建入库记录
|
|
|
|
|
String id = "IN" + System.currentTimeMillis();
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
|
|
|
|
|
// 修改数据库连接为相对路径
|
|
|
|
|
String url = "jdbc:sqlite:db/dbuml.db3";
|
|
|
|
|
try (Connection conn = DriverManager.getConnection(url)) {
|
|
|
|
|
String sql = "INSERT INTO inbound_records (id, goods_id, quantity, supplier, inbound_time, operator, remark) " +
|
|
|
|
|
"VALUES (?, ?, ?, ?, ?, ?, ?)";
|
|
|
|
|
|
|
|
|
|
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
|
|
|
|
pstmt.setString(1, id);
|
|
|
|
|
pstmt.setString(2, goodsName);
|
|
|
|
|
pstmt.setInt(3, quantity);
|
|
|
|
|
pstmt.setString(4, supplier);
|
|
|
|
|
pstmt.setString(5, now.toString());
|
|
|
|
|
pstmt.setString(6, "当前用户");
|
|
|
|
|
pstmt.setString(7, remark);
|
|
|
|
|
|
|
|
|
|
pstmt.executeUpdate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建记录对象并添加到表格
|
|
|
|
|
InboundRecord record = new InboundRecord(
|
|
|
|
|
id,
|
|
|
|
|
goodsName,
|
|
|
|
|
quantity,
|
|
|
|
|
supplier,
|
|
|
|
|
LocalDateTime.now(),
|
|
|
|
|
now,
|
|
|
|
|
"当前用户",
|
|
|
|
|
remark
|
|
|
|
|
);
|
|
|
|
@ -194,21 +218,22 @@ public class InboundView extends BorderPane {
|
|
|
|
|
// 添加到表格
|
|
|
|
|
tableView.getItems().add(record);
|
|
|
|
|
|
|
|
|
|
// 更新总计
|
|
|
|
|
// <EFBFBD><EFBFBD>新总计
|
|
|
|
|
updateTotal();
|
|
|
|
|
|
|
|
|
|
// 清空输入
|
|
|
|
|
handleClear();
|
|
|
|
|
|
|
|
|
|
showAlert("成功", "入库记录已保存!");
|
|
|
|
|
|
|
|
|
|
// 在handleSave方法中添加日志记录
|
|
|
|
|
// 添加操作日志
|
|
|
|
|
String details = String.format("入库货物:%s,数量:%d,供应商:%s",
|
|
|
|
|
goodsName, quantity, supplier);
|
|
|
|
|
DataManager.getInstance().addOperationLog("入库", goodsName, "当前用户", details);
|
|
|
|
|
|
|
|
|
|
showAlert("成功", "入库记录已保存!");
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
showAlert("错误", "保存失败:" + e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -226,4 +251,31 @@ public class InboundView extends BorderPane {
|
|
|
|
|
alert.setContentText(content);
|
|
|
|
|
alert.showAndWait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 添加加载数据的方法
|
|
|
|
|
private void loadInboundRecords() {
|
|
|
|
|
String url = "jdbc:sqlite:db/dbuml.db3";
|
|
|
|
|
try (Connection conn = DriverManager.getConnection(url)) {
|
|
|
|
|
String sql = "SELECT * FROM inbound_records ORDER BY inbound_time DESC";
|
|
|
|
|
try (Statement stmt = conn.createStatement();
|
|
|
|
|
ResultSet rs = stmt.executeQuery(sql)) {
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
InboundRecord record = new InboundRecord(
|
|
|
|
|
rs.getString("id"),
|
|
|
|
|
rs.getString("goods_id"),
|
|
|
|
|
rs.getInt("quantity"),
|
|
|
|
|
rs.getString("supplier"),
|
|
|
|
|
LocalDateTime.parse(rs.getString("inbound_time")),
|
|
|
|
|
rs.getString("operator"),
|
|
|
|
|
rs.getString("remark")
|
|
|
|
|
);
|
|
|
|
|
tableView.getItems().add(record);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
showAlert("错误", "加载入库记录失败:" + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|