-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.java
More file actions
984 lines (889 loc) · 43.1 KB
/
Controller.java
File metadata and controls
984 lines (889 loc) · 43.1 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
package com.example.android.break2;
import android.app.DownloadManager;
import android.widget.Switch;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
public class Controller {
private DBManager dbMan; // A Reference of type DBManager
public Controller() {
dbMan = new DBManager(); // Create the DBManager Object
}
public void TerminateConnection() {
dbMan.closeConnection();
}
public int[] InsertNewFollower(String name, int age, String email, String password, String username) throws SQLException {
int ResultArr[] = new int[2];
// query for checking this username is used before or not
String username_queryCheck = "Select * from follower,admins where follower.username ='" + username + "' or admins.username ='" + username + "' ;";
ResultSet username_RS = (ResultSet) dbMan.ExecuteReader(username_queryCheck);
if (username_RS.next()) {
ResultArr[0] = -1;
ResultArr[1] = -1;
return ResultArr;// -1 ARRAY for username used before
}
// query for checking this email is used before or not
String email_queryCheck = "Select * from follower,admins where follower.email ='" + email + "' or admins.email ='" + email + "';";
ResultSet emailcheck_RS = (ResultSet) dbMan.ExecuteReader(email_queryCheck);
if (emailcheck_RS.next()) {
ResultArr[0] = -100;
ResultArr[1] = -100;
return ResultArr;// -100 ARRAY for email used before
}
// otherwise the username and the email are valid so we can enter the query now
String query = "Insert into follower (name,age,Email,fpassword,username) values( " +
"'" + name + "'," +
age + "," +
"'" + email + "'," +
"'" + password + "'," +
"'" + username + "' ) ; ";
int res = dbMan.ExecuteNonQuery(query);
if (res == 1) {
query = "Select * from follower " + "" +
"where " +
" ( follower.username= '" + username + "') and follower.fpassword = '" + password + "';";
ResultSet UserData = dbMan.ExecuteReader(query);
if (UserData.next()) {
ResultArr[0] = 2; // the first element is for the privileges 2 means it is follower
ResultArr[1] = UserData.getInt("follower_id"); // the second element is for the user ID
return ResultArr;
}
}
return null;
}
public int InsertNewAdmin(String username, String email, String password) throws SQLException {
// query for checking this username is used before or not
String username_queryCheck = "Select * from follower,admins where follower.username ='" + username + "' or admins.username ='" + username + "' ;";
ResultSet username_RS = (ResultSet) dbMan.ExecuteReader(username_queryCheck);
if (username_RS.next()) {
return -1; // if it is used the function returns -1 for username used error
}
// otherwise the username is valid so we can enter the query now
String query = "Insert into admins (username,email,a_password) values( " +
"'" + username + "'," +
"'" + email + "'," +
"'" + password + "' ) ; ";
return dbMan.ExecuteNonQuery(query);
}
public int[] LoginCheck(String username, String password) throws SQLException {
String query = "Select * from follower " + "" +
"where " +
" ( follower.username= '" + username + "') and follower.fpassword = '" + password + "';";
ResultSet isUser = dbMan.ExecuteReader(query);
int ResultArr[] = new int[2];
if (isUser.next()) {
ResultArr[0] = 2; // the first element is for the privileges 2 means it is follower
ResultArr[1] = isUser.getInt("follower_id"); // the second element is for the user ID
return ResultArr;
}
query = "Select * from admins " + "" +
"where " +
" ( admins.username= '" + username + "' ) and a_password = '" + password + "';";
ResultSet isAdmin = dbMan.ExecuteReader(query);
if (isAdmin.next()) {
ResultArr[0] = 1; // the first element is for the privileges 1 means it is an admin
ResultArr[1] = isAdmin.getInt("admin_id"); // the second element is for the user ID
return ResultArr;
} else
return null;
}
public int InsertAdv(String title, String cmpName, String stDate,
String endDate, String content, String price, String url, int adminID)throws SQLException
{
// here we need to pickup a query that contains the current logged admin id
String checkquery = "select * from advertisement where ad_title = '" + title + "' ;";
ResultSet adv_exists = dbMan.ExecuteReader(checkquery);
if (adv_exists.next())
return 404; // returns 404 if the actor is already exist with same name
String query = "Insert into advertisement (company_name,ad_title,ad_content,ad_start_date,ad_end_date,price,url,admin_id) values( " +
"'" + cmpName + "'," +
"'" + title + "'," +
"'" + content + "'," +
"'" + stDate + "'," +
"'" + endDate + "'," +
+Integer.parseInt(price) + "," +
"'" + url + "'," + adminID + ");";
return dbMan.ExecuteNonQuery(query);
}
public int InsertNewCinema(String cname, String clocation) throws SQLException {
String checkquery = "select * from cinema where cinema_name = '" + cname + "' ;";
ResultSet cinema_exists = dbMan.ExecuteReader(checkquery);
if (cinema_exists.next())
return 404; // returns 404 if the actor is already exist with same name
String query = "Insert into cinema (cinema_name,cinema_location) values( " +
"'" + cname + "'," +
"'" + clocation + "');";
return dbMan.ExecuteNonQuery(query);
}
public int InsertNewMovie(String name, String language,
String rdate,String description,
int age_rest,String url,
Float reviewers,Float users,
int directorID,int authorID,
String duration,String genre)
{
return 1;
}
public ResultSet GetMoviesNames()
{
String query="select * from movies ";
return dbMan.ExecuteReader(query);
}
public ResultSet GetMemberNames(int type)
{
String kind=Integer.toString(type);
String query="select * from crew_members where member_type="+kind+";";
return dbMan.ExecuteReader(query);
}
public ResultSet GetCinemaNames()
{
String query="select * from cinema ";
return dbMan.ExecuteReader(query);
}
public ResultSet GetMovieInfo(String Name)
{
String query="select * from movies where movie_name like '%"+Name+"%';";
return dbMan.ExecuteReader(query);
}
public ResultSet GetMemberInfo(String Name)
{
String query="select * from crew_members where member_name like '%"+Name+"%';";
return dbMan.ExecuteReader(query);
}
public ResultSet GetCinemaInfo(String Name)
{
String query="select * from cinema where cinema_name='"+Name+"';";
return dbMan.ExecuteReader(query);
}
public ResultSet GetAuthorName(int id)
{
String query="select member_name from movies,crew_members where authors_id=member_id and authors_id="+id+";";
return dbMan.ExecuteReader(query);
}
public ResultSet GetDirectorName(int id)
{
String query="select member_name from movies,crew_members where director_id=member_id and director_id="+id+";";
return dbMan.ExecuteReader(query);
}
public ResultSet GetActorName(int id)
{
String query="select member_name from crew_members c ,actors_movie a where a.movie_id="+id+" and a.actors_id=c.member_id ";
return dbMan.ExecuteReader(query);
}
public ResultSet SelectMovieByName(String name)
{
String query = "select * from movies where movie_name = '" + name + "';";
return dbMan.ExecuteReader(query);
}
public int AddMovieToCinema(String cname,String mname,String showtime,int price)throws SQLException
{
ResultSet cinemaData =SelectCinemaByName(cname);
ResultSet movieData = SelectMovieByName(mname);
int cinemaID,movieID;
if (cinemaData.next()) {
cinemaID = cinemaData.getInt("cinema_id");
} else return -1;
if(movieData.next())
movieID=movieData.getInt("movie_id");
else return -1;
String query = "Insert into available_at values (" + cinemaID + "," + movieID +", '"+showtime+"',"+price+");";
return dbMan.ExecuteNonQuery(query);
}
public int InsertActor(String ActorName, String ActorBirthDay, String brief) throws SQLException {
// String checkquery ="select * from crew_members where member_name = '"+ActorName+"' and birth_date="+"'"+ ActorBirthDay+"' ;";
String checkquery = "select * from crew_members where member_name = '" + ActorName + "' ;";
ResultSet actor_exists = dbMan.ExecuteReader(checkquery);
if (actor_exists.next())
return 404; // returns 404 if the actor is already exist with same name
String query = "Insert into crew_members(member_name,birth_date,brief,member_type)" +
" values('" + ActorName + "'," +
"'" + ActorBirthDay + "'," +
"'" + brief + "',0);"; //Zero for actor tpyes
int res = dbMan.ExecuteNonQuery(query);
if (res == 1) {
query = "select * from crew_members where member_name = '" + ActorName + "' and birth_date=" + "'" + ActorBirthDay + "' ;";
ResultSet actor = dbMan.ExecuteReader(query);
int actorID;
if (actor.next()) {
actorID = actor.getInt("member_id");
} else return -1;
query = "Insert into actors values (" + actorID + ");";
return dbMan.ExecuteNonQuery(query);
} else return -1;
}
public int InsertDirector(String Name, String BirthDay, String Brief, String Style) throws SQLException {
// String checkquery ="select * from crew_members where member_name = '"+Name+"' and birth_date="+"'"+ BirthDay+"' ;";
String checkquery = "select * from crew_members where member_name = '" + Name + "' ;";
ResultSet actor_exists = dbMan.ExecuteReader(checkquery);
if (actor_exists.next())
return 404; // returns 404 if this crew_member is already exist with same name **
String query = "Insert into crew_members(member_name,birth_date,brief,member_type)" +
" values('" + Name + "'," +
"'" + BirthDay + "'," +
"'" + Brief + "',1);"; //ONE for Director tpyes
int res = dbMan.ExecuteNonQuery(query);
if (res == 1) {
query = "select * from crew_members where member_name = '" + Name + "' and birth_date=" + "'" + BirthDay + "' ;";
ResultSet crew_memb = dbMan.ExecuteReader(query);
int memberID;
if (crew_memb.next()) {
memberID = crew_memb.getInt("member_id");
} else return -1;
query = "Insert into director values (" + memberID + ",'" + Style + "');";
return dbMan.ExecuteNonQuery(query);
} else return -1;
}
public int InsertAuthor(String Name, String BirthDay, String Brief, String Style) throws SQLException {
// String checkquery ="select * from crew_members where member_name = '"+Name+"' and birth_date="+"'"+ BirthDay+"' ;";
String checkquery = "select * from crew_members where member_name = '" + Name + "' ;";
ResultSet actor_exists = dbMan.ExecuteReader(checkquery);
if (actor_exists.next())
return 404; // returns 404 if this crew_member is already exist with same name ** **
String query = "Insert into crew_members(member_name,birth_date,brief,member_type)" +
" values('" + Name + "'," +
"'" + BirthDay + "'," +
"'" + Brief + "',2);"; //TWO for Director tpyes
int res = dbMan.ExecuteNonQuery(query);
if (res == 1) {
query = "select * from crew_members where member_name = '" + Name + "' and birth_date=" + "'" + BirthDay + "' ;";
ResultSet crew_memb = dbMan.ExecuteReader(query);
int memberID;
if (crew_memb.next()) {
memberID = crew_memb.getInt("member_id");
} else return -1;
query = "Insert into authors values (" + memberID + ",'" + Style + "');";
return dbMan.ExecuteNonQuery(query);
} else return -1;
}
public ResultSet SelectAllCrewMembers() throws SQLException {
String query = "select * from crew_members;"; //Zero for Director tpyes
return dbMan.ExecuteReader(query);
}
public ResultSet SelectAllMovies() throws SQLException {
String query = "select * from movies;"; //Zero for Director tpyes
return dbMan.ExecuteReader(query);
}
public ResultSet SelectAllAdvs() throws SQLException {
String query = "select * from advertisement;"; //Zero for Director tpyes
return dbMan.ExecuteReader(query);
}
public ResultSet SelectAllActors() throws SQLException
{ String query = "select * from crew_members,actors where member_id=actors_id ;"; //
return dbMan.ExecuteReader(query);
}
public ResultSet SelectAllDirectors() throws SQLException
{ String query = "select * from crew_members,director where member_id=director_id ;"; //
return dbMan.ExecuteReader(query);
}
public ResultSet SelectAllAuthors() throws SQLException
{ String query = "select * from crew_members,authors where member_id=authors_id ;"; //
return dbMan.ExecuteReader(query);
}
public ResultSet SelectCinemaByName(String name)
{
String query = "select * from cinema where cinema_name = '" + name + "';";
return dbMan.ExecuteReader(query);
}
public ResultSet SelectAdvByName(String name)
{
String query = "select * from advertisement where ad_title = '" + name + "';";
return dbMan.ExecuteReader(query);
}
public ResultSet SelectCrewMemberByName(String name)
{
String query = "select * from crew_members where member_name = '" + name + "';";
return dbMan.ExecuteReader(query);
}
public ResultSet SelectAuthorByName(String name)
{
String query = "select * from crew_members,authors where member_name = '" + name + "' and authors_id=member_id ;";
return dbMan.ExecuteReader(query);
}
public ResultSet SelectDirectorByName(String name)
{
String query = "select * from crew_members,director where member_name = '" + name + "' and director_id=member_id ;";
return dbMan.ExecuteReader(query);
}
public int UpdateActor(String newName,String newDate,String newBrief , String IdName)
{
String query = "Update crew_members SET member_name = '" + newName + "'" +
" , birth_date = '" + newDate +"' , brief = '" + newBrief +"' "+
"where member_name ="+"'" +IdName+"';";
return dbMan.ExecuteNonQuery(query);
}
public int UpdateAuthor(String newName,String newDate,String newBrief ,String newStyle, String IdName)throws SQLException
{
String query = "Update crew_members SET member_name = '" + newName + "'" +
" , birth_date = '" + newDate +"' , brief = '" + newBrief +"' "+
"where member_name ="+"'" +IdName+"';";
int res = dbMan.ExecuteNonQuery(query);
if (res==1) {
query = "select * from crew_members where member_name = '" + newName + "' ;";
ResultSet crew_memb = dbMan.ExecuteReader(query);
int memberID;
if (crew_memb.next()) {
memberID = crew_memb.getInt("member_id");
query = "Update authors SET writing_style = '" + newStyle + "'" +
"where authors_id ="+"'" +memberID+"';";
return dbMan.ExecuteNonQuery(query);
}
}
return -1;
}
public int UpdateDirector(String newName,String newDate,String newBrief ,String newStyle, String IdName)throws SQLException
{
String query = "Update crew_members SET member_name = '" + newName + "'" +
" , birth_date = '" + newDate +"' , brief = '" + newBrief +"' "+
"where member_name ="+"'" +IdName+"';";
int res = dbMan.ExecuteNonQuery(query);
if (res==1) {
query = "select * from crew_members where member_name = '" + newName + "' ;";
ResultSet crew_memb = dbMan.ExecuteReader(query);
int memberID;
if (crew_memb.next()) {
memberID = crew_memb.getInt("member_id");
query = "Update Director SET making_style = '" + newStyle + "'" +
"where director_id ="+"'" +memberID+"';";
return dbMan.ExecuteNonQuery(query);
}
}
return -1;
}
public int UpdateCinema(String name,String location ,String IdName)throws SQLException
{
String query = "Update cinema SET cinema_name = '" + name + "'" +
" , cinema_location = '" + location +"'"+
"where cinema_name ="+"'" +IdName+"';";
return dbMan.ExecuteNonQuery(query);
}
public int UpdateAdv(String title,String companyname,String startdate,String enddate,String content,String price,String url,String AdvIdentify)throws SQLException
{
String query = "Update advertisement SET ad_title = '" + title + "'" +
" , company_name= '" + companyname +"'"+
" , ad_start_date= '" + startdate +"'"+
" , ad_end_date= '" + enddate +"'"+
" , ad_content= '" + content +"'"+
" , price = " + price +
" , url = '" + url +"'"+
"where ad_title ="+"'" +AdvIdentify+"';";
return dbMan.ExecuteNonQuery(query);
}
public ResultSet SelectAllCinemas()throws SQLException
{
String query = "select * from cinema;" ;
return dbMan.ExecuteReader(query);
}
public int DeleteMovie(String name)throws SQLException
{
String query = "delete from movies where movie_name ='"+name+"';" ; //Zero for Director tpyes
return dbMan.ExecuteNonQuery(query);
}
public int DeleteCinema(String name)throws SQLException
{
String query = "delete from cinema where cinema_name ='"+name+"';" ; //Zero for Director tpyes
return dbMan.ExecuteNonQuery(query);
}
public int DeleteCrewMember(String name)throws SQLException
{
String query = "delete from crew_members where member_name ='"+name+"';" ; //Zero for Director tpyes
return dbMan.ExecuteNonQuery(query);
}
public int DeleteAdv(String name)throws SQLException
{
String query = "delete from advertisement where ad_title ='"+name+"';" ; //Zero for Director tpyes
return dbMan.ExecuteNonQuery(query);
}
//------------------------------------>
public int InsertRequest(String Name,int ID) throws SQLException
{
String checkquery = "select * from movies where movie_name = '" + Name + "';";
ResultSet movie_exists = dbMan.ExecuteReader(checkquery);
if (movie_exists.next())
return 404; // returns 404 if this crew_member is already exist with same name and birthday
String date = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(new Date());
String query = "Insert into request (req_movie_name,req_date,follower_id)"+
" values('"+Name+"',"+
"'"+date+"',"
+ID+");" ;
return dbMan.ExecuteNonQuery(query);
}
public ResultSet ViewAllRequests() throws SQLException {
String query = "select req_movie_name from request ;";
return dbMan.ExecuteReader(query);
}
public ResultSet ViewHistory(int id) throws SQLException {
String query = "select movie_name from history h,movies m where h.movie_id=m.movie_id and follower_id="+id+" ;";
return dbMan.ExecuteReader(query);
}
public ResultSet ViewWishlist(int id) throws SQLException {
String query = "select movie_name from wishlist w,movies m where w.movie_id=m.movie_id and follower_id="+id+" ;";
return dbMan.ExecuteReader(query);
}
public int ChangePass(String oldpass,String newpass,int id,int priv) throws SQLException {
if(priv==2) {
String q="Select fpassword from follower where follower_id="+id+";";
ResultSet a = dbMan.ExecuteReader(q);
a.next();
String p=a.getString("fpassword");
if(!p.equals(oldpass))
{
return 77;
}
String query = "Update follower " +
" set fpassword='" + newpass + "'" +
" where follower_id=" + id +
" And fpassword='" + oldpass + "';";
return dbMan.ExecuteNonQuery(query);
}
else {
String q="Select a_password from admins where admin_id="+id+";";
ResultSet a = dbMan.ExecuteReader(q);
a.next();
String p=a.getString("a_password");
if(!p.equals(oldpass))
{
return 77;
}
String query = "Update admins " +
" set a_password='" + newpass + "'" +
" where admin_id=" + id +
" And a_password='" + oldpass + "';";
return dbMan.ExecuteNonQuery(query);
}
}
public int InsertActorToMovie(String ActorName, String moviename,String ChName) throws SQLException {
String query = "select * from crew_members where member_name = '"+ActorName+"' and member_type=0;";
ResultSet actor = dbMan.ExecuteReader(query);
int actorID;
if(actor.next())
{ actorID=actor.getInt("member_id"); }
else return 400;// returns 400 if there is no actor with this name
String query2 = "select * from movies where movie_name = '"+moviename+"';";
ResultSet movie= dbMan.ExecuteReader(query2);
int movieID;
if(movie.next())
{ movieID=movie.getInt("movie_id"); }
else return 404;// returns 404 if there is no movie with this name
String checkQuery="select* from actors_movie where actors_id="+actorID+" and movie_id="+movieID+";";
ResultSet rs = dbMan.ExecuteReader(checkQuery);
if(!rs.equals(null) && rs.next())
return 22;
query="Insert into actors_movie values ("+actorID+","+movieID+",'"+ChName+"');";
return dbMan.ExecuteNonQuery(query);
}
public ResultSet GetActorNames() throws SQLException {
String query = "select member_name from crew_members where member_type=0;";
return dbMan.ExecuteReader(query);
}
public ResultSet GetMovieNames() throws SQLException {
String query = "select movie_name from movies ;";
return dbMan.ExecuteReader(query);
}
public int InsertInWishList(int followerId,int movieId)
{
String query ="Insert into wishlist values("+followerId+","+movieId+");";
return dbMan.ExecuteNonQuery(query);
}
public int InsertInHistoryList(int followerId,int movieId)
{
String query ="Insert into history values("+followerId+","+movieId+");";
return dbMan.ExecuteNonQuery(query);
}
public ResultSet getMostWished()
{
String query = "\n" +
"select movie_name,m.movie_id,count(follower_id) as temp from wishlist w join movies m on m.movie_id =w.movie_id \n" +
"group by m.movie_id,movie_name \n" +
"order by temp desc;\n";
return dbMan.ExecuteReader(query);
}
public ResultSet getMostViewed()
{
String query = "\n" +
"select movie_name,m.movie_id,count(follower_id) as temp from history w join movies m on m.movie_id =w.movie_id \n" +
"group by m.movie_id,movie_name \n" +
"order by temp desc;\n";
return dbMan.ExecuteReader(query);
}
public ResultSet getMostRated()
{
String query = "select movie_name from movies order by reviewers_rating desc ;";
return dbMan.ExecuteReader(query);
}
public ResultSet getNewReales()
{
String query = "select movie_name from movies order by release_date desc ;";
return dbMan.ExecuteReader(query);
}
public int recordUserRate(int followerId,int movieId,String rate) throws SQLException {
String check="select * from follower_rating where movie_id="+movieId+" and follower_id="+followerId+";";
ResultSet s=dbMan.ExecuteReader(check);
if(s!=null&&s.next())
{
String query="update follower_rating set rating="+rate+" where movie_id="+movieId+";";
return dbMan.ExecuteNonQuery(query);
}
String query ="Insert into follower_rating values("+movieId+","+followerId+","+rate+");";
return dbMan.ExecuteNonQuery(query);
}
public ResultSet getAvgUserRating(int movieId)
{
String query="Select Avg(rating) ar from follower_rating where movie_id="+movieId+";";
return dbMan.ExecuteReader(query);
}
ResultSet authors_names ()
{
String query = "select member_name,member_id from authors join crew_members on authors_id = member_id ;";
return dbMan.ExecuteReader(query);
}
ResultSet directors_names ()
{
String query = "select member_name,member_id from director join crew_members on director_id = member_id ;";
return dbMan.ExecuteReader(query);
}
int Add_Genre(String m_id,String Gen)throws SQLException
{
String query = "insert into genre values ('"+m_id+"',lower('"+Gen+"'));";
return dbMan.ExecuteNonQuery(query);
}
public int InsertNewMovie(String name,String desc,String lang,
String age_rest,String rdate,
String reviewers,String url,
String duration,int Admin_id,String Aut_id
,String dir_id )throws SQLException
{
String checkquery ="select * from movies where movie_name = lower('"+name+"') and release_date="+"'"+ rdate+"' ;";
ResultSet movie_exists = dbMan.ExecuteReader(checkquery);
if(movie_exists.next())
return 404; // returns 404 if this crew_member is already exist with same name and birthday
String query ="insert into movies values (lower('"+name+"'),lower('"+desc+"'),lower('"+lang+"'),"
+Integer.parseInt(age_rest)+",'"+rdate+"',"+0.0+","+Float.parseFloat(reviewers)+",'"+url+"','"+duration+"',"+Admin_id
+","+Integer.parseInt(Aut_id)+","+Integer.parseInt(dir_id)+");";
return dbMan.ExecuteNonQuery(query);
}
public int getMovieId(String name,String date)throws SQLException
{
String query ="select movie_id from movies where movie_name = '"+name+"' and release_date="+"'"+ date+"' ;";
ResultSet r = dbMan.ExecuteReader(query);
if(r.next()) {
String s =r.getString(1);
return Integer.parseInt(s);
}
return -1;
}
public int InsertAward(String Aname,int Atype,String Fname,String Fdate,String Floc)throws SQLException
{
String checkquery = "select * from award where award_name = lower('"+Aname+"') and award_type = "+
Atype + " and fest_name = lower('"+Fname+"') and fest_date = lower('"+Fdate+"') and fest_location = lower('"+
Floc +"');";
ResultSet r = dbMan.ExecuteReader(checkquery);
if(r.next())
return 404;
String query = "insert into award values(lower('"+Aname+"'),"+Atype+",lower('"+Fname+"'),lower('"+
Fdate+"'),lower('"+Floc+"'));";
return dbMan.ExecuteNonQuery(query);
}
public ArrayList<String> SetNamesToArray (ResultSet names , ArrayList<String> id_list) throws SQLException
{
ArrayList<String> Names = new ArrayList<String>();
try{
while (names.next())
{
Names.add(names.getString(1));
id_list.add(names.getString(2));
}
}catch (java.sql.SQLException e)
{
}
return Names;
}
public ResultSet get_movies()throws SQLException{
String query="select movie_name,movie_id from movies; ";
return dbMan.ExecuteReader(query);
}
public ResultSet getAward(int typ)throws SQLException
{
String query = "select award_name , award_id from award where award_type = "+typ+";";
return dbMan.ExecuteReader(query);
}
//////////////////add_movie///////////////////
public int UpdateAward(String newName,String festloc,int awardtype,String festname, String festdate, String oldName)
{
String query = "Update award SET award_name = '" + newName + "'" +
" , fest_location = '" + festloc +"' , award_type = '" + awardtype +"' "+
" , fest_name = '" + festname +"' , fest_date = '" + festdate +"' "+
" where award_name ="+"'" +oldName+"';";
return dbMan.ExecuteNonQuery(query);
}
public int UpdateMovie(String newName,String language ,String des, String ageR,String url,String reviewerRating,String duration ,String oldName)
{
String query = "Update movies SET movie_name = '" + newName + "'" +
" , movie_language = '" + language +"' , movie_description = '" + des +"' "+
" , age_resriction = '" + ageR +"' , url = '" + url +"' "+
" , reviewers_rating = '" + reviewerRating +"' , duration = '" + duration +"' "+
"where movie_name ="+"'" +oldName+"';";
return dbMan.ExecuteNonQuery(query);
}
public ResultSet SelectAwardByName(String name)
{
String query = "select * from award where award_name = '" + name + "';";
return dbMan.ExecuteReader(query);
}
public ResultSet SelectAllAwards() throws SQLException {
String query = "select * from award;"; //Zero for Director tpyes
return dbMan.ExecuteReader(query);
}
public ResultSet getNoOfMovieForDirector(int directorId)
{
String query = "select count(*) from crew_members a,movies m where member_type=2 and a.member_id=m.director_id and director_id="+directorId+";'"; //Zero for Director tpyes
return dbMan.ExecuteReader(query);
}
public ResultSet getNoOfMovieForAuthor(int authorId)
{
String query = "select count(*) from crew_members a,movies m where member_type=1 and a.member_id=m.authors_id and authors_id="+authorId+";'"; //Zero for Director tpyes
return dbMan.ExecuteReader(query);
}
public ResultSet getNoOfMovieForActor(int actorId)
{
String query = "select count(*) from actors_movie where actors_id="+actorId+";"; //Zero for Director tpyes
return dbMan.ExecuteReader(query);
}
public ResultSet getNoOfAwardsForMember(int memberId)
{
String query = "select count (member_id) from movie_member_award where member_id="+memberId+";"; //Zero for Director tpyes
return dbMan.ExecuteReader(query);
}
public ResultSet getNoOfAwardsForMovie(int movieId)
{
String query = "select count (movie_id) from movie_member_award where movie_id="+movieId+";'"; //Zero for Director tpyes
return dbMan.ExecuteReader(query);
}
public int SelectMovieIDByName(String name)throws SQLException
{
String query = "select * from movies where movie_name = '" + name + "';";
ResultSet r = dbMan.ExecuteReader(query);
r.next();
int id = r.getInt("movie_id");
return id;
}
public int SelectRequestIDByName(String name)throws SQLException
{
String query = "select * from request where req_movie_name = '" + name + "';";
ResultSet r = dbMan.ExecuteReader(query);
r.next();
int id = r.getInt("req_id");
return id;
}
public int DeleteFromWsihlist(int uid,int mid)throws SQLException
{
String query = "delete from wishlist where follower_id ="+uid+" and movie_id = "+mid+";" ;
return dbMan.ExecuteNonQuery(query);
}
public int DeleteFromHistory(int uid,int mid)throws SQLException
{
String query = "delete from history where follower_id ="+uid+" and movie_id = "+mid+";" ;
return dbMan.ExecuteNonQuery(query);
}
public int DeleteFromRequest(int rid)throws SQLException
{
String query = "delete from request where req_id ="+rid+" ;" ;
return dbMan.ExecuteNonQuery(query);
}
public ResultSet getEmailAddressAdmins(String username)
{
String query="Select email from admins where username='"+username+"';";
return dbMan.ExecuteReader(query);
}
public ResultSet getEmailAddressFollowers(String username)
{
String query="Select email from follower where username="+username+";";
return dbMan.ExecuteReader(query);
}
//Statistics
public ResultSet getStatFavCat(int id)throws SQLException{
String query ="select g.genre, Count(*) from wishlist w join genre g on g.movie_id = w.movie_id where w.follower_id =" +id+" group by g.genre;";
return dbMan.ExecuteReader(query);
}
public ResultSet getStatHistCat(int id)throws SQLException{
String query ="select g.genre, Count(*) from history w join genre g on g.movie_id = w.movie_id where w.follower_id = "+id+" group by g.genre";
return dbMan.ExecuteReader(query);
}
public String getVisitedM(int id)throws SQLException
{
String query = "select COUNT(*) from history where follower_id ="+id+";";
return (String)dbMan.ExecuteScalar(query);
}
public String getLikeddM(int id)throws SQLException
{
String query = "select COUNT(*) from wishlist where follower_id ="+id+";";
return (String)dbMan.ExecuteScalar(query);
}
public String getRateddM(int id)throws SQLException
{
String query = "select COUNT(*) from follower_rating where follower_id ="+id+";";
return (String)dbMan.ExecuteScalar(query);
}
public String getReqdM(int id)throws SQLException
{
String query = "select COUNT(*) from request where follower_id ="+id+";";
return (String)dbMan.ExecuteScalar(query);
}
public String getAdminActivityInfo (int t ,int id)throws SQLException {
String query;
switch (t) {
case 0: //admin movies
query = "select count(*) from movies m join admins a on m.admin_id=a.admin_id where a.admin_id = " + id + ";";
return (String) dbMan.ExecuteScalar(query);
case 1: //admin ads
query = "select count(*) from advertisement m join admins a on m.admin_id=a.admin_id where a.admin_id ="+id+";";
return (String)dbMan.ExecuteScalar(query);
case 2: //admin requests
query = "select count(*) from request m join admins a on m.admin_id=a.admin_id where a.admin_id ="+id+";";
return (String)dbMan.ExecuteScalar(query);
}
return "0";
}
public String getDatabaseInfo(int t)throws SQLException
{
String query;
switch (t)
{
case 0 :
query="Select count(*) from movies ;";
return (String)dbMan.ExecuteScalar(query);
case 1 :
query="Select count(*) from actors ;";
return (String)dbMan.ExecuteScalar(query);
case 2 :
query="Select count(*) from authors ;";
return (String)dbMan.ExecuteScalar(query);
case 3 :
query="Select count(*) from director ;";
return (String)dbMan.ExecuteScalar(query);
case 4 :
query="Select count(*) from cinema ;";
return (String)dbMan.ExecuteScalar(query);
case 5 :
query="Select count(*) from award ;";
return (String)dbMan.ExecuteScalar(query);
case 6 :
query="Select count(*) from advertisement ;";
return (String)dbMan.ExecuteScalar(query);
case 7 :
query="Select count(*) from follower ;";
return (String)dbMan.ExecuteScalar(query);
case 8 :
query="Select count(*) from admins ;";
return (String)dbMan.ExecuteScalar(query);
}
return "0";
}
public ResultSet getStatMostLiked()
{
String query = "select movie_name,count(follower_id) as temp from wishlist w join movies m on m.movie_id =w.movie_id \n" +
" group by m.movie_id,movie_name \n" +
" order by temp desc;";
return dbMan.ExecuteReader(query);
}
public ResultSet getStatMostViewed()
{
String query = "\n" +
"select movie_name,count(follower_id) as temp from history w join movies m on m.movie_id =w.movie_id \n" +
"group by m.movie_id,movie_name \n" +
"order by temp desc;\n";
return dbMan.ExecuteReader(query);
}
public ResultSet getStatMostRated()
{
String query = "select movie_name,users_rating from movies order by reviewers_rating desc ;";
return dbMan.ExecuteReader(query);
}
///Award
public int add_award_to_movie(String M_id,String A_id,String date)throws SQLException{
String checkQuery = "select * from movie_member_award where movie_id = "+M_id+"and award_id = "+A_id+"and winning_date = '"+date+"';";
ResultSet r =dbMan.ExecuteReader(checkQuery);
if(r.next())
return 404;
String query = "insert into movie_member_award (movie_id,award_id,winning_date) values ("+M_id+","+A_id+",'"+date+"');";
return dbMan.ExecuteNonQuery(query);
}
public int add_award_to_author(String M_id,String Act_id ,String A_id,String date)throws SQLException{
String checkQuery = "select * from movie_member_award where movie_id = "+M_id+"and award_id = "+A_id+"and member_id = "+Act_id+";";
ResultSet r =dbMan.ExecuteReader(checkQuery);
if(r.next())
return 404;
String checkauthor = "select * from movies where authors_id ="+Act_id+";";
ResultSet r2 = dbMan.ExecuteReader(checkauthor);
if(!r2.next())
return -1;
String query = "insert into movie_member_award values ("+M_id+","+Act_id+","+A_id+",'"+date+"');";
return dbMan.ExecuteNonQuery(query);
}
public int add_award_to_director(String M_id,String Act_id ,String A_id,String date)throws SQLException{
String checkQuery = "select * from movie_member_award where movie_id = "+M_id+"and award_id = "+A_id+"and member_id = "+Act_id+";";
ResultSet r =dbMan.ExecuteReader(checkQuery);
if(r.next())
return 404;
String checkauthor = "select * from movies where director_id ="+Act_id+";";
ResultSet r2 = dbMan.ExecuteReader(checkauthor);
if(!r2.next())
return -1;
String query = "insert into movie_member_award values ("+M_id+","+Act_id+","+A_id+",'"+date+"');";
return dbMan.ExecuteNonQuery(query);
}
public int add_award_to_actor(String M_id,String Act_id ,String A_id,String date)throws SQLException{
String checkQuery = "select * from movie_member_award where movie_id = "+M_id+"and member_id = "+Act_id+"and award_id = "+A_id+";";
ResultSet r =dbMan.ExecuteReader(checkQuery);
if(r.next())
return 404;
String checkactor = "select movie_name,m.movie_id from actors_movie a join movies m on m.movie_id = a.movie_id where a.actors_id ="+Act_id+"; ";
ResultSet r1 =dbMan.ExecuteReader(checkactor);
if(!r1.next())
return -1;
String query = "insert into movie_member_award values (" + M_id + "," + Act_id + "," + A_id + ",'" + date + "');";
return dbMan.ExecuteNonQuery(query);
}
public ResultSet actors_names ()throws SQLException
{
String query = "select member_name,member_id from actors join crew_members on actors_id = member_id ;";
return dbMan.ExecuteReader(query);
}
public ResultSet getMemberMovies(int t,String id)throws SQLException{
String query = "";
switch (t){
case (0): //actor
query = "select movie_name,m.movie_id from actors_movie a join movies m on m.movie_id = a.movie_id where a.actors_id ="+id+";";
break;
case (1): //author
query = "select movie_name,movie_id from movies where authors_id ="+id+";";
break;
case (2): //director
query = "select movie_name,movie_id from movies where director_id ="+id+";";
break;
}
return dbMan.ExecuteReader(query);
}
public ResultSet getAwardName (int id)throws SQLException
{
String query = "select award_name from award a,movie_member_award m where a.award_id=m.award_id and member_id="+id+";";
return dbMan.ExecuteReader(query);
}
public ResultSet cinema_names ()throws SQLException
{
String query = "select * from cinema;";
return dbMan.ExecuteReader(query);
}
public ResultSet movie_cinema_names (String name)throws SQLException
{
int id=-1;
String perquisite="Select cinema_id from cinema where cinema_name='"+name+"';";
ResultSet temp=dbMan.ExecuteReader(perquisite);
if(temp!=null&&temp.next())
id=temp.getInt(1);
String query = "select movie_name from movies m,available_at a where m.movie_id=a.movie_id and cinema_id="+id+";";
return dbMan.ExecuteReader(query);
}
}