This commit is contained in:
-SSS- 2025-04-22 12:19:10 +03:00
parent 50e56467d7
commit 4c7cd11a02
18 changed files with 106 additions and 71 deletions

View File

@ -16,6 +16,7 @@ public partial class App : Application
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
}
base.OnFrameworkInitializationCompleted();

View File

@ -6,7 +6,7 @@
<TextBlock Text="ШТРИХ-КОД ЗАКАЗА" FontSize="16" FontWeight="Bold"/>
<Border BorderBrush="Black" BorderThickness="1" Padding="15" CornerRadius="5">
<Canvas x:Name="BarcodeCanvas" Width="300" Height="100"/>
<Canvas x:Name="BarcodeCanvas" Width="100" Height="100"/>
</Border>
<TextBlock x:Name="BarcodeText" FontFamily="Courier New" FontSize="14" TextAlignment="Center"/>

View File

@ -7,7 +7,7 @@
Height="600">
<StackPanel Margin="20">
<!-- Номер заказа -->
<StackPanel Margin="0,0,0,15">
<TextBlock Text="Номер заказа:" FontWeight="Bold" FontSize="14"/>
<TextBox x:Name="OrderNumberBox"
@ -17,7 +17,7 @@
Padding="5"/>
</StackPanel>
<!-- Клиент -->
<StackPanel Margin="0,0,0,15">
<TextBlock Text="Клиент:" FontWeight="Bold" FontSize="14"/>
<DockPanel LastChildFill="True">
@ -34,7 +34,7 @@
</DockPanel>
</StackPanel>
<!-- Услуги -->
<StackPanel Margin="0,0,0,15">
<TextBlock Text="Услуги:" FontWeight="Bold" FontSize="14"/>
<DockPanel LastChildFill="True" Margin="0,0,0,10">
@ -50,7 +50,7 @@
Padding="5"/>
</DockPanel>
<!-- Время аренды -->
<StackPanel Margin="0,0,0,10" Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Text="Время аренды (минуты):"
Margin="0,0,10,0"
@ -61,7 +61,7 @@
Padding="5"/>
</StackPanel>
<!-- Список выбранных услуг -->
<TextBlock Text="Выбранные услуги:"
Margin="0,0,0,5"
FontWeight="Bold"
@ -95,7 +95,7 @@
</ListBox>
</StackPanel>
<!-- Кнопка оформления -->
<Button Content="Оформить заказ"
HorizontalAlignment="Stretch"
Margin="0,20,0,0"
@ -106,7 +106,7 @@
FontSize="14"
FontWeight="Bold"/>
<!-- Статус -->
<TextBlock x:Name="StatusText"
Foreground="Red"
TextWrapping="Wrap"

View File

@ -216,81 +216,115 @@ public partial class SallerWindow : Window, INotifyPropertyChanged, IReactiveObj
}
private void GenerateOrderPdfDocument(Model.Order order)
{
string documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string pdfFilePath = Path.Combine(documentsDirectory, $"Order_{order.OrderCode.Replace("/", "_")}.pdf");
using (Document document = new Document(PageSize.A4, 40, 40, 40, 40))
{
string documentsDirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string pdfFilePath = Path.Combine(documentsDirectoryPath, $"Заказ_{order.OrderCode.Replace("/", "_")}.pdf");
PdfWriter.GetInstance(document, new FileStream(pdfFilePath, FileMode.Create));
document.Open();
using (Document document = new Document(PageSize.A4, 40, 40, 40, 40))
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
Font titleFont = new Font(bf, 16, Font.BOLD);
Font headerFont = new Font(bf, 12, Font.BOLD);
Font normalFont = new Font(bf, 12);
var title = new Paragraph("Payment Receipt", titleFont)
{
PdfWriter pdfWriter = PdfWriter.GetInstance(document, new FileStream(pdfFilePath, FileMode.Create));
document.Open();
Alignment = Element.ALIGN_CENTER,
SpacingAfter = 20f
};
document.Add(title);
Font titleFont = FontFactory.GetFont("Arial", 16, Font.BOLD);
Font headerFont = FontFactory.GetFont("Arial", 12, Font.BOLD);
Font normalFont = FontFactory.GetFont("Arial", 12);
Paragraph titleParagraph = new Paragraph("Квитанция об оплате", titleFont);
titleParagraph.Alignment = Element.ALIGN_CENTER;
titleParagraph.SpacingAfter = 20;
document.Add(titleParagraph);
PdfPTable infoTable = new PdfPTable(2) { WidthPercentage = 100 };
infoTable.SetWidths(new float[] { 30f, 70f });
AddCell(infoTable, "Order Number:", order.OrderCode, headerFont, normalFont);
AddCell(infoTable, "Date & Time:", $"{order.StartDate:dd.MM.yyyy} {order.Time:hh\\:mm}", headerFont, normalFont);
AddCell(infoTable, "Customer:", SelectedClient?.Fio ?? "N/A", headerFont, normalFont);
AddCell(infoTable, "Status:", order.Status, headerFont, normalFont);
document.Add(infoTable);
PdfPTable orderInfoTable = new PdfPTable(2);
orderInfoTable.WidthPercentage = 100;
orderInfoTable.SetWidths(new float[] { 30, 70 });
document.Add(new Paragraph(" "));
AddPdfTableRow(orderInfoTable, "Номер заказа:", order.OrderCode, headerFont, normalFont);
AddPdfTableRow(orderInfoTable, "Дата и время:", $"{order.StartDate:dd.MM.yyyy} {order.Time:hh\\:mm}", headerFont, normalFont);
AddPdfTableRow(orderInfoTable, "Клиент:", SelectedClient?.Fio ?? "Не указан", headerFont, normalFont);
AddPdfTableRow(orderInfoTable, "Статус:", order.Status, headerFont, normalFont);
document.Add(orderInfoTable);
document.Add(new Paragraph(" "));
Paragraph servicesTitleParagraph = new Paragraph("Оказанные услуги:", headerFont);
servicesTitleParagraph.SpacingAfter = 10;
document.Add(servicesTitleParagraph);
PdfPTable servicesTable = new PdfPTable(3);
servicesTable.WidthPercentage = 100;
servicesTable.SetWidths(new float[] { 60, 20, 20 });
servicesTable.AddCell(new Phrase("Наименование услуги", headerFont));
servicesTable.AddCell(new Phrase("Стоимость/час", headerFont));
servicesTable.AddCell(new Phrase("Время (мин)", headerFont));
foreach (ServiceWithRentTime service in SelectedServices)
{
servicesTable.AddCell(new Phrase(service.ServiceName, normalFont));
servicesTable.AddCell(new Phrase($"{service.CostPerHour:N2} ₽", normalFont));
servicesTable.AddCell(new Phrase(service.RentTime.ToString(), normalFont));
}
document.Add(servicesTable);
document.Add(new Paragraph(" "));
decimal totalAmount = SelectedServices.Sum(service => (service.CostPerHour ?? 0) * (service.RentTime / 60m));
Paragraph totalParagraph = new Paragraph($"Итого к оплате: {totalAmount:N2} ₽", headerFont);
totalParagraph.Alignment = Element.ALIGN_RIGHT;
document.Add(totalParagraph);
}
try
var svcTitle = new Paragraph("Services Rendered:", headerFont)
{
Process.Start(new ProcessStartInfo
SpacingAfter = 10f
};
document.Add(svcTitle);
PdfPTable svcTable = new PdfPTable(3)
{
WidthPercentage = 100,
SpacingBefore = 5f,
SpacingAfter = 5f
};
svcTable.SetWidths(new float[] { 60f, 20f, 20f });
foreach (var hdr in new[] { "Service Name", "Rate/hour", "Duration (min)" })
{
svcTable.AddCell(new PdfPCell(new Phrase(hdr, headerFont))
{
FileName = pdfFilePath,
UseShellExecute = true
HorizontalAlignment = Element.ALIGN_CENTER,
BackgroundColor = BaseColor.LIGHT_GRAY,
Padding = 5f
});
}
catch (Exception exception)
foreach (var svc in SelectedServices)
{
StatusText.Text = $"Ошибка при открытии PDF: {exception.Message}";
svcTable.AddCell(new PdfPCell(new Phrase(svc.ServiceName, normalFont)) { Padding = 5f });
svcTable.AddCell(new PdfPCell(new Phrase($"{svc.CostPerHour:N2} ₽", normalFont))
{
HorizontalAlignment = Element.ALIGN_RIGHT,
Padding = 5f
});
svcTable.AddCell(new PdfPCell(new Phrase(svc.RentTime.ToString(), normalFont))
{
HorizontalAlignment = Element.ALIGN_RIGHT,
Padding = 5f
});
}
document.Add(svcTable);
decimal total = SelectedServices.Sum(s => (s.CostPerHour ?? 0) * (s.RentTime / 60m));
var totalPara = new Paragraph($"Total Due: {total:N2} ₽", headerFont)
{
Alignment = Element.ALIGN_RIGHT,
SpacingBefore = 10f
};
document.Add(totalPara);
}
private void AddPdfTableRow(PdfPTable table, string label, string value, Font labelFont, Font valueFont)
try
{
table.AddCell(new Phrase(label, labelFont));
table.AddCell(new Phrase(value, valueFont));
Process.Start(new ProcessStartInfo
{
FileName = pdfFilePath,
UseShellExecute = true
});
}
catch (Exception ex)
{
StatusText.Text = $"Error opening PDF: {ex.Message}";
}
}
private void AddCell(PdfPTable table, string label, string value, Font labelFont, Font valueFont)
{
table.AddCell(new Phrase(label, labelFont));
table.AddCell(new Phrase(value, valueFont));
}
}

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("demo_hard")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+69fe9ea9bc91472e247d6c5d565068a4efb0a683")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+50e56467d7d10df36759130ef24997a8c6ea8a33")]
[assembly: System.Reflection.AssemblyProductAttribute("demo_hard")]
[assembly: System.Reflection.AssemblyTitleAttribute("demo_hard")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
b558e1c40e2637b7a5437875d3c594c1eda934e9d40f49c41e49dbf89f9df5f0
d558e19871cd3b2b9f2f0170e2a01cb1d30cd37918ea9e521a55dc94c303ad3d