コード例 #1
0
        public static void BuyContinue()
        {
            DisplayArchive.Displaylist();
            Book       book = new Book();
            BuyDetails buy  = new BuyDetails();

            Console.WriteLine("Select Book Id you want to shop");
            buy.buyBookId = int.Parse(Console.ReadLine());
            Console.Write("Number of Books : ");
            buy.buyCount = int.Parse(Console.ReadLine());
            if (bookList.Exists(x => x.bookId == buy.buyBookId))
            {
                foreach (Book searchId in bookList)
                {
                    if (searchId.bookId == buy.buyBookId)
                    {
                        if (searchId.bookCount >= searchId.bookCount - buy.buyCount && searchId.bookCount - buy.buyCount >= 0)
                        {
                            searchId.bookCount = searchId.bookCount - buy.buyCount;
                            buy.buyBookname    = searchId.bookName;
                            buy.buyBookPrice   = searchId.bookPrice;
                        }
                        else
                        {
                            Console.WriteLine("Only {0} books are found", searchId.bookCount);
                            break;
                        }
                        buyList.Add(buy);
                    }
                }
            }
            else
            {
                Console.WriteLine("Book id {0} not found", buy.buyBookId);
            }

            Console.WriteLine("");
            DisplayBuyList.Displaylist1();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: agilan96/CRUD_CSHARP
        static void Main(string[] args)
        {
            Console.Write("\t\t\t\t\t\tWelcome To HigginBothams!!!\n" + "Login\n");
            Console.Write("Enter Username:\n");
            string username = Console.ReadLine();

            Console.Write("Enter password:\n");
            string password  = Console.ReadLine();
            int    noofbooks = 4;

            if ((username == "user1") && (password == "pass1"))
            {
                bool close = true;
                while (close)
                {
                    Console.WriteLine("\nList:\n" +
                                      "1)Display books\n" +
                                      "2)Buy book\n" +
                                      "3)Search book\n" +
                                      "4)Proceed To Cart\n" +
                                      "5)Add book\n" +
                                      "6)Delete book\n" +
                                      "7)Close\n\n");
                    Console.Write("Choose your option from List :");

                    int option = int.Parse(Console.ReadLine());

                    if (option == 1)
                    {
                        DisplayArchive.Displaylist();
                    }
                    else if (option == 2)
                    {
                        BuyBook.Buy();
                    }
                    else if (option == 3)
                    {
                        SearchBook.SearchBook1();
                    }
                    else if (option == 4)
                    {
                        DisplayBuyList.Displaylist1();
                        close = false;
                    }
                    else if (option == 5)
                    {
                        noofbooks = noofbooks + 1;
                        AddBook.GetBook(noofbooks);
                    }
                    else if (option == 6)
                    {
                        DeleteBook.RemoveBook();
                    }
                    else if (option == 7)
                    {
                        Console.WriteLine("Thank you");
                        close = false;
                        Console.Clear();
                        Environment.Exit(0);
                    }
                    else
                    {
                        Console.WriteLine("Invalid option\nRetry !!!");
                    }
                }
            }
            else
            {
                Console.WriteLine("Invalid username or password");
            }
            Console.ReadLine();
        }