// Отправка сообщения на сервер private void buttonSend_Click(object sender, EventArgs e) { string title = textBoxTitle.Text; string send = entryF.CurrentUser.Login; string recipient = listBoxUser.Text; string text = textBoxSMS.Text; using (var client = new Service.ServiceClient("BasicHttpBinding_IService")) { int ids = client.getUserId(send); int idr = client.getUserId(recipient); if (ids != 0 && idr != 0) { client.setMail(new Service.Mail { Title = title, Date = DateTime.Now, Sender = send, Recipient = recipient, Text = text }); } } textBoxTitle.Clear(); textBoxSMS.Clear(); ResetCorrespondence(); }
// Аутентификация пользователя 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); } }
// Региструем пользователя 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); } }