Compare commits
2 Commits
dfbbdb049a
...
4f5c9f4b71
Author | SHA1 | Date | |
---|---|---|---|
4f5c9f4b71 | |||
ebc61c5ef4 |
@ -10,10 +10,11 @@ namespace BusinessLogic.BusinessLogic
|
||||
{
|
||||
public class BarcodeLogic
|
||||
{
|
||||
public GeneratedBarcode CreateBarcode(ProductBindingModel model)
|
||||
public GeneratedBarcode CreateBarcode(ProductBindingModel model, bool save)
|
||||
{
|
||||
var barCode = IronBarCode.BarcodeWriter.CreateBarcode(model.Id.ToString(), BarcodeEncoding.Code128);
|
||||
return barCode.SaveAsPng($"product{model.Id}.png");
|
||||
if (save) return barCode.SaveAsPng($"product{model.Id}.png");
|
||||
return barCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
77
BusinessLogic/OfficePackage/AbstractSaveToPdf.cs
Normal file
77
BusinessLogic/OfficePackage/AbstractSaveToPdf.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using BusinessLogic.OfficePackage.HelperEnums;
|
||||
using BusinessLogic.OfficePackage.HelperModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BusinessLogic.OfficePackage
|
||||
{
|
||||
public abstract class AbstractSaveToPdf
|
||||
{
|
||||
public void CreateDoc(PdfInfo info)
|
||||
{
|
||||
CreatePdf(info);
|
||||
CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = info.Title,
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = $"с{info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
CreateTable(new List<string> { "2cm", "3cm", "6cm", "4cm" });
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Идентификатор", "Дата поставки", "Информация", "Статус" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { info.Supply.Id.ToString(), info.Supply.Date.ToShortDateString(), info.Supply.Name, info.Supply.Status.ToString() },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = $"Итого: {info.Supply.Price}",
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Right
|
||||
});
|
||||
SavePdf(info);
|
||||
}
|
||||
/// <summary>
|
||||
/// Создание doc-файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void CreatePdf(PdfInfo info);
|
||||
/// <summary>
|
||||
/// Создание параграфа с текстом
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="style"></param>
|
||||
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
||||
/// <summary>
|
||||
/// Создание таблицы
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="style"></param>
|
||||
protected abstract void CreateTable(List<string> columns);
|
||||
/// <summary>
|
||||
/// Создание и заполнение строки
|
||||
/// </summary>
|
||||
/// <param name="rowParameters"></param>
|
||||
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
||||
/// <summary>
|
||||
/// Сохранение файла
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
protected abstract void SavePdf(PdfInfo info);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
public enum PdfParagraphAlignmentType
|
||||
{
|
||||
Center,
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
}
|
18
BusinessLogic/OfficePackage/HelperModels/PdfInfo.cs
Normal file
18
BusinessLogic/OfficePackage/HelperModels/PdfInfo.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using Contracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfInfo
|
||||
{
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
public SupplyViewModel Supply { get; set; } = new();
|
||||
}
|
||||
}
|
16
BusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs
Normal file
16
BusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using BusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfParagraph
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
16
BusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs
Normal file
16
BusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using BusinessLogic.OfficePackage.HelperEnums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BusinessLogic.OfficePackage.HelperModels
|
||||
{
|
||||
public class PdfRowParameters
|
||||
{
|
||||
public List<string> Texts { get; set; } = new();
|
||||
public string Style { get; set; } = string.Empty;
|
||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
@ -100,6 +100,12 @@ namespace WinFormsApp
|
||||
IsBeingSold = checkBoxIsSold.Checked,
|
||||
};
|
||||
var operationResult = _id.HasValue ? _productLogic.Update(model) : _productLogic.Create(model);
|
||||
var lastProductCreated = _productLogic.ReadList(null).Last();
|
||||
_barcodeLogic.CreateBarcode(new ProductBindingModel()
|
||||
{
|
||||
Id = lastProductCreated.Id,
|
||||
Name = lastProductCreated.Name,
|
||||
}, true);
|
||||
_id = null;
|
||||
if (!operationResult)
|
||||
{
|
||||
@ -196,7 +202,7 @@ namespace WinFormsApp
|
||||
{
|
||||
Id = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value,
|
||||
Name = Convert.ToString(dataGridView.SelectedRows[0].Cells["Name"].Value),
|
||||
});
|
||||
}, true);
|
||||
pictureBox1.Image = barcode.Image;
|
||||
_barcode = BarcodeReader.Read($"product{barcode.Value}.png");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user