diff --git a/RouteGuide/RouteGuideContracts/ViewModels/RouteViewModel.cs b/RouteGuide/RouteGuideContracts/ViewModels/RouteViewModel.cs index ebec2c7..c14c42b 100644 --- a/RouteGuide/RouteGuideContracts/ViewModels/RouteViewModel.cs +++ b/RouteGuide/RouteGuideContracts/ViewModels/RouteViewModel.cs @@ -30,6 +30,12 @@ namespace RouteGuideContracts.ViewModels /// public int TransportId { get; set; } + /// + /// Номерной знак транспорта + /// + [DisplayName("Номер транспорта")] + public string TransportLicense { get; set; } = string.Empty; + /// /// Коллекция остановок маршрута /// diff --git a/RouteGuide/RouteGuideContracts/ViewModels/ScheduleViewModel.cs b/RouteGuide/RouteGuideContracts/ViewModels/ScheduleViewModel.cs index 352e020..1c7f3f0 100644 --- a/RouteGuide/RouteGuideContracts/ViewModels/ScheduleViewModel.cs +++ b/RouteGuide/RouteGuideContracts/ViewModels/ScheduleViewModel.cs @@ -47,5 +47,11 @@ namespace RouteGuideContracts.ViewModels /// Идентификатор маршрута /// public int RouteId { get; set; } + + /// + /// Название маршрута + /// + [DisplayName("Маршрут")] + public string RouteName { get; set; } = string.Empty; } } diff --git a/RouteGuide/RouteGuideContracts/ViewModels/StopViewModel.cs b/RouteGuide/RouteGuideContracts/ViewModels/StopViewModel.cs index d5d6c1e..6d4a50a 100644 --- a/RouteGuide/RouteGuideContracts/ViewModels/StopViewModel.cs +++ b/RouteGuide/RouteGuideContracts/ViewModels/StopViewModel.cs @@ -1,4 +1,5 @@ -using System; +using RouteGuideDataModels.Models; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -11,7 +12,7 @@ namespace RouteGuideContracts.ViewModels /// Модель для передачи данных пользователю /// для отображения для остановок /// - public class StopViewModel + public class StopViewModel : IStopModel { /// /// Идентификатор diff --git a/RouteGuide/RouteGuideContracts/ViewModels/TransportViewModel.cs b/RouteGuide/RouteGuideContracts/ViewModels/TransportViewModel.cs index a5b6b32..e8253c8 100644 --- a/RouteGuide/RouteGuideContracts/ViewModels/TransportViewModel.cs +++ b/RouteGuide/RouteGuideContracts/ViewModels/TransportViewModel.cs @@ -42,5 +42,11 @@ namespace RouteGuideContracts.ViewModels /// Идентификатор водителя /// public int DriverId { get; set; } + + /// + /// ФИО водителя + /// + [DisplayName("ФИО водителя")] + public string DriverName { get; set; } = string.Empty; } } diff --git a/RouteGuide/RouteGuideDatabaseImplement/Models/Route.cs b/RouteGuide/RouteGuideDatabaseImplement/Models/Route.cs index db6ce88..a55e5b5 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Models/Route.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Models/Route.cs @@ -112,7 +112,8 @@ namespace RouteGuideDatabaseImplement.Models Id = Id, Name = Name, TransportId = TransportId, - RouteStops = RouteStops + RouteStops = RouteStops, + TransportLicense = Transport.License }; /// diff --git a/RouteGuide/RouteGuideDatabaseImplement/Models/Schedule.cs b/RouteGuide/RouteGuideDatabaseImplement/Models/Schedule.cs index aa31332..429ad58 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Models/Schedule.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Models/Schedule.cs @@ -109,7 +109,8 @@ namespace RouteGuideDatabaseImplement.Models DepartureTime = DepartureTime, ArrivalTime = ArrivalTime, Frequency = Frequency, - RouteId = RouteId + RouteId = RouteId, + RouteName = Route.Name }; } } diff --git a/RouteGuide/RouteGuideDatabaseImplement/Models/Transport.cs b/RouteGuide/RouteGuideDatabaseImplement/Models/Transport.cs index f40b9bf..bfc00e3 100644 --- a/RouteGuide/RouteGuideDatabaseImplement/Models/Transport.cs +++ b/RouteGuide/RouteGuideDatabaseImplement/Models/Transport.cs @@ -99,7 +99,8 @@ namespace RouteGuideDatabaseImplement.Models Id = Id, License = License, Type = Type, - DriverId = DriverId + DriverId = DriverId, + DriverName = Driver.FullName }; } } diff --git a/RouteGuide/RouteGuideView/Form1.Designer.cs b/RouteGuide/RouteGuideView/Form1.Designer.cs deleted file mode 100644 index c9e70d6..0000000 --- a/RouteGuide/RouteGuideView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace RouteGuideView -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/RouteGuide/RouteGuideView/Form1.cs b/RouteGuide/RouteGuideView/Form1.cs deleted file mode 100644 index 4c6ca7c..0000000 --- a/RouteGuide/RouteGuideView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace RouteGuideView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/RouteGuide/RouteGuideView/FormDriver.Designer.cs b/RouteGuide/RouteGuideView/FormDriver.Designer.cs new file mode 100644 index 0000000..af7b6ef --- /dev/null +++ b/RouteGuide/RouteGuideView/FormDriver.Designer.cs @@ -0,0 +1,140 @@ +namespace RouteGuideView +{ + partial class FormDriver + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + textBoxFullName = new TextBox(); + textBoxPhone = new TextBox(); + textBoxExperience = new TextBox(); + labelFullName = new Label(); + labelPhone = new Label(); + labelExperience = new Label(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // textBoxFullName + // + textBoxFullName.Location = new Point(80, 12); + textBoxFullName.Name = "textBoxFullName"; + textBoxFullName.Size = new Size(292, 23); + textBoxFullName.TabIndex = 0; + // + // textBoxPhone + // + textBoxPhone.Location = new Point(80, 41); + textBoxPhone.Name = "textBoxPhone"; + textBoxPhone.Size = new Size(292, 23); + textBoxPhone.TabIndex = 1; + // + // textBoxExperience + // + textBoxExperience.Location = new Point(80, 70); + textBoxExperience.Name = "textBoxExperience"; + textBoxExperience.Size = new Size(292, 23); + textBoxExperience.TabIndex = 2; + // + // labelFullName + // + labelFullName.AutoSize = true; + labelFullName.Location = new Point(12, 15); + labelFullName.Name = "labelFullName"; + labelFullName.Size = new Size(37, 15); + labelFullName.TabIndex = 3; + labelFullName.Text = "ФИО:"; + // + // labelPhone + // + labelPhone.AutoSize = true; + labelPhone.Location = new Point(12, 44); + labelPhone.Name = "labelPhone"; + labelPhone.Size = new Size(58, 15); + labelPhone.TabIndex = 4; + labelPhone.Text = "Телефон:"; + // + // labelExperience + // + labelExperience.AutoSize = true; + labelExperience.Location = new Point(12, 73); + labelExperience.Name = "labelExperience"; + labelExperience.Size = new Size(40, 15); + labelExperience.TabIndex = 5; + labelExperience.Text = "Опыт:"; + // + // buttonCancel + // + buttonCancel.Location = new Point(297, 106); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(216, 106); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // FormDriver + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(384, 141); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(labelExperience); + Controls.Add(labelPhone); + Controls.Add(labelFullName); + Controls.Add(textBoxExperience); + Controls.Add(textBoxPhone); + Controls.Add(textBoxFullName); + Name = "FormDriver"; + Text = "Водитель"; + Load += FormDriver_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxFullName; + private TextBox textBoxPhone; + private TextBox textBoxExperience; + private Label labelFullName; + private Label labelPhone; + private Label labelExperience; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormDriver.cs b/RouteGuide/RouteGuideView/FormDriver.cs new file mode 100644 index 0000000..06e2c70 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormDriver.cs @@ -0,0 +1,141 @@ +using Microsoft.Extensions.Logging; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +using RouteGuideContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RouteGuideView +{ + /// + /// Форма для создания/редактирования водителей + /// + public partial class FormDriver : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика + /// + private readonly IDriverLogic _driverLogic; + + /// + /// Идентификатор + /// + private int? _id; + + /// + /// Идентификатор + /// + public int Id { set { _id = value; } } + + /// + /// Конструктор + /// + public FormDriver(ILogger logger, IDriverLogic driverLogic) + { + InitializeComponent(); + _logger = logger; + _driverLogic = driverLogic; + } + + /// + /// Загрузка информации о сущности + /// + /// + /// + private void FormDriver_Load(object sender, EventArgs e) + { + if (!_id.HasValue) + { + return; + } + + try + { + _logger.LogInformation("Получение сущности 'Водитель'"); + var view = _driverLogic.ReadElement(new DriverSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFullName.Text = view.FullName; + textBoxPhone.Text = view.Phone; + textBoxExperience.Text = view.Experience.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения сущности 'Водитель'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Сохранить" + /// + /// + /// + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxFullName.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPhone.Text)) + { + MessageBox.Show("Заполните номер телефона", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение сущности 'Водитель'"); + try + { + var model = new DriverBindingModel + { + Id = _id ?? 0, + FullName = textBoxFullName.Text, + Phone = textBoxPhone.Text, + Experience = int.TryParse(textBoxExperience.Text, out int experience) ? experience : 0 + }; + + var operationResult = _id.HasValue ? _driverLogic.Update(model) : _driverLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении сущности 'Водитель'. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение сущности 'Водитель' прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения сущности 'Водитель'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Отмена" + /// + /// + /// + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/RouteGuide/RouteGuideView/Form1.resx b/RouteGuide/RouteGuideView/FormDriver.resx similarity index 93% rename from RouteGuide/RouteGuideView/Form1.resx rename to RouteGuide/RouteGuideView/FormDriver.resx index 1af7de1..af32865 100644 --- a/RouteGuide/RouteGuideView/Form1.resx +++ b/RouteGuide/RouteGuideView/FormDriver.resx @@ -1,17 +1,17 @@  - diff --git a/RouteGuide/RouteGuideView/FormDrivers.Designer.cs b/RouteGuide/RouteGuideView/FormDrivers.Designer.cs new file mode 100644 index 0000000..f64af6d --- /dev/null +++ b/RouteGuide/RouteGuideView/FormDrivers.Designer.cs @@ -0,0 +1,121 @@ +namespace RouteGuideView +{ + partial class FormDrivers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonCreate = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(550, 361); + dataGridView.TabIndex = 6; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(585, 99); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(75, 23); + buttonRefresh.TabIndex = 10; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(585, 70); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 9; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(585, 41); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 8; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonCreate + // + buttonCreate.Location = new Point(585, 12); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(75, 23); + buttonCreate.TabIndex = 7; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // FormDrivers + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(684, 361); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonCreate); + Controls.Add(dataGridView); + Name = "FormDrivers"; + Text = "Водители"; + Load += FormDrivers_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonCreate; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormDrivers.cs b/RouteGuide/RouteGuideView/FormDrivers.cs new file mode 100644 index 0000000..441e355 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormDrivers.cs @@ -0,0 +1,151 @@ +using Microsoft.Extensions.Logging; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +using System; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RouteGuideView +{ + /// + /// Форма для вывода списка водителей + /// + public partial class FormDrivers : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика + /// + private readonly IDriverLogic _driverlogic; + + /// + /// Конструктор + /// + public FormDrivers(ILogger logger, IDriverLogic driverLogic) + { + InitializeComponent(); + _logger = logger; + _driverlogic = driverLogic; + } + + /// + /// Загрузка данных + /// + /// + /// + private void FormDrivers_Load(object sender, EventArgs e) + { + LoadData(); + } + + /// + /// Кнопка "Создать" + /// + /// + /// + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDriver)); + if (service is FormDriver form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + /// + /// Кнопка "Изменить" + /// + /// + /// + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDriver)); + if (service is FormDriver form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + /// + /// Кнопка "Удалить" + /// + /// + /// + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление сущности 'Водитель'"); + + try + { + if (!_driverlogic.Delete(new DriverBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении сущности 'Водитель'. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления сущности 'Водитель'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + /// + /// Кнопка "Обновить" + /// + /// + /// + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + + /// + /// Загрузка данных + /// + private void LoadData() + { + try + { + var list = _driverlogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["FullName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка списка водителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка водителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/RouteGuide/RouteGuideView/FormDrivers.resx b/RouteGuide/RouteGuideView/FormDrivers.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormDrivers.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormMain.Designer.cs b/RouteGuide/RouteGuideView/FormMain.Designer.cs new file mode 100644 index 0000000..058cf89 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormMain.Designer.cs @@ -0,0 +1,183 @@ +namespace RouteGuideView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + DrviversToolStripMenuItem = new ToolStripMenuItem(); + TransportToolStripMenuItem = new ToolStripMenuItem(); + RoutesToolStripMenuItem = new ToolStripMenuItem(); + StopsToolStripMenuItem = new ToolStripMenuItem(); + buttonCreate = new Button(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + dataGridView = new DataGridView(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(984, 24); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DrviversToolStripMenuItem, TransportToolStripMenuItem, RoutesToolStripMenuItem, StopsToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(97, 20); + справочникиToolStripMenuItem.Text = " Справочники"; + // + // DrviversToolStripMenuItem + // + DrviversToolStripMenuItem.Name = "DrviversToolStripMenuItem"; + DrviversToolStripMenuItem.Size = new Size(180, 22); + DrviversToolStripMenuItem.Text = "Водители"; + DrviversToolStripMenuItem.Click += DrviversToolStripMenuItem_Click; + // + // TransportToolStripMenuItem + // + TransportToolStripMenuItem.Name = "TransportToolStripMenuItem"; + TransportToolStripMenuItem.Size = new Size(180, 22); + TransportToolStripMenuItem.Text = "Транспорт"; + TransportToolStripMenuItem.Click += TransportToolStripMenuItem_Click; + // + // RoutesToolStripMenuItem + // + RoutesToolStripMenuItem.Name = "RoutesToolStripMenuItem"; + RoutesToolStripMenuItem.Size = new Size(180, 22); + RoutesToolStripMenuItem.Text = "Маршруты"; + RoutesToolStripMenuItem.Click += RoutesToolStripMenuItem_Click; + // + // StopsToolStripMenuItem + // + StopsToolStripMenuItem.Name = "StopsToolStripMenuItem"; + StopsToolStripMenuItem.Size = new Size(180, 22); + StopsToolStripMenuItem.Text = "Остановки"; + StopsToolStripMenuItem.Click += StopsToolStripMenuItem_Click; + // + // buttonCreate + // + buttonCreate.Location = new Point(885, 37); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(75, 23); + buttonCreate.TabIndex = 1; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(885, 66); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 2; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(885, 95); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(885, 124); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(75, 23); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 24); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(850, 337); + dataGridView.TabIndex = 5; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(984, 361); + Controls.Add(dataGridView); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonCreate); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "Расписание"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem DrviversToolStripMenuItem; + private ToolStripMenuItem TransportToolStripMenuItem; + private ToolStripMenuItem RoutesToolStripMenuItem; + private ToolStripMenuItem StopsToolStripMenuItem; + private Button buttonCreate; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + private DataGridView dataGridView; + } +} diff --git a/RouteGuide/RouteGuideView/FormMain.cs b/RouteGuide/RouteGuideView/FormMain.cs new file mode 100644 index 0000000..57253a3 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormMain.cs @@ -0,0 +1,204 @@ +using Microsoft.Extensions.Logging; +using RouteGuideBusinessLogics.BusinessLogics; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; + +namespace RouteGuideView +{ + /// + /// + /// + public partial class FormMain : Form + { + /// + /// + /// + private readonly ILogger _logger; + + /// + /// - + /// + private readonly IScheduleLogic _schedulelogic; + + /// + /// + /// + /// + /// + public FormMain(ILogger logger, IScheduleLogic scheduleLogic) + { + InitializeComponent(); + _logger = logger; + _schedulelogic = scheduleLogic; + } + + /// + /// + /// + /// + /// + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + /// + /// + /// + /// + /// + private void DrviversToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDrivers)); + if (service is FormDrivers form) + { + form.ShowDialog(); + } + } + + /// + /// + /// + /// + /// + private void TransportToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTransports)); + if (service is FormTransports form) + { + form.ShowDialog(); + } + } + + /// + /// + /// + /// + /// + private void RoutesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRoutes)); + if (service is FormRoutes form) + { + form.ShowDialog(); + } + } + + /// + /// + /// + /// + /// + private void StopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStops)); + if (service is FormStops form) + { + form.ShowDialog(); + } + } + + /// + /// "" + /// + /// + /// + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSchedule)); + if (service is FormSchedule form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + /// + /// "" + /// + /// + /// + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSchedule)); + if (service is FormSchedule form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + /// + /// "" + /// + /// + /// + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show(" ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation(" ''"); + + try + { + if (!_schedulelogic.Delete(new ScheduleBindingModel { Id = id })) + { + throw new Exception(" ''. ."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, " ''"); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + /// + /// "" + /// + /// + /// + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + + /// + /// + /// + private void LoadData() + { + try + { + var list = _schedulelogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["RouteId"].Visible = false; + dataGridView.Columns["RouteName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation(" "); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/RouteGuide/RouteGuideView/FormMain.resx b/RouteGuide/RouteGuideView/FormMain.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormRoute.Designer.cs b/RouteGuide/RouteGuideView/FormRoute.Designer.cs new file mode 100644 index 0000000..c704611 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormRoute.Designer.cs @@ -0,0 +1,211 @@ +namespace RouteGuideView +{ + partial class FormRoute + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + textBoxName = new TextBox(); + labelName = new Label(); + groupBox = new GroupBox(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonCreate = new Button(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnNumber = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // textBoxName + // + textBoxName.Location = new Point(80, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(200, 23); + textBoxName.TabIndex = 0; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 15); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 1; + labelName.Text = "Название:"; + // + // groupBox + // + groupBox.Controls.Add(buttonRefresh); + groupBox.Controls.Add(buttonDelete); + groupBox.Controls.Add(buttonUpdate); + groupBox.Controls.Add(buttonCreate); + groupBox.Controls.Add(dataGridView); + groupBox.Location = new Point(12, 41); + groupBox.Name = "groupBox"; + groupBox.Size = new Size(660, 279); + groupBox.TabIndex = 2; + groupBox.TabStop = false; + groupBox.Text = "Остановки"; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(558, 109); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(75, 23); + buttonRefresh.TabIndex = 18; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(558, 80); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 17; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(558, 51); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 16; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonCreate + // + buttonCreate.Location = new Point(558, 22); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(75, 23); + buttonCreate.TabIndex = 15; + buttonCreate.Text = "Добавить"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnNumber }); + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(3, 19); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(530, 257); + dataGridView.TabIndex = 0; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; + ColumnId.Visible = false; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Остановка"; + ColumnName.Name = "ColumnName"; + ColumnName.ReadOnly = true; + // + // ColumnNumber + // + ColumnNumber.HeaderText = "Номер остановки"; + ColumnNumber.Name = "ColumnNumber"; + ColumnNumber.ReadOnly = true; + // + // buttonSave + // + buttonSave.Location = new Point(516, 326); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 9; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(597, 326); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormRoute + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(684, 361); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(groupBox); + Controls.Add(labelName); + Controls.Add(textBoxName); + Name = "FormRoute"; + Text = "Маршрут"; + Load += FormRoute_Load; + groupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxName; + private Label labelName; + private GroupBox groupBox; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonCreate; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnNumber; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormRoute.cs b/RouteGuide/RouteGuideView/FormRoute.cs new file mode 100644 index 0000000..bcd7ef4 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormRoute.cs @@ -0,0 +1,273 @@ +using Microsoft.Extensions.Logging; +using RouteGuideBusinessLogics.BusinessLogics; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +using RouteGuideContracts.SearchModels; +using RouteGuideDataModels.Models; +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 RouteGuideView +{ + /// + /// Форма для создания/редактирования маршрутов + /// + public partial class FormRoute : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика + /// + private readonly IRouteLogic _routeLogic; + + /// + /// Идентификатор + /// + private int? _id; + + /// + /// Идентификатор + /// + public int Id { set { _id = value; } } + + /// + /// Список остановок в маршруте + /// + private Dictionary _routeStops; + + /// + /// Конструктор + /// + /// + /// + public FormRoute(ILogger logger, IRouteLogic routeLogic) + { + InitializeComponent(); + _logger = logger; + _routeLogic = routeLogic; + _routeStops = new Dictionary(); + } + + /// + /// Загрузка данных + /// + /// + /// + private void FormRoute_Load(object sender, EventArgs e) + { + if (!_id.HasValue) + { + return; + } + + try + { + _logger.LogInformation("Получение сущности 'Маршрут'"); + var view = _routeLogic.ReadElement(new RouteSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.Name; + _routeStops = view.RouteStops ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения сущности 'Маршрут'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Добавить" + /// + /// + /// + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRouteStop)); + if (service is FormRouteStop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.StopModel == null) + { + return; + } + + _logger.LogInformation("Добавление остановки.{Id}: {StopName} в маршрут на позицию {Number}", form.Id, form.StopModel.Name, form.Number); + if (_routeStops.ContainsKey(form.Id)) + { + _routeStops[form.Id] = (form.StopModel, form.Number); + } + else + { + _routeStops.Add(form.Id, (form.StopModel, form.Number)); + } + LoadData(); + } + } + } + + /// + /// Кнопка "Изменить" + /// + /// + /// + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRouteStop)); + if (service is FormRouteStop form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Number = _routeStops[id].Item2; + + if (form.ShowDialog() == DialogResult.OK) + { + if (form.StopModel == null) + { + return; + } + + _logger.LogInformation("Изменение остановки.{Id}: {StopName} в маршруте на позиции {Number}", form.Id, form.StopModel.Name, form.Number); + _routeStops[form.Id] = (form.StopModel, form.Number); + LoadData(); + } + } + } + } + + /// + /// Кнопка "Удалить" + /// + /// + /// + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление остановки.{Id}: {StopName} с позиции в маршруте {Number}", dataGridView.SelectedRows[0].Cells[0].Value, dataGridView.SelectedRows[0].Cells[1].Value, dataGridView.SelectedRows[0].Cells[2].Value); + _routeStops.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления остановки.{Id}: {StopName} с позиции в маршруте {Number}", dataGridView.SelectedRows[0].Cells[0].Value, dataGridView.SelectedRows[0].Cells[1].Value, dataGridView.SelectedRows[0].Cells[2].Value); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + /// + /// Кнопка "Обновить" + /// + /// + /// + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + + /// + /// Кнопка "Сохранить" + /// + /// + /// + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название маршрута", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение сущности 'Маршрут'"); + try + { + var model = new RouteBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text, + RouteStops = _routeStops + }; + + var operationResult = _id.HasValue ? _routeLogic.Update(model) : _routeLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении сущности 'Маршрут'. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение сущности 'Маршрут' прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения сущности 'Маршрут'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Отмена" + /// + /// + /// + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + /// + /// Загрузка данных + /// + private void LoadData() + { + _logger.LogInformation("Загрузка списка остановок в маршруте"); + try + { + if (_routeStops != null) + { + dataGridView.Rows.Clear(); + foreach (var rs in _routeStops) + { + dataGridView.Rows.Add(new object[] + { + rs.Key, + rs.Value.Item1.Name, + rs.Value.Item2 + }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка остановок в маршруте"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/RouteGuide/RouteGuideView/FormRoute.resx b/RouteGuide/RouteGuideView/FormRoute.resx new file mode 100644 index 0000000..64451e7 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormRoute.resx @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormRouteStop.Designer.cs b/RouteGuide/RouteGuideView/FormRouteStop.Designer.cs new file mode 100644 index 0000000..55479d3 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormRouteStop.Designer.cs @@ -0,0 +1,118 @@ +namespace RouteGuideView +{ + partial class FormRouteStop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + comboBoxStop = new ComboBox(); + textBoxNumber = new TextBox(); + labelStop = new Label(); + labelNumber = new Label(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // comboBoxStop + // + comboBoxStop.FormattingEnabled = true; + comboBoxStop.Location = new Point(80, 7); + comboBoxStop.Name = "comboBoxStop"; + comboBoxStop.Size = new Size(292, 23); + comboBoxStop.TabIndex = 0; + // + // textBoxNumber + // + textBoxNumber.Location = new Point(80, 41); + textBoxNumber.Name = "textBoxNumber"; + textBoxNumber.Size = new Size(292, 23); + textBoxNumber.TabIndex = 1; + // + // labelStop + // + labelStop.AutoSize = true; + labelStop.Location = new Point(12, 15); + labelStop.Name = "labelStop"; + labelStop.Size = new Size(68, 15); + labelStop.TabIndex = 2; + labelStop.Text = "Остановка:"; + // + // labelNumber + // + labelNumber.AutoSize = true; + labelNumber.Location = new Point(12, 44); + labelNumber.Name = "labelNumber"; + labelNumber.Size = new Size(48, 15); + labelNumber.TabIndex = 3; + labelNumber.Text = "Номер:"; + // + // buttonCancel + // + buttonCancel.Location = new Point(297, 76); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(216, 76); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // FormRouteStop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(384, 111); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(labelNumber); + Controls.Add(labelStop); + Controls.Add(textBoxNumber); + Controls.Add(comboBoxStop); + Name = "FormRouteStop"; + Text = "Остановка маршрута"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxStop; + private TextBox textBoxNumber; + private Label labelStop; + private Label labelNumber; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormRouteStop.cs b/RouteGuide/RouteGuideView/FormRouteStop.cs new file mode 100644 index 0000000..9370a0c --- /dev/null +++ b/RouteGuide/RouteGuideView/FormRouteStop.cs @@ -0,0 +1,124 @@ +using RouteGuideContracts.BusinessLogicsContracts; +using RouteGuideContracts.ViewModels; +using RouteGuideDataModels.Models; +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 RouteGuideView +{ + /// + /// Форма для привязки остановки к маршруту + /// + public partial class FormRouteStop : Form + { + /// + /// Список остановок + /// + private readonly List? _list; + + /// + /// Идентификатор остановки + /// + public int Id + { + get + { + return Convert.ToInt32(comboBoxStop.SelectedValue); + } + set + { + comboBoxStop.SelectedValue = value; + } + } + + /// + /// Сущность "Остановка" + /// + public IStopModel? StopModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + + /// + /// Номер остановки в маршруте + /// + public int Number + { + get { return Convert.ToInt32(textBoxNumber.Text); } + set { textBoxNumber.Text = value.ToString(); } + } + + /// + /// Конструктор + /// + /// + public FormRouteStop(IStopLogic stopLogic) + { + InitializeComponent(); + + // Загрузка списка остановок для ComboBoxStop + _list = stopLogic.ReadList(null); + if (_list != null) + { + comboBoxStop.DisplayMember = "Name"; + comboBoxStop.ValueMember = "Id"; + comboBoxStop.DataSource = _list; + comboBoxStop.SelectedItem = null; + } + } + + /// + /// Кнопка "Сохранить" + /// + /// + /// + private void buttonSave_Click(object sender, EventArgs e) + { + if (comboBoxStop.SelectedValue == null) + { + MessageBox.Show("Выберите остановку", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxNumber.Text)) + { + MessageBox.Show("Заполните номер остановки", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + DialogResult = DialogResult.OK; + Close(); + } + + /// + /// Кнопка "Отмена" + /// + /// + /// + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/RouteGuide/RouteGuideView/FormRouteStop.resx b/RouteGuide/RouteGuideView/FormRouteStop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormRouteStop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormRoutes.Designer.cs b/RouteGuide/RouteGuideView/FormRoutes.Designer.cs new file mode 100644 index 0000000..c0833e1 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormRoutes.Designer.cs @@ -0,0 +1,121 @@ +namespace RouteGuideView +{ + partial class FormRoutes + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonCreate = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(550, 361); + dataGridView.TabIndex = 7; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(585, 99); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(75, 23); + buttonRefresh.TabIndex = 14; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(585, 70); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 13; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(585, 41); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 12; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonCreate + // + buttonCreate.Location = new Point(585, 12); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(75, 23); + buttonCreate.TabIndex = 11; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // FormRoutes + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(684, 361); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonCreate); + Controls.Add(dataGridView); + Name = "FormRoutes"; + Text = "Маршруты"; + Load += FormRoutes_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonCreate; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormRoutes.cs b/RouteGuide/RouteGuideView/FormRoutes.cs new file mode 100644 index 0000000..f37b0b1 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormRoutes.cs @@ -0,0 +1,155 @@ +using Microsoft.Extensions.Logging; +using RouteGuideBusinessLogics.BusinessLogics; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +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 RouteGuideView +{ + /// + /// Форма для вывода списка маршрутов + /// + public partial class FormRoutes : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика + /// + private readonly IRouteLogic _routelogic; + + /// + /// Конструктор + /// + public FormRoutes(ILogger logger, IRouteLogic routeLogic) + { + InitializeComponent(); + _logger = logger; + _routelogic = routeLogic; + } + + /// + /// Загрузка данных + /// + /// + /// + private void FormRoutes_Load(object sender, EventArgs e) + { + LoadData(); + } + + /// + /// Кнопка "Создать" + /// + /// + /// + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRoute)); + if (service is FormRoute form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + /// + /// Кнопка "Изменить" + /// + /// + /// + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRoute)); + if (service is FormRoute form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + /// + /// Кнопка "Удалить" + /// + /// + /// + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление сущности 'Маршрут'"); + + try + { + if (!_routelogic.Delete(new RouteBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении сущности 'Маршрут'. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления сущности 'Маршрут'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + /// + /// Кнопка "Обновить" + /// + /// + /// + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + + /// + /// Загрузка данных + /// + private void LoadData() + { + try + { + var list = _routelogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["RouteStops"].Visible = false; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка списка маршрутов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка маршрутов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/RouteGuide/RouteGuideView/FormRoutes.resx b/RouteGuide/RouteGuideView/FormRoutes.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormRoutes.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormSchedule.Designer.cs b/RouteGuide/RouteGuideView/FormSchedule.Designer.cs new file mode 100644 index 0000000..d6929ff --- /dev/null +++ b/RouteGuide/RouteGuideView/FormSchedule.Designer.cs @@ -0,0 +1,189 @@ +namespace RouteGuideView +{ + partial class FormSchedule + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dateTimePickerDate = new DateTimePicker(); + dateTimePickerDepartureTime = new DateTimePicker(); + dateTimePickerArrivalTime = new DateTimePicker(); + dateTimePickerFrequency = new DateTimePicker(); + comboBoxRoute = new ComboBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + labelRoute = new Label(); + labelDate = new Label(); + labelDeparture = new Label(); + labelArrival = new Label(); + labelFrequency = new Label(); + SuspendLayout(); + // + // dateTimePickerDate + // + dateTimePickerDate.Location = new Point(101, 41); + dateTimePickerDate.Name = "dateTimePickerDate"; + dateTimePickerDate.Size = new Size(271, 23); + dateTimePickerDate.TabIndex = 0; + // + // dateTimePickerDepartureTime + // + dateTimePickerDepartureTime.Format = DateTimePickerFormat.Time; + dateTimePickerDepartureTime.Location = new Point(101, 70); + dateTimePickerDepartureTime.Name = "dateTimePickerDepartureTime"; + dateTimePickerDepartureTime.Size = new Size(271, 23); + dateTimePickerDepartureTime.TabIndex = 1; + // + // dateTimePickerArrivalTime + // + dateTimePickerArrivalTime.Format = DateTimePickerFormat.Time; + dateTimePickerArrivalTime.Location = new Point(101, 99); + dateTimePickerArrivalTime.Name = "dateTimePickerArrivalTime"; + dateTimePickerArrivalTime.Size = new Size(271, 23); + dateTimePickerArrivalTime.TabIndex = 2; + // + // dateTimePickerFrequency + // + dateTimePickerFrequency.Format = DateTimePickerFormat.Time; + dateTimePickerFrequency.Location = new Point(101, 128); + dateTimePickerFrequency.Name = "dateTimePickerFrequency"; + dateTimePickerFrequency.Size = new Size(271, 23); + dateTimePickerFrequency.TabIndex = 3; + // + // comboBoxRoute + // + comboBoxRoute.FormattingEnabled = true; + comboBoxRoute.Location = new Point(101, 12); + comboBoxRoute.Name = "comboBoxRoute"; + comboBoxRoute.Size = new Size(271, 23); + comboBoxRoute.TabIndex = 4; + // + // buttonSave + // + buttonSave.Location = new Point(216, 164); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(297, 164); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // labelRoute + // + labelRoute.AutoSize = true; + labelRoute.Location = new Point(12, 15); + labelRoute.Name = "labelRoute"; + labelRoute.Size = new Size(63, 15); + labelRoute.TabIndex = 8; + labelRoute.Text = "Маршрут:"; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(12, 47); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(35, 15); + labelDate.TabIndex = 9; + labelDate.Text = "Дата:"; + // + // labelDeparture + // + labelDeparture.AutoSize = true; + labelDeparture.Location = new Point(12, 76); + labelDeparture.Name = "labelDeparture"; + labelDeparture.Size = new Size(83, 15); + labelDeparture.TabIndex = 10; + labelDeparture.Text = "Отправление:"; + // + // labelArrival + // + labelArrival.AutoSize = true; + labelArrival.Location = new Point(12, 105); + labelArrival.Name = "labelArrival"; + labelArrival.Size = new Size(67, 15); + labelArrival.TabIndex = 11; + labelArrival.Text = "Прибытие:"; + // + // labelFrequency + // + labelFrequency.AutoSize = true; + labelFrequency.Font = new Font("Segoe UI", 8.25F, FontStyle.Regular, GraphicsUnit.Point); + labelFrequency.Location = new Point(12, 135); + labelFrequency.Name = "labelFrequency"; + labelFrequency.Size = new Size(95, 13); + labelFrequency.TabIndex = 12; + labelFrequency.Text = "Периодичность:"; + // + // FormSchedule + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(384, 200); + Controls.Add(labelFrequency); + Controls.Add(labelArrival); + Controls.Add(labelDeparture); + Controls.Add(labelDate); + Controls.Add(labelRoute); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(comboBoxRoute); + Controls.Add(dateTimePickerFrequency); + Controls.Add(dateTimePickerArrivalTime); + Controls.Add(dateTimePickerDepartureTime); + Controls.Add(dateTimePickerDate); + Name = "FormSchedule"; + Text = "Расписание"; + Load += FormSchedule_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DateTimePicker dateTimePickerDate; + private DateTimePicker dateTimePickerDepartureTime; + private DateTimePicker dateTimePickerArrivalTime; + private DateTimePicker dateTimePickerFrequency; + private ComboBox comboBoxRoute; + private Button buttonSave; + private Button buttonCancel; + private Label labelRoute; + private Label labelDate; + private Label labelDeparture; + private Label labelArrival; + private Label labelFrequency; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormSchedule.cs b/RouteGuide/RouteGuideView/FormSchedule.cs new file mode 100644 index 0000000..0f2398d --- /dev/null +++ b/RouteGuide/RouteGuideView/FormSchedule.cs @@ -0,0 +1,176 @@ +using Microsoft.Extensions.Logging; +using RouteGuideBusinessLogics.BusinessLogics; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +using RouteGuideContracts.SearchModels; +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 RouteGuideView +{ + /// + /// Форма для создания/редактирования расписания + /// + public partial class FormSchedule : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика для расписаний + /// + private readonly IScheduleLogic _scheduleLogic; + + /// + /// Бизнес-логика для маршрутов + /// + private readonly IRouteLogic _routeLogic; + + /// + /// Идентификатор + /// + private int? _id; + + /// + /// Идентификатор + /// + public int Id { set { _id = value; } } + + /// + /// Констурктор + /// + /// + /// + /// + public FormSchedule(ILogger logger, IScheduleLogic scheduleLogic, IRouteLogic routeLogic) + { + InitializeComponent(); + _logger = logger; + _scheduleLogic = scheduleLogic; + _routeLogic = routeLogic; + } + + /// + /// Загрузка данных + /// + /// + /// + private void FormSchedule_Load(object sender, EventArgs e) + { + try + { + // Загрузка маршрутов для ComboBoxRoute + _logger.LogInformation("Загрузка списка маршрутов"); + var list = _routeLogic.ReadList(null); + if (list != null) + { + comboBoxRoute.DisplayMember = "Name"; + comboBoxRoute.ValueMember = "Id"; + comboBoxRoute.DataSource = list; + comboBoxRoute.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка маршрутов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + if (!_id.HasValue) + { + return; + } + + try + { + // Заполнение полей + _logger.LogInformation("Получение сущности 'Расписание'"); + var view = _scheduleLogic.ReadElement(new ScheduleSearchModel + { + Id = _id.Value + }); + if (view != null) + { + comboBoxRoute.SelectedItem = view.RouteId; + dateTimePickerDate.Value = view.Date; + dateTimePickerDepartureTime.Value = view.DepartureTime; + dateTimePickerArrivalTime.Value = view.ArrivalTime; + dateTimePickerFrequency.Value = view.Frequency; + } + } + catch (Exception ex1) + { + _logger.LogError(ex1, "Ошибка получения сущности 'Расписание'"); + MessageBox.Show(ex1.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Сохранить" + /// + /// + /// + private void buttonSave_Click(object sender, EventArgs e) + { + if (comboBoxRoute.SelectedValue == null) + { + MessageBox.Show("Выберите маршрут", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (dateTimePickerDepartureTime.Value >= dateTimePickerArrivalTime.Value) + { + MessageBox.Show("Время прибытия должно опережать время отправления", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение сущности 'Расписание'"); + try + { + var model = new ScheduleBindingModel + { + Id = _id ?? 0, + Date = dateTimePickerDate.Value, + DepartureTime = dateTimePickerDepartureTime.Value, + ArrivalTime = dateTimePickerArrivalTime.Value, + Frequency = dateTimePickerFrequency.Value, + RouteId = Convert.ToInt32(comboBoxRoute.SelectedValue) + }; + + var operationResult = _id.HasValue ? _scheduleLogic.Update(model) : _scheduleLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении сущности 'Расписание'. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение сущности 'Расписание' прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения сущности 'Расписание'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Отмена" + /// + /// + /// + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/RouteGuide/RouteGuideView/FormSchedule.resx b/RouteGuide/RouteGuideView/FormSchedule.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormSchedule.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormStop.Designer.cs b/RouteGuide/RouteGuideView/FormStop.Designer.cs new file mode 100644 index 0000000..4835470 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormStop.Designer.cs @@ -0,0 +1,140 @@ +namespace RouteGuideView +{ + partial class FormStop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonSave = new Button(); + buttonCancel = new Button(); + labelNumber = new Label(); + labelStreet = new Label(); + labelFullName = new Label(); + textBoxNumber = new TextBox(); + textBoxStreet = new TextBox(); + textBoxName = new TextBox(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Location = new Point(216, 106); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 15; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(297, 106); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 14; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // labelNumber + // + labelNumber.AutoSize = true; + labelNumber.Location = new Point(12, 73); + labelNumber.Name = "labelNumber"; + labelNumber.Size = new Size(34, 15); + labelNumber.TabIndex = 13; + labelNumber.Text = "Дом:"; + // + // labelStreet + // + labelStreet.AutoSize = true; + labelStreet.Location = new Point(12, 44); + labelStreet.Name = "labelStreet"; + labelStreet.Size = new Size(44, 15); + labelStreet.TabIndex = 12; + labelStreet.Text = "Улица:"; + // + // labelFullName + // + labelFullName.AutoSize = true; + labelFullName.Location = new Point(12, 15); + labelFullName.Name = "labelFullName"; + labelFullName.Size = new Size(62, 15); + labelFullName.TabIndex = 11; + labelFullName.Text = "Название:"; + // + // textBoxNumber + // + textBoxNumber.Location = new Point(80, 70); + textBoxNumber.Name = "textBoxNumber"; + textBoxNumber.Size = new Size(292, 23); + textBoxNumber.TabIndex = 10; + // + // textBoxStreet + // + textBoxStreet.Location = new Point(80, 41); + textBoxStreet.Name = "textBoxStreet"; + textBoxStreet.Size = new Size(292, 23); + textBoxStreet.TabIndex = 9; + // + // textBoxName + // + textBoxName.Location = new Point(80, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(292, 23); + textBoxName.TabIndex = 8; + // + // FormStop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(384, 141); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(labelNumber); + Controls.Add(labelStreet); + Controls.Add(labelFullName); + Controls.Add(textBoxNumber); + Controls.Add(textBoxStreet); + Controls.Add(textBoxName); + Name = "FormStop"; + Text = "Остановка"; + Load += FormStop_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label labelNumber; + private Label labelStreet; + private Label labelFullName; + private TextBox textBoxNumber; + private TextBox textBoxStreet; + private TextBox textBoxName; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormStop.cs b/RouteGuide/RouteGuideView/FormStop.cs new file mode 100644 index 0000000..a22c5d2 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormStop.cs @@ -0,0 +1,148 @@ +using Microsoft.Extensions.Logging; +using RouteGuideBusinessLogics.BusinessLogics; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +using RouteGuideContracts.SearchModels; +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 RouteGuideView +{ + /// + /// Форма для создания/редактирования остановок + /// + public partial class FormStop : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика + /// + private readonly IStopLogic _stopLogic; + + /// + /// Идентификатор + /// + private int? _id; + + /// + /// Идентификатор + /// + public int Id { set { _id = value; } } + + /// + /// Конструктор + /// + public FormStop(ILogger logger, IStopLogic stopLogic) + { + InitializeComponent(); + _logger = logger; + _stopLogic = stopLogic; + } + + /// + /// Загрузка информации о сущности + /// + /// + /// + private void FormStop_Load(object sender, EventArgs e) + { + if (!_id.HasValue) + { + return; + } + + try + { + _logger.LogInformation("Получение сущности 'Остановка'"); + var view = _stopLogic.ReadElement(new StopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.Name; + textBoxStreet.Text = view.Street; + textBoxNumber.Text = view.Number.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения сущности 'Остановка'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Сохранить" + /// + /// + /// + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название остановки", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxStreet.Text)) + { + MessageBox.Show("Заполните название улицы", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxNumber.Text)) + { + MessageBox.Show("Заполните номер дома", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение сущности 'Остановка'"); + try + { + var model = new StopBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text, + Street = textBoxStreet.Text, + Number = int.TryParse(textBoxNumber.Text, out int number) ? number : 1 + }; + + var operationResult = _id.HasValue ? _stopLogic.Update(model) : _stopLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении сущности 'Остановка'. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение сущности 'Остановка' прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения сущности 'Остановка'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Отмена" + /// + /// + /// + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/RouteGuide/RouteGuideView/FormStop.resx b/RouteGuide/RouteGuideView/FormStop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormStop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormStops.Designer.cs b/RouteGuide/RouteGuideView/FormStops.Designer.cs new file mode 100644 index 0000000..7116cbf --- /dev/null +++ b/RouteGuide/RouteGuideView/FormStops.Designer.cs @@ -0,0 +1,121 @@ +namespace RouteGuideView +{ + partial class FormStops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonCreate = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(550, 361); + dataGridView.TabIndex = 7; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(585, 99); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(75, 23); + buttonRefresh.TabIndex = 14; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(585, 70); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 13; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(585, 41); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 12; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonCreate + // + buttonCreate.Location = new Point(585, 12); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(75, 23); + buttonCreate.TabIndex = 11; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // FormStops + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(684, 361); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonCreate); + Controls.Add(dataGridView); + Name = "FormStops"; + Text = "Остановки"; + Load += FormStops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonCreate; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormStops.cs b/RouteGuide/RouteGuideView/FormStops.cs new file mode 100644 index 0000000..28e28aa --- /dev/null +++ b/RouteGuide/RouteGuideView/FormStops.cs @@ -0,0 +1,153 @@ +using Microsoft.Extensions.Logging; +using RouteGuideBusinessLogics.BusinessLogics; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +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 RouteGuideView +{ + /// + /// Форма для вывода списка остановок + /// + public partial class FormStops : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика + /// + private readonly IStopLogic _stoplogic; + + /// + /// Конструктор + /// + public FormStops(ILogger logger, IStopLogic stopLogic) + { + InitializeComponent(); + _logger = logger; + _stoplogic = stopLogic; + } + + /// + /// Загрузка данных + /// + /// + /// + private void FormStops_Load(object sender, EventArgs e) + { + LoadData(); + } + + /// + /// Кнопка "Создать" + /// + /// + /// + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStop)); + if (service is FormStop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + /// + /// Кнопка "Изменить" + /// + /// + /// + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStop)); + if (service is FormStop form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + /// + /// + /// + /// + /// + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление сущности 'Остановка'"); + + try + { + if (!_stoplogic.Delete(new StopBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении сущности 'Остановка'. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления сущности 'Остановка'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + /// + /// Кнопка "Обновить" + /// + /// + /// + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + + /// + /// Загрузка данных + /// + private void LoadData() + { + try + { + var list = _stoplogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + } + _logger.LogInformation("Загрузка списка остановок"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка остановок"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/RouteGuide/RouteGuideView/FormStops.resx b/RouteGuide/RouteGuideView/FormStops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormStops.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormTransport.Designer.cs b/RouteGuide/RouteGuideView/FormTransport.Designer.cs new file mode 100644 index 0000000..95fba38 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormTransport.Designer.cs @@ -0,0 +1,164 @@ +namespace RouteGuideView +{ + partial class FormTransport + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + comboBoxType = new ComboBox(); + comboBoxDriver = new ComboBox(); + textBoxLicense = new TextBox(); + textBoxCapacity = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + labelType = new Label(); + labelDriver = new Label(); + labelLicense = new Label(); + labelCapacity = new Label(); + SuspendLayout(); + // + // comboBoxType + // + comboBoxType.FormattingEnabled = true; + comboBoxType.Location = new Point(101, 12); + comboBoxType.Name = "comboBoxType"; + comboBoxType.Size = new Size(271, 23); + comboBoxType.TabIndex = 0; + // + // comboBoxDriver + // + comboBoxDriver.FormattingEnabled = true; + comboBoxDriver.Location = new Point(101, 41); + comboBoxDriver.Name = "comboBoxDriver"; + comboBoxDriver.Size = new Size(271, 23); + comboBoxDriver.TabIndex = 1; + // + // textBoxLicense + // + textBoxLicense.Location = new Point(101, 70); + textBoxLicense.Name = "textBoxLicense"; + textBoxLicense.Size = new Size(271, 23); + textBoxLicense.TabIndex = 2; + // + // textBoxCapacity + // + textBoxCapacity.Location = new Point(101, 99); + textBoxCapacity.Name = "textBoxCapacity"; + textBoxCapacity.Size = new Size(271, 23); + textBoxCapacity.TabIndex = 3; + // + // buttonCancel + // + buttonCancel.Location = new Point(297, 135); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(216, 135); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // labelType + // + labelType.AutoSize = true; + labelType.Location = new Point(12, 15); + labelType.Name = "labelType"; + labelType.Size = new Size(30, 15); + labelType.TabIndex = 6; + labelType.Text = "Тип:"; + // + // labelDriver + // + labelDriver.AutoSize = true; + labelDriver.Location = new Point(12, 44); + labelDriver.Name = "labelDriver"; + labelDriver.Size = new Size(61, 15); + labelDriver.TabIndex = 7; + labelDriver.Text = "Водитель:"; + // + // labelLicense + // + labelLicense.AutoSize = true; + labelLicense.Location = new Point(12, 73); + labelLicense.Name = "labelLicense"; + labelLicense.Size = new Size(48, 15); + labelLicense.TabIndex = 8; + labelLicense.Text = "Номер:"; + // + // labelCapacity + // + labelCapacity.AutoSize = true; + labelCapacity.Location = new Point(12, 102); + labelCapacity.Name = "labelCapacity"; + labelCapacity.Size = new Size(83, 15); + labelCapacity.TabIndex = 9; + labelCapacity.Text = "Вместимость:"; + // + // FormTransport + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(384, 171); + Controls.Add(labelCapacity); + Controls.Add(labelLicense); + Controls.Add(labelDriver); + Controls.Add(labelType); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxCapacity); + Controls.Add(textBoxLicense); + Controls.Add(comboBoxDriver); + Controls.Add(comboBoxType); + Name = "FormTransport"; + Text = "FormTransport"; + Load += FormTransport_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxType; + private ComboBox comboBoxDriver; + private TextBox textBoxLicense; + private TextBox textBoxCapacity; + private Button buttonCancel; + private Button buttonSave; + private Label labelType; + private Label labelDriver; + private Label labelLicense; + private Label labelCapacity; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormTransport.cs b/RouteGuide/RouteGuideView/FormTransport.cs new file mode 100644 index 0000000..253b0b6 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormTransport.cs @@ -0,0 +1,191 @@ +using Microsoft.Extensions.Logging; +using RouteGuideBusinessLogics.BusinessLogics; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +using RouteGuideContracts.SearchModels; +using RouteGuideDataModels.Enums; +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 RouteGuideView +{ + /// + /// Форма для создания/редактирования транспорта + /// + public partial class FormTransport : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика для транспорта + /// + private readonly ITransportLogic _transportLogic; + + /// + /// Бизнес-логика для водителей + /// + private readonly IDriverLogic _driverLogic; + + /// + /// Идентификатор + /// + private int? _id; + + /// + /// Идентификатор + /// + public int Id { set { _id = value; } } + + /// + /// Конструктор + /// + /// + /// + /// + public FormTransport(ILogger logger, ITransportLogic transportLogic, IDriverLogic driverLogic) + { + InitializeComponent(); + _logger = logger; + _transportLogic = transportLogic; + _driverLogic = driverLogic; + } + + /// + /// Загрузка данных + /// + /// + /// + private void FormTransport_Load(object sender, EventArgs e) + { + // Загрузка типов транспорта для ComboBoxType + foreach (TransportType type in Enum.GetValues(typeof(TransportType))) + { + comboBoxType.Items.Add(type); + } + + try + { + // Загрузка водителей для ComboBoxDriver + _logger.LogInformation("Загрузка списка водителей"); + var list = _driverLogic.ReadList(null); + if (list != null) + { + comboBoxDriver.DisplayMember = "FullName"; + comboBoxDriver.ValueMember = "Id"; + comboBoxDriver.DataSource = list; + comboBoxDriver.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка водителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + if (!_id.HasValue) + { + return; + } + + try + { + // Заполнение полей + _logger.LogInformation("Получение сущности 'Транспорт'"); + var view = _transportLogic.ReadElement(new TransportSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxLicense.Text = view.License; + textBoxCapacity.Text = view.Capacity.ToString(); + comboBoxDriver.SelectedItem = view.DriverId; + comboBoxType.SelectedItem = view.Type; + } + } + catch (Exception ex1) + { + _logger.LogError(ex1, "Ошибка получения сущности 'Водитель'"); + MessageBox.Show(ex1.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Сохранить" + /// + /// + /// + private void buttonSave_Click(object sender, EventArgs e) + { + if (comboBoxType.SelectedValue == null) + { + MessageBox.Show("Выберите тип транспорта", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxDriver.SelectedValue == null) + { + MessageBox.Show("Выберите водителя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxLicense.Text)) + { + MessageBox.Show("Заполните номер транспорта", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCapacity.Text)) + { + MessageBox.Show("Заполните вместимость", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение сущности 'Транспорт'"); + try + { + var model = new TransportBindingModel + { + Id = _id ?? 0, + License = textBoxLicense.Text, + Type = (TransportType)comboBoxType.SelectedValue, + Capacity = int.TryParse(textBoxCapacity.Text, out var capacity) ? capacity : 1, + DriverId = Convert.ToInt32(comboBoxDriver.SelectedValue) + }; + + var operationResult = _id.HasValue ? _transportLogic.Update(model) : _transportLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении сущности 'Транспорт'. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение сущности 'Транспорт' прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения сущности 'Транспорт'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Отмена" + /// + /// + /// + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/RouteGuide/RouteGuideView/FormTransport.resx b/RouteGuide/RouteGuideView/FormTransport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormTransport.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormTransports.Designer.cs b/RouteGuide/RouteGuideView/FormTransports.Designer.cs new file mode 100644 index 0000000..6601692 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormTransports.Designer.cs @@ -0,0 +1,121 @@ +namespace RouteGuideView +{ + partial class FormTransports + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonCreate = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(550, 361); + dataGridView.TabIndex = 7; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(585, 99); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(75, 23); + buttonRefresh.TabIndex = 14; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(585, 70); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 13; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(585, 41); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 12; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonCreate + // + buttonCreate.Location = new Point(585, 12); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(75, 23); + buttonCreate.TabIndex = 11; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // FormTransports + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(684, 361); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonCreate); + Controls.Add(dataGridView); + Name = "FormTransports"; + Text = "Транспорт"; + Load += FormTransports_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonCreate; + } +} \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/FormTransports.cs b/RouteGuide/RouteGuideView/FormTransports.cs new file mode 100644 index 0000000..e3df11d --- /dev/null +++ b/RouteGuide/RouteGuideView/FormTransports.cs @@ -0,0 +1,154 @@ +using Microsoft.Extensions.Logging; +using RouteGuideBusinessLogics.BusinessLogics; +using RouteGuideContracts.BindingModels; +using RouteGuideContracts.BusinessLogicsContracts; +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 RouteGuideView +{ + /// + /// Форма для вывода списка транспорта + /// + public partial class FormTransports : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика + /// + private readonly ITransportLogic _transportlogic; + + /// + /// Конструктор + /// + public FormTransports(ILogger logger, ITransportLogic transportLogic) + { + InitializeComponent(); + _logger = logger; + _transportlogic = transportLogic; + } + + /// + /// Загрузка данных + /// + /// + /// + private void FormTransports_Load(object sender, EventArgs e) + { + LoadData(); + } + + /// + /// Кнопка "Создать" + /// + /// + /// + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTransport)); + if (service is FormTransport form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + /// + /// Кнопка "Изменить" + /// + /// + /// + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTransport)); + if (service is FormTransport form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + /// + /// Кнопка "Удалить" + /// + /// + /// + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление сущности 'Транспорт'"); + + try + { + if (!_transportlogic.Delete(new TransportBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении сущности 'Транспорт'. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления сущности 'Транспорт'"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + /// + /// Кнопка "Обновить" + /// + /// + /// + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + + /// + /// Загрузка данных + /// + private void LoadData() + { + try + { + var list = _transportlogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["DriverId"].Visible = false; + } + _logger.LogInformation("Загрузка списка транспорта"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка транспорта"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/RouteGuide/RouteGuideView/FormTransports.resx b/RouteGuide/RouteGuideView/FormTransports.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RouteGuide/RouteGuideView/FormTransports.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/Program.cs b/RouteGuide/RouteGuideView/Program.cs index 4e47056..9b96d03 100644 --- a/RouteGuide/RouteGuideView/Program.cs +++ b/RouteGuide/RouteGuideView/Program.cs @@ -1,7 +1,21 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using RouteGuideBusinessLogics.BusinessLogics; +using RouteGuideContracts.BusinessLogicsContracts; +using RouteGuideContracts.StoragesContracts; +using RouteGuideDatabaseImplement.Implements; + namespace RouteGuideView { internal static class Program { + /// + /// IoC- + /// + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -11,7 +25,53 @@ namespace RouteGuideView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + + Application.Run(_serviceProvider.GetRequiredService()); + } + + /// + /// + /// + /// + private static void ConfigureServices(ServiceCollection services) + { + // + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + + // IoC-, + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + // IoC-, - + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + // IoC-, + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/RouteGuideView.csproj b/RouteGuide/RouteGuideView/RouteGuideView.csproj index 508eab8..64da0a9 100644 --- a/RouteGuide/RouteGuideView/RouteGuideView.csproj +++ b/RouteGuide/RouteGuideView/RouteGuideView.csproj @@ -9,9 +9,29 @@ + + + + + + Always + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + \ No newline at end of file diff --git a/RouteGuide/RouteGuideView/nlog.config b/RouteGuide/RouteGuideView/nlog.config new file mode 100644 index 0000000..bf280eb --- /dev/null +++ b/RouteGuide/RouteGuideView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file