You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
test/branch_zyx/My_branch/InTableModel.java

107 lines
3.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.lingnan.supermarket.table; // 声明当前类所在的包
import java.util.List; // 导入List接口用于表示列表
import java.util.Vector; // 导入Vector类用于实现可增长的对象数组
import javax.swing.JFrame; // 导入JFrame类用于创建窗口框架
import javax.swing.table.AbstractTableModel; // 导入AbstractTableModel类用于创建表格模型
import com.lingnan.supermarket.dto.InOrder; // 导入InOrder类表示进货订单的数据传输对象
import com.lingnan.supermarket.dto.Production; // 导入Production类表示产品数据传输对象
import com.lingnan.supermarket.dto.User; // 导入User类表示用户数据传输对象
import com.lingnan.supermarket.dao.UserService; // 导入UserService接口用于用户数据访问
import com.lingnan.supermarket.dao.impl.*; // 导入所有实现类,可能用于数据访问层的具体实现
import com.lingnan.supermarket.dialog.InDialog; // 导入InDialog类可能用于显示进货对话框
public class InTableModel extends AbstractTableModel{ // 定义一个类继承自AbstractTableModel用于创建进货表格数据模型
// 定义列名数组,用于表格的列标题
private String [] columnName = {"id","名称","数量","单价","价格","保质期","类别","供应商id"};
// 创建productionImpl实例用于操作产品数据
private productionImpl prodDao = new productionImpl();
// 声明一个Vector用于存储Production对象集合
private Vector<Production> v;
// 声明一个String变量用于存储id
String id ;
// 构造函数接收一个Vector<Production>类型的参数
public InTableModel(Vector<Production> v) {
System.out.println("调用InTableModel里面的构造函数"); // 打印日志信息
this.v=v; // 将传入的Vector<Production>赋值给类的成员变量v
}
// 获取表格的行数,即数据集合的大小
public int getRowCount() {
return v.size(); // 返回Vector v的大小
}
// 计算所有商品的总价格
public Float getAllPrice() {
Float allPrice=(float) 0; // 初始化总价格为0
for(Production p:v) { // 遍历Vector v中的所有Production对象
allPrice+=p.getPrice(); // 累加每个商品的价格
}
return allPrice; // 返回计算出的总价格
}
// 重写方法,获取表格的列数,即列名数组的长度
@Override
public int getColumnCount() {
return columnName.length; // 返回columnName数组的长度
}
// 重写方法,获取指定行和列的单元格值
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Production p = v.get(rowIndex); // 从Vector v中获取指定行的Production对象
id=p.getId(); // 将Production对象的id赋值给类的成员变量id
if(columnIndex==0) { // 判断列索引,并返回相应的值
return p.getId();
}else if(columnIndex==1) {
return p.getName(); // 返回商品名称
}else if(columnIndex==2) {
return p.getSum(); // 返回商品数量
}else if(columnIndex==3) {
return p.getInPrice(); // 返回商品进货单价
}else if(columnIndex==4) {
return p.getPrice(); // 返回商品价格
}else if(columnIndex==5) {
return p.getLife(); // 返回商品保质期
}else if(columnIndex==6) {
return p.getName2()+p.getId2(); // 返回商品类别和类别id的组合
}else if(columnIndex==7) {
return p.getSupplyId(); // 返回供应商id
}else {
return null; // 如果列索引不匹配返回null
}
}
// 获取要修改或删除的记录的id
public String getId() {
return id; // 返回类的成员变量id
}
// 重写方法,获取指定列的列名
@Override
public String getColumnName(int column) {
return columnName[column]; // 返回columnName数组中指定索引的值
}
}