aaa
aa吧
全部回复
仅看楼主
level 1
private string Login(HttpContext context)
{ //session实现的接口IRequiresSessionState
string user =context.Request["user"];
string pwd = context.Request["pwd"];
BookDataContext table = newBookDataContext();
var result1 = from v1 intable.tb_admin
where v1.adminName ==user && v1.pwd == pwd
select v1;
if (result1.Count() > 0)
{
context.Session["admin"] = user;
return "success";
}
else
{
var result2 = from v2 intable.tb_reader
wherev2.readerName == user && v2.readerId == pwd
select v2;
if (result2.Count() > 0)
{
context.Session["readerId"] = pwd;
return "success";
}
else
{
return "erro";
}
}
}
private string Insert(HttpContextcontext) {
int bookId =Convert.ToInt32(context.Request["bookid"]);
var sql = from v intable.tb_bookinfo
where v.bookId == bookId
select v;
if (sql.Count() == 0) {
string bookTypeId = newBookTypeController().GetTypeId(context.Request["BookTypeName"]);
tb_bookinfo book = newtb_bookinfo() {
bookname =context.Request["bookName"],
bookTypeId = bookTypeId,
author =context.Request["author"],
storage = Convert.ToInt32(context.Request["storage"]),
borrownum =Convert.ToInt32(context.Request["borrowNum"])
};
table.tb_bookinfo.InsertOnSubmit(book);
table.SubmitChanges();
return "success";
}
return "erro";
}
private string Update(HttpContextcontext)
{
string bookTypeId = newBookTypeController().GetTypeId(context.Request["BookTypeName"]);
int bookId = Convert.ToInt32(context.Request["bookid"]);
var sql = from v intable.tb_bookinfo
where v.bookId == bookId
select v;
if (sql.Count() > 0)
{
foreach (tb_bookinfo info insql)
{
info.bookId = bookId;
info.bookname =context.Request["bookName"];
info.bookTypeId =bookTypeId;
info.author =context.Request["author"];
info.storage =Convert.ToInt32(context.Request["storage"]);
info.borrownum =Convert.ToInt32(context.Request["borrowNum"]);
}
table.SubmitChanges();
return "success";
}
return "erro";
}
private string Del(HttpContext context)
{
int bookid =Convert.ToInt32(context.Request["bookid"]);
var sql = from v intable.tb_bookinfo
where v.bookId == bookid
select v;
if (sql.Count() > 0)
{
table.tb_bookinfo.DeleteAllOnSubmit(sql);
table.SubmitChanges();
return "success";
}
return "erro";
}
private int GetCount()
{
var sql = from v intable.tb_bookinfo
select v;
if (sql.Count() > 0)
{
return(int)Math.Ceiling((double)sql.Count() / pageSize);
}
return 0;
}
· private string Show(HttpContextcontext)
{
if(context.Session["readerId"] == null &&context.Session["admin"] == null) {
return "未登录";
}
string info =context.Request["pageIndex"];
int pageIndex = 0;
if (info == "首页")
pageIndex = 1;
else if (info == "尾页")
pageIndex = GetCount();
else
pageIndex = Convert.ToInt32(info);
int temp = (pageIndex - 1) *pageSize;
var result = from a intable.tb_bookinfo
join b intable.tb_booktype on a.bookTypeId equals b.bookTypeId
select new
{
bookid = a.bookId,
bookName =a.bookname,
bookType =b.bookTypeName,
author = a.author,
storage =a.storage,
borrowNum =a.borrownum
};
if (result.Count() > 0)
{
List<object> list =result.Skip(temp).Take(pageSize).ToList<object>();
JavaScriptSerializer js = newJavaScriptSerializer();
return js.Serialize(list);
}
return "erro";
}
public bool DelOneBook(int bookId) {
var sql = from v intable.tb_bookinfo
where v.bookId == bookId
select v;
if (sql.Count() > 0) {
foreach (tb_bookinfo t in sql){
t.borrownum -= 1;
}
table.SubmitChanges();
return true;
}
return false;
}
2017年05月25日 04点05分 1
level 1
private string BorrowBook(HttpContext context) {
if (context.Session["readerId"] == null)
{
return "读者未登录";
}
else {
int bookid = Convert.ToInt32(context.Request["bookid"]);
string readerId = context.Session["readerId"].ToString();
var sql = from v in table.tb_borrowandback
where v.bookId == bookid && v.readerId == readerId
select v;
bool flag = false;
if (sql.Count() > 0) {
foreach (tb_borrowandback b in sql) {
if (!(bool)b.i**ack) {
return "该书已借,请选归还";
}else {
flag = true;
}
}
}
if (sql.Count() == 0 || flag) {
tb_borrowandback borrow = new tb_borrowandback()
{
readerId = readerId,
bookId = bookid,
borrowTime = DateTime.Now,
s**ackTime = null,
i**ack = false
};
table.tb_borrowandback.InsertOnSubmit(borrow);
table.SubmitChanges();
if (!new ReaderController().AddOneBorrowNum(readerId))
{
return "当前可借数超过最大限度";
}
else if (new BookController().DelOneBook(bookid) && new ReaderController().AddOneBorrowNum(readerId))
{
return "success";
}
}
return "借阅失败!!";
}
}
public bool AddOneBorrowNum(string readerId) {
var sql = from v in table.tb_reader
where v.readerId == readerId
select v;
bool flag = false;
if (sql.Count() > 0) {
foreach (tb_reader r in sql) {
if (r.borrownum < r.num){
r.borrownum += 1;
flag = true;
}
else {
flag = false;
}
}
if (flag) {
table.SubmitChanges();
return true;
}
}
return false;
}
private string GetType(HttpContext context) {
var sql = from v in table.tb_booktype
select new {
bookTypeName = v.bookTypeName
};
if (sql.Count() > 0) {
List<object> list = sql.ToList<object>();
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Serialize(list);
}
return "erro";
}
public string GetTypeId(string BookTypeName) {
var sql = from v in table.tb_booktype
where v.bookTypeName == BookTypeName
select v;
string bookTypeId = "";
if (sql.Count() > 0)
{
foreach (tb_booktype t in sql)
{
bookTypeId = t.bookTypeId;
}
}
return bookTypeId;
}
2017年05月25日 04点05分 3
level 13
2017年06月01日 08点06分 4
1