|
@@ -1,3 +1,5 @@
|
|
|
+using DocumentFormat.OpenXml.Office2010.Excel;
|
|
|
+using DocumentFormat.OpenXml.Wordprocessing;
|
|
|
using InABox.Logikal;
|
|
|
using Ofcas.Lk.Api.Client.Core;
|
|
|
using Ofcas.Lk.Api.Client.Ui;
|
|
@@ -12,8 +14,10 @@ using System.Data.SQLite;
|
|
|
using System.Diagnostics;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
+using System.Linq.Expressions;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
+using System.Windows.Navigation;
|
|
|
|
|
|
namespace PRSLogikal
|
|
|
{
|
|
@@ -185,17 +189,8 @@ namespace PRSLogikal
|
|
|
IList<IBaseProjectInfo> _projects = center.CoreObject.ChildrenInfos;
|
|
|
foreach (var _project in _projects)
|
|
|
{
|
|
|
- var _summary = new LogikalProject()
|
|
|
- {
|
|
|
- ID = _project.Guid,
|
|
|
- Name = _project.Name,
|
|
|
- PersonInCharge = _project.PersonInCharge,
|
|
|
- Path = _project.Path,
|
|
|
- LastUpdated = _project.LastChangedDateTime,
|
|
|
- Created = _project.CreatedDateTime,
|
|
|
- JobNumber = _project.AsProjectInfo().JobNumber,
|
|
|
- OfferNumber = _project.AsProjectInfo().OfferNumber
|
|
|
- };
|
|
|
+ var _summary = new LogikalProject();
|
|
|
+ PopulateProject(_project, _summary);
|
|
|
_projectresults.Add(_summary);
|
|
|
}
|
|
|
|
|
@@ -216,6 +211,18 @@ namespace PRSLogikal
|
|
|
GetProjectCentres(_child, results);
|
|
|
}
|
|
|
|
|
|
+ private void PopulateProject(IBaseProjectInfo source, ILogikalProject target)
|
|
|
+ {
|
|
|
+ target.ID = source.Guid;
|
|
|
+ target.Name = source.Name;
|
|
|
+ target.PersonInCharge = source.PersonInCharge;
|
|
|
+ target.Path = source.Path;
|
|
|
+ target.LastUpdated = source.LastChangedDateTime;
|
|
|
+ target.Created = source.CreatedDateTime;
|
|
|
+ target.JobNumber = source.AsProjectInfo().JobNumber;
|
|
|
+ target.OfferNumber = source.AsProjectInfo().OfferNumber;
|
|
|
+ }
|
|
|
+
|
|
|
private List<LogikalProjectCentre> GetProjectCentres()
|
|
|
{
|
|
|
var _results = new List<LogikalProjectCentre>();
|
|
@@ -262,6 +269,28 @@ namespace PRSLogikal
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public LogikalResponse GetProject(LogikalProjectRequest request)
|
|
|
+ {
|
|
|
+ if (_proxy == null)
|
|
|
+ return NOTCONNECTED;
|
|
|
+
|
|
|
+ if (_login == null)
|
|
|
+ return NOTLOGGEDIN;
|
|
|
+
|
|
|
+ var _project = _login.CoreObject.GetProjectByGuid(request.ProjectID);
|
|
|
+ if (_project == null)
|
|
|
+ return new LogikalErrorResponse()
|
|
|
+ {
|
|
|
+ Status = LogikalStatus.InvalidProjectID,
|
|
|
+ Message = $"Cannot Load Project {request.ProjectID}"
|
|
|
+ };
|
|
|
+
|
|
|
+ var response = new LogikalProjectResponse();
|
|
|
+ PopulateProject(_project.CoreObject.Info, response);
|
|
|
+ return response;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public LogikalResponse GetPhases(LogikalPhasesRequest request)
|
|
|
{
|
|
|
if (_proxy == null)
|
|
@@ -322,26 +351,29 @@ namespace PRSLogikal
|
|
|
var _elevations = _phase.CoreObject.GetChildren().CoreObjectResults;
|
|
|
foreach (var _elevation in _elevations)
|
|
|
{
|
|
|
- var _result = new LogikalElevation()
|
|
|
- {
|
|
|
- ID = _elevation.CoreObject.Info.Guid,
|
|
|
- Name = _elevation.CoreObject.Info.Name,
|
|
|
- Description = _elevation.CoreObject.Info.SystemDescription,
|
|
|
- Size = _elevation.CoreObject.Info.Size
|
|
|
- };
|
|
|
- using (var ms = new MemoryStream())
|
|
|
- {
|
|
|
- IStreamResult thumbnail =
|
|
|
- _elevation.CoreObject.GetThumbnail(new Dictionary<string, object>() { });
|
|
|
- thumbnail.Stream.CopyTo(ms);
|
|
|
- _result.Thumbnail = ms.GetBuffer();
|
|
|
- }
|
|
|
+ var _result = new LogikalElevation();
|
|
|
+ PopulateElevation(_elevation.CoreObject, _result);
|
|
|
_results.Add(_result);
|
|
|
}
|
|
|
return new LogikalElevationsResponse<LogikalElevation>() { Elevations = _results.ToArray() };
|
|
|
}
|
|
|
|
|
|
- public LogikalResponse GetBOM(LogikalBOMRequest request)
|
|
|
+ private void PopulateElevation(IElevation source, ILogikalElevation target)
|
|
|
+ {
|
|
|
+ target.ID = source.Info.Guid;
|
|
|
+ target.Name = source.Info.Name;
|
|
|
+ target.Description = source.Info.SystemDescription;
|
|
|
+ target.Size = source.Info.Size;
|
|
|
+ using (var ms = new MemoryStream())
|
|
|
+ {
|
|
|
+ IStreamResult thumbnail =
|
|
|
+ source.GetThumbnail(new Dictionary<string, object>() { });
|
|
|
+ thumbnail.Stream.CopyTo(ms);
|
|
|
+ target.Thumbnail = ms.GetBuffer();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public LogikalResponse GetBillOfMaterials(LogikalBOMRequest request)
|
|
|
{
|
|
|
|
|
|
if (_proxy == null)
|
|
@@ -349,6 +381,81 @@ namespace PRSLogikal
|
|
|
|
|
|
if (_login == null)
|
|
|
return NOTLOGGEDIN;
|
|
|
+
|
|
|
+ var _project = _login.CoreObject.GetProjectByGuid(request.ProjectID);
|
|
|
+ if (_project == null)
|
|
|
+ return new LogikalErrorResponse()
|
|
|
+ {
|
|
|
+ Status = LogikalStatus.InvalidProjectID,
|
|
|
+ Message = $"Cannot Load Project [{request.ProjectID}]"
|
|
|
+ };
|
|
|
+
|
|
|
+ var _elevations = new List<IElevationInfo>();
|
|
|
+
|
|
|
+
|
|
|
+ if (request.ElevationIDs?.Any() == true)
|
|
|
+ {
|
|
|
+ var _phases = _project.CoreObject.GetChildren();
|
|
|
+ foreach (var _phase in _phases.CoreObjectResults)
|
|
|
+ _elevations.AddRange(_phase.CoreObject.ChildrenInfos.Where(x => request.ElevationIDs.Contains(x.Guid)));
|
|
|
+ }
|
|
|
+
|
|
|
+ using (IReportItemsResult reportItemsResult = _project.CoreObject.GetReports())
|
|
|
+ {
|
|
|
+ if (reportItemsResult.OperationCode != OperationCode.Accepted)
|
|
|
+ {
|
|
|
+ return new LogikalErrorResponse()
|
|
|
+ {
|
|
|
+ Status = LogikalStatus.Error,
|
|
|
+ Message = $"Cannot Get Reports for Project!"
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ // Filter available reports for the erp export report item
|
|
|
+ IReportItem reportItem = reportItemsResult.ReportItems.First(rep =>
|
|
|
+ (rep.Id == WellKnownReports.Delivery.ErpExport) &&
|
|
|
+ (rep.Category.Id == WellKnownReports.Delivery.CategoryId));
|
|
|
+
|
|
|
+ // Create parameters for erp export, export format is required, but always sqlite
|
|
|
+ var exportParameters = new Dictionary<string, object>
|
|
|
+ {
|
|
|
+ { WellKnownParameterKey.Project.Report.ExportFormat, "SQLite" },
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ // Check if report can be exported for the given parameters
|
|
|
+ var operationInfo = _project.CoreObject.CanGetReport(reportItem, _elevations, exportParameters);
|
|
|
+ if (!operationInfo.CanExecute)
|
|
|
+ {
|
|
|
+ return new LogikalErrorResponse()
|
|
|
+ {
|
|
|
+ Status = LogikalStatus.Error,
|
|
|
+ Message = $"Cannot Get Erp Report for Project!"
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ // Run report creation asynchronously - begin method starts the operation in background task
|
|
|
+ using (ISynchronizedOperationResult synchronizedOperationResult =
|
|
|
+ _project.CoreObject.BeginGetReport(reportItem, _elevations, exportParameters))
|
|
|
+ {
|
|
|
+
|
|
|
+ var response = new LogikalBOMResponse<LogikalProfile, LogikalComponent, LogikalGlass, LogikalLabour>();
|
|
|
+ // End method waits for the background operation to complete in separate task
|
|
|
+ using (IStreamResult streamResult = Task.Run<IStreamResult>(() =>
|
|
|
+ _project.CoreObject.EndGetReport(synchronizedOperationResult.SynchronizedOperation)).Result)
|
|
|
+ {
|
|
|
+ PopulateParts(request, response, streamResult);
|
|
|
+ }
|
|
|
+ return response;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public LogikalResponse GetElevation(LogikalElevationRequest request)
|
|
|
+ {
|
|
|
|
|
|
var _project = _login.CoreObject.GetProjectByGuid(request.ProjectID);
|
|
|
if (_project == null)
|
|
@@ -357,193 +464,230 @@ namespace PRSLogikal
|
|
|
Status = LogikalStatus.InvalidProjectID,
|
|
|
Message = $"Cannot Load Project [{request.ProjectID}]"
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
var _phases = _project.CoreObject.GetChildren().CoreObjectResults;
|
|
|
var _phase = _phases.FirstOrDefault(p => p.CoreObject.GetChildren().CoreObjectResults.Any(e => e.CoreObject.Info.Guid == request.ElevationID));
|
|
|
if (_phase == null)
|
|
|
return new LogikalErrorResponse()
|
|
|
{
|
|
|
Status = LogikalStatus.ElevationNotFound,
|
|
|
- Message = $"Elevation [{request.ElevationID}] within project [{request.ProjectID}]"
|
|
|
+ Message = $"Cannot find Elevation [{request.ElevationID}] within project [{request.ProjectID}]"
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
var _elevation = _phase.CoreObject.GetChildren().CoreObjectResults.FirstOrDefault(x => x.CoreObject.Info.Guid == request.ElevationID);
|
|
|
if (_elevation == null)
|
|
|
+ {
|
|
|
return new LogikalErrorResponse()
|
|
|
{
|
|
|
Status = LogikalStatus.InvalidElevationID,
|
|
|
Message = $"Cannot find elevation [{request.ElevationID}] within phase [{_phase.CoreObject.Info.Name}]"
|
|
|
};
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ var response = new LogikalElevationResponse<LogikalProfile, LogikalComponent, LogikalGlass, LogikalLabour>();
|
|
|
+
|
|
|
+ PopulateElevation(_elevation.CoreObject, response);
|
|
|
+
|
|
|
+ // Setup parameters for export of the elevation drawing
|
|
|
+ var sectionDrawingParameters = new Dictionary<string, object>
|
|
|
+ {
|
|
|
+ { WellKnownParameterKey.Elevation.Drawing.Format, ElevationDrawingFormat.DXF },
|
|
|
+ { WellKnownParameterKey.Elevation.Drawing.View, Ofcas.Lk.Api.Shared.View.Interior },
|
|
|
+ { WellKnownParameterKey.Elevation.Drawing.Type, ElevationDrawingType.Elevation },
|
|
|
+ { WellKnownParameterKey.Elevation.Drawing.DxfVersion, DxfVersion.R12 },
|
|
|
+ { WellKnownParameterKey.Elevation.Drawing.ShowDescription, true },
|
|
|
+ { WellKnownParameterKey.Elevation.Drawing.ShowDimensions, true },
|
|
|
+ { WellKnownParameterKey.Elevation.Drawing.Scale, 1.0 },
|
|
|
+ };
|
|
|
+
|
|
|
+ // Check if the drawing can be exported for the elevation with the given parameters
|
|
|
+ if (!_elevation.CoreObject.CanGetDrawing(sectionDrawingParameters).CanExecute)
|
|
|
+ {
|
|
|
+ return new LogikalErrorResponse()
|
|
|
+ {
|
|
|
+ Status = LogikalStatus.Error,
|
|
|
+ Message = $"GetDrawing() not permitted for [{request.ElevationID}]"
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ // Generate drawing for the elevation with the given parameters
|
|
|
+ using (IDrawingResult drawingResult = _elevation.CoreObject.GetDrawing(sectionDrawingParameters))
|
|
|
+ {
|
|
|
+ Stream exportStream = drawingResult.Stream;
|
|
|
+ using (var _ms = new MemoryStream())
|
|
|
+ {
|
|
|
+ exportStream.CopyTo(_ms);
|
|
|
+ response.Drawing = _ms.GetBuffer();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ using (IStreamResult streamResult = _elevation.CoreObject.GetPartsList())
|
|
|
+ PopulateParts(request, response, streamResult);
|
|
|
+ return response;
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ return new LogikalErrorResponse() { Status = LogikalStatus.Error, Message = $"{e.Message}\n\n{e.StackTrace}" };
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ private void PopulateParts<TRequest, TResponse>(TRequest request, TResponse response, IStreamResult stream)
|
|
|
+ where TRequest : AbstractLogikalPartsRequest
|
|
|
+ where TResponse : AbstractLogikalPartsResponse<LogikalProfile,LogikalComponent,LogikalGlass,LogikalLabour>
|
|
|
+ {
|
|
|
var _excelData = new byte[] { };
|
|
|
var _profiles = new List<LogikalProfile>();
|
|
|
var _components = new List<LogikalComponent>();
|
|
|
var _glass = new List<LogikalGlass>();
|
|
|
var _labour = new List<LogikalLabour>();
|
|
|
-
|
|
|
- try
|
|
|
+
|
|
|
+ var file = Path.ChangeExtension(Path.Combine(Path.GetTempPath(), Path.GetTempFileName()), "sqlite3");
|
|
|
+ using (var fs = new FileStream(file, FileMode.OpenOrCreate))
|
|
|
+ stream.Stream.CopyTo(fs);
|
|
|
+
|
|
|
+ var sb = new SQLiteConnectionStringBuilder();
|
|
|
+ sb.DataSource = file;
|
|
|
+ var _connection = new SQLiteConnection(sb.ToString());
|
|
|
+ _connection.Open();
|
|
|
+
|
|
|
+ // Get Profiles
|
|
|
+ using (var _data = new SQLiteCommand(_connection))
|
|
|
{
|
|
|
- using (IStreamResult parts = _elevation.CoreObject.GetPartsList())
|
|
|
+ _data.CommandText = request.ProfileQuery;
|
|
|
+ using (var _reader = _data.ExecuteReader())
|
|
|
{
|
|
|
- var file = Path.ChangeExtension(Path.Combine(Path.GetTempPath(), Path.GetTempFileName()), "sqlite3");
|
|
|
- using (var fs = new FileStream(file, FileMode.OpenOrCreate))
|
|
|
- parts.Stream.CopyTo(fs);
|
|
|
+ DataTable _dt = new DataTable();
|
|
|
+ _dt.Load(_reader);
|
|
|
+ foreach (DataRow row in _dt.Rows)
|
|
|
+ {
|
|
|
+ var _profile = new LogikalProfile();
|
|
|
+ _profile.Code = (string)row[nameof(LogikalProfile.Code)];
|
|
|
+ _profile.Description = (string)row[nameof(LogikalProfile.Description)];
|
|
|
+ _profile.Quantity = (double)row[nameof(LogikalProfile.Quantity)];
|
|
|
+ _profile.Cost = (double)row[nameof(LogikalProfile.Cost)];
|
|
|
+ _profile.Finish = (string)row[nameof(LogikalProfile.Finish)];
|
|
|
+ _profile.Length = (double)row[nameof(LogikalProfile.Length)];
|
|
|
+ _profiles.Add(_profile);
|
|
|
|
|
|
- var sb = new SQLiteConnectionStringBuilder();
|
|
|
- sb.DataSource = file;
|
|
|
- var _connection = new SQLiteConnection(sb.ToString());
|
|
|
- _connection.Open();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // Get Profiles
|
|
|
- using (var _data = new SQLiteCommand(_connection))
|
|
|
+ // Get Components
|
|
|
+ using (var _data = new SQLiteCommand(_connection))
|
|
|
+ {
|
|
|
+ _data.CommandText = request.ComponentQuery;
|
|
|
+ using (var _reader = _data.ExecuteReader())
|
|
|
+ {
|
|
|
+ DataTable _dt = new DataTable();
|
|
|
+ _dt.Load(_reader);
|
|
|
+ foreach (DataRow row in _dt.Rows)
|
|
|
{
|
|
|
- _data.CommandText = request.ProfileQuery.Replace("1=1", "where e.[xGuid]='{request.ElevationID}'");
|
|
|
- using (var _reader = _data.ExecuteReader())
|
|
|
- {
|
|
|
- DataTable _dt = new DataTable();
|
|
|
- _dt.Load(_reader);
|
|
|
- foreach (DataRow row in _dt.Rows)
|
|
|
- {
|
|
|
- _profiles.Add(new LogikalProfile()
|
|
|
- {
|
|
|
- Code = (string)row[nameof(LogikalProfile.Code)],
|
|
|
- Description = (string)row[nameof(LogikalProfile.Description)],
|
|
|
- Quantity = (double)row[nameof(LogikalProfile.Quantity)],
|
|
|
- Cost = (double)row[nameof(LogikalProfile.Cost)],
|
|
|
- Finish = (string)row[nameof(LogikalProfile.Finish)],
|
|
|
- Length = (double)row[nameof(LogikalProfile.Length)],
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
+ var _component = new LogikalComponent();
|
|
|
+ _component.Code = (string)row[nameof(LogikalComponent.Code)];
|
|
|
+ _component.Description = (string)row[nameof(LogikalComponent.Description)];
|
|
|
+ _component.Quantity = (double)row[nameof(LogikalComponent.Quantity)];
|
|
|
+ _component.Cost = (double)row[nameof(LogikalComponent.Cost)];
|
|
|
+ _component.PackSize = (double)row[nameof(LogikalComponent.PackSize)];
|
|
|
+ _components.Add(_component);
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // Get Components
|
|
|
- using (var _data = new SQLiteCommand(_connection))
|
|
|
+ // Get Glass
|
|
|
+ using (var _data = new SQLiteCommand(_connection))
|
|
|
+ {
|
|
|
+ _data.CommandText = request.GlassQuery;
|
|
|
+ using (var _reader = _data.ExecuteReader())
|
|
|
+ {
|
|
|
+ DataTable _dt = new DataTable();
|
|
|
+ _dt.Load(_reader);
|
|
|
+ foreach (DataRow row in _dt.Rows)
|
|
|
{
|
|
|
- _data.CommandText = request.ComponentQuery.Replace("1=1", "where e.[xGuid]='{request.ElevationID}'");
|
|
|
- using (var _reader = _data.ExecuteReader())
|
|
|
- {
|
|
|
- DataTable _dt = new DataTable();
|
|
|
- _dt.Load(_reader);
|
|
|
- foreach (DataRow row in _dt.Rows)
|
|
|
- {
|
|
|
- _components.Add(new LogikalComponent()
|
|
|
- {
|
|
|
- Code = (string)row[nameof(LogikalComponent.Code)],
|
|
|
- Description = (string)row[nameof(LogikalComponent.Description)],
|
|
|
- Quantity = (double)row[nameof(LogikalComponent.Quantity)],
|
|
|
- Cost = (double)row[nameof(LogikalComponent.Cost)],
|
|
|
- PackSize = (double)row[nameof(LogikalComponent.PackSize)],
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
+ var _glassitem = new LogikalGlass();
|
|
|
+ _glassitem.Code = (string)row[nameof(LogikalGlass.Code)];
|
|
|
+ _glassitem.Description = (string)row[nameof(LogikalGlass.Description)];
|
|
|
+ _glassitem.Quantity = (double)row[nameof(LogikalGlass.Quantity)];
|
|
|
+ _glassitem.Cost = (double)row[nameof(LogikalGlass.Cost)];
|
|
|
+ _glassitem.Height = (double)row[nameof(LogikalGlass.Height)];
|
|
|
+ _glassitem.Width = (double)row[nameof(LogikalGlass.Width)];
|
|
|
+ _glassitem.Treatment = (string)row[nameof(LogikalGlass.Treatment)];
|
|
|
+ _glassitem.Location = (string)row[nameof(LogikalGlass.Location)];
|
|
|
+ _glass.Add(_glassitem);
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // Get Glass
|
|
|
- using (var _data = new SQLiteCommand(_connection))
|
|
|
+ // Get Labour
|
|
|
+ using (var _data = new SQLiteCommand(_connection))
|
|
|
+ {
|
|
|
+ _data.CommandText = request.LabourQuery;
|
|
|
+ using (var _reader = _data.ExecuteReader())
|
|
|
+ {
|
|
|
+ DataTable _dt = new DataTable();
|
|
|
+ _dt.Load(_reader);
|
|
|
+ foreach (DataRow row in _dt.Rows)
|
|
|
{
|
|
|
- _data.CommandText = request.GlassQuery.Replace("1=1", "where e.[xGuid]='{request.ElevationID}'");
|
|
|
- using (var _reader = _data.ExecuteReader())
|
|
|
- {
|
|
|
- DataTable _dt = new DataTable();
|
|
|
- _dt.Load(_reader);
|
|
|
- foreach (DataRow row in _dt.Rows)
|
|
|
- {
|
|
|
- _glass.Add(new LogikalGlass()
|
|
|
- {
|
|
|
- Code = (string)row[nameof(LogikalGlass.Code)],
|
|
|
- Description = (string)row[nameof(LogikalGlass.Description)],
|
|
|
- Quantity = (double)row[nameof(LogikalGlass.Quantity)],
|
|
|
- Cost = (double)row[nameof(LogikalGlass.Cost)],
|
|
|
- Height = (double)row[nameof(LogikalGlass.Height)],
|
|
|
- Width = (double)row[nameof(LogikalGlass.Width)],
|
|
|
- Treatment = (string)row[nameof(LogikalGlass.Treatment)],
|
|
|
- Location = (string)row[nameof(LogikalGlass.Location)],
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
+ var _labouritem = new LogikalLabour();
|
|
|
+
|
|
|
+ _labouritem.Code = row[nameof(LogikalLabour.Code)].ToString();
|
|
|
+ _labouritem.Description = (string)row[nameof(LogikalLabour.Description)];
|
|
|
+ _labouritem.Quantity = (double)row[nameof(LogikalLabour.Quantity)];
|
|
|
+ _labouritem.Cost = (double)row[nameof(LogikalLabour.Cost)];
|
|
|
+ _labour.Add(_labouritem);
|
|
|
}
|
|
|
- // Get Labour
|
|
|
- using (var _data = new SQLiteCommand(_connection))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (request.IncludeExcelData)
|
|
|
+ {
|
|
|
+ List<string> _tables = new List<string>();
|
|
|
+ using (var _master = new SQLiteCommand(_connection))
|
|
|
+ {
|
|
|
+ _master.CommandText = "select * from sqlite_master where type='table'";
|
|
|
+ using (var _reader = _master.ExecuteReader())
|
|
|
{
|
|
|
- _data.CommandText = request.LabourQuery.Replace("1=1", "where e.[xGuid]='{request.ElevationID}'");
|
|
|
- using (var _reader = _data.ExecuteReader())
|
|
|
+ if (_reader.HasRows)
|
|
|
{
|
|
|
- DataTable _dt = new DataTable();
|
|
|
- _dt.Load(_reader);
|
|
|
- foreach (DataRow row in _dt.Rows)
|
|
|
- {
|
|
|
- _labour.Add(new LogikalLabour()
|
|
|
- {
|
|
|
- Code = (string)row[nameof(LogikalLabour.Code)],
|
|
|
- Description = (string)row[nameof(LogikalLabour.Description)],
|
|
|
- Quantity = (double)row[nameof(LogikalLabour.Quantity)],
|
|
|
- Cost = (double)row[nameof(LogikalLabour.Cost)],
|
|
|
- });
|
|
|
- }
|
|
|
+ while (_reader.Read())
|
|
|
+ _tables.Add(_reader.GetString(1));
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // Labour
|
|
|
- // select TimeType, Name, TotalMinutes from labourtimes
|
|
|
- // where elevationid='{request.ElevationID}'
|
|
|
-
|
|
|
- if (request.IncludeExcelData)
|
|
|
+ DataSet _ds = new DataSet();
|
|
|
+ foreach (var _table in _tables)
|
|
|
+ {
|
|
|
+ using (var _data = new SQLiteCommand(_connection))
|
|
|
{
|
|
|
- List<string> _tables = new List<string>();
|
|
|
- using (var _master = new SQLiteCommand(_connection))
|
|
|
- {
|
|
|
- _master.CommandText = "select * from sqlite_master where type='table'";
|
|
|
- using (var _reader = _master.ExecuteReader())
|
|
|
- {
|
|
|
- if (_reader.HasRows)
|
|
|
- {
|
|
|
- while (_reader.Read())
|
|
|
- _tables.Add(_reader.GetString(1));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- DataSet _ds = new DataSet();
|
|
|
- foreach (var _table in _tables)
|
|
|
- {
|
|
|
- using (var _data = new SQLiteCommand(_connection))
|
|
|
- {
|
|
|
- _data.CommandText = $"select * from {_table}";
|
|
|
- using (var _reader = _data.ExecuteReader())
|
|
|
- {
|
|
|
- DataTable _dt = new DataTable(_table);
|
|
|
- _ds.Tables.Add(_dt);
|
|
|
- _dt.Load(_reader);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- var excelApp = OfficeOpenXML.GetInstance();
|
|
|
-
|
|
|
- using (var stream = excelApp.GetExcelStream(_ds, false))
|
|
|
+ _data.CommandText = $"select * from {_table}";
|
|
|
+ using (var _reader = _data.ExecuteReader())
|
|
|
{
|
|
|
- _excelData = stream.GetBuffer();
|
|
|
+ DataTable _dt = new DataTable(_table);
|
|
|
+ _ds.Tables.Add(_dt);
|
|
|
+ _dt.Load(_reader);
|
|
|
}
|
|
|
-
|
|
|
- _connection.Close();
|
|
|
- File.Delete(file);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- return new LogikalErrorResponse() { Status = LogikalStatus.Error, Message = $"{e.Message}\n\n{e.StackTrace}" };
|
|
|
+ var excelApp = OfficeOpenXML.GetInstance();
|
|
|
+ using (var _buffer = excelApp.GetExcelStream(_ds, false))
|
|
|
+ _excelData = _buffer.GetBuffer();
|
|
|
+
|
|
|
+ _connection.Close();
|
|
|
+ File.Delete(file);
|
|
|
}
|
|
|
|
|
|
- return new LogikalBOMResponse<LogikalProfile, LogikalComponent, LogikalGlass, LogikalLabour>()
|
|
|
- {
|
|
|
- Profiles = _profiles.ToArray(),
|
|
|
- Components = _components.ToArray(),
|
|
|
- Glass = _glass.ToArray(),
|
|
|
- Labour = _labour.ToArray(),
|
|
|
- ExcelData = _excelData
|
|
|
- };
|
|
|
-
|
|
|
+
|
|
|
+ response.Profiles = _profiles.ToArray();
|
|
|
+ response.Components = _components.ToArray();
|
|
|
+ response.Glass = _glass.ToArray();
|
|
|
+ response.Labour = _labour.ToArray();
|
|
|
+ response.ExcelData = _excelData;
|
|
|
}
|
|
|
|
|
|
public void Dispose()
|