ISEbd-21.Fedotov.I.A.LabWork04 #4

Closed
Ilfedotov.01 wants to merge 10 commits from ISEbd-21.Fedotov.I.A.LabWork04 into ISEbd-21.Fedotov.I.A.LabWork03
24 changed files with 134 additions and 60 deletions
Showing only changes of commit d754b31220 - Show all commits

View File

@ -31,8 +31,8 @@ namespace DinerContracts.ViewModels
[DisplayName("Номер")]
public int ID { get; set; }
[DisplayName("Снэк")]
// какой снэк изготавливается в рамках заказа
[DisplayName("Снэк")]
public string ProductName { get; set; } = string.Empty;
}
}

View File

@ -1,4 +1,5 @@
using System;
using DinerDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -12,5 +13,6 @@ namespace DinerContracts.ViewModels
public DateTime DateCreate { get; set; }
public string ProductName { get; set; } = string.Empty;
public double Sum { get; set; }
public string OrderStatus { get; set; } = string.Empty;
}
}

View File

@ -8,8 +8,8 @@ namespace DinerContracts.ViewModels
{
public class ReportSnackFoodsViewModel
{
public string ComponentName { get; set; } = string.Empty;
public string ProductName { get; set; } = string.Empty;
public int TotalCount { get; set; }
public List<(string Product, int count)> Products { get; set; } = new();
public List<(string Product, int count)> Components { get; set; } = new();
}
}

View File

@ -47,7 +47,7 @@ namespace DinerDataBaseImplement.Implements
return context.Orders
.Include(x => x.Snack)
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.Select(GetViewModel)
.ToList();
}
}

View File

@ -33,7 +33,7 @@ namespace DinerDataBaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<string>("ComponentName")
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("nvarchar(max)");
@ -94,7 +94,7 @@ namespace DinerDataBaseImplement.Migrations
b.HasKey("ID");
b.ToTable("Products");
b.ToTable("Components");
});
modelBuilder.Entity("DinerDataBaseImplement.Models.SnackFood", b =>

View File

@ -44,7 +44,7 @@ namespace DinerDataBaseImplement.Migrations
});
migrationBuilder.CreateTable(
name: "Products",
name: "Components",
columns: table => new
{
ID = table.Column<int>(type: "int", nullable: false)
@ -79,7 +79,7 @@ namespace DinerDataBaseImplement.Migrations
table.ForeignKey(
name: "FK_ProductComponents_Products_ProductID",
column: x => x.ProductID,
principalTable: "Products",
principalTable: "Components",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
@ -108,7 +108,7 @@ namespace DinerDataBaseImplement.Migrations
name: "Components");
migrationBuilder.DropTable(
name: "Products");
name: "Components");
}
}
}

View File

@ -33,7 +33,7 @@ namespace DinerDataBaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<string>("ComponentName")
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("nvarchar(max)");
@ -93,7 +93,7 @@ namespace DinerDataBaseImplement.Migrations
b.HasKey("ID");
b.ToTable("Products");
b.ToTable("Components");
});
modelBuilder.Entity("DinerDataBaseImplement.Models.SnackFood", b =>

View File

@ -33,7 +33,7 @@ namespace DinerDataBaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<string>("ComponentName")
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("nvarchar(max)");
@ -98,7 +98,7 @@ namespace DinerDataBaseImplement.Migrations
b.HasKey("ID");
b.ToTable("Products");
b.ToTable("Components");
});
modelBuilder.Entity("DinerDataBaseImplement.Models.SnackFood", b =>

View File

@ -25,7 +25,7 @@ namespace DinerDataBaseImplement.Migrations
name: "FK_Orders_Products_SnackID",
table: "Orders",
column: "SnackID",
principalTable: "Products",
principalTable: "Components",
principalColumn: "ID");
}

View File

@ -30,7 +30,7 @@ namespace DinerDataBaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<string>("ComponentName")
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("nvarchar(max)");
@ -95,7 +95,7 @@ namespace DinerDataBaseImplement.Migrations
b.HasKey("ID");
b.ToTable("Products", (string)null);
b.ToTable("Components", (string)null);
});
modelBuilder.Entity("DinerDataBaseImplement.Models.SnackFood", b =>

View File

@ -59,7 +59,7 @@ namespace DinerDataBaseImplement.Models
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
DateImplement = DateImplement,
};
}

View File

@ -33,7 +33,7 @@ namespace DinerFileImplement.Models
return new Food()
{
ID = Convert.ToInt32(element.Attribute("ID")!.Value),
ComponentName = element.Element("ComponentName")!.Value,
ComponentName = element.Element("ProductName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value)
};
}
@ -51,7 +51,7 @@ namespace DinerFileImplement.Models
};
public XElement GetXElement => new("Food", new XAttribute("ID", ID),
new XElement("ComponentName", ComponentName),
new XElement("ProductName", ComponentName),
new XElement("Price", Price.ToString()));
}
}

View File

@ -34,7 +34,7 @@ namespace DinerView
{
dataGridView.DataSource = list;
dataGridView.Columns["ID"].Visible = false;
dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ProductName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка продуктов");
}

View File

@ -181,7 +181,8 @@ namespace DinerView
private void ordersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
if (service is FormReportOrders form) {
if (service is FormReportOrders form)
{
form.ShowDialog();
}
}

View File

@ -34,8 +34,8 @@ namespace DinerView
dataGridView.Rows.Clear();
foreach (var elem in dict)
{
dataGridView.Rows.Add(new object[] { elem.ComponentName, "", "" });
foreach (var listElem in elem.Products)
dataGridView.Rows.Add(new object[] { elem.ProductName, "", "" });
foreach (var listElem in elem.Components)
{
dataGridView.Rows.Add(new object[] { " ", listElem.Item1, listElem.Item2 });
}

View File

@ -93,7 +93,7 @@ namespace DinerView
if (form.ShowDialog() == DialogResult.OK)
{
if (form.foodModel == null) return;
_logger.LogInformation("Добавление нового снэка: {ComponentName} - {Count}", form.foodModel.ComponentName, form.Count);
_logger.LogInformation("Добавление нового снэка: {ProductName} - {Count}", form.foodModel.ComponentName, form.Count);
if (_productComponents.ContainsKey(form.ID))
{
_productComponents[form.ID] = (form.foodModel, form.Count);
@ -120,7 +120,7 @@ namespace DinerView
if (form.ShowDialog() == DialogResult.OK)
{
if (form.foodModel == null) return;
_logger.LogInformation("Изменение снэка: {ComponentName} - {Count}", form.foodModel.ComponentName, form.Count);
_logger.LogInformation("Изменение снэка: {ProductName} - {Count}", form.foodModel.ComponentName, form.Count);
_productComponents[form.ID] = (form.foodModel, form.Count);
LoadData();
}
@ -136,7 +136,7 @@ namespace DinerView
{
try
{
_logger.LogInformation("Удаление снэка: {ComponentName}", dataGridView.SelectedRows[0].Cells[1].Value);
_logger.LogInformation("Удаление снэка: {ProductName}", dataGridView.SelectedRows[0].Cells[1].Value);
_productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
}
catch (Exception ex)

View File

@ -57,7 +57,7 @@ namespace DinerView
_list = logic.ReadList(null);
if (_list != null)
{
comboBoxComponent.DisplayMember = "ComponentName";
comboBoxComponent.DisplayMember = "ProductName";
comboBoxComponent.ValueMember = "ID";
comboBoxComponent.DataSource = _list;
comboBoxComponent.SelectedItem = null;

View File

@ -17,8 +17,8 @@
<CommandText>/* Local Query */</CommandText>
</Query>
<Fields>
<Field Name="Id">
<DataField>Id</DataField>
<Field Name="ID">
<DataField>ID</DataField>
<rd:TypeName>System.Int32</rd:TypeName>
</Field>
<Field Name="DateCreate">
@ -33,6 +33,10 @@
<DataField>Sum</DataField>
<rd:TypeName>System.Decimal</rd:TypeName>
</Field>
<Field Name="Status">
<DataField>OrderStatus</DataField>
<rd:TypeName>System.Decimal</rd:TypeName>
</Field>
</Fields>
<rd:DataSetInfo>
<rd:DataSetName>DinerContracts.ViewModels</rd:DataSetName>
@ -127,6 +131,9 @@
<TablixColumn>
<Width>2.5cm</Width>
</TablixColumn>
<TablixColumn>
<Width>2.5cm</Width>
</TablixColumn>
</TablixColumns>
<TablixRows>
<TablixRow>
@ -205,7 +212,7 @@
<Paragraph>
<TextRuns>
<TextRun>
<Value>Изделие</Value>
<Value>Снэк</Value>
<Style>
<FontWeight>Bold</FontWeight>
</Style>
@ -260,6 +267,38 @@
</Textbox>
</CellContents>
</TablixCell>
<TablixCell>
<CellContents>
<Textbox Name="Textbox2">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>Status</Value>
<Style>
<FontWeight>Bold</FontWeight>
</Style>
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox2</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
</TablixCells>
</TablixRow>
<TablixRow>
@ -267,21 +306,21 @@
<TablixCells>
<TablixCell>
<CellContents>
<Textbox Name="Id">
<Textbox Name="ID">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Fields!Id.Value</Value>
<Value>=Fields!ID.Value</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Id</rd:DefaultName>
<rd:DefaultName>ID</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
@ -387,6 +426,36 @@
</Textbox>
</CellContents>
</TablixCell>
<TablixCell>
<CellContents>
<Textbox Name="Status">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Fields!Status.Value</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Status</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
</TablixCells>
</TablixRow>
</TablixRows>
@ -397,6 +466,7 @@
<TablixMember />
<TablixMember />
<TablixMember />
<TablixMember />
</TablixMembers>
</TablixColumnHierarchy>
<TablixRowHierarchy>
@ -413,7 +483,7 @@
<Top>2.48391cm</Top>
<Left>0.55245cm</Left>
<Height>1.2cm</Height>
<Width>16.44755cm</Width>
<Width>18.94755cm</Width>
<ZIndex>2</ZIndex>
<Style>
<Border>
@ -491,7 +561,7 @@
<Height>5.72875cm</Height>
<Style />
</Body>
<Width>21cm</Width>
<Width>25.43558cm</Width>
<Page>
<PageHeight>29.7cm</PageHeight>
<PageWidth>21cm</PageWidth>

View File

@ -47,7 +47,7 @@ namespace DineryBusinessLogic.BusinessLogic
public FoodViewModel? ReadElement(FoodSearchModel model)
{
if (model == null) throw new ArgumentNullException(nameof(model));
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}. ID:{ID}", model.ComponentName, model.ID);
_logger.LogInformation("ReadElement. ProductName:{ProductName}. ID:{ID}", model.ComponentName, model.ID);
var element = _componentStorage.GetElement(model);
if (element == null) {
_logger.LogWarning("ReadElement. element not found");
@ -59,7 +59,7 @@ namespace DineryBusinessLogic.BusinessLogic
public List<FoodViewModel>? ReadList(FoodSearchModel? model)
{
_logger.LogInformation("ReadList. ComponentName:{ComponentName}. ID:{ID}", model?.ComponentName, model?.ID);
_logger.LogInformation("ReadList. ProductName:{ProductName}. ID:{ID}", model?.ComponentName, model?.ID);
var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
if (list == null) {
_logger.LogWarning("ReadList return null list");
@ -86,7 +86,7 @@ namespace DineryBusinessLogic.BusinessLogic
throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName));
if (model.Price <= 0)
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Price));
_logger.LogInformation("Component. ComponentName:{ComponentName}. Price:{Price}. ID:{ID}",
_logger.LogInformation("Component. ProductName:{ProductName}. Price:{Price}. ID:{ID}",
model.ComponentName, model.Price, model.ID);
var element = _componentStorage.GetElement(new FoodSearchModel { ComponentName = model.ComponentName });
if (element != null && element.ID != model.ID)

View File

@ -44,6 +44,7 @@ namespace DineryBusinessLogic.BusinessLogic
DateCreate = x.DateCreate,
ProductName = x.ProductName,
Sum = x.Sum,
OrderStatus = x.Status.ToString(),
})
.ToList();
}
@ -53,17 +54,17 @@ namespace DineryBusinessLogic.BusinessLogic
var components = _componentStorage.GetFullList();
Review

При получении изделий, у них уже есть список компонент, отдельно его получать не требуется

При получении изделий, у них уже есть список компонент, отдельно его получать не требуется
Review

Так мы же в логике проходимся по всем созданным компонентам, смотрим есть ли такое в словаре компонет изделия, если есть, то уже в созданном объекте record дополняем список и добавляем 1 к totalcount. У нас же может быть создан компонент, который в изделиях не использован. Поэтому у нас будет recoed {ComponentName = "",Products = [], totalCount = 0};

Так мы же в логике проходимся по всем созданным компонентам, смотрим есть ли такое в словаре компонет изделия, если есть, то уже в созданном объекте record дополняем список и добавляем 1 к totalcount. У нас же может быть создан компонент, который в изделиях не использован. Поэтому у нас будет recoed {ComponentName = "",Products = [], totalCount = 0};
var products = _productStorage.GetFullList();
var list = new List<ReportSnackFoodsViewModel>();
foreach (var component in components) {
foreach (var pr in products) {
var record = new ReportSnackFoodsViewModel
{
ComponentName = component.ComponentName,
Products = new List<(string, int)>(),
ProductName = pr.ProductName,
Components = new(),
TotalCount = 0
};
foreach (var product in products) {
if (product.ProductComponents.ContainsKey(component.ID)) {
record.Products.Add(new(product.ProductName, product.ProductComponents[component.ID].Item2));
record.TotalCount += product.ProductComponents[component.ID].Item2;
foreach (var cp in components) {
if (pr.ProductComponents.ContainsKey(cp.ID)) {
record.Components.Add(new(cp.ComponentName, pr.ProductComponents[cp.ID].Item2));
record.TotalCount += pr.ProductComponents[cp.ID].Item2;
}
}
list.Add(record);
@ -77,7 +78,7 @@ namespace DineryBusinessLogic.BusinessLogic
{
FileName = model.FileName,
Title = "Список еды",
Components = _componentStorage.GetFullList()
Products = _productStorage.GetFullList(),
});
}

View File

@ -32,11 +32,11 @@ namespace DineryBusinessLogic.OfficePackage
{
ColumnName = "A",
RowIndex = rowIndex,
Text = pc.ComponentName,
Text = pc.ProductName,
StyleInfo = ExcelStyleInfoType.Title
});
rowIndex++;
foreach (var (Product, Count) in pc.Products) {
foreach (var (Product, Count) in pc.Components) {
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",

View File

@ -25,10 +25,10 @@ namespace DineryBusinessLogic.OfficePackage
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Right
});
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm" });
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm", "3cm" });
CreateRow(new PdfRowParameters
{
Text = new List<string> { "Номер", "Дата заказа", "Изделие", "Сумма" },
Text = new List<string> { "Номер", "Дата заказа", "Изделие", "Сумма", "Статус" },
Style = "NormalTittle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
@ -37,7 +37,7 @@ namespace DineryBusinessLogic.OfficePackage
CreateRow(new PdfRowParameters
{
Text = new List<string> { order.ID.ToString(), order.DateCreate.ToShortTimeString(),
order.ProductName, order.Sum.ToString() },
order.ProductName, order.Sum.ToString(), order.OrderStatus.ToString() },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});

View File

@ -21,15 +21,15 @@ namespace DineryBusinessLogic.OfficePackage
JustificationType = WordJustificationType.Center
}
});
foreach (var component in info.Components) {
foreach (var pr in info.Products)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (component.ComponentName, new WordTextProperties { Size = "24", }) },
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.both
}
Texts = new List<(string, WordTextProperties)> {
(pr.ProductName+' ', new WordTextProperties { Size = "24", Bold = true }),
(pr.Price.ToString(), new WordTextProperties { Size = "24" })
},
TextProperties = new WordTextProperties { Size = "24", Bold = true}
});
}
SaveWord(info);

View File

@ -11,6 +11,6 @@ namespace DineryBusinessLogic.OfficePackage.HelperModels
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<FoodViewModel> Components { get; set; } = new();
public List<SnackViewModel> Products { get; set; } = new();
}
}