📄 booktypedal.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using Model;
using BLL;
using BLL.interfaces;
using System.Data.SqlClient;
using System.Data;
namespace DAL
{
public class BookTypeDal : IBookType
{
SqlDataReader read = null;
SqlCommand com = new SqlCommand();
#region IBookType 成员
public bool addBookType(BookType bookType)
{
bool flag = false;
string sqlStr = "INSERT INTO BookType (id,[Name] ,Pid) VALUES (@id,@Name,@Pid)";
SqlParameter[] p = new SqlParameter[]
{
new SqlParameter("@id",bookType.Id),
new SqlParameter("@Name",bookType.Name),
new SqlParameter("@Pid",bookType.Pid)
};
int rows = DBHelp.Rework1(sqlStr, p);
flag = rows > 0 ? true : false;
return flag;
}
public List<BookType> selBookType(int pid)
{
List<BookType> list = new List<BookType>();
string sqlStr = "select * from BookType where pid=@pid";
try
{
SqlParameter[] p = new SqlParameter[]
{
new SqlParameter("@pid",pid)
};
read = DBHelp.Selparam(sqlStr, p);
while (read.Read())
{
BookType bookType = new BookType();
bookType.Id = int.Parse(read["Id"].ToString());
bookType.Name = read["Name"].ToString();
bookType.Pid = int.Parse(read["Pid"].ToString());
list.Add(bookType);
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
try
{
read.Close();
}
catch (Exception ex)
{
throw ex;
}
}
return list;
}
public List<BookType> selBookType()
{
List<BookType> list = new List<BookType>();
string sqlStr = "select * from BookType";
try
{
read = DBHelp.Sel(sqlStr);
while (read.Read())
{
BookType bookType = new BookType();
bookType.Id = int.Parse(read["Id"].ToString());
bookType.Name = read["Name"].ToString();
bookType.Pid = int.Parse(read["Pid"].ToString());
list.Add(bookType);
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
try
{
read.Close();
}
catch (Exception ex)
{
throw ex;
}
}
return list;
}
bool IBookType.delBookType(int id)
{
bool flag = false;
string sqlStr = "delete from booktype where id=@id";
SqlParameter[] p = new SqlParameter[]
{
new SqlParameter("@id",id)
};
try
{
int row = DBHelp.Rework1(sqlStr, p);
if (row > 0)
{
flag = true;
}
}
catch (Exception ex)
{
throw ex;
}
return flag;
}
bool IBookType.updateBook(BookType bookType)
{
bool flag = false;
string sqlStr = "update booktype set name=@name where id=@id";
SqlParameter[] p=new SqlParameter[]
{
new SqlParameter("@name",bookType.Name),
new SqlParameter("@id",bookType.Id)
};
try
{
int row = DBHelp.Rework1(sqlStr, p);
if (row > 0)
{
flag = true;
}
}
catch (Exception ex)
{
throw ex;
}
return flag;
}
public int sel()
{
int maxId = 0;
string sqlStr = "select max(id) from BookType ";
try
{
read = DBHelp.Sel(sqlStr);
while (read.Read())
{
if (read.GetValue(0).ToString() == "")
{
maxId = 0;
}
else
{
maxId = int.Parse(read.GetValue(0).ToString());
}
}
return maxId;
}
catch (Exception ex)
{
throw ex;
}
finally
{
try
{
read.Close();
}
catch (Exception ex)
{
throw ex;
}
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -