From caaa5d7f0fbafbe5666a430cbf87bee9587605eb Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Fri, 5 May 2023 14:16:56 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=D0=BA=D0=BE=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D1=8B=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TransportGuide/Form1.Designer.cs | 39 ------ TransportGuide/Form1.cs | 10 -- TransportGuide/FormMain.Designer.cs | 96 ++++++++++++++ TransportGuide/FormMain.cs | 57 +++++++++ TransportGuide/FormMain.resx | 63 +++++++++ TransportGuide/FormRoute.Designer.cs | 39 ++++++ TransportGuide/FormRoute.cs | 20 +++ TransportGuide/{Form1.resx => FormRoute.resx} | 0 TransportGuide/FormRoutes.Designer.cs | 39 ++++++ TransportGuide/FormRoutes.cs | 20 +++ TransportGuide/FormRoutes.resx | 120 ++++++++++++++++++ TransportGuide/FormStop.Designer.cs | 98 ++++++++++++++ TransportGuide/FormStop.cs | 91 +++++++++++++ TransportGuide/FormStop.resx | 120 ++++++++++++++++++ TransportGuide/FormStops.Designer.cs | 116 +++++++++++++++++ TransportGuide/FormStops.cs | 118 +++++++++++++++++ TransportGuide/FormStops.resx | 120 ++++++++++++++++++ TransportGuide/FormTransportType.Designer.cs | 119 +++++++++++++++++ TransportGuide/FormTransportType.cs | 90 +++++++++++++ TransportGuide/FormTransportType.resx | 60 +++++++++ TransportGuide/FormTransportTypes.Designer.cs | 116 +++++++++++++++++ TransportGuide/FormTransportTypes.cs | 117 +++++++++++++++++ TransportGuide/FormTransportTypes.resx | 120 ++++++++++++++++++ TransportGuide/Program.cs | 61 +++++++-- TransportGuide/TransportGuide.csproj | 1 + 25 files changed, 1789 insertions(+), 61 deletions(-) delete mode 100644 TransportGuide/Form1.Designer.cs delete mode 100644 TransportGuide/Form1.cs create mode 100644 TransportGuide/FormMain.Designer.cs create mode 100644 TransportGuide/FormMain.cs create mode 100644 TransportGuide/FormMain.resx create mode 100644 TransportGuide/FormRoute.Designer.cs create mode 100644 TransportGuide/FormRoute.cs rename TransportGuide/{Form1.resx => FormRoute.resx} (100%) create mode 100644 TransportGuide/FormRoutes.Designer.cs create mode 100644 TransportGuide/FormRoutes.cs create mode 100644 TransportGuide/FormRoutes.resx create mode 100644 TransportGuide/FormStop.Designer.cs create mode 100644 TransportGuide/FormStop.cs create mode 100644 TransportGuide/FormStop.resx create mode 100644 TransportGuide/FormStops.Designer.cs create mode 100644 TransportGuide/FormStops.cs create mode 100644 TransportGuide/FormStops.resx create mode 100644 TransportGuide/FormTransportType.Designer.cs create mode 100644 TransportGuide/FormTransportType.cs create mode 100644 TransportGuide/FormTransportType.resx create mode 100644 TransportGuide/FormTransportTypes.Designer.cs create mode 100644 TransportGuide/FormTransportTypes.cs create mode 100644 TransportGuide/FormTransportTypes.resx diff --git a/TransportGuide/Form1.Designer.cs b/TransportGuide/Form1.Designer.cs deleted file mode 100644 index f90c390..0000000 --- a/TransportGuide/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace TransportGuide -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/TransportGuide/Form1.cs b/TransportGuide/Form1.cs deleted file mode 100644 index 637bf97..0000000 --- a/TransportGuide/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace TransportGuide -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/TransportGuide/FormMain.Designer.cs b/TransportGuide/FormMain.Designer.cs new file mode 100644 index 0000000..c85a1ff --- /dev/null +++ b/TransportGuide/FormMain.Designer.cs @@ -0,0 +1,96 @@ +namespace TransportGuide +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.transportTypeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.stopToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.routeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.transportTypeToolStripMenuItem, + this.stopToolStripMenuItem, + this.routeToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(800, 33); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "menuStrip"; + // + // transportTypeToolStripMenuItem + // + this.transportTypeToolStripMenuItem.Name = "transportTypeToolStripMenuItem"; + this.transportTypeToolStripMenuItem.Size = new System.Drawing.Size(139, 29); + this.transportTypeToolStripMenuItem.Text = "TransportType"; + this.transportTypeToolStripMenuItem.Click += new System.EventHandler(this.transportTypeToolStripMenuItem_Click); + // + // stopToolStripMenuItem + // + this.stopToolStripMenuItem.Name = "stopToolStripMenuItem"; + this.stopToolStripMenuItem.Size = new System.Drawing.Size(65, 29); + this.stopToolStripMenuItem.Text = "Stop"; + this.stopToolStripMenuItem.Click += new System.EventHandler(this.stopToolStripMenuItem_Click); + // + // routeToolStripMenuItem + // + this.routeToolStripMenuItem.Name = "routeToolStripMenuItem"; + this.routeToolStripMenuItem.Size = new System.Drawing.Size(74, 29); + this.routeToolStripMenuItem.Text = "Route"; + this.routeToolStripMenuItem.Click += new System.EventHandler(this.routeToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.Text = "FormMain"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem transportTypeToolStripMenuItem; + private ToolStripMenuItem stopToolStripMenuItem; + private ToolStripMenuItem routeToolStripMenuItem; + } +} \ No newline at end of file diff --git a/TransportGuide/FormMain.cs b/TransportGuide/FormMain.cs new file mode 100644 index 0000000..c052f32 --- /dev/null +++ b/TransportGuide/FormMain.cs @@ -0,0 +1,57 @@ +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 TransportGuide +{ + public partial class FormMain : Form + { + public FormMain() + { + InitializeComponent(); + } + + private void FormMain_Load(object sender, EventArgs e) + { + + } + + + private void transportTypeToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTransportTypes)); + + if (service is FormTransportTypes form) + { + form.ShowDialog(); + } + + } + + private void stopToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStops)); + + if (service is FormStops form) + { + form.ShowDialog(); + } + } + + private void routeToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRoutes)); + + if (service is FormRoutes form) + { + form.ShowDialog(); + } + } + } +} diff --git a/TransportGuide/FormMain.resx b/TransportGuide/FormMain.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/TransportGuide/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/TransportGuide/FormRoute.Designer.cs b/TransportGuide/FormRoute.Designer.cs new file mode 100644 index 0000000..56a0bcf --- /dev/null +++ b/TransportGuide/FormRoute.Designer.cs @@ -0,0 +1,39 @@ +namespace TransportGuide +{ + partial class FormRoute + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "FormRoute"; + } + + #endregion + } +} \ No newline at end of file diff --git a/TransportGuide/FormRoute.cs b/TransportGuide/FormRoute.cs new file mode 100644 index 0000000..f466112 --- /dev/null +++ b/TransportGuide/FormRoute.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 TransportGuide +{ + public partial class FormRoute : Form + { + public FormRoute() + { + InitializeComponent(); + } + } +} diff --git a/TransportGuide/Form1.resx b/TransportGuide/FormRoute.resx similarity index 100% rename from TransportGuide/Form1.resx rename to TransportGuide/FormRoute.resx diff --git a/TransportGuide/FormRoutes.Designer.cs b/TransportGuide/FormRoutes.Designer.cs new file mode 100644 index 0000000..ea8a26c --- /dev/null +++ b/TransportGuide/FormRoutes.Designer.cs @@ -0,0 +1,39 @@ +namespace TransportGuide +{ + partial class FormRoutes + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "FormRoutes"; + } + + #endregion + } +} \ No newline at end of file diff --git a/TransportGuide/FormRoutes.cs b/TransportGuide/FormRoutes.cs new file mode 100644 index 0000000..9eaefad --- /dev/null +++ b/TransportGuide/FormRoutes.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 TransportGuide +{ + public partial class FormRoutes : Form + { + public FormRoutes() + { + InitializeComponent(); + } + } +} diff --git a/TransportGuide/FormRoutes.resx b/TransportGuide/FormRoutes.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TransportGuide/FormRoutes.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TransportGuide/FormStop.Designer.cs b/TransportGuide/FormStop.Designer.cs new file mode 100644 index 0000000..ea99d8a --- /dev/null +++ b/TransportGuide/FormStop.Designer.cs @@ -0,0 +1,98 @@ +namespace TransportGuide +{ + partial class FormStop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(554, 353); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + this.buttonSave.TabIndex = 0; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(676, 353); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + this.buttonCancel.TabIndex = 1; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(90, 113); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(94, 25); + this.labelName.TabIndex = 2; + this.labelName.Text = "Название:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(212, 113); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(150, 31); + this.textBoxName.TabIndex = 4; + + // + // FormStop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormStop"; + this.Text = "Stop"; + this.Load += new System.EventHandler(this.FormStop_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label labelName; + private TextBox textBoxName; + } +} \ No newline at end of file diff --git a/TransportGuide/FormStop.cs b/TransportGuide/FormStop.cs new file mode 100644 index 0000000..ff4d9bc --- /dev/null +++ b/TransportGuide/FormStop.cs @@ -0,0 +1,91 @@ +using Microsoft.Extensions.Logging; +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.BusinessLogicsContracts; +using TransportGuideContracts.SearchModels; +using TransportGuideContracts.BindingModels; + +namespace TransportGuide +{ + public partial class FormStop : Form + { + private readonly ILogger _logger; + private readonly IStopLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormStop(ILogger logger, IStopLogic + logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormStop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var view = _logic.ReadElement(new StopSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + textBoxName.Text = view.Name; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error with loading", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Name cant be empty", "error", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var model = new StopBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text, + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Error with saving."); + } + MessageBox.Show("Stop was saved", "Saved", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + } +} diff --git a/TransportGuide/FormStop.resx b/TransportGuide/FormStop.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TransportGuide/FormStop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TransportGuide/FormStops.Designer.cs b/TransportGuide/FormStops.Designer.cs new file mode 100644 index 0000000..4a13fc4 --- /dev/null +++ b/TransportGuide/FormStops.Designer.cs @@ -0,0 +1,116 @@ +namespace TransportGuide +{ + partial class FormStops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonChange = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(459, 488); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(480, 25); + 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); + // + // buttonChange + // + this.buttonChange.Location = new System.Drawing.Point(481, 67); + 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); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(481, 107); + 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); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(481, 147); + 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); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(614, 488); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonChange); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormStops"; + this.Text = "Stops"; + this.Load += new System.EventHandler(this.FormStops_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonChange; + private Button buttonDelete; + private Button buttonUpdate; + } +} \ No newline at end of file diff --git a/TransportGuide/FormStops.cs b/TransportGuide/FormStops.cs new file mode 100644 index 0000000..3b203d2 --- /dev/null +++ b/TransportGuide/FormStops.cs @@ -0,0 +1,118 @@ +using Microsoft.Extensions.Logging; +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.BindingModels; +using TransportGuideContracts.BusinessLogicsContracts; + +namespace TransportGuide +{ + public partial class FormStops : Form + { + private readonly ILogger _logger; + private readonly IStopLogic _logic; + public FormStops(ILogger logger, IStopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormStops_Load(object sender, EventArgs e) + { + LoadData(); + } + 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; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStop)); + if (service is FormStop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new StopBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormStop)); + if (service is FormStop form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + } +} diff --git a/TransportGuide/FormStops.resx b/TransportGuide/FormStops.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TransportGuide/FormStops.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TransportGuide/FormTransportType.Designer.cs b/TransportGuide/FormTransportType.Designer.cs new file mode 100644 index 0000000..e96e5f4 --- /dev/null +++ b/TransportGuide/FormTransportType.Designer.cs @@ -0,0 +1,119 @@ +namespace TransportGuide +{ + partial class FormTransportType + { + /// + /// 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.labelName = new System.Windows.Forms.Label(); + this.labelPrice = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(76, 56); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(59, 25); + this.labelName.TabIndex = 0; + this.labelName.Text = "Name"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(76, 136); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(49, 25); + this.labelPrice.TabIndex = 1; + this.labelPrice.Text = "Price"; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(76, 242); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(112, 34); + this.buttonSave.TabIndex = 2; + this.buttonSave.Text = "Save"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(219, 242); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(112, 34); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Cancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(181, 56); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(150, 31); + this.textBoxName.TabIndex = 4; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(181, 136); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(150, 31); + this.textBoxPrice.TabIndex = 5; + // + // FormTransportType + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(443, 315); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelName); + this.Name = "FormTransportType"; + this.Text = "TransportType"; + this.Load += new System.EventHandler(this.FormTransportType_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelPrice; + private Button buttonSave; + private Button buttonCancel; + private TextBox textBoxName; + private TextBox textBoxPrice; + } +} \ No newline at end of file diff --git a/TransportGuide/FormTransportType.cs b/TransportGuide/FormTransportType.cs new file mode 100644 index 0000000..063d039 --- /dev/null +++ b/TransportGuide/FormTransportType.cs @@ -0,0 +1,90 @@ +using Microsoft.Extensions.Logging; +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.BindingModels; +using TransportGuideContracts.BusinessLogicsContracts; +using TransportGuideContracts.SearchModels; + +namespace TransportGuide +{ + public partial class FormTransportType : Form + { + private readonly ITransportTypeLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormTransportType(ITransportTypeLogic logic) + { + InitializeComponent(); + _logic = logic; + } + private void FormTransportType_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var view = _logic.ReadElement(new TransportTypeSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.Name; + textBoxPrice.Text = view.Price.ToString(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Loading error", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Error", "Name cant be empty", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var model = new TransportTypeBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Error with save."); + } + MessageBox.Show("Transport Type was saved", "", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + + } +} diff --git a/TransportGuide/FormTransportType.resx b/TransportGuide/FormTransportType.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/TransportGuide/FormTransportType.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/FormTransportTypes.Designer.cs b/TransportGuide/FormTransportTypes.Designer.cs new file mode 100644 index 0000000..19e47e2 --- /dev/null +++ b/TransportGuide/FormTransportTypes.Designer.cs @@ -0,0 +1,116 @@ +namespace TransportGuide +{ + partial class FormTransportTypes + { + /// + /// 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 InitializeTransportType() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonChange = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.RowTemplate.Height = 33; + this.dataGridView.Size = new System.Drawing.Size(459, 488); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(480, 25); + 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); + // + // buttonChange + // + this.buttonChange.Location = new System.Drawing.Point(481, 67); + 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); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(481, 107); + 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); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(481, 147); + 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); + // + // FormTransportTypes + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(614, 488); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonChange); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormTransportTypes"; + this.Text = "TransportTypes"; + this.Load += new System.EventHandler(this.FormTransportTypes_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonChange; + private Button buttonDelete; + private Button buttonUpdate; + } +} \ No newline at end of file diff --git a/TransportGuide/FormTransportTypes.cs b/TransportGuide/FormTransportTypes.cs new file mode 100644 index 0000000..5c01f56 --- /dev/null +++ b/TransportGuide/FormTransportTypes.cs @@ -0,0 +1,117 @@ +using Microsoft.Extensions.Logging; +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.BusinessLogicsContracts; +using TransportGuideContracts.BindingModels; + +namespace TransportGuide +{ + public partial class FormTransportTypes : Form + { + private readonly ILogger _logger; + private readonly ITransportTypeLogic _logic; + public FormTransportTypes(ILogger logger, ITransportTypeLogic logic) + { + InitializeTransportType(); + _logger = logger; + _logic = logic; + } + + private void FormTransportTypes_Load(object sender, EventArgs e) + { + LoadData(); + } + 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; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTransportType)); + if (service is FormTransportType form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new TransportTypeBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormTransportType)); + if (service is FormTransportType form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + } +} diff --git a/TransportGuide/FormTransportTypes.resx b/TransportGuide/FormTransportTypes.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TransportGuide/FormTransportTypes.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 8ad0a3f..55d6de1 100644 --- a/TransportGuide/Program.cs +++ b/TransportGuide/Program.cs @@ -1,17 +1,54 @@ +using BusinessLogic.BusinessLogic; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using TransportGuideContracts.BusinessLogicsContracts; +using TransportGuideContracts.StoragesContracts; +using TransportGuideDatabaseImplements.Implements; + namespace TransportGuide { internal static class Program { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); - } - } + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + } + } } \ No newline at end of file diff --git a/TransportGuide/TransportGuide.csproj b/TransportGuide/TransportGuide.csproj index b38c828..8b504e4 100644 --- a/TransportGuide/TransportGuide.csproj +++ b/TransportGuide/TransportGuide.csproj @@ -14,6 +14,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive +