예제 #1
0
 private void Password2TextBoxClick(object sender, MouseButtonEventArgs e)
 {
     Password2.Clear();
 }
예제 #2
0
        private void RegisterButtonSubmitClick(object sender, RoutedEventArgs e)
        {
            if (Password1.Password.Length > 4 && Password1.Password.Length < 10 && Password1.Password == Password2.Password && Name.Text.Length > 4 && Name.Text.Length < 16)
            {
                BinaryWriter writer = new BinaryWriter(App.getStream());
                BinaryReader reader = new BinaryReader(App.getStream());

                try
                {
                    string login    = Name.Text;
                    string password = Password1.Password.ToString();
                    writer.Write(2);
                    writer.Flush();
                    writer.Write(login);
                    writer.Flush();
                    writer.Write(password);
                    writer.Flush();


                    var res = reader.ReadInt32();
                    switch (res)
                    {
                    case 1:
                        MessageBox.Show("Ви успішно зареєструвалися");
                        Name.Clear();
                        Password1.Clear();
                        Password2.Clear();
                        break;

                    case 2:
                        MessageBox.Show("Користувач з таким логіном вже існує");
                        break;

                    case 0:
                        MessageBox.Show("Сталася помилка на сервері");
                        break;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Something is wrong. \n\n\n" + ex.ToString());
                }
                finally
                {
                    writer.Close();
                    reader.Close();
                    App.closeClient();
                }
            }

            if (Name.Text == "")
            {
                NameErrorLabel.Content    = "Name is empty";
                NameErrorLabel.Visibility = Visibility.Visible;
            }

            if (Password1.Password.ToString() == "")
            {
                PasswordErrorLabel.Content    = "Password is empty";
                PasswordErrorLabel.Visibility = Visibility.Visible;
            }

            if (Password2.Password.ToString() == "")
            {
                Password2ErrorLabel.Content    = "Password is empty";
                Password2ErrorLabel.Visibility = Visibility.Visible;
            }
        }