.NET MVC 分页以及增删查改

这个博客介绍了如何使用.NET MVC进行电影数据的增删查改操作。在DAL层,展示了如何通过存储过程进行分页查询、获取总数、详情查询、更新和删除电影。在Controller层,实现了电影列表展示、编辑、删除和创建的功能。最后,前台页面包含创建、编辑和显示电影列表的HTML,并使用了简单的JavaScript交互。
摘要由CSDN通过智能技术生成

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;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sust2012

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值