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

📄 frmbrjfdb.java

📁 很全面的包括了住院管理的各项功能。如:管理员登录
💻 JAVA
字号:
package FrmBRJFDb;
import java.sql.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class FrmBRJFDb{
	
	public ResultSet rs = null;
    
    //定义数据库连接的字符串常量
    String dbDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String dbConn = "jdbc:odbc:Dbserver";
    
    Connection con;
    Statement stmt;	
	
	//进行数据库连接,返回是否连接失败
	public boolean getConnection(){
		try {
		//加载驱动程序
        Class.forName(dbDriver);
        //建立连接
        con = DriverManager.getConnection(dbConn);
        //关闭自动提交
        con.setAutoCommit(false);
        //设定事务级别        
        con.setTransactionIsolation(con.TRANSACTION_SERIALIZABLE);
        //创建一个JDBC声明
        stmt = con.createStatement();
        System.out.println("数据库连接成功");
        return false;
	    }
	    catch (Exception e) {
	    	System.out.println(e.getMessage());
        	e.printStackTrace();
        	return true;
	    }
	}
	
	//关闭数据库连接
	public void closeDB(){
		try{
			//在系统连接关闭之前,将所有未能及时提交的事务释放
			con.commit();
			//关闭连接
			if (!con.isClosed())
				con.close();
		}
		catch(SQLException se){
			System.out.print(se.getMessage());
			se.printStackTrace();
		}
	}
	
	//根据住院号取得病人姓名
	public String getname(String zyh){
		try{
			String strSQL;
			//先从出入院记录视图中找到当前住院号对应的病历号,再根据病历号从病人信息表中查出病人姓名
			strSQL="SELECT BRXM FROM BRXX WHERE BLH=(select BLH from RCYJL where ZYH='"+zyh+"')";
			rs = stmt.executeQuery(strSQL);
			//当有符合的记录时返回BRXM
			if(rs.next())
				return rs.getString("BRXM");
		}
		catch (SQLException e){
			System.out.println(e.getMessage());
			e.printStackTrace();
			//查询出错
		}
		//无记录,非法的住院号时
		return new String("查无此人!");		
	}
	
	//根据当前收费员,取得应上缴金额
	public float getysjje(){
		try{
			float ysjje=0;
			String strSQL;
			//从SFUser表中取得当前收费员,再从JFJL表中取得未结帐的记录金额合计
			strSQL="select JE from JFJL where SFY = (select UserID from SFUser where DQBJ='1') and JZRQ is null";
			rs = stmt.executeQuery(strSQL);
			while(rs.next()){				
				//取出金额累加
				ysjje+=rs.getFloat("JE");
			}
			return ysjje;
		}
		catch (SQLException e){
			System.out.println(e.getMessage());
			e.printStackTrace();
			return -1;
			//查询出错
		}
	}
	
	//取得当前收费员
	public String getUserID(){
		try{
			String strSQL;
			//查询SFUser表中当前标记为1记录,取出UserID
			strSQL="select UserID from SFUser where DQBJ='1'";
				rs = stmt.executeQuery(strSQL);	
				if(rs.next())
					return rs.getString("UserID");
				return new String("无登录用户");							
			}
		catch (SQLException e){
			System.out.println(e.getMessage());
			e.printStackTrace();
			return new String("出错");
		}		
	}
	
	//取得当前病人的缴费合计
	public float getjfhj(String zyh){
		try{
			float jfhj=0;
			String strSQL;
			//从JFJL表中查询当前病人的缴费记录,取出金额并累加
			strSQL="select JE from JFJL where ZYH='"+zyh+"'";
			rs = stmt.executeQuery(strSQL);
			while(rs.next()){
				jfhj+=rs.getFloat("JE");
			}
			//返回合计值
			return jfhj;
		}
		catch (SQLException e){
			System.out.println(e.getMessage());
			e.printStackTrace();
			return -1;
			//查询出错
		}
	}
	
	//取得当前病人的费用合计
	public float getfyhj(String zyh){
		try{
			float fyhj=0;
			String strSQL;
			//从视图View_WJZFY中查询当前病人的费用记录,取出单价乘以数量和自费比例再累加
			strSQL="select DJ,SL,ZFBL from View_WJZFY where ZYH='"+zyh+"'";
			rs = stmt.executeQuery(strSQL);
			while(rs.next()){
				fyhj+=rs.getFloat("DJ")*rs.getFloat("SL")*rs.getFloat("ZFBL")/100;
			}
			return fyhj;
		}
		catch (SQLException e){
			System.out.println(e.getMessage());
			e.printStackTrace();
			return -1;
			//查询出错
		}
	}
	
	//根据参数lx取得表格内容,不需要住院号的情况
	public void getTableItem(int lx){		
		switch(lx){
			case 1://当类型为1时,表示表格内容为显示当前收费员应上缴明细
				String strSQL;
				//取出JFJL表中未结帐的记录
				strSQL="select * from JFJL where SFY = (select UserID from SFUser where DQBJ='1') and JZRQ is null";				
				try{
					rs = stmt.executeQuery(strSQL);							
				}
				catch (SQLException e){
					System.out.println(e.getMessage());
					e.printStackTrace();
					//查询出错
				}
				break;
		}
        
	}
	
	//根据住院号和类型取得表格内容
	public void getTableItem(int lx,String zyh){
		String strSQL;
		switch(lx){
			case 2://类型为2表示表格内容为当前病人未结帐的缴费明细
				strSQL="select * from JFJL where ZYH='"+zyh+"' and JZRQ is null";
				try{
					rs = stmt.executeQuery(strSQL);						
				}
				catch (SQLException e){
					System.out.println(e.getMessage());
					e.printStackTrace();
					//查询出错
				}
				break;
			case 3://类型为3表示表格内容为当前病人的未结帐的费用发生情况
				strSQL="select * from View_WJZFY where ZYH='"+zyh+"'";
				try{
					rs = stmt.executeQuery(strSQL);		
				}
				catch (SQLException e){
					System.out.println(e.getMessage());
					e.printStackTrace();
					//查询出错
				}
				break;	
		}
	}
	
	//提交数据,返回是否插入成功
	public boolean update(String zyh,String jfxs,String sfy,float je){
		try{//插入到JFJL表的前五列,后两列为空。时间为数据库的当前时间
			String strSQL="INSERT INTO [ZYSF].[dbo].[JFJL]([ZYH], [JFRQ], [JFXS], [SFY], [JE])VALUES('"+zyh+"', GETDATE(), '"+jfxs+"', '"+sfy+"',"+je+")";
			stmt.execute(strSQL);
			//事物提交
			con.commit();
			return true;
		}
		catch (SQLException e){
			System.out.println(e.getMessage());
			e.printStackTrace();
		    return false;
		}	
	}
	
	//检查住院号是否存在
	public boolean checkzyh(String zyh){
		String strSQL="select BLH from RCYJL where ZYH='"+zyh+"'";
		try{//查询RCYJL表中是否存在ZYH为输入住院号的记录
			rs=stmt.executeQuery(strSQL);
			if(rs.next())
				return true;
			return false;	
		}
		catch (SQLException e){
			System.out.println(e.getMessage());
			e.printStackTrace();
		    return false;
		}		
	} 
}

⌨️ 快捷键说明

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