java编程编码图书进销存管理系统的功能结构如图2-1所示。主要功能如下。 (1)采购管理:采购管理主要记录图书采购信息,管理员登录系统后,可依实际采购情况添加新的采购单,将图书信息入库。另外还可以按月查看历史采购信息。
时间: 2024-02-16 09:01:50 浏览: 73
java 图书进销存管理系统
5星 · 资源好评率100%
Java编程实现图书进销存管理系统的采购管理功能的代码如下:
1. 定义Purchase类,用于记录图书采购信息
```java
public class Purchase {
private String purchaseID; // 采购单号
private Date purchaseDate; // 采购日期
private String purchaser; // 采购员
private String supplier; // 供应商
private String bookName; // 图书名称
private int bookQuantity; // 图书数量
private double bookPrice; // 图书单价
// 构造函数
public Purchase(String purchaseID, Date purchaseDate, String purchaser, String supplier, String bookName, int bookQuantity, double bookPrice) {
this.purchaseID = purchaseID;
this.purchaseDate = purchaseDate;
this.purchaser = purchaser;
this.supplier = supplier;
this.bookName = bookName;
this.bookQuantity = bookQuantity;
this.bookPrice = bookPrice;
}
// getter和setter方法
public String getPurchaseID() {
return purchaseID;
}
public void setPurchaseID(String purchaseID) {
this.purchaseID = purchaseID;
}
public Date getPurchaseDate() {
return purchaseDate;
}
public void setPurchaseDate(Date purchaseDate) {
this.purchaseDate = purchaseDate;
}
public String getPurchaser() {
return purchaser;
}
public void setPurchaser(String purchaser) {
this.purchaser = purchaser;
}
public String getSupplier() {
return supplier;
}
public void setSupplier(String supplier) {
this.supplier = supplier;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public int getBookQuantity() {
return bookQuantity;
}
public void setBookQuantity(int bookQuantity) {
this.bookQuantity = bookQuantity;
}
public double getBookPrice() {
return bookPrice;
}
public void setBookPrice(double bookPrice) {
this.bookPrice = bookPrice;
}
}
```
2. 添加新的采购单
```java
public void addPurchase() {
// 获取采购单号等信息
String purchaseID = "PUR" + System.currentTimeMillis();
Date purchaseDate = new Date();
String purchaser = "管理员";
String supplier = "供应商A";
String bookName = "Java编程思想";
int bookQuantity = 10;
double bookPrice = 68.8;
// 将采购信息插入数据库
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = DBUtil.getConnection();
String sql = "INSERT INTO purchase(purchase_id, purchase_date, purchaser, supplier, book_name, book_quantity, book_price) VALUES (?, ?, ?, ?, ?, ?, ?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, purchaseID);
pstmt.setDate(2, new java.sql.Date(purchaseDate.getTime()));
pstmt.setString(3, purchaser);
pstmt.setString(4, supplier);
pstmt.setString(5, bookName);
pstmt.setInt(6, bookQuantity);
pstmt.setDouble(7, bookPrice);
int result = pstmt.executeUpdate();
if (result > 0) {
System.out.println("添加采购单成功!");
} else {
System.out.println("添加采购单失败!");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(conn, pstmt, null);
}
}
```
3. 按月查看历史采购信息
```java
public void viewPurchaseByMonth(int year, int month) {
// 查询数据库中指定月份的采购信息
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = DBUtil.getConnection();
String sql = "SELECT purchase_id, purchase_date, purchaser, supplier, book_name, book_quantity, book_price FROM purchase WHERE YEAR(purchase_date) = ? AND MONTH(purchase_date) = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, year);
pstmt.setInt(2, month);
rs = pstmt.executeQuery();
while (rs.next()) {
String purchaseID = rs.getString("purchase_id");
Date purchaseDate = rs.getDate("purchase_date");
String purchaser = rs.getString("purchaser");
String supplier = rs.getString("supplier");
String bookName = rs.getString("book_name");
int bookQuantity = rs.getInt("book_quantity");
double bookPrice = rs.getDouble("book_price");
System.out.println(purchaseID + "\t" + purchaseDate + "\t" + purchaser + "\t" + supplier + "\t" + bookName + "\t" + bookQuantity + "\t" + bookPrice);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(conn, pstmt, rs);
}
}
```
通过以上代码实现了图书进销存管理系统的采购管理功能,管理员可以添加新的采购单,并按月查看历史采购信息。
阅读全文