Beispiel #1
0
            bool TrashScreen(Trash trash)
            {
                Element[] trashToPrint = new Element[trash.Length * 3 + 2];
                Book      currBook;
                string    str;

                for (int i = 0; i < trash.Length; ++i)
                {
                    if (trash[i].stored is Book)
                    {
                        currBook                = trash[i].stored as Book;
                        str                     = Validator.ValidStr(currBook.shortTitle, 16) + " | ";
                        str                    += Validator.ValidStr(currBook.autherName, 16) + " | ";
                        str                    += Validator.ValidStr(currBook.price.ToString(), 7);
                        trashToPrint[i * 3]     = new ActiveStaticElement(str, new Coord(5, (short)(i + 5)));
                        trashToPrint[i * 3 + 1] = new ActiveCounter("-----", new Coord(53, (short)(i + 5)), new Coord(1, 0), ref trash[i].cnt, 1, 255, "   ");
                        trashToPrint[i * 3 + 2] = new ActiveStaticElement("X", new Coord(62, (short)(i + 5)));
                    }
                }
                str  = Validator.ValidStr("Title", 16) + " | ";
                str += Validator.ValidStr("Auther name", 16) + " | ";
                str += Validator.ValidStr("Price", 7) + " | ";
                str += Validator.ValidStr("Cnt", 5) + " | ";
                str += Validator.ValidStr("Del", 5);
                trashToPrint[trash.Length * 3] = new StaticElement(str, new Coord(5, 4));
                if (trash.Length != 0)
                {
                    string buyBtn = "_____\n|Buy|\n-----";
                    trashToPrint[trash.Length * 3 + 1] = new ActiveStaticElement(buyBtn, new Coord((short)(str.Length / 2 - buyBtn.Length / 2), (short)(trash.Length + 6)));
                }
                else
                {
                    trashToPrint[trash.Length * 3 + 1] = null;
                }
                byte choose;
                ActiveElementDraw trashWindow = new ActiveElementDraw(head, trashToPrint);
                NextWindow        nextWindow  = null;

                trashWindow.InitStatic();
                while (true)
                {
                    trashWindow.Print();
                    choose = trashWindow.Input(InbisibleInput());
                    if (choose == 255)
                    {
                        continue;
                    }

                    switch (choose)
                    {
                    //Main
                    case 0:
                        goto TRASH_SCREEN_RETURN;

                    //Find
                    case 1:
                        nextWindow = new NextWindow(BooksListByName);
                        goto TRASH_SCREEN_RETURN;

                    //Register/Login    Logout
                    case 2:
                        nextWindow = new NextWindow(ClickOnLoginBtn);
                        goto TRASH_SCREEN_RETURN;

                    default:

                        choose -= 13;
                        if (choose == trash.Length * 3 + 1)
                        {
                            TrashObj[] deliver = shop.Buy();
                            trashWindow.ClearScreen();
                            bool accept = AcceptBeforeDeliver(deliver);
                            trashWindow.InitStatic();
                            if (accept)
                            {
                                if (shop.IsLogOn())
                                {
                                    ;                            //Послать юзеру
                                }
                                else
                                {
                                    ;                            //Открить окно ввода адреса
                                }
                            }
                            else
                            {
                                foreach (var i in deliver)
                                {
                                    if (i.cnt != 0 && i.stored != null)
                                    {
                                        shop.GetClientTrash().Add(i);
                                        for (int j = 0; j < i.cnt; ++j)
                                        {
                                            shop.GetCargo().Add(i.stored);
                                        }
                                    }
                                }
                            }
                            goto TRASH_SCREEN_RETURN;
                        }
                        else if (choose % 3 == 0)
                        {
                            trashWindow.ClearScreen();
                            BookInfoScreen(((Book)trash[choose / 3].stored), false);
                            trashWindow.InitStatic();
                        }
                        else if (choose % 3 == 2)
                        {
                            trash.Delete(((Book)trash[choose / 3].stored));
                            trashWindow.ClearScreen();
                            TrashScreen(trash);
                            goto TRASH_SCREEN_RETURN;
                        }
                        break;
                    }
                }

TRASH_SCREEN_RETURN:
                trashWindow.ClearScreen();
                if (nextWindow != null)
                {
                    nextWindow.Invoke();
                }
                return(true);
            }
Beispiel #2
0
            bool BooksListScreen(System.Collections.Generic.List <Book> find)
            {
                bool toReturn = false;

                Element[] booksToPrint = new Element[find.Count + 2];
                Book      currBook     = null;
                string    str          = null;
                int       len          = find.Count > downRightCorner.y - 7 ? downRightCorner.y - 7 : find.Count;

                for (int i = 0; i < len; ++i)
                {
                    currBook = find[i];
                    str      = Validator.ValidStr(currBook.shortTitle, 16) + " | ";
                    str     += Validator.ValidStr(currBook.autherName, 16) + " | ";
                    str     += Validator.ValidStr(currBook.price.ToString(), 7);
                    if (i % 2 == 0)
                    {
                        booksToPrint[i] = new ActiveStaticElement(str, new Coord(5, (short)(i / 2 + 5)));
                    }
                    else
                    {
                        booksToPrint[i] = new ActiveStaticElement(str, new Coord((short)(downRightCorner.x / 2 + 3), (short)(i / 2 + 5)));
                    }
                }

                str  = Validator.ValidStr("Title", 16) + " | ";
                str += Validator.ValidStr("Auther name", 16) + " | ";
                str += Validator.ValidStr("Price", 7);
                booksToPrint[find.Count] = new StaticElement(str, new Coord(5, 4));
                if (find.Count != 1)
                {
                    booksToPrint[find.Count + 1] = new StaticElement(str, new Coord((short)(downRightCorner.x / 2 + 3), 4));
                }
                else
                {
                    booksToPrint[find.Count + 1] = new StaticElement("", new Coord(0, 0));
                }

                byte choose;
                ActiveElementDraw findWindow = new ActiveElementDraw(head, booksToPrint);
                NextWindow        nextWindow = null;

                findWindow.InitStatic();
                while (true)
                {
                    findWindow.Print();
                    choose = findWindow.Input(InbisibleInput());
                    if (choose == 255)
                    {
                        continue;
                    }

                    switch (choose)
                    {
                    //Main
                    case 0:
                        goto BOOK_LIST_SCREEN_RETURN;

                    //Find
                    case 1:
                        nextWindow = new NextWindow(BooksListByName);
                        goto BOOK_LIST_SCREEN_RETURN;

                    //Register/Login    Logout
                    case 2:
                        nextWindow = new NextWindow(ClickOnLoginBtn);
                        goto BOOK_LIST_SCREEN_RETURN;

                    default:
                        if (choose >= 13)
                        {
                            findWindow.ClearScreen();
                            if (BookInfoScreen(find[choose - 13]))
                            {
                                goto BOOK_LIST_SCREEN_RETURN;
                            }
                            findWindow.InitStatic();
                        }
                        break;
                    }
                }

BOOK_LIST_SCREEN_RETURN:
                findWindow.ClearScreen();
                head.InitStatic();
                if (nextWindow != null)
                {
                    nextWindow.Invoke();
                }
                return(toReturn);
            }
Beispiel #3
0
            void MainScreen()
            {
                string[]  bookTypes          = shop.GetBookTypes();
                Element[] mainScreenElements = new Element[bookTypes.Length + 3];
                mainScreenElements[0] = new ActiveStaticElement("__________\n| Trash  |\n----------", new Coord((short)(downRightCorner.x - 10), 4));

                mainScreenElements[1] = mainScreenElements[2] = null;

                for (byte i = 0; i < bookTypes.Length; ++i)
                {
                    mainScreenElements[i + 3] = new ActiveStaticElement(bookTypes[i], new Coord(5, (short)(i + 4)));
                }

                byte choose;
                ActiveElementDraw mainWindow = new ActiveElementDraw(head, mainScreenElements);

                mainWindow.InitStatic();
                while (true)
                {
                    mainWindow.Print();
                    choose = mainWindow.Input(InbisibleInput());
                    if (choose == 255)
                    {
                        continue;
                    }

                    switch (choose)
                    {
                    //Main
                    case 0:
                        if (WantToExit())
                        {
                            return;
                        }
                        break;

                    //Find
                    case 1:
                        mainWindow.ClearScreen();
                        BooksListByName();
                        mainWindow.InitStatic();
                        break;

                    //Register/Login    Logout
                    case 2:
                        mainWindow.ClearScreen();
                        ClickOnLoginBtn();
                        if (shop.IsLogOn())
                        {
                            mainScreenElements[1] = new ActiveStaticElement("__________\n|UserInfo|\n----------", new Coord((short)(downRightCorner.x - 10), 7));
                        }
                        else
                        {
                            mainScreenElements[1] = null;
                        }

                        if (shop.IsSuperUserLogOn())
                        {
                            mainScreenElements[2] = new ActiveStaticElement("____________\n|AdminPanel|\n------------", new Coord((short)(downRightCorner.x - 12), 10));
                        }
                        else
                        {
                            mainScreenElements[2] = null;
                        }
                        mainWindow = new ActiveElementDraw(head, mainScreenElements);
                        mainWindow.InitStatic();
                        break;

                    //Trash manager
                    case 13:
                        mainWindow.ClearScreen();
                        TrashScreen(shop.GetClientTrash());
                        mainWindow.InitStatic();
                        break;

                    //User profile
                    case 14:
                        mainWindow.ClearScreen();
                        UserScreen(shop.GetClient());
                        mainWindow.InitStatic();
                        break;

                    //Admin terminal
                    case 15:
                        mainWindow.ClearScreen();
                        AdminPanel();
                        mainWindow.InitStatic();
                        break;

                    default:
                        if (choose >= 16)
                        {
                            mainWindow.ClearScreen();
                            BooksListByType((Book.BookTypes)(choose - 15));
                            mainWindow.InitStatic();
                        }
                        break;
                    }
                }
            }