|
|
|
@ -1,99 +1,121 @@
|
|
|
|
|
package com.lingnan.supermarket.table;
|
|
|
|
|
package com.lingnan.supermarket.table; // 定义包名,表示这个类属于com.lingnan.supermarket.table包
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Vector;
|
|
|
|
|
import java.util.List; // 导入Java的List接口,用于存储集合数据
|
|
|
|
|
import java.util.Vector; // 导入Java的Vector类,用于存储表格数据
|
|
|
|
|
|
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
|
import javax.swing.table.AbstractTableModel;
|
|
|
|
|
import javax.swing.JFrame; // 导入Swing库中的JFrame类,用于创建窗口框架
|
|
|
|
|
import javax.swing.table.AbstractTableModel; // 导入Swing库中的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.*; // 导入impl包下的所有类,可能包含数据访问层的实现类
|
|
|
|
|
import com.lingnan.supermarket.dialog.InDialog; // 导入自定义的InDialog类,但在此代码中未使用
|
|
|
|
|
|
|
|
|
|
import com.lingnan.supermarket.dto.InOrder;
|
|
|
|
|
public class InTableModel extends AbstractTableModel{ // 定义一个名为InTableModel的类,该类继承自AbstractTableModel类,用于创建表格模型
|
|
|
|
|
|
|
|
|
|
import com.lingnan.supermarket.dto.Production;
|
|
|
|
|
import com.lingnan.supermarket.dto.User;
|
|
|
|
|
import com.lingnan.supermarket.dao.UserService;
|
|
|
|
|
import com.lingnan.supermarket.dao.impl.*;
|
|
|
|
|
import com.lingnan.supermarket.dialog.InDialog;
|
|
|
|
|
private String [] columnName = {"id","名称","数量","单价","价格","保质期","类别","供应商id"}; // 定义一个字符串数组,用于存储表格的列名
|
|
|
|
|
|
|
|
|
|
private productionImpl prodDao = new productionImpl(); // 创建productionImpl类的实例,用于访问商品数据
|
|
|
|
|
|
|
|
|
|
private Vector<Production> v; // 声明一个Vector类型的变量,用于存储商品列表
|
|
|
|
|
|
|
|
|
|
public class InTableModel extends AbstractTableModel{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String [] columnName = {"id","名称","数量","单价","价格","保质期","类别","供应商id"};
|
|
|
|
|
String id ; // 声明一个String类型的变量,用于存储id,但未初始化和使用
|
|
|
|
|
|
|
|
|
|
private productionImpl prodDao = new productionImpl();
|
|
|
|
|
|
|
|
|
|
private Vector<Production> v;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String id ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public InTableModel(Vector<Production> v) {
|
|
|
|
|
System.out.println("调用imtablemodel里面的构造函数");
|
|
|
|
|
this.v=v;
|
|
|
|
|
public InTableModel(Vector<Production> v) { // 定义一个名为InTableModel的构造函数,接收Vector<Production>类型的参数
|
|
|
|
|
System.out.println("调用imtablemodel里面的构造函数"); // 打印信息,表示构造函数被调用
|
|
|
|
|
this.v=v; // 将传入的参数v赋值给成员变量v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 定义一个方法getRowCount,用来获取集合v中的元素数量
|
|
|
|
|
public int getRowCount() {
|
|
|
|
|
return v.size();
|
|
|
|
|
return v.size(); // 返回集合v的大小,即元素的数量
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 定义一个方法getAllPrice,用来计算集合v中所有Production对象的价格总和
|
|
|
|
|
public Float getAllPrice() {
|
|
|
|
|
Float allPrice=(float) 0;
|
|
|
|
|
for(Production p:v) {
|
|
|
|
|
allPrice+=p.getPrice();
|
|
|
|
|
|
|
|
|
|
Float allPrice=(float) 0; // 初始化总价格为0.0
|
|
|
|
|
|
|
|
|
|
for(Production p:v) { // 遍历集合v中的每一个Production对象
|
|
|
|
|
allPrice+=p.getPrice(); // 将当前Production对象的价格加到总价格上
|
|
|
|
|
}
|
|
|
|
|
return allPrice;
|
|
|
|
|
|
|
|
|
|
return allPrice; // 返回计算出的总价格
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 重写getColumnCount方法,返回表格模型中的列数
|
|
|
|
|
@Override
|
|
|
|
|
public int getColumnCount() {
|
|
|
|
|
return columnName.length;
|
|
|
|
|
public int getColumnCount() {
|
|
|
|
|
return columnName.length; // 返回列名数组的长度,即列的数量
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 重写getValueAt方法,根据行索引和列索引获取表格模型中的值
|
|
|
|
|
@Override
|
|
|
|
|
public Object getValueAt(int rowIndex, int columnIndex) {
|
|
|
|
|
Production p = v.get(rowIndex);
|
|
|
|
|
/* System.out.println( "id="+users.get(rowIndex).getId());
|
|
|
|
|
System.out.println("rowIndex"+rowIndex);
|
|
|
|
|
System.out.println("columnIndex"+columnIndex);*/
|
|
|
|
|
id=p.getId();
|
|
|
|
|
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();
|
|
|
|
|
}else if(columnIndex==7) {
|
|
|
|
|
return p.getSupplyId();
|
|
|
|
|
}else {
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
Production p = v.get(rowIndex); // 根据行索引从集合v中获取对应的Production对象
|
|
|
|
|
/* 以下是注释掉的打印语句,用于调试,显示行索引、列索引和用户ID
|
|
|
|
|
System.out.println( "id="+users.get(rowIndex).getId());
|
|
|
|
|
System.out.println("rowIndex"+rowIndex);
|
|
|
|
|
System.out.println("columnIndex"+columnIndex); */
|
|
|
|
|
|
|
|
|
|
id=p.getId(); // 将Production对象的ID赋值给id变量
|
|
|
|
|
|
|
|
|
|
if(columnIndex==0) { // 如果列索引为0
|
|
|
|
|
return p.getId(); // 返回Production对象的ID
|
|
|
|
|
}else if(columnIndex==1) { // 如果列索引为1
|
|
|
|
|
return p.getName(); // 返回Production对象的名称
|
|
|
|
|
}else if(columnIndex==2) { // 如果列索引为2
|
|
|
|
|
return p.getSum(); // 返回Production对象的Sum属性
|
|
|
|
|
}else if(columnIndex==3) { // 如果列索引为3
|
|
|
|
|
return p.getInPrice(); // 返回Production对象的InPrice属性
|
|
|
|
|
}else if(columnIndex==4) { // 如果列索引为4
|
|
|
|
|
return p.getPrice(); // 返回Production对象的Price属性
|
|
|
|
|
}else if(columnIndex==5) { // 如果列索引为5
|
|
|
|
|
return p.getLife(); // 返回Production对象的Life属性
|
|
|
|
|
}else if(columnIndex==6) { // 如果列索引为6
|
|
|
|
|
return p.getName2()+p.getId2(); // 返回Production对象的Name2和Id2拼接的字符串
|
|
|
|
|
}else if(columnIndex==7) { // 如果列索引为7
|
|
|
|
|
return p.getSupplyId(); // 返回Production对象的SupplyId属性
|
|
|
|
|
}else { // 如果列索引不匹配上述任何情况
|
|
|
|
|
return null; // 返回null
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 定义一个方法getId,用来获取当前对象的ID属性值
|
|
|
|
|
public String getId() { /*返回要修改或删除的记录*/
|
|
|
|
|
return id;
|
|
|
|
|
|
|
|
|
|
return id; // 返回当前对象的id字段值
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 重写getColumnName方法,根据列索引返回对应的列名
|
|
|
|
|
@Override
|
|
|
|
|
public String getColumnName(int column) {
|
|
|
|
|
return columnName[column];
|
|
|
|
|
|
|
|
|
|
return columnName[column]; // 返回存储列名的数组中对应索引的列名
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|