namespace HStation.WinFrmUI.PhartRelation { /// /// /// public partial class XhsValveMainPhartListCtrl : XtraUserControl { public XhsValveMainPhartListCtrl() { InitializeComponent(); this.treeList1.InitialDefaultSettings(); this.treeList1.SelectImageList = ImageLib.Lib; this.layoutControl1.SetupLayoutControl(); } public class CurrentViewModel { public CurrentViewModel() { } public CurrentViewModel(Vmo.XhsValveMainPhartMappingExtensions model) { this.ID = model.ID; this.Name = model.OtherName; this.Importance = model.Importance; this.SortCode = model.SortCode; this.ImageIndex = ImageLib.Question; this.Model = model; } public long ID { get; set; } public string Name { get; set; } public int Importance { get; set; } public int SortCode { get; set; } public int ImageIndex { get; set; } public object Model { get; set; } } /// /// 聚焦改变事件 /// public event Action FocusedChangedEvent; private readonly Lazy _bll_ex = new (); private List _allBindingList = null;//所有绑定列表 /// /// 绑定数据 /// public void Clear() { _allBindingList = new List(); this.treeList1.DataSource = _allBindingList; this.FocusedChangedEvent?.Invoke(null); } /// /// 绑定数据 /// public async void SetBindingData(long valve_main_id) { WaitFormHelper.ShowWaitForm("正在加载数据..."); _allBindingList = new List(); var list = await _bll_ex.Value.GetByValveMainID(valve_main_id); if (list != null && list.Any()) { //list= list.OrderBy(x => x.Importance).ToList(); foreach (var item in list) { var vm = new CurrentViewModel(item); _allBindingList.Add(vm); } } this.treeList1.DataSource = _allBindingList; this.treeList1.ForceInitialize(); WaitFormHelper.HideWaitForm(); } /// /// 添加 /// public void Add(Vmo.XhsValveMainPhartMappingExtensions vmo) { if (vmo == null) return; var vm = new CurrentViewModel(vmo); _allBindingList.Add(vm); this.treeList1.RefreshDataSource(); } /// /// 删除 /// public void Delete(long id) { _allBindingList.RemoveAll(x => x.ID == id); this.treeList1.RefreshDataSource(); } /// /// 别名 /// public void UpdateOtherName(long id, string other_name) { var vmo = _allBindingList.Find(x => x.ID == id); if (vmo != null) { vmo.Name = other_name; (vmo.Model as Vmo.XhsValveMainPhartMappingExtensions).OtherName = other_name; this.treeList1.RefreshNode(this.treeList1.FocusedNode); } } /// /// 重要度 /// public void UpdateImportance(long id, int importance) { var vmo = _allBindingList.Find(x => x.ID == id); if (vmo != null) { vmo.Importance = importance; (vmo.Model as Vmo.XhsValveMainPhartMappingExtensions).Importance = importance; this.treeList1.RefreshNode(this.treeList1.FocusedNode); } } //聚焦改变 private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) { var vm = this.treeList1.GetCurrentViewModel(_allBindingList); if (vm == null) return; var vmo = vm.Model as Vmo.XhsValveMainPhartMappingExtensions; this.FocusedChangedEvent?.Invoke(vmo); } } }