/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package beanMember;
import EntityBean.Users;
import SessionBean.UsersSSBLocal;
import java.util.Date;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import helper.operationSession;
import helper.messages;
import javax.faces.application.FacesMessage;
/**
*
* @author Huynh Kim Toan
*/
@ManagedBean(name = "AddInfor")
@RequestScoped
public class insertInformation {
@EJB
private UsersSSBLocal loginFacade;
@EJB
private Users login = new Users();
private String fullname;
private Date birth;
private String gender;
private String city;
private String address;
private int card;
private int telephone;
private String email;
private int userid;
private String variableEmail;
public insertInformation() {
}
public String createInformation() {
this.login = this.loginFacade.getUserID((String) operationSession.layGTSession("user"));
int userID = login.getUserID();
Users member = new Users();
if(fullname.length() < 6)
{
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Full Name must be greater than 5 characters", "error");
}else if(birth == null)
{
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Please select date of birth !", "error");
}else if(email.length() < 6)
{
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Email must be greater than 5 characters !", "error");
}else if(address.length()<6){
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Address must be greater than 5 characters", "error");
}else {
String mail = email + variableEmail;
member.setFullname(fullname);
member.setDayofbirth(birth);
member.setGender(gender);
member.setCity(city);
member.setAddress(address);
member.setCardnumber(card);
member.setTelephone(telephone);
member.setEmail(mail);
member.setUserID(this.loginFacade.find(userID).getUserID());
try {
Users member1 = this.loginFacade.getUserID(fullname);
if(member1 == null)
{
this.loginFacade.create(member);
messages.taoTB(FacesMessage.SEVERITY_INFO, "Update Information Successfull !", "Successfull");
return "/member/ViewInfomation";
}else
{
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Error !", "error");
}
//this.member1Facade.create(member);
} catch (Exception ex) {
ex.printStackTrace();
}
}
return null;
}
public Users getLogin() {
return login;
}
/**
* @param login the login to set
*/
public void setLogin(Users login) {
this.login = login;
}
public String getVariableEmail() {
return variableEmail;
}
public void setVariableEmail(String variableEmail) {
this.variableEmail = variableEmail;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public int getCard() {
return card;
}
public void setCard(int card) {
this.card = card;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getTelephone() {
return telephone;
}
public void setTelephone(int telephone) {
this.telephone = telephone;
}
public int getUserid() {
return userid;
}
public void setUserid(int userid) {
this.userid = userid;
}
/**
* @return the member
*/
}