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

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

View File

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

View File

@ -117,10 +117,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="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> <value>True</value>
</metadata> </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> <value>True</value>
</metadata> </metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <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" CellToName = "C1"
}); });
uint rowIndex = 2; uint rowIndex = 2;
foreach (var pc in info.SushiComponents) foreach (var sc in info.SushiComponents)
{ {
InsertCellInWorksheet(new ExcelCellParameters InsertCellInWorksheet(new ExcelCellParameters
{ {
ColumnName = "A", ColumnName = "A",
RowIndex = rowIndex, RowIndex = rowIndex,
Text = pc.ComponentName, Text = sc.SushiName,
StyleInfo = ExcelStyleInfoType.Text StyleInfo = ExcelStyleInfoType.Text
}); });
rowIndex++; rowIndex++;
foreach (var product in pc.Sushis) foreach (var component in sc.Components)
{ {
InsertCellInWorksheet(new ExcelCellParameters InsertCellInWorksheet(new ExcelCellParameters
{ {
ColumnName = "B", ColumnName = "B",
RowIndex = rowIndex, RowIndex = rowIndex,
Text = product.Item1, Text = component.Item1,
StyleInfo = StyleInfo = ExcelStyleInfoType.TextWithBroder
ExcelStyleInfoType.TextWithBroder
}); });
InsertCellInWorksheet(new ExcelCellParameters InsertCellInWorksheet(new ExcelCellParameters
{ {
ColumnName = "C", ColumnName = "C",
RowIndex = rowIndex, RowIndex = rowIndex,
Text = product.Item2.ToString(), Text = component.Item2.ToString(),
StyleInfo = StyleInfo = ExcelStyleInfoType.TextWithBroder
ExcelStyleInfoType.TextWithBroder
}); });
rowIndex++; rowIndex++;
} }
@ -67,7 +65,7 @@ namespace SushiBarBusinessLogic.OfficePackage
{ {
ColumnName = "C", ColumnName = "C",
RowIndex = rowIndex, RowIndex = rowIndex,
Text = pc.TotalCount.ToString(), Text = sc.TotalCount.ToString(),
StyleInfo = ExcelStyleInfoType.Text StyleInfo = ExcelStyleInfoType.Text
}); });
rowIndex++; rowIndex++;

View File

@ -10,7 +10,10 @@ namespace SushiBarBusinessLogic.OfficePackage
CreateWord(info); CreateWord(info);
CreateParagraph(new WordParagraph 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 TextProperties = new WordTextProperties
{ {
Size = "24", Size = "24",
@ -22,8 +25,10 @@ namespace SushiBarBusinessLogic.OfficePackage
CreateParagraph(new WordParagraph CreateParagraph(new WordParagraph
{ {
Texts = new List<(string, WordTextProperties)> { 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 TextProperties = new WordTextProperties
{ {
Size = "24", Size = "24",

View File

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

View File

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

View File

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