using System;
|
using System.Collections.Generic;
|
using TProduct.Model;
|
|
namespace TProduct.WinFrmUI.Data4Factory
|
{
|
public partial class SelProductValveContentListCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public SelProductValveContentListCtrl()
|
{
|
InitializeComponent();
|
this.treeList1.SetTreeListColor();
|
this.layoutControl1.SetupLayoutControl();
|
this.treeList1.InitialMultiColSettings();
|
}
|
|
public event Action<Model.ProductMainExValve> SelectProductValveEvent = null;
|
public event Action<Model.ProductSeries> SelectProductSeriesEvent = null;
|
private List<CurrentViewModel> _bindList = null;
|
public class CurrentViewModel : Model.ProductMainExValve
|
{
|
public enum eObjectType
|
{
|
系列,
|
设备
|
}
|
|
public CurrentViewModel() { }
|
public CurrentViewModel(Model.ProductSeries rhs)
|
{
|
this.ParentID = -1;
|
this.ID = rhs.ID;
|
this.CreateUserID = rhs.CreateUserID;
|
this.CreateTime = rhs.CreateTime;
|
this.UpdateUserID = rhs.UpdateUserID;
|
this.UpdateTime = rhs.UpdateTime;
|
this.Code = rhs.Code;
|
this.Name = rhs.Name;
|
this.Model = rhs;
|
this.ObjectType = eObjectType.系列;
|
}
|
public CurrentViewModel(Model.ProductMainExValve rhs) : base(rhs)
|
{
|
this.ParentID = SeriesID;
|
this.ObjectType = eObjectType.设备;
|
this.strDia = rhs.Dia.ToString();
|
this.Model = rhs;
|
}
|
public CurrentViewModel(Model.ProductMainExValve rhs, RatedParas4Valve Valveparas) : base(rhs)
|
{
|
this.ParentID = SeriesID;
|
this.Model = rhs;
|
this.ObjectType = eObjectType.设备;
|
if (Valveparas.Dia > 0)
|
this.strDia = Valveparas.Dia.ToString();
|
}
|
public string strDia { get; set; }
|
public eObjectType ObjectType { get; set; }
|
public long ParentID { get; set; }
|
public object Model { get; set; }
|
public bool Selected { get; set; }
|
}
|
public void SetBindingData()
|
{
|
_bindList = new List<CurrentViewModel>();
|
|
var all = new Model.ProductSeries()
|
{
|
ID = -1,
|
Name = "全部",
|
};
|
_bindList.Add(new CurrentViewModel(all));
|
var seriesList = new BLL.ProductSeries().GetByProductType(Model.eProductType.Valve);
|
if (seriesList == null)
|
return;
|
seriesList?.ForEach(x => _bindList.Add(new CurrentViewModel(x)));
|
var productPumpList = new BLL.ProductValve().GetExAll();
|
if (productPumpList == null || productPumpList.Count < 1)
|
{
|
return;
|
}
|
foreach (var item in productPumpList)
|
{
|
if (!string.IsNullOrEmpty(item.RatedParas))
|
{
|
var paras = RatedParas4Valve.ToModel(item.RatedParas);
|
_bindList.Add(new CurrentViewModel(item, paras));
|
}
|
else
|
{
|
_bindList.Add(new CurrentViewModel(item));
|
}
|
}
|
|
this.bindingSource1.DataSource = _bindList;
|
this.bindingSource1.ResetBindings(false);
|
this.treeList1.ExpandAll();
|
|
}
|
public void SetFocused()
|
{
|
treeList1.FocusedNode = treeList1.Nodes.FirstNode;
|
}
|
private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
|
{
|
if (_bindList == null)
|
return;
|
var vm = this.treeList1.GetCurrentViewModel(this._bindList) as CurrentViewModel;
|
if (vm == null)
|
return;
|
if (vm.ObjectType == CurrentViewModel.eObjectType.系列)
|
this.SelectProductSeriesEvent?.Invoke(vm.Model as Model.ProductSeries);
|
if (vm.ObjectType == CurrentViewModel.eObjectType.设备)
|
this.SelectProductValveEvent?.Invoke(vm as Model.ProductMainExValve);
|
}
|
}
|
}
|