예제 #1
0
 public RegisterForm(Model.RegisterData regData)
 {
     InitializeComponent();
     this.regData  = regData;
     btnOk.Enabled = OpenOkBtn();
 }
예제 #2
0
        static void Main()
        {
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Client.TryGetClient();
            Model.LoginData loginData = new Model.LoginData();
            while (Client.Id == -1)
            {
                LoginForm    loginForm = new LoginForm(loginData);
                DialogResult result    = loginForm.ShowDialog();
                // логин
                if (result == DialogResult.OK)
                {
                    UserLoginOuput userLoginOutput;
                    try
                    {
                        using var channel = Connection.GetDispatcherChannel();
                        var serviceClient = new GodvilleServiceClient(channel);
                        userLoginOutput = serviceClient.Login(
                            new LoginData
                        {
                            Login    = loginData.Login,
                            Password = loginData.Password,
                        });
                    }
                    catch (Exception e)
                    {
                        Logger.AddErrorMessage(e.Message);
                        MessageBox.Show("Что-то пошло не так");
                        return;
                    }

                    if (userLoginOutput.Id == -1)
                    {
                        MessageBox.Show("Неверное имя пользователя или пароль");
                    }
                    else
                    {
                        Client.Id         = userLoginOutput.Id;
                        Client.Nickname   = userLoginOutput.Nickname;
                        Client.CountLives = userLoginOutput.HealthCount;
                        Client.HeroName   = userLoginOutput.HeroName;
                        Client.SetClientData();
                    }
                }
                // регистрация
                else if (result == DialogResult.Ignore)
                {
                    Model.RegisterData regData = new Model.RegisterData();
                    RegisterForm       rf      = new RegisterForm(regData);
                    if (rf.ShowDialog() == DialogResult.OK)
                    {
                        UserRegOutput userRegOutput;
                        try
                        {
                            using var channel = Connection.GetDispatcherChannel();
                            var serviceClient = new GodvilleServiceClient(channel);
                            userRegOutput = serviceClient.Register(
                                new RegisterData
                            {
                                LoginData = new LoginData {
                                    Login = regData.Login, Password = regData.Password
                                },
                                Nickname = regData.Nickname,
                                Heroname = regData.HeroName
                            });
                        } catch (Exception e)
                        {
                            MessageBox.Show("Что-то пошло не так");
                            Logger.AddErrorMessage(e.Message);
                            return;
                        }

                        if (userRegOutput.Id == -1)
                        {
                            MessageBox.Show("Логин занят, выберите другой");
                        }
                        else
                        {
                            Client.Id         = userRegOutput.Id;
                            Client.Nickname   = userRegOutput.Nickname;
                            Client.CountLives = Client.GetLivesCount();
                            Client.HeroName   = regData.HeroName;
                            Client.SetClientData();
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                // завершение работы
                else if (result == DialogResult.Cancel)
                {
                    return;
                }
            }
            Application.Run(new StartForm());
        }