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

📄 execute_button_action.java

📁 7、学生学籍管理系统 调查所在学校学生处、教务处
💻 JAVA
字号:
package file;

import java.util.ArrayList;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
/***
 * 
 * 本类为按钮事件的实现类
 * */
public class Execute_button_action {
	
private Operate_db op_db;//定义数据库连接类
	
	//构造函数
	public Execute_button_action()
	{
		op_db=new Operate_db();
	}
	/**
	 * @param f1 文本域对象
	 * 实现对删除功能
	 * */
	public void b1_Action(JTextField f1)
	{
		//学号的合法性校验
		boolean flag=true;
		String number=f1.getText();
		if(number==null || number.equals(""))
		{
			JOptionPane.showMessageDialog(null,"  请输入学号!");
			flag=false;
		}
		if(flag)
		{
			for(int i=0;i<number.length();i++)
			{
				if(number.charAt(i)>'9' || number.charAt(i)<'0')
					flag=false;
			}
			if(!flag)
			{
				JOptionPane.showMessageDialog(null,"  请正确输入学号!");
			}
		}
		if(flag)
		{
			if(!op_db.isFound(number))
			{
				flag=false;
				JOptionPane.showMessageDialog(null,"  没有该学生记录!");
			}
		}
		if(flag)
		{   //删除学号学生的所有记录
			int i=JOptionPane.showConfirmDialog(null,"你确认删除吗?请确认!!",null,JOptionPane.YES_NO_OPTION);
			if(i==0)
			{
				//delect
				if(op_db.del_s(number))
				{	
					f1.setText(null);
					JOptionPane.showMessageDialog(null,"  已删除!");
				}
				else
				{
					JOptionPane.showMessageDialog(null,"  删除失败!");
				}
			}
			else if(i==1)
			{
				//do noyhing
				f1.setText(null);
			}
			
		}
	}
	//
	
	/**
	 * 一个以取消的功能
	 * **/
	public void b2_Action()
	{

		ArrayList al=new ArrayList();
		al=op_db.get_dan_Hige();
		int math=(Integer)al.get(0);
		int chinese=(Integer)al.get(1);
		int english=(Integer)al.get(2);
		JOptionPane.showMessageDialog(null,"语文最高分:"+chinese+".\n数学最高分:"+math+".\n英语最高分:"+english+".");
	}
	
	//b3=new JButton("个高分");
	//b4=new JButton("个总分");
	//b5=new JButton("平均分");
	public void b3_Action()
	{
		op_db.getPerson1();
	}
	//
	public void b4_Action()
	{
		op_db.getSum();
	}
	public void b5_Action()
	{
		op_db.getAvg();	
	}
	//
	/**
	 * 实现对学生信息的添加
	 * */
	public void b6_Action(String number,String name,String chinese,String math,String english,String age,String s_class,String sex)
	{
		//check start
		boolean flag=true;//以下全部为输入数据的合法性判断
		int math1=0,chinese1=0,english1=0,age1=0;
		if(number==null || number.equals(""))
		{
			flag=false;
			JOptionPane.showMessageDialog(null,"   请输入学号!");
		}
		for(int i=0;i<number.length();i++)
		{
			if(number.charAt(i)>'9' || number.charAt(i)<'0')
			{
				flag=false;
			}
			if(!flag)
			{
				JOptionPane.showMessageDialog(null,"   请正确输入学号!");
				break;
			}
			
		}
		if(flag)
		{
			if(name==null || name.equals(""))
			{
				flag=false;
				JOptionPane.showMessageDialog(null,"   请正确输入姓名!");
			}
		}
		if(flag)
		{
			try
			{
				chinese1=Integer.parseInt(chinese);
				math1=Integer.parseInt(math);
				english1=Integer.parseInt(english);
			}
			catch(Exception e)
			{
				flag=false;
				JOptionPane.showMessageDialog(null,"   请正确输入成绩!");
			}
		}
		if(flag)
		{
			try
			{
				age1=Integer.parseInt(age);
			}
			catch(Exception e)
			{
				flag=false;
				JOptionPane.showMessageDialog(null,"   请正确输入年龄!");
			}
		}
		if(flag)
		{
			if(s_class==null || s_class.equals(""))
			{
				flag=false;
				JOptionPane.showMessageDialog(null,"   请输入班级!");
			}
		}
		
		//验证成功
		if(flag)
		{
			if(op_db.isFound(number))
			{
				JOptionPane.showMessageDialog(null,"    该学号已存在!");
			}
			else
			{
				//执行添加操作
				int i=JOptionPane.showConfirmDialog(null,"你确认添加吗?请确认!!",null,JOptionPane.YES_NO_OPTION);
				if(i==0)
				{
					op_db.insert_score(number,chinese1,math1,english1);
					op_db.insert_information(number,name,s_class,age1,sex);
					JOptionPane.showMessageDialog(null,"    添加学生记录成功!");
				}
			}
		}
		//if check ok ,insert
		
		//insert start
		
		//insert end
	}
	/**
	 * 实现对学生信息的修改
	 * */
	public void b8_Action(String number,String name,String age,String sex,String chinese,String math,String english,String s_class)
	{
		boolean flag=true;
		int s_age=0;
		int chinese1=0,math1=0,english1=0;
		if(name==null || name.equals(""))
		{
			flag=false;
			JOptionPane.showMessageDialog(null,"   请正确输入姓名!");
		}
		
		if(flag)
		{
			try
			{
				s_age=Integer.parseInt(age);
			}
			catch(Exception e)
			{
				flag=false;
				JOptionPane.showMessageDialog(null,"   请正确输入年龄!");
			}
		}
		
		
		if(flag)
		{
			try
			{
				chinese1=Integer.parseInt(chinese);
				math1=Integer.parseInt(math);
				english1=Integer.parseInt(english);
			}
			catch(Exception e)
			{
				flag=false;
				JOptionPane.showMessageDialog(null,"   请正确输入成绩!");
			}
		}
		if(flag)
		{
			if(s_class==null || s_class.equals(""))
			{
				JOptionPane.showMessageDialog(null,"请输入班级");
				flag=false;
			}
		}
		
		if(flag)
		{
			op_db.updateScore(number, chinese1, math1, english1);
			op_db.updateInformation(number,name,sex,s_class,s_age);
			JOptionPane.showMessageDialog(null,"       已完成修改!");
		}
		
	}
	//关闭数据库的链接
	public void close()
	{
		op_db.close();
	}

}

⌨️ 快捷键说明

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