Формы desktop

This commit is contained in:
prodigygirl 2023-03-25 12:08:33 +04:00
parent efc44b4d1d
commit 9391517849
8 changed files with 292 additions and 21 deletions

View File

@ -0,0 +1,75 @@
namespace FurnitureAssembly
{
partial class FormClients
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.ButtonDel = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 85);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(559, 453);
this.dataGridView.TabIndex = 6;
//
// ButtonDel
//
this.ButtonDel.Location = new System.Drawing.Point(466, 40);
this.ButtonDel.Name = "ButtonDel";
this.ButtonDel.Size = new System.Drawing.Size(105, 29);
this.ButtonDel.TabIndex = 11;
this.ButtonDel.Text = "Удалить";
this.ButtonDel.UseVisualStyleBackColor = true;
this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// FormClients
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(588, 549);
this.Controls.Add(this.ButtonDel);
this.Controls.Add(this.dataGridView);
this.Name = "FormClients";
this.Text = "Клиенты";
this.Load += new System.EventHandler(this.FormClients_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button ButtonDel;
}
}

View File

@ -0,0 +1,79 @@
using FurnitureAssemblyContracts.BindingModels;
using FurnitureAssemblyContracts.BusinessLogicsContarcts;
using Microsoft.Extensions.Logging;
namespace FurnitureAssembly
{
public partial class FormClients : Form
{
private readonly ILogger _logger;
private readonly IClientLogic _logic;
public FormClients(ILogger<FormClients> logger, IClientLogic clientLogic)
{
InitializeComponent();
_logger = logger;
_logic = clientLogic;
}
private void FormClients_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["ClientFIO"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Email"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Password"].Visible = false;
}
_logger.LogInformation("Загрузка клиентов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки клиентов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
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 ClientBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления клиента");
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -36,12 +36,14 @@
this.textBoxSum = new System.Windows.Forms.TextBox();
this.ButtonSave = new System.Windows.Forms.Button();
this.ButtonCancel = new System.Windows.Forms.Button();
this.comboBoxClientEmail = new System.Windows.Forms.ComboBox();
this.labelClient = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// labelFurniture
//
this.labelFurniture.AutoSize = true;
this.labelFurniture.Location = new System.Drawing.Point(29, 23);
this.labelFurniture.Location = new System.Drawing.Point(28, 53);
this.labelFurniture.Name = "labelFurniture";
this.labelFurniture.Size = new System.Drawing.Size(56, 15);
this.labelFurniture.TabIndex = 0;
@ -50,7 +52,7 @@
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(29, 50);
this.labelCount.Location = new System.Drawing.Point(28, 88);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(75, 15);
this.labelCount.TabIndex = 1;
@ -59,7 +61,7 @@
// labelSum
//
this.labelSum.AutoSize = true;
this.labelSum.Location = new System.Drawing.Point(29, 77);
this.labelSum.Location = new System.Drawing.Point(28, 124);
this.labelSum.Name = "labelSum";
this.labelSum.Size = new System.Drawing.Size(45, 15);
this.labelSum.TabIndex = 2;
@ -67,7 +69,7 @@
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(125, 44);
this.textBoxCount.Location = new System.Drawing.Point(124, 85);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(297, 23);
this.textBoxCount.TabIndex = 3;
@ -76,7 +78,7 @@
// comboBoxProduct
//
this.comboBoxProduct.FormattingEnabled = true;
this.comboBoxProduct.Location = new System.Drawing.Point(125, 15);
this.comboBoxProduct.Location = new System.Drawing.Point(124, 50);
this.comboBoxProduct.Name = "comboBoxProduct";
this.comboBoxProduct.Size = new System.Drawing.Size(297, 23);
this.comboBoxProduct.TabIndex = 4;
@ -84,14 +86,14 @@
//
// textBoxSum
//
this.textBoxSum.Location = new System.Drawing.Point(125, 77);
this.textBoxSum.Location = new System.Drawing.Point(124, 121);
this.textBoxSum.Name = "textBoxSum";
this.textBoxSum.Size = new System.Drawing.Size(297, 23);
this.textBoxSum.TabIndex = 5;
//
// ButtonSave
//
this.ButtonSave.Location = new System.Drawing.Point(188, 104);
this.ButtonSave.Location = new System.Drawing.Point(186, 150);
this.ButtonSave.Name = "ButtonSave";
this.ButtonSave.Size = new System.Drawing.Size(105, 29);
this.ButtonSave.TabIndex = 6;
@ -101,7 +103,7 @@
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(317, 104);
this.ButtonCancel.Location = new System.Drawing.Point(316, 150);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(105, 29);
this.ButtonCancel.TabIndex = 7;
@ -109,11 +111,30 @@
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// comboBoxClientEmail
//
this.comboBoxClientEmail.FormattingEnabled = true;
this.comboBoxClientEmail.Location = new System.Drawing.Point(124, 12);
this.comboBoxClientEmail.Name = "comboBoxClientEmail";
this.comboBoxClientEmail.Size = new System.Drawing.Size(297, 23);
this.comboBoxClientEmail.TabIndex = 9;
//
// labelClient
//
this.labelClient.AutoSize = true;
this.labelClient.Location = new System.Drawing.Point(28, 15);
this.labelClient.Name = "labelClient";
this.labelClient.Size = new System.Drawing.Size(49, 15);
this.labelClient.TabIndex = 8;
this.labelClient.Text = "Клиент:";
//
// FormCreateOrder
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(453, 137);
this.ClientSize = new System.Drawing.Size(453, 191);
this.Controls.Add(this.comboBoxClientEmail);
this.Controls.Add(this.labelClient);
this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.ButtonSave);
this.Controls.Add(this.textBoxSum);
@ -140,5 +161,7 @@
private TextBox textBoxSum;
private Button ButtonSave;
private Button ButtonCancel;
private ComboBox comboBoxClientEmail;
private Label labelClient;
}
}

View File

@ -21,12 +21,14 @@ namespace FurnitureAssembly
private readonly ILogger _logger;
private readonly IFurnitureLogic _logicF;
private readonly IOrderLogic _logicO;
public FormCreateOrder(ILogger<FormCreateOrder> logger, IFurnitureLogic logicF, IOrderLogic logicO)
private readonly IClientLogic _logicC;
public FormCreateOrder(ILogger<FormCreateOrder> logger, IFurnitureLogic logicF, IOrderLogic logicO, IClientLogic logicC)
{
InitializeComponent();
_logger = logger;
_logicF = logicF;
_logicO = logicO;
_logicC = logicC;
}
private void ButtonSave_Click(object sender, EventArgs e)
@ -43,6 +45,12 @@ namespace FurnitureAssembly
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxClientEmail.SelectedValue == null)
{
MessageBox.Show("Выберите клиента", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание заказа");
try
{
@ -50,7 +58,8 @@ namespace FurnitureAssembly
{
FurnitureId = Convert.ToInt32(comboBoxProduct.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text)
Sum = Convert.ToDouble(textBoxSum.Text),
ClientId = Convert.ToInt32(comboBoxClientEmail.SelectedValue)
});
if (!operationResult)
{
@ -71,7 +80,7 @@ namespace FurnitureAssembly
private void FormCreateOrder_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка изделий для заказа");
_logger.LogInformation("Загрузка изделий и клиентов для заказа");
// прописать логику
LoadData();
}
@ -85,6 +94,14 @@ namespace FurnitureAssembly
comboBoxProduct.DataSource = _list;
comboBoxProduct.SelectedItem = null;
}
var _listCli = _logicC.ReadList(null);
if (_listCli != null)
{
comboBoxClientEmail.DisplayMember = "Email"; // по нему однозначно можно определить клиента
comboBoxClientEmail.ValueMember = "Id";
comboBoxClientEmail.DataSource = _listCli;
comboBoxClientEmail.SelectedItem = null;
}
}

View File

@ -57,7 +57,4 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="labelSum.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -38,6 +38,7 @@
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ClientsMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.FurnituresToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.FurnituresComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -120,7 +121,8 @@
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.компонентыToolStripMenuItem,
this.изделияToolStripMenuItem});
this.изделияToolStripMenuItem,
this.ClientsMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.справочникиToolStripMenuItem.Text = "Справочники";
@ -128,17 +130,24 @@
// компонентыToolStripMenuItem
//
this.компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.компонентыToolStripMenuItem.Text = "Компоненты";
this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
//
// изделияToolStripMenuItem
//
this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
this.изделияToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.изделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.изделияToolStripMenuItem.Text = "Изделия";
this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click);
//
// ClientsMenuItem
//
this.ClientsMenuItem.Name = "ClientsMenuItem";
this.ClientsMenuItem.Size = new System.Drawing.Size(180, 22);
this.ClientsMenuItem.Text = "Клиенты";
this.ClientsMenuItem.Click += new System.EventHandler(this.ClientsMenuItem_Click);
//
// отчетыToolStripMenuItem
//
this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -152,7 +161,7 @@
// FurnituresToolStripMenuItem
//
this.FurnituresToolStripMenuItem.Name = "FurnituresToolStripMenuItem";
this.FurnituresToolStripMenuItem.Size = new System.Drawing.Size(218, 22);
this.FurnituresToolStripMenuItem.Size = new System.Drawing.Size(216, 22);
this.FurnituresToolStripMenuItem.Text = "Список изделий";
this.FurnituresToolStripMenuItem.Click += new System.EventHandler(this.FurnituresToolStripMenuItem_Click);
//
@ -166,7 +175,7 @@
// списокЗаказовToolStripMenuItem
//
this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem";
this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(218, 22);
this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(216, 22);
this.списокЗаказовToolStripMenuItem.Text = "Список заказов";
this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click);
//
@ -210,5 +219,6 @@
private ToolStripMenuItem FurnituresToolStripMenuItem;
private ToolStripMenuItem FurnituresComponentsToolStripMenuItem;
private ToolStripMenuItem списокЗаказовToolStripMenuItem;
private ToolStripMenuItem ClientsMenuItem;
}
}

View File

@ -38,7 +38,8 @@ namespace FurnitureAssembly
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["FurnitureId"].Visible = false;
dataGridView.Columns["FurnitureId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
}
_logger.LogInformation("Загрузка заказов");
}
@ -190,5 +191,14 @@ namespace FurnitureAssembly
form.ShowDialog();
}
}
private void ClientsMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
form.ShowDialog();
}
}
}
}