Bladeren bron

Bug fixes for V6 Project import

frogsoftware 10 maanden geleden
bovenliggende
commit
c990f5c4b4

+ 5 - 4
prs.classes/Entities/V6/V6Profile.cs

@@ -20,9 +20,9 @@ namespace Comal.Classes
             $"  e.extn_code as {nameof(Code)},  \n" +
             $"  e.descr as {nameof(Description)}, \n" +
             $"  f.fincol_code as {nameof(Finish)}, \n" +
-            $"  bb.bar_length as {nameof(Length)}, \n" +
-            $"  sum(bp.piece_length * bp.piece_count) / bb.bar_length as {nameof(Quantity)}, \n" +
-            $"  bb.cost as {nameof(Cost)} \n" +
+            $"  round(coalesce(bb.bar_length, 0.0) * 0.0254, 2) as {nameof(Length)}, \n" +
+            $"  sum(bp.piece_count) as {nameof(Quantity)}, \n" +
+            $"  round(bb.cost * coalesce(bb.bar_length, 0.0),2) as {nameof(Cost)} \n" +
             "FROM \n" +
             "  bom_piece bp \n" +
             "left outer join \n" +
@@ -39,12 +39,13 @@ namespace Comal.Classes
             "  fincol f on f.fincol_lib_id = bp.fincol_lib_id and f.fincol_id = bp.fincol_id \n" +
             "where \n" +
             "  1 = 1 \n" +
+            "and \n" +
+            "  bb.bar_length is  not null \n" +
             "group by \n" +
             "  e.extn_code, \n" +
             "  e.descr, \n" +
             "  f.fincol_code, \n" +
             "  bb.bar_length, \n" +
             "  bb.cost";
-
     }
 }

+ 4 - 0
prs.classes/PRSClasses.csproj

@@ -39,5 +39,9 @@
       <ProjectReference Include="..\..\inabox\InABox.Core\InABox.Core.csproj" />
     </ItemGroup>
 
+    <ItemGroup>
+      <Folder Include="Entities\Logikal\" />
+    </ItemGroup>
+
 
 </Project>

+ 169 - 85
prs.desktop/Panels/Jobs/V6ProjectImport.xaml.cs

@@ -2,7 +2,6 @@ using System;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Linq;
-using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Media.Imaging;
@@ -96,61 +95,72 @@ public partial class V6ProjectImport : Window
         var _importCosts = (V6ImportCosts)ImportCosts.SelectedValue;
         var _importDesigns = (V6ImportDesigns)ImportDesigns.SelectedValue;
 
-        ProductDimensionUnit? _profileUOM = null;
-        ProductDimensionUnit? _componentUOM = null;
-        ProductDimensionUnit? _glassUOM = null;
+        ProductDimensionUnit? _profileUom = new();
+        ProductDimensionUnit? _componentUom = new();
+        ProductDimensionUnit? _glassUom = new();
         
+        ManufacturingTemplate? _template = new ManufacturingTemplate();
+        ManufacturingTemplateStage[] _stages = [];
+        
+        MultiQuery query = new MultiQuery();
         if (_importCosts != V6ImportCosts.None)
         {
-            var _uoms = Client.Query(
+            query.Add(
                 new Filter<ProductDimensionUnit>(x => x.Code).InList(new string[]
                     { _client.Settings.ProfileUom, _client.Settings.ComponentUom, _client.Settings.GlassUom }),
                 Columns.All<ProductDimensionUnit>()
-            ).ToObjects<ProductDimensionUnit>().ToArray();
-
-            _profileUOM = _uoms.FirstOrDefault(x => string.Equals(x.Code, _client.Settings.ProfileUom));
-            if (_profileUOM == null)
-            {
-                MessageWindow.ShowMessage(
-                    "Profile UOM setting has not been configured correctly!\nPlease correct this and try again.", "Error");
-                return;
-            }
-
-            _componentUOM = _uoms.FirstOrDefault(x => string.Equals(x.Code, _client.Settings.ComponentUom));
-            if (_componentUOM == null)
-            {
-                MessageWindow.ShowMessage(
-                    "Component UOM settings has not been configured correctly!\nPlease correct this and try again.", "Error");
-                return;
-            }
-
-            _glassUOM = _uoms.FirstOrDefault(x => string.Equals(x.Code, _client.Settings.GlassUom));
-            if (_glassUOM == null)
-            {
-                MessageWindow.ShowMessage(
-                    "Glass UOM setting has not been configured correctly!\nPlease correct this and try again.", "Error");
-                return;
-            }
+            );
         }
 
-        ManufacturingTemplate? _template = null;
-        ManufacturingTemplateStage[] _stages = [];
         if (_importDesigns == V6ImportDesigns.ToManufacturing)
         {
-            MultiQuery query = new MultiQuery();
             query.Add(new Filter<ManufacturingTemplate>(x => x.Code).IsEqualTo(_client.Settings.PacketTemplate));
             query.Add(new Filter<ManufacturingTemplateStage>(x => x.Template.Code).IsEqualTo(_client.Settings.PacketTemplate));
-            query.Query();
+        }
+        
+        query.Query();
+        
+        if (_importDesigns == V6ImportDesigns.ToManufacturing)
+        {
             _template = query.Get<ManufacturingTemplate>().Rows.FirstOrDefault()?.ToObject<ManufacturingTemplate>();
             _stages = query.Get<ManufacturingTemplateStage>().ToObjects<ManufacturingTemplateStage>().ToArray();
-            if (_template == null)
-            {
-                MessageWindow.ShowMessage(
-                    "Packet Template setting has not been configured correctly!\nPlease correct this and try again.", "Error");
-                return;
-            }    
         }
 
+        if (_importCosts != V6ImportCosts.None)
+        {
+            var _uoms = query.Get<ProductDimensionUnit>().ToObjects<ProductDimensionUnit>().ToList();
+            _profileUom = _uoms.FirstOrDefault(x => string.Equals(x.Code, _client.Settings.ProfileUom));
+            _componentUom = _uoms.FirstOrDefault(x => string.Equals(x.Code, _client.Settings.ComponentUom));
+            _glassUom = _uoms.FirstOrDefault(x => string.Equals(x.Code, _client.Settings.GlassUom));
+        }
+
+        if (_profileUom == null)
+        {
+            MessageWindow.ShowMessage(
+                "Profile UOM setting has not been configured correctly!\nPlease correct this and try again.", "Error");
+            return;
+        }
+        if (_componentUom == null)
+        {
+            MessageWindow.ShowMessage(
+                "Component UOM settings has not been configured correctly!\nPlease correct this and try again.", "Error");
+            return;
+        }
+        
+        if (_glassUom == null)
+        {
+            MessageWindow.ShowMessage(
+                "Glass UOM setting has not been configured correctly!\nPlease correct this and try again.", "Error");
+            return;
+        }
+        
+        if (_template == null)
+        {
+            MessageWindow.ShowMessage(
+                "Packet Template setting has not been configured correctly!\nPlease correct this and try again.", "Error");
+            return;
+        }   
+
         List<V6Profile> _profiles = new();
         List<V6Component> _components = new();
         List<V6Glass> _glass = new();
@@ -166,21 +176,47 @@ public partial class V6ProjectImport : Window
         List<V6Glass> _missingGlass = new();
         List<V6Labour> _missingLabour = new();
 
+        string exception = null;
+
         if (_importCosts != V6ImportCosts.None)
         {
 
             Progress.ShowModal("Checking Products", progress =>
             {
                 
-                progress.Report("Loading Profiles");
-                _profiles = _client.GetProfiles(_project.Number, _project.Variation);
-
-                progress.Report("Loading Components");
-                _components = _client.GetComponents(_project.Number, _project.Variation);
-
-                progress.Report("Loading Glass");
-                _glass = _client.GetGlass(_project.Number, _project.Variation);
-
+                try
+                {
+                    progress.Report("Loading Profiles");
+                    _profiles = _client.GetProfiles(_project.Number, _project.Variation);
+                }
+                catch (Exception _exception)
+                {
+                    exception = $"Error retrieving Profiles : {_exception.Message}";
+                    return;
+                }
+                
+                try
+                {
+                    progress.Report("Loading Components");
+                    _components = _client.GetComponents(_project.Number, _project.Variation);
+                }
+                catch (Exception _exception)
+                {
+                    exception = $"Error retrieving Components : {_exception.Message}";
+                    return;
+                }
+                
+                try
+                {
+                    progress.Report("Loading Glass");
+                    _glass = _client.GetGlass(_project.Number, _project.Variation);
+                }
+                catch (Exception _exception)
+                {
+                    exception = $"Error retrieving Glass : {_exception.Message}";
+                    return;
+                }
+                
                 progress.Report("Checking Product List");
                 var _productcodes = _profiles.Select(x => x.Code)
                     .Union(_components.Select(x => x.Code))
@@ -211,6 +247,12 @@ public partial class V6ProjectImport : Window
 
             });
 
+            if (!string.IsNullOrWhiteSpace(exception))
+            {
+                MessageWindow.ShowMessage(exception,"V6 Error",PRSDesktop.Resources.warning.AsBitmapImage());
+                return;
+            }
+
             if (_missingProfiles.Any() || _missingComponents.Any() || _missingGlass.Any())
             {
                 if (!MessageWindow.ShowYesNo(
@@ -222,9 +264,6 @@ public partial class V6ProjectImport : Window
                         $"Do you wish to create them now?",
                         "Create Missing Products"))
                     return;
-                CreateMissingProducts<V6Profile>(_profileUOM, _missingProfiles, _products);
-                CreateMissingProducts<V6Component>(_componentUOM, _missingComponents, _products);
-                CreateMissingProducts<V6Glass>(_glassUOM, _missingGlass, _products);
             }
 
             Progress.ShowModal("Checking Labour", progress =>
@@ -250,63 +289,108 @@ public partial class V6ProjectImport : Window
                 if (!MessageWindow.ShowOKCancel(
                         $"The following products do not exist in PRS\n" +
                         $"- {string.Join("\n- ", _missingLabour.Select(x => x.Code).Distinct().OrderBy(x => x))}\n\n" +
-                        $"Do you wish to create them now?",
+                        $"Do you wish to create them?",
                         "Create Missing Activities"))
                     return;
-                CreateMissingLabour(_missingLabour, _activities);
             }
         }
 
+        List<String> designExceptions = new();
         if (_importDesigns != V6ImportDesigns.None)
         {
+
+            List<V6Elevation> _designlist = new();
             Progress.ShowModal("Checking Designs", progress =>
             {
-                    foreach (var _design in _client.GetItems(_project.Number, _project.Variation))
+                try
+                {
+                    _designlist = _client.GetItems(_project.Number, _project.Variation);
+                }
+                catch (Exception _exception)
+                {
+                    designExceptions.Add($"Error retrieving designs : {_exception.Message}");
+                    return;
+                }
+                
+                foreach (var _design in _designlist)
+                {
+                    try
+                    {
                         _designs[_design] = new V6Drawings();
+                    }
+                    catch (Exception _exception)
+                    {
+                        designExceptions.Add($"Error retrieving design [{_design.Description}]: {_exception.Message}");
+                    }
+                }
+                    
             });
         }
 
+        if (designExceptions.Any())
+        {
+            MessageWindow.ShowMessage(string.Join("\n",designExceptions),"V6 Error",PRSDesktop.Resources.warning.AsBitmapImage());
+            return;
+        }
+
+        string createException = "";
         Progress.ShowModal("Creating Job", progress =>
         {
-            var _scope = CreateJob(_project);
-            
-            if (_importCosts != V6ImportCosts.None)
+            try
             {
-
-                progress.Report("Creating Bill of Materials");
-                var bom = CreateBillofMaterials(_project, _scope, 
-                    _profiles, _profileUOM, 
-                    _components, _componentUOM, 
-                    _glass, _glassUOM, 
-                    _products);
-
-                if (_importCosts == V6ImportCosts.Requisitions)
+                
+                var _scope = CreateJob(_project);
+            
+                if (_importCosts != V6ImportCosts.None)
                 {
-                    // Convert BOM to Requisition
+                    CreateMissingProducts<V6Profile>(_profileUom, _missingProfiles, _products);
+                    CreateMissingProducts<V6Component>(_componentUom, _missingComponents, _products);
+                    CreateMissingProducts<V6Glass>(_glassUom, _missingGlass, _products);
+                    CreateMissingLabour(_missingLabour, _activities);
+
+                    progress.Report("Creating Bill of Materials");
+                    var bom = CreateBillofMaterials(_project, _scope, 
+                        _profiles, _profileUom, 
+                        _components, _componentUom, 
+                        _glass, _glassUom, 
+                        _products);
+
+                    if (_importCosts == V6ImportCosts.Requisitions)
+                    {
+                        // Convert BOM to Requisition
+                    }
+
+                    progress.Report("Creating Labour Budget");
+                    CreateActivities(_project, _scope, _labour, _activities);
                 }
 
-                progress.Report("Creating Labour Budget");
-                CreateActivities(_project, _scope, _labour, _activities);
-            }
-
-            if (_importDesigns != V6ImportDesigns.None)
-            {
-                progress.Report("Loading Drawings");
-                foreach (var _key in _designs.Keys)
+                if (_importDesigns != V6ImportDesigns.None)
                 {
-                    progress.Report($"Loading Drawing: {_key.Description}");
-                    _designs[_key] = _client.GetDrawings(_key.ID);
+                    progress.Report("Loading Drawings");
+                    foreach (var _key in _designs.Keys)
+                    {
+                        progress.Report($"Loading Drawing: {_key.Description}");
+                        _designs[_key] = _client.GetDrawings(_key.ID);
+                    }
+
+                    if (_importDesigns == V6ImportDesigns.ForApproval)
+                        CreateStagedSetouts(_project, _scope, _designs, _template, _stages);
+                    else
+                        CreateManufacturingPackets(_project, _scope, _designs, _template, _stages);
                 }
-
-                if (_importDesigns == V6ImportDesigns.ForApproval)
-                    CreateStagedSetouts(_project, _scope, _designs, _template, _stages);
-                else
-                    CreateManufacturingPackets(_project, _scope, _designs, _template, _stages);
             }
-
+            catch (Exception _exception)
+            {
+                createException = $"Error Creating Job: {_exception.Message}\n{_exception.StackTrace}";
+            }
         });
-        
 
+        if (!string.IsNullOrWhiteSpace(createException))
+        {
+            MessageWindow.ShowMessage(createException,"PRS Error",PRSDesktop.Resources.warning.AsBitmapImage());
+            return;
+        }
+        
         List<String> _missing = new();
         _missing.AddRange(_missingLabour.Select(x => $"- Activity {x.Code}: {x.Description}").Distinct().OrderBy(x => x));
         _missing.AddRange(_missingProfiles.Select(x => $"- Product {x.Code}: {x.Description}")

+ 8 - 5
prs.desktop/Utils/V6Utils/V6Client.cs

@@ -40,7 +40,7 @@ public class V6Client : IDisposable
         DataTable _result = new DataTable(tablename);
         if (connection != null)
         {
-            using (var _command = new SqlCommand(sql, connection))
+            using (var _command = new SqlCommand(sql.Replace("\r\n"," ").Replace("\n"," ").Replace("\r"," "), connection))
             {
                 if (parameters?.Any() == true)
                 {
@@ -59,12 +59,14 @@ public class V6Client : IDisposable
 
     public int GetInteger(DataRow row, string field, int defaultvalue = 0)
     {
-        return row[field] == DBNull.Value ? 0 : (int)row[field];
+        return row[field] == DBNull.Value ? 0 : Convert.ToInt32(row[field]);
     }
     
     public double GetDouble(DataRow row, string field, double defaultvalue = 0.0)
     {
-        return row[field] == DBNull.Value ? 0.0 : Decimal.ToDouble(((decimal)(row[field])));
+        return row[field] == DBNull.Value
+            ? 0.0
+            : Convert.ToDouble(row[field]);
     }
 
     public string GetString(DataRow row, string field, string defaultvalue = "")
@@ -359,7 +361,7 @@ public class V6Client : IDisposable
 
         _result.Code = GetString(row, nameof(V6Profile.Code));
         _result.Description = GetString(row, nameof(V6Profile.Description));
-        _result.Length = GetDouble(row, nameof(V6Profile.Length)) /  25.4;
+        _result.Length = GetDouble(row, nameof(V6Profile.Length));
         _result.Quantity = Math.Ceiling(GetDouble(row,nameof(V6Profile.Quantity)) / (_result.Length.IsEffectivelyEqual(0.0) ? 1.0 : _result.Length));
         return _result;
     }
@@ -436,7 +438,8 @@ public class V6Client : IDisposable
             Treatment = GetString(row, nameof(V6Glass.Treatment)),
             Height = GetDouble(row, nameof(V6Glass.Height)),
             Width = GetDouble(row, nameof(V6Glass.Width)),    
-            Location = GetString(row, nameof(V6Glass.Location))
+            Location = GetString(row, nameof(V6Glass.Location)),
+            Quantity = GetDouble(row, nameof(V6Glass.Quantity))   
         };
     }
 

+ 2 - 2
prs.desktop/prsdesktop.iss

@@ -8,7 +8,7 @@
 #define public Dependency_Path_NetCoreCheck "dependencies\"
 
 #define MyAppName "PRS Desktop"
-#define MyAppVersion "8.13a"
+#define MyAppVersion "8.13b"
 #define MyAppPublisher "PRS Digital"
 #define MyAppURL "https://www.prs-software.com.au"
 #define MyAppExeName "PRSDesktop.exe"
@@ -51,7 +51,7 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{
 Source: "{#Dependency_Path_NetCoreCheck}netcorecheck.exe"; Flags: dontcopy noencryption
 Source: "{#Dependency_Path_NetCoreCheck}netcorecheck_x64.exe"; Flags: dontcopy noencryption
 Source: "bin\Debug\net8.0-windows\*"; DestDir: "{app}"; Excludes: "version.txt"; Flags: ignoreversion recursesubdirs createallsubdirs; AfterInstall: UpdateVersionNumber
-Source: "..\prs.logikal\bin\Debug\*"; DestDir: "{app}\PRSLogikal"; Flags: ignoreversion recursesubdirs createallsubdirs;
+; Source: "..\prs.logikal\bin\Debug\*"; DestDir: "{app}\PRSLogikal"; Flags: ignoreversion recursesubdirs createallsubdirs;
 
 [Dirs]
 Name: "{userappdata}\PRSDesktop"; Flags: 

+ 1 - 1
prs.licensing/PRSLicensing.iss

@@ -8,7 +8,7 @@
 #define public Dependency_Path_NetCoreCheck "dependencies\"
 
 #define MyAppName "PRS Licensing"
-#define MyAppVersion "8.13a"
+#define MyAppVersion "8.13b"
 #define MyAppPublisher "PRS Digital"
 #define MyAppURL "https://www.prs-software.com.au"
 #define MyAppExeName "PRSLicensing.exe"

+ 1 - 1
prs.server/PRSServer.iss

@@ -8,7 +8,7 @@
 #define public Dependency_Path_NetCoreCheck "dependencies\"
 
 #define MyAppName "PRS Server"
-#define MyAppVersion "8.13a"
+#define MyAppVersion "8.13b"
 #define MyAppPublisher "PRS Digital"
 #define MyAppURL "https://www.prs-software.com.au"
 #define MyAppExeName "PRSServer.exe"