?? disk.cs
字號:
///定義返回值
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 + -