📄 booksdb.cs
字号:
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using Rainbow.Configuration;
namespace Rainbow.DesktopModules
{
public class BooksDB
{
/// <summary>
/// GetSinglerb_Books
/// </summary>
/// <param name="ItemID">ItemID</param>
/// <returns>A SqlDataReader</returns>
public SqlDataReader GetSinglerb_Books(int ItemID)
{
// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new SqlCommand("rb_GetSingleBook", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterItemID = new SqlParameter("@ItemID", SqlDbType.Int);
parameterItemID.Value = ItemID;
myCommand.Parameters.Add(parameterItemID);
// Execute the command
myConnection.Open();
SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
// Return the datareader
return result;
}
/// <summary>
/// Getrb_Books
/// </summary>
/// <param name="ItemID">ItemID</param>
/// <returns>A SqlDataReader</returns>
public DataSet Getrb_Books(int ModuleId)
{
// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlDataAdapter myCommand = new SqlDataAdapter("rb_GetBooks", myConnection);
// Mark the Command as a SPROC
myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterModuleId = new SqlParameter("@ModuleId", SqlDbType.Int);
parameterModuleId.Value = ModuleId;
myCommand.SelectCommand.Parameters.Add(parameterModuleId);
DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet);
return myDataSet;
}
/// <summary>
/// Deleterb_Books
/// </summary>
/// <param name="ItemID">ItemID</param>
/// <returns>Void</returns>
public void Deleterb_Books(int ItemID)
{
// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new SqlCommand("rb_DeleteBook", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterItemID = new SqlParameter("@ItemID", SqlDbType.Int);
parameterItemID.Value = ItemID;
myCommand.Parameters.Add(parameterItemID);
// Execute the command
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
}
/// <summary>
/// Addrb_Books
/// </summary>
/// <param name="ItemID">ItemID</param>
/// <returns>The newly created ID</returns>
public int Addrb_Books(int ModuleID, string CreatedByUser, string Title, string ImageUrl, string Authors, string Price, string ISBN, string Buylink)
{
// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new SqlCommand("rb_AddBook", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterItemID = new SqlParameter("@ItemID", SqlDbType.Int);
parameterItemID.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterItemID);
SqlParameter parameterModuleID = new SqlParameter("@ModuleID", SqlDbType.Int);
parameterModuleID.Value = ModuleID;
myCommand.Parameters.Add(parameterModuleID);
SqlParameter parameterCreatedByUser = new SqlParameter("@CreatedByUser", SqlDbType.NVarChar, 100);
parameterCreatedByUser.Value = CreatedByUser;
myCommand.Parameters.Add(parameterCreatedByUser);
SqlParameter parameterTitle = new SqlParameter("@Title", SqlDbType.NVarChar, 150);
parameterTitle.Value = Title;
myCommand.Parameters.Add(parameterTitle);
SqlParameter parameterImageUrl = new SqlParameter("@ImageUrl", SqlDbType.NVarChar, 150);
parameterImageUrl.Value = ImageUrl;
myCommand.Parameters.Add(parameterImageUrl);
SqlParameter parameterAuthors = new SqlParameter("@Authors", SqlDbType.NVarChar, 150);
parameterAuthors.Value = Authors;
myCommand.Parameters.Add(parameterAuthors);
SqlParameter parameterPrice = new SqlParameter("@Price", SqlDbType.NVarChar, 10);
parameterPrice.Value = Price;
myCommand.Parameters.Add(parameterPrice);
SqlParameter parameterISBN = new SqlParameter("@ISBN", SqlDbType.NVarChar, 10);
parameterISBN.Value = ISBN;
myCommand.Parameters.Add(parameterISBN);
SqlParameter parameterBuylink = new SqlParameter("@Buylink", SqlDbType.NVarChar, 150);
parameterBuylink.Value = Buylink;
myCommand.Parameters.Add(parameterBuylink);
// Open the database connection and execute the command
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
// Return the newly created ID
return (int)parameterItemID.Value;
}
/// <summary>
/// Updaterb_Books
/// </summary>
/// <param name="ItemID">ItemID</param>
/// <returns>Void</returns>
public void Updaterb_Books(int ItemID, string CreatedByUser, string Title, string ImageUrl, string Authors, string Price, string ISBN, string Buylink)
{
// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new SqlCommand("rb_UpdateBook", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Update Parameters to SPROC
SqlParameter parameterItemID = new SqlParameter("@ItemID", SqlDbType.Int);
parameterItemID.Value = ItemID;
myCommand.Parameters.Add(parameterItemID);
SqlParameter parameterCreatedByUser = new SqlParameter("@CreatedByUser", SqlDbType.NVarChar, 100);
parameterCreatedByUser.Value = CreatedByUser;
myCommand.Parameters.Add(parameterCreatedByUser);
SqlParameter parameterTitle = new SqlParameter("@Title", SqlDbType.NVarChar, 150);
parameterTitle.Value = Title;
myCommand.Parameters.Add(parameterTitle);
SqlParameter parameterImageUrl = new SqlParameter("@ImageUrl", SqlDbType.NVarChar, 150);
parameterImageUrl.Value = ImageUrl;
myCommand.Parameters.Add(parameterImageUrl);
SqlParameter parameterAuthors = new SqlParameter("@Authors", SqlDbType.NVarChar, 150);
parameterAuthors.Value = Authors;
myCommand.Parameters.Add(parameterAuthors);
SqlParameter parameterPrice = new SqlParameter("@Price", SqlDbType.NVarChar, 10);
parameterPrice.Value = Price;
myCommand.Parameters.Add(parameterPrice);
SqlParameter parameterISBN = new SqlParameter("@ISBN", SqlDbType.NVarChar, 10);
parameterISBN.Value = ISBN;
myCommand.Parameters.Add(parameterISBN);
SqlParameter parameterBuylink = new SqlParameter("@Buylink", SqlDbType.NVarChar, 150);
parameterBuylink.Value = Buylink;
myCommand.Parameters.Add(parameterBuylink);
// Execute the command
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -