private List <ErrorUser> GetErrorUser() { List <ErrorUser> list = ErrorUserManager.GetErrorUsers(); List <Book> bList = new List <Book>(); foreach (var item in BookManager.GetBooks()) { if (item.m_State == BookState.已借) { bList.Add(item); } } DateTime now = DateTime.Now; foreach (var item in bList) { List <Record> relist = RecordManager.GetRecordsByBookId(item.m_ID); if (relist != null) { Record nr = relist[relist.Count - 1]; TimeSpan span = now - nr.m_Date; if (span.Days >= 30) { ErrorUser user = new ErrorUser( nr.m_ID, nr.m_ReaderId, UserManager.GetUserById(nr.m_ReaderId).m_UserName, item.m_ID, item.m_BookName, span.Days); if (!ListContainsRecorId(list, user)) //有空的时候重写compareto代替 { list.Add(user); ErrorUserManager.SaveErrorUser(user); } } } } return(list); }
public void EnterButtonOnclick() { string rids = ReaderIDField.text; string bids = BookIDField.text; if (string.IsNullOrEmpty(rids)) { //Debug.Log("ReaderIDField.text == null"); HintWindowManager.Contorl.Show("读者ID不能为空!"); return; } if (string.IsNullOrEmpty(bids)) { //Debug.Log("BookIDField.text == null"); HintWindowManager.Contorl.Show("书本ID不能为空!"); return; } int bid = Int32.Parse(bids); int rid = Int32.Parse(rids); Book book = BookManager.GetBookById(bid); if (book == null) { //Debug.Log("Book == null"); HintWindowManager.Contorl.Show("书本不存在或已被删除!"); return; } User user = UserManager.GetUserById(rid); if (user == null) { //Debug.Log("User == null"); HintWindowManager.Contorl.Show("管理员不存在或已被删除!"); return; } BookState state; RecordType type; if (StateDropdowm.value == 0) { if (book.m_State != BookState.已借) { state = BookState.已借; } else { //Debug.Log("书本已被借走"); HintWindowManager.Contorl.Show("书本已被借走!"); return; } if (user.m_BookCount == 5) { HintWindowManager.Contorl.Show("该读者已经借出5本书!"); return; } if (user.m_Error) { HintWindowManager.Contorl.Show("该读者尚未进行处罚!"); return; } type = RecordType.借书; user.m_BookCount = user.m_BookCount + 1; } else { if (book.m_State != BookState.已还) { state = BookState.已还; } else { //Debug.Log("书本已被还回"); HintWindowManager.Contorl.Show("书本已被还回!"); return; } type = RecordType.还书; List <Record> list = RecordManager.GetRecordsByBookId(bids); //未测试bug Record re = list[list.Count - 1]; User bu = UserManager.GetUserById(re.m_ReaderId); bu.m_BookCount = bu.m_BookCount - 1; UserManager.SaveUser(bu); /* -- */ TimeSpan span = DateTime.Now - re.m_Date; if (span.Days >= 30) { ErrorUser euser = new ErrorUser( re.m_ID, re.m_ReaderId, UserManager.GetUserById(re.m_ReaderId).m_UserName, bids, BookManager.GetBookById(bids).m_BookName, span.Days ); ErrorUserManager.SaveErrorUser(euser); HintWindowManager.Contorl.Show("该读者逾期" + span.Days + "天归还书本,需要进行处罚!"); } //user.m_BookCount = user.m_BookCount - 1; //替别人还书情况处理 } book.m_State = state; BookManager.SaveBook(book); UserManager.SaveUser(user); Record record = new Record(rids, bids, ApplicationManager.LocUserId, type, DateTime.Now); RecordManager.SaveRecord(record); RefreshTable(); }
void Start() { //m_TittleNames = new string[] { "ID", "用户名", "账号", "密码" }; Func <List <ErrorUser> > GetRefreshList = GetErrorUser; Action <ErrorUser> action = delegate(ErrorUser t) { ErrorUser u = (ErrorUser)(object)t; List <TableCell> list = new List <TableCell>(); list.Add(m_table.CreateInputFieldTableCell(u.RecordId)); list.Add(m_table.CreateInputFieldTableCell(u.ReaderId)); list.Add(m_table.CreateInputFieldTableCell(u.ReaderName)); list.Add(m_table.CreateInputFieldTableCell(u.BookId)); list.Add(m_table.CreateInputFieldTableCell(u.BookName)); list.Add(m_table.CreateInputFieldTableCell(u.date + "")); list.Add(m_table.CreateTableButtonCell("已处罚", (cell) => { ErrorUserManager.DelErrorUser(((TableInputFieldCell)cell.Row.Cells[0]).Value); if (RecordManager.GetRecordsByBookId(((TableInputFieldCell)cell.Row.Cells[3]).Value).Count % 2 != 0) { HintWindowManager.Contorl.Show("请先让该读者归还书籍!"); } User user = UserManager.GetUserById(((TableInputFieldCell)cell.Row.Cells[1]).Value); if (user == null) { Debug.Log("user==null"); return; } if (!ListContainsReader(ErrorUserManager.GetErrorUsers(), user.m_ID)) { user.m_Error = false; } RefreshTable(); })); TableRow row = m_table.AddRow(list.ToArray()); row.Cells[0].GetComponent <InputField>().interactable = false; row.Cells[1].GetComponent <InputField>().interactable = false; row.Cells[2].GetComponent <InputField>().interactable = false; row.Cells[3].GetComponent <InputField>().interactable = false; row.Cells[4].GetComponent <InputField>().interactable = false; row.Cells[5].GetComponent <InputField>().interactable = false; }; Action <ErrorUser> actionS = delegate(ErrorUser u) { string sname = m_SearchName.text; switch (SeachTypeDrop.value) { case 0: if (u.RecordId == sname) { m_AllList.Add(u); } break; case 1: if (u.ReaderId == sname) { m_AllList.Add(u); } break; case 2: if (u.BookId == sname) { m_AllList.Add(u); } break; } }; Setting(GetRefreshList, action, actionS); //- /* * ToggleNameIdButton.onClick.AddListener(() => * { * if (IsShowID) * { * ToggleNameIdButton.GetComponentInChildren<Text>().text = "显示名称"; * IsShowID = false; * } * else * { * ToggleNameIdButton.GetComponentInChildren<Text>().text = "显示ID"; * IsShowID = true; * } * RefreshTable(); * * }); */ }