работа с ворд

This commit is contained in:
Мк Игорь 2023-05-09 18:37:02 +04:00
parent 5df83b8834
commit b2a5ea6274
6 changed files with 85 additions and 8 deletions

View File

@ -45,6 +45,7 @@
this.buttonRef = new System.Windows.Forms.Button();
this.buttonFillStore = new System.Windows.Forms.Button();
this.buttonSellManufacture = new System.Windows.Forms.Button();
this.reportStoresToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@ -96,7 +97,8 @@
this.reportToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.reportComponentsToolStripMenuItem,
this.reportManufactureComponentsToolStripMenuItem,
this.reportOrdersToolStripMenuItem});
this.reportOrdersToolStripMenuItem,
this.reportStoresToolStripMenuItem});
this.reportToolStripMenuItem.Name = "reportToolStripMenuItem";
this.reportToolStripMenuItem.Size = new System.Drawing.Size(51, 20);
this.reportToolStripMenuItem.Text = "Отчет";
@ -208,6 +210,13 @@
this.buttonSellManufacture.UseVisualStyleBackColor = true;
this.buttonSellManufacture.Click += new System.EventHandler(this.ButtonSellManufacture_Click);
//
// reportStoresToolStripMenuItem
//
this.reportStoresToolStripMenuItem.Name = "reportStoresToolStripMenuItem";
this.reportStoresToolStripMenuItem.Size = new System.Drawing.Size(218, 22);
this.reportStoresToolStripMenuItem.Text = "Список магазинов";
this.reportStoresToolStripMenuItem.Click += new System.EventHandler(this.ReportStoresToolStripMenuItem_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@ -253,5 +262,6 @@
private ToolStripMenuItem reportComponentsToolStripMenuItem;
private ToolStripMenuItem reportManufactureComponentsToolStripMenuItem;
private ToolStripMenuItem reportOrdersToolStripMenuItem;
private ToolStripMenuItem reportStoresToolStripMenuItem;
}
}

View File

@ -200,5 +200,15 @@ namespace BlacksmithWorkshopView
LoadData();
}
}
private void ReportStoresToolStripMenuItem_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK)
{
_reportLogic.SaveStoresToWordFile(new ReportBindingModel { FileName = dialog.FileName });
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}

View File

@ -15,16 +15,18 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
{
private readonly IComponentStorage _componentStorage;
private readonly IManufactureStorage _manufactureStorage;
private readonly IStoreStorage _storeStorage;
private readonly IOrderStorage _orderStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(IManufactureStorage manufactureStorage, IComponentStorage componentStorage, IOrderStorage orderStorage,
public ReportLogic(IManufactureStorage manufactureStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IStoreStorage storeStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_manufactureStorage = manufactureStorage;
_componentStorage = componentStorage;
_orderStorage = orderStorage;
_storeStorage = storeStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
@ -92,11 +94,24 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
Manufactures = _manufactureStorage.GetFullList()
});
}
/// <summary>
/// Сохранение изделий с указаеним продуктов в файл-Excel
/// </summary>
/// <param name="model"></param>
public void SaveManufactureComponentToExcelFile(ReportBindingModel model)
/// <summary>
/// Сохранение магазинов в файл-Word
/// </summary>
/// <param name="model"></param>
public void SaveStoresToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDocStores(new WordInfo
{
FileName = model.FileName,
Title = "Список магазинов",
Stores = _storeStorage.GetFullList()
});
}
/// <summary>
/// Сохранение изделий с указаеним продуктов в файл-Excel
/// </summary>
/// <param name="model"></param>
public void SaveManufactureComponentToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{

View File

@ -39,6 +39,42 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage
}
SaveWord(info);
}
public void CreateDocStores(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
}
});
foreach (var store in info.Stores)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
(store.StoreName, new WordTextProperties { Bold = true, Size = "24", }),
(" ", new WordTextProperties { Size = "24"}),
(store.Address, new WordTextProperties { Size = "24" }),
(" ", new WordTextProperties { Size = "24"}),
(store.OpeningDate.ToShortDateString(), new WordTextProperties { Size = "24" })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
SaveWord(info);
}
/// <summary>
/// Создание doc-файла
/// </summary>

View File

@ -7,5 +7,6 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ManufactureViewModel> Manufactures { get; set; } = new();
public List<StoreViewModel> Stores { get; set; } = new();
}
}

View File

@ -31,5 +31,10 @@ namespace BlacksmithWorkshopContracts.BusinessLogicsContracts
/// </summary>
/// <param name="model"></param>
void SaveOrdersToPdfFile(ReportBindingModel model);
}
/// <summary>
/// Сохранение магазинов в файл-Word
/// </summary>
/// <param name="model"></param>
void SaveStoresToWordFile(ReportBindingModel model);
}
}