-
Notifications
You must be signed in to change notification settings - Fork 0
/
Movies.cs
60 lines (51 loc) · 2.36 KB
/
Movies.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace DSED_02
{
public class Movies
{
Database moviesDatabase = new Database();
sqlMethods sql = new sqlMethods();
private string table = "Movies";
private string fields = "MovieID, Title, Year, Rating, Genre, Rental_Cost, Copies, Plot, Date ";
public DataView ReadEntries(string whereClause)
{
DataView moviesTable = moviesDatabase.SelectAll(fields, table, whereClause);
return moviesTable;
}
public DataView ReadEntriesBestMovies(string whereClause)
{
DataView moviesTable = moviesDatabase.SelectAll("MovieIDFK, Title, Year, Rating, Genre, Rental_Cost, Copies, Date", "Movies_v_Best_v_RentedMovies", whereClause);
return moviesTable;
}
public bool Create(string[] data)
{
string[] parameterAssign = { "@Title", "@Year", "@Rating", "@Genre", "@Rental_Cost", "@Copies", "@Plot" };
string setFields = "Title, Year, Rating, Genre, Rental_Cost, Copies, Plot";
string parameterAssignFields = "@Title, @Year, @Rating, @Genre, @Rental_Cost, @Copies, @Plot";
bool updateData = moviesDatabase.CreateData(table, setFields, parameterAssign, parameterAssignFields, data);
return updateData;
}
public bool Update(string[] data)
{
// parameterDefine, parameterAssign & insertArr need to be the same length.
string[] parameterAssign = { "@MovieID", "@Title", "@Year", "@Rating", "@Genre", "@Rental_Cost", "@Copies", "@Plot" };
string setFields = "Title=@Title, Year=@Year, Rating=@Rating, Genre=@Genre, Rental_Cost=@Rental_Cost, Copies=@Copies, Plot=@Plot";
string whereClause = "WHERE MovieID=@MovieID";
bool updateData = moviesDatabase.UpdateData(table, setFields, whereClause, parameterAssign, data);
return updateData;
}
public bool Delete(string id)
{
string[] parameterAssign = { "@MovieID" };
string whereClause = "WHERE MovieID=@MovieID";
bool updateData = moviesDatabase.Delete(table, whereClause, parameterAssign, id);
return updateData;
}
}
}