基础java项目3(MainFrame )

时间:2022-08-07 08:53:10

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JMenuBar;
import java.awt.GridLayout;
import javax.swing.JComboBox;
import javax.swing.JToolBar;
import javax.swing.table.AbstractTableModel;
import java.util.*;
import javax.swing.JTable;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JScrollPane;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JLabel;

class MainFrame extends JFrame {
    JFrame frame = new JFrame("固定资产管理系统");
    DATAConnection dcon = null;
    JMenu loginmenu;
    JMenuItem exit, reg;
    JMenuBar mbar;
    JPanel set_pan;
    JComboBox jcbset1;
    JButton jbtsetok;
    JButton jbtset, jbtop, jbtabout, jbtseek;
    String user;
    JToolBar jtbar;
    JTextField info1;
    mytable model;
    JTable table;
    JScrollPane table_pan;

    //管理员设置操作面板
    JPanel man_pan;
    JLabel jpmanuser;
    JLabel jpmanpass;
    JTextField jtmanuser;
    JTextField jtmanpass;
    JButton man_ok;
    JButton man_back;
    //科目选择窗体
    JPanel sub_pan;
    JButton sub_ok;
    JButton sub_back;
    JComboBox JCB_sub;
    //科目操作窗体
    JPanel sub_op_pan;
    JButton sub_op_back;
    JButton sub_op_del;
    JButton sub_op_insert;
    JComboBox JCB_op_sub;
    JTextField opid;
    //科目插入菜单
    JPanel sub_op_insert_pan;
    JTextField fristsubID;
    JTextField fristsubname;
    JButton jbt_op_insert_ok;
    JButton jbt_op_insert_back;
    JComboBox jcb_frist_second;
    String temp = "";
    //雇员操作
    JPanel sub_work_pan;
    JButton jbt_work_insert;
    JButton jbt_work_del;
    JButton jbt_work_badk;
    JPanel sub_work_pan_insert;
    JButton jbt_work_insert_ok;
    JTextField workID;
    JTextField workname;
    JTextField workduty;
    JTextField workmem;
    JButton jbt_work_insert_back;
    //操作窗体
    JPanel op_pan;
    JButton op_brow;
    JButton op_return;
    JButton op_insert;
    JPanel op_pan_brow;
    JButton op_brow_ok;
    JButton op_op_mem;
    JComboBox jcb_op_brow;
    JTextField used;
    JTextField draw_mem;
    JTextField drawDate;
    JTextField amongmanager;
    JButton op_modi;
    JButton op_del;
    JPanel add_op_add;
    JComboBox add_intsert;
    JComboBox add2;
    JTextField add_mc;
    JTextField add_price;
    JTextField bh;
    JTextField kmbh;
    JPanel op_pan_del;
    JButton op_del_ok;
    JComboBox mark;
    JPanel op_mark;
    JButton jbt_op_brow_back;
    JButton jbt_op_return_back;
    JButton jbt_op_add_back;
    JButton jbt_op_del_back;
    JButton jbt_op_mark_back;
    //seek
    JPanel seek_pan;
    JPanel seek_pan_kinds;
    JPanel seek_pan_person;
    JComboBox seek_choice;
    JButton seek_kinds;
    JButton seek_prerson;
    JButton seek_status;
    JComboBox seek_choic_person;
    JPanel seek_pan_status;
    JComboBox seek_choic_status;
    JButton seek_kinds_BACK;
    JButton seek_prerson_BACK;
    JButton seek_status_BACK;

    //构造MainFrame
    MainFrame(String user) {
        try {
            this.user = user;
            jinit();
        } catch (Exception e) {
            System.out.println("Exception in :MainFrame in :MainFrame()::" +
                               e.getMessage());
            e.printStackTrace();
        }
    }

    //筛选条件
    public String[] getchoiceCondi(String tname) {
        dcon = new DATAConnection();
        String[] s = null;
        String s1 = null;
        String sql = null;
        if (tname.equals("MACKinds")) {
            s1 = "kname";
            sql = "select " + s1 + " from " + tname;
        } else if (tname.equals("1")) {
            sql = "select pname from MACperson";
        } else if (tname.equals("2")) {
            sql = "select CName from MACContentsKinds";
        } else if (tname.equals("3")) {
            sql = "select pname from MACperson";
        } else {
            s1 = "CName";
            sql = "select " + s1 + " from " + tname;
        }
        Vector managerV = dcon.select(sql);
        int count = managerV.size();
        if (!tname.equals("1")) {
            s = new String[count + 1];
        } else {
            s = new String[count];
        }
        for (int i = 0; i < count; i++) {
            s[i] = ((Vector) managerV.get(i)).get(0).toString();
        }
        if (!tname.equals("1")) {
            if (!tname.equals("2")) {
                s[count] = "全部";
            } else {
                s[count] = "";
            }
        }
        return s;
    }

    //科目选择
    public void subchoice() {
        sub_ok = new JButton("确定");
        sub_back = new JButton("返回");
        String[] subject = {"一级科目", "二级科目"};
        JCB_sub = new JComboBox(subject);
        sub_pan = new JPanel();
        sub_pan.add(JCB_sub);
        sub_pan.add(sub_ok);
        sub_pan.add(sub_back);
        frame.getContentPane().add(sub_pan, BorderLayout.CENTER);
        frame.repaint();
        frame.setVisible(true);
        sub_back.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(sub_pan);
                setchoice();
            }
        });
        sub_ok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(sub_pan);
                if (JCB_sub.getSelectedItem().toString().equals("一级科目")) {
                    subjectop("MACKinds");

                } else {
                    subjectop("MACContentsKinds");
                }
            }

        });
    }

    //科目的操作
    public void subjectop(String tablename) {
        final String tablen = tablename;
        String sql = "select * from " + tablename;
        model = new mytable();
        model.setTitle(gettitle(sql));
        model.setContent(getv(sql));
        table = new JTable(model);
        table.setRowSelectionAllowed(false);
        table_pan = new JScrollPane(table);
        frame.getContentPane().add(table_pan, BorderLayout.CENTER);
        opid = new JTextField(10);
        opid.setEditable(false);
        sub_op_del = new JButton("删除");
        sub_op_insert = new JButton("增加");
        sub_op_back = new JButton("返回");
        JCB_op_sub = new JComboBox(getchoiceCondi("MACKinds"));
        sub_op_pan = new JPanel();
        sub_op_pan.add(opid);
        sub_op_pan.add(sub_op_del);
        sub_op_pan.add(sub_op_insert);
        sub_op_pan.add(sub_op_back);
        sub_op_pan.add(JCB_op_sub);
        frame.getContentPane().add(sub_op_pan, BorderLayout.SOUTH);
        frame.repaint();
        frame.setVisible(true);
        sub_op_back.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(table_pan);
                frame.remove(sub_op_pan);
                subchoice();
            }
        });
        sub_op_del.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dcon = new DATAConnection();
                String cons = opid.getText().trim();
                JOptionPane jtp = new JOptionPane();
                String s1 = null;
                boolean flags = true;
                if (cons.length() == 0) {
                    jtp.showMessageDialog(frame, "还没有选择要操作的记录");
                } else {
                    if (tablen.equals("MACKinds")) {
                        s1 = "kid";
                        String sql =
                                "select * from MACContentsKinds where KID='" +
                                cons + "'";
                        if (dcon.isNull(sql)) {
                            jtp.showMessageDialog(frame, "下级帐户有相关联的记录");
                            flags = false;
                        }
                    } else {
                        s1 = "CKid";
                        String sql = "select * from MACapital where ckID='" +
                                     cons + "'";
                        if (dcon.isNull(sql)) {
                            jtp.showMessageDialog(frame, "下级帐户有相关联的记录");
                            flags = false;
                        }
                    }
                    if (flags) {
                        String sql = "delete from " + tablen + " where " + s1 +
                                     "='" + cons + "'";
                        jtp.showMessageDialog(frame, dcon.update(2, sql));
                        model.setContent(getv("select * from " + tablen));
                        sub_op_pan.remove(JCB_op_sub);
                        JCB_op_sub = new JComboBox(getchoiceCondi(tablen));
                        sub_op_pan.add(JCB_op_sub);
                        table.updateUI();
                        frame.repaint();
                        frame.setVisible(true);
                    }
                }
            }
        });
        JCB_op_sub.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (!JCB_op_sub.getSelectedItem().toString().equals("全部")) {
                    dcon = new DATAConnection();
                    String sql = "select kid from MACKinds where kname = '" +
                                 JCB_op_sub.getSelectedItem().toString() + "'";
                    Vector v = dcon.select(sql);
                    temp = ((Vector) v.get(0)).get(0).toString();
                    info1.setText(temp);
                    sql = "select * from " + tablen + " where KID = '" + temp +
                          "'";
                    model.setContent(dcon.select(sql));
                    table.updateUI();
                    frame.repaint();
                } else {
                    temp = "";
                    info1.setText(temp);
                    dcon = new DATAConnection();
                    String sql = "select * from  " + tablen;
                    Vector v = dcon.select(sql);
                    model.setContent(v);
                    table.updateUI();
                    frame.repaint();
                }

            }
        });
        sub_op_insert.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (tablen.equals("MACKinds")) {
                    fristsubinsert();
                } else {
                    secondsubinsert();
                }
            }
        });
        table.addMouseListener(new MouseListener() {
            public void mouseClicked(java.awt.event.MouseEvent e) {
                if (table.getSelectedRow() != -1 &&
                    table.getSelectedColumn() != -1) {
                    opid.setText((String) table.getValueAt(table.getSelectedRow(),
                            0));
                }
            }

            public void mouseEntered(MouseEvent e) {
            }

            public void mouseExited(MouseEvent e) {
            }

            public void mousePressed(MouseEvent e) {
            }

            public void mouseReleased(MouseEvent e) {
            }

        });

    }

    //二级科目的增加
    public void secondsubinsert() {
        sub_op_insert_pan = new JPanel();
        fristsubID = new JTextField(10);
        fristsubname = new JTextField(10);
        jcb_frist_second = new JComboBox(getchoiceCondi("MACKinds"));
        jbt_op_insert_ok = new JButton("确定");
        jbt_op_insert_back = new JButton("返回");
        sub_op_insert_pan.add(jcb_frist_second);
        sub_op_insert_pan.add(fristsubID);
        sub_op_insert_pan.add(fristsubname);
        sub_op_insert_pan.add(jbt_op_insert_ok);
        sub_op_insert_pan.add(jbt_op_insert_back);
        frame.remove(sub_op_pan);
        frame.getContentPane().add(sub_op_insert_pan, BorderLayout.SOUTH);
        frame.repaint();
        frame.setVisible(true);
        jcb_frist_second.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (!jcb_frist_second.getSelectedItem().toString().equals("全部")) {
                    dcon = new DATAConnection();
                    String sql = "select kid from MACKinds where kname = '" +
                                 jcb_frist_second.getSelectedItem().toString() +
                                 "'";
                    Vector v = dcon.select(sql);
                    temp = ((Vector) v.get(0)).get(0).toString();
                    info1.setText(temp);
                    sql = "select * from MACContentsKinds where KID = '" + temp +
                          "'";
                    model.setContent(dcon.select(sql));
                    table.updateUI();
                    frame.repaint();
                } else {
                    temp = "";
                    info1.setText(temp);
                    dcon = new DATAConnection();
                    String sql = "select * from MACContentsKinds ";
                    Vector v = dcon.select(sql);
                    model.setContent(v);
                    table.updateUI();
                    frame.repaint();
                }
            }
        });
        jbt_op_insert_ok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane jtp = new JOptionPane();
                if (temp.length() == 0 || temp.length() != 3 ||
                    fristsubID.getText().trim().length() == 0 ||
                    fristsubname.getText().trim().length() == 0) {
                    jtp.showMessageDialog(frame, "编号和名称不能为空");
                } else if (fristsubID.getText().trim().length() != 5 ||
                           !fristsubID.getText().trim().startsWith(temp)) {
                    jtp.showMessageDialog(frame, "编号输入不对");
                } else if (!isnum(fristsubID.getText().trim())) {
                    jtp.showMessageDialog(frame, "编号应为数字");
                } else {
                    String sql01 =
                            "select * from MACContentsKinds where CKid = '" +
                            fristsubID.getText().trim() + "'";
                    boolean flags1 = dcon.isNull(sql01);
                    String sql02 =
                            "select * from MACContentsKinds where CKid = '" +
                            fristsubname.getText().trim().trim() + "'";
                    boolean flags2 = dcon.isNull(sql02);
                    if (!flags1 && !flags2) {
                        String sql11 =
                                "insert into MACContentsKinds(CKid,KID,CName) values('" +
                                fristsubID.getText().trim() + "','" + temp +
                                "','" + fristsubname.getText().trim() + "')";
                        jtp.showMessageDialog(frame, dcon.update(3, sql11));
                        jcb_frist_second.addItem(fristsubname.getText().trim());
                    } else {
                        jtp.showMessageDialog(frame, "有相同的编号或名称");
                    }
                }
                model.setContent(getv("select * from MACContentsKinds"));
                table.updateUI();
                frame.repaint();
            }
        });
        jbt_op_insert_back.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(sub_op_insert_pan);
                frame.getContentPane().add(sub_op_pan, BorderLayout.SOUTH);
                frame.repaint();
                frame.setVisible(true);
            }
        });
    }

    //一级科目的增加
    public void fristsubinsert() {
        sub_op_insert_pan = new JPanel();
        fristsubID = new JTextField(10);
        fristsubname = new JTextField(10);
        jbt_op_insert_ok = new JButton("确定");
        jbt_op_insert_back = new JButton("返回");
        sub_op_insert_pan.add(fristsubID);
        sub_op_insert_pan.add(fristsubname);
        sub_op_insert_pan.add(jbt_op_insert_ok);
        sub_op_insert_pan.add(jbt_op_insert_back);
        frame.remove(sub_op_pan);
        frame.getContentPane().add(sub_op_insert_pan, BorderLayout.SOUTH);
        frame.repaint();
        frame.setVisible(true);
        jbt_op_insert_back.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(sub_op_insert_pan);
                frame.getContentPane().add(sub_op_pan, BorderLayout.SOUTH);
                frame.repaint();
                frame.setVisible(true);
            }
        });
        jbt_op_insert_ok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane jtp = new JOptionPane();
                if (fristsubID.getText().trim().length() == 0 ||
                    fristsubname.getText().trim().length() == 0) {
                    jtp.showMessageDialog(frame, "编号和名称不能为空");
                } else if (fristsubID.getText().trim().length() != 3) {
                    jtp.showMessageDialog(frame, "编号输入不对");
                } else if (!isnum(fristsubID.getText().trim())) {
                    jtp.showMessageDialog(frame, "编号应为数字");
                } else {
                    dcon = new DATAConnection();
                    String sql01 = "select * from MACKinds where kid = '" +
                                   fristsubID.getText().trim() + "'";
                    boolean flags1 = dcon.isNull(sql01);
                    String sql02 = "select * from MACKinds where kid = '" +
                                   fristsubname.getText().trim().trim() + "'";
                    boolean flags2 = dcon.isNull(sql02);
                    if (!flags1 && !flags2) {
                        String sql11 =
                                "insert into MACKinds(kid,kname) values('" +
                                fristsubID.getText().trim() + "','" +
                                fristsubname.getText().trim() + "')";
                        dcon.update(3, sql11);
                    } else {
                        jtp.showMessageDialog(frame, "有相同的编号或名称");
                    }
                }
                model.setContent(getv("select * from MACKinds"));
                table.updateUI();
                frame.repaint();
            }
        });

    }


    public void jinit() {
        //操作菜单
        reg = new JMenuItem("注册管理员");
        exit = new JMenuItem("退出");
        loginmenu = new JMenu("操作");
        loginmenu.add(reg);
        loginmenu.add(exit);
        //帮助菜单
        //菜单
        mbar = new JMenuBar();
        mbar.add(loginmenu);
        frame.setJMenuBar(mbar);
        //工具栏
        info1 = new JTextField(2);
        info1.setEditable(false);
        jbtset = new JButton("设置");
        jbtop = new JButton("操作");
        jbtabout = new JButton("退出");
        jbtseek = new JButton("查询");
        jtbar = new JToolBar();
        jtbar.setFloatable(false);
        jtbar.setBorderPainted(true);
        jtbar.add(info1);
        jtbar.add(jbtset);
        jtbar.add(jbtop);
        jtbar.add(jbtseek);
        jtbar.add(jbtabout);
        frame.getContentPane().add(jtbar, BorderLayout.NORTH);
        frame.setResizable(false);
        frame.setSize(500, 400);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jbtset.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.getContentPane().removeAll();
                jinit();
                setchoice();
            }
        });
        reg.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.getContentPane().removeAll();
                closeall();
                ManagerReg mr = new ManagerReg() ;
                mr.jbinit();
            }
        });

        exit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.getContentPane().removeAll();
                closeall();
            }
        });

        jbtabout.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                closeall();
            }
        });

        jbtop.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.getContentPane().removeAll();
                jinit();
                operate();
            }
        });
        jbtseek.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.getContentPane().removeAll();
                jinit();
                seek();
            }
        });

    }

    public void seek() {
        seek_pan = new JPanel();
        seek_kinds = new JButton("按种类");
        seek_prerson = new JButton("按人");
        seek_status = new JButton("按状态");
        seek_pan.add(seek_kinds);
        seek_pan.add(seek_prerson);
        seek_pan.add(seek_status);
        frame.getContentPane().add(seek_pan, BorderLayout.CENTER);
        frame.repaint();
        frame.setVisible(true);
        seek_kinds.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                seekkinds();
            }
        });
        seek_prerson.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                seekperson();
            }
        });
        seek_status.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                seekStatus();
            }
        });
    }

    public void seekStatus() {
        model = new mytable();
        String sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACapital.userid  from  MACapital,MACContentsKinds where MACapital.ckid = MACContentsKinds.ckid ";
        model.setTitle(gettitle(sql));
        model.setContent(getv(sql));
        table = new JTable(model);
        table.setRowSelectionAllowed(false);
        table_pan = new JScrollPane(table);
        frame.remove(seek_pan);
        frame.getContentPane().add(table_pan, BorderLayout.CENTER);
        String[] stutasstr = {"正常", "维修", "报废", "全部"};
        seek_choic_status = new JComboBox(stutasstr);
        seek_choic_status.setEditable(false);
        seek_pan_status = new JPanel();
        seek_pan_status.add(seek_choic_status);
        seek_status_BACK = new JButton("返回");
         seek_pan_status.add(seek_status_BACK);
        frame.getContentPane().add(seek_pan_status, BorderLayout.SOUTH);
        frame.repaint();
        frame.setVisible(true);
        seek_status_BACK.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e) {
               frame.remove(seek_pan_status);
               frame.remove(table_pan);
               frame.getContentPane().add(seek_pan, BorderLayout.CENTER);
               frame.repaint();
               frame.setVisible(true);
           }});

        seek_choic_status.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                JOptionPane jpt = new JOptionPane();
                if (seek_choic_status.getSelectedItem().toString().trim().
                    length() == 0) {
                    jpt.showMessageDialog(frame, "请选择条件");
                } else if (seek_choic_status.getSelectedItem().toString().trim().
                           equals("全部")) {
                    String sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACapital.userid  from  MACapital,MACContentsKinds where MACapital.ckid = MACContentsKinds.ckid ";
                    model.setTitle(gettitle(sql));
                    model.setContent(getv(sql));
                    table.updateUI();
                } else {
                    dcon = new DATAConnection();
                    String sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACapital.userid  from  MACapital,MACContentsKinds where MACapital.ckid = MACContentsKinds.ckid and MACapital.status = '" +
                                 seek_choic_status.getSelectedItem().toString().
                                 trim() + "'";
                    model.setTitle(gettitle(sql));
                    model.setContent(getv(sql));
                    table.updateUI();
                }
            }
        });

    }

    //按人查找
    public void seekperson() {
        model = new mytable();
        String sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACapital.userid  from  MACapital,MACContentsKinds where MACapital.ckid = MACContentsKinds.ckid ";
        model.setTitle(gettitle(sql));
        model.setContent(getv(sql));
        table = new JTable(model);
        table.setRowSelectionAllowed(false);
        table_pan = new JScrollPane(table);
        frame.remove(seek_pan);
        frame.getContentPane().add(table_pan, BorderLayout.CENTER);
        seek_choic_person = new JComboBox(getchoiceCondi("3"));
        seek_choic_person.setEditable(false);
        seek_pan_person = new JPanel();
        seek_pan_person.add(seek_choic_person);
        seek_prerson_BACK = new JButton("返回");
        seek_pan_person.add(seek_prerson_BACK);
        frame.getContentPane().add(seek_pan_person, BorderLayout.SOUTH);
        frame.repaint();
        frame.setVisible(true);
        seek_prerson_BACK.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e) {
               frame.remove(seek_pan_person);
               frame.remove(table_pan);
               frame.getContentPane().add(seek_pan, BorderLayout.CENTER);
               frame.repaint();
               frame.setVisible(true);
           }

       });

        seek_choic_person.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                JOptionPane jpt = new JOptionPane();
                if (seek_choic_person.getSelectedItem().toString().trim().
                    length() == 0) {
                    jpt.showMessageDialog(frame, "请选择条件");
                } else if (seek_choic_person.getSelectedItem().toString().trim().
                           equals("全部")) {
                    String sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACapital.userid  from  MACapital,MACContentsKinds where MACapital.ckid = MACContentsKinds.ckid ";
                    model.setTitle(gettitle(sql));
                    model.setContent(getv(sql));
                    table.updateUI();
                } else {
                    dcon = new DATAConnection();
                    String sql1 = "select pID from MACperson where pname='" +
                                  seek_choic_person.getSelectedItem().toString() +
                                  "'";
                    Vector v = dcon.select(sql1);
                    String name = ((Vector) v.get(0)).get(0).toString();
                    String sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACapital.userid  from  MACapital,MACContentsKinds where MACapital.ckid = MACContentsKinds.ckid and  MACapital.userid= '" +
                                 name + "'";
                    model.setTitle(gettitle(sql));
                    model.setContent(getv(sql));
                    table.updateUI();
                }
            }
        });
    }

    //按种类查找
    public void seekkinds() {
        model = new mytable();
        String sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACapital.userid  from  MACapital,MACContentsKinds where MACapital.ckid = MACContentsKinds.ckid ";
        model.setTitle(gettitle(sql));
        model.setContent(getv(sql));
        table = new JTable(model);
        table.setRowSelectionAllowed(false);
        table_pan = new JScrollPane(table);
        frame.remove(seek_pan);
        frame.getContentPane().add(table_pan, BorderLayout.CENTER);
        seek_choice = new JComboBox(getchoiceCondi("MACContentsKinds"));
        seek_choice.setEditable(false);
        seek_pan_kinds = new JPanel();
        seek_kinds_BACK = new JButton("返回");
        seek_pan_kinds.add(seek_choice);
        seek_pan_kinds.add(seek_kinds_BACK);
        frame.getContentPane().add(seek_pan_kinds, BorderLayout.SOUTH);
        frame.repaint();
        frame.setVisible(true);
        seek_kinds_BACK.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                frame.remove(seek_pan_kinds);
                frame.remove(table_pan);
                frame.getContentPane().add(seek_pan, BorderLayout.CENTER);
                frame.repaint();
                frame.setVisible(true);
            }

        });
        seek_choice.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                JOptionPane jpt = new JOptionPane();
                if (seek_choice.getSelectedItem().toString().trim().length() ==
                    0) {
                    jpt.showMessageDialog(frame, "请选择条件");
                } else if (seek_choice.getSelectedItem().toString().trim().
                           equals("全部")) {
                    String sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACapital.userid  from  MACapital,MACContentsKinds where MACapital.ckid = MACContentsKinds.ckid ";
                    model.setTitle(gettitle(sql));
                    model.setContent(getv(sql));
                    table.updateUI();
                } else {
                    String sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACapital.userid  from  MACapital,MACContentsKinds where MACapital.ckid = MACContentsKinds.ckid and  MACContentsKinds.cname= '" +
                                 seek_choice.getSelectedItem().toString().trim() +
                                 "'";
                    model.setTitle(gettitle(sql));
                    model.setContent(getv(sql));
                    table.updateUI();

                }
            }
        });

    }

//操作选择
    public void operate() {
        op_pan = new JPanel();
        op_brow = new JButton("领取");
        op_return = new JButton("归还");
        op_insert = new JButton("增加");
        op_del = new JButton("删除");
        op_op_mem = new JButton("标记");
        op_pan.add(op_brow);
        op_pan.add(op_return);
        op_pan.add(op_insert);
        op_pan.add(op_del);
        op_pan.add(op_op_mem);
        frame.getContentPane().add(op_pan, BorderLayout.CENTER);
        frame.repaint();
        frame.setVisible(true);
        op_brow.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                draw();
            }
        });
        op_return.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(op_pan);
                op_return();
            }

        });
        op_insert.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(op_pan);
                op_add();
            }
        });
        op_del.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(op_pan);
                op_del();
            }
        });
        op_op_mem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(op_pan);
                op_mark();
            }
        });
    }

    //标记
    public void op_mark() {
        op_mark = new JPanel();
        model = new mytable();
        String sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACapital.userid  from  MACapital,MACContentsKinds where MACapital.ckid = MACContentsKinds.ckid and (MACapital.userid is null or len(MACapital.userid)=0)";
        model.setTitle(gettitle(sql));
        model.setContent(getv(sql));
        table = new JTable(model);
        table.setRowSelectionAllowed(false);
        table_pan = new JScrollPane(table);
        frame.remove(op_pan);
        frame.getContentPane().add(table_pan, BorderLayout.CENTER);
        String[] s = {"正常", "维修", "报废"};
        mark = new JComboBox(s);
        mark.setEditable(false);
        opid = new JTextField(10);
        opid.setEditable(false);
        op_del_ok = new JButton("标记");
        jbt_op_mark_back = new JButton("返回");
        op_mark.add(opid);
        op_mark.add(mark);
        op_mark.add(op_del_ok);
        op_mark.add(jbt_op_mark_back);
        frame.getContentPane().add(op_mark, BorderLayout.SOUTH);
        frame.repaint();
        frame.setVisible(true);
        jbt_op_mark_back.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(op_mark);
                frame.remove(table_pan);
                frame.getContentPane().add(op_pan, BorderLayout.CENTER);
                frame.repaint();
                frame.setVisible(true);

            }

        });
        table.addMouseListener(new MouseListener() {
            public void mouseClicked(java.awt.event.MouseEvent e) {
                if (table.getSelectedRow() != -1 &&
                    table.getSelectedColumn() != -1) {
                    opid.setText((String) table.getValueAt(table.getSelectedRow(),
                            0));
                }
            }

            public void mouseEntered(MouseEvent e) {
            }

            public void mouseExited(MouseEvent e) {
            }

            public void mousePressed(MouseEvent e) {
            }

            public void mouseReleased(MouseEvent e) {
            }
        });
        op_del_ok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane jpt = new JOptionPane();
                if (opid.getText().trim().length() == 0) {
                    jpt.showMessageDialog(frame, "请选择要操作的记录");
                } else {
                    dcon = new DATAConnection();
                    String sql = "update  MACapital set status='" +
                                 mark.getSelectedItem().toString().trim() +
                                 "' where Bh='" + opid.getText().trim() + "'";
                    jpt.showMessageDialog(frame, dcon.update(1, sql));
                    sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACapital.userid  from  MACapital,MACContentsKinds where MACapital.ckid = MACContentsKinds.ckid and (MACapital.userid is null or len(MACapital.userid)=0)";
                    model.setContent(getv(sql));
                    table.updateUI();
                }
            }
        });

    }

//删除
    public void op_del() {
        model = new mytable();
        String sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACapital.userid  from  MACapital,MACContentsKinds where(MACapital.ckid = MACContentsKinds.ckid)";
        model.setTitle(gettitle(sql));
        model.setContent(getv(sql));
        table = new JTable(model);
        table.setRowSelectionAllowed(false);
        table_pan = new JScrollPane(table);
        frame.remove(op_pan);
        frame.getContentPane().add(table_pan, BorderLayout.CENTER);
        opid = new JTextField(10);
        opid.setEditable(false);
        op_del_ok = new JButton("删除");
        jbt_op_del_back = new JButton("返回");
        op_pan_del = new JPanel();
        op_pan_del.add(opid);
        op_pan_del.add(op_del_ok);
        op_pan_del.add(jbt_op_del_back);
        frame.getContentPane().add(op_pan_del, BorderLayout.SOUTH);
        frame.repaint();
        frame.setVisible(true);
        jbt_op_del_back.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(op_pan_del);
                frame.remove(table_pan);
                frame.getContentPane().add(op_pan, BorderLayout.CENTER);
                frame.repaint();
                frame.setVisible(true);
            }

        });
        table.addMouseListener(new MouseListener() {
            public void mouseClicked(java.awt.event.MouseEvent e) {
                if (table.getSelectedRow() != -1 &&
                    table.getSelectedColumn() != -1) {
                    opid.setText((String) table.getValueAt(table.getSelectedRow(),
                            0));
                }
            }

            public void mouseEntered(MouseEvent e) {
            }

            public void mouseExited(MouseEvent e) {
            }

            public void mousePressed(MouseEvent e) {
            }

            public void mouseReleased(MouseEvent e) {
            }
        });
        op_del_ok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane jpt = new JOptionPane();
                if (opid.getText().trim().length() == 0) {
                    jpt.showMessageDialog(frame, "请选择要操作的记录");
                } else {
                    dcon = new DATAConnection();
                    String sql = "select * from MACapital where Bh= '" +
                                 opid.getText().trim() +
                                 "' and ((userID is null) or (len(userID)=0)) ";
                    if (dcon.isNull(sql)) {
                        sql = "delete from MACapital  where Bh= '" +
                              opid.getText().trim() + "'";
                        jpt.showMessageDialog(frame, dcon.update(2, sql));
                        sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACapital.userid  from  MACapital,MACContentsKinds where(MACapital.ckid = MACContentsKinds.ckid)";
                        model.setContent(getv(sql));
                        table.updateUI();
                    } else {
                        jpt.showMessageDialog(frame, "请退回后在删除");
                    }
                }
            }
        });

    }

//增加
    public void op_add() {
        model = new mytable();
        String sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACapital.userid  from  MACapital,MACContentsKinds where(MACapital.ckid = MACContentsKinds.ckid)";
        model.setTitle(gettitle(sql));
        model.setContent(getv(sql));
        table = new JTable(model);
        table.setRowSelectionAllowed(false);
        table_pan = new JScrollPane(table);
        frame.remove(op_pan);
        frame.getContentPane().add(table_pan, BorderLayout.CENTER);
        add_op_add = new JPanel(new GridLayout(5, 4));
        JLabel km = new JLabel("种类");
        add_intsert = new JComboBox(getchoiceCondi("2"));
        add_op_add.add(km);
        add_op_add.add(add_intsert);
        JLabel kmbh1 = new JLabel("科目编号");
        kmbh = new JTextField(10);
        kmbh.setEditable(false);
        add_op_add.add(kmbh1);
        add_op_add.add(kmbh);
        JLabel mc = new JLabel("名称");
        add_mc = new JTextField(10);
        add_op_add.add(mc);
        add_op_add.add(add_mc);
        JLabel bhl = new JLabel("编号");
        bh = new JTextField();
        add_op_add.add(bhl);
        add_op_add.add(bh);
        JLabel p = new JLabel("价格");
        add_price = new JTextField(10);
        add_op_add.add(p);
        add_op_add.add(add_price);
        JLabel draw_date = new JLabel("领取时间");
        Calendar today = Calendar.getInstance();
        int month = today.get(Calendar.MONTH) + 1;
        int year = today.get(Calendar.YEAR);
        int day = today.get(Calendar.DATE);
        final String currentdate = String.valueOf(year) + "-" +
                                   String.valueOf(month) + "-" +
                                   String.valueOf(day);
        drawDate = new JTextField(currentdate, 10);
        drawDate.setEditable(false);
        add_op_add.add(draw_date);
        add_op_add.add(drawDate);
        JLabel status = new JLabel("说明");
        String[] s = {"正常", "维修"};
        add2 = new JComboBox(s);
        add2.setEditable(false);
        add_op_add.add(status);
        add_op_add.add(add2);
        JLabel drawmem = new JLabel("备注");
        draw_mem = new JTextField(10);
        add_op_add.add(drawmem);
        add_op_add.add(draw_mem);
        op_brow_ok = new JButton("增加");
        jbt_op_add_back = new JButton("返回");
        add_op_add.add(op_brow_ok);
        add_op_add.add(jbt_op_add_back);
        frame.getContentPane().add(add_op_add, BorderLayout.SOUTH);
        frame.repaint();
        frame.setVisible(true);
        jbt_op_add_back.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(add_op_add);
                frame.remove(table_pan);
                frame.getContentPane().add(op_pan, BorderLayout.CENTER);
                frame.repaint();
                frame.setVisible(true);

            }

        });
        add_intsert.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (add_intsert.getSelectedItem().toString().trim().length() >
                    0) {
                    dcon = new DATAConnection();
                    String sql =
                            "Select CKid from MACContentsKinds where CName = '" +
                            add_intsert.getSelectedItem().toString().trim() +
                            "'";
                    Vector v = dcon.select(sql);
                    kmbh.setText(((Vector) v.get(0)).get(0).toString());
                } else {
                    kmbh.setText("");
                }
            }
        });
        op_brow_ok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane jpt = new JOptionPane();
                if (kmbh.getText().trim().length() == 0 ||
                    add_mc.getText().trim().length() == 0 ||
                    bh.getText().trim().length() == 0 ||
                    add_price.getText().trim().length() == 0) {
                    jpt.showMessageDialog(frame, "不能为空");
                } else if (!isnum(add_price.getText().trim())) {
                    jpt.showMessageDialog(frame, "价格必须为数字");
                } else if (Float.valueOf(add_price.getText().trim()).floatValue() <
                           2000) {
                    jpt.showMessageDialog(frame, "价格>2000");
                } else if (bh.getText().trim().length() != 7 ||!
                           bh.getText().trim().startsWith(kmbh.getText().trim())) {
                    jpt.showMessageDialog(frame, "编号格式不对");
                } else {
                    dcon = new DATAConnection();
                    String sql = "select * from MACapital where Bh='" +
                                 bh.getText().trim() + "'";
                    if (dcon.isNull(sql)) {
                        jpt.showMessageDialog(frame, "此编号已经存在");
                    } else {
                        String str;
                        if (draw_mem.getText().trim().length() == 0) {
                            str = "";
                        } else {
                            str = draw_mem.getText().trim();
                        }
                        sql = " insert into MACapital(Bh,ckID,style,price,purDate,status,userID,mem) values ('";
                        sql += bh.getText().trim() + "','" +
                                kmbh.getText().trim() + "','";
                        sql += add_mc.getText().trim() + "','" +
                                add_price.getText().trim() + "','";
                        sql += drawDate.getText().trim() + "','" +
                                add2.getSelectedItem().toString().trim() +
                                "','','" + str + "')";
                        jpt.showMessageDialog(frame, dcon.update(3, sql));
                        sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACapital.userid  from  MACapital,MACContentsKinds where(MACapital.ckid = MACContentsKinds.ckid)";
                        model.setContent(getv(sql));
                        table.updateUI();
                        kmbh.setText("");
                        add_mc.setText("");
                        bh.setText("");
                        add_price.setText("");
                    }
                }

            }
        });
    }

//归还
    public void op_return() {
        model = new mytable();
        String sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACperson.pname from  MACapital,MACContentsKinds,MACperson where ((MACapital.ckid = MACContentsKinds.ckid) and (MACapital.status ='正常' ) and (MACapital.userid  is not  null or len(MACapital.userid)>0 ) and (MACperson.pid = MACapital.userid) )";
        model.setTitle(gettitle(sql));
        model.setContent(getv(sql));
        table = new JTable(model);
        table.setRowSelectionAllowed(false);
        table_pan = new JScrollPane(table);
        frame.remove(op_pan);
        frame.getContentPane().add(table_pan, BorderLayout.CENTER);
        JLabel id = new JLabel("编号");
        opid = new JTextField(10);
        opid.setEditable(false);
        Calendar today = Calendar.getInstance();
        int month = today.get(Calendar.MONTH) + 1;
        int year = today.get(Calendar.YEAR);
        int day = today.get(Calendar.DATE);
        JLabel draw_date = new JLabel("领取时间");
        drawDate = new JTextField(10);
        drawDate.setEditable(false);
        JLabel message = new JLabel("当日管理员:");
        amongmanager = new JTextField(10);
        amongmanager.setEditable(false);
        JLabel curinformation = new JLabel("今日管理员:");
        JTextField todaymana = new JTextField(user);
        todaymana.setEditable(false);
        jbt_op_return_back = new JButton("返回");
        op_brow_ok = new JButton("归还");
        op_pan_brow = new JPanel();
        op_pan_brow.setLayout(new GridLayout(5, 2));
        op_pan_brow.add(id);
        op_pan_brow.add(opid);
        op_pan_brow.add(draw_date);
        op_pan_brow.add(drawDate);
        op_pan_brow.add(message);
        op_pan_brow.add(amongmanager);
        op_pan_brow.add(curinformation);
        op_pan_brow.add(todaymana);
        op_pan_brow.add(op_brow_ok);
        op_pan_brow.add(jbt_op_return_back);
        frame.getContentPane().add(op_pan_brow, BorderLayout.SOUTH);
        frame.repaint();
        frame.setVisible(true);
        jbt_op_return_back.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(op_pan_brow);
                frame.remove(table_pan);
                frame.getContentPane().add(op_pan, BorderLayout.CENTER);
                frame.repaint();
                frame.setVisible(true);

            }
        });
        table.addMouseListener(new MouseListener() {
            public void mouseClicked(java.awt.event.MouseEvent e) {
                if (table.getSelectedRow() != -1 &&
                    table.getSelectedColumn() != -1) {
                    opid.setText((String) table.getValueAt(table.getSelectedRow(),
                            0));
                    drawDate.setText("");
                    amongmanager.setText("");
                }
                if (opid.getText().trim().length() > 0) {
                    dcon = new DATAConnection();
                    String sql = " select * from MACDT where BH = '" +
                                 opid.getText().trim() + "'";
                    if (dcon.isNull(sql)) {
                        sql = "select curdate from MACDT where BH = '" +
                              opid.getText().trim() + "'";
                        Vector v = dcon.select(sql);
                        String s1 = ((Vector) v.get(0)).get(0).toString();
                        sql = "select  manager from MACDT where BH = '" +
                              opid.getText().trim() + "'";
                        v = dcon.select(sql);
                        String s2 = ((Vector) v.get(0)).get(0).toString();
                        drawDate.setText(s1.substring(0, 10));
                        amongmanager.setText(s2);
                    }
                }

            }

            public void mouseEntered(MouseEvent e) {
            }

            public void mouseExited(MouseEvent e) {
            }

            public void mousePressed(MouseEvent e) {
            }

            public void mouseReleased(MouseEvent e) {
            }

        });
        op_brow_ok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane jtp = new JOptionPane();
                if (opid.getText().trim().length() == 0) {
                    jtp.showMessageDialog(frame, "选择要操作的记录");
                } else {
                    dcon = new DATAConnection();
                    String sql1 = "update MACapital set userID='' where bh = '" +
                                  opid.getText().trim() +
                                  "'";
                    jtp.showMessageDialog(frame, dcon.update(1, sql1));
                    String sql12 = "delect from MACDT where BH ='" +
                                   opid.getText().trim() + "'";
                    jtp.showMessageDialog(frame, dcon.update(2, sql1));
                    String sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status ,MACperson.pname from  MACapital,MACContentsKinds,MACperson where ((MACapital.ckid = MACContentsKinds.ckid) and (MACapital.status ='正常' ) and (MACapital.userid  is not  null or len(MACapital.userid)>0 ) and (MACperson.pid = MACapital.userid) )";
                    model.setContent(getv(sql));
                    table.updateUI();
                    opid.setText("");
                }
            }

        });

    }

//领取
    public void draw() {
        model = new mytable();
        String sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status  from  MACapital,MACContentsKinds where ((MACapital.ckid = MACContentsKinds.ckid) and (MACapital.status ='正常' ) and (MACapital.userid is null or len(MACapital.userid)=0 ))";
        model.setTitle(gettitle(sql));
        model.setContent(getv(sql));
        table = new JTable(model);
        table.setRowSelectionAllowed(false);
        table_pan = new JScrollPane(table);
        frame.remove(op_pan);
        frame.getContentPane().add(table_pan, BorderLayout.CENTER);
        JLabel id = new JLabel("编号");
        opid = new JTextField(10);
        opid.setEditable(false);
        JLabel drawuse = new JLabel("用途");
        used = new JTextField(10);
        JLabel drawmem = new JLabel("备注");
        draw_mem = new JTextField(10);
        Calendar today = Calendar.getInstance();
        int month = today.get(Calendar.MONTH) + 1;
        int year = today.get(Calendar.YEAR);
        int day = today.get(Calendar.DATE);
        final String currentdate = String.valueOf(year) + "-" +
                                   String.valueOf(month) + "-" +
                                   String.valueOf(day);
        JLabel draw_date = new JLabel("时间");
        drawDate = new JTextField(currentdate, 10);
        drawDate.setEditable(false);
        JLabel message = new JLabel("管理员:");
        JLabel messageuser = new JLabel(user);
        op_pan_brow = new JPanel();
        op_pan_brow.setLayout(new GridLayout(4, 4, 0, 0));
        op_brow_ok = new JButton("确定");
        jbt_op_brow_back = new JButton("返回");
        jcb_op_brow = new JComboBox(getchoiceCondi("1"));
        op_pan_brow.add(id);
        op_pan_brow.add(opid);
        JLabel userid = new JLabel("领物人");
        op_pan_brow.add(userid);
        op_pan_brow.add(jcb_op_brow);
        op_pan_brow.add(drawuse);
        op_pan_brow.add(used);
        op_pan_brow.add(drawmem);
        op_pan_brow.add(draw_mem);
        op_pan_brow.add(draw_date);
        op_pan_brow.add(drawDate);
        op_pan_brow.add(message);
        op_pan_brow.add(messageuser);
        op_pan_brow.add(op_brow_ok);
        op_pan_brow.add(jbt_op_brow_back);
        frame.getContentPane().add(op_pan_brow, BorderLayout.SOUTH);
        frame.repaint();
        frame.setVisible(true);
        jbt_op_brow_back.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(op_pan_brow);
                frame.remove(table_pan);
                frame.getContentPane().add(op_pan, BorderLayout.CENTER);
                frame.repaint();
                frame.setVisible(true);

            }
        });
        table.addMouseListener(new MouseListener() {
            public void mouseClicked(java.awt.event.MouseEvent e) {
                if (table.getSelectedRow() != -1 &&
                    table.getSelectedColumn() != -1) {
                    opid.setText((String) table.getValueAt(table.getSelectedRow(),
                            0));
                }
            }

            public void mouseEntered(MouseEvent e) {
            }

            public void mouseExited(MouseEvent e) {
            }

            public void mousePressed(MouseEvent e) {
            }

            public void mouseReleased(MouseEvent e) {
            }
        });
        op_brow_ok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane jtp = new JOptionPane();
                if (opid.getText().trim().length() == 0) {
                    jtp.showMessageDialog(frame, "选择要操作的记录");
                } else {
                    dcon = new DATAConnection();
                    String sql = "select pID from MACperson where pname ='" +
                                 jcb_op_brow.getSelectedItem().toString() + "'";
                    Vector v = dcon.select(sql);
                    temp = ((Vector) v.get(0)).get(0).toString();
                    System.out.println(temp);
                    System.out.println(jcb_op_brow.getSelectedItem().toString());
                    String sql1 = "update MACapital set userID='" + temp +
                                  "' where bh = '" + opid.getText().trim() +
                                  "'";
                    jtp.showMessageDialog(frame, dcon.update(1, sql1));
                    String strused = "";
                    if (used.getText().trim().length() > 0) {
                        strused = used.getText().trim();
                    }
                    String strmem = "";
                    if (draw_mem.getText().trim().length() > 0) {
                        strmem = draw_mem.getText().trim();
                    }
                    sql =
                            "insert into MACDT(BH,direction,curdate,pid,used,mem,manager) values('";
                    sql += opid.getText().trim() + "','领取','" + currentdate +
                            "','";
                    sql += temp + "','" + strused + "','" + strmem + "','" +
                            user + "')";
                    jtp.showMessageDialog(frame, dcon.update(3, sql));
                    sql = "select MACapital.bh, MACContentsKinds.cname, MACapital.style, MACapital.price, MACapital.purdate, MACapital.status  from  MACapital,MACContentsKinds where ((MACapital.ckid = MACContentsKinds.ckid) and (MACapital.status ='正常' ) and (MACapital.userid is null or len(MACapital.userid)=0 ))";
                    model.setContent(getv(sql));
                    table.updateUI();
                    opid.setText("");
                }
            }
        });

    }

//设置选择菜单
    public void setchoice() {
        set_pan = new JPanel();
        set_pan.setSize(100, 100);
        String[] s = {"管理员", "科目", "雇员"};
        jcbset1 = new JComboBox(s);
        jcbset1.setEditable(false);
        jbtsetok = new JButton("确定");
        set_pan.add(jcbset1);
        set_pan.add(jbtsetok);
        frame.getContentPane().add(set_pan, BorderLayout.CENTER);
        frame.repaint();
        frame.setVisible(true);
        jbtsetok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (jcbset1.getSelectedItem().toString().equals("管理员")) {
                    man_modify();
                } else if (jcbset1.getSelectedItem().toString().equals("科目")) {
                    frame.remove(set_pan);
                    subchoice();
                } else {
                    frame.remove(set_pan);
                    workop();
                }
            }
        });
    }

    public void workop() {
        model = new mytable();
        String sql = "select * from MACperson";
        model.setTitle(gettitle(sql));
        model.setContent(getv(sql));
        table = new JTable(model);
        table.setRowSelectionAllowed(false);
        table_pan = new JScrollPane(table);
        frame.getContentPane().add(table_pan, BorderLayout.CENTER);
        sub_work_pan = new JPanel();
        jbt_work_insert = new JButton("增加");
        jbt_work_del = new JButton("删除");
        jbt_work_badk = new JButton("返回");
        opid = new JTextField(10);
        opid.setEditable(false);
        sub_work_pan.add(opid);
        sub_work_pan.add(jbt_work_insert);
        sub_work_pan.add(jbt_work_del);
        sub_work_pan.add(jbt_work_badk);
        frame.getContentPane().add(sub_work_pan, BorderLayout.SOUTH);
        frame.repaint();
        frame.setVisible(true);
        jbt_work_badk.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(table_pan);
                frame.remove(sub_work_pan);
                frame.getContentPane().add(set_pan, BorderLayout.CENTER);
                frame.repaint();
                frame.setVisible(true);
            }
        });
        jbt_work_insert.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                workerinsert();
            }
        });
        jbt_work_del.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane jtp = new JOptionPane();
                if (opid.getText().trim().length() == 0) {
                    jtp.showMessageDialog(frame, "选择要操作的记录");
                } else {
                    dcon = new DATAConnection();
                    String sql = "delete from MACperson where pID = '" +
                                 opid.getText().trim() + "'";
                    jtp.showMessageDialog(frame, dcon.update(2, sql));
                    String sql2 = "select * from MACperson ";
                    model.setContent(getv(sql2));
                    table.updateUI();
                }
            }
        });
        table.addMouseListener(new MouseListener() {
            public void mouseClicked(java.awt.event.MouseEvent e) {
                if (table.getSelectedRow() != -1 &&
                    table.getSelectedColumn() != -1) {
                    opid.setText((String) table.getValueAt(table.getSelectedRow(),
                            0));
                }
            }

            public void mouseEntered(MouseEvent e) {
            }

            public void mouseExited(MouseEvent e) {
            }

            public void mousePressed(MouseEvent e) {
            }

            public void mouseReleased(MouseEvent e) {
            }

        });
    }

//雇员增加
    public void workerinsert() {
        sub_work_pan_insert = new JPanel();
        jbt_work_insert_ok = new JButton("确定");
        JLabel jlb1 = new JLabel("用户编号");
        workID = new JTextField(10);
        JLabel jlb2 = new JLabel("用户姓名");
        workname = new JTextField(10);
        JLabel jlb3 = new JLabel("用户职务");
        workduty = new JTextField(10);
        JLabel jlb4 = new JLabel("备注");
        workmem = new JTextField(10);
        jbt_work_insert_back = new JButton("返回");
        sub_work_pan_insert.setLayout(new GridLayout(3, 4, 0, 0));
        sub_work_pan_insert.add(jlb1);
        sub_work_pan_insert.add(workID);
        sub_work_pan_insert.add(jlb2);
        sub_work_pan_insert.add(workname);
        sub_work_pan_insert.add(jlb3);
        sub_work_pan_insert.add(workduty);
        sub_work_pan_insert.add(jlb4);
        sub_work_pan_insert.add(workmem);
        sub_work_pan_insert.add(jbt_work_insert_ok);
        sub_work_pan_insert.add(jbt_work_insert_back);
        frame.remove(sub_work_pan);
        frame.getContentPane().add(sub_work_pan_insert, BorderLayout.SOUTH);
        frame.repaint();
        frame.setVisible(true);
        jbt_work_insert_back.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(sub_work_pan_insert);
                frame.getContentPane().add(sub_work_pan, BorderLayout.SOUTH);
                frame.repaint();
                frame.setVisible(true);
            }
        });
        jbt_work_insert_ok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane jtp = new JOptionPane();
                if (workID.getText().trim().length() == 0 ||
                    workname.getText().trim().length() == 0 ||
                    workduty.getText().trim().length() == 0) {
                    jtp.showMessageDialog(frame, "员工编号/员工名/员工职务不能为空");
                } else if (!isnum(workID.getText().trim())) {
                    jtp.showMessageDialog(frame, "员工编号应为数字");
                } else {
                    dcon = new DATAConnection();
                    String sql = "select * from MACperson where pID = '" +
                                 workID.getText().trim() + "'";
                    if (dcon.isNull(sql)) {
                        jtp.showMessageDialog(frame, "该编号已经存在");
                    } else {

                        String sql1 =
                                "insert into MACperson(pID,pname,pduty,pmem) values('" +
                                workID.getText().trim() + "','" +
                                workname.getText().trim() + "','" +
                                workduty.getText().trim() + "','" +
                                workmem.getText().trim() + "')";
                        jtp.showMessageDialog(frame, dcon.update(3, sql1));
                        String sql2 = "select * from MACperson ";
                        model.setContent(getv(sql2));
                        table.updateUI();
                    }
                }
            }
        });
    }

//管理员操作
    public void man_modify() {
        man_pan = new JPanel();
        jpmanuser = new JLabel("用户名");
        jtmanuser = new JTextField(user, 5);
        jpmanpass = new JLabel("密  码");
        jtmanpass = new JTextField(5);
        man_ok = new JButton("确定");
        man_back = new JButton("退回");
        man_pan.add(jpmanuser);
        man_pan.add(jtmanuser);
        man_pan.add(jpmanpass);
        man_pan.add(jtmanpass);
        man_pan.add(man_ok);
        man_pan.add(man_back);
        man_pan.setSize(50, 50);
        frame.remove(set_pan);
        String sql = "select * from MACusers where ( username = '" + user +
                     "')";
        model = new mytable();
        model.setTitle(gettitle(sql));
        model.setContent(getv(sql));
        table = new JTable(model);
        table_pan = new JScrollPane(table);
        frame.getContentPane().add(table_pan, BorderLayout.CENTER); //
        frame.getContentPane().add(man_pan, BorderLayout.SOUTH);
        frame.repaint();
        frame.setVisible(true);
        man_ok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (jtmanuser.getText().trim().length() == 0 ||
                    jtmanpass.getText().trim().length() == 0) {
                    JOptionPane jtp = new JOptionPane();
                    jtp.showMessageDialog(frame, "用户名和密码不能为空");
                } else {
                    String sql = "update MACusers set username = '";
                    sql += jtmanuser.getText().trim();
                    sql += "',password ='";
                    sql += jtmanpass.getText().trim();
                    sql += "' where username = '";
                    sql += user + "'";
                    m_modify(jtmanuser.getText().trim(), sql);
                }
            }
        });
        man_back.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.remove(table_pan);
                frame.remove(man_pan);
                setchoice();
            }
        });
    }

    public void m_modify(String name, String sql) {
        boolean flags = false;
        JOptionPane jtp = new JOptionPane();
        dcon = new DATAConnection();
        String sql1 = "select * from MACusers where username = '" + name + "'";
        flags = dcon.isNull(sql1);
        if (flags) {
            String sql15 = "update MACusers set password = '";
            sql15 += jtmanpass.getText().trim();
            sql15 += "' where username = '";
            sql15 += user + "'";
            jtp.showMessageDialog(frame, dcon.update(1, sql15));
        } else {
            jtp.showMessageDialog(frame, dcon.update(1, sql));

        }
        name = jtmanuser.getText().trim();
        user = name;
        String sql2 = "select * from MACusers where username = '" + name + "'";
        model.setContent(getv(sql2));
        table.updateUI();

    }

//取得表格内容
    public Vector getv(String sql) {
        Vector v = null;
        dcon = new DATAConnection();
        v = dcon.select(sql);
        return v;
    }

//取得表格标题
    public String[] gettitle(String sql) {
        dcon = new DATAConnection();
        String[] sn = dcon.getColumnname(sql);
        return sn;
    }

//关闭窗体
    public void closeall() {
        frame.setVisible(false);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

//判断字符是否是数字
    public boolean isnum(String s) {
        boolean flags = true;
        int i = 0;
        while (flags && i < s.length()) {
            flags = Character.isDigit(s.charAt(i));
            i++;
        }
        return flags;
    }
}