⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 picturedao.cs

📁 ASP.net网站开发四“酷”全书:新闻、论坛、电子商城、博客_源码
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;

namespace WesternByte.MyBlog.Core.Picture
{
	/// <summary>
	/// PictureDAO 的摘要说明。
	/// </summary>
	public class PictureDAO : DbObject
	{
		//选取某个图片信息
		public PictureVO Load(int id)
		{
			Connection.Open();
			SqlCommand sqlComm = new SqlCommand("select * from Picture where PictureID = " + id,Connection);
			SqlDataReader tmpReader = sqlComm.ExecuteReader();
			PictureVO pictureVO = new PictureVO();
			if(tmpReader.Read())
			{
				pictureVO.PictureID = Convert.ToInt32(tmpReader["PictureID"].ToString());
				pictureVO.BlogID = Convert.ToInt32(tmpReader["BlogID"].ToString());
				pictureVO.CategoryID = Convert.ToInt32(tmpReader["CategoryID"].ToString());
				pictureVO.Subject = tmpReader["Subject"].ToString();
				pictureVO.ImageUrl = tmpReader["ImageUrl"].ToString();
			}
			tmpReader.Close();
			Connection.Close();
			return pictureVO;
		}

		//添加图片
		public int Insert(PictureVO pictureVO)
		{
			int flag = 0;
			Connection.Open();
			string sql = "insert into Picture(Subject,ImageUrl,BlogID,CategoryID) values(@Subject,@ImageUrl,@BlogID,@CategoryID)";
			SqlCommand sqlComm = new SqlCommand(sql,Connection);
			sqlComm.Parameters.Add(new SqlParameter("@Subject",SqlDbType.NVarChar, 50));
			sqlComm.Parameters.Add(new SqlParameter("@ImageUrl",SqlDbType.NVarChar, 200));
			sqlComm.Parameters.Add(new SqlParameter("@BlogID",SqlDbType.Int, 4));
			sqlComm.Parameters.Add(new SqlParameter("@CategoryID",SqlDbType.Int, 4));
			sqlComm.Parameters["@Subject"].Value=pictureVO.Subject;
			sqlComm.Parameters["@ImageUrl"].Value=pictureVO.ImageUrl;
			sqlComm.Parameters["@BlogID"].Value=pictureVO.BlogID;
			sqlComm.Parameters["@CategoryID"].Value=pictureVO.CategoryID;
			flag = sqlComm.ExecuteNonQuery();
			Connection.Close();
			return flag;
		}

		//修改图片信息
		public int Update(PictureVO pictureVO)
		{
			int flag = 0;
			Connection.Open();
			string sql = "update Picture set Subject = @Subject,ImageUrl = @ImageUrl where PictureID = @PictureID";
			SqlCommand sqlComm = new SqlCommand(sql,Connection);
			sqlComm.Parameters.Add(new SqlParameter("@Subject",SqlDbType.NVarChar, 50));
			sqlComm.Parameters.Add(new SqlParameter("@ImageUrl",SqlDbType.NVarChar, 200));
			sqlComm.Parameters.Add(new SqlParameter("@PictureID",SqlDbType.Int, 4));
			sqlComm.Parameters["@Subject"].Value=pictureVO.Subject;
			sqlComm.Parameters["@ImageUrl"].Value=pictureVO.ImageUrl;
			sqlComm.Parameters["@PictureID"].Value=pictureVO.PictureID;
			flag = sqlComm.ExecuteNonQuery();
			Connection.Close();
			return flag;
		}

		//删除图片信息
		public int Delete(int id)
		{
			int flag = 0;
			Connection.Open();
			string sql = "delete from Picture where PictureID = " + id;
			SqlCommand sqlComm = new SqlCommand(sql,Connection);
			flag = sqlComm.ExecuteNonQuery();
			Connection.Close();
			return flag;
		}
		//删除某个分类下的图片信息
		public int DeleteC(int CategoryID)
		{
			int flag = 0;
			Connection.Open();
			string sql = "delete from Picture where CategoryID = " + CategoryID;
			SqlCommand sqlComm = new SqlCommand(sql,Connection);
			flag = sqlComm.ExecuteNonQuery();
			Connection.Close();
			return flag;
		}
		//删除某个Blog下的图片信息
		public int DeleteB(int BlogID)
		{
			int flag = 0;
			Connection.Open();
			string sql = "delete from Picture where BlogID = " + BlogID;
			SqlCommand sqlComm = new SqlCommand(sql,Connection);
			flag = sqlComm.ExecuteNonQuery();
			Connection.Close();
			return flag;
		}

		//选取图片列表信息
		public DataSet LoadList(int BlogID,int CategoryID,int startPage,int pageSize)
		{
			DataSet Datas=new DataSet();
			Connection.Open();
			string sql = "select * from Picture where BlogID = " + BlogID;
			if(CategoryID!=0)sql+= " and CategoryID = " + CategoryID;
			sql += " order by PictureID desc";
			SqlDataAdapter sqlDA = new SqlDataAdapter(sql,Connection);
			SqlCommand command = new SqlCommand(sql,Connection);
			sqlDA.SelectCommand = command;
			sqlDA.Fill( Datas,startPage,pageSize, "Picture" );
			Connection.Close();
			return Datas;
		}

		//选取图片总数信息
		public int LoadCount(int BlogID,int CategoryID)
		{
			DataSet Datas=new DataSet();
			Connection.Open();
			string sql = "select count(*) as count from Picture where BlogID = " + BlogID;
			if(CategoryID!=0)sql+= " and CategoryID = " + CategoryID;
			SqlCommand command = new SqlCommand(sql,Connection);
			SqlDataReader tmpReader = command.ExecuteReader();
			int flag = 0;
			if(tmpReader.Read())
			{
				flag = Convert.ToInt32(tmpReader["count"].ToString());
			}
			tmpReader.Close();
			Connection.Close();
			return flag;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -