правильные выводы в файлики

This commit is contained in:
2024-04-01 23:48:54 +04:00
parent 26ed21219d
commit 3e0efda331
11 changed files with 102 additions and 50 deletions

View File

@@ -162,7 +162,7 @@ namespace ComputersShop
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK)
{
_reportLogic.SaveComponentsToWordFile(new ReportBindingModel
_reportLogic.SaveComputersToWordFile(new ReportBindingModel
{
FileName = dialog.FileName
});

View File

@@ -35,11 +35,11 @@ namespace ComputersShop
{
dataGridView.Rows.Add(new object[]
{
elem.ComponentName,
elem.ComputerName,
"",
""
});
foreach (var listElem in elem.Computers)
foreach (var listElem in elem.Components)
{
dataGridView.Rows.Add(new object[]
{

View File

@@ -33,6 +33,10 @@
<DataField>Sum</DataField>
<rd:TypeName>System.Decimal</rd:TypeName>
</Field>
<Field Name="Status">
<DataField>Status</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
</Fields>
<rd:DataSetInfo>
<rd:DataSetName>ComputerNameContracts.ViewModels</rd:DataSetName>
@@ -92,11 +96,14 @@
<Width>5.50333cm</Width>
</TablixColumn>
<TablixColumn>
<Width>10.28935cm</Width>
<Width>6.82331cm</Width>
</TablixColumn>
<TablixColumn>
<Width>6.1195cm</Width>
</TablixColumn>
<TablixColumn>
<Width>5.17229cm</Width>
</TablixColumn>
</TablixColumns>
<TablixRows>
<TablixRow>
@@ -258,6 +265,36 @@
</Textbox>
</CellContents>
</TablixCell>
<TablixCell>
<CellContents>
<Textbox Name="Textbox1">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>Статус</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox1</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>
@@ -364,7 +401,7 @@
</TablixCell>
<TablixCell>
<CellContents>
<Textbox Name="Textbox11">
<Textbox Name="Sum">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
@@ -378,7 +415,6 @@
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox11</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
@@ -392,6 +428,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>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
<rd:Selected>true</rd:Selected>
</CellContents>
</TablixCell>
</TablixCells>
</TablixRow>
</TablixRows>
@@ -402,6 +468,7 @@
<TablixMember />
<TablixMember />
<TablixMember />
<TablixMember />
</TablixMembers>
</TablixColumnHierarchy>
<TablixRowHierarchy>
@@ -418,7 +485,7 @@
<Top>2.34103cm</Top>
<Left>0.42333cm</Left>
<Height>2.47cm</Height>
<Width>27.41551cm</Width>
<Width>29.12176cm</Width>
<ZIndex>1</ZIndex>
<Style>
<Border>
@@ -518,7 +585,7 @@
<Height>2.81911in</Height>
<Style />
</Body>
<Width>11.43426in</Width>
<Width>11.94443in</Width>
<Page>
<PageHeight>29.7cm</PageHeight>
<PageWidth>21cm</PageWidth>

View File

@@ -34,29 +34,12 @@ namespace ComputersShopBusinessLogic.BusinessLogics
}
public List<ReportComputerComponentViewModel> GetComputerComponent()
{
var components = _componentStorage.GetFullList();
var computers = _computerStorage.GetFullList();
var list = new List<ReportComputerComponentViewModel>();
foreach ( var component in components )
return _computerStorage.GetFullList().Select(x => new ReportComputerComponentViewModel
{
var record = new ReportComputerComponentViewModel
{
ComponentName = component.ComponentName,
Computers = new List<Tuple<string, int>>(),
TotalCount = 0
};
foreach ( var computer in computers)
{
if(computer.ComputerComponents.ContainsKey(component.Id))
{
record.Computers.Add(new Tuple<string, int>(computer.ComputerName,
computer.ComputerComponents[component.Id].Item2));
record.TotalCount += computer.ComputerComponents[component.Id].Item2;
}
}
list.Add(record);
}
return list;
ComputerName = x.ComputerName,
Components = x.ComputerComponents.Select(x => (x.Value.Item1.ComponentName, x.Value.Item2)).ToList(),
TotalCount = x.ComputerComponents.Select(x => x.Value.Item2).Sum()
}).ToList();
}
public List<ReportOrsersViewModel> GetOrders(ReportBindingModel model)
{
@@ -70,16 +53,17 @@ namespace ComputersShopBusinessLogic.BusinessLogics
Id = x.Id,
DateCreate = x.DateCreate,
ComputerName = x.ComputerName,
Sum = x.Sum
Sum = x.Sum,
Status = x.Status.ToString(),
}).ToList();
}
public void SaveComponentsToWordFile(ReportBindingModel model)
public void SaveComputersToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список компонентов",
Components = _componentStorage.GetFullList()
Title = "Список компьютеров",
Computers = _computerStorage.GetFullList()
});
}
public void SaveComputerComponentsToExcelFile(ReportBindingModel model)

View File

@@ -26,23 +26,23 @@ namespace ComputersShopBusinessLogic.OfficePackege
CellToName = "C1"
});
uint rowIndex = 2;
foreach (var pc in info.ComputerComponents)
foreach (var cc in info.ComputerComponents)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = pc.ComponentName,
Text = cc.ComputerName,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var product in pc.Computers)
foreach (var component in cc.Components)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = product.Item1,
Text = component.Item1,
StyleInfo =
ExcelStyleInfoType.TextWithBorder
});
@@ -50,7 +50,7 @@ namespace ComputersShopBusinessLogic.OfficePackege
{
ColumnName = "C",
RowIndex = rowIndex,
Text = product.Item2.ToString(),
Text = component.Item2.ToString(),
StyleInfo =
ExcelStyleInfoType.TextWithBorder
});
@@ -67,7 +67,7 @@ namespace ComputersShopBusinessLogic.OfficePackege
{
ColumnName = "C",
RowIndex = rowIndex,
Text = pc.TotalCount.ToString(),
Text = cc.TotalCount.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;

View File

@@ -24,10 +24,10 @@ namespace ComputersShopBusinessLogic.OfficePackege
Text = $"с { info.DateFrom.ToShortDateString() } по { info.DateTo.ToShortDateString() }", Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm" });
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm", "3cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Номер", "Дата заказа", "Изделие", "Сумма" },
Texts = new List<string> { "Номер", "Дата заказа", "Изделие", "Сумма", "Статус" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
@@ -35,7 +35,7 @@ namespace ComputersShopBusinessLogic.OfficePackege
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.ComputerName, order.Sum.ToString() },
Texts = new List<string> { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.ComputerName, order.Sum.ToString(), order.Status },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});

View File

@@ -27,14 +27,14 @@ namespace ComputersShopBusinessLogic.OfficePackege
}
});
foreach (var component in info.Components)
foreach (var computer in info.Computers)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
(component.ComponentName,
new WordTextProperties { Size = "24", })
(computer.ComputerName, new WordTextProperties { Size = "24", Bold = true}),
("\t" + computer.Price.ToString(), new WordTextProperties { Size = "24"}),
},
TextProperties = new WordTextProperties
{

View File

@@ -11,6 +11,6 @@ namespace ComputersShopBusinessLogic.OfficePackege.HelperModels
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ComponentViewModel> Components { get; set; } = new();
public List<ComputerViewModel> Computers { get; set; } = new();
}
}

View File

@@ -12,7 +12,7 @@ namespace ComputersShopContracts.BuisnessLogicsContracts
{
List<ReportComputerComponentViewModel> GetComputerComponent();
List<ReportOrsersViewModel> GetOrders(ReportBindingModel model);
void SaveComponentsToWordFile(ReportBindingModel model);
void SaveComputersToWordFile(ReportBindingModel model);
void SaveComputerComponentsToExcelFile(ReportBindingModel model);
void SaveOrdersToPdfFile(ReportBindingModel model);
}

View File

@@ -8,8 +8,8 @@ namespace ComputersShopContracts.ViewModels
{
public class ReportComputerComponentViewModel
{
public string ComponentName { get; set; } = string.Empty;
public string ComputerName { get; set; } = string.Empty;
public int TotalCount { get; set; }
public List<Tuple<string, int>> Computers { get; set; } = new();
public List<(string Component, int Count)> Components { get; set; } = new();
}
}

View File

@@ -12,5 +12,6 @@ namespace ComputersShopContracts.ViewModels
public DateTime DateCreate { get; set; }
public string ComputerName { get; set; } = string.Empty;
public double Sum { get; set; }
public string Status { get; set; }
}
}