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

📄 authenticationmanager.java

📁 旅游自助系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     */
    public static boolean cancelSubmit(String email, Long groupId){
    	Client client = null;
		TravelGroup group = null;
		try {
			client = (Client) CacheManager.getByEmail(email);
			/* group = (TravelGroup) CacheManager.getByUnique(ObjectType.GROUP, "name", name);*/
			group = (TravelGroup) CacheManager.getById(groupId);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
    	client.removeGroup(group);
    	
    	String sql = "delete from group2client where groupId=" + groupId + " and clientId=" + client.getId();
    	try {
			DbManager.excute(sql);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
		return true;
    }
    
    
    
    
    //the following part is about corperation
    
    
    
    
    /**
     *the following method needed by youqi's code
     *used when the corperation registes 
     *you need to insert these informatin into the database
     *return true if succeded
	 *else return false
	 */
    public static boolean corpRegistry(String email,String password,
                                         String name,String address,
                                               String description){
    	List<String> names = new ArrayList<String>();
		List<Integer> types = new ArrayList<Integer>();
		
		names.add("id");
		types.add(Types.BIGINT);
		names.add("email");
		types.add(Types.VARCHAR);
		names.add("password");
		types.add(Types.VARCHAR);
		names.add("name");
		types.add(Types.VARCHAR);
		names.add("address");
		types.add(Types.VARCHAR);
		names.add("description");
		types.add(Types.VARCHAR);
		
		ColumnInfo info = null;
		try {
			info = new ColumnInfo(names, types);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}

		Long id;
		try {
			id  = IdGenerationFactory.generateId(ObjectType.CORP);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return false;
		} catch (DBTableFullException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return false;
		}
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("email", email);
		map.put("password", password);
		map.put("name", name);
		map.put("address", address);
		map.put("description", description);
		TableRow row = new TableRow("travelcorp", map, info);
		try {
			DbManager.insert(row);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
		return true;    	
    }
    
    /**
     * the following method needed by youqi's code
     *used when the corperation logins 
     *you need to  validate these informatin by querying  the database
     *return true if succeded
	 *else return false
	 * 
	 * @param email
	 * @param password
	 * @return
     * @throws DBLockedException 
	 */
    public static boolean corpLogin(String email,String password){
		try{
			if(authenticatePassword(email, password) == AuthState.SUCCESS){
				return true;
			}
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
		return false;
    }
    
    /**
     * the following method needed by youqi's code
     *return all the information of TravlGroup  named name in the corp to 
     *the collcetion of Vector  by querying the database
     *if the parameter name equals null,then return the informaion of all the TravlGroups of this corp
     *return null if failure
     * 
     * @param corpEmail
     * @param name
     * @return
     * @throws SQLException 
     * @throws DBLockedException 
     */
    public static Vector searchGroups(String corpEmail, String name) {
		try {
			Vector<TravelGroup> groups = new Vector<TravelGroup>();
			TravelCorp corp = (TravelCorp) CacheManager.getByEmail(corpEmail);

			String sql = "select groupId from corp2group where corpId=" + corp.getId() + ";";
			TableRowIterator iterator = DbManager.query(sql);

			TravelGroup group = null;
			while (iterator.hasNext()) {
				TableRow row = iterator.next();
				Long id = Long.valueOf(row.getColumn("groupId").toString());
				group = (TravelGroup) CacheManager.getById(id);
				if (name == null) {
					groups.add(group);
				} else {
					if (name.equals(group.getName())) {
						groups.add(group);
					}
				}
			}

			return groups;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
    
    /**
     * the following method needed by youqi's code
     *delete the travlGroup named the parameter name to the corp  of email 
     *return true if succeded
     *else return false
     * 
     * @param corpEmail
     * @param name
     * @return
     * @throws DBLockedException 
     * @throws SQLException 
     */
    
    public static boolean cancelGroup(String corpEmail,String name){
    	try {
			TravelCorp corp = (TravelCorp) CacheManager.getByEmail(corpEmail);

			String sql = "select groupId from corp2group where corpId=" + corp.getId() + ";";
			TableRowIterator iterator = DbManager.query(sql);

			TravelGroup group = null;
			while (iterator.hasNext()) {
				TableRow row = iterator.next();
				Long id = Long.valueOf(row.getColumn("groupId").toString());
				group = (TravelGroup) CacheManager.getById(id);
				if (group.getName().equals(name)) {
					List<Client> clients = group.getAllClients();
					Client client = null;
					sql = "delete from group2client where clientId={0} and groupId={1};";
					for(Iterator i = clients.iterator(); i.hasNext(); ){
						client = (Client) i.next();
						client.removeGroup(group);
						sql = MessageFormat.format(sql, new Object[]{client.getId(), group.getId()});
						DbManager.excute(sql);
					}
					corp.removeGroup(group);
					break;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
    	}
		return true;
    }
    
    
    
    //the following part is about the traveldept
    
    
    /**
     * the following method needed by youqi's code
     *used when the travldept logins 
     *you need to  validate these informatin by querying  the database
     *return true if succeded
	 *else return false
     * @throws DBLockedException 
	 * 
	 */
    public static boolean travdeptLogin(String deptEmail,String password){
		try{
			if(authenticatePassword(deptEmail, password).equals(AuthState.SUCCESS)){
				return true;
			}
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
		return false;
    }
    /** 
     * the following method needed by youqi's code
     *you need to insert this sightspot's information into the database
     *return true if succeded
     *else return false
     * 
     * @param name
     * @param address
     * @param path 
     * @param discription
     * @return
     */
    public static boolean openSightspot(String path, String name ,String address, String imagetail, String description){
    	List<String> names = new ArrayList<String>();
		List<Integer> types = new ArrayList<Integer>();
		
		names.add("id");
		types.add(Types.BIGINT);
		names.add("name");
		types.add(Types.VARCHAR);
		names.add("address");
		types.add(Types.VARCHAR);
		names.add("image");
		types.add(Types.VARCHAR);
		names.add("description");
		types.add(Types.VARCHAR);
		
		ColumnInfo info = null;
		try {
			info = new ColumnInfo(names, types);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}

		Long id;
		try {
			id  = IdGenerationFactory.generateId(ObjectType.SIGHTSPOT);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return false;
		} catch (DBTableFullException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return false;
		}
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("name", name);
		map.put("address", address);
		File file = new File(path + "/upload/temp"+imagetail);
		if(file.exists()){
			File newfile = new File(path + "/upload/" + id +  imagetail);
			if(newfile.exists()){
				newfile.delete();
			}
			file.renameTo(newfile);
		}
		map.put("image", "/upload/" + id + imagetail);
		map.put("description", description);
		
		TableRow row = new TableRow("sightspot", map, info);
		try {
			DbManager.insert(row);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
		return true;    	
    }
     /**
      * the following method needed by youqi's code
      *you need to delete this sightspot's information from the database
      *return true if succeded
      *else return false
      * 
      * @param name
      * @return
     * @throws Exception 
      */
    public static boolean closeSightspot(String name) {
    	SightSpot sight = null;
		try {
			TableRow row = DbManager.queryByUnique("sightspot", "name", name);
			sight = (SightSpot) CacheManager.convert(row);
			
			if(sight.hasGroup()){
				return false;
			}
			String sql = "delete from sightspot where id=" + sight.getId() + ";";
			return DbManager.excute(sql);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
    }
    
    
    
    //client
    /**
     * get all the personal material reprensted by email
     * return null if failure
     * 
     * @param email
     * @return
     *//*
    public static Vector getPersData(String email){
    	Client c = null;
    	try {
			c = (Client) CacheManager.getByEmail(email);
			return c.selfList();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}*/
    public static Client getClient(String email){
    	Client c = null;
    	try {
			c = (Client) CacheManager.getByEmail(email);
			return c;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
    
    /**
     * save or modify the personal material contained by persData
     * there are two attibutes ,one is email ,the other is password
     * you only need to change the password reprented by email
     * if success return true
     * else return false
     * 
     * @param persData
     * @return
     */
	public static boolean savePersData(Vector data) {
		try {
			if(data.size() != Client.propertyLength){
				System.out.println("data.size() != Client.propertyLength");
				return false;
			}

			String email = (String) data.get(2); // get email;
			Client c = (Client)CacheManager.getByEmail(email);
			c.modify(data);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
    		return false;
    	}
    }
    /**
     * get all the corp material reprensted by email
     * return null if failure
     * @param email
     * @return
     */
    
    /*
    public static Vector getCorpData(String email){
    	TravelCorp tc = null;
    	try {
			tc = (TravelCorp) CacheManager.getByEmail(email);
			return tc.selfList();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

⌨️ 快捷键说明

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