⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 posmenuactionimp.java

📁 好的超市源码供大家下载
💻 JAVA
字号:
package action.implementclass.menuaction;

import java.awt.event.ActionEvent;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

import view.com.factory.DialogFactory;
import view.frame.PosFrame;
import view.frame.frameoper.PosFrameOper;
import vo.SaleProductVo;
import action.interfaces.menuaction.MenuAction;

/**
 * pos端中的菜单事件
 * 
 * @author wenjie,linfeng
 * 
 */
public class PosMenuActionImp implements MenuAction {
  /**
   * sale_id 序号 sum 总计金额 value SaleProductVo对象
   */
  private int sale_id = 0;
  private double sum = 0;
  public static SaleProductVo value;

  public void actionPerformed(ActionEvent e) {
    String name = e.getActionCommand();

    int row = PosFrame.table.getSelectedRow();

    if (name.equals("更换登录")) {

      PosFrame.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      // 释放当前POS界面
      int ch = JOptionPane.showConfirmDialog(null, "确定要换班吗?", "友情提示",
          JOptionPane.YES_NO_OPTION);
      if (ch == JOptionPane.YES_OPTION) {
        PosFrame.frame.dispose();
        // 产生新的登录界面
        name = "换班登录";
        DialogFactory.getInstance(name).getContainer();
      }
    }
    if (name.equals("小票打印")) {
      JOptionPane.showMessageDialog(null, "由于时间仓促,暂时未能实现打印!", "抱歉",
          JOptionPane.PLAIN_MESSAGE);
    }
    if (name.equals("退货")) {
      // 清空当前POS界面上Jtable中的所有商品信息
      DefaultTableModel tableModel = (DefaultTableModel) PosFrame.table
          .getModel();
      int counts = tableModel.getRowCount();
      for (int i = counts - 1; i >= 0; i--) {
        tableModel.removeRow(i);
      }
    }
    if (name.equals("帮助文档")) {
      JOptionPane.showConfirmDialog(null, "等做好chm文档再完善此功能!","友情提示",JOptionPane.OK_OPTION);
    }
    if (name.equals("退出")) {
      int ch = JOptionPane.showConfirmDialog(null, "你确定要退出超市管理系统的POS端吗?",
          "温馨提示", JOptionPane.YES_NO_OPTION);
      if (ch == JOptionPane.YES_OPTION) {
        PosFrame.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // 释放POS界面
        PosFrame.frame.dispose();
      }
    }
    if (name.equals("提取信息")) {
      PosFrameOper.checkInputValue();
    }
    if (name.equals("确定")) {
      sale_id++;
      sum += Double.parseDouble(PosFrame.product_sumText.getText());
      value = PosFrameOper.getInputTextValue();

      // 获得JTable的数据模型
      DefaultTableModel tableModel = (DefaultTableModel) PosFrame.table
          .getModel();
      // 将要加入的JTable中的数据构造为一个一维数组
      Object[] data = { new Integer(sale_id),
          new Integer(value.getProduct_id()), value.getProduct_name(),
          value.getProduct_type(), new Double(value.getProduct_price()),
          new Double(value.getPrice_pct()), new Integer(value.getSale_num()),
          new Double(value.getSale_sum()), new Double(sum),
          value.getSale_date() };
      // 通过DefaultTableModel模型将数据增加到JTable对象中
      tableModel.addRow(data);

    }
    if (name.equals("重置")) {
      PosFrameOper.initialTextValue();
    }
    if (name.equals("删除")) {
      int ch = JOptionPane.showConfirmDialog(null, "确定不需要购买此商品?", "温馨提示",
          JOptionPane.YES_NO_OPTION);
      if (ch == JOptionPane.YES_OPTION) {
        DefaultTableModel tableModel = (DefaultTableModel) PosFrame.table
            .getModel();
        tableModel.removeRow(row);
      }
    }
    if (name.equals("清空")) {
      DefaultTableModel tableModel = (DefaultTableModel) PosFrame.table
          .getModel();
      int counts = tableModel.getRowCount();
      // 循环删除jtable中所有信息
      for (int i = counts - 1; i >= 0; i--) {
        tableModel.removeRow(i);
      }
    }
    if (name.equals("结账")) {
      DefaultTableModel tableModel = (DefaultTableModel) PosFrame.table
          .getModel();
      int counts = tableModel.getRowCount();
      // 只有当jtable中有数据时才能进行结账
      if (counts >= 1) {
        DialogFactory.getInstance(name).getContainer();
      } else {
        JOptionPane.showMessageDialog(null, "商品信息栏中没有任何商品!", "提示",
            JOptionPane.PLAIN_MESSAGE);
      }
    }

  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -