/******************************
* 说明:自定义多选搜索框
* 创建人:龚宇超
* 创建日期:2017-08-08
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
******************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors;
using Lskj.Data;
using Lskj.Control.Model;
using Lskj.Control.MultiGridLookUp;
using Lskj.Business.Impl;
using Lskj.Util;
using Lskj.Control.MultiModelLookUp;
namespace Lskj.Control
{
///
/// 自定义多选搜索框
///
public partial class LabelMultiAutoTextEdit2 : BaseUserControl
{
///
/// The _look up form
///
private FrmModelLookUp _lookUpForm = null;
///
/// 绑定ValueMember
///
public string ValueMember = string.Empty;
///
/// 隐藏值字段
///
public string ValueField = string.Empty;
///
/// 显示值字段
///
public string TextField = string.Empty;
///
/// 备注字段
///
public string RemarkField = string.Empty;
///
/// 数据源SQL
///
public string SourceSQL = string.Empty;
///
/// 隐藏值
///
public string EditValue = string.Empty;
///
/// The contro object
///
public MyControl ControlObj;
///
/// 文本
///
/// The label.
public Label Label { get { return lblText; } }
///
/// 自动搜索框控件
///
public TextEdit TextEdit { get { return txtEdit; } }
///
/// 配置的关联ModuleCodel值
///
/// The Union ModuleCodel.
public string UnionModuleCodel;
public LabelMultiAutoTextEdit2()
{
InitializeComponent();
}
///
/// 说明:设置控件显示文本
/// 创建人:龚宇超
/// 创建日期:2017-08-08
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// 显示Lebel文本
public override string LabelText
{
get
{
return this.lblText.Text;
}
set
{
this.lblText.Text = value;
if (FontSize > 0)
{
this.plLeft.Dock = DockStyle.Left;
this.plLeft.AutoSize = false;
this.lblText.AutoSize = false;
this.lblText.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblText.Location = new System.Drawing.Point(0, 0);
this.lblText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.txtEdit.Properties.AutoHeight = false;
this.plLeft.Width = value.Length * GetCharWidth();
GetCharWidthMultilingual(this.lblText, this.lblText.Text, this.plLeft);
}
else
{
this.plLeft.Width = this.lblText.Width + PaddingLeft;
}
}
}
///
/// 字体大小
///
/// 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);
}
}
}
///
/// 说明:设置控件值
/// 创建人:龚宇超
/// 创建日期:2017-08-08
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
public override string EditText
{
get
{
return this.txtEdit.Text;
}
set
{
this.EditValue = value;
if (!string.IsNullOrEmpty(value) && _lookUpForm != null && _lookUpForm.DataSource != null)
{
string[] values = value.Trim(',').Split(',');
string text = string.Empty;
foreach (string item in values)
{
DataRow rowItem = _lookUpForm.DataSource.Rows.Cast().FirstOrDefault(x => x[ValueMember] + "" == item);
if (rowItem != null)
{
text += rowItem[TextField] + ",";
}
}
this.txtEdit.Text = text;
}
else
{
this.txtEdit.Text = "";
}
}
}
///
/// 说明:设置控件提示文本
/// 创建人:龚宇超
/// 创建日期:2017-08-08
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本: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.txtEdit.Properties.ReadOnly = value;
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;
}
}
}
///
/// 说明:需要单独验证是否修改
/// 创建人:龚宇超
/// 创建日期:2017-11-08
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// true if this instance is update; otherwise, false.
public override bool IsUpdate()
{
if (Model.FieldType == ControlType.LabMultiSelectValue ||
Model.FieldType == ControlType.LabMultiSelectValueParam)
{
return !this.Model.Text.Equals(this.EditValue, StringComparison.OrdinalIgnoreCase);
}
else
{
return base.IsUpdate();
}
}
///
/// 说明:设置数据源
/// 创建人:龚宇超
/// 创建日期:2017-08-08
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// 数据源
public void SetDataSource(DataTable dataSource)
{
_lookUpForm = new FrmModelLookUp(UnionModuleCodel);
_lookUpForm.ValueField = ValueField;
_lookUpForm.ValueMember = ValueMember;
_lookUpForm.TextField = TextField;
_lookUpForm.SourceSQL = SourceSQL;
_lookUpForm.DataSource = dataSource;
}
///
/// 说明:清空选中的值
/// 创建人:龚宇超
/// 创建日期:2018-08-24
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
public void ClearSelectForm()
{
// _lookUpForm.ClearSelect();
}
///
/// 说明:打开界面
/// 创建人:龚宇超
/// 创建日期:2018-03-20
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void btnMore_Click(object sender, EventArgs e)
{
try
{
//_lookUpForm = new FrmModelLookUp();
//_lookUpForm.ValueField = ValueField;
//_lookUpForm.ValueMember = ValueMember;
//_lookUpForm.TextField = TextField;
//_lookUpForm.SourceSQL = Model.SourceSql;
//_lookUpForm.UnionModuleCodel = UnionModuleCodel;
//_lookUpForm.EditValue = this.EditValue;
//_lookUpForm.IsType = Model.FieldType;
//_lookUpForm.EditText = this.TextEdit.Text;
//_lookUpForm.DataSource = BaseImpl.GetDataTableResult(_lookUpForm.SourceSQL);
if (_lookUpForm != null)
{
if (_lookUpForm != null)
{
_lookUpForm.EditValue = this.EditValue;
_lookUpForm.IsType = Model.FieldType;
_lookUpForm.EditText = this.TextEdit.Text;
}
string sqlValue = string.Empty;
if (this.ControlObj != null)
{
sqlValue = this.ControlObj.ReplaceControlValue(Model.SourceSql);
sqlValue = sqlValue.Replace("#", "");
_lookUpForm.SourceSQL = sqlValue;
//_lookUpForm.DataSource = MainImpl.GetDataTableResult(sqlValue);
}
_lookUpForm.InitControls(UnionModuleCodel);
DialogResult result = _lookUpForm.ShowDialog();
if (result == DialogResult.OK)
{
string value = Model.FieldType == ControlType.LabSelectReturnId ? _lookUpForm.EditValue : _lookUpForm.EditText;
this.EditValue = value;
this.TextEdit.Text = _lookUpForm.EditText;
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message,ex.Message);
}
}
}
}