码迷,mamicode.com
首页 > 其他好文 > 详细

学生学籍管理系统_管理员登陆对学生的信息进行操作

时间:2016-07-21 13:03:26      阅读:411      评论:0      收藏:0      [点我收藏+]

标签:

MInterface.java

package studentManage;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/*
 * 管理员
 * 操作界面接口类,可以直接扩展、调用。
 */

public class MInterface extends JFrame implements ActionListener {
	static JMenuBar jMenuBar = new JMenuBar();// 菜单条
	static JMenu jMenuFile = new JMenu("文件");// 菜单项
	static JMenu jMenuExit = new JMenu("退出");	
	static JMenuItem jMenuItem2= new JMenuItem("信息查询");
	static JMenuItem jMenuItem3 = new JMenuItem("学生注册");	
	static JLabel label3 = new JLabel("请选择操作项");
	static JLabel label4 = new JLabel("学籍管理系统");	
	static JButton button2 = new JButton("信息查询");
	static JButton button3 = new JButton("学生注册");
	
	public MInterface() {
		this.setTitle("学籍管理系统");
		this.setLayout(null);
		this.setSize(400, 400);
		label3.setBounds(158, 92, 98, 33);
		label3.setFont(new Font("Dialog", Font.PLAIN, 15));
		label4.setFont(new Font("Dialog", Font.BOLD, 20));		
		label4.setBounds(157, 37, 280, 40);
		button2.setBounds(74, 136, 97, 33);
		button3.setBounds(226, 136, 97, 33);		
		this.add(button2);
		this.add(button3);		
		this.add(label3);
		this.add(label4);
		setJMenuBar(jMenuBar);
		// ”文件“菜单项中加入子菜单
		jMenuFile.add(jMenuItem2);
		jMenuFile.add(jMenuItem3);		
		jMenuBar.add(jMenuFile);// 将菜单项加入菜单条
		jMenuBar.add(jMenuExit);
		button2.addActionListener(this);// 本窗口向按钮事件源注册
		button3.addActionListener(this);
		// 本窗口菜单子项注册
		jMenuItem2.addActionListener(this);
		jMenuItem3.addActionListener(this);		
		jMenuExit.addActionListener(this);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}

	public static void main(String[] args) {
		MInterface a = new MInterface();
	}

	
	public void actionPerformed(ActionEvent e) // 按钮事件的处理
	{
		if (e.getSource() == jMenuExit) {
			System.exit(0);
		} else if (e.getSource() == jMenuItem2 || e.getSource() == button2) {
			//对学生的信息进行查询
			try {
				MCx a = new MCx();
			} catch (Exception ee) {
			}
		} else if (e.getSource() == jMenuItem3 || e.getSource() == button3) {
			//注册学生
			try {
				Zhuce a = new Zhuce();
			} catch (Exception ed) {
			}
		} 
	}
	
	

}

MCx.java

package studentManage;

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class MCx extends JFrame implements ActionListener {
	static MCx s;
	static JLabel label1 = new JLabel("学号:");
	static JTextField textField1 = new JTextField("");
	static JLabel label2 = new JLabel("姓名:");
	static JTextField textField2 = new JTextField("");
	static JLabel label3 = new JLabel("班级:");
	static JTextField textField3= new JTextField("");
	static JLabel label4 = new JLabel("专业:");
	static JTextField textField4 = new JTextField("");
	static JLabel label5 = new JLabel("院系:");
	static JTextField textField5 = new JTextField("");
	static JLabel label6 = new JLabel("性别");
	static JTextField textField6 = new JTextField("");
	static JLabel label7 = new JLabel("年级:");
	static JTextField textField7 = new JTextField("");
	static JLabel label8 = new JLabel("生日");
	static JTextField textField8 = new JTextField("");
	static JLabel label9 = new JLabel("电话:");
	static JTextField textField9 = new JTextField("");
	static JLabel label10 = new JLabel("QQ:");
	static JTextField textField10 = new JTextField("");
	static JLabel label11 = new JLabel("状态:");
	static JTextField textField11 = new JTextField("");
	static JLabel label12 = new JLabel("密码:");
	static JTextField textField12 = new JTextField("");
	
	static JButton button3 = new JButton("按学号查询");
	static JButton button4 = new JButton("修改");
	static JButton button5 = new JButton("删除");
	static JButton button6 = new JButton("按姓名查询");

	//初始化界面	
	public MCx() throws Exception {
		this.setTitle("查询学生信息");
		this.setLayout(null);
		this.setSize(600, 600);
		
		label1.setBounds(30, 11, 50, 30);	//学号	
		textField1.setBounds(60, 16, 70, 20);
		
		label2.setBounds(160, 11, 50, 30);//姓名
		textField2.setBounds(190, 16, 70, 20);
		
		label3.setBounds(290, 11, 50, 30);//班级
		textField3.setBounds(320, 16, 70, 20);
		//===========
		
		label4.setBounds(30, 61, 50, 30);//专业
		textField4.setBounds(60, 66, 70, 20);
		
		label5.setBounds(160, 61, 50, 30);//系别
		textField5.setBounds(190, 66, 70, 20);
		
		label6.setBounds(290, 61,50, 30);//性别		
		textField6.setBounds(320, 66, 70, 20);
		
		//===========
		
		label7.setBounds(30, 111, 50, 30);//年级	
		textField7.setBounds(60, 116, 70, 20);	
		
		label8.setBounds(140, 111, 50, 30);//出生日期		
		textField8.setBounds(190, 116, 70, 20);
		
		label9.setBounds(290, 111, 50, 30);//电话
		textField9.setBounds(320, 116, 70, 20);
		
		//=========
		
		label10.setBounds(30, 161, 50, 30);//QQ
		textField10.setBounds(60,166,70,20 );
		
		label11.setBounds(160, 161, 50, 30);//状态
		textField11.setBounds(190,166, 70, 20);
		
		label12.setBounds(290, 161, 51, 33);//密码
		textField12.setBounds(320,166, 70, 22);
		
				
		button6.setBounds(60, 241, 100, 33);
		button3.setBounds(180, 241, 100, 33);
		
		button4.setBounds(60, 300, 100, 33);
		button5.setBounds(180, 300, 100, 33);
		
		
		button3.addActionListener(this);
		button4.addActionListener(this);
		button5.addActionListener(this);
		button6.addActionListener(this);
		
		this.add(label1);
		this.add(label2);
		this.add(label3);
		this.add(label4);
		this.add(label5);
		this.add(label6);
		this.add(label7);
		this.add(label8);
		this.add(label9);
		this.add(label10);
		this.add(label11);
		this.add(label12);
		
		this.add(textField1);
		this.add(textField2);
		this.add(textField3);
		this.add(textField4);		
		this.add(textField5);
		this.add(textField6);
		this.add(textField7);
		this.add(textField8);
		this.add(textField9);
		this.add(textField10);
		this.add(textField11);
		this.add(textField12);		
		
		this.add(button3);
		this.add(button4);
		this.add(button5);
		this.add(button6);
		
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.setVisible(true);

	}

	public static void main(String[] args) throws Exception {
		MCx a = new MCx();
		a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public void actionPerformed(ActionEvent e) {
		
		if (e.getSource() == button6) {
			try {

				Class.forName("com.mysql.jdbc.Driver");
			} catch (ClassNotFoundException ce) {
				JOptionPane.showMessageDialog(s, ce.getMessage());
			}
			try {
				Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stu","root","111");
				Statement stmt = con.createStatement();
				
				ResultSet rs = stmt.executeQuery("select * from infor where name='"
								+ textField2.getText() + "'");
				if (textField2.getText().trim().equals("")) {
					JOptionPane.showMessageDialog(this, "姓名不可为空!");
				}
				else if (rs.next()) {
					textField1.setText(rs.getString("stuId"));
					textField2.setText(rs.getString("name"));
					textField3.setText(rs.getString("class"));
					textField4.setText(rs.getString("profess"));
					textField5.setText(rs.getString("depart"));
					textField6.setText(rs.getString("sex"));
					textField7.setText(rs.getString("grade"));
					textField8.setText(rs.getString("bir"));
					textField9.setText(rs.getString("phone"));
					textField10.setText(rs.getString("QQ"));
					textField11.setText(rs.getString("state"));
					textField12.setText(rs.getString("password"));
				
				} else {
					JOptionPane.showMessageDialog(this, "无此记录!!!");
				}
			}
			catch (SQLException se) {
				JOptionPane.showMessageDialog(s, se.getMessage());
			}
		}
		
		
		
		if (e.getSource() == button3) {
			try {

				Class.forName("com.mysql.jdbc.Driver");
			} catch (ClassNotFoundException ce) {
				JOptionPane.showMessageDialog(s, ce.getMessage());
			}
			try {
				Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stu","root","111");
				Statement stmt = con.createStatement();
				
				ResultSet rs = stmt.executeQuery("select * from infor where stuId='"
								+ textField1.getText() + "'");
				if (textField1.getText().trim().equals("")) {
					JOptionPane.showMessageDialog(this, "学号不可为空!");
				}
				else if (rs.next()) {
					textField1.setText(rs.getString("stuId"));
					textField2.setText(rs.getString("name"));
					textField3.setText(rs.getString("class"));
					textField4.setText(rs.getString("profess"));
					textField5.setText(rs.getString("depart"));
					textField6.setText(rs.getString("sex"));
					textField7.setText(rs.getString("grade"));
					textField8.setText(rs.getString("bir"));
					textField9.setText(rs.getString("phone"));
					textField10.setText(rs.getString("QQ"));
					textField11.setText(rs.getString("state"));
					textField12.setText(rs.getString("password"));
				
				} else {
					JOptionPane.showMessageDialog(this, "无此记录!!!");
				}
			}
			catch (SQLException se) {
				JOptionPane.showMessageDialog(s, se.getMessage());
			}
		}
		
		//修改表信息
		if(e.getSource()==button4)
	    {
				try{
		
						Class.forName("com.mysql.jdbc.Driver");
						}
				catch (ClassNotFoundException ce)
					{
						JOptionPane.showMessageDialog(s,ce.getMessage());
					}
				try
				{
					Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stu","root","111");
				
					Statement stmt = con.createStatement();
				
				
	     ResultSet rs=stmt.executeQuery("select * from infor where stuId='"+textField1.getText()+"'");
	                if(textField1.getText().trim().equals(""))
	                {
	                    JOptionPane.showMessageDialog(this,"学号不可为空!");
	                }else if(rs.next())
	               {             
	                	 try{
	                		 
	                	stmt.execute("update infor set name='"+
	               	          textField2.getText()+"',class='"+textField3.getText()+"',profess='"+
	               	                 textField4.getText()+"',depart='"+textField5.getText()+"',sex='"+
	               	                 textField6.getText()+"',grade='"+textField7.getText()+"',bir='"+
	               	                 textField8.getText()+ "',phone='"+textField9.getText()+"',QQ='"+textField10.getText()+
	               	                 "',state='"+textField11.getText()+"',password='"+textField12.getText()
	               	              +"'where stuId='"+textField1.getText

	               	           ()+"'");  
	               	           
	                	stmt.execute("insert into operate(stuId,operate)values("+textField1.getText()+",'修改操作')");
	                				JOptionPane.showMessageDialog(null,"修改成功并把此次操作记录存入数据库");                 	 
	                	 }               	                
	               	                 	//stmt.executeQuery(updateSql);}
	               	             // stmt.executeUpdate(updateSql);}
	               	                 	catch(SQLException se)
	               	                 	{
	               	                 	//JOptionPane.showMessageDialog(null,"请输入正确的信息");
	               	                 	JOptionPane.showMessageDialog(s,se.getMessage());               	                 		
	               	                 	}      	                 
	                	               	
	               	}   	
	                     }
	      	catch(SQLException se)
	        {
	           JOptionPane.showMessageDialog(s,se.getMessage());
	          }
	    }
		
		if (e.getSource() == button5) {
			try {

				Class.forName("com.mysql.jdbc.Driver");
			} catch (ClassNotFoundException ce) {
				JOptionPane.showMessageDialog(s, ce.getMessage());
			}
			try {
				Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stu","root","111");
				Statement stmt = con.createStatement();
				ResultSet rs = stmt
						.executeQuery("select * from infor where stuId='"
								+ textField1.getText() + "'");
				if (textField1.getText().trim().equals("")) {
					JOptionPane.showMessageDialog(this, "学号不可为空!");
				}

				else if (rs.next()) {
					JOptionPane.showConfirmDialog(null,
							"确定要删除该信息嘛?\n删除的信息将不能恢复,继续?", "删除 确定",
							JOptionPane.OK_CANCEL_OPTION);// ,JOption.QUESTION_MESSAGE)==0;
					stmt.execute("delete  from infor where  stuId='"
							+ textField1.getText() + "'");
					stmt.execute("insert into operate(stuId,operate)values("+textField1.getText()+",'删除操作')");
					JOptionPane.showMessageDialog(null, "删除信息成功并把此次操作记录存入数据库!");
					this.dispose();
				} else
					JOptionPane.showMessageDialog(null, "无此学号对应信息", "警告",
							JOptionPane.WARNING_MESSAGE);
			} catch (Exception ed) {
				JOptionPane.showMessageDialog(s, ed.getMessage());
			}
		}		
	}
}

Zhuce.java

package studentManage;

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class Zhuce extends JFrame implements ActionListener {
	static Zhuce s;
	static JLabel label1 = new JLabel("学号:");
	static JTextField textField1 = new JTextField("");
	static JLabel label2 = new JLabel("姓名:");
	static JTextField textField2 = new JTextField("");
	static JLabel label3 = new JLabel("班级:");
	static JTextField textField3= new JTextField("");
	static JLabel label4 = new JLabel("专业:");
	static JTextField textField4 = new JTextField("");
	
	static JLabel label5 = new JLabel("院系:");
	static JTextField textField5 = new JTextField("");
	
	//制作下拉框
	static JComboBox<String> ck=new JComboBox<String>();
	//ck.addItem("计算机");
	
	
	
	
	static JLabel label6 = new JLabel("性别");
	static JTextField textField6 = new JTextField("");
	static JLabel label7 = new JLabel("年级:");
	static JTextField textField7 = new JTextField("");
	static JLabel label8 = new JLabel("生日");
	static JTextField textField8 = new JTextField("");
	static JLabel label9 = new JLabel("电话:");
	static JTextField textField9 = new JTextField("");
	static JLabel label10 = new JLabel("QQ:");
	static JTextField textField10 = new JTextField("");
	static JLabel label11 = new JLabel("状态:");
	static JTextField textField11 = new JTextField("");
	static JLabel label12 = new JLabel("密码:");
	static JTextField textField12 = new JTextField("");
	
	
	static JButton button1 = new JButton("注册");

	public Zhuce() {
		this.setTitle("用户注册");
		this.setLayout(null);
		
        this.setSize(600, 600);
		
		label1.setBounds(30, 11, 50, 30);	//学号	
		textField1.setBounds(60, 16, 70, 20);
		
		label2.setBounds(160, 11, 50, 30);//姓名
		textField2.setBounds(190, 16, 70, 20);
		
		label3.setBounds(290, 11, 50, 30);//班级
		textField3.setBounds(320, 16, 70, 20);
		//===========
		
		label4.setBounds(30, 61, 50, 30);//专业
		//textField4.setBounds(60, 66, 70, 20);
				
		ck.addItem("英语");
		ck.addItem("日语");		
		ck.addItem("体育");
		ck.addItem("声乐");
		
		
		ck.setBounds(60, 66, 70, 20);
		
		label5.setBounds(160, 61, 50, 30);//系别
		textField5.setBounds(190, 66, 70, 20);
		
		label6.setBounds(290, 61,50, 30);//性别		
		textField6.setBounds(320, 66, 70, 20);
		
		//===========
		
		label7.setBounds(30, 111, 50, 30);//年级	
		textField7.setBounds(60, 116, 70, 20);	
		
		label8.setBounds(160, 111, 50, 30);//生日	
		textField8.setBounds(190, 116, 70, 20);
		
		label9.setBounds(290, 111, 50, 30);//电话
		textField9.setBounds(320, 116, 70, 20);
		
		//=========
		
		label10.setBounds(30, 161, 50, 30);//QQ
		textField10.setBounds(60,166,70,20 );
		
		label11.setBounds(160, 161, 50, 30);//状态
		textField11.setBounds(190,166, 70, 20);
		
		label12.setBounds(290, 161, 51, 33);//密码
		textField12.setBounds(320,166, 70, 22);
		
		button1.setBounds(250, 241, 80, 33);
		
		this.add(label1);
		this.add(label2);
		this.add(label3);
		this.add(label4);
		this.add(label5);
		this.add(label6);
		this.add(label7);
		this.add(label8);
		this.add(label9);
		this.add(label10);
		this.add(label11);
		this.add(label12);
		
		this.add(textField1);
		this.add(textField2);
		this.add(textField3);
		//this.add(textField4);
		this.add(ck);
		
		this.add(textField5);
		this.add(textField6);
		this.add(textField7);
		this.add(textField8);
		this.add(textField9);
		this.add(textField10);
		this.add(textField11);
		this.add(textField12);
		
		this.add(button1);

		button1.addActionListener(this);
		
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.setVisible(true);
	}

	public static void main(String[] args) throws Exception {
		Zhuce a = new Zhuce();
		a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	}

	public void actionPerformed(ActionEvent e)//事件处理程序
   {    if (e.getSource() == button1) 
    {
    	try{	
					//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    			Class.forName("com.mysql.jdbc.Driver");
			}
			catch (ClassNotFoundException ce)
				{
					JOptionPane.showMessageDialog(s,ce.getMessage());
				}
			try
			{
			Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stu","root","111");
			Statement stmt = con.createStatement();
     ResultSet rs=stmt.executeQuery("select * from infor where stuId='"+textField1.getText()+"'");
         if(rs.next())
         {
         	JOptionPane.showMessageDialog(null,"此用户已经被注册");
         	}
         	else
         	{
         		stmt.execute("insert into infor (stuId,name,class,profess,depart,sex,grade,bir,phone,QQ,state,password) values ('"+
         		       textField1.getText()+"','"+textField2.getText()+"','" +textField3.getText()+"','" +ck.getSelectedIndex()+"','"
         		       +textField5.getText()+"','"+textField6.getText()+"','"+textField7.getText()+"','"
         		       +textField8.getText()+"','"+textField9.getText()+"','"+textField10.getText()+"','"
         		       +textField11.getText()+"','"+textField12.getText()  		                          		  
		               		 +"')");
    	    	JOptionPane.showMessageDialog(null,"添加用户成功");
           }          
  }
  catch (SQLException se)
			{
				JOptionPane.showMessageDialog(s,se.getMessage());
			}
    	}
   }
	
	
	
}

管理员的相关功能代码

学生学籍管理系统_管理员登陆对学生的信息进行操作

标签:

原文地址:http://blog.csdn.net/hoho_12/article/details/51980930

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!