Skip to content

Commit 7cbf5a6

Browse files
authored
Merge pull request #37 from leungkimming/michael3
fix coverity
2 parents 5593996 + 7ecd1e9 commit 7cbf5a6

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

API/Controllers/DocumentProcessingController.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class DocumentProcessingController : ControllerBase {
2727
private readonly IWordProcessing _wordProcessing;
2828
private readonly ISpreadProcessing _spreadProcessing;
2929
private readonly IZipProcessing _zipProcessing;
30-
private static readonly List<FileDetails> _uploadedFiles =new List<FileDetails>();
30+
private static readonly List<FileDetails> _uploadedFiles = new List<FileDetails>();
3131
public DocumentProcessingController(IPdfProcessing pdfProcessing, IWordProcessing wordProcessing, ISpreadProcessing spreadProcessing, IZipProcessing zipProcessing) {
3232
_pdfProcessing = pdfProcessing;
3333
_wordProcessing = wordProcessing;
@@ -65,7 +65,7 @@ public async Task<IActionResult> MergePDF() {
6565
[AccessCodeAuthorize("AA01")]
6666
public async Task<IActionResult> ExportToDocx() {
6767
RadFlowDocument? document = DocumentGenerator.CreateFlowDocument();
68-
var wordFile =_wordProcessing.GetWordByte(DocumentFormat.docx, document);
68+
var wordFile = _wordProcessing.GetWordByte(DocumentFormat.docx, document);
6969
if (wordFile == null) {
7070
return NotFound();
7171
}
@@ -75,8 +75,8 @@ public async Task<IActionResult> ExportToDocx() {
7575
[Route("exporttoxlsx")]
7676
[AccessCodeAuthorize("AA01")]
7777
public async Task<IActionResult> ExportToXlsx() {
78-
Workbook workbook = DocumentGenerator.CreateWorkbook();
79-
var excelFile =_spreadProcessing.GetXlsxByte(workbook);
78+
using Workbook workbook = DocumentGenerator.CreateWorkbook();
79+
var excelFile = _spreadProcessing.GetXlsxByte(workbook);
8080
if (excelFile == null) {
8181
return NotFound();
8282
}
@@ -87,7 +87,7 @@ public async Task<IActionResult> ExportToXlsx() {
8787
[AccessCodeAuthorize("AA01")]
8888
public async Task<IActionResult> UploadFiles(IEnumerable<IFormFile> files) {
8989
if (files != null) {
90-
IFormFile? file =files.FirstOrDefault();
90+
IFormFile? file = files.FirstOrDefault();
9191
if (file == null) {
9292
return new NotFoundResult();
9393
}
@@ -110,7 +110,7 @@ public async Task<IActionResult> ZipFiles(string password) {
110110
DefaultEncryptionSettings encryptionSettings = new DefaultEncryptionSettings {
111111
Password = password
112112
};
113-
Dictionary<string, Stream> zipArchiveFiles=new Dictionary<string, Stream>();
113+
Dictionary<string, Stream> zipArchiveFiles = new Dictionary<string, Stream>();
114114
foreach (FileDetails? fileItem in _uploadedFiles) {
115115
zipArchiveFiles[fileItem.Name] = new MemoryStream(fileItem.Data);
116116
}
@@ -385,24 +385,24 @@ private static void CreateHeader(RadFlowDocumentEditor editor) {
385385
editor.MoveToParagraphStart(header.Blocks.AddParagraph());
386386
}
387387
public static Workbook CreateWorkbook() {
388-
Workbook workbook = new Workbook();
389-
workbook.Sheets.Add(SheetType.Worksheet);
390-
391-
Worksheet worksheet = workbook.ActiveWorksheet;
392-
List<Product>? products =new Products().GetData(20).ToList();
393-
PrepareInvoiceDocument(worksheet, products.Count);
394-
395-
int currentRow = IndexRowItemStart + 1;
396-
foreach (Product product in products) {
397-
worksheet.Cells[currentRow, 0].SetValue(product.Name);
398-
worksheet.Cells[currentRow, IndexColumnQuantity].SetValue(product.Quantity);
399-
worksheet.Cells[currentRow, IndexColumnUnitPrice].SetValue(product.UnitPrice);
400-
worksheet.Cells[currentRow, IndexColumnSubTotal].SetValue(product.SubTotal);
388+
using (Workbook workbook = new Workbook()) {
389+
workbook.Sheets.Add(SheetType.Worksheet);
390+
Worksheet worksheet = workbook.ActiveWorksheet;
391+
List<Product>? products = new Products().GetData(20).ToList();
392+
PrepareInvoiceDocument(worksheet, products.Count);
393+
394+
int currentRow = IndexRowItemStart + 1;
395+
foreach (Product product in products) {
396+
worksheet.Cells[currentRow, 0].SetValue(product.Name);
397+
worksheet.Cells[currentRow, IndexColumnQuantity].SetValue(product.Quantity);
398+
worksheet.Cells[currentRow, IndexColumnUnitPrice].SetValue(product.UnitPrice);
399+
worksheet.Cells[currentRow, IndexColumnSubTotal].SetValue(product.SubTotal);
400+
401+
currentRow++;
402+
}
401403

402-
currentRow++;
404+
return workbook;
403405
}
404-
405-
return workbook;
406406
}
407407
private static void PrepareInvoiceDocument(Worksheet worksheet, int itemsCount) {
408408
int lastItemIndexRow = IndexRowItemStart + itemsCount;

0 commit comments

Comments
 (0)