using System; using System.Collections.Generic; using System.Linq; using Comal.Classes; using InABox.Clients; using InABox.Core; using InABox.DynamicGrid; namespace PRSDesktop { internal class SetoutManufacturingGrid : DynamicOneToManyGrid { private readonly ManufacturingSection[] Sections = new Client().Load(); private readonly ManufacturingTemplateStage[] Stages = new Client().Load(); protected override Dictionary EditorValueChanged(IDynamicEditorForm editor, ManufacturingPacket[] items, string name, object value) { var result = base.EditorValueChanged(editor, items, name, value); if (name == "ManufacturingTemplateLink.ID") { var template = new Client().Load(new Filter(x => x.ID).IsEqualTo(value)) .FirstOrDefault(); if (template != null) { foreach (var item in items) item.Group = template.Factory.Name; result["Group"] = template.Factory.Name; } //Type attrtype = typeof(IDynamicEnclosedListGrid<,>).MakeGenericType(typeof(ManufacturingPacket), typeof(CoreAttribute)); //var attrpage = editor.Pages.FirstOrDefault(x => x.GetType().GetInterface(attrtype.Name) != null); //if (attrpage != null) //{ // if (!attrpage.Ready) // attrpage.Load(items.First(), null); // MethodInfo load = attrpage.GetType().GetMethod("LoadItems"); // load.Invoke(attrpage, new object[] { template.CustomAttributes }); //} var stagetype = typeof(IDynamicOneToManyGrid<,>).MakeGenericType(typeof(ManufacturingPacket), typeof(ManufacturingPacketStage)); var stagepage = editor.Pages.FirstOrDefault(x => x.GetType().GetInterface(stagetype.Name) != null); if (stagepage != null) { var tstages = Stages.Where(x => x.Template.ID.Equals(value)).OrderBy(x => x.Sequence); var pstages = new List(); foreach (var tstage in tstages) { var pstage = new ManufacturingPacketStage { Time = tstage.Time, Sequence = tstage.Sequence, SequenceType = tstage.SequenceType, Started = DateTime.MinValue, PercentageComplete = 0.0F, Completed = DateTime.MinValue, QualityChecks = tstage.QualityChecks, QualityStatus = QualityStatus.NotChecked, QualityNotes = "" }; var section = Sections.Where(x => x.ID.Equals(tstage.Section.ID)); //pstage.QAChecks.AddRange(tstage.QAChecks); pstage.ManufacturingSectionLink.ID = tstage.Section.ID; pstage.ManufacturingSectionLink.Name = tstage.Section.Name; pstages.Add(pstage); } if (!stagepage.Ready) stagepage.Load(items.First(), null); var load = stagepage.GetType().GetMethod("LoadItems"); load.Invoke(stagepage, new object[] { pstages.ToArray() }); } } return result; } } }