-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddPerformController.java
112 lines (89 loc) · 2.58 KB
/
AddPerformController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class AddPerformController implements ActionListener,Subject {
private ArrayList<Observer> observer=new ArrayList<Observer>();
private Performance p=null;
AddPerformController()
{
new AddObserver(this);
}
public void eventAddPerformance(String performName, int placeNum,int monthNum,int dayNum,String[] Time, int duration, String price, String Text)
{
Calendar temp=Calendar.getInstance();
SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd");
java.sql.Date d = null;
Date date=new Date();
temp.set(temp.get(Calendar.YEAR), monthNum, dayNum);
date=new Date(temp.getTimeInMillis());
Date t = null;
SimpleDateFormat transFormat2= new SimpleDateFormat("HH:MM:SS");
Time[] time2= new Time[7];
DBHelper helper= DBHelper.getInstance();
for(int i=0; i<7; i++)
{
try {
if(i<duration+1)
{
String a = Time[i]+":"+"00";
t=transFormat2.parse(a);
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(i<duration+1)
time2[i] = new java.sql.Time(t.getTime());
else
time2[i]=null;
}
Integer priceInt = new Integer(price);
p = new Performance(placeNum,helper.getHost(),
new Schedule(performName,new java.sql.Date(date.getTime()),duration+1,time2),performName,priceInt,Text);
boolean a =helper.addPerformance(p);
this.notifyObservers(a);
//performances.add(new Performance(placeindex, DBHelper.getInstance().getHost(),
// new Schedule(PerformanceName,new java.sql.Date(date.getDate()),1,time2),PerformanceName
// ,cost,"1"));
}
@Override
public void actionPerformed(ActionEvent e) {
}
@Override
public void registerObserver(Observer o) {
// TODO Auto-generated method stub
observer.add(o);
}
@Override
public void removeObserver(Observer o) {
// TODO Auto-generated method stub
int i=observer.size();
if(i>=0)
observer.remove(o);
}
@Override
public void notifyObservers(boolean bool) {
// TODO Auto-generated method stub
Observer temp;
for(int i=0; i<observer.size();i++)
{
temp = observer.get(i);
if(bool==true)
temp.update(p);
else
temp.fail();
}
}
}