This commit is contained in:
Maxim 2024-12-02 20:36:33 +04:00
parent 9648b4210d
commit fdfc7602b2
2 changed files with 32 additions and 28 deletions

View File

@ -9,6 +9,10 @@ namespace ProjectGSM.Entities.Enums
[Flags]
public enum LicenseType
{
None, Base, Novokek, Pro, Master, Guru
None = 0,
Base = 1 << 0,
Pro = 1 << 1,
Master = 1 << 2,
Guru = 1 << 3
}
}
}

View File

@ -5,7 +5,6 @@ using ProjectGSM.Repositories;
namespace ProjectGSM.Forms
{
public partial class FormAdvocate : Form
{
private readonly IAdvocateRepository _advocateRepository;
@ -19,11 +18,11 @@ namespace ProjectGSM.Forms
try
{
var advocate =
_advocateRepository.ReadAdvocateById(value);
_advocateRepository.ReadAdvocateById(value);
if (advocate == null)
{
throw new
InvalidDataException(nameof(advocate));
InvalidDataException(nameof(advocate));
}
_advocateId = value;
@ -32,13 +31,14 @@ namespace ProjectGSM.Forms
if ((elem & advocate.LicenseType) != 0)
{
checkedListBox.SetItemChecked(checkedListBox.Items.IndexOf(
elem), true);
elem), true);
}
}
nameTextBox.Text = advocate.Name;
sexCheckBox.Checked= advocate.Sex;
dateTimePicker.Value = new DateTime(advocate.DateOfBirth.Year, advocate.DateOfBirth.Month, advocate.DateOfBirth.Day);
sexCheckBox.Checked = advocate.Sex;
dateTimePicker.Value = new DateTime(advocate.DateOfBirth.Year, advocate.DateOfBirth.Month,
advocate.DateOfBirth.Day);
expNumeric.Value = advocate.Experience;
tasksNumeric.Value = advocate.CompletedTasks;
ratingNumeric.Value = advocate.Rating;
@ -48,7 +48,8 @@ namespace ProjectGSM.Forms
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
}
@ -59,14 +60,13 @@ namespace ProjectGSM.Forms
{
InitializeComponent();
_advocateRepository = advocateRepository ??
throw new
ArgumentNullException(nameof(advocateRepository));
throw new
ArgumentNullException(nameof(advocateRepository));
foreach (var elem in Enum.GetValues(typeof(LicenseType)))
{
checkedListBox.Items.Add(elem);
}
}
private void saveButton_Click(object sender, EventArgs e)
@ -80,6 +80,7 @@ namespace ProjectGSM.Forms
{
throw new Exception("Имеются незаполненные поля");
}
if (_advocateId.HasValue)
{
_advocateRepository.UpdateAdvocate(CreateAdvocate(_advocateId.Value));
@ -88,36 +89,35 @@ namespace ProjectGSM.Forms
{
_advocateRepository.CreateAdvocate(CreateAdvocate(0));
}
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void cancelButton_Click(object sender, EventArgs e) => Close();
private Advocate CreateAdvocate(int id)
{
LicenseType licenseType = LicenseType.None;
foreach (var elem in checkedListBox.CheckedItems)
int licenseType = 0;
foreach (int elem in checkedListBox.CheckedItems)
{
licenseType |= (LicenseType)elem;
licenseType |= elem;
}
return Advocate.CreateEntity(id,
nameTextBox.Text,
sexCheckBox.Checked,
dateTimePicker.Value,
Convert.ToInt32(expNumeric.Value),
Convert.ToInt32(tasksNumeric.Value),
Convert.ToInt32(ratingNumeric.Value),
emailTextBox.Text,
phoneText.Text,
adressBox.Text, licenseType);
nameTextBox.Text,
sexCheckBox.Checked,
dateTimePicker.Value,
Convert.ToInt32(expNumeric.Value),
Convert.ToInt32(tasksNumeric.Value),
Convert.ToInt32(ratingNumeric.Value),
emailTextBox.Text,
phoneText.Text,
adressBox.Text, (LicenseType)licenseType);
}
}
}
}