📄 xuanke.java
字号:
else if(e.getSource()==back18)
lay.show(this,"c17");
else if(e.getSource()==input_course) //录入课程
{
lay.show(this,"c2");
addno.setText("");
addname.setText("");
addcredit.setText("");
addaddress.setText("");
addbegintime.setText("");
}
else if(e.getSource()==back17)
lay.show(this,"ca");
else if(e.getSource()==ok2) //录入课程到Course表
{
String Input_Tuser=T_userField.getText();
String I_no=addno.getText();
String I_name=addname.getText();
String I_credit=addcredit.getText();
String I_address=addaddress.getText();
String I_begintime=addbegintime.getText();
String sql_TN="select Tname from Teacher where Tno='"+Input_Tuser+"'";
String I_teacher=TeacherName(sql_TN);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException e1){System.out.println("not found!");}
try{
con=DriverManager.getConnection(url," ",null);
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sql1="INSERT INTO Course"+
" VALUES('"+I_no+"','"+I_name+"','"+I_credit+"','"+I_address+"','"+I_begintime+"','"+I_teacher+"')";
stmt.executeUpdate(sql1);
stmt.close();
con.close();
}catch(SQLException ex){System.out.print(ex.getMessage());}
final Frame frmFrame = new Frame();
JOptionPane.showMessageDialog(frmFrame, "课程录入成功!");
return;
}
else if(e.getSource()==back2)
lay.show(this,"cb");
else if(e.getSource()==input_grade) //教师录入学生成绩
{
lay.show(this,"c10");
L_Sno.setText("");
L_Cno.setText("");
L_grade.setText("");
}
else if(e.getSource()==ok10)
{
String sno=L_Sno.getText();
String cno=L_Cno.getText();
String grade=L_grade.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException e1){System.out.println("not found!");}
try{
con=DriverManager.getConnection(url," ",null);
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sql_grade="update SC set Grade='"+grade+"' where Sno='"+sno+"' and Cno='"+cno+"'";
stmt.executeUpdate(sql_grade);
stmt.close();
con.close();
}catch(SQLException ex){System.out.print(ex.getMessage());}
final Frame frmFrame = new Frame();
JOptionPane.showMessageDialog(frmFrame, "成绩录入成功!");
return;
}
else if(e.getSource()==back10)
lay.show(this,"cb");
else if(e.getSource()==query_part) //单个课程查询
{
lay.show(this,"cc");
displayc.setText("");
query_name.setText("");
}
else if(e.getSource()==queryc) //输入课程名进行查询
{
String dname=query_name.getText();
a=Query_Part(dname);
displayc.setText(a);
}
else if(e.getSource()==backc)
lay.show(this,"cb");
else if(e.getSource()==query_sc)
lay.show(this,"c13");
else if(e.getSource()==ad_studentquery) //管理员查询所有学生的选修情况
{
lay.show(this,"c9");
String sql_sq="select Sname,Cname,Sdept from SC,Student,Course where SC.Sno=Student.Sno and SC.Cno=Course.Cno";
a=Display_SC_sq(sql_sq);
display9.setText(a);
}
else if(e.getSource()==back9)
lay.show(this,"c13");
else if(e.getSource()==ad_coursequery) //管理员查询所有课程被选修的情况
{
lay.show(this,"c14");
String Input_user=userField.getText();
String sql_cq="select Cname,count(Cname) number from SC,Course where SC.Cno=Course.Cno group by SC.Cno,Cname";
a=Lookfor_All(sql_cq);
display14.setText(a);
}
else if(e.getSource()==back14)
lay.show(this,"c13");
else if(e.getSource()==back13)
lay.show(this,"cb");
else if(e.getSource()==query_all) //全部课程查询
{
lay.show(this,"c6");
String sql="select * from Course";
a=Query_All(sql);
display6.setText(a);
}
else if(e.getSource()==back6)
lay.show(this,"cb");
else if(e.getSource()==delete_course) //删除课程
{
detele_name.setText("");
displayd.setText("");
lay.show(this,"cd");
}
else if(e.getSource()==deleted) //输入要删除课程的名字删除课程
{
String de_name=detele_name.getText();
a=Delete_Course(de_name);
displayd.setText(a);
final Frame frmFrame = new Frame();
JOptionPane.showMessageDialog(frmFrame, "课程删除成功!");
return;
}
else if(e.getSource()==backd)
lay.show(this,"cb");
else if(e.getSource()==student_loading) //学生登陆
{
userField.setText("");
passwordField.setText("");
lay.show(this,"c3");
}
else if(e.getSource()==back3)
lay.show(this,"ca");
else if(e.getSource()==loading3) //学生输入用户名和密码登陆
{
String Input_user=userField.getText();
String Input_password=passwordField.getText();
String sql4="select user_no,password from Regedit where user_no='"+Input_user+"' and password='"+Input_password+"'";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException e1){System.out.println("not found!");}
try
{
Connection con=DriverManager.getConnection(url,"",null);
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=stmt.executeQuery(sql4);
rs.last();
num=rs.getRow();
rs.beforeFirst();
stmt.close();
con.close();
}catch(SQLException ex){}
if(num!=0)
lay.show(this,"ce");
else
{
final Frame frmFrame = new Frame();
JOptionPane.showMessageDialog(frmFrame,"用户名或密码错!");
return;
}
}
else if(e.getSource()==look_course) //学生浏览课程
{
lay.show(this,"cf");
String sql_look="select * from Course";
a=Query_All(sql_look);
displayf.setText(a);
}
else if(e.getSource()==backf)
lay.show(this,"ce");
else if(e.getSource()==sc) //学生选课,显示课程信息
{
lay.show(this,"c5");
inputCno_Field.setText("");
String sql_sc="select * from Course";
a=Query_All(sql_sc);
display5.setText(a);
}
else if(e.getSource()==ok5)
{
String Inputno=inputCno_Field.getText();
String Input_user=userField.getText();
String Input_grade="";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException e1){System.out.println("not found!");}
try{
con=DriverManager.getConnection(url," ",null);
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sqladd_sc="INSERT INTO SC"+
" VALUES('"+Input_user+"','"+Inputno+"','"+Input_grade+"')";
stmt.executeUpdate(sqladd_sc);
stmt.close();
con.close();
}catch(SQLException ex){System.out.print(ex.getMessage());}
final Frame frmFrame = new Frame();
JOptionPane.showMessageDialog(frmFrame, "选课成功!");
lay.show(this,"c8");
String sql_displaysc="select * from SC,Course where SC.Sno='"+Input_user+"' and SC.Cno=Course.Cno";
a=Display_SC(sql_displaysc);
display8.setText(a);
return;
}
else if(e.getSource()==back8)
lay.show(this,"ce");
else if(e.getSource()==back5)
lay.show(this,"ce");
else if(e.getSource()==quit_sc)
{
lay.show(this,"c7");
quitCno_Field.setText("");
String Input_user=userField.getText();
String sql_displaysc="select * from SC,Course where SC.Sno='"+Input_user+"' and SC.Cno=Course.Cno";
a=Display_SC(sql_displaysc);
display7.setText(a);
}
else if(e.getSource()==ok7)
{
String quitno=quitCno_Field.getText();
a=Quit_Sc(quitno);
lay.show(this,"c8");
String Input_user=userField.getText();
String sql_displaysc="select * from SC,Course where SC.Sno='"+Input_user+"' and SC.Cno=Course.Cno";
a=Display_SC(sql_displaysc);
display8.setText(a);
}
else if(e.getSource()==back7)
lay.show(this,"ce");
else if(e.getSource()==QueryGrade) //学生查询自己的成绩
{
lay.show(this,"c19");
String Input_user=userField.getText();
String sql19="select Cname,Grade from Course,SC where Course.Cno=SC.Cno and Sno='"+Input_user+"'";
a=D_Grade(sql19);
display19.setText(a);
}
else if(e.getSource()==back19)
lay.show(this,"ce");
else if(e.getSource()==backe)
lay.show(this,"ca");
else if(e.getSource()==regedit)
{
lay.show(this,"c4");
R_userField.setText("");
R_passwordField.setText("");
R_userField.setText("");
R_realnameField.setText("");
R_deptField.setText("");
}
else if(e.getSource()==ok4) //填写注册信息
{
String use=R_userField.getText();
String word=R_passwordField.getText();
String no=R_userField.getText();
String name=R_realnameField.getText();
String dept=R_deptField.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException e1){System.out.println("not found!");}
try{
con=DriverManager.getConnection(url," ",null);
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sql2="INSERT INTO Regedit"+" VALUES('"+use+"','"+word+"')";
stmt.executeUpdate(sql2);
stmt.close();
con.close();
}catch(SQLException ex){System.out.print(ex.getMessage());}
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException e1){System.out.println("not found!");}
try{
con=DriverManager.getConnection(url," ",null);
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sql3="INSERT INTO Student"+" VALUES('"+no+"','"+name+"','"+dept+"')";
stmt.executeUpdate(sql3);
stmt.close();
con.close();
}catch(SQLException ex){System.out.print(ex.getMessage());}
final Frame frmFrame = new Frame();
JOptionPane.showMessageDialog(frmFrame, "注册成功!");
return;
}
else if(e.getSource()==back4)
lay.show(this,"c3");
else if(e.getSource()==allquery) //学生查看课程被选修的情况
{
lay.show(this,"c11");
String Input_user=userField.getText();
String sql_displayallsc="select Cname,count(Cname) number from SC,Course where SC.Cno=Course.Cno group by SC.Cno,Cname";
a=Lookfor_All(sql_displayallsc);
display11.setText(a);
}
else if(e.getSource()==back11)
lay.show(this,"ce");
else if(e.getSource()==myquery) //学生查看自己的选修情况
{
lay.show(this,"c12");
String Input_user=userField.getText();
String sql_displaysc="select * from SC,Course where SC.Sno='"+Input_user+"' and SC.Cno=Course.Cno";
a=Display_SC(sql_displaysc);
display12.setText(a);
}
else if(e.getSource()==back12)
lay.show(this,"ce");
else if(e.getSource()==onecourse) //查询选单个课程的所有学生
{
lay.show(this,"c15");
Cname_Field.setText("");
display15.setText("");
}
else if(e.getSource()==ok15)
{
String In_c=Cname_Field.getText();
String sql15="select Sname from Course,Student,SC where SC.Sno=Student.Sno and SC.Cno=Course.Cno and Cname='"+In_c+"'";
a=Query_c(sql15);
display15.setText(a);
}
else if(e.getSource()==back15)
lay.show(this,"c13");
else if(e.getSource()==onestudent) //查询单个学生选修的所有课程
{
lay.show(this,"c16");
Sname_Field.setText("");
display16.setText("");
}
else if(e.getSource()==ok16)
{
String In_s=Sname_Field.getText();
String sql16="select Cname from Course,Student,SC where SC.Sno=Student.Sno and SC.Cno=Course.Cno and Sname='"+In_s+"'";
a=Query_s(sql16);
display16.setText(a);
}
else if(e.getSource()==back16)
lay.show(this,"c13");
else if(e.getSource()==query_grade)
lay.show(this,"c20");
else if(e.getSource()==q_n)
lay.show(this,"c21");
else if(e.getSource()==ok21)
{
String In_qn=Sname_Grade.getText();
String sql21="select Cname,Grade from Course,SC,Student where Course.Cno=SC.Cno and Student.Sno=SC.Sno and Sname='"+In_qn+"'";
a=D_Grade(sql21);
display21.setText(a);
}
else if(e.getSource()==q_c)
lay.show(this,"c22");
else if(e.getSource()==ok22)
{
String In_qc=Cname_Grade.getText();
String sql22="select Sname,Grade from Course,SC,Student where Course.Cno=SC.Cno and Student.Sno=SC.Sno and Cname='"+In_qc+"'";
a=Query_qc(sql22);
display22.setText(a);
}
else if(e.getSource()==q_a)
{
lay.show(this,"c23");
String sql23="select Sname,Cname,Grade from Course,SC,Student where Course.Cno=SC.Cno and Student.Sno=SC.Sno";
a=Query_qa(sql23);
display23.setText(a);
}
else if(e.getSource()==back20)
lay.show(this,"cb");
else if(e.getSource()==back21)
lay.show(this,"c20");
else if(e.getSource()==back22)
lay.show(this,"c20");
else if(e.getSource()==back23)
lay.show(this,"c20");
}
public static void main(String[] e)
{
Frame x=new xuanke();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -