This commit is contained in:
mmrbnjd
2024-07-21 16:07:53 +03:30
parent d80e1706c9
commit d9fd29dbba
2 changed files with 13 additions and 57 deletions

View File

@@ -386,7 +386,6 @@
@code {
private Modal Codemodal = default!;
public bool SendInvoice { get; set; } = false;
List<ToastMessage> messages = new List<ToastMessage>();
private ConfirmDialog dialog = default!;
@@ -504,29 +503,8 @@
hc._nav.NavigateTo($"FullInvoiceItem/{InvoiceID}");
}
}
private async Task onClickLink()
{
ExUrl = $"{fv.Domin}/InvoiceReport/" + InvoiceID;
await Codemodal.ShowAsync();
}
private async Task ShowReport()
{
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))
ShowDangerAlert("مشکلی در ساخت فایل رخ داده لطفا مجدد تلاش کنید");
else
await DownloadFileFromStream(str, $"{invoice.ID}.pdf");
}
else
ShowDangerAlert("خطایی در چاپ فاکتور");
PreloadService.Hide();
}
private async Task LoadData()
{
PreloadService.Show(SpinnerColor.Dark);
@@ -568,7 +546,7 @@
}
await CallBack(msg);
// if (result.Status == ComponentStatus.success)
// await LoadCod(1);
//await LoadData();
await modal.HideAsync();
}
@@ -578,6 +556,7 @@
{
ShowSuccessAlert(result);
await LoadData();
}
}
private void ShowSuccessAlert(string msg)
@@ -784,35 +763,5 @@
}
}
//for download
private Stream GetFileStream(byte[] bytes)
{
var fileStream = new MemoryStream(bytes);
return fileStream;
}
private async Task DownloadFileFromStream(string Base64, string FileName)
{
byte[] bytes = System.Convert.FromBase64String(Base64);
var fileStream = GetFileStream(bytes);
// var fileName = "log.bin";
using var streamRef = new DotNetStreamReference(stream: fileStream);
await JS.InvokeVoidAsync("downloadFileFromStream", FileName, streamRef);
}
}
<script>
window.downloadFileFromStream = async (fileName, contentStreamReference) => {
const arrayBuffer = await contentStreamReference.arrayBuffer();
const blob = new Blob([arrayBuffer]);
const url = URL.createObjectURL(blob);
const anchorElement = document.createElement('a');
anchorElement.href = url;
anchorElement.download = fileName ?? '';
anchorElement.click();
anchorElement.remove();
URL.revokeObjectURL(url);
}
</script>