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

📄 messagecontrol.java

📁 oa办公管理系统。一些小型的企业办公管理用的系统。一个月废寝忘食的结果。
💻 JAVA
字号:
package com.soft.message.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.soft.util.DBConn;
import com.soft.vo.MessageInfo;

public class MessageControl {

	private PreparedStatement ps=null;
	private ResultSet rs=null;
	private Connection conn=null;
	private DBConn db=new DBConn();
	
	public int setMessage(int employeeId,int recivePeopleID,String content,int isSend,String theme)
	{
		int i=0;
		conn=db.getConnection();
		try
		{
			if(recivePeopleID==0)
			{
				return i;
			}
			conn.setAutoCommit(false);
			String sql="insert into message values("+employeeId+",sysdate,"+recivePeopleID+",'"+content+"',"+isSend+",0,'"+theme+"')";
			ps=conn.prepareStatement(sql);
			i=ps.executeUpdate();
			conn.commit();
		}
		catch(SQLException e)
		{
			try
			{
				if(conn!=null)
				{
					conn.rollback();
				}
			}
				catch(SQLException ex)
				{
					ex.printStackTrace();
				}
				e.printStackTrace();
			}
		finally
		{
			try
			{
				if(conn!=null)
					conn.close();
				if(ps!=null)
					ps.close();
				if(rs!=null)
					rs.close();
			}
			catch(SQLException e)
			{
				e.printStackTrace();
			}
		}
		return i;
	}
	
	
	public int deleteAllMessage(String sendtime)
	{
		conn=db.getConnection();
		int i=0;
		try
		{
			conn.setAutoCommit(false);
			String sql="delete from message where to_char(sendtime,'yyyy-mm-dd hh24:mi:ss')='"+sendtime+"'";
			ps=conn.prepareStatement(sql);
			i=ps.executeUpdate();
			conn.commit();
		}
		catch(SQLException e)
		{
			try
			{
				if(conn!=null)
				{
					conn.rollback();
				}
			}
				catch(SQLException ex)
				{
					ex.printStackTrace();
				}
				e.printStackTrace();
			}
		finally
		{
			try
			{
				if(conn!=null)
					conn.close();
				if(ps!=null)
					ps.close();
				if(rs!=null)
					rs.close();
			}
			catch(SQLException e)
			{
				e.printStackTrace();
			}
		}
		return i;
	}
	
	public int updateMessage(String theme,String content,String edittime)
	{
		conn=db.getConnection();
		int i=0;
		try
		{
			conn.setAutoCommit(false);
			String sql="update message set theme='"+theme+"',content='"+content+"' where to_char(sendtime,'yyyy-mm-dd hh24:mi:ss')='"+edittime+"'";
			ps=conn.prepareStatement(sql);
			i=ps.executeUpdate();
			conn.commit();
		}
		catch(SQLException e)
		{
			try
			{
				if(conn!=null)
				{
					conn.rollback();
				}
			}
				catch(SQLException ex)
				{
					ex.printStackTrace();
				}
				e.printStackTrace();
			}
		finally
		{
			try
			{
				if(conn!=null)
					conn.close();
				if(ps!=null)
					ps.close();
				if(rs!=null)
					rs.close();
			}
			catch(SQLException e)
			{
				e.printStackTrace();
			}
		}
		return i;
	}
	
	public void updateUnreadMessage(String sendtime)
	{
		conn=db.getConnection();
		try
		{
			conn.setAutoCommit(false);
			String sql="update message set isread=1 where to_char(sendtime,'yyyy-mm-dd hh24:mi:ss')='"+sendtime+"'";
			ps=conn.prepareStatement(sql);
			int i=ps.executeUpdate();
			conn.commit();
		}
		catch(SQLException e)
		{
			try
			{
				if(conn!=null)
				{
					conn.rollback();
				}
			}
				catch(SQLException ex)
				{
					ex.printStackTrace();
				}
				e.printStackTrace();
			}
		finally
		{
			try
			{
				if(conn!=null)
					conn.close();
				if(ps!=null)
					ps.close();
				if(rs!=null)
					rs.close();
			}
			catch(SQLException e)
			{
				e.printStackTrace();
			}
		}
	}
	
	public List getDetails(String time)
	{
		List<MessageInfo> list=new ArrayList<MessageInfo>();
		conn=db.getConnection();
		try
		{
			conn.setAutoCommit(false);
			String sql="select m.sender,m.receiver,m.content,m.issend,m.isread,m.theme,e.name from message m,employee e where m.receiver=e.employeeid and to_char(m.sendtime,'yyyy-mm-dd hh24:mi:ss')='"+time+"'";
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery();
			while(rs.next())
			{
				MessageInfo messageInfo=new MessageInfo();
				messageInfo.setTheme(rs.getString("theme"));
				messageInfo.setName(rs.getString("name"));
				messageInfo.setContent(rs.getString("content"));
				
				list.add(messageInfo);
			}
			conn.commit();
		}
		catch(SQLException e)
		{
			try
			{
				if(conn!=null)
				{
					conn.rollback();
				}
			}
				catch(SQLException ex)
				{
					ex.printStackTrace();
				}
				e.printStackTrace();
			}
		finally
		{
			try
			{
				if(conn!=null)
					conn.close();
				if(ps!=null)
					ps.close();
				if(rs!=null)
					rs.close();
			}
			catch(SQLException e)
			{
				e.printStackTrace();
			}
		}
		return list;
	}
	
	public List getReceiveDetails(String time)
	{
		List<MessageInfo> list=new ArrayList<MessageInfo>();
		conn=db.getConnection();
		try
		{
			conn.setAutoCommit(false);
			String sql="select * from (select m.sender,m.receiver,m.content, to_char(m.sendtime,'yyyy-mm-dd hh24:mi:ss') st,m.issend,m.isread,m.theme,e.name from message m,employee e where m.sender=e.employeeid) where st='"+time+"'";
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery();
			System.out.println("无数据/////////////////////////////////");
			while(rs.next())
			{
				System.out.println("有数据:///////////////////////////");
				MessageInfo messageInfo=new MessageInfo();
				messageInfo.setTheme(rs.getString("theme"));
				messageInfo.setName(rs.getString("name"));
				messageInfo.setContent(rs.getString("content"));
				
				list.add(messageInfo);
			}
			conn.commit();
		}
		catch(SQLException e)
		{
			try
			{
				if(conn!=null)
				{
					conn.rollback();
				}
			}
				catch(SQLException ex)
				{
					ex.printStackTrace();
				}
				e.printStackTrace();
			}
		finally
		{
			try
			{
				if(conn!=null)
					conn.close();
				if(ps!=null)
					ps.close();
				if(rs!=null)
					rs.close();
			}
			catch(SQLException e)
			{
				e.printStackTrace();
			}
		}
		return list;
	}
}

⌨️ 快捷键说明

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