работа над лабой 5 продолжение

This commit is contained in:
Полина Чубыкина 2024-04-21 12:18:48 +04:00
parent 12b16be979
commit 3bffef1d0d
5 changed files with 84 additions and 12 deletions

View File

@ -36,6 +36,8 @@
this.textBoxSum = new System.Windows.Forms.TextBox();
this.ButtonSave = new System.Windows.Forms.Button();
this.ButtonCancel = new System.Windows.Forms.Button();
this.comboBoxClient = new System.Windows.Forms.ComboBox();
this.labelClient = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// labelPastry
@ -43,14 +45,14 @@
this.labelPastry.AutoSize = true;
this.labelPastry.Location = new System.Drawing.Point(38, 30);
this.labelPastry.Name = "labelPastry";
this.labelPastry.Size = new System.Drawing.Size(71, 20);
this.labelPastry.Size = new System.Drawing.Size(72, 20);
this.labelPastry.TabIndex = 0;
this.labelPastry.Text = "Выпечка:";
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(38, 67);
this.labelCount.Location = new System.Drawing.Point(38, 100);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(93, 20);
this.labelCount.TabIndex = 1;
@ -59,7 +61,7 @@
// labelSum
//
this.labelSum.AutoSize = true;
this.labelSum.Location = new System.Drawing.Point(38, 102);
this.labelSum.Location = new System.Drawing.Point(38, 135);
this.labelSum.Name = "labelSum";
this.labelSum.Size = new System.Drawing.Size(58, 20);
this.labelSum.TabIndex = 2;
@ -76,7 +78,7 @@
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(150, 60);
this.textBoxCount.Location = new System.Drawing.Point(150, 93);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(429, 27);
this.textBoxCount.TabIndex = 4;
@ -85,14 +87,14 @@
// textBoxSum
//
this.textBoxSum.Enabled = false;
this.textBoxSum.Location = new System.Drawing.Point(150, 95);
this.textBoxSum.Location = new System.Drawing.Point(150, 128);
this.textBoxSum.Name = "textBoxSum";
this.textBoxSum.Size = new System.Drawing.Size(429, 27);
this.textBoxSum.TabIndex = 5;
//
// ButtonSave
//
this.ButtonSave.Location = new System.Drawing.Point(216, 137);
this.ButtonSave.Location = new System.Drawing.Point(216, 170);
this.ButtonSave.Name = "ButtonSave";
this.ButtonSave.Size = new System.Drawing.Size(94, 29);
this.ButtonSave.TabIndex = 6;
@ -102,7 +104,7 @@
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(361, 137);
this.ButtonCancel.Location = new System.Drawing.Point(361, 170);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(94, 29);
this.ButtonCancel.TabIndex = 7;
@ -110,11 +112,30 @@
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// comboBoxClient
//
this.comboBoxClient.FormattingEnabled = true;
this.comboBoxClient.Location = new System.Drawing.Point(150, 59);
this.comboBoxClient.Name = "comboBoxClient";
this.comboBoxClient.Size = new System.Drawing.Size(429, 28);
this.comboBoxClient.TabIndex = 9;
//
// labelClient
//
this.labelClient.AutoSize = true;
this.labelClient.Location = new System.Drawing.Point(38, 67);
this.labelClient.Name = "labelClient";
this.labelClient.Size = new System.Drawing.Size(61, 20);
this.labelClient.TabIndex = 8;
this.labelClient.Text = "Клиент:";
//
// FormCreateOrder
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(591, 180);
this.ClientSize = new System.Drawing.Size(591, 245);
this.Controls.Add(this.comboBoxClient);
this.Controls.Add(this.labelClient);
this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.ButtonSave);
this.Controls.Add(this.textBoxSum);
@ -141,5 +162,7 @@
private TextBox textBoxSum;
private Button ButtonSave;
private Button ButtonCancel;
private ComboBox comboBoxClient;
private Label labelClient;
}
}

View File

@ -19,12 +19,14 @@ namespace ConfectioneryView
private readonly ILogger _logger;
private readonly IPastryLogic _logicP;
private readonly IOrderLogic _logicO;
public FormCreateOrder(ILogger<FormCreateOrder> logger, IPastryLogic logicP, IOrderLogic logicO)
private readonly IClientLogic _logicC;
public FormCreateOrder(ILogger<FormCreateOrder> logger, IPastryLogic logicP, IOrderLogic logicO, IClientLogic logicC)
{
InitializeComponent();
_logger = logger;
_logicP = logicP;
_logicO = logicO;
_logicC = logicC;
}
private void FormCreateOrder_Load(object sender, EventArgs e)
@ -46,6 +48,23 @@ namespace ConfectioneryView
_logger.LogError(ex, "Error during loading pastry for order");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_logger.LogInformation("Loading clients for order");
try
{
var clientList = _logicC.ReadList(null);
if (clientList != null)
{
comboBoxClient.DisplayMember = "ClientFIO";
comboBoxClient.ValueMember = "Id";
comboBoxClient.DataSource = clientList;
comboBoxClient.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading clients for order");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CalcSum()
{
@ -95,12 +114,18 @@ namespace ConfectioneryView
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxClient.SelectedValue == null)
{
MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание заказа");
try
{
var operationResult = _logicO.CreateOrder(new OrderBindingModel
{
PastryId = Convert.ToInt32(comboBoxPastry.SelectedValue),
ClientId = Convert.ToInt32(comboBoxClient.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text)
});

View File

@ -32,6 +32,7 @@
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.списокКомпонентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -62,7 +63,8 @@
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.компонентыToolStripMenuItem,
this.изделияToolStripMenuItem});
this.изделияToolStripMenuItem,
this.клиентыToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24);
this.справочникиToolStripMenuItem.Text = "Справочники";
@ -70,17 +72,24 @@
// компонентыToolStripMenuItem
//
this.компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.компонентыToolStripMenuItem.Text = "Компоненты";
this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
//
// изделияToolStripMenuItem
//
this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
this.изделияToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.изделияToolStripMenuItem.Text = "Изделия";
this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click);
//
// клиентыToolStripMenuItem
//
this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.клиентыToolStripMenuItem.Text = "Клиенты";
this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.КлиентыToolStripMenuItem_Click);
//
// отчетыToolStripMenuItem
//
this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -212,5 +221,6 @@
private ToolStripMenuItem списокКомпонентовToolStripMenuItem;
private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem;
private ToolStripMenuItem списокЗаказовToolStripMenuItem;
private ToolStripMenuItem клиентыToolStripMenuItem;
}
}

View File

@ -41,6 +41,8 @@ namespace ConfectioneryView
dataGridView.DataSource = list;
dataGridView.Columns["PastryId"].Visible = false;
dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Orders loading");
}
@ -69,6 +71,15 @@ namespace ConfectioneryView
}
}
private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
form.ShowDialog();
}
}
private void СписокКомпонентовToolStripMenuItem_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };

View File

@ -38,11 +38,13 @@ namespace ConfectioneryView
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IPastryStorage, PastryStorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IPastryLogic, PastryLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
@ -57,6 +59,7 @@ namespace ConfectioneryView
services.AddTransient<FormPastries>();
services.AddTransient<FormReportPastryComponents>();
services.AddTransient<FormReportOrders>();
services.AddTransient<FormClients>();
}
}
}