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

📄 util.java

📁 这是本人曾经在公司里用的,内部开发框架,基于struts+hibernate今天分享给大家
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	//通讯录
	public static testtree getTesttreeObject(HttpServletRequest req, String id)
			throws BwayHibernateException, BwayException {
		testtree d = new testtree();
		Session sess;
		try {
			sess = HibernateSessionFactory.currentSession();
			d = (testtree) sess.get(testtree.class, id);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			HibernateSessionFactory.closeSession();
		}
		return d;
	}	
	
	//如果访目录不存在则创建
	public static void oprdrictory(String path) {
		try {
			File f3 = new File(path);
			if (f3.exists()) {
				System.out.println("该文件夹存在");
			} else {
				System.out.println("不存在该文件夹");
				f3.mkdir();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	//改变函数
	public static String getNewChangeStr(String theNum) {
		System.out.println("theNum:  " + theNum);
		String oneNum = "";
		String make = "";
		int len = theNum.length();
		for (int i = 0; i < len; i++) {
			oneNum = theNum.substring(i, i + 1);
			if ("��".equals(oneNum)) {
				oneNum = ".";
			}
			make = make + oneNum;
		}
		System.out.println("make:  " + make);
		return make;
	}
	
	//判断是否有查看文件夹的权限
	public static boolean folderIsShare(HttpServletRequest request,
			Connection conn) throws BwayHibernateException, BwayException {
		boolean isShare = false;
		String sql = "";
		String id = "";
		String staffname = "";
		ResultSet rs = null;
		HttpSession session = request.getSession();
		try {
			staffname = (String) session
					.getAttribute(LoginConstants.GLOBLE_STAFF_NAME);
			id = request.getParameter("id");
			sql = "select * from sharefolder where staffname='" + staffname
					+ "' and folderid='" + id + "' ";
			rs = conn.createStatement().executeQuery(sql);
			if (rs.next()) {
				isShare = true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (null != rs) {
					rs.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return isShare;
	}

	//共享文件夹
	public static List getShareFolderList(HttpServletRequest request)
			throws BwayHibernateException, BwayException {
		List lst = new ArrayList();
		ResultSet rs = null;
		Session sess;
		Folders e = null;
		Connection conn = null;
		String sql = "";
		try {
			sess = HibernateSessionFactory.currentSession();
			conn = sess.connection();
			
			sql = "select * from folders where isshare='1' ";
			System.out.println("the share sql:   " + sql);
			rs = conn.prepareStatement(sql).executeQuery();
			while (rs.next()) {
				e = new Folders();
				e.setId(String.valueOf(rs.getInt("id")));
				e.setMenuid(rs.getString("menuid"));
				e.setMunefatherid(rs.getString("munefatherid"));
				e.setMenuname(rs.getString("menuname"));
				e.setStaffname(rs.getString("staffname"));
				
				lst.add(e);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			try {
				if (null != conn) {
					conn.close();
				}
				if (null != rs) {
					rs.close();
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			HibernateSessionFactory.closeSession();
		}
		return lst;
	}

	//求出共享人
	public static String getShareManList(HttpServletRequest request,String id
						)throws BwayHibernateException, BwayException {
		ResultSet rs = null;
		Session sess;
		Connection conn = null;
		String staffnamelist="";
		String sql = "";
		try {
			sess = HibernateSessionFactory.currentSession();
			conn = sess.connection();
			
			sql = "select * from sharefolder where folderid ='"+id+"' ";
			rs = conn.prepareStatement(sql).executeQuery();
			while(rs.next()) {
				staffnamelist = staffnamelist+ ","+ rs.getString("staffname");
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			try {
				if (null != conn) {
					conn.close();
				}
				if (null != rs) {
					rs.close();
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			HibernateSessionFactory.closeSession();
		}
		return staffnamelist;
	}

	//判断是否已添加
	public static boolean checkfolder(Connection conn,String id,String staffname
						)throws BwayHibernateException, BwayException {
		ResultSet rs = null;
		String sql="";			
		boolean ishavefolders = false;
		try{
			sql="select * from sharefolder where staffname='"+staffname+"' and folderid='"+id+"'  ";
			rs = conn.prepareStatement(sql).executeQuery();
			if(rs.next()) {
				ishavefolders=true;
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally {
			try {
				if (null != rs) {
					rs.close();
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
		return ishavefolders;
	}
	
	
	//获得值班表所有的ID号
	public static String getDutyNameList(Connection conn,String dutyid
					)throws BwayHibernateException, BwayException {
		String listname ="";
		String sql="";
		ResultSet rs = null;
		Staffinfo s =null;
		try{
			sql="select * from staffduty where dutyid ='"+dutyid+"' ";
			rs = conn.prepareStatement(sql).executeQuery();
			while(rs.next()) {
				s = new Staffinfo();
				String staffname = rs.getString("staffname");
				
				listname = listname + "," + staffname;
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally {
			try {
				if (null != rs) {
					rs.close();
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
		return listname;
	}
	
	//删除所有值班用户
	public static void deleteDuty(Connection conn,String dutyid
					)throws BwayHibernateException, BwayException {
		String sql="";
		try{
			sql="delete from staffduty where dutyid ='"+dutyid+"' ";
			conn.createStatement().executeUpdate(sql);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	//短信详细内容
	public static List getMsmContantList(HttpServletRequest request,String msmaotuid
			)throws BwayHibernateException, BwayException {
		List lst=new ArrayList();
		ResultSet rs = null;
		PreparedStatement stat = null;
		Session sess;
		Connection conn=null;
		String sql="";
		String msmMan="";
		String msmContant="";
		String msmTime="";
		try{
			sess = HibernateSessionFactory.currentSession();
			conn=sess.connection();
			conn.setAutoCommit(false);
			
			//短信所发送的人
			sql="select * from staffownemsm where mobilemsnid ='"+msmaotuid+"' ";
			rs=conn.createStatement().executeQuery(sql);
			while(rs.next()){
				msmMan=msmMan+","+rs.getString("staffname");
			}
			lst.add(0,msmMan);
			
			//短信内容
			sql="select * from mobilemsm where automsnid ='"+msmaotuid+"' ";
			rs=conn.createStatement().executeQuery(sql);
			if(rs.next()){
				msmContant=rs.getString("msmcontent");
				msmTime=rs.getString("adddate");
			}
			lst.add(1,msmContant);
			lst.add(2,msmTime);
			
			conn.commit();
		}catch(Exception ex){
			ex.printStackTrace();
		} finally {
			try {
				if(null !=conn){
					conn.close();
				}
				if(null !=rs){
					rs.close();
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			HibernateSessionFactory.closeSession();
		}
		return lst;
	}
	
	public static String getManageMailName(HttpServletRequest 
			request,String id)throws BwayHibernateException, BwayException {
		String filename="";
		String sql="";
		Session sess=null;
		Connection conn=null;
		ResultSet rs = null;
		try{
			sess = HibernateSessionFactory.currentSession();
			conn=sess.connection();
			sql="select filename from manageremail where id='"+id+"' ";
			rs=conn.createStatement().executeQuery(sql);
			if(rs.next()){
				filename=rs.getString("filename");
			}
		}catch(Exception e){
			e.printStackTrace();
		} finally {
			try {
				if(null !=conn){
					conn.close();
				}
				if(null !=rs){
					rs.close();
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			HibernateSessionFactory.closeSession();
		}
		return filename;
	}
	
	public static String getFileName(HttpServletRequest 
			request,String id)throws BwayHibernateException, BwayException {
		String filename="";
		String sql="";
		Session sess=null;
		Connection conn=null;
		ResultSet rs = null;
		try{
			sess = HibernateSessionFactory.currentSession();
			conn=sess.connection();
			sql="select filename from personfolder where id='"+id+"' ";
			rs=conn.createStatement().executeQuery(sql);
			if(rs.next()){
				filename=rs.getString("filename");
			}
		}catch(Exception e){
			e.printStackTrace();
		} finally {
			try {
				if(null !=conn){
					conn.close();
				}
				if(null !=rs){
					rs.close();
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			HibernateSessionFactory.closeSession();
		}
		return filename;
	}
		
	
	public static String geWorkFileName(HttpServletRequest 
			request,String id)throws BwayHibernateException, BwayException {
		String filename="";
		String sql="";
		Session sess=null;
		Connection conn=null;
		ResultSet rs = null;
		try{
			sess = HibernateSessionFactory.currentSession();
			conn=sess.connection();
			sql="select filename from staffworkplan where id='"+id+"' ";
			rs=conn.createStatement().executeQuery(sql);
			if(rs.next()){
				filename=rs.getString("filename");
			}
		}catch(Exception e){
			e.printStackTrace();
		} finally {
			try {
				if(null !=conn){
					conn.close();
				}
				if(null !=rs){
					rs.close();
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			HibernateSessionFactory.closeSession();
		}
		return filename;
	}
	
	public static String getNoteNewsName(HttpServletRequest 
			request,String id)throws BwayHibernateException, BwayException {
		String filename="";
		String sql="";
		Session sess=null;
		Connection conn=null;
		ResultSet rs = null;
		try{
			sess = HibernateSessionFactory.currentSession();
			conn=sess.connection();
			sql="select filename from noticeinfo where id='"+id+"' ";
			rs=conn.createStatement().executeQuery(sql);
			if(rs.next()){
				filename=rs.getString("filename");
			}
		}catch(Exception e){
			e.printStackTrace();
		} finally {
			try {
				if(null !=conn){
					conn.close();
				}
				if(null !=rs){
					rs.close();
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			HibernateSessionFactory.closeSession();
		}
		return filename;
	}
	
	
	public static String getPersonPlanName(HttpServletRequest 
			request,String id)throws BwayHibernateException, BwayException {
		String filename="";
		String sql="";
		Session sess=null;
		Connection conn=null;
		ResultSet rs = null;
		try{
			sess = HibernateSessionFactory.currentSession();
			conn=sess.connection();
			sql="select filename from personworkplan where id='"+id+"' ";
			rs=conn.createStatement().executeQuery(sql);
			if(rs.next()){
				filename=rs.getString("filename");
			}
		}catch(Exception e){
			e.printStackTrace();
		} finally {
			try {
				if(null !=conn){
					conn.close();
				}
				if(null !=rs){
					rs.close();
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			HibernateSessionFactory.closeSession();
		}
		return filename;
	}
	
	
	public static String getStaffPlanName(HttpServletRequest 
			request,String id)throws BwayHibernateException, BwayException {
		String filename="";
		String sql="";
		Session sess=null;
		Connection conn=null;
		ResultSet rs = null;
		try{
			sess = HibernateSessionFactory.currentSession();
			conn=sess.connection();
			sql="select filename from staffworkplan where id='"+id+"' ";
			rs=conn.createStatement().executeQuery(sql);
			if(rs.next()){
				filename=rs.getString("filename");
			}
		}catch(Exception e){
			e.printStackTrace();
		} finally {
			try {
				if(null !=conn){
					conn.close();
				}
				if(null !=rs){
					rs.close();
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			HibernateSessionFactory.closeSession();
		}
		return filename;
	}
	
	
	//工作日志下载
	public static String getWorklogFile(HttpServletRequest 
			request,String id)throws BwayHibernateException, BwayException {
		String filename="";
		String sql="";
		Session sess=null;
		Connection conn=null;
		ResultSet rs = null;
		try{
			sess = HibernateSessionFactory.currentSession();
			conn=sess.connection();
			sql="select filename from worklog where id='"+id+"' ";
			rs=conn.createStatement().executeQuery(sql);
			if(rs.next()){
				filename=rs.getString("filename");
			}
		}catch(Exception e){
			e.printStackTrace();
		} finally {
			try {
				if(null !=conn){
					conn.close();
				}
				if(null !=rs){
					rs.close();
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			HibernateSessionFactory.closeSession();
		}
		return filename;
	}	
	
	
	
	
	
	
	
	
	
	
}

⌨️ 快捷键说明

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