using DevExpress.XtraEditors.Repository;
|
|
namespace Yw.WinFrmUI
|
{
|
public partial class SetHydroEvaluationModelCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public SetHydroEvaluationModelCtrl()
|
{
|
InitializeComponent();
|
this.gridView1.SetBindingLimitEditView();
|
}
|
|
private long _modelId;//模型id
|
private string _catalog;//分类
|
private List<SetHydroEvaluationModelViewModel> _allList = null;
|
private BindingList<SetHydroEvaluationModelViewModel> _allBindingList = null;
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public void InitialData(List<Yw.Vmo.HydroEvaluationVmo> allList)
|
{
|
_allList = new List<SetHydroEvaluationModelViewModel>();
|
allList?.ForEach(x =>
|
{
|
_allList.Add(new SetHydroEvaluationModelViewModel(x));
|
});
|
}
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(long modelId, string catalog)
|
{
|
_modelId = modelId;
|
_catalog = catalog;
|
_allBindingList = new BindingList<SetHydroEvaluationModelViewModel>();
|
var list = _allList?.Where(x => x.ModelID == modelId && x.Catalog == catalog).OrderBy(x => x.SortCode).ToList();
|
list?.ForEach(x =>
|
{
|
_allBindingList.Add(x);
|
});
|
this.setHydroEvaluationModelViewModelBindingSource.DataSource = _allBindingList;
|
this.setHydroEvaluationModelViewModelBindingSource.ResetBindings(false);
|
}
|
|
/// <summary>
|
/// 获取评价
|
/// </summary>
|
public List<Yw.Vmo.HydroEvaluationVmo> GetEvaluation()
|
{
|
var list = new List<Yw.Vmo.HydroEvaluationVmo>();
|
_allList?.ForEach(x =>
|
{
|
var vmo = new Yw.Vmo.HydroEvaluationVmo()
|
{
|
ID = x.ID,
|
ModelID = x.ModelID,
|
Catalog = x.Catalog,
|
EvaluateType = x.EvaluateType,
|
EvaluateLower = x.EvaluateLower,
|
EvaluateUpper = x.EvaluateUpper,
|
EvaluateContent = x.EvaluateContent,
|
SortCode = x.SortCode,
|
Description = x.Description
|
};
|
list.Add(vmo);
|
});
|
return list;
|
}
|
|
//自定义下拉框
|
private void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
|
{
|
if (e.Column == this.colEvaluateType)
|
{
|
var dict = HydroEvaluationTypeHelper.GetDict(_catalog);
|
if (dict != null && dict.Count > 0)
|
{
|
var repositoryItem = new RepositoryItemImageComboBox();
|
foreach (var item in dict)
|
{
|
repositoryItem.Items.Add(item.Value, item.Key, -1);
|
}
|
e.RepositoryItem = repositoryItem;
|
}
|
}
|
}
|
|
//初始化
|
private void gridView1_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
|
{
|
var row = this.gridView1.GetRow(e.RowHandle) as SetHydroEvaluationModelViewModel;
|
if (row != null)
|
{
|
row.ModelID = _modelId;
|
row.Catalog = _catalog;
|
row.SortCode = _allBindingList == null || _allBindingList.Count < 1 ? 1 : _allBindingList.Max(x => x.SortCode) + 1;
|
_allList.Add(row);
|
}
|
}
|
|
//编辑框显示
|
private void gridView1_ShowingEditor(object sender, CancelEventArgs e)
|
{
|
if (_allBindingList == null)
|
{
|
e.Cancel = true;
|
return;
|
}
|
var row = this.gridView1.GetFocusedRow() as SetHydroEvaluationModelViewModel;
|
if (row == null)
|
{
|
var col = this.gridView1.FocusedColumn;
|
if (col != this.colEvaluateType)
|
{
|
e.Cancel = true;
|
return;
|
}
|
}
|
}
|
|
//删除
|
private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
|
{
|
if (e.Column == this.colDelete)
|
{
|
var row = this.gridView1.GetRow(e.RowHandle) as SetHydroEvaluationModelViewModel;
|
if (row != null)
|
{
|
_allBindingList?.Remove(row);
|
_allList?.Remove(row);
|
}
|
}
|
}
|
|
|
}
|
}
|