/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package beanMember;
import EntityBean.Enroll;
import EntityBean.Events;
import EntityBean.Users;
import SessionBean.EnrollSSBLocal;
import SessionBean.EventsLocal;
import SessionBean.UsersSSBLocal;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import helper.operationSession;
import beanAdmin.beanEvents;
import java.util.Date;
import java.util.List;
import helper.messages;
import javax.faces.application.FacesMessage;
/**
*
* @author Huynh Kim Toan
*/
@ManagedBean(name = "RG")
@RequestScoped
public class managerEvents {
@EJB
private EventsLocal eventsFacade;
@EJB
private EnrollSSBLocal involveFacade;
@EJB
private UsersSSBLocal loginFacade;
private String payment;
private beanEvents event = new beanEvents();
private int quantityRegiste = 0;
private String title;
private int EventID;
private String desctiption;
/** Creates a new instance of registerEvent */
public managerEvents() {
}
public void CreateRegisteEvent() {
Enroll enroll = new Enroll();
Date time = new Date();
String title = (String) operationSession.layGTSession("title");
int eventid = Integer.parseInt((String)operationSession.layGTSession("title"));
try {
Users login = this.loginFacade.getUserID((String) operationSession.layGTSession("user"));
if (login == null) {
messages.taoTB(FacesMessage.SEVERITY_ERROR, "please register information .", "Error");
} else {
int memberID = login.getUserID();
enroll.setUserID(this.loginFacade.find(memberID));
enroll.setEventID(this.eventsFacade.find(eventid));
enroll.setPayment(payment);
enroll.setPaymentStatus(true);
enroll.setEnrollDate(time);
Enroll involve1 = this.involveFacade.getAllEnroll(memberID, title);
if (involve1 == null) {
if (quantityRegis() > 0) {
this.involveFacade.create(enroll);
messages.taoTB(FacesMessage.SEVERITY_INFO, "Register Successfull !", "Invovle");
} else {
messages.taoTB(FacesMessage.SEVERITY_ERROR, "The number of full!", "Invovle");
}
} else {
messages.taoTB(FacesMessage.SEVERITY_ERROR, "You have registered this event !", "Invovle");
}
}
} catch (Exception ex) {
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Error !", "Invovle");
}
}
public int quantityRegis() {
Events events = this.eventsFacade.find(Integer.parseInt((String)operationSession.layGTSession("title")));
String title = events.getTitle();
int Quantity = events.getPeopleQuantity();
for (int i = 0; i < this.involveFacade.count(); i++) {
if (this.involveFacade.findAll().get(i).getPaymentStatus().equals(true) && this.involveFacade.findAll().get(i).getEventID().getTitle().equals(title)) {
quantityRegiste++;
}
}
int total = Quantity - quantityRegiste;
return total;
}
public boolean chechMember() {
boolean check = false;
Users login = this.loginFacade.getUserID((String) operationSession.layGTSession("user"));
if (login == null) {
check = false;
} else {
check = true;
}
return check;
}
public void CancelEvent() {
try {
String title = (String) operationSession.layGTSession("title");
Users login = this.loginFacade.getUserID((String) operationSession.layGTSession("user"));
if (login == null) {
messages.taoTB(FacesMessage.SEVERITY_ERROR, "please register information .", "Error");
} else {
int memberID = login.getUserID();
Enroll involve = this.involveFacade.getAllEnroll(memberID, title);
// involve.setMember1(this.member1Facade.find(memberID));
if (involve == null) {
messages.taoTB(FacesMessage.SEVERITY_ERROR, "Event is not registered .", "Error");
}else if(involve.getPaymentStatus().equals(true))
{
messages.taoTB(FacesMessage.SEVERITY_ERROR, "pending status can't cancel .", "Error");
}else
{
involve.setPaymentStatus(false);
this.involveFacade.edit(involve);
messages.taoTB(FacesMessage.SEVERITY_INFO, "Cancelled events .", "Successfull");
}
}
} catch (Exception ex) {
}
}
public List<Events> getList() {
List<Events> events = this.eventsFacade.searchRegisteStatus();
return events;
}
public String getPayment() {
return payment;
}
/**
* @param payment the payment to set
*/
public void setPayment(String payment) {
this.payment = payment;
}
/**
* @return the event
*/
public beanEvents getEvent() {
return event;
}
/**
* @param event the event to set
*/
public void setEvent(beanEvents event) {
this.event = event;
}
public String getDesctiption() {
return desctiption = (String) operationSession.layGTSession("des");
}
public void setDesctiption(String desctiption) {
this.desctiption = desctiption;
}
public String getTitle() {
Events title1 = this.eventsFacade.find(Integer.parseInt((String) operationSession.layGTSession("title")));
return title=title1.getTitle();
}
public int getEventID() {
return EventID = Integer.parseInt((String)operationSession.layGTSession("title"));
}
public void setEventID(int eventID) {
this.EventID = eventID;
}
public void setTitle(String title) {
this.title = title;
}
}