This repository has been archived on 2022-08-31. You can view files and clone it, but cannot push or open issues or pull requests.
awesome-email-extractor/EditUserForm.cs

70 lines
1.8 KiB
C#
Raw Permalink Normal View History

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AwesomeEmailExtractor
{
public partial class EditUserForm : Form
{
public User User { get; set; }
public EditUserForm()
{
InitializeComponent();
}
private void EditUserForm_Load(object sender, EventArgs e)
{
idTextBox.Text = User.ID.ToString();
loginTextBox.Text = User.Login;
roleComboBox.Items.Add(UserRoles.DEFAULT.ToString());
roleComboBox.Items.Add(UserRoles.ADMIN.ToString());
roleComboBox.SelectedIndex = (int)User.Role;
}
private void submitButton_Click(object sender, EventArgs e)
{
if (loginTextBox.Text.Length == 0)
{
MessageBox.Show("Логин не может быть пустым!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
AdminUtils adminUtils = new AdminUtils(Globals.currentUser);
User editedUser = new User(User.ID, loginTextBox.Text, (UserRoles)roleComboBox.SelectedIndex);
2022-05-25 08:23:03 +03:00
try
{
2022-05-25 08:23:03 +03:00
if (passwordTextBox.Text != "")
{
adminUtils.editUser(editedUser, passwordTextBox.Text);
}
else
{
adminUtils.editUser(editedUser);
}
}
2022-05-25 08:23:03 +03:00
catch (Exception ex)
{
2022-05-25 08:23:03 +03:00
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
this.Close();
}
}
}