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

📄 mailbean.java

📁 “JSP数据库项目案例导航”一书从第一章到第十一章各章实例的源程序文件以及数据库文件。 注意: 1. 本书中的案例提供的数据库环境不同
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		  db.ExecuteSQL(strSQL);
    }
    public void modifyREAD(int value,long sjid){
		 String strSQL="update zz_syjb set read='"+value+"'  where sjid='"+sjid+"'";
		 db.ExecuteSQL(strSQL);
   }
    //value is new value;glc is the value replaced
    public void modifyGlc(String value,String zgbh){
		 String strSQL="update zz_glcb set glc='"+value+"' where zgbh='"+zgbh+"'";
		 db.ExecuteSQL(strSQL);
   }
    public void delFMail(String value){
       String strSQL="delete from zz_fyjb where fjid='"+value+"'";
       db.ExecuteSQL(strSQL);
     }
     public void delFJ(long value){
		   String strSQL="delete from zz_yjfjb where yjfjid='"+value+"'";
		   db.ExecuteSQL(strSQL);
     }
     public void delSMail(String value){
		   String strSQL="delete from zz_syjb where sjid='"+value+"'";
		   db.ExecuteSQL(strSQL);
     }
     public void delGlc(int value){
            String strSQL="delete from zz_glcb where glcid='"+value+"'";
            db.ExecuteSQL(strSQL);
          }
    public String getMax(String table,String value){
		   String strSQL="select "+value+" as maxvalue from zz_"+table+" where "+value+"=(select max("+value+") from zz_"+table+")";
		   ResultSet rs = db.QuerySQL(strSQL);
		   Statement stmt = null;
		   String rValue="0";
		   try{
			   if(rs.next()){
				 rValue=rs.getString("maxvalue");
			   }
			}catch(Exception e){System.out.println("运行时出错:"+e);}
			finally{
				if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
				if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
			}
		   return rValue;
    }
    public void addSJR(Hashtable hash){
          String strFJID = ds.toString((String)hash.get("FJID"));
          String strSJRZGBH = ds.toString((String)hash.get("SJR"));
          String strSQL="insert into zz_sjrb(FJID,SJRZGBH) values('"+strFJID+"','"+strSJRZGBH+"')";
          db.ExecuteSQL(strSQL);
    }
    public void delSJR(long value){
		  String strSQL="delete from zz_sjrb where fjid='"+value+"'";
		  db.ExecuteSQL(strSQL);
    }
    public void delSFGX(long value){
            String strSQL="delete from zz_sjfjgxb where sjid='"+value+"'";
            db.ExecuteSQL(strSQL);
          }

   public void addSFGX(String sjid,String yjfjid){
            String strSQL="insert into zz_sjfjgxb (SJID,YJFJID) values('"+sjid+"','"+yjfjid+"')";
            db.ExecuteSQL(strSQL);
   }

    public Vector getFJ(String value){
		  String strSQL="select * from zz_YJFJB where FJID='"+value+"'";
		  ResultSet rs=db.QuerySQL(strSQL);
		  Statement stmt = null;
		  Vector vct=new Vector();
		  try{
		  while(rs.next()){
			  Hashtable hash=new Hashtable();
			  hash.put("YJFJID",rs.getString("YJFJID"));
			  hash.put("FJDX",rs.getString("FJDX"));
			  vct.add(hash);
		  }
			}catch(Exception e){System.out.println("运行时出错:"+e);}
			finally{
				if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
				if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
			}
		  return vct;
	}


    public int refuse(String jsrbh,String zgbh){
		 String strSQL="select zgbh from zz_jsb where JSRBH='"+jsrbh+"'";
		 int flag=0;
		 ResultSet rs=db.QuerySQL(strSQL);
		 Statement stmt = null;
		 Vector vec=new Vector();
		 try{
		  while (rs.next()){
			   if (zgbh.equals(rs.getString("ZGBH")))
				  flag++;
		  }
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
		}
		   return flag;
       }
   public String convert(int value){
	    	 java.text.DecimalFormat f=new java.text.DecimalFormat("#####.#");
			 float m=1024*1024;
			 float n=1024;
			 String value1="";
			if ((float)value>m){
				value1 = f.format((float)value/m)+"M";
			}
			else if ((float)value>0&&(float)value<m){
					if ((float)value/n<0.1){
						value1 = "0.1K";
					}
					else value1 = f.format((float)value/n)+"K";
				}
				else if ((float)value==0){
					value1 = "0";
				}
		 return value1;
  }

 public String toUtf8String(String src)
 {
       byte[] b = src.getBytes();
       char[] c = new char[b.length];
       for(int i=0;i<b.length;i++)
       {
          c[i] = (char)(b[i]&0x00FF);
       }
       return new String(c);
    }

public String getGL()
{
		DocBean doc=null;
		String gl="";
		String sql = "";
		Statement stmt = null;
		ResultSet rs = null;
		try{
			doc=new DocBean();
			DealString ds=new DealString();
			sql = "select XMMC from CODE_ZDB where ZDMC='系统邮件过滤'";
			rs = doc.QuerySQL(sql);
			Vector vt = new Vector();
			while(rs.next()){
				gl=ds.toString(rs.getString("XMMC"));
			}
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
			if(doc!=null)doc.closeConn();
		}
		return gl;
	}
    //check whether the used space is larger than the default argument
	public int CheckMount(String zgbh ,RightBean rb ,DocBean doc )
	{
		//RightBean rb=null;
		//DocBean doc=null;
		ResultSet rs=null;
		int sum = 0;
		Statement stmt = null;
		try{
		//rb=new RightBean();
		DealString ds=new DealString();
		//doc=new DocBean();
		rb.setUID(zgbh);
		int total=Integer.parseInt(rb.getConfValue("附件大小"))*1024*1024;
		String str= "select sjid,zt,nr,fssj,fjdx,yjzt,read"
					+ " from zz_syjb"
					+ " where yjzt<>'2' and success='0' and sjrzgbh='"+zgbh+"'"
					+ " union"
					+ " select fjid,zt,nr,fssj,fjdx,yjzt,read"
					+ " from zz_fyjb"
					+ " where yjzt<>'2' and yjzt<>'6' and success='0' and fjrzgbh='"+zgbh+"'";
		rs=doc.QuerySQL(str);
		int nr1=0;
		int zt1=0;
		int fjdx1=0;
		while(rs.next()) {
			nr1+=ds.toString(rs.getString(3)).length();
			zt1+=ds.toString(rs.getString(2)).length();
			fjdx1+=Integer.parseInt((String)rs.getString(5));
		}
		sum=nr1+zt1+fjdx1;
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
			//if(rb!=null)  rb.closeConn();
			//if(doc!=null) doc.closeConn();
		}
		return sum;
	}

	public void DeleteFujianFromReceive(String sjid)
	{		
		  DocBean doc=null;
		  ResultSet rs=null,rs1=null,rs2=null,rs3=null;
		  Statement stmt = null;
		  String str1="select yjfjid from zz_sjfjgxb where sjid='"+sjid+"'";
		  try{
			  doc=new DocBean();
		  rs1=doc.QuerySQL(str1);
		  while (rs1.next()){
			      String yjfjid=rs1.getString("yjfjid");
		    	  String str="select sjid"
							+ " from zz_sjfjgxb"
							+ " where yjfjid='"+yjfjid+"'";
				rs=doc.QuerySQL(str);
				int count=0;
				while (rs.next())
					  count++;
				rs.close();  Statement st = rs.getStatement(); if(st!=null) st.close();
				if (count==1){							//no other sjrzgbh is using the addition,so check the fyjb;
				   String str2="select fjid" 
								 + " from zz_yjfjb"
								 + " where yjfjid='"+yjfjid+"'"; 	
				  rs2=doc.QuerySQL(str2);
				  while (rs2.next()){
					  String fjid=rs2.getString("fjid");
					  long fjid1=Long.parseLong(fjid);
					  String str3="select *"
								  + " from zz_fyjb"
								  + " where fjid='"+fjid+"'";
					   rs3=doc.QuerySQL(str3);
					   while (rs3.next()){
							 int yjzt=Integer.parseInt(rs3.getString("yjzt")); 
							 if (yjzt==2){
								MailElementBean meb=new MailElementBean();
								Vector mInfo=new Vector();
								mInfo=receiveFujian(yjfjid,"yjfjid");
								if (mInfo!=null){
									for(int j=mInfo.size()-1;j>=0;j--){
										meb=new MailElementBean();
										meb=(MailElementBean)mInfo.get(j);
										String wz=meb.getFJWZ();
										String xmc=meb.getFJXMC();
										File file=new File(wz+xmc);
										if (file.exists()){
											file.delete();
										}
										//delete record from zz_yjfjb
										delFJ(Long.parseLong(yjfjid));
									}
								}	
							 }
						 }
					 }
				}
			//  rs2.close();
       }
	   delSFGX(Integer.parseInt(sjid));
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs1!=null)try{ stmt = rs1.getStatement(); rs1.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
			if(rs2!=null)try{ stmt = rs2.getStatement(); rs2.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
			if(rs3!=null)try{ stmt = rs3.getStatement(); rs3.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
			if(doc!=null)  doc.closeConn();
		}
	}
	
	public void DeleteFujianFromSend(String yjfjid)
	{
		//DocBean doc=new DocBean();
		//ResultSet rs=null;
		//String str="select * from zz_yjfjb where fjid='"+fjid+"'";
		//rs=doc.QuerySQL(str);
		//while (rs.next()){
			MailElementBean meb=new MailElementBean();
			Vector mInfo=new Vector();
			mInfo=receiveFujian(yjfjid,"yjfjid");
			if (mInfo!=null){
				meb=new MailElementBean();
				meb=(MailElementBean)mInfo.get(0);
				String wz=meb.getFJWZ();
				String xmc=meb.getFJXMC();
				File file=new File(wz+xmc);
				if (file.exists()){
					file.delete();
				}
			delFJ(Long.parseLong(yjfjid));
    		}
		//}
		//rs.close(); Statement stmt = rs.getStatement(); if(stmt!=null) stmt.close();
		//doc.closeConn();
	}

	public void DeleteFJ(String yjfjid) {
		DealString ds = new DealString();
		MailElementBean meb=new MailElementBean();
		Vector mInfo = new Vector();
		
		//read data from the table 
		mInfo=receiveFujian(yjfjid,"yjfjid");	
		meb=(MailElementBean)mInfo.get(0);
		String wz=meb.getFJWZ();
		String xmc=meb.getFJXMC();
		String day = xmc.substring(6,8);

		long fid = Long.parseLong(yjfjid);		
		//delete file
		File file=new File(wz+day+"\\"+xmc);
		if (file.exists()){
			file.delete();
			}  
		delFJ(fid);
	}	

	private int CheckS(String yjfjid) {
			DocBean doc = null;
			ResultSet rs = null;
			Statement stmt = null;
			int count = 0;
			
			String sql = "select * from zz_sjfjgxb where yjfjid='"+yjfjid+"'";
			try{
				doc = new DocBean();
				rs = doc.QuerySQL(sql);
				while (rs.next()){
					count++;
				}
			}catch(Exception e){System.out.println("运行时出错:"+e);}
			finally{
				if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
				if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
				if(doc!=null)doc.closeConn(); 
			}
			return count;
	}

	private int CheckF(String yjfjid) {
		DocBean doc = null;
		ResultSet rs = null;
		Statement stmt = null;
		int count = 0; 	
		
		String sql = "select zz_fyjb.*"
		   	        +" from zz_fyjb,zz_yjfjb"
		   	        +" where zz_fyjb.fjid=zz_yjfjb.fjid and zz_fyjb.yjzt<>2 and" 
		   	        +" zz_fyjb.yjzt<>5 and zz_fyjb.yjzt<>6 and zz_yjfjb.yjfjid='"+yjfjid+"'";
		try{
			doc = new DocBean();
			rs = doc.QuerySQL(sql);
			while (rs.next()){
				count++;		
			}
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}		
			if(doc!=null) doc.closeConn();
		}
		return count;
	}

	public void DeleteFJInS (String yjfjid,String sjid,String value){
		DocBean doc = null;
		try{
		doc = new DocBean();
		String fid = yjfjid;		
		int sjnum = CheckS(fid);
		int fjnum = CheckF(fid);
		String str = "";
		if (value==null)
		{
			//删除sjfjgxb
			str = "delete from zz_sjfjgxb where yjfjid='"+yjfjid+"' and sjid='"+sjid+"'";
		}
		else 
		{
			str = "delete from zz_sjfjgxb"
				   +" where yjfjid='"+yjfjid+"' and sjid in"
				   +" (select sjid from zz_syjb where sjid='"+sjid+"' and yjzt='"+value+"')"; 
		}	
			doc.ExecuteSQL(str);
			//当收件箱(或垃圾箱)只有1条记录且发件箱,草稿箱没有记录,即系统中没有其他人使用该记录时
			if (sjnum==1 && fjnum==0){
				DeleteFJ(yjfjid);
			}
		}catch(Exception e){System.out.println("运行时出错:"+e);}
		finally{
			if(doc!=null)doc.closeConn();
		}
	}	

	public void DeleteFJInF(String yjfjid,String fjid){
		DealString ds = new DealString();
		DocBean doc = null;
		ResultSet rs=null,rs1 = null; 
		Statement stmt =  null;
		String fid = yjfjid;
		int sjnum = CheckS(fid);
		int fjnum = CheckF(fid);
		
		int count = 0;
		try{
			doc = new DocBean();
			if (sjnum==0 && fjnum==1){
				String str1 = "select fjid from zz_yjfjb where fjid='"+fjid+"'";
				rs1 = doc.QuerySQL(str1);
				while (rs1.next()){
					if (fjid.equals(rs1.getString("fjid")))
						count++;
				}
				if (count==1){		
					long fjid1 = Long.parseLong(fjid);
					delSJR(fjid1);
					delFMail(fjid);
				}
				DeleteFJ(yjfjid);
			}
			//对发件箱或者草稿箱:当有其他人使用该附件时,将该邮件的状态值改为2	
			else {
				long fjid1 = Long.parseLong(fjid);
				modifyFMail(2,fjid1);
			}	
		}catch(Exception e){System.out.println("运行时出错:"+e);}

⌨️ 快捷键说明

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