Пример #1
0
        private bool Entering(string login, string password, bool adm_or_us)
        {
            List <user_admin> users_adm /* = new List<user_admin>()*/;

            if (adm_or_us)
            {
                File_Work file_Work = new File_Work("adm.txt");
                users_adm = file_Work.From_File();
            }
            else
            {
                File_Work file_Work = new File_Work();
                users_adm = file_Work.From_File();
            }
            foreach (var item in users_adm)
            {
                if (item.Get_Login == login && item.Get_Password == password)
                {
                    users_adm.Clear();
                    return(true);
                }
            }
            users_adm.Clear();
            return(false);
        }
Пример #2
0
        private void Work_with_users()
        {
            try
            {
                byte[]            buffer = new byte[256];
                List <user_admin> users /*= new List<user_admin>()*/;
                File_Work         file_Work = new File_Work();

                users = file_Work.From_File();
                if (users.Count == 0)
                {
                    buffer = Encoding.UTF8.GetBytes("NULL");
                    stream.Write(buffer, 0, buffer.Length);
                }
                else
                {
                    foreach (var item in users)
                    {
                        buffer = Encoding.UTF8.GetBytes(item.NetWork_Send);
                        stream.Write(buffer, 0, buffer.Length);///шлем данные о пользователях
                    }
                }
                StringBuilder builder = new StringBuilder();
                int           bytes   = 0;
                byte[]        buf     = new byte[1];
                bytes = stream.Read(buf, 0, buf.Length);
                builder.Append(Encoding.UTF8.GetString(buf, 0, bytes));
                string msg_code = builder.ToString();
                if (Convert.ToInt32(msg_code) == 1)
                {
                    users.Clear();
                    Console.WriteLine("Админ изменил список пользователей ->");
                    string log, pass, str = "";
                    do
                    {
                        builder.Clear();
                        bytes = 0;
                        bytes = stream.Read(buffer, 0, buffer.Length);
                        builder.Append(Encoding.UTF8.GetString(buffer, 0, bytes));
                        str += builder.ToString();
                        builder.Clear();
                    } while (stream.DataAvailable);
                    if (str == "NULL")
                    {
                        Console.WriteLine("Пользователи удалены");
                        users.Clear();
                        file_Work.DelFile();
                    }
                    else
                    {
                        string[] str_arr = str.Split('\n');
                        for (int i = 0, j = 1; i < str_arr.Length - 1; i++, j++)
                        {
                            log = str_arr[i];
                            i++;
                            pass = str_arr[i];
                            users.Add(new user_admin(log, pass));
                            Console.WriteLine($"Ползователь {j}: {log} - {pass}");
                        }
                        file_Work.To_File(users);
                    }
                }
                else
                {
                    Console.WriteLine("Админ не менял данных");
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }