using DevExpress.XtraEditors;
|
using DevExpress.XtraEditors.Controls;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Drawing.Design;
|
using System.IO;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
using System.Windows.Forms.Design;
|
|
namespace Hydro.MapView
|
{
|
public class DlTemplateEditor : UITypeEditor
|
{
|
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
|
{
|
return UITypeEditorEditStyle.DropDown;
|
}
|
|
public static ImageComboBoxEdit ImageComboBoxEdit = null;
|
|
public override object EditValue(ITypeDescriptorContext context, IServiceProvider serviceProvider, object value)
|
{
|
ImageComboBoxEdit = new ImageComboBoxEdit();
|
if (context != null && serviceProvider != null)
|
{
|
IWindowsFormsEditorService editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
|
|
if (editorService != null)
|
{
|
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "Data\\WaterEquivalent.Json");
|
if (File.Exists(filePath))
|
{
|
var json = File.ReadAllText(filePath);
|
if (!string.IsNullOrEmpty(json))
|
{
|
var w = JsonConvert.DeserializeObject<List<EquivalentTemplateModel>>(json);
|
if (w != null)
|
{
|
foreach (var item in w)
|
{
|
var imageItem = new ImageComboBoxItem(item.Name, item.ID);
|
ImageComboBoxEdit.Properties.Items.Add(imageItem);
|
}
|
}
|
editorService.DropDownControl(ImageComboBoxEdit);
|
}
|
}
|
value = ImageComboBoxEdit.Text;
|
}
|
}
|
return value;
|
}
|
}
|
}
|