|
|
package view;
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
|
import java.awt.Color;
|
|
|
import java.awt.FlowLayout;
|
|
|
import java.awt.Font;
|
|
|
import java.awt.GridLayout;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import javax.swing.ImageIcon;
|
|
|
import javax.swing.JButton;
|
|
|
import javax.swing.JComboBox;
|
|
|
import javax.swing.JLabel;
|
|
|
import javax.swing.JPanel;
|
|
|
import javax.swing.JScrollPane;
|
|
|
import javax.swing.JSeparator;
|
|
|
import javax.swing.JSplitPane;
|
|
|
import javax.swing.JTable;
|
|
|
import javax.swing.ListSelectionModel;
|
|
|
import javax.swing.SwingConstants;
|
|
|
import javax.swing.table.TableModel;
|
|
|
|
|
|
import dao.OrdersDAOtyj;
|
|
|
import dao.impl.OrdersDaoImpltyj;
|
|
|
import domain.Orderstyj;
|
|
|
|
|
|
public class OrderListFramembz extends MyFrame{
|
|
|
|
|
|
private JTable table;
|
|
|
|
|
|
|
|
|
//商品列表集合
|
|
|
private List<Orderstyj> orders;
|
|
|
///创建商品Dao对象
|
|
|
private final OrdersDAOtyj dao =new OrdersDaoImpltyj();
|
|
|
|
|
|
//,键是选择商品的Id,值是商品的数量
|
|
|
private Map<Long,Integer> cart = new HashMap<Long,Integer>();
|
|
|
|
|
|
//选择的商品索引
|
|
|
private int selectedRow = -1;
|
|
|
|
|
|
public OrderListFramembz(String title, int width, int height) {
|
|
|
super(title, width, height);
|
|
|
// TODO 自动生成的构造函数存根
|
|
|
this.tubiao();
|
|
|
|
|
|
//查询所有商品
|
|
|
orders = dao.findAll();
|
|
|
|
|
|
|
|
|
//初始化界面
|
|
|
|
|
|
//初始化分隔面板
|
|
|
JSplitPane splitPane = new JSplitPane();
|
|
|
//设置分隔线位置
|
|
|
splitPane.setDividerLocation(600);
|
|
|
//设置左侧面板
|
|
|
splitPane.setLeftComponent(getLeftPanel());
|
|
|
//设置右侧面板
|
|
|
splitPane.setRightComponent(getRightPanel());
|
|
|
//添加分隔面板
|
|
|
getContentPane().add(splitPane,BorderLayout.CENTER);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//右侧面板
|
|
|
private JPanel getRightPanel() {
|
|
|
|
|
|
JPanel rightPanel = new JPanel();
|
|
|
rightPanel.setBackground(Color.WHITE);
|
|
|
|
|
|
|
|
|
JButton btnAdd = new JButton("接单");
|
|
|
btnAdd.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
rightPanel.add(btnAdd);
|
|
|
|
|
|
//布局占位使用
|
|
|
JLabel lb1 = new JLabel("");
|
|
|
rightPanel.add(lb1);
|
|
|
|
|
|
JButton btnCheck = new JButton("查看接单列表");
|
|
|
btnCheck.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
rightPanel.add(btnCheck);
|
|
|
|
|
|
//注册【添加购物车】按钮的ActionEvent事件监听器
|
|
|
btnAdd.addActionListener(e -> {
|
|
|
|
|
|
if (selectedRow == -1) {
|
|
|
return;
|
|
|
}
|
|
|
//添加商品到购物车处理
|
|
|
Orderstyj selectorder = orders.get(selectedRow);
|
|
|
Long orderid = selectorder.getOrderid();
|
|
|
|
|
|
if (cart.containsKey(orderid)) {
|
|
|
//购物车中已有该商品
|
|
|
//获得商品数量
|
|
|
Integer quantity = cart.get(orderid);
|
|
|
cart.put(orderid, ++quantity);
|
|
|
|
|
|
} else {
|
|
|
cart.put(orderid, 1);
|
|
|
}
|
|
|
System.out.println(cart);
|
|
|
});
|
|
|
//注册【查看接单列表】按钮的ActionEvent事件监听器
|
|
|
btnCheck.addActionListener(e -> {
|
|
|
//System.out.println(cart);
|
|
|
JiedanFramembz jiedanFrame = new JiedanFramembz(cart, this);
|
|
|
jiedanFrame.setVisible(true);
|
|
|
setVisible(false);
|
|
|
});
|
|
|
|
|
|
return rightPanel;
|
|
|
}
|
|
|
|
|
|
//初始化左侧面板
|
|
|
private JScrollPane getLeftPanel(){
|
|
|
|
|
|
JScrollPane leftScrollPane = new JScrollPane();
|
|
|
|
|
|
leftScrollPane.setViewportView(getTable());
|
|
|
return leftScrollPane;
|
|
|
}
|
|
|
//初始化左侧面板中的表格控件
|
|
|
private JTable getTable() {
|
|
|
TableModel model = new OrderTableModelmbz(this.orders);
|
|
|
|
|
|
if (table == null) {
|
|
|
table = new JTable(model);
|
|
|
//设置表中内容字体
|
|
|
table.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
//设置表列标题字体
|
|
|
table.getTableHeader().setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
//设置表行高
|
|
|
table.setRowHeight(51);
|
|
|
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
|
ListSelectionModel rowSelectionModel = table.getSelectionModel();
|
|
|
|
|
|
rowSelectionModel.addListSelectionListener(e -> {
|
|
|
//只处理鼠标释放
|
|
|
if (e.getValueIsAdjusting()) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
|
|
|
selectedRow = lsm.getMinSelectionIndex();
|
|
|
if (selectedRow < 0) {
|
|
|
return;
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
table.setModel(model);
|
|
|
}
|
|
|
return table;
|
|
|
|
|
|
}
|
|
|
//软件图标
|
|
|
public void tubiao() {
|
|
|
MyFrame.setTitleImage(this,"e39b4ce2ebe83d39adabb339c23a1e0.png" );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|