DeleteUser.java~5~
上传用户:liming9091
上传日期:2014-10-27
资源大小:3376k
文件大小:3k
源码类别:

Java编程

开发平台:

Java

  1. package uml_gaokai;
  2. import java.awt.*;
  3. import javax.swing.*;
  4. import com.borland.jbcl.layout.*;
  5. import java.awt.event.*;
  6. import com.borland.dx.sql.dataset.*;
  7. import java.sql.*;
  8. /**
  9.  * <p>Title: </p>
  10.  * <p>Description: </p>
  11.  * <p>Copyright: Copyright (c) 2003</p>
  12.  * <p>Company: </p>
  13.  * @author unascribed
  14.  * @version 1.0
  15.  */
  16. public class DeleteUser extends JDialog {
  17.   private JPanel panel1 = new JPanel();
  18.   private XYLayout xYLayout1 = new XYLayout();
  19.   private JLabel jLabel1 = new JLabel();
  20.   private JLabel jLabel2 = new JLabel();
  21.   private JTextField jTextField1 = new JTextField();
  22.   private JTextField jTextField2 = new JTextField();
  23.   private JButton jButton1 = new JButton();
  24.   private JButton jButton2 = new JButton();
  25.   private Database database1 = new Database();
  26.   public DeleteUser(Frame frame, String title, boolean modal) {
  27.     super(frame, title, modal);
  28.     try {
  29.       jbInit();
  30.       pack();
  31.     }
  32.     catch(Exception ex) {
  33.       ex.printStackTrace();
  34.     }
  35.   }
  36.   public DeleteUser() {
  37.     this(null, "", false);
  38.   }
  39.   private void jbInit() throws Exception {
  40.     panel1.setLayout(xYLayout1);
  41.     jLabel1.setText("用户名");
  42.     jLabel2.setText("类别");
  43.     jButton1.setText("确定");
  44.     jButton1.addActionListener(new java.awt.event.ActionListener() {
  45.       public void actionPerformed(ActionEvent e) {
  46.         jButton1_actionPerformed(e);
  47.       }
  48.     });
  49.     jButton2.setText("取消");
  50.     jButton2.addActionListener(new java.awt.event.ActionListener() {
  51.       public void actionPerformed(ActionEvent e) {
  52.         jButton2_actionPerformed(e);
  53.       }
  54.     });
  55.     database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:gaokaiSQL", "sa", "", false, "sun.jdbc.odbc.JdbcOdbcDriver"));
  56.     getContentPane().add(panel1);
  57.     panel1.add(jLabel1,  new XYConstraints(58, 44, 78, 25));
  58.     panel1.add(jLabel2,  new XYConstraints(59, 92, 84, 27));
  59.     panel1.add(jTextField1,  new XYConstraints(153, 44, 109, 27));
  60.     panel1.add(jTextField2,  new XYConstraints(153, 93, 112, 29));
  61.     panel1.add(jButton1,  new XYConstraints(151, 202, 82, 28));
  62.     panel1.add(jButton2,       new XYConstraints(256, 203, 83, 27));
  63.   }
  64.   public void cancel(){
  65.     dispose() ;
  66.   }
  67.   void jButton2_actionPerformed(ActionEvent e) {
  68.     cancel();
  69.   }
  70.   void jButton1_actionPerformed(ActionEvent e) {
  71.     String userName = String.valueOf(jTextField1.getText()) ;
  72.     String userAuthority = String.valueOf(jTextField2.getText()) ;
  73.     int response = JOptionPane.showConfirmDialog(null,"请问是否删除该用户","",JOptionPane.YES_NO_CANCEL_OPTION) ;
  74.     if(response == 0){
  75.       try{
  76.       Statement sql = database1.createStatement() ;
  77.       sql.executeUpdate("DELETE FROM [UML_CS].[dbo].[user] WHERE userName = '"+userName+"' and userAuthority = '"+userAuthority+"'") ;
  78.       }
  79.       catch(SQLException www){www.printStackTrace();}
  80.     }
  81.   }
  82. }