1. 数据库操作,DAL 层:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common.DataCommon;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
namespace DAL.DAL.Movie
{
public class MovieDAL
{
private readonly SqlHelper sh = new SqlHelper();
//pager query movie list
public DataTable QueryMovie(int currPage,int pageSize) {
DataTable dt = null;
string procName = "sp_Movie_GetPagerList";
try {
SqlParameter[] sps = {
new SqlParameter("@currPage",SqlDbType.Int),
new SqlParameter("@pageSize",SqlDbType.Int)
};
sps[0].Value = currPage;
sps[1].Value = pageSize;
dt = sh.ExecuteProcWithReturn(procName, sps);
}catch(Exception ex){
throw ex;
}
return dt;
}
//get the movie count
public Int32 GetMovieCount()
{
Int32 count = 1;
string procName = "sp_Movie_GetCount";
try
{
DataTable dt = sh.ExecuteProcWithReturn(procName, null);
if (null != dt){
count = Convert.ToInt32(dt.Rows[0]["mCount"]);
}
}
catch (Exception ex)
{
throw ex;
}
return count;
}
//get the movie detail
public DataTable GetMovie(string movieId)
{
DataTable dt = null;
string procName = "sp_Movie_GetModel";
try
{
SqlParameter[] sps = {
new SqlParameter("@in_Id",SqlDbType.VarChar)
};
sps[0].Value = movieId;
dt = sh.ExecuteProcWithReturn(procName, sps);
}
catch (Exception ex)
{
throw ex;
}
return dt;
}
//upload movie
public bool UpdateMovie(Model.Movie movie) {
bool flag = false;
string callName = "sp_Movie_Update";
try {
SqlParameter[] sps = {
new SqlParameter("@in_Id",SqlDbType.VarChar),
new SqlParameter("@in_Title",SqlDbType.NVarChar),
new SqlParameter("@in_ReleaseDate",SqlDbType.Date),
new SqlParameter("@in_Category",SqlDbType.NVarChar),
new SqlParameter("@in_Price",SqlDbType.Money)
};
sps[0].Value = movie.Id;
sps[1].Value = movie.Title;
sps[2].Value = movie.ReleaseDate;
sps[3].Value = movie.Category;
sps[4].Value = movie.Price;