📄 tempstore.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace DataAccessLayer
{
/// <summary>
/// Summary description for TempStore.
/// </summary>
public class TempStore:DbBase.Base
{
private int bookId;
private int userId;
public TempStore()
{
//
// TODO: Add constructor logic here
//
}
#region Properties of temp store
/// <summary>
/// Book ID
/// </summary>
public int BookId
{
get
{
return bookId;
}
set
{
bookId = value;
}
}
/// <summary>
/// User ID
/// </summary>
public int UserId
{
get
{
return userId;
}
set
{
userId = value;
}
}
#endregion
#region Functions of temp store
/// <summary>
/// Add new book in temp store
/// need book ID、User ID.
/// </summary>
public void Add()
{
if(IsExist())
{
throw new Exception("Exist this book in your temp store!");
}
else
{
strSQL = "Insert into TempStore (BookId,UserId) Values("
+ this.BookId.ToString() + ","
+ this.UserId.ToString() + ")";
try
{
ExecuteSql(strSQL);
}
catch
{
throw new Exception("增加新书失败!");
}
}
}
/// <summary>
/// Add new book in temp store.
/// </summary>
public static void Add(int bookId,int userId)
{
if(IsExist(bookId,userId))
{
throw new Exception("Exist this book in your temp store!");
}
else
{
strSQL = "Insert into TempStore (BookId,UserId) Values("
+ bookId.ToString() + ","
+ userId.ToString() + ")";
try
{
ExecuteSql(strSQL);
}
catch
{
throw new Exception("增加新书失败!");
}
}
}
/// <summary>
/// Delete book from temp store
/// </summary>
/// <param name="bookId">Book ID(int)</param>
/// <param name="userId">User ID(int)</param>
public static void Delete(int bookId,int userId)
{
strSQL = "Delete From TempStore Where BookId="+bookId.ToString()
+" And UserId=" + userId.ToString();
try
{
ExecuteSql(strSQL);
}
catch
{
throw new Exception("删除书失败!");
}
}
/// <summary>
/// Delete book from temp store
/// </summary>
public void Delete()
{
strSQL = "Delete From TempStore Where bookId=" + this.BookId.ToString()
+" And UserId=" + this.UserId.ToString();
try
{
ExecuteSql(strSQL);
}
catch
{
throw new Exception("删除书失败!");
}
}
/// <summary>
/// Clear user's temp store
/// </summary>
/// <param name="userId">userId</param>
public static void Clear(int userId)
{
strSQL = "Delete From TempStore Where UserId = " + userId.ToString();
try
{
ExecuteSql(strSQL);
}
catch
{
throw new Exception("清除暂寸失败!");
}
}
/// <summary>
/// Does this book exist?
/// </summary>
/// <returns>return bool value</returns>
public bool IsExist()
{
strSQL = "Select BookId from TempStore Where BookId="
+ this.BookId.ToString() + " And UserId=" + this.UserId.ToString();
try
{
ExecuteSql4Value(strSQL);
return true;
}
catch
{
return false;
}
}
/// <summary>
/// Does this book exist?
/// </summary>
/// <param name="bookId">Book ID(int)</param>
/// <param name="userId">User ID(int)</param>
/// <returns>return bool value</returns>
public static bool IsExist(int bookId,int userId)
{
strSQL = "Select BookId from TempStore Where BookId="
+ bookId.ToString() + " And UserId=" + userId.ToString();
try
{
ExecuteSql4Value(strSQL);
return true;
}
catch
{
return false;
}
}
/// <summary>
/// Get all the books in the temp store
/// </summary>
/// <param name="userId">User ID(int)</param>
/// <returns>return books(DataSet)</returns>
public static DataSet GetBooks(int userId)
{
strSQL = "SELECT * FROM TempStoreV Where UserId=" + userId.ToString();
try
{
return ExecuteSql4Ds(strSQL);
}
catch
{
throw new Exception("得到所有书失败");
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -