⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 administrator.java

📁 自己用java编的选课系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			if(sourse==queryButton[0]){
				System.out.println(order[0]);
				if(query[0].getText().equals(""))
					JOptionPane.showMessageDialog(null,"输入查询内容");
				else{
				try{
					for(int p=count[0]-1;p>=0;p--){
						m[0].removeRow(p);
					}
					res=stmt.executeQuery("select * from "+cha[0]+" where "+order[0]+"='"+query[0].getText()+"'");
				Vector vect=new Vector();
					while(res.next()){
					Vector v=new Vector();
					for(int j=0;j<5;j++)
			v.add(res.getString(xuexin[j]));
					vect.add(v);
				}
					o[0]=new Object[vect.size()][5];
					for(int i=0;i<vect.size();i++){
						Vector vvv=(Vector)vect.elementAt(i);
						m[0].addRow(vvv);
						for(int j=0;j<5;j++){
							o[0][i][j]=vvv.elementAt(j);
						}
					}
					index[0]=0;
					count[0]=vect.size();
					if(count[0]==0){
						JOptionPane.showMessageDialog(null,"没有相应记录");
						for(int i=0;i<5;i++){
							xinxi[0][i].setText("");
						}
					}else
					for(int i=0;i<5;i++){
						xinxi[0][i].setText(o[0][index[0]][i].toString());
					}
				}
				catch(SQLException se){
			  se.printStackTrace(System.out);
			 }
			}
			}
	else if(sourse==queryButton[1]){
		if(query[1].getText().equals(""))
			JOptionPane.showMessageDialog(null,"输入查询内容");
		else{
		try{
			for(int p=count[1]-1;p>=0;p--){
				m[1].removeRow(p);
			}
			res=stmt.executeQuery("select * from "+cha[1]+" where "+order[2]+"='"+query[1].getText()+"'");
		Vector vect=new Vector();
			while(res.next()){
			Vector v=new Vector();
			for(int j=0;j<5;j++)
	v.add(res.getString(jiaoshixin[j]));
			vect.add(v);
		}
			o[1]=new Object[vect.size()][5];
			for(int i=0;i<vect.size();i++){
				Vector vvv=(Vector)vect.elementAt(i);
				m[1].addRow(vvv);
				for(int j=0;j<5;j++){
					o[1][i][j]=vvv.elementAt(j);
				}
			}
			index[1]=0;
			count[1]=vect.size();
			if(count[1]==0){
				JOptionPane.showMessageDialog(null,"没有相应记录");
				for(int i=0;i<5;i++){
					xinxi[1][i].setText("");
				}
			}else
			for(int i=0;i<5;i++){
				xinxi[1][i].setText(o[1][index[1]][i].toString());
			}
		}
		catch(SQLException se){
	  se.printStackTrace(System.out);
	 }
		}
	}
	else if(sourse==queryButton[2]){
		if(query[2].getText().equals(""))
			JOptionPane.showMessageDialog(null,"输入查询内容");
		else{
		try{
			for(int p=count[2]-1;p>=0;p--){
				m[2].removeRow(p);
			}
			if(order[1].equals("学分"))
				res=stmt.executeQuery("select * from "+cha[2]+" where "+order[1]+"="+Integer.parseInt(query[2].getText())+"");
			else
			res=stmt.executeQuery("select * from "+cha[2]+" where "+order[1]+"='"+query[2].getText()+"'");
		Vector vect=new Vector();
			while(res.next()){
			Vector v=new Vector();
			for(int j=0;j<4;j++)
	v.add(res.getString(kechengxin[j]));
			vect.add(v);
		}
			o[2]=new Object[vect.size()][4];
			for(int i=0;i<vect.size();i++){
				Vector vvv=(Vector)vect.elementAt(i);
				m[2].addRow(vvv);
				for(int j=0;j<4;j++){
					o[2][i][j]=vvv.elementAt(j);
				}
			}
			index[2]=0;
			count[2]=vect.size();
			if(count[2]==0){
				JOptionPane.showMessageDialog(null,"没有相应记录");
				for(int i=0;i<4;i++){
					xinxi[2][i].setText("");
				}
			}else
			for(int i=0;i<4;i++){
				xinxi[2][i].setText(o[2][index[2]][i].toString());
			}
		}
		catch(SQLException se){
	  se.printStackTrace(System.out);
	 }
	}}
	else {
		for(int i=0;i<3;i++){
				if(sourse==Button[i][0]){
					if(index[i]==0)
						JOptionPane.showMessageDialog(null,"已经是第一条");
					else{
						index[i]--;
						if(i==2)
							for(int j=0;j<4;j++)
								xinxi[i][j].setText(o[i][index[i]][j].toString());
						else{
					for(int j=0;j<5;j++)
						xinxi[i][j].setText(o[i][index[i]][j].toString());
					}
					
					}
					
				}
				if(sourse==Button[i][1]){
					if(index[i]==count[i]-1)
						JOptionPane.showMessageDialog(null,"已经是最后一条");
					else{
						index[i]++;
						if(i==2)
							for(int j=0;j<4;j++)
								xinxi[i][j].setText(o[i][index[i]][j].toString());
						else
					for(int j=0;j<5;j++){
						xinxi[i][j].setText(o[i][index[i]][j].toString());
					}
					
					}
					
				}
			if(sourse==Button[i][2]){//添加
				try{
					res=stmt.executeQuery("select * from "+cha[i]+" where "+chaxun[i]+"='"+xinxi[i][0].getText()+"'");
					if(res.next())
						JOptionPane.showMessageDialog(null,"存在相同"+chaxun[i]+",不能添加");
					else{
						if(i!=2){
					String sss="insert into " +cha[i]+" values('"+xinxi[i][0].getText()+"','"
					+xinxi[i][1].getText()+"','"+xinxi[i][2].getText()+"',"+Integer.parseInt(xinxi[i][3].getText())+",'"
					+xinxi[i][4].getText()+"')";
					int geng=stmt.executeUpdate(sss);
					JOptionPane.showMessageDialog(null,"添加成功");
					for(int p=count[i]-1;p>=0;p--){
						m[i].removeRow(p);
					}
					gengxin(i);
					}
						else{
							String sss="insert into " +cha[i]+" values('"+xinxi[i][0].getText()+"','"
							+xinxi[i][1].getText()+"','"+xinxi[i][2].getText()+"',"+Integer.parseInt(xinxi[i][3].getText())+")";
							int geng=stmt.executeUpdate(sss);
							JOptionPane.showMessageDialog(null,"添加成功");
							for(int p=count[i]-1;p>=0;p--){
								m[i].removeRow(p);
							}
							gengxin(i);
							//m[i].addRow(new Object[]{xinxi[i][0].getText(),xinxi[i][1].getText(),xinxi[i][2].getText(),xinxi[i][3].getText(),xinxi[i][4].getText()});
						}
					}
				}catch(SQLException se){
					se.printStackTrace(System.out);
				}
			}
			if(sourse==Button[i][3]){//删除
				try{
					String sss="delete from " +cha[i]+" where "+chaxun[i]+"='"+xinxi[i][0].getText()+"'";
					int geng=stmt.executeUpdate(sss);
					JOptionPane.showMessageDialog(null,"删除成功");
					for(int p=count[i]-1;p>=0;p--){
						m[i].removeRow(p);
					}
					gengxin(i);
				if(i==0){//删除学生
					String ss="delete from xuanke where "+chaxun[i]+"='"+xinxi[i][0].getText()+"'";
					int gen=stmt.executeUpdate(ss);
				}
				else if(i==1){//删除教师
					String sh="select 课程号 from shouke where  教师号='"+xinxi[i][0].getText()+"'";
					res=stmt.executeQuery(sh);
					Vector vecto=new Vector();
					while(res.next()){
						vecto.add(res.getString("课程号"));
					}
					for(int p=0;p<vecto.size();p++){
						sh="delete from xuanke where 课程号='"+vecto.elementAt(p).toString()+"'";
						int shan=stmt.executeUpdate(sh);
						System.out.println(p);
					}
					String ss="delete from shouke where "+chaxun[i]+"='"+xinxi[i][0].getText()+"'";
					int gen=stmt.executeUpdate(ss);
					
				}
				else if(i==2){//删除课程
					String ss="delete from xuanke where "+chaxun[i]+"='"+xinxi[i][0].getText()+"'";
					int gen=stmt.executeUpdate(ss);
					ss="delete from shouke where "+chaxun[i]+"='"+xinxi[i][0].getText()+"'";
					 gen=stmt.executeUpdate(ss);
				}
				}catch(SQLException se){
					se.printStackTrace(System.out);
				}
			}
			if(sourse==Button[i][4]){
				try{
						if(i==0){
					String sss="update " +cha[0]+"  set 姓名='"
					+xinxi[i][1].getText()+"',性别='"+xinxi[i][2].getText()+"',年龄="+Integer.parseInt(xinxi[i][3].getText())+",系别='"
					+xinxi[i][4].getText()+"' where 学号='"+xinxi[i][0].getText()+"'";
					int geng=stmt.executeUpdate(sss);
					JOptionPane.showMessageDialog(null,"修改成功");
					for(int p=count[i]-1;p>=0;p--){
						m[i].removeRow(p);
					}
					gengxin(i);
					}
						else if(i==1){
							String sss="update " +cha[1]+"  set 姓名='"
							+xinxi[i][1].getText()+"',性别='"+xinxi[i][2].getText()+"',年龄="+Integer.parseInt(xinxi[i][3].getText())+",系别='"
							+xinxi[i][4].getText()+"' where 教师号='"+xinxi[i][0].getText()+"'";
							int geng=stmt.executeUpdate(sss);
							JOptionPane.showMessageDialog(null,"修改成功");
							for(int p=count[i]-1;p>=0;p--){
								m[i].removeRow(p);
							}
							gengxin(i);
						}
						else{
							String sss="update " +cha[i]+"  set 课程名='"
							+xinxi[i][1].getText()+"',先行课='"+xinxi[i][2].getText()+"',学分="+Integer.parseInt(xinxi[i][3].getText())
							+"where 课程号='"+xinxi[i][0].getText()+"'";
							int geng=stmt.executeUpdate(sss);
							JOptionPane.showMessageDialog(null,"修改成功");
							for(int p=count[i]-1;p>=0;p--){
								m[i].removeRow(p);
							}
							gengxin(i);
							}
						
				}catch(SQLException se){
					se.printStackTrace(System.out);
				}
			}
			
			
			
			
			
			
			
			
			
			
			
		}
		
	}
}
	public void gengxin(int i){
		query[i].setText("");
		Vector v1=new Vector();
		try{
			res=stmt.executeQuery("select * from "+cha[i]);
			while(res.next()){
				Vector v=new Vector();
				if(i==0)
				for(int j=0;j<5;j++){
					v.add(res.getString(xuexin[j]));
				}
				else if(i==1)
					for(int j=0;j<5;j++){
						v.add(res.getString(jiaoshixin[j]));
					}
				else if(i==2)
					for(int j=0;j<4;j++){
						v.add(res.getString(kechengxin[j]));
					}
				v1.add(v);
			}
			index[i]=0;
			count[i]=v1.size();
			if(i!=2)
			o[i]=new Object[count[i]][5];
			else
				o[i]=new Object[count[i]][4];
			for(int j=0;j<count[i];j++){
				Vector row=(Vector)v1.elementAt(j);
				m[i].addRow(row);
				for(int p=0;(p<5&&i!=2)||(p<4&&i==2);p++){
					o[i][j][p]=row.elementAt(p);
				}
			}
			
			for(int j=0;(j<5&i!=2)||(j<4&&i==2);j++){
				xinxi[i][j].setText((o[i][index[i]][j].toString()));
			}
		}catch(SQLException se){
			se.printStackTrace(System.out);
		}
	}

}
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -