package student; import javax.swing.*; import java.awt.*; import com.borland.dx.sql.dataset.*; import com.borland.dx.dataset.*; import java.awt.event.*; import com.borland.dbswing.*; public class Frame2 extends JFrame { JLabel jLabel8 = new JLabel(); JTextField jTextField6 = new JTextField(); JLabel jLabel4 = new JLabel(); JButton jButton2 = new JButton(); JLabel jLabel1 = new JLabel(); JTextField jTextField7 = new JTextField(); JLabel jLabel3 = new JLabel(); JTextField jTextField3 = new JTextField(); JLabel jLabel2 = new JLabel(); JButton jButton1 = new JButton(); JTextField jTextField8 = new JTextField(); JTextField jTextField5 = new JTextField(); JLabel jLabel9 = new JLabel(); JLabel jLabel11 = new JLabel(); JLabel jLabel7 = new JLabel(); JPanel jPanel1 = new JPanel(); JTextField jTextField2 = new JTextField(); JComboBox jComboBox2 = new JComboBox(); JLabel jLabel6 = new JLabel(); JComboBox jComboBox1 = new JComboBox(); JTextField jTextField4 = new JTextField(); JLabel jLabel10 = new JLabel(); JLabel jLabel5 = new JLabel(); JComboBox jComboBox3 = new JComboBox(); JComboBox jComboBox4 = new JComboBox(); String Class; Database database1 = new Database(); QueryDataSet queryDataSet1 = new QueryDataSet(); ParameterRow parameterRow1 = new ParameterRow(); Column column1 = new Column(); QueryDataSet queryDataSet2 = new QueryDataSet(); String mark; QueryDataSet queryDataSet3 = new QueryDataSet(); Column column2 = new Column(); public Frame2(String Class,String mark) { try { this.mark=mark; this.Class=Class; jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } void jbInit() throws Exception { jPanel1.setLayout(null); jPanel1.setToolTipText(""); jPanel1.setBounds(new Rectangle(0, 0, 539, 343)); jPanel1.setRequestFocusEnabled(true); jPanel1.setPreferredSize(new Dimension(10, 10)); jPanel1.setOpaque(true); jPanel1.setMinimumSize(new Dimension(1, 1)); jPanel1.setDebugGraphicsOptions(0); jPanel1.setAlignmentY((float) 0.5); jLabel7.setBounds(new Rectangle(4, 130, 74, 26)); jLabel7.setText("个人电话"); jLabel7.setFont(new java.awt.Font("Dialog", 0, 15)); jLabel11.setBounds(new Rectangle(6, 15, 47, 19)); jLabel11.setText("学号"); jLabel11.setFont(new java.awt.Font("Dialog", 0, 15)); jLabel9.setBounds(new Rectangle(4, 212, 73, 26)); jLabel9.setText("家庭住址"); jLabel9.setFont(new java.awt.Font("Dialog", 0, 15)); jTextField5.setBounds(new Rectangle(83, 130, 105, 26)); jTextField5.setText(""); jTextField5.setFont(new java.awt.Font("Dialog", 0, 15)); jTextField8.setBounds(new Rectangle(278, 173, 94, 26)); jTextField8.setText(""); jTextField8.setFont(new java.awt.Font("Dialog", 0, 15)); jButton1.setText("保存"); jButton1.addActionListener(new Frame2_jButton1_actionAdapter(this)); jButton1.setFont(new java.awt.Font("Dialog", 0, 15)); jButton1.setBounds(new Rectangle(72, 272, 107, 27)); jLabel2.setBounds(new Rectangle(8, 51, 74, 26)); jLabel2.setText("性 别"); jLabel2.setFont(new java.awt.Font("Dialog", 0, 15)); jTextField3.setBounds(new Rectangle(83, 87, 105, 26)); jTextField3.setText(""); jTextField3.setMaximumSize(new Dimension(2147483647, 2147483647)); jTextField3.setFont(new java.awt.Font("Dialog", 0, 15)); jLabel3.setBounds(new Rectangle(3, 168, 73, 26)); jLabel3.setText("身份证号"); jLabel3.setFont(new java.awt.Font("Dialog", 0, 15)); jTextField7.setBounds(new Rectangle(83, 215, 304, 26)); jTextField7.setText(""); jTextField7.setFont(new java.awt.Font("Dialog", 0, 15)); jLabel1.setBounds(new Rectangle(208, 12, 62, 26)); jLabel1.setText("姓 名"); jLabel1.setFont(new java.awt.Font("Dialog", 0, 15)); jButton2.setText("退出"); jButton2.setFont(new java.awt.Font("Dialog", 0, 15)); jButton2.setBounds(new Rectangle(236, 271, 123, 30)); jLabel4.setBounds(new Rectangle(4, 89, 72, 26)); jLabel4.setText("出生日期"); jLabel4.setFont(new java.awt.Font("Dialog", 0, 15)); jTextField6.setBounds(new Rectangle(278, 131, 94, 26)); jTextField6.setText(""); jTextField6.setFont(new java.awt.Font("Dialog", 0, 15)); jLabel8.setBounds(new Rectangle(215, 131, 75, 26)); jLabel8.setText("家庭电话"); jLabel8.setFont(new java.awt.Font("Dialog", 0, 15)); this.getContentPane().setLayout(null); jTextField2.setFont(new java.awt.Font("Dialog", 0, 15)); jTextField2.setText(""); jTextField2.setBounds(new Rectangle(83, 173, 106, 26)); jComboBox2.setFont(new java.awt.Font("Dialog", 0, 15)); jComboBox2.setBounds(new Rectangle(278, 90, 94, 26)); jLabel6.setFont(new java.awt.Font("Dialog", 0, 15)); jLabel6.setText("籍贯"); jLabel6.setBounds(new Rectangle(215, 48, 44, 26)); jComboBox1.setFont(new java.awt.Font("Dialog", 0, 15)); jComboBox1.setBounds(new Rectangle(83, 51, 105, 26)); jTextField4.setFont(new java.awt.Font("Dialog", 0, 15)); jTextField4.setText(""); jTextField4.setBounds(new Rectangle(278, 48, 94, 26)); jLabel10.setFont(new java.awt.Font("Dialog", 0, 15)); jLabel10.setText("家庭邮编"); jLabel10.setBounds(new Rectangle(215, 173, 83, 26)); jLabel5.setFont(new java.awt.Font("Dialog", 0, 15)); jLabel5.setText("政治面貌"); jLabel5.setBounds(new Rectangle(215, 88, 101, 26)); jComboBox3.setBounds(new Rectangle(81, 9, 105, 26)); jComboBox4.setBounds(new Rectangle(278, 15, 94, 26)); database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:studentmanage", "", "", false, "sun.jdbc.odbc.JdbcOdbcDriver")); column1.setColumnName("班级"); column1.setDataType(com.borland.dx.dataset.Variant.STRING); column1.setServerColumnName("NewColumn1"); column1.setSqlType(0); queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select * from student where 班级=:班级", parameterRow1, true, Load.ALL)); queryDataSet2.setAccumulateResults(false); queryDataSet2.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select * from stumessage,student where stumessage.学号=student.学号 and " + "student.班级=:班级\n", parameterRow1, true, Load.ALL)); queryDataSet3.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select * from stumessage where 学号=:学号", parameterRow1, true, Load.ALL)); column2.setColumnName("学号"); column2.setDataType(com.borland.dx.dataset.Variant.STRING); column2.setServerColumnName("NewColumn1"); column2.setSqlType(0); jPanel1.add(jLabel4, null); jPanel1.add(jTextField3, null); jPanel1.add(jLabel5, null); jPanel1.add(jComboBox2, null); jPanel1.add(jTextField6, null); jPanel1.add(jLabel8, null); jPanel1.add(jTextField5, null); jPanel1.add(jLabel7, null); jPanel1.add(jLabel3, null); jPanel1.add(jTextField2, null); jPanel1.add(jTextField8, null); jPanel1.add(jLabel10, null); jPanel1.add(jTextField7, null); jPanel1.add(jLabel9, null); jPanel1.add(jLabel6, null); jPanel1.add(jTextField4, null); jPanel1.add(jButton1, null); jPanel1.add(jButton2, null); jPanel1.add(jComboBox1, null); jPanel1.add(jLabel2, null); jPanel1.add(jLabel1, null); jPanel1.add(jLabel11, null); jPanel1.add(jComboBox4, null); jPanel1.add(jComboBox3, null); this.getContentPane().add(jPanel1, null); jComboBox2.addItem("中共党员"); jComboBox2.addItem("中青团员"); jComboBox2.addItem("群众"); jComboBox1.addItem("男"); jComboBox1.addItem("女"); parameterRow1.setColumns(new Column[] {column1, column2}); parameterRow1.setString("班级",Class); if(mark=="修改"){ queryDataSet2.executeQuery(); int i=queryDataSet2.rowCount(); for(int a=0;a jComboBox3.addItem(String.valueOf(queryDataSet2.getString("学号"))); jComboBox4.addItem(String.valueOf(queryDataSet2.getString("姓名"))); queryDataSet2.next(); }} jComboBox3.addActionListener(new Frame2_jComboBox3_actionAdapter(this)); jComboBox4.addActionListener(new Frame2_jComboBox4_actionAdapter(this)); queryDataSet3.close(); parameterRow1.setString("学号",String.valueOf(jComboBox3.getSelectedItem())); queryDataSet3.executeQuery(); jComboBox1.setSelectedItem(String.valueOf(queryDataSet3.getString("性别"))); jTextField4.setText(String.valueOf(queryDataSet3.getString("籍贯"))); jTextField2.setText(queryDataSet3.getString("身份证号")); String date=String.valueOf(queryDataSet3.getTimestamp("出生日期")).substring(0,10); jTextField3.setText(date); jComboBox2.setSelectedItem(queryDataSet3.getString("政治面貌")); jTextField5.setText(queryDataSet3.getString("个人电话")); jTextField6.setText(queryDataSet3.getString("家庭电话")); jTextField8.setText(queryDataSet3.getString("家庭邮编")); jTextField7.setText(queryDataSet3.getString("家庭住址")); } void jComboBox3_actionPerformed(ActionEvent e) { queryDataSet3.close(); jComboBox4.setSelectedIndex(jComboBox3.getSelectedIndex()); parameterRow1.setString("学号",String.valueOf(jComboBox3.getSelectedItem())); queryDataSet3.executeQuery(); jComboBox1.setSelectedItem(String.valueOf(queryDataSet3.getString("性别"))); jTextField4.setText(String.valueOf(queryDataSet3.getString("籍贯"))); jTextField2.setText(queryDataSet3.getString("身份证号")); String date=String.valueOf(queryDataSet3.getTimestamp("出生日期")).substring(0,10); jTextField3.setText(date); jComboBox2.setSelectedItem(queryDataSet3.getString("政治面貌")); jTextField5.setText(queryDataSet3.getString("个人电话")); jTextField6.setText(queryDataSet3.getString("家庭电话")); jTextField8.setText(queryDataSet3.getString("家庭邮编")); jTextField7.setText(queryDataSet3.getString("家庭住址")); } void jComboBox4_actionPerformed(ActionEvent e) { queryDataSet3.close(); jComboBox3.setSelectedIndex(jComboBox4.getSelectedIndex()); parameterRow1.setString("学号",String.valueOf(jComboBox3.getSelectedItem())); queryDataSet3.executeQuery(); jComboBox1.setSelectedItem(String.valueOf(queryDataSet3.getString("性别"))); jTextField4.setText(String.valueOf(queryDataSet3.getString("籍贯"))); jTextField2.setText(queryDataSet3.getString("身份证号")); String date=String.valueOf(queryDataSet3.getTimestamp("出生日期")).substring(0,10); jTextField3.setText(date); jComboBox2.setSelectedItem(queryDataSet3.getString("政治面貌")); jTextField5.setText(queryDataSet3.getString("个人电话")); jTextField6.setText(queryDataSet3.getString("家庭电话")); jTextField8.setText(queryDataSet3.getString("家庭邮编")); jTextField7.setText(queryDataSet3.getString("家庭住址")); } void jButton1_actionPerformed(ActionEvent e) { /* String sql="delete from stumessage where 学号='"+jComboBox3.getSelectedItem()+"'"; database1.executeStatement(sql); if(!(jTextField3.getText().trim().equals(""))){ String sql1="insert into stumessage values('"+jComboBox3.getSelectedItem() +"','"+jComboBox4.getSelectedItem()+"','"+jComboBox1.getSelectedItem() +"','"+jTextField2.getText().trim()+"',"+jTextField3.getText().trim() +",'"+jComboBox2.getSelectedItem()+"','"+jTextField4.getText().trim() +"','"+jTextField5.getText().trim()+"','"+jTextField6.getText().trim() +"','"+jTextField7.getText().trim()+"','"+jTextField8.getText().trim() +"')"; database1.executeStatement(sql1); }else{ String sql1="insert into stumessage (学号,姓名,性别,身份证号,政治面貌,籍贯,个人电话,家庭电话,家庭住址,家庭邮编) values('"+jComboBox3.getSelectedItem() +"','"+jComboBox4.getSelectedItem()+"','"+jComboBox1.getSelectedItem() +"','"+jTextField2.getText().trim()+"',"+"'"+jComboBox2.getSelectedItem()+"','"+jTextField4.getText().trim() +"','"+jTextField5.getText().trim()+"','"+jTextField6.getText().trim() +"','"+jTextField7.getText().trim()+"','"+jTextField8.getText().trim() +"')"; database1.executeStatement(sql1); }*/ } } class Frame2_jComboBox3_actionAdapter implements java.awt.event.ActionListener { Frame2 adaptee; Frame2_jComboBox3_actionAdapter(Frame2 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jComboBox3_actionPerformed(e); } } class Frame2_jComboBox4_actionAdapter implements java.awt.event.ActionListener { Frame2 adaptee; Frame2_jComboBox4_actionAdapter(Frame2 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jComboBox4_actionPerformed(e); } } class Frame2_jButton1_actionAdapter implements java.awt.event.ActionListener { Frame2 adaptee; Frame2_jButton1_actionAdapter(Frame2 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); } }