/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package beanAdmin;
import Business.business;
import EntityBean.EventCategory;
import EntityBean.EventType;
import EntityBean.Events;
import EntityBean.Users;
import SessionBean.EventCategorySSBLocal;
import SessionBean.EventTypeSSBLocal;
import SessionBean.EventsLocal;
import SessionBean.UsersSSBLocal;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import helper.operationSession;
import helper.messages;
import java.util.ArrayList;
import java.util.Date;
import javax.faces.application.FacesMessage;
/**
*
* @author Huynh Kim Toan
*/
@ManagedBean(name = "beanEvent")
@RequestScoped
public final class beanEvents implements Serializable {
@EJB
private UsersSSBLocal loginFacade;
@EJB
private EventsLocal eventsFacade;
private EventTypeSSBLocal eventTypeFacade;
private EventCategorySSBLocal eventCategoryFacade;
private Events events = new Events();
private Users login = new Users();
private String title;
private EventCategory Category;
private EventType Type;
private String speakers;
private String address;
private String description,prize,status;
private int eventType,eventCategory,peopleQuantity;
private double fee;
private Date conductDate;
public beanEvents() {
}
public List<Events> getLists() {
return new business().getEventsFacade().findAll();
}
public List<EventType> getListTypeEvent()
{
List<EventType> Type1 = new ArrayList<EventType>();
int count = new business().getEventTypeFacade().count();
if(count <3)
{
count = new business().getEventTypeFacade().count();
}else
count = 3;
for(int i = 0 ; i < count ; i++)
{
int[] EventType = new int[10];
EventType[i] = new business().getEventTypeFacade().findAll().get(i).getTypeID();
Type1.add(new EventType(EventType[i],new business().getEventTypeFacade().find(EventType[i]).getTypeName()));
}
return Type1;
}
public List<EventCategory> getListCategoryEvent()
{
List<EventCategory> Category1 = new ArrayList<EventCategory>();
int count = new business().getEventCategoryFacade().count();
if(count <3)
{
count = new business().getEventCategoryFacade().count();
}else
count = 3;
for(int i = 0 ; i < count ; i++)
{
int[] EventCategory = new int[10];
EventCategory[i] = new business().getEventCategoryFacade().findAll().get(i).getCateID();
Category1.add(new EventCategory(EventCategory[i],new business().getEventCategoryFacade().find(EventCategory[i]).getCateName(),new business().getEventCategoryFacade().find(EventCategory[i]).getDescription()));
}
return Category1;
}
public String viewDetails(int title) {
operationSession.ganGiaTriChoSession("title", String.valueOf(title));
setEvents(new business().getEventsFacade().find(title));
String des = this.events.getDescription();
operationSession.ganGiaTriChoSession("des", des);
peopleQuantity=this.events.getPeopleQuantity();
prize=this.events.getPrize();
Type=this.events.getTypeID();
Category=this.events.getCateID();
eventType=Type.getTypeID();
eventCategory=Category.getCateID();
status=events.getStatus();
fee=events.getFee();
this.title=this.events.getTitle();
conductDate=this.events.getConductDate();
description = this.events.getDescription();
speakers = this.events.getSpeakers();
address = this.events.getAddress();
String userName = (String) operationSession.layGTSession("user");
this.login = this.loginFacade.getUserID(userName);
if (login.getRoles().equals("admin")) {
return "/admin/ManagerStatusEvents";
} else if (login.getRoles().equals("member")) {
return "/member/registerEvents";
} else if (login.getRoles().equals("staff")) {
return "/staff/RegistePayment";
} else {
return null;
}
}
public void updateStatusEvents() {
if (speakers.length() == 0) {
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Speaker Not null .", "Error");
} else if (description.length() == 0) {
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Description Not null .", "Error");
} else if (address.length() == 0) {
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Address Not null .", "Error");
} else {
this.events = this.eventsFacade.find(Integer.parseInt((String)operationSession.layGTSession("title")));
events.setStatus(status);
events.setCateID(new business().getEventCategoryFacade().find(eventCategory));
events.setFee(fee);
events.setTypeID(new business().getEventTypeFacade().find(eventType));
events.setTitle(title);
events.setPeopleQuantity(peopleQuantity);
events.setConductDate(conductDate);
events.setPrize(prize);
events.setSpeakers(speakers);
events.setDescription(description);
events.setAddress(address);
this.eventsFacade.edit(events);
messages.taoTB(FacesMessage.SEVERITY_INFO, "update Event Successfull", "Successfull");
}
}
public void deleteEvent() {
this.events = this.eventsFacade.find(Integer.parseInt(operationSession.layGTSession("title").toString()));
this.eventsFacade.remove(events);
messages.taoTB(FacesMessage.SEVERITY_INFO, "Delete Event Successfull", "Successfull");
}
public Events getEvents() {
return events;
}
public void setEvents(Events events) {
this.events = events;
}
public EventCategory getCategory() {
return Category;
}
public void setCategory(EventCategory Category) {
this.Category = Category;
}
public EventType getType() {
return Type;
}
public void setType(EventType Type) {
this.Type = Type;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getSpeakers() {
return speakers;
}
public void setSpeakers(String speakers) {
this.speakers = speakers;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public double getFee() {
return fee;
}
public void setFee(double fee) {
this.fee = fee;
}
public String getPrize() {
return prize;
}
public void setPrize(String prize) {
this.prize = prize;
}
public int getPeopleQuantity() {
return peopleQuantity;
}
public void setPeopleQuantity(int peopleQuantity) {
this.peopleQuantity = peopleQuantity;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public int getEventType() {
return eventType;
}
public void setEventType(int eventType) {
this.eventType = eventType;
}
public int getEventCategory() {
return eventCategory;
}
public void setEventCategory(int eventCategory) {
this.eventCategory = eventCategory;
}
public Date getConductDate() {
return conductDate;
}
public void setConductDate(Date conductDate) {
this.conductDate = conductDate;
}
}