12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Controls;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- namespace PRSDesktop
- {
- public class ManufacturingTemplateGrid : DynamicDataGrid<ManufacturingTemplate>
- {
- private bool bShowAll;
- public ManufacturingTemplateGrid()
- {
- AddButton("Show All", null, ShowAllClick);
- }
- private bool ShowAllClick(Button arg1, CoreRow[] arg2)
- {
- bShowAll = !bShowAll;
- UpdateButton(arg1, null, bShowAll ? "Active Only" : "Show All");
- return true;
- }
- protected override void Reload(Filters<ManufacturingTemplate> criteria, Columns<ManufacturingTemplate> columns,
- ref SortOrder<ManufacturingTemplate> sort, Action<CoreTable, Exception> action)
- {
- if (!bShowAll)
- criteria.Add(new Filter<ManufacturingTemplate>(x => x.Active).IsEqualTo(true));
- base.Reload(criteria, columns, ref sort, action);
- }
- protected override Dictionary<string, object> EditorValueChanged(DynamicEditorForm editor, ManufacturingTemplate[] items, string name,
- object value)
- {
- var result = base.EditorValueChanged(editor, items, name, value);
- if (name == "Factory.ID")
- {
- var type = typeof(IDynamicOneToManyGrid<,>).MakeGenericType(typeof(ManufacturingTemplate), typeof(ManufacturingTemplateStage));
- var page = editor.Pages.FirstOrDefault(x => x.GetType().GetInterface(type.Name) != null);
- if (page != null)
- {
- var sections = new Client<ManufacturingSection>().Load(new Filter<ManufacturingSection>(x => x.Factory.ID).IsEqualTo(value));
- var stages = new List<ManufacturingTemplateStage>();
- foreach (var section in sections)
- {
- var stage = new ManufacturingTemplateStage
- {
- SequenceType = SequenceType.Link,
- Time = new TimeSpan(0, 0, 0),
- QualityChecks = "",
- Sequence = section.Sequence
- };
- stage.Section.ID = section.ID;
- stage.Section.Synchronise(section);
- stages.Add(stage);
- }
- var load = page.GetType().GetMethod("LoadItems");
- load.Invoke(page, new object[] { stages.ToArray() });
- }
- }
- return result;
- }
- }
- }
|