developer
HouXinyu 9 months ago
parent ad2a162593
commit 3716d82083

@ -19,73 +19,73 @@ public class productionImpl implements productionService {
public Vector<Production> findAllproduction() { public Vector<Production> findAllproduction() {
Vector<Production> productions = new Vector<Production>(); Vector<Production> productions = new Vector<Production>();
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
String SQL = "select * from production where delmark = 1"; String SQL = "select * from production where delmark = 1"; // SQL查询语句只查询未被删除的商品
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
try { try {
preparedStatement = conn.prepareStatement(SQL); preparedStatement = conn.prepareStatement(SQL); // 创建PreparedStatement对象
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery(); // 执行查询,获取结果集
while (resultSet.next()) { while (resultSet.next()) { // 遍历结果集
Production production = new Production(); Production production = new Production();
production.setId(resultSet.getString("id")); production.setId(resultSet.getString("id")); // 设置商品ID
production.setName(resultSet.getString("name")); production.setName(resultSet.getString("name")); // 设置商品名称
production.setInPrice(resultSet.getFloat("inPrice")); production.setInPrice(resultSet.getFloat("inPrice")); // 设置进价
production.setOutPrice(resultSet.getFloat("OutPrice")); production.setOutPrice(resultSet.getFloat("OutPrice")); // 设置售价
production.setLife(resultSet.getInt("life")); production.setLife(resultSet.getInt("life")); // 设置保质期
production.setSum(resultSet.getInt("sum")); production.setSum(resultSet.getInt("sum")); // 设置库存数量
production.setSupplyId(resultSet.getInt("supplyId")); production.setSupplyId(resultSet.getInt("supplyId")); // 设置供应商ID
production.setId2(resultSet.getString("id2")); production.setId2(resultSet.getString("id2")); // 设置商品类别ID
production.setName2(resultSet.getString("name2")); production.setName2(resultSet.getString("name2")); // 设置商品类别名称
production.setDelmark(resultSet.getInt("delmark")); production.setDelmark(resultSet.getInt("delmark")); // 设置删除标记
productions.add(production); productions.add(production); // 将商品信息添加到Vector中
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(resultSet, preparedStatement, conn); JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭数据库资源
} }
return productions; return productions; // 返回所有商品信息
} }
/* 用于收银系统通过商品id返回所有信息 */ /* 用于收银系统通过商品id返回所有信息 */
public Production findByIdProduction(String id) { public Production findByIdProduction(String id) {
Production production = new Production(); Production production = new Production();
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
try { try {
preparedStatement = conn preparedStatement = conn
.prepareStatement("select * from production where id=? and delmark = 1"); .prepareStatement("select * from production where id=? and delmark = 1"); // 查询指定ID且未被删除的商品
preparedStatement.setString(1, id); preparedStatement.setString(1, id); // 设置查询参数
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery(); // 执行查询
if (resultSet.next()) { if (resultSet.next()) { // 如果找到商品
production.setId(resultSet.getString("id")); production.setId(resultSet.getString("id")); // 设置商品ID
production.setName(resultSet.getString("name")); production.setName(resultSet.getString("name")); // 设置商品名称
production.setInPrice(resultSet.getFloat("inPrice")); production.setInPrice(resultSet.getFloat("inPrice")); // 设置进价
production.setOutPrice(resultSet.getFloat("OutPrice")); production.setOutPrice(resultSet.getFloat("OutPrice")); // 设置售价
production.setLife(resultSet.getInt("life")); production.setLife(resultSet.getInt("life")); // 设置保质期
production.setSum(resultSet.getInt("sum")); production.setSum(resultSet.getInt("sum")); // 设置库存数量
production.setSupplyId(resultSet.getInt("supplyId")); production.setSupplyId(resultSet.getInt("supplyId")); // 设置供应商ID
production.setId2(resultSet.getString("id2")); production.setId2(resultSet.getString("id2")); // 设置商品类别ID
production.setName2(resultSet.getString("name2")); production.setName2(resultSet.getString("name2")); // 设置商品类别名称
production.setDelmark(resultSet.getInt("delmark")); production.setDelmark(resultSet.getInt("delmark")); // 设置删除标记
} else { } else {
System.out.println("未找到"); System.out.println("未找到");
return null; return null; // 如果未找到商品返回null
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(resultSet, preparedStatement, conn); JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭数据库资源
} }
return production; return production; // 返回商品信息
} }
@Override @Override
@ -94,35 +94,35 @@ public class productionImpl implements productionService {
* *
*/ */
Vector<Production> productions = new Vector<Production>(); Vector<Production> productions = new Vector<Production>();
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
try { try {
preparedStatement = conn.prepareStatement("select * from production where name like ? and delmark = 1"); preparedStatement = conn.prepareStatement("select * from production where name like ? and delmark = 1"); // 模糊查询商品名称
String s='%'+name+'%'; String s = '%' + name + '%'; // 构造模糊查询字符串
preparedStatement.setString(1, s); preparedStatement.setString(1, s); // 设置查询参数
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery(); // 执行查询
while (resultSet.next()) { while (resultSet.next()) { // 遍历结果集
Production production = new Production(); Production production = new Production();
production.setId(resultSet.getString("id")); production.setId(resultSet.getString("id")); // 设置商品ID
production.setName(resultSet.getString("name")); production.setName(resultSet.getString("name")); // 设置商品名称
production.setInPrice(resultSet.getFloat("inPrice")); production.setInPrice(resultSet.getFloat("inPrice")); // 设置进价
production.setOutPrice(resultSet.getFloat("OutPrice")); production.setOutPrice(resultSet.getFloat("OutPrice")); // 设置售价
production.setLife(resultSet.getInt("life")); production.setLife(resultSet.getInt("life")); // 设置保质期
production.setSum(resultSet.getInt("sum")); production.setSum(resultSet.getInt("sum")); // 设置库存数量
production.setSupplyId(resultSet.getInt("supplyId")); production.setSupplyId(resultSet.getInt("supplyId")); // 设置供应商ID
production.setId2(resultSet.getString("id2")); production.setId2(resultSet.getString("id2")); // 设置商品类别ID
production.setName2(resultSet.getString("name2")); production.setName2(resultSet.getString("name2")); // 设置商品类别名称
production.setDelmark(resultSet.getInt("delmark")); production.setDelmark(resultSet.getInt("delmark")); // 设置删除标记
productions.add(production); productions.add(production); // 将商品信息添加到Vector中
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(resultSet, preparedStatement, conn); JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭数据库资源
} }
return productions; return productions; // 返回所有匹配的商品信息
} }
@Override @Override
@ -131,34 +131,34 @@ public class productionImpl implements productionService {
*/ */
public Production findByNameProduction(String name) { public Production findByNameProduction(String name) {
Production production = new Production(); Production production = new Production();
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
try { try {
preparedStatement = conn preparedStatement = conn
.prepareStatement("select * from production where name=?"); .prepareStatement("select * from production where name=?"); // 精确查询商品名称
preparedStatement.setString(1, name); preparedStatement.setString(1, name); // 设置查询参数
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery(); // 执行查询
if (resultSet.next()) { if (resultSet.next()) { // 如果找到商品
production.setId(resultSet.getString("id")); production.setId(resultSet.getString("id")); // 设置商品ID
production.setName(resultSet.getString("name")); production.setName(resultSet.getString("name")); // 设置商品名称
production.setInPrice(resultSet.getFloat("inPrice")); production.setInPrice(resultSet.getFloat("inPrice")); // 设置进价
production.setOutPrice(resultSet.getFloat("OutPrice")); production.setOutPrice(resultSet.getFloat("OutPrice")); // 设置售价
production.setLife(resultSet.getInt("life")); production.setLife(resultSet.getInt("life")); // 设置保质期
production.setSum(resultSet.getInt("sum")); production.setSum(resultSet.getInt("sum")); // 设置库存数量
production.setSupplyId(resultSet.getInt("supplyId")); production.setSupplyId(resultSet.getInt("supplyId")); // 设置供应商ID
production.setDelmark(resultSet.getInt("delmark")); production.setDelmark(resultSet.getInt("delmark")); // 设置删除标记
} else { } else {
return null; return null; // 如果未找到商品返回null
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(resultSet, preparedStatement, conn); JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭数据库资源
} }
return production; return production; // 返回商品信息
} }
@Override @Override
@ -167,39 +167,39 @@ public class productionImpl implements productionService {
*/ */
public int addProduction(Production p) { public int addProduction(Production p) {
int flag = 0; int flag = 0;
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
PreparedStatement preparedStatement1 = null; PreparedStatement preparedStatement1 = null;
ResultSet resultSet1=null; ResultSet resultSet1 = null;
// 假设商品不存在 // 假设商品不存在
try { try {
preparedStatement1 = conn.prepareStatement("select * from production where id=?"); preparedStatement1 = conn.prepareStatement("select * from production where id=?"); // 检查商品是否已存在
preparedStatement1.setString(1, p.getId()); preparedStatement1.setString(1, p.getId()); // 设置查询参数
resultSet1=preparedStatement1.executeQuery(); resultSet1 = preparedStatement1.executeQuery(); // 执行查询
if(resultSet1.next()){ if (resultSet1.next()) {
return flag=2; return flag = 2; // 如果商品已存在返回2
} }
preparedStatement = conn.prepareStatement("insert into production values(?,?,?,?,?,?,?,?,?,?,?)"); preparedStatement = conn.prepareStatement("insert into production values(?,?,?,?,?,?,?,?,?,?,?)"); // 插入新商品
preparedStatement.setString(1, p.getId()); preparedStatement.setString(1, p.getId()); // 设置商品ID
preparedStatement.setString(2, p.getName()); preparedStatement.setString(2, p.getName()); // 设置商品名称
preparedStatement.setFloat(3, p.getInPrice()); preparedStatement.setFloat(3, p.getInPrice()); // 设置进价
preparedStatement.setFloat(4, p.getOutPrice()); preparedStatement.setFloat(4, p.getOutPrice()); // 设置售价
preparedStatement.setInt(5, p.getLife()); preparedStatement.setInt(5, p.getLife()); // 设置保质期
preparedStatement.setInt(6, p.getSum()); preparedStatement.setInt(6, p.getSum()); // 设置库存数量
preparedStatement.setInt(7, p.getSupplyId()); preparedStatement.setInt(7, p.getSupplyId()); // 设置供应商ID
preparedStatement.setString(8, p.getId2()); preparedStatement.setString(8, p.getId2()); // 设置商品类别ID
preparedStatement.setString(9, p.getName2()); preparedStatement.setString(9, p.getName2()); // 设置商品类别名称
preparedStatement.setFloat(10, 0); preparedStatement.setFloat(10, 0); // 设置未知字段
preparedStatement.setInt(11, 1); preparedStatement.setInt(11, 1); // 设置删除标记为1未删除
preparedStatement.executeUpdate(); preparedStatement.executeUpdate(); // 执行插入
flag=1; flag = 1; // 插入成功返回1
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(null, preparedStatement, conn); JDBCUtil.close(null, preparedStatement, conn); // 关闭数据库资源
} }
return flag; return flag; // 返回操作结果
} }
@Override @Override
@ -208,22 +208,21 @@ public class productionImpl implements productionService {
*/ */
public int deleteProduction(String id) { public int deleteProduction(String id) {
int flag = 0; int flag = 0;
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
try { try {
preparedStatement = conn preparedStatement = conn
.prepareStatement("delete from production where id = ?"); .prepareStatement("delete from production where id = ?"); // 删除指定ID的商品
preparedStatement.setString(1, id); preparedStatement.setString(1, id); // 设置查询参数
preparedStatement.executeUpdate(); preparedStatement.executeUpdate(); // 执行删除
flag = 1; flag = 1; // 删除成功返回1
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(null, preparedStatement, conn); JDBCUtil.close(null, preparedStatement, conn); // 关闭数据库资源
} }
return flag; return flag; // 返回操作结果
} }
@Override @Override
@ -232,98 +231,99 @@ public class productionImpl implements productionService {
*/ */
public int updateProduction(Production p) { public int updateProduction(Production p) {
int flag = 0; int flag = 0;
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
try { try {
preparedStatement = conn preparedStatement = conn
.prepareStatement("update production set name=?,inPrice=?,OutPrice=?,life=?,sum=?,delmark=? where id = ? and supplyId=?"); .prepareStatement("update production set name=?,inPrice=?,OutPrice=?,life=?,sum=?,delmark=? where id = ? and supplyId=?"); // 更新商品信息
preparedStatement.setString(1, p.getName()); preparedStatement.setString(1, p.getName()); // 设置商品名称
preparedStatement.setFloat(2, p.getInPrice()); preparedStatement.setFloat(2, p.getInPrice()); // 设置进价
preparedStatement.setFloat(3, p.getOutPrice()); preparedStatement.setFloat(3, p.getOutPrice()); // 设置售价
preparedStatement.setInt(4, p.getLife()); preparedStatement.setInt(4, p.getLife()); // 设置保质期
preparedStatement.setInt(5, p.getSum()); preparedStatement.setInt(5, p.getSum()); // 设置库存数量
preparedStatement.setInt(6, p.getDelmark()); preparedStatement.setInt(6, p.getDelmark()); // 设置删除标记
preparedStatement.setString(7, p.getId()); preparedStatement.setString(7, p.getId()); // 设置商品ID
preparedStatement.setInt(8, p.getSupplyId()); preparedStatement.setInt(8, p.getSupplyId()); // 设置供应商ID
preparedStatement.executeUpdate(); preparedStatement.executeUpdate(); // 执行更新
flag = 1; flag = 1; // 更新成功返回1
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(null, preparedStatement, conn); JDBCUtil.close(null, preparedStatement, conn); // 关闭数据库资源
} }
return flag; return flag; // 返回操作结果
} }
@Override @Override
public Vector<Production> findProductionById2(String id) { public Vector<Production> findProductionById2(String id) {
/** /**
* id2 * id2
*/ */
Vector<Production> productions = new Vector<Production>(); Vector<Production> productions = new Vector<Production>();
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
try { try {
if(id.equals("0")) if (id.equals("0"))
preparedStatement = conn.prepareStatement("select * from production where delmark = 1"); preparedStatement = conn.prepareStatement("select * from production where delmark = 1"); // 查询所有未删除的商品
else else {
{preparedStatement = conn.prepareStatement("select * from production where id2= ? and delmark = 1"); preparedStatement = conn.prepareStatement("select * from production where id2= ? and delmark = 1"); // 查询指定类别ID且未删除的商品
preparedStatement.setString(1, id);} preparedStatement.setString(1, id); // 设置查询参数
resultSet = preparedStatement.executeQuery(); }
resultSet = preparedStatement.executeQuery(); // 执行查询
while (resultSet.next()) {
while (resultSet.next()) { // 遍历结果集
Production production = new Production(); Production production = new Production();
production.setId(resultSet.getString("id")); production.setId(resultSet.getString("id")); // 设置商品ID
production.setName(resultSet.getString("name")); production.setName(resultSet.getString("name")); // 设置商品名称
production.setInPrice(resultSet.getFloat("inPrice")); production.setInPrice(resultSet.getFloat("inPrice")); // 设置进价
production.setOutPrice(resultSet.getFloat("OutPrice")); production.setOutPrice(resultSet.getFloat("OutPrice")); // 设置售价
production.setLife(resultSet.getInt("life")); production.setLife(resultSet.getInt("life")); // 设置保质期
production.setSum(resultSet.getInt("sum")); production.setSum(resultSet.getInt("sum")); // 设置库存数量
production.setSupplyId(resultSet.getInt("supplyId")); production.setSupplyId(resultSet.getInt("supplyId")); // 设置供应商ID
production.setId2(resultSet.getString("id2")); production.setId2(resultSet.getString("id2")); // 设置商品类别ID
production.setName2(resultSet.getString("name2")); production.setName2(resultSet.getString("name2")); // 设置商品类别名称
production.setDelmark(resultSet.getInt("delmark")); production.setDelmark(resultSet.getInt("delmark")); // 设置删除标记
productions.add(production); productions.add(production); // 将商品信息添加到Vector中
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(resultSet, preparedStatement, conn); JDBCUtil.close(resultSet, preparedStatement, conn); // 关闭数据库资源
} }
return productions; return productions; // 返回所有匹配的商品信息
} }
@Override @Override
/** /**
* *
*/ */
public boolean updateProductionSum(String prodId,int sum) { public boolean updateProductionSum(String prodId, int sum) {
boolean flag = false; boolean flag = false;
Connection conn = JDBCUtil.getConn(); Connection conn = JDBCUtil.getConn(); // 获取数据库连接
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
try { try {
preparedStatement = conn preparedStatement = conn
.prepareStatement("update production set sum=?+(select sum from(select sum from production where id = ? and delmark=1 ) p) where id = ? and delmark=1;"); .prepareStatement("update production set sum=?+(select sum from(select sum from production where id = ? and delmark=1 ) p) where id = ? and delmark=1;"); // 更新商品库存数量
preparedStatement.setInt(1, sum); preparedStatement.setInt(1, sum); // 设置新增库存数量
preparedStatement.setString(2, prodId); preparedStatement.setString(2, prodId); // 设置商品ID
preparedStatement.setString(3, prodId); preparedStatement.setString(3, prodId); // 设置商品ID
if(preparedStatement.executeUpdate()==1); if (preparedStatement.executeUpdate() == 1)
flag = true; flag = true; // 更新成功返回true
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
JDBCUtil.close(null, preparedStatement, conn); JDBCUtil.close(null, preparedStatement, conn); // 关闭数据库资源
} }
return flag; return flag; // 返回操作结果
} }
}
}

@ -30,195 +30,157 @@ import com.lingnan.supermarket.table.OutTableModel;
import com.lingnan.supermarket.view.InView; import com.lingnan.supermarket.view.InView;
import com.lingnan.supermarket.view.OutView; import com.lingnan.supermarket.view.OutView;
// 定义一个继承自JDialog的类InDialog用于显示添加商品的对话框
public class InDialog extends JDialog implements ActionListener {
public class InDialog extends JDialog implements ActionListener{ // 定义面板、标签、文本框、按钮等组件
private JPanel prodIdPanel, sumPanel, phonePanel, opePanel;
private JLabel prodIdLabel, sumLabel;
private JPanel prodIdPanel,sumPanel,phonePanel,opePanel; private JTextField prodIdTF, sumTF;
private JButton addBtn, cancelBtn;
private JLabel prodIdLabel,sumLabel;
private JTextField prodIdTF,sumTF;
private JButton addBtn,cancelBtn;
// 定义OutTableModel对象用于表格数据模型
private OutTableModel outTableModel = new OutTableModel(); private OutTableModel outTableModel = new OutTableModel();
// 定义Production对象和productionImpl对象用于处理商品数据
private Production production; private Production production;
private productionImpl productionImpl; private productionImpl productionImpl;
// 定义Vector集合用于存储商品数据
private Vector<Production> v; private Vector<Production> v;
// 定义User对象用于存储用户信息
private User user; private User user;
// 定义JFrame对象用于存储父窗口
private JFrame JFramparent; private JFrame JFramparent;
// 定义JComboBox对象和字符串数组用于商品编号选择
private JComboBox<String> combo; private JComboBox<String> combo;
private String allProdId[] = null; private String allProdId[] = null;
private Vector<Production> vAll; private Vector<Production> vAll;
private static String catalog; private static String catalog;
public InDialog(JFrame parent,Vector<Production> v,User user) { // 构造方法,初始化对话框并设置相关属性
super(parent,"添加商品"); public InDialog(JFrame parent, Vector<Production> v, User user) {
super(parent, "添加商品"); // 调用父类构造方法,设置对话框标题
setSize(250,200);
setLocationRelativeTo(null); setSize(250, 200); // 设置对话框大小
setModal(true); setLocationRelativeTo(null); // 设置对话框居中显示
setResizable(false); setModal(true); // 设置对话框为模态对话框
this.setLayout(new FlowLayout()); setResizable(false); // 禁止调整对话框大小
JFramparent=parent; this.setLayout(new FlowLayout()); // 设置布局为流式布局
this.v=v; JFramparent = parent; // 保存父窗口
this.user = user; this.v = v; // 保存商品数据集合
initView(); this.user = user; // 保存用户信息
initView(); // 初始化界面
} }
// 初始化界面方法
private void initView() { private void initView() {
prodIdPanel = new JPanel(); prodIdPanel = new JPanel(); // 创建商品编号面板
prodIdLabel = new JLabel("编号"); prodIdLabel = new JLabel("编号"); // 创建商品编号标签
productionImpl = new productionImpl(); // 创建productionImpl对象
productionImpl= new productionImpl(); vAll = productionImpl.findAllproduction(); // 获取所有商品数据
vAll=productionImpl.findAllproduction(); allProdId = new String[vAll.size()]; // 初始化商品编号数组
allProdId = new String[vAll.size()]; for (int i = 0; i < vAll.size(); i++) {
for(int i=0;i<vAll.size();i++) { allProdId[i] = vAll.elementAt(i).getId(); // 将商品编号存入数组
allProdId[i]=vAll.elementAt(i).getId();
} }
catalog = allProdId[0]; catalog = allProdId[0]; // 默认选择第一个商品编号
System.out.println(allProdId[0]); System.out.println(allProdId[0]); // 打印默认商品编号
combo = new JComboBox<String>(allProdId); combo = new JComboBox<String>(allProdId); // 创建商品编号下拉框
combo.addItemListener(new MyItemListener()); combo.addItemListener(new MyItemListener()); // 添加下拉框监听器
prodIdPanel.add(prodIdLabel); prodIdPanel.add(prodIdLabel); // 将商品编号标签添加到面板
prodIdPanel.add(combo); prodIdPanel.add(combo); // 将商品编号下拉框添加到面板
sumPanel = new JPanel(); // 创建数量面板
sumLabel = new JLabel("数量"); // 创建数量标签
sumPanel = new JPanel(); sumTF = new JTextField(10); // 创建数量文本框
sumLabel = new JLabel("数量"); sumPanel.add(sumLabel); // 将数量标签添加到面板
sumTF = new JTextField(10); sumPanel.add(sumTF); // 将数量文本框添加到面板
sumPanel.add(sumLabel);
sumPanel.add(sumTF); opePanel = new JPanel(); // 创建操作面板
addBtn = new JButton("添加"); // 创建添加按钮
cancelBtn = new JButton("取消"); // 创建取消按钮
opePanel = new JPanel(); addBtn.addActionListener(this); // 为添加按钮添加事件监听器
addBtn = new JButton("添加"); cancelBtn.addActionListener(this); // 为取消按钮添加事件监听器
cancelBtn = new JButton("取消"); opePanel.add(addBtn); // 将添加按钮添加到面板
addBtn.addActionListener(this); opePanel.add(cancelBtn); // 将取消按钮添加到面板
cancelBtn.addActionListener(this);
opePanel.add(addBtn); Container container = getContentPane(); // 获取内容面板
opePanel.add(cancelBtn); container.add(prodIdPanel); // 将商品编号面板添加到内容面板
container.add(sumPanel); // 将数量面板添加到内容面板
Container container = getContentPane(); container.add(opePanel); // 将操作面板添加到内容面板
container.add(prodIdPanel);
container.add(sumPanel);
container.add(opePanel);
} }
/*将数组传到inview的刷新方法里面再刷新*/ // 获取商品数据集合的方法
public Vector<Production> getVector(){ public Vector<Production> getVector() {
return v; return v; // 返回商品数据集合
} }
// 下拉框监听器类
//下拉框监听 static class MyItemListener implements ItemListener {
static class MyItemListener implements ItemListener{
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
JComboBox cb=(JComboBox)e.getSource(); JComboBox cb = (JComboBox) e.getSource(); // 获取事件源
String select=(String) cb.getSelectedItem(); String select = (String) cb.getSelectedItem(); // 获取选中的商品编号
catalog=select; catalog = select; // 更新当前选中的商品编号
} }
} }
// 事件处理方法
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Object source = e.getSource(); Object source = e.getSource(); // 获取事件源
if(source==addBtn){ if (source == addBtn) { // 如果事件源是添加按钮
//1.判断是否存在这个商品 String prodId = catalog; // 获取选中的商品编号
//2.如果存在就获取这条商品记录为一个对象 System.out.println("proId=" + prodId); // 打印商品编号
//3.判断购物缓冲区是否有这个记录 System.out.println("vatalog=" + catalog); // 打印当前选中的商品编号
//3.1如果有update数量和price
//3.2如果没有就insert这条记录把sum更新 if (sumTF.getText().equals("")) { // 如果数量文本框为空
//保存到数据库 JOptionPane.showMessageDialog(this, "请输入完整", "提示", JOptionPane.ERROR_MESSAGE); // 提示输入完整信息
//关闭对话框
//刷新table
String prodId =catalog;
System.out.println("proId="+prodId);
System.out.println("vatalog="+catalog);
if(sumTF.getText().equals("")) {
JOptionPane.showMessageDialog(this,"请输入完整","提示",JOptionPane.ERROR_MESSAGE);
return; return;
} }
int sum = Integer.parseInt(sumTF.getText()) ; int sum = Integer.parseInt(sumTF.getText()); // 获取输入的数量
if(sum<0) {/*判断输入大于0*/ if (sum < 0) { // 如果数量小于0
JOptionPane.showMessageDialog(this,"请输入大于0的数量","提示",JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(this, "请输入大于0的数量", "提示", JOptionPane.ERROR_MESSAGE); // 提示输入大于0的数量
return; return;
} }
//TODO 参数校验 // 参数校验
/*/判断是已添加,未添加还是不存在*/ productionImpl productionImpl = new productionImpl(); // 创建productionImpl对象
productionImpl productionImpl = new productionImpl(); production = new Production(); // 创建Production对象
production = new Production(); production = productionImpl.findByIdProduction(prodId); // 根据商品编号查找商品
production = productionImpl.findByIdProduction(prodId);
if (production != null) { // 如果商品存在
if(production!=null) {/*商品库有这个商品存在*/
int mark = 0; int mark = 0;
for(Production p:v) { for (Production p : v) { // 遍历商品数据集合
if (p.getId().equals(prodId)) { // 如果集合中存在相同商品
if(p.getId().equals(prodId)){/*如果数组中存在相同商品就更新数量和价格*/ sum = p.getSum() + sum; // 更新数量
sum=p.getSum()+sum;/*数量*/ p.setSum(sum); // 设置数量
p.setSum(sum); p.setPrice(sum * p.getInPrice()); // 更新价格
p.setPrice(sum*p.getInPrice());/*进货价格*/ mark = 1; // 标记为已存在
mark = 1;
break; break;
} }
} }
if(mark==0) {/*插入新的*/ if (mark == 0) { // 如果集合中不存在相同商品
System.out.println("缓存区不存在,插入新的数据"); System.out.println("缓存区不存在,插入新的数据");
production.setSum(sum);/*更新价格和数量后插入心的*/ production.setSum(sum); // 设置数量
production.setPrice(sum*production.getInPrice()); production.setPrice(sum * production.getInPrice()); // 设置价格
v.add(production); v.add(production); // 将商品添加到集合
} }
System.out.println("插入后v的大小"+v.size()); System.out.println("插入后v的大小" + v.size()); // 打印集合大小
this.dispose(); this.dispose(); // 关闭对话框
JOptionPane.showMessageDialog(this,"添加成功","提示",JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(this, "添加成功", "提示", JOptionPane.ERROR_MESSAGE); // 提示添加成功
} else { // 如果商品不存在
JOptionPane.showMessageDialog(this, "商品不存在", "提示", JOptionPane.ERROR_MESSAGE); // 提示商品不存在
} }
} else if (source == cancelBtn) { // 如果事件源是取消按钮
this.dispose(); // 关闭对话框
else {/*商品库没有这个商品*/
JOptionPane.showMessageDialog(this,"商品不存在","提示",JOptionPane.ERROR_MESSAGE);
}
}
else if(source == cancelBtn) {
this.dispose();
} }
} }
}
}

@ -17,7 +17,6 @@ import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTextField; import javax.swing.JTextField;
import com.lingnan.supermarket.*;
import com.lingnan.supermarket.dao.SupplierInfService; import com.lingnan.supermarket.dao.SupplierInfService;
import com.lingnan.supermarket.dao.productionService; import com.lingnan.supermarket.dao.productionService;
import com.lingnan.supermarket.dao.impl.SupplierInfImpl; import com.lingnan.supermarket.dao.impl.SupplierInfImpl;
@ -28,172 +27,179 @@ import com.lingnan.supermarket.dto.Production;
import com.lingnan.supermarket.dto.SupplierInf; import com.lingnan.supermarket.dto.SupplierInf;
import com.lingnan.supermarket.table.ProdCatalogTM; import com.lingnan.supermarket.table.ProdCatalogTM;
import com.lingnan.supermarket.view.StorageView; import com.lingnan.supermarket.view.StorageView;
import com.lingnan.supermarket.view.SupplierView;
import com.lingnan.supermarket.view.ProdCatalogView.MyItemListener;
/**
*
* JDialog
*/
public class ProductionDialog extends JDialog implements ActionListener { public class ProductionDialog extends JDialog implements ActionListener {
// 定义各个面板,用于组织界面布局
private JPanel namePanel, addressPanel, contactPanel, private JPanel namePanel, addressPanel, contactPanel,
opePanel,idPanel,inpricePanel,outpricePanel,lifePanel, opePanel, idPanel, inpricePanel, outpricePanel, lifePanel,
sumPanel,supplyidPanel,id2Panel,name2Panel; sumPanel, supplyidPanel, id2Panel, name2Panel;
// 定义各个标签,用于显示提示信息
private JLabel nameLabel, addressLabel, contactLabel, private JLabel nameLabel, addressLabel, contactLabel,
idLabel,inpriceLabel,outpriceLabel,lifeLabel,sumLabel, idLabel, inpriceLabel, outpriceLabel, lifeLabel, sumLabel,
supplyidLabel,id2Label,name2Label; supplyidLabel, id2Label, name2Label;
// 定义各个文本框,用于用户输入数据
private JTextField nameTF, addressTF, contactTF, private JTextField nameTF, addressTF, contactTF,
idTF,inpriceTF,outpriceTF,lifeTF,sumTF, idTF, inpriceTF, outpriceTF, lifeTF, sumTF,
supplyidTF,id2TF,name2TF; supplyidTF, id2TF, name2TF;
// 定义保存和取消按钮
private JButton saveBtn, cancelBtn; private JButton saveBtn, cancelBtn;
// 商品服务接口的实现类,用于操作商品数据
private productionService productionService = new productionImpl(); private productionService productionService = new productionImpl();
//下拉类别 // 下拉类别相关变量
private String log[]=null; private String log[] = null; // 商品类别名称数组
private ArrayList<String>alog=null; private ArrayList<String> alog = null; // 商品类别名称列表
private ProdCatalogTM prodCatalogTM; private ProdCatalogTM prodCatalogTM; // 商品类别表格模型
private ProdCatalog pc; private ProdCatalog pc; // 商品类别对象
private prodCatalogImpl pci; private prodCatalogImpl pci; // 商品类别服务实现类
private JComboBox<String> combo; private JComboBox<String> combo; // 商品类别下拉框
private String id2; private String id2; // 商品类别ID
private String name2; private String name2; // 商品类别名称
//下拉供应商类别 // 下拉供应商类别相关变量
private String superlier[]=null; private String superlier[] = null; // 供应商名称数组
private ArrayList<String>asuperlier=null; private ArrayList<String> asuperlier = null; // 供应商名称列表
private SupplierInf si; private SupplierInf si; // 供应商对象
private SupplierInfImpl sii; private SupplierInfImpl sii; // 供应商服务实现类
private JComboBox<String> combo1; private JComboBox<String> combo1; // 供应商下拉框
private int supplyid; private int supplyid; // 供应商ID
private StorageView storageView; private StorageView storageView; // 库存视图
private Production production; private Production production; // 商品对象
/**
*
* @param parent
*/
public ProductionDialog(JFrame parent) { public ProductionDialog(JFrame parent) {
super(parent, "添加"); super(parent, "添加"); // 调用父类构造函数,设置标题为“添加”
// 设置对话框大小
setSize(350, 500); setSize(350, 500);
// 设置对话框居中显示
setLocationRelativeTo(null); setLocationRelativeTo(null);
// 设置为模态对话框,即打开对话框时,父窗口不可操作
setModal(true); setModal(true);
setResizable(false); setResizable(false); // 禁止调整对话框大小
// 设置布局为流式布局
this.setLayout(new FlowLayout()); this.setLayout(new FlowLayout());
// 初始化视图
initView(); initView();
} }
/**
*
*/
private void initView() { private void initView() {
// 商品编号面板
idPanel = new JPanel(); idPanel = new JPanel();
idLabel = new JLabel("商品编号"); idLabel = new JLabel("商品编号");
idTF = new JTextField(15); idTF = new JTextField(15);
idPanel.add(idLabel); idPanel.add(idLabel);
idPanel.add(idTF); idPanel.add(idTF);
// 商品名称面板
namePanel = new JPanel(); namePanel = new JPanel();
nameLabel = new JLabel("名称"); nameLabel = new JLabel("名称");
nameTF = new JTextField(15); nameTF = new JTextField(15);
namePanel.add(nameLabel); namePanel.add(nameLabel);
namePanel.add(nameTF); namePanel.add(nameTF);
// 进货单价面板
inpricePanel = new JPanel(); inpricePanel = new JPanel();
inpriceLabel = new JLabel("进货单价"); inpriceLabel = new JLabel("进货单价");
inpriceTF = new JTextField(15); inpriceTF = new JTextField(15);
inpricePanel.add(inpriceLabel); inpricePanel.add(inpriceLabel);
inpricePanel.add(inpriceTF); inpricePanel.add(inpriceTF);
// 购买单价面板
outpricePanel = new JPanel(); outpricePanel = new JPanel();
outpriceLabel = new JLabel("购买单价"); outpriceLabel = new JLabel("购买单价");
outpriceTF = new JTextField(15); outpriceTF = new JTextField(15);
outpricePanel.add(outpriceLabel); outpricePanel.add(outpriceLabel);
outpricePanel.add(outpriceTF); outpricePanel.add(outpriceTF);
// 保质期面板
lifePanel = new JPanel(); lifePanel = new JPanel();
lifeLabel = new JLabel("保质期(月份数)"); lifeLabel = new JLabel("保质期(月份数)");
lifeTF = new JTextField(15); lifeTF = new JTextField(15);
lifePanel.add(lifeLabel); lifePanel.add(lifeLabel);
lifePanel.add(lifeTF); lifePanel.add(lifeTF);
// 库存面板
sumPanel = new JPanel(); sumPanel = new JPanel();
sumLabel = new JLabel("库存"); sumLabel = new JLabel("库存");
sumTF = new JTextField(15); sumTF = new JTextField(15);
sumPanel.add(sumLabel); sumPanel.add(sumLabel);
sumPanel.add(sumTF); sumPanel.add(sumTF);
//供应商名下拉框 传递supplyid // 供应商名下拉框面板
supplyidPanel = new JPanel(); supplyidPanel = new JPanel();
supplyidLabel = new JLabel("供应商"); supplyidLabel = new JLabel("供应商");
// supplyidTF = new JTextField(15); sii = new SupplierInfImpl(); // 创建供应商服务实现类对象
this.asuperlier = sii.findNameSupplier(); // 获取所有供应商名称
this.superlier = new String[asuperlier.size()]; // 初始化供应商名称数组
for (int i = 0; i < asuperlier.size(); i++)
superlier[i] = asuperlier.get(i); // 将供应商名称存入数组
sii=new SupplierInfImpl(); combo1 = new JComboBox<String>(superlier); // 创建供应商下拉框
this.asuperlier=sii.findNameSupplier(); combo1.addItemListener(new MyItemListener1()); // 添加下拉框监听器
this.superlier=new String[asuperlier.size()];
for(int i=0;i<asuperlier.size();i++)
superlier[i]=asuperlier.get(i);
for(int i=0;i<superlier.length;i++)
{
System.out.println(superlier[i]);
}
combo1 = new JComboBox<String>(superlier);
combo1.addItemListener(new MyItemListener1());
supplyidPanel.add(supplyidLabel); supplyidPanel.add(supplyidLabel);
supplyidPanel.add(combo1); supplyidPanel.add(combo1);
// 类名下拉框面板
/* id2Panel = new JPanel();
id2Label = new JLabel("分类id");
id2TF = new JTextField(id2,15);
id2Panel.add(id2Label);
id2Panel.add(id2TF);*/
//类名下拉框
name2Panel = new JPanel(); name2Panel = new JPanel();
name2Label = new JLabel("类名"); name2Label = new JLabel("类名");
pci=new prodCatalogImpl(); pci = new prodCatalogImpl(); // 创建商品类别服务实现类对象
this.alog=pci.findNameProdCatalog(); this.alog = pci.findNameProdCatalog(); // 获取所有商品类别名称
this.log=new String[alog.size()]; this.log = new String[alog.size()]; // 初始化商品类别名称数组
for(int i=0;i<alog.size();i++) for (int i = 0; i < alog.size(); i++)
log[i]=alog.get(i); log[i] = alog.get(i); // 将商品类别名称存入数组
combo = new JComboBox<String>(log); // 创建商品类别下拉框
combo = new JComboBox<String>(log); combo.addItemListener(new MyItemListener()); // 添加下拉框监听器
combo.addItemListener(new MyItemListener());
name2Panel.add(name2Label); name2Panel.add(name2Label);
name2Panel.add(combo); name2Panel.add(combo);
// 地址面板
addressPanel = new JPanel(); addressPanel = new JPanel();
addressLabel = new JLabel("地址"); addressLabel = new JLabel("地址");
addressTF = new JTextField(15); addressTF = new JTextField(15);
addressPanel.add(addressLabel); addressPanel.add(addressLabel);
addressPanel.add(addressTF); addressPanel.add(addressTF);
// 电话面板
contactPanel = new JPanel(); contactPanel = new JPanel();
contactLabel = new JLabel("电话"); contactLabel = new JLabel("电话");
contactTF = new JTextField(15); contactTF = new JTextField(15);
contactPanel.add(contactLabel); contactPanel.add(contactLabel);
contactPanel.add(contactTF); contactPanel.add(contactTF);
// 操作按钮面板
opePanel = new JPanel(); opePanel = new JPanel();
saveBtn = new JButton("保存"); saveBtn = new JButton("保存");
cancelBtn = new JButton("取消"); cancelBtn = new JButton("取消");
saveBtn.addActionListener(this); saveBtn.addActionListener(this); // 添加保存按钮监听器
cancelBtn.addActionListener(this); cancelBtn.addActionListener(this); // 添加取消按钮监听器
opePanel.add(saveBtn); opePanel.add(saveBtn);
opePanel.add(cancelBtn); opePanel.add(cancelBtn);
// 将所有面板添加到容器中
Container container = getContentPane(); Container container = getContentPane();
container.add(idPanel); container.add(idPanel);
container.add(namePanel); container.add(namePanel);
@ -202,20 +208,19 @@ public class ProductionDialog extends JDialog implements ActionListener {
container.add(lifePanel); container.add(lifePanel);
container.add(sumPanel); container.add(sumPanel);
container.add(supplyidPanel); container.add(supplyidPanel);
// container.add(id2Panel);
container.add(name2Panel); container.add(name2Panel);
container.add(opePanel); container.add(opePanel);
} }
/**
*
* @param e
*/
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Object source = e.getSource(); Object source = e.getSource();
if (source == saveBtn) { if (source == saveBtn) {
// 思路获取数据 // 获取输入的数据
// 保存到数据库
// 关闭对话框
// 刷新table
String name = nameTF.getText(); String name = nameTF.getText();
String id = idTF.getText(); String id = idTF.getText();
float inprice = Float.parseFloat((inpriceTF.getText())); float inprice = Float.parseFloat((inpriceTF.getText()));
@ -223,26 +228,25 @@ public class ProductionDialog extends JDialog implements ActionListener {
int life = Integer.parseInt(lifeTF.getText()); int life = Integer.parseInt(lifeTF.getText());
int sum = Integer.parseInt(sumTF.getText()); int sum = Integer.parseInt(sumTF.getText());
// 参数校验
// TODO 参数校验
if (this.production == null) { if (this.production == null) {
if(supplyid==-1){ if (supplyid == -1) {
JOptionPane.showMessageDialog(this, "商品检索出错", "提示", JOptionPane.showMessageDialog(this, "商品检索出错", "提示",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
return; return;
} }
if(supplyid==0){ if (supplyid == 0) {
JOptionPane.showMessageDialog(this, "请选择商品名", "提示", JOptionPane.showMessageDialog(this, "请选择商品名", "提示",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
return; return;
} }
if(id2.equals("0")){ if (id2.equals("0")) {
JOptionPane.showMessageDialog(this, "请选择商品类", "提示", JOptionPane.showMessageDialog(this, "请选择商品类", "提示",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
return; return;
} }
// 创建商品对象并设置属性
Production production = new Production(); Production production = new Production();
production.setId(id); production.setId(id);
production.setName(name); production.setName(name);
@ -253,69 +257,58 @@ public class ProductionDialog extends JDialog implements ActionListener {
production.setSupplyId(supplyid); production.setSupplyId(supplyid);
production.setId2(id2); production.setId2(id2);
production.setName2(name2); production.setName2(name2);
// 调用服务接口添加商品
int result = productionService.addProduction(production); int result = productionService.addProduction(production);
// int result = 1;
if (result == 1) { if (result == 1) {
JOptionPane.showMessageDialog(this, "添加成功", "提示", JOptionPane.showMessageDialog(this, "添加成功", "提示",
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
this.dispose(); this.dispose(); // 关闭对话框
} else if(result == 2){ } else if (result == 2) {
JOptionPane.showMessageDialog(this, "已存在该商品", "提示", JOptionPane.showMessageDialog(this, "已存在该商品", "提示",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
} } else {
else {
JOptionPane.showMessageDialog(this, "出错!添加失败", "提示", JOptionPane.showMessageDialog(this, "出错!添加失败", "提示",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
} }
}/*else{ }
//更新
SupplierInf supplierInf= new SupplierInf();
supplierInf.setName(name);
supplierInf.setAddress(address);
supplierInf.setContact(contact);
supplierInf.setId(this.supplierInf.getId());
int result = supplierInfService.updateSupplierInf(supplierInf);
if(result==1){
JOptionPane.showMessageDialog(this, "更新成功", "提示",
JOptionPane.INFORMATION_MESSAGE);
}
}*/
} else if (source == cancelBtn) { } else if (source == cancelBtn) {
// 关闭对话框
this.dispose(); this.dispose();
} }
} }
/**
*
*/
public class MyItemListener implements ItemListener { public class MyItemListener implements ItemListener {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
JComboBox cb = (JComboBox) e.getSource(); JComboBox cb = (JComboBox) e.getSource();
name2 = (String) cb.getSelectedItem(); name2 = (String) cb.getSelectedItem(); // 获取选中的商品类别名称
pci =new prodCatalogImpl(); pci = new prodCatalogImpl();
for(int i=0;i<log.length;i++){ for (int i = 0; i < log.length; i++) {
if(name2.equals(log[i])) if (name2.equals(log[i]))
id2=pci.findProdCatalogByname(name2); id2 = pci.findProdCatalogByname(name2); // 根据名称获取商品类别ID
} }
} }
} }
/**
*
*/
public class MyItemListener1 implements ItemListener { public class MyItemListener1 implements ItemListener {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
JComboBox cb = (JComboBox) e.getSource(); JComboBox cb = (JComboBox) e.getSource();
String suppliername = (String) cb.getSelectedItem(); String suppliername = (String) cb.getSelectedItem(); // 获取选中的供应商名称
sii =new SupplierInfImpl(); sii = new SupplierInfImpl();
for(int i=0;i<superlier.length;i++){ for (int i = 0; i < superlier.length; i++) {
if(suppliername.equals(superlier[i])) if (suppliername.equals(superlier[i]))
supplyid=sii.findIdSupplierByName(suppliername); supplyid = sii.findIdSupplierByName(suppliername); // 根据名称获取供应商ID
} }
} }
} }
} }

@ -13,7 +13,6 @@ import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTextField; import javax.swing.JTextField;
import com.lingnan.supermarket.*;
import com.lingnan.supermarket.dao.SupplierInfService; import com.lingnan.supermarket.dao.SupplierInfService;
import com.lingnan.supermarket.dao.impl.SupplierInfImpl; import com.lingnan.supermarket.dao.impl.SupplierInfImpl;
import com.lingnan.supermarket.dto.SupplierInf; import com.lingnan.supermarket.dto.SupplierInf;
@ -21,68 +20,78 @@ import com.lingnan.supermarket.view.SupplierView;
public class SupplierInfDialog extends JDialog implements ActionListener { public class SupplierInfDialog extends JDialog implements ActionListener {
private JPanel namePanel, addressPanel, contactPanel,emailPanel, opePanel; private JPanel namePanel, addressPanel, contactPanel, emailPanel, opePanel;
private JLabel nameLabel, addressLabel, contactLabel,emailLabel; private JLabel nameLabel, addressLabel, contactLabel, emailLabel;
private JTextField nameTF, addressTF, contactTF,emailTF; private JTextField nameTF, addressTF, contactTF, emailTF;
private JButton saveBtn, cancelBtn; private JButton saveBtn, cancelBtn;
private SupplierInfService supplierInfService = new SupplierInfImpl(); private SupplierInfService supplierInfService = new SupplierInfImpl(); // 供应商信息服务接口的实现类
private SupplierView supplierView; private SupplierView supplierView; // 供应商视图对象
private SupplierInf supplierInf; private SupplierInf supplierInf; // 供应商信息对象
//构造函数,初始化对话框
public SupplierInfDialog(JFrame parent, SupplierView supplierView) { public SupplierInfDialog(JFrame parent, SupplierView supplierView) {
super(parent, "添加"); super(parent, "添加"); // 调用父类构造函数,设置对话框标题为“添加”
this.supplierView = supplierView; this.supplierView = supplierView; // 保存供应商视图对象
setSize(350, 300); setSize(350, 300); // 设置对话框大小
setLocationRelativeTo(null); setLocationRelativeTo(null); // 设置对话框居中显示
setModal(true); setModal(true); // 设置对话框为模态对话框
setResizable(false); setResizable(false); // 禁止调整对话框大小
this.setLayout(new FlowLayout()); this.setLayout(new FlowLayout()); // 设置对话框的布局为流式布局
initView(); initView(); // 初始化对话框界面
} }
/**
*
*/
private void initView() { private void initView() {
// 名称面板
namePanel = new JPanel(); namePanel = new JPanel();
nameLabel = new JLabel("名称"); nameLabel = new JLabel("名称");
nameTF = new JTextField(15); nameTF = new JTextField(15);
namePanel.add(nameLabel); namePanel.add(nameLabel);
namePanel.add(nameTF); namePanel.add(nameTF);
// 地址面板
addressPanel = new JPanel(); addressPanel = new JPanel();
addressLabel = new JLabel("地址"); addressLabel = new JLabel("地址");
addressTF = new JTextField(15); addressTF = new JTextField(15);
addressPanel.add(addressLabel); addressPanel.add(addressLabel);
addressPanel.add(addressTF); addressPanel.add(addressTF);
// 联系电话面板
contactPanel = new JPanel(); contactPanel = new JPanel();
contactLabel = new JLabel("电话"); contactLabel = new JLabel("电话");
contactTF = new JTextField(15); contactTF = new JTextField(15);
contactPanel.add(contactLabel); contactPanel.add(contactLabel);
contactPanel.add(contactTF); contactPanel.add(contactTF);
// 邮箱面板
emailPanel = new JPanel(); emailPanel = new JPanel();
emailLabel = new JLabel("邮箱"); emailLabel = new JLabel("邮箱");
emailTF = new JTextField(15); emailTF = new JTextField(15);
emailPanel.add(emailLabel); emailPanel.add(emailLabel);
emailPanel.add(emailTF); emailPanel.add(emailTF);
// 操作面板
opePanel = new JPanel(); opePanel = new JPanel();
saveBtn = new JButton("保存"); saveBtn = new JButton("保存");
cancelBtn = new JButton("取消"); cancelBtn = new JButton("取消");
saveBtn.addActionListener(this); saveBtn.addActionListener(this); // 为保存按钮添加事件监听器
cancelBtn.addActionListener(this); cancelBtn.addActionListener(this); // 为取消按钮添加事件监听器
opePanel.add(saveBtn); opePanel.add(saveBtn);
opePanel.add(cancelBtn); opePanel.add(cancelBtn);
// 将各个面板添加到对话框的内容面板中
Container container = getContentPane(); Container container = getContentPane();
container.add(namePanel); container.add(namePanel);
container.add(addressPanel); container.add(addressPanel);
@ -91,56 +100,51 @@ public class SupplierInfDialog extends JDialog implements ActionListener {
container.add(opePanel); container.add(opePanel);
} }
/**
*
*
* @param e
*/
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Object source = e.getSource(); Object source = e.getSource(); // 获取事件源
if (source == saveBtn) { if (source == saveBtn) { // 如果事件源是保存按钮
// 思路获取数据 // 获取用户输入的数据
// 保存到数据库
// 关闭对话框
// 刷新table
String name = nameTF.getText(); String name = nameTF.getText();
String address = addressTF.getText(); String address = addressTF.getText();
String contact = contactTF.getText(); String contact = contactTF.getText();
String email = emailTF.getText(); String email = emailTF.getText();
// TODO 参数校验 // TODO 参数校验
if (this.supplierInf == null) { if (this.supplierInf == null) { // 如果当前没有供应商信息对象(即新增操作)
SupplierInf supplierInf = new SupplierInf(); SupplierInf supplierInf = new SupplierInf();
supplierInf.setName(name); supplierInf.setName(name);
supplierInf.setAddress(address); supplierInf.setAddress(address);
supplierInf.setContact(contact); supplierInf.setContact(contact);
supplierInf.setEmail(email); supplierInf.setEmail(email);
int result = supplierInfService.addSupplierInf(supplierInf); int result = supplierInfService.addSupplierInf(supplierInf); // 调用服务接口添加供应商信息
// int result = 1; if (result == 1) { // 如果添加成功
if (result == 1) { JOptionPane.showMessageDialog(this, "添加成功", "提示", JOptionPane.INFORMATION_MESSAGE);
this.dispose(); // 关闭对话框
JOptionPane.showMessageDialog(this, "添加成功", "提示", } else { // 如果添加失败
JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(this, "添加失败", "提示", JOptionPane.ERROR_MESSAGE);
this.dispose();
} else {
JOptionPane.showMessageDialog(this, "添加失败", "提示",
JOptionPane.ERROR_MESSAGE);
}
}/*else{
//更新
SupplierInf supplierInf= new SupplierInf();
supplierInf.setName(name);
supplierInf.setAddress(address);
supplierInf.setContact(contact);
supplierInf.setId(this.supplierInf.getId());
int result = supplierInfService.updateSupplierInf(supplierInf);
if(result==1){
JOptionPane.showMessageDialog(this, "更新成功", "提示",
JOptionPane.INFORMATION_MESSAGE);
} }
}*/ } /*else {
// 更新操作(当前代码被注释掉)
} else if (source == cancelBtn) { SupplierInf supplierInf = new SupplierInf();
supplierInf.setName(name);
this.dispose(); supplierInf.setAddress(address);
supplierInf.setContact(contact);
supplierInf.setId(this.supplierInf.getId());
int result = supplierInfService.updateSupplierInf(supplierInf);
if (result == 1) {
JOptionPane.showMessageDialog(this, "更新成功", "提示", JOptionPane.INFORMATION_MESSAGE);
}
}*/
} else if (source == cancelBtn) { // 如果事件源是取消按钮
this.dispose(); // 关闭对话框
} }
} }
} }

@ -2,6 +2,7 @@ package com.lingnan.supermarket.dto;
import com.lingnan.supermarket.dto.base.BaseProduction; import com.lingnan.supermarket.dto.base.BaseProduction;
public class Buffer extends BaseProduction{ // 定义一个 Buffer 类,继承自 BaseProduction
public class Buffer extends BaseProduction {
} }

@ -2,40 +2,71 @@ package com.lingnan.supermarket.dto;
import java.util.Date; import java.util.Date;
//表示出库订单的相关信息
public class OutOrder { public class OutOrder {
private String oNumber;
private Float allOutPrice; //出库订单编号
private Date oDate; private String oNumber;
private String principal;
private int delmark; // 出库订单的总出库价格
private Float allOutPrice;
//出库日期
private Date oDate;
//负责人
private String principal;
//删除标记用于标识该订单是否被删除0已删除1未删除
private int delmark;
// 获取出库订单编号
public String getoNumber() { public String getoNumber() {
return oNumber; return oNumber;
} }
// 设置出库订单编号
public void setoNumber(String oNumber) { public void setoNumber(String oNumber) {
this.oNumber = oNumber; this.oNumber = oNumber;
} }
// 获取出库订单的总出库价格
public Float getAllOutPrice() { public Float getAllOutPrice() {
return allOutPrice; return allOutPrice;
} }
// 设置出库订单的总出库价格
public void setAllOutPrice(Float allOutPrice) { public void setAllOutPrice(Float allOutPrice) {
this.allOutPrice = allOutPrice; this.allOutPrice = allOutPrice;
} }
// 获取出库日期
public Date getoDate() { public Date getoDate() {
return oDate; return oDate;
} }
// 设置出库日期
public void setoDate(Date oDate) { public void setoDate(Date oDate) {
this.oDate = oDate; this.oDate = oDate;
} }
//获取负责人
public String getPrincipal() { public String getPrincipal() {
return principal; return principal;
} }
//设置负责人
public void setPrincipal(String principal) { public void setPrincipal(String principal) {
this.principal = principal; this.principal = principal;
} }
//获取删除标记
public int getDelmark() { public int getDelmark() {
return delmark; return delmark;
} }
//设置删除标记
public void setDelmark(int delmark) { public void setDelmark(int delmark) {
this.delmark = delmark; this.delmark = delmark;
} }
} }

@ -2,26 +2,46 @@ package com.lingnan.supermarket.dto;
import com.lingnan.supermarket.dto.base.BsDomain; import com.lingnan.supermarket.dto.base.BsDomain;
public class OutRecord extends BsDomain{ // 出库记录类
private String oNumber;
private int sum; public class OutRecord extends BsDomain {
private Float outPrice;
// 出库编号
private String oNumber;
// 出库数量
private int sum;
// 出库单价
private Float outPrice;
// 获取出库编号
public String getoNumber() { public String getoNumber() {
return oNumber; return oNumber;
} }
// 设置出库编号
public void setoNumber(String oNumber) { public void setoNumber(String oNumber) {
this.oNumber = oNumber; this.oNumber = oNumber;
} }
//获取出库数量
public int getSum() { public int getSum() {
return sum; return sum;
} }
//设置出库数量
public void setSum(int sum) { public void setSum(int sum) {
this.sum = sum; this.sum = sum;
} }
//获取出库单价
public Float getOutPrice() { public Float getOutPrice() {
return outPrice; return outPrice;
} }
//设置出库单价
public void setOutPrice(Float outPrice) { public void setOutPrice(Float outPrice) {
this.outPrice = outPrice; this.outPrice = outPrice;
} }
} }

@ -1,15 +1,18 @@
package com.lingnan.supermarket.dto.base; package com.lingnan.supermarket.dto.base;
// 封装对象的通用属性
public class BaseDomain { public class BaseDomain {
private Integer id; private Integer id;
// 获取 id 属性的 getter 方法
public Integer getId() { public Integer getId() {
return id; return id;
} }
// 设置 id 属性的 setter 方法
public void setId(Integer id) { public void setId(Integer id) {
this.id = id; this.id = id;
} }
} }

@ -1,86 +1,148 @@
package com.lingnan.supermarket.dto.base; package com.lingnan.supermarket.dto.base;
// 封装商品相关的通用属性
public class BaseProduction { public class BaseProduction {
// 商品标识符
private String id; private String id;
// 商品的名称
private String name; private String name;
private float inPrice;
private float OutPrice; // 商品的进货价格
private int life; private float inPrice;
private int sum;
private int supplyId; // 商品的出货价格
private String id2; private float OutPrice;
private String name2;
private Float price; // 商品的保质期
private int delmark; private int life;
// 商品的库存数量
public String getId() { private int sum;
// 供应商的唯一标识符
private int supplyId;
// 商品的辅助标识符
private String id2;
// 商品的辅助名称
private String name2;
// 商品的总价格,浮点数类型
private Float price;
// 商品的删除标记用于标识商品是否被删除0未删除1已删除
private int delmark;
// 获取商品唯一标识符的方法
public String getId() {
return id; return id;
} }
// 设置商品唯一标识符
public void setId(String id) { public void setId(String id) {
this.id = id; this.id = id;
} }
// 获取商品删除标记
public int getDelmark() { public int getDelmark() {
return delmark; return delmark;
} }
// 设置商品删除标记
public void setDelmark(int delmark) { public void setDelmark(int delmark) {
this.delmark = delmark; this.delmark = delmark;
} }
// 获取商品库存数量
public int getSum() { public int getSum() {
return sum; return sum;
} }
// 设置商品库存数量
public void setSum(int sum) { public void setSum(int sum) {
this.sum = sum; this.sum = sum;
} }
// 获取商品名称
public String getName() { public String getName() {
return name; return name;
} }
// 设置商品名称
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
// 获取商品进货价格
public float getInPrice() { public float getInPrice() {
return inPrice; return inPrice;
} }
// 设置商品进货价格
public void setInPrice(float inPrice) { public void setInPrice(float inPrice) {
this.inPrice = inPrice; this.inPrice = inPrice;
} }
// 获取商品出货价格
public float getOutPrice() { public float getOutPrice() {
return OutPrice; return OutPrice;
} }
// 设置商品出货价格
public void setOutPrice(float outPrice) { public void setOutPrice(float outPrice) {
OutPrice = outPrice; OutPrice = outPrice;
} }
// 获取商品保质期
public int getLife() { public int getLife() {
return life; return life;
} }
// 设置商品保质期
public void setLife(int life) { public void setLife(int life) {
this.life = life; this.life = life;
} }
// 获取商品辅助标识符
public String getId2() { public String getId2() {
return id2; return id2;
} }
// 设置商品辅助标识符
public void setId2(String id2) { public void setId2(String id2) {
this.id2 = id2; this.id2 = id2;
} }
// 获取商品辅助名称
public String getName2() { public String getName2() {
return name2; return name2;
} }
// 设置商品辅助名称
public void setName2(String name2) { public void setName2(String name2) {
this.name2 = name2; this.name2 = name2;
} }
// 获取供应商唯一标识符
public int getSupplyId() { public int getSupplyId() {
return supplyId; return supplyId;
} }
// 设置供应商唯一标识符
public void setSupplyId(int supplyId) { public void setSupplyId(int supplyId) {
this.supplyId = supplyId; this.supplyId = supplyId;
} }
// 获取商品总价格
public Float getPrice() { public Float getPrice() {
return price; return price;
} }
// 设置商品总价格
public void setPrice(Float price) { public void setPrice(Float price) {
this.price = price; this.price = price;
} }
} }

@ -1,13 +1,13 @@
package com.lingnan.supermarket.dto.base; package com.lingnan.supermarket.dto.base;
public class BsDomain { public class BsDomain {
private String id; private String id;
// 获取 id 属性的 getter 方法
public String getId() { public String getId() {
return id; return id;
} }
// 设置 id 属性的 setter 方法
public void setId(String id) { public void setId(String id) {
this.id = id; this.id = id;
} }
} }

@ -15,93 +15,102 @@ import com.lingnan.supermarket.dao.UserService;
import com.lingnan.supermarket.dao.impl.*; import com.lingnan.supermarket.dao.impl.*;
import com.lingnan.supermarket.dialog.InDialog; import com.lingnan.supermarket.dialog.InDialog;
//用于管理入库订单的表格数据
public class InOrderTM extends AbstractTableModel{ public class InOrderTM extends AbstractTableModel {
private String [] columnName = {"订单号","总价","时间","负责人","状态"}; // 表格列名
private String[] columnName = {"订单号", "总价", "时间", "负责人", "状态"};
// 商品服务实现类
private productionImpl prodDao = new productionImpl(); private productionImpl prodDao = new productionImpl();
private Vector<InOrder> InOrders; // 入库订单数据集合
private inOrderServiceImpl inOrderImpl= new inOrderServiceImpl(); private Vector<InOrder> InOrders;
private InOrder inOrder ;
String iNumber ;/*订单号*/ // 入库订单服务实现类
private inOrderServiceImpl inOrderImpl = new inOrderServiceImpl();
// 当前操作的入库订单对象
private InOrder inOrder;
// 订单号
String iNumber;
//加载所有入库订单记录
public void allInOrderRecord() { public void allInOrderRecord() {
//将添加的商品加入到静态变量Vector数组中 // 从数据库中获取所有入库订单记录
/*prod = InDialog.getProduction();*/
InOrders = inOrderImpl.findAllInOrder(); InOrders = inOrderImpl.findAllInOrder();
} }
//查找分类结果 //根据分类查找入库订单记录0全部1已入库2待入库3已取消
public void resultOfFind(int catalog) { public void resultOfFind(int catalog) {
if(catalog==0) if (catalog == 0) {
// 加载所有入库订单记录
InOrders = inOrderImpl.findAllInOrder(); InOrders = inOrderImpl.findAllInOrder();
else } else {
// 根据状态查找入库订单记录
InOrders = inOrderImpl.FindStatus(catalog); InOrders = inOrderImpl.FindStatus(catalog);
}
} }
//根据订单查找 // 根据订单查找入库订单记录
public void resultOfNumber(String Number) { public void resultOfNumber(String Number) {
InOrders=new Vector<InOrder>(); InOrders = new Vector<InOrder>();
inOrder = inOrderImpl.findByIdinOrder(Number); inOrder = inOrderImpl.findByIdinOrder(Number);
InOrders.add(inOrder); InOrders.add(inOrder);
} }
//获取表格行数
@Override @Override
public int getRowCount() { public int getRowCount() {
return InOrders.size(); return InOrders.size();
} }
/* public Float getAllPrice() { // 获取表格列数
return BufferImpl.InBufferAllPrice();
}
*/
@Override @Override
public int getColumnCount() { public int getColumnCount() {
return columnName.length; return columnName.length;
} }
//获取指定单元格的值
@Override @Override
public Object getValueAt(int rowIndex, int columnIndex) { public Object getValueAt(int rowIndex, int columnIndex) {
inOrder = InOrders.get(rowIndex); inOrder = InOrders.get(rowIndex);
/* System.out.println( "id="+users.get(rowIndex).getId()); iNumber = inOrder.getiNumber();
System.out.println("rowIndex"+rowIndex);
System.out.println("columnIndex"+columnIndex);*/ // 根据列索引返回对应的数据
iNumber=inOrder.getiNumber(); if (columnIndex == 0) {
if(columnIndex==0) { return inOrder.getiNumber(); // 订单号
return inOrder.getiNumber(); } else if (columnIndex == 1) {
}else if(columnIndex==1) { return inOrder.getAllInPrice(); // 总价
return inOrder.getAllInPrice(); } else if (columnIndex == 2) {
}else if(columnIndex==2) { return inOrder.getInDate(); // 时间
return inOrder.getInDate(); } else if (columnIndex == 3) {
}else if(columnIndex==3) { return inOrder.getPrincipal(); // 负责人
return inOrder.getPrincipal(); } else if (columnIndex == 4) {
}else if(columnIndex==4) { // 根据状态返回对应的字符串
String status = null; String status = null;
if(inOrder.getStatus()==1) if (inOrder.getStatus() == 1)
status= "已入库"; status = "已入库";
else if(inOrder.getStatus()==2) else if (inOrder.getStatus() == 2)
status= "待入库"; status = "待入库";
else if(inOrder.getStatus()==3) else if (inOrder.getStatus() == 3)
status= "已取消"; status = "已取消";
return status; return status;
}else { } else {
return null; return null;
} }
} }
public String getINumber() { /*返回要修改或删除的记录*/ //获取当前操作的订单号
public String getINumber() {
return iNumber; return iNumber;
} }
//获取指定列的列名
@Override @Override
public String getColumnName(int column) { public String getColumnName(int column) {
return columnName[column]; return columnName[column];
} }
}
}

@ -9,83 +9,83 @@ import javax.swing.table.AbstractTableModel;
import com.lingnan.supermarket.dto.Buffer; import com.lingnan.supermarket.dto.Buffer;
import com.lingnan.supermarket.dto.InOrder; import com.lingnan.supermarket.dto.InOrder;
import com.lingnan.supermarket.dto.InRecord; import com.lingnan.supermarket.dto.InRecord;
import com.lingnan.supermarket.dto.Buffer;
import com.lingnan.supermarket.dto.Production; import com.lingnan.supermarket.dto.Production;
import com.lingnan.supermarket.dto.User; import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.dao.UserService; import com.lingnan.supermarket.dao.UserService;
import com.lingnan.supermarket.dao.impl.*; import com.lingnan.supermarket.dao.impl.*;
import com.lingnan.supermarket.dialog.InDialog; import com.lingnan.supermarket.dialog.InDialog;
//用于管理入库记录的表格数据
public class InRecordTM extends AbstractTableModel {
public class InRecordTM extends AbstractTableModel{ // 表格列名数组
private String[] columnName = { "订单号", "id", "数量", "金额" };
private String [] columnName = {"订单号","id","数量","金额"};
// 商品数据访问对象
private productionImpl prodDao = new productionImpl(); private productionImpl prodDao = new productionImpl();
private Vector<InRecord> InRecords; // 入库记录数据集合
private Vector<InRecord> InRecords;
// 入库记录服务实现类
private inRecordServiceImpl inRecordImpl = new inRecordServiceImpl(); private inRecordServiceImpl inRecordImpl = new inRecordServiceImpl();
private InRecord inRecord= new InRecord();
// 当前操作的入库记录对象
private InRecord inRecord = new InRecord();
private String iNumber ;/*订单号*/ // 订单号
private String iNumber;
//构造函数,初始化订单号
public InRecordTM(String iNumber) { public InRecordTM(String iNumber) {
this.iNumber=iNumber; this.iNumber = iNumber;
} }
//根据订单号查找入库记录
public void findInRecordByINumber() { public void findInRecordByINumber() {
//将添加的商品加入到静态变量Vector数组中 // 将添加的商品加入到静态变量 Vector 数组中
/*prod = InDialog.getProduction();*/ // prod = InDialog.getProduction();
InRecords = inRecordImpl.findByIdinRecord(iNumber); InRecords = inRecordImpl.findByIdinRecord(iNumber);
} }
//获取表格的行数
@Override @Override
public int getRowCount() { public int getRowCount() {
return InRecords.size(); return InRecords.size();
} }
/* public Float getAllPrice() { //获取表格的列数
return BufferImpl.InBufferAllPrice();
}
*/
@Override @Override
public int getColumnCount() { public int getColumnCount() {
return columnName.length; return columnName.length;
} }
//获取指定单元格的值
@Override @Override
public Object getValueAt(int rowIndex, int columnIndex) { public Object getValueAt(int rowIndex, int columnIndex) {
inRecord = InRecords.get(rowIndex); inRecord = InRecords.get(rowIndex);
/* System.out.println( "id="+users.get(rowIndex).getId()); iNumber = inRecord.getiNumber();
System.out.println("rowIndex"+rowIndex); if (columnIndex == 0) {
System.out.println("columnIndex"+columnIndex);*/ return inRecord.getiNumber(); // 返回订单号
iNumber=inRecord.getiNumber(); } else if (columnIndex == 1) {
if(columnIndex==0) { return inRecord.getId(); // 返回商品ID
return inRecord.getiNumber(); } else if (columnIndex == 2) {
}else if(columnIndex==1) { return inRecord.getSum(); // 返回数量
return inRecord.getId(); } else if (columnIndex == 3) {
}else if(columnIndex==2) { return inRecord.getInPrice(); // 返回金额
return inRecord.getSum(); } else {
}else if(columnIndex==3) {
return inRecord.getInPrice();
}else {
return null; return null;
} }
} }
public String getINumber() { /*返回要修改或删除的记录*/ //获取订单
public String getINumber() {
return iNumber; return iNumber;
} }
// 获取指定列的列名
@Override @Override
public String getColumnName(int column) { public String getColumnName(int column) {
return columnName[column]; return columnName[column];
} }
}
}

@ -3,91 +3,90 @@ package com.lingnan.supermarket.table;
import java.util.List; import java.util.List;
import java.util.Vector; import java.util.Vector;
import javax.swing.table.AbstractTableModel; import javax.swing.table.AbstractTableModel;
import com.lingnan.supermarket.dto.SupplierInf; import com.lingnan.supermarket.dto.SupplierInf;
import com.lingnan.supermarket.dao.SupplierInfService; import com.lingnan.supermarket.dao.SupplierInfService;
import com.lingnan.supermarket.dao.impl.*; import com.lingnan.supermarket.dao.impl.SupplierInfImpl;
public class SupplierTableModel extends AbstractTableModel{ // 管理供应商信息的表格数据
public class SupplierTableModel extends AbstractTableModel {
private String [] columnName = {"id","名称","地址","电话","邮箱"}; // 定义表格的列名数组
private String[] columnName = { "id", "名称", "地址", "电话", "邮箱" };
//private SupplierInfImpl supplierDao = new SupplierInfImpl(); // 创建 SupplierInfService 对象,用于与数据库交互
private SupplierInfService supplierInfService = new SupplierInfImpl(); private SupplierInfService supplierInfService = new SupplierInfImpl();
// 创建 SupplierInf 对象,用于存储单个供应商信息
private SupplierInf supplierInf = new SupplierInf(); private SupplierInf supplierInf = new SupplierInf();
// 创建 Vector 集合,用于存储所有供应商信息
private Vector<SupplierInf> suppliers; private Vector<SupplierInf> suppliers;
private int id=0; // 定义一个整型变量 id用于存储供应商的唯一标识符
private int id = 0;
// 加载所有供应商信息的方法
public void all() { public void all() {
//查找全部数据 // 从数据库中查找全部供应商信息
suppliers = supplierInfService.findAllSupplierInf(); suppliers = supplierInfService.findAllSupplierInf();
} }
// 根据供应商名称加载供应商信息的方法
public void Byname(SupplierInf supplierInf) { public void Byname(SupplierInf supplierInf) {
// 根据供应商名称查找供应商信息
suppliers = supplierInfService.findByNameSupplierInf(supplierInf); suppliers = supplierInfService.findByNameSupplierInf(supplierInf);
} }
// 获取表格行数的方法
@Override @Override
public int getRowCount() { public int getRowCount() {
return suppliers.size(); return suppliers.size(); // 返回供应商集合的大小
} }
// 获取表格列数的方法
@Override @Override
public int getColumnCount() { public int getColumnCount() {
return columnName.length; return columnName.length; // 返回列名数组的长度
} }
// 获取指定单元格值的方法
@Override @Override
public Object getValueAt(int rowIndex, int columnIndex) { public Object getValueAt(int rowIndex, int columnIndex) {
SupplierInf prod = suppliers.get(rowIndex); SupplierInf prod = suppliers.get(rowIndex); // 获取指定行的供应商对象
//id = supplierInf.getId(); // 根据列索引返回对应的供应商信息
/* System.out.println( "id="+users.get(rowIndex).getId()); if (columnIndex == 0) {
System.out.println("rowIndex"+rowIndex); return prod.getId(); // 返回供应商的唯一标识符
System.out.println("columnIndex"+columnIndex);*/ } else if (columnIndex == 1) {
if(columnIndex==0) { return prod.getName(); // 返回供应商的名称
return prod.getId(); } else if (columnIndex == 2) {
}else if(columnIndex==1) { return prod.getAddress(); // 返回供应商的地址
return prod.getName(); } else if (columnIndex == 3) {
}else if(columnIndex==2) { return prod.getContact(); // 返回供应商的联系电话
return prod.getAddress(); } else if (columnIndex == 4) {
}else if(columnIndex==3) { return prod.getEmail(); // 返回供应商的邮箱
return prod.getContact(); } else {
}else if(columnIndex==4){ return null; // 如果列索引无效,返回 null
return prod.getEmail();
}
else {
return null;
} }
} }
// 获取指定列名的方法
@Override @Override
public String getColumnName(int column) { public String getColumnName(int column) {
return columnName[column]; return columnName[column]; // 返回列名数组中指定索引的列名
} }
/* /*
public int getId() { *
return id; * public int getId() {
} * return id;
public int getValueAt(int rowIndex){ * }
SupplierInf supplierInf = suppliers.get(rowIndex); *
id=suppliers.get(rowIndex).getId(); * public int getValueAt(int rowIndex){
//System.out.println("rowIndex"+rowIndex); * SupplierInf supplierInf = suppliers.get(rowIndex);
//System.out.println("columnIndex"+columnIndex); * id = suppliers.get(rowIndex).getId();
return supplierInf.getId(); * return supplierInf.getId();
} * }
*/
*/ }
}

@ -3,17 +3,8 @@ package com.lingnan.supermarket.utils;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
// DateUtil类从名称可以推测是用于处理日期相关操作的工具类 // 用于处理日期相关操作的工具类
public class DateUtil { public class DateUtil {
/**
* dateToStringDate
*
* @param date Date
* @param pattern "yyyy-MM-dd HH:mm:ss"-- ::
* patternnull使"yyyy-MM-dd HH:mm:ss"
* @return 便使
*/
public static String dateToString(Date date, String pattern) { public static String dateToString(Date date, String pattern) {
// 创建SimpleDateFormat对象它是Java中用于格式化日期的类通过指定的模式将日期转换为相应格式的字符串。 // 创建SimpleDateFormat对象它是Java中用于格式化日期的类通过指定的模式将日期转换为相应格式的字符串。
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat();

@ -3,7 +3,6 @@ package com.lingnan.supermarket.utils;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import javax.mail.internet.AddressException; import javax.mail.internet.AddressException;
// EmailTest类
public class EmailTest { public class EmailTest {
//Java程序的入口点 //Java程序的入口点

@ -9,7 +9,7 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.Properties; import java.util.Properties;
// JDBCUtil工具类用于管理数据库连接相关的操作,如加载数据库配置、获取数据库连接以及释放相关资源等 // 用于管理数据库连接相关的操作,如加载数据库配置、获取数据库连接以及释放相关资源等
public class JDBCUtil { public class JDBCUtil {
// 用于存储数据库连接相关的配置信息,通过读取配置文件将配置项加载到该对象中 // 用于存储数据库连接相关的配置信息,通过读取配置文件将配置项加载到该对象中

@ -1,6 +1,6 @@
package com.lingnan.supermarket.utils; package com.lingnan.supermarket.utils;
//测试类,用于演示静态代码块的使用 //用于演示静态代码块的使用
public class Test { public class Test {
static { static {
System.out.println("tasdasd."); // 打印一条测试信息 System.out.println("tasdasd."); // 打印一条测试信息

@ -4,17 +4,8 @@ import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Random; import java.util.Random;
//具类,用于生成订单号和时间戳 //生成订单号和时间戳
public class TimeAndOrder { public class TimeAndOrder {
/**
*
*
* "yyyy-MM-dd HH:mm:ss"
*
* @param username
* @return
*/
public static String[] TimeAndOrder(String username) { public static String[] TimeAndOrder(String username) {
// 创建一个长度为2的字符串数组用于存储订单号和时间戳 // 创建一个长度为2的字符串数组用于存储订单号和时间戳
String[] s = new String[2]; String[] s = new String[2];

@ -29,166 +29,136 @@ import com.lingnan.supermarket.table.StorageTableModel;
import com.lingnan.supermarket.table.UserTableModel; import com.lingnan.supermarket.table.UserTableModel;
import com.lingnan.supermarket.utils.FontUtil; import com.lingnan.supermarket.utils.FontUtil;
public class ProdCatalogView extends JPanel { /**
*
* JPanel
*/
public class ProdCatalogView extends JPanel {
// 上面 // 顶部工具栏面板
private JPanel toolBarPanel; private JPanel toolBarPanel;
// 搜索面板
private JPanel searchPanel; private JPanel searchPanel;
private JLabel logLabel, locationLabel; private JLabel logLabel, locationLabel;
private JTextField nameSearchTF; private JTextField nameSearchTF;
private JButton searchBtn; private JButton searchBtn;
// 操作面板
private JPanel opePanel; private JPanel opePanel;
private JButton addBtn, updateBtn, deleteBtn; private JButton addBtn, updateBtn, deleteBtn;
private String catalog = "0"; // 商品类别相关变量
private JComboBox<String> combo; private String catalog = "0"; // 当前选中的商品类别ID
private String log[]=null; private JComboBox<String> combo; // 商品类别下拉框
private ArrayList<String>alog=null; private String log[] = null; // 商品类别名称数组
private ProdCatalogTM prodCatalogTM; private ArrayList<String> alog = null; // 商品类别名称列表
private ProdCatalog pc; private ProdCatalogTM prodCatalogTM; // 商品类别表格模型
private prodCatalogImpl pci; private ProdCatalog pc; // 商品类别对象
private prodCatalogImpl pci; // 商品类别服务实现类
// 中间 // 中间表格相关变量
private JScrollPane tableScrollPane; private JScrollPane tableScrollPane;
private JTable prodCatalogTable; private JTable prodCatalogTable;
// 下面 // 底部面板
private JPanel bottomPanel; private JPanel bottomPanel;
private JLabel countInfoLabel; private JLabel countInfoLabel;
private JFrame jFrame; private JFrame jFrame; // 父窗口
// 构造函数,初始化商品目录视图
public ProdCatalogView(JFrame jFrame) { public ProdCatalogView(JFrame jFrame) {
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout()); // 设置布局为BorderLayout
initView(); initView(); // 初始化视图
this.jFrame = jFrame; this.jFrame = jFrame; // 保存父窗口
} }
//初始化视图
private void initView() { private void initView() {
// 初始化顶部工具栏面板
toolBarPanel = new JPanel(new BorderLayout()); toolBarPanel = new JPanel(new BorderLayout());
// 初始化搜索面板
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
locationLabel = new JLabel("商品目录"); locationLabel = new JLabel("商品目录");
locationLabel.setFont(new FontUtil().userFont); locationLabel.setFont(new FontUtil().userFont); // 设置字体
locationLabel.setForeground(new Color(18, 150, 219)); locationLabel.setForeground(new Color(18, 150, 219)); // 设置颜色
logLabel = new JLabel("分类"); logLabel = new JLabel("分类");
nameSearchTF = new JTextField(10); nameSearchTF = new JTextField(10);
searchBtn = new JButton("搜索", new ImageIcon("static\\icon\\search.png")); searchBtn = new JButton("搜索", new ImageIcon("static\\icon\\search.png"));
// opePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // 初始化商品类别下拉框
// addBtn = new JButton(new ImageIcon("static\\icon\\add.png")); pci = new prodCatalogImpl();
// updateBtn = new JButton(new ImageIcon("static\\icon\\update.png")); this.alog = pci.findNameProdCatalog(); // 获取所有商品类别名称
// deleteBtn = new JButton(new ImageIcon("static\\icon\\delete.png")); this.log = new String[alog.size()]; // 初始化商品类别名称数组
for (int i = 0; i < alog.size(); i++)
// addBtn.addActionListener(this); log[i] = alog.get(i); // 将商品类别名称存入数组
// updateBtn.addActionListener(this);
// deleteBtn.addActionListener(this);
// opePanel.add(addBtn);
// opePanel.add(updateBtn);
// opePanel.add(deleteBtn);
pci=new prodCatalogImpl();
this.alog=pci.findNameProdCatalog();
this.log=new String[alog.size()];
for(int i=0;i<alog.size();i++)
log[i]=alog.get(i);
for(int i=0;i<log.length;i++)
{
System.out.println(log[i]);
}
combo = new JComboBox<String>(log); // 创建商品类别下拉框
combo.addItemListener(new MyItemListener()); // 添加下拉框监听器
// 将组件添加到搜索面板
combo = new JComboBox<String>(log);
combo.addItemListener(new MyItemListener());
searchPanel.add(locationLabel); searchPanel.add(locationLabel);
searchPanel.add(logLabel); searchPanel.add(logLabel);
searchPanel.add(combo); searchPanel.add(combo);
/*
* searchPanel.add(nameSearchTF); searchPanel.add(searchBtn);
*/
// 将搜索面板添加到工具栏面板的左侧
toolBarPanel.add(searchPanel, "West"); toolBarPanel.add(searchPanel, "West");
// toolBarPanel.add(opePanel, "East");
// 中间表格 // 初始化中间表格
prodCatalogTM = new ProdCatalogTM(); prodCatalogTM = new ProdCatalogTM();
prodCatalogTM.all(); prodCatalogTM.all(); // 加载所有商品类别数据
prodCatalogTable = new JTable(prodCatalogTM); prodCatalogTable = new JTable(prodCatalogTM);
prodCatalogTable.setFont(FontUtil.tableFont); prodCatalogTable.setFont(FontUtil.tableFont); // 设置表格字体
prodCatalogTable.setRowHeight(50); prodCatalogTable.setRowHeight(50); // 设置表格行高
tableScrollPane = new JScrollPane(prodCatalogTable); tableScrollPane = new JScrollPane(prodCatalogTable);
// 下面 // 初始化底部面板
bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
countInfoLabel = new JLabel("总共" + prodCatalogTable.getRowCount() + "条"); countInfoLabel = new JLabel("总共" + prodCatalogTable.getRowCount() + "条");
bottomPanel.add(countInfoLabel); bottomPanel.add(countInfoLabel);
this.add(toolBarPanel, "North"); // 将各个面板添加到主面板
this.add(tableScrollPane, "Center");/* 将表格放到中间 */ this.add(toolBarPanel, "North"); // 顶部工具栏
this.add(bottomPanel, "South"); this.add(tableScrollPane, "Center"); // 中间表格
this.add(bottomPanel, "South"); // 底部信息
setVisible(true); setVisible(true); // 设置可见
} }
// @Override //商品类别下拉框监听器
// public void actionPerformed(ActionEvent e) {
// Object source = e.getSource();
// if (addBtn == source) {
// UserDialog userDialog = new UserDialog(jFrame);
// userDialog.setVisible(true);
// } else if (updateBtn == source) {
//
// } else if (deleteBtn == source) {
//
// }
// }
public class MyItemListener implements ItemListener { public class MyItemListener implements ItemListener {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
JComboBox cb = (JComboBox) e.getSource(); JComboBox cb = (JComboBox) e.getSource();
String catalog1 = (String) cb.getSelectedItem(); String catalog1 = (String) cb.getSelectedItem(); // 获取选中的商品类别名称
pci =new prodCatalogImpl(); pci = new prodCatalogImpl();
for(int i=0;i<log.length;i++){ for (int i = 0; i < log.length; i++) {
if(catalog1.equals(log[i])) if (catalog1.equals(log[i]))
catalog = pci.findProdCatalogByname(catalog1); // 根据名称获取商品类别ID
catalog=pci.findProdCatalogByname(catalog1);
System.out.println(catalog); System.out.println(catalog);
} }
refreshFindId2(); refreshFindId2(); // 刷新界面
} }
} }
// 刷新当前界面 //刷新当前界面根据商品类别ID加载数据
public void refreshFindId2() { public void refreshFindId2() {
Production p = new Production(); Production p = new Production();
p.setId2(catalog); // 设置商品类别ID
p.setId2(catalog);
prodCatalogTM = new ProdCatalogTM(); prodCatalogTM = new ProdCatalogTM();
prodCatalogTM.ById2(p); prodCatalogTM.ById2(p); // 根据商品类别ID加载数据
prodCatalogTable.setModel(prodCatalogTM); prodCatalogTable.setModel(prodCatalogTM); // 更新表格模型
// 同时更新下面的记录数 refreshCount(); // 同时更新下面的记录数
refreshCount();
} }
//刷新底部记录数信息
public void refreshCount() { public void refreshCount() {
bottomPanel.removeAll(); bottomPanel.removeAll(); // 清空底部面板
countInfoLabel = new JLabel("总共" + prodCatalogTM.getRowCount() + "条"); countInfoLabel = new JLabel("总共" + prodCatalogTM.getRowCount() + "条"); // 更新记录数
bottomPanel.add(countInfoLabel); bottomPanel.add(countInfoLabel); // 添加到底部面板
} }
} }
Loading…
Cancel
Save