Ну вроде работает сохранение магазинов

This commit is contained in:
dasha 2023-03-23 16:33:10 +04:00
parent 0a4909706f
commit 146a8cd252
8 changed files with 178 additions and 13 deletions

View File

@ -32,11 +32,11 @@
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ингредиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.сушиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.shopsToolStripMenuItem = 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.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonUpdate = new System.Windows.Forms.Button();
this.buttonSetToFinish = new System.Windows.Forms.Button();
this.buttonSetToDone = new System.Windows.Forms.Button();
@ -45,6 +45,7 @@
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonAddSushiInShop = new System.Windows.Forms.Button();
this.buttonSellSushi = new System.Windows.Forms.Button();
this.списокМагазиновToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@ -84,12 +85,20 @@
this.сушиToolStripMenuItem.Text = "Суши";
this.сушиToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click);
//
// shopsToolStripMenuItem
//
this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem";
this.shopsToolStripMenuItem.Size = new System.Drawing.Size(148, 22);
this.shopsToolStripMenuItem.Text = "Магазины";
this.shopsToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click);
//
// отчетыToolStripMenuItem
//
this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.списокИнгредиентовToolStripMenuItem,
this.ингредиентыПоСушиToolStripMenuItem,
this.списокЗаказовToolStripMenuItem});
this.списокЗаказовToolStripMenuItem,
this.списокМагазиновToolStripMenuItem});
this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(60, 20);
this.отчетыToolStripMenuItem.Text = "Отчеты";
@ -115,13 +124,6 @@
this.списокЗаказовToolStripMenuItem.Text = "Список заказов";
this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click);
//
// shopsToolStripMenuItem
//
this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem";
this.shopsToolStripMenuItem.Size = new System.Drawing.Size(148, 22);
this.shopsToolStripMenuItem.Text = "Магазины";
this.shopsToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(778, 212);
@ -211,6 +213,13 @@
this.buttonSellSushi.UseVisualStyleBackColor = true;
this.buttonSellSushi.Click += new System.EventHandler(this.ButtonSellSushi_Click);
//
// списокМагазиновToolStripMenuItem
//
this.списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem";
this.списокМагазиновToolStripMenuItem.Size = new System.Drawing.Size(203, 22);
this.списокМагазиновToolStripMenuItem.Text = "Список магазинов";
this.списокМагазиновToolStripMenuItem.Click += new System.EventHandler(this.ShopsReportToolStripMenuItem_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@ -256,5 +265,6 @@
private ToolStripMenuItem shopsToolStripMenuItem;
private Button buttonAddSushiInShop;
private Button buttonSellSushi;
private ToolStripMenuItem списокМагазиновToolStripMenuItem;
}
}

View File

@ -155,6 +155,16 @@ namespace SushiBarView
}
}
private void ShopsReportToolStripMenuItem_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK)
{
_reportLogic.SaveShopsToWordFile(new ReportBindingModel { FileName = dialog.FileName });
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void SushiIngredientToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportSushiIngredients));

View File

@ -16,14 +16,16 @@ namespace SushiBarBusinessLogic.BusinessLogics
private readonly IOrderStorage _orderStorage;
private readonly IShopStorage _shopStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(ISushiStorage productStorage, IIngredientStorage ingredientStorage, IOrderStorage orderStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
public ReportLogic(ISushiStorage productStorage, IIngredientStorage ingredientStorage, IOrderStorage orderStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf, IShopStorage shopStorage)
{
_sushiStorage = productStorage;
_ingredientStorage = ingredientStorage;
@ -32,6 +34,7 @@ namespace SushiBarBusinessLogic.BusinessLogics
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
_shopStorage = shopStorage;
}
/// <summary>
@ -103,6 +106,20 @@ namespace SushiBarBusinessLogic.BusinessLogics
});
}
/// <summary>
/// Сохранение магазинов в файл-Word
/// </summary>
/// <param name="model"></param>
public void SaveShopsToWordFile(ReportBindingModel model)
{
_saveToWord.CreateShopsDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список магазинов",
Shops = _shopStorage.GetFullList()
});
}
/// <summary>
/// Сохранение ингредиентов с указаеним суши в файл-Excel
/// </summary>

View File

@ -23,7 +23,7 @@ namespace SushiBarBusinessLogic.OfficePackage
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> {
Texts = new List<(string, WordTextProperties)> {
(sushi.SushiName+' ', new WordTextProperties { Size = "24", Bold = true }),
(sushi.Price.ToString(), new WordTextProperties { Size = "24" })
},
@ -38,12 +38,69 @@ namespace SushiBarBusinessLogic.OfficePackage
SaveWord(info);
}
public void CreateShopsDoc(WordInfo info)
{
CreateWord(info);
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24" }) },
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Center
}
});
List<WordRow> rows = new List<WordRow>();
rows.Add(new WordRow
{
Texts = new List<(string, WordTextProperties)> {
("Название", new WordTextProperties { Size = "24", Bold = true }),
("Адрес", new WordTextProperties { Size = "24", Bold = true }),
("Дата открытия", new WordTextProperties { Size = "24", Bold = true })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
foreach (var shop in info.Shops)
{
rows.Add(new WordRow
{
Texts = new List<(string, WordTextProperties)> {
(shop.ShopName, new WordTextProperties { Size = "24" }),
(shop.Address, new WordTextProperties { Size = "24" }),
(shop.DateOpening.ToShortDateString(), new WordTextProperties { Size = "24" })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
CreateTable(rows);
SaveWord(info);
}
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateWord(WordInfo info);
/// <summary>
/// Создание таблицы
/// </summary>
/// <param name="rows"></param>
protected abstract void CreateTable(List<WordRow> rows);
/// <summary>
/// Создание абзаца с текстом
/// </summary>

View File

@ -9,5 +9,7 @@ namespace SushiBarBusinessLogic.OfficePackage.HelperModels
public string Title { get; set; } = string.Empty;
public List<SushiViewModel> ListSushi { get; set; } = new();
public List<ShopViewModel> Shops { get; set; } = new();
}
}

View File

@ -0,0 +1,9 @@
namespace SushiBarBusinessLogic.OfficePackage.HelperModels
{
public class WordRow
{
public List<(string, WordTextProperties)> Texts { get; set; } = new();
public WordTextProperties? TextProperties { get; set; }
}
}

View File

@ -89,6 +89,60 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
_docBody = mainPart.Document.AppendChild(new Body());
}
protected override void CreateTable(List<WordRow> data)
{
if (_docBody == null || data == null)
{
return;
}
Table table = new Table();
var tableProp = new TableProperties();
tableProp.AppendChild(new TableLayout { Type = TableLayoutValues.Fixed });
tableProp.AppendChild(new TableBorders(
new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 }
));
tableProp.AppendChild(new TableWidth { Type = TableWidthUnitValues.Auto });
table.AppendChild(tableProp);
TableGrid tableGrid = new TableGrid();
for (int j = 0; j < data[0].Texts.Count; ++j)
{
tableGrid.AppendChild(new GridColumn() { Width = "3200" });
}
table.AppendChild(tableGrid);
for (int i = 0; i < data.Count; ++i)
{
TableRow docRow = new TableRow();
for (int j = 0; j < data[i].Texts.Count; ++j)
{
var docParagraph = new Paragraph();
var docRun = new Run();
var runProperties = new RunProperties();
docParagraph.AppendChild(CreateParagraphProperties(data[i].Texts[j].Item2));
runProperties.AppendChild(new RunFonts() { Ascii = "Times New Roman", ComplexScript = "Times New Roman", HighAnsi = "Times New Roman" });
runProperties.AppendChild(new FontSize { Val = data[i].Texts[j].Item2.Size == null ? data[i].Texts[j].Item2.Size : "24" });
if (data[i].Texts[j].Item2.Bold)
runProperties.AppendChild(new Bold());
docRun.AppendChild(runProperties);
docRun.AppendChild(new Text { Text = data[i].Texts[j].Item1.ToString(), Space = SpaceProcessingModeValues.Preserve });
docParagraph.AppendChild(docRun);
TableCell docCell = new TableCell();
docCell.AppendChild(docParagraph);
docRow.AppendChild(docCell);
}
table.AppendChild(docRow);
}
_docBody.AppendChild(table);
}
protected override void CreateParagraph(WordParagraph paragraph)
{
if (_docBody == null || paragraph == null)

View File

@ -19,11 +19,17 @@ namespace SushiBarContracts.BusinessLogicsContracts
List<ReportOrdersViewModel> GetOrders(ReportBindingModel model);
/// <summary>
/// Сохранение индгредиентов в файл-Word
/// Сохранение суши в файл-Word
/// </summary>
/// <param name="model"></param>
void SaveListSushiToWordFile(ReportBindingModel model);
/// <summary>
/// Сохранение магазинов в файл-Word
/// </summary>
/// <param name="model"></param>
void SaveShopsToWordFile(ReportBindingModel model);
/// <summary>
/// Сохранение индгредиентов с указаеним суши в файл-Excel
/// </summary>