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

📄 disk.cs

📁 网站开发非常之旅
💻 CS
📖 第 1 页 / 共 2 页
字号:
		///定义返回值
		int nResult = -1;

		try
		{
			///打开链接
			myConnection.Open();
			///执行SQL语句
			nResult = myCommand.ExecuteNonQuery();
		}
		catch(SqlException ex)
		{
			///抛出异常
			throw new Exception(ex.Message,ex);
		}
		finally
		{   ///关闭链接
			myConnection.Close();
		}
		///返回nResult
		return nResult;
	}

	public int DeleteDirectory(int nDirID)
	{
		///创建链接
		SqlConnection myConnection = new SqlConnection(
			ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);

		///定义返回值
		int nResult = -1;
		///创建Command
		SqlCommand myCommand = new SqlCommand("Pr_DeleteDirectory",myConnection);
		myCommand.CommandType = CommandType.StoredProcedure;
		///添加存储过程的参数
		SqlParameter pDirID = new SqlParameter("@DirID",SqlDbType.Int,4);
		pDirID.Value = nDirID;
		myCommand.Parameters.Add(pDirID);	

		try
		{
			///打开链接
			myConnection.Open();
			///执行SQL语句
			nResult = myCommand.ExecuteNonQuery();
		}
		catch(SqlException ex)
		{
			///抛出异常
			throw new Exception(ex.Message,ex);
		}
		finally
		{   ///关闭链接
			myConnection.Close();
		}
		///返回nResult
		return nResult;
	}

	public int MoveDirectory(int nDirID,int nParentID)
	{
		///创建链接
		SqlConnection myConnection = new SqlConnection(
			ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);

		///定义返回值
		int nResult = -1;

		///创建Command
		SqlCommand myCommand = new SqlCommand("Pr_MoveDirectory",myConnection);
		myCommand.CommandType = CommandType.StoredProcedure;
		///添加存储过程的参数
		SqlParameter pDirID = new SqlParameter("@DirID",SqlDbType.Int,4);
		pDirID.Value = nDirID;
		myCommand.Parameters.Add(pDirID);
		SqlParameter pParentID = new SqlParameter("@ParentID",SqlDbType.Int,4);
		pParentID.Value = nParentID;
		myCommand.Parameters.Add(pParentID);

		try
		{
			///打开链接
			myConnection.Open();
			///执行SQL语句
			nResult = myCommand.ExecuteNonQuery();
		}
		catch(SqlException ex)
		{
			///抛出异常
			throw new Exception(ex.Message,ex);
		}
		finally
		{   ///关闭链接
			myConnection.Close();
		}
		///返回nResult
		return nResult;
	}

	public SqlDataReader GetFile(int nParentID)
	{
		///创建链接
		SqlConnection myConnection = new SqlConnection(
			ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);

		///定义SQL语句
		string cmdText = "SELECT Directory.*,Url.Url,Url.Type "
			+ "FROM Directory Left JOIN Url ON Directory.DirID = Url.DirID "
			+ "WHERE Flag='0' AND ParentID='" + nParentID.ToString() + "'";
		///创建Command
		SqlCommand myCommand = new SqlCommand(cmdText,myConnection);

		///定义DataReader
		SqlDataReader dr = null;
		try
		{
			///打开链接
			myConnection.Open();
			///读取数据
			dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
		}
		catch(SqlException ex)
		{
			///抛出异常
			throw new Exception(ex.Message,ex);
		}
		///返回DataReader
		return dr;
	}

	public SqlDataReader GetSingleFile(int nFileID)
	{
		///创建链接
		SqlConnection myConnection = new SqlConnection(
			ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);

		///定义SQL语句
		string cmdText = "SELECT Directory.*,Url.Url,Url.Type "
			+ "FROM Directory Left JOIN Url ON Directory.DirID = Url.DirID WHERE Directory.DirID='"
			+ nFileID.ToString() + "'";
		///创建Command
		SqlCommand myCommand = new SqlCommand(cmdText,myConnection);

		///定义DataReader
		SqlDataReader dr = null;
		try
		{
			///打开链接
			myConnection.Open();
			///读取数据
			dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
		}
		catch(SqlException ex)
		{
			///抛出异常
			throw new Exception(ex.Message,ex);
		}
		///返回DataReader
		return dr;
	}

	public int AddFile(string sName,int nParentID,int nContain,string sUrl,string sType)
	{
		///创建链接
		SqlConnection myConnection = new SqlConnection(
			ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);

		/////定义SQL语句
		//string cmdText = "INSERT INTO Directory (Name,ParentID,Contain,DirCount,FileCount,Flag,CreateDate)VALUES("
		//    + "'" + sName + "',"
		//    + "'" + nParentID.ToString() + "',"
		//    + "'" + nContain.ToString() + "',"
		//    + "'0" + "',"
		//    + "'0" + "',"
		//    + "'0" + "',"
		//    + "GetDate()"
		//    + ")";
		/////创建Command
		//SqlCommand myCommand = new SqlCommand(cmdText,myConnection);

		/////定义返回值
		//int nResult = -1;

		//try
		//{
		//    ///打开链接
		//    myConnection.Open();
		//    ///执行SQL语句
		//    nResult = myCommand.ExecuteNonQuery();
		//    if(nResult > -1)
		//    {   ///添加文件属性的SQL语句
		//        cmdText = "INSERT INTO Url (Url,Type,DirID,CreateDate)VALUES("
		//            + "'" + sUrl + "',"
		//            + "'" + sType + "',"
		//            + "'" + nResult.ToString() + "',"
		//            + "GetDate()"
		//            + ")";
		//        ///执行上载文件
		//        myCommand.CommandText = cmdText;
		//        nResult = myCommand.ExecuteNonQuery();
		//    }
		//    else
		//    {   ///删除已经创建的文件
		//        DeleteDirectory(nResult);
		//    }
		//}
		SqlCommand myCommand = new SqlCommand("Pr_AddFile",myConnection);
		myCommand.CommandType = CommandType.StoredProcedure;
		///添加存储过程的参数
		SqlParameter pName = new SqlParameter("@Name",SqlDbType.VarChar,200);
		pName.Value = sName;
		myCommand.Parameters.Add(pName);		
		SqlParameter pParentID = new SqlParameter("@ParentID",SqlDbType.Int,4);
		pParentID.Value = nParentID;
		myCommand.Parameters.Add(pParentID);		
		SqlParameter pContain = new SqlParameter("@Contain",SqlDbType.Int,4);
		pContain.Value = nContain;
		myCommand.Parameters.Add(pContain);
		SqlParameter pUrl = new SqlParameter("@Url",SqlDbType.VarChar,255);
		pUrl.Value = sUrl;
		myCommand.Parameters.Add(pUrl);
		SqlParameter pType = new SqlParameter("@Type",SqlDbType.VarChar,200);
		pType.Value = sType;
		myCommand.Parameters.Add(pType);

		///定义返回值
		int nResult = -1;

		try
		{
			///打开链接
			myConnection.Open();
			///执行SQL语句
			nResult = myCommand.ExecuteNonQuery();			
		}
		catch(SqlException ex)
		{
			///抛出异常
			throw new Exception(ex.Message,ex);
		}
		finally
		{   ///关闭链接
			myConnection.Close();
		}
		///返回nResult
		return nResult;
	}

	public int EditFile(int nFileID,string sName)
	{
		///创建链接
		SqlConnection myConnection = new SqlConnection(
			ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);

		///定义SQL语句
		string cmdText = "UPDATE Directory SET Name ="
			+ "'" + sName + "'"
			+ " WHERE DirID='" + nFileID.ToString() + "'";
		///创建Command
		SqlCommand myCommand = new SqlCommand(cmdText,myConnection);

		///定义返回值
		int nResult = -1;

		try
		{
			///打开链接
			myConnection.Open();
			///执行SQL语句
			nResult = myCommand.ExecuteNonQuery();
		}
		catch(SqlException ex)
		{
			///抛出异常
			throw new Exception(ex.Message,ex);
		}
		finally
		{   ///关闭链接
			myConnection.Close();
		}
		///返回nResult
		return nResult;
	}

	public int DeleteFile(int nFileID)
	{
		///创建链接
		SqlConnection myConnection = new SqlConnection(
			ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
		
		///定义返回值
		int nResult = -1;

		///创建Command
		SqlCommand myCommand = new SqlCommand("Pr_DeleteFile",myConnection);
		myCommand.CommandType = CommandType.StoredProcedure;
		///添加存储过程的参数
		SqlParameter pDirID = new SqlParameter("@DirID",SqlDbType.Int,4);
		pDirID.Value = nFileID;
		myCommand.Parameters.Add(pDirID);		

		try
		{
			///打开链接
			myConnection.Open();
			///执行SQL语句
			nResult = myCommand.ExecuteNonQuery();		
		}
		catch(SqlException ex)
		{
			///抛出异常
			throw new Exception(ex.Message,ex);
		}
		finally
		{   ///关闭链接
			myConnection.Close();
		}
		///返回nResult
		return nResult;
	}

	public int MoveFile(int nFileID,int nParentID)
	{
		///创建链接
		SqlConnection myConnection = new SqlConnection(
			ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);

		///定义返回值
		int nResult = -1;

		///创建Command
		SqlCommand myCommand = new SqlCommand("Pr_MoveFile",myConnection);
		myCommand.CommandType = CommandType.StoredProcedure;
		///添加存储过程的参数
		SqlParameter pDirID = new SqlParameter("@DirID",SqlDbType.Int,4);
		pDirID.Value = nFileID;
		myCommand.Parameters.Add(pDirID);
		SqlParameter pParentID = new SqlParameter("@ParentID",SqlDbType.Int,4);
		pParentID.Value = nParentID;
		myCommand.Parameters.Add(pParentID);

		try
		{
			///打开链接
			myConnection.Open();
			///执行SQL语句
			nResult = myCommand.ExecuteNonQuery();
		}
		catch(SqlException ex)
		{
			///抛出异常
			throw new Exception(ex.Message,ex);
		}
		finally
		{   ///关闭链接
			myConnection.Close();
		}
		///返回nResult
		return nResult;
	}

	public SqlDataReader SearchFiles(string sKey)
	{
		///创建链接
		SqlConnection myConnection = new SqlConnection(
			ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);

		///定义SQL语句
		string cmdText = "SELECT Directory.*,Url.Url,Url.Type "
			+ "FROM Directory Left JOIN Url ON Directory.DirID = Url.DirID WHERE Flag = '0' AND Name like '%"
			+ sKey + "%' ORDER BY Directory.CREATEDATE DESC";
		///创建Command
		SqlCommand myCommand = new SqlCommand(cmdText,myConnection);

		///定义DataReader
		SqlDataReader dr = null;
		try
		{
			///打开链接
			myConnection.Open();
			///读取数据
			dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
		}
		catch(SqlException ex)
		{
			///抛出异常
			throw new Exception(ex.Message,ex);
		}
		///返回DataReader
		return dr;
	}

	#endregion
}

⌨️ 快捷键说明

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