forked from p4vsywzlp/test
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.
106 lines
2.5 KiB
106 lines
2.5 KiB
package com.lingnan.supermarket.table;
|
|
|
|
import java.util.List;
|
|
import java.util.Vector;
|
|
|
|
|
|
|
|
import javax.swing.table.AbstractTableModel;
|
|
|
|
import com.lingnan.supermarket.dto.SupplierInf;
|
|
import com.lingnan.supermarket.dao.SupplierInfService;
|
|
import com.lingnan.supermarket.dao.impl.*;
|
|
|
|
|
|
public class SupplierTableModel extends AbstractTableModel{
|
|
|
|
// 定义表格列名数组
|
|
private String [] columnName = {"id","名称","地址","联系方式","邮箱"};
|
|
|
|
// 声明供应商信息服务接口实例
|
|
//private SupplierInfImpl supplierDao = new SupplierInfImpl();
|
|
private SupplierInfService supplierInfService = new SupplierInfImpl();
|
|
|
|
// 创建供应商信息对象
|
|
private SupplierInf supplierInf = new SupplierInf();
|
|
|
|
// 创建供应商信息列表
|
|
private Vector<SupplierInf> suppliers;
|
|
|
|
// 定义供应商ID变量
|
|
private int id=0;
|
|
|
|
// 查找全部供应商信息的方法
|
|
public void all() {
|
|
// 查找全部数据
|
|
suppliers = supplierInfService.findAllSupplierInf();
|
|
}
|
|
|
|
// 根据名称查找供应商信息的方法
|
|
public void Byname(SupplierInf supplierInf) {
|
|
// 根据名称查找供应商信息
|
|
suppliers = supplierInfService.findByNameSupplierInf(supplierInf);
|
|
|
|
}
|
|
|
|
// 重写获取行数的方法
|
|
@Override
|
|
public int getRowCount() {
|
|
// 返回供应商列表的大小
|
|
return suppliers.size();
|
|
}
|
|
|
|
// 重写获取列数的方法
|
|
@Override
|
|
public int getColumnCount() {
|
|
// 返回列名数组的长度
|
|
return columnName.length;
|
|
}
|
|
|
|
// 重写获取单元格值的方法
|
|
@Override
|
|
public Object getValueAt(int rowIndex, int columnIndex) {
|
|
// 获取指定行的供应商信息
|
|
SupplierInf prod = suppliers.get(rowIndex);
|
|
// 根据列索引返回相应的供应商信息属性
|
|
if(columnIndex==0) {
|
|
return prod.getId();
|
|
}else if(columnIndex==1) {
|
|
return prod.getName();
|
|
}else if(columnIndex==2) {
|
|
return prod.getAddress();
|
|
}else if(columnIndex==3) {
|
|
return prod.getContact();
|
|
}else if(columnIndex==4){
|
|
return prod.getEmail();
|
|
}
|
|
else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
// 重写获取列名的方法
|
|
@Override
|
|
public String getColumnName(int column) {
|
|
// 返回指定列索引的列名
|
|
return columnName[column];
|
|
}
|
|
|
|
/*
|
|
public int getId() {
|
|
return id;
|
|
}
|
|
public int getValueAt(int rowIndex){
|
|
SupplierInf supplierInf = suppliers.get(rowIndex);
|
|
id=suppliers.get(rowIndex).getId();
|
|
//System.out.println("rowIndex"+rowIndex);
|
|
//System.out.println("columnIndex"+columnIndex);
|
|
return supplierInf.getId();
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|