|
|
|
@ -13,6 +13,8 @@ import model.InventoryManager;
|
|
|
|
|
import java.sql.*;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class InventoryView extends BorderPane {
|
|
|
|
|
private TextField goodsField;
|
|
|
|
@ -88,15 +90,33 @@ public class InventoryView extends BorderPane {
|
|
|
|
|
goodsField = new TextField();
|
|
|
|
|
goodsField.setPromptText("请输入货物名称");
|
|
|
|
|
|
|
|
|
|
basicInfo.addRow(0, goodsLabel, goodsField);
|
|
|
|
|
// 第一行:操作员
|
|
|
|
|
Label operatorLabel = new Label("操作员:");
|
|
|
|
|
TextField operatorField = new TextField();
|
|
|
|
|
operatorField.setPromptText("请输入操作员");
|
|
|
|
|
|
|
|
|
|
// 第一行:供应商
|
|
|
|
|
Label supplierLabel = new Label("供应商:");
|
|
|
|
|
TextField supplierField = new TextField();
|
|
|
|
|
supplierField.setPromptText("请输入供应商");
|
|
|
|
|
|
|
|
|
|
basicInfo.addRow(0, goodsLabel, goodsField, operatorLabel, operatorField, supplierLabel, supplierField);
|
|
|
|
|
|
|
|
|
|
// 设置列宽
|
|
|
|
|
ColumnConstraints column1 = new ColumnConstraints();
|
|
|
|
|
column1.setMinWidth(80);
|
|
|
|
|
ColumnConstraints column2 = new ColumnConstraints();
|
|
|
|
|
column2.setMinWidth(200);
|
|
|
|
|
ColumnConstraints column3 = new ColumnConstraints();
|
|
|
|
|
column3.setMinWidth(80);
|
|
|
|
|
ColumnConstraints column4 = new ColumnConstraints();
|
|
|
|
|
column4.setMinWidth(200);
|
|
|
|
|
ColumnConstraints column5 = new ColumnConstraints();
|
|
|
|
|
column5.setMinWidth(80);
|
|
|
|
|
ColumnConstraints column6 = new ColumnConstraints();
|
|
|
|
|
column6.setMinWidth(200);
|
|
|
|
|
|
|
|
|
|
basicInfo.getColumnConstraints().addAll(column1, column2);
|
|
|
|
|
basicInfo.getColumnConstraints().addAll(column1, column2, column3, column4, column5, column6);
|
|
|
|
|
|
|
|
|
|
// 操作按钮
|
|
|
|
|
HBox buttonBox = new HBox(10);
|
|
|
|
@ -104,7 +124,7 @@ public class InventoryView extends BorderPane {
|
|
|
|
|
buttonBox.setPadding(new Insets(10, 0, 0, 0));
|
|
|
|
|
|
|
|
|
|
Button queryButton = new Button("查询库存");
|
|
|
|
|
queryButton.setOnAction(e -> handleQuery());
|
|
|
|
|
queryButton.setOnAction(e -> handleQuery(operatorField.getText(), supplierField.getText()));
|
|
|
|
|
|
|
|
|
|
buttonBox.getChildren().add(queryButton);
|
|
|
|
|
|
|
|
|
@ -112,10 +132,11 @@ public class InventoryView extends BorderPane {
|
|
|
|
|
return topArea;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleQuery() {
|
|
|
|
|
private void handleQuery(String operator, String supplier) {
|
|
|
|
|
String goodsName = goodsField.getText().trim();
|
|
|
|
|
if (goodsName.isEmpty()) {
|
|
|
|
|
showAlert("错误", "请输入货物名称!");
|
|
|
|
|
|
|
|
|
|
if (goodsName.isEmpty() && operator.isEmpty() && supplier.isEmpty()) {
|
|
|
|
|
showAlert("错误", "请输入至少一个查询条件!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -123,34 +144,51 @@ public class InventoryView extends BorderPane {
|
|
|
|
|
try {
|
|
|
|
|
String url = "jdbc:sqlite:db/dbuml.db3";
|
|
|
|
|
try (Connection conn = DriverManager.getConnection(url)) {
|
|
|
|
|
// 修改SQL查询语句,使用LIKE实现模糊查询
|
|
|
|
|
String sql = "SELECT * FROM warehouse WHERE goods_id LIKE ?";
|
|
|
|
|
StringBuilder sqlBuilder = new StringBuilder("SELECT * FROM warehouse WHERE 1=1");
|
|
|
|
|
List<Object> params = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
if (!goodsName.isEmpty()) {
|
|
|
|
|
sqlBuilder.append(" AND goods_id LIKE ?");
|
|
|
|
|
params.add("%" + goodsName + "%");
|
|
|
|
|
}
|
|
|
|
|
if (!operator.isEmpty()) {
|
|
|
|
|
sqlBuilder.append(" AND operator LIKE ?");
|
|
|
|
|
params.add("%" + operator + "%");
|
|
|
|
|
}
|
|
|
|
|
if (!supplier.isEmpty()) {
|
|
|
|
|
sqlBuilder.append(" AND supplier LIKE ?");
|
|
|
|
|
params.add("%" + supplier + "%");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String sql = sqlBuilder.toString();
|
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
|
|
|
// 在搜索词前后添加%实现模糊匹配
|
|
|
|
|
stmt.setString(1, "%" + goodsName + "%");
|
|
|
|
|
for (int i = 0; i < params.size(); i++) {
|
|
|
|
|
stmt.setString(i + 1, (String) params.get(i));
|
|
|
|
|
}
|
|
|
|
|
ResultSet rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
// 获取当前表格中的数据
|
|
|
|
|
ObservableList<InventoryManager> existingData = tableView.getItems();
|
|
|
|
|
// 清空现有数据
|
|
|
|
|
existingData.clear();
|
|
|
|
|
|
|
|
|
|
boolean found = false;
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
String id = rs.getString("id");
|
|
|
|
|
String goodsId = rs.getString("goods_id");
|
|
|
|
|
int quantity = rs.getInt("quantity");
|
|
|
|
|
String supplier = rs.getString("supplier");
|
|
|
|
|
String operator = rs.getString("operator");
|
|
|
|
|
String supplierRs = rs.getString("supplier");
|
|
|
|
|
String operatorRs = rs.getString("operator");
|
|
|
|
|
String remark = rs.getString("remark");
|
|
|
|
|
|
|
|
|
|
InventoryManager record = new InventoryManager(
|
|
|
|
|
id,
|
|
|
|
|
goodsId,
|
|
|
|
|
quantity,
|
|
|
|
|
supplier,
|
|
|
|
|
supplierRs,
|
|
|
|
|
null, // 入库时间为 null
|
|
|
|
|
null, // 出库时间为 null
|
|
|
|
|
operator,
|
|
|
|
|
operatorRs,
|
|
|
|
|
remark,
|
|
|
|
|
null // 客户为 null
|
|
|
|
|
);
|
|
|
|
|