using HStation.WinFrmUI;
using System.ComponentModel;
using MessageBoxHelper = Yw.WinFrmUI.MessageBoxHelper;
namespace MFire.WinFrmUI
{
public partial class SelectCorprationListCtrl : DevExpress.XtraEditors.XtraUserControl
{
public SelectCorprationListCtrl()
{
InitializeComponent();
this.treeListLookUpEdit1TreeList.InitialDefaultSettings(25);
this.treeListLookUpEdit1TreeList.SelectImageList = svgImageTree;
this.treeListLookUpEdit1.EditValueChanged += treeListLookUpEdit1_EditValueChanged;
}
public class CurrentViewModel
{
public CurrentViewModel(Yw.Vmo.SysModuleVmo rhs)
{
this.ID = rhs.ID;
this.Name = rhs.Name;
this.SortCode = rhs.SortCode;
this.Description = rhs.Description;
}
public CurrentViewModel(Yw.Vmo.SysTypeVmo rhs)
{
this.ID = rhs.ID;
this.Name = rhs.Name;
this.SortCode = rhs.SortCode;
this.Description = rhs.Description;
this.ParentID = rhs.ModuleID;
}
///
/// UserID
///
public long ID { get; set; }
///
/// 父级ID
///
public long ParentID { get; set; }
///
/// 名称
///
public string Name { get; set; }
///
/// 排序码
///
public int SortCode { get; set; }
///
/// 说明
///
public string Description { get; set; }
}
///
/// 选择项变换
///
public event Action SelectedChangedEvent;
private BindingList _allBindingList { get; set; }
///
/// 绑定数据
///
public async void SetBindingData()
{
_allBindingList = new BindingList();
var alllist = await SysTypeHelper.GetSysTypeTreeList();
if (alllist == null)
return;
foreach (var item in alllist)
{
_allBindingList.Add(new CurrentViewModel(item.Module));
foreach (var child in item.Children)
{
_allBindingList.Add(new CurrentViewModel(child));
}
}
this.treeListLookUpEdit1TreeList.DataSource = _allBindingList;
this.treeListLookUpEdit1TreeList.ExpandAll();
if (_allBindingList.Count > 0)
{
var vm = _allBindingList.First();
this.treeListLookUpEdit1.EditValue = vm.ID;
SelectedChanged(vm);
}
}
//选择对象变换
private void SelectedChanged(CurrentViewModel vm)
{
if (SelectedChangedEvent != null)
{
SelectedChangedEvent.Invoke(vm.ID);
}
}
//值变换
private void treeListLookUpEdit1_EditValueChanged(object sender, EventArgs e)
{
var vm = this.treeListLookUpEdit1TreeList.GetCurrentViewModel(_allBindingList);
if (vm != null)
{
SelectedChanged(vm);
}
}
public long GetCurrentTypeID()
{
var vm = this.treeListLookUpEdit1TreeList.GetCurrentViewModel(_allBindingList);
if (vm == null)
{
MessageBoxHelper.ShowWarning("请选择数据行!");
return default;
}
return vm.ID;
}
}
}