public void actionPerformed(final ActionEvent e) { int i = Dao.DelSalesman(ISBN.getText().trim()); if (i == 1) { JOptionPane.showMessageDialog(null, "删除成功"); Object[][] results = getFileStates(Dao.selectSalesman()); model.setDataVector(results, columnNames); table.setModel(model); } }
public SalesmanModiAndDelIFrame() { super(); setIconifiable(true); setClosable(true); setTitle("销售人员信息修改与删除"); setBounds(100, 100, 600, 420); final JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.setPreferredSize(new Dimension(400, 80)); getContentPane().add(panel, BorderLayout.NORTH); final JLabel logoLabel = new JLabel(); ImageIcon readerModiAndDelIcon = CreatecdIcon.add("readerModiAndDel.jpg"); logoLabel.setIcon(readerModiAndDelIcon); logoLabel.setBackground(Color.CYAN); logoLabel.setOpaque(true); logoLabel.setPreferredSize(new Dimension(400, 80)); panel.add(logoLabel); logoLabel.setText("销售人员信息修改logo(400*80)"); final JPanel panel_1 = new JPanel(); panel_1.setLayout(new BorderLayout()); getContentPane().add(panel_1); final JScrollPane scrollPane = new JScrollPane(); scrollPane.setPreferredSize(new Dimension(0, 100)); panel_1.add(scrollPane, BorderLayout.NORTH); final DefaultTableModel model = new DefaultTableModel(); Object[][] results = getFileStates(Dao.selectSalesman()); model.setDataVector(results, columnNames); table = new JTable(); table.setModel(model); scrollPane.setViewportView(table); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.addMouseListener(new TableListener()); final JPanel panel_2 = new JPanel(); final GridLayout gridLayout = new GridLayout(0, 4); gridLayout.setVgap(9); panel_2.setLayout(gridLayout); panel_2.setPreferredSize(new Dimension(0, 200)); panel_1.add(panel_2, BorderLayout.SOUTH); final JLabel label_1 = new JLabel(); label_1.setText(" 姓 名:"); panel_2.add(label_1); readername = new JTextField(); readername.setDocument(new MyDocument(10)); panel_2.add(readername); final JLabel label_2 = new JLabel(); label_2.setText(" 性 别:"); panel_2.add(label_2); final JPanel panel_3 = new JPanel(); final FlowLayout flowLayout_1 = new FlowLayout(); flowLayout_1.setVgap(0); panel_3.setLayout(flowLayout_1); panel_2.add(panel_3); JRadioButton1 = new JRadioButton(); JRadioButton1.setSelected(true); buttonGroup.add(JRadioButton1); panel_3.add(JRadioButton1); JRadioButton1.setText("男"); JRadioButton2 = new JRadioButton(); buttonGroup.add(JRadioButton2); panel_3.add(JRadioButton2); JRadioButton2.setText("女"); final JLabel label_3 = new JLabel(); label_3.setText(" 年 龄:"); panel_2.add(label_3); age = new JTextField(); age.setDocument(new MyDocument(2)); age.addKeyListener(new NumberListener()); panel_2.add(age); final JLabel label_5 = new JLabel(); label_5.setText(" 专 业:"); panel_2.add(label_5); zy = new JTextField(); zy.setDocument(new MyDocument(30)); panel_2.add(zy); final JLabel label = new JLabel(); label.setText(" 有效证件:"); panel_2.add(label); comboBox = new JComboBox(); comboBox.setModel(new DefaultComboBoxModel(array)); for (int i = 1; i < array.length; i++) { comboBox.setSelectedIndex(i); comboBox.setSelectedItem(array); } panel_2.add(comboBox); final JLabel label_6 = new JLabel(); label_6.setText(" 证件号码:"); panel_2.add(label_6); zjnumber = new JTextField(); zjnumber.setDocument(new MyDocument(13)); zjnumber.addKeyListener(new NumberListener()); panel_2.add(zjnumber); final JLabel label_7 = new JLabel(); label_7.setText(" 办证日期:"); panel_2.add(label_7); SimpleDateFormat myfmt = new SimpleDateFormat("yyyy-MM-dd"); bztime = new JFormattedTextField(myfmt.getDateInstance()); panel_2.add(bztime); final JLabel label_9 = new JLabel(); label_9.setText(" 最大调货量:"); panel_2.add(label_9); maxnumber = new JTextField(); maxnumber.addKeyListener(new NumberListener()); panel_2.add(maxnumber); final JLabel label_13 = new JLabel(); label_13.setText(" 证件有效日期:"); panel_2.add(label_13); date = new JFormattedTextField(myfmt.getDateInstance()); panel_2.add(date); final JLabel label_8 = new JLabel(); label_8.setText(" 电 话:"); panel_2.add(label_8); tel = new JFormattedTextField(); tel.addKeyListener(new TelListener()); tel.setDocument(new MyDocument(11)); panel_2.add(tel); final JLabel label_14 = new JLabel(); label_14.setText(" 工 资:"); panel_2.add(label_14); keepmoney = new JTextField(); keepmoney.addKeyListener(new KeepmoneyListener()); panel_2.add(keepmoney); final JLabel label_4 = new JLabel(); label_4.setText(" 销售人员编号:"); panel_2.add(label_4); ISBN = new JTextField(); ISBN.setEditable(false); ISBN.setDocument(new MyDocument(13)); panel_2.add(ISBN); final JPanel panel_4 = new JPanel(); panel_4.setMaximumSize(new Dimension(0, 0)); final FlowLayout flowLayout = new FlowLayout(); flowLayout.setVgap(0); flowLayout.setHgap(4); panel_4.setLayout(flowLayout); panel_2.add(panel_4); final JButton button = new JButton(); button.setHorizontalTextPosition(SwingConstants.CENTER); panel_4.add(button); button.setText("修改"); button.addActionListener(new ModiButtonListener(model)); final JButton buttonDel = new JButton(); panel_4.add(buttonDel); buttonDel.setText("删除"); buttonDel.addActionListener(new DelButtonListener(model)); setVisible(true); // }
public void actionPerformed(final ActionEvent e) { if (readername.getText().length() == 0) { JOptionPane.showMessageDialog(null, "销售人员姓名文本框不可为空"); return; } if (age.getText().length() == 0) { JOptionPane.showMessageDialog(null, "销售人员年龄文本框不可为空"); return; } if (zjnumber.getText().length() == 0) { JOptionPane.showMessageDialog(null, "证件号码文本框不可为空"); return; } if (keepmoney.getText().length() == 0) { JOptionPane.showMessageDialog(null, "工资文本框不可为空"); return; } if (zy.getText().length() == 0) { JOptionPane.showMessageDialog(null, "毕业文本框不可为空"); return; } if (ISBN.getText().length() == 0) { JOptionPane.showMessageDialog(null, "销售人员条形码文本框不可为空"); return; } if (ISBN.getText().length() != 13) { JOptionPane.showMessageDialog(null, "销售人员条形码文本框为13位"); return; } if (bztime.getText().length() == 0) { JOptionPane.showMessageDialog(null, "办证时间文本框不可为空"); return; } if (tel.getText().length() == 0) { JOptionPane.showMessageDialog(null, "电话号码文本框不可为空"); return; } if (tel.getText().length() > 11 || tel.getText().length() < 0) { JOptionPane.showMessageDialog(null, "电话号码位数小于11位"); return; } if (maxnumber.getText().length() == 0) { JOptionPane.showMessageDialog(null, "最大调货量文本框不可为空"); return; } if (maxnumber.getText().length() > 2 || tel.getText().length() < 0) { JOptionPane.showMessageDialog(null, "最大调货量为两位数字"); return; } String sex = "1"; if (!JRadioButton1.isSelected()) { sex = "2"; } String zj = String.valueOf(comboBox.getSelectedIndex()); System.out.println(comboBox.getSelectedIndex()); int i = Dao.UpdateSalesman( id, readername.getText().trim(), sex, age.getText().trim(), zjnumber.getText().trim(), Date.valueOf(date.getText().trim()), maxnumber.getText().trim(), tel.getText().trim(), Double.valueOf(keepmoney.getText().trim()), zj, zy.getText().trim(), Date.valueOf(bztime.getText().trim()), ISBN.getText().trim()); System.out.println(i); if (i == 1) { JOptionPane.showMessageDialog(null, "修改成功"); Object[][] results = getFileStates(Dao.selectSalesman()); model.setDataVector(results, columnNames); table.setModel(model); } }