|
@@ -1,13 +1,8 @@
|
|
|
using InABox.Integration.Logikal;
|
|
|
-using PRSLogikal.OpenXML;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
-using System.Data;
|
|
|
-using System.Data.SQLite;
|
|
|
-using System.Diagnostics;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
-using System.Text.RegularExpressions;
|
|
|
using System.Threading.Tasks;
|
|
|
using Ofcas.Lk.Api.Client.Core;
|
|
|
using Ofcas.Lk.Api.Client.Ui;
|
|
@@ -426,10 +421,15 @@ namespace PRSLogikal
|
|
|
|
|
|
var response = new LogikalBOMResponse<LogikalBOM, LogikalFinish, LogikalProfile, LogikalGasket, LogikalComponent, LogikalGlass, LogikalLabour>();
|
|
|
// End method waits for the background operation to complete in separate task
|
|
|
- using (IStreamResult streamResult = Task.Run<IStreamResult>(() =>
|
|
|
+ using (IStreamResult partsResult = Task.Run<IStreamResult>(() =>
|
|
|
_project.CoreObject.EndGetReport(synchronizedOperationResult.SynchronizedOperation)).Result)
|
|
|
{
|
|
|
- PopulateParts(request, response.BOM, streamResult);
|
|
|
+ Stream exportStream = partsResult.Stream;
|
|
|
+ using (var _ms = new MemoryStream())
|
|
|
+ {
|
|
|
+ exportStream.CopyTo(_ms);
|
|
|
+ response.BOM.SQLiteData = _ms.GetBuffer();
|
|
|
+ }
|
|
|
}
|
|
|
return response;
|
|
|
|
|
@@ -518,7 +518,7 @@ namespace PRSLogikal
|
|
|
? ElevationDrawingType.ElevationWithSectionLines
|
|
|
: ElevationDrawingType.SectionLine
|
|
|
},
|
|
|
- { WellKnownParameterKey.Elevation.Drawing.DxfVersion, DxfVersion.Acad2010 },
|
|
|
+ { WellKnownParameterKey.Elevation.Drawing.DxfVersion, DxfVersion.Acad2013 },
|
|
|
{ WellKnownParameterKey.Elevation.Drawing.ShowDescription, true },
|
|
|
{ WellKnownParameterKey.Elevation.Drawing.ShowDimensions, true },
|
|
|
{ WellKnownParameterKey.Elevation.Drawing.Scale, 1.0 },
|
|
@@ -546,283 +546,20 @@ namespace PRSLogikal
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- using (IStreamResult streamResult = _elevation.CoreObject.GetPartsList())
|
|
|
+ using (IStreamResult partsResult = _elevation.CoreObject.GetPartsList())
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- PopulateParts(detailRequest, newel, streamResult);
|
|
|
- //return response;
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
+ Stream exportStream = partsResult.Stream;
|
|
|
+ using (var _ms = new MemoryStream())
|
|
|
{
|
|
|
- return new LogikalErrorResponse()
|
|
|
- { Status = LogikalStatus.Error, Message = $"{e.Message}\n{e.StackTrace}" };
|
|
|
+ exportStream.CopyTo(_ms);
|
|
|
+ newel.SQLiteData = _ms.GetBuffer();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private T CheckValue<T>(object value)
|
|
|
- {
|
|
|
- if (value == null || value is DBNull || value.GetType() != typeof(T))
|
|
|
- return default(T);
|
|
|
- return (T)value;
|
|
|
- }
|
|
|
-
|
|
|
- private void PopulateParts<TRequest, TBOM>(TRequest request, TBOM bom, IStreamResult stream)
|
|
|
- where TRequest : AbstractLogikalPartsRequest
|
|
|
- where TBOM : ILogikalBOM<LogikalFinish, LogikalProfile, LogikalGasket, LogikalComponent,LogikalGlass,LogikalLabour>
|
|
|
- {
|
|
|
- var _excelData = new byte[] { };
|
|
|
- var sqLiteData = new byte[] { };
|
|
|
- var _finishes = new List<LogikalFinish>();
|
|
|
- var _profiles = new List<LogikalProfile>();
|
|
|
- var _gaskets = new List<LogikalGasket>();
|
|
|
- var _components = new List<LogikalComponent>();
|
|
|
- var _glass = new List<LogikalGlass>();
|
|
|
- var _labour = new List<LogikalLabour>();
|
|
|
-
|
|
|
- var file = Path.ChangeExtension(Path.Combine(Path.GetTempPath(), Path.GetTempFileName()), "sqlite3");
|
|
|
- using (var fs = new FileStream(file, FileMode.OpenOrCreate))
|
|
|
- stream.Stream.CopyTo(fs);
|
|
|
-
|
|
|
- if (request.IncludeSqliteData)
|
|
|
- sqLiteData = File.ReadAllBytes(file);
|
|
|
-
|
|
|
- var sb = new SQLiteConnectionStringBuilder();
|
|
|
- sb.DataSource = file;
|
|
|
- using (var _connection = new SQLiteConnection(sb.ToString()))
|
|
|
- {
|
|
|
-
|
|
|
- _connection.Open();
|
|
|
-
|
|
|
- // Get Finishes
|
|
|
- using (var _data = new SQLiteCommand(_connection))
|
|
|
- {
|
|
|
- _data.CommandText = request.FinishQuery.Replace('\n', ' ');
|
|
|
- try
|
|
|
- {
|
|
|
- using (var _reader = _data.ExecuteReader())
|
|
|
- {
|
|
|
- DataTable _dt = new DataTable();
|
|
|
- _dt.Load(_reader);
|
|
|
- foreach (DataRow row in _dt.Rows)
|
|
|
- {
|
|
|
- var _finish = new LogikalFinish();
|
|
|
- _finish.Code = CheckValue<string>(row[nameof(LogikalFinish.Code)]);
|
|
|
- _finish.Description = CheckValue<string>(row[nameof(LogikalFinish.Description)]);
|
|
|
- _finishes.Add(_finish);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- throw new Exception($"Error: {e.Message}\nQuery: {_data.CommandText}\nTrace: {e.StackTrace}");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Get Profiles
|
|
|
- using (var _data = new SQLiteCommand(_connection))
|
|
|
- {
|
|
|
- _data.CommandText = request.ProfileQuery.Replace('\n', ' ');
|
|
|
- try
|
|
|
- {
|
|
|
- using (var _reader = _data.ExecuteReader())
|
|
|
- {
|
|
|
- DataTable _dt = new DataTable();
|
|
|
- _dt.Load(_reader);
|
|
|
- foreach (DataRow row in _dt.Rows)
|
|
|
- {
|
|
|
- var _profile = new LogikalProfile();
|
|
|
- _profile.Code = CheckValue<string>(row[nameof(LogikalProfile.Code)]);
|
|
|
- _profile.Description = CheckValue<string>(row[nameof(LogikalProfile.Description)]);
|
|
|
- _profile.Quantity = CheckValue<Int64>(row[nameof(LogikalProfile.Quantity)]);
|
|
|
- _profile.Cost = CheckValue<double>(row[nameof(LogikalProfile.Cost)]);
|
|
|
- _profile.Finish = CheckValue<string>(row[nameof(LogikalProfile.Finish)]);
|
|
|
- _profile.Length = CheckValue<double>(row[nameof(LogikalProfile.Length)]);
|
|
|
- _profiles.Add(_profile);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- throw new Exception($"Error: {e.Message}\nQuery: {_data.CommandText}\nTrace: {e.StackTrace}");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Get Gaskets
|
|
|
- using (var _data = new SQLiteCommand(_connection))
|
|
|
- {
|
|
|
- _data.CommandText = request.GasketQuery.Replace('\n', ' ');
|
|
|
- try
|
|
|
- {
|
|
|
- using (var _reader = _data.ExecuteReader())
|
|
|
- {
|
|
|
- DataTable _dt = new DataTable();
|
|
|
- _dt.Load(_reader);
|
|
|
- foreach (DataRow row in _dt.Rows)
|
|
|
- {
|
|
|
- var _gasket = new LogikalGasket();
|
|
|
- _gasket.Code = CheckValue<string>(row[nameof(LogikalGasket.Code)]);
|
|
|
- _gasket.Description = CheckValue<string>(row[nameof(LogikalGasket.Description)]);
|
|
|
- _gasket.Quantity = CheckValue<Int64>(row[nameof(LogikalGasket.Quantity)]);
|
|
|
- _gasket.Cost = CheckValue<double>(row[nameof(LogikalGasket.Cost)]);
|
|
|
- _gasket.Length = CheckValue<double>(row[nameof(LogikalGasket.Length)]);
|
|
|
- _gaskets.Add(_gasket);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- throw new Exception($"Error: {e.Message}\nQuery: {_data.CommandText}\nTrace: {e.StackTrace}");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Get Components
|
|
|
- using (var _data = new SQLiteCommand(_connection))
|
|
|
- {
|
|
|
- _data.CommandText = request.ComponentQuery.Replace('\n', ' ');
|
|
|
- try
|
|
|
- {
|
|
|
- using (var _reader = _data.ExecuteReader())
|
|
|
- {
|
|
|
- DataTable _dt = new DataTable();
|
|
|
- _dt.Load(_reader);
|
|
|
- foreach (DataRow row in _dt.Rows)
|
|
|
- {
|
|
|
- var _component = new LogikalComponent();
|
|
|
- _component.Code = CheckValue<string>(row[nameof(LogikalComponent.Code)]);
|
|
|
- _component.Description = CheckValue<string>(row[nameof(LogikalComponent.Description)]);
|
|
|
- _component.Quantity = CheckValue<double>(row[nameof(LogikalComponent.Quantity)]);
|
|
|
- _component.Cost = CheckValue<double>(row[nameof(LogikalComponent.Cost)]);
|
|
|
- _component.PackSize = CheckValue<double>(row[nameof(LogikalComponent.PackSize)]);
|
|
|
- _components.Add(_component);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- throw new Exception($"Error: {e.Message}\nQuery: {_data.CommandText}\nTrace: {e.StackTrace}");
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // Get Glass
|
|
|
- using (var _data = new SQLiteCommand(_connection))
|
|
|
- {
|
|
|
- _data.CommandText = request.GlassQuery.Replace('\n', ' ');
|
|
|
- try
|
|
|
- {
|
|
|
- using (var _reader = _data.ExecuteReader())
|
|
|
- {
|
|
|
- DataTable _dt = new DataTable();
|
|
|
- _dt.Load(_reader);
|
|
|
- foreach (DataRow row in _dt.Rows)
|
|
|
- {
|
|
|
- var _glassitem = new LogikalGlass();
|
|
|
- _glassitem.Code = CheckValue<string>(row[nameof(LogikalGlass.Code)]);
|
|
|
- _glassitem.Description = CheckValue<string>(row[nameof(LogikalGlass.Description)]);
|
|
|
- _glassitem.Quantity = CheckValue<Int64>(row[nameof(LogikalGlass.Quantity)]);
|
|
|
- _glassitem.Cost = CheckValue<double>(row[nameof(LogikalGlass.Cost)]);
|
|
|
- _glassitem.Height = CheckValue<double>(row[nameof(LogikalGlass.Height)]);
|
|
|
- _glassitem.Width = CheckValue<double>(row[nameof(LogikalGlass.Width)]);
|
|
|
- _glassitem.Treatment = CheckValue<string>(row[nameof(LogikalGlass.Treatment)]);
|
|
|
- _glassitem.Location = CheckValue<string>(row[nameof(LogikalGlass.Location)]);
|
|
|
- _glass.Add(_glassitem);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- throw new Exception($"Error: {e.Message}\nQuery: {_data.CommandText}\nTrace: {e.StackTrace}");
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // Get Labour
|
|
|
- using (var _data = new SQLiteCommand(_connection))
|
|
|
- {
|
|
|
- _data.CommandText = request.LabourQuery.Replace('\n', ' ');
|
|
|
- try
|
|
|
- {
|
|
|
- using (var _reader = _data.ExecuteReader())
|
|
|
- {
|
|
|
- DataTable _dt = new DataTable();
|
|
|
- _dt.Load(_reader);
|
|
|
- foreach (DataRow row in _dt.Rows)
|
|
|
- {
|
|
|
- var _labouritem = new LogikalLabour();
|
|
|
-
|
|
|
- _labouritem.Code = CheckValue<string>(row[nameof(LogikalLabour.Code)]);
|
|
|
- _labouritem.Description = CheckValue<string>(row[nameof(LogikalLabour.Description)]);
|
|
|
- _labouritem.Quantity = CheckValue<double>(row[nameof(LogikalLabour.Quantity)]);
|
|
|
- _labouritem.Cost = CheckValue<double>(row[nameof(LogikalLabour.Cost)]);
|
|
|
- _labour.Add(_labouritem);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- throw new Exception($"Error: {e.Message}\nQuery: {_data.CommandText}\nTrace: {e.StackTrace}");
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- 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())
|
|
|
- {
|
|
|
- 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 _buffer = excelApp.GetExcelStream(_ds, false))
|
|
|
- _excelData = _buffer.GetBuffer();
|
|
|
-
|
|
|
- _connection.Close();
|
|
|
- File.Delete(file);
|
|
|
- }
|
|
|
-
|
|
|
- bom.Finishes = _finishes.ToArray();
|
|
|
- bom.Profiles = _profiles.ToArray();
|
|
|
- bom.Gaskets = _gaskets.ToArray();
|
|
|
- bom.Components = _components.ToArray();
|
|
|
- bom.Glass = _glass.ToArray();
|
|
|
- bom.Labour = _labour.ToArray();
|
|
|
- bom.ExcelData = _excelData;
|
|
|
- bom.SQLiteData = sqLiteData;
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
public void Dispose()
|
|
|
{
|
|
|
Disconnect();
|