diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/FormPeopleTransportation.Designer.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/FormPeopleTransportation.Designer.cs index ec5df17..c2d4e80 100644 --- a/ProjectPeopleTransportation/ProjectPeopleTransportation/FormPeopleTransportation.Designer.cs +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/FormPeopleTransportation.Designer.cs @@ -34,9 +34,9 @@ автобусыToolStripMenuItem = new ToolStripMenuItem(); маршрутныеЛистыToolStripMenuItem = new ToolStripMenuItem(); операцииToolStripMenuItem = new ToolStripMenuItem(); - отчетыToolStripMenuItem = new ToolStripMenuItem(); раздачаМаршрутовToolStripMenuItem = new ToolStripMenuItem(); началоСменыToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); SuspendLayout(); // @@ -61,18 +61,21 @@ работникToolStripMenuItem.Name = "работникToolStripMenuItem"; работникToolStripMenuItem.Size = new Size(186, 22); работникToolStripMenuItem.Text = "Работники"; + работникToolStripMenuItem.Click += EmployeeToolStripMenuItem_Click; // // автобусыToolStripMenuItem // автобусыToolStripMenuItem.Name = "автобусыToolStripMenuItem"; автобусыToolStripMenuItem.Size = new Size(186, 22); автобусыToolStripMenuItem.Text = "Автобусы"; + автобусыToolStripMenuItem.Click += BusesToolStripMenuItem_Click; // // маршрутныеЛистыToolStripMenuItem // маршрутныеЛистыToolStripMenuItem.Name = "маршрутныеЛистыToolStripMenuItem"; маршрутныеЛистыToolStripMenuItem.Size = new Size(186, 22); маршрутныеЛистыToolStripMenuItem.Text = "Маршрутные листы"; + маршрутныеЛистыToolStripMenuItem.Click += RouteListsToolStripMenuItem_Click; // // операцииToolStripMenuItem // @@ -81,23 +84,25 @@ операцииToolStripMenuItem.Size = new Size(75, 20); операцииToolStripMenuItem.Text = "Операции"; // - // отчетыToolStripMenuItem - // - отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - отчетыToolStripMenuItem.Size = new Size(60, 20); - отчетыToolStripMenuItem.Text = "Отчеты"; - // // раздачаМаршрутовToolStripMenuItem // раздачаМаршрутовToolStripMenuItem.Name = "раздачаМаршрутовToolStripMenuItem"; раздачаМаршрутовToolStripMenuItem.Size = new Size(184, 22); раздачаМаршрутовToolStripMenuItem.Text = "Раздача маршрутов"; + раздачаМаршрутовToolStripMenuItem.Click += RouteGiveawayToolStripMenuItem_Click; // // началоСменыToolStripMenuItem // началоСменыToolStripMenuItem.Name = "началоСменыToolStripMenuItem"; началоСменыToolStripMenuItem.Size = new Size(184, 22); началоСменыToolStripMenuItem.Text = "Начало смены"; + началоСменыToolStripMenuItem.Click += StartingShiftToolStripMenuItem_Click; + // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(60, 20); + отчетыToolStripMenuItem.Text = "Отчеты"; // // FormPeopleTransportation // diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/FormPeopleTransportation.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/FormPeopleTransportation.cs index 3d87c9f..c2c7fc5 100644 --- a/ProjectPeopleTransportation/ProjectPeopleTransportation/FormPeopleTransportation.cs +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/FormPeopleTransportation.cs @@ -1,10 +1,76 @@ +using ProjectPeopleTransportation.Forms; +using Unity; + namespace ProjectPeopleTransportation { public partial class FormPeopleTransportation : Form { - public FormPeopleTransportation() + private readonly IUnityContainer _container; + public FormPeopleTransportation(IUnityContainer container) { InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + } + + private void EmployeeToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void BusesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void RouteListsToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void RouteGiveawayToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void StartingShiftToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } } } diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.Designer.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.Designer.cs index 4d47749..2a239ed 100644 --- a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.Designer.cs +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.Designer.cs @@ -28,12 +28,120 @@ /// 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"; + comboBoxEmployee = new ComboBox(); + labelEmployee = new Label(); + groupBoxRoutes = new GroupBox(); + dataGridViewRoutes = new DataGridView(); + ColumnRouteName = new DataGridViewComboBoxColumn(); + ColumnRouteNum = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBoxRoutes.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewRoutes).BeginInit(); + SuspendLayout(); + // + // comboBoxEmployee + // + comboBoxEmployee.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxEmployee.FormattingEnabled = true; + comboBoxEmployee.Location = new Point(199, 45); + comboBoxEmployee.Name = "comboBoxEmployee"; + comboBoxEmployee.Size = new Size(121, 23); + comboBoxEmployee.TabIndex = 7; + // + // labelEmployee + // + labelEmployee.AutoSize = true; + labelEmployee.Location = new Point(42, 53); + labelEmployee.Name = "labelEmployee"; + labelEmployee.Size = new Size(59, 15); + labelEmployee.TabIndex = 6; + labelEmployee.Text = "Работник"; + // + // groupBoxRoutes + // + groupBoxRoutes.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBoxRoutes.Controls.Add(dataGridViewRoutes); + groupBoxRoutes.Location = new Point(42, 110); + groupBoxRoutes.Name = "groupBoxRoutes"; + groupBoxRoutes.Size = new Size(243, 254); + groupBoxRoutes.TabIndex = 8; + groupBoxRoutes.TabStop = false; + groupBoxRoutes.Text = "Маршруты"; + // + // dataGridViewRoutes + // + dataGridViewRoutes.AllowUserToResizeColumns = false; + dataGridViewRoutes.AllowUserToResizeRows = false; + dataGridViewRoutes.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewRoutes.Columns.AddRange(new DataGridViewColumn[] { ColumnRouteName, ColumnRouteNum }); + dataGridViewRoutes.Dock = DockStyle.Fill; + dataGridViewRoutes.Location = new Point(3, 19); + dataGridViewRoutes.MultiSelect = false; + dataGridViewRoutes.Name = "dataGridViewRoutes"; + dataGridViewRoutes.RowHeadersVisible = false; + dataGridViewRoutes.Size = new Size(237, 232); + dataGridViewRoutes.TabIndex = 9; + // + // ColumnRouteName + // + ColumnRouteName.HeaderText = "Название"; + ColumnRouteName.Name = "ColumnRouteName"; + // + // ColumnRouteNum + // + ColumnRouteNum.HeaderText = "Количество"; + ColumnRouteNum.Name = "ColumnRouteNum"; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSave.Location = new Point(45, 374); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 9; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(207, 374); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 10; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormRouteGiveaway + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(343, 409); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxRoutes); + Controls.Add(comboBoxEmployee); + Controls.Add(labelEmployee); + Name = "FormRouteGiveaway"; + Text = "Раздача маршрутов"; + groupBoxRoutes.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewRoutes).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion + + private ComboBox comboBoxEmployee; + private Label labelEmployee; + private GroupBox groupBoxRoutes; + private DataGridView dataGridViewRoutes; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewComboBoxColumn ColumnRouteName; + private DataGridViewTextBoxColumn ColumnRouteNum; } } \ No newline at end of file diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.cs index 602a9d4..bcdfe37 100644 --- a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.cs +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.cs @@ -1,4 +1,7 @@ -using System; +using ProjectPeopleTransportation.Entities; +using ProjectPeopleTransportation.Repositories; +using ProjectPeopleTransportation.Repositories.Implementations; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +15,61 @@ namespace ProjectPeopleTransportation.Forms { public partial class FormRouteGiveaway : Form { - public FormRouteGiveaway() + private readonly IRouteGiveawayRepository _routeGiveawayRepository; + + public FormRouteGiveaway(IRouteGiveawayRepository routeGiveawayRepository, + IEmployeeRepository employeeRepository, + IRouteListRepository routeListRepository) { InitializeComponent(); + _routeGiveawayRepository = routeGiveawayRepository ?? + throw new ArgumentNullException(nameof(routeGiveawayRepository)); + + comboBoxEmployee.DataSource = employeeRepository.ReadEmployees(); + comboBoxEmployee.DisplayMember = "FirstName"; + comboBoxEmployee.ValueMember = "Id"; + + ColumnRouteName.DataSource = routeListRepository.ReadRouteLists(); + ColumnRouteName.DisplayMember = "RoutName"; + ColumnRouteName.ValueMember = "Id"; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (dataGridViewRoutes.RowCount < 1 || + comboBoxEmployee.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля"); + } + + _routeGiveawayRepository.CreateRouteGiveaway(RouteGiveaway.CreateOperation(0, + (int)comboBoxEmployee.SelectedValue!, CreateListRouteRouteGiveawayFromDataGrid())); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private List CreateListRouteRouteGiveawayFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridViewRoutes.Rows) + { + if (row.Cells["ColumnRoute"].Value == null || row.Cells["ColumnCount"].Value == null) + { + continue; + } + list.Add(RouteRouteGiveaway.CreateElement(0, Convert.ToInt32(row.Cells["ColumnRoute"].Value), + Convert.ToInt32(row.Cells["ColumnCount"].Value))); + } + return list; } } } diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.resx b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.resx index 1af7de1..fddcb1e 100644 --- a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.resx +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaway.resx @@ -1,17 +1,17 @@  - @@ -117,4 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + + + True + \ No newline at end of file diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaways.Designer.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaways.Designer.cs new file mode 100644 index 0000000..51c222d --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaways.Designer.cs @@ -0,0 +1,104 @@ +namespace ProjectPeopleTransportation.Forms +{ + partial class FormRouteGiveaways + { + /// + /// 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(); + buttonAdd = new Button(); + dataGridViewGiveaway = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewGiveaway).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonDelete); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(651, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(133, 439); + panel1.TabIndex = 0; + // + // buttonDelete + // + buttonDelete.BackgroundImage = Properties.Resources.remove_151678_1280; + buttonDelete.BackgroundImageLayout = ImageLayout.Stretch; + buttonDelete.Location = new Point(28, 193); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 67); + buttonDelete.TabIndex = 4; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.Fairytale_button_add_svg; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(28, 43); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 67); + buttonAdd.TabIndex = 2; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewGiveaway + // + dataGridViewGiveaway.AllowUserToAddRows = false; + dataGridViewGiveaway.AllowUserToDeleteRows = false; + dataGridViewGiveaway.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewGiveaway.Dock = DockStyle.Fill; + dataGridViewGiveaway.Location = new Point(0, 0); + dataGridViewGiveaway.Name = "dataGridViewGiveaway"; + dataGridViewGiveaway.ReadOnly = true; + dataGridViewGiveaway.Size = new Size(651, 439); + dataGridViewGiveaway.TabIndex = 1; + // + // FormRouteGiveaways + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(784, 439); + Controls.Add(dataGridViewGiveaway); + Controls.Add(panel1); + Name = "FormRouteGiveaways"; + Text = "Раздачи маршрутов"; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewGiveaway).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private DataGridView dataGridViewGiveaway; + private Button buttonAdd; + private Button buttonDelete; + } +} \ No newline at end of file diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaways.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaways.cs new file mode 100644 index 0000000..a4fa171 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaways.cs @@ -0,0 +1,76 @@ +using ProjectPeopleTransportation.Repositories; +using ProjectPeopleTransportation.Repositories.Implementations; +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 FormRouteGiveaways : Form + { + private readonly IUnityContainer _container; + + private readonly IRouteGiveawayRepository _routeGiveawayRepository; + public FormRouteGiveaways(IUnityContainer container, IRouteGiveawayRepository routeGiveawayRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _routeGiveawayRepository = routeGiveawayRepository ?? throw new ArgumentNullException(nameof(routeGiveawayRepository)); + } + 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 ButtonDelete_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + + try + { + _routeGiveawayRepository.DeleteRouteGiveaway(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewGiveaway.DataSource = _routeGiveawayRepository.ReadRouteGiveaway(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewGiveaway.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + id = Convert.ToInt32(dataGridViewGiveaway.SelectedRows[0].Cells["Id"].Value); + return true; + } + } +} diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaways.resx b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaways.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteGiveaways.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/FormRouteLists.Designer.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteLists.Designer.cs new file mode 100644 index 0000000..f5d93cf --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteLists.Designer.cs @@ -0,0 +1,115 @@ +namespace ProjectPeopleTransportation.Forms +{ + partial class FormRouteLists + { + /// + /// 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(); + dataGridViewRoute = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewRoute).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonDelete); + panel1.Controls.Add(buttonUpdate); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(702, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(151, 347); + panel1.TabIndex = 0; + // + // buttonDelete + // + buttonDelete.BackgroundImage = Properties.Resources.remove_151678_1280; + buttonDelete.BackgroundImageLayout = ImageLayout.Stretch; + buttonDelete.Location = new Point(38, 196); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 67); + buttonDelete.TabIndex = 5; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.BackgroundImage = Properties.Resources.d5b7655bb6ab6f1a24b6ac537fcb639a; + buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpdate.Location = new Point(38, 113); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 67); + buttonUpdate.TabIndex = 4; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.Fairytale_button_add_svg; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(38, 32); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 67); + buttonAdd.TabIndex = 2; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewRoute + // + dataGridViewRoute.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewRoute.Dock = DockStyle.Fill; + dataGridViewRoute.Location = new Point(0, 0); + dataGridViewRoute.Name = "dataGridViewRoute"; + dataGridViewRoute.Size = new Size(702, 347); + dataGridViewRoute.TabIndex = 1; + // + // FormRouteLists + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(853, 347); + Controls.Add(dataGridViewRoute); + Controls.Add(panel1); + Name = "FormRouteLists"; + Text = "Маршрутные листы"; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewRoute).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private DataGridView dataGridViewRoute; + private Button buttonAdd; + private Button buttonDelete; + private Button buttonUpdate; + } +} \ No newline at end of file diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteLists.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteLists.cs new file mode 100644 index 0000000..6cb4592 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteLists.cs @@ -0,0 +1,100 @@ +using ProjectPeopleTransportation.Repositories; +using ProjectPeopleTransportation.Repositories.Implementations; +using Unity; + +namespace ProjectPeopleTransportation.Forms +{ + public partial class FormRouteLists : Form + { + private readonly IUnityContainer _container; + + private readonly IRouteListRepository _routeListRepository; + + public FormRouteLists(IUnityContainer container, IRouteListRepository routeListRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _routeListRepository = routeListRepository ?? throw new ArgumentNullException(nameof(routeListRepository)); + } + private void FormRouteLists_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 + { + _routeListRepository.DeleteRouteList(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewRoute.DataSource = _routeListRepository.ReadRouteLists(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewRoute.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + id = Convert.ToInt32(dataGridViewRoute.SelectedRows[0].Cells["Id"].Value); + return true; + } + } +} diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteLists.resx b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteLists.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormRouteLists.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 index c3b417e..b2e8862 100644 --- a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.Designer.cs +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.Designer.cs @@ -28,18 +28,63 @@ /// private void InitializeComponent() { + panel1 = new Panel(); + buttonAdd = new Button(); + dataGridViewData = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); SuspendLayout(); // + // panel1 + // + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(658, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(142, 450); + panel1.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.Fairytale_button_add_svg; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(32, 46); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 67); + buttonAdd.TabIndex = 2; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.Size = new Size(658, 450); + dataGridViewData.TabIndex = 1; + // // FormStartingShifts // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); + Controls.Add(dataGridViewData); + Controls.Add(panel1); Name = "FormStartingShifts"; Text = "Начало смен"; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); ResumeLayout(false); } #endregion + + private Panel panel1; + private DataGridView dataGridViewData; + private Button buttonAdd; } } \ No newline at end of file diff --git a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.cs b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.cs index 8c25697..9761723 100644 --- a/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.cs +++ b/ProjectPeopleTransportation/ProjectPeopleTransportation/Forms/FormStartingShifts.cs @@ -1,4 +1,6 @@ -using System; +using ProjectPeopleTransportation.Repositories; +using ProjectPeopleTransportation.Repositories.Implementations; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -7,14 +9,47 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Unity; namespace ProjectPeopleTransportation.Forms { public partial class FormStartingShifts : Form { - public FormStartingShifts() + private readonly IUnityContainer _container; + + private readonly IStartingShiftRepository _startingShiftRepository; + + public FormStartingShifts(IUnityContainer container, IStartingShiftRepository startingShiftRepository) { InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _startingShiftRepository = startingShiftRepository ?? throw new ArgumentNullException(nameof(startingShiftRepository)); } + + private void FormStartingShifts_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 LoadList() => dataGridViewData.DataSource = _startingShiftRepository.ReadStartingShifts(); } }