using System;
|
using System.Collections.Generic;
|
using TProduct.Model;
|
|
namespace TProduct.WinFrmUI.Data4Factory
|
{
|
public partial class SelProductPumpContentListCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public SelProductPumpContentListCtrl()
|
{
|
InitializeComponent();
|
this.treeList1.SetTreeListColor();
|
this.layoutControl1.SetupLayoutControl();
|
this.treeList1.InitialMultiColSettings();
|
}
|
|
public event Action<Model.ProductMainExPump> SelectProductPumpChanedEvent = null;
|
public event Action<Model.ProductSeries> SelectProductSeriesChanedEvent = null;
|
private List<CurrentViewModel> _bindList = null;
|
public class CurrentViewModel : Model.ProductMainExPump
|
{
|
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.ObjectType = eObjectType.系列;
|
this.Model = rhs;
|
this.ProductStyleID = rhs.ProductStyleID;
|
}
|
public CurrentViewModel(Model.ProductMainExPump rhs) : base(rhs)
|
{
|
this.ParentID = SeriesID;
|
}
|
public CurrentViewModel(Model.ProductMainExPump rhs, RatedParas4Pump pumpparas) : base(rhs)
|
{
|
this.ParentID = rhs.SeriesID;
|
if (pumpparas.Q > 0)
|
this.Q = pumpparas.Q.ToString();
|
if (pumpparas.Q < 0)
|
this.Q = "";
|
if (pumpparas.H > 0)
|
this.H = pumpparas.H.ToString();
|
if (pumpparas.H < 0)
|
this.H = "";
|
if (rhs.Ratedn > 0)
|
this.N = rhs.Ratedn.ToString();
|
if (rhs.Ratedn < 0)
|
this.N = "";
|
this.Model = rhs;
|
this.ObjectType = eObjectType.设备;
|
}
|
public long ParentID { get; set; }
|
public string Q { get; set; }
|
public string H { get; set; }
|
public string N { get; set; }
|
public eObjectType ObjectType { get; set; }
|
public object Model { get; set; }
|
public long ProductStyleID { get; set; }
|
}
|
public void SetBindingData()
|
{
|
_bindList = new List<CurrentViewModel>();
|
var series = new BLL.ProductSeries().GetByProductType(Model.eProductType.Pump);
|
series?.ForEach(x => _bindList.Add(new CurrentViewModel(x)));
|
var productPumpList = new BLL.ProductPump().GetExAll();
|
if (productPumpList == null || productPumpList.Count < 1)
|
{
|
return;
|
}
|
var all = new Model.ProductSeries()
|
{
|
ID = -1,
|
Name = "全部",
|
};
|
_bindList.Add(new CurrentViewModel(all));
|
foreach (var item in productPumpList)
|
{
|
if (!string.IsNullOrEmpty(item.RatedParas))
|
{
|
var paras = RatedParas4Pump.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.SelectProductSeriesChanedEvent?.Invoke(vm.Model as Model.ProductSeries);
|
if (vm.ObjectType == CurrentViewModel.eObjectType.设备)
|
this.SelectProductPumpChanedEvent?.Invoke(vm.Model as Model.ProductMainExPump);
|
}
|
}
|
}
|