示例#1
0
        public static void RZSignUp(ref List <RZAccount> RZAccountsList)
        {
            Console.SetWindowSize(35, 19);
            Console.SetBufferSize(35, 19);
            RZAccount info = new RZAccount();

            do
            {
                Console.WriteLine($"Create a new user with new id: {RZAccountsList.Count}");
                do
                {
                    Console.SetCursorPosition(2, 6);
                    Console.Write("Name:    ");
                    info.RZName = Console.ReadLine();
                } while (info.RZName.Length == 0);
                do
                {
                    Console.SetCursorPosition(2, 7);
                    Console.Write("Surname: ");
                    info.RZSurname = Console.ReadLine();
                } while (info.RZSurname.Length == 0);
                do
                {
                    Console.SetCursorPosition(2, 8);
                    Console.Write("Age:     ");
                    int.TryParse(Console.ReadLine(), out int tempint);
                    info.RZAge = tempint;
                } while (info.RZAge == 0);

                Console.WriteLine($"Name:    {info.RZName}");
                Console.WriteLine($"Surname: {info.RZSurname}");
                Console.WriteLine($"Age:     {info.RZAge}");
                Console.WriteLine();

                if (info.RZName.Length > 0)
                {
                    info.RZLogin  = info.RZName.ToUpper();
                    info.RZLogin += "_";
                }
                if (info.RZSurname.Length > 0)
                {
                    string temp_name = info.RZSurname.ToLower();
                    info.RZLogin += temp_name[0];
                    if (info.RZSurname.Length > 1)
                    {
                        info.RZLogin += temp_name[1];
                    }
                }
                if (info.RZAge > 0)
                {
                    if (info.RZSurname.Length > 0)
                    {
                        info.RZLogin += "_";
                    }
                    info.RZLogin += info.RZAge.ToString();
                }
                info.RZPassword = RandomString(password_len);
                //info.RZPassword = Console.ReadLine();
                for (int i = 0; i < RZAccountsList.Count; i++)
                {
                    if (info.RZLogin == RZAccountsList[i].RZLogin)
                    {
                        info.RZLogin += "c";
                    }
                }
                Console.WriteLine($"User Login:    {info.RZLogin}");
                Console.WriteLine($"User Password: {info.RZPassword}");

                Console.ReadKey();
            } while (info.RZLogin.Length == 0);
            //RZWriteBin(ref info);
            RZAccountsList.Add(info);
            //---------------------------------
            RZJson RZJsonx = new RZJson();

            RZJsonx.Save(RZAccountsList, "Users");
            //***************************************
        }
        public static void RZMainMenyu(ref List <RZAccount> RZAccountsList)
        {
            if (ThisUser.Length != 0)
            {
                RZMainMenyuUser(ref RZAccountsList);
            }
            else
            {
                Console.SetWindowSize(20, 11);
                Console.SetBufferSize(20, 11);

                int m_ind   = 0;
                int m_count = 3;
                var m_list  = new string[m_count];
                m_list[0] = "  Sign up     ";
                m_list[1] = "  Log in      ";
                m_list[2] = "  Exit        ";

                ConsoleKeyInfo cki;
                do
                {
                    Console.Clear();
                    for (short i = 0; i < m_list.Length; i++)
                    {
                        if (m_ind == i)
                        {
                            SetColorBlue();
                            Console.WriteLine(m_list[i]);
                            Console.ResetColor();
                        }
                        else
                        {
                            Console.WriteLine(m_list[i]);
                        }
                    }
                    cki = Console.ReadKey();
                    //Console.WriteLine(cki.Key);
                    if (cki.Key == ConsoleKey.Escape)
                    {
                        System.Environment.Exit(1);
                    }
                    if (cki.KeyChar == 'a')
                    {
                        Console.WriteLine("You pressed a");
                    }
                    if (cki.Key == ConsoleKey.X &&
                        cki.Modifiers == ConsoleModifiers.Control)
                    {
                        Console.WriteLine("You pressed Ctrl+X");
                    }
                    if (cki.Key == ConsoleKey.DownArrow)
                    {
                        m_ind += 1;
                        if (m_ind >= m_count)
                        {
                            m_ind = m_count - 1;
                        }
                    }
                    if (cki.Key == ConsoleKey.UpArrow)
                    {
                        m_ind -= 1;
                        if (m_ind <= 0)
                        {
                            m_ind = 0;
                        }
                    }
                    if (cki.Key == ConsoleKey.Enter)
                    {
                        switch (m_ind)
                        {
                        case 0:
                            RZAccount.RZSignUp(ref RZAccountsList);
                            break;

                        case 1:
                            if (RZAccountsList.Count == 0)
                            {
                                Console.WriteLine("Users is not exist!");
                                RZAccount.RZSignUp(ref RZAccountsList);      //if user is not then create new user
                            }
                            else
                            {
                                RZAccount.RZLogIn(ref RZAccountsList);
                            }
                            break;

                        case 2:
                            Environment.Exit(1);
                            break;
                        }
                    }
                } while (true);
            }
        }