Реализованы формы для работы с мгазинами

This commit is contained in:
Никита Потапов 2024-03-11 11:20:30 +04:00
parent 1ec3a79493
commit 671b74d99b
4 changed files with 247 additions and 40 deletions

View File

@ -140,6 +140,7 @@
buttonSave.TabIndex = 7; buttonSave.TabIndex = 7;
buttonSave.Text = "Сохранить"; buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true; buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
// //
// buttonCancel // buttonCancel
// //
@ -150,6 +151,7 @@
buttonCancel.TabIndex = 8; buttonCancel.TabIndex = 8;
buttonCancel.Text = "Закрыть"; buttonCancel.Text = "Закрыть";
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
// //
// FormShop // FormShop
// //
@ -167,6 +169,7 @@
Controls.Add(labelName); Controls.Add(labelName);
Name = "FormShop"; Name = "FormShop";
Text = "Магазин"; Text = "Магазин";
Load += FormShop_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();

View File

@ -28,12 +28,119 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); comboBoxShop = new ComboBox();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; comboBoxSecure = new ComboBox();
this.ClientSize = new System.Drawing.Size(800, 450); labelShop = new Label();
this.Text = "FormShopSupply"; label2 = new Label();
label3 = new Label();
buttonSupply = new Button();
buttonCancel = new Button();
textBoxCount = new TextBox();
SuspendLayout();
//
// comboBoxShop
//
comboBoxShop.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxShop.FormattingEnabled = true;
comboBoxShop.Location = new Point(125, 6);
comboBoxShop.Name = "comboBoxShop";
comboBoxShop.Size = new Size(432, 28);
comboBoxShop.TabIndex = 0;
//
// comboBoxSecure
//
comboBoxSecure.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSecure.FormattingEnabled = true;
comboBoxSecure.Location = new Point(125, 47);
comboBoxSecure.Name = "comboBoxSecure";
comboBoxSecure.Size = new Size(432, 28);
comboBoxSecure.TabIndex = 1;
//
// labelShop
//
labelShop.AutoSize = true;
labelShop.Location = new Point(12, 9);
labelShop.Name = "labelShop";
labelShop.Size = new Size(72, 20);
labelShop.TabIndex = 3;
labelShop.Text = "Магазин:";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(12, 50);
label2.Name = "label2";
label2.Size = new Size(71, 20);
label2.TabIndex = 4;
label2.Text = "Изделие:";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(12, 89);
label3.Name = "label3";
label3.Size = new Size(93, 20);
label3.TabIndex = 5;
label3.Text = "Количество:";
//
// buttonSupply
//
buttonSupply.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonSupply.Location = new Point(342, 130);
buttonSupply.Name = "buttonSupply";
buttonSupply.Size = new Size(94, 29);
buttonSupply.TabIndex = 6;
buttonSupply.Text = "Поставить";
buttonSupply.UseVisualStyleBackColor = true;
buttonSupply.Click += buttonSupply_Click;
//
// buttonCancel
//
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(463, 130);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 7;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// textBoxCount
//
textBoxCount.Location = new Point(125, 89);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(167, 27);
textBoxCount.TabIndex = 8;
//
// FormShopSupply
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(569, 169);
Controls.Add(textBoxCount);
Controls.Add(buttonCancel);
Controls.Add(buttonSupply);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(labelShop);
Controls.Add(comboBoxSecure);
Controls.Add(comboBoxShop);
Name = "FormShopSupply";
Text = "Поставка изделия";
Load += FormShopSupply_Load;
ResumeLayout(false);
PerformLayout();
} }
#endregion #endregion
private ComboBox comboBoxShop;
private ComboBox comboBoxSecure;
private Label labelShop;
private Label label2;
private Label label3;
private Button buttonSupply;
private Button buttonCancel;
private TextBox textBoxCount;
} }
} }

View File

@ -1,20 +1,117 @@
using System; using Microsoft.Extensions.Logging;
using System.Collections.Generic; using SecuritySystemContracts.BindingModels;
using System.ComponentModel; using SecuritySystemContracts.BusinessLogicsContracts;
using System.Data; using SecuritySystemContracts.SearchModels;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SecuritySystemView namespace SecuritySystemView
{ {
public partial class FormShopSupply : Form public partial class FormShopSupply : Form
{ {
public FormShopSupply() private readonly ILogger _logger;
private readonly ISecureLogic _logicSecure;
private readonly IShopLogic _logicShop;
public FormShopSupply(ILogger<FormShopSupply> logger, ISecureLogic logicSecure, IShopLogic logicShop)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger;
_logicSecure = logicSecure;
_logicShop = logicShop;
}
private void FormShopSupply_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка secure для пополнения");
try
{
var list = _logicSecure.ReadList(null);
if (list != null)
{
comboBoxSecure.DisplayMember = "SecureName";
comboBoxSecure.ValueMember = "Id";
comboBoxSecure.DataSource = list;
comboBoxSecure.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка secure");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_logger.LogInformation("Загрузка магазинов для пополнения");
try
{
var list = _logicShop.ReadList(null);
if (list != null)
{
comboBoxShop.DisplayMember = "Name";
comboBoxShop.ValueMember = "Id";
comboBoxShop.DataSource = list;
comboBoxShop.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка магазинов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonSupply_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxSecure.SelectedValue == null)
{
MessageBox.Show("Выберите secure", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxShop.SelectedValue == null)
{
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание поставки");
try
{
var operationResult = _logicShop.SupplySecures(
new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue), Name = comboBoxShop.Text },
new SecureBindingModel { Id = Convert.ToInt32(comboBoxSecure.SelectedValue), SecureName = comboBoxSecure.Text },
Convert.ToInt32(textBoxCount.Text)
);
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();
} }
} }
} }

View File

@ -18,7 +18,7 @@
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> <data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value> <value>[base64 mime encoded serialized .NET Framework object]</value>
</data> </data>