utildiary.java

来自「spring+struts+hibernate做的银行系统」· Java 代码 · 共 324 行

JAVA
324
字号
/*
 * Created on 2006-4-19
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package cn.com.tym.util.tablebean;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.http.HttpServletRequest;

import cn.com.tym.blank.form.DiaryForm;

import cn.com.tym.pub.DB;
import cn.com.tym.pub.PageBean;

import cn.com.tym.table.bean.DiaryBean;
import cn.com.tym.util.text.DealText;
import cn.com.tym.util.text.ExchangeInput;

/**
 * @author jack_booth
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class UtilDiary {

	//����ռ�
	
    public boolean insert(DiaryForm frm,String id,DB db)
    throws SQLException
{	 
    boolean check = false;
//       bigClassID = exchangeInput.StringToInt(frm.getCoteId());
//       viewBigClass viewBigClass = new viewBigClass();
//        if(viewBigClass.seeByID(bigClassID))
//          bigClassName = viewBigClass.getBigClassName();
//    viewBigClass = null;
    DiaryBean bean=new DiaryBean();
    
    	bean.setMainTitle(ExchangeInput.StringToString(frm.getMainTitle()));
    	bean.setContent(ExchangeInput.StringToString(frm.getContent()));
    	bean.setDiaryTime(ExchangeInput.getNewTime());
    	bean.setLock(frm.getLock());
    	System.out.println(frm.getMainTitle()+" "+bean.getLock()+" "+bean.getContent());
 
 
     if(!bean.getMainTitle().equals("") && !bean.getContent().equals(""))
    {
        String mainTitle = DealText.dealToSql(bean.getMainTitle());
        String content=DealText.dealToSql(bean.getContent());
        
        System.out.println(bean.getMainTitle()+" "+bean.getContent()+"   "
        		+bean.getDiaryTime()+bean.getLock()+id);
        String strSql = "insert into mdh_diary values('"+bean.getMainTitle()+"','"+bean.getContent()+"','"+bean.getDiaryTime()+"','"+bean.getLock()+"','"+id+"');";
      try{
        if(db.ExecSql(strSql)!= 0)
            check = true;
          
      }catch(SQLException e){
      	System.out.println("#)))))))))))))))))))))))))))))");
      	  throw e;
      }
    }
    return check;
}
    
    /**
    
    public boolean makeSubmit(DiaryForm frm,String id,DB db)
    throws SQLException
{
    boolean check = false;
//       bigClassID = exchangeInput.StringToInt(frm.getCoteId());
//       viewBigClass viewBigClass = new viewBigClass();
//        if(viewBigClass.seeByID(bigClassID))
//          bigClassName = viewBigClass.getBigClassName();
//    viewBigClass = null;
    DiaryBean bean=new DiaryBean();
    
    	bean.setMainTitle(ExchangeInput.StringToString(frm.getMainTitle()));
    	bean.setContent(ExchangeInput.StringToString(frm.getContent()));
    	bean.setDiaryTime(ExchangeInput.getNewTime());
    	bean.setLock(frm.getLock());
   
     if(!bean.getMainTitle().equals("") && !bean.getContent().equals(""))
    {
        String mainTitle = DealText.dealToSql(bean.getMainTitle());
        String content=DealText.dealToSql(bean.getContent());
        
        String strSql = "insert into mdh_diary values('"+bean.getMainTitle()+"','"+bean.getContent()+"','"+bean.getDiaryTime()+"','"+bean.getLock()+"','"+id+"');";
      try{
        if(db.ExecSql(strSql)!= 0)
            check = true;
            db.close();
      }catch(SQLException e){
      	  db.close();
      	  throw e;
      }
    }
    return check;
}
    
    */
    
    public boolean delete(String diaryId,DB db)
    throws SQLException
{
    boolean check = false;
 
        
        String strSql = "delete  from mdh_diary where  diary_id='"+diaryId+"'";
      try{
        if(db.ExecSql(strSql)!= 0)
            check = true;
            db.close();
      }catch(SQLException e){
      	  throw e;
      } 
    return check;
    
} 
    
    //�޸��修改日记 update ssd_communion_msaccept set isRead=1,readtime='"+getNewTime()+"' where  keyID='"+keyID+"'
    
    public boolean ismake(DiaryForm frm,DB db)
    throws SQLException
{
    	boolean page=false;
		 	String strSql= "update mdh_diary  set mainTile='"+frm.getMainTitle()+"'," +
		 			"content='"+frm.getContent()+"',lock='"+frm.getLock()+"' where diary_id='"+frm.getDiaryId()+"'"; 
		     try
		     {
		     	int vv=db.ExecSql(strSql);
		     	if(vv==1)
		     		page=true;
		     }
		     catch(SQLException e)
		     {
		          e.printStackTrace();
		          throw e;
		     }
		     return page;
    
} 
    
    public ArrayList diaryAll(HttpServletRequest request,String id,DB db)throws SQLException{
    	 
    		        ArrayList list = new ArrayList();
    		   	 	String strSql= "select * from mdh_diary   where vipId='"+id+"' order by diary_id desc"; 
    	 
    			Collection arraylist=new ArrayList();
    				 	ResultSet rs = null;
    			PageBean pageBean=new PageBean(request);
    			pageBean.setPageSize(10);
    			pageBean.count();
    			int currRow=pageBean.getCurrentRow();
    			int lastRow=pageBean.getLastRow();
    		 
    	 
    			String csql="select count(*) from mdh_diary   where vipId='"+id+"'";
    			String urlStr="DiaryPageAction.do?method=execute&mmId="+id+"";
    			try{
    			pageBean.count(db,rs,csql,urlStr);
    			}
    			catch(Exception e){}
    	 
      
    			strSql=" select  top "+lastRow+" * from  mdh_diary  where vipId='"+id+"' order by diary_id desc  ";
    			try{
    			rs=db.OpenSql(strSql);
    			if(currRow>0)
    				rs.absolute(currRow);
    		       while(rs.next())
    		        {		 
    		        	 
    		       	DiaryBean bean=new DiaryBean();
    		       	
    		       	bean.setDiaryId(rs.getString("diary_id"));
    		       	bean.setMainTitle(rs.getString("mainTile"));
    
    		       	bean.setContent(rs.getString("content"));
    		       	bean.setDiaryTime(ExchangeInput.getTime(rs.getString("diartyTime")));
     
    		       	bean.setLock(checkLock(rs.getInt("lock")));
    		          
    		             list.add(bean);
    		             bean=null;
    		        }}
    			     	catch(SQLException e){
    			       
    			     		
    			       	e.printStackTrace();
    			       	throw e;
    			     	}
    		 
    					return list;
    		}
    	
    
    //查看不是本人的日记
    
    public ArrayList diaryNotAll(HttpServletRequest request,String id,DB db)throws SQLException{
   	 
   		        ArrayList list = new ArrayList();
   		   	 	String strSql= "select * from mdh_diary   where vipId='"+id+"' and lock!=1 order by diary_id desc"; 
   	 
   			Collection arraylist=new ArrayList();
   				 	ResultSet rs = null;
   			PageBean pageBean=new PageBean(request);
   			pageBean.setPageSize(10);
   			pageBean.count();
   			int currRow=pageBean.getCurrentRow();
   			int lastRow=pageBean.getLastRow();
   		 
   	 
   			String csql="select count(*) from mdh_diary   where vipId='"+id+"' and lock!=1 ";
   			String urlStr="DiaryPageAction.do?method=execute&mmId="+id+"";
   			try{
   			pageBean.count(db,rs,csql,urlStr);
   			}
   			catch(Exception e){}
   	 
     
   			strSql=" select  top "+lastRow+" * from  mdh_diary  where vipId='"+id+"' and lock!=1 order by diary_id desc  ";
   			try{
   			rs=db.OpenSql(strSql);
   			if(currRow>0)
   				rs.absolute(currRow);
   		       while(rs.next())
   		        {		 
   		        	 
   		       	DiaryBean bean=new DiaryBean();
   		       	
   		       	bean.setDiaryId(rs.getString("diary_id"));
   		       	bean.setMainTitle(rs.getString("mainTile"));
   
   		       	bean.setContent(rs.getString("content"));
   		       	bean.setDiaryTime(ExchangeInput.getTime(rs.getString("diartyTime")));
    
   		       	bean.setLock(checkLock(rs.getInt("lock")));
   		          
   		             list.add(bean);
   		             bean=null;
   		        }}
   			     	catch(SQLException e){
   			       
   			     		
   			       	e.printStackTrace();
   			       	throw e;
   			     	}
   		 
   					return list;
   		}
   	
    //�Ƿ����
    
	public String checkLock(int lock)throws SQLException{
		
		String dd="";
   
			  if(lock==1){
			  	dd="已锁";
			} 
			return dd;
}
	
	//�õ� �����ռ�
	  public DiaryBean seeLock(String diaryid,DB db ) throws SQLException
		 {
 
		  
		 	DiaryBean bean=null;
		 	String strSql= "select * from mdh_diary   where diary_id='"+diaryid+"' order by diary_id desc"; 
		    
		     try
		     {
		     	ResultSet rs=db.OpenSql(strSql);
		        if(rs.next())
		         {
		        	 
    		       bean=new DiaryBean();
    		       	bean.setAuthor(getAuthor(rs.getString("vipId"),db));
    		       	bean.setDiaryId(rs.getString("diary_id"));
    		       	bean.setMainTitle(rs.getString("mainTile"));
    		       	bean.setContent(rs.getString("content"));
    		       	bean.setDiaryTime(rs.getString("diartyTime"));
    		       	bean.setLock(checkLock(rs.getInt("lock")));
     
		         }

		     }
		     catch(SQLException e)
		     {
		          e.printStackTrace();
		          throw e;
		     }
		     return bean;
		 }
	  
	  //�õ��ձ��ǵ�����
	  public String getAuthor(String id,DB db)throws SQLException{
	  	
	  	String dd="";
	  	String strSql="select rname from mdh_register where register_id='"+id+"'";
	  	try{
	  		ResultSet rs=db.OpenSql(strSql);
			if(rs.next()){ 
				dd=rs.getString("rname");
			}
	  	}
	  	catch(SQLException e){
	  		e.printStackTrace();
	  		throw e;
	  	} 
	  	return dd;
	  }
}

⌨️ 快捷键说明

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