#region
|
|
using System;
|
using System.Data;
|
using System.Windows.Forms;
|
using DevExpress.XtraEditors;
|
using DevExpress.XtraGrid.Columns;
|
using DevExpress.XtraGrid.Views.Grid;
|
|
#endregion
|
|
namespace CSFrameworkV5.Library.UserControls
|
{
|
/// <summary>
|
/// 应用CodeNamePicker组件,查询数据的事件
|
/// </summary>
|
/// <param name="code">编号</param>
|
/// <param name="name">名称</param>
|
/// <returns></returns>
|
public delegate DataTable OnShowFiltredData(string code, string name);
|
|
/// <summary>
|
/// 标准编号名称选择框
|
/// </summary>
|
public partial class ucCodeNamePicker : UserControl
|
{
|
private EventHandler _OnClear;
|
|
private LookupEditorPopupControlClick _OnRowClick;
|
|
private OnShowFiltredData _OnShowFiltredData;
|
|
private bool _ShowClear;
|
|
public ucCodeNamePicker()
|
{
|
InitializeComponent();
|
}
|
|
public PopupContainerControl PopupContainer => popupContainerControl1;
|
|
public bool ShowClear
|
{
|
set => _ShowClear = value;
|
get => _ShowClear;
|
}
|
|
private void btnClose_Click(object sender, EventArgs e)
|
{
|
if (_OnClear != null)
|
{
|
_OnClear(sender, e);
|
txt_Code.Text = "";
|
txt_Name.Text = "";
|
}
|
}
|
|
public void DoAddColumn(string fieldName, string caption, int width)
|
{
|
var col = new GridColumn();
|
col.FieldName = fieldName;
|
col.Name = "col" + fieldName;
|
col.Width = width;
|
col.Caption = caption;
|
col.Visible = true;
|
col.VisibleIndex = gvSummary.Columns.Count;
|
gvSummary.Columns.Add(col);
|
}
|
|
public void DoSetCaption(string code, string name)
|
{
|
colID.Caption = code;
|
colName.Caption = name;
|
}
|
|
public void DoSetEditorCaption(string code, string name)
|
{
|
lbCode.Text = code;
|
lbName.Text = name;
|
}
|
|
public void DoSetField(string codeField, string nameField)
|
{
|
colID.FieldName = codeField;
|
colName.FieldName = nameField;
|
}
|
|
public void DoSetSize(int height)
|
{
|
var i = 0;
|
foreach (GridColumn c in gvSummary.Columns) i += c.Width;
|
|
if (i + 50 < 300)
|
Width = 300;
|
else
|
Width = i + 50;
|
|
Height = height;
|
}
|
|
public void DoShowDefaultData(DataTable source)
|
{
|
gcSummary.DataSource = source;
|
gcSummary.RefreshDataSource();
|
}
|
|
private void DoShowFiltredData()
|
{
|
if (_OnShowFiltredData != null)
|
{
|
var dt = _OnShowFiltredData(txt_Code.Text, txt_Name.Text);
|
gcSummary.DataSource = null;
|
gcSummary.DataSource = dt;
|
gcSummary.RefreshDataSource();
|
}
|
}
|
|
private void gvSummary_RowClick(object sender, RowClickEventArgs e)
|
{
|
if (_OnRowClick != null)
|
{
|
popupContainerControl1.Hide();
|
_OnRowClick(gvSummary.GetDataRow(gvSummary.FocusedRowHandle));
|
txt_Code.Text = "";
|
txt_Name.Text = "";
|
}
|
}
|
|
public event EventHandler OnClear
|
{
|
add => _OnClear = value;
|
remove => _OnClear = null;
|
}
|
|
public event LookupEditorPopupControlClick OnRowClick
|
{
|
add => _OnRowClick = value;
|
remove => _OnRowClick = null;
|
}
|
|
public event OnShowFiltredData OnShowFiltredData
|
{
|
add => _OnShowFiltredData = value;
|
remove => _OnShowFiltredData = null;
|
}
|
|
private void txt_Code_EditValueChanged(object sender, EventArgs e)
|
{
|
DoShowFiltredData();
|
}
|
|
private void txt_Name_EditValueChanged(object sender, EventArgs e)
|
{
|
DoShowFiltredData();
|
}
|
|
private void ucCodeNamePicker_Load(object sender, EventArgs e)
|
{
|
btnClear.Visible = _ShowClear;
|
}
|
}
|
}
|