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

📄 classmagdialog.java

📁 学生管理系统。使用java编程
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				bisRight = false;
				JOptionPane.showMessageDialog(this, "专业号为"
						+ newclass.getMajorId() + "的专业不存在,请重输!");
			}
		}

		// 如果不与其它表关联向数据库写入数据
		if (bisRight) {
			// 创建SQL语句
			strSQL = "update classes set" 
				+" TeacherId = "+newclass.getTeacherId()
				+", MajorId = "+newclass.getMajorId()
				+" , ClassName = '"+ newclass.getClassName()
				+"', StuNum = "+newclass.getStuNum()
				+" , FlagYear ='" +newclass.getFlagYear()
				+"'  where ClassId = "
				+newclass.getClassId();

			// 执行SQL语句
			try {
				updateLine = jdbcConnection.updateData(strSQL);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			if (updateLine > 0) {
				System.out.println(updateLine);
				bisUpdated  = true;
			} else {
				bisUpdated = false;
			}
		}
		return bisUpdated;
	}
	
	/**
	 * 初始化班级表
	 * @throws SQLException
	 */
	private void initTable()  {
		// 建立一个JDBC对象
		JdbcConnct jdbcConnection = new JdbcConnct();
		// 定义Vector变量,存储从数据库查询来的信息
		Vector vecData = new Vector();
		// 定义SQL语句
		String strSQL = "select * from teach_clas_maj_view order by ClassId ASC";

		ClassQueryTableModel = new DefaultTableModel(row, column);
		this.ClassQueryTable.setModel(ClassQueryTableModel);
		BorderLayout tableHeaderLayout = new BorderLayout();
		ClassQueryTable.getTableHeader().setLayout(tableHeaderLayout);
		ClassQueryTable.getTableHeader().setPreferredSize(
				new java.awt.Dimension(481, 12));
		// this.CourseQueryTable.setRowMargin(20);
		// 获得数据
		try{
			vecData = jdbcConnection.getData(strSQL);		
		}catch(SQLException e){
			e.printStackTrace();
		}
		// 依次为各行插入数据
		if(vecData.size() > 0){
			for (int i = 0; i < vecData.size(); i++) {
				ClassQueryTableModel.addRow((String[]) vecData.get(i));
			}
			// 显示班级信息
			this.ClassMagTabbedPane.setSelectedComponent(this.DataViewPanel1);
		}else{
			JOptionPane.showMessageDialog(this, "班级信息表中没有记录!请为班级信息表增加信息.");
		}
	}
	
	/**
	 * 获取用户点击数据
	 * @param  Class类对象 newclass
	 * @return Class类对象 newclass
	 */
	private Class getMouseClickData(Class newclass){
		// 定义变量 班级名、班级号、班主任ID、专业号、学生人数、界别
		String strclassId = "";
		String strclassName = "";
		String[] strteacherID = new String[1];
		String strmajorID  = "";
		String strstuNum = "";
		String strFlagYear = "";

		int nclassId = 0;
		int nteacherID = 0;
		int nmajorID = 0;
		int nstuNum = 0;
		int nFlagYear = 0;
		// 定义鼠标点击行
		int nrow = 0;

		// 获取鼠标点击行
		nrow = this.ClassQueryTable.getSelectedRow();
		// 获取行内数据
		strclassId      =  String.valueOf(this.ClassQueryTable.getValueAt(nrow, 0));
		strclassName    =  String.valueOf(this.ClassQueryTable.getValueAt(nrow, 1));
		strteacherID[0] =  String.valueOf(this.ClassQueryTable.getValueAt(nrow,2));
		strmajorID      =  String.valueOf(this.ClassQueryTable.getValueAt(nrow, 4));
		strstuNum       =  String.valueOf(this.ClassQueryTable.getValueAt(nrow, 6));
		strFlagYear     =  String.valueOf(this.ClassQueryTable.getValueAt(nrow, 7));

		// 类型转换
		try {
			nclassId = Integer.parseInt(strclassId);
			nteacherID = Integer.parseInt(strteacherID[0]);
			nmajorID   = Integer.parseInt(strmajorID); 
			nstuNum = Integer.parseInt(strstuNum);
			nFlagYear = Integer.parseInt(strFlagYear);

		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		// 初始化Class对象
		newclass.setValue(nclassId, strclassName, nteacherID, nmajorID, nstuNum,
				nFlagYear);
		
		return newclass;
	}
	
	/**
	 * 初始化为班级分配学生对话框已选学生表
	 * @param stuMatchClassDialog 为班级分配学生Dialog对象 
	 * @return 初始化是否成功 bisRight
	 */
	private boolean initSelectedStudentTable(StuMatchClassDialog stuMatchClassDialog){
		// 定义boolean型变量bisRight,表格初始化是否成功
		boolean bisRight = false;
		// 建立一个JDBC对象
		JdbcConnct jdbcConnection = new JdbcConnct();
		// 定义Vector变量,存储从数据库查询来的信息
		Vector vecData = new Vector();
		// 定义SQL语句
		String strSQL = "";
		//定义已选学生人数
		String strselectedStuNum = "";
		
		//组合SQL语句
		strSQL = "select  StudentId, StuName, gender , age ,BirthDay,ClassId,  EnterTime " +
		"from student " + "where ClassId = " +stuMatchClassDialog.classIdViewLabel.getText()
		+" order by StudentId ASC";		

		stuMatchClassDialog.SelectStuTableModel = new DefaultTableModel(stuMatchClassDialog.row, 
				stuMatchClassDialog.columnStudent);
		stuMatchClassDialog.SelectStuTable.setModel(stuMatchClassDialog.SelectStuTableModel);

		// 获得数据
		try{
			vecData = jdbcConnection.getData(strSQL);		
		}catch(SQLException e){
			e.printStackTrace();
		}
		// 依次为各行插入数据
		if(vecData.size() > 0){
			//获得班级已选学生人数
			stuMatchClassDialog.nselectedStuNum = vecData.size();
			strselectedStuNum = String.valueOf(stuMatchClassDialog.nselectedStuNum);
			bisRight = true;
			for (int i = 0; i < vecData.size(); i++) {
				stuMatchClassDialog.SelectStuTableModel.addRow((String[]) vecData.get(i));
			}
			//显示班级已选学生人数
			stuMatchClassDialog.selectedStuNumLabel.setText(strselectedStuNum);
		}else{
			bisRight = false;
			JOptionPane.showMessageDialog(this, "班级信息表中没有学生!请为班级信息表增加学生.");
		}		
		return bisRight;
	}
	/**
	 * Class类,用于存储班级信息
	 * 
	 * @author Administrator
	 * 
	 */
	class Class {
		// 定义Class类属性,班级号、班级名、班主任ID、班主任名、学生人数、
		//届别、专业号、专业名
		private int nClassId;

		private String strClassName;

		private int nTeacherId;
		
		private String strTheacherName;

		private int nStuNum;

		private int nFlagYear;
		
		private int nMajorId;
		
		private String strMajorName;
		

		/**
		 * Class类含参构造函数
		 * 
		 * @param nClassId
		 * @param strClassName
		 * @param nTeacherId
		 * @param nStuNum
		 * @param nFlagYear
		 */
		public Class(int nClassId, String strClassName, int nTeacherId,
				int nStuNum, int nFlagYear) {
			this.nClassId        = nClassId;
			this.strClassName    = strClassName;
			this.nTeacherId      = nTeacherId;
			this.strTheacherName = "";
			this.nStuNum         = nStuNum;
			this.nFlagYear       = nFlagYear;
			this.nMajorId        = 0;
			this.strMajorName    = "";
		}

		/**
		 * Class类无参构造函数,变量初始化为空或0
		 * 
		 */
		public Class() {
			this.nClassId = 0;
			this.strClassName = "";
			this.nTeacherId = 0;
			this.strTheacherName = "";
			this.nStuNum = 0;
			this.nFlagYear = 0;
		}

		/**
		 * 属性器setClassId(),为ClassId赋值
		 * 
		 * @param nClassId
		 */
		public void setClassId(int nClassId) {
			this.nClassId = nClassId;
		}

		/**
		 * 属性器setClassName(),为ClassName赋值
		 * 
		 * @param strClassName
		 */
		public void setClassName(String strClassName) {
			this.strClassName = strClassName;
		}

		/**
		 * 属性器setTeacherId(),为TeacherId赋值
		 * 
		 * @param nTeacherId
		 */
		public void setTeacherId(int nTeacherId) {
			this.nTeacherId = nTeacherId;
		}
		/**
		 *属性器setTeacherName(),为TeacherName赋值 
		 * @param strTeacherName
		 */
		public void setTeacherName(String strTeacherName) {
			this.strTheacherName = strTeacherName;
		}
		

		/**
		 * 属性器setStuNum(),为StuNum赋值
		 * 
		 * @param nStuNum
		 */
		public void setStuNum(int nStuNum) {
			this.nStuNum = nStuNum;
		}
        /**
         * 属性器setFlagYear(),为FlagYear赋值
         * @param nFlagYear
         */
		public void setFlagYear(int nFlagYear) {
			this.nFlagYear = nFlagYear;
		}
		
		/**
		 * 属性器setMajorId(),为MajorId赋值
		 * @param nMajorId
		 */
		public void setMajorId(int nMajorId) {
			this.nMajorId = nMajorId;
		}
		
		/**
		 * 属性器setMajorName(),为MajorName赋值
		 * @param strMajorName
		 */
		public void setMajorName(String strMajorName) {
			this.strMajorName = strMajorName;
		}

		/**
		 * 属性器getClassId(),返回ClassId
		 * 
		 * @return
		 */
		public int getClassId() {
			return this.nClassId;
		}

		/**
		 * 属性器getClassName()
		 * 
		 * @return 返回String型 ClassName
		 */
		public String getClassName() {
			return this.strClassName;
		}

		/**
		 * 属性器getTeacherId()
		 * 
		 * @return 返回int型 TeacherId
		 */
		public int getTeacherId() {
			return this.nTeacherId;
		}
		
		/**
		 *  属性器getTeacherName()
		 * @return 返回String型变量 TeacherName
		 */
		public String getTeacherName() {
			return this.strTheacherName;
		}
		

		/**
		 * 属性器getStuNum()
		 * 
		 * @return 返回int型 StuNum
		 */
		public int getStuNum() {
			return this.nStuNum;
		}

		/**
		 * 属性器getFlagYear()
		 * 
		 * @return 返回int型 FlagYear
		 */
		public int getFlagYear() {
			return this.nFlagYear;
		}

		/**
		 * 属性器getFlagYear()
		 * @return int型 MajorId
		 */
		public int getMajorId() {
			return this.nMajorId;
		}
		
		/**
		 * 属性器getMajorName()
		 * @return String型 MajorName
		 */
		public String getMajorName() {
			return this.strMajorName;
		}
		
		/**
		 * 属性器setValue(),为class类属性赋值
		 * 
		 * @param nClassId
		 *            班级号
		 * @param strClassName
		 *            班级姓名
		 * @param nTeacherId
		 *            教师ID
		 * @param nMajorId
		 *            专业号           
		 * @param nStuNum
		 *            学生人数
		 * @param nFlagYear
		 *            届别
		 */
		public void setValue(int nClassId, String strClassName, int nTeacherId,
				int nmajorId, int nStuNum, int nFlagYear) {
			this.nClassId = nClassId;
			this.strClassName = strClassName;
			this.nTeacherId = nTeacherId;
			this.nMajorId   = nmajorId;
			this.nStuNum = nStuNum;
			this.nFlagYear = nFlagYear;
		}

	}

}

⌨️ 快捷键说明

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