using Lskj.Business.Impl;
using Lskj.Control;
using Lskj.Control.Model;
using Lskj.Data;
using Lskj.Model;
using Lskj.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Lskj.Control
{
public partial class LabelAutoTextSearch : BaseUserControl
{
///
/// 绑定ValueMember
///
public string ValueMember
{
get { return txtEdit.ValueMember; }
set { txtEdit.ValueMember = value; }
}
///
/// 隐藏值字段
///
public string ValueField
{
get { return txtEdit.ValueField; }
set { txtEdit.ValueField = value; }
}
///
/// 显示值字段
///
public string TextField
{
get { return txtEdit.TextMember; }
set { txtEdit.TextMember = value; }
}
///
/// 自动搜索框控件
///
public AutoGridLookUp TextEdit { get { return txtEdit; } }
///
/// 文本
///
/// The label.
public Label Label { get { return lblText; } }
///
/// 数据源
///
/// The label.
public DataTable dataTable;
public LabelAutoTextSearch()
{
InitializeComponent();
//this.TextEdit.OnDisPopupEvent();//删除绑定点击事件
}
///
/// 字体大小
///
/// The size of the control.
public override float FontSize
{
get
{
return base.FontSize;
}
set
{
base.FontSize = value;
if (value > 0)
{
this.lblText.Font = new Font(this.lblText.Font.FontFamily, value);
this.TextEdit.Font = new Font(this.TextEdit.Font.FontFamily, value);
}
}
}
///
/// 说明:设置控件显示文本
/// 创建人:王一帆
/// 创建日期:2021-08-07
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// 显示Lebel文本
public override string LabelText
{
get
{
return this.lblText.Text;
}
set
{
this.lblText.Text = value;
this.plLeft.Width = this.lblText.Width + PaddingLeft;
}
}
///
/// 说明:设置控件值
/// 创建人:王一帆
/// 创建日期:2021-08-07
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
public override string EditText
{
get
{
return this.txtEdit.Text;
}
set
{
this.txtEdit.EditValue = value;
}
}
///
/// 获取隐藏值
///
/// The edit value.
public string EditValue
{
get
{
try
{
if (string.IsNullOrEmpty(this.txtEdit.EditValue + "") && this.txtEdit.DataSourceTable != null && this.txtEdit.DataSourceTable.Rows.Count > 0 && Model != null && !string.IsNullOrEmpty(this.txtEdit.Text))
{
DataRow[] dataRows = this.txtEdit.DataSourceTable.Select().Where(n => n[Model.TextMember].Equals(this.txtEdit.Text)).ToArray();
if (dataRows.Count() == 1)
{
return dataRows[0][Model.ValueMember] + "";
}
}
return this.txtEdit.EditValue + "";
}
catch (Exception)
{
return this.txtEdit.EditValue + "";
}
return this.txtEdit.EditValue + "";
}
}
///
/// 说明:设置控件提示文本
/// 创建人:王一帆
/// 创建日期:2021-08-07
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// 返回控件值
public override string NullText
{
get
{
return this.txtEdit.Properties.NullValuePrompt;
}
set
{
if (!string.IsNullOrEmpty(value))
{
this.TextEdit.Properties.NullValuePromptShowForEmptyValue = true;
this.TextEdit.Properties.NullValuePrompt = value;
}
base.NullText = value;
}
}
///
/// 只读文本颜色
///
/// The color of the read only label.
public override bool ReadOnly
{
get
{
return base.ReadOnly;
}
set
{
base.ReadOnly = value;
this.TextEdit.Properties.ReadOnly = value;
if (this.Model != null && !this.Model.IsSearchControl)
this.lblText.ForeColor = value ? base.ReadOnlyLabelForceColor : Required ? base.RequiredLabelForceColor : base.DefaultLabelForceColor;
}
}
///
/// 必填文本颜色
///
/// The color of the required label.
public override bool Required
{
get
{
return base.Required;
}
set
{
base.Required = value;
if (value)
{
this.lblText.ForeColor = base.RequiredLabelForceColor;
}
}
}
///
/// 说明:搜索返回ID需要单独验证是否修改
/// 创建人:王一帆
/// 创建日期:2021-11-08
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// true if this instance is update; otherwise, false.
public override bool IsUpdate()
{
return !this.Model.Text.Equals(this.EditValue, StringComparison.OrdinalIgnoreCase);
}
///
/// 说明:设置数据源
/// 创建人:王一帆
/// 创建日期:2021-02-26
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The data source.
public void SetDataSource(DataTable dataSource)
{
this.dataTable = dataSource;
this.txtEdit.DataSource = dataSource;
this.txtEdit.DataSourceTable = dataSource.Copy();
}
///
/// 说明:打开界面
/// 创建人:王一帆
/// 创建日期:2021-03-20
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
void OnMoreClick(object sender, EventArgs e)
{
this.txtEdit.OnAutoPopupShow();
}
}
}