From 80e4f7914c9a9b831551f7a86ca8ed167c92b785 Mon Sep 17 00:00:00 2001
From: ljc <3413625611@qq.com>
Date: Tue, 26 Nov 2024 15:59:44 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=AE=9E?=
=?UTF-8?q?=E6=97=B6=E6=97=B6=E9=97=B4getCurrenTime()?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/uiDesigner.xml | 124 +++++++++++++++++++
src/Main.java | 51 ++++++--
src/model/OutboundRecord.java | 82 +++++++++++++
src/view/OutboundView.java | 224 ++++++++++++++++++++++++++++++++++
4 files changed, 472 insertions(+), 9 deletions(-)
create mode 100644 .idea/uiDesigner.xml
create mode 100644 src/model/OutboundRecord.java
create mode 100644 src/view/OutboundView.java
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Main.java b/src/Main.java
index 59702d3..1b7c51f 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -1,12 +1,14 @@
package src;
import javafx.application.Application;
+import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import view.InboundView;
+import view.OutboundView;
public class Main extends Application {
@@ -92,16 +94,31 @@ public class Main extends Application {
Label statusLabel = new Label("就绪");
Label userLabel = new Label("当前用户:管理员");
- Label timeLabel = new Label("2024-03-14 10:30:00");
-
+ Label timeLabel = new Label(getCurrentTime());
+
+
Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);
statusBar.getChildren().addAll(statusLabel, spacer, userLabel, timeLabel);
-
+ // 动态更新时间
+ Thread timeThread = new Thread(() -> {
+ while (true) {
+ try {
+ Thread.sleep(1000);
+ Platform.runLater(() -> timeLabel.setText(getCurrentTime()));
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ timeThread.setDaemon(true);
+ timeThread.start();
return statusBar;
}
-
+ private String getCurrentTime() {
+ return java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+ }
private MenuBar createMenuBar() {
MenuBar menuBar = new MenuBar();
@@ -132,7 +149,10 @@ public class Main extends Application {
// 为入库管理菜单项添加事件处理
inboundItem.setOnAction(e -> showInboundView());
-
+
+ // 为出库管理菜单项添加事件处理
+ outboundItem.setOnAction(e -> showOutboundView());
+
menuBar.getMenus().addAll(systemMenu, inventoryMenu, goodsMenu, reportMenu);
return menuBar;
}
@@ -170,11 +190,21 @@ public class Main extends Application {
// 为导航树添加事件处理
tree.setOnMouseClicked(event -> {
TreeItem item = tree.getSelectionModel().getSelectedItem();
- if (item != null && item.getValue().equals("入库管理")) {
- showInboundView();
+ if (item != null) {
+ switch (item.getValue()){
+ case "入库管理":
+ showInboundView();
+ break;
+ case "出库管理":
+ showOutboundView();
+ break;
+ default:
+ // 其他菜单项的处理逻辑
+ break;
+ }
}
});
-
+
return tree;
}
@@ -182,7 +212,10 @@ public class Main extends Application {
InboundView inboundView = new InboundView();
contentArea.setCenter(inboundView);
}
-
+ private void showOutboundView() {
+ OutboundView outboundView = new OutboundView();
+ contentArea.setCenter(outboundView);
+ }
public static void main(String[] args) {
launch(args);
}
diff --git a/src/model/OutboundRecord.java b/src/model/OutboundRecord.java
new file mode 100644
index 0000000..30bf39d
--- /dev/null
+++ b/src/model/OutboundRecord.java
@@ -0,0 +1,82 @@
+
+package model;
+
+import java.time.LocalDateTime;
+
+public class OutboundRecord {
+ private String id;
+ private String goodsId;
+ private int quantity;
+ private String customer;
+ private LocalDateTime outboundTime;
+ private String operator;
+ private String remark;
+
+ public OutboundRecord(String id, String goodsId, int quantity, String customer,
+ LocalDateTime outboundTime, String operator, String remark) {
+ this.id = id;
+ this.goodsId = goodsId;
+ this.quantity = quantity;
+ this.customer = customer;
+ this.outboundTime = outboundTime;
+ this.operator = operator;
+ this.remark = remark;
+ }
+
+ // Getters and Setters
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getGoodsId() {
+ return goodsId;
+ }
+
+ public void setGoodsId(String goodsId) {
+ this.goodsId = goodsId;
+ }
+
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public void setQuantity(int quantity) {
+ this.quantity = quantity;
+ }
+
+ public String getCustomer() {
+ return customer;
+ }
+
+ public void setCustomer(String customer) {
+ this.customer = customer;
+ }
+
+ public LocalDateTime getOutboundTime() {
+ return outboundTime;
+ }
+
+ public void setOutboundTime(LocalDateTime outboundTime) {
+ this.outboundTime = outboundTime;
+ }
+
+ public String getOperator() {
+ return operator;
+ }
+
+ public void setOperator(String operator) {
+ this.operator = operator;
+ }
+
+ public String getRemark() {
+ return remark;
+ }
+
+ public void setRemark(String remark) {
+ this.remark = remark;
+ }
+}
\ No newline at end of file
diff --git a/src/view/OutboundView.java b/src/view/OutboundView.java
new file mode 100644
index 0000000..6a3d766
--- /dev/null
+++ b/src/view/OutboundView.java
@@ -0,0 +1,224 @@
+package view;
+
+import javafx.geometry.Insets;
+import javafx.geometry.Pos;
+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 {
+
+ private TextField goodsField;
+ private TextField customerField;
+ private TextField quantityField;
+ private TextField remarkField;
+ private TableView tableView;
+ private Label totalValue;
+
+ public OutboundView() {
+ initializeUI();
+ }
+
+ private void initializeUI() {
+ // 顶部操作区域
+ VBox topArea = createTopArea();
+ setTop(topArea);
+
+ // 中间表格区域
+ tableView = createTableView();
+ setCenter(tableView);
+
+ // 底部汇总区域
+ HBox bottomArea = createBottomArea();
+ setBottom(bottomArea);
+ }
+
+ private VBox createTopArea() {
+ VBox topArea = new VBox(10);
+ topArea.setPadding(new Insets(10));
+
+ // 第一行:基本信息
+ GridPane basicInfo = new GridPane();
+ basicInfo.setHgap(10);
+ basicInfo.setVgap(10);
+
+ Label goodsLabel = new Label("货物名称:");
+ goodsField = new TextField();
+ goodsField.setPromptText("请输入货物名称");
+
+ Label customerLabel = new Label("客户:");
+ customerField = new TextField();
+ customerField.setPromptText("请输入客户");
+
+ basicInfo.addRow(0, goodsLabel, goodsField, customerLabel, customerField);
+
+ // 第二行:数量和备注
+ Label quantityLabel = new Label("数量:");
+ quantityField = new TextField();
+ quantityField.setPromptText("请输入数量");
+
+ Label remarkLabel = new Label("备注:");
+ remarkField = new TextField();
+ remarkField.setPromptText("请输入备注信息");
+
+ basicInfo.addRow(1, quantityLabel, quantityField, remarkLabel, remarkField);
+
+ // 设置列宽
+ 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);
+
+ basicInfo.getColumnConstraints().addAll(column1, column2, column3, column4);
+
+ // 操作按钮
+ HBox buttonBox = new HBox(10);
+ buttonBox.setAlignment(Pos.CENTER_RIGHT);
+ buttonBox.setPadding(new Insets(10, 0, 0, 0));
+
+ Button saveButton = new Button("保存");
+ saveButton.setOnAction(e -> handleSave());
+
+ Button clearButton = new Button("清空");
+ clearButton.setOnAction(e -> handleClear());
+
+ buttonBox.getChildren().addAll(saveButton, clearButton);
+
+ topArea.getChildren().addAll(basicInfo, buttonBox);
+ return topArea;
+ }
+
+ private TableView createTableView() {
+ TableView table = new TableView<>();
+
+ TableColumn idCol = new TableColumn<>("出库单号");
+ idCol.setCellValueFactory(new PropertyValueFactory<>("id"));
+
+ TableColumn goodsCol = new TableColumn<>("货物名称");
+ goodsCol.setCellValueFactory(new PropertyValueFactory<>("goodsId"));
+
+ TableColumn quantityCol = new TableColumn<>("数量");
+ quantityCol.setCellValueFactory(new PropertyValueFactory<>("quantity"));
+
+ TableColumn customerCol = new TableColumn<>("客户");
+ customerCol.setCellValueFactory(new PropertyValueFactory<>("customer"));
+
+ TableColumn timeCol = new TableColumn<>("出库时间");
+ timeCol.setCellValueFactory(new PropertyValueFactory<>("outboundTime"));
+
+ TableColumn operatorCol = new TableColumn<>("操作员");
+ operatorCol.setCellValueFactory(new PropertyValueFactory<>("operator"));
+
+ TableColumn remarkCol = new TableColumn<>("备注");
+ remarkCol.setCellValueFactory(new PropertyValueFactory<>("remark"));
+
+ table.getColumns().addAll(idCol, goodsCol, quantityCol, customerCol,
+ timeCol, operatorCol, remarkCol);
+
+ table.getItems().addListener((javafx.collections.ListChangeListener.Change extends OutboundRecord> c) -> {
+ updateTotal();
+ });
+
+ return table;
+ }
+
+ private HBox createBottomArea() {
+ HBox bottomArea = new HBox(10);
+ bottomArea.setPadding(new Insets(10));
+ bottomArea.setAlignment(Pos.CENTER_RIGHT);
+
+ Label totalLabel = new Label("出库总数量:");
+ totalValue = new Label("0");
+ Label unitLabel = new Label("件");
+
+ bottomArea.getChildren().addAll(totalLabel, totalValue, unitLabel);
+ return bottomArea;
+ }
+
+ private void updateTotal() {
+ int total = tableView.getItems().stream()
+ .mapToInt(OutboundRecord::getQuantity)
+ .sum();
+ totalValue.setText(String.valueOf(total));
+ }
+
+ private void handleSave() {
+ try {
+ String goodsName = goodsField.getText().trim();
+ String customer = customerField.getText().trim();
+ String quantityText = quantityField.getText().trim();
+ String remark = remarkField.getText().trim();
+
+ // 输入验证
+ if (goodsName.isEmpty() || customer.isEmpty() || quantityText.isEmpty()) {
+ showAlert("错误", "请填写完整的出库信息!");
+ return;
+ }
+
+ int quantity;
+ try {
+ quantity = Integer.parseInt(quantityText);
+ if (quantity <= 0) {
+ showAlert("错误", "数量必须大于0!");
+ return;
+ }
+ } catch (NumberFormatException e) {
+ showAlert("错误", "请输入有效的数量!");
+ return;
+ }
+
+ // 创建出库记录
+ String id = "OUT" + System.currentTimeMillis();
+ OutboundRecord record = new OutboundRecord(
+ id,
+ goodsName,
+ quantity,
+ customer,
+ LocalDateTime.now(),
+ "当前用户",
+ remark
+ );
+
+ // 添加到表格
+ tableView.getItems().add(record);
+
+ // 更新总计
+ updateTotal();
+
+ // 清空输入
+ handleClear();
+
+ showAlert("成功", "出库记录已保存!");
+
+ } catch (Exception e) {
+ showAlert("错误", "保存失败:" + e.getMessage());
+ }
+ }
+
+ private void handleClear() {
+ goodsField.clear();
+ customerField.clear();
+ quantityField.clear();
+ remarkField.clear();
+ }
+
+ private void showAlert(String title, String content) {
+ Alert alert = new Alert(Alert.AlertType.INFORMATION);
+ alert.setTitle(title);
+ alert.setHeaderText(null);
+ alert.setContentText(content);
+ alert.showAndWait();
+ }
+}