Esempio n. 1
0
        // Аутентификация пользователя
        private void buttonEnter_Click(object sender, EventArgs e)
        {
            try
            {
                string login    = textBoxELogin.Text;
                string password = textBoxEPassword.Text;

                using (var client = new Service.ServiceClient("BasicHttpBinding_IService"))
                {
                    int id = client.getUserId(login);
                    if (id == 0)
                    {
                        MessageBox.Show("Пользователь с таким логином не найден.");
                    }
                    else
                    {
                        var dict = client.checkUser(login, password);
                        if (dict.Count == 0)
                        {
                            MessageBox.Show("Неверный пароль.");
                        }
                        else
                        {
                            CurrentUser = dict.Values.ToArray()[0];
                            this.Hide();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        // Региструем пользователя
        private void buttonReg_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBoxRName.Text == string.Empty)
                {
                    MessageBox.Show("Введите имя.");
                    return;
                }
                string name = textBoxRName.Text;

                if (textBoxRLogin.Text == string.Empty)
                {
                    MessageBox.Show("Введите логин.");
                    return;
                }
                string login = textBoxRLogin.Text;

                if (textBoxRPassword.Text == string.Empty)
                {
                    MessageBox.Show("Введите пароль.");
                    return;
                }
                string password = textBoxRPassword.Text;

                using (var client = new Service.ServiceClient("BasicHttpBinding_IService"))
                {
                    // Проверяем логин
                    int id = client.getUserId(login);
                    if (id != 0)
                    {
                        MessageBox.Show("Этот логин уже занят, придумайте другой");
                    }
                    else
                    {
                        Service.User user = new Service.User
                        {
                            Login = login,
                            Name  = name
                        };
                        // Добавляем пользователя в базу
                        client.setUser(user, password);

                        // Проверяем, получаем информацию о пользователе
                        var dict = client.checkUser(login, password);
                        if (dict.Count == 0)
                        {
                            MessageBox.Show("Неизвестная ошибка");
                        }
                        else
                        {
                            // Сохраняем имя текущего пользователя
                            CurrentUser = dict.Values.ToArray()[0];
                            this.Hide();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }