Step by step to create a 3-storey architecture online movie website! (4) System design

xiaoxiao2021-03-06  43

1, data layer

The data layer consists of four classes, two of which bearer, Moviedetails and CategoryDetails, only attributes, no way, represents a row in Movies and Categories, respectively. The other two are basic data operation classes, providing corresponding specific data operations, respectively: Movies and categories.

The following uses the class diagram to represent the specific situation of the four classes:

Moviedetails

MOVIE_ID: INT

Category_ID: INT

Level: String

Title: String

Intro: String

UPTime: DateTime

ShowTime: DateTime

ViewCount: int

Image: String

Address: String

CategoryDetails

Category_ID: INT

Name: String

Category_Intro: String

Movie

Movies (in Connectionstring: String)

GetMovies ():

GetMovies ():

GetMoviesbycount ():

GetHeadLines ():

Getgetmoviedetails ():

GetDetailsrow ():

Add (): int

UPDATE (): BOOL

Delete (): bool

AddViewCount (): bool

Categories

Categories (in connectionString: string)

Getcategories ():

GetCategoryName ():

GetCategoryDetails ():

GetDetailsrow ():

Add (): int

UPDATE (): BOOL

Delete (): bool

Two basic data operation classes are described in detail below:

Movies:

Method details

description

Public Movies (String NewConnectiionstring)

Class constructor to connect strings as parameters

Public Dataset getMovies (int Category_ID)

Returns all movie entries for the specified type

Public DataSet GetHeadines (int Category_ID)

Returns all movie entries for the specified type entry Movie_ID, Title, Uptime, ViewCount, Image

Public Dataset getMovies ()

Returns all movie information in order for uploading time

Public Dataset getMoviesbycount ()

Returns all movie information in order to click rate

Public DataSet GetHeadlines (int Category_ID)

Returns a category movie head information

Public MoviesDetails getMoviedetails (int movie_id)

Returns a specific content of the movie entry specified by MOVIE_ID PUBLIC DATAROW GETDETAILSROW (int movie_id)

Returns DataRow for movie details

Public Int Add (int Category_ID, String Level, String Title, String Intro, DateTime Uptime, DateTime ShowTime, String Image, String Address)

Add a new movie entry, if success, return new movie_id if there is a repeated record, return -1

Public Bool Update (int movie_id, int category_id, string level, string title, string intertime showtime, string image, string address)

Update information about the specified movie entry

Public Bool Delete (int movie_id)

Delete the specified movie entry

Public Bool AddViewCount (int movie_id)

Add 1 unit access to the specified movie entry

Categories:

Method details

description

Public categories (String newConnectiionstring)

Class constructor to connect strings as parameters

Public DataSet getcategories ()

Returns a DataSet with all categories

Public Dataset getcategoryName ()

Return to all categories of names and numbers

Public CategoryDetails getcategoryDetails (int category_id)

Returns a CategoryDetails instance that describes the specified classification

Public DataRow getDetailsRow (int category_id)

Returns the DataRow specified by the ID classification entry

Public Int Add (String Name, String Category_Intro)

Add a new category entry, if success, return new category_id, return -1 if there is a repeated record

Public Bool Update (int Category_ID, String Name, String Category_Intro)

Update details of specified classification entry

Public Bool Delete (int Category_ID)

Delete the specified classification entry

Using system.data; using system.data.sqlclient;

namespace Coofucoo.Data {public class MovieDetails {public int movie_id; public int category_id; public string level; public string title; public string intro; public DateTime uptime; public DateTime showtime; public int viewcount; public string image; public string address;}

Public class movies: coofucoo.core.dbobject {public moviestring: base (newconnectionstring) {}

// return all the Movie of the specified category public DataSet GetMovies (int category_id) {// create the parameters SqlParameter [] parameters = {new SqlParameter ( "@ category_id", SqlDbType.Int, 4)}; // set the values parameters [0] .Value = category_id; return RunProcedure ( "GetMovies", parameters, "movies");} // return all the Movie order by upload time public DataSet GetAllMovies () {return RunProcedure ( "GetAllMovies", new IDataParameter [ ] {}, "movies");

Public DataSet getMoviesbycount () {Return Runprocedure ("getMoviesbycount", new iDataParameter [] {}, "moviesbycount");

// return the headlines for the current and approved Movie public DataSet GetHeadlines (int category_id) {// create the parameter SqlParameter [] parameters = {new SqlParameter ( "@ category_id", SqlDbType.Int, 4)}; parameters [0] .Value = category_id; Return Runprocedure ("GetHeadines", parameters, "headlines");}

// return only the record with the specified ID public MovieDetails GetMovieDetails (int movie_id) {// create the parameter SqlParameter [] parameters = {new SqlParameter ( "@ movie_id", SqlDbType.Int, 4)}; parameters [0]. Value = movie_id; using (DataSet Movie = RunProcedure ( "GetMovieDetails", parameters, "MovieDetails")) {MovieDetails details = new MovieDetails (); // if the record was found, set the properties of the class instance if (Movie. Tables [0]. ROWS.COUNT> 0) {DATAROW ROWMOVIE = MOVIE.TABLES [0]. Rows [0]; Details.Movie_id = Convert.Toint32 (RowMovie ["Movie_ID"]); Details.category_ID = Convert.Toint32 (RowMovie ["Category_ID"]); Details.Level = RowMovie ["Level"]. TOSTRING (); Details.title = ROWMOVIE ["Title"]. Tostring (); Details.Intro = ROWMOVIE ["INTRO"]. TOSTRING (); details.uptime = convert.todatetime (RowMovie ["uPtime"]); details.showtime = convert.todatetime (RowMovie ["ShowTime"]); Details.ViewCount = Convert.Toint32 (Rowmov IE ["ViewCount"]); details.image = rowmovie ["Image"]. TOSTRING (); Details.address = ROWMOVIE ["address"]. Tostring ();} else details.movie_id = -1; return Details; }

// return only the record with the specified ID public DataRow GetDetailsRow (int movie_id) {// create the parameter SqlParameter [] parameters = {new SqlParameter ( "@ movie_id", SqlDbType.Int, 4)}; parameters [0]. Value = movie_id; using (DataSet Movie = RunProcedure ( "GetMovieDetails", parameters, "MovieDetailsRow")) {return Movie.Tables [0] .Rows [0];}} // delete the record identified by the specified ID public bool Delete (int movie_id) {int numAffected; // create the parameter SqlParameter [] parameters = {new SqlParameter ( "@ movie_id", SqlDbType.Int, 4)}; parameters [0] .Value = movie_id; RunProcedure ( "DeleteMovie" Parameters, Out NumaffECTED;

Return (Numaffected == 1);

// update the Movie identified by the specified ID public bool Update (int movie_id, int category_id, string level, string title, string intro, DateTime showtime, string image, string address) {int numAffected; // create the parameters SqlParameter [] parameters = {new SqlParameter ( "@ movie_id", SqlDbType.Int, 4), new SqlParameter ( "@ category_id", SqlDbType.Int, 4), new SqlParameter ( "@ levell", SqlDbType.NVarChar, 50), new SqlParameter ( "@title", SqlDbType.NVarChar, 50), new SqlParameter ( "@ intro", SqlDbType.Text), new SqlParameter ( "@ showtime", SqlDbType.DateTime), new SqlParameter ( "@ image", SqlDbType.NVarChar , 100), New SqlParameter ("@ address", sqldbtype.nvarchar, 100),}; // set the value} [0] .value = movie_id; parameters [1] .value = category_id; parameters [2] .value = Level.trim (); parameters [3] .value = Title.trim (); parameters [4] .value = intro.trim (); parameters 5] .value = showtime; parameters [6] .value = image.trim (); parameters [7] .value = address.trim (); Runprocedure ("Updatemovie", parameters, out number

Return (Numaffected == 1);

// add a Movie public int Add (int category_id, string level, string title, string intro, DateTime uptime, DateTime showtime, string image, string address) {int numAffected; // create the parameters SqlParameter [] parameters = {new SqlParameter ("@category_id", sqldbtype.int, 4), New Sqlparameter ("@ Level", Sqldbtype.Nvarchar, 50), New SqlParameter ("@ title", Sqldbtype.nvarchar, 50), New Sqlparameter ("@ INTRO" , SqlDbType.Text), new SqlParameter ( "@ uptime", SqlDbType.DateTime), new SqlParameter ( "@ showtime", SqlDbType.DateTime), new SqlParameter ( "@ image", SqlDbType.NVarChar, 100), new SqlParameter ( "@address", sqldbtype.nvarchar, 100), new sqlparameter ("@ movie_id", sqldbtype.int, 4)}; // set the value, parameters [0] .Value = category_id; parameters [1] .value = level .Trim (); parameters [2] .Value = Title.trim (); parameters [3] .value = intro.trim (); parameters [4] .value = Up Time; parameters [5] .value = showtime; parameters [6] .value = image.trim (); parameters [7] .Value = address.trim (); parameters [8] .direction = parameterdirection.output; Runprocedure ( "Insertmovie", Parameters, Out NumaffECTED;

Return (int) parameters [8] .value;

// set the Viewcount public bool AddViewcount (int movie_id) {int numAffected; // create the parameters SqlParameter [] parameters = {new SqlParameter ( "@ movie_id", SqlDbType.Int, 4)};

// set the values ​​parameters [0] .value = MOVIE_ID;

Runprocedure ("AddViewCount", Parameters, Out Numaffected; Return (Numaffected == 1);}

}} Categories: using System; using System.Data; using System.Data.SqlClient; namespace Coofucoo.Data {public class CategoryDetails {public int category_id; public string name; public string category_intro;}

Public class categories: coofucoo.core.dbobject {public categoriestring: base (newconnectionstring) {}

// Return All The Categories Public Dataset getcategories () {Return Runprocedure ("getcategories", new iDataParameter [] {}, "categories");}

// Return All name of the categories public dataset getcategoryName () {Return Runprocedure ("getcategoryName", new iDataParameter [] {}, "categoryName");}

// return only the record with the specified ID public CategoryDetails GetCategoryDetails (int category_id) {// create the parameter SqlParameter [] parameters = {new SqlParameter ( "@ category_id", SqlDbType.Int, 4)}; parameters [0]. Value = category_id;

using (DataSet categories = RunProcedure ( "GetCategoryDetails", parameters, "CategoryDetails")) {CategoryDetails details = new CategoryDetails (); // if the record was found, set the properties of the class instance if (categories.Tables [0] .Rows.count> 0) {DATAROW ROWCATEGORY = Categories.tables [0] .ROWS [0]; Details.category_ID = (int) Rowcategory ["category_id"]; details.name = rowcategory ["name"]. TOSTRING Details.category_intro = rowcategory ["category_intro"]. TOSTRING ();} else details.category_id = -1;

Return Details;}}

// return only the record with the specified ID public DataRow GetDetailsRow (int category_id) {// create the parameter SqlParameter [] parameters = {new SqlParameter ( "@ category_id", SqlDbType.Int, 4)}; parameters [0]. Value = category_id; using (DataSet Categories = Runprocedure ("getcategorydetails", parameters, "categoryDetails)) {return categories.tables [0] .rows [0];}

// delete the record identified by the specified ID public bool Delete (int category_id) {int numAffected; // create the parameter SqlParameter [] parameters = {new SqlParameter ( "@ category_id", SqlDbType.Int, 4)}; parameters [ 0] .value = category_id; Runprocedure ("deletecategory", parameters, out numias;

Return (Numaffected == 1);

// update Name, Description and ImageUrl of the record identified by the specified ID public bool Update (int category_id, string name, string category_intro) {int numAffected; // create the parameters SqlParameter [] parameters = {new SqlParameter ( "@ category_id "Sqldbtype.int, 4), New SqlParameter (" @ name ", sqldbtype.nvarchar, 50), new sqlparameter (" @ category_intro ", sqldbtype.nvarchar, 100),}; // set the value of parameters [0] .Value = category_id; parameters [1] .Value = name.trim (); parameters [2] .value = category_intro.trim ();

Runprocedure ("Updatecategory", Parameters, Out NumaffECTED;

Return (Numaffected == 1);

// add a new category public int Add (string name, string category_intro) {int numAffected; // create the parameters SqlParameter [] parameters = {new SqlParameter ( "@ name", SqlDbType.VarChar, 50), new SqlParameter ( " @category_intro ", sqldbtype.varchar, 100), new sqlparameter (" @ category_id ", sqldbtype.int, 4),}; // set the value = name.trim (); parameters [1] .Value = category_intro.Trim (); parameters [2] .Direction = ParameterDirection.Output; // run the procedure RunProcedure ( "InsertCategory", parameters, out numAffected); return (int) parameters [2] .Value;}

}

转载请注明原文地址:https://www.9cbs.com/read-75524.html

New Post(0)