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

📄 adminclass.java

📁 新闻管理系统,使用Struts框架编写. 系统包括前端页面和后端管理页面
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	* 返回值:字符串型。返回操作的信息
	***********************************************************/ 
    public String EditSClass(String s0,String s1,String s2,String s3,String s4,String s5,String s6)
    {			
		try
    	{
	    	Connection Conn = DBConn.getConn();
	    	Statement stmt = Conn.createStatement(1004,1007);
	    	Statement stmt1 = Conn.createStatement(1004,1007);
	    	ResultSet rs1 = null;
	    	ResultSet rs2 = null;
	    	boolean OK=true;
	    	String sError="";
	    	int BigClassID = Fun.StrToInt(s0);
	    	int SmallClassID = Fun.StrToInt(s1);
	    	String NewSClassName = Fun.CheckReplace(s2);
	    	String OldSClassName = Fun.CheckReplace(s4);
	    	String SClassInfo = Fun.CheckReplace(s3);
	    	String [] sa1 = new String [3];
	    	String [] sa2 = new String [3];
	    	sa1[0] = s0;
	    	sa1[1] = s2;
	    	sa1[2] = s3;
	    	sa2[0] = "所属大类";
	    	sa2[1] = "小类标题";
	    	sa2[2] = "小类说明";
	    	String s = Fun.CheckDate(sa1,sa2);
	    	if (!s.equals("Yes"))
	    	{
	    		OK = false;
	    		sError = s; 
	    	}
	    	if (SmallClassID==0 || BigClassID==0)
	    	{
	    		OK = false;
	    		sError = "类别参数传递错误,请重试!"; 
	    	}
		    if (OK)
		    {
		    	String sql1 = "select * from SmallClass where SmallClassName='" + NewSClassName + "'";
		    	rs1 = stmt1.executeQuery(sql1);
		    	rs1.last();
		     	if ((!OldSClassName.equals(s2)) && rs1.getRow()>0)
		    	{
		    		rs1.close();
		    		stmt1.close();
		    		sError += "<li>该小类标题 [ " + s2 + " ] 已经存在,不能重复!";
		    		OK = false;	
		    	}
		    }
	    	if(OK)
	    	{
		    	String sql = "update SmallClass set ";
		    	sql += "SmallClassName='" + NewSClassName + "',";
		    	sql += "SmallClassInfo='" + SClassInfo + "',";
		    	sql += "BigClassID=" + BigClassID;
		    	sql += " where SmallClassID=" + SmallClassID;
		 		//Conn.setAutoCommit(false);
		    	stmt.executeUpdate(sql);
		    	//Conn.commit();
		    	//Conn.setAutoCommit(true);
				stmt.close();
				Conn.close();
				String NowTime = (new java.util.Date()).toLocaleString();
		    	String [] sLog = new String[5];
				sLog[0] = Fun.CheckReplace(s5);
		    	sLog[1] = "修改原小类[" + OldSClassName + "]为[" + NewSClassName + "]";
		    	sLog[2] = NowTime;
		    	sLog[3] = Fun.CheckReplace(s6); 
		    	sLog[4] = "Yes";
		    	Fun.AddLog(sLog);
		    	return "Yes";
		    }
		    else return sError;
	    }catch(SQLException e)
        {
            ////e.printStackTrace();
            //System.out.print(sql);
            return "操作失败!";
        }
     }
     
 	
 	
 	/*********************************************************
	* 函数名:DelSClass
	* 作  用:删除小类
	* 参  数:s1,小类ID,s2,操作用户,s3,IP地址
	* 返回值:成功 true,否则false
	***********************************************************/ 
    public boolean DelSClass(String s1,String s2,String s3)
    {			
		String NowTime = (new java.util.Date()).toLocaleString();
		String [] sLog = new String[5];
		sLog[0] = s2;
		sLog[2] = NowTime;
		sLog[3] = s3; 
		try
    	{
	    	Connection Conn = DBConn.getConn();
	    	Statement stmt = Conn.createStatement(1004,1007);
	    	boolean OK=true;
	    	int SClassID = Fun.StrToInt(s1);
	    	String sql1 = "delete from SmallClass where SmallClassID=" + SClassID;
	    	String sql2 = "delete from News where SmallClassID=" + SClassID;	
			if(SClassID>0)
			{   
				try
			    {
			    	//用事物处理,防止程序出错。
			    	Conn.setAutoCommit(false);	//更改默认事物处理
			    	stmt.executeUpdate(sql1);
			    	stmt.executeUpdate(sql2);
			    	Conn.commit();
			    	Conn.setAutoCommit(true);
					stmt.close();
					Conn.close();
			    	sLog[1] = "删除ID为 [ " + s1 + " ] 的小类"; 
			    	sLog[4] = "Yes";
			    	Fun.AddLog(sLog);
			    	return true;
			    }catch (Exception e) {
						Conn.rollback();		//回滚JDBC事务
						////e.printStackTrace();
						Conn.close();
						return false;
						}  
			}else return false;
	    }catch(SQLException e)
        {
            ////e.printStackTrace();
    		sLog[1] = "删除ID为[" + s1 + "]的小类,操作出错!"; 
	    	sLog[4] = "No";
	    	Fun.AddLog(sLog);
            //System.out.print(sql);
            return false;
        }
     }
 
 	
 	/*********************************************************
	* 函数名:AddSpecial
	* 作  用:添加大类
	* 参  数:s1,专题名称;s2,专题说明
	* 		  s3,操作用户,s4,IP地址
	* 返回值:字符串型。返回操作的信息
	***********************************************************/
    public String AddSpecial(String s1,String s2,String s3,String s4)
    {			
		try
    	{
	    	boolean OK = true;
    		Connection Conn = DBConn.getConn();
	    	Statement stmt = Conn.createStatement(1004,1007);
	    	ResultSet rs = null;
    		String sError = "";
	    	String SpecialName = Fun.CheckReplace(s1);
	    	String SpecialInfo = Fun.CheckReplace(s2);
	    	String [] sa1 = new String [2];
	    	String [] sa2 = new String [2];
	    	sa1[0] = s1;
	    	sa1[1] = s2;
	    	sa2[0] = "专题名称";
	    	sa2[1] = "专题说明";
	    	String s = Fun.CheckDate(sa1,sa2);
	    	if (!s.equals("Yes"))
	    	{
	    		OK = false;
	    		sError = s; 
	    	}	
	    	if(OK)
		    {
		    	String sql1 = "select * from Special where SpecialName='" + SpecialName + "'";
		    	ResultSet rs1 = stmt.executeQuery(sql1);
		    	if (rs1.next()) 
		    	{
		    		rs1.close();
		    		OK = false;
		    		sError = "<li>该排专题名称 [ " + s1 + " ] 已经存在,不能重复!";
		    	}
		    }
	    	if(OK)
	    	{	
		    	String NowTime = (new java.util.Date()).toLocaleString();
		    	String [] sLog = new String[5];
		    	String sql = "insert into Special (SpecialName,";
		    	sql += "SpecialInfo,SpecialTime) values (";
				sql += "'" + SpecialName + "',";
				sql += "'" + SpecialInfo + "',";
				sql += "'" + NowTime + "')";
		    	stmt.executeUpdate(sql);
		    	sLog[0] = Fun.CheckReplace(s3);
		    	sLog[1] = "添加专题[" + SpecialName + "]";
		    	sLog[2] = NowTime;
		    	sLog[3] = Fun.CheckReplace(s4); 
		    	sLog[4] = "Yes";
		    	Fun.AddLog(sLog);
				stmt.close();
				Conn.close();
		    	return "Yes";
		    }
		    else return sError;
	    }catch(Exception e)
        {
            //e.printStackTrace();
            //ystem.out.print(e.getMessage());
            return "操作失败!";
        }
     }
 
 
 
 
 	/*********************************************************
	* 函数名:EditSpecial
	* 作  用:修改专题
	* 参  数:s1,专题名称;s2,专题说明,s3,操作用户
	* 		  s4,IP地址,s5,专题ID,s6,原专题名称
	* 返回值:字符串型。返回操作的信息
	***********************************************************/ 
    public String EditSpecial(String s1,String s2,String s3,String s4,String s5,String s6)
    {			
		try
    	{
	    	Connection Conn = DBConn.getConn();
	    	Statement stmt = Conn.createStatement(1004,1007);
	    	ResultSet rs = null;
	    	boolean OK=true;
	    	String sError="";
	    	int SpecialID = Fun.StrToInt(s5);
	    	String SpecialName = Fun.CheckReplace(s1);
	    	String OldSpecialName = Fun.CheckReplace(s6);
	    	String SpecialInfo = Fun.CheckReplace(s2);
	    	String [] sa1 = new String [2];
	    	String [] sa2 = new String [2];
	    	sa1[0] = s1;
	    	sa1[1] = s2;
	    	sa2[0] = "专题名称";
	    	sa2[1] = "专题说明";
	    	String s = Fun.CheckDate(sa1,sa2);
	    	if (!s.equals("Yes"))
	    	{
	    		OK = false;
	    		sError = s; 
	    	}
	    	if (SpecialID==0)
	    	{
	    		OK = false;
	    		sError = "参数传递错误"; 
	    	}
		    if (OK)
		    {
		    	String sql1 = "select * from Special where SpecialName='" + SpecialName + "'";
		    	rs = stmt.executeQuery(sql1);
		    	rs.last();
		     	if ((!OldSpecialName.equals(SpecialName)) && rs.getRow()>0)
		    	{
		    		rs.close();
		    		stmt.close();
		    		sError += "<li>该专题名称 [ " + SpecialName + " ] 已经存在,不能重复!";
		    		OK = false;	
		    	}
		    }
	    	if(OK)
	    	{
		    	String sql = "update Special set ";
		    	sql += "SpecialName='" + SpecialName + "',";
		    	sql += "SpecialInfo='" + SpecialInfo + "'";
		    	sql += " where SpecialID=" + SpecialID;

		    	stmt.executeUpdate(sql);
				stmt.close();
				Conn.close();
				String NowTime = (new java.util.Date()).toLocaleString();
		    	String [] sLog = new String[5];
				sLog[0] = Fun.CheckReplace(s3);
		    	sLog[1] = "修改原专题[" + OldSpecialName + " ]为[" + SpecialName + " ]";
		    	sLog[2] = NowTime;
		    	sLog[3] = Fun.CheckReplace(s4); 
		    	sLog[4] = "Yes";
		    	Fun.AddLog(sLog);
		    	return "Yes";
			    
		    }
		    else return sError;
	    }catch(Exception e)
        {
            //e.printStackTrace();
            //System.out.print(sql);
            return "操作失败!";
        }
     }
 
 	
 	
 	/*********************************************************
	* 函数名:DelSpecial
	* 作  用:删除专题
	* 参  数:s1,专题ID,s2,操作用户,s3,IP地址
	* 返回值:成功 true,否则false
	***********************************************************/ 
    public boolean DelSpecial(String s1,String s2,String s3)
    {			
		String NowTime = (new java.util.Date()).toLocaleString();
		String [] sLog = new String[5];
		sLog[0] = s2;
		sLog[2] = NowTime;
		sLog[3] = s3; 
		try
    	{
	    	Connection Conn = DBConn.getConn();
	    	Statement stmt = Conn.createStatement(1004,1007);
	    	boolean OK=true;
	    	int SpecialID = Fun.StrToInt(s1);
	    	String sql1 = "delete from Special where SpecialID=" + SpecialID;
	    	String sql2 = "delete from News where SpecialID=" + SpecialID;	
			if(SpecialID>0)
			{   
				try
			    {
			    	//用事物处理,防止程序出错。
			    	Conn.setAutoCommit(false);	//更改默认事物处理
			    	stmt.executeUpdate(sql1);
			    	stmt.executeUpdate(sql2);
			    	Conn.commit();
			    	Conn.setAutoCommit(true);
					stmt.close();
					Conn.close();
			    	sLog[1] = "删除ID为[" + s1 + "]的专题"; 
			    	sLog[4] = "Yes";
			    	Fun.AddLog(sLog);
			    	return true;
			    }catch (Exception e) {
						Conn.rollback();		//回滚JDBC事务
						////e.printStackTrace();
						Conn.close();
						return false;
						}  
			}else return false;
	    }catch(SQLException e)
        {
            //e.printStackTrace();
    		sLog[1] = "删除ID为[" + s1 + "] 的专题,操作出错!"; 
	    	sLog[4] = "No";
	    	Fun.AddLog(sLog);
            //System.out.print(sql);
            return false;
        }
     }
 	
 	
 	
 	 //测试
	public static void main(String[] args)
	{	
		AdminClass aClass = new AdminClass();
		//System.out.print(aClass.AddBigClass("11","地方新闻1","地方","znl","172.16.166.51"));
		//boolean b = aClass.DelBigClass("7","dream","172.16.166.50");
		//if (b) System.out.println("Yes");
		//else System.out.println("No");
		//System.out.print(aClass.EditBigClass("5","国内新闻","国内新闻","10","国际新闻","dream","localhost"));
		//System.out.print(aClass.ReadClass("AdminClass.jsp","1"));
		//System.out.print(aClass.EditSClass("1","5","军事新闻","军事新闻","军事","dream","localhost"));
		String [][] as1 = aClass.GetAllClass(true,true,null);
	
		//String [][] sa = new String[5][2];
		//System.out.print(sa.length);
		//if(aClass.DelSClass("fjdlf","http://ww","2")) System.out.print("Yes");
		//else System.out.print("No");
		if(as1==null) System.out.print("null");
		else
		{
			for(int i=0;i<as1.length;i++)
			{
				System.out.println(as1[i][0]+","+as1[i][1]);
			}
		}
		//System.out.print(aClass.ReadSpecial("1")[0]);
	}
}

⌨️ 快捷键说明

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