base文件夹部分修改

pull/43/head
郑亦歆 9 months ago
parent a19fdbe104
commit 43656d2b42

@ -43,165 +43,260 @@ import com.lingnan.supermarket.utils.SendQQMailUtil;
import com.lingnan.supermarket.utils.TimeAndOrder; import com.lingnan.supermarket.utils.TimeAndOrder;
import com.lingnan.supermarket.view.ProdCatalogView.MyItemListener; import com.lingnan.supermarket.view.ProdCatalogView.MyItemListener;
// 定义一个名为InView的类继承自JPanel并实现ActionListener接口
public class InView extends JPanel implements ActionListener{ public class InView extends JPanel implements ActionListener{
//上面 // 定义顶部工具栏面板
private JPanel toolBarPanel; private JPanel toolBarPanel;
// 定义搜索面板
private JPanel searchPanel; private JPanel searchPanel;
// 定义标签
private JLabel nameLabel,locationLabel; private JLabel nameLabel,locationLabel;
// 定义文本框,用于商品名称搜索
private JTextField nameSearchTF; private JTextField nameSearchTF;
// 定义按钮,包括搜索、库存、退出等
private JButton searchBtn,StockBtn,exitBtn; private JButton searchBtn,StockBtn,exitBtn;
// 定义操作面板
private JPanel opePanel; private JPanel opePanel;
// 定义操作按钮,包括添加、更新、删除、历史、返回、详情等
private JButton addBtn,updateBtn,deleteBtn,historyBtn,backBtn,detailBtn; private JButton addBtn,updateBtn,deleteBtn,historyBtn,backBtn,detailBtn;
//中间 // 定义中间部分的滚动面板和表格
private JScrollPane tableScrollPane; private JScrollPane tableScrollPane;
private JTable inTable; private JTable inTable;
//下面 // 定义底部面板及其左右部分
private JPanel bottomPanel,bottomPanelLeft,bottomPanelRight; private JPanel bottomPanel,bottomPanelLeft,bottomPanelRight;
// 定义显示记录数的标签
private JLabel countInfoLabel,countInfoLabel2; private JLabel countInfoLabel,countInfoLabel2;
// 定义缓冲区对象和其实现类
private Buffer Buffer; private Buffer Buffer;
private BufferImpl BufferImpl; private BufferImpl BufferImpl;
// 定义一个静态的向量用于存储Production对象
private static Vector<Production> v = new Vector<Production>(); private static Vector<Production> v = new Vector<Production>();
// 定义一个下拉框,用于选择状态
private JComboBox<String> combo; private JComboBox<String> combo;
// 定义状态数组,包含不同的货物状态
private String[] status ={"全部","已入库","待入库","已取消"}; private String[] status ={"全部","已入库","待入库","已取消"};
// 定义商品目录ID
private int catalog; private int catalog;
// 定义一个JFrame对象用于引用主窗口
private JFrame jFrame; private JFrame jFrame;
// 定义一个User对象用于存储当前用户信息
private User user; private User user;
// 定义一个表格模型,用于进货表格
private InTableModel inTableModel ; private InTableModel inTableModel ;
// 实例化缓冲区实现类
private BufferImpl bufferImpl = new BufferImpl(); private BufferImpl bufferImpl = new BufferImpl();
// 定义一个标记,用于区分是从进货表还是提醒过来的表
private int mark;/*标记从提醒那里来1是进货表0是提醒过来的表*/ private int mark;/*标记从提醒那里来1是进货表0是提醒过来的表*/
// 定义一个进货订单服务实现类
private inOrderServiceImpl inOrderImpl; private inOrderServiceImpl inOrderImpl;
// 定义一个浮点数,用于存储总价
private Float allPrice; private Float allPrice;
// 定义一个整数,用于存储行号
private int row; private int row;
// 定义一个字符串,用于存储用户名
private String uname; private String uname;
// InView类的构造方法接收主窗口、用户、货物向量、标记作为参数
public InView(JFrame jFrame,User user,Vector<Production> v,int mark) { public InView(JFrame jFrame,User user,Vector<Production> v,int mark) {
// 设置布局管理器为边界布局
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout());
// 保存传入的JFrame引用
this.jFrame = jFrame; this.jFrame = jFrame;
// 保存传入的用户对象
this.user = user; this.user = user;
//获得进货缓冲区的保存的货物并删除缓冲区 // 获取进货缓冲区保存的货物并删除缓冲区中的数据
this.v =bufferImpl.allInBuffer(); this.v =bufferImpl.allInBuffer();
bufferImpl.DelAllInBuffer(); bufferImpl.DelAllInBuffer();
// 保存传入的标记
this.mark=mark; this.mark=mark;
// 打印标记值
System.out.println("mark="+mark); System.out.println("mark="+mark);
// 获取用户名
uname = user.getUsername(); uname = user.getUsername();
// 初始化视图
initView(); initView();
} }
// 初始化视图的方法
private void initView() { private void initView() {
// 创建工具栏面板,并设置布局管理器为边界布局
toolBarPanel = new JPanel(new BorderLayout()); toolBarPanel = new JPanel(new BorderLayout());
// 创建搜索面板,并设置布局管理器为流布局,对齐方式为右对齐
searchPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); searchPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
// 创建并初始化订单号标签
nameLabel = new JLabel("订单号"); nameLabel = new JLabel("订单号");
// 创建文本框用于输入订单号宽度为20
nameSearchTF = new JTextField(20); nameSearchTF = new JTextField(20);
// 创建搜索按钮,并设置图标
searchBtn = new JButton(new ImageIcon("static\\icon\\search.png")); searchBtn = new JButton(new ImageIcon("static\\icon\\search.png"));
// 为搜索按钮添加动作监听器
searchBtn.addActionListener(this); searchBtn.addActionListener(this);
// 创建并初始化位置标签
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));
// 创建下拉框,并使用状态数组初始化
combo = new JComboBox<String>(status); combo = new JComboBox<String>(status);
// 为下拉框添加项目监听器
combo.addItemListener(new MyItemListener()); combo.addItemListener(new MyItemListener());
// 创建操作面板,并设置布局管理器为流布局,对齐方式为左对齐
opePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); opePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
// 创建添加按钮,并设置图标
addBtn =new JButton(new ImageIcon("static\\icon\\add.png")); addBtn =new JButton(new ImageIcon("static\\icon\\add.png"));
// 创建更新按钮,并设置图标
updateBtn =new JButton(new ImageIcon("static\\icon\\change.png")); updateBtn =new JButton(new ImageIcon("static\\icon\\change.png"));
// 创建删除按钮,并设置图标
deleteBtn =new JButton(new ImageIcon("static\\icon\\delete.png")); deleteBtn =new JButton(new ImageIcon("static\\icon\\delete.png"));
// 创建历史按钮,并设置图标
historyBtn =new JButton(new ImageIcon("static\\icon\\history.png")); historyBtn =new JButton(new ImageIcon("static\\icon\\history.png"));
// 创建返回按钮,并设置图标
backBtn =new JButton(new ImageIcon("static\\icon\\back.png")); backBtn =new JButton(new ImageIcon("static\\icon\\back.png"));
// 创建详情按钮,并设置图标
detailBtn = new JButton(new ImageIcon("static\\icon\\detail.png")); detailBtn = new JButton(new ImageIcon("static\\icon\\detail.png"));
// 为添加按钮添加动作监听器
addBtn.addActionListener(this); addBtn.addActionListener(this);
// 为更新按钮添加动作监听器
updateBtn.addActionListener(this); updateBtn.addActionListener(this);
// 为删除按钮添加动作监听器
deleteBtn.addActionListener(this); deleteBtn.addActionListener(this);
// 为历史按钮添加动作监听器
historyBtn.addActionListener(this); historyBtn.addActionListener(this);
// 为返回按钮添加动作监听器
backBtn.addActionListener(this); backBtn.addActionListener(this);
// 为详情按钮添加动作监听器
detailBtn.addActionListener(this); detailBtn.addActionListener(this);
backBtn.setVisible(false);/*在记录页面显示出来*/ // 设置返回按钮为不可见,它在记录页面会显示出来
detailBtn.setVisible(false);/*在订单详情页显示出来*/ backBtn.setVisible(false);
// 设置详情按钮为不可见,它在订单详情页会显示出来
detailBtn.setVisible(false);
// 将添加按钮添加到操作面板
opePanel.add(addBtn); opePanel.add(addBtn);
// 将返回按钮添加到操作面板
opePanel.add(backBtn); opePanel.add(backBtn);
// 将详情按钮添加到操作面板
opePanel.add(detailBtn); opePanel.add(detailBtn);
// 将更新按钮添加到操作面板
opePanel.add(updateBtn); opePanel.add(updateBtn);
// 将删除按钮添加到操作面板
opePanel.add(deleteBtn); opePanel.add(deleteBtn);
// 将历史按钮添加到操作面板
opePanel.add(historyBtn); opePanel.add(historyBtn);
// 将位置标签添加到搜索面板
searchPanel.add(locationLabel); searchPanel.add(locationLabel);
// 将订单号标签添加到搜索面板
searchPanel.add(nameLabel); searchPanel.add(nameLabel);
// 将订单号文本框添加到搜索面板
searchPanel.add(nameSearchTF); searchPanel.add(nameSearchTF);
// 将搜索按钮添加到搜索面板
searchPanel.add(searchBtn); searchPanel.add(searchBtn);
// 将下拉框添加到搜索面板
searchPanel.add(combo); searchPanel.add(combo);
// 将搜索面板添加到工具栏面板的西边
toolBarPanel.add(searchPanel,"West"); toolBarPanel.add(searchPanel,"West");
// 将操作面板添加到工具栏面板的东边
toolBarPanel.add(opePanel,"East"); toolBarPanel.add(opePanel,"East");
//中间表 // 初始化中间表格模型使用货物向量v
inTableModel = new InTableModel(v); inTableModel = new InTableModel(v);
// 创建表格,使用中间表格模型
inTable = new JTable(inTableModel); inTable = new JTable(inTableModel);
// 设置表格字体
inTable.setFont(FontUtil.tableFont); inTable.setFont(FontUtil.tableFont);
// 设置表格行高
inTable.setRowHeight(50); inTable.setRowHeight(50);
// 创建滚动面板,并将表格添加到其中
tableScrollPane = new JScrollPane(inTable); tableScrollPane = new JScrollPane(inTable);
// 获取表格模型中的总价格
allPrice = inTableModel.getAllPrice(); allPrice = inTableModel.getAllPrice();
// 获取表格模型中的行数
row = inTableModel.getRowCount(); row = inTableModel.getRowCount();
// 创建底部左侧面板,并设置布局管理器为流布局,对齐方式为右对齐
//下面
bottomPanelLeft = new JPanel(new FlowLayout(FlowLayout.RIGHT)); bottomPanelLeft = new JPanel(new FlowLayout(FlowLayout.RIGHT));
// 创建并初始化显示商品种类和总价的标签
countInfoLabel = new JLabel("商品种类:"+row+",总价:"+allPrice); countInfoLabel = new JLabel("商品种类:"+row+",总价:"+allPrice);
// 将标签添加到左侧面板,指定对齐方式为左对齐
bottomPanelLeft.add(countInfoLabel,"Left"); bottomPanelLeft.add(countInfoLabel,"Left");
// 创建底部右侧面板,并设置布局管理器为流布局,对齐方式为左对齐
bottomPanelRight = new JPanel(new FlowLayout(FlowLayout.LEFT)); bottomPanelRight = new JPanel(new FlowLayout(FlowLayout.LEFT));
// 创建结账按钮,并设置图标
StockBtn =new JButton(new ImageIcon("static\\icon\\stock.png"));/*结账按钮*/ StockBtn =new JButton(new ImageIcon("static\\icon\\stock.png"));/*结账按钮*/
// 创建退出按钮,并设置图标
exitBtn =new JButton(new ImageIcon("static\\icon\\exit.png"));/*退出按钮*/ exitBtn =new JButton(new ImageIcon("static\\icon\\exit.png"));/*退出按钮*/
// 为结账按钮添加动作监听器
StockBtn.addActionListener(this); StockBtn.addActionListener(this);
// 为退出按钮添加动作监听器
exitBtn.addActionListener(this); exitBtn.addActionListener(this);
// 将结账按钮添加到右侧面板
bottomPanelRight.add(StockBtn); bottomPanelRight.add(StockBtn);
// 将退出按钮添加到右侧面板
bottomPanelRight.add(exitBtn); bottomPanelRight.add(exitBtn);
// 创建底部面板,并设置布局管理器为边界布局
bottomPanel = new JPanel(new BorderLayout()); bottomPanel = new JPanel(new BorderLayout());
// 将右侧面板添加到底部面板的东边
bottomPanel.add(bottomPanelRight,"East"); bottomPanel.add(bottomPanelRight,"East");
// 将左侧面板添加到底部面板的西边
bottomPanel.add(bottomPanelLeft,"West"); bottomPanel.add(bottomPanelLeft,"West");
// 将工具栏面板添加到窗口的北边
this.add(toolBarPanel,"North"); this.add(toolBarPanel,"North");
// 将滚动面板(含表格)添加到窗口的中间
this.add(tableScrollPane,"Center");/*将表格放到中间*/ this.add(tableScrollPane,"Center");/*将表格放到中间*/
// 将底部面板添加到窗口的南边
this.add(bottomPanel,"South"); this.add(bottomPanel,"South");
// 如果标记为1表示从提醒页面过来刷新缓冲区
if(mark==1) /*判断是不是从提醒那里过来的*/{ if(mark==1) /*判断是不是从提醒那里过来的*/{
refreshBuffer(v); refreshBuffer(v);
} }
// 如果标记为0执行进货订单记录操作
else if(mark==0) { else if(mark==0) {
InOrderRecord(); InOrderRecord();
} }
@ -210,6 +305,10 @@ public class InView extends JPanel implements ActionListener{
// 设置窗口为可见
setVisible(true); setVisible(true);
@ -217,19 +316,25 @@ public class InView extends JPanel implements ActionListener{
} }
// 提供一个静态方法用于获取存储Production对象的向量
public static Vector<Production> getVector(){ public static Vector<Production> getVector(){
return v; return v;
} }
// 定义一个内部类实现ItemListener接口用于监听下拉框的项目状态改变事件
public class MyItemListener implements ItemListener { public class MyItemListener implements ItemListener {
// 重写itemStateChanged方法当下拉框中的项目状态改变时被调用
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
// 将事件源强制转换为JComboBox
JComboBox cb = (JComboBox) e.getSource(); JComboBox cb = (JComboBox) e.getSource();
// 获取下拉框中选中的项目,并转换为字符串
String catalog1 = (String) cb.getSelectedItem(); String catalog1 = (String) cb.getSelectedItem();
// 根据选中的项目设置商品目录ID
if(catalog1.equals("全部")) if(catalog1.equals("全部"))
catalog=0; catalog=0;
else if(catalog1.equals("已入库")) else if(catalog1.equals("已入库"))
@ -239,91 +344,152 @@ public class InView extends JPanel implements ActionListener{
else if(catalog1.equals("已取消")) else if(catalog1.equals("已取消"))
catalog=3; catalog=3;
// 根据商品目录ID执行查找状态的结果处理
resultOfFindStatus(catalog); resultOfFindStatus(catalog);
} }
} }
}
//按钮组件隐藏
// 设置按钮组件的可见性,用于订单视图
public void OrderView() { public void OrderView() {
// 显示返回按钮
backBtn.setVisible(true); backBtn.setVisible(true);
// 显示详情按钮
detailBtn.setVisible(true); detailBtn.setVisible(true);
// 显示更新按钮
updateBtn.setVisible(true); updateBtn.setVisible(true);
// 显示删除按钮
deleteBtn.setVisible(true); deleteBtn.setVisible(true);
// 隐藏添加按钮
addBtn.setVisible(false); addBtn.setVisible(false);
// 隐藏历史按钮
historyBtn.setVisible(false); historyBtn.setVisible(false);
} }
// 根据订单编号处理结果
public void resultOfNumber(String iNumber) { public void resultOfNumber(String iNumber) {
// 重置标记
this.mark=0; this.mark=0;
// 创建订单表格模型
InOrderTM inOrderTM = new InOrderTM(); InOrderTM inOrderTM = new InOrderTM();
// 根据订单编号查询结果
inOrderTM.resultOfNumber(iNumber); inOrderTM.resultOfNumber(iNumber);
// 更新表格模型
inTable.setModel(inOrderTM); inTable.setModel(inOrderTM);
// 清空底部左侧面板
bottomPanelLeft.removeAll(); bottomPanelLeft.removeAll();
// 创建并初始化显示记录数的标签
countInfoLabel = new JLabel("共"+inOrderTM.getRowCount()+"条记录"); countInfoLabel = new JLabel("共"+inOrderTM.getRowCount()+"条记录");
// 将标签添加到底部左侧面板
bottomPanelLeft.add(countInfoLabel); bottomPanelLeft.add(countInfoLabel);
// 调用OrderView设置按钮可见性
OrderView(); OrderView();
} }
// 根据状态处理查询结果
public void resultOfFindStatus(int catalog) { public void resultOfFindStatus(int catalog) {
// 重置标记
this.mark=0; this.mark=0;
// 创建订单表格模型
InOrderTM inOrderTM = new InOrderTM(); InOrderTM inOrderTM = new InOrderTM();
// 根据状态查询结果
inOrderTM.resultOfFind(catalog); inOrderTM.resultOfFind(catalog);
// 更新表格模型
inTable.setModel(inOrderTM); inTable.setModel(inOrderTM);
// 清空底部左侧面板
bottomPanelLeft.removeAll(); bottomPanelLeft.removeAll();
// 创建并初始化显示记录数的标签
countInfoLabel = new JLabel("共"+inOrderTM.getRowCount()+"条记录"); countInfoLabel = new JLabel("共"+inOrderTM.getRowCount()+"条记录");
// 将标签添加到底部左侧面板
bottomPanelLeft.add(countInfoLabel); bottomPanelLeft.add(countInfoLabel);
// 调用OrderView设置按钮可见性
OrderView(); OrderView();
} }
// 刷新缓冲区,更新表格数据
/*刷新*/
public void refreshBuffer(Vector<Production> v) { public void refreshBuffer(Vector<Production> v) {
// 设置标记
this.mark=1; this.mark=1;
// 创建商品表格模型
InTableModel inTableModel = new InTableModel(v); InTableModel inTableModel = new InTableModel(v);
// 更新表格模型
inTable.setModel(inTableModel); inTable.setModel(inTableModel);
// 清空底部左侧面板
bottomPanelLeft.removeAll(); bottomPanelLeft.removeAll();
// 创建并初始化显示商品种类和总价的标签
countInfoLabel = new JLabel("商品种类:"+inTableModel.getRowCount()+",总价:"+inTableModel.getAllPrice()); countInfoLabel = new JLabel("商品种类:"+inTableModel.getRowCount()+",总价:"+inTableModel.getAllPrice());
// 将标签添加到底部左侧面板
bottomPanelLeft.add(countInfoLabel); bottomPanelLeft.add(countInfoLabel);
// 隐藏返回按钮
backBtn.setVisible(false); backBtn.setVisible(false);
// 隐藏详情按钮
detailBtn.setVisible(false); detailBtn.setVisible(false);
// 显示历史按钮
historyBtn.setVisible(true); historyBtn.setVisible(true);
// 显示更新按钮
updateBtn.setVisible(true); updateBtn.setVisible(true);
// 显示添加按钮
addBtn.setVisible(true); addBtn.setVisible(true);
// 显示删除按钮
deleteBtn.setVisible(true); deleteBtn.setVisible(true);
// 更新总价和行数
allPrice = inTableModel.getAllPrice(); allPrice = inTableModel.getAllPrice();
row = inTableModel.getRowCount(); row = inTableModel.getRowCount();
} }
/* 调出进货订单表 */ /* 调出进货订单表 */
public void InOrderRecord() { public void InOrderRecord() {
// 设置标记为0
this.mark=0; this.mark=0;
// 创建进货订单表格模型
InOrderTM inOrderTM = new InOrderTM(); InOrderTM inOrderTM = new InOrderTM();
// 获取所有进货订单记录
inOrderTM.allInOrderRecord(); inOrderTM.allInOrderRecord();
// 更新表格模型
inTable.setModel(inOrderTM); inTable.setModel(inOrderTM);
// 清空底部左侧面板
bottomPanelLeft.removeAll(); bottomPanelLeft.removeAll();
// 创建并初始化显示记录数的标签
countInfoLabel = new JLabel("共"+inOrderTM.getRowCount()+"条记录"); countInfoLabel = new JLabel("共"+inOrderTM.getRowCount()+"条记录");
// 将标签添加到底部左侧面板
bottomPanelLeft.add(countInfoLabel); bottomPanelLeft.add(countInfoLabel);
// 调用OrderView设置按钮可见性
OrderView(); OrderView();
} }
/*调出进货订单表*/ /* 根据订单号调出进货订单记录 */
public void InRecord(String iNumber) { public void InRecord(String iNumber) {
// 设置标记为2
this.mark=2; this.mark=2;
// 创建进货记录表格模型,并传入订单号
InRecordTM inRecordTM = new InRecordTM(iNumber); InRecordTM inRecordTM = new InRecordTM(iNumber);
// 根据订单号查询进货记录
inRecordTM.findInRecordByINumber(); inRecordTM.findInRecordByINumber();
// 更新表格模型
inTable.setModel(inRecordTM); inTable.setModel(inRecordTM);
// 清空底部左侧面板
bottomPanelLeft.removeAll(); bottomPanelLeft.removeAll();
// 创建并初始化显示订单号和记录数的标签
countInfoLabel = new JLabel("订单号@"+iNumber+"共有"+inRecordTM.getRowCount()+"条记录"); countInfoLabel = new JLabel("订单号@"+iNumber+"共有"+inRecordTM.getRowCount()+"条记录");
// 将标签添加到底部左侧面板
bottomPanelLeft.add(countInfoLabel); bottomPanelLeft.add(countInfoLabel);
// 设置按钮可见性
backBtn.setVisible(true); backBtn.setVisible(true);
detailBtn.setVisible(false); detailBtn.setVisible(false);
updateBtn.setVisible(false); updateBtn.setVisible(false);
@ -331,183 +497,270 @@ public class InView extends JPanel implements ActionListener{
historyBtn.setVisible(false); historyBtn.setVisible(false);
deleteBtn.setVisible(false); deleteBtn.setVisible(false);
}
} }
/*按钮监听时间*/ /* 按钮监听事件 */
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// 实例化购物车
BufferImpl = new BufferImpl();/* 获得购物车 */ BufferImpl = new BufferImpl();/* 获得购物车 */
// 获取事件源
Object source = e.getSource(); Object source = e.getSource();
// 如果事件源是搜索按钮
if(searchBtn==source) { if(searchBtn==source) {
// 获取搜索框中的文本
String number = nameSearchTF.getText(); String number = nameSearchTF.getText();
// 打印搜索后的订单号
System.out.println("搜索后的订单:"+number); System.out.println("搜索后的订单:"+number);
// 处理搜索结果
resultOfNumber(number); resultOfNumber(number);
} }
// 如果事件源是添加按钮
else if(addBtn==source) {/* 添加 */ else if(addBtn==source) {/* 添加 */
// 创建并显示添加对话框
InDialog outDialog = new InDialog(jFrame,v,user); InDialog outDialog = new InDialog(jFrame,v,user);
outDialog.setVisible(true); outDialog.setVisible(true);
// 获取对话框中的向量并更新
v=outDialog.getVector(); v=outDialog.getVector();
// 刷新购物车
refreshBuffer(v); refreshBuffer(v);
} }
// 如果事件源是更新按钮
else if(updateBtn==source) {/* 更新 */ else if(updateBtn==source) {/* 更新 */
// 打印当前标记
System.out.println("mark="+mark); System.out.println("mark="+mark);
// 获取选中行的索引
int rowIndex = inTable.getSelectedRow(); int rowIndex = inTable.getSelectedRow();
// 如果没有选中行,弹出提示
if(rowIndex==-1) { if(rowIndex==-1) {
JOptionPane.showMessageDialog(this,"请选中一条进行更改数量"); JOptionPane.showMessageDialog(this,"请选中一条进行更改数量");
return; return;
} }
//进货表修改 // 如果标记为1表示进货表修改
if(mark==1) { if(mark==1) {
// 获取选中行的ID
String id =(String) inTable.getValueAt(rowIndex,0); String id =(String) inTable.getValueAt(rowIndex,0);
// 创建并显示更改数量对话框
ChangeSumDialog changesumDialog = new ChangeSumDialog(jFrame,id,"In",v); ChangeSumDialog changesumDialog = new ChangeSumDialog(jFrame,id,"In",v);
changesumDialog.setVisible(true); changesumDialog.setVisible(true);
// 获取对话框中的向量并更新
v = changesumDialog.getVector(); v = changesumDialog.getVector();
// 打印更改状态后的向量大小
System.out.println("更改状态后v.size="+v.size()); System.out.println("更改状态后v.size="+v.size());
// 刷新购物车
refreshBuffer(v); refreshBuffer(v);
} }
//inOrder修改,修改状态 // 如果标记为0表示inOrder修改修改状态
else if(mark==0) { else if(mark==0) {
// 获取选中行的订单号和状态
String iNumber =(String) inTable.getValueAt(rowIndex,0); String iNumber =(String) inTable.getValueAt(rowIndex,0);
String status =(String) inTable.getValueAt(rowIndex,4); String status =(String) inTable.getValueAt(rowIndex,4);
// 如果状态为已入库,弹出提示
if(status.equals("已入库")) { if(status.equals("已入库")) {
JOptionPane.showMessageDialog(this,"订单上的货物已入库无法修改状态","提示",JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(this,"订单上的货物已入库无法修改状态","提示",JOptionPane.INFORMATION_MESSAGE);
return; return;
} }
// 创建并显示更改状态对话框
ChangeStatusDialog changeStatusDialog = new ChangeStatusDialog(jFrame,iNumber,status); ChangeStatusDialog changeStatusDialog = new ChangeStatusDialog(jFrame,iNumber,status);
changeStatusDialog.setVisible(true); changeStatusDialog.setVisible(true);
// 刷新提醒和首页视图
MainView.refreshRemind(); MainView.refreshRemind();
HomeView.refreshHome(); HomeView.refreshHome();
// 重新加载进货订单记录
InOrderRecord(); InOrderRecord();
} }
} }
// 如果事件源是删除按钮
else if(deleteBtn==source) { else if(deleteBtn==source) {
// 获取选中行的索引
int rowIndex = inTable.getSelectedRow(); int rowIndex = inTable.getSelectedRow();
// 如果没有选中行,弹出提示
if(rowIndex==-1) { if(rowIndex==-1) {
JOptionPane.showMessageDialog(this,"请选中一条"); JOptionPane.showMessageDialog(this,"请选中一条");
return; return;
} }
/*删除进货表的*/
/* 删除进货表的记录 */
if(mark==1) { if(mark==1) {
// 打印提示信息
System.out.println("删除进货表"); System.out.println("删除进货表");
// 获取选中行的ID
String id =(String) inTable.getValueAt(rowIndex,0); String id =(String) inTable.getValueAt(rowIndex,0);
// 显示确认删除对话框
int select = JOptionPane.showConfirmDialog(this,"是否删除id为"+id+"的记录","提示",JOptionPane.YES_NO_OPTION); int select = JOptionPane.showConfirmDialog(this,"是否删除id为"+id+"的记录","提示",JOptionPane.YES_NO_OPTION);
// 如果用户选择是
if(select==JOptionPane.YES_OPTION) {/*选择是*/ if(select==JOptionPane.YES_OPTION) {/*选择是*/
// 遍历向量v查找并删除对应ID的记录
for(int i =0;i<v.size();i++) { for(int i =0;i<v.size();i++) {
// 打印删除操作开始提示
System.out.println("开始删除"); System.out.println("开始删除");
// 如果找到对应ID的记录
if(v.elementAt(i).getId().equals(id)) if(v.elementAt(i).getId().equals(id))
{ {
// 删除记录
v.remove(i); v.remove(i);
// 显示删除成功提示
JOptionPane.showMessageDialog(this,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(this,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE);
break; break;
} }
} }
// 刷新购物车
refreshBuffer(v); refreshBuffer(v);
} }
} }
//删除进货订单*/ // 删除进货订单的记录
else if(mark==0) { else if(mark==0) {
// 打印提示信息
System.out.println("删除订单表"); System.out.println("删除订单表");
// 获取选中行的订单号
String iNumber =(String) inTable.getValueAt(rowIndex,0); String iNumber =(String) inTable.getValueAt(rowIndex,0);
// 显示确认删除对话框
int select = JOptionPane.showConfirmDialog(this,"是否删除订单为"+iNumber+"的记录","提示",JOptionPane.YES_NO_OPTION); int select = JOptionPane.showConfirmDialog(this,"是否删除订单为"+iNumber+"的记录","提示",JOptionPane.YES_NO_OPTION);
// 如果用户选择是
if(select==JOptionPane.YES_OPTION) {/*选择是*/ if(select==JOptionPane.YES_OPTION) {/*选择是*/
// 打印订单号
System.out.println("iNumber="+iNumber); System.out.println("iNumber="+iNumber);
// 实例化订单服务实现类
inOrderImpl=new inOrderServiceImpl(); inOrderImpl=new inOrderServiceImpl();
// 调用删除订单的方法
inOrderImpl.deleteInOrder(iNumber); inOrderImpl.deleteInOrder(iNumber);
// 显示删除成功提示
JOptionPane.showMessageDialog(this,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(this,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE);
// 重新加载进货订单记录
InOrderRecord(); InOrderRecord();
} }
}
// 如果事件源是查看历史按钮
}else if(historyBtn==source) {/*查看历史全部记录*/ }else if(historyBtn==source) {/*查看历史全部记录*/
// 重新加载进货订单记录
InOrderRecord(); InOrderRecord();
// 如果事件源是返回按钮
}else if(backBtn==source) {/*历史记录中的返回按钮*/ }else if(backBtn==source) {/*历史记录中的返回按钮*/
// 如果标记为0刷新购物车
if(mark==0) if(mark==0)
refreshBuffer(v); refreshBuffer(v);
// 如果标记为2重新加载进货订单记录
else if(mark==2) else if(mark==2)
InOrderRecord(); InOrderRecord();
// 如果事件源是详情按钮
}else if(detailBtn==source) {/*查看订单详细*/ }else if(detailBtn==source) {/*查看订单详细*/
// 获取选中行的索引
int rowIndex = inTable.getSelectedRow(); int rowIndex = inTable.getSelectedRow();
// 如果没有选中行,弹出提示
if(rowIndex==-1) { if(rowIndex==-1) {
JOptionPane.showMessageDialog(this,"请选中一条查看订单详细信息"); JOptionPane.showMessageDialog(this,"请选中一条查看订单详细信息");
return; return;
} }
// 获取选中行的订单号
String iNumber =(String) inTable.getValueAt(rowIndex,0); String iNumber =(String) inTable.getValueAt(rowIndex,0);
// 打印详情订单号
System.out.println("详情订单号为="+iNumber); System.out.println("详情订单号为="+iNumber);
// 查看订单详细信息
InRecord(iNumber); InRecord(iNumber);
} }
// 如果事件源是结账按钮
else if(StockBtn==source) {/*结账*/ else if(StockBtn==source) {/*结账*/
// 刷新购物车
refreshBuffer(v); refreshBuffer(v);
// 如果购物车为空
if(v.size()==0)/*购物车为空*/{ if(v.size()==0)/*购物车为空*/{
// 显示提示信息
JOptionPane.showMessageDialog(null,"您的进货页面为空", "提示", JOptionPane.YES_OPTION); JOptionPane.showMessageDialog(null,"您的进货页面为空", "提示", JOptionPane.YES_OPTION);
} }
// 如果购物车不为空
else {/*购物车不为空*/ else {/*购物车不为空*/
// 显示确认对话框,包含进价总金额、负责人等信息
int res = JOptionPane.showConfirmDialog(null,"进价总金额:"+allPrice+"元\r\n负责人:"+uname+"\r\n发送邮件至 re@qq.com", "提交订单", JOptionPane.YES_NO_OPTION); int res = JOptionPane.showConfirmDialog(null,"进价总金额:"+allPrice+"元\r\n负责人:"+uname+"\r\n发送邮件至 re@qq.com", "提交订单", JOptionPane.YES_NO_OPTION);
// 如果用户选择是,即已经结账
if(res==JOptionPane.YES_OPTION)/*如果已经结账*/{ if(res==JOptionPane.YES_OPTION)/*如果已经结账*/{
/*获得时间和订单号,s[0]为订单号,s[1]为时间*/ // 获取时间和订单号s[0]为订单号s[1]为时间
String[] s =TimeAndOrder.TimeAndOrder(uname); String[] s =TimeAndOrder.TimeAndOrder(uname);
/*往订单表插入一条记录*/ // 往订单表插入一条记录
inOrderServiceImpl inOrderImpl = new inOrderServiceImpl(); inOrderServiceImpl inOrderImpl = new inOrderServiceImpl();
inOrderImpl.InsertInOrder(s[0], allPrice, s[1],uname ,2); inOrderImpl.InsertInOrder(s[0], allPrice, s[1],uname ,2);
/*往inRecord表添加数据*/ // 往inRecord表添加数据
inRecordServiceImpl inRecordImpl = new inRecordServiceImpl(); inRecordServiceImpl inRecordImpl = new inRecordServiceImpl();
for(Production p:v) {/*往inRecord表添加数据*/ for(Production p:v) {/*往inRecord表添加数据*/
inRecordImpl.insertInRecord(s[0], p); inRecordImpl.insertInRecord(s[0], p);
} }
/*生成订单文本*/ // 生成订单文本
CreateOrder createOrder = new CreateOrder(); CreateOrder createOrder = new CreateOrder();
String OrderText = createOrder.CreateOrder(v, s[0], s[1], allPrice,uname); String OrderText = createOrder.CreateOrder(v, s[0], s[1], allPrice,uname);
try {/*发送邮件*/ try {/*发送邮件*/
SendQQMailUtil QQEmail = new SendQQMailUtil("cwfeng5@qq.com","wlcinslohrgpdiac","1912638153@qq.com","@新民超市进货需求申请",OrderText); SendQQMailUtil QQEmail = new SendQQMailUtil("cwfeng5@qq.com","wlcinslohrgpdiac","1912638153@qq.com","@新民超市进货需求申请",OrderText);
} catch (MessagingException e1) { } catch (MessagingException e1) {
// TODO Auto-generated catch block // 打印异常堆栈信息
e1.printStackTrace(); e1.printStackTrace();
} }
// 清空购物车
v=new Vector<Production>(); v=new Vector<Production>();
// 刷新购物车显示
refreshBuffer(v); refreshBuffer(v);
// 刷新主视图提醒
MainView.refreshRemind(); MainView.refreshRemind();
// 显示发送邮件成功提示
JOptionPane.showConfirmDialog(null,"发送邮件成功\r\n订单号:"+s[0]+"\r\n负责人:"+uname, "提示", JOptionPane.YES_OPTION); JOptionPane.showConfirmDialog(null,"发送邮件成功\r\n订单号:"+s[0]+"\r\n负责人:"+uname, "提示", JOptionPane.YES_OPTION);
}
} }
// 如果事件源是退出按钮
}else if(exitBtn==source) { }else if(exitBtn==source) {
// 显示确认对话框,询问是否退出并清空购物车
int res = JOptionPane.showConfirmDialog(null,"确定退出并清空购物车吗", "结账", JOptionPane.YES_NO_OPTION); int res = JOptionPane.showConfirmDialog(null,"确定退出并清空购物车吗", "结账", JOptionPane.YES_NO_OPTION);
// 如果用户选择是,即退出
if(res==JOptionPane.YES_OPTION)/*如果退出*/{ if(res==JOptionPane.YES_OPTION)/*如果退出*/{
// 将购物车数组置空
v=new Vector<Production>();/*将数组置空*/ v=new Vector<Production>();/*将数组置空*/
// 刷新购物车显示
refreshBuffer(v); refreshBuffer(v);
// 显示退出成功提示
JOptionPane.showConfirmDialog(null,"退出成功", "提示", JOptionPane.PLAIN_MESSAGE); JOptionPane.showConfirmDialog(null,"退出成功", "提示", JOptionPane.PLAIN_MESSAGE);
} }
} }
} }
} }

@ -1,104 +1,121 @@
package com.lingnan.supermarket.view; package com.lingnan.supermarket.view; // 定义包名,包含视图相关的类
import java.awt.BorderLayout; import java.awt.BorderLayout; // 导入用于窗口布局的BorderLayout类
import java.awt.Color; import java.awt.Color; // 导入用于颜色处理的Color类
import java.awt.FlowLayout; import java.awt.FlowLayout; // 导入用于面板布局的FlowLayout类
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent; // 导入用于处理动作事件的ActionEvent类
import java.awt.event.ActionListener; import java.awt.event.ActionListener; // 导入用于监听动作事件的ActionListener接口
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent; // 导入用于处理项目事件的ItemEvent类
import java.awt.event.ItemListener; import java.awt.event.ItemListener; // 导入用于监听项目事件的ItemListener接口
import java.util.ArrayList; import java.util.ArrayList; // 导入用于数组列表的ArrayList类
import javax.swing.ImageIcon; import javax.swing.ImageIcon; // 导入用于处理图像图标的ImageIcon类
import javax.swing.JButton; import javax.swing.JButton; // 导入用于创建按钮的JButton类
import javax.swing.JComboBox; import javax.swing.JComboBox; // 导入用于创建组合框的JComboBox类
import javax.swing.JFrame; import javax.swing.JFrame; // 导入用于创建窗口的JFrame类
import javax.swing.JLabel; import javax.swing.JLabel; // 导入用于创建标签的JLabel类
import javax.swing.JPanel; import javax.swing.JPanel; // 导入用于创建面板的JPanel类
import javax.swing.JScrollPane; import javax.swing.JScrollPane; // 导入用于创建滚动窗格的JScrollPane类
import javax.swing.JTable; import javax.swing.JTable; // 导入用于创建表格的JTable类
import javax.swing.JTextField; import javax.swing.JTextField; // 导入用于创建文本字段的JTextField类
import com.lingnan.supermarket.dao.impl.prodCatalogImpl; import com.lingnan.supermarket.dao.impl.prodCatalogImpl; // 导入产品目录数据访问层的实现类
import com.lingnan.supermarket.dialog.UserDialog; import com.lingnan.supermarket.dialog.UserDialog; // 导入用户对话框类
import com.lingnan.supermarket.dto.ProdCatalog; import com.lingnan.supermarket.dto.ProdCatalog; // 导入产品目录数据传输对象
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.table.ProdCatalogTM; import com.lingnan.supermarket.table.ProdCatalogTM; // 导入产品目录表格模型
import com.lingnan.supermarket.table.StorageTableModel; 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 { public class ProdCatalogView extends JPanel { // 创建一个公共类ProdCatalogView继承自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 String catalog = "0"; // 目录字符串,默认为"0"
private JComboBox<String> combo; private JComboBox<String> combo; // 字符串组合框
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 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) { // ProdCatalogView构造方法接收一个JFrame参数
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout()); // 设置面板布局为BorderLayout
initView(); initView(); // 初始化视图
this.jFrame = jFrame; this.jFrame = jFrame; // 将传入的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("分类");
// 创建文本框用于输入搜索内容指定宽度为10
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)); // opePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
// // 创建并初始化按钮,指定图标
// addBtn = new JButton(new ImageIcon("static\\icon\\add.png")); // addBtn = new JButton(new ImageIcon("static\\icon\\add.png"));
// updateBtn = new JButton(new ImageIcon("static\\icon\\update.png")); // updateBtn = new JButton(new ImageIcon("static\\icon\\update.png"));
// deleteBtn = new JButton(new ImageIcon("static\\icon\\delete.png")); // deleteBtn = new JButton(new ImageIcon("static\\icon\\delete.png"));
//
// // 为按钮添加事件监听器
// addBtn.addActionListener(this); // addBtn.addActionListener(this);
// updateBtn.addActionListener(this); // updateBtn.addActionListener(this);
// deleteBtn.addActionListener(this); // deleteBtn.addActionListener(this);
//
// // 将按钮添加到操作面板
// opePanel.add(addBtn); // opePanel.add(addBtn);
// opePanel.add(updateBtn); // opePanel.add(updateBtn);
// opePanel.add(deleteBtn); // opePanel.add(deleteBtn);
// 实例化商品目录实现类
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);
// 打印商品目录名称,用于调试
for(int i=0;i<log.length;i++) for(int i=0;i<log.length;i++)
{ {
System.out.println(log[i]); System.out.println(log[i]);
@ -108,39 +125,61 @@ public class ProdCatalogView extends JPanel {
// 创建下拉列表,并使用商品目录名称作为选项
combo = new JComboBox<String>(log); combo = new JComboBox<String>(log);
// 为下拉列表添加项目监听器
combo.addItemListener(new MyItemListener()); 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); *
* searchPanel.add(nameSearchTF);
* searchPanel.add(searchBtn);
*/ */
// 将搜索面板添加到工具栏面板的西边
toolBarPanel.add(searchPanel, "West"); toolBarPanel.add(searchPanel, "West");
// 将操作面板添加到工具栏面板的东边,当前被注释
// toolBarPanel.add(opePanel, "East"); // 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(toolBarPanel, "North");
// 将表格滚动面板添加到当前窗口的中间
this.add(tableScrollPane, "Center");/* 将表格放到中间 */ this.add(tableScrollPane, "Center");/* 将表格放到中间 */
// 将底部面板添加到当前窗口的南部
this.add(bottomPanel, "South"); this.add(bottomPanel, "South");
// 设置当前窗口为可见
setVisible(true); setVisible(true);
} }
// 以下是注释掉的代码,实现按钮的事件监听
// @Override // @Override
// public void actionPerformed(ActionEvent e) { // public void actionPerformed(ActionEvent e) {
// Object source = e.getSource(); // Object source = e.getSource();
@ -148,47 +187,73 @@ public class ProdCatalogView extends JPanel {
// UserDialog userDialog = new UserDialog(jFrame); // UserDialog userDialog = new UserDialog(jFrame);
// userDialog.setVisible(true); // userDialog.setVisible(true);
// } else if (updateBtn == source) { // } else if (updateBtn == source) {
// // // 更新按钮的逻辑
// } else if (deleteBtn == 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); catalog=pci.findProdCatalogByname(catalog1);
// 打印商品目录对象,用于调试
System.out.println(catalog); System.out.println(catalog);
} }
// 刷新界面,显示与所选商品目录相关的数据
refreshFindId2(); refreshFindId2();
} }
} }
// 刷新当前界面 // 刷新当前界面,显示与特定商品目录相关的数据
public void refreshFindId2() { public void refreshFindId2() {
// 创建商品对象
Production p = new Production(); Production p = new Production();
// 设置商品目录ID
p.setId2(catalog); p.setId2(catalog);
// 创建新的表格模型根据商品目录ID查询数据
prodCatalogTM = new ProdCatalogTM(); prodCatalogTM = new ProdCatalogTM();
prodCatalogTM.ById2(p); prodCatalogTM.ById2(p);
// 更新表格模型
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);
} }
} }

@ -1,224 +1,234 @@
package com.lingnan.supermarket.view; package com.lingnan.supermarket.view; // 定义包名
import java.awt.BorderLayout; import java.awt.BorderLayout; // 导入BorderLayout布局管理器
import java.awt.Color; import java.awt.Color; // 导入Color类用于颜色管理
import java.awt.FlowLayout; import java.awt.FlowLayout; // 导入FlowLayout布局管理器
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent; // 导入ActionEvent类用于事件处理
import java.awt.event.ActionListener; import java.awt.event.ActionListener; // 导入ActionListener接口用于监听事件
import javax.swing.ImageIcon; import javax.swing.ImageIcon; // 导入ImageIcon类用于显示图片
import javax.swing.JButton; import javax.swing.JButton; // 导入JButton类用于创建按钮
import javax.swing.JFrame; import javax.swing.JFrame; // 导入JFrame类用于创建窗口
import javax.swing.JLabel; import javax.swing.JLabel; // 导入JLabel类用于创建标签
import javax.swing.JOptionPane; import javax.swing.JOptionPane; // 导入JOptionPane类用于显示对话框
import javax.swing.JPanel; import javax.swing.JPanel; // 导入JPanel类用于创建面板
import javax.swing.JScrollPane; import javax.swing.JScrollPane; // 导入JScrollPane类用于创建滚动面板
import javax.swing.JTable; import javax.swing.JTable; // 导入JTable类用于创建表格
import javax.swing.JTextField; import javax.swing.JTextField; // 导入JTextField类用于创建文本框
import com.lingnan.supermarket.dao.productionService; import com.lingnan.supermarket.dao.productionService; // 导入productionService接口
import com.lingnan.supermarket.dao.impl.productionImpl; import com.lingnan.supermarket.dao.impl.productionImpl; // 导入productionImpl类
import com.lingnan.supermarket.dialog.ProductionDialog; import com.lingnan.supermarket.dialog.ProductionDialog; // 导入ProductionDialog类
import com.lingnan.supermarket.dialog.UserDialog; import com.lingnan.supermarket.dialog.UserDialog; // 导入UserDialog类
import com.lingnan.supermarket.dto.Production; import com.lingnan.supermarket.dto.Production; // 导入Production类
import com.lingnan.supermarket.table.StorageRecordTM; import com.lingnan.supermarket.table.StorageRecordTM; // 导入StorageRecordTM类
import com.lingnan.supermarket.table.StorageTableModel; import com.lingnan.supermarket.table.StorageTableModel; // 导入StorageTableModel类
import com.lingnan.supermarket.utils.FontUtil; import com.lingnan.supermarket.utils.FontUtil; // 导入FontUtil类
public class StorageView extends JPanel implements ActionListener{ public class StorageView extends JPanel implements ActionListener{ // 定义StorageView类并实现ActionListener接口
//上面 //上面
private JPanel toolBarPanel; private JPanel toolBarPanel; // 工具栏面板变量声明
private JPanel searchPanel; private JPanel searchPanel; // 搜索面板变量声明
private JLabel nameLabel,locationLabel; private JLabel nameLabel,locationLabel; // 标签变量声明
private JTextField nameSearchTF; private JTextField nameSearchTF; // 文本框变量声明
private JButton searchBtn; private JButton searchBtn; // 搜索按钮变量声明
private JPanel opePanel; private JPanel opePanel; // 操作面板变量声明
private JButton addBtn,updateBtn,deleteBtn,historyBtn,backBtn; private JButton addBtn,updateBtn,deleteBtn,historyBtn,backBtn; // 按钮变量声明
//中间 //中间
private JScrollPane tableScrollPane; private JScrollPane tableScrollPane; // 表格滚动面板变量声明
private JTable storageTable; private JTable storageTable; // 表格变量声明
//下面 //下面
private JPanel bottomPanel; private JPanel bottomPanel; // 底部面板变量声明
private JLabel countInfoLabel; private JLabel countInfoLabel; // 记录数标签变量声明
private StorageTableModel storageTableModel ; private StorageTableModel storageTableModel ; // 存储表格模型变量声明
private JFrame jFrame; private JFrame jFrame; // 窗口变量声明
private productionService productionService=new productionImpl(); private productionService productionService=new productionImpl(); // 创建productionService实例
public StorageView(JFrame jFrame) { public StorageView(JFrame jFrame) { // StorageView构造方法
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()); // 创建工具栏面板并设置布局为BorderLayout
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 创建搜索面板并设置布局为左对齐的FlowLayout
locationLabel=new JLabel("当前位置>商品库存"); // 创建当前位置标签并设置文本
locationLabel.setFont(new FontUtil().userFont); // 设置标签字体
locationLabel.setForeground(new Color(18, 150, 219)); // 设置标签前景色
nameLabel = new JLabel("商品名"); // 创建商品名标签
nameSearchTF = new JTextField(10); // 创建文本框用于输入商品名大小为10
toolBarPanel = new JPanel(new BorderLayout());
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
locationLabel=new JLabel("当前位置>商品库存");
locationLabel.setFont(new FontUtil().userFont);
locationLabel.setForeground(new Color(18, 150, 219));
nameLabel = new JLabel("商品名");
nameSearchTF = new JTextField(10);
searchBtn = new JButton(new ImageIcon("static\\icon\\search.png"));
opePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); searchBtn = new JButton(new ImageIcon("static\\icon\\search.png")); // 创建搜索按钮并设置图标
addBtn =new JButton(new ImageIcon("static\\icon\\add.png"));
updateBtn =new JButton(new ImageIcon("static\\icon\\update.png"));
deleteBtn =new JButton(new ImageIcon("static\\icon\\delete.png"));
backBtn =new JButton(new ImageIcon("static\\icon\\back.png"));
historyBtn =new JButton(new ImageIcon("static\\icon\\history.png"));
backBtn.setVisible(false);
addBtn.addActionListener(this); opePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // 创建操作面板并设置布局为右对齐的FlowLayout
updateBtn.addActionListener(this); addBtn =new JButton(new ImageIcon("static\\icon\\add.png")); // 创建添加按钮并设置图标
deleteBtn.addActionListener(this); updateBtn =new JButton(new ImageIcon("static\\icon\\update.png")); // 创建更新按钮并设置图标
searchBtn.addActionListener(this); deleteBtn =new JButton(new ImageIcon("static\\icon\\delete.png")); // 创建删除按钮并设置图标
backBtn.addActionListener(this); backBtn =new JButton(new ImageIcon("static\\icon\\back.png")); // 创建返回按钮并设置图标
historyBtn.addActionListener(this); historyBtn =new JButton(new ImageIcon("static\\icon\\history.png")); // 创建历史按钮并设置图标
backBtn.setVisible(false); // 设置返回按钮不可见
opePanel.add(addBtn); addBtn.addActionListener(this); // 为添加按钮添加事件监听器
opePanel.add(updateBtn); updateBtn.addActionListener(this); // 为更新按钮添加事件监听器
opePanel.add(deleteBtn); deleteBtn.addActionListener(this); // 为删除按钮添加事件监听器
opePanel.add(backBtn); searchBtn.addActionListener(this); // 为搜索按钮添加事件监听器
opePanel.add(historyBtn); backBtn.addActionListener(this); // 为返回按钮添加事件监听器
historyBtn.addActionListener(this); // 为历史按钮添加事件监听器
searchPanel.add(locationLabel); opePanel.add(addBtn); // 将添加按钮添加到操作面板
searchPanel.add(nameLabel); opePanel.add(updateBtn); // 将更新按钮添加到操作面板
searchPanel.add(nameSearchTF); opePanel.add(deleteBtn); // 将删除按钮添加到操作面板
searchPanel.add(searchBtn); opePanel.add(backBtn); // 将返回按钮添加到操作面板
opePanel.add(historyBtn); // 将历史按钮添加到操作面板
searchPanel.add(locationLabel); // 将位置标签添加到搜索面板
searchPanel.add(nameLabel); // 将商品名标签添加到搜索面板
searchPanel.add(nameSearchTF); // 将商品名文本框添加到搜索面板
searchPanel.add(searchBtn); // 将搜索按钮添加到搜索面板
toolBarPanel.add(searchPanel,"West");
toolBarPanel.add(opePanel,"East"); toolBarPanel.add(searchPanel,"West"); // 将搜索面板添加到工具栏面板的西边
toolBarPanel.add(opePanel,"East"); // 将操作面板添加到工具栏面板的东边
//中间表格 //中间表格
storageTableModel = new StorageTableModel(); storageTableModel = new StorageTableModel(); // 创建存储表格模型
storageTableModel.all(); storageTableModel.all(); // 初始化表格模型数据
storageTable = new JTable(storageTableModel); storageTable = new JTable(storageTableModel); // 创建表格并设置模型
storageTable.setFont(FontUtil.tableFont); storageTable.setFont(FontUtil.tableFont); // 设置表格字体
storageTable.setRowHeight(50); storageTable.setRowHeight(50); // 设置表格行高
tableScrollPane = new JScrollPane(storageTable); tableScrollPane = new JScrollPane(storageTable); // 创建滚动面板并包含表格
//下面 //下面
bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 创建底部面板并设置布局为左对齐的FlowLayout
countInfoLabel = new JLabel("总共"+storageTableModel.getRowCount()+"条"); countInfoLabel = new JLabel("总共"+storageTableModel.getRowCount()+"条"); // 创建记录数标签并设置文本
bottomPanel.add(countInfoLabel); bottomPanel.add(countInfoLabel); // 将记录数标签添加到底部面板
this.add(toolBarPanel,"North"); this.add(toolBarPanel,"North"); // 将工具栏面板添加到当前面板的北边
this.add(tableScrollPane,"Center"); /*将表格放到中间*/ this.add(tableScrollPane,"Center"); /*将表格放到中间*/
this.add(bottomPanel,"South"); this.add(bottomPanel,"South"); // 将底部面板添加到当前面板的南边
setVisible(true); setVisible(true); // 设置当前面板可见
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) { // 重写actionPerformed方法以处理按钮点击事件
Object source = e.getSource(); Object source = e.getSource(); // 获取事件源
if(addBtn==source) { if(addBtn==source) { // 如果事件源是添加按钮
//添加数据的对话框 //添加数据的对话框
ProductionDialog productionDialog = new ProductionDialog(jFrame); ProductionDialog productionDialog = new ProductionDialog(jFrame); // 创建添加数据的对话框
productionDialog.setVisible(true); productionDialog.setVisible(true); // 显示对话框
refreshProduction(); refreshProduction(); // 刷新数据
}else if(updateBtn==source) { }else if(updateBtn==source) { // 如果事件源是更新按钮
refreshProduction(); refreshProduction(); // 刷新数据
}else if(historyBtn==source) { }else if(historyBtn==source) { // 如果事件源是历史按钮
storageRecord(); storageRecord(); // 处理存储记录
}else if(backBtn==source) { }else if(backBtn==source) { // 如果事件源是返回按钮
refreshProduction(); refreshProduction(); // 刷新数据
} }
else if(deleteBtn==source) { else if(deleteBtn==source) { // 如果事件源是删除按钮
//获取选中记录,删除 //获取选中记录,删除
int[] rowIndexs = storageTable.getSelectedRows(); int[] rowIndexs = storageTable.getSelectedRows(); // 获取表格中选中的行索引
if(rowIndexs.length==0) { if(rowIndexs.length==0) { // 如果没有选中任何行
JOptionPane.showMessageDialog(this,"请至少选中一条"); JOptionPane.showMessageDialog(this,"请至少选中一条"); // 显示提示信息
return; return; // 结束方法执行
} }
int select=JOptionPane.showConfirmDialog(this,"是否删除选中的"+rowIndexs.length+"条记录","提示",JOptionPane.YES_NO_OPTION); int select=JOptionPane.showConfirmDialog(this,"是否删除选中的"+rowIndexs.length+"条记录","提示",JOptionPane.YES_NO_OPTION); // 显示确认对话框
if(select==JOptionPane.YES_OPTION){ if(select==JOptionPane.YES_OPTION){ // 如果用户选择是
for(int i=0;i<rowIndexs.length;i++){ // 遍历所有选中的行
for(int i=0;i<rowIndexs.length;i++){ String id = (String)storageTable.getValueAt(rowIndexs[i],0); // 获取选中行的ID
String id = (String)storageTable.getValueAt(rowIndexs[i],0); if(productionService.deleteProduction(id)==1) { // 尝试删除记录
if(productionService.deleteProduction(id)==1) {
}else { }else {
JOptionPane.showMessageDialog(this,"删除失败,id="+id,"提示",JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(this,"删除失败,id="+id,"提示",JOptionPane.ERROR_MESSAGE); // 显示删除失败信息
} }
} }
JOptionPane.showMessageDialog(this,"删除操作结束","提示",JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(this,"删除操作结束","提示",JOptionPane.INFORMATION_MESSAGE); // 显示删除操作结束信息
} }
refreshProduction(); refreshProduction(); // 刷新数据
}else if(source==searchBtn){ }else if(source==searchBtn){ // 如果事件源是搜索按钮
refreshFindRname(); refreshFindRname(); // 刷新搜索结果
} }
} }
public void refreshFindRname() { public void refreshFindRname() { // 刷新搜索结果的方法
String name = nameSearchTF.getText(); String name = nameSearchTF.getText(); // 获取搜索框中的文本
Production p=new Production(); Production p=new Production(); // 创建Production对象
p.setName(name); p.setName(name); // 设置Production对象的名称
storageTableModel = new StorageTableModel(); storageTableModel = new StorageTableModel(); // 创建新的存储表格模型
storageTableModel.Byname(p); storageTableModel.Byname(p); // 根据名称过滤数据
storageTable.setModel(storageTableModel); storageTable.setModel(storageTableModel); // 更新表格模型
//同时更新下面的记录数 //同时更新下面的记录数
refreshCount(); refreshCount(); // 刷新记录数
hiddinBtn(); hiddinBtn(); // 隐藏按钮
} }
public void refreshProduction() { public void refreshProduction() { // 刷新生产数据的方法
storageTableModel = new StorageTableModel(); storageTableModel = new StorageTableModel(); // 创建新的存储表格模型
storageTableModel.all(); storageTableModel.all(); // 加载所有数据
storageTable.setModel(storageTableModel); storageTable.setModel(storageTableModel); // 更新表格模型
//同时更新下面的记录数 //同时更新下面的记录数
refreshCount(); refreshCount(); // 刷新记录数
hiddinBtn(); hiddinBtn(); // 隐藏按钮
} }
public void refreshCount(){ public void refreshCount(){ // 刷新记录数的方法
bottomPanel.removeAll(); bottomPanel.removeAll(); // 清除底部面板上的所有组件
countInfoLabel = new JLabel("总共"+storageTableModel.getRowCount()+"条"); countInfoLabel = new JLabel("总共"+storageTableModel.getRowCount()+"条"); // 创建新的记录数标签
bottomPanel.add(countInfoLabel); bottomPanel.add(countInfoLabel); // 将记录数标签添加到底部面板
hiddinBtn(); hiddinBtn(); // 隐藏按钮
} }
public void storageRecord() { public void storageRecord() {
StorageRecordTM storageRecordTM= new StorageRecordTM(); StorageRecordTM storageRecordTM= new StorageRecordTM(); // 创建存储记录表格模型
storageRecordTM.allStoragrRecord(); storageRecordTM.allStoragrRecord(); // 加载所有存储记录
storageTable.setModel(storageRecordTM); storageTable.setModel(storageRecordTM); // 设置表格模型为存储记录
//同时更新下面的记录数 //同时更新下面的记录数
bottomPanel.removeAll(); bottomPanel.removeAll(); // 清除底部面板上的所有组件
countInfoLabel = new JLabel("总共"+storageRecordTM.getRowCount()+"条"); countInfoLabel = new JLabel("总共"+storageRecordTM.getRowCount()+"条"); // 创建新的记录数标签
bottomPanel.add(countInfoLabel); bottomPanel.add(countInfoLabel); // 将记录数标签添加到底部面板
backBtn.setVisible(true); backBtn.setVisible(true); // 设置返回按钮可见
updateBtn.setVisible(false); updateBtn.setVisible(false); // 设置更新按钮不可见
addBtn.setVisible(false); addBtn.setVisible(false); // 设置添加按钮不可见
historyBtn.setVisible(false); historyBtn.setVisible(false); // 设置历史按钮不可见
deleteBtn.setVisible(false); deleteBtn.setVisible(false); // 设置删除按钮不可见
} }
public void hiddinBtn() { public void hiddinBtn() {
backBtn.setVisible(false); backBtn.setVisible(false); // 设置返回按钮不可见
updateBtn.setVisible(true); updateBtn.setVisible(true); // 设置更新按钮可见
addBtn.setVisible(true); addBtn.setVisible(true); // 设置添加按钮可见
historyBtn.setVisible(true); historyBtn.setVisible(true); // 设置历史按钮可见
deleteBtn.setVisible(true); deleteBtn.setVisible(true); // 设置删除按钮可见
} }

@ -1,177 +1,183 @@
package com.lingnan.supermarket.view; package com.lingnan.supermarket.view; // 定义包名
import java.awt.BorderLayout; import java.awt.BorderLayout; // 导入BorderLayout布局管理器
import java.awt.Color; import java.awt.Color; // 导入Color类用于颜色管理
import java.awt.FlowLayout; import java.awt.FlowLayout; // 导入FlowLayout布局管理器
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent; // 导入ActionEvent类用于监听按钮点击事件
import java.awt.event.ActionListener; import java.awt.event.ActionListener; // 导入ActionListener接口用于实现事件监听
import javax.swing.ImageIcon; import javax.swing.ImageIcon; // 导入ImageIcon类用于显示图片
import javax.swing.JButton; import javax.swing.JButton; // 导入JButton类用于创建按钮
import javax.swing.JFrame; import javax.swing.JFrame; // 导入JFrame类用于创建窗口
import javax.swing.JLabel; import javax.swing.JLabel; // 导入JLabel类用于创建标签
import javax.swing.JOptionPane; import javax.swing.JOptionPane; // 导入JOptionPane类用于显示对话框
import javax.swing.JPanel; import javax.swing.JPanel; // 导入JPanel类用于创建面板
import javax.swing.JScrollPane; import javax.swing.JScrollPane; // 导入JScrollPane类用于创建滚动面板
import javax.swing.JTable; import javax.swing.JTable; // 导入JTable类用于创建表格
import javax.swing.JTextField; import javax.swing.JTextField; // 导入JTextField类用于创建文本框
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.dialog.SupplierInfDialog; import com.lingnan.supermarket.dialog.SupplierInfDialog; // 导入供应商信息对话框类
import com.lingnan.supermarket.dto.SupplierInf; import com.lingnan.supermarket.dto.SupplierInf; // 导入供应商信息数据传输对象
import com.lingnan.supermarket.table.SupplierTableModel; import com.lingnan.supermarket.table.SupplierTableModel; // 导入供应商表格模型类
import com.lingnan.supermarket.utils.FontUtil; import com.lingnan.supermarket.utils.FontUtil; // 导入字体工具类
public class SupplierView extends JPanel implements ActionListener{ public class SupplierView extends JPanel implements ActionListener{ // 创建一个公共类SupplierView继承JPanel并实现ActionListener接口
//上面 //上面
private JPanel toolBarPanel; private JPanel toolBarPanel; // 声明工具栏面板变量
private JPanel searchPanel; private JPanel searchPanel; // 声明搜索面板变量
private JLabel nameLabel,locationLabel; private JLabel nameLabel,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 JScrollPane tableScrollPane; private JScrollPane tableScrollPane; // 声明表格滚动面板变量
private JTable supplierTable; private JTable supplierTable; // 声明表格变量
//下面 //下面
private JPanel bottomPanel; private JPanel bottomPanel; // 声明底部面板变量
private JLabel countInfoLabel; private JLabel countInfoLabel; // 声明信息标签变量
private SupplierTableModel supplierTableModel; private SupplierTableModel supplierTableModel; // 声明供应商表格模型变量
private JFrame jFrame; private JFrame jFrame; // 声明窗口变量
private SupplierInfService supplierInfService = new SupplierInfImpl(); private SupplierInfService supplierInfService = new SupplierInfImpl(); // 创建供应商信息服务实例
public SupplierView(JFrame jFrame) { public SupplierView(JFrame jFrame) { // SupplierView构造方法接收一个JFrame参数
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout()); // 设置面板布局为BorderLayout
initView(); initView(); // 调用初始化视图方法
this.jFrame = jFrame; this.jFrame = jFrame; // 将传入的JFrame赋值给成员变量
} }
private void initView() { private void initView() { // 初始化视图方法
toolBarPanel = new JPanel(new BorderLayout()); // 创建工具栏面板并设置布局为BorderLayout
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 创建搜索面板并设置布局为左对齐的FlowLayout
locationLabel=new JLabel("当前位置>供应商"); // 创建当前位置标签
locationLabel.setFont(new FontUtil().userFont); // 设置标签字体
locationLabel.setForeground(new Color(18, 150, 219)); // 设置标签前景色
nameLabel = new JLabel("公司名称"); // 创建公司名称标签
nameSearchTF = new JTextField(10); // 创建文本框用于输入公司名称大小为10
toolBarPanel = new JPanel(new BorderLayout());
searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
locationLabel=new JLabel("当前位置>供应商");
locationLabel.setFont(new FontUtil().userFont);
locationLabel.setForeground(new Color(18, 150, 219));
nameLabel = new JLabel("公司名称");
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)); opePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // 创建操作面板并设置布局为右对齐的FlowLayout
addBtn =new JButton(new ImageIcon("static\\icon\\add.png")); addBtn =new JButton(new ImageIcon("static\\icon\\add.png")); // 创建添加按钮并设置图标
updateBtn =new JButton(new ImageIcon("static\\icon\\update.png")); updateBtn =new JButton(new ImageIcon("static\\icon\\update.png")); // 创建更新按钮并设置图标
deleteBtn =new JButton(new ImageIcon("static\\icon\\delete.png")); deleteBtn =new JButton(new ImageIcon("static\\icon\\delete.png")); // 创建删除按钮并设置图标
addBtn.addActionListener(this); addBtn.addActionListener(this); // 为添加按钮添加事件监听器
updateBtn.addActionListener(this); updateBtn.addActionListener(this); // 为更新按钮添加事件监听器
deleteBtn.addActionListener(this); deleteBtn.addActionListener(this); // 为删除按钮添加事件监听器
searchBtn.addActionListener(this); searchBtn.addActionListener(this); // 为搜索按钮添加事件监听器
opePanel.add(addBtn); opePanel.add(addBtn); // 将添加按钮添加到操作面板
opePanel.add(updateBtn); opePanel.add(updateBtn); // 将更新按钮添加到操作面板
opePanel.add(deleteBtn); opePanel.add(deleteBtn); // 将删除按钮添加到操作面板
searchPanel.add(locationLabel); searchPanel.add(locationLabel); // 将当前位置标签添加到搜索面板
searchPanel.add(nameLabel); searchPanel.add(nameLabel); // 将公司名称标签添加到搜索面板
searchPanel.add(nameSearchTF); searchPanel.add(nameSearchTF); // 将公司名称文本框添加到搜索面板
searchPanel.add(searchBtn); searchPanel.add(searchBtn); // 将搜索按钮添加到搜索面板
toolBarPanel.add(searchPanel,"West"); toolBarPanel.add(searchPanel,"West"); // 将搜索面板添加到工具栏面板的西边
toolBarPanel.add(opePanel,"East"); toolBarPanel.add(opePanel,"East"); // 将操作面板添加到工具栏面板的东边
//中间表格 //中间表格
SupplierTableModel supplierTableModel = new SupplierTableModel(); supplierTableModel = new SupplierTableModel(); // 创建供应商表格模型实例
supplierTableModel.all(); supplierTableModel.all(); // 调用表格模型的方法以加载所有数据
supplierTable = new JTable(supplierTableModel); supplierTable = new JTable(supplierTableModel); // 创建表格并使用供应商表格模型
supplierTable.setFont(FontUtil.tableFont); supplierTable.setFont(FontUtil.tableFont); // 设置表格字体
supplierTable.setRowHeight(50); supplierTable.setRowHeight(50); // 设置表格行高为50像素
tableScrollPane = new JScrollPane(supplierTable);/*滑动条*/ tableScrollPane = new JScrollPane(supplierTable); // 创建滚动面板并添加表格/*滑动条*/
//下面 //下面
bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 创建底部面板并设置布局为左对齐的FlowLayout
countInfoLabel = new JLabel("总共"+supplierTableModel.getRowCount()+"条"); countInfoLabel = new JLabel("总共"+supplierTableModel.getRowCount()+"条"); // 创建信息标签并设置显示总条数
bottomPanel.add(countInfoLabel); bottomPanel.add(countInfoLabel); // 将信息标签添加到底部面板
this.add(toolBarPanel,"North"); this.add(toolBarPanel,"North"); // 将工具栏面板添加到当前面板的北边
this.add(tableScrollPane,"Center");/*将表格放到中间*/ this.add(tableScrollPane,"Center"); // 将表格滚动面板添加到当前面板的中间/*将表格放到中间*/
this.add(bottomPanel,"South"); this.add(bottomPanel,"South"); // 将底部面板添加到当前面板的南边
setVisible(true); setVisible(true); // 设置当前面板可见
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) { // 重写actionPerformed方法以处理按钮点击事件
Object source = e.getSource(); Object source = e.getSource(); // 获取事件源
if(addBtn==source) { if(addBtn==source) { // 如果事件源是添加按钮
SupplierInfDialog supplierInfDialog = new SupplierInfDialog(jFrame, null); SupplierInfDialog supplierInfDialog = new SupplierInfDialog(jFrame, null); // 创建供应商信息对话框
supplierInfDialog.setVisible(true); supplierInfDialog.setVisible(true); // 显示供应商信息对话框
refreshSupplier(); refreshSupplier(); // 刷新供应商列表
}else if(updateBtn==source) { }else if(updateBtn==source) { // 如果事件源是更新按钮
refreshSupplier(); refreshSupplier(); // 刷新供应商列表
}else if(deleteBtn==source) { }else if(deleteBtn==source) { // 如果事件源是删除按钮
//获取选中记录 //获取选中记录
int rowIndex = supplierTable.getSelectedRow(); int rowIndex = supplierTable.getSelectedRow(); // 获取表格中选中的行索引
if(rowIndex==-1) { if(rowIndex==-1) { // 如果没有选中任何行
JOptionPane.showMessageDialog(this,"请选中一条"); JOptionPane.showMessageDialog(this,"请选中一条"); // 显示提示信息
return; return; // 结束方法执行
} }
int id = (Integer)supplierTable.getValueAt(rowIndex,0); int id = (Integer)supplierTable.getValueAt(rowIndex,0); // 获取选中行的ID
int select=JOptionPane.showConfirmDialog(this,"是否删除id="+id,"提示",JOptionPane.YES_NO_OPTION); int select=JOptionPane.showConfirmDialog(this,"是否删除id="+id,"提示",JOptionPane.YES_NO_OPTION); // 显示确认删除对话框
if(select==JOptionPane.YES_OPTION){ if(select==JOptionPane.YES_OPTION){ // 如果用户选择是
if(supplierInfService.deleteSupplierInf(id)==1) { if(supplierInfService.deleteSupplierInf(id)==1) { // 尝试删除供应商信息
JOptionPane.showMessageDialog(this,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(this,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE); // 显示删除成功信息
refreshSupplier(); refreshSupplier(); // 刷新供应商列表
}else { }else {
JOptionPane.showMessageDialog(this,"删除失败","提示",JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(this,"删除失败","提示",JOptionPane.ERROR_MESSAGE); // 显示删除失败信息
} }
} }
}else{ }else{ // 如果事件源不是以上按钮
System.out.println("搜索"); System.out.println("搜索"); // 输出搜索信息
refreshFindRname(); refreshFindRname(); // 刷新搜索结果
} }
} }
public void refreshFindRname() { public void refreshFindRname() { // 刷新搜索结果的方法
String name = nameSearchTF.getText(); String name = nameSearchTF.getText(); // 获取文本框中的搜索名称
SupplierInf supplierInf =new SupplierInf(); SupplierInf supplierInf =new SupplierInf(); // 创建供应商信息对象
supplierInf.setName(name); supplierInf.setName(name); // 设置供应商名称
supplierTableModel = new SupplierTableModel(); // 创建供应商表格模型
supplierTableModel = new SupplierTableModel(); supplierTableModel.Byname(supplierInf); // 根据名称过滤供应商信息
supplierTableModel.Byname(supplierInf); supplierTable.setModel(supplierTableModel); // 更新表格模型
refreshCount(); // 刷新记录数显示
supplierTable.setModel(supplierTableModel);
refreshCount();
} }
public void refreshSupplier() { public void refreshSupplier() { // 刷新供应商列表的方法
supplierTableModel = new SupplierTableModel(); supplierTableModel = new SupplierTableModel(); // 创建供应商表格模型
supplierTableModel.all(); supplierTableModel.all(); // 加载所有供应商信息
supplierTable.setModel(supplierTableModel); supplierTable.setModel(supplierTableModel); // 更新表格模型
refreshCount(); // 刷新记录数显示
refreshCount();
} }
public void refreshCount(){ public void refreshCount(){ // 刷新记录数显示的方法
bottomPanel.removeAll(); bottomPanel.removeAll(); // 清除底部面板上的所有组件
countInfoLabel = new JLabel("总共"+supplierTableModel.getRowCount()+"条"); countInfoLabel = new JLabel("总共"+supplierTableModel.getRowCount()+"条"); // 创建新的记录数标签
bottomPanel.add(countInfoLabel); bottomPanel.add(countInfoLabel); // 将记录数标签添加到底部面板
} }
} }

Loading…
Cancel
Save