Реализовано добавление клиента в заказ

This commit is contained in:
Никита Потапов 2024-04-07 00:41:06 +04:00
parent fbfb6f133b
commit 7fbe743e1a
3 changed files with 71 additions and 17 deletions

View File

@ -36,6 +36,8 @@
textBoxSum = new TextBox(); textBoxSum = new TextBox();
buttonSave = new Button(); buttonSave = new Button();
buttonCancel = new Button(); buttonCancel = new Button();
comboBoxClients = new ComboBox();
labelClient = new Label();
SuspendLayout(); SuspendLayout();
// //
// labelSecureName // labelSecureName
@ -67,33 +69,37 @@
// //
// comboBoxSecure // comboBoxSecure
// //
comboBoxSecure.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSecure.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSecure.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSecure.FormattingEnabled = true; comboBoxSecure.FormattingEnabled = true;
comboBoxSecure.Location = new Point(110, 9); comboBoxSecure.Location = new Point(113, 9);
comboBoxSecure.Name = "comboBoxSecure"; comboBoxSecure.Name = "comboBoxSecure";
comboBoxSecure.Size = new Size(462, 28); comboBoxSecure.Size = new Size(469, 28);
comboBoxSecure.TabIndex = 0; comboBoxSecure.TabIndex = 0;
comboBoxSecure.SelectedIndexChanged += ComboBoxSecure_SelectedIndexChanged; comboBoxSecure.SelectedIndexChanged += ComboBoxSecure_SelectedIndexChanged;
// //
// textBoxCount // textBoxCount
// //
textBoxCount.Location = new Point(110, 43); textBoxCount.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
textBoxCount.Location = new Point(113, 43);
textBoxCount.Name = "textBoxCount"; textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(462, 27); textBoxCount.Size = new Size(469, 27);
textBoxCount.TabIndex = 1; textBoxCount.TabIndex = 1;
textBoxCount.TextChanged += TextBoxCount_TextChanged; textBoxCount.TextChanged += TextBoxCount_TextChanged;
// //
// textBoxSum // textBoxSum
// //
textBoxSum.Location = new Point(110, 75); textBoxSum.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
textBoxSum.Location = new Point(113, 75);
textBoxSum.Name = "textBoxSum"; textBoxSum.Name = "textBoxSum";
textBoxSum.ReadOnly = true; textBoxSum.ReadOnly = true;
textBoxSum.Size = new Size(462, 27); textBoxSum.Size = new Size(469, 27);
textBoxSum.TabIndex = 2; textBoxSum.TabIndex = 2;
// //
// buttonSave // buttonSave
// //
buttonSave.Location = new Point(370, 118); buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonSave.Location = new Point(379, 154);
buttonSave.Name = "buttonSave"; buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(94, 29); buttonSave.Size = new Size(94, 29);
buttonSave.TabIndex = 3; buttonSave.TabIndex = 3;
@ -103,7 +109,8 @@
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Location = new Point(478, 118); buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(487, 154);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29); buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 4; buttonCancel.TabIndex = 4;
@ -111,11 +118,32 @@
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click; buttonCancel.Click += ButtonCancel_Click;
// //
// comboBoxClients
//
comboBoxClients.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxClients.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxClients.FormattingEnabled = true;
comboBoxClients.Location = new Point(113, 108);
comboBoxClients.Name = "comboBoxClients";
comboBoxClients.Size = new Size(469, 28);
comboBoxClients.TabIndex = 5;
//
// labelClient
//
labelClient.AutoSize = true;
labelClient.Location = new Point(12, 111);
labelClient.Name = "labelClient";
labelClient.Size = new Size(63, 20);
labelClient.TabIndex = 6;
labelClient.Text = "Клмент:";
//
// FormCreateOrder // FormCreateOrder
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(586, 160); ClientSize = new Size(591, 196);
Controls.Add(labelClient);
Controls.Add(comboBoxClients);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonSave); Controls.Add(buttonSave);
Controls.Add(textBoxSum); Controls.Add(textBoxSum);
@ -141,5 +169,7 @@
private TextBox textBoxSum; private TextBox textBoxSum;
private Button buttonSave; private Button buttonSave;
private Button buttonCancel; private Button buttonCancel;
private ComboBox comboBoxClients;
private Label labelClient;
} }
} }

View File

@ -10,33 +10,50 @@ namespace SecuritySystemView
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly ISecureLogic _logicSecure; private readonly ISecureLogic _logicSecure;
private readonly IOrderLogic _logicOrder; private readonly IOrderLogic _logicOrder;
public FormCreateOrder(ILogger<FormCreateOrder> logger, ISecureLogic logicSecure, IOrderLogic logicOrder) private readonly IClientLogic _clientLogic;
public FormCreateOrder(ILogger<FormCreateOrder> logger, ISecureLogic logicSecure, IOrderLogic logicOrder, IClientLogic clientLogic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logicSecure = logicSecure; _logicSecure = logicSecure;
_logicOrder = logicOrder; _logicOrder = logicOrder;
_clientLogic = clientLogic;
} }
private void FormCreateOrder_Load(object sender, EventArgs e) private void FormCreateOrder_Load(object sender, EventArgs e)
{ {
_logger.LogInformation("Загрузка изделий для заказа"); _logger.LogInformation("Загрузка изделий для заказа");
try try
{ {
var list = _logicSecure.ReadList(null); var listSecures = _logicSecure.ReadList(null);
if (list != null) if (listSecures != null)
{ {
comboBoxSecure.DisplayMember = "SecureName"; comboBoxSecure.DisplayMember = "SecureName";
comboBoxSecure.ValueMember = "Id"; comboBoxSecure.ValueMember = "Id";
comboBoxSecure.DataSource = list; comboBoxSecure.DataSource = listSecures;
comboBoxSecure.SelectedItem = null; comboBoxSecure.SelectedItem = null;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка загрузки списка изделий"); _logger.LogError(ex, "Ошибка загрузки списка изделий");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
try
{
var listClients = _clientLogic.ReadList(null);
if (listSecures != null)
{
comboBoxClients.DisplayMember = "ClientFIO";
comboBoxClients.ValueMember = "Id";
comboBoxClients.DataSource = listClients;
comboBoxClients.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка клиентов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} }
private void CalcSum() private void CalcSum()
{ {
@ -83,6 +100,12 @@ namespace SecuritySystemView
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
if (comboBoxClients.SelectedValue == null)
{
MessageBox.Show("Выберите клиента", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание заказа"); _logger.LogInformation("Создание заказа");
try try
{ {
@ -90,7 +113,8 @@ namespace SecuritySystemView
{ {
SecureId = Convert.ToInt32(comboBoxSecure.SelectedValue), SecureId = Convert.ToInt32(comboBoxSecure.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text), Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text) Sum = Convert.ToDouble(textBoxSum.Text),
ClientId = Convert.ToInt32(comboBoxClients.SelectedValue)
}); });
if (!operationResult) if (!operationResult)
{ {

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>