123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using NPOI.SS.Formula.Functions;
- using Syncfusion.Pdf;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace PRSDesktop
- {
- public class ScanGrid : DynamicDataGrid<Scan>
- {
- public string? AppliesTo { get; set; }
- public ScanGrid()
- {
- Options.BeginUpdate()
- .AddRange(DynamicGridOption.MultiSelect, DynamicGridOption.DragSource, DynamicGridOption.FilterRows)
- .Remove(DynamicGridOption.ImportData)
- .EndUpdate();
- }
- protected override void OnRowsDragStart(CoreRow[] rows)
- {
- var table = new CoreTable();
- table.Columns.Add(new CoreColumn { ColumnName = "ID", DataType = typeof(Guid) });
- foreach(var row in rows)
- {
- var newRow = table.NewRow();
- newRow.Set<Document, Guid>(x => x.ID, row.Get<Scan, Guid>(x => x.Document.ID));
- table.Rows.Add(newRow);
- }
- DragTable(typeof(Document), table);
- }
- private void UploadDocument(string filename, byte[] data)
- {
- var document = new Document
- {
- FileName = filename,
- CRC = CoreUtils.CalculateCRC(data),
- TimeStamp = DateTime.Now,
- Data = data
- };
- new Client<Document>().Save(document, "");
- var scan = new Scan();
- scan.Document.ID = document.ID;
- scan.AppliesTo = AppliesTo ?? "";
- new Client<Scan>().Save(scan, "");
- Dispatcher.Invoke(() =>
- {
- Refresh(false, true);
- });
- }
- private static PdfDocumentBase CombinePages(IEnumerable<DocumentManipulationWindow.Page> pages)
- {
- var document = new PdfDocument();
- foreach (var page in pages)
- {
- document.ImportPage(page.Pdf, page.PageIndex);
- }
- return document;
- }
- public void ShowDocumentWindow(List<DocumentManipulationWindow.Page> pages, string filename)
- {
- var window = new DocumentManipulationWindow(pages, filename);
- if (window.ShowDialog() == true)
- {
- Progress.ShowModal("Uploading Files", (progress) =>
- {
- foreach (var group in window.Groups)
- {
- progress.Report($"Uploading '{group.FileName}'");
- var doc = CombinePages(group.Pages);
- byte[] data;
- using (var ms = new MemoryStream())
- {
- doc.Save(ms);
- data = ms.ToArray();
- }
- UploadDocument(group.FileName, data);
- }
- });
- }
- }
- protected override void DoAdd()
- {
- ShowDocumentWindow(new(), "");
- }
- protected override Scan CreateItem()
- {
- var scan = base.CreateItem();
- scan.AppliesTo = AppliesTo ?? "";
- return scan;
- }
- protected override void GenerateColumns(DynamicGridColumns columns)
- {
- base.GenerateColumns(columns);
- columns.RemoveAll(x => x.ColumnName == "Document.FileName");
- columns.Add<Scan, string>(x => x.Document.FileName, 0, "Filename", "", InABox.Core.Alignment.MiddleLeft);
- }
- protected override void Reload(Filters<Scan> criteria, Columns<Scan> columns, ref SortOrder<Scan>? sort, Action<CoreTable?, Exception?> action)
- {
- if (!string.IsNullOrWhiteSpace(AppliesTo))
- {
- criteria.Add(new Filter<Scan>(x => x.AppliesTo).IsEqualTo(AppliesTo));
- }
- base.Reload(criteria, columns, ref sort, action);
- }
- }
- }
|