From fdfc7602b2152a51514fe363f9c645c3db145094 Mon Sep 17 00:00:00 2001 From: Maxim Date: Mon, 2 Dec 2024 20:36:33 +0400 Subject: [PATCH] mini fix --- ProjectGSM/Entities/Enums/LicenseType.cs | 8 +++- ProjectGSM/Forms/FormAdvocate.cs | 52 ++++++++++++------------ 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/ProjectGSM/Entities/Enums/LicenseType.cs b/ProjectGSM/Entities/Enums/LicenseType.cs index 6175505..685f926 100644 --- a/ProjectGSM/Entities/Enums/LicenseType.cs +++ b/ProjectGSM/Entities/Enums/LicenseType.cs @@ -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 } -} +} \ No newline at end of file diff --git a/ProjectGSM/Forms/FormAdvocate.cs b/ProjectGSM/Forms/FormAdvocate.cs index c9bba6c..a41a5be 100644 --- a/ProjectGSM/Forms/FormAdvocate.cs +++ b/ProjectGSM/Forms/FormAdvocate.cs @@ -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); } - } -} +} \ No newline at end of file