namespace Yw.WinFrmUI
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public partial class SetParasGridCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public SetParasGridCtrl()
|
{
|
InitializeComponent();
|
this.gridView1.SetBindingLimitEditView();
|
}
|
|
private BindingList<ParasItemViewModel> _allBindingList = null;
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(Dictionary<string, string> dict)
|
{
|
_allBindingList = new BindingList<ParasItemViewModel>();
|
if (dict != null && dict.Count > 0)
|
{
|
foreach (var item in dict)
|
{
|
_allBindingList.Add(new ParasItemViewModel()
|
{
|
PropName = item.Key,
|
PropValue = item.Value
|
});
|
}
|
}
|
this.parasItemViewModelBindingSource1.DataSource = _allBindingList;
|
this.parasItemViewModelBindingSource1.ResetBindings(false);
|
}
|
|
/// <summary>
|
/// 获取参数
|
/// </summary>
|
public Dictionary<string, string> GetParas()
|
{
|
var dict = new Dictionary<string, string>();
|
if (_allBindingList != null && _allBindingList.Count > 0)
|
{
|
foreach (var item in _allBindingList)
|
{
|
if (!string.IsNullOrEmpty(item.PropName))
|
{
|
if (!dict.ContainsKey(item.PropName))
|
{
|
dict.Add(item.PropName, item.PropValue);
|
}
|
}
|
}
|
}
|
return dict;
|
}
|
|
//自定义下拉框
|
private void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
|
{
|
if (e.Column == this.colPropName)
|
{
|
|
}
|
}
|
|
//初始化
|
private void gridView1_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
|
{
|
if (_allBindingList == null)
|
{
|
return;
|
}
|
var row = this.gridView1.GetRow(e.RowHandle) as ParasItemViewModel;
|
if (row != null)
|
{
|
row.PropValue = string.Empty;
|
}
|
}
|
|
//编辑框显示
|
private void gridView1_ShowingEditor(object sender, CancelEventArgs e)
|
{
|
if (_allBindingList == null)
|
{
|
e.Cancel = true;
|
return;
|
}
|
var row = this.gridView1.GetFocusedRow() as ParasItemViewModel;
|
if (row == null)
|
{
|
var col = this.gridView1.FocusedColumn;
|
if (col != this.colPropName)
|
{
|
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 ParasItemViewModel;
|
if (row != null)
|
{
|
_allBindingList?.Remove(row);
|
}
|
}
|
}
|
|
//验证
|
private void gridView1_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
|
{
|
if (_allBindingList == null)
|
{
|
return;
|
}
|
var row = this.gridView1.GetFocusedRow() as ParasItemViewModel;
|
if (row != null)
|
{
|
var col = this.gridView1.FocusedColumn;
|
if (col == this.colPropName)
|
{
|
if (e.Value != null)
|
{
|
var propName = e.Value.ToString();
|
var count = _allBindingList.Count(x => x.PropName == propName && x != row);
|
if (count > 0)
|
{
|
e.Valid = false;
|
e.ErrorText = "重复";
|
}
|
}
|
}
|
}
|
|
}
|
|
|
}
|
}
|