Parcourir la source

Tweaked Logikal and V6 import options

frankvandenbos il y a 2 mois
Parent
commit
3fda62b2f7

+ 17 - 0
prs.classes/Integrations/Logikal/LogikalSettings.cs

@@ -214,5 +214,22 @@ namespace Comal.Classes
         public String LabourSQL { get; set; }
 
         
+        public bool CanImport<TSecurity>(bool enabled, Job? job) where TSecurity : ISecurityDescriptor, new()
+        {
+            if (!enabled)
+                return false;
+            
+            if (job is null)
+                return false;
+        
+            if (!Security.IsAllowed<TSecurity>())
+                return false;
+            
+            if (UseLogikalProjectNumber)
+                return (string.IsNullOrWhiteSpace(ProjectPrefix) || job.JobNumber.StartsWith(ProjectPrefix)); 
+            
+            return (string.IsNullOrWhiteSpace(job.SourceRef) || job.SourceRef.StartsWith("Logikal:"));
+        }
+        
     }
 }

+ 17 - 0
prs.classes/Integrations/V6/V6Settings.cs

@@ -191,5 +191,22 @@ namespace Comal.Classes
         [Caption("Query")]
         public String LabourSQL { get; set; }// = V6Labour.SQL;
         
+        public bool CanImport<TSecurity>(bool enabled, Job? job) where TSecurity : ISecurityDescriptor, new()
+        {
+            if (!enabled)
+                return false;
+            
+            if (job is null)
+                return false;
+        
+            if (!Security.IsAllowed<TSecurity>())
+                return false;
+            
+            if (UseV6QuoteNumber)
+                return (string.IsNullOrWhiteSpace(ProjectPrefix) || job.JobNumber.StartsWith(ProjectPrefix)); 
+            
+            return (string.IsNullOrWhiteSpace(job.SourceRef) || job.SourceRef.StartsWith("V6:"));
+        }
+        
     }
 }

+ 1 - 1
prs.desktop/Integrations/Logikal/Grids/LogikalProjectGrid.cs

@@ -32,7 +32,7 @@ public class LogikalProjectGrid : LogikalGrid<LogikalProject>
         if (string.IsNullOrWhiteSpace(JobNumber))
             result.Add<LogikalProject>(x => x.JobNumber, 60, "Job", "", Alignment.MiddleCenter);
         result.Add<LogikalProject>(x => x.Title, 0, "Name", "", Alignment.MiddleLeft);
-        result.Add<LogikalProject>(x => x.PersonInCharge, 80, "Manager", "", Alignment.MiddleLeft);
+        result.Add<LogikalProject>(x => x.PersonInCharge, 120, "Manager", "", Alignment.MiddleLeft);
         return result;
     }
 

+ 301 - 23
prs.desktop/Integrations/Logikal/LogikalClient.cs

@@ -1,6 +1,8 @@
 using System;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
+using System.Data;
+using System.Data.SQLite;
 using System.Diagnostics;
 using System.IO;
 using System.Linq;
@@ -13,6 +15,7 @@ using H.Pipes;
 using InABox.Clients;
 using InABox.Configuration;
 using InABox.Core;
+using InABox.Integration.Awg;
 using InABox.Integration.Logikal;
 using InABox.Wpf;
 using InABox.WPF;
@@ -237,6 +240,7 @@ public class LogikalClient : IDisposable
                 .Replace(@"\common\bin\logikal.exe", "")
                 .ToUpper() ?? "C")
             .Distinct()
+            .OrderBy(x=>x)
             .ToArray();
 
         if (drives.Length == 1)
@@ -476,19 +480,20 @@ public class LogikalClient : IDisposable
             
             try
             {
-                var _request = new LogikalBOMRequest(
-                    projectid, 
-                    elevationids, 
-                    Settings.FinishSQL,
-                    Settings.BillOfMaterialsProfileSQL, 
-                    Settings.GasketSQL, 
-                    Settings.ComponentSQL, 
-                    Settings.GlassSQL, 
-                    Settings.LabourSQL, 
-                    excel,
-                    sqlite);
-
-                _result = Send(_request);
+                var _request = new LogikalBOMRequest(projectid, elevationids);
+
+                _result = Send(_request)
+                    .Success<LogikalBOMResponse<
+                        LogikalElevationDetail,
+                        LogikalFinish,
+                        LogikalProfile,
+                        LogikalGasket,
+                        LogikalComponent,
+                        LogikalGlass,
+                        LogikalLabour>>(response =>
+                    {
+                        ExtractBOMData([response.BOM], true, excel);
+                    });
             }
             catch (Exception e)
             {
@@ -514,15 +519,6 @@ public class LogikalClient : IDisposable
                 var _request = new LogikalElevationDetailRequest(
                     projectid, 
                     elevationids,
-                    Settings.FinishSQL,
-                    Settings.DesignProfileSQL, 
-                    Settings.GasketSQL, 
-                    Settings.ComponentSQL, 
-                    Settings.GlassSQL,
-                    Settings.LabourSQL, 
-                    excel,
-                    sqlite, 
-                
                     Settings.DrawingFormat == Comal.Classes.LogikalDrawingFormat.DXF 
                         ? InABox.Integration.Logikal.LogikalDrawingFormat.DXF 
                         : InABox.Integration.Logikal.LogikalDrawingFormat.PNG,
@@ -543,7 +539,18 @@ public class LogikalClient : IDisposable
                         
                 );
 
-                _result = Send(_request);
+                _result = Send(_request)
+                    .Success<LogikalElevationDetailResponse<
+                        LogikalElevationDetail,
+                        LogikalFinish,
+                        LogikalProfile,
+                        LogikalGasket,
+                        LogikalComponent,
+                        LogikalGlass,
+                        LogikalLabour>>(response =>
+                    {
+                        ExtractBOMData(response.Elevations, false, excel);
+                    });
             }
             catch (Exception e)
             {
@@ -553,6 +560,277 @@ public class LogikalClient : IDisposable
         });
         return _result;
     }
+    
+
+    private T CheckValue<T>(object value)
+    {
+        if (value == null || value is DBNull || value.GetType() != typeof(T))
+            return default(T);
+        return (T)value;
+    }
+    
+    private double GetScale(LogikalMeasurement scale)
+    {
+        return scale == LogikalMeasurement.Metres
+            ? 1.0 / 1000.0
+            : 1.0;
+    }
+
+    private void ExtractBOMData(IEnumerable<LogikalElevationDetail> elevations, bool optimised, bool includeexcel)
+    {
+        foreach (var elevation in elevations)
+        {
+            var file = Path.ChangeExtension(Path.Combine(Path.GetTempPath(), Path.GetTempFileName()), "sqlite3");
+            File.WriteAllBytes(file,elevation.SQLiteData);
+            
+            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 = Settings.FinishSQL.Replace('\n', ' ');
+                    try
+                    {
+                        using (var _reader = _data.ExecuteReader())
+                        {
+                            DataTable _dt = new DataTable();
+                            _dt.Load(_reader);
+                            List<LogikalFinish> finishes = new List<LogikalFinish>();
+                            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);
+                            }
+
+                            elevation.Finishes = finishes;
+                        }
+
+                    }
+                    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 = optimised
+                        ? Settings.BillOfMaterialsProfileSQL.Replace('\n', ' ')
+                        : Settings.DesignProfileSQL.Replace('\n', ' ');
+                    try
+                    {
+                        using (var _reader = _data.ExecuteReader())
+                        {
+                            DataTable _dt = new DataTable();
+                            _dt.Load(_reader);
+                            List<LogikalProfile> profiles = new List<LogikalProfile>();
+                            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)]) *
+                                                  GetScale(Settings.ProfileMeasurement);
+                                profiles.Add(_profile);
+                            }
+
+                            elevation.Profiles = profiles;
+                        }
+
+                    }
+                    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 = Settings.GasketSQL.Replace('\n', ' ');
+                    try
+                    {
+                        using (var _reader = _data.ExecuteReader())
+                        {
+                            DataTable _dt = new DataTable();
+                            _dt.Load(_reader);
+                            List<LogikalGasket> gaskets = new List<LogikalGasket>();
+                            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)]) *
+                                                 GetScale(Settings.GasketMeasurement);
+                                gaskets.Add(_gasket);
+                            }
+
+                            elevation.Gaskets = gaskets;
+                        }
+                    }
+                    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 = Settings.ComponentSQL.Replace('\n', ' ');
+                    try
+                    {
+                        using (var _reader = _data.ExecuteReader())
+                        {
+                            DataTable _dt = new DataTable();
+                            _dt.Load(_reader);
+                            List<LogikalComponent> components = new List<LogikalComponent>();
+                            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);
+                            }
+
+                            elevation.Components = components;
+                        }
+                    }
+                    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 = Settings.GlassSQL.Replace('\n', ' ');
+                    try
+                    {
+                        using (var _reader = _data.ExecuteReader())
+                        {
+                            DataTable _dt = new DataTable();
+                            _dt.Load(_reader);
+                            List<LogikalGlass> glass = new List<LogikalGlass>();
+                            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)]) *
+                                                    GetScale(Settings.GlassMeasurement);
+                                _glassitem.Width = CheckValue<double>(row[nameof(LogikalGlass.Width)]) *
+                                                   GetScale(Settings.GlassMeasurement);
+                                _glassitem.Treatment = CheckValue<string>(row[nameof(LogikalGlass.Treatment)]);
+                                _glassitem.Location = CheckValue<string>(row[nameof(LogikalGlass.Location)]);
+                                glass.Add(_glassitem);
+                            }
+
+                            elevation.Glass = glass;
+                        }
+                    }
+                    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 = Settings.LabourSQL.Replace('\n', ' ');
+                    try
+                    {
+                        using (var _reader = _data.ExecuteReader())
+                        {
+                            DataTable _dt = new DataTable();
+                            _dt.Load(_reader);
+                            List<LogikalLabour> labour = new List<LogikalLabour>();
+                            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);
+                            }
+
+                            elevation.Labour = labour;
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        throw new Exception($"Error: {e.Message}\nQuery: {_data.CommandText}\nTrace: {e.StackTrace}");
+                    }
+
+                }
+                
+                if (includeexcel)
+                {
+                    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))
+                        elevation.ExcelData = _buffer.GetBuffer();
+
+                    _connection.Close();
+                    File.Delete(file);
+                }
+            }
+
+            File.Delete(file);
+        }
+    }
 
 
 }

+ 1 - 1
prs.desktop/Integrations/Logikal/LogikalElevationSelection.xaml

@@ -34,7 +34,7 @@
                 <RowDefinition Height="*"/>
             </Grid.RowDefinitions>
             <Grid.ColumnDefinitions>
-                <ColumnDefinition Width ="250"/>
+                <ColumnDefinition Width ="400"/>
                 <ColumnDefinition Width ="Auto"/>
                 <ColumnDefinition Width ="*"/>
             </Grid.ColumnDefinitions>

+ 2 - 2
prs.logikal/OpenXML/OfficeOpenXML.cs → prs.desktop/Integrations/Logikal/OfficeOpenXML.cs

@@ -1,4 +1,4 @@
-using System;
+using System;
 using System.Collections.Generic;
 using System.Data;
 using System.IO;
@@ -6,7 +6,7 @@ using DocumentFormat.OpenXml;
 using DocumentFormat.OpenXml.Packaging;
 using DocumentFormat.OpenXml.Spreadsheet;
 
-namespace PRSLogikal.OpenXML
+namespace PRSDesktop
 {
     public sealed class OfficeOpenXML
     {

+ 1 - 0
prs.desktop/PRSDesktop.csproj

@@ -905,6 +905,7 @@
       <PackageReference Include="DeviceId.Windows.Wmi" Version="6.2.0" />
       <PackageReference Include="Dirkster.AvalonDock" Version="4.72.1" />
       <PackageReference Include="Dirkster.AvalonDock.Themes.Metro" Version="4.72.1" />
+      <PackageReference Include="DocumentFormat.OpenXml" Version="3.1.1" />
       <PackageReference Include="Fluent.Ribbon" Version="10.1.0" />
       <PackageReference Include="Geocoding.Core" Version="4.0.1" />
       <PackageReference Include="Geocoding.Google" Version="4.0.1" />

+ 3 - 10
prs.desktop/Panels/Jobs/BillOfMaterials/JobBillOfMaterialsGrid.cs

@@ -111,9 +111,7 @@ namespace PRSDesktop
             
             ContextMenu? menu = null;
             _v6Settings ??= new GlobalConfiguration<V6Settings>().Load();
-            if (_v6Settings.ImportBoms 
-                && Security.IsAllowed<ImportV6BillsOfMaterials>()
-                && (string.IsNullOrWhiteSpace(Master?.SourceRef) || Master.SourceRef.StartsWith("V6:")))
+            if (_v6Settings.CanImport<ImportV6BillsOfMaterials>(_v6Settings.ImportBoms, Master))
             {
                 menu ??= new ContextMenu();
                 
@@ -127,14 +125,9 @@ namespace PRSDesktop
             }
 
             _logikalSettings ??= new GlobalConfiguration<LogikalSettings>().Load();
-            if (_logikalSettings.ImportBoms 
-                && Security.IsAllowed<ImportLogikalBillsOfMaterials>() 
-                && (string.IsNullOrWhiteSpace(Master?.SourceRef) || Master.SourceRef.StartsWith("Logikal:")))
+            if (_logikalSettings.CanImport<ImportLogikalBillsOfMaterials>(_logikalSettings.ImportBoms, Master))
             {
-                if (menu == null)
-                    menu = new ContextMenu();
-                else
-                    menu.Items.Add(new Separator());
+                menu ??= new ContextMenu();
                 
                 var item = new MenuItem()
                 {

+ 3 - 10
prs.desktop/Panels/Jobs/Requisitions/JobRequisitionGrid.cs

@@ -183,9 +183,7 @@ namespace PRSDesktop
         {
             ContextMenu? menu = null;
             _v6Settings ??= new GlobalConfiguration<V6Settings>().Load();
-            if (_v6Settings.ImportRequis 
-                && Security.IsAllowed<ImportV6Requisitions>()
-                && (string.IsNullOrWhiteSpace(Master?.SourceRef) || Master.SourceRef.StartsWith("V6:")))
+            if (_v6Settings.CanImport<ImportV6Requisitions>(_v6Settings.ImportRequis, Master))
             {
                 menu ??= new ContextMenu();
                 
@@ -199,14 +197,9 @@ namespace PRSDesktop
             }
 
             _logikalSettings ??= new GlobalConfiguration<LogikalSettings>().Load();
-            if (_logikalSettings.ImportRequis 
-                && Security.IsAllowed<ImportLogikalRequisitions>() 
-                && (string.IsNullOrWhiteSpace(Master?.SourceRef) || Master.SourceRef.StartsWith("Logikal:")))
+            if (_logikalSettings.CanImport<ImportLogikalRequisitions>(_logikalSettings.ImportRequis, Master))
             {
-                if (menu == null)
-                    menu = new ContextMenu();
-                else
-                    menu.Items.Add(new Separator());
+                menu ??= new ContextMenu();
                 
                 var item = new MenuItem()
                 {

+ 6 - 2
prs.desktop/Panels/Staging/Setouts/StagingSetoutGrid.cs

@@ -17,6 +17,7 @@ using System.Reactive.Linq;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Windows.Media;
+using Comal.Classes.SecurityDescriptors;
 using InABox.Wpf;
 using InABox.Dxf;
 using InABox.Integration.Logikal;
@@ -524,11 +525,13 @@ public class StagingSetoutGrid : DynamicDataGrid<StagingSetout>
         return page.EditItems(new[] { group });
     }
 
+
+    
     protected override void DoAdd(bool openEditorOnDirectEdit = false)
     {
         ContextMenu menu = null;
         
-        if (_v6Settings.ImportDesigns == V6DesignType.NotApproved && (Job == null || Job?.SourceRef.StartsWith("V6:") == true))
+        if (_v6Settings.CanImport<ImportV6Designs>(_v6Settings.ImportDesigns == V6DesignType.NotApproved, Job))
         {
             menu ??= new ContextMenu();
             MenuItem item = new MenuItem()
@@ -540,7 +543,7 @@ public class StagingSetoutGrid : DynamicDataGrid<StagingSetout>
             menu.Items.Add(item);
         }
         
-        if (_logikalSettings.ImportDesigns == LogikalDesignType.NotApproved && (Job == null || Job?.SourceRef.StartsWith("Logikal:") == true))
+        if (_logikalSettings.CanImport<ImportLogikalDesigns>(_logikalSettings.ImportDesigns == LogikalDesignType.NotApproved, Job))
         {
             menu ??= new ContextMenu();
             MenuItem item = new MenuItem()
@@ -644,6 +647,7 @@ public class StagingSetoutGrid : DynamicDataGrid<StagingSetout>
                         (p, s, d, q, c) =>
                         {
                             var ssc = new StagingSetoutComponent();
+                            ssc.Dimensions.Unit.CopyFrom(p.UnitOfMeasure);
                             ssc.Product.CopyFrom(p);
                             ssc.Dimensions.CopyFrom(d);
                             ssc.Dimensions.CalculateValueAndUnitSize();

+ 14 - 277
prs.logikal/LogikalServer.cs

@@ -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();

+ 0 - 1
prs.logikal/PRSLogikal.csproj

@@ -96,7 +96,6 @@
     </Compile>
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="OpenXML\OfficeOpenXML.cs" />
     <Compile Include="Properties\AssemblyInfo.cs">
       <SubType>Code</SubType>
     </Compile>