Exemple #1
0
        public void RemoveBook(string searchBy)
        {
            string confirm;

            BookVO foundBook = SearchBook("removeSearch", searchBy);

            print.RemoveBook(foundBook);

            if (foundBook == null)
            {
                menu.BookManagementMenu();
                return;
            }

            print.RemoveBook(foundBook);
            confirm = Console.ReadLine();

            if (errorCheck.Confirm(confirm))
            {
                print.MenuErrorMsg("Y/N오류");
                menu.BookManagementMenu();
            }

            sqlQuery = "delete from book where name ='" + foundBook.Name + "';";
            SendQuery();
            dataReader.Read();

            if (errorCheck.IsValidChange(dataReader) == false) //편집 에러
            {
                CloseDB();
                print.ErrorMsg("도서 정보 삭제");
                menu.BookManagementMenu();
                return;
            }

            CloseDB();
            print.CompleteMsg("도서 정보 삭제 완료");
            menu.BookManagementMenu();
            return;
        }
Exemple #2
0
        public void RentBook(string searchBy)
        {
            ConsoleKeyInfo input;
            BookVO         foundBook = SearchBook("rentBook", searchBy);

            if (dataReader == null)
            {
                menu.BookRentSearchMenu();
                return;
            }

            if (foundBook.Count == 0) //빌릴 책의 수량이 없는 경우
            {
                print.NotInStockMsg();
                menu.BookRentSearchMenu();
                return;
            }

            if (Login.logOnMember.RentBook != "없음") //빌려간 책이 있는 경우
            {
                while (true)
                {
                    print.RentErrorMsg(Login.logOnMember.Name, Login.logOnMember.RentBook);
                    input = Console.ReadKey();
                    if (errorCheck.IsValidMenuInput(input, "선택") == false)
                    {
                        break;
                    }
                }

                if (input.KeyChar.ToString().Equals("1"))
                {
                    ReturnBook();
                    return;
                }
                menu.BookRentSearchMenu();
                return;
            }

            print.CheckRentBook(foundBook);
            while (true) //제대로 입력할때까지 반복
            {
                input = Console.ReadKey();
                if (errorCheck.Confirm(input.KeyChar.ToString()) == false)
                {
                    break;
                }

                print.MenuErrorMsg("Y/N오류");
            }

            if (input.KeyChar.ToString().Equals("N") || input.KeyChar.ToString().Equals("n")) //대여 안함
            {
                menu.BookRentSearchMenu();
                return;
            }

            //대여함
            sqlQuery = "update member set rentbook ='" + foundBook.Name + "', duedate ='" + "2018-05-11" + "' where id='" + Login.logOnMember.Id + "';";
            SendQuery();
            Login.logOnMember.RentBook = foundBook.Name;
            Login.logOnMember.DueDate  = "2018-05-11";

            if (errorCheck.IsValidChange(dataReader) == false)
            {
                CloseDB();
                print.ErrorMsg("대여");
                menu.BookRentSearchMenu();
                return;
            }
            CloseDB();

            foundBook.Count = foundBook.Count - 1;

            sqlQuery = "update book set count ='" + foundBook.Count + "' where name='" + foundBook.Name + "';";
            SendQuery();

            if (errorCheck.IsValidChange(dataReader) == false)
            {
                CloseDB();
                print.ErrorMsg("도서 수량 정보 갱신");
                menu.BookRentSearchMenu();
                return;
            }

            CloseDB();
            print.CompleteMsg("해당 도서 대여");
            menu.BookRentMenu();
            return;
        }
Exemple #3
0
        public BookVO SearchBook(string searchType, string searchBy)
        {
            string searchName;
            string searchAuthor;
            string searchPublisher;

            if (searchBy.Equals("도서명"))
            {
                switch (searchType)
                {
                case "editSearch":
                    print.Search("편집할 책 이름");
                    break;

                case "removeSearch":
                    print.Search("삭제할 책의 이름");
                    break;

                case "justSearch":
                    print.Search("검색할 책 이름");
                    break;

                case "rentBook":
                    print.Search("대여할 책 이름");
                    break;
                }

                searchName = Console.ReadLine();
                if (errorCheck.BookName(searchName))
                {
                    print.FormErrorMsg("도서제목");
                    menu.BookManagementMenu();
                }

                sqlQuery = "select * from book where name='" + searchName + "';";
            }

            else if (searchBy.Equals("출판사명"))
            {
                switch (searchType)
                {
                case "editSearch":
                    print.Search("편집할 책 출판사명");
                    break;

                case "removeSearch":
                    print.Search("삭제할 책의 출판사명");
                    break;

                case "justSearch":
                    print.Search("검색할 책 출판사명");
                    break;

                case "rentBook":
                    print.Search("대여할 책 출판사명");
                    break;
                }

                searchPublisher = Console.ReadLine();
                if (errorCheck.BookPublisher(searchPublisher))
                {
                    print.FormErrorMsg("출판사명");
                    menu.BookManagementMenu();
                }

                sqlQuery = "select * from book where publisher='" + searchPublisher + "';";
            }

            else if (searchBy.Equals("저자명"))
            {
                switch (searchType)
                {
                case "editSearch":
                    print.Search("편집할 책 저자명");
                    break;

                case "removeSearch":
                    print.Search("삭제할 책의 저자명");
                    break;

                case "justSearch":
                    print.Search("검색할 책 저자명");
                    break;

                case "rentBook":
                    print.Search("대여할 책 저자명");
                    break;
                }

                searchAuthor = Console.ReadLine();
                if (errorCheck.BookAuthor("저자명"))
                {
                    print.FormErrorMsg("저자명");
                    menu.BookManagementMenu();
                }

                sqlQuery = "select * from book where author='" + searchAuthor + "';";
            }
            SendQuery();
            dataReader.Read();

            if (errorCheck.IsValidBook(dataReader) == false) //검색 에러
            {
                CloseDB();
                print.ErrorMsg("존재하는 도서 찾기");
                if (searchType.Equals("justSearch"))
                {
                    menu.BookManagementMenu();
                }
                return(null);
            }

            BookVO foundBook = new BookVO(dataReader["name"].ToString(), dataReader["author"].ToString(),
                                          dataReader["publisher"].ToString(), int.Parse(dataReader["count"].ToString()));

            if (searchType.Equals("justSearch"))
            {
                print.BookInfo(foundBook);
                menu.BookSearchMenu();
            }

            CloseDB();
            return(foundBook);
        }