Example #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            BookDB db     = new BookDB();
            int    bookID = int.Parse(txtBookid.Text);

            //유효성체크
            // 1. 입력한 도서번호가 유효한 도서번호인지 체크
            if (!db.IsValid(bookID))
            {
                MessageBox.Show("도서가 존재하지 않습니다.");
            }

            // 2. 대여중인 도서인지 체크

            else if (db.IsLended(bookID))
            {
                MessageBox.Show("대여중인 도서입니다.");
            }


            // 3. 대여가능하지만 예약한 학번이 입력한 학번인지 체크

            else
            {
                int stuid = int.Parse(txtStudentid.Text);
                //예약한 학번 조회 (0 또는 이미 예약한 학번)
                int reserveStuid = db.GetReserveStuId(bookID);
                if (reserveStuid > 0 && reserveStuid != stuid)
                {
                    MessageBox.Show("이미 예약된 도서입니다.");
                }
                else
                {
                    //입력된 도서를 대여목록(ListBox)에 추가한다
                    Book curBook = db.GetBookInfo(bookID);
                    lstLendBook.Items.Add($"{curBook.BookID} / {curBook.BookName} / {curBook.Author} / {curBook.Publisher}");
                    txtBookid.Text = "";
                }
            }

            db.Dispose();
        }