| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778 | using System;using System.Collections.Generic;using System.Globalization;using System.Linq;using System.Threading.Tasks;using System.Windows;using Comal.Classes;using InABox.Clients;using InABox.Core;using InABox.DynamicGrid;using InABox.Wpf;using InABox.WPF;using NPOI.OpenXmlFormats.Wordprocessing;using PRSDesktop.Integrations.V6;namespace PRSDesktop;public partial class V6ProjectSelection : Window{        private V6Client _client;    private Func<V6Project, bool>? _filter;    private Action<V6Project>? _selected;        public V6ProjectSelection(V6Client client, Func<V6Project,bool> filter, Action<V6Project> selected)    {        _client = client;        _filter = filter;        _selected = selected;        InitializeComponent();                ImportCosts.SelectedValue = _client.Settings.ImportCosts;        ImportDesigns.SelectedValue = _client.Settings.ImportDesigns;        if (_client.IsConnected)        {            Projects.Items = _client.GetProjects()                .Where(filter)                .ToList();                                    // Task<List<V6Project>> v6Task = Task.Run(() =>            // {            //     var _quotes = _client.IsConnected            //         ? _client?.GetQuotes()?.ToList()             //           : null;            //     return _quotes ?? new List<V6Project>();            // });            //            // 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("Not Connected to V6!","Error");            Projects.Items = new List<V6Project>();                    }        Projects.Refresh(true,true);            }        private void Cancel_Click(object sender, RoutedEventArgs e)    {        DialogResult = false;    }    private void Projects_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)    {        Ok.IsEnabled = Projects.SelectedRows.Any();    }        private void OK_Click(object sender, RoutedEventArgs e)    {                var _project = Projects.LoadItem(Projects.SelectedRows.First());        _selected?.Invoke(_project);        DialogResult = true;                // var _importCosts = (V6CostType)ImportCosts.SelectedValue;        // var _importDesigns = (V6DesignType)ImportDesigns.SelectedValue;        //        // ManufacturingTemplate? _template = new ManufacturingTemplate();        // ManufacturingTemplateStage[] _stages = [];        //        // MultiQuery query = new MultiQuery();        //        // if (_importDesigns == V6DesignType.Approved)        // {        //     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 == V6DesignType.Approved)        // {        //     _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;        // }        //        // List<string> _finishes = new();        // List<V6Profile> _profiles = new();        // List<V6Component> _components = new();        // List<V6Glass> _glass = new();        // List<V6Labour> _labour = new();        //        // List<ProductStyle> _styles = 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();        // List<string> _missingFinishes = new();        //        // string exception = null;        //        // if (_importCosts != V6CostType.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 PRS Codes");        //        //         MultiQuery query = new MultiQuery();        //                 //         var _productStyles = _profiles.Select(x => x.Finish)        //             .Union(_glass.Select(x => x.Treatment))        //             .Distinct()        //             .ToArray();        //        //         query.Add(        //             new Filter<ProductStyle>(x => x.Code).InList(_productStyles),        //             Columns.None<ProductStyle>().Add(x => x.ID).Add(x => x.Code)        //         );        //                 //         var _productcodes = _profiles.Select(x => x.Code)        //             .Union(_components.Select(x => x.Code))        //             .Union(_glass.Select(x => x.Code))        //             .Distinct()        //             .ToArray();        //        //         query.Add(        //             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)        //                 .Add(x => x.TaxCode.ID)        //                 .Add(x => x.TaxCode.Code)        //         );        //        //         query.Query();        //        //         _styles = query.Get<ProductStyle>().ToObjects<ProductStyle>().ToList();        //         _products = query.Get<Product>().ToObjects<Product>().ToList();        //                 //         _missingFinishes.AddRange(_productStyles.Where(c => !string.IsNullOrWhiteSpace(c) && !_styles.Any(p => string.Equals(p.Code, c))));        //                 //         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;        //     }        //        //     if (_missingFinishes.Any())        //     {        //         if (!MessageWindow.ShowYesNo(        //                 $"The following styles do not exist in PRS\n" +        //                 $"- {string.Join("\n- ", _missingFinishes        //                     .Distinct().OrderBy(x => x))}\n\n" +        //                 $"Do you wish to create them now?",        //                 "Create Missing Styles"))        //             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 != V6DesignType.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, _client.Settings.JobStatus, _client.Settings.TaxCode);        //             //         // if (_importCosts != V6ImportCosts.None)        //         // {        //         //     CreateMissingStyles(_missingFinishes, _styles);        //         //     CreateMissingProducts<V6Profile>(_profileUom, _taxCode, _missingProfiles, _products);        //         //     CreateMissingProducts<V6Component>(_componentUom, _taxCode, _missingComponents, _products);        //         //     CreateMissingProducts<V6Glass>(_glassUom, _taxCode, _missingGlass, _products);        //         //     CreateMissingLabour(_missingLabour, _activities);        //         //        //         //     progress.Report("Creating Bill of Materials");        //         //     var bom = CreateBillofMaterials(_project, _scope,         //         //         _profiles, _profileUom,         //         //         _components, _componentUom,         //         //         _glass, _glassUom,         //         //         _products, _styles);        //         //        //         //     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(_missingFinishes.Select(x => $"- Style {x}").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.Problem.Notes = new string[] { "Created by V6 Import" };    //             _updates.Add(_activity);    //         }    //     }    //    //     Client.Save(_updates, "Created by V6 Import");    //     activitylist.AddRange(_updates);    // }    //    // private static void CreateMissingStyles( List<string> missingitems, List<ProductStyle> styleList)    // {    //         //     List<ProductStyle> _updates = new();    //     foreach (var _missingitem in missingitems)    //     {    //         if (!_updates.Any(x => String.Equals(x.Code, _missingitem)))    //         {    //             var _productstyle = new ProductStyle();    //             _productstyle.Code = _missingitem;    //             _productstyle.Description = _missingitem;    //             _productstyle.Problem.Notes = new string[] { "Created by V6 Import" };    //             _updates.Add(_productstyle);    //         }    //     }    //    //     Client.Save(_updates, "Created by V6 Import");    //     styleList.AddRange(_updates);    // }    //    // private static void CreateMissingProducts<T>(ProductDimensionUnit uom, TaxCode tax, 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.Problem.Notes = new string[] { "Created by V6 Import" };    //             _product.TaxCode.CopyFrom(tax);    //             _updates.Add(_product);    //         }    //     }    //    //     Client.Save(_updates, "Created by V6 Import");    //     productlist.AddRange(_updates);    // }        // private static JobScope CreateJob(V6Project project, JobStatusLink status, TaxCodeLink tax)    // {    //     var _jobno = $"V{project.Number}";    //     MultiQuery query = new MultiQuery();    //     query.Add(    //         new Filter<Job>(x=>x.JobNumber).IsEqualTo(_jobno),    //         Columns.Required<Job>().Add(x=>x.DefaultScope.ID)    //     );    //     if (!string.IsNullOrWhiteSpace(project.ClientID))    //     {    //         query.Add(    //             new Filter<Customer>(x => x.Code).IsEqualTo(project.ClientID),    //             Columns.Required<Customer>()    //         );    //     }    //     query.Query();    //         //     var _scope = new JobScope();    //         //     var _job = query.Get<Job>().ToObjects<Job>().FirstOrDefault();    //         //     var _customer = !string.IsNullOrWhiteSpace(project.ClientID)    //         ? query.Get<Customer>().ToObjects<Customer>().FirstOrDefault()    //         : null;    //         //     if (_job == null)    //     {    //             //         if (!string.IsNullOrWhiteSpace(project.ClientID) && _customer == null)    //         {    //             _customer = new Customer();    //             _customer.Code = project.ClientID;    //             _customer.Name = project.ClientName;    //             _customer.Delivery.Street = project.Street;    //             _customer.Delivery.City = project.City;    //             _customer.Delivery.State = project.State;    //             _customer.Delivery.PostCode = project.PostCode;    //             Client.Save(_customer,"Imported From V6");    //         }    //             //         _job = new Job();    //         _job.JobNumber = _jobno;    //         _job.Name = project.Title;    //         _job.JobStatus.CopyFrom(status);    //         if (_customer != null)    //         {    //             _job.Customer.CopyFrom(_customer);    //             _job.Account.CopyFrom(_customer);    //         }    //         _job.SiteAddress.Street = project.Street;    //         _job.SiteAddress.City = project.City;    //         _job.SiteAddress.State = project.State;    //         _job.SiteAddress.PostCode = project.PostCode;    //         Client.Save(_job,"Imported From V6");    //         _scope.ID = _job.DefaultScope.ID;    //         _scope.CommitChanges();    //     }    //     _scope.Job.ID = _job.ID;    //     _scope.Number = project.Variation;    //     _scope.SourceRef = $"{project.ID}.{project.Revision}";    //     _scope.Description = string.IsNullOrWhiteSpace(project.Variation)    //         ? "Main Job"    //         : project.Title;    //     _scope.ExTax = project.SellPrice;    //     _scope.TaxCode.CopyFrom(tax);    //     _scope.Type = string.IsNullOrWhiteSpace(project.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, List<ProductStyle> _styles)    // {    //     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;    //         }    //         else    //             _bomitem.Problem.Notes = new string[] { $"Unable to Locate Product: {_profile.Quantity} x {_profile.Code}: {_profile.Description} ({_profile.Length})" };    //    //         if (!string.IsNullOrWhiteSpace(_profile.Finish))    //         {    //             if (_styles.FirstOrDefault(x => x.Code == _profile.Finish) is { } _s)    //                 _bomitem.Style.CopyFrom(_s);    //             else    //                 _bomitem.Problem.Notes = new string[] { $"Unable to Locate Style: {_profile.Finish}" };    //         }    //    //         _bomitem.Quantity = _profile.Quantity;    //         _bomitem.UnitCost = _profile.Cost;    //         _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;    //             _bomitems.Add(_bomitem);    //         }    //         else    //             _bomitem.Problem.Notes = new string[] { $"Unable to Locate Product: {_component.Quantity} x {_component.Code}: {_component.Description} ({_component.PackSize})" };    //             //         _bomitem.Quantity = _component.Quantity * _component.PackSize;    //         _bomitem.UnitCost = _component.Cost;    //     }    //    //     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 { } _p)    //         {    //             _bomitem.Product.CopyFrom(_p);    //             _bomitem.Dimensions.Unit.CopyFrom(glassUOM);    //             _bomitem.Dimensions.Height = _glass.Height * 25.4;    //             _bomitem.Dimensions.Width = _glass.Width * 25.4;    //             _bomitems.Add(_bomitem);    //         }    //         else    //             _bomitem.Problem.Notes = new string[] {     //                 $"Unable to Locate Product: {_glass.Code}: {_glass.Description} ({_glass.Height} x {_glass.Width})" };    //    //         if (!string.IsNullOrWhiteSpace(_glass.Treatment))    //         {    //             if (_styles.FirstOrDefault(x => x.Code == _glass.Treatment) is { } _s)    //                 _bomitem.Style.CopyFrom(_s);    //             else    //                 _bomitem.Problem.Notes = new string[] { $"Unable to Locate Style: {_glass.Treatment})" };    //         }    //    //         _bomitem.Quantity = _glass.Quantity;    //         _bomitem.UnitCost = _glass.Cost;    //    //     }    //         //     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.FromHours(_labour.Quantity);    //         _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");    //             //     }    // }}
 |