using Autofac; using Bro.Common.Helper; using Bro.Common.Interface; using Bro.Common.Model; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace Bro.M071.Process { internal class KeyNameDictConverter : StringConverter { public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return true; } public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { using (var scope = GlobalVar.Container.BeginLifetimeScope()) { IProcessConfig iConfig = scope.Resolve(); if (iConfig is M071Config config) { return new StandardValuesCollection(config.KeyNameCollection); } } return base.GetStandardValues(context); ; } } internal class SnapshotPointConverter : ComboBoxItemTypeConvert { public override Hashtable GetConvertHash(ITypeDescriptorContext context) { Hashtable table = new Hashtable(); using (var scope = GlobalVar.Container.BeginLifetimeScope()) { IProcessConfig iConfig = scope.Resolve(); if (iConfig is M071Config config) { config.SnapshotPointCollection.ForEach(s => { table[s.Id] = s.Name; }); } } return table; } } internal class KeyAlgorithemConverter : ComboBoxItemTypeConvert { public override Hashtable GetConvertHash(ITypeDescriptorContext context) { Hashtable table = new Hashtable(); using (var scope = GlobalVar.Container.BeginLifetimeScope()) { IProcessConfig iConfig = scope.Resolve(); if (iConfig is M071Config config) { config.KeyAlgorithemCollection.ForEach(s => { table[s.Id] = s.Name; }); } } return table; } } internal class KeyResultConverter : ComboBoxItemTypeConvert { public override Hashtable GetConvertHash(ITypeDescriptorContext context) { Hashtable table = new Hashtable(); using (var scope = GlobalVar.Container.BeginLifetimeScope()) { IProcessConfig iConfig = scope.Resolve(); if (iConfig is M071Config config) { config.KeyResultCollection.ForEach(s => { table[s.Id] = s.Name; }); } } return table; } } //internal class KeyUnitConverter : ComboBoxItemTypeConvert //{ // public override Hashtable GetConvertHash(ITypeDescriptorContext context) // { // Hashtable table = new Hashtable(); // using (var scope = GlobalVar.Container.BeginLifetimeScope()) // { // IProcessConfig iConfig = scope.Resolve(); // if (iConfig is M071Config config) // { // config.KeyUnitCollection.ForEach(s => // { // table[s.Id] = s.Key; // }); // } // } // return table; // } //} internal class KeyUnitResultConverter : ComboBoxItemTypeConvert { public override Hashtable GetConvertHash(ITypeDescriptorContext context) { Hashtable table = new Hashtable(); using (var scope = GlobalVar.Container.BeginLifetimeScope()) { IProcessConfig iConfig = scope.Resolve(); if (iConfig is M071Config config) { var resultIds = config.KeyUnitCollection.Where(u => u.Key == (context.Instance as KeyUnitBind).Key).Select(u => u.KeyResult).ToList(); var result = config.KeyResultCollection.Where(u => resultIds.Contains(u.Id)).SelectMany(u => u.Results).ToList(); if (result != null && result.Count > 0) { result.ForEach(r => { table[r] = r; }); table[""] = ""; } } } return table; } } internal class MeasureTypeConverter : StringConverter { public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return true; } public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { using (var scope = GlobalVar.Container.BeginLifetimeScope()) { IProcessConfig iConfig = scope.Resolve(); if (iConfig is M071Config config) { return new StandardValuesCollection(config.MeasureSpecCollection.Select(u => u.Code).ToList()); } } return base.GetStandardValues(context); ; } } }