学生信息管理系统代码
c语言学生管理系统代码
C语言学生管理系统代码
简介
学生管理系统是一个用于管理学生信息的简单程序,它可以实现添加学生信息、显示学生信息、修改学生信息和删除学生信息等功能。
通过这个系统,学校或机构可以更方便地管理和维护学生的相关数据。
功能
1.添加学生信息:通过输入学生的姓名、学号、年龄和性别等信息,将
学生信息存储在系统中。
每个学生信息包括学号、姓名、年龄和性别等关键信息。
2.显示学生信息:可以显示系统中所有学生的信息,包括学号、姓名、
年龄和性别。
3.修改学生信息:通过输入学生的学号,可以修改该学生的姓名、年龄
和性别等信息。
4.删除学生信息:通过输入学生的学号,可以删除该学生的信息。
实现
下面是一个简单的C语言学生管理系统代码示例:
```c #include <stdio.h> #include <string.h>
#define MAX_STUDENTS 100
// 定义学生结构体 struct Student { int id; char name[100]; int age; char
gender[10]; };
// 定义全局变量,用于存储学生信息和统计学生数量 struct Student
students[MAX_STUDENTS]; int num_students = 0;
// 添加学生 void addStudent() { if (num_students >= MAX_STUDENTS) { printf(。
学生信息管理系统代码
主要代码如下:1、登录界面代码:Dim cn As New ADODB.ConnectionDim rst As New ADODB。
RecordsetPrivate Sub Command1_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB。
RecordsetStatic i%cn。
ConnectionString = ”Provider=SQLOLEDB。
1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847”cn.Openusna = Trim(Text1.Text)mysql = "select * from 用户表 where 用户名='”& usna &”’”rst。
Open mysql, cnIf rst。
EOF ThenMsgBox ”用户名不存在!”cn。
CloseText1.Text = "”Text2.Text = ""Text1。
SetFocusElseIf Trim(rst(”密码”)) = Trim(Text2。
Text) Then管理界面.ShowElsei = i + 1If i < 3 ThenMsgBox ”用户名或密码错误!”, vbOKOnly + vbExclamation, "警告”cn。
CloseText2。
Text = ””Text1.Text = ””Text1。
SetFocusElseMsgBox "该用户已被锁定!”, vbOKOnly + vbExclamation, "警告"End IfEnd IfEnd IfEnd SubPrivate Sub Command2_Click()Text1。
学生管理系统c语言源代码
int main()
{
initLinkTable(&head);//初始化表头
readStu();//读入源文件
while (1)
{
menu();
system("cls");
}
}
void initLinkTable(studentLinkPoint *p)
int sum(studentLinkPoint);//求和
void avg(studentLinkPoint);//求平均分
void disAvgSum(studentLinkPoint);//显示总分和平均分
char *inputNumber();//专门用来输入一个学生的学号,返回该字符串的指针
char name[20];
char number[18];
int i;
if(temp==0)
{
error("input");
return 0;
}
else
{
temp->student=(studentPint)malloc(sizeof(studentNod));
break;
case 0:
del(head,end);
break;
}
if(c==0)
exit(1);
}
void del(studentLinkPoint p,studentLinkPoint End)
{
studentLinkPoint q;
if(end==head)
printf(" %3.1f %3.1f\n",p->student->sum,p->student->avg);
java学生管理系统大作业代码
java学生管理系统大作业代码Java学生管理系统是一个基于Java语言开发的学生信息管理系统,用于方便学校教务人员进行学生信息的管理和查询。
以下是该系统的代码实现。
1. 登录界面代码实现该界面是用户登录的入口,用户需要输入用户名和密码才能进入系统。
```javaimport javax.swing.*;import java.awt.*;import java.awt.event.*;public class Login extends JFrame implements ActionListener {JLabel lb1, lb2, lb3;JTextField txtName;JPasswordField txtPwd;JButton btnOK, btnCancel;String userName = "admin";// 默认用户名String password = "123456";// 默认密码public Login() {setTitle("学生信息管理系统登录");// 设置窗体标题setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置窗体关闭方式setSize(350, 200);// 设置窗体大小setLocationRelativeTo(null);// 设置居中显示setLayout(new BorderLayout());JPanel pNorth = new JPanel();lb1 = new JLabel("欢迎使用学生信息管理系统", JLabel.CENTER); lb1.setFont(new Font("微软雅黑", Font.BOLD, 20));pNorth.add(lb1);add(pNorth, BorderLayout.NORTH);JPanel pCenter = new JPanel();pCenter.setLayout(new GridLayout(3, 2));lb2 = new JLabel("用户名:", JLabel.RIGHT);pCenter.add(lb2);txtName = new JTextField(20);pCenter.add(txtName);lb3 = new JLabel("密码:", JLabel.RIGHT);pCenter.add(lb3);txtPwd = new JPasswordField(20);txtPwd.setEchoChar('*');// 设置密码框的回显字符pCenter.add(txtPwd);btnOK = new JButton("登录");pCenter.add(btnOK);btnCancel = new JButton("取消");pCenter.add(btnCancel);add(pCenter, BorderLayout.CENTER);btnOK.addActionListener(this);btnCancel.addActionListener(this);setVisible(true);// 显示窗体}public void actionPerformed(ActionEvent e) {if (e.getSource() == btnOK) {String name = txtName.getText();// 获取用户名String password = new String(txtPwd.getPassword());// 获取密码 if (name.equals(userName) && password.equals(password)) {setVisible(false);new MainFrame();} else {JOptionPane.showMessageDialog(Login.this, "用户名或密码错误!", "登录失败", JOptionPane.ERROR_MESSAGE);}} else if (e.getSource() == btnCancel) {txtName.setText("");txtPwd.setText("");}}public static void main(String[] args) {new Login();}}```2. 主界面代码实现该界面是系统的主界面,包含了菜单栏、工具栏和表格显示区域。
学生信息管理系统完整源代码+mysql文件
数据库所用的数据自己导入MYSQL5.5,Navicat8就可以用了。
下面是具体的数据资料/*MySQL Data TransferSource Host: localhostSource Database: simsTarget Host: localhostTarget Database: simsDate: 2013-6-25 9:24:26*/SET FOREIGN_KEY_CHECKS=0;-- ------------------------------ Table structure for manager-- ----------------------------DROP TABLE IF EXISTS `manager`;CREATE TABLE `manager` (`id` varchar(10) NOT NULL,`name` varchar(30) NOT NULL,`Mima` varchar(20) NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;-- ------------------------------ Table structure for studentinfo-- ----------------------------DROP TABLE IF EXISTS `studentinfo`;CREATE TABLE `studentinfo` (`Sname` varchar(30) NOT NULL,`Ssex` varchar(10) NOTNULL,`Snumber` varchar(10) NOT NULL,`Sprofession` varchar(30) NOT NULL,`Sclass`varchar(20) NOT NULL,`Sdate` varchar(30) character set utf8 collate utf8_unicode_ciNOT NULL,PRIMARY KEY (`Snumber`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='InnoDBfree: 4096 kB';-- ------------------------------ Table structure for userinfo-- ----------------------------DROP TABLE IF EXISTS `userinfo`;CREATE TABLE `userinfo` (`id` varchar(10) NOT NULL,`name` varchar(30) NOT NULL,`Mima` varchar(20) character set utf8 collate utf8_unicode_ci NOT NULL, PRIMARY KEY(`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;-- ------------------------------ Records-- ----------------------------INSERT INTO `manager` VALUES ('1', '1', '2');INSERT INTO `manager` VALUES ('2', '恩恩', '123456');INSERT INTO `manager` VALUES ('3', '大大', '123456');INSERT INTO `manager` VALUES ('4', '啊啊', '123456');INSERT INTO `manager` VALUES ('5', '5', '5');INSERT INTO `manager` VALUES ('6', '孙霞', '123456');INSERT INTO `studentinfo` V ALUES ('张三', '男', '2010303755', '数学', '2', '2010-02- 12');INSERT INTO `studentinfo` V ALUES ('李四', '男', '2010303760', '物理', '1', '1995.9.6'); INSERT INTO `studentinfo` V ALUES ('王二', '女', '2010303761', '应数', '2','1990.9.11');INSERT INTO `studentinfo` V ALUES ('麻子', '女', '2010303762', '信计', '1','1999.9.10');INSERT INTO `userinfo` V ALUES ('1', '1', '1');INSERT INTO `userinfo` V ALUES ('13', '13', '1');INSERT INTO `userinfo` V ALUES ('2', '2', '2');INSERT INTO `userinfo` V ALUES ('3', '3', '3');INSERT INTO `userinfo` V ALUES ('6', '6', '6');INSERT INTO `userinfo` V ALUES ('7', '7', '6');下面是相应的程序:package MS;import java.awt.event.ActionEvent;import java.awt.event.ActionListener; import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.GridLayout;import java.awt.Toolkit;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.SwingConstants;public class Add implements ActionListener {JFrame f1;Container ct;JPanel jp,jp1,jp2,jp3;JButton btn1,btn2;JLabel label;JTextField tf1,tf2,tf3,tf4,tf5,tf6;Add(){f1=new JFrame();ct=f1.getContentPane();//初始化面板jp=new JPanel();jp1=new JPanel(new GridLayout(6,1));jp2=new JPanel(new GridLayout(6,1));jp3=new JPanel();btn1=new JButton("确定");btn2=new JButton("取消");label=new JLabel("<html><font color=#CC00FF size='4'>添加学生信息</font>",SwingConstants.CENTER);label.setForeground(Color.gray);tf1=new JTextField(20);tf2=new JTextField(20);tf3=new JTextField(20);tf4=new JTextField(20);tf5=new JTextField(20);tf6=new JTextField(20);tf6.setText("例:2000-02-02");//文本框加入提示语tf6.addFocusListener(new FocusListener(){public void focusGained(FocusEvent e) {tf6.setText("");}public void focusLost(FocusEvent e) {}});jp.add(label);ct.add(jp,"North");jp1.add(new JLabel("姓名",SwingConstants.CENTER));jp2.add(tf1);jp1.add(new JLabel("性别",SwingConstants.CENTER));jp2.add(tf2);jp1.add(new JLabel("学号",SwingConstants.CENTER));jp2.add(tf3);jp1.add(new JLabel("专业",SwingConstants.CENTER));jp2.add(tf4);jp1.add(new JLabel("班级",SwingConstants.CENTER));jp2.add(tf5);jp1.add(new JLabel("入学时间",SwingConstants.CENTER));jp2.add(tf6);jp3.add(btn1);jp3.add(btn2);ct.add(jp1,"West");ct.add(jp2,"East");ct.add(jp3,"South");Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width;int y=screen.height;f1.setSize(350,330);int xcenter=(x-350)/2;int ycenter=(y-330)/2;f1.setLocation(xcenter, ycenter);f1.setVisible(true);//f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);btn1.addActionListener(this);btn2.addActionListener(this);}public void insert(){if(tf1.getText().equals("")||tf2.getText().equals("")||tf3.getText().equals("")||tf4.getText().equals("")||tf5.getText().equals("")||tf6.getText().equals("")){JOptionPane.showMessageDialog(f1,"请填写完整信息");return;}try{Class.forName("com.mysql.jdbc.Driver");}catch(ClassNotFoundException e){System.out.print("加载驱动程序失败");}String conURL="jdbc:mysql://localhost:3306/sims";try{Connectioncon=DriverManager.getConnection(conURL,"root","123456");Statement st=con.createStatement();String s="insert into studentinfo values('"+tf1.getText()+"','"+tf2.getText()+"','"+tf3.getText()+"','"+tf4.getText()+"','"+tf5.getText()+"','"+tf6.getText()+"');";String query="select * from studentinfo where Snumber='"+tf3.getText().trim()+"'";ResultSet res=st.executeQuery(query);if(res.next()){JOptionPane.showMessageDialog(f1,"学号信息已经存在!");con.close();tf3.setText("");}else if(tf6.getText().length()!=10){JOptionPane.showMessageDialog(f1,"入学时间格式有误!");con.close();tf6.setText("");}int insert=st.executeUpdate(s);if(insert==1){JOptionPane.showMessageDialog(f1,"录入信息成功!");tf1.setText("");tf2.setText("");tf3.setText("");tf4.setText("");tf5.setText("");tf6.setText("");}}catch(SQLException e){System.out.println("错误代码:"+e.getErrorCode());System.out.println("错误信息:"+e.getMessage());}}@SuppressWarnings("deprecation")public void actionPerformed(ActionEvent e){String cmd=e.getActionCommand();if(cmd.equals("确定")){insert();}else if(cmd.equals("取消")){f1.hide();}}public Container getCt(){return ct;}public void setCt(Container ct){this.ct = ct;}}package MS;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.SwingConstants;public class Delete implements ActionListener {JFrame f2;Container ct;JPanel jp1,jp2,jp3,jp4;JLabel label;JTextField text;JTable table;//接收数据库中返回的信息JButton btn1,btn2,btn3;Object columnName[]={"姓名","性别","学号","专业","班级","入学时间"};Object ar[][]=new Object[80][6];Delete(){f2=new JFrame();ct=f2.getContentPane();jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();jp4=new JPanel();label=new JLabel();text=new JTextField();btn1=new JButton("查询");btn2=new JButton("删除");btn3=new JButton("取消");label=new JLabel("<html><font color=#CC00FF size='4'>请输入要删除的学生姓名:</font>",SwingConstants.CENTER);label.setBackground(Color.blue);table=new JTable(ar,columnName);JScrollPane scroll=new JScrollPane(table);text=new JTextField(20);jp2.add(btn1);jp2.add(btn2);jp2.add(btn3);jp1.add(label);jp1.add(text);ct.add(jp1,"North");jp3.setLayout(new BorderLayout());jp3.add(new JLabel("学生信息如下"));jp3.add(scroll);ct.add(jp2,"South");ct.add(jp3,"Center");Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width;int y=screen.height;f2.setSize(450, 400);int xcenter=(x-450)/2;int ycenter=(y-400)/2;f2.setLocation(xcenter, ycenter);f2.setVisible(true);//f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);btn1.addActionListener(this);btn2.addActionListener(this);btn3.addActionListener(this);}int i=0;public void show(String s){while(i>=0){ar[i][0]="";ar[i][1]="";ar[i][2]="";ar[i][3]="";ar[i][4]="";ar[i][5]="";i--;}i=0;try{Class.forName("com.mysql.jdbc.Driver");}catch(ClassNotFoundException e){System.out.print("加载驱动程序失败");}String conURL="jdbc:mysql://localhost:3306/sims";try{Connection con=DriverManager.getConnection(conURL,"root","123456");Statement st=con.createStatement();String sql="select * from studentinfo where Sname='"+s+"'";ResultSet res=st.executeQuery(sql);/*if(!(res.next())){JOptionPane.showMessageDialog(f,"所要查询的信息不存在");} */while(res.next()){String sName=res.getString(1);String sSex=res.getString(2);String sNumber=res.getString(3);String sProfession=res.getString(4);String sClass=res.getString(5);String sDate=res.getString(6);ar[i][0]=sName;ar[i][1]=sSex;ar[i][2]=sNumber;ar[i][3]=sProfession;ar[i][4]=sClass;ar[i][5]=sDate;i++;}f2.repaint();con.close();}catch(SQLException e){System.out.println("错误代码:"+e.getErrorCode());System.out.println("错误信息:"+e.getMessage());}}public void delete(int line){try{Class.forName("com.mysql.jdbc.Driver");}catch(ClassNotFoundException e){System.out.print("加载驱动程序失败");}String conURL="jdbc:mysql://localhost:3306/sims";try{Connection con=DriverManager.getConnection(conURL,"root","123456");Statement st=con.createStatement();String name=(String)(ar[line][2]);String sql="delete from studentinfo where Snumber ='"+name+"'";int del=st.executeUpdate(sql);if(del==1){ar[line][0]="";ar[line][1]="";ar[line][2]="";ar[line][3]="";ar[line][4]="";ar[line][5]="";JOptionPane.showMessageDialog(null,"删除成功!","信息", JOptionPane.YES_NO_OPTION);}con.close();f2.repaint();}catch(SQLException e){System.out.println("错误代码:"+e.getErrorCode());System.out.println("错误信息:"+e.getMessage());}}@SuppressWarnings("deprecation")public void actionPerformed(ActionEvent e){String cmd=e.getActionCommand();if(cmd.equals("查询")){String qu=text.getText().trim();show(qu);}if(cmd.equals("删除")){int de=table.getSelectedRow();if(de==-1){JOptionPane.showMessageDialog(null,"请选定要删除的行","错误信息", JOptionPane.YES_NO_OPTION);}else{delete(de);}}if(cmd.equals("取消")){f2.hide();}}}package MS;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.SwingConstants;public class Liulan implements ActionListener {JFrame f4;Container ct;JPanel jp1,jp2,jp3,jp4;JLabel label;JButton btn1,btn2;JTable table;Object[][] ar=new Object[80][6];Object[] columnName={"姓名","性别","学号","专业","班级","入学时间"};Liulan(){f4=new JFrame();ct=f4.getContentPane();jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();jp4=new JPanel();btn1=new JButton("点击浏览");btn2=new JButton(" 取消");label=new JLabel("<html><font color=#00FF22 size='4'>学生信息浏览<font>",SwingConstants.CENTER);label.setBackground(Color.blue);table=new JTable(ar, columnName);JScrollPane scroll=new JScrollPane(table);jp1.add(label);jp2.add(btn1);jp2.add(btn2);jp3.add(scroll);ct.add(jp1,"North");ct.add(jp3,"Center");ct.add(jp2,"South");Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width;int y=screen.height;f4.setSize(500,530);int xcen=(x-500)/2;int ycen=(y-530)/2;f4.setLocation(xcen,ycen);f4.setVisible(true);btn1.addActionListener(this);btn2.addActionListener(this);}int i=0;public void select(){while(i>=0){ar[i][0]="";ar[i][1]="";ar[i][2]="";ar[i][3]="";ar[i][4]="";ar[i][5]="";i--;}i=0;try{Class.forName("com.mysql.jdbc.Driver");}catch(ClassNotFoundException e){System.out.print("加载驱动程序失败");}String conURL="jdbc:mysql://localhost:3306/sims";try{Connection con=DriverManager.getConnection(conURL,"root","123456");Statement st=con.createStatement();String s="select * from studentinfo";ResultSet res=st.executeQuery(s);while(res.next()){String sName=res.getString(1);String sSex=res.getString(2);String sNumber=res.getString(3);String sProfession=res.getString(4);String sClass=res.getString(5);String sDate=res.getString(6);ar[i][0]=sName;ar[i][1]=sSex;ar[i][2]=sNumber;ar[i][3]=sProfession;ar[i][4]=sClass;ar[i][5]=sDate;i++;}f4.repaint();con.close();}catch(SQLException e){System.out.println("错误代码:"+e.getErrorCode());System.out.println("错误信息:"+e.getMessage());}}@SuppressWarnings("deprecation")public void actionPerformed(ActionEvent e){// TODO Auto-generated method stubString cmd=e.getActionCommand();if(cmd.equals("点击浏览")){select();}else if(cmd.equals(" 取消")){f4.hide();}}}package MS;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.sql.Connection;import java.sql.DriverManager;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JRadioButton;import javax.swing.JTextField;import javax.swing.SwingConstants;@SuppressWarnings("serial")public class Login extends JFrame implements ActionListener {Container cp=null;JFrame f=null;JButton button1,button2,button3;JTextField t1;JPasswordField t2;JLabel jlable1,jlable2;JRadioButton rabtn1,rabtn2;Color c;JPanel jp1,jp2,jp3;String table=null;Login(){f=new JFrame("学生信息管理系统");button1=new JButton("确定");button2=new JButton("取消");button3=new JButton("注册");//button3.setOpaque(false);button3.setBorder(null);button3.setBackground(Color.getColor("#292421"));rabtn1=new JRadioButton("普通用户");rabtn1.setBackground(Color.getColor("#292421"));rabtn2=new JRadioButton("管理员");rabtn2.setBackground(Color.getColor("#292421"));ButtonGroup group=new ButtonGroup();group.add(rabtn1);group.add(rabtn2);cp=f.getContentPane();jlable1=new JLabel("输入用户号");jlable2=new JLabel("输入密码");jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();t1=new JTextField(20);t2=new JPasswordField(20);//jp3.add(group);jp1.add(jlable1);jp1.add(t1);jp1.add(jlable2);jp1.add(t2);jp1.add(rabtn1);jp1.add(rabtn2);jp1.add(button3);JLabel JL=new JLabel("<html><font color=#292421 size='7'><i>欢迎登陆" + "</i></font>",SwingConstants.CENTER);cp.add(JL,"North");jp2.add(button1);jp2.add(button2);cp.add(jp1,"Center");cp.add("South",jp2);cp.setBackground(new Color(127, 255, 212 ));jp2.setBackground(new Color(127, 255, 212 ));jp1.setBackground(new Color(127, 255, 212 ));Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width;int y=screen.height;f.setSize(250,300);int xcenter=(x-300)/2;int ycenter=(y-300)/2;f.setLocation(xcenter,ycenter);/*显示在窗口中央*/f.setVisible(true);//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//------------------------------------------------------------///*监听事件*/button1.addActionListener(this);button2.addActionListener(this);button3.addActionListener(this);rabtn1.addItemListener(new ItemListener(){public void itemStateChanged(ItemEvent e){JRadioButton jop=(JRadioButton) e.getSource();if (jop.isSelected())table="userinfo";}});rabtn2.addItemListener(new ItemListener(){public void itemStateChanged(ItemEvent e){JRadioButton jop=(JRadioButton) e.getSource();if (jop.isSelected())table="manager";}});f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});}@SuppressWarnings("deprecation")public void confirm(String tableName){try{Class.forName("com.mysql.jdbc.Driver");}catch(ClassNotFoundException e){System.out.print("加载驱动程序失败");}String conURL="jdbc:mysql://localhost:3306/sims";try{Connection con=DriverManager.getConnection(conURL,"root","123456");Statement st=con.createStatement();String id=t1.getText().trim();String Mima=t2.getText().trim();String queryMima="select * from "+tableName+" where id='"+id+"' and mima='"+Mima+"'";ResultSet res=st.executeQuery(queryMima);if(res.next()){if(tableName.equals("manager"))new Mstudent(id);else if(tableName.equals("userinfo"))new Ustudent(id);f.hide();con.close();}else{JOptionPane.showMessageDialog(null,"密码错误请重输!!!","提示!",JOptionPane.YES_NO_OPTION);}t1.setText("");t2.setText("");}catch(SQLException g){System.out.println("错误代码:"+g.getErrorCode());System.out.println("错误内容:"+g.getMessage());}}ItemListener listen=new ItemListener(){public void itemStateChanged(ItemEvent e) {// TODO Auto-generated method stub}};public void actionPerformed(ActionEvent e){String cmd=e.getActionCommand();if(cmd.equals("确定")){if(table==null){JOptionPane.showMessageDialog(f,"请选择用户类型");}confirm(table);}else if(cmd.equals("取消")){f.dispose();}else if(cmd.equals("注册")){new Regist();}}public static void main(String []arg){new Login();}}package MS;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenuBar;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.SwingConstants;import javax.swing.border.TitledBorder;@SuppressWarnings("serial")public class Mstudent extends JFrame implements ActionListener {JButton Query = new JButton("查询信息");JButton add = new JButton("添加信息");JButton delete = new JButton("删除信息");JButton xiugai = new JButton("浏览全部信息");JButton liulan = new JButton("修改密码");JMenuBar mb = new JMenuBar();// 菜单栏JPanel jp = new JPanel();Container cp = getContentPane();String userName;Mstudent(){}Mstudent(String userName){erName = userName;mb.add(Query);mb.add(add);mb.add(delete);mb.add(xiugai);mb.add(liulan);JPanel j=new JPanel();j.add(mb,"Center");cp.add(j, "North");// 设置边框jp.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.blue, 2), null, TitledBorder.CENTER,TitledBorder.TOP));jp.setLayout(new BorderLayout());JLabel label1 = new JLabel("欢迎使用学生信息管理系统",SwingConstants.CENTER);jp.add(label1);JScrollPane scrollpane = new JScrollPane(jp);cp.add(scrollpane,"Center");setTitle("欢迎登陆" + "--" + "你好:" + userName);Toolkit kit = Toolkit.getDefaultToolkit();Dimension screen = kit.getScreenSize();int x = screen.width; /* 取得显示器窗口的宽度*/int y = screen.height; /* 取得显示器窗口的高度*/setSize(600, 600);int xcenter = (x - 600) / 2;int ycenter = (y - 600) / 2;setLocation(xcenter, ycenter);/* 显示在窗口中央*/setVisible(true);//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 注册临听器Query.addActionListener(this);add.addActionListener(this);delete.addActionListener(this);xiugai.addActionListener(this);liulan.addActionListener(this);}public void actionPerformed(ActionEvent e){String cmd = e.getActionCommand();if (cmd.equals("查询信息")){new QueryWays();}if (cmd.equals("添加信息")){new Add();}if (cmd.equals("删除信息")){new Delete();}if (cmd.equals("浏览全部信息")){new Liulan();}if (cmd.equals("修改密码")){new UpdateCode();}}public static void main(String[] args){new Mstudent("");}}package MS;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.GridLayout;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.SwingConstants;public class Query implements ActionListener {String sql =null;int a;String info;JFrame f3;// Container cp;JPanel jp1,jp2,jp3,jp4,jp,jpwest;JButton btn1,btn2;//确定,取消JLabel label,label2;//标签,请输入姓名(label)JTextField tf,tf1,tf2,tf3,tf4,tf5,tf6;//文本框Query(int a){this.a=a;f3=new JFrame();Container cp=f3.getContentPane();//初始化面板,按钮,标签,文本框jp=new JPanel();jp1=new JPanel();jp2=new JPanel(new GridLayout(6,1));jp3=new JPanel();jp4=new JPanel(new GridLayout(6,1));jpwest=new JPanel();btn1=new JButton("确定");btn2=new JButton("取消");label=new JLabel("<html><font color=#CC00FF size='4'>请输入姓名:" + "</font>",SwingConstants.CENTER);label2=new JLabel("<html><font color=#CC00FF size='4'>请输入学号:" + "</font>",SwingConstants.CENTER);label.setForeground(Color.gray);tf=new JTextField(20);//------------------------------------------------tf1=new JTextField(20);tf2=new JTextField(20);tf3=new JTextField(20);tf4=new JTextField(20);tf5=new JTextField(20);tf6=new JTextField(20);//布局,添加控件if(a==0){jp.add(label);jp.add(tf);}else if(a==1){jp.add(label2);jp.add(tf);}cp.add(jp,"North");jp4.add(new JLabel("姓名",SwingConstants.CENTER));jp2.add(tf1);jp4.add(new JLabel("性别",SwingConstants.CENTER));jp2.add(tf2);jp4.add(new JLabel("学号",SwingConstants.CENTER));jp2.add(tf3);jp4.add(new JLabel("专业",SwingConstants.CENTER));jp2.add(tf4);jp4.add(new JLabel("班级",SwingConstants.CENTER));jp2.add(tf5);jp4.add(new JLabel("入学时间",SwingConstants.CENTER));jp2.add(tf6);jp3.add(btn1);jp3.add(btn2);cp.add(jp4,"West");cp.add(jp2,"East");cp.add(jp3,"South");cp.add(jp1);Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width; //显示窗口宽度int y=screen.height;//窗口高度f3.setSize(350,330);int xcenter=(x-350)/2;int ycenter=(y-330)/2;f3.setLocation(xcenter,ycenter);f3.setVisible(true);//f3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);btn1.addActionListener(this);btn2.addActionListener(this);/*f3.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});*/。
学生管理系统c语言简单版
学生管理系统c语言简单版学生管理系统c语言简单版介绍:学生管理系统是一种用于管理学生信息的软件,它可以方便地对学生的基本信息、课程成绩等进行录入、查询、修改和删除等操作。
本文将介绍如何使用C语言编写一个简单的学生管理系统。
功能:1. 添加学生信息2. 查询学生信息3. 修改学生信息4. 删除学生信息5. 显示所有学生信息实现方法:1. 添加学生信息添加学生信息需要输入以下内容:姓名、性别、年龄、班级和电话号码。
我们可以定义一个结构体来存储这些信息,代码如下:```struct Student {char name[20];char sex[10];int age;char class[20];char phone[20];};```然后定义一个数组来存储多个学生的信息:```struct Student students[100];int count = 0; // 学生数量```接下来,我们可以编写一个函数来添加新的学生信息:```void addStudent() {struct Student student;printf("请输入姓名:");scanf("%s", );printf("请输入性别:");scanf("%s", student.sex);printf("请输入年龄:");scanf("%d", &student.age);printf("请输入班级:");scanf("%s", student.class);printf("请输入电话号码:");scanf("%s", student.phone);students[count++] = student; // 将新的学生信息存储到数组中 printf("添加成功!\n");}```2. 查询学生信息查询学生信息可以按照姓名或电话号码进行查询。
Python编写的学生信息管理系统
import timedef addStu(): #添加学生信息print('请输入学生信息')xinxi=['编号:','姓名:','性别:','年龄:','电话:'] stu=[]for i in xinxi:x=input(i)stu.append(x)fa.seek(0,2)fa.write(','.join(stu)+'\n')print('添加学生\'{}\'的信息成功'.format(stu[1]))def readStu(): #显示学生信息fa.seek(0)stu=[]print('编号\t姓名\t性别\t年龄\t电话')for line in fa:stu.append(line.strip('\n').split(','))for i in stu:for j in i:print('{:<4}'.format(j),end='\t')print('')def updateStu(): #修改学生信息num=input('请输入学生编号:')stuOld=[]stu=[]stuNew=[]fa.seek(0)jishu=0for line in fa:stuOld=line.strip('\n').split(',')if stuOld[0]==num:jishu=1print('编号\t姓名\t性别\t年龄\t电话')for row in stuOld:print(row,end='\t')print()while True:print('''请选择要修改的信息1.姓名2.性别3.年龄4.电话0.返回上层菜单''')s=input("请输入你的选择:")if s=='1':xm=input("请输入姓名:")stuOld[1]=xmprint('修改成功')breakelif s=='2':xb=input("请输入性别:")stuOld[2]=xbprint('修改成功')breakelif s=='3':nl=input("请输入年龄:")stuOld[3]=nlprint('修改成功')breakelif s=='4':dh=input("请输入电话:")stuOld[4]=dlprint('修改成功')breakelif s=='0':jishu=2print("12345")breakelse:print("请重新选择")stu.append(stuOld)stuNew=stuOldelse:stu.append(stuOld)fa.close()if jishu==1:fb=open('学生信息表.csv','w')stu.sort()for row in stu:fb.write(','.join(row)+'\n')print('编号\t姓名\t性别\t年龄\t电话')for i in stuNew:print(i,end='\t')print('\n')fb.close()elif jishu==2:passelse:print("没有找到学生信息")def findStu(): #查找学生信息num=input('请输入学生编号:')fa.seek(0)jishu=0for line in fa:stu=line.strip('\n').split(',')if stu[0]==num:jishu+=1print('编号\t姓名\t性别\t年龄\t电话')for i in stu:print(i,end='\t')print()if jishu==0:print("没有找到学生信息,请重新输入")time.sleep(1)findStu()def delStu(): #删除学生信息num=input('请输入学生编号:')stuNew=[]stuOld=[]fa.seek(0)for line in fa:stuOld=line.strip('\n').split(',')if stuOld[0]!=num:stuNew.append(line.strip('\n').split(','))else:print('编号\t姓名\t性别\t年龄\t电话')for i in stuOld:print(i,end='\t')x=input("\n确定要删除这个学生信息吗?(是/否)")if x=='是':print('删除成功!')continueelse:print('未进行任何操作!')stuNew.append(line.strip('\n').split(',')) fb=open('学生信息表.csv','w')for row in stuNew:fb.write(','.join(row)+'\n')fb.close()def sortStu(): #排序fa.seek(0)stu=[]x=1for line in fa:stu.append(line.strip('\n').split(','))stu.sort()fb=open('学生信息表.csv','w')for row in stu:fb.write(','.join(row)+'\n')fb.close()print('排序完成!')def controlStu(): #控制x=input()if x=='1':addStu()elif x=='2':findStu()elif x=='3':updateStu()elif x=='4':delStu()elif x=='5':readStu()elif x=='6':sortStu()elif x=='0':quit()else:print("输入错误,请重新选择")while True:try:fa=open('学生信息表.txt','r+')print('''------欢迎登录学生信息管理系统------ ------------------------------------请选择你要执行的功能:1.添加学生信息2.查找学生信息3.更新学生信息4.删除学生信息5.显示学生信息6.排序学生信息0.退出系统''')controlStu() finally:fa.close()。
Jsp学生信息管理系统登录验证全代码
1.jsp登录界面 Login.jspNo.:00000000000000587 <%@page language="java"contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><html><head><meta http-equiv="Content-Type"content="text/html;charset=UTF-8"><title>用户登录界面</title></head><form action="LoginServlet"method="post"><body bgcolor="blue"><marquee direction="right"onmouseover="stop()"onmouseout="start()"style="font-family: 楷体_GB2312"><p><font size="10px"color="red">学生信息信息管理系统</font></p></marquee><table align=center width="237"><tr><td><table width=100%><tr><td colspan=6><font size=2><div id="b2bContent"style="FILTER: revealTrans(Duration = 1, Transition =</font></td></tr><tr><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt0"onclick="javascript:showPage(0);clearTimeout(theTimer);theTimer=s etTimeout('turnPage()',speed);checkBt();">1</div></font></td><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt1"onclick="javascript:showPage(1);clearTimeout(theTimer);theTimer=s etTimeout('turnPage()',speed);checkBt();">2</div></font></td><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt2"onclick="javascript:showPage(2);clearTimeout(theTimer);theTimer=s etTimeout('turnPage()',speed);checkBt();">3</div></font></td><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt3"onclick="javascript:showPage(3);clearTimeout(theTimer);theTimer=s etTimeout('turnPage()',speed);checkBt();">4</div></font></td><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt4"onclick="javascript:showPage(4);clearTimeout(theTimer);theTimer=s etTimeout('turnPage()',speed);checkBt();">5</div></font></td><td align=center STYLE='cursor: hand'><font size=2><div class="b2bbutton"id="bt5"onclick="javascript:showPage(5);clearTimeout(theTimer);theTimer=s etTimeout('turnPage()',speed);checkBt();">6</div></font></td></tr></table><script language="javascript">b2bStr = new Array();b2bStr[0]= "<div style='float:left; width:100%;overflow:hidden;'><a href=1.gif target=_blank><img src=1.gif width=214px height=145px border=0></a><br><a target=_blank title=太阳岛公园一角 href=1.gif>太阳岛公园一角</a></div>";width:100%;overflow:hidden;'><a href=2.gif target=_blank><img src=2.gif width=214px height=145px border=0></a><br><a target=_blank title=太阳岛公园湖光山色 href=2.gif>太阳岛公园湖光山色</a></div>";b2bStr[2] = "<div style='float:left; width:100%;overflow:hidden;'><a href=3.gif target=_blank><img src=3.gif width=214px height=145px border=0></a><br><a target=_blank title=哈尔滨雪雕 href=3.gif>哈尔滨雪雕</a></div>";b2bStr[3] = "<div style='float:left; width:100%;overflow:hidden;'><a href=4.gif target=_blank><img src=4.gif width=214px height=145px border=0></a><br><a target=_blank title=镜泊湖 href=4.gif>镜泊湖</a></div>";b2bStr[4] = "<div style='float:left; width:100%;overflow:hidden;'><a href=5.gif target=_blank><img src=5.gif width=214px height=145px border=0></a><br><a target=_blank title=太阳岛公园瀑布 href=5.gif>太阳岛公园瀑布</a></div>";b2bStr[5] = "<div style='float:left; width:100%;overflow:hidden;'><a href=6.gif target=_blank><img src=6.gif width=214px height=145px border=0></a><br><a target=_blank title=镜泊湖夜色 href=6.gif>镜泊湖夜色</a></div>";var page=0;var speed=3000;function showPage(id){setTransition();b2bContent.innerHTML=b2bStr[id];b2bContent.filters.revealTrans.play();}function turnPage(){showPage(page);theTimer=setTimeout("turnPage()", speed);checkBt();page++;if(page>=6) page=0;}function checkBt(){for(var i=0;i<6;i++){btObj=eval('bt'+i);if(page==i){btObj.style.color='#FFFFFF';btObj.style.backgroundCol or='#FF781C';}else{btObj.style.color='#000000';btObj.style.backgroundColor='#F7 F7F7';}}}function setTransition(){b2bContent.filters.revealTrans.Transition=Math.round(Math.random( )*23);b2bContent.filters.revealTrans.apply();}turnPage();</script></TD></TR></table><hr color="green"width="540"><table align="center"><tr><td>用户名:<input type="text"name="username"size="8" maxlength="6"></td></tr><tr><td>密 码:<input type="password" name="password"size="10"maxlength="6"></td></tr><tr><td><input type="submit"value="登录"> <input type="reset"value="取消"></td></table></form></body></html>2.java代码(1)User.Java 定义的属性和数据库中的字段相对应package com.softeem.dt;public class User {private int id;private String username;private String password;private String xh;private String college;public int getId(){return id;}public void setId(int id){this.id = id;}public String getUsername() {return username;}ername = username;}public String getPassword() {return password;}public void setPassword(String password) { this.password = password;}public String getXh() {return xh;}public void setXh(String xh) {this.xh = xh;}public String getCollege() {return college;}public void setCollege(String college) { this.college = college;}}(2)UserDAO.java 操作数据库tb_user,验证用户登录package com.softeem.dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import com.softeem.db.DBManager;import er;public class UserDAO {/***验证用户登录*@return*/public boolean checkDenglu(User user) {boolean flag = false;// 获得数据库连接Connection conn = DBManager.getConnection();// 用select * from查询数据库中的所有字段String sql = "select count(*) from tb_user where username=? and password=?";try {PreparedStatement pst = conn.prepareStatement(sql);pst.setString(1, user.getUsername());pst.setString(2, user.getPassword());ResultSet rs = pst.executeQuery();while (rs.next()) {int count = rs.getInt(1);//用count和0比较,若大于0表示该用户存在,否则不存在if(count > 0){flag = true;}}} catch (SQLException e) {e.printStackTrace();}return flag;}}3.LoginServlet,点击登录跳转到服务器端package com.softeem.servlet;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import er;/*** Servlet implementation class LoginServlet*/public class LoginServlet extends HttpServlet {private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public LoginServlet() {super();}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { super.doGet(request, response);}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //获取表单数据//处理乱码request.setCharacterEncoding("utf-8");String username = request.getParameter("username");String password = request.getParameter("password");//封装到user对象中User user = new User();user.setUsername(username);user.setPassword(password);//调用dao的checkLogin方法UserDAO dao = new UserDAO();boolean flag = dao.checkLogin(user);String message = null;String path = null;if(flag){message = "登录成功";path="success.jsp";request.getSession().setAttribute("user", user);}else{message ="对不起密码错误,请重新输入!";path="fail.jsp";}//response返回messageresponse.setCharacterEncoding("utf-8");response.getWriter().write(message);*///属于服务器跳转,浏览器地址栏没有发生改变request.getRequestDispatcher(path).forward(request,response);}}青年人首先要树雄心,立大志,其次就要决心作一个有用的人才。
HTML学生信息管理系统+代码
HTML学生信息管理系统+代码系统设计表单表单包含了一系列输入字段,用于添加或编辑学生信息。
以下是表单的字段:- 姓名- 年龄- 性别- 学号- 专业学生信息展示区域学生信息展示区域用于展示添加或编辑后的学生信息。
该区域通过一个表格来展示学生列表。
CSS 样式系统的CSS 样式用于美化界面,使其更加易于使用和吸引人。
JavaScript 代码系统的 JavaScript 代码用于处理用户的输入,并根据用户操作来更新学生信息展示区域。
以下是系统的主要 JavaScript 函数:- `addStudentInfo()`: 用于添加新的学生信息到学生列表中;- `editStudentInfo()`: 用于编辑学生信息;- `deleteStudentInfo()`: 用于删除学生信息;- `displayStudentInfo()`: 用于展示学生信息;系统实现系统的实现步骤如下:2. 使用 CSS 样式美化界面;3. 在 JavaScript 中定义相应的函数,并使用 DOM 操作来处理用户的输入;5. 运行网页,测试系统的功能。
代码示例以下是一个代码示例,展示如何实现系统的功能。
<head><title>学生信息管理系统</title><style>/* CSS 样式 *//* ... */</style><script>// JavaScript 代码function addStudentInfo() {// 实现添加学生信息的逻辑}function editStudentInfo() {// 实现编辑学生信息的逻辑}function deleteStudentInfo() {// 实现删除学生信息的逻辑}function displayStudentInfo() {// 实现展示学生信息的逻辑}</script></head><body><h1>学生信息管理系统</h1><form><!-- 表单字段 --><!-- ... --><button onclick="addStudentInfo()">添加</button><button onclick="editStudentInfo()">编辑</button><button onclick="deleteStudentInfo()">删除</button></form><div id="studentList"><!-- 学生信息展示区域 --><!-- ... --></div></body>总结通过上述的设计和实现,我们成功地创建了一个简单的学生信息管理系统。
学生信息管理系统源代码
#include<stdio.h>#include <stdlib.h>#include <string.h>typedef struct{long class_1; //班级long number; //学号char name[20]; //姓名float math; //数学float c_program; //C语言float physics; //大学物理float english; //大学英语float polity; //政治float sport; //体育float summary; //总分float average; //平均分}Student;Student stud[100]; //定义结构体数组变量的大小int i=0; //i用于记录输入的学生的个数int menu() //菜单函数{int a;printf("***********************学生信息管理系统*************************\n");//菜单选择printf("\t\t【1】输入学生信息\n");printf("\t\t【2】显示所有学生的信息\n");printf("\t\t【3】按平均分升降排序\n");printf("\t\t【4】根据学生的学号查找学生的信息\n");printf("\t\t【5】插入学生的信息\n");printf("\t\t【6】删除学生的信息\n");printf("\t\t【7】修改学生的信息\n");printf("\t\t【8】从文件中读入数据\n");printf("\t\t【9】将所有记录写入文件\n");printf("\t\t【0】退出本系统\n");printf("***********************学生信息管理系统*************************\n");printf("请选择你要的操作【0-9】:");scanf("%d",&a); //读入一个数while(a<0 || a>9){printf("输入错误!请重新输入。
[工学]学生信息管理系统完整源码
学生信息管理系统完整源代码注:本系统采用C/S结构,运用Java GUI知识编写,数据库为SQL SERVER 2005,没有采用典型的三级框架结构,所以代码有冗余,仅供参考。
一、数据表及数据源首先创建数据库,包含数据表如下:数据库创建完成后,新建一个名为SIMS的数据源,不会建数据源的同学可以在去搜索创建数据源的详细步骤,这里的数据名称一定要为SIMS,否则在以后程序连接数据库的语句中会出现错误。
二、操作演示三、代码部分创建Java工程,创建名称为SIMS的包,一下Java类均包含在一个包内。
1.登录界面package SIMS;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;import java.text.SimpleDateFormat;import java.util.*;import java.util.Date;public class login extends JFrame implements ActionListener{String userID; //保留用户输入IDString password; //保留用户输入passwordJLabel jlID=new JLabel("用户ID:"); //使用文本创建标签对象 JLabel jlPwd=new JLabel("密码:");JTextField jtID=new JTextField(); //创建ID输入框JPasswordField jpPwd=new JPasswordField(); //创建密码输入框ButtonGroup bg=new ButtonGroup(); //创建ButtonGroup组件对象JPanel jp=new JPanel(); //创建Panel容器JLabel jl=new JLabel();JRadioButton jrb1=new JRadioButton("管理员");JRadioButton jrb2=new JRadioButton("教师");JRadioButton jrb3=new JRadioButton("学生",true);JButton jb1=new JButton("登录");JButton jb2=new JButton("重置");public login(){this.setLayout(null); //设置窗口布局管理器this.setTitle("学生信息管理系统"); //设置窗口标题this.setBounds(200,150,500,300); //设置主窗体位置大小和可见性this.setVisible(true); //设置窗口的可见性this.setResizable(false);jlID.setBounds(150,60,100,20); //设置ID框属性jtID.setBounds(220,60,100,20); //设置ID输入框属性jlPwd.setBounds(150,90,100,20); //设置密码框属性jpPwd.setBounds(220,90,100,20); //设置密码输入框属性jp.setBounds(35,120,400,250); //设置JPanel容器属性jb1.setBounds(160,170,60,20); //设置登录按钮属性jb2.setBounds(250,170,60,20); //设置取消按钮属性jb1.addActionListener(this); //设置登录按钮监听器jb2.addActionListener(this); //设置取消按钮监听器jl.setBounds(340,75,130,20); //设置提示框属性bg.add(jrb1); //将所有空间加入窗体bg.add(jrb2);bg.add(jrb3);this.add(jlID);this.add(jlPwd);this.add(jtID);this.add(jpPwd);this.add(jb1);this.add(jb2);this.add(jl);jp.add(jrb1);jp.add(jrb2);jp.add(jrb3);this.add(jp);centerShell(this);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}private void centerShell(JFrame shell) //窗口在屏幕中间显示{//得到屏幕的宽度和高度int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;//得到Shell窗口的宽度和高度int shellHeight = shell.getBounds().height;int shellWidth = shell.getBounds().width;//如果窗口大小超过屏幕大小,让窗口与屏幕等大if(shellHeight > screenHeight)shellHeight = screenHeight;if(shellWidth > screenWidth)shellWidth = screenWidth;//让窗口在屏幕中间显示shell.setLocation(( (screenWidth - shellWidth) / 2),((screenHeight - shellHeight) / 2) );}public boolean equals(Object obj){ //重写equals方法判断字符串相等if(obj==null)return false;if(this == obj){return true;}if(obj instanceof String) {String str = (String)obj;return str.equals(userID);}return false;}public void actionPerformed(ActionEvent e){userID=jtID.getText(); //获取用户输入IDpassword=jpPwd.getText(); //获取用户输入密码if(e.getSource()==jb1){ //处理登录事件if(userID.equals("") || password.equals("")){jl.setFont(new Font("red",Font.BOLD,12)); //设置提示字体jl.setForeground(Color.red);jl.setText("请输入用户ID和密码");}else{Connection con=null;try{String url="jdbc:odbc:SIMS"; //连接数据库con=DriverManager.getConnection(url,"","");//获取连接字符串Statement stat=con.createStatement();if(jrb1.isSelected())//如果登录选中的管理员{ResultSet rs=stat.executeQuery("select * from Admin"); //判断输入用户名是否存在int flag=0;while(rs.next()){if(rs.getString(1).equals(userID)){flag=1;break;}}if(flag==0){jl.setFont(new Font("red",Font.BOLD,12));//设置提示字体jl.setForeground(Color.red);jl.setText("用户ID不存在");}if(flag==1){ResultSet rss=stat.executeQuery("selectAdmin_Pwd,Admin_Name from Admin where Admin_ID='"+userID+"'");//从表Admin获取信息while(rss.next()){String str=rss.getString(1);if(str.equals(password)){new admin(rss.getString(2));//创建admin窗口this.dispose(); //释放窗体}else{jl.setFont(new Font("red",Font.BOLD,12)); //设置提示字体jl.setForeground(Color.red);jl.setText("密码错误");}}}}else if(jrb2.isSelected()){ResultSet rs=stat.executeQuery("select * from Teacher_Info"); //判断输入用户名是否存在int flag=0;while(rs.next()){if(rs.getString(1).equals(userID)){flag=1;break;}}if(flag==0){jl.setFont(new Font("red",Font.BOLD,12));//设置提示字体jl.setForeground(Color.red);jl.setText("用户ID不存在");}if(flag==1){ResultSet rss=stat.executeQuery("selectTea_Pwd,Tea_Names from Teacher_Info where Tea_ID='"+userID+"'");//从表Teacher_Info获取信息while(rss.next()){String str=rss.getString(1);if(str.equals(password)){new teacher(rss.getString(2),userID);//创建admin窗口this.dispose(); //释放窗体}else{jl.setFont(new Font("red",Font.BOLD,12));//设置提示字体jl.setForeground(Color.red);jl.setText("密码错误");}}}}else if(jrb3.isSelected()){ResultSet rs=stat.executeQuery("select * from Student_Info"); //判断输入用户名是否存在int flag=0;while(rs.next()){if(rs.getString(1).equals(userID)){flag=1;break;}}if(flag==0){jl.setFont(new Font("red",Font.BOLD,12));//设置提示字体jl.setForeground(Color.red);jl.setText("用户ID不存在");}if(flag==1){ResultSet rsss=stat.executeQuery("selectStu_Pwd,Stu_Name from Student_Info where Stu_ID='"+userID+"'");//从表Student_Info获取信息while(rsss.next()){String str=rsss.getString(1);if(str.equals(password)){new student(rsss.getString(2),userID);//创建admin窗口this.dispose(); //释放窗体}else{jl.setFont(new Font("red",Font.BOLD,12));//设置提示字体jl.setForeground(Color.red);jl.setText("密码错误");}}}}}catch(Exception ex){ex.getStackTrace();}finally{try{con.close();}catch(Exception exc){exc.printStackTrace();}}}}else if(e.getSource()==jb2){ //处理登录事件jtID.setText("");jpPwd.setText("");jrb3.setSelected(true);jl.setText("");}}public static void main(String[] args){new login();}}2.添加课程package SIMS;import javax.swing.*;import java.sql.*;import java.awt.*;import java.awt.event.*;public class add_course extends JFrame implements ActionListener{ static add_course ss;String courseID=""; //课程名String coursename=""; //课程名String count=""; //课时JLabel warning=new JLabel(); //输入信息提示框JLabel title=new JLabel();JLabel note1=new JLabel("*");JLabel note2=new JLabel("*");JLabel jlcourseID=new JLabel("课程号:"); //使用文本框创建标签对象JLabel jlcoursename=new JLabel("课程名:");JLabel jlcount=new JLabel("课时:");JTextField jtcourseID=new JTextField(); //创建文本框对象JTextField jtcoursename=new JTextField();JTextField jtcount=new JTextField();JButton submit=new JButton("添加"); //创建按钮对象JButton reset=new JButton("重置");public add_course(){ //添加教师账号信息this.setTitle("添加课程信息"); //设置窗口标题this.setLayout(null); //设置窗口布局管理器this.add(jlcourseID); //将控件添加到窗体this.add(title);this.add(jlcoursename);this.add(jlcount);this.add(jtcourseID);this.add(jtcoursename);this.add(jtcount);this.add(note1);this.add(note2);this.add(submit);this.add(reset);this.add(warning);title.setFont(new Font("red",Font.BOLD,15)); //设置提示字体title.setForeground(Color.red);note1.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note1.setForeground(Color.red);note2.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note2.setForeground(Color.red);warning.setFont(new Font("red",Font.BOLD,12)); //设置提示字体warning.setForeground(Color.red);title.setText("添加课程信息"); //设置控件及窗体位置大小title.setBounds(222,20,150,20);jlcourseID.setBounds(180,80,100,20);jlcoursename.setBounds(180,140,100,20);jlcount.setBounds(180,200,100,20);jtcourseID.setBounds(250,80,140,20);jtcoursename.setBounds(250,140,140,20);jtcount.setBounds(250,200,140,20);note1.setBounds(400,80,140,20);note2.setBounds(400,140,140,20);submit.setBounds(200,270,60,20);reset.setBounds(300,270,60,20);warning.setBounds(420,140,150,20); //设置提示框位置大小submit.addActionListener(this); //添加监听器reset.addActionListener(this);this.setSize(600,400); //设置窗体大小centerShell(this); //设置窗口位置在屏幕中央this.setResizable(false); //设置窗体不可变大小this.setVisible(true); //设置窗口可见性this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}public boolean equals(Object obj){ //重写equals方法判断字符串相等if(obj==null)return false;if(this == obj){return true;}if(obj instanceof String) {String str = (String)obj;return str.equals(courseID);}return false;}public void actionPerformed(ActionEvent e){courseID=jtcourseID.getText(); //获取用户输入内容coursename=jtcoursename.getText();count=jtcount.getText();int temp=0,flag=0;Connection con=null;if(e.getSource()==submit){ //判断是否已输入必填信息if(courseID.equals("") || coursename.equals("")){warning.setText("请输入必填信息");}else{try{String url="jdbc:odbc:SIMS"; //连接数据库con=DriverManager.getConnection(url,"",""); //获取连接字符串Statement stat=con.createStatement();ResultSet rs=stat.executeQuery("select Course_ID from Course");while(rs.next()){if(rs.getString(1).equals(courseID)){warning.setText("课程ID已存在");flag=1; //判断用户名唯一break;}}if(flag!=1){if(!count.equals("")){temp=stat.executeUpdate("insert intoCourse(Course_ID,Course_Name,Course_Count)values('"+courseID+"','"+coursename+"','"+count+"')");}else{temp=stat.executeUpdate("insert intoCourse(Course_ID,Course_Name) values('"+courseID+"','"+coursename+"')");}}if(temp==1){JOptionPane.showMessageDialog(ss,"添加成功");warning.setText("");}else{JOptionPane.showMessageDialog(ss,"添加失败");}}catch(Exception ex){ex.getStackTrace();}}}else if(e.getSource()==reset){warning.setText("");jtcourseID.setT ext("");jtcoursename.setText("");jtcount.setText("");}}private void centerShell(JFrame shell) //窗口在屏幕中间显示{//得到屏幕的宽度和高度int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;//得到Shell窗口的宽度和高度int shellHeight = shell.getBounds().height;int shellWidth = shell.getBounds().width;//如果窗口大小超过屏幕大小,让窗口与屏幕等大if(shellHeight > screenHeight)shellHeight = screenHeight;if(shellWidth > screenWidth)shellWidth = screenWidth;//让窗口在屏幕中间显示shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2));}}3.添加学生package SIMS;import javax.swing.*;import java.sql.*;import java.awt.*;import java.awt.event.*;public class add_student extends JFrame implements ActionListener{static add_teacher ss;String userID=""; //用户名String pwd1=""; //密码String pwd2=""; //确认密码String getsdept=""; //院系String name=""; //姓名JLabel warning=new JLabel(); //输入信息提示框JLabel title=new JLabel();JLabel note1=new JLabel("*");JLabel note2=new JLabel("*");JLabel note3=new JLabel("*");JLabel jlID=new JLabel("学号:"); //创建文本框对象 JLabel jlName=new JLabel("姓名:");JLabel jlPwd=new JLabel("密码:");JLabel jlPwd2=new JLabel("确认密码:");JLabel sdept=new JLabel("学院:");JTextField jtID=new JTextField();JTextField jtName=new JTextField();JPasswordField jtPwd=new JPasswordField ();JPasswordField jtPwd2=new JPasswordField ();JTextField jtsdept=new JTextField();JButton submit=new JButton("添加"); //创建按钮对象JButton reset=new JButton("重置");public add_student(){this.setTitle("添加学生账号信息"); //设置窗口标题this.setLayout(null); //设置窗口布局管理器this.add(jlID); //将控件添加到窗体this.add(title);this.add(jlName);this.add(jlPwd);this.add(jlPwd2);this.add(sdept);this.add(jtID);this.add(jtName);this.add(jtPwd);this.add(jtPwd2);this.add(jtsdept);this.add(note1);this.add(note2);this.add(note3);this.add(submit);this.add(reset);this.add(warning);title.setFont(new Font("red",Font.BOLD,15)); //设置提示字体title.setForeground(Color.red);note1.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note1.setForeground(Color.red);note2.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note2.setForeground(Color.red);note3.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note3.setForeground(Color.red);warning.setFont(new Font("red",Font.BOLD,12)); //设置提示字体warning.setForeground(Color.red);title.setText("添加学生账号信息");title.setBounds(222,20,150,20);jlID.setBounds(180,60,100,20);jlName.setBounds(180,100,100,20);jlPwd.setBounds(180,140,100,20);jlPwd2.setBounds(180,180,100,20);sdept.setBounds(180,220,100,20);jtID.setBounds(250,60,140,20);jtName.setBounds(250,100,140,20);jtPwd.setBounds(250,140,140,20);jtPwd2.setBounds(250,180,140,20);jtsdept.setBounds(250,220,140,20);note1.setBounds(400,60,140,20);note2.setBounds(400,140,140,20);note3.setBounds(400,180,140,20);submit.setBounds(200,270,60,20);reset.setBounds(300,270,60,20);warning.setBounds(420,100,150,20);submit.addActionListener(this);reset.addActionListener(this);this.setSize(600,400);centerShell(this);this.setVisible(true);this.setResizable(false); //设置窗体不可变大小this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}public boolean equals(Object obj){ //重写equals方法判断字符串相等if(obj==null)return false;if(this == obj){return true;}if(obj instanceof String) {String str = (String)obj;return str.equals(pwd1);}return false;}public void actionPerformed(ActionEvent e){userID=jtID.getText(); //获取用户输入内容pwd1=jtPwd.getText();pwd2=jtPwd2.getText();getsdept=jtsdept.getText();name=jtName.getText();int temp=0,flag=0;Connection con=null;if(e.getSource()==submit){if(userID.equals("") || pwd1.equals("") || pwd2.equals("")){ //判断是否已输入必填信息warning.setText("请输入必填信息");}else if(!pwd1.equals(pwd2)){ //判断两次输入密码是否相同warning.setText("两次输入密码不相同");}else{try{String url="jdbc:odbc:SIMS"; //连接数据库con=DriverManager.getConnection(url,"",""); //获取连接字符串Statement stat=con.createStatement();ResultSet rs=stat.executeQuery("select Stu_ID from Student_Info");while(rs.next()){if(rs.getString(1).equals(userID)){warning.setText("用户ID已存在");flag=1; //判断用户名唯一break;}}if(flag!=1){if(!name.equals("") && !getsdept.equals("")){temp=stat.executeUpdate("insert intoStudent_Info(Stu_ID,Stu_Name,Stu_Pwd,Depart)values('"+userID+"','"+name+"','"+pwd1+"','"+getsdept+"')");}else if(!name.equals("") && getsdept.equals("")){temp=stat.executeUpdate("insert intoStudent_Info(Stu_ID,Stu_Name,Stu_Pwd) values('"+userID+"','"+name+"','"+pwd1+"')");}else if(name.equals("") && !getsdept.equals("")){temp=stat.executeUpdate("insert intoStudent_Info(Stu_ID,Stu_Pwd,Depart) values('"+userID+"','"+pwd1+"','"+getsdept+"')");}else{temp=stat.executeUpdate("insert intoStudent_Info(Stu_ID,Stu_Pwd) values('"+userID+"','"+pwd1+"')");}}if(temp==1){JOptionPane.showMessageDialog(ss,"添加成功");}else{JOptionPane.showMessageDialog(ss,"添加失败");}}catch(Exception ex){ex.getStackTrace();}}}else if(e.getSource()==reset){ //重置所有控件warning.setText("");jtID.setText("");jtName.setText("");jtPwd.setText("");jtPwd2.setText("");jtsdept.setText("");}}private void centerShell(JFrame shell) //窗口在屏幕中间显示{//得到屏幕的宽度和高度int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;//得到Shell窗口的宽度和高度int shellHeight = shell.getBounds().height;int shellWidth = shell.getBounds().width;//如果窗口大小超过屏幕大小,让窗口与屏幕等大if(shellHeight > screenHeight)shellHeight = screenHeight;if(shellWidth > screenWidth)shellWidth = screenWidth;//让窗口在屏幕中间显示shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2));}//public static void main(String args[]){// new add_student();//}}4.添加教师package SIMS;import javax.swing.*;import java.sql.*;import java.awt.*;import java.awt.event.*;public class add_teacher extends JFrame implements ActionListener{static add_teacher ss;String userID=""; //用户名String pwd1=""; //密码String pwd2=""; //确认密码String getsdept=""; //院系String name=""; //姓名JLabel warning=new JLabel(); //输入信息提示框JLabel title=new JLabel();JLabel note1=new JLabel("*");JLabel note2=new JLabel("*");JLabel note3=new JLabel("*");JLabel jlID=new JLabel("教工号:"); //使用文本框创建标签对象 JLabel jlName=new JLabel("姓名:");JLabel jlPwd=new JLabel("密码:");JLabel jlPwd2=new JLabel("确认密码:");JLabel sdept=new JLabel("学院:");JTextField jtID=new JTextField(); //创建文本框对象JTextField jtName=new JTextField();JPasswordField jtPwd=new JPasswordField ();JPasswordField jtPwd2=new JPasswordField ();JTextField jtsdept=new JTextField();JButton submit=new JButton("添加"); //创建按钮对象JButton reset=new JButton("重置");public add_teacher(){ //添加教师账号信息this.setTitle("添加教师账号信息"); //设置窗口标题this.setLayout(null); //设置窗口布局管理器this.add(jlID); //将控件添加到窗体this.add(title);this.add(jlName);this.add(jlPwd);this.add(jlPwd2);this.add(sdept);this.add(jtID);this.add(jtName);this.add(jtPwd);this.add(jtPwd2);this.add(jtsdept);this.add(note1);this.add(note2);this.add(note3);this.add(submit);this.add(reset);this.add(warning);title.setFont(new Font("red",Font.BOLD,15)); //设置提示字体title.setForeground(Color.red);note1.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note1.setForeground(Color.red);note2.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note2.setForeground(Color.red);note3.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note3.setForeground(Color.red);warning.setFont(new Font("red",Font.BOLD,12)); //设置提示字体warning.setForeground(Color.red);title.setText("添加教师账号信息"); //设置控件及窗体位置大小title.setBounds(222,20,150,20);jlID.setBounds(180,60,100,20);jlName.setBounds(180,100,100,20);jlPwd.setBounds(180,140,100,20);jlPwd2.setBounds(180,180,100,20);sdept.setBounds(180,220,100,20);jtID.setBounds(250,60,140,20);jtName.setBounds(250,100,140,20);jtPwd.setBounds(250,140,140,20);jtPwd2.setBounds(250,180,140,20);jtsdept.setBounds(250,220,140,20);note1.setBounds(400,60,140,20);note2.setBounds(400,140,140,20);note3.setBounds(400,180,140,20);submit.setBounds(200,270,60,20);reset.setBounds(300,270,60,20);warning.setBounds(420,100,150,20); //设置提示框位置大小submit.addActionListener(this); //添加监听器reset.addActionListener(this);this.setSize(600,400); //设置窗体大小centerShell(this); //设置窗口位置在屏幕中央this.setResizable(false); //设置窗体不可变大小this.setVisible(true); //设置窗口可见性this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}public boolean equals(Object obj){ //重写equals方法判断字符串相等if(obj==null)return false;if(this == obj){return true;}if(obj instanceof String) {String str = (String)obj;return str.equals(pwd1);}return false;}public void actionPerformed(ActionEvent e){userID=jtID.getText(); //获取用户输入内容pwd1=jtPwd.getText();pwd2=jtPwd2.getText();getsdept=jtsdept.getText();name=jtName.getText();int temp=0,flag=0;Connection con=null;if(e.getSource()==submit){ //判断是否已输入必填信息if(userID.equals("") || pwd1.equals("") || pwd2.equals("")){warning.setText("请输入必填信息");}else if(!pwd1.equals(pwd2)){ //判断两次输入密码是否一致warning.setText("两次输入密码不相同");}else{try{String url="jdbc:odbc:SIMS"; //连接数据库con=DriverManager.getConnection(url,"",""); //获取连接字符串Statement stat=con.createStatement();ResultSet rs=stat.executeQuery("select Tea_ID from Teacher_Info");while(rs.next()){if(rs.getString(1).equals(userID)){warning.setText("用户ID已存在");flag=1; //判断用户名唯一break;}}if(flag!=1){if(!name.equals("") && !getsdept.equals("")){temp=stat.executeUpdate("insert intoTeacher_Info(Tea_ID,Tea_Names,T ea_Pwd,Depart)values('"+userID+"','"+name+"','"+pwd1+"','"+getsdept+"')");}else if(!name.equals("") && getsdept.equals("")){temp=stat.executeUpdate("insert intoTeacher_Info(Tea_ID,Tea_Names,T ea_Pwd)values('"+userID+"','"+name+"','"+pwd1+"')");}else if(name.equals("") && !getsdept.equals("")){temp=stat.executeUpdate("insert intoTeacher_Info(Tea_ID,Tea_Pwd,Depart) values('"+userID+"','"+pwd1+"','"+getsdept+"')");}else{temp=stat.executeUpdate("insert intoTeacher_Info(Tea_ID,Tea_Pwd) values('"+userID+"','"+pwd1+"')");}}if(temp==1){JOptionPane.showMessageDialog(ss,"添加成功");}else{JOptionPane.showMessageDialog(ss,"添加失败");}}catch(Exception ex){ex.getStackTrace();}}}else if(e.getSource()==reset){warning.setText("");jtID.setText("");jtName.setText("");jtPwd.setText("");jtPwd2.setText("");jtsdept.setText("");}}private void centerShell(JFrame shell) //窗口在屏幕中间显示{//得到屏幕的宽度和高度int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;//得到Shell窗口的宽度和高度int shellHeight = shell.getBounds().height;int shellWidth = shell.getBounds().width;//如果窗口大小超过屏幕大小,让窗口与屏幕等大if(shellHeight > screenHeight)shellHeight = screenHeight;if(shellWidth > screenWidth)shellWidth = screenWidth;//让窗口在屏幕中间显示shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2));}// public static void main(String[] args){// new add_teacher();// }}5.添加授课信息package SIMS;import javax.swing.*;import java.sql.*;import java.awt.*;import java.awt.event.*;public class add_tc extends JFrame implements ActionListener{static add_tc ss;String courseID=""; //课程名String teachername=""; //课程名JLabel warning=new JLabel(); //输入信息提示框JLabel title=new JLabel();JLabel note1=new JLabel("*");JLabel note2=new JLabel("*");JLabel jlcourseID=new JLabel("课程号:"); //使用文本框创建标签对象JLabel jlteachername=new JLabel("教师号:");JTextField jtcourseID=new JTextField(); //创建文本框对象JTextField jtteachername=new JTextField();JButton submit=new JButton("添加"); //创建按钮对象JButton reset=new JButton("重置");public add_tc(){ //添加授课信息this.setTitle("添加授课信息"); //设置窗口标题this.setLayout(null); //设置窗口布局管理器this.add(jlcourseID); //将控件添加到窗体this.add(jlteachername);this.add(title);this.add(jtcourseID);this.add(jtteachername);this.add(note1);this.add(note2);this.add(submit);this.add(reset);this.add(warning);title.setFont(new Font("red",Font.BOLD,15)); //设置提示字体title.setForeground(Color.red);note1.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note1.setForeground(Color.red);note2.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note2.setForeground(Color.red);warning.setFont(new Font("red",Font.BOLD,12)); //设置提示字体warning.setForeground(Color.red);title.setText("添加授课信息"); //设置控件及窗体位置大小title.setBounds(222,20,150,20);jlcourseID.setBounds(180,80,100,20);jlteachername.setBounds(180,140,100,20);jtcourseID.setBounds(250,80,140,20);jtteachername.setBounds(250,140,140,20);note1.setBounds(400,80,140,20);note2.setBounds(400,140,140,20);submit.setBounds(200,250,60,20);reset.setBounds(300,250,60,20);warning.setBounds(420,140,150,20); //设置提示框位置大小submit.addActionListener(this); //添加监听器reset.addActionListener(this);this.setSize(600,400); //设置窗体大小centerShell(this); //设置窗口位置在屏幕中央this.setResizable(false); //设置窗体不可变大小this.setVisible(true); //设置窗口可见性this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}public boolean equals(Object obj){ //重写equals方法判断字符串相等if(obj==null)return false;if(this == obj){return true;}if(obj instanceof String) {String str = (String)obj;return str.equals(courseID);}return false;}public void actionPerformed(ActionEvent e){courseID=jtcourseID.getText(); //获取用户输入内容teachername=jtteachername.getText();int temp=0,flag1=0,flag2=0,flag3=0;Connection con=null;if(e.getSource()==submit){ //判断是否已输入必填信息if(courseID.equals("") || teachername.equals("")){warning.setText("请输入必填信息");}else{try{String url="jdbc:odbc:SIMS"; //连接数据库con=DriverManager.getConnection(url,"",""); //获取连接字符串Statement stat=con.createStatement();ResultSet rs=stat.executeQuery("select Course_ID from Course");while(rs.next()){if(rs.getString(1).equals(courseID)){flag1=1; //判断课程ID存在break;}}ResultSet rss=stat.executeQuery("select Tea_ID fromTeacher_Info");while(rss.next()){if(rss.getString(1).equals(teachername)){flag2=1; //判断教师ID存在break;}}if(flag1!=1){warning.setText("课程ID不存在");}else if(flag2!=1){warning.setText("教师ID不存在");}ResultSet rsss=stat.executeQuery("select Course_ID,T ea_ID from tc");while(rsss.next()){if(rsss.getString(1).equals(courseID) &&rsss.getString(2).equals(teachername)){flag3=1;warning.setText("授课信息重复");。
学生信息管理系统python代码总结
学生信息管理系统python代码总结学生信息管理系统是一个基于Python编写的简单的数据库应用程序。
它使用户能够轻松地添加、更新、删除和搜索学生信息。
以下是关于学生信息管理系统 python 代码的总结:1. 采用SQLite数据库实现该系统的关键点之一是采用SQLite数据库。
SQLite是一个自给自足的、零配置的、事务性的SQL数据库引擎,因其易于使用、快速、小巧可靠而受到广泛关注。
使用SQLite存储数据,使得应用程序能够轻松存取、查询、更新和删除学生信息。
2. 用户验证为确保该学生信息管理系统具有安全性,用户必须进行验证才能访问系统。
用户需要输入正确的用户名和密码才能登录系统。
登录认证采用图形用户界面(GUI)与终端交互式控制台(CLI)方式,用户可根据自己的需要选择适合自己的方式进行登录。
3. 显示所有学生信息学生信息管理系统将所有学生的信息存储在一个数据库中。
要显示所有学生信息,系统会读取数据库中的所有学生信息并将其显示在列表框中。
用户可以使用滚动条来浏览以前存储的所有学生信息。
在系统的主窗口中,用户可以在图像界面中查看所有学生的信息。
4. 添加学生信息当用户想要添加一位新学生的信息时,他们可以在界面中选择“添加学生”选项。
在另一个弹出的窗口中,用户可以输入学生的姓名、年龄、性别和学号等详细信息。
用户可以随时添加任意数量的学生信息,只需要单击添加按钮即可保存学生信息。
如果用户输入有误或者学生信息发生了变化,系统允许用户随时更新学生信息。
用户可以通过单击“编辑”按钮来更改学生的信息。
在输入新的信息后,用户可以单击“保存”按钮以保存已更改的学生信息。
如果用户需要删除一个或多个学生的信息,他们可以通过单击“删除”按钮来进行。
用户可以选择要删除的学生并单击“删除”按钮,该学生的所有信息将从系统中删除。
系统允许用户使用多种参数搜索学生信息。
例如,用户可以根据学生姓名、年龄、性别、学号等来搜索学生信息。
学生信息管理系统c语言版源代码
学生信息管理系统c语言版源代码#include <stdio.h> #include <string.h> #include <stdlib.h> #include <conio.h> #define N 1000typedef struct student {int number;char name[20];int grade;int gaoshu;int yingyu;int jisuanji;int sum;}STUDENT;STUDENT student[N]; int shuliang=0;void menu();void fhzjm(){char biaozhi[20];printf("\n");printf("还需要操作么,如果需要操作请输入:yes,否则请输入:no\n");scanf("%s",biaozhi);if(strcmp(biaozhi,"yes")==0){menu();}else if(strcmp(biaozhi,"no")==0)exit(0);else{printf("请输入正确的字符,谢谢~\n"); fhzjm();}}void DengJi(){int rs;int i,k=1;system("CLS");printf("请输入需要输入几个学生信息:"); scanf("%d",&rs);for(i=shuliang;i<shuliang+rs;i++,k++) {printf("请输入第%d个学生的学号:",k); scanf("%d",&student[i].number);printf("请输入学生的姓名:");scanf("%s",student[i].name);printf("请输入学生3门课的成绩:"); printf("请输入第1门课的成绩:");scanf("%d",&student[i].gaoshu);printf("请输入第2门课的成绩:");scanf("%d",&student[i].yingyu);printf("请输入第3门课的成绩:");scanf("%d",&student[i].jisuanji);}shuliang=shuliang+rs;fhzjm();}void ShanChu(){char shanchuinfo[10];system("CLS");printf("删除全部学生信息请输入\"all\",删除指定学号的学生信息请输入\"one\"\n");scanf("%s",shanchuinfo);if(strcmp(shanchuinfo,"all")==0){int j;printf("你删除的学生信息如下:\n");printf("-----------学号-------------姓名-------------高数--------------英语--------------计算机\t\n");for(j=0;j<shuliang;j++)printf("----%d-------%s-------%d-------%d-------%d\t\n",student[j].number,student[j].name,student[j].gaoshu,student[j].jisuanji);shuliang=0;printf("删除成功\n\n");}else if(strcmp(shanchuinfo,"one")==0){struct student *p=NULL;int choice;int i,j,k=0;printf("请输入你要删除的人的学号:");scanf("%d",&choice);for(i=0;i<shuliang;i++){if(choice==student[i].number){k=1;j=i;break;}}if(k){if(shuliang==1){p=&student[0];free(p);shuliang=0;}else{for(i=j;i<shuliang;i++) {student[i]=student[i+1];}shuliang=shuliang-1;}printf("删除成功\n\n");}else{printf("输入数据错误~\n"); }}fhzjm();}void LiuLan(){int i;system("CLS");if(shuliang==0){printf("系统里面没有任何学生的信息~\n");}else{for(i=0;i<shuliang;i++){printf("第%d个学生的学号为:%d\n",i+1,student[i].number);printf("第%d个学生的姓名为:%s\n",i+1,student[i].name);printf("第%d个学生的第一门课的成绩为:%d\n",i+1,student[i].gaoshu);printf("第%d个学生的第二门课的成绩为:%d\n",i+1,student[i].yingyu);printf("第%d个学生的第三门课的成绩为:%d\n",i+1,student[i].jisuanji);student[i].sum=student[i].gaoshu+student[i].yingyu+student[i].jisuan ji;printf("第%d个学生的总成绩为:%d\n",i+1,student[i].sum);}}fhzjm();}void ChaZhao(){int xx;char choice,yy[20];int i,j,k=0;system("CLS");if(shuliang==0){printf("系统里面没有任何学生的信息~\n");fhzjm();}printf("三种查找方式:学号,姓名,成绩\n");printf("如果按学号查找请输1,如果按姓名查找请输2,如果按成绩查找请输3\n");printf("请输入您查找的方式:");scanf("%s",&choice);if(choice=='1'){printf("请输入需要查找学生的学号:");scanf("%d",&xx);printf("您所查找的学生的信息为:\n");printf("----学号----姓名----高数成绩----英语成绩----计算机成绩----\t\n");for(i=0;i<shuliang;i++){if(xx==student[i].number){j=i;k=1;printf("----%d-------%s-------%d-------%d-------%d----\t\n",student[j].number,student[j].name,student[j].gaoshu,student[j].yingyu,student[i].jis uanji);}}if(k==0)printf("输入信息有误:\n");}else if(choice=='2'){printf("请输入需要查找学生的姓名:\n");scanf("%s",yy);printf("您所查找的学生的信息为:\n");printf("----学号----姓名----高数成绩----英语成绩----计算机成绩----\t\n");for(i=0;i<shuliang;i++){if(strcmp(yy,student[i].name)==0){j=i;k=1;printf("----%d-------%s-------%d-------%d-------%d----\t\n",student[j].number,student[j].name,student[j].gaoshu,student[j].yingyu,student[j].jis uanji);}}if(k==0)printf("输入信息有误:\n");}else if(choice=='3'){printf("请输入需要查找学生的成绩:\n");scanf("%d",&xx);printf("您所查找的学生的信息为:\n");printf("----学号----姓名----高数----英语----计算机----\t\n");for(i=0;i<shuliang;i++){if(xx==student[i].grade){j=i;k=1;printf("----%d-------%s-------%d-------%d-------%d----\t\n",student[j].number,student[j].name,student[j].gaoshu,student[j].yingyu,student[i].jis uanji);}}if(k==0)printf("输入信息有误:\n");}fhzjm();}void PaiXu(){struct student *p1[N],**p2,*temp;int i,j;system("CLS");p2=p1;for( i=0;i<shuliang;i++){p1[i]=student+i;}for( i=0;i<shuliang;i++){for( j=i+1;j<shuliang;j++){if((*(p2+i))->sum<(*(p2+j))->sum){temp=*(p2+i);*(p2+i)=*(p2+j);*(p2+j)=temp;} }}printf("按照总成绩排序之后的信息为:\n");printf("----学号----姓名----总成绩----\t\n");for( i=0;i<shuliang;i++){student[i].sum=student[i].gaoshu+student[i].yingyu+student[i].jisuan ji;printf("----%d-----%s----%d-----\n",(*(p2+i))->number,(*(p2+i))->name,(*(p2+i))->sum);}fhzjm();}void CunChu(){int i;FILE *rs;if((rs=fopen("student.txt","w"))==NULL){printf("not open");exit(0);}for(i=0;i<shuliang;i++){fwrite(&student[i], sizeof(student[i]), 1, rs); }if(ferror(rs)){fclose(rs);perror("写文件失败~\n");return;}printf("存储文件成功~\n");fclose(rs);fhzjm();}void DaoChu(){struct student t;int i=0;FILE* fp = fopen("student.txt", "r");shuliang=0;if(NULL==fp){perror("读取文件打开失败~\n");return;}memset(student,0x0,sizeof(student));while(1){fread(&t,sizeof(t),1,fp);if(ferror(fp)){fclose(fp);perror("读文件过程失败~\n");return;}if(feof(fp)){break;}student[i]=t;i++;}fclose(fp);shuliang=i; printf("导出文件成功~\n"); fhzjm();}void menu(){int n=0;system("CLS");printf(" 学生信息管理系统\n");printf(" 作者:陈椿\n");printf("-------------------MENU-----------------\n"); printf(" 1.登记学生信息\n");printf(" 2.删除学生信息\n");printf(" 3.浏览所有已经登记的学生\n");printf(" 4.查找\n");printf(" 4.1按学号查找\n");printf(" 4.2按姓名查找\n");printf(" 4.3按成绩查找\n");printf(" 5.根据总成绩排序\n");printf(" 6.存储到文件\n");printf(" 7.从文件导出\n");printf(" 8.退出系统\n");a: printf(" 请选择:");scanf("%d",&n);switch (n){case 1:DengJi();break;case 2:ShanChu();break;case 3:LiuLan();break;case 4:ChaZhao();break;case 5:PaiXu();break;case 6:CunChu();break;case 7:DaoChu();break;case 8:exit(0);break;default:{printf("请输入1-8之间的数字,谢谢~\n"); goto a;}}}main() {menu();}。
学生管理系统c语言源代码
学生管理系统c语言源代码学生管理系统c语言源代码#include stdio.h#include dos.h#include string.h#include stdlib.h#include malloc.h#define SIZE 8struct student{char name;char num;int score;float ave;struct student *next;}stu[SIZE],temp,s;void shuru(){int i,j,sum,length,flag=1,a;FILE *fp;while(flag==1){printf(“Define a rangeclass number:");scanf("%d",printf("Input the total number of the class(a):"); scanf("%d",length);if(lengtha)flag=0;}for(i=0;ilength;i++){printf("\n请输入学生的信息:");printf("\n输入姓名:");scanf("%s",stu[i].name);printf("\n输入序号.:");scanf("%s",stu[i].num);printf("\n输入成绩:\n");sum=0;for(j=0;jj++){printf("score %d:",j+1);scanf("%d",stu[i].score[j]);sum+=stu[i].score[j];}stu[i].ave=sum/3.0;}学生管理系统c语言源代码fp=fopen("stu1.txt","w");for(i=0;ilength;i++)if(fwrite(stu[i],sizeof(struct student),1,fp)!=1)printf("File write error\n");fclose(fp);fp=fopen("stu1.txt","r");printf("\name\ NO. score1 score2 score3 sum ave\n");for(i=0;ilength;i++){fread(stu[i],sizeof(struct student),1,fp);printf("%3s%5s%7d%7d%7d%7d%10.2f\n",stu[i].name,stu[i].num,stu[i ].score,stu[i].score,stu[i].score,sum=stu[i].score+stu[i].score+stu[i].score,stu[i].ave);}}void chaxun(){ FILE *fp, *fp1;char n,name;int i,j,k,t,m,flag=1;if((fp=fopen("stu1.txt","r"))==NULL){printf("Can not open the file.");exit(0);}printf("\noriginal data:\n");k=i;printf("\nPlease select the menu(1.number ):"); scanf("%d",switch(m){case 1:printf("\nchaxun number:");scanf("%s",n);for(flag=1,i=0;ii++){if(strcmp(n,stu[i].num)==0){j=i;flag=0;break;}}break;case 2:printf("\nchaxun name:");scanf("%s",name);for(flag=1,i=0;ii++){if(strcmp(name,stu[i].name)==0){j=i;flag=0;break;学生管理系统c语言源代码}}}if(!flag){printf("\nYou can find:\n");fp1=fopen("stu2.txt","w");printf(" name NO. score1 score2 score3ave\n");fwrite(stu[j],sizeof(struct student),1,fp1);printf("%-15s%11s%7d%7d%7d%10.2f",stu[j].name,stu[j].num,stu[j].score,stu[j].score,stu[j].score,stu[j].ave);}else printf("\nNot found!");fclose(fp);fclose(fp1);}xiugai(){ int a;printf("\nplease select the menu(1.CHARU 2.__ ):");scanf("%d",switch(a){case 1:Insert(); break;case 2:Delete(); break;}}Insert(){ FILE *fp;int i,j,t,n;printf("\nNO.:");scanf("%s",s.num);printf("name:");scanf("%s",);printf("score1,score2,score3:");scanf("%d,%d,%d",s.score,s.score,s.score);s.ave=(s.score+s.score+s.score)/3.0;if((fp=fopen("stu1.txt","r"))==NULL){printf("Can not open the file.");exit(0);}printf("\noriginal data:\n");for(i=0;fread(stu[i],sizeof(struct student),1,fp)!=0;i++) {printf("\n%-15s%11s",stu[i].name,stu[i].num);for(j=0;jj++)学生管理系统c语言源代码printf("%7d",stu[i].score[j]);printf("%10.2f",stu[i].ave);}fclose(fp);n=i;for(t=0;stu[t].aves.avett++);printf("\nnow:\n");fp=fopen("stu1.txt","w");for(i=0;ii++){fwrite(stu[i],sizeof(struct student),1,fp);printf("\n%-15s%11s",stu[i].name,stu[i].num);for(j=0;jj++)printf("%7d",stu[i].score[j]);printf("%10.2f",stu[i].ave);}fwrite(s,sizeof(struct student),1,fp);printf("\n%-15s%11s%7d%7d%7d%10.2f",,s.num,s.score,s.score, s.score,s.ave);for(i=t;ii++){fwrite(stu[i],sizeof(struct student),1,fp);printf("\n%-15s%11s",stu[i].name,stu[i].num);for(j=0;jj++)printf("%7d",stu[i].score[j]);printf("%10.2f",stu[i].ave);}fclose(fp);}Delete(){ FILE *fp;int i,j,t,n,flag;char number;if((fp=fopen("stu1.txt","rb"))==NULL){printf("Can not open the file.");exit(0);}printf("\noriginal data:");for(i=0;fread(stu[i],sizeof(struct student),1,fp)!=0;i++) {printf("\n%-15s%11s",stu[i].name,stu[i].num);for(j=0;jj++)printf("%7d",stu[i].score[j]);printf("%10.2f",stu[i].ave);}fclose(fp);n=i;学生管理系统c语言源代码printf("\nInput number deleted:");scanf("%s",number);for(flag=1,i=0;flagii++){if(strcmp(number,stu[i].num)==0){for(t=i;tt++){strcpy(stu[t].num,stu[t+1].num);strcpy(stu[t].name,stu[t+1].name);for(j=0;jj++)stu[t].score[j]=stu[t+1].score[j];stu[t].ave=stu[t+1].ave;}n=n-1;elseprintf("\n Not found!");printf("\nNow,the content of file:\n");fp=fopen("stu1.txt","wb");for(i=0;ii++)fwrite(stu[i],sizeof(struct student),1,fp);fclose(fp);fp=fopen("stu1.txt","r");for(i=0;fread(stu[i],sizeof(struct student),1,fp)!=0;i++)printf("%-15s%11s%7d%7d%7d%10.2f\n",stu[i].name,stu[i].num,stu[i].score, stu[i].score,stu[i].score,stu[i].ave);fclose(fp);}paixu(){FILE *fp;int i,j,n;if((fp=fopen("stu1.txt","r"))==NULL){printf("Can not open the file.");exit(0);}printf("\nfile'stu1.txt':");for(i=0;fread(stu[i],sizeof(struct student),1,fp)!=0;i++) {printf("\n%-15s%11s",stu[i].name,stu[i].num);for(j=0;jj++)printf("%7d",stu[i].score[j]);printf("%10.2f",stu[i].ave);}fclose(fp);n=i;for(i=0;ii++)for(j=i+1;jj++)学生管理系统c语言源代码if(stu[i].avestu[j].ave){temp=stu[i];stu[i]=stu[j];stu[j]=temp;}printf("\nnow:");fp=fopen("stu1.txt","w");for(i=0;ii++){fwrite(stu[i],sizeof(struct student),1,fp);printf("\n%-15s%11s",stu[i].name,stu[i].num);tongji(){ FILE *fp;int i,j,k,labe1,b;int a5=0;int a6=0;int a7=0;int a8=0;int a9=0; int a10=0; float t;if((fp=fopen("stu1.txt","r"))==NULL){printf("Can not open the file.");exit(0);}printf("\nfile'stu1.txt':");for(i=0;fread(stu[i],sizeof(struct student),1,fp)!=0;i++){printf("\n%-15s%11s",stu[i].name,stu[i].num); for(j=0;jj++)printf("%7d",stu[i].score[j]);printf("%10.2f",stu[i].ave);}fclose(fp);k=i;for(i=0;ii++){labe1=0;if(stu[i].ave60){labe1++;t=labe1/(float)k*100;}}printf("\nbujigelv:");printf("%f%",t);printf("\n");for(j=0;jj++){a5=0;a6=0;a7=0;a8=0;a9=0;a10=0;k=i;printf("kemu is %d:\n",j);for(i=0;ii++)学生管理系统c语言源代码{b=stu[i].score[j]/10;if(b6)a5++;elseif(b=6b7)a6++;elseif(b=7b8)a7++;elseif(b=8b9)a8++;if(b=9b10)a9++;elseif(b==10)a10++;}printf(" 不及格is %d\n",a5);printf(" 60--69 is %d\n",a6);printf(" 70--79 is %d\n",a7);printf(" 80--89 is %d\n",a8);printf(" 90--99 is %d\n",a9);printf(" 100 is %d\n",a10);}}main(){int a;printf(" ____\n"); printf(" 欢迎进入学生成绩管理系统\n");printf(" ____\n"); while(1){printf("\n选择菜单:\n");printf("\n");printf(" 1.输入 2.查询 3.排序 4.修改 5.统计 6.退出\n"); scanf("%d",switch(a){case 1: shuru();break;case 2: chaxun(); break;case 3: paixu(); break;case 4: xiugai(); break;学生管理系统c语言源代码case 5: tongji();break; case 6: exit(0); }。
学生管理系统 C语言代码
#include"stdio.h"#include"stdlib.h"#include"string.h"struct stu_info1{char num[13];//学号char name[10];//姓名char sex[5];//性别char cls[20];//班级}stu1[6];struct stu_info2{char counum[6];//课程号char counam[20];//课程名称int credit;//学分}stu2[6];struct stu_info3{char num[13];//学号char counum[6];//课程号float results;//分数}stu3[12];struct stu_info4{char num[13];//学号char counum[6];//课程号float results;//分数}stu4[12];int n=11;void main(){void gengxin();void input1();void input2();void input3();void output();void xianshi();void chaxun();void printf1();void printf2();input1();input2();output();int i;loop: ;printf("*************欢迎使用分数查询系统*************\n");printf("** 请选择**\n");printf("** 1.录入2.删除无用信息(管理员功能) **\n");printf("** 3.显示4.查询(学生功能) **\n");printf("** 5.显示学生信息6.显示课程信息**\n");printf("** 7.退出**\n");printf("**********************************************\n");scanf("%d",&i);switch(i){case 1: input3();break;case 2:gengxin();break;case 3:xianshi();goto loop;case 4: chaxun();goto loop;case 5: printf1();goto loop;case 6: printf2();goto loop;case 7:break;default:printf("error");break;}}void input1()//录入结构体stu1[]{int i;FILE *fp;if((fp=fopen("A.txt","r"))==NULL){printf("can not open file\n");exit(0);}/* printf(" 学号姓名性别班级\n");*/for(i=0;i<=5;i++){fscanf(fp,"%s%s%s%s",&stu1[i].num,&stu1[i].name,&stu1[i].sex,&stu1[i].cls);/*printf("%-13s %-10s %-5s %-20s\n",stu1[i].num,stu1[i].name,stu1[i].sex,stu1[i] .cls);*/}fclose(fp);}void input2()//录入结构体stu2[]{int i;FILE *fp;if((fp=fopen("B.txt","r"))==NULL){printf("can not open file\n");exit(0);}for(i=0;i<=5;i++){fscanf(fp,"%s%s%d",&stu2[i].counum,&stu2[i].counam,&stu2[i].credit);}fclose(fp);}void input3()//录入成绩{FILE *fp;fp=fopen("C.txt","w");int a,i,j,k;float cetss;char number[13],cnum[6],mima[10];printf("请输入管理员密码\n");scanf("%s",mima);if(strcmp(mima,"abc111")==0){printf("请输入要录入学生成绩的个数\n");scanf("%d",&a);for(i=1;i<=a;i++){printf("请输入要录入的第%d同学的学号:",i);scanf("%s",number);printf("请输入要录入的第%d同学的课程号:",i);scanf("%s",cnum);for(j=0;j<=5;j++)//学号{if((strcmp(number,stu1[j].num)==0))break;}if(j<=5){for(k=0;k<=5;k++)//课程号{if(strcmp(cnum,stu2[k].counum)==0){printf("请输入要录入同学的成绩:");scanf("%f",&cetss);fprintf(fp,"%s %s %f\n",number,cnum,cetss);break;}}}if(j>5||k>5){printf("Error,please input again");i=i-1;}printf("录入成功\n");}}else{printf("密码错误\n");}}void output()// 录入结构体stu3[]{int i;FILE *fp=fopen("C.txt","r");for(i=0;i<n;i++){fscanf(fp,"%s%s%f",&stu3[i].num,&stu3[i].counum,&stu3[i].results);/*printf("%s%s%f\n",stu3[i].num,stu3[i].counum,stu3[i].results);*/ }fclose(fp);}void xianshi()// 显示成绩{int i,j;for(i=0;i<n;i++){for(j=0;j<6;j++){if((strcmp(stu3[i].num,stu1[j].num))==0)printf("%s\t",stu1[j].name);}for(j=0;j<6;j++){if(strcmp(stu3[i].counum,stu2[j].counum)==0)printf("%s\t",stu2[j].counam);}printf("%3.1f\n",stu3[i].results);}}void chaxun()//查询功能{char number[13],c;int i,j,k,a,b,d;while((c=getchar())!='Q'){a=0,b=0;//a记录学分b记录学科printf("请输入要查询同学的学号\n");scanf("%s",number);for(i=0;i<n;i++){if(strcmp(number,stu3[i].num)==0){printf("学号:%s\t",stu3[i].num);for(j=0;j<6;j++){if(strcmp(stu3[i].num,stu1[j].num)==0){printf("姓名:%s\n",stu1[j].name);}}break;}}d=i;for(i=0;i<n;i++)if(strcmp(number,stu3[i].num)==0){b=b+1;for(j=0;j<6;j++){if(strcmp(stu3[i].num,stu1[j].num)==0){for(k=0;k<6;k++){if(strcmp(stu3[i].counum,stu2[k].counum)==0)break;}break;}}if(stu3[i].results>=60){a=a+stu2[k].credit;printf("课程号:%s\t课程名称:%s\t成绩:%3.1f\t实得学分:%d\n",stu3[i].counum,stu2[k].counam,stu3[i].results,stu2[k].credit);}elseprintf("课程号:%s\t课程名称:%s\t成绩:%3.1f\t实得学分:%d\n",stu3[i].counum,stu2[k].counam,stu3[i].results,0);}if(d<n){printf("共修%d科\t\t实得总学分:%d\n",b,a);}else{printf("学号输入错误\n");}getchar();printf("退出请按Q+回车,继续查询请按回车键");}}void gengxin()//更新信息,删除C.txt中无用信息{FILE *fp;int i,j,k;char mima[10];printf("请输入管理员密码\n");scanf("%s",mima);if(strcmp(mima,"abc111")==0){fp=fopen("C.txt","w");for(i=0;i<n;i++){for(j=0;j<6;j++)if(strcmp(stu3[i].num,stu1[j].num)==0){for(k=0;k<=5;k++)if(strcmp(stu3[i].counum,stu2[k].counum)==0)break;if(k<=5){fprintf(fp,"%s %s %f\n",stu3[i].num,stu3[i].counum,stu3[i].results);}}}printf("更新C.txt成功\n");fclose(fp);}else{printf("密码错误\n");}}void printf1()//显示学生信息{int i;printf(" 学号姓名性别班级\n");for(i=0;i<=5;i++){printf("%-13s%-10s%-5s %-20s\n\n",stu1[i].num,stu1[i].name,stu1[i].sex,stu1[i].cls);}}void printf2()//显示课程信息{int i;printf(" 课程编号课程名称学分\n");for(i=0;i<=5;i++){printf("%-6s%-20s %-4d\n\n",stu2[i].counum,stu2[i].counam,stu2[i].credit);}}。
学生信息管理系统c语言代码
学生信息管理系统c语言代码以下是一个简单的学生信息管理系统的 C 语言代码示例,包含了学生信息的添加、查询、修改和删除功能。
由于代码超过了 400 字,我将提供一个简化的版本,你可以根据需要进行扩展和改进。
```c#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX_STUDENTS 100// 学生结构体struct Student {char id[10];char name[50];int age;};// 学生信息列表struct Student students[MAX_STUDENTS];// 学生数量int studentCount = 0;// 添加学生信息void addStudent() {if (studentCount >= MAX_STUDENTS) {printf("学生数量已满,无法添加更多学生。
\n");return;}printf("请输入学生 ID: ");scanf("%s", students[studentCount].id);printf("请输入学生姓名: ");scanf("%s", students[studentCount].name);printf("请输入学生年龄: ");scanf("%d", &students[studentCount].age);studentCount++;printf("学生信息添加成功。
\n");}// 查询学生信息void queryStudent() {if (studentCount == 0) {printf("没有学生信息可供查询。
学生信息管理系统(vc)
void SaveToFile();/* 保存到文件 */
void LoadFile();/* 从文件中读入记录 */
void CopyFile(); /* 复制文件 */
void InsertToFile();/* 追加记录到文件中 */
OutList();
break;
/* 查找记录 */
case 5:
SearchPrintNode();
SWITCH[6] = 0;
printf("追加完毕!\n");
break;
/* 索引 */
case 13:
{
switch (n)
{
/* 执行初始化 */
case 1:
head = Init();
void InputList(); /*读取多个学生信息*/
void OutputNodeInfo(Student*);/*显示学生信息*/
void OutList();/*显示多个学生信息*/
Student* SearchFrontNode(Student*);/*查找前一结点*/
void SearchPrintNode();/* 按姓名查找记录并打印 */
if (SWITCH[8])
{
head = Sort(CmpID, 0);
system("cls");
void Compute();/* 计算总分和均分 */
int CmpID(Student*, Student*, int);/*比较两个id*/
JAVA课程设计学生信息管理系统代码
JAVA课程设计学生信息管理系统代码某Tochangethitemplate,chooeTool|Template某andopenthetemplateintheeditor.某/packagetudentinfo;importjava.awt.某;importjava某.wing.某;importjava.awt.event.某;importjava.awt.某;importjava.awt.event.某;importjava.util.某;importjava某.wing.border.某;importjava某.wing.JOptionPane;importjava某.wing.JLabel;importjava某.wing.JPanel;importjava某.wing.table.DefaultTableModel; importjava某.wing.table.TableColumn;importjava.ql.某;importjava.awt.GridLayout;//网格式布局//导入javar需要的jar包publicclaStudentInfo{publicStudentInfo()//构造方法{}publictaticvoidmain(String[]arg){//TODOcodeapplicationlogichereloginFramelf=newloginFrame();//加载窗体lf.etViible(true);//设置窗体可见lf.addWindowLitener(newWindowAdapter()//添加窗口监听以接受关闭事件{publicvoidwindowCloing(WindowEvente){Sytem.e某it(0);}});}}//学生成绩管理系统界面clamainFramee某tendJFrameimplementActionLitener{MenuBarmyMenuBar=newMenuBar();//菜单MenuItemmiNew,miOpen,miSave,miSaveA,miE某it;MenuItemmiAdd,miEdit,miDel,miFind,miShow,miUer,miAbout;public JTabletable=newJTable();//表格publicDefaultTableModelmm;//表格模型publicmainFrame(){myMenuFile=newMenu("文件");miNew=newMenuItem("新建");miOpen=newMenuItem("打开");miSave=newMenuItem("保存");miE某it=newMenuItem("退出");//miNew.enable(fale);//miOpen.enable(fale);//miSave.enable(fa le);//myMenuFile.add(miNew);//myMenuFile.add(miOpen);//myMenuFil e.add(miSave);myMenuFile.add(miE某it);myMenuEdit=newMenu("数据编辑");miFind=newMenuItem("查找数据");miAdd=newMenuItem("添加数据");miEdit=newMenuItem("修改数据");miDel=newMenuItem("删除数据");miShow=newMenuItem("全部显示");myMenuEdit.add(miFind);myMenuEdit.add(miAdd);myMenuEdit.add(m iEdit);myMenuEdit.add(miDel);myMenuEdit.add(miShow);myMenuUer=ne wMenu("用户管理");miUer=newMenuItem("编辑用户");myMenuUer.add(miUer);myMenuAbout=newMenu("关于我");miAbout=newMenuItem("我的信息");myMenuAbout.add(miAbout);myMenuBar.add(myMenuFile);myMenuBar.add(myMenuEdit);myMenuBar.add(myMenuUer);myMenuBar.add(myMenuAbout);String[]col={"学号","姓名","性别","班级","专业","大学语文","大学英语","高等数学"};//创建属性列名table.etModel(mm);JScrollPanetableScrollPane=newJScrollPane( table);//设置滚动条thi.etMenuBar(myMenuBar);thi.add(tableScrollPane);miE某it.addActionLitener(thi);//为各按钮注册事件监听器对象miFind.addActionLitener(thi);miAdd.addActionLitener(thi);miEdit. addActionLitener(thi);miDel.addActionLitener(thi);miShow.addActi onLitener(thi);miUer.addActionLitener(thi);miAbout.addActionLite ner(thi);}publicvoidfrehTable(Stringql){myConnectionconn=newmyCo nnection();//获得数据库连接ReultSetr;//保存查询返回结果对象r=conn.getReult(ql);if(r!=null){try{mm.etRowCount(0);table.etMod el(mm);while(r.ne某t()){String学号=r.getString("学号");String姓名=r.getString("姓名");String性别=r.getString("性别");String班级=r.getString("班级");String专业=r.getString("专业");String大学语文=r.getString("大学语文");String大学英语=r.getString("大学英语");String高等数学=r.getString("高等数学");String[]cloumn={学号,姓名,性别,班级,专业,大学语文,大学英语,高等数学};mm.addRow(cloumn);}//table.clearSelection();table.etModel(mm );}catch(E某ceptione){}}}//捕获异常publicvoidactionPerformed(ActionEvente)//重载动作事件接口中的方法{//退出if(e.getSource()==miE某it){Sytem.e 某it(0);//查找}eleif(e.getSource()==miFind){findFrameff=newfindFrame(thi);ff .etViible(true);//添加}eleif(e.getSource()==miAdd){addFrameaf=newaddFrame(thi);af.et Viible(true);//修改}eleif(e.getSource()==miEdit){if(table.getSelectedRow()==-1){JOptionPane.howMeageDialog(null,"请选择你要修改的内容","温馨提示",RMATION_MESSAGE);//弹窗提示}{editFrameef=neweditFrame(thi);ef.学号.etTe某t((String)table.getValueAt(table.getSelectedRow(),0));ef.姓名.etTe某t((String)table.getValueAt(table.getSelectedRow(),1));ef.性别.etTe某t((String)table.getValueAt(table.getSelectedRow(),2));ef.班级.etTe某t((String)table.getValueAt(table.getSelectedRow(),3));ef.专业.etTe某t((String)table.getValueAt(table.getSelectedRow(),4));ef.大学语文.etTe某t((String)table.getValueAt(table.getSelectedRow(),5));ef.大学英语.etTe某t((String)table.getValueAt(table.getSelectedRow(),6));ef.高等数学.etTe某t((String)table.getValueAt(table.getSelectedRow(),7));ef.etViibl e(true);thi.frehTable("elect某from学生成绩表");//刷新表格}//删除eleif(e.getSource()==miDel){if(table.getSelectedRow()==-1){JOptionPane.howMeageDialog(null,"请选择你要删除的行","温馨提示",RMATION_MESSAGE);}ele{Stringql="deletefrom学生成绩表where学号='"+table.getValueAt(table.getSelectedRow(),0)+"'";//JOptionPane.howMeageDialog(null,ql,"温馨提示",RMATION_MESSAGE);myConnectionconn=newmyConnection();if(conn.e某ecuteSql(ql)){JOptionPane.howMeageDialog(null,"成功删除","温馨提示",RMATION_MESSAGE);thi.frehTable("elect某from学生成绩表");ele{JOptionPane.howMeageDialog(null,"未知错误","删除失败",RMATION_MESSAGE);}}//显示}eleif(e.getSource()==miShow){//JOptionPane.howMeageDialog(null,"未知错误","删除失败",RMATION_MESSAGE);thi.frehTable("elect某from学生成绩表");//编辑用户}eleif(e.getSource()==miUer){uerFrameuf=newuerFrame();uf.etViible(true);//作业说明}eleif(e.getSource()==miAbout){aboutFrameaf=newaboutFrame();af.etViible(true);}}}clamyConnection{ReultSetre;Stringtrurl="jdbc:odbc:driver={MicrooftAcceDriver(某.mdb)};D BQ=学生管理数据库.mdb";//Stringtrurl="jdbc:odbc:driver={MicrooftAcceDriver(某.mdb)} ;DBQ=学生管理数据库.mdb";//Stringtrurl="jdbc:odbc:cah";//cah为数据源名称publicmyConnection(){}publicReultSetgetReult(Stringql){try{Cla.forName("un.jdbc.odbc.JdbcOdbcDriver");Connectionconn=DriverManager.getConnection(trurl);Statementtmt=conn.createStatement(ReultSet.TYPE_SCROLL_SENSITIVE,Reul tSet.CONCUR_UPDATABLE);ReultSetre=tmt.e某ecuteQuery(ql);returnre;}catch(E某ceptione){e.printStackTrace();//异常处理returnnull;}}publicbooleane某ecuteSql(Stringql){try{Cla.forName("un.jdbc.odbc.JdbcOdbcDriver"); Connectionconn=DriverManager.getConnection(trurl); Statementtmt=conn.createStatement();tmt.e某ecuteUpdate(ql);mit();returntrue;}catch(E某ceptione){e.printStackTrace();returnfale;}}}claaddFramee某tendJDialogimplementActionLitener {publictaticfinalintWIDTH=400;publictaticfinalintHEIGHT=400;JLabel学号1,姓名1,性别1,班级1,专业1,大学语文1,大学英语1,高等数学1;JTe某tField学号,姓名,性别,班级,专业,大学语文,大学英语,高等数学;JButtonb;JPanelp;mainFramemf;publicaddFrame(mainFramemmf){etT itle("添加学生成绩");etSize(WIDTH,HEIGHT);etLocation(120,180);ContainercontentPane =getContentPane();//创建一个容器对象contentPane.etLayout(newFlowLayout());//流式布局学号1=newJLabel("学号");姓名1=newJLabel("姓名");性别1=newJLabel("性别");班级1=newJLabel("班级");专业1=newJLabel("专业");大学语文1=newJLabel("大学语文");大学英语1=newJLabel("大学英语");高等数学1=newJLabel("高等数学");学号=newJTe某tField(5);姓名=newJTe某tField(5);性别=newJTe某tField(5);班级=newJTe某tField(5);专业=newJTe某tField(5);大学语文=newJTe某tField(5);大学英语=newJTe 某tField(10);高等数学=newJTe某tField(10);b=newJButton("确定");p=newJPanel();p.etLayout(newGridLayout(10,2,5,5));//表格布局p.add(学号1);p.add(学号);p.add(姓名1);p.add(姓名);p.add(性别1);p.add(性别);p.add(班级1);p.add(班级);p.add(专业1);p.add(专业);p.add(大学语文1);p.add(大学语文);p.add(大学英语1);p.add(大学英语);p.add(高等数学1);p.add(高等数学);p.add(newLabel(""));p.add(newLabel(""));p.add(b);contentPane .add(p);//添加按钮监听器b.addActionLitener(thi);mf=mmf;}publicvoidactionPerformed(ActionEvente){if(学号.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入学号","温馨提示",RMATION_MESSAGE);}eleif(姓名.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入姓名","温馨提示",RMATION_MESSAGE);}eleif(大学语文.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入大学语文","温馨提示",RMATION_MESSAGE);}ele{Stringql="elect某from学生成绩表where学号='"+学号.getTe某t()+"'";myConnectionconn=newmyConnection();ReultSetr;r=conn.getReult (ql);try{//Sytem.out.println(r.getRow());if(r.ne某t()){ JOptionPane.howMeageDialog(null,"此学号已经存在","温馨提示",RMATION_MESSAGE);误信息}//添加学生的时候,发现数据库已经有了,提示你学号已经存在,报错ele{ql="inertinto学生成绩表value('"+学号.getTe某t()+"','"+姓名.getTe某t()+"','"+性别.getTe某t()+"','"+班级.getTe某t()+"','"+专业.getTe某t()+"','"+大学语文.getTe某t()+"','"+大学英语.getTe某t()+"','"+高等数学.getTe某t()+"')";//实行数据库插入的语句if(conn.e某ecuteSql(ql))//插入语句{JOptionPane.howMeageDialog(null,"添加成功","温馨提示",RMATION_MESSAGE);}ele{mf.frehTable("elect某from学生成绩表");学号.etTe某t("");姓名.etTe某t("");性别.etTe某t("");班级.etTe某t("");专业.etTe某t("");大学语文.etTe某t("");大学英语.etTe某t("");高等数学.etTe某t("");JOptionPane.howMeageDialog(null,"添加失败","温馨提示",RMATION_MESSAGE);}//插入失败}}catch(E某ceptioner){Sytem.out.println(er.toString());}}}}claeditFramee某tendJDialogimplementActionLitener{publictaticfinalintWIDTH=400;publictaticfinalintHEIGHT=400;JLabel学号1,姓名1,性别1,班级1,专业1,大学语文1,大学英语1,高等数学1;JTe某tField学号,姓名,性别,班级,专业,大学语文,大学英语,高等数学;JButtonb;JPanelp;mainFramemf;publiceditFrame(mainFramemmf){et Title("修改学生信息");etSize(WIDTH,HEIGHT);etLocation(120,180);ContainercontentPane =getContentPane();contentPane.etLayout(newFlowLayout());学号1=newJLabel("学号");姓名1=newJLabel("姓名");性别1=newJLabel("性别");班级1=newJLabel("班级");专业1=newJLabel("专业");大学语文1=newJLabel("大学语文");大学英语1=newJLabel("大学英语");高等数学1=newJLabel("高等数学");学号=newJTe某tField(5);姓名=newJTe某tField(5);性别=newJTe某tField(5);班级=newJTe某tField(5);专业=newJTe某tField(5);大学语文=newJTe某tField(5);大学英语=newJTe 某tField(10);高等数学=newJTe某tField(10);学号.etEnabled(fale);b=newJButton("确定");p=newJPanel();p.etLayout(newGridLayout(10,2,5,5));p.add(学号1);p.add(学号);p.add(姓名1);p.add(姓名);p.add(性别);p.add(班级1);p.add(班级);p.add(专业1);p.add(专业);p.add(大学语文1);p.add(大学语文);p.add(大学英语1);p.add(大学英语);p.add(高等数学1);p.add(高等数学);p.add(newLabel(""));p.add(newLabel(""));p.add(b);contentPane .add(p);//添加按钮监听器b.addActionLitener(thi);mf=mmf;}//这是画界面publicvoidactionPerformed(ActionEvente){if(学号.getTe某t().toString().equal(""))//判断{JOptionPane.howMeageDialog(null,"请输入学号","温馨提示",RMATION_MESSAGE);//弹出的小窗口提示}eleif(姓名.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入姓名","温馨提示",RMATION_MESSAGE);}eleif(大学语文.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入大学语文","温馨提示",RMATION_MESSAGE);}ele{Stringql="update学生成绩表et姓名='"+姓名.getTe某t()+"',性别='"+性别.getTe某t()+"',班级='"+班级.getTe某t()+"',专业='"+专业.getTe某t()+"',大学语文='"+大学语文.getTe某t()+"',大学英语='"+大学英语.getTe某t()+"',高等数学='"+高等数学.getTe某t()+"'where学号='"+学号.getTe某t()+"'";myConnectionconn=newmyConnection();//打开数据库的连接try{//JOptionPane.howMeageDialog(null,ql,"温馨提示",RMATION_MESSAGE);if(conn.e某ecuteSql(ql))//执行ql语句,弹出窗口,查询学生表刷新table{JOptionPane.howMeageDialog(null,"修改成功","温馨提示",RMATION_MESSAGE);mf.frehTable("elect某from学生成绩表");thi.dipoe();//关闭当前窗体对象,隐藏}ele{JOptionPane.howMeageDialog(null,"修改失败","温馨提示",RMATION_MESSAGE);}}catch(E某ceptioner){er.printStackTrace();}}}}clafindFramee某tendJDialogimplementActionLitener{mainFramemf;JPanelp;JTe某tFieldt;JButtonb;JButtonfAll;Stringql="elect某fromtudent";String[]colStr={"学号","姓名","性别","班级","专业","大学语文","大学英语","高等数学"};publicfindFrame(mainFramemmf) {mf=mmf;p=newJPanel();t=newJTe某tField(10);b=newJButton("查找");fAll=newJButton("全部显示");b.addActionLitener(thi);fAll.addActionLitener(thi);p.add(newJLabel("选择"));p.add(c);p.add(newJLabel("查找内容"));p.add(t);p.add(b);p.add(fAll);thi.add(p);thi.etTitle("查找");thi.etSize(450,80);}publicvoidactionPerformed(ActionEvente){//查找if(e.getSource()==b){StringelectStr=c.getSelectedItem().toString(); if(electStr=="大学英语"){ql="elect某from学生成绩表"+t.getTe某t().toString();}ele{ql="elect某from学生成绩表'"+t.getTe某t().toString()+"'";}mf.frehTable(ql);//全部显示}if(e.getSource()==fAll){ql="elect某from学生成绩表";mf.frehTable(ql);}//监听程序,选择查成绩,最后是重新刷新table }}claaboutFramee某tendJDialog//关于我的信息{aboutFrame(){JPanelp1=newJPanel();where"+electStr+"where"+electStr+"== clauerFramee某tendJFrameimplementActionLitener//用户密码{JTe某tFielduer,pa;JButtonadd,del;JTablet;JPanelp1,p2,p3,p4,p5;DefaultTableModelm;publicuerFrame(){p1=newJPanel();p2=newJPanel();p3=newJPanel();p4=newJPanel();p5=newJPanel();uer=newJTe某tField(8);pa=newJTe某tField(8);add=newJButton("添加");del=newJButton("删除");String[]col={"用户名","密码"};m=newDefaultTableModel(col,0);t=newJTable();t.etModel(m);JScr ollPanep=newJScrollPane(t);p1.add(newJLabel("用户名"));p1.add(uer);p1.add(newJLabel("密码"));p1.add(pa);p1.add(add);p2.add(p);p3.add(del);add.addActionLi tener(thi);del.addActionLitener(thi);myConnectionconn=newmyConne ction();ReultSetr;r=conn.getReult("elect某from管理员");//开始时连接数据库,查询数据,返回结果集,if(r!=null){//把查询结果放到table里面try{//m.etRowCount(0);//table.etModel(mm);while(r.ne某t()){String用户名=r.getString("用户名");String密码=r.getString("密码");String[]cloumn={用户名,密码};m.addRow(cloumn);}t.etModel(m);}catch(E某ceptione){Sytem.out.println(e.toString());}}thi.add(p1,BorderLay out.NORTH);thi.add(p2,BorderLayout.CENTER);thi.add(p3,BorderLayo ut.SOUTH);thi.add(p4,BorderLayout.WEST);thi.add(p5,BorderLayout. EAST);thi.etTitle("用户管理");thi.etSize(600,400);}publicvoidactionPerformed(ActionEvente){ //用户添加if(e.getSource()==add){if(uer.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入用户名","温馨提示",RMATION_MESSAGE);eleif(pa.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入密码","温馨提示",RMATION_MESSAGE);}elemyConnectionconn=newmyConnection();ReultSetr;try{r=conn.getReult("elect某from管理员where用户名='"+uer.getTe某t().toString()+"'");if(r.ne某t()){JOptionPane.howMeageDialog(null,"此用户已经存在","温馨提示",RMATION_MESSAGE);}ele{if(conn.e某ecuteSql("inertinto管value('"+uer.getTe某t().toString()+"','"+pa.getTe某t().toString()+"')"))String[]newUer={uer.getTe某t(),pa.getTe某t()};m.addRow(newUer);t.etModel(m);理员JOptionPane.howMeageDialog(null,"添加成功","温馨提示",RMATION_MESSAGE);}ele{JOptionPane.howMeageDialog(null,"添加失败","温馨提示",RMATION_MESSAGE);}}}catch(E某ceptioner){Sytem.out.println(er.toString());}}//删除}eleif(e.getSource()==del){if(t.getSelectedRow()==-1){JOptionPane.howMeageDialog(null,"请选择你要删除的行","温馨提示",RMATION_MESSAGE);}ele{=",Stringql="deletefrom管理员where用户名'"+t.getValueAt(t.getSelectedRow(),0)+"'";//JOptionPane.howMeage Dialog(null,ql,"温馨提示RMATION_MESSAGE);myConnectionconn=newmyConnection();if(conn.e某ecuteSql(ql)){m.removeRow(t.getSelectedRow());t.etModel(m);//t.removeRowSelectionInterval();JOptionPane.howMeageDialog(null,"成功删除","温馨提示",RMATION_MESSAGE);}ele{JOptionPane.howMeageDialog(null,"未知错误","删除失败",RMATION_MESSAGE);}}}}}claloginFramee某tendJDialogimplementActionLitener//登陆{JPanelp;JTe某tFielduer,pa;JButtonlogin,cancel;publicloginFrame(){p=newJPanel();uer=newJTe某tField(10);pa=newJTe某tField(10);login=newJButton("登录");cancel=newJButton("退出");uer.etTe某t("");pa.etTe某t("");login.addActionLitener(thi);cancel.addActionLitener(thi);p.add(newJLabel("账号"));p.add(uer);p.add(newJLabel("密码"));p.add(pa);p.add(login);p.add(cancel);thi.add(p);thi.etTitle("学生成绩管理系统");JLabelimg=newJLabel(newImageIcon("1.jpg"));p.add(img);thi.etSize(700,600);}publicvoidactionPerformed(ActionEvente){//查找if(e.getSource()==login){if(uer.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入用户名","温馨提示",RMATION_MESSAGE);}eleif(pa.getTe某t().toString().equal("")){JOptionPane.howMeageDialog(null,"请输入密码","温馨提示",RMATION_MESSAGE);}ele{myConnectionconn=newmyConnection();ReultSetr;Stringql="elect某from管理员where用户名='"+uer.getTe某t().toString()+"'and密码='"+pa.getTe某t().toString()+"'";try{r=conn.getReult(ql);if(r.ne某t()){thi.dipoe();//JOptionPane.howMeageDialog(null,"此用户已经存在","温馨提示",RMATION_MESSAGE);ql="elect某from学生成绩表";mainFramemf=newmainFrame();mf.etTitle("学生成绩管理系统");mf.etSize(600,486);mf.frehTable(ql);mf.etViible(true);mf.addWindowLitener(newWindowAdapter(){publicvoidwindowCloing(WindowEvente){Sytem.e某it(0);}});}ele{JOptionPane.howMeageDialog(null,"用户名或密码错误","登录失败",RMATION_MESSAGE);}}catch(E某ceptioner){Sytem.out.println(er.toString());}}}}//全部显示}if(e.getSource()==cancel){Sytem.e某it(0);}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
主要代码如下:1、登录界面代码:Dim cn As New ADODB.ConnectionDim rst As New ADODB.RecordsetPrivate Sub mand1_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.RecordsetStatic i%cn.ConnectionString = "Provider=SQLOLEDB.1;Persist SecurityInfo=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.Openusna = Trim(Text1.Text)mysql = "select * from 用户表 where 用户名='" & usna & "'"rst.Open mysql, cnIf rst.EOF ThenMsgBox "用户名不存在!"cn.CloseText1.Text = ""Text2.Text = ""Text1.SetFocusElseIf Trim(rst("密码")) = Trim(Text2.Text) Then管理界面.ShowElsei = i + 1If i < 3 ThenMsgBox "用户名或密码错误!", vbOKOnly + vbExclamation, "警告"cn.CloseText2.Text = ""Text1.Text = ""Text1.SetFocusElseMsgBox "该用户已被锁定!", vbOKOnly + vbExclamation, "警告"End IfEnd IfEnd IfEnd SubPrivate Sub mand2_Click() Text1.Text = ""Text2.Text = ""Text3.Text = ""End Sub2、管理界面代码:Private Sub Sinsert_Click() 添加学生信息.ShowEnd SubPrivate Sub Sselect_Click() 查询学生信息.ShowEnd SubPrivate Sub sustu_Click() 查询更新学生信息.ShowEnd SubPrivate Sub xgmm_Click()修改密码.ShowEnd SubPrivate Sub yhzc_Click()用户注册.ShowEnd Sub3、查询学生信息代码:Dim cn As New ADODB.ConnectionDim rst As New ADODB.RecordsetPrivate Sub mand1_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist SecurityInfo=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.OpenIf bo1.Text <> "" Thenmysql = "select * from 学生信息表 where 系别='" & Trim(bo1.Text) & "'"rst.Open mysql, cnIf rst.EOF ThenMsgBox "没有学生!", vbOKOnly + vbExclamation, "警告"bo1.Text = ""ElseWith MSFlexGrid1.TextMatrix(0, 1) = "学号".TextMatrix(0, 2) = "姓名".TextMatrix(0, 3) = "性别".TextMatrix(0, 4) = "年龄".TextMatrix(0, 5) = "系别".TextMatrix(0, 6) = "班级"MSFlexGrid1.Rows = 1 '每次查询自动定位到第一行Do While Not rst.EOF.Rows = .Rows + 1.CellAlignment = 8.TextMatrix(.Rows - 1, 1) = rst.Fields("学号").TextMatrix(.Rows - 1, 2) = rst.Fields("姓名").TextMatrix(.Rows - 1, 3) = rst.Fields("性别").TextMatrix(.Rows - 1, 4) = rst.Fields("年龄").TextMatrix(.Rows - 1, 5) = rst.Fields("系别").TextMatrix(.Rows - 1, 6) = rst.Fields("班级")rst.MoveNextLoopEnd WithEnd IfElseIf bo2.Text <> "" Thenmysql = "select * from 学生信息表 where 班级='" & Trim(bo2.Text) & "'"rst.Open mysql, cnIf rst.EOF ThenMsgBox "没有学生!", vbOKOnly + vbExclamation, "警告"bo1.Text = ""ElseWith MSFlexGrid1.TextMatrix(0, 1) = "学号".TextMatrix(0, 2) = "姓名".TextMatrix(0, 3) = "性别".TextMatrix(0, 4) = "年龄".TextMatrix(0, 5) = "系别".TextMatrix(0, 6) = "班级"MSFlexGrid1.Rows = 1 '每次查询自动定位到第一行 Do While Not rst.EOF.Rows = .Rows + 1.CellAlignment = 8.TextMatrix(.Rows - 1, 1) = rst.Fields("学号") .TextMatrix(.Rows - 1, 2) = rst.Fields("姓名") .TextMatrix(.Rows - 1, 3) = rst.Fields("性别") .TextMatrix(.Rows - 1, 4) = rst.Fields("年龄").TextMatrix(.Rows - 1, 5) = rst.Fields("系别").TextMatrix(.Rows - 1, 6) = rst.Fields("班级")rst.MoveNextLoopEnd WithEnd IfElseIf Text1.Text <> "" Thenmysql = "select * from 学生信息表 where 学号='" & Trim(Text1.Text) & "'"rst.Open mysql, cnIf rst.EOF ThenMsgBox "没有学生!", vbOKOnly + vbExclamation, "警告"bo1.Text = ""ElseWith MSFlexGrid1.TextMatrix(0, 1) = "学号".TextMatrix(0, 2) = "姓名".TextMatrix(0, 3) = "性别".TextMatrix(0, 4) = "年龄".TextMatrix(0, 5) = "系别".TextMatrix(0, 6) = "班级"MSFlexGrid1.Rows = 1 '每次查询自动定位到第一行 Do While Not rst.EOF.Rows = .Rows + 1.CellAlignment = 8.TextMatrix(.Rows - 1, 1) = rst.Fields("学号") .TextMatrix(.Rows - 1, 2) = rst.Fields("姓名") .TextMatrix(.Rows - 1, 3) = rst.Fields("性别") .TextMatrix(.Rows - 1, 4) = rst.Fields("年龄") .TextMatrix(.Rows - 1, 5) = rst.Fields("系别") .TextMatrix(.Rows - 1, 6) = rst.Fields("班级") rst.MoveNextLoopEnd WithEnd IfElseMsgBox "请输入查询条件!", vbOKOnly + vbExclamation, "警告" End IfEnd SubPrivate Sub mand2_Click()bo1.Text = ""bo2.Text = ""Text1.Text = ""End SubPrivate Sub mand3_Click()修改学生信息.ShowEnd Sub '修改学生信息Private Sub mand4_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist SecurityInfo=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.Openmysql = "delete from 学生信息表 where 学号='" & Text1.Text & "'"rst.Open mysql, cnMsgBox "删除成功!", vbOKOnly + vbExclamation, "警告"End SubPrivate Sub Form_Load()bo1.AddItem "信息服务学院"bo1.AddItem "电子信息工程系"bo2.AddItem "40821P"bo2.AddItem "40811P"bo2.AddItem "40822P"bo2.AddItem "40721P"End Sub4、添加学生信息代码Dim cn As New ADODB.Connection Dim rst As New ADODB.RecordsetPrivate Sub Form_Load()bo1.AddItem "信息服务学院"bo1.AddItem "电子信息工程系" bo2.AddItem "40821P"bo2.AddItem "40811P"bo2.AddItem "40822P"bo2.AddItem "40721P"End SubPrivate Sub mand1_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist SecurityInfo=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.OpenDim sex As Stringusna = Trim(Text1.Text)mysql = "select * from 学生信息表 where 学号='" & usna & "'"rst.Open mysql, cnIf rst.EOF Thenrst.CloseElserst.CloseMsgBox "该学生信息已存在!", vbOKOnly + vbExclamation, "警告"Text1.Text = ""Text3.Text = ""bo1.Text = ""bo2.Text = ""Option1.Value = FalseText1.SetFocusEnd IfIf Text1.Text = "" ThenMsgBox "请输入学号!", vbOKOnly + vbExclamation, "警告" Text1.SetFocusExit SubEnd IfIf Text2.Text = "" ThenMsgBox "请输入姓名!", vbOKOnly + vbExclamation, "警告" Text2.SetFocusExit SubEnd IfMsgBox "请输入年龄!", vbOKOnly + vbExclamation, "警告" Text3.SetFocusExit SubEnd IfIf Option1.Value Thensex = "男"Elsesex = "女"End Ifxh = Trim(Text1.Text)xm = Trim(Text2.Text)xb = sexnl = Trim(Text3.Text)xofy = Trim(bo1.Text)bj = Trim(bo2.Text)mysql = "insert into 学生信息表(学号,姓名,性别,年龄,系别,班级)values ('" & xh & "','" & xm & "','" & xb & "','" & nl & "','" & xofy & "','" & bj & "')"rst.Open mysql, cnMsgBox ("信息添加成功!")Text1.Text = ""Text2.Text = ""Text3.Text = ""bo1.Text = ""bo2.Text = ""Option1.Value = FalseEnd Sub5、修改密码:Dim rst As New ADODB.RecordsetDim cn As New ADODB.ConnectionPrivate Sub mand1_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist SecurityInfo=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.OpenIf Text1.Text = "" ThenMsgBox "请输入密码!", vbOKOnly + vbExclamation, "警告"Text1.SetFocusExit SubEnd IfIf Text2.Text = "" ThenMsgBox "请输入新密码!", vbOKOnly + vbExclamation, "警告"Text2.SetFocusExit SubEnd IfIf Text3.Text = "" ThenMsgBox "请确认输入的新密码!", vbOKOnly + vbExclamation, "警告"Text3.SetFocusExit SubEnd IfIf Text2.Text = Text3.Text Thenxmm = Trim(Text2.Text)mysql = "update 用户表 set 密码 = '" & xmm & "' where 用户名 = '" & 登陆.Text1.Text & "'"rst.Open mysql, cnMsgBox ("密修改成功!")End IfEnd SubPrivate Sub mand2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""End Sub6、修改学生信息代码:Dim cn As New ADODB.ConnectionDim rst As New ADODB.RecordsetPrivate Sub mand1_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist SecurityInfo=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.Openusna = Trim(Text1.Text)mysql = "select * from 学生信息表 where 学号='" & usna & "'" rst.Open mysql, cnrst.Closemysql = "delete from 学生信息表 where 学号='" & Text1.Text & "'" rst.Open mysql, cnIf Text1.Text = "" ThenMsgBox "请输入学号!", vbOKOnly + vbExclamation, "警告" Text1.SetFocusExit SubEnd IfIf Text2.Text = "" ThenMsgBox "请输入姓名!", vbOKOnly + vbExclamation, "警告" Text2.SetFocusExit SubEnd IfIf Text3.Text = "" ThenMsgBox "请输入年龄!", vbOKOnly + vbExclamation, "警告" Text3.SetFocusExit SubEnd IfIf Option1.Value Thensex = "男"Elsesex = "女"End Ifxh = Trim(Text1.Text)xm = Trim(Text2.Text)xb = sexnl = Trim(Text3.Text)xofy = Trim(bo1.Text)bj = Trim(bo2.Text)mysql = "insert into 学生信息表(学号,姓名,性别,年龄,系别,班级) values ('" & xh & "','" & xm & "','" & xb & "','" & nl & "','" & xofy & "','" & bj & "')"rst.Open mysql, cnMsgBox ("信息修改成功!")Text1.Text = ""Text2.Text = ""Text3.Text = ""bo1.Text = ""bo2.Text = ""Option1.Value = FalseEnd SubPrivate Sub Form_Load()bo1.AddItem "信息服务学院"bo1.AddItem "电子信息工程系"bo2.AddItem "40821P"bo2.AddItem "40811P"bo2.AddItem "40822P"bo2.AddItem "40721P"End Sub7、用户注册代码:Dim rst As New ADODB.RecordsetDim cn As New ADODB.ConnectionPrivate Sub mand1_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist SecurityInfo=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.OpenIf Text1.Text = "" ThenMsgBox "请输入用户名!", vbOKOnly + vbExclamation, "警告"Text1.SetFocusExit SubEnd IfIf Text2.Text = "" ThenMsgBox "请输入密码!", vbOKOnly + vbExclamation, "警告"Text2.SetFocusExit SubEnd IfIf Text3.Text = "" ThenMsgBox "请再次输入密码!", vbOKOnly + vbExclamation, "警告"Text3.SetFocusExit SubEnd Ifsryhm = Trim(Text1.Text)srmm = Trim(Text2.Text)mysql = "insert into 用户表(用户名,密码) values ('" & sryhm & "','" & srmm & "')"rst.Open mysql, cnMsgBox ("用户添加成功!")Text1.Text = ""Text2.Text = ""Text3.Text = ""End Sub '添加用户Private Sub mand2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""End Sub '重置按钮Private Sub mand3_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist SecurityInfo=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.Openusna = Trim(Text1.Text)mysql = "select * from 用户表 where 用户名='" & usna & "'"rst.Open mysql, cnIf rst.EOF ThenMsgBox "用户名可用!"ElseMsgBox "用户名已存在!", vbOKOnly + vbExclamation, "警告"Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusExit SubEnd IfEnd Sub '检查用户名Private Sub mand4_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist SecurityInfo=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.Openusna = Trim(Text1.Text)mysql = "select * from 用户表 where 用户名='" & usna & "'"rst.Open mysql, cnIf rst.EOF ThenMsgBox "无此用户名,删除不成功!", vbOKOnly + vbExclamation, "警告"Elserst.Closeusna = Trim(Text1.Text)mysql = "delete from 用户表 where 用户名='" & usna & "'"rst.Open mysql, cnMsgBox "删除成功!", vbOKOnly + vbExclamation, "警告"Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd IfEnd Sub '删除用户Private Sub mand5_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist SecurityInfo=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.Openmysql = "select * from 用户表 "rst.Open mysql, cnIf rst.EOF ThenMsgBox "出错!", vbOKOnly + vbExclamation, "警告" End IfWith MSFlexGrid1.TextMatrix(0, 1) = "用户名".TextMatrix(0, 2) = "密码"MSFlexGrid1.Rows = 1 '每次查询自动定位到第一行Do While Not rst.EOF.Rows = .Rows + 1.CellAlignment = 8.TextMatrix(.Rows - 1, 1) = rst.Fields("用户名") .TextMatrix(.Rows - 1, 2) = rst.Fields("密码") rst.MoveNextLoopEnd Withrst.CloseEnd Sub '查询用户表。