From e2d291b861897e3991cc739baf581515666ecb15 Mon Sep 17 00:00:00 2001 From: cyxaruk Date: Wed, 13 Nov 2024 21:12:14 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B5=D1=89=D0=B5=20=D0=BD=D0=B5=D0=BC=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=B4=D0=BE=20=D0=BA=D0=BE=D0=BD=D1=86?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/Employee.cs | 4 +- .../Forms/FormBuses.Designer.cs | 82 ++++----- .../Forms/FormBuses.cs | 70 ++++++- .../Forms/FormEmployee.Designer.cs | 141 +++++++++++++++ .../Forms/FormEmployee.cs | 80 ++++++++ .../Forms/FormEmployee.resx | 120 ++++++++++++ .../Forms/FormEmployees.Designer.cs | 126 +++++++++++++ .../Forms/FormEmployees.cs | 111 ++++++++++++ .../Forms/FormEmployees.resx | 120 ++++++++++++ .../Forms/FormRouteGiveaway.Designer.cs | 39 ++++ .../Forms/FormRouteGiveaway.cs | 20 ++ .../Forms/FormRouteGiveaway.resx | 120 ++++++++++++ .../Forms/FormRouteList.Designer.cs | 142 +++++++++++++++ .../Forms/FormRouteList.cs | 98 ++++++++++ .../Forms/FormRouteList.resx | 120 ++++++++++++ .../Forms/FormStartingShift.Designer.cs | 171 ++++++++++++++++++ .../Forms/FormStartingShift.cs | 60 ++++++ .../Forms/FormStartingShift.resx | 120 ++++++++++++ .../Forms/FormStartingShifts.Designer.cs | 45 +++++ .../Forms/FormStartingShifts.cs | 20 ++ .../Forms/FormStartingShifts.resx | 120 ++++++++++++ 21 files changed, 1884 insertions(+), 45 deletions(-) create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployee.Designer.cs create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployee.cs create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployee.resx create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployees.Designer.cs create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployees.cs create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployees.resx create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.Designer.cs create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.cs create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.resx create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteList.Designer.cs create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteList.cs create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteList.resx create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShift.Designer.cs create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShift.cs create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShift.resx create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.Designer.cs create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.cs create mode 100644 ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.resx diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Entities/Employee.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Entities/Employee.cs index 740a267..ee37c35 100644 --- a/ProjectPeopleTransportation/ProjectPeopleTransportation/Entities/Employee.cs +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Entities/Employee.cs @@ -10,18 +10,16 @@ public class Employee public string LastName { get; private set; } = string.Empty; - public int PhoneNum { get; private set; } public EmployeePost EmployeePost { get; private set; } - public static Employee CreateEntity(int id, string first, string last, int phone, EmployeePost employeePost) + public static Employee CreateEntity(int id, string first, string last, EmployeePost employeePost) { return new Employee { ID = id, FirstName = first ?? string.Empty, LastName = last ?? string.Empty, - PhoneNum = phone, EmployeePost = employeePost }; diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormBuses.Designer.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormBuses.Designer.cs index 6aae823..6bef72b 100644 --- a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormBuses.Designer.cs +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormBuses.Designer.cs @@ -29,12 +29,12 @@ private void InitializeComponent() { panel1 = new Panel(); - buttonAdd = new Button(); - buttonUpdate = new Button(); buttonDelete = new Button(); - dataGridView = new DataGridView(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + dataGridViewData = new DataGridView(); panel1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); SuspendLayout(); // // panel1 @@ -48,16 +48,16 @@ panel1.Size = new Size(149, 450); panel1.TabIndex = 0; // - // buttonAdd + // buttonDelete // - buttonAdd.BackgroundImage = Properties.Resources.Fairytale_button_add_svg; - buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; - buttonAdd.Location = new Point(37, 21); - buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(75, 67); - buttonAdd.TabIndex = 0; - buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += ButtonAdd_Click; + buttonDelete.BackgroundImage = Properties.Resources.remove_151678_1280; + buttonDelete.BackgroundImageLayout = ImageLayout.Stretch; + buttonDelete.Location = new Point(37, 167); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 67); + buttonDelete.TabIndex = 2; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; // // buttonUpdate // @@ -70,47 +70,47 @@ buttonUpdate.UseVisualStyleBackColor = true; buttonUpdate.Click += ButtonUpdate_Click; // - // buttonDelete + // buttonAdd // - buttonDelete.BackgroundImage = Properties.Resources.remove_151678_1280; - buttonDelete.BackgroundImageLayout = ImageLayout.Stretch; - buttonDelete.Location = new Point(37, 167); - buttonDelete.Name = "buttonDelete"; - buttonDelete.Size = new Size(75, 67); - buttonDelete.TabIndex = 2; - buttonDelete.UseVisualStyleBackColor = true; - buttonDelete.Click += ButtonDelete_Click; + buttonAdd.BackgroundImage = Properties.Resources.Fairytale_button_add_svg; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(37, 21); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 67); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; // - // dataGridView + // dataGridViewData // - dataGridView.AllowUserToAddRows = false; - dataGridView.AllowUserToDeleteRows = false; - dataGridView.AllowUserToResizeColumns = false; - dataGridView.AllowUserToResizeRows = false; - dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Dock = DockStyle.Fill; - dataGridView.Location = new Point(0, 0); - dataGridView.MultiSelect = false; - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersVisible = false; - dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(651, 450); - dataGridView.TabIndex = 1; + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(651, 450); + dataGridViewData.TabIndex = 1; // // FormBuses // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); - Controls.Add(dataGridView); + Controls.Add(dataGridViewData); Controls.Add(panel1); Name = "FormBuses"; StartPosition = FormStartPosition.CenterParent; Text = "Автобусы"; panel1.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); ResumeLayout(false); } @@ -120,6 +120,6 @@ private Button buttonDelete; private Button buttonUpdate; private Button buttonAdd; - private DataGridView dataGridView; + private DataGridView dataGridViewData; } } \ No newline at end of file diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormBuses.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormBuses.cs index cb735df..33115a0 100644 --- a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormBuses.cs +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormBuses.cs @@ -17,19 +17,87 @@ namespace ProjectPeopleTransportation.Forms _busRepository = busRepository ?? throw new ArgumentNullException(nameof(busRepository)); } + private void FormBuses_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) { - + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void ButtonUpdate_Click(object sender, EventArgs e) { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void ButtonDelete_Click(object sender, EventArgs e) { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _busRepository.DeleteBus(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewData.DataSource = _busRepository.ReadBuses(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + + if (dataGridViewData.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value); + return true; } } } diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployee.Designer.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployee.Designer.cs new file mode 100644 index 0000000..8720dda --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployee.Designer.cs @@ -0,0 +1,141 @@ +namespace ProjectPeopleTransportation.Forms +{ + partial class FormEmployee + { + /// + /// 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() + { + comboBoxPost = new ComboBox(); + labelFirstName = new Label(); + labelLastName = new Label(); + labelPost = new Label(); + textBoxFirstName = new TextBox(); + textBoxLastName = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // comboBoxPost + // + comboBoxPost.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxPost.FormattingEnabled = true; + comboBoxPost.Location = new Point(129, 131); + comboBoxPost.Name = "comboBoxPost"; + comboBoxPost.Size = new Size(121, 23); + comboBoxPost.TabIndex = 0; + // + // labelFirstName + // + labelFirstName.AutoSize = true; + labelFirstName.Location = new Point(28, 38); + labelFirstName.Name = "labelFirstName"; + labelFirstName.Size = new Size(31, 15); + labelFirstName.TabIndex = 1; + labelFirstName.Text = "Имя"; + // + // labelLastName + // + labelLastName.AutoSize = true; + labelLastName.Location = new Point(28, 90); + labelLastName.Name = "labelLastName"; + labelLastName.Size = new Size(58, 15); + labelLastName.TabIndex = 2; + labelLastName.Text = "Фамилия"; + // + // labelPost + // + labelPost.AutoSize = true; + labelPost.Location = new Point(28, 134); + labelPost.Name = "labelPost"; + labelPost.Size = new Size(69, 15); + labelPost.TabIndex = 3; + labelPost.Text = "Должность"; + // + // textBoxFirstName + // + textBoxFirstName.Location = new Point(129, 35); + textBoxFirstName.Name = "textBoxFirstName"; + textBoxFirstName.Size = new Size(100, 23); + textBoxFirstName.TabIndex = 4; + // + // textBoxLastName + // + textBoxLastName.Location = new Point(129, 82); + textBoxLastName.Name = "textBoxLastName"; + textBoxLastName.Size = new Size(100, 23); + textBoxLastName.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(53, 207); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(205, 207); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormEmployee + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(316, 257); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxLastName); + Controls.Add(textBoxFirstName); + Controls.Add(labelPost); + Controls.Add(labelLastName); + Controls.Add(labelFirstName); + Controls.Add(comboBoxPost); + Name = "FormEmployee"; + Text = "Работник"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxPost; + private Label labelFirstName; + private Label labelLastName; + private Label labelPost; + private TextBox textBoxFirstName; + private TextBox textBoxLastName; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployee.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployee.cs new file mode 100644 index 0000000..33505ed --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployee.cs @@ -0,0 +1,80 @@ +using ProjectPeopleTransportation.Entities; +using ProjectPeopleTransportation.Entities.Enums; +using ProjectPeopleTransportation.Repositories; + + +namespace ProjectPeopleTransportation.Forms +{ + public partial class FormEmployee : Form + { + + private readonly IEmployeeRepository _employeeRepository; + + private int? _employeeId; + + public int Id + { + set + { + try + { + var employee = _employeeRepository.ReadEmployeeByID(value); + + if (employee == null) + { + throw new InvalidDataException(nameof(employee)); + } + + textBoxFirstName.Text = employee.FirstName; + textBoxLastName.Text = employee.LastName; + comboBoxPost.SelectedItem = employee.EmployeePost; + _employeeId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + + public FormEmployee(IEmployeeRepository employeeRepository) + { + InitializeComponent(); + _employeeRepository = employeeRepository ?? throw new ArgumentNullException(nameof(employeeRepository)); + comboBoxPost.DataSource = Enum.GetValues(typeof(EmployeePost)); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) || string.IsNullOrWhiteSpace(textBoxLastName.Text) + || comboBoxPost.SelectedIndex < 1) + { + throw new Exception("Имеются незаполненные поля"); + } + if (_employeeId.HasValue) + { + _employeeRepository.UpdateEmployee(CreateEmployee(_employeeId.Value)); + } + else + { + _employeeRepository.CreateEmployee(CreateEmployee(0)); + } + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Employee CreateEmployee(int id) => Employee.CreateEntity(id, textBoxFirstName.Text, + textBoxLastName.Text, (EmployeePost)comboBoxPost.SelectedItem!); + } +} diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployee.resx b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployee.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployee.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/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployees.Designer.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployees.Designer.cs new file mode 100644 index 0000000..e6a1ef7 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployees.Designer.cs @@ -0,0 +1,126 @@ +namespace ProjectPeopleTransportation.Forms +{ + partial class FormEmployees + { + /// + /// 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() + { + panel1 = new Panel(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + dataGridViewData = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonDelete); + panel1.Controls.Add(buttonUpdate); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(666, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(134, 450); + panel1.TabIndex = 0; + // + // buttonDelete + // + buttonDelete.BackgroundImage = Properties.Resources.remove_151678_1280; + buttonDelete.BackgroundImageLayout = ImageLayout.Stretch; + buttonDelete.Location = new Point(27, 201); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 67); + buttonDelete.TabIndex = 3; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.BackgroundImage = Properties.Resources.d5b7655bb6ab6f1a24b6ac537fcb639a; + buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpdate.Location = new Point(27, 116); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 67); + buttonUpdate.TabIndex = 2; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.Fairytale_button_add_svg; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(27, 34); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 67); + buttonAdd.TabIndex = 1; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(666, 450); + dataGridViewData.TabIndex = 2; + // + // FormEmployees + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormEmployees"; + StartPosition = FormStartPosition.CenterParent; + Text = "Работники"; + Load += FormEmployees_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonDelete; + private DataGridView dataGridViewData; + } +} \ No newline at end of file diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployees.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployees.cs new file mode 100644 index 0000000..2263c87 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployees.cs @@ -0,0 +1,111 @@ +using ProjectPeopleTransportation.Repositories; +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; +using Unity; + +namespace ProjectPeopleTransportation.Forms +{ + public partial class FormEmployees : Form + { + private readonly IUnityContainer _container; + + private readonly IEmployeeRepository _employeeRepository; + + public FormEmployees(IUnityContainer container, IEmployeeRepository employeeRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _employeeRepository = employeeRepository ?? throw new ArgumentNullException(nameof(employeeRepository)); + } + + private void FormEmployees_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + + try + { + _employeeRepository.DeleteEmployee(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewData.DataSource = _employeeRepository.ReadEmployees(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewData.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value); + return true; + } + + } +} diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployees.resx b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployees.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormEmployees.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/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.Designer.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.Designer.cs new file mode 100644 index 0000000..4d47749 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.Designer.cs @@ -0,0 +1,39 @@ +namespace ProjectPeopleTransportation.Forms +{ + partial class FormRouteGiveaway + { + /// + /// 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 = "FormRouteGiveaway"; + } + + #endregion + } +} \ No newline at end of file diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.cs new file mode 100644 index 0000000..602a9d4 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.cs @@ -0,0 +1,20 @@ +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 ProjectPeopleTransportation.Forms +{ + public partial class FormRouteGiveaway : Form + { + public FormRouteGiveaway() + { + InitializeComponent(); + } + } +} diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.resx b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.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/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteList.Designer.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteList.Designer.cs new file mode 100644 index 0000000..477897f --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteList.Designer.cs @@ -0,0 +1,142 @@ +namespace ProjectPeopleTransportation.Forms +{ + partial class FormRouteList + { + /// + /// 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() + { + checkedListBoxRouteListType = new CheckedListBox(); + textBoxName = new TextBox(); + labelRouteListType = new Label(); + labelRouteListName = new Label(); + labelRouteDescription = new Label(); + textBoxDescription = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // checkedListBoxRouteListType + // + checkedListBoxRouteListType.FormattingEnabled = true; + checkedListBoxRouteListType.Location = new Point(153, 12); + checkedListBoxRouteListType.Name = "checkedListBoxRouteListType"; + checkedListBoxRouteListType.Size = new Size(186, 94); + checkedListBoxRouteListType.TabIndex = 0; + // + // textBoxName + // + textBoxName.Location = new Point(153, 130); + textBoxName.Multiline = true; + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(186, 31); + textBoxName.TabIndex = 1; + // + // labelRouteListType + // + labelRouteListType.AutoSize = true; + labelRouteListType.Location = new Point(21, 34); + labelRouteListType.Name = "labelRouteListType"; + labelRouteListType.Size = new Size(105, 15); + labelRouteListType.TabIndex = 2; + labelRouteListType.Text = "Номер маршрута"; + // + // labelRouteListName + // + labelRouteListName.AutoSize = true; + labelRouteListName.Location = new Point(21, 146); + labelRouteListName.Name = "labelRouteListName"; + labelRouteListName.Size = new Size(59, 15); + labelRouteListName.TabIndex = 3; + labelRouteListName.Text = "Название"; + // + // labelRouteDescription + // + labelRouteDescription.AutoSize = true; + labelRouteDescription.Location = new Point(21, 207); + labelRouteDescription.Name = "labelRouteDescription"; + labelRouteDescription.Size = new Size(65, 15); + labelRouteDescription.TabIndex = 4; + labelRouteDescription.Text = "Описание "; + // + // textBoxDescription + // + textBoxDescription.Location = new Point(153, 189); + textBoxDescription.Multiline = true; + textBoxDescription.Name = "textBoxDescription"; + textBoxDescription.Size = new Size(186, 91); + textBoxDescription.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(37, 303); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(190, 303); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormRouteList + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(366, 348); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxDescription); + Controls.Add(labelRouteDescription); + Controls.Add(labelRouteListName); + Controls.Add(labelRouteListType); + Controls.Add(textBoxName); + Controls.Add(checkedListBoxRouteListType); + Name = "FormRouteList"; + Text = "FormRouteList"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CheckedListBox checkedListBoxRouteListType; + private TextBox textBoxName; + private Label labelRouteListType; + private Label labelRouteListName; + private Label labelRouteDescription; + private TextBox textBoxDescription; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteList.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteList.cs new file mode 100644 index 0000000..1016521 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteList.cs @@ -0,0 +1,98 @@ +using ProjectPeopleTransportation.Entities.Enums; +using ProjectPeopleTransportation.Repositories; +using ProjectPeopleTransportation.Entities; + +namespace ProjectPeopleTransportation.Forms +{ + public partial class FormRouteList : Form + { + private readonly IRouteListRepository _routeListRepository; + + private int? _routeListId; + + public int Id + { + set + { + try + { + var routeList = _routeListRepository.ReadRouteListByID(value); + if (routeList == null) + { + throw new InvalidDataException(nameof(routeList)); + } + + foreach (RouteListType elem in Enum.GetValues(typeof(RouteListType))) + { + if ((elem & routeList.RouteListType) != 0) + { + checkedListBoxRouteListType.SetItemChecked(checkedListBoxRouteListType.Items.IndexOf(elem), true); + } + } + + + textBoxName.Text = routeList.Name; + textBoxDescription.Text = routeList.Description; + _routeListId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormRouteList(IRouteListRepository routeListRepository) + { + InitializeComponent(); + _routeListRepository = routeListRepository ?? throw new ArgumentNullException(nameof(routeListRepository)); + foreach (var elem in Enum.GetValues(typeof(RouteListType))) + { + checkedListBoxRouteListType.Items.Add(elem); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxName.Text) || + string.IsNullOrWhiteSpace(textBoxDescription.Text) || + checkedListBoxRouteListType.CheckedItems.Count == 0) + { + throw new Exception("Имеются незаполненные поля"); + } + + if (_routeListId.HasValue) + { + _routeListRepository.UpdateRouteList(CreateRouteList(_routeListId.Value)); + } + else + { + _routeListRepository.CreateRouteList(CreateRouteList(0)); + } + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private RouteList CreateRouteList(int id) + { + RouteListType routeListType = RouteListType.None; + + foreach (var elem in checkedListBoxRouteListType.CheckedItems) + { + routeListType |= (RouteListType)elem; + } + + return RouteList.CreateEntity(id, textBoxName.Text, textBoxDescription.Text, routeListType); + } + } +} diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteList.resx b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteList.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteList.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/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShift.Designer.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShift.Designer.cs new file mode 100644 index 0000000..0f16437 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShift.Designer.cs @@ -0,0 +1,171 @@ +namespace ProjectPeopleTransportation.Forms +{ + partial class FormStartingShift + { + /// + /// 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() + { + comboBoxRoute = new ComboBox(); + labelRoute = new Label(); + labelEmployee = new Label(); + labelBus = new Label(); + labelDuration = new Label(); + comboBoxEmployee = new ComboBox(); + comboBoxBus = new ComboBox(); + numericUpDownShiftDuration = new NumericUpDown(); + buttonSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownShiftDuration).BeginInit(); + SuspendLayout(); + // + // comboBoxRoute + // + comboBoxRoute.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxRoute.FormattingEnabled = true; + comboBoxRoute.Location = new Point(178, 33); + comboBoxRoute.Name = "comboBoxRoute"; + comboBoxRoute.Size = new Size(121, 23); + comboBoxRoute.TabIndex = 0; + // + // labelRoute + // + labelRoute.AutoSize = true; + labelRoute.Location = new Point(21, 33); + labelRoute.Name = "labelRoute"; + labelRoute.Size = new Size(60, 15); + labelRoute.TabIndex = 1; + labelRoute.Text = "Маршрут"; + // + // labelEmployee + // + labelEmployee.AutoSize = true; + labelEmployee.Location = new Point(21, 92); + labelEmployee.Name = "labelEmployee"; + labelEmployee.Size = new Size(59, 15); + labelEmployee.TabIndex = 2; + labelEmployee.Text = "Работник"; + // + // labelBus + // + labelBus.AutoSize = true; + labelBus.Location = new Point(21, 150); + labelBus.Name = "labelBus"; + labelBus.Size = new Size(52, 15); + labelBus.TabIndex = 3; + labelBus.Text = "Автобус"; + // + // labelDuration + // + labelDuration.AutoSize = true; + labelDuration.Location = new Point(21, 197); + labelDuration.Name = "labelDuration"; + labelDuration.Size = new Size(124, 15); + labelDuration.TabIndex = 4; + labelDuration.Text = "Длительность смены"; + // + // comboBoxEmployee + // + comboBoxEmployee.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxEmployee.FormattingEnabled = true; + comboBoxEmployee.Location = new Point(178, 84); + comboBoxEmployee.Name = "comboBoxEmployee"; + comboBoxEmployee.Size = new Size(121, 23); + comboBoxEmployee.TabIndex = 5; + // + // comboBoxBus + // + comboBoxBus.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxBus.FormattingEnabled = true; + comboBoxBus.Location = new Point(178, 142); + comboBoxBus.Name = "comboBoxBus"; + comboBoxBus.Size = new Size(121, 23); + comboBoxBus.TabIndex = 6; + // + // numericUpDownShiftDuration + // + numericUpDownShiftDuration.Location = new Point(178, 195); + numericUpDownShiftDuration.Minimum = new decimal(new int[] { 2, 0, 0, 0 }); + numericUpDownShiftDuration.Name = "numericUpDownShiftDuration"; + numericUpDownShiftDuration.Size = new Size(120, 23); + numericUpDownShiftDuration.TabIndex = 7; + numericUpDownShiftDuration.Value = new decimal(new int[] { 2, 0, 0, 0 }); + // + // buttonSave + // + buttonSave.Location = new Point(36, 265); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(165, 265); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormStartingShift + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(340, 336); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(numericUpDownShiftDuration); + Controls.Add(comboBoxBus); + Controls.Add(comboBoxEmployee); + Controls.Add(labelDuration); + Controls.Add(labelBus); + Controls.Add(labelEmployee); + Controls.Add(labelRoute); + Controls.Add(comboBoxRoute); + Name = "FormStartingShift"; + Text = "Начало смены"; + ((System.ComponentModel.ISupportInitialize)numericUpDownShiftDuration).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxRoute; + private Label labelRoute; + private Label labelEmployee; + private Label labelBus; + private Label labelDuration; + private ComboBox comboBoxEmployee; + private ComboBox comboBoxBus; + private NumericUpDown numericUpDownShiftDuration; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShift.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShift.cs new file mode 100644 index 0000000..dea48ea --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShift.cs @@ -0,0 +1,60 @@ +using ProjectPeopleTransportation.Repositories; +using ProjectPeopleTransportation.Entities; + + +namespace ProjectPeopleTransportation.Forms +{ + public partial class FormStartingShift : Form + { + private readonly IStartingShiftRepository _startingShiftRepository; + public FormStartingShift(IStartingShiftRepository startingShiftRepository, + IBusRepository busRepository, IEmployeeRepository employeeRepository, + IRouteListRepository routeListRepository) + { + InitializeComponent(); + _startingShiftRepository = startingShiftRepository ?? + throw new ArgumentNullException(nameof(startingShiftRepository)); + + comboBoxEmployee.DataSource = employeeRepository.ReadEmployees(); + comboBoxEmployee.DisplayMember = "FirstName"; + comboBoxEmployee.ValueMember = "Id"; + + comboBoxBus.DataSource = busRepository.ReadBuses(); + comboBoxBus.DisplayMember = "Name"; + comboBoxBus.ValueMember = "Id"; + + comboBoxRoute.DataSource = routeListRepository.ReadRouteLists(); + comboBoxRoute.DisplayMember = "RoutName"; + comboBoxRoute.ValueMember = "Id"; + + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxBus.SelectedIndex < 0 || + comboBoxEmployee.SelectedIndex < 0 || + comboBoxRoute.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля"); + } + + _startingShiftRepository.CreateStartingShift(StartingShift.CreateOperation(0, + (int)comboBoxRoute.SelectedValue!, (int)comboBoxEmployee.SelectedValue!, + (int)comboBoxBus.SelectedValue!, + Convert.ToInt32(numericUpDownShiftDuration.Value))); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + + } +} diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShift.resx b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShift.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShift.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/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.Designer.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.Designer.cs new file mode 100644 index 0000000..c3b417e --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.Designer.cs @@ -0,0 +1,45 @@ +namespace ProjectPeopleTransportation.Forms +{ + partial class FormStartingShifts + { + /// + /// 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() + { + SuspendLayout(); + // + // FormStartingShifts + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Name = "FormStartingShifts"; + Text = "Начало смен"; + ResumeLayout(false); + } + + #endregion + } +} \ No newline at end of file diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.cs new file mode 100644 index 0000000..8c25697 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.cs @@ -0,0 +1,20 @@ +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 ProjectPeopleTransportation.Forms +{ + public partial class FormStartingShifts : Form + { + public FormStartingShifts() + { + InitializeComponent(); + } + } +} diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.resx b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.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