第一次添加

pull/13/head
Redmi 9 months ago
parent f0f38a4a13
commit 7fe44258db

@ -16,323 +16,297 @@ import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.text.html.HTMLDocument.Iterator;
import com.lingnan.supermarket.dao.impl.BufferImpl; import com.lingnan.supermarket.dao.impl.BufferImpl;
import com.lingnan.supermarket.dialog.ChangeSumDialog; import com.lingnan.supermarket.dialog.ChangeSumDialog;
import com.lingnan.supermarket.dialog.OutDialog; import com.lingnan.supermarket.dialog.OutDialog;
import com.lingnan.supermarket.dialog.UserDialog;
import com.lingnan.supermarket.dto.Buffer; import com.lingnan.supermarket.dto.Buffer;
import com.lingnan.supermarket.dto.User; import com.lingnan.supermarket.dto.User;
import com.lingnan.supermarket.table.*; import com.lingnan.supermarket.table.*;
import com.lingnan.supermarket.utils.FontUtil; import com.lingnan.supermarket.utils.FontUtil;
import com.lingnan.supermarket.utils.TimeAndOrder; import com.lingnan.supermarket.utils.TimeAndOrder;
public class OutView extends JPanel implements ActionListener{ public class OutView 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,AccountBtn,exitBtn; private JButton searchBtn, AccountBtn, 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 outTable; private JTable outTable;
//下面 //下面
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;
private Vector<Buffer> v; private Vector<Buffer> v;
private JFrame jFrame; private JFrame jFrame;
private User user; private User user;
private OutTableModel outTableModel = new OutTableModel(); private OutTableModel outTableModel = new OutTableModel();
private int mark;/*标记订单表和订单详情表*/ private int mark;/*标记订单表和订单详情表*/
public OutView(JFrame jFrame,User user) { public OutView(JFrame jFrame, User user) {
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout()); // 设置主布局为BorderLayout
initView(); initView(); // 初始化界面组件
this.jFrame = jFrame; this.jFrame = jFrame; // 将传入的JFrame赋值给成员变量
this.user = user; this.user = user; // 将传入的User赋值给成员变量
} }
private void initView() { private void initView() {
toolBarPanel = new JPanel(new BorderLayout()); toolBarPanel = new JPanel(new BorderLayout()); // 创建顶部工具栏面板设置为BorderLayout布局
searchPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); searchPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); // 创建搜索面板设置为居中对齐的FlowLayout布局
nameLabel = new JLabel("订单号"); nameLabel = new JLabel("订单号"); // 创建“订单号”标签
nameSearchTF = new JTextField(20); nameSearchTF = new JTextField(20); // 创建订单号输入框长度为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)); // 设置标签字体颜色
opePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); opePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 创建操作按钮面板设置为左对齐的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\\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")); // 创建查看详情按钮并设置图标
backBtn.setVisible(false);/*在记录页面显示出来*/ backBtn.setVisible(false); // 初始时隐藏返回按钮,记录页面显示
detailBtn.setVisible(false);/*在订单详情页显示出来*/ detailBtn.setVisible(false); // 初始时隐藏查看详情按钮,订单详情页显示
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);
// 将各按钮添加到操作面板
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);
// 将搜索面板和操作面板分别添加到工具栏的两侧
toolBarPanel.add(searchPanel,"West"); toolBarPanel.add(searchPanel, "West");
toolBarPanel.add(opePanel,"East"); toolBarPanel.add(opePanel, "East");
// 中间表格区域
//中间表格 outTableModel = new OutTableModel(); // 创建订单表格数据模型
outTableModel = new OutTableModel(); outTableModel.allOutBuffer(); // 查询所有购物车数据
outTableModel.allOutBuffer();/*查找所有购物车*/ outTable = new JTable(outTableModel); // 创建表格并设置数据模型
outTable = new JTable(outTableModel); outTable.setFont(FontUtil.tableFont); // 设置表格字体样式
outTable.setFont(FontUtil.tableFont); outTable.setRowHeight(50); // 设置表格行高
outTable.setRowHeight(50); tableScrollPane = new JScrollPane(outTable); // 创建带滚动条的表格
tableScrollPane = new JScrollPane(outTable);
// 底部左侧面板,用于显示统计信息
//下面 bottomPanelLeft = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 设置为左对齐的FlowLayout布局
bottomPanelLeft = new JPanel(new FlowLayout(FlowLayout.LEFT)); countInfoLabel = new JLabel("商品种类:" + outTableModel.getRowCount() + ",总价:" + outTableModel.getAllPrice()); // 显示商品种类和总价
countInfoLabel = new JLabel("商品种类:"+outTableModel.getRowCount()+",总价:"+outTableModel.getAllPrice()); bottomPanelLeft.add(countInfoLabel); // 将统计信息标签添加到左侧面板
bottomPanelLeft.add(countInfoLabel);
// 底部右侧面板,用于显示操作按钮
bottomPanelRight = new JPanel(new FlowLayout(FlowLayout.RIGHT)); bottomPanelRight = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // 设置为右对齐的FlowLayout布局
AccountBtn =new JButton(new ImageIcon("static\\icon\\Account.png"));/*结账按钮*/ AccountBtn = new JButton(new ImageIcon("static\\icon\\Account.png")); // 创建结账按钮并设置图标
exitBtn =new JButton(new ImageIcon("static\\icon\\exit.png"));/*退出按钮*/ exitBtn = new JButton(new ImageIcon("static\\icon\\exit.png")); // 创建退出按钮并设置图标
AccountBtn.addActionListener(this); AccountBtn.addActionListener(this); // 为结账按钮添加点击事件监听
exitBtn.addActionListener(this); exitBtn.addActionListener(this); // 为退出按钮添加点击事件监听
bottomPanelRight.add(AccountBtn); bottomPanelRight.add(AccountBtn); // 将结账按钮添加到底部右侧面板
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"); // 将底部面板放在底部
this.add(bottomPanel,"South");
setVisible(true); // 设置主面板为可见状态
setVisible(true);
} }
// 按钮组件隐藏和显示设置
//按钮组件隐藏
public void OrderView() { public void OrderView() {
backBtn.setVisible(true); backBtn.setVisible(true); // 显示返回按钮
detailBtn.setVisible(true); detailBtn.setVisible(true); // 显示查看详情按钮
updateBtn.setVisible(false); updateBtn.setVisible(false); // 隐藏更新按钮
deleteBtn.setVisible(true); deleteBtn.setVisible(true); // 显示删除按钮
addBtn.setVisible(false); addBtn.setVisible(false); // 隐藏添加按钮
historyBtn.setVisible(false); historyBtn.setVisible(false); // 隐藏历史记录按钮
} }
//通过订单查找 //通过订单查找
public void resultOfNumber(String oNumber) { public void resultOfNumber(String oNumber) {
this.mark=1; this.mark = 1; // 设置标记为1表示当前显示的是订单数据
OutOrderTM outOrderTM = new OutOrderTM(); OutOrderTM outOrderTM = new OutOrderTM(); // 创建一个OutOrderTM对象用于存储订单数据
outOrderTM.resultOfNumber(oNumber); outOrderTM.resultOfNumber(oNumber); // 根据订单号查询相关的订单数据
outTable.setModel(outOrderTM); outTable.setModel(outOrderTM); // 设置表格数据模型为查询到的订单数据
bottomPanelLeft.removeAll(); bottomPanelLeft.removeAll(); // 清除底部左侧面板的所有组件
countInfoLabel = new JLabel("共"+outOrderTM.getRowCount()+"条记录"); countInfoLabel = new JLabel("共" + outOrderTM.getRowCount() + "条记录"); // 显示当前记录的数量
bottomPanelLeft.add(countInfoLabel); bottomPanelLeft.add(countInfoLabel); // 将记录数量标签添加到左侧面板
OrderView(); OrderView(); // 调用OrderView方法更新按钮的显示状态
} }
/*刷新*/ /*刷新*/
public void refreshOutBuffer() { public void refreshOutBuffer() {
OutTableModel outTableModel = new OutTableModel(); OutTableModel outTableModel = new OutTableModel(); // 创建一个新的OutTableModel对象
outTableModel.allOutBuffer(); outTableModel.allOutBuffer(); // 查询所有购物车数据
outTable.setModel(outTableModel); outTable.setModel(outTableModel); // 设置表格数据模型为查询到的所有购物车数据
bottomPanelLeft.removeAll(); bottomPanelLeft.removeAll(); // 清除底部左侧面板的所有组件
countInfoLabel = new JLabel("商品种类:"+outTableModel.getRowCount()+",总价:"+outTableModel.getAllPrice()); countInfoLabel = new JLabel("商品种类:" + outTableModel.getRowCount() + ",总价:" + outTableModel.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); // 显示删除按钮
} }
/*调出收银出货订单表*/ /*调出收银出货订单表*/
public void OutOrderRecord() { public void OutOrderRecord() {
this.mark=1; this.mark = 1; // 设置标记为1表示当前显示的是订单记录数据
OutOrderTM outOrderTM = new OutOrderTM(); OutOrderTM outOrderTM = new OutOrderTM(); // 创建一个OutOrderTM对象用于存储订单记录数据
outOrderTM.allOutOrderRecord(); outOrderTM.allOutOrderRecord(); // 查询所有的出货订单记录
outTable.setModel(outOrderTM); outTable.setModel(outOrderTM); // 设置表格数据模型为查询到的订单记录
bottomPanelLeft.removeAll(); bottomPanelLeft.removeAll(); // 清除底部左侧面板的所有组件
countInfoLabel = new JLabel("共"+outOrderTM.getRowCount()+"条记录"); countInfoLabel = new JLabel("共" + outOrderTM.getRowCount() + "条记录"); // 显示订单记录的数量
bottomPanelLeft.add(countInfoLabel); bottomPanelLeft.add(countInfoLabel); // 将订单记录数量标签添加到左侧面板
OrderView(); OrderView(); // 调用OrderView方法更新按钮的显示状态
} }
public void OutRecord(String oNumber) { public void OutRecord(String oNumber) {
this.mark=0; this.mark = 0; // 设置标记为0表示当前显示的是订单详情数据
OutRecordTM outRecordTM = new OutRecordTM(oNumber); OutRecordTM outRecordTM = new OutRecordTM(oNumber); // 创建一个OutRecordTM对象根据订单号查询订单详情数据
outRecordTM.findOutRecordByINumber(); outRecordTM.findOutRecordByINumber(); // 查询根据订单号找到的订单详情
outTable.setModel(outRecordTM); outTable.setModel(outRecordTM); // 设置表格数据模型为查询到的订单详情数据
bottomPanelLeft.removeAll(); bottomPanelLeft.removeAll(); // 清除底部左侧面板的所有组件
countInfoLabel = new JLabel("订单号@"+oNumber+"共有"+outRecordTM.getRowCount()+"条记录"); countInfoLabel = new JLabel("订单号@" + oNumber + "共有" + outRecordTM.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); // 隐藏更新按钮
addBtn.setVisible(false); addBtn.setVisible(false); // 隐藏添加按钮
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(); // 创建BufferImpl对象用于获取购物车数据
Object source = e.getSource(); Object source = e.getSource(); // 获取触发事件的按钮
if(searchBtn==source) { if (searchBtn == source) { // 如果点击的是搜索按钮
String number = nameSearchTF.getText(); String number = nameSearchTF.getText(); // 获取订单号
resultOfNumber(number); resultOfNumber(number); // 根据订单号查询订单数据
}
if(addBtn==source) {
OutDialog outDialog = new OutDialog(jFrame);
outDialog.setVisible(true);
refreshOutBuffer();
}
else if(updateBtn==source) {
int rowIndex = outTable.getSelectedRow();
if(rowIndex==-1) {
JOptionPane.showMessageDialog(this,"请选中一条进行更改数量");
return;
}
String id =(String) outTable.getValueAt(rowIndex,0);
ChangeSumDialog changesumDialog = new ChangeSumDialog(jFrame,id,"Out");
changesumDialog.setVisible(true);
refreshOutBuffer();
} }
else if(deleteBtn==source) { if (addBtn == source) { // 如果点击的是添加按钮
int rowIndex = outTable.getSelectedRow(); OutDialog outDialog = new OutDialog(jFrame); // 创建OutDialog对话框
if(rowIndex==-1) { outDialog.setVisible(true); // 显示添加对话框
JOptionPane.showMessageDialog(this,"请选中一条"); refreshOutBuffer(); // 刷新购物车数据
return; } else if (updateBtn == source) { // 如果点击的是更新按钮
} int rowIndex = outTable.getSelectedRow(); // 获取选中的表格行索引
String id =(String) outTable.getValueAt(rowIndex,0); if (rowIndex == -1) { // 如果没有选中行
int select = JOptionPane.showConfirmDialog(this,"是否删除id为"+id+"的记录","提示",JOptionPane.YES_NO_OPTION); JOptionPane.showMessageDialog(this, "请选中一条进行更改数量"); // 提示用户选择记录
if(select==JOptionPane.YES_OPTION) {/*选择是*/ return;
if(BufferImpl.DelOutBufferById(id)==true) {
JOptionPane.showMessageDialog(this,"删除成功","提示",JOptionPane.INFORMATION_MESSAGE);
}else {
JOptionPane.showMessageDialog(this,"删除失败","提示",JOptionPane.ERROR_MESSAGE);
}
refreshOutBuffer();
}
}else if(historyBtn==source) {/*查看历史全部记录*/
OutOrderRecord();
}else if(backBtn==source) {/*历史记录中的返回按钮*/
System.out.println("outView中的mark="+mark);
if(mark==1) {
refreshOutBuffer();
}else if(mark==0) {
OutOrderRecord();
} }
String id = (String) outTable.getValueAt(rowIndex, 0); // 获取选中行的订单ID
}else if(detailBtn==source) {/*查看订单详细*/ ChangeSumDialog changesumDialog = new ChangeSumDialog(jFrame, id, "Out"); // 创建修改数量的对话框
changesumDialog.setVisible(true); // 显示修改对话框
int rowIndex = outTable.getSelectedRow(); refreshOutBuffer(); // 刷新购物车数据
if(rowIndex==-1) { } else if (deleteBtn == source) { // 如果点击的是删除按钮
JOptionPane.showMessageDialog(this,"请选中一条查看订单详细信息"); int rowIndex = outTable.getSelectedRow(); // 获取选中的表格行索引
if (rowIndex == -1) { // 如果没有选中行
JOptionPane.showMessageDialog(this, "请选中一条"); // 提示用户选择记录
return; return;
} }
String id = (String) outTable.getValueAt(rowIndex, 0); // 获取选中行的订单ID
String oNumber =(String) outTable.getValueAt(rowIndex,0); int select = JOptionPane.showConfirmDialog(this, "是否删除id为" + id + "的记录", "提示", JOptionPane.YES_NO_OPTION); // 提示是否删除
System.out.println("详情订单号为="+oNumber); if (select == JOptionPane.YES_OPTION) { // 如果选择了删除
OutRecord(oNumber); if (BufferImpl.DelOutBufferById(id) == true) { // 调用BufferImpl删除购物车数据
} JOptionPane.showMessageDialog(this, "删除成功", "提示", JOptionPane.INFORMATION_MESSAGE); // 显示删除成功提示
} else {
JOptionPane.showMessageDialog(this, "删除失败", "提示", JOptionPane.ERROR_MESSAGE); // 显示删除失败提示
}
else if(AccountBtn==source) {/*结账*/ refreshOutBuffer(); // 刷新购物车数据
refreshOutBuffer(); }
v = BufferImpl.allOutBuffer(); } else if (historyBtn == source) { // 如果点击的是历史记录按钮
if(v.size()==0)/*购物车为空*/{ OutOrderRecord(); // 调用方法查询历史记录
JOptionPane.showMessageDialog(null,"您的购物车为空", "提示", JOptionPane.YES_OPTION); } else if (backBtn == source) { // 如果点击的是返回按钮
} System.out.println("outView中的mark=" + mark); // 打印当前mark的值
else {/*购物车不为空*/ if (mark == 1) { // 如果标记为1表示当前显示的是订单数据
int res = JOptionPane.showConfirmDialog(null,"总金额:"+outTableModel.getAllPrice()+"元\r\n是否已经结账", "结账", JOptionPane.YES_NO_OPTION); refreshOutBuffer(); // 刷新购物车数据
if(res==JOptionPane.YES_OPTION)/*如果已经结账*/{ } else if (mark == 0) { // 如果标记为0表示当前显示的是订单详情数据
OutOrderRecord(); // 查询历史订单记录
String[] s =TimeAndOrder.TimeAndOrder(user.getUsername());/*获得时间和订单号*/ }
} else if (detailBtn == source) { // 如果点击的是查看订单详情按钮
BufferImpl.InsertOutOrder(s[0],outTableModel.getAllPrice(), s[1], user.getUsername());/*往订单表插入一条记录*/ int rowIndex = outTable.getSelectedRow(); // 获取选中的表格行索引
for(int i=0;i<v.size();i++) { if (rowIndex == -1) { // 如果没有选中行
Buffer = v.elementAt(i); JOptionPane.showMessageDialog(this, "请选中一条查看订单详细信息"); // 提示用户选择记录
BufferImpl.Account(s[0],s[1],Buffer.getId(),Buffer.getSum(),Buffer.getPrice());/*调用结账存储过程*/ return;
} }
refreshOutBuffer();/*刷新所有购物车*/
HomeView.refreshHome();/*刷新首页*/ String oNumber = (String) outTable.getValueAt(rowIndex, 0); // 获取选中行的订单号
JOptionPane.showConfirmDialog(null,"支付成功\r\n订单号:"+s[0]+"\r\n负责人:"+user.getUsername(), "提示", JOptionPane.YES_OPTION); System.out.println("详情订单号为=" + oNumber); // 打印订单号
OutRecord(oNumber); // 显示该订单的详细信息
} } else if (AccountBtn == source) { // 如果点击的是结账按钮
refreshOutBuffer(); // 刷新购物车数据
v = BufferImpl.allOutBuffer(); // 获取购物车中的所有商品数据
if (v.size() == 0) { // 如果购物车为空
JOptionPane.showMessageDialog(null, "您的购物车为空", "提示", JOptionPane.YES_OPTION); // 提示购物车为空
} else { // 如果购物车不为空
int res = JOptionPane.showConfirmDialog(null, "总金额:" + outTableModel.getAllPrice() + "元\r\n是否已经结账", "结账", JOptionPane.YES_NO_OPTION); // 提示结账确认
if (res == JOptionPane.YES_OPTION) { // 如果选择结账
String[] s = TimeAndOrder.TimeAndOrder(user.getUsername()); // 获取当前时间和订单号
BufferImpl.InsertOutOrder(s[0], outTableModel.getAllPrice(), s[1], user.getUsername()); // 向订单表插入记录
for (int i = 0; i < v.size(); i++) { // 遍历购物车中的所有商品
Buffer = v.elementAt(i); // 获取每个商品
BufferImpl.Account(s[0], s[1], Buffer.getId(), Buffer.getSum(), Buffer.getPrice()); // 结账并调用存储过程
} }
refreshOutBuffer(); // 刷新购物车数据
}else if(exitBtn==source) { HomeView.refreshHome(); // 刷新首页
refreshOutBuffer(); JOptionPane.showConfirmDialog(null, "支付成功\r\n订单号:" + s[0] + "\r\n负责人:" + user.getUsername(), "提示", JOptionPane.YES_OPTION); // 显示支付成功提示
int res = JOptionPane.showConfirmDialog(null,"确定退出并清空购物车吗", "结账", JOptionPane.YES_NO_OPTION);
if(res==JOptionPane.YES_OPTION)/*如果已经结账*/{
BufferImpl.DelAllOutBuffer();
refreshOutBuffer();/*刷新所有购物车*/
JOptionPane.showConfirmDialog(null,"退出成功", "提示", JOptionPane.PLAIN_MESSAGE);
} }
} }
} else if (exitBtn == source) { // 如果点击的是退出按钮
refreshOutBuffer(); // 刷新购物车数据
int res = JOptionPane.showConfirmDialog(null, "确定退出并清空购物车吗", "结账", JOptionPane.YES_NO_OPTION); // 提示确认退出并清空购物车
if (res == JOptionPane.YES_OPTION) { // 如果选择退出
BufferImpl.DelAllOutBuffer(); // 清空购物车
refreshOutBuffer(); // 刷新购物车数据
JOptionPane.showConfirmDialog(null, "退出成功", "提示", JOptionPane.PLAIN_MESSAGE); // 显示退出成功提示
}
} }
} }
}

Loading…
Cancel
Save