|
@@ -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}")
|