查询功能更新模糊匹配及页面优化,数据库文件

master
金安民 2 months ago
parent 3ef04ccfaa
commit fef43d4e47

Binary file not shown.

@ -90,16 +90,34 @@ public class Main extends Application {
leftPanel.setStyle("-fx-background-color: #e8e8e8;");
leftPanel.setPrefWidth(200);
// 创建搜索框
TextField searchField = new TextField();
searchField.setPromptText("搜索...");
// 创建导航树
TreeView<String> navigationTree = createNavigationTree();
// 添加到左侧面板
leftPanel.getChildren().addAll(searchField, navigationTree);
VBox.setVgrow(navigationTree, Priority.ALWAYS);
// 创建功能按钮
Button inboundBtn = createFunctionButton("入库管理");
Button outboundBtn = createFunctionButton("出库管理");
Button inventoryBtn = createFunctionButton("库存查询");
Button goodsBtn = createFunctionButton("货物管理");
Button categoryBtn = createFunctionButton("分类管理");
Button reportBtn = createFunctionButton("库存报表");
Button logBtn = createFunctionButton("操作日志");
// 添加按钮点击事件
inboundBtn.setOnAction(e -> showInboundView());
outboundBtn.setOnAction(e -> showOutboundView());
inventoryBtn.setOnAction(e -> showInventoryView());
goodsBtn.setOnAction(e -> showGoodsManagementView());
categoryBtn.setOnAction(e -> showCategoryManagementView());
reportBtn.setOnAction(e -> showInventoryReportView());
logBtn.setOnAction(e -> showOperationLogView());
// 添加所有按钮到面板
leftPanel.getChildren().addAll(
inboundBtn,
outboundBtn,
inventoryBtn,
goodsBtn,
categoryBtn,
reportBtn,
logBtn
);
return leftPanel;
}
@ -177,17 +195,17 @@ public class Main extends Application {
MenuItem logItem = new MenuItem("操作日志");
reportMenu.getItems().addAll(inventoryReportItem, logItem);
// 为入库管理菜单项添加事件处理
// 添加所有菜单项的事件处理
inboundItem.setOnAction(e -> showInboundView());
// 为出库管理菜单项添加事件处理。
outboundItem.setOnAction(e -> showOutboundView());
// 为货物信息菜单项添加事件处理
queryItem.setOnAction(e -> showInventoryView());
goodsInfoItem.setOnAction(e -> showGoodsManagementView());
//为库存报表菜单项添加事件处理
categoryItem.setOnAction(e -> showCategoryManagementView());
inventoryReportItem.setOnAction(e -> showInventoryReportView());
logItem.setOnAction(e -> showOperationLogView());
// 退出按钮事件处理
exitItem.setOnAction(e -> Platform.exit());
menuBar.getMenus().addAll(systemMenu, inventoryMenu, goodsMenu, reportMenu);
return menuBar;
@ -298,4 +316,40 @@ public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
// 添加创建功能按钮的辅助方法
private Button createFunctionButton(String text) {
Button button = new Button(text);
button.setPrefWidth(180);
button.setStyle(
"-fx-background-color: #4CAF50;" +
"-fx-text-fill: white;" +
"-fx-font-size: 14px;" +
"-fx-padding: 8px 16px;" +
"-fx-cursor: hand"
);
// 添加鼠标悬停效果
button.setOnMouseEntered(e ->
button.setStyle(
"-fx-background-color: #45a049;" +
"-fx-text-fill: white;" +
"-fx-font-size: 14px;" +
"-fx-padding: 8px 16px;" +
"-fx-cursor: hand"
)
);
button.setOnMouseExited(e ->
button.setStyle(
"-fx-background-color: #4CAF50;" +
"-fx-text-fill: white;" +
"-fx-font-size: 14px;" +
"-fx-padding: 8px 16px;" +
"-fx-cursor: hand"
)
);
return button;
}
}

@ -123,10 +123,11 @@ public class InventoryView extends BorderPane {
try {
String url = "jdbc:sqlite:db/dbuml.db3";
try (Connection conn = DriverManager.getConnection(url)) {
// 查询当前库存
String sql = "SELECT * FROM warehouse WHERE goods_id = ?";
// 修改SQL查询语句使用LIKE实现模糊查询
String sql = "SELECT * FROM warehouse WHERE goods_id LIKE ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, goodsName);
// 在搜索词前后添加%实现模糊匹配
stmt.setString(1, "%" + goodsName + "%");
ResultSet rs = stmt.executeQuery();
// 获取当前表格中的数据
@ -158,7 +159,7 @@ public class InventoryView extends BorderPane {
found = true;
}
if (!found) {
showAlert("错误", "未找到该货物!");
showAlert("提示", "未找到匹配的货物!");
}
}
}

Loading…
Cancel
Save