dictionary_finacialbean.java

来自「java开发的办公系统 1.系统管理 (地区管理,部门管理,菜单管理,用户管理」· Java 代码 · 共 645 行 · 第 1/2 页

JAVA
645
字号
			finally{				DBclose();			}			return list;		}		/**		 * @author	Administrator		 * @param	无		 * @return	KeyId:插入记录时当前记录的id号		 * @see		获得插入记录时当前记录的id号		 */		public int getKey(){			return keyId;		}		/**		 * @author	Administrator		 * @param	无		 * @return	(totalRecord):插入记录时当前记录的id号		 * @see		获得插入记录时当前记录的id号		 */		public int getTotalRecord(){	        return totalRecord;	    }		/**		 * @author	Administrator		 * @param	item:要添加的数据对象DICTIONARY_FINACIALItem		 * @return	boolean:是否添加成功,如果添加成功返回true,否则返回false		 * @see		添加一条记录		 */		public boolean addItem(Dictionary_finacialItem item){			try{								String sql="insert into "+T.DICTIONARY_FINACIAL+"("+							"id,"+							"pid,"+							"nodepath,"+							"name,"+							"instruction)values("+							""+item.getId()+","+							""+item.getPid()+","+							"'"+item.getNodepath()+"',"+							"'"+item.getName()+"',"+							"'"+item.getInstruction()+"')";				executeUpdate(sql);								String max_id=item.getId();//插入的id				String nodepath="";//上级路径				sql=" select  *  from   "+T.DICTIONARY_FINACIAL+"   where  id="+item.getPid();				rs = executeQuery(sql);				if(rs.next())				{					nodepath=rs.getString("nodepath");				}				if(item.getPid().equals("0"))				{					item.setNodepath("0,"+max_id);				}				else				{					item.setNodepath(nodepath+","+max_id);				}				sql="update "+T.DICTIONARY_FINACIAL+" set "+								"nodepath='"+item.getNodepath()+"' where id="+max_id;				return executeUpdate(sql);			}catch(Exception e){				System.out.println(e.toString());				return false;			}			finally{				DBclose();			}		}		/**		 * @author	Administrator		 * @param	item:要添加的数据对象UsersItem		 * @return	keyId:当前添加记录的id号 否则返回 0		 * @see		添加一条记录		 */		public Dictionary_finacialItem addItemAndMaxId(Dictionary_finacialItem item){			Dictionary_finacialItem dictionary_finacialItem=new Dictionary_finacialItem();			try{				String sql="insert into "+T.DICTIONARY_FINACIAL+"("+							"id,"+							"pid,"+							"nodepath,"+							"name,"+							"instruction)values("+							""+item.getId()+","+							""+item.getPid()+","+							"'"+item.getNodepath()+"',"+							"'"+item.getName()+"',"+							"'"+item.getInstruction()+"')";				executeUpdate(sql);								String max_id=item.getId();//插入的id				String nodepath="";//上级路径				sql=" select  *  from   "+T.DICTIONARY_FINACIAL+"   where  id="+item.getPid();				rs = executeQuery(sql);				if(rs.next())				{					nodepath=rs.getString("nodepath");				}				if(item.getPid().equals("0"))				{					item.setNodepath("0,"+max_id);				}				else				{					item.setNodepath(nodepath+","+max_id);				}				sql="update "+T.DICTIONARY_FINACIAL+" set "+								"nodepath='"+item.getNodepath()+"' where id="+max_id;				executeUpdate(sql);								sql = "select * from "+T.DICTIONARY_FINACIAL+" where id="+max_id;				rs = executeQuery(sql);				if(rs.next()){					dictionary_finacialItem.setId(rs.getString("id"));					dictionary_finacialItem.setPid(rs.getString("pid"));					dictionary_finacialItem.setNodepath(rs.getString("nodepath"));					dictionary_finacialItem.setName(rs.getString("name"));					dictionary_finacialItem.setInstruction(rs.getString("instruction"));				}							}catch(SQLException e){				System.out.println(e.toString());			}			finally{				DBclose();			}			return dictionary_finacialItem;		}		/**		 * @author	Administrator		 * @param	item:要修改的数据对象DICTIONARY_FINACIALItem		 * @return	boolean:如果修改成功返回true,否则返回false		 * @see		修改一条记录		 */		public Dictionary_finacialItem updateItem(Dictionary_finacialItem item){			Dictionary_finacialItem dictionary_finacialItem=new Dictionary_finacialItem();			try{				String max_id=item.getId_no();//插入的id				String nodepath="";//上级路径								String sql=" select  *  from   "+T.DICTIONARY_FINACIAL+"   where  id="+item.getPid();				rs = executeQuery(sql);				if(rs.next())				{					nodepath=rs.getString("nodepath");				}				if(item.getPid().equals("0"))				{					item.setNodepath("0,"+max_id);				}				else				{					item.setNodepath(nodepath+","+max_id);				}				sql="update "+T.DICTIONARY_FINACIAL+" set "+							"id="+item.getId_no()+","+							"pid="+item.getPid()+","+							"nodepath='"+item.getNodepath()+"',"+							"name='"+item.getName()+"',"+		   	 			   	"instruction='"+item.getInstruction()+"' where id="+item.getId();				executeQuery(sql);								sql = "select * from "+T.DICTIONARY_FINACIAL+" where id="+item.getId_no();				rs = executeQuery(sql);				if(rs.next()){					dictionary_finacialItem.setId(item.getId());					dictionary_finacialItem.setId_no(rs.getString("id"));					dictionary_finacialItem.setPid(rs.getString("pid"));					dictionary_finacialItem.setNodepath(rs.getString("nodepath"));					dictionary_finacialItem.setName(rs.getString("name"));					dictionary_finacialItem.setInstruction(rs.getString("instruction"));				}			}catch(Exception e){				System.out.println(e.toString());			}			finally{				DBclose();			}			return dictionary_finacialItem;		}		/**		 * @author	Administrator		 * @param	item:要修改的数据对象DICTIONARY_FINACIALItem		 * @return	boolean:如果修改成功返回true,否则返回false		 * @see		修改一条记录		 */		public boolean updateItemFile(Dictionary_finacialItem item){			try{				String sql="update "+T.DICTIONARY_FINACIAL+" set "+							"pid="+item.getPid()+","+							"nodepath='"+item.getNodepath()+"',"+							"name='"+item.getName()+"',"+		   	 			   	"instruction='"+item.getInstruction()+"' where id="+item.getId();				return executeUpdate(sql);			}catch(Exception e){				System.out.println(e.toString());				return false;			}			finally{				DBclose();			}		}		/**		 * @author	Administrator		 * @param	item:要删除的数据对象DICTIONARY_FINACIALItem		 * @return	boolean:如果删除成功返回true,否则返回false		 * @see		删除一条记录		 */		public int removeItem(Dictionary_finacialItem item){			int flag=1;			try{				//判断是否存在下级流程类别				  String sql = "select count(1) as num from "+T.DICTIONARY_FINACIAL+" where pid="+item.getId();				  rs = executeQuery(sql);				  if (rs.next()&&rs.getInt("num")>0)				  {				  	flag=2;				  }								  if(flag==1)				  {					sql="delete from  "+T.DICTIONARY_FINACIAL+"  where id="+item.getId() ;					executeUpdate(sql);				  }			}catch(Exception e){				System.out.println(e.toString());			}			finally{				DBclose();			}			return flag;		}		/**		 * @author	Administrator		 * @param	ids:要删除的记录的ids数组		 * @return	boolean:如果删除成功返回true,否则返回false		 * @see		批量删除条记录		 */		public boolean removeItems(String[] ids)		{			try{				String sql="delete from  "+T.DICTIONARY_FINACIAL+"  where id in (";				String filter="";				for(int i=0;i<ids.length-1;i++){					filter+=ids[i]+",";				}				filter+=ids[ids.length-1]+")";				sql+=filter;				return executeUpdate(sql);			}catch(Exception e){				System.out.println(e.toString());				return false;			}			finally{				DBclose();			}		}		/**		 * @author	Administrator		 * @param	sql:要更新的sql 语句		 * @return	boolean:如果执行成功返回true,否则返回false		 * @see		执行更新一条sql 语句		 */		public boolean executeUpdate(String sql){			try{				access.getConnection();				return access.executeUpdate(sql);			}			catch(Exception e){				System.out.println(e.toString());				return false;			}		}		/**		 * @author	Administrator		 * @param	sql:要查询的sql 语句		 * @return	boolean:如果执行成功返回true,否则返回false		 * @see		执行查询一条sql 语句		 */		public ResultSet executeQuery(String sql){			try			{				access.getConnection();				rs=access.executeQuery(sql);				return rs;			}			catch(Exception e){				System.out.println(e.toString());				return null;			}		}		/**		 * @author	Administrator		 * @param	无		 * @return	无		 * @see		关闭数据库操作对象		 */		public void DBclose(){			try {				access.DBclose(rs);			}			catch(Exception e) {				System.out.println(e.toString());			}		}}

⌨️ 快捷键说明

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