40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using CaeKnowledge.Data;
|
|
using LiteDB;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
|
|
namespace CaeKnowledge.View
|
|
{
|
|
internal class CutterConverter : StringConverter
|
|
{
|
|
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true;
|
|
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => true;
|
|
|
|
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
|
|
{
|
|
var items = new List<string>();
|
|
|
|
var fullPath = CaeGlobals.Tools.GetLiteDatabase();
|
|
|
|
if (fullPath == null || !File.Exists(fullPath))
|
|
{
|
|
return new StandardValuesCollection(items);
|
|
}
|
|
|
|
// Connect to LiteDB and fetch distinct values
|
|
using (var db = new LiteDatabase(fullPath))
|
|
{
|
|
var col = db.GetCollection<Cutter>("cutters");
|
|
|
|
if (col.Count() > 0)
|
|
{
|
|
items.AddRange(col.Query().OrderBy(x => x.Cid).Select(x => x.Cid).ToEnumerable());
|
|
}
|
|
}
|
|
|
|
return new StandardValuesCollection(items);
|
|
}
|
|
}
|
|
} |