почти готовая лаба 1

This commit is contained in:
Полина Чубыкина 2024-02-27 23:07:55 +04:00
parent b4a88a1231
commit 9210394589
9 changed files with 98 additions and 36 deletions

View File

@ -16,18 +16,18 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IPastryStorage _iceCreamStorage; private readonly IPastryStorage _pastryStorage;
public PastryLogic(ILogger<PastryLogic> logger, IPastryStorage iceCreamStorage) public PastryLogic(ILogger<PastryLogic> logger, IPastryStorage pastryStorage)
{ {
_logger = logger; _logger = logger;
_iceCreamStorage = iceCreamStorage; _pastryStorage = pastryStorage;
} }
public List<PastryViewModel>? ReadList(PastrySearchModel? model) public List<PastryViewModel>? ReadList(PastrySearchModel? model)
{ {
_logger.LogInformation("ReadList. PastryName: {PastryName}. Id: {Id}", model?.PastryName, model?.Id); _logger.LogInformation("ReadList. PastryName: {PastryName}. Id: {Id}", model?.PastryName, model?.Id);
var list = model == null ? _iceCreamStorage.GetFullList() : _iceCreamStorage.GetFilteredList(model); var list = model == null ? _pastryStorage.GetFullList() : _pastryStorage.GetFilteredList(model);
if (list == null) if (list == null)
{ {
_logger.LogWarning("ReadList return null list"); _logger.LogWarning("ReadList return null list");
@ -44,7 +44,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
throw new ArgumentNullException(nameof(model)); throw new ArgumentNullException(nameof(model));
} }
_logger.LogInformation("ReadElement. PastryName: {PastryName}. Id: {Id}", model.PastryName, model.Id); _logger.LogInformation("ReadElement. PastryName: {PastryName}. Id: {Id}", model.PastryName, model.Id);
var element = _iceCreamStorage.GetElement(model); var element = _pastryStorage.GetElement(model);
if (element == null) if (element == null)
{ {
_logger.LogWarning("ReadElement element not found"); _logger.LogWarning("ReadElement element not found");
@ -57,7 +57,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
public bool Create(PastryBindingModel model) public bool Create(PastryBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (_iceCreamStorage.Insert(model) == null) if (_pastryStorage.Insert(model) == null)
{ {
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
return false; return false;
@ -68,7 +68,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
public bool Update(PastryBindingModel model) public bool Update(PastryBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (_iceCreamStorage.Update(model) == null) if (_pastryStorage.Update(model) == null)
{ {
_logger.LogWarning("Update operation failed"); _logger.LogWarning("Update operation failed");
return false; return false;
@ -80,7 +80,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
{ {
CheckModel(model, false); CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id); _logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_iceCreamStorage.Delete(model) == null) if (_pastryStorage.Delete(model) == null)
{ {
_logger.LogWarning("Delete operation failed"); _logger.LogWarning("Delete operation failed");
return false; return false;
@ -111,7 +111,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
throw new ArgumentNullException("Мороженое должно состоять хотя бы из одного компонента"); throw new ArgumentNullException("Мороженое должно состоять хотя бы из одного компонента");
} }
_logger.LogInformation("Pastry. PastryName: {PastryName}. Price: {Price}. Id: {Id}", model.PastryName, model.Price, model.Id); _logger.LogInformation("Pastry. PastryName: {PastryName}. Price: {Price}. Id: {Id}", model.PastryName, model.Price, model.Id);
var element = _iceCreamStorage.GetElement(new PastrySearchModel var element = _pastryStorage.GetElement(new PastrySearchModel
{ {
PastryName = model.PastryName PastryName = model.PastryName
}); });

View File

@ -70,7 +70,7 @@
this.comboBoxPastry.FormattingEnabled = true; this.comboBoxPastry.FormattingEnabled = true;
this.comboBoxPastry.Location = new System.Drawing.Point(150, 22); this.comboBoxPastry.Location = new System.Drawing.Point(150, 22);
this.comboBoxPastry.Name = "comboBoxPastry"; this.comboBoxPastry.Name = "comboBoxPastry";
this.comboBoxPastry.Size = new System.Drawing.Size(337, 28); this.comboBoxPastry.Size = new System.Drawing.Size(429, 28);
this.comboBoxPastry.TabIndex = 3; this.comboBoxPastry.TabIndex = 3;
this.comboBoxPastry.SelectedIndexChanged += new System.EventHandler(this.ComboBoxPastry_SelectedIndexChanged); this.comboBoxPastry.SelectedIndexChanged += new System.EventHandler(this.ComboBoxPastry_SelectedIndexChanged);
// //
@ -78,7 +78,7 @@
// //
this.textBoxCount.Location = new System.Drawing.Point(150, 60); this.textBoxCount.Location = new System.Drawing.Point(150, 60);
this.textBoxCount.Name = "textBoxCount"; this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(337, 27); this.textBoxCount.Size = new System.Drawing.Size(429, 27);
this.textBoxCount.TabIndex = 4; this.textBoxCount.TabIndex = 4;
this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged);
// //
@ -86,7 +86,7 @@
// //
this.textBoxSum.Location = new System.Drawing.Point(150, 95); this.textBoxSum.Location = new System.Drawing.Point(150, 95);
this.textBoxSum.Name = "textBoxSum"; this.textBoxSum.Name = "textBoxSum";
this.textBoxSum.Size = new System.Drawing.Size(337, 27); this.textBoxSum.Size = new System.Drawing.Size(429, 27);
this.textBoxSum.TabIndex = 5; this.textBoxSum.TabIndex = 5;
// //
// ButtonSave // ButtonSave
@ -113,7 +113,7 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(499, 180); this.ClientSize = new System.Drawing.Size(591, 180);
this.Controls.Add(this.ButtonCancel); this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.ButtonSave); this.Controls.Add(this.ButtonSave);
this.Controls.Add(this.textBoxSum); this.Controls.Add(this.textBoxSum);

View File

@ -29,8 +29,23 @@ namespace ConfectioneryView
private void FormCreateOrder_Load(object sender, EventArgs e) private void FormCreateOrder_Load(object sender, EventArgs e)
{ {
_logger.LogInformation("Загрузка изделий для заказа"); _logger.LogInformation("Loading ice cream for order");
// прописать логику try
{
var pastryList = _logicP.ReadList(null);
if (pastryList != null)
{
comboBoxPastry.DisplayMember = "PastryName";
comboBoxPastry.ValueMember = "Id";
comboBoxPastry.DataSource = pastryList;
comboBoxPastry.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading ice cream for order");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} }
private void CalcSum() private void CalcSum()
{ {

View File

@ -28,7 +28,7 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.menuStrip = new System.Windows.Forms.MenuStrip();
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();
@ -38,20 +38,20 @@
this.ButtonOrderReady = new System.Windows.Forms.Button(); this.ButtonOrderReady = new System.Windows.Forms.Button();
this.ButtonIssuedOrder = new System.Windows.Forms.Button(); this.ButtonIssuedOrder = new System.Windows.Forms.Button();
this.ButtonRef = new System.Windows.Forms.Button(); this.ButtonRef = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout(); this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// menuStrip1 // menuStrip
// //
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.справочникиToolStripMenuItem}); this.справочникиToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1"; this.menuStrip.Name = "menuStrip";
this.menuStrip1.Size = new System.Drawing.Size(1376, 28); this.menuStrip.Size = new System.Drawing.Size(1376, 28);
this.menuStrip1.TabIndex = 0; this.menuStrip.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1"; this.menuStrip.Text = "menuStrip";
// //
// справочникиToolStripMenuItem // справочникиToolStripMenuItem
// //
@ -147,13 +147,13 @@
this.Controls.Add(this.ButtonTakeOrderInWork); this.Controls.Add(this.ButtonTakeOrderInWork);
this.Controls.Add(this.ButtonCreateOrder); this.Controls.Add(this.ButtonCreateOrder);
this.Controls.Add(this.dataGridView); this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip1); this.Controls.Add(this.menuStrip);
this.MainMenuStrip = this.menuStrip1; this.MainMenuStrip = this.menuStrip;
this.Name = "FormMain"; this.Name = "FormMain";
this.Text = "Кондитерская"; this.Text = "Кондитерская";
this.Load += new System.EventHandler(this.FormMain_Load); this.Load += new System.EventHandler(this.FormMain_Load);
this.menuStrip1.ResumeLayout(false); this.menuStrip.ResumeLayout(false);
this.menuStrip1.PerformLayout(); this.menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@ -162,7 +162,7 @@
#endregion #endregion
private MenuStrip menuStrip1; private MenuStrip menuStrip;
private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem изделияToolStripMenuItem; private ToolStripMenuItem изделияToolStripMenuItem;

View File

@ -70,8 +70,7 @@ namespace ConfectioneryView
private void ButtonCreateOrder_Click(object sender, EventArgs e) private void ButtonCreateOrder_Click(object sender, EventArgs e)
{ {
var service = var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
if (service is FormCreateOrder form) if (service is FormCreateOrder form)
{ {
form.ShowDialog(); form.ShowDialog();
@ -82,8 +81,7 @@ namespace ConfectioneryView
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
int id = int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try try
{ {

View File

@ -57,7 +57,10 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value>
</metadata>
</root> </root>

View File

@ -54,6 +54,7 @@
this.ButtonUpd.TabIndex = 8; this.ButtonUpd.TabIndex = 8;
this.ButtonUpd.Text = "Изменить"; this.ButtonUpd.Text = "Изменить";
this.ButtonUpd.UseVisualStyleBackColor = true; this.ButtonUpd.UseVisualStyleBackColor = true;
this.ButtonUpd.Click += new System.EventHandler(this.ButtonEdit_Click);
// //
// ButtonDel // ButtonDel
// //
@ -63,6 +64,7 @@
this.ButtonDel.TabIndex = 7; this.ButtonDel.TabIndex = 7;
this.ButtonDel.Text = "Удалить"; this.ButtonDel.Text = "Удалить";
this.ButtonDel.UseVisualStyleBackColor = true; this.ButtonDel.UseVisualStyleBackColor = true;
this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click);
// //
// ButtonRef // ButtonRef
// //
@ -72,6 +74,7 @@
this.ButtonRef.TabIndex = 6; this.ButtonRef.TabIndex = 6;
this.ButtonRef.Text = "Обновить"; this.ButtonRef.Text = "Обновить";
this.ButtonRef.UseVisualStyleBackColor = true; this.ButtonRef.UseVisualStyleBackColor = true;
this.ButtonRef.Click += new System.EventHandler(this.ButtonUpd_Click);
// //
// ButtonAdd // ButtonAdd
// //
@ -81,6 +84,7 @@
this.ButtonAdd.TabIndex = 5; this.ButtonAdd.TabIndex = 5;
this.ButtonAdd.Text = "Добавить"; this.ButtonAdd.Text = "Добавить";
this.ButtonAdd.UseVisualStyleBackColor = true; this.ButtonAdd.UseVisualStyleBackColor = true;
this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
// //
// FormPastries // FormPastries
// //

View File

@ -40,6 +40,9 @@
this.ButtonCancel = new System.Windows.Forms.Button(); this.ButtonCancel = new System.Windows.Forms.Button();
this.labelName = new System.Windows.Forms.Label(); this.labelName = new System.Windows.Forms.Label();
this.labelPrice = new System.Windows.Forms.Label(); this.labelPrice = new System.Windows.Forms.Label();
this.Number = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.groupBox.SuspendLayout(); this.groupBox.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -61,6 +64,10 @@
// dataGridView // dataGridView
// //
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Number,
this.Component,
this.Count});
this.dataGridView.Location = new System.Drawing.Point(6, 26); this.dataGridView.Location = new System.Drawing.Point(6, 26);
this.dataGridView.Name = "dataGridView"; this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowHeadersWidth = 51;
@ -160,6 +167,28 @@
this.labelPrice.TabIndex = 10; this.labelPrice.TabIndex = 10;
this.labelPrice.Text = "Стоимость:"; this.labelPrice.Text = "Стоимость:";
// //
// Number
//
this.Number.HeaderText = "Номер";
this.Number.MinimumWidth = 6;
this.Number.Name = "Number";
this.Number.Visible = false;
this.Number.Width = 125;
//
// Component
//
this.Component.HeaderText = "Компонент";
this.Component.MinimumWidth = 6;
this.Component.Name = "Component";
this.Component.Width = 125;
//
// Count
//
this.Count.HeaderText = "Количество";
this.Count.MinimumWidth = 6;
this.Count.Name = "Count";
this.Count.Width = 125;
//
// FormPastry // FormPastry
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
@ -173,7 +202,8 @@
this.Controls.Add(this.textBoxPrice); this.Controls.Add(this.textBoxPrice);
this.Controls.Add(this.textBoxName); this.Controls.Add(this.textBoxName);
this.Name = "FormPastry"; this.Name = "FormPastry";
this.Text = "FormPastry"; this.Text = "Выпечка";
this.Load += new System.EventHandler(this.FormPastry_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.groupBox.ResumeLayout(false); this.groupBox.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
@ -195,5 +225,8 @@
private Button ButtonCancel; private Button ButtonCancel;
private Label labelName; private Label labelName;
private Label labelPrice; private Label labelPrice;
private DataGridViewTextBoxColumn Number;
private DataGridViewTextBoxColumn Component;
private DataGridViewTextBoxColumn Count;
} }
} }

View File

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