/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package beanStaff;
import Business.business;
import EntityBean.EventCategory;
import EntityBean.EventType;
import EntityBean.Events;
import SessionBean.EventCategorySSBLocal;
import SessionBean.EventTypeSSBLocal;
import SessionBean.EventsLocal;
import java.util.Date;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import helper.messages;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Huynh Kim Toan
*/
@ManagedBean(name = "EVENTS")
@RequestScoped
public class events {
@EJB
private EventsLocal eventsFacade;
private EventTypeSSBLocal eventTypeFacade;
private EventCategorySSBLocal eventCategoryFacade;
private String title, speaker, description, address,status,prize;
private Date startDate_endDate;
private EventCategory Category;
private EventType Type;
private int quantity,eventCategory,eventType;
private float balance;
/** Creates a new instance of events */
public events() {
}
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]).getCateName()));
}
return Category1;
}
public void createEvent() {
Events event = new Events();
Date NgayhienTai = new Date();
long songay = startDate_endDate.getTime() - NgayhienTai.getTime();
long i = songay / (24 * 60 * 60 * 1000);
if(title == null || title.length() < 6)
{
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Title must be greater than 6 characters", "error");
}else if(speaker == null || speaker.length() < 6)
{
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Speaker must be greater than 6 characters", "error");
}else if(description == null || description.length() < 6)
{
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Description must be greater than 6 characters", "error");
}else if(address == null || address.length() <6)
{
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Address must be greater than 6 characters", "error");
}else if(!checkEvent())
{
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Event Exist", "error");
}else if( i < 10)
{
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Registration date to more than 9 days", "error");
}
else {
event.setTitle(title);
event.setSpeakers(speaker);
event.setDescription(description);
event.setAddress(address);
event.setPeopleQuantity(quantity);
event.setFee(balance);
event.setCateID(Category);
event.setTypeID(Type);
event.setPrize(prize);
event.setConductDate(startDate_endDate);
event.setStatus(status);
this.eventsFacade.create(event);
messages.taoTB(FacesMessage.SEVERITY_INFO, "Successfull", "Successfull");
}
}
public boolean checkEvent()
{
boolean Flag = true;
for(int i=0 ; i < this.eventsFacade.count() ; i++)
{
if(this.eventsFacade.findAll().get(i).getTitle().equals(title))
{
Flag = false;
}
}
return Flag;
}
public void Reset()
{
title = null;
speaker = null;
description = null;
address = null;
quantity = 0;
}
public EventCategory getCategory() {
return eventCategoryFacade.find(eventCategory);
}
public void setCategory() {
this.Category = eventCategoryFacade.find(eventCategory);
}
public EventType getType() {
return eventTypeFacade.find(eventType);
}
public void setType() {
this.Type = eventTypeFacade.find(eventType);
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public float getBalance() {
return balance;
}
public void setBalance(float balance) {
this.balance = balance;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getQuantity() {
return quantity;
}
public int getEventType() {
return eventType;
}
public void setEventType(int eventType) {
this.eventType = eventType;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getSpeaker() {
return speaker;
}
public void setSpeaker(String speaker) {
this.speaker = speaker;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getPrize() {
return prize;
}
public void setPrize(String prize) {
this.prize = prize;
}
/**
* @return the startDate_endDate
*/
public Date getStartDate_endDate() {
return startDate_endDate;
}
public int getEventCategory() {
return eventCategory;
}
public void setEventCategory(int eventCategory) {
this.eventCategory = eventCategory;
}
/**
* @param startDate_endDate the startDate_endDate to set
*/
public void setStartDate_endDate(Date startDate_endDate) {
this.startDate_endDate = startDate_endDate;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}