Esempio n. 1
0
        public static NextWindow Init()
        {
            try
            {
                if (!Directory.Exists(ROOT_DIR))
                {
                    Directory.CreateDirectory(ROOT_DIR);
                }
                if (!Directory.Exists(PATH_TO_ROOMSFILES))
                {
                    Directory.CreateDirectory(PATH_TO_ROOMSFILES);
                }
                if (!Directory.Exists(PATH_TO_RECORDS))
                {
                    Directory.CreateDirectory(PATH_TO_RECORDS);
                }
            }
            catch
            {
            }

            NextWindow nextWindow = NextWindow.Login;

            if (File.Exists(AppController.PATH_TO_LOGININFO))
            {
                try
                {
                    string        json      = File.ReadAllText(AppController.PATH_TO_LOGININFO);
                    LoginInfoData loginInfo = JsonConvert.DeserializeObject <LoginInfoData>(json);
                    AppController.LoginInfo = loginInfo;
                    nextWindow = NextWindow.Main;
                }
                catch
                {
                }
            }

            return(nextWindow);
        }
    private void raiseNextWindow(RaiseWindowMessage obj)
    {
        // determine which window to raise and show it
        switch (obj.WindowName)
        {
        case "NextWindow":
            NextWindow view = new NextWindow();
            if (obj.ShowAsDialog)
            {
                view.ShowDialog();
            }
            else
            {
                view.Show();
            }
            break;

        // some other case here...
        default:
            break;
        }
    }
Esempio n. 3
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. 4
0
            bool BookInfoScreen(Book book, bool withTrashBtn = true)
            {
                if (book == null)
                {
                    return(false);
                }

                byte choose;
                ActiveElementDraw bookWindow;

                if (withTrashBtn)
                {
                    bookWindow = new ActiveElementDraw(head,
                                                       new StaticElement('[' + book.type.ToString() + "] " + book.shortTitle, new Coord((short)(downRightCorner.x / 2 + 3), 5)),
                                                       new StaticElement(book.autherName, new Coord((short)(downRightCorner.x / 2 + 3), 6)),
                                                       new StaticElement("Price:" + book.price.ToString(), new Coord((short)(downRightCorner.x / 2 + 3), 7)),
                                                       new StaticElement("Pages:" + book.pages.ToString(), new Coord((short)(downRightCorner.x / 2 + 3), 8)),

                                                       new ActiveStaticElement("______________\n|Add to trash|\n--------------", new Coord((short)(downRightCorner.x / 2 + downRightCorner.x / 6), 15))
                                                       );
                }
                else
                {
                    bookWindow = new ActiveElementDraw(head,
                                                       new StaticElement('[' + book.type.ToString() + "] " + book.shortTitle, new Coord((short)(downRightCorner.x / 2 + 3), 5)),
                                                       new StaticElement(book.autherName, new Coord((short)(downRightCorner.x / 2 + 3), 6)),
                                                       new StaticElement("Price:" + book.price.ToString(), new Coord((short)(downRightCorner.x / 2 + 3), 7)),
                                                       new StaticElement("Pages:" + book.pages.ToString(), new Coord((short)(downRightCorner.x / 2 + 3), 8))
                                                       );
                }
                NextWindow nextWindow = null;

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

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

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

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

                    case 17:
                        shop.AddToTrash(book);
                        goto BOOK_INFO_SCREEN_RETURN;

                    default:
                        break;
                    }
                }

BOOK_INFO_SCREEN_RETURN:
                bookWindow.ClearScreen();
                head.InitStatic();
                if (nextWindow != null)
                {
                    nextWindow.Invoke();
                    return(true);
                }
                return(false);
            }
Esempio n. 5
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. 6
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);
            }