📄 lackrecord.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace DataAccessLayer
{
/// <summary>
/// Lack books record
/// </summary>
public class LackRecord:DbBase.Base
{
private int m_UserId;
private string m_Publisher;
private string m_Reply;
/// <summary>
/// Property:Publisher
/// </summary>
public string Publisher
{
get
{
return m_Publisher;
}
set
{
m_Publisher = value;
}
}
/// <summary>
/// Property:manager reply
/// </summary>
public string Reply
{
get
{
return m_Reply;
}
set
{
m_Reply = value;
}
}
/// <summary>
/// Property:User ID
/// </summary>
public int UserId
{
get
{
return m_UserId;
}
set
{
m_UserId = value;
}
}
public LackRecord()
{
}
/// <summary>
/// add unavailable books. set Name、Publisher.
/// </summary>
public void Add()
{
if(IsExist())
{
throw new Exception("Book existed");
}
else
{
strSQL = "Insert into LackRecord (UserId,Name,Publisher) Values("
+ this.UserId.ToString()
+ ",'" + this.Name + "',"
+ "'" + this.Publisher + "')";
try
{
ExecuteSql(strSQL);
}
catch
{
throw new Exception("register failed");
}
}
}
/// <summary>
/// add books.
/// </summary>
public static void Add(int userId,string name,string publisher)
{
if(IsExist(name,publisher))
{
throw new Exception("book existed");
}
else
{
strSQL = "Insert into LackRecord (UserId,Name,Publisher) Values("
+ userId.ToString()
+ ",'" + name + "',"
+ "'" + publisher + "')";
try
{
ExecuteSql(strSQL);
}
catch
{
throw new Exception("register failed");
}
}
}
/// <summary>
/// reply
/// </summary>
public void SetReply()
{
strSQL = "Update LackRecord Set "
+ "Reply='" + Reply + "'"
+ " Where Id=" + this.ID;
try
{
ExecuteSql(strSQL);
}
catch
{
throw new Exception("回复成功!");
}
}
/// <summary>
/// reply
/// </summary>
public static void SetReply(int id,string reply)
{
strSQL = "Update LackRecord Set "
+ "Reply='" + reply + "'"
+ " Where Id=" + id;
try
{
ExecuteSql(strSQL);
}
catch
{
throw new Exception("回复成功!");
}
}
/// <summary>
/// del book
/// </summary>
/// <param name="Id">(int)</param>
public static void Delete(int id)
{
strSQL = "Delete From LackRecord Where Id="+id;
try
{
ExecuteSql(strSQL);
}
catch
{
throw new Exception("删除失败!");
}
}
/// <summary>
/// delete
/// </summary>
public void Delete()
{
strSQL = "Delete From LackRecord Where Id="+this.ID;
try
{
ExecuteSql(strSQL);
}
catch
{
throw new Exception("删除失败!");
}
}
/// <summary>
/// batch delete
/// </summary>
/// <param name="names"></param>
public static void DeleteGroup(string ids)
{
strSQL = "Delete From LackRecord Where Id in ('" + ids + "')";
try
{
ExecuteSql(strSQL);
}
catch
{
throw new Exception("删除失败!");
}
}
/// <summary>
/// get information of book
/// </summary>
/// <returns>(DataSet)</returns>
public static DataSet GetLackRecords()
{
strSQL = "SELECT * FROM LackRecord Where Reply Is null or Reply = ''";
try
{
return ExecuteSql4Ds(strSQL);
}
catch
{
throw new Exception("得到匮乏记录失败!");
}
}
/// <summary>
/// get all books data from the same user
/// </summary>
/// <returns>(DataSet)</returns>
public static DataSet GetLackRecords(int userId)
{
strSQL = "SELECT * FROM LackRecord Where UserId=" + userId;
try
{
return ExecuteSql4Ds(strSQL);
}
catch
{
throw new Exception("得到匮乏记录失败!");
}
}
/// <summary>
/// if the books exist
/// </summary>
/// <returns>return bool,if exist then set true,otherwise false</returns>
public bool IsExist()
{
strSQL = "Select Id from LackRecord Where Name='"
+ this.Name + "' And Publisher='" + this.Publisher +"'";
try
{
ExecuteSql4Value(strSQL);
return true;
}
catch
{
return false;
}
}
/// <summary>
/// if exist the book
/// </summary>
/// <param name="name">string)</param>
/// <returns>return bool,if exist then set true,otherwise false</returns>
public static bool IsExist(string name,string publisher)
{
strSQL = "Select Id from LackRecord Where Name='"
+ name + "' And Publisher='" + publisher +"'";
try
{
ExecuteSql4Value(strSQL);
return true;
}
catch
{
return false;
}
}
/// <summary>
/// update information.
/// </summary>
/// <returns>return</returns>
public bool Update()
{
strSQL = "Update LackRecord Set "
+ "Name='" + this.Name + "',Publisher='"
+ this.Publisher
+ "' Where Id=" + this.ID.ToString();
try
{
ExecuteSql(strSQL);
return true;
}
catch
{
throw new Exception("更新失败!");
}
}
/// <summary>
/// update
/// </summary>
/// <param name="name">email address(string)</param>
/// <param name="Reply">book name(string)</param>
/// <param name="Publisher">password(string)</param>
/// <returns>return</returns>
public static bool Update(int id,string name,string publisher)
{
strSQL = "Update LackRecord Set "
+ "Name='" + name + "',Publisher='"
+ publisher
+ "' Where Id=" + id.ToString();
try
{
ExecuteSql(strSQL);
return true;
}
catch
{
throw new Exception("更新失败!");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -