изменения к требованиям по сохранению в ворд и эксель

This commit is contained in:
ekallin 2024-03-30 18:38:45 +03:00
parent 9acfdd7a5b
commit 408a86401a
9 changed files with 70 additions and 83 deletions

View File

@ -29,10 +29,10 @@
private void InitializeComponent()
{
dataGridView1 = new DataGridView();
Component = new DataGridViewTextBoxColumn();
Sushi = new DataGridViewTextBoxColumn();
Count = new DataGridViewTextBoxColumn();
buttonSaveToExcel = new Button();
Sushi = new DataGridViewTextBoxColumn();
Component = new DataGridViewTextBoxColumn();
Count = new DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
SuspendLayout();
//
@ -41,7 +41,7 @@
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView1.BackgroundColor = Color.LightGoldenrodYellow;
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView1.Columns.AddRange(new DataGridViewColumn[] { Component, Sushi, Count });
dataGridView1.Columns.AddRange(new DataGridViewColumn[] { Sushi, Component, Count });
dataGridView1.Dock = DockStyle.Bottom;
dataGridView1.Location = new Point(0, 57);
dataGridView1.Name = "dataGridView1";
@ -50,24 +50,6 @@
dataGridView1.Size = new Size(800, 448);
dataGridView1.TabIndex = 0;
//
// Component
//
Component.HeaderText = "Компонент";
Component.MinimumWidth = 6;
Component.Name = "Component";
//
// Sushi
//
Sushi.HeaderText = "Суши";
Sushi.MinimumWidth = 6;
Sushi.Name = "Sushi";
//
// Count
//
Count.HeaderText = "Количество";
Count.MinimumWidth = 6;
Count.Name = "Count";
//
// buttonSaveToExcel
//
buttonSaveToExcel.BackColor = Color.Goldenrod;
@ -79,6 +61,24 @@
buttonSaveToExcel.UseVisualStyleBackColor = false;
buttonSaveToExcel.Click += ButtonSaveToExcel_Click;
//
// Sushi
//
Sushi.HeaderText = "Суши";
Sushi.MinimumWidth = 6;
Sushi.Name = "Sushi";
//
// Component
//
Component.HeaderText = "Компонент";
Component.MinimumWidth = 6;
Component.Name = "Component";
//
// Count
//
Count.HeaderText = "Количество";
Count.MinimumWidth = 6;
Count.Name = "Count";
//
// FormReportSushiComponent
//
AutoScaleDimensions = new SizeF(8F, 20F);
@ -88,7 +88,7 @@
Controls.Add(dataGridView1);
Name = "FormReportSushiComponent";
Text = "Компоненты по изделиям";
Load += FormReportProductComponents_Load;
Load += FormReportSushiComponents_Load;
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
ResumeLayout(false);
}
@ -97,8 +97,8 @@
private DataGridView dataGridView1;
private Button buttonSaveToExcel;
private DataGridViewTextBoxColumn Component;
private DataGridViewTextBoxColumn Sushi;
private DataGridViewTextBoxColumn Component;
private DataGridViewTextBoxColumn Count;
}
}

View File

@ -14,7 +14,7 @@ namespace SushiBarView
_logger = logger;
_logic = logic;
}
private void FormReportProductComponents_Load(object sender, EventArgs e)
private void FormReportSushiComponents_Load(object sender, EventArgs e)
{
try
{
@ -24,8 +24,8 @@ namespace SushiBarView
dataGridView1.Rows.Clear();
foreach (var elem in dict)
{
dataGridView1.Rows.Add(new object[] { elem.ComponentName, "", "" });
foreach (var listElem in elem.Sushis)
dataGridView1.Rows.Add(new object[] { elem.SushiName, "", "" });
foreach (var listElem in elem.Components)
{
dataGridView1.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 });
}

View File

@ -117,10 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="Component.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<metadata name="Sushi.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Sushi.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<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">

View File

@ -26,33 +26,31 @@ namespace SushiBarBusinessLogic.OfficePackage
CellToName = "C1"
});
uint rowIndex = 2;
foreach (var pc in info.SushiComponents)
foreach (var sc in info.SushiComponents)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = pc.ComponentName,
Text = sc.SushiName,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var product in pc.Sushis)
foreach (var component in sc.Components)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = product.Item1,
StyleInfo =
ExcelStyleInfoType.TextWithBroder
Text = component.Item1,
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = product.Item2.ToString(),
StyleInfo =
ExcelStyleInfoType.TextWithBroder
Text = component.Item2.ToString(),
StyleInfo = ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
}
@ -67,7 +65,7 @@ namespace SushiBarBusinessLogic.OfficePackage
{
ColumnName = "C",
RowIndex = rowIndex,
Text = pc.TotalCount.ToString(),
Text = sc.TotalCount.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;

View File

@ -10,7 +10,10 @@ namespace SushiBarBusinessLogic.OfficePackage
CreateWord(info);
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
Texts = new List<(string, WordTextProperties)>
{
(info.Title, new WordTextProperties { Bold = true, Size = "24", })
},
TextProperties = new WordTextProperties
{
Size = "24",
@ -22,8 +25,10 @@ namespace SushiBarBusinessLogic.OfficePackage
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> {
(sushi.SushiName, new WordTextProperties { Size = "24", })
(sushi.SushiName, new WordTextProperties { Bold = true, Size = "24", }),
(" цена: " + sushi.Price.ToString() + " рублей", new WordTextProperties { Size = "24", })
},
TextProperties = new WordTextProperties
{
Size = "24",

View File

@ -151,30 +151,24 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
var tableStyles = new TableStyles()
{
Count = 0U,
DefaultTableStyle =
"TableStyleMedium2",
DefaultTableStyle = "TableStyleMedium2",
DefaultPivotStyle = "PivotStyleLight16"
};
var stylesheetExtensionList = new StylesheetExtensionList();
var stylesheetExtension1 = new StylesheetExtension()
{
Uri =
"{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"
Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"
};
stylesheetExtension1.AddNamespaceDeclaration("x14",
"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
stylesheetExtension1.Append(new SlicerStyles()
{
DefaultSlicerStyle =
"SlicerStyleLight1"
DefaultSlicerStyle = "SlicerStyleLight1"
});
var stylesheetExtension2 = new StylesheetExtension()
{
Uri =
"{9260A510-F301-46a8-8635-F512D64BE5F5}"
Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}"
};
stylesheetExtension2.AddNamespaceDeclaration("x15",
"http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
stylesheetExtension2.Append(new TimelineStyles()
{
DefaultTimelineStyle = "TimeSlicerStyleLight1"
@ -242,8 +236,7 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
sheets.Append(sheet);
_worksheet = worksheetPart.Worksheet;
}
protected override void InsertCellInWorksheet(ExcelCellParameters
excelParams)
protected override void InsertCellInWorksheet(ExcelCellParameters excelParams)
{
if (_worksheet == null || _shareStringPart == null)
{
@ -256,11 +249,9 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
}
// Ищем строку, либо добавляем ее
Row row;
if (sheetData.Elements<Row>().Where(r => r.RowIndex! ==
excelParams.RowIndex).Any())
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).Any())
{
row = sheetData.Elements<Row>().Where(r => r.RowIndex! ==
excelParams.RowIndex).First();
row = sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).First();
}
else
{
@ -269,21 +260,18 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
}
// Ищем нужную ячейку
Cell cell;
if (row.Elements<Cell>().Where(c => c.CellReference!.Value ==
excelParams.CellReference).Any())
if (row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).Any())
{
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value ==
excelParams.CellReference).First();
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).First();
}
else
{
// Все ячейки должны быть последовательно друг за другом расположены
// нужно определить, после какой вставлять
Cell? refCell = null;
Cell? refCell = null;
foreach (Cell rowCell in row.Elements<Cell>())
{
if (string.Compare(rowCell.CellReference!.Value,
excelParams.CellReference, true) > 0)
if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0)
{
refCell = rowCell;
break;
@ -291,19 +279,15 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
}
var newCell = new Cell()
{
CellReference =
excelParams.CellReference
CellReference = excelParams.CellReference
};
row.InsertBefore(newCell, refCell);
cell = newCell;
}
// вставляем новый текст
_shareStringPart.SharedStringTable.AppendChild(new
SharedStringItem(new Text(excelParams.Text)));
_shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text)));
_shareStringPart.SharedStringTable.Save();
cell.CellValue = new
CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count(
) - 1).ToString());
cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count() - 1).ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
}

View File

@ -95,4 +95,4 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
renderer.PdfDocument.Save(info.FileName);
}
}
}
}

View File

@ -37,19 +37,19 @@ namespace SushiBarBusinessLogic
var components = _componentStorage.GetFullList();
var sushis = _sushiStorage.GetFullList();
var list = new List<ReportSushiComponentViewModel>();
foreach (var component in components)
foreach (var sushi in sushis)
{
var record = new ReportSushiComponentViewModel
{
ComponentName = component.ComponentName,
Sushis = new List<Tuple<string, int>>(),
SushiName = sushi.SushiName,
Components = new List<Tuple<string, int>>(),
TotalCount = 0
};
foreach (var sushi in sushis)
foreach (var component in components)
{
if (sushi.SushiComponents.ContainsKey(component.Id))
{
record.Sushis.Add(new Tuple<string, int>(sushi.SushiName, sushi.SushiComponents[component.Id].Item2));
record.Components.Add(new Tuple<string, int>(component.ComponentName, sushi.SushiComponents[component.Id].Item2));
record.TotalCount += sushi.SushiComponents[component.Id].Item2;
}
}
@ -85,7 +85,7 @@ namespace SushiBarBusinessLogic
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список компонент",
Title = "Список суши",
Sushi = _sushiStorage.GetFullList()
});
}
@ -98,7 +98,7 @@ namespace SushiBarBusinessLogic
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список компонент",
Title = "Список изделий",
SushiComponents = GetSushiComponent()
});
}

View File

@ -2,9 +2,9 @@
{
public class ReportSushiComponentViewModel
{
public string ComponentName { get; set; } = string.Empty;
public string SushiName { get; set; } = string.Empty;
public int TotalCount { get; set; }
public List<Tuple<string, int>> Sushis { get; set; } = new();
public List<Tuple<string, int>> Components { get; set; } = new();
}
}