This commit is contained in:
mmrbnjd
2024-07-06 16:18:23 +03:30
parent d4410ea328
commit e175d83c2a
9 changed files with 60 additions and 119 deletions

View File

@@ -4,17 +4,16 @@
<Preload LoadingText="در حال بارگذاری..." />
<Toasts class="p-3" Messages="messages" Placement="ToastsPlacement.MiddleCenter" />
@layout EmptyLayout
@page "/InvoiceReport/{ExternalAccessCode}"
@page "/InvoiceReport/{InvoiceID:int}"
@using Front.Services
@code {
[Inject] protected PreloadService PreloadService { get; set; } = default!;
List<ToastMessage> messages = new List<ToastMessage>();
[Parameter] public string ExternalAccessCode { get; set; }
[Parameter] public int? InvoiceID { get; set; }
protected async override Task OnParametersSetAsync()
{
if (!string.IsNullOrEmpty(ExternalAccessCode))
await ShowReport();
await ShowReport();
await base.OnParametersSetAsync();
}
@@ -31,22 +30,31 @@
};
private async Task ShowReport()
{
PreloadService.Show(SpinnerColor.Dark);
var rsp = await hc.Get($"Invoice/GetReportByExternalAccessCode/{ExternalAccessCode}");
if (rsp.IsSuccessStatusCode)
if (InvoiceID != null && InvoiceID > 0)
{
var str = await rsp.Content.ReadAsStringAsync();
if (string.IsNullOrEmpty(str))
ShowMessage(ToastType.Warning, "مشکلی در ساخت فایل رخ داده لطفا مجدد تلاش کنید");
else
await DownloadFileFromStream(str, $"{ExternalAccessCode}.pdf");
PreloadService.Show(SpinnerColor.Dark);
var rsp = await hc.Get($"Invoice/GetReport/{InvoiceID}");
if (rsp.IsSuccessStatusCode)
{
var str = await rsp.Content.ReadAsStringAsync();
if (string.IsNullOrEmpty(str))
ShowMessage(ToastType.Warning, "مشکلی در ساخت فایل رخ داده لطفا مجدد تلاش کنید");
else
await DownloadFileFromStream(str, $"{InvoiceID}.pdf");
}
else if (rsp.StatusCode == System.Net.HttpStatusCode.NotFound)
ShowMessage(ToastType.Warning, "فاکتوری یافت نشد");
else ShowMessage(ToastType.Warning, "خطایی در چاپ فاکتور");
PreloadService.Hide();
}
else if (rsp.StatusCode == System.Net.HttpStatusCode.NotFound)
ShowMessage(ToastType.Warning, "فاکتوری یافت نشد");
else hc._nav.NavigateTo("Invoice");
else ShowMessage(ToastType.Warning, "خطایی در چاپ فاکتور");
PreloadService.Hide();
}
//for download
private Stream GetFileStream(byte[] bytes)