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);
    }
Exemplo n.º 2
0
    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();
    }