123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710 |
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Media.Imaging;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.Wpf;
- using InABox.WPF;
- namespace PRSDesktop;
- public class V6ProjectImportGrid : DynamicItemsListGrid<V6Quote>
- {
- private static BitmapImage Quotation => PRSDesktop.Resources.quotation.AsBitmapImage();
- private static BitmapImage Revision => PRSDesktop.Resources.revision.AsBitmapImage();
-
- public V6ProjectImportGrid()
- {
- ActionColumns.Add(new DynamicImageColumn(StatusImage) { Position = DynamicActionColumnPosition.Start});
- }
- private BitmapImage? StatusImage(CoreRow? row)
- {
- return row == null
- ? Quotation
- : string.IsNullOrWhiteSpace(row.Get<V6Quote, string>(x => x.Variation))
- ? Quotation
- : Revision;
- }
- protected override void DoReconfigure(DynamicGridOptions options)
- {
- base.DoReconfigure(options);
- options.FilterRows = true;
- options.HideDatabaseFilters = true;
- }
- }
- public partial class V6ProjectImport : Window
- {
- private readonly V6Client _client;
-
- public V6ProjectImport()
- {
- InitializeComponent();
- _client = new V6Client();
- ImportCosts.SelectedValue = _client.Settings.ImportCosts;
- ImportDesigns.SelectedValue = _client.Settings.ImportDesigns;
- if (_client.Connect())
- {
- Task<List<V6Quote>> v6Task = Task.Run(() =>
- {
- var _quotes = _client.IsConnected
- ? _client?.GetQuotes()?.ToList()
- : null;
- return _quotes ?? new List<V6Quote>();
- });
-
- Task<List<JobScope>> prsTask = Task.Run(() => Client.Query<JobScope>(null,
- Columns.None<JobScope>().Add(x => x.Job.ID).Add(x => x.Job.JobNumber).Add(x=>x.Job.SourceRef).Add(x=>x.Job.DefaultScope.ID).Add(x=>x.ID).Add(x=>x.Number).Add(x=>x.SourceRef)
- ).ToObjects<JobScope>().ToList());
-
- Task.WaitAll(v6Task,prsTask);
- var quotes = v6Task.Result;
- var scopes = prsTask.Result;
- Projects.Items = quotes
- .Where(q => string.IsNullOrWhiteSpace(q.Variation)
- ? !scopes.Any(x=>string.Equals(x.Job.DefaultScope.SourceRef, $"{q.Number}"))
- : !scopes.Any(x=> string.Equals(x.SourceRef,$"{q.Number}")))
- .ToList();
- }
- else
- {
- MessageWindow.ShowMessage("Cannot connect to V6!","Error");
- Projects.Items = new List<V6Quote>();
-
- }
- Projects.Refresh(true,true);
-
- }
-
- private void OK_Click(object sender, RoutedEventArgs e)
- {
-
- var _project = Projects.LoadItem(Projects.SelectedRows.First());
- var _importCosts = (V6ImportCosts)ImportCosts.SelectedValue;
- var _importDesigns = (V6ImportDesigns)ImportDesigns.SelectedValue;
- ProductDimensionUnit? _profileUom = new();
- ProductDimensionUnit? _componentUom = new();
- ProductDimensionUnit? _glassUom = new();
-
- ManufacturingTemplate? _template = new ManufacturingTemplate();
- ManufacturingTemplateStage[] _stages = [];
-
- MultiQuery query = new MultiQuery();
- if (_importCosts != V6ImportCosts.None)
- {
- query.Add(
- new Filter<ProductDimensionUnit>(x => x.Code).InList(new string[]
- { _client.Settings.ProfileUom, _client.Settings.ComponentUom, _client.Settings.GlassUom }),
- Columns.All<ProductDimensionUnit>()
- );
- }
- if (_importDesigns == V6ImportDesigns.ToManufacturing)
- {
- 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();
-
- if (_importDesigns == V6ImportDesigns.ToManufacturing)
- {
- _template = query.Get<ManufacturingTemplate>().Rows.FirstOrDefault()?.ToObject<ManufacturingTemplate>();
- _stages = query.Get<ManufacturingTemplateStage>().ToObjects<ManufacturingTemplateStage>().ToArray();
- }
- 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();
- List<V6Labour> _labour = new();
-
- List<Product> _products = new();
- List<Activity> _activities = new();
- Dictionary<V6Elevation, V6Drawings> _designs = new();
-
- List<V6Profile> _missingProfiles = new();
- List<V6Component> _missingComponents = new();
- List<V6Glass> _missingGlass = new();
- List<V6Labour> _missingLabour = new();
- string exception = null;
- if (_importCosts != V6ImportCosts.None)
- {
- Progress.ShowModal("Checking Products", progress =>
- {
-
- 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))
- .Union(_glass.Select(x => x.Code))
- .Distinct()
- .ToArray();
- _products = Client.Query(
- new Filter<Product>(x => x.Code).InList(_productcodes),
- Columns.None<Product>()
- .Add(x => x.ID)
- .Add(x => x.Code)
- .Add(x => x.Name)
- .Add(x => x.UnitOfMeasure.ID)
- .Add(x => x.UnitOfMeasure.Code)
- .Add(x => x.UnitOfMeasure.Description)
- .Add(x => x.UnitOfMeasure.HasQuantity)
- .Add(x => x.UnitOfMeasure.HasLength)
- .Add(x => x.UnitOfMeasure.HasWidth)
- .Add(x => x.UnitOfMeasure.HasHeight)
- .Add(x=>x.UnitOfMeasure.Format)
- .Add(x=>x.UnitOfMeasure.Formula)
- ).ToObjects<Product>().ToList();
- var _missingCodes = _productcodes.Where(c => !_products.Any(p => string.Equals(p.Code, c))).ToArray();
- _missingProfiles.AddRange(_profiles.Where(x => _missingCodes.Contains(x.Code)));
- _missingComponents.AddRange(_components.Where(x => _missingCodes.Contains(x.Code)));
- _missingGlass.AddRange(_glass.Where(x => _missingCodes.Contains(x.Code)));
- });
- if (!string.IsNullOrWhiteSpace(exception))
- {
- MessageWindow.ShowMessage(exception,"V6 Error",PRSDesktop.Resources.warning.AsBitmapImage());
- return;
- }
- if (_missingProfiles.Any() || _missingComponents.Any() || _missingGlass.Any())
- {
- if (!MessageWindow.ShowYesNo(
- $"The following products do not exist in PRS\n" +
- $"- {string.Join("\n- ", _missingProfiles.Select(x => x.Code)
- .Union(_missingComponents.Select(x => x.Code))
- .Union(_missingGlass.Select(x => x.Code))
- .Distinct().OrderBy(x => x))}\n\n" +
- $"Do you wish to create them now?",
- "Create Missing Products"))
- return;
- }
- Progress.ShowModal("Checking Labour", progress =>
- {
- progress.Report("Loading Labour");
- _labour = _client.GetLabour(_project.Number, _project.Variation);
- var _labourcodes = _labour.Select(x => x.Code).Distinct().ToArray();
- _activities = Client.Query(
- new Filter<Activity>(x => x.Code).InList(_labourcodes),
- Columns.None<Activity>()
- .Add(x => x.ID)
- .Add(x => x.Code)
- .Add(x => x.Description)
- ).ToObjects<Activity>().ToList();
- var _missingCodes = _labourcodes.Where(l => !_activities.Any(a => string.Equals(a.Code, l))).ToArray();
- _missingLabour.AddRange(_labour.Where(x => _missingCodes.Contains(x.Code)));
- });
- if (_missingLabour.Any())
- {
- 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?",
- "Create Missing Activities"))
- return;
- }
- }
- List<String> designExceptions = new();
- if (_importDesigns != V6ImportDesigns.None)
- {
- List<V6Elevation> _designlist = new();
- Progress.ShowModal("Checking Designs", progress =>
- {
- 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 =>
- {
- try
- {
-
- var _scope = CreateJob(_project);
-
- if (_importCosts != V6ImportCosts.None)
- {
- 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);
- }
- if (_importDesigns != V6ImportDesigns.None)
- {
- 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);
- }
- }
- 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}")
- .Union(_missingComponents.Select(x => $"- Product {x.Code}: {x.Description}"))
- .Union(_missingGlass.Select(x => $"- Product {x.Code}: {x.Description}"))
- .Distinct()
- .OrderBy(x => x));
- if (_missing.Any())
- MessageWindow.ShowMessage($"The following items were auto-created and should be manually checked:\n{String.Join("\n",_missing)}","Results");
- DialogResult = true;
- }
- private static void CreateMissingLabour(List<V6Labour> missinglabour, List<Activity> activitylist)
- {
- List<Activity> _updates = new();
- foreach (var _missing in missinglabour)
- {
- if (!_updates.Any(x => String.Equals(x.Code, _missing.Code)))
- {
- var _activity = new Activity();
- _activity.Code = _missing.Code;
- _activity.Description = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(_missing.Code.ToLower());
- _activity.Issues = $"Created By V6 Import";
- _updates.Add(_activity);
- }
- }
- Client.Save(_updates, "Created by V6 Import");
- activitylist.AddRange(_updates);
- }
- private static void CreateMissingProducts<T>(ProductDimensionUnit uom, List<T> missingitems, List<Product> productlist) where T : V6BOMItem
- {
-
- List<Product> _updates = new();
- foreach (var _missingitem in missingitems)
- {
- if (!_updates.Any(x => String.Equals(x.Code, _missingitem.Code)))
- {
- var _product = new Product();
- _product.UnitOfMeasure.CopyFrom(uom);
- _product.Code = _missingitem.Code;
- _product.Name = _missingitem.Description;
- _product.Issues = $"Created By V6 Import";
- _updates.Add(_product);
- }
- }
- Client.Save(_updates, "Created by V6 Import");
- productlist.AddRange(_updates);
- }
-
- private static JobScope CreateJob(V6Quote quote)
- {
- var _jobno = $"V{quote.Number}";
- MultiQuery query = new MultiQuery();
- query.Add(
- new Filter<Job>(x=>x.JobNumber).IsEqualTo(_jobno),
- Columns.Required<Job>().Add(x=>x.DefaultScope.ID)
- );
- query.Query();
-
- var _scope = new JobScope();
- var _job = query.Get<Job>().ToObjects<Job>()?.FirstOrDefault();
- if (_job == null)
- {
- _job = new Job();
- _job.JobNumber = _jobno;
- _job.Name = quote.Title;
- Client.Save(_job,"Imported From V6");
- _scope.ID = _job.DefaultScope.ID;
- _scope.CommitChanges();
- }
- _scope.Job.ID = _job.ID;
- _scope.Number = quote.Variation;
- _scope.SourceRef = $"{quote.ID}.{quote.Revision}";
- _scope.Description = string.IsNullOrWhiteSpace(quote.Variation)
- ? "Main Job"
- : quote.Title;
- _scope.ExTax = quote.SellPrice;
- _scope.Type = string.IsNullOrWhiteSpace(quote.Variation)
- ? JobScopeType.Contract
- : JobScopeType.Variation;
- Client.Save(_scope, "Imported From V6");
- return _scope;
- }
-
- private JobBillOfMaterials CreateBillofMaterials(V6Quote quote, JobScope scope,
- List<V6Profile> profiles, ProductDimensionUnit profileUOM,
- List<V6Component> components, ProductDimensionUnit componentUOM,
- List<V6Glass> glass, ProductDimensionUnit glassUOM,
- List<Product> _products)
- {
- var _bom = new JobBillOfMaterials();
- _bom.Job.ID = scope.Job.ID;
- _bom.Description = string.IsNullOrWhiteSpace(quote.Variation)
- ? "Main Job"
- : $"{quote.Variation}";
- Client.Save(_bom,"Imported From V6");
-
- List<JobBillOfMaterialsItem> _bomitems = new();
-
- foreach (var _profile in profiles)
- {
- var _bomitem = new JobBillOfMaterialsItem();
- _bomitem.BillOfMaterials.ID = _bom.ID;
- _bomitem.Job.ID = scope.Job.ID;
- _bomitem.Scope.ID = scope.ID;
- if (_products.FirstOrDefault(x => x.Code == _profile.Code) is { } _p)
- {
- _bomitem.Product.CopyFrom(_p);
- _bomitem.Dimensions.Unit.CopyFrom(profileUOM);
- _bomitem.Dimensions.Length = _profile.Length;
- _bomitem.Quantity = _profile.Quantity;
- }
- else
- _bomitem.Issues = $"Unable to Locate Product: {_profile.Quantity} x {_profile.Code}: {_profile.Description} ({_profile.Length})";
- _bomitems.Add(_bomitem);
- }
-
- foreach (var _component in components)
- {
- var _bomitem = new JobBillOfMaterialsItem();
- _bomitem.BillOfMaterials.ID = _bom.ID;
- _bomitem.Job.ID = scope.Job.ID;
- _bomitem.Scope.ID = scope.ID;
- if (_products.FirstOrDefault(x => x.Code == _component.Code) is { } _s)
- {
- _bomitem.Product.CopyFrom(_s);
- _bomitem.Dimensions.Unit.CopyFrom(componentUOM);
- _bomitem.Dimensions.Quantity = 1;
- _bomitem.Quantity = _component.Quantity * _component.PackSize;
- _bomitems.Add(_bomitem);
- }
- else
- _bomitem.Issues = $"Unable to Locate Profile: {_component.Quantity} x {_component.Code}: {_component.Description} ({_component.PackSize})";
- }
- foreach (var _glass in glass)
- {
- var _bomitem = new JobBillOfMaterialsItem();
- _bomitem.BillOfMaterials.ID = _bom.ID;
- _bomitem.Job.ID = scope.Job.ID;
- _bomitem.Scope.ID = scope.ID;
- if (_products.FirstOrDefault(x => x.Code == _glass.Code) is { } _s)
- {
- _bomitem.Product.CopyFrom(_s);
- _bomitem.Dimensions.Unit.CopyFrom(glassUOM);
- _bomitem.Dimensions.Height = _glass.Height * 25.4;
- _bomitem.Dimensions.Width = _glass.Width * 25.4;
- _bomitem.Quantity = _glass.Quantity;
- _bomitems.Add(_bomitem);
- }
- else
- _bomitem.Issues =
- $"Unable to Locate Profile: {_glass.Quantity} x {_glass.Code}: {_glass.Description} ({_glass.Height} x {_glass.Width})";
- }
- Client.Save(_bomitems,"Imported From V6");
- return _bom;
- }
-
- private void CreateActivities(V6Quote project, JobScope scope, List<V6Labour> labour, List<Activity> activities)
- {
- var _jobactivities = Client.Query(
- new Filter<JobActivity>(x => x.JobLink.ID).IsEqualTo(scope.Job.ID),
- Columns.Required<JobActivity>()
- .Add(x => x.JobLink.ID)
- .Add(x => x.ActivityLink.ID)
- .Add(x => x.Budget)
- ).ToObjects<JobActivity>().ToList();
- List<JobActivity> _updates = new List<JobActivity>();
- foreach (var _labour in labour)
- {
- var _activity = activities.FirstOrDefault(x => string.Equals(x.Code, _labour.Code)) ?? new Activity();
- var _jobactivity = _jobactivities.FirstOrDefault(x => x.ActivityLink.ID == _activity.ID) ?? new JobActivity();
- _jobactivity.JobLink.ID = scope.Job.ID;
- _jobactivity.ActivityLink.CopyFrom(_activity);
- _jobactivity.Budget += TimeSpan.FromMinutes(_labour.Minutes);
- _updates.Add(_jobactivity);
- }
- Client.Save(_updates,"Imported From V6");
- }
-
- private void CreateManufacturingPackets(V6Quote project, JobScope scope, Dictionary<V6Elevation, V6Drawings> designs, ManufacturingTemplate template, ManufacturingTemplateStage[] stages)
- {
- foreach (var _design in designs)
- {
- var _setout = new Setout();
- _setout.JobLink.ID = scope.Job.ID;
- _setout.Description = _design.Key.Description;
- _setout.Number = _design.Key.Description;
- Client.Save(_setout,"Imported From V6");
- var _drawings = _client.DecodeDrawings(_design.Value.Drawings, new string[] { "FrameDrawing" });
- List<Document> _documents = new();
- foreach (var _drawing in _drawings)
- {
- var _document = new Document();
- _document.FileName = System.IO.Path.ChangeExtension(_drawing.FileName, ".pdf");
- _document.Data = ImageUtils.BitmapToPdf(_drawing.Data);
- _documents.Add(_document);
- }
- if (_documents.Any())
- Client.Save(_documents, "Imported From V6");
-
- List<SetoutDocument> _setoutdocuments = new();
- foreach (var _document in _documents)
- {
- var _setoutdocument = new SetoutDocument();
- _setoutdocument.EntityLink.CopyFrom(_setout);
- _setoutdocument.DocumentLink.CopyFrom(_document);
- _setoutdocument.Thumbnail = ImageUtils.GetPDFThumbnail(_document.Data, 256, 256);
- _setoutdocuments.Add(_setoutdocument);
- }
- if (_setoutdocuments.Any())
- Client.Save(_setoutdocuments, "Imported From V6");
- var _packet = new ManufacturingPacket();
- _packet.SetoutLink.ID = _setout.ID;
- _packet.ManufacturingTemplateLink.CopyFrom(template);
- _packet.Title = _setout.Description;
- _packet.Quantity = _design.Key.Quantity;
- Client.Save(_packet,"Imported From V6");
- List<ManufacturingPacketStage> _packetstages = new();
- foreach (var _templatestage in stages)
- {
- var _packetstage = new ManufacturingPacketStage
- {
- Time = _templatestage.Time,
- SequenceType = _templatestage.SequenceType,
- Sequence = _templatestage.Sequence
- };
- _packetstage.Parent.ID = _packet.ID;
- _packetstage.ManufacturingSectionLink.ID = _templatestage.Section.ID;
- _packetstage.ManufacturingSectionLink.Name = _templatestage.Section.Name;
- _packetstages.Add(_packetstage);
- }
- if (_packetstages.Any())
- Client.Save(_packetstages,"Imported from V6");
- }
- }
- private void CreateStagedSetouts(V6Quote project, JobScope scope, Dictionary<V6Elevation, V6Drawings> designs, ManufacturingTemplate template, ManufacturingTemplateStage[] stages)
- {
- foreach (var _design in designs)
- {
- var _setout = new StagingSetout();
- _setout.JobLink.ID = scope.Job.ID;
- _setout.Number = _design.Key.Description;
- Client.Save(_setout,"Imported From V6");
-
- var _drawings = _client.DecodeDrawings(_design.Value.Drawings, new string[] { "FrameDrawing" });
- List<Document> _documents = new();
- foreach (var _drawing in _drawings)
- {
- var _document = new Document();
- _document.FileName = System.IO.Path.ChangeExtension(_drawing.FileName, ".pdf");
- _document.Data = ImageUtils.BitmapToPdf(_drawing.Data);
- _documents.Add(_document);
- }
- if (_documents.Any())
- Client.Save(_documents, "Imported From V6");
-
- List<StagingSetoutDocument> _setoutdocuments = new();
- foreach (var _document in _documents)
- {
- var _setoutdocument = new StagingSetoutDocument();
- _setoutdocument.EntityLink.CopyFrom(_setout);
- _setoutdocument.DocumentLink.CopyFrom(_document);
- _setoutdocument.Thumbnail = ImageUtils.GetPDFThumbnail(_document.Data, 256, 256);
- _setoutdocuments.Add(_setoutdocument);
- }
- if (_setoutdocuments.Any())
- Client.Save(_setoutdocuments, "Imported From V6");
- var _packet = new StagingManufacturingPacket();
- _packet.StagingSetout.ID = _setout.ID;
- _packet.Template.CopyFrom(template);
- _packet.Title = _setout.Number;
- _packet.Quantity = _design.Key.Quantity;
- Client.Save(_packet,"Imported From V6");
-
- List<StagingManufacturingPacketStage> _packetstages = new();
- foreach (var _templatestage in stages)
- {
- var _packetstage = new StagingManufacturingPacketStage
- {
- Time = _templatestage.Time,
- SequenceType = _templatestage.SequenceType,
- Sequence = _templatestage.Sequence
- };
- _packetstage.Packet.ID = _packet.ID;
- _packetstage.Section.ID = _templatestage.Section.ID;
- _packetstage.Section.Name = _templatestage.Section.Name;
- _packetstages.Add(_packetstage);
- }
- if (_packetstages.Any())
- Client.Save(_packetstages,"Imported from V6");
-
- }
- }
- private void Cancel_Click(object sender, RoutedEventArgs e)
- {
- DialogResult = false;
- }
- private void Projects_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
- {
- Ok.IsEnabled = Projects.SelectedRows.Any();
- }
- }
|