Exemplo n.º 1
0
        /// <summary>
        /// 도서예약
        /// </summary>
        /// <param name="stuid">학번</param>
        /// <param name="bookid">도서번호</param>
        /// <returns>예약성공여부</returns>
        public bool ReserveBook(int stuid, int bookid)
        {
            //유효성체크
            //학번이 유효한지, 도서번호가 유효한지, 대여가능한지, 예약상태인지
            //대여한 학생이 또 예약하는 것은 현재 허용
            StudentDB stu = new StudentDB();

            if (!stu.IsValid(stuid))
            {
                throw new Exception("유효한 학번이 아닙니다.");
            }
            stu.Dispose();

            BookDB bk = new BookDB();

            if (!bk.IsValid(bookid))
            {
                throw new Exception("유효한 도서가 아닙니다.");
            }
            else if (!bk.IsLended(bookid))
            {
                throw new Exception("대여 가능한 도서입니다.");
            }
            else
            {
                if (bk.IsReserved(bookid))
                {
                    throw new Exception("이미 예약된 도서입니다.");
                }
                bk.Dispose();

                try
                {
                    MySqlCommand cmd = new MySqlCommand();
                    cmd.CommandText = "update book set reservestuid = @reservestuid where bookid = @bookid";
                    cmd.Connection  = conn;

                    cmd.Parameters.Add("@reservestuid", MySqlDbType.Int32);
                    cmd.Parameters["@reservestuid"].Value = stuid;

                    cmd.Parameters.Add("@bookid", MySqlDbType.Int32);
                    cmd.Parameters["@bookid"].Value = bookid;

                    cmd.ExecuteNonQuery();
                    return(true);
                }
                catch (Exception err)
                {
                    throw err;
                    //return false; //도달하지 않는 코드
                }
            }
        }
Exemplo n.º 2
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();
        }