From c358e0c5c86679593706e21fc94c5021974df99a Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Sat, 9 Mar 2024 21:18:26 +0400 Subject: [PATCH] lab 1 hard: error correction --- .../BlacksmithWorkshop/FormSupply.Designer.cs | 200 +++++++-------- .../BlacksmithWorkshop/FormSupply.cs | 242 +++++++++--------- 2 files changed, 221 insertions(+), 221 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs index e350ec8..5e2f0fd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs @@ -1,108 +1,108 @@ namespace BlacksmithWorkshop { - partial class FormSupply - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormSupply + { + /// + /// 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() - { - ShopComboBox = new ComboBox(); - ManufactureComboBox = new ComboBox(); - CountTextBox = new TextBox(); - button1 = new Button(); - button2 = new Button(); - SuspendLayout(); - // - // ShopComboBox - // - ShopComboBox.DropDownStyle = ComboBoxStyle.DropDownList; - ShopComboBox.FormattingEnabled = true; - ShopComboBox.Location = new Point(12, 12); - ShopComboBox.Name = "ShopComboBox"; - ShopComboBox.Size = new Size(224, 23); - ShopComboBox.TabIndex = 0; - // - // ManufactureComboBox - // - ManufactureComboBox.DropDownStyle = ComboBoxStyle.DropDownList; - ManufactureComboBox.FormattingEnabled = true; - ManufactureComboBox.Location = new Point(242, 12); - ManufactureComboBox.Name = "ManufactureComboBox"; - ManufactureComboBox.Size = new Size(224, 23); - ManufactureComboBox.TabIndex = 1; - // - // CountTextBox - // - CountTextBox.Location = new Point(472, 12); - CountTextBox.Name = "CountTextBox"; - CountTextBox.Size = new Size(224, 23); - CountTextBox.TabIndex = 2; - // - // button1 - // - button1.Location = new Point(162, 47); - button1.Name = "button1"; - button1.Size = new Size(157, 28); - button1.TabIndex = 3; - button1.Text = "Сохранить"; - button1.UseVisualStyleBackColor = true; - button1.Click += SaveButton_Click; - // - // button2 - // - button2.Location = new Point(394, 47); - button2.Name = "button2"; - button2.Size = new Size(157, 28); - button2.TabIndex = 4; - button2.Text = "Отмена"; - button2.UseVisualStyleBackColor = true; - button2.Click += CancelButton_Click; - // - // FormSupply - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(707, 87); - Controls.Add(button2); - Controls.Add(button1); - Controls.Add(CountTextBox); - Controls.Add(ManufactureComboBox); - Controls.Add(ShopComboBox); - Name = "FormSupply"; - StartPosition = FormStartPosition.CenterParent; - Text = "Пополнение магазина"; - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + ShopComboBox = new ComboBox(); + ManufactureComboBox = new ComboBox(); + CountTextBox = new TextBox(); + buttonSave = new Button(); + buttonCansel = new Button(); + SuspendLayout(); + // + // ShopComboBox + // + ShopComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + ShopComboBox.FormattingEnabled = true; + ShopComboBox.Location = new Point(12, 12); + ShopComboBox.Name = "ShopComboBox"; + ShopComboBox.Size = new Size(224, 23); + ShopComboBox.TabIndex = 0; + // + // ManufactureComboBox + // + ManufactureComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + ManufactureComboBox.FormattingEnabled = true; + ManufactureComboBox.Location = new Point(242, 12); + ManufactureComboBox.Name = "ManufactureComboBox"; + ManufactureComboBox.Size = new Size(224, 23); + ManufactureComboBox.TabIndex = 1; + // + // CountTextBox + // + CountTextBox.Location = new Point(472, 12); + CountTextBox.Name = "CountTextBox"; + CountTextBox.Size = new Size(224, 23); + CountTextBox.TabIndex = 2; + // + // buttonSave + // + buttonSave.Location = new Point(162, 47); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(157, 28); + buttonSave.TabIndex = 3; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += SaveButton_Click; + // + // buttonCansel + // + buttonCansel.Location = new Point(394, 47); + buttonCansel.Name = "buttonCansel"; + buttonCansel.Size = new Size(157, 28); + buttonCansel.TabIndex = 4; + buttonCansel.Text = "Отмена"; + buttonCansel.UseVisualStyleBackColor = true; + buttonCansel.Click += CancelButton_Click; + // + // FormSupply + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(707, 87); + Controls.Add(buttonCansel); + Controls.Add(buttonSave); + Controls.Add(CountTextBox); + Controls.Add(ManufactureComboBox); + Controls.Add(ShopComboBox); + Name = "FormSupply"; + StartPosition = FormStartPosition.CenterParent; + Text = "Пополнение магазина"; + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private ComboBox ShopComboBox; - private ComboBox ManufactureComboBox; - private TextBox CountTextBox; - private Button button1; - private Button button2; - } + private ComboBox ShopComboBox; + private ComboBox ManufactureComboBox; + private TextBox CountTextBox; + private Button buttonSave; + private Button buttonCansel; + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs index 4288560..9742c1e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs @@ -14,126 +14,126 @@ using System.Windows.Forms; namespace BlacksmithWorkshop { - public partial class FormSupply : Form - { - private readonly List? _manufactureList; - private readonly List? _shopsList; - IShopLogic _shopLogic; - IManufactureLogic _manufactureLogic; - public int ShopId - { - get - { - return Convert.ToInt32(ShopComboBox.SelectedValue); - } - set - { - ShopComboBox.SelectedValue = value; - } - } - public int ManufactureId - { - get - { - return Convert.ToInt32(ManufactureComboBox.SelectedValue); - } - set - { - ManufactureComboBox.SelectedValue = value; - } - } - public IManufactureModel? ManufactureModel - { - get - { - if (_manufactureList == null) - { - return null; - } - foreach (var elem in _manufactureList) - { - if (elem.Id == ManufactureId) - { - return elem; - } - } - return null; - } - } - public int Count - { - get { return Convert.ToInt32(CountTextBox.Text); } - set { CountTextBox.Text = value.ToString(); } - } - public FormSupply(IManufactureLogic ManufactureLogic, IShopLogic shopLogic) - { - InitializeComponent(); - _shopLogic = shopLogic; - _manufactureLogic = ManufactureLogic; - _manufactureList = ManufactureLogic.ReadList(null); - _shopsList = shopLogic.ReadList(null); - if (_manufactureList != null) - { - ManufactureComboBox.DisplayMember = "ManufactureName"; - ManufactureComboBox.ValueMember = "Id"; - ManufactureComboBox.DataSource = _manufactureList; - ManufactureComboBox.SelectedItem = null; - } - if (_shopsList != null) - { - ShopComboBox.DisplayMember = "ShopName"; - ShopComboBox.ValueMember = "Id"; - ShopComboBox.DataSource = _shopsList; - ShopComboBox.SelectedItem = null; - } - } - private void SaveButton_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(CountTextBox.Text)) - { - MessageBox.Show("Заполните поле Количество", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (ManufactureComboBox.SelectedValue == null) - { - MessageBox.Show("Выберите кузнечное изделие", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (ShopComboBox.SelectedValue == null) - { - MessageBox.Show("Выберите магазин", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - try - { - int count = Convert.ToInt32(CountTextBox.Text); - bool res = _shopLogic.ReplenishManufactures( - new ShopSearchModel() { Id = Convert.ToInt32(ShopComboBox.SelectedValue) }, - _manufactureLogic.ReadElement(new() { Id = Convert.ToInt32(ManufactureComboBox.SelectedValue) }), - count - ); - if (!res) - { - throw new Exception("Ошибка при пополнении. Дополнительная информация в логах"); - } - MessageBox.Show("Пополнение прошло успешно"); - DialogResult = DialogResult.OK; - Close(); + public partial class FormSupply : Form + { + private readonly List? _manufactureList; + private readonly List? _shopsList; + IShopLogic _shopLogic; + IManufactureLogic _manufactureLogic; + public int ShopId + { + get + { + return Convert.ToInt32(ShopComboBox.SelectedValue); + } + set + { + ShopComboBox.SelectedValue = value; + } + } + public int ManufactureId + { + get + { + return Convert.ToInt32(ManufactureComboBox.SelectedValue); + } + set + { + ManufactureComboBox.SelectedValue = value; + } + } + public IManufactureModel? ManufactureModel + { + get + { + if (_manufactureList == null) + { + return null; + } + foreach (var elem in _manufactureList) + { + if (elem.Id == ManufactureId) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(CountTextBox.Text); } + set { CountTextBox.Text = value.ToString(); } + } + public FormSupply(IManufactureLogic ManufactureLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _manufactureLogic = ManufactureLogic; + _manufactureList = ManufactureLogic.ReadList(null); + _shopsList = shopLogic.ReadList(null); + if (_manufactureList != null) + { + ManufactureComboBox.DisplayMember = "ManufactureName"; + ManufactureComboBox.ValueMember = "Id"; + ManufactureComboBox.DataSource = _manufactureList; + ManufactureComboBox.SelectedItem = null; + } + if (_shopsList != null) + { + ShopComboBox.DisplayMember = "ShopName"; + ShopComboBox.ValueMember = "Id"; + ShopComboBox.DataSource = _shopsList; + ShopComboBox.SelectedItem = null; + } + } + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (ManufactureComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите кузнечное изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (ShopComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + int count = Convert.ToInt32(CountTextBox.Text); + bool res = _shopLogic.ReplenishManufactures( + new ShopSearchModel() { Id = Convert.ToInt32(ShopComboBox.SelectedValue) }, + _manufactureLogic.ReadElement(new() { Id = Convert.ToInt32(ManufactureComboBox.SelectedValue) }), + count + ); + if (!res) + { + throw new Exception("Ошибка при пополнении. Дополнительная информация в логах"); + } + MessageBox.Show("Пополнение прошло успешно"); + DialogResult = DialogResult.OK; + Close(); - } - catch (Exception) - { - MessageBox.Show("Ошибка пополнения"); - return; - } - } - private void CancelButton_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - } + } + catch (Exception) + { + MessageBox.Show("Ошибка пополнения"); + return; + } + } + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } }