From 36095824187e4d93708106fb397722d6bb4b876e Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Fri, 5 May 2023 14:57:40 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20=D1=81?= =?UTF-8?q?=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=BC=D0=B0=D1=80=D1=88=D1=80=D1=83=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TransportGuide/FormRoute.Designer.cs | 222 +++++++++++++++++++++- TransportGuide/FormRoute.cs | 225 ++++++++++++++++++++++- TransportGuide/FormRoute.resx | 62 +------ TransportGuide/FormRoutes.Designer.cs | 88 ++++++++- TransportGuide/FormRoutes.cs | 105 ++++++++++- TransportGuide/FormStopRoute.Designer.cs | 119 ++++++++++++ TransportGuide/FormStopRoute.cs | 91 +++++++++ TransportGuide/FormStopRoute.resx | 120 ++++++++++++ TransportGuide/Program.cs | 2 +- 9 files changed, 961 insertions(+), 73 deletions(-) create mode 100644 TransportGuide/FormStopRoute.Designer.cs create mode 100644 TransportGuide/FormStopRoute.cs create mode 100644 TransportGuide/FormStopRoute.resx diff --git a/TransportGuide/FormRoute.Designer.cs b/TransportGuide/FormRoute.Designer.cs index 56a0bcf..c73db6a 100644 --- a/TransportGuide/FormRoute.Designer.cs +++ b/TransportGuide/FormRoute.Designer.cs @@ -28,12 +28,228 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.labelName = new System.Windows.Forms.Label(); + this.labelIP = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxIP = new System.Windows.Forms.TextBox(); + this.groupBoxStop = new System.Windows.Forms.GroupBox(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonChange = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnStop = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnNomer = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.labelTransportType = new System.Windows.Forms.Label(); + this.comboBoxTransportType = new System.Windows.Forms.ComboBox(); + this.groupBoxStop.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(19, 19); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(94, 25); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelIP + // + this.labelIP.AutoSize = true; + this.labelIP.Location = new System.Drawing.Point(19, 59); + this.labelIP.Name = "labelIP"; + this.labelIP.Size = new System.Drawing.Size(47, 25); + this.labelIP.TabIndex = 1; + this.labelIP.Text = "ИП: "; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(177, 16); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(340, 31); + this.textBoxName.TabIndex = 2; + // + // textBoxIP + // + this.textBoxIP.Location = new System.Drawing.Point(177, 56); + this.textBoxIP.Name = "textBoxIP"; + this.textBoxIP.Size = new System.Drawing.Size(150, 31); + this.textBoxIP.TabIndex = 3; + // + // groupBoxStop + // + this.groupBoxStop.Controls.Add(this.buttonUpdate); + this.groupBoxStop.Controls.Add(this.buttonDelete); + this.groupBoxStop.Controls.Add(this.buttonChange); + this.groupBoxStop.Controls.Add(this.buttonAdd); + this.groupBoxStop.Controls.Add(this.dataGridView); + this.groupBoxStop.Location = new System.Drawing.Point(19, 157); + this.groupBoxStop.Name = "groupBoxStop"; + this.groupBoxStop.Size = new System.Drawing.Size(763, 330); + this.groupBoxStop.TabIndex = 4; + this.groupBoxStop.TabStop = false; + this.groupBoxStop.Text = "Stops"; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(604, 164); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(112, 34); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(604, 124); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(112, 34); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click); + // + // buttonChange + // + this.buttonChange.Location = new System.Drawing.Point(602, 81); + this.buttonChange.Name = "buttonChange"; + this.buttonChange.Size = new System.Drawing.Size(112, 34); + this.buttonChange.TabIndex = 2; + this.buttonChange.Text = "Изменить"; + this.buttonChange.UseVisualStyleBackColor = true; + this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(602, 35); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(112, 34); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.ColumnStop, + this.ColumnNomer}); + this.dataGridView.Location = new System.Drawing.Point(27, 35); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(554, 281); + this.dataGridView.TabIndex = 0; + // + // ID + // + this.ID.HeaderText = "Column1"; + this.ID.MinimumWidth = 8; + this.ID.Name = "ID"; + this.ID.Visible = false; + this.ID.Width = 150; + // + // ColumnStop + // + this.ColumnStop.HeaderText = "Stop"; + this.ColumnStop.MinimumWidth = 8; + this.ColumnStop.Name = "ColumnStop"; + this.ColumnStop.Width = 150; + // + // ColumnNomer + // + this.ColumnNomer.HeaderText = "Nomer"; + this.ColumnNomer.MinimumWidth = 8; + this.ColumnNomer.Name = "ColumnNomer"; + this.ColumnNomer.Width = 150; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(436, 501); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(567, 503); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // labelTransportType + // + this.labelTransportType.AutoSize = true; + this.labelTransportType.Location = new System.Drawing.Point(19, 103); + this.labelTransportType.Name = "labelTransportType"; + this.labelTransportType.Size = new System.Drawing.Size(141, 25); + this.labelTransportType.TabIndex = 7; + this.labelTransportType.Text = "Тип Транспорта"; + // + // comboBoxTransportType + // + this.comboBoxTransportType.FormattingEnabled = true; + this.comboBoxTransportType.Location = new System.Drawing.Point(177, 103); + this.comboBoxTransportType.Name = "comboBoxTransportType"; + this.comboBoxTransportType.Size = new System.Drawing.Size(182, 33); + this.comboBoxTransportType.TabIndex = 8; + // + // FormRoute + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormRoute"; + this.ClientSize = new System.Drawing.Size(800, 579); + this.Controls.Add(this.comboBoxTransportType); + this.Controls.Add(this.labelTransportType); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.groupBoxStop); + this.Controls.Add(this.textBoxIP); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelIP); + this.Controls.Add(this.labelName); + this.Name = "FormRoute"; + this.Text = "Route"; + this.Load += new System.EventHandler(this.FormRoute_Load); + this.groupBoxStop.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private Label labelName; + private Label labelIP; + private TextBox textBoxName; + private TextBox textBoxIP; + private GroupBox groupBoxStop; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonChange; + private Button buttonAdd; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ColumnStop; + private DataGridViewTextBoxColumn ColumnNomer; + private Label labelTransportType; + private ComboBox comboBoxTransportType; } } \ No newline at end of file diff --git a/TransportGuide/FormRoute.cs b/TransportGuide/FormRoute.cs index f466112..f4acdc8 100644 --- a/TransportGuide/FormRoute.cs +++ b/TransportGuide/FormRoute.cs @@ -1,20 +1,239 @@ -using System; +using Microsoft.Extensions.Logging; +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 TransportGuideContracts.BusinessLogicsContracts; +using TransportGuideContracts.SearchModels; +using TransportGuideDataModels.Models; +using TransportGuideContracts.BindingModels; namespace TransportGuide { public partial class FormRoute : Form { - public FormRoute() + private readonly ILogger _logger; + private readonly IRouteLogic _logic; + private readonly ITransportTypeLogic _logicTT; + private int? _id; + private Dictionary _RouteStops; + public int Id { set { _id = value; } } + public FormRoute(ILogger logger, IRouteLogic logic, ITransportTypeLogic logicTT) { InitializeComponent(); + _logger = logger; + _logic = logic; + _RouteStops = new Dictionary(); + _logicTT = logicTT; } + + private void FormRoute_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var view = _logic.ReadElement(new RouteSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.Name; + textBoxIP.Text = view.IP.ToString(); + _RouteStops = view.StopRoutes ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + try + { + var list = _logicTT.ReadList(null); + if (list != null) + { + comboBoxTransportType.DisplayMember = "Type"; + comboBoxTransportType.ValueMember = "Id"; + comboBoxTransportType.DataSource = list.Select(c => c.Name).ToList(); + comboBoxTransportType.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + private void LoadData() + { + try + { + if (_RouteStops != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _RouteStops) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.Name, pc.Value.Item2 }); + } + //textBoxIP.Text = CalcIP().ToString(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStopRoute)); + if (service is FormStopRoute form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.StopModel == null) + { + return; + } + if (_RouteStops.ContainsKey(form.Id)) + { + _RouteStops[form.Id] = (form.StopModel, form.Nomer); + } + else + { + _RouteStops.Add(form.Id, (form.StopModel, form.Nomer)); + } + LoadData(); + } + } + + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStopRoute)); + if (service is FormStopRoute form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Nomer = _RouteStops[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.StopModel == null) + { + return; + } + _RouteStops[form.Id] = (form.StopModel, form.Nomer); + LoadData(); + } + } + } + + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _RouteStops?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Fill in Name", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxIP.Text)) + { + MessageBox.Show("Fill in IP", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (_RouteStops == null || _RouteStops.Count == 0) + { + MessageBox.Show("Fill in Stops", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxTransportType.SelectedItem == null) + { + MessageBox.Show("Fill in Type", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var model = new RouteBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text, + IP = textBoxIP.Text, + TransportTypeId = comboBoxTransportType.SelectedIndex, + StopRoutes = _RouteStops + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.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/TransportGuide/FormRoute.resx b/TransportGuide/FormRoute.resx index 1af7de1..f298a7b 100644 --- a/TransportGuide/FormRoute.resx +++ b/TransportGuide/FormRoute.resx @@ -1,64 +1,4 @@ - - - + diff --git a/TransportGuide/FormRoutes.Designer.cs b/TransportGuide/FormRoutes.Designer.cs index ea8a26c..c0961b7 100644 --- a/TransportGuide/FormRoutes.Designer.cs +++ b/TransportGuide/FormRoutes.Designer.cs @@ -28,12 +28,94 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.DataGridView = new System.Windows.Forms.DataGridView(); + this.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 2); + this.DataGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 62; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(597, 547); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(615, 12); + this.AddButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(171, 39); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(615, 110); + this.ChangeButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(171, 39); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(615, 209); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(171, 39); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(615, 310); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(171, 39); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormRoutes + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormRoutes"; + this.ClientSize = new System.Drawing.Size(805, 563); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.Name = "FormRoutes"; + this.Text = "Routes"; + this.Load += new System.EventHandler(this.FormRoutes_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + } #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; } } \ No newline at end of file diff --git a/TransportGuide/FormRoutes.cs b/TransportGuide/FormRoutes.cs index 9eaefad..2a987a4 100644 --- a/TransportGuide/FormRoutes.cs +++ b/TransportGuide/FormRoutes.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -7,14 +8,114 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using TransportGuideContracts.BindingModels; +using TransportGuideContracts.BusinessLogicsContracts; namespace TransportGuide { public partial class FormRoutes : Form { - public FormRoutes() + private readonly ILogger _logger; + private readonly IRouteLogic _logic; + + public FormRoutes(ILogger logger, IRouteLogic logic) { InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["StopRoutes"].Visible = false; + + } + + _logger.LogInformation("Загрузка компонентов"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_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 ChangeButton_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 DeleteButton_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); + + try + { + if (!_logic.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 UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + + private void FormRoutes_Load(object sender, EventArgs e) + { + LoadData(); } } } diff --git a/TransportGuide/FormStopRoute.Designer.cs b/TransportGuide/FormStopRoute.Designer.cs new file mode 100644 index 0000000..945e60e --- /dev/null +++ b/TransportGuide/FormStopRoute.Designer.cs @@ -0,0 +1,119 @@ +namespace TransportGuide +{ + partial class FormStopRoute + { + /// + /// 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.comboBoxStop = new System.Windows.Forms.ComboBox(); + this.textBoxNomer = new System.Windows.Forms.TextBox(); + this.labelStop = new System.Windows.Forms.Label(); + this.labelNomer = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxStop + // + this.comboBoxStop.FormattingEnabled = true; + this.comboBoxStop.Location = new System.Drawing.Point(148, 10); + this.comboBoxStop.Name = "comboBoxStop"; + this.comboBoxStop.Size = new System.Drawing.Size(182, 33); + this.comboBoxStop.TabIndex = 0; + // + // textBoxNomer + // + this.textBoxNomer.Location = new System.Drawing.Point(150, 53); + this.textBoxNomer.Name = "textBoxNomer"; + this.textBoxNomer.Size = new System.Drawing.Size(150, 31); + this.textBoxNomer.TabIndex = 1; + // + // labelStop + // + this.labelStop.AutoSize = true; + this.labelStop.Location = new System.Drawing.Point(16, 18); + this.labelStop.Name = "labelStop"; + this.labelStop.Size = new System.Drawing.Size(103, 25); + this.labelStop.TabIndex = 2; + this.labelStop.Text = "Stop"; + // + // labelNomer + // + this.labelNomer.AutoSize = true; + this.labelNomer.Location = new System.Drawing.Point(16, 57); + this.labelNomer.Name = "labelNomer"; + this.labelNomer.Size = new System.Drawing.Size(112, 25); + this.labelNomer.TabIndex = 3; + this.labelNomer.Text = "Nomer "; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(75, 99); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(206, 99); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отменить"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormJewelStop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(426, 142); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.labelNomer); + this.Controls.Add(this.labelStop); + this.Controls.Add(this.textBoxNomer); + this.Controls.Add(this.comboBoxStop); + this.Name = "FormStopRoute"; + this.Text = "Stop Route"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxStop; + private TextBox textBoxNomer; + private Label labelStop; + private Label labelNomer; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/TransportGuide/FormStopRoute.cs b/TransportGuide/FormStopRoute.cs new file mode 100644 index 0000000..578b2a2 --- /dev/null +++ b/TransportGuide/FormStopRoute.cs @@ -0,0 +1,91 @@ +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; +using TransportGuideContracts.ViewModels; +using TransportGuideDataModels.Models; +using TransportGuideContracts.BusinessLogicsContracts; + +namespace TransportGuide +{ + public partial class FormStopRoute : 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 Nomer + { + get { return Convert.ToInt32(textBoxNomer.Text); } + set { textBoxNomer.Text = value.ToString(); } + } + + public FormStopRoute(IStopLogic logic) + { + InitializeComponent(); + _list = logic.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 (string.IsNullOrEmpty(textBoxNomer.Text)) + { + MessageBox.Show("Fill in Nomer", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxStop.SelectedValue == null) + { + MessageBox.Show("Choose Stop", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/TransportGuide/FormStopRoute.resx b/TransportGuide/FormStopRoute.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TransportGuide/FormStopRoute.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/TransportGuide/Program.cs b/TransportGuide/Program.cs index 55d6de1..68f422f 100644 --- a/TransportGuide/Program.cs +++ b/TransportGuide/Program.cs @@ -48,7 +48,7 @@ namespace TransportGuide services.AddTransient(); services.AddTransient(); services.AddTransient(); - + services.AddTransient(); } } } \ No newline at end of file