?? usermanagerimpl.java
字號:
package org.yeeku.service.impl;
import org.yeeku.dao.*;
import org.yeeku.model.*;
import org.yeeku.service.UserManager;
import java.util.List;
import java.sql.Time;
import java.util.Date;
public class UserManagerImpl implements UserManager
{
private UserDao userDao;
public void setUserDao(UserDao userDao)
{
this.userDao = userDao;
}
/**
* 新增用戶
* @param user 新增用戶的用戶名
* @param pass 新增用戶的密碼
* @param email 新增用戶的電子郵件
* @return 新增用戶的主鍵
*/
public int addUser(String user , String pass,String LastTime)
throws Exception
{
try
{
User u = new User();
u.setId(1);
u.setUsername(user);
u.setPassword(pass);
u.setGrade("1");
u.setLasttime(LastTime);
u.setTotalMessage(0);
u.setNewMessage(0);
userDao.save(u);
return u.getId();
}
catch (Exception e)
{
e.printStackTrace();
throw new Exception("新增用戶時出現異常");
}
}
/**
* 驗證用戶登陸
* @param user 需要登陸的用戶名
* @param pass 需要登陸的密碼
* @return 是否登陸成功
*/
public int loginValid(String user , String pass)
throws Exception
{
try
{
User u = userDao.findUserByNameAndPass(user , pass);
if (u != null)
{
return u.getId();
}
}
catch (Exception e)
{
e.printStackTrace();
throw new Exception("驗證用戶登陸時出現異常");
}
return -1;
}
/**
* 驗證用戶名是否可用,如果系統中已有該用戶名,則不可用。
* @param user 需要驗證的用戶名
* @return 用戶名是否可用
*/
public boolean validateName(String user)
throws Exception
{
try
{
if (userDao.findUserByName(user) == null)
{
return true;
}
return false;
}
catch (Exception e)
{
throw new Exception("驗證用戶名是否有效出錯!");
}
}
public List<Message> checkNewMessage(String name)throws Exception
{
try
{
List u= userDao.checkNewMessage(name);
if (u != null)
{
return u;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new Exception("checkNewMessage時出現異常");
}
return null;
}
public List<Message> getMessage(String name)throws Exception
{
try
{
List<Message> u= userDao.getMessageByName(name);
if (u != null)
{
return u;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new Exception("getMessage時出現異常");
}
return null;
}
public List<Message> getMessagefrom(String fromname,String username)throws Exception
{
try
{
List<Message> u= userDao.getMessageFrom(fromname,username);
if (u != null)
{
return u;
}
}
catch (Exception e)
{
e.printStackTrace();
throw new Exception("getMessage時出現異常");
}
return null;
}
public boolean addMessage(String strFrom,String strTo,String strContent,String strTitle,String datetime)throws Exception
{
try
{
Message u = new Message();
u.setTouser(strTo);
u.setFromuser(strFrom);
u.setTitle(strTitle);
u.setIsnew(1);
u.setContent(strContent);
u.setMessagetime(datetime);
userDao.saveMessage(u);
}
catch (Exception e)
{
e.printStackTrace();
throw new Exception("消息插入時出現異常");
}
return true;
}
public boolean deleteMessage(int id)throws Exception
{
try
{
userDao.deleteMessage(id);
}
catch (Exception e)
{
e.printStackTrace();
throw new Exception("刪除時出現異常");
}
return true;
}
public boolean modify(int id)throws Exception
{
try
{
User user=userDao.get(id);
userDao.update(user);
}
catch (Exception e)
{
e.printStackTrace();
throw new Exception("修改時出現異常");
}
return true;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -