Example #1
0
  /** Create the frame. */
  public SRT_Manager(Teacher teacher) {
    this.teacher = teacher;
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    setSize(400, 250);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JPanel panel = new JPanel();
    panel.setBounds(0, 0, 384, 145);
    contentPane.add(panel);
    panel.setLayout(null);

    final JComboBox<String> CBClass = new JComboBox<String>();
    // CBClass.addActionListener(new getClassListener());
    String class_info = teacher.getUClass();
    classinfo = class_info.split(",");
    CBClass.addItem("请选择班级");
    for (int i = 0; i < classinfo.length; i++) {
      CBClass.addItem(classinfo[i]);
    }
    // CBClass.addItem(teacher.getUClass());
    /*int count = 0;
    if(count < classinfo.size())
    {
    	CBClass.addItem(classinfo.get(count));
    	count++;
    }*/

    // CBClass.setSelectedItem("1");

    CBClass.setBounds(163, 22, 140, 26);
    panel.add(CBClass);

    JLabel lblNewLabel = new JLabel("\u73ED\u7EA7\uFF1A");
    lblNewLabel.setBounds(68, 22, 47, 26);
    panel.add(lblNewLabel);

    JLabel lblNewLabel_1 = new JLabel("\u59D3\u540D\uFF1A");
    lblNewLabel_1.setBounds(68, 82, 47, 26);
    panel.add(lblNewLabel_1);

    final JComboBox<String> CBName = new JComboBox<String>();

    System.out.println("SELECT * From ClassInfo WHERE Class = '" + getclass + "'");
    // TODO Auto-generated method stub

    // TODO Auto-generated method stub
    /*	String sql = "SELECT * From ClassInfo WHERE Class = '" + getclass + "'";
    	System.out.println(sql);
    	Statement stmt;
    	ResultSet result = null;
    	try {
    		stmt = connection().createStatement();
    		result = stmt.executeQuery(sql);
    	} catch (SQLException e1) {
    		// TODO Auto-generated catch block
    		e1.printStackTrace();
    	}
    	//System.out.println(result);

    	try {
    		while(result.next())
    		{
    			CBName.addItem(result.getString("student"));
    			System.out.println(result.getString("student"));
    		}
    	} catch (SQLException e1) {
    		// TODO Auto-generated catch block
    		e1.printStackTrace();
    	}
    */
    ItemListener itemlis =
        new ItemListener() {

          @Override
          public void itemStateChanged(ItemEvent e) {
            // TODO Auto-generated method stub
            if (e.getStateChange() == e.SELECTED) {
              getclass = (String) CBClass.getSelectedItem();
              // TODO Auto-generated method stub
              String sql = "SELECT * From ClassInfo WHERE Class = '" + getclass + "'";
              System.out.println(sql);
              Statement stmt;
              ResultSet result = null;
              try {
                stmt = connection().createStatement();
                result = stmt.executeQuery(sql);
              } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
              }
              // System.out.println(result);

              CBName.removeAllItems();
              CBName.addItem("请选择学生");
              try {

                while (result.next()) {
                  CBName.addItem(result.getString("student"));
                  System.out.println(result.getString("student"));
                }
              } catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
              }
            }
          }
        };
    CBClass.addItemListener(itemlis);
    /*int count1 = 0;
    if(count1 < studentinfo.size())
    {
    	CBClass.addItem(studentinfo.get(count1));
    	count1++;
    }*/
    CBName.setBounds(163, 82, 140, 26);
    ItemListener getstu =
        new ItemListener() {

          @Override
          public void itemStateChanged(ItemEvent e) {
            // TODO Auto-generated method stub
            if (e.getStateChange() == e.SELECTED) {
              getstudent = (String) CBName.getSelectedItem();
            }
          }
        };
    CBName.addItemListener(getstu);

    panel.add(CBName);

    JPanel panel_1 = new JPanel();
    panel_1.setBounds(0, 145, 384, 66);
    contentPane.add(panel_1);
    panel_1.setLayout(null);

    JButton yes = new JButton("\u786E\u8BA4");
    yes.setBounds(34, 10, 114, 31);
    yes.addActionListener(new yesListener());
    panel_1.add(yes);

    JButton quit = new JButton("\u9000\u51FA");
    quit.setBounds(229, 10, 132, 31);
    quit.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            // System.exit(0);
            dispose();
          }
        });
    panel_1.add(quit);
  }
  public void judge() throws ClassNotFoundException, IOException, SQLException {

    if (user.getURole().equalsIgnoreCase("student")) {
      String sql = "SELECT * From STUDENT WHERE ID = '" + user.getUID() + "'";
      System.out.println(sql);
      Statement stmt;
      ResultSet result = null;
      try {
        stmt = connection().createStatement();
        result = stmt.executeQuery(sql);
      } catch (SQLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
      // System.out.println(result);

      try {
        while (result.next()) {
          System.out.println(result.getString(4) + result.getString(2));
          student.setUName(result.getString(4));
          student.setUBirthday(result.getString(8));
          student.setUCard(result.getString(1));
          student.setUClass(result.getString(6));
          student.setUHometown(result.getString(7));
          student.setUID(result.getString(2));
          student.setURole(result.getString(3));
          student.setUSex(result.getString(6));
        }
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      SchoolRollStudents SRS = new SchoolRollStudents(student, false);
      System.out.println(student.getUName());
      SRS.setPanel();
      SRS.setVisible(true);
    } else if (user.getURole().equalsIgnoreCase("teacher")
        || user.getURole().equalsIgnoreCase("admin")) {
      String sql = "SELECT * From TEACHER where ID = '" + user.getUID() + "'";
      System.out.println(sql);
      Statement stmt;
      ResultSet result = null;
      try {
        stmt = connection().createStatement();
        result = stmt.executeQuery(sql);
      } catch (SQLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
      System.out.println(result);
      try {
        while (result.next()) {
          teacher.setUName(result.getString("Name"));
          // teacher.setUBirthday(result.getString(1));
          teacher.setUCard(result.getString("ID"));
          teacher.setUClass(result.getString("class"));
          // teacher.setUHometown(result.getString(4));
          teacher.setUID(result.getString("Num"));
          teacher.setURole(result.getString("role"));
          teacher.setUSex(result.getString("sex"));
        }

      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      SchoolRollTeachers SCT = new SchoolRollTeachers(teacher, true);
      SCT.setVisible(true);
      SCT.setPanel();
    }
  }