Esempio n. 1
0
            void RegisterAndLoginScreen()
            {
                byte choose;
                ActiveElementDraw loginWindow;
                NextWindow        nextWindow = null;

                {
                    loginWindow = new ActiveElementDraw(head,

                                                        new StaticElement(" ::Login::", new Coord(10, 5)),
                                                        new ActiveInputElement("Login:"******"Pass:"******"-------\n|Login|\n-------", new Coord(10, 10)),


                                                        new StaticElement("╔══╗╔═══╗\n║╔╗║║╔═╗║\n║║║║║╚═╝║\n║║║║║╔╗╔╝\n║╚╝║║║║║\n╚══╝╚╝╚╝", new Coord((short)(downRightCorner.x / 2 - 10), (short)(downRightCorner.y / 2 - 5))),

                                                        new StaticElement(" ::Register::", new Coord((short)(downRightCorner.x / 2 + 10), 5)),
                                                        new ActiveInputElementAllSymbols("E-mail: " + new string(' ', 31), new Coord((short)(downRightCorner.x / 2 + 10), 7), new Coord(8, 0), 32),
                                                        new ActiveInputElement("Login: "******"Pass: "******"Name:    " + new string(' ', 16), new Coord((short)(downRightCorner.x / 2 + 10), 11), new Coord((short)"Name:    ".Length, 0), 16),
                                                        new ActiveInputElement("Surname: " + new string(' ', 16), new Coord((short)(downRightCorner.x / 2 + 10), 12), new Coord((short)"Surname: ".Length, 0), 16),
                                                        new ActiveInputElement("Phone:   " + new string(' ', 13), new Coord((short)(downRightCorner.x / 2 + 10), 13), new Coord((short)"Phone:   ".Length, 0), 10),

                                                        new ActiveStaticElement("----------\n|Register|\n----------", new Coord((short)(downRightCorner.x / 2 + 10), 15))
                                                        );
                }

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

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

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

                    //Register/Login    Logout
                    case 2:
                        break;

                    //Login
                    case 16:
                        if (shop.Login(loginWindow.GetInputValue(14), LoginPass.Hasher(loginWindow.GetInputValue(15))) != null)
                        {
                            head.ChangeDoubleElementContrain(2);
                            goto REGISTER_AND_LOGIN_RETURN;
                        }
                        break;

                    //Register
                    case 25:
                        if (loginWindow.GetInputValue(22).Length == 0 || loginWindow.GetInputValue(23).Length == 0 ||
                            loginWindow.GetInputValue(24).Length == 0 || loginWindow.GetInputValue(21).Length == 0 ||
                            loginWindow.GetInputValue(20).Length == 0 || loginWindow.GetInputValue(19).Length == 0
                            )
                        {
                            break;
                        }
                        if (!(Validator.IsEmail(loginWindow.GetInputValue(19)) && Validator.IsPhone(loginWindow.GetInputValue(24))))
                        {
                            break;
                        }
                        if (shop.CreateUser(new Person(loginWindow.GetInputValue(22), loginWindow.GetInputValue(23), loginWindow.GetInputValue(24)),
                                            loginWindow.GetInputValue(20), LoginPass.Hasher(loginWindow.GetInputValue(21)), loginWindow.GetInputValue(19)))
                        {
                            shop.Login(loginWindow.GetInputValue(20), LoginPass.Hasher(loginWindow.GetInputValue(21)));
                            head.ChangeDoubleElementContrain(2);
                            goto REGISTER_AND_LOGIN_RETURN;
                        }

                        break;

                    default:
                        //Console.Write(choose);
                        break;
                    }
                }

REGISTER_AND_LOGIN_RETURN:
                loginWindow.ClearScreen();
                head.InitStatic();
                if (nextWindow != null)
                {
                    nextWindow.Invoke();
                }
            }
Esempio n. 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);
            }
Esempio n. 3
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);
            }
Esempio n. 4
0
            bool AcceptBeforeDeliver(TrashObj[] toDeliver)
            {
                Element[] trashToPrint = new Element[toDeliver.Length * 3 + 3];
                Book      currBook;
                string    str;

                for (int i = 0; i < toDeliver.Length; ++i)
                {
                    if (toDeliver[i].stored is Book)
                    {
                        currBook                = toDeliver[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 StaticElement(str, new Coord(5, (short)(i + 5)));
                        trashToPrint[i * 3 + 1] = new StaticElement(toDeliver[i].cnt.ToString(), new Coord(53, (short)(i + 5)));
                        if (toDeliver[i].cnt == 0)
                        {
                            trashToPrint[i * 3 + 2] = new StaticElement("not in stock", new Coord(62, (short)(i + 5)));
                        }
                        else
                        {
                            trashToPrint[i * 3 + 2] = new StaticElement("", 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) + " | ";
                trashToPrint[toDeliver.Length * 3] = new StaticElement(str, new Coord(5, 4));
                if (toDeliver.Length != 0)
                {
                    string buyBtn = "_____\n|Buy|\n-----";
                    trashToPrint[toDeliver.Length * 3 + 1] = new ActiveStaticElement(buyBtn, new Coord((short)(str.Length / 2 - buyBtn.Length / 2 - 10), (short)(toDeliver.Length + 6)));
                    buyBtn = "________\n|Cancel|\n--------";
                    trashToPrint[toDeliver.Length * 3 + 2] = new ActiveStaticElement(buyBtn, new Coord((short)(str.Length / 2 - buyBtn.Length / 2 + 10), (short)(toDeliver.Length + 6)));
                }
                else
                {
                    trashToPrint[toDeliver.Length * 3 + 1] = trashToPrint[toDeliver.Length * 3 + 2] = null;
                }

                byte choose;
                ActiveElementDraw trashWindow = new ActiveElementDraw(head, trashToPrint);

                trashWindow.InitStatic();
                while (true)
                {
                    trashWindow.Print();
                    choose  = trashWindow.Input(InbisibleInput());
                    choose -= 13;
                    if (choose == 255)
                    {
                        continue;
                    }
                    if (choose == toDeliver.Length * 3 + 1)
                    {
                        trashWindow.ClearScreen();
                        return(true);
                    }
                    if (choose == toDeliver.Length * 3 + 2)
                    {
                        trashWindow.ClearScreen();
                        return(false);
                    }
                }
            }
Esempio n. 5
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;
                    }
                }
            }