Example #1
0
        public BookVO RegisterBook()
        {
            string name;
            string author;
            string publisher;
            string count;

            Console.Clear();
            while (true)
            {
                Console.Write("\n\n\t도서 제목 입력(16자이내) : ");
                name = Console.ReadLine();
                if (errorCheck.BookName(name) == false)
                {
                    break;
                }

                FormErrorMsg("도서제목");
            }

            while (true)
            {
                Console.Write("\n\n\t저자 입력(10자이내) : ");
                author = Console.ReadLine();
                if (errorCheck.BookAuthor(author) == false)
                {
                    break;
                }

                FormErrorMsg("저자");
            }

            while (true)
            {
                Console.Write("\n\n\t출판사 입력(8자이내) : ");
                publisher = Console.ReadLine();
                if (errorCheck.BookName(publisher) == false)
                {
                    break;
                }

                FormErrorMsg("출판사명");
            }

            while (true)
            {
                Console.Write("\n\n\t수량 입력(숫자만 입력) : ");
                count = Console.ReadLine();
                if (errorCheck.BookCount(count) == false)
                {
                    break;
                }

                FormErrorMsg("수량");
            }
            BookVO newBook = new BookVO(name, author, publisher, int.Parse(count));

            return(newBook);
        }
Example #2
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);
        }