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

📄 selectframehandler.java

📁 可以对名片进行增删改查,用户管理包括增删改查等,对名片查询时可以模糊查询
💻 JAVA
字号:
package card;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane;
import javax.swing.event.TreeSelectionListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

/**
 * <p>Title: Card</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class SelectFrameHandler implements ActionListener,
        TreeSelectionListener {
    SelectFrame sf;
    DatabaseOperate dbo = new DatabaseOperate();
    ArrayList al;
    cardDialog cd;
    updatecardDialog ud;
    public SelectFrameHandler(SelectFrame f) {
        this.sf = f;
        updateinfo("");
        updateType();

    }

    public void actionPerformed(ActionEvent e) {

        if (e.getActionCommand() == "select") {
            choicSql();
        }
        if (e.getActionCommand() == "delete") {
            int intRow = sf.tabInfo.getSelectedRow();
            if (intRow == -1) {
                JOptionPane.showMessageDialog(sf, "请先选择要删除的名片!", "错误",
                                              JOptionPane.ERROR_MESSAGE);
                return;
            }
            //      String abc=sf.tm.getValueAt(intRow,1).toString();
            if (dbo.delInfo(sf.tabInfo.getValueAt(intRow, 0).toString())) {
                JOptionPane.showMessageDialog(sf, "删除名片成功!", "成功",
                                              JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(sf, "删除名片失败!", "错误",
                                              JOptionPane.ERROR_MESSAGE);
            }
            updateinfo("");

        }
        if (e.getActionCommand() == "edit") {
            int intRow = sf.tabInfo.getSelectedRow();
            if (intRow == -1) {
                JOptionPane.showMessageDialog(sf, "请先选择要删除的名片!", "错误",
                                              JOptionPane.ERROR_MESSAGE);
                return;
            }

            else {
                ud = new updatecardDialog();
                ud.txtcardid.setText(sf.tabInfo.getValueAt(intRow, 0).toString());
                ud.txtname.setText(sf.tabInfo.getValueAt(intRow, 3).toString());
                ud.txtsex.setText(sf.tabInfo.getValueAt(intRow, 4).toString());
                ud.txtbrithday.setText(sf.tabInfo.getValueAt(intRow, 5).
                                       toString());
                ud.txtdepart.setText(sf.tabInfo.getValueAt(intRow, 6).toString());
                ud.txtpower.setText(sf.tabInfo.getValueAt(intRow, 7).toString());
                ud.txthomephone.setText(sf.tabInfo.getValueAt(intRow, 8).
                                        toString());
                ud.txtofficephone.setText(sf.tabInfo.getValueAt(intRow, 9).
                                          toString());
                ud.txtmobil.setText(sf.tabInfo.getValueAt(intRow, 10).toString());
                ud.txtaddress.setText(sf.tabInfo.getValueAt(intRow, 11).
                                      toString());
                ud.txtnumber.setText(sf.tabInfo.getValueAt(intRow, 12).toString());
                ud.txtemail.setText(sf.tabInfo.getValueAt(intRow, 13).toString());
                ud.comtpname.setSelectedItem(sf.tabInfo.getValueAt(intRow, 2).toString());
                ud.setBounds(350, 150, 550, 550);
                ud.setVisible(true);
            }
        }
//        allmodel am = new allmodel();
//        cardmodel cm = new cardmodel();
//        typemodel tm = new typemodel();
//        cm.setCarid(Integer.parseInt(sf.tabInfo.getValueAt(intRow, 0).toString()));
//        tm.setTyname(sf.tabInfo.getValueAt(intRow, 1).toString());
//
//
//        cd = new cardDialog();
//        cd.btnselect.setVisible(false);
//        cd.btncreate.setVisible(false);
//        cd.setBounds(350, 150, 550, 550);
//        cd.lblTypeid.setText("类别名称");
//        cd.txtcardid.setText(sf.tabInfo.getValueAt(intRow, 0).toString());
//        cd.txttypeid.setText(sf.tabInfo.getValueAt(intRow, 1).toString());
//        cd.txtname.setText(sf.tabInfo.getValueAt(intRow, 2).toString());
//        cd.setVisible(true);


    }


    public void choicSql() {
        String sql = "";
        if (sf.cboType.getSelectedItem().equals("类别")) {
            sql = " and  typetable.tpname like '%" +
                  sf.txtIn.getText().trim() +
                  "%'";
        }
        if (sf.cboType.getSelectedItem().equals("姓名")) {
            sql = " and  frdname like '%" + sf.txtIn.getText().trim() +
                  "%'";
        }
        if (sf.cboType.getSelectedItem().equals("性别")) {
            sql = " and  sex like '%" + sf.txtIn.getText().trim() +
                  "%'";
        }
        if (sf.cboType.getSelectedItem().equals("生日")) {
            sql = " and  birthday like '%" + sf.txtIn.getText().trim() +
                  "%'";
        }
        if (sf.cboType.getSelectedItem().equals("工作单位")) {
            sql = " and  depart like '%" + sf.txtIn.getText().trim() +
                  "%'";
        }
        if (sf.cboType.getSelectedItem().equals("职务")) {
            sql = " and  power like '%" + sf.txtIn.getText().trim() +
                  "%'";
        }
        if (sf.cboType.getSelectedItem().equals("家庭电话")) {
            sql = " and  homephone like '%" + sf.txtIn.getText().trim() +
                  "%'";
        }
        if (sf.cboType.getSelectedItem().equals("办公电话")) {
            sql = " and  officephone like '%" + sf.txtIn.getText().trim() +
                  "%'";
        }
        if (sf.cboType.getSelectedItem().equals("手机")) {
            sql = " and  mobil like '%" + sf.txtIn.getText().trim() +
                  "%'";
        }
        if (sf.cboType.getSelectedItem().equals("家庭地址")) {
            sql = " and  address like '%" + sf.txtIn.getText().trim() +
                  "%'";
        }
        if (sf.cboType.getSelectedItem().equals("邮编")) {
            sql = " and  number like '%" + sf.txtIn.getText().trim() +
                  "%'";
        }
        if (sf.cboType.getSelectedItem().equals("电子邮件")) {
            sql = " and  email like '%" + sf.txtIn.getText().trim() +
                  "%'";
        }
        updateinfo(sql);
    }


    public void updateinfo(String sql) {
        Object arrInfo[][] = {};
        Object arrField[] = {"卡号","类别编号", "类别", "姓名", "性别", "生日", "工作单位", "职务", "家庭电话",
                            "办公电话", "手机", "家庭地址", "邮编", "电子邮件"};
        DefaultTableModel tm = new DefaultTableModel(arrInfo, arrField);

        al = dbo.selectall(sql);
        for (int i = 0; i < al.size(); i++) {
            allmodel am = (allmodel) al.get(i);
            Object info[] = {String.valueOf(am.getcm().getCarid()),String.valueOf(am.gettym().getTyid()),
                            am.gettym().getTyname(), am.getcm().getFrdname(),
                            am.getcm().getSex(), am.getcm().getBirthday(),
                            am.getcm().getDepart(), am.getcm().getPower(),
                            am.getcm().getHomephone(),
                            am.getcm().getOfficephone(),
                            am.getcm().getMobil(), am.getcm().getAddress(),
                            am.getcm().getNumber(), am.getcm().getEmail()};
            tm.addRow(info);
        }
        sf.tabInfo.setModel(tm);
        sf.cboType.removeAllItems();
        sf.cboType.addItem("类别");
        sf.cboType.addItem("姓名");
        sf.cboType.addItem("性别");
        sf.cboType.addItem("生日");
        sf.cboType.addItem("工作单位");
        sf.cboType.addItem("职务");
        sf.cboType.addItem("家庭电话");
        sf.cboType.addItem("办公电话");
        sf.cboType.addItem("手机");
        sf.cboType.addItem("家庭地址");
        sf.cboType.addItem("邮编");
        sf.cboType.addItem("电子邮件");
    }

    public void updateType() {
        ArrayList arr = dbo.selectType();
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("类别");
        DefaultTreeModel dtm=new DefaultTreeModel(root);
      //  sf.root.removeAllChildren();
      sf.treType.setModel(dtm);
        for (int i = 0; i < arr.size(); i++) {
            typemodel tm = (typemodel) arr.get(i);
            DefaultMutableTreeNode df = new DefaultMutableTreeNode(tm.getTyname().
                    trim());
//            sf.root.add(df);
            root.add(df);
        }

    }

    public void valueChanged(TreeSelectionEvent e) {

        try {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) sf.treType.
                                          getLastSelectedPathComponent();
            if (!node.isRoot()) {
                Object nodeInfo = node.getUserObject();
                String sql = " and  typetable.tpname like '%" +
                             nodeInfo.toString().trim() +
                             "%'";
                updateinfo(sql);
            }
        } catch (Exception ex) {

        }
    }
    }







⌨️ 快捷键说明

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