示例#1
0
        private void RegisterMethod(/*object obj*/)
        {
            ThicknessAnimation errorAnimation = new ThicknessAnimation();

            errorAnimation.Duration          = TimeSpan.FromSeconds(0.4);
            errorAnimation.From              = new Thickness(0);
            errorAnimation.To                = new Thickness(3);
            errorAnimation.AccelerationRatio = 0.3;
            errorAnimation.DecelerationRatio = 0.7;
            errorAnimation.AutoReverse       = true;

            string pass = (PasswordTextBox.Visibility == Visibility.Visible) ? PasswordTextBox.Text : PasswordBoxBox.Password;

            if (LoginBox.Text.Contains(' '))
            {
                LoginBox.BeginAnimation(BorderThicknessProperty, errorAnimation);
                ShowErrorWindow("Can't use spaces");
            }
            else if (pass == "")
            {
                PasswordTextBox.BeginAnimation(BorderThicknessProperty, errorAnimation);
            }
            else
            {
                try
                {
                    tcpClient = new TcpClient();
                    tcpClient.Connect(ServerIp, ServerPort);
                    WriteToStream(tcpClient.GetStream(), $"REGU {LoginBox.Text} {pass}");

                    string data = ReadStringFromStream(tcpClient.GetStream());
                    if (data == "OK")
                    {
                        Login    = LoginBox.Text;
                        Password = pass;

                        LoadGroups();
                        ShowSuccessWindow("Successfully registered");
                        var animation = new ThicknessAnimation();
                        animation.From              = new Thickness(0, 0, 0, 0);
                        animation.To                = new Thickness(0, -500, 0, 500);
                        animation.Duration          = TimeSpan.FromSeconds(1);
                        animation.AccelerationRatio = 0.3;
                        animation.DecelerationRatio = 0.7;
                        LogInGrid.BeginAnimation(MarginProperty, animation);
                    }
                    else if (data == "USER")
                    {
                        ShowErrorWindow("Login already used");
                        LoginBox.BeginAnimation(BorderThicknessProperty, errorAnimation);
                    }
                    tcpClient.Close();
                }
                catch (Exception)
                {
                    ShowErrorWindow("Something went wrong");
                }
            }
        }
示例#2
0
        //Вход пользователя
        private void LogInMethod(/*object obj*/)
        {
            ThicknessAnimation errorAnimation = new ThicknessAnimation();

            errorAnimation.Duration          = TimeSpan.FromSeconds(0.4);
            errorAnimation.From              = new Thickness(0);
            errorAnimation.To                = new Thickness(3);
            errorAnimation.AccelerationRatio = 0.3;
            errorAnimation.DecelerationRatio = 0.7;
            errorAnimation.AutoReverse       = true;

            try
            {
                tcpClient = new TcpClient();
                tcpClient.Connect(ServerIp, ServerPort);
                string pass = (PasswordTextBox.Visibility == Visibility.Visible) ? PasswordTextBox.Text : PasswordBoxBox.Password;
                WriteToStream(tcpClient.GetStream(), $"LGIN {LoginBox.Text} {pass}");

                string data = ReadStringFromStream(tcpClient.GetStream());
                switch (data)
                {
                case "OK":     //Все правильно
                {
                    Login    = LoginBox.Text;
                    Password = PasswordTextBox.Text;

                    LoadGroups();
                    ShowSuccessWindow("Successfully logged in");
                    var animation = new ThicknessAnimation();
                    animation.From              = new Thickness(0, 0, 0, 0);
                    animation.To                = new Thickness(0, -500, 0, 500);
                    animation.Duration          = TimeSpan.FromSeconds(1);
                    animation.AccelerationRatio = 0.3;
                    animation.DecelerationRatio = 0.7;
                    LogInGrid.BeginAnimation(MarginProperty, animation);
                    break;
                }

                case "PASS":     //Неверный пароль
                {
                    if (PasswordTextBox.Visibility == Visibility.Visible)
                    {
                        PasswordTextBox.BeginAnimation(BorderThicknessProperty, errorAnimation);
                    }
                    else
                    {
                        PasswordBoxBox.BeginAnimation(BorderThicknessProperty, errorAnimation);
                    }
                    break;
                }

                case "LOGIN":     //Не найден логин
                {
                    LoginBox.BeginAnimation(BorderThicknessProperty, errorAnimation);
                    break;
                }

                default:
                    MessageBox.Show("Error with answer.");
                    break;
                }
                tcpClient.Close();
            }
            catch (Exception)
            {
                ShowErrorWindow("Something went wrong");
            }
        }