分享
 
 
 

一步一步打造3层架构在线电影网站!(4)系统设计

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

1、 数据层

数据层由四个类组成,其中两个位信息承载类,MovieDetails and CategoryDetails,只有属性,无任何方法,分别代表表movies和categories中某行。另外两个为基本数据操作类,提供相应的具体数据操作,分别为:Movies and Categories。

以下分别用类图表示四个类的具体情况:

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():<unspecified>

+GetAllMovies():<unspecified>

+GetMoviesByCount():<unspecified>

+GetHeadlines():<unspecified>

+GetGetMovieDetails():<unspecified>

+GetDetailsRow():<unspecified>

+Add():int

+Update():bool

+Delete():bool

+AddViewcount():bool

Categories

+Categories(in connectionString:string)

+GetCategories():<unspecified>

+GetCategoryName():<unspecified>

+GetCategoryDetails():<unspecified>

+GetDetailsRow():<unspecified>

+Add():int

+Update():bool

+Delete():bool

以下详细描述两个基本数据操作类的方法:

Movies:

方法详情

描述

public Movies( string newConnectiionString)

类构造函数,以连接字符串作为参数

public DataSet GetMovies(int category_id)

返回指定类型的所有电影条目

public DataSet GetHeadines(int category_id)

返回指定类型条目的所有电影条目的movie_id、title、uptime、viewcount、image

public DataSet GetAllMovies()

以上传时间为顺序返回所有电影信息

public DataSet GetMoviesByCount()

以点击率为顺序返回所有电影信息

public DataSet GetHeadlines(int category_id)

返回某一分类的电影头信息

public MoviesDetails GetMovieDetails(int movie_id)

返回一个由movie_id指定的电影条目的具体内容

public DataRow GetDetailsRow(int movie_id)

返回电影详细信息的DataRow

public int Add(int category_id,string level,string title,string intro,datetime uptime,datetime showtime,string image,string address)

添加新的电影条目,如果成功则返回新的movie_id,如果有重复记录,则返回-1

public bool Update(int movie_id,int category_id,string level,string title,string intro,datetime showtime, string image,string address)

更新指定电影条目的相关信息

public bool Delete(int movie_id)

删除指定的电影条目

public bool AddViewcount(int movie_id)

给指定的电影条目增加1单位访问量

Categories:

方法详情

描述

public Categories( string newConnectiionString)

类构造函数,以连接字符串作为参数

public DataSet GetCategories()

返回包含所有分类的DataSet

public DataSet GetCategoryName()

返回所有分类的名称和编号

public CategoryDetails GetCategoryDetails(int category_id)

返回描述指定分类的CategoryDetails实例

public DataRow GetDetailsRow(int category_id)

返回指定ID分类条目的DataRow

public int Add(string name,string category_intro)

添加新的分类条目,如果成功则返回新的category_id,如果有重复记录,则返回-1

public bool Update(int category_id,string name,string category_intro)

更新指定分类条目的详细信息

public bool Delete(int category_id)

删除指定分类条目

Movies:

using System;

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 Movies(string newConnectionString) : 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["levell"].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(rowMovie["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 values

parameters[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 numAffected);

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 values

parameters[0].Value = category_id;

parameters[1].Value = level.Trim();

parameters[2].Value = title.Trim();

parameters[3].Value = intro.Trim();

parameters[4].Value = uptime;

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 Categories(string newConnectionString) : 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 numAffected);

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 values

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 values

parameters[0].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;

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有