using System.ComponentModel;
|
using Yw.Dto;
|
|
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.SysTypeLogicalTreeVmo rhs)
|
{
|
var module = rhs.LogicalModel as Yw.Dto.SysModuleStdDto;
|
this.ID = module.ID;
|
this.Name = module.Name;
|
this.SortCode = module.SortCode;
|
this.Description = module.Description;
|
}
|
|
public CurrentViewModel(SysTypeStdDto rhs)
|
{
|
this.ID = rhs.ID;
|
this.Name = rhs.Name;
|
this.SortCode = rhs.SortCode;
|
this.Description = rhs.Description;
|
this.ParentID = rhs.ModuleID;
|
}
|
|
/// <summary>
|
/// UserID
|
/// </summary>
|
public long ID { get; set; }
|
|
/// <summary>
|
/// 父级ID
|
/// </summary>
|
public long ParentID { get; set; }
|
|
/// <summary>
|
/// 名称
|
/// </summary>
|
public string Name { get; set; }
|
|
/// <summary>
|
/// 排序码
|
/// </summary>
|
public int SortCode { get; set; }
|
|
/// <summary>
|
/// 说明
|
/// </summary>
|
public string Description { get; set; }
|
}
|
|
private Yw.BLL.SysTypeStd _bll = null;
|
|
/// <summary>
|
/// 选择项变换
|
/// </summary>
|
public event Action<long> SelectedChangedEvent;
|
|
private BindingList<CurrentViewModel> _allBindingList { get; set; }
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public async void SetBindingData()
|
{
|
_bll = new Yw.BLL.SysTypeStd();
|
_allBindingList = new BindingList<CurrentViewModel>();
|
var alllist = await _bll.GetExtendLogicalTreeList();
|
if (alllist == null)
|
return;
|
foreach (var item in alllist)
|
{
|
_allBindingList.Add(new CurrentViewModel(item));
|
foreach (var child in item.Children)
|
{
|
var type = child.LogicalModel as Yw.Dto.SysTypeStdDto;
|
if (type != null)
|
{
|
_allBindingList.Add(new CurrentViewModel(type));
|
}
|
}
|
}
|
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;
|
}
|
}
|
}
|