Exemple #1
0
        private void RegisterUser()
        {
            string filePath = path + @"\" + yourName.Text + ".json";

            if (color1.Text != colorPicker.SelectedColorText || color2.Text != colorPicker2.SelectedColorText || color1.Text == "" || color2.Text == "")
            {
                MessageBox.Show("Please, select colors!");
            }
            else
            {
                if (yourName.Text == null || yourName.Text == " " || yourName.Text == "")
                {
                    MessageBox.Show("Please, write your name!");
                }
                else
                {
                    if (File.Exists(filePath))
                    {
                        MessageBox.Show("Sorry, this name already exists!");
                    }
                    else
                    {
                        somebody = new Somebody
                        {
                            Name        = yourName.Text,
                            Background  = colorPicker.SelectedColor.ToString(),
                            ColorOfName = colorPicker2.SelectedColor.ToString()
                        };
                        File.WriteAllText(filePath, JsonConvert.SerializeObject(somebody));

                        if (MessageBox.Show("You're registered!", "Congrat", MessageBoxButton.OK) == MessageBoxResult.OK)
                        {
                            User user = new User();
                            Application.Current.MainWindow = user;
                            Close();
                            user.Show();
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void TextBoxKeyUp(object sender, KeyEventArgs e)
        {
            userName = @"\" + userNameText.Text + ".json";
            if (e.Key == Key.Enter)
            {
                if (!File.Exists(userPath + userName))
                {
                    if (MessageBox.Show(message, title, button) == MessageBoxResult.Yes)
                    {
                        Register register = new Register();
                        Application.Current.MainWindow = register;
                        Close();
                        register.Show();
                    }
                }
                else
                {
                    MainWindow main   = new MainWindow();
                    TextBlock  name   = (TextBlock)main.FindName("you");
                    MainWindow window = (MainWindow)main.FindName("main");

                    string         json       = File.ReadAllText(userPath + userName, Encoding.UTF8);
                    JsonSerializer serializer = new JsonSerializer();
                    Somebody       somebody   = JsonConvert.DeserializeObject <Somebody>(json);

                    name.Text = somebody.Name;
                    var bc = new BrushConverter();
                    name.Foreground = (Brush)bc.ConvertFrom(somebody.ColorOfName);

                    var bc2 = new BrushConverter();
                    window.Background = (Brush)bc2.ConvertFrom(somebody.Background);

                    Application.Current.MainWindow = main;
                    Close();
                    main.Show();
                }
            }
        }