diff --git a/git/JurasicZoo/JurasicZoo/ClientCreateRoute.cs b/git/JurasicZoo/JurasicZoo/ClientCreateRoute.cs deleted file mode 100644 index c999838..0000000 --- a/git/JurasicZoo/JurasicZoo/ClientCreateRoute.cs +++ /dev/null @@ -1,20 +0,0 @@ -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 ZooView -{ - public partial class ClientCreateRoute : Form - { - public ClientCreateRoute() - { - InitializeComponent(); - } - } -} diff --git a/git/JurasicZoo/JurasicZoo/ClientRoutes.Designer.cs b/git/JurasicZoo/JurasicZoo/ClientRoutes.Designer.cs deleted file mode 100644 index 352f576..0000000 --- a/git/JurasicZoo/JurasicZoo/ClientRoutes.Designer.cs +++ /dev/null @@ -1,154 +0,0 @@ -namespace ZooView -{ - partial class ClientRoutes - { - /// - /// 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() - { - dataGridView1 = new DataGridView(); - RouteId = new DataGridViewTextBoxColumn(); - RouteName = new DataGridViewTextBoxColumn(); - RouteCost = new DataGridViewTextBoxColumn(); - DateStart = new DataGridViewTextBoxColumn(); - DateFinish = new DataGridViewTextBoxColumn(); - buttonAddRoute = new Button(); - buttonUpdateRoute = new Button(); - buttonRouteDelete = new Button(); - buttonRoutePay = new Button(); - RouteStatus = new DataGridViewTextBoxColumn(); - ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); - SuspendLayout(); - // - // dataGridView1 - // - dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView1.Columns.AddRange(new DataGridViewColumn[] { RouteId, RouteName, RouteCost, DateStart, DateFinish, RouteStatus }); - dataGridView1.Location = new Point(12, 3); - dataGridView1.Name = "dataGridView1"; - dataGridView1.RowTemplate.Height = 25; - dataGridView1.Size = new Size(484, 435); - dataGridView1.TabIndex = 1; - // - // RouteId - // - RouteId.HeaderText = "id"; - RouteId.Name = "RouteId"; - RouteId.Visible = false; - // - // RouteName - // - RouteName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - RouteName.HeaderText = "Название"; - RouteName.Name = "RouteName"; - // - // RouteCost - // - RouteCost.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - RouteCost.HeaderText = "Стоимость"; - RouteCost.Name = "RouteCost"; - // - // DateStart - // - DateStart.HeaderText = "Дата начала"; - DateStart.Name = "DateStart"; - // - // DateFinish - // - DateFinish.HeaderText = "Дата окончания"; - DateFinish.Name = "DateFinish"; - // - // buttonAddRoute - // - buttonAddRoute.Location = new Point(507, 27); - buttonAddRoute.Name = "buttonAddRoute"; - buttonAddRoute.Size = new Size(129, 37); - buttonAddRoute.TabIndex = 2; - buttonAddRoute.Text = "Добавить"; - buttonAddRoute.UseVisualStyleBackColor = true; - // - // buttonUpdateRoute - // - buttonUpdateRoute.Location = new Point(508, 97); - buttonUpdateRoute.Name = "buttonUpdateRoute"; - buttonUpdateRoute.Size = new Size(129, 37); - buttonUpdateRoute.TabIndex = 3; - buttonUpdateRoute.Text = "Изменить"; - buttonUpdateRoute.UseVisualStyleBackColor = true; - // - // buttonRouteDelete - // - buttonRouteDelete.Location = new Point(507, 161); - buttonRouteDelete.Name = "buttonRouteDelete"; - buttonRouteDelete.Size = new Size(129, 37); - buttonRouteDelete.TabIndex = 4; - buttonRouteDelete.Text = "Удалить"; - buttonRouteDelete.UseVisualStyleBackColor = true; - // - // buttonRoutePay - // - buttonRoutePay.Location = new Point(508, 220); - buttonRoutePay.Name = "buttonRoutePay"; - buttonRoutePay.Size = new Size(129, 37); - buttonRoutePay.TabIndex = 5; - buttonRoutePay.Text = "Оплатить"; - buttonRoutePay.UseVisualStyleBackColor = true; - // - // RouteStatus - // - RouteStatus.HeaderText = "Статус оплаты"; - RouteStatus.Name = "RouteStatus"; - // - // Routes - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(649, 450); - Controls.Add(buttonRoutePay); - Controls.Add(buttonRouteDelete); - Controls.Add(buttonUpdateRoute); - Controls.Add(buttonAddRoute); - Controls.Add(dataGridView1); - Name = "Routes"; - Text = "Routes"; - ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); - ResumeLayout(false); - } - - #endregion - - private DataGridView dataGridView1; - private DataGridViewTextBoxColumn RouteId; - private DataGridViewTextBoxColumn RouteName; - private DataGridViewTextBoxColumn RouteCost; - private DataGridViewTextBoxColumn DateStart; - private DataGridViewTextBoxColumn DateFinish; - private Button buttonAddRoute; - private Button buttonUpdateRoute; - private Button buttonRouteDelete; - private Button buttonRoutePay; - private DataGridViewTextBoxColumn RouteStatus; - } -} \ No newline at end of file diff --git a/git/JurasicZoo/JurasicZoo/ClientRoutes.cs b/git/JurasicZoo/JurasicZoo/ClientRoutes.cs deleted file mode 100644 index a58cb4c..0000000 --- a/git/JurasicZoo/JurasicZoo/ClientRoutes.cs +++ /dev/null @@ -1,20 +0,0 @@ -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 ZooView -{ - public partial class ClientRoutes : Form - { - public ClientRoutes() - { - InitializeComponent(); - } - } -} diff --git a/git/JurasicZoo/JurasicZoo/FormClientMain.Designer.cs b/git/JurasicZoo/JurasicZoo/FormClientMain.Designer.cs new file mode 100644 index 0000000..b587fe7 --- /dev/null +++ b/git/JurasicZoo/JurasicZoo/FormClientMain.Designer.cs @@ -0,0 +1,129 @@ +namespace ZooView +{ + partial class FormClientMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip1 = new MenuStrip(); + создатьМаршрутToolStripMenuItem = new ToolStripMenuItem(); + оплатитьМаршрутToolStripMenuItem = new ToolStripMenuItem(); + получитьОтчетToolStripMenuItem = new ToolStripMenuItem(); + вДокументToolStripMenuItem = new ToolStripMenuItem(); + наПочтуToolStripMenuItem = new ToolStripMenuItem(); + button1 = new Button(); + button2 = new Button(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { создатьМаршрутToolStripMenuItem, оплатитьМаршрутToolStripMenuItem, получитьОтчетToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(800, 24); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // создатьМаршрутToolStripMenuItem + // + создатьМаршрутToolStripMenuItem.Name = "создатьМаршрутToolStripMenuItem"; + создатьМаршрутToolStripMenuItem.Size = new Size(116, 20); + создатьМаршрутToolStripMenuItem.Text = "Создать маршрут"; + создатьМаршрутToolStripMenuItem.Click += создатьМаршрутToolStripMenuItem_Click; + // + // оплатитьМаршрутToolStripMenuItem + // + оплатитьМаршрутToolStripMenuItem.Name = "оплатитьМаршрутToolStripMenuItem"; + оплатитьМаршрутToolStripMenuItem.Size = new Size(125, 20); + оплатитьМаршрутToolStripMenuItem.Text = "Оплатить маршрут"; + // + // получитьОтчетToolStripMenuItem + // + получитьОтчетToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { вДокументToolStripMenuItem, наПочтуToolStripMenuItem }); + получитьОтчетToolStripMenuItem.Name = "получитьОтчетToolStripMenuItem"; + получитьОтчетToolStripMenuItem.Size = new Size(106, 20); + получитьОтчетToolStripMenuItem.Text = "Получить отчет"; + // + // вДокументToolStripMenuItem + // + вДокументToolStripMenuItem.Name = "вДокументToolStripMenuItem"; + вДокументToolStripMenuItem.Size = new Size(136, 22); + вДокументToolStripMenuItem.Text = "В документ"; + // + // наПочтуToolStripMenuItem + // + наПочтуToolStripMenuItem.Name = "наПочтуToolStripMenuItem"; + наПочтуToolStripMenuItem.Size = new Size(136, 22); + наПочтуToolStripMenuItem.Text = "На почту"; + // + // button1 + // + button1.Location = new Point(156, 186); + button1.Name = "button1"; + button1.Size = new Size(75, 23); + button1.TabIndex = 1; + button1.Text = "button1"; + button1.UseVisualStyleBackColor = true; + // + // button2 + // + button2.Location = new Point(510, 192); + button2.Name = "button2"; + button2.Size = new Size(75, 23); + button2.TabIndex = 2; + button2.Text = "button2"; + button2.UseVisualStyleBackColor = true; + // + // FormClientMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(button2); + Controls.Add(button1); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormClientMain"; + Text = "FormClientMain"; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem создатьМаршрутToolStripMenuItem; + private ToolStripMenuItem оплатитьМаршрутToolStripMenuItem; + private ToolStripMenuItem получитьОтчетToolStripMenuItem; + private ToolStripMenuItem вДокументToolStripMenuItem; + private ToolStripMenuItem наПочтуToolStripMenuItem; + private Button button1; + private Button button2; + } +} \ No newline at end of file diff --git a/git/JurasicZoo/JurasicZoo/FormClientMain.cs b/git/JurasicZoo/JurasicZoo/FormClientMain.cs new file mode 100644 index 0000000..dc4b7b0 --- /dev/null +++ b/git/JurasicZoo/JurasicZoo/FormClientMain.cs @@ -0,0 +1,30 @@ +using ZooView; +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 ZooView +{ + public partial class FormClientMain : Form + { + public FormClientMain() + { + InitializeComponent(); + } + + private void создатьМаршрутToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRoutes)); + if (service is FormRoutes form) + { + form.ShowDialog(); + } + } + } +} diff --git a/git/JurasicZoo/JurasicZoo/ClientRoutes.resx b/git/JurasicZoo/JurasicZoo/FormClientMain.resx similarity index 72% rename from git/JurasicZoo/JurasicZoo/ClientRoutes.resx rename to git/JurasicZoo/JurasicZoo/FormClientMain.resx index fca3d87..a0623c8 100644 --- a/git/JurasicZoo/JurasicZoo/ClientRoutes.resx +++ b/git/JurasicZoo/JurasicZoo/FormClientMain.resx @@ -117,42 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - 17, 17 diff --git a/git/JurasicZoo/JurasicZoo/FormPreserve.Designer.cs b/git/JurasicZoo/JurasicZoo/FormPreserve.Designer.cs new file mode 100644 index 0000000..1161eb4 --- /dev/null +++ b/git/JurasicZoo/JurasicZoo/FormPreserve.Designer.cs @@ -0,0 +1,124 @@ +namespace ZooView +{ + partial class FormPreserve + { + /// + /// 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.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.labelCost = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(10, 7); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(86, 7); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(275, 23); + this.textBoxName.TabIndex = 1; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(86, 32); + this.textBoxCost.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(122, 23); + this.textBoxCost.TabIndex = 3; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(10, 32); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(38, 15); + this.labelCost.TabIndex = 2; + this.labelCost.Text = "Цена:"; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(143, 72); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(96, 26); + 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(245, 72); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(97, 26); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(373, 106); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxCost; + private Label labelCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/git/JurasicZoo/JurasicZoo/FormPreserve.cs b/git/JurasicZoo/JurasicZoo/FormPreserve.cs new file mode 100644 index 0000000..366ed42 --- /dev/null +++ b/git/JurasicZoo/JurasicZoo/FormPreserve.cs @@ -0,0 +1,92 @@ +using Microsoft.Extensions.Logging; +using ZooContracts.BindingModels; +using ZooContracts.BusinessLogicsContracts; +using ZooContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ZooContracts.BuisnessLogicsContracts; + + +namespace ZooView +{ + public partial class FormPreserve : Form + { + private readonly ILogger _logger; + private readonly IPreserveLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormPreserve(ILogger logger, IPreserveLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new PreserveSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.PreserveName; + textBoxCost.Text = view.PreservePrice.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new PreserveBindingModel + { + Id = _id ?? 0, + PreserveName = textBoxName.Text, + PreservePrice = Convert.ToDouble(textBoxCost.Text) + }; + 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/git/JurasicZoo/JurasicZoo/FormPreserve.resx b/git/JurasicZoo/JurasicZoo/FormPreserve.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/git/JurasicZoo/JurasicZoo/FormPreserve.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/git/JurasicZoo/JurasicZoo/FormPreserves.Designer.cs b/git/JurasicZoo/JurasicZoo/FormPreserves.Designer.cs new file mode 100644 index 0000000..d839677 --- /dev/null +++ b/git/JurasicZoo/JurasicZoo/FormPreserves.Designer.cs @@ -0,0 +1,138 @@ +namespace ZooView +{ + partial class FormPreserves + { + /// + /// 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.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.ToolsPanel.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 2); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(519, 360); + this.dataGridView.TabIndex = 0; + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.dataGridView); + this.ToolsPanel.Controls.Add(this.buttonRef); + this.ToolsPanel.Controls.Add(this.buttonDel); + this.ToolsPanel.Controls.Add(this.buttonUpd); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(-1, -1); + this.ToolsPanel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(675, 364); + this.ToolsPanel.TabIndex = 1; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(528, 155); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(110, 27); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(528, 107); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(110, 27); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(528, 58); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(110, 27); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(528, 13); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 27); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(673, 361); + this.Controls.Add(this.ToolsPanel); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ToolsPanel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Panel ToolsPanel; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/git/JurasicZoo/JurasicZoo/FormPreserves.cs b/git/JurasicZoo/JurasicZoo/FormPreserves.cs new file mode 100644 index 0000000..fcb5b55 --- /dev/null +++ b/git/JurasicZoo/JurasicZoo/FormPreserves.cs @@ -0,0 +1,114 @@ +using Microsoft.Extensions.Logging; +using ZooContracts.BindingModels; +using ZooContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ZooContracts.BuisnessLogicsContracts; + +namespace ZooView +{ + public partial class FormPreserves : Form + { + private readonly ILogger _logger; + private readonly IPreserveLogic _logic; + public FormPreserves(ILogger logger, IPreserveLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponents_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["PreserveName"].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(FormPreserve)); + if (service is FormPreserve form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPreserve)); + if (service is FormPreserve form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_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 PreserveBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/git/JurasicZoo/JurasicZoo/FormPreserves.resx b/git/JurasicZoo/JurasicZoo/FormPreserves.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/git/JurasicZoo/JurasicZoo/FormPreserves.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/git/JurasicZoo/JurasicZoo/ClientCreateRoute.Designer.cs b/git/JurasicZoo/JurasicZoo/FormRoute.Designer.cs similarity index 70% rename from git/JurasicZoo/JurasicZoo/ClientCreateRoute.Designer.cs rename to git/JurasicZoo/JurasicZoo/FormRoute.Designer.cs index ace2011..5b698ef 100644 --- a/git/JurasicZoo/JurasicZoo/ClientCreateRoute.Designer.cs +++ b/git/JurasicZoo/JurasicZoo/FormRoute.Designer.cs @@ -1,6 +1,6 @@ namespace ZooView { - partial class ClientCreateRoute + partial class FormRoute { /// /// Required designer variable. @@ -28,78 +28,93 @@ /// private void InitializeComponent() { - buttonSave = new Button(); - buttonCancel = new Button(); - groupBoxPreserves = new GroupBox(); + labelName = new Label(); + textBoxName = new TextBox(); + labelPrice = new Label(); + textBoxPrice = new TextBox(); + groupBoxComponents = new GroupBox(); buttonRef = new Button(); buttonDel = new Button(); buttonAdd = new Button(); dataGridView = new DataGridView(); - textBoxPrice = new TextBox(); - labelPrice = new Label(); - textBoxName = new TextBox(); - labelName = new Label(); + buttonCancel = new Button(); + buttonSave = new Button(); id = new DataGridViewTextBoxColumn(); - Preserve = new DataGridViewTextBoxColumn(); - Price = new DataGridViewTextBoxColumn(); - groupBoxPreserves.SuspendLayout(); + Component = new DataGridViewTextBoxColumn(); + groupBoxComponents.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // - // buttonSave + // labelName // - buttonSave.Location = new Point(231, 316); - buttonSave.Margin = new Padding(3, 2, 3, 2); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(110, 26); - buttonSave.TabIndex = 13; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; + labelName.AutoSize = true; + labelName.Location = new Point(14, 11); + labelName.Name = "labelName"; + labelName.Size = new Size(65, 15); + labelName.TabIndex = 0; + labelName.Text = "Название: "; // - // buttonCancel + // textBoxName // - buttonCancel.Location = new Point(347, 316); - buttonCancel.Margin = new Padding(3, 2, 3, 2); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(110, 26); - buttonCancel.TabIndex = 12; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; + textBoxName.Location = new Point(98, 9); + textBoxName.Margin = new Padding(3, 2, 3, 2); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(246, 23); + textBoxName.TabIndex = 1; // - // groupBoxPreserves + // labelPrice // - groupBoxPreserves.Controls.Add(buttonRef); - groupBoxPreserves.Controls.Add(buttonDel); - groupBoxPreserves.Controls.Add(buttonAdd); - groupBoxPreserves.Controls.Add(dataGridView); - groupBoxPreserves.Location = new Point(-4, 66); - groupBoxPreserves.Margin = new Padding(3, 2, 3, 2); - groupBoxPreserves.Name = "groupBoxPreserves"; - groupBoxPreserves.Padding = new Padding(3, 2, 3, 2); - groupBoxPreserves.Size = new Size(562, 239); - groupBoxPreserves.TabIndex = 11; - groupBoxPreserves.TabStop = false; - groupBoxPreserves.Text = "Заповедники"; + labelPrice.AutoSize = true; + labelPrice.Location = new Point(14, 38); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(73, 15); + labelPrice.TabIndex = 2; + labelPrice.Text = "Стоимость: "; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(98, 38); + textBoxPrice.Margin = new Padding(3, 2, 3, 2); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(135, 23); + textBoxPrice.TabIndex = 3; + // + // groupBoxComponents + // + groupBoxComponents.Controls.Add(buttonRef); + groupBoxComponents.Controls.Add(buttonDel); + groupBoxComponents.Controls.Add(buttonAdd); + groupBoxComponents.Controls.Add(dataGridView); + groupBoxComponents.Location = new Point(10, 63); + groupBoxComponents.Margin = new Padding(3, 2, 3, 2); + groupBoxComponents.Name = "groupBoxComponents"; + groupBoxComponents.Padding = new Padding(3, 2, 3, 2); + groupBoxComponents.Size = new Size(562, 239); + groupBoxComponents.TabIndex = 4; + groupBoxComponents.TabStop = false; + groupBoxComponents.Text = "Компоненты"; // // buttonRef // - buttonRef.Location = new Point(439, 146); + buttonRef.Location = new Point(439, 158); buttonRef.Margin = new Padding(3, 2, 3, 2); buttonRef.Name = "buttonRef"; buttonRef.Size = new Size(110, 26); buttonRef.TabIndex = 4; buttonRef.Text = "Обновить"; buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; // // buttonDel // - buttonDel.Location = new Point(439, 89); + buttonDel.Location = new Point(439, 118); buttonDel.Margin = new Padding(3, 2, 3, 2); buttonDel.Name = "buttonDel"; buttonDel.Size = new Size(110, 26); buttonDel.TabIndex = 3; buttonDel.Text = "Удалить"; buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; // // buttonAdd // @@ -110,6 +125,7 @@ buttonAdd.TabIndex = 1; buttonAdd.Text = "Добавить"; buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; // // dataGridView // @@ -118,7 +134,7 @@ dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView.BackgroundColor = Color.White; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { id, Preserve, Price }); + dataGridView.Columns.AddRange(new DataGridViewColumn[] { id, Component }); dataGridView.Location = new Point(5, 20); dataGridView.Margin = new Padding(3, 2, 3, 2); dataGridView.Name = "dataGridView"; @@ -128,39 +144,27 @@ dataGridView.Size = new Size(416, 215); dataGridView.TabIndex = 0; // - // textBoxPrice + // buttonCancel // - textBoxPrice.Location = new Point(84, 41); - textBoxPrice.Margin = new Padding(3, 2, 3, 2); - textBoxPrice.Name = "textBoxPrice"; - textBoxPrice.Size = new Size(135, 23); - textBoxPrice.TabIndex = 10; + buttonCancel.Location = new Point(361, 313); + buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(110, 26); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; // - // labelPrice + // buttonSave // - labelPrice.AutoSize = true; - labelPrice.Location = new Point(0, 41); - labelPrice.Name = "labelPrice"; - labelPrice.Size = new Size(73, 15); - labelPrice.TabIndex = 9; - labelPrice.Text = "Стоимость: "; - // - // textBoxName - // - textBoxName.Location = new Point(84, 12); - textBoxName.Margin = new Padding(3, 2, 3, 2); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(246, 23); - textBoxName.TabIndex = 8; - // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(0, 14); - labelName.Name = "labelName"; - labelName.Size = new Size(65, 15); - labelName.TabIndex = 7; - labelName.Text = "Название: "; + buttonSave.Location = new Point(245, 313); + buttonSave.Margin = new Padding(3, 2, 3, 2); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(110, 26); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; // // id // @@ -170,35 +174,30 @@ id.ReadOnly = true; id.Visible = false; // - // Preserve + // Component // - Preserve.HeaderText = "Заповедник"; - Preserve.MinimumWidth = 6; - Preserve.Name = "Preserve"; - Preserve.ReadOnly = true; + Component.HeaderText = "Компонент"; + Component.MinimumWidth = 6; + Component.Name = "Component"; + Component.ReadOnly = true; // - // Price - // - Price.HeaderText = "Цена"; - Price.MinimumWidth = 6; - Price.Name = "Price"; - Price.ReadOnly = true; - // - // CreateRoute + // FormRoute // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(554, 355); + ClientSize = new Size(599, 347); Controls.Add(buttonSave); Controls.Add(buttonCancel); - Controls.Add(groupBoxPreserves); + Controls.Add(groupBoxComponents); Controls.Add(textBoxPrice); Controls.Add(labelPrice); Controls.Add(textBoxName); Controls.Add(labelName); - Name = "CreateRoute"; - Text = "Создание маршрута"; - groupBoxPreserves.ResumeLayout(false); + Margin = new Padding(3, 2, 3, 2); + Name = "FormRoute"; + Text = "Изделие"; + Load += FormCanned_Load; + groupBoxComponents.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); PerformLayout(); @@ -206,19 +205,18 @@ #endregion - private Button buttonSave; - private Button buttonCancel; - private GroupBox groupBoxPreserves; + private Label labelName; + private TextBox textBoxName; + private Label labelPrice; + private TextBox textBoxPrice; + private GroupBox groupBoxComponents; private Button buttonRef; private Button buttonDel; private Button buttonAdd; private DataGridView dataGridView; + private Button buttonCancel; + private Button buttonSave; private DataGridViewTextBoxColumn id; - private DataGridViewTextBoxColumn Preserve; - private DataGridViewTextBoxColumn Price; - private TextBox textBoxPrice; - private Label labelPrice; - private TextBox textBoxName; - private Label labelName; + private DataGridViewTextBoxColumn Component; } } \ No newline at end of file diff --git a/git/JurasicZoo/JurasicZoo/FormRoute.cs b/git/JurasicZoo/JurasicZoo/FormRoute.cs new file mode 100644 index 0000000..f0ea952 --- /dev/null +++ b/git/JurasicZoo/JurasicZoo/FormRoute.cs @@ -0,0 +1,214 @@ +using Microsoft.Extensions.Logging; +using ZooContracts.BindingModels; +using ZooContracts.BusinessLogicsContracts; +using ZooContracts.SearchModels; +using ZooDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ZooView +{ + public partial class FormRoute : Form + { + private readonly ILogger _logger; + private readonly IRouteLogic _logic; + private int? _id; + private Dictionary _RoutePreserves; + public int Id { set { _id = value; } } + public FormRoute(ILogger logger, IRouteLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _RoutePreserves = new Dictionary(); + } + private void FormCanned_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка маршрута"); + try + { + var view = _logic.ReadElement(new RouteSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.RouteName; + textBoxPrice.Text = view.RoutePrice.ToString(); + _RoutePreserves = view.RoutePreserves ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_RoutePreserves != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _RoutePreserves) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.PreserveName }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + 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(FormRoutePreserves)); + if (service is FormRoutePreserves form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.PreserveModel == null) + { + return; + } + _logger.LogInformation("Добавление нового заповедника:{ PreserveName}", form.PreserveModel.PreserveName); + if (_RoutePreserves.ContainsKey(form.Id)) + { + _RoutePreserves[form.Id] = (form.PreserveModel + ); + } + else + { + _RoutePreserves.Add(form.Id, (form.PreserveModel + )); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRoutePreserves)); + if (service is FormRoutePreserves form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.PreserveModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента:{ PreserveName}", form.PreserveModel.PreserveName); + _RoutePreserves[form.Id] = (form.PreserveModel); + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента:{ PreserveName}-{ Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _RoutePreserves?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_RoutePreserves == null || _RoutePreserves.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new RouteBindingModel + { + Id = _id ?? 0, + ClientId=1, + RouteName = textBoxName.Text, + RoutePrice = Convert.ToDouble(textBoxPrice.Text), + + RoutePreserves = _RoutePreserves + }; + 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(); + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _RoutePreserves) + { + price += ((elem.Value?.PreservePrice ?? 0)); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/git/JurasicZoo/JurasicZoo/ClientCreateRoute.resx b/git/JurasicZoo/JurasicZoo/FormRoute.resx similarity index 100% rename from git/JurasicZoo/JurasicZoo/ClientCreateRoute.resx rename to git/JurasicZoo/JurasicZoo/FormRoute.resx diff --git a/git/JurasicZoo/JurasicZoo/FormRoutePreserves.Designer.cs b/git/JurasicZoo/JurasicZoo/FormRoutePreserves.Designer.cs new file mode 100644 index 0000000..5516ce0 --- /dev/null +++ b/git/JurasicZoo/JurasicZoo/FormRoutePreserves.Designer.cs @@ -0,0 +1,101 @@ +namespace ZooView +{ + partial class FormRoutePreserves + { + /// + /// 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() + { + labelComponent = new Label(); + comboBoxComponent = new ComboBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(10, 7); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(72, 15); + labelComponent.TabIndex = 0; + labelComponent.Text = "Заповедник"; + // + // comboBoxComponent + // + comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(104, 7); + comboBoxComponent.Margin = new Padding(3, 2, 3, 2); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(235, 23); + comboBoxComponent.TabIndex = 1; + // + // buttonCancel + // + buttonCancel.Location = new Point(253, 70); + buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(86, 31); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(168, 70); + buttonSave.Margin = new Padding(3, 2, 3, 2); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(79, 31); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // FormRoutePreserves + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(373, 110); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(comboBoxComponent); + Controls.Add(labelComponent); + Margin = new Padding(3, 2, 3, 2); + Name = "FormRoutePreserves"; + Text = "Заповедник маршрута"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelComponent; + private ComboBox comboBoxComponent; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/git/JurasicZoo/JurasicZoo/FormRoutePreserves.cs b/git/JurasicZoo/JurasicZoo/FormRoutePreserves.cs new file mode 100644 index 0000000..aab974b --- /dev/null +++ b/git/JurasicZoo/JurasicZoo/FormRoutePreserves.cs @@ -0,0 +1,79 @@ +using ZooContracts.BusinessLogicsContracts; +using ZooContracts.ViewModels; +using ZooDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ZooContracts.BuisnessLogicsContracts; + +namespace ZooView +{ + public partial class FormRoutePreserves : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + public IPreserveModel? PreserveModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + + public FormRoutePreserves(IPreserveLogic logic) + { + InitializeComponent(); + + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "PreserveName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/git/JurasicZoo/JurasicZoo/FormRoutePreserves.resx b/git/JurasicZoo/JurasicZoo/FormRoutePreserves.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/git/JurasicZoo/JurasicZoo/FormRoutePreserves.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/git/JurasicZoo/JurasicZoo/FormRoutes.Designer.cs b/git/JurasicZoo/JurasicZoo/FormRoutes.Designer.cs index 0a1b8c7..7170ad5 100644 --- a/git/JurasicZoo/JurasicZoo/FormRoutes.Designer.cs +++ b/git/JurasicZoo/JurasicZoo/FormRoutes.Designer.cs @@ -1,191 +1,148 @@ -namespace JurasicZoo +namespace ZooView { - partial class FormRoutes - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + 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); - } + /// + /// 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 + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - menuStrip1 = new MenuStrip(); - справочникиToolStripMenuItem = new ToolStripMenuItem(); - заповедникиToolStripMenuItem = new ToolStripMenuItem(); - отчетыToolStripMenuItem = new ToolStripMenuItem(); - выводВdocToolStripMenuItem = new ToolStripMenuItem(); - выводВxlxToolStripMenuItem = new ToolStripMenuItem(); - отправитьНаПочтуToolStripMenuItem = new ToolStripMenuItem(); - dataGridView1 = new DataGridView(); - checkedListBoxPreserves = new CheckedListBox(); - RouteId = new DataGridViewTextBoxColumn(); - Preserves = new DataGridViewTextBoxColumn(); - Datestart = new DataGridViewTextBoxColumn(); - DateFinish = new DataGridViewTextBoxColumn(); - Status = new DataGridViewTextBoxColumn(); - buttonUpd = new Button(); - menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); - SuspendLayout(); - // - // menuStrip1 - // - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem }); - menuStrip1.Location = new Point(0, 0); - menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(876, 24); - menuStrip1.TabIndex = 0; - menuStrip1.Text = "menuStrip1"; - // - // справочникиToolStripMenuItem - // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заповедникиToolStripMenuItem }); - справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - справочникиToolStripMenuItem.Size = new Size(94, 20); - справочникиToolStripMenuItem.Text = "Справочники"; - // - // заповедникиToolStripMenuItem - // - заповедникиToolStripMenuItem.Name = "заповедникиToolStripMenuItem"; - заповедникиToolStripMenuItem.Size = new Size(180, 22); - заповедникиToolStripMenuItem.Text = "Заповедники"; - // - // отчетыToolStripMenuItem - // - отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { выводВdocToolStripMenuItem, выводВxlxToolStripMenuItem, отправитьНаПочтуToolStripMenuItem }); - отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - отчетыToolStripMenuItem.Size = new Size(60, 20); - отчетыToolStripMenuItem.Text = "Отчеты"; - // - // выводВdocToolStripMenuItem - // - выводВdocToolStripMenuItem.Name = "выводВdocToolStripMenuItem"; - выводВdocToolStripMenuItem.Size = new Size(183, 22); - выводВdocToolStripMenuItem.Text = "Вывод в .doc"; - // - // выводВxlxToolStripMenuItem - // - выводВxlxToolStripMenuItem.Name = "выводВxlxToolStripMenuItem"; - выводВxlxToolStripMenuItem.Size = new Size(183, 22); - выводВxlxToolStripMenuItem.Text = "Вывод в .xlsx"; - // - // отправитьНаПочтуToolStripMenuItem - // - отправитьНаПочтуToolStripMenuItem.Name = "отправитьНаПочтуToolStripMenuItem"; - отправитьНаПочтуToolStripMenuItem.Size = new Size(183, 22); - отправитьНаПочтуToolStripMenuItem.Text = "Отправить на почту"; - // - // dataGridView1 - // - dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView1.Columns.AddRange(new DataGridViewColumn[] { RouteId, Preserves, Datestart, DateFinish, Status }); - dataGridView1.Location = new Point(12, 27); - dataGridView1.Name = "dataGridView1"; - dataGridView1.RowTemplate.Height = 25; - dataGridView1.Size = new Size(728, 331); - dataGridView1.TabIndex = 1; - // - // checkedListBoxPreserves - // - checkedListBoxPreserves.FormattingEnabled = true; - checkedListBoxPreserves.Location = new Point(746, 27); - checkedListBoxPreserves.Name = "checkedListBoxPreserves"; - checkedListBoxPreserves.Size = new Size(120, 94); - checkedListBoxPreserves.TabIndex = 2; - // - // RouteId - // - RouteId.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - RouteId.HeaderText = "Номер маршрута"; - RouteId.Name = "RouteId"; - // - // Preserves - // - Preserves.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - Preserves.HeaderText = "Заповедники"; - Preserves.Name = "Preserves"; - // - // Datestart - // - Datestart.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - Datestart.HeaderText = "Дата начала"; - Datestart.Name = "Datestart"; - // - // DateFinish - // - DateFinish.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - DateFinish.HeaderText = "Дата окончание"; - DateFinish.Name = "DateFinish"; - // - // Status - // - Status.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - Status.HeaderText = "Статус оплаты"; - Status.Name = "Status"; - // - // buttonUpd - // - buttonUpd.Location = new Point(746, 273); - buttonUpd.Name = "buttonUpd"; - buttonUpd.Size = new Size(118, 51); - buttonUpd.TabIndex = 3; - buttonUpd.Text = "Обновить"; - buttonUpd.UseVisualStyleBackColor = true; - // - // FormRoutes - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(876, 370); - Controls.Add(buttonUpd); - Controls.Add(checkedListBoxPreserves); - Controls.Add(dataGridView1); - Controls.Add(menuStrip1); - MainMenuStrip = menuStrip1; - Name = "FormRoutes"; - Text = "Маршруты"; - menuStrip1.ResumeLayout(false); - menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonAddRoute = new Button(); + buttonUpdateRoute = new Button(); + buttonRouteDelete = new Button(); + buttonRoutePay = new Button(); + menuStrip1 = new MenuStrip(); + получитьОтчетToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + создатьЗаповедникToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonAddRoute + // + buttonAddRoute.Location = new Point(507, 27); + buttonAddRoute.Name = "buttonAddRoute"; + buttonAddRoute.Size = new Size(129, 37); + buttonAddRoute.TabIndex = 2; + buttonAddRoute.Text = "Добавить"; + buttonAddRoute.UseVisualStyleBackColor = true; + buttonAddRoute.Click += buttonAddRoute_Click; + // + // buttonUpdateRoute + // + buttonUpdateRoute.Location = new Point(508, 97); + buttonUpdateRoute.Name = "buttonUpdateRoute"; + buttonUpdateRoute.Size = new Size(129, 37); + buttonUpdateRoute.TabIndex = 3; + buttonUpdateRoute.Text = "Изменить"; + buttonUpdateRoute.UseVisualStyleBackColor = true; + buttonUpdateRoute.Click += buttonUpdateRoute_Click; + // + // buttonRouteDelete + // + buttonRouteDelete.Location = new Point(507, 161); + buttonRouteDelete.Name = "buttonRouteDelete"; + buttonRouteDelete.Size = new Size(129, 37); + buttonRouteDelete.TabIndex = 4; + buttonRouteDelete.Text = "Удалить"; + buttonRouteDelete.UseVisualStyleBackColor = true; + buttonRouteDelete.Click += buttonRouteDelete_Click; + // + // buttonRoutePay + // + buttonRoutePay.Location = new Point(508, 220); + buttonRoutePay.Name = "buttonRoutePay"; + buttonRoutePay.Size = new Size(129, 37); + buttonRoutePay.TabIndex = 5; + buttonRoutePay.Text = "Оплатить"; + buttonRoutePay.UseVisualStyleBackColor = true; + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { получитьОтчетToolStripMenuItem, создатьЗаповедникToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(649, 24); + menuStrip1.TabIndex = 6; + menuStrip1.Text = "menuStrip1"; + // + // получитьОтчетToolStripMenuItem + // + получитьОтчетToolStripMenuItem.Name = "получитьОтчетToolStripMenuItem"; + получитьОтчетToolStripMenuItem.Size = new Size(106, 20); + получитьОтчетToolStripMenuItem.Text = "Получить отчет"; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 27); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(489, 398); + dataGridView.TabIndex = 7; + // + // создатьЗаповедникToolStripMenuItem + // + создатьЗаповедникToolStripMenuItem.Name = "создатьЗаповедникToolStripMenuItem"; + создатьЗаповедникToolStripMenuItem.Size = new Size(128, 20); + создатьЗаповедникToolStripMenuItem.Text = "Создать заповедник"; + создатьЗаповедникToolStripMenuItem.Click += создатьЗаповедникToolStripMenuItem_Click; + // + // FormRoutes + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(649, 450); + Controls.Add(dataGridView); + Controls.Add(buttonRoutePay); + Controls.Add(buttonRouteDelete); + Controls.Add(buttonUpdateRoute); + Controls.Add(buttonAddRoute); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormRoutes"; + Text = "Routes"; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion - - private MenuStrip menuStrip1; - private ToolStripMenuItem справочникиToolStripMenuItem; - private ToolStripMenuItem заповедникиToolStripMenuItem; - private ToolStripMenuItem отчетыToolStripMenuItem; - private ToolStripMenuItem выводВdocToolStripMenuItem; - private ToolStripMenuItem выводВxlxToolStripMenuItem; - private ToolStripMenuItem отправитьНаПочтуToolStripMenuItem; - private DataGridView dataGridView1; - private CheckedListBox checkedListBoxPreserves; - private DataGridViewTextBoxColumn RouteId; - private DataGridViewTextBoxColumn Preserves; - private DataGridViewTextBoxColumn Datestart; - private DataGridViewTextBoxColumn DateFinish; - private DataGridViewTextBoxColumn Status; - private Button buttonUpd; - } -} + #endregion + private Button buttonAddRoute; + private Button buttonUpdateRoute; + private Button buttonRouteDelete; + private Button buttonRoutePay; + private MenuStrip menuStrip1; + private ToolStripMenuItem получитьОтчетToolStripMenuItem; + private DataGridView dataGridView; + private ToolStripMenuItem создатьЗаповедникToolStripMenuItem; + } +} \ No newline at end of file diff --git a/git/JurasicZoo/JurasicZoo/FormRoutes.cs b/git/JurasicZoo/JurasicZoo/FormRoutes.cs index d96d059..2ceee50 100644 --- a/git/JurasicZoo/JurasicZoo/FormRoutes.cs +++ b/git/JurasicZoo/JurasicZoo/FormRoutes.cs @@ -1,10 +1,86 @@ -namespace JurasicZoo +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 ZooContracts.BusinessLogicsContracts; + +namespace ZooView { - public partial class FormRoutes : Form - { - public FormRoutes() - { - InitializeComponent(); - } - } + public partial class FormRoutes : Form + { + private readonly ILogger _logger; + private readonly IRouteLogic _logic; + public FormRoutes(ILogger logger, IRouteLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormCanneds_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["RoutePreserves"].Visible = false; + dataGridView.Columns["RouteName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка маршрутов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки маршрутов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void buttonAddRoute_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 buttonUpdateRoute_Click(object sender, EventArgs e) + { + + } + + private void buttonRouteDelete_Click(object sender, EventArgs e) + { + + } + + private void создатьЗаповедникToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPreserves)); + if (service is FormPreserves form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } } diff --git a/git/JurasicZoo/JurasicZoo/FormRoutes.resx b/git/JurasicZoo/JurasicZoo/FormRoutes.resx index b1cfa50..a0623c8 100644 --- a/git/JurasicZoo/JurasicZoo/FormRoutes.resx +++ b/git/JurasicZoo/JurasicZoo/FormRoutes.resx @@ -120,34 +120,4 @@ 17, 17 - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - \ No newline at end of file diff --git a/git/JurasicZoo/JurasicZoo/Program.cs b/git/JurasicZoo/JurasicZoo/Program.cs index b246e26..579cebf 100644 --- a/git/JurasicZoo/JurasicZoo/Program.cs +++ b/git/JurasicZoo/JurasicZoo/Program.cs @@ -1,17 +1,66 @@ -namespace JurasicZoo +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using ZooBusinessLogic.BusinessLogic; +using ZooContracts.BindingModels; +using ZooContracts.BusinessLogicsContracts; +using ZooContracts.StorageContracts; +using ZooDataBaseImplement.Implements; +using System; +using Microsoft.EntityFrameworkCore.Design; +using ZooView; +using ZooContracts.BuisnessLogicsContracts; + +namespace ZooView { - 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 FormRoutes()); - } - } -} \ No newline at end of file + internal static class Program + { + 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); + }); + 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(); + services.AddTransient(); + + services.AddTransient(); + + } + + } +} diff --git a/git/JurasicZoo/JurasicZoo/ZooView.csproj b/git/JurasicZoo/JurasicZoo/ZooView.csproj index e82dbb3..9053a30 100644 --- a/git/JurasicZoo/JurasicZoo/ZooView.csproj +++ b/git/JurasicZoo/JurasicZoo/ZooView.csproj @@ -16,6 +16,7 @@ + diff --git a/git/JurasicZoo/ZooBusinessLogic/BusinessLogic/RouteLogic.cs b/git/JurasicZoo/ZooBusinessLogic/BusinessLogic/RouteLogic.cs index b7c4f51..62a9afa 100644 --- a/git/JurasicZoo/ZooBusinessLogic/BusinessLogic/RouteLogic.cs +++ b/git/JurasicZoo/ZooBusinessLogic/BusinessLogic/RouteLogic.cs @@ -35,6 +35,22 @@ namespace ZooBusinessLogic.BusinessLogic _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } + public RouteViewModel? ReadElement(RouteSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement.RouteName:{RouteName}.Id:{ Id}", model.RouteName, model.Id); + var element = _routeStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } public bool Create(RouteBindingModel model) { @@ -46,6 +62,27 @@ namespace ZooBusinessLogic.BusinessLogic } return true; } + public bool Update(RouteBindingModel model) + { + CheckModel(model); + if (_routeStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(RouteBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_routeStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } public bool CheckRoutePay(RouteBindingModel model, RouteStatus status) { CheckModel(model); @@ -69,8 +106,7 @@ namespace ZooBusinessLogic.BusinessLogic { return CheckRoutePay(model, RouteStatus.Оплачен); } - private void CheckModel(RouteBindingModel model, bool withParams = - true) + private void CheckModel(RouteBindingModel model, bool withParams = true) { if (model == null) { @@ -82,14 +118,21 @@ namespace ZooBusinessLogic.BusinessLogic } if (string.IsNullOrEmpty(model.RouteName)) { - throw new ArgumentNullException("Нет названия маршрута", - nameof(model.RouteName)); + throw new ArgumentNullException("Нет названия изделия", nameof(model.RouteName)); } if (model.RoutePrice <= 0) { - throw new ArgumentNullException("Стоимость маршрута должна быть >0", nameof(model.RoutePrice)); + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.RoutePrice)); + } + _logger.LogInformation("Canned. RouteName:{RouteName}.Price:{Price}.Id: { Id}", model.RouteName, model.RoutePrice, model.Id); + var element = _routeStorage.GetElement(new RouteSearchModel + { + RouteName = model.RouteName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); } - _logger.LogInformation("Route. RouteName:{RouteName}.RoutePrice:{ RoutePrice} Id: { Id}", model.RouteName, model.RoutePrice, model.Id); } } diff --git a/git/JurasicZoo/ZooClientApp/Controllers/HomeController.cs b/git/JurasicZoo/ZooClientApp/Controllers/HomeController.cs index 6cf2e43..49b5a53 100644 --- a/git/JurasicZoo/ZooClientApp/Controllers/HomeController.cs +++ b/git/JurasicZoo/ZooClientApp/Controllers/HomeController.cs @@ -1,32 +1,159 @@ using Microsoft.AspNetCore.Mvc; using System.Diagnostics; using ZooClientApp.Models; +using ZooContracts.BindingModels; +using ZooContracts.ViewModels; namespace ZooClientApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; - public HomeController(ILogger logger) { _logger = logger; } - public IActionResult Index() { - return View(); + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return + View(APIClient.GetRequest>($"api/main/getroutes?clientId={APIClient.Client.Id}")); } - + [HttpGet] public IActionResult Privacy() { - return View(); + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.Client); } - - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [HttpPost] + public void Privacy(string login, string password, string fio) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(login) || + string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + { + throw new Exception("Введите логин, пароль и ФИО"); + } + APIClient.PostRequest("api/client/updatedata", new + ClientBindingModel + { + Id = APIClient.Client.Id, + ClientFIO = fio, + EMail = login, + Password = password + }); + APIClient.Client.ClientFIO = fio; + APIClient.Client.Email = login; + APIClient.Client.Password = password; + Response.Redirect("Index"); + } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, + NoStore = true)] public IActionResult Error() { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + return View(new ErrorViewModel + { + RequestId = + Activity.Current?.Id ?? HttpContext.TraceIdentifier + }); + } + [HttpGet] + public IActionResult Enter() + { + return View(); + } + [HttpPost] + public void Enter(string login, string password) + { + if (string.IsNullOrEmpty(login) || + string.IsNullOrEmpty(password)) + { + throw new Exception("Введите логин и пароль"); + } + APIClient.Client = + APIClient.GetRequest($"api/client/login?login={login}&password={password}"); + if (APIClient.Client == null) + { + throw new Exception("Неверный логин/пароль"); + } + Response.Redirect("Index"); + } + [HttpGet] + public IActionResult Register() + { + return View(); + } + [HttpPost] + public void Register(string login, string password, string fio) + { + if (string.IsNullOrEmpty(login) || + string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + { + throw new Exception("Введите логин, пароль и ФИО"); + } + APIClient.PostRequest("api/client/register", new + ClientBindingModel + { + ClientFIO = fio, + EMail = login, + Password = password + }); + Response.Redirect("Enter"); + return; + } + [HttpGet] + public IActionResult Create() + { + ViewBag.Canneds = + APIClient.GetRequest>("api/main/getcannedlist"); + return View(); + } + [HttpPost] + public void Create(int canned, int count) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (count <= 0) + { + throw new Exception("Количество и сумма должны быть больше 0"); + } + APIClient.PostRequest("api/main/createorder", new + RouteBindingModel + { + ClientId = APIClient.Client.Id + + }); + Response.Redirect("Index"); + } + [HttpPost] + public double Calc(int count, int canned) + { + var prod = + APIClient.GetRequest($"api/main/getcanned?cannedId={canned}" + ); + return count * (prod?.PreservePrice ?? 1); + } + + [HttpGet] + public IActionResult Mails() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(); + //return View(APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client.Id}")); } } } \ No newline at end of file diff --git a/git/JurasicZoo/ZooContracts/BindingModels/RouteBindingModel.cs b/git/JurasicZoo/ZooContracts/BindingModels/RouteBindingModel.cs index 8c3b466..9851953 100644 --- a/git/JurasicZoo/ZooContracts/BindingModels/RouteBindingModel.cs +++ b/git/JurasicZoo/ZooContracts/BindingModels/RouteBindingModel.cs @@ -17,7 +17,7 @@ namespace ZooContracts.BindingModels public RouteStatus Status { get; set; } = RouteStatus.Неоплачен; public DateTime DateStart { get; set; } public DateTime DateFinish { get; set; } - public Dictionary RoutePreserves + public Dictionary RoutePreserves { get; set; diff --git a/git/JurasicZoo/ZooContracts/BusinessLogicsContracts/IRouteLogic.cs b/git/JurasicZoo/ZooContracts/BusinessLogicsContracts/IRouteLogic.cs index de5cd79..88f06fa 100644 --- a/git/JurasicZoo/ZooContracts/BusinessLogicsContracts/IRouteLogic.cs +++ b/git/JurasicZoo/ZooContracts/BusinessLogicsContracts/IRouteLogic.cs @@ -13,7 +13,11 @@ namespace ZooContracts.BusinessLogicsContracts public interface IRouteLogic { List? ReadList(RouteSearchModel? model); + + RouteViewModel? ReadElement(RouteSearchModel model); bool Create(RouteBindingModel model); + bool Update(RouteBindingModel model); + bool Delete(RouteBindingModel model); bool CheckRoutePay(RouteBindingModel model,RouteStatus status); bool RouteWasPaid(RouteBindingModel model); } diff --git a/git/JurasicZoo/ZooContracts/ViewModels/RouteViewModel.cs b/git/JurasicZoo/ZooContracts/ViewModels/RouteViewModel.cs index 1ab8dbf..f1a5669 100644 --- a/git/JurasicZoo/ZooContracts/ViewModels/RouteViewModel.cs +++ b/git/JurasicZoo/ZooContracts/ViewModels/RouteViewModel.cs @@ -10,7 +10,7 @@ using ZooDataModels.Models; namespace ZooContracts.ViewModels { - public class RouteViewModel + public class RouteViewModel : IRouteModel { [DisplayName("Номер")] public int Id { get; set; } @@ -28,7 +28,7 @@ namespace ZooContracts.ViewModels public DateTime DateStart { get; set; } [DisplayName("Дата окончания")] public DateTime DateFinish { get; set; } - public Dictionary Preserves + public Dictionary RoutePreserves { get; set; diff --git a/git/JurasicZoo/ZooDataBaseImplement/Implements/PreserveStorage.cs b/git/JurasicZoo/ZooDataBaseImplement/Implements/PreserveStorage.cs index 2f59fda..484aa7e 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Implements/PreserveStorage.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Implements/PreserveStorage.cs @@ -5,12 +5,13 @@ using System.Text; using System.Threading.Tasks; using ZooContracts.BindingModels; using ZooContracts.SearchModels; +using ZooContracts.StorageContracts; using ZooContracts.ViewModels; using ZooDataBaseImplement.Models; namespace ZooDataBaseImplement.Implements { - public class PreserveStorage + public class PreserveStorage :IPreserveStorage { public List GetFullList() { diff --git a/git/JurasicZoo/ZooDataBaseImplement/Implements/RouteStorage.cs b/git/JurasicZoo/ZooDataBaseImplement/Implements/RouteStorage.cs index 8c49ef9..93f44b7 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Implements/RouteStorage.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Implements/RouteStorage.cs @@ -63,14 +63,14 @@ namespace ZooDataBaseImplement.Implements public RouteViewModel? Insert(RouteBindingModel model) { using var context = new ZooDatabase(); - var newCanned = Route.Create(context, model); - if (newCanned == null) + var newRoute = Route.Create(context, model); + if (newRoute == null) { return null; } - context.Routes.Add(newCanned); + context.Routes.Add(newRoute); context.SaveChanges(); - return newCanned.GetViewModel; + return newRoute.GetViewModel; } public RouteViewModel? Update(RouteBindingModel model) @@ -87,6 +87,7 @@ namespace ZooDataBaseImplement.Implements } route.Update(model); context.SaveChanges(); + route.UpdateComponents(context, model); transaction.Commit(); return route.GetViewModel; } diff --git a/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240428140917_InitialCreate.Designer.cs b/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240530120856_InitialCreate.Designer.cs similarity index 97% rename from git/JurasicZoo/ZooDataBaseImplement/Migrations/20240428140917_InitialCreate.Designer.cs rename to git/JurasicZoo/ZooDataBaseImplement/Migrations/20240530120856_InitialCreate.Designer.cs index 9b9d55d..f639dc1 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240428140917_InitialCreate.Designer.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240530120856_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using ZooDataBaseImplement; namespace ZooDataBaseImplement.Migrations { [DbContext(typeof(ZooDatabase))] - [Migration("20240428140917_InitialCreate")] + [Migration("20240530120856_InitialCreate")] partial class InitialCreate { /// @@ -142,9 +142,6 @@ namespace ZooDataBaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("Count") - .HasColumnType("int"); - b.Property("PreserveID") .HasColumnType("int"); @@ -155,6 +152,8 @@ namespace ZooDataBaseImplement.Migrations b.HasIndex("PreserveID"); + b.HasIndex("RouteID"); + b.ToTable("RoutePreserves"); }); @@ -186,7 +185,7 @@ namespace ZooDataBaseImplement.Migrations b.HasOne("ZooDataBaseImplement.Models.Route", "Route") .WithMany("Preserves") - .HasForeignKey("PreserveID") + .HasForeignKey("RouteID") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); diff --git a/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240428140917_InitialCreate.cs b/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240530120856_InitialCreate.cs similarity index 95% rename from git/JurasicZoo/ZooDataBaseImplement/Migrations/20240428140917_InitialCreate.cs rename to git/JurasicZoo/ZooDataBaseImplement/Migrations/20240530120856_InitialCreate.cs index 9916061..14ea651 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240428140917_InitialCreate.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240530120856_InitialCreate.cs @@ -92,8 +92,7 @@ namespace ZooDataBaseImplement.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), RouteID = table.Column(type: "int", nullable: false), - PreserveID = table.Column(type: "int", nullable: false), - Count = table.Column(type: "int", nullable: false) + PreserveID = table.Column(type: "int", nullable: false) }, constraints: table => { @@ -105,8 +104,8 @@ namespace ZooDataBaseImplement.Migrations principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_RoutePreserves_Routes_PreserveID", - column: x => x.PreserveID, + name: "FK_RoutePreserves_Routes_RouteID", + column: x => x.RouteID, principalTable: "Routes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); @@ -122,6 +121,11 @@ namespace ZooDataBaseImplement.Migrations table: "RoutePreserves", column: "PreserveID"); + migrationBuilder.CreateIndex( + name: "IX_RoutePreserves_RouteID", + table: "RoutePreserves", + column: "RouteID"); + migrationBuilder.CreateIndex( name: "IX_Routes_ClientId", table: "Routes", diff --git a/git/JurasicZoo/ZooDataBaseImplement/Migrations/ZooDatabaseModelSnapshot.cs b/git/JurasicZoo/ZooDataBaseImplement/Migrations/ZooDatabaseModelSnapshot.cs index 88d64c2..253d970 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Migrations/ZooDatabaseModelSnapshot.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Migrations/ZooDatabaseModelSnapshot.cs @@ -139,9 +139,6 @@ namespace ZooDataBaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("Count") - .HasColumnType("int"); - b.Property("PreserveID") .HasColumnType("int"); @@ -152,6 +149,8 @@ namespace ZooDataBaseImplement.Migrations b.HasIndex("PreserveID"); + b.HasIndex("RouteID"); + b.ToTable("RoutePreserves"); }); @@ -183,7 +182,7 @@ namespace ZooDataBaseImplement.Migrations b.HasOne("ZooDataBaseImplement.Models.Route", "Route") .WithMany("Preserves") - .HasForeignKey("PreserveID") + .HasForeignKey("RouteID") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); diff --git a/git/JurasicZoo/ZooDataBaseImplement/Models/Route.cs b/git/JurasicZoo/ZooDataBaseImplement/Models/Route.cs index 7a94946..8787746 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Models/Route.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Models/Route.cs @@ -23,23 +23,23 @@ namespace ZooDataBaseImplement.Models public DateTime DateStart { get; private set; } public DateTime DateFinish { get; private set; } - private Dictionary? _routepreserves = + private Dictionary? _routePreserves = null; [NotMapped] - public Dictionary RoutePreserves + public Dictionary RoutePreserves { get { - if (_routepreserves == null) + if (_routePreserves == null) { - _routepreserves = Preserves + _routePreserves = Preserves .ToDictionary(recRP => recRP.PreserveID, recRP => - (recRP.Preserve as IPreserveModel, recRP.Count)); + (recRP.Preserve as IPreserveModel)); } - return _routepreserves; + return _routePreserves; } } - [ForeignKey("PreserveID")] + [ForeignKey("RouteID")] public virtual List Preserves { get; set; } = new(); public static Route Create(ZooDatabase context, RouteBindingModel model) @@ -56,8 +56,7 @@ namespace ZooDataBaseImplement.Models DateFinish = model.DateFinish, Preserves = model.RoutePreserves.Select(x => new RoutePreserve { - Preserve = context.Preserves.First(y => y.Id == x.Key), - Count = x.Value.Item2 + Preserve = context.Preserves.First(y => y.Id == x.Key) }).ToList() }; } @@ -67,6 +66,8 @@ namespace ZooDataBaseImplement.Models { return; } + RouteName = model.RouteName; + RoutePrice = model.RoutePrice; Status = model.Status; DateStart = model.DateStart; DateFinish = model.DateFinish; @@ -83,5 +84,28 @@ namespace ZooDataBaseImplement.Models DateStart= DateStart, DateFinish=DateFinish, }; + public void UpdateComponents(ZooDatabase context, + RouteBindingModel model) + { + var routePreserves = context.RoutePreserves.Where(rec => + rec.RouteID == model.Id).ToList(); + if (routePreserves != null && routePreserves.Count > 0) + { // удалили те, которых нет в модели + context.RoutePreserves.RemoveRange(routePreserves.Where(rec + => !model.RoutePreserves.ContainsKey(rec.PreserveID))); + context.SaveChanges(); + } + var route = context.Routes.First(x => x.Id == Id); + foreach (var pc in model.RoutePreserves) + { + context.RoutePreserves.Add(new RoutePreserve + { + Route = route, + Preserve = context.Preserves.First(x => x.Id == pc.Key) + }); + context.SaveChanges(); + } + _routePreserves = null; + } } } diff --git a/git/JurasicZoo/ZooDataBaseImplement/Models/RoutePreserve.cs b/git/JurasicZoo/ZooDataBaseImplement/Models/RoutePreserve.cs index ffd091d..a7a052f 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Models/RoutePreserve.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Models/RoutePreserve.cs @@ -16,8 +16,6 @@ namespace ZooDataBaseImplement.Models public int RouteID { get; set; } [Required] public int PreserveID { get; set; } - [Required] - public int Count { get; set; } public virtual Preserve Preserve { get; set; } = new(); public virtual Route Route { get; set; } = new(); } diff --git a/git/JurasicZoo/ZooDataBaseImplement/ZooDataBaseImplement.csproj b/git/JurasicZoo/ZooDataBaseImplement/ZooDataBaseImplement.csproj index d6bb1f9..a44b9bc 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/ZooDataBaseImplement.csproj +++ b/git/JurasicZoo/ZooDataBaseImplement/ZooDataBaseImplement.csproj @@ -19,4 +19,8 @@ + + + + diff --git a/git/JurasicZoo/ZooDataModels/Models/IRouteModel.cs b/git/JurasicZoo/ZooDataModels/Models/IRouteModel.cs index 5bc8d7f..318acea 100644 --- a/git/JurasicZoo/ZooDataModels/Models/IRouteModel.cs +++ b/git/JurasicZoo/ZooDataModels/Models/IRouteModel.cs @@ -15,6 +15,6 @@ namespace ZooDataModels.Models RouteStatus Status { get; } DateTime DateStart { get; } DateTime DateFinish { get; } - Dictionary RoutePreserves{ get; } + Dictionary RoutePreserves{ get; } } }