508 lines
18 KiB
C#
508 lines
18 KiB
C#
/******************************
|
|
* 说明:自定义多选搜索框
|
|
* 创建人:龚宇超
|
|
* 创建日期: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;
|
|
|
|
namespace Lskj.Control
|
|
{
|
|
/// <summary>
|
|
/// 自定义多选搜索框
|
|
/// </summary>
|
|
public partial class LabelMultiAutoTextEdit : BaseUserControl
|
|
{
|
|
/// <summary>
|
|
/// The _look up form
|
|
/// </summary>
|
|
private FrmLookUp _lookUpForm = null;
|
|
/// <summary>
|
|
/// 绑定ValueMember
|
|
/// </summary>
|
|
public string ValueMember = string.Empty;
|
|
/// <summary>
|
|
/// 隐藏值字段
|
|
/// </summary>
|
|
public string ValueField = string.Empty;
|
|
/// <summary>
|
|
/// 显示值字段
|
|
/// </summary>
|
|
public string TextField = string.Empty;
|
|
/// <summary>
|
|
/// 备注字段
|
|
/// </summary>
|
|
public string RemarkField = string.Empty;
|
|
/// <summary>
|
|
/// 数据源SQL
|
|
/// </summary>
|
|
public string SourceSQL = string.Empty;
|
|
/// <summary>
|
|
/// The contro object
|
|
/// </summary>
|
|
public MyControl ControlObj;
|
|
/// <summary>
|
|
/// 文本
|
|
/// </summary>
|
|
/// <value>The label.</value>
|
|
public Label Label { get { return lblText; } }
|
|
/// <summary>
|
|
/// 自动搜索框控件
|
|
/// </summary>
|
|
public TextEdit TextEdit { get { return txtEdit; } }
|
|
/// <summary>
|
|
/// 文本禁编,但可以点击按钮
|
|
/// </summary>
|
|
public bool ProhibitInput;
|
|
/// <summary>
|
|
/// 初始赋值
|
|
/// </summary>
|
|
public string ControlValue = string.Empty;
|
|
/// <summary>
|
|
/// 保存表格属性用到的key
|
|
/// </summary>
|
|
public string CurrentOperColumnKey = string.Empty;
|
|
|
|
|
|
|
|
public LabelMultiAutoTextEdit()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:设置控件显示文本</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-08 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="text">显示Lebel文本</param>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 字体大小
|
|
/// </summary>
|
|
/// <value>The size of the control.</value>
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置控件值</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-08 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
public override string EditText
|
|
{
|
|
get
|
|
{
|
|
return this.txtEdit.Text;
|
|
}
|
|
set
|
|
{
|
|
//this.EditValue = value;
|
|
this.ControlValue = 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<DataRow>().FirstOrDefault(x => x[ValueMember] + "" == item);
|
|
if (rowItem == null)
|
|
{
|
|
rowItem = _lookUpForm.DataSource.Rows.Cast<DataRow>().FirstOrDefault(x => x[TextField] + "" == item);
|
|
}
|
|
if (rowItem != null)
|
|
{
|
|
text += rowItem[TextField] + ",";
|
|
}
|
|
}
|
|
this.txtEdit.Text = text;
|
|
}
|
|
else
|
|
{
|
|
this.txtEdit.Text = "";
|
|
if (_lookUpForm != null)
|
|
{
|
|
_lookUpForm.EditText = "";
|
|
_lookUpForm.EditValue = "";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置控件的实际值</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-09-13 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
public string EditValue
|
|
{
|
|
get
|
|
{
|
|
string value = Model.FieldType == ControlType.LabMultiSelectValue || Model.FieldType == ControlType.LabMultiSelectValueNew || Model.FieldType == ControlType.LabCheckMultiSelectValue || Model.FieldType == ControlType.LabMultiSelectValueParam ? _lookUpForm.EditValue : _lookUpForm.EditText;
|
|
|
|
//如果设置了初始值的清空下,点开弹窗清空后执行保存,之前的判断会把初始值重新返回出去保存 之前判断:string.IsNullOrEmpty(value)
|
|
if (value==null||(string.IsNullOrEmpty(value)&&!string.IsNullOrEmpty(this.txtEdit.Text)))
|
|
{
|
|
//直接点击保存时,弹出框里不会返回数据,直接用初始化时赋的值
|
|
value = ControlValue;
|
|
}
|
|
//string value = Model.FieldType == ControlType.LabMultiSelectValue || Model.FieldType == ControlType.LabCheckMultiSelectValue || Model.FieldType == ControlType.LabMultiSelectValueParam ? _lookUpForm.EditValue : _lookUpForm.EditText;
|
|
return value;
|
|
|
|
//string TextEdit = this.txtEdit.Text;
|
|
//string text = string.Empty;
|
|
//if (!string.IsNullOrEmpty(TextEdit) && _lookUpForm != null && _lookUpForm.DataSource != null)
|
|
//{
|
|
// string[] values = TextEdit.Trim(',').Split(',');
|
|
// foreach (string item in values)
|
|
// {
|
|
// DataRow rowItem = _lookUpForm.DataSource.Rows.Cast<DataRow>().FirstOrDefault(x => x[TextField] + "" == item);
|
|
// if (rowItem == null)
|
|
// {
|
|
// rowItem = _lookUpForm.DataSource.Rows.Cast<DataRow>().FirstOrDefault(x => x[ValueMember] + "" == item);
|
|
// }
|
|
// if (rowItem != null)
|
|
// {
|
|
// text += rowItem[ValueMember] + ",";
|
|
// }
|
|
// }
|
|
//}
|
|
//return text;
|
|
}
|
|
set
|
|
{
|
|
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<DataRow>().FirstOrDefault(x => x[TextField] + "" == item);
|
|
if (rowItem == null)
|
|
{
|
|
rowItem = _lookUpForm.DataSource.Rows.Cast<DataRow>().FirstOrDefault(x => x[ValueMember] + "" == item);
|
|
}
|
|
if (rowItem != null)
|
|
{
|
|
text += rowItem[ValueMember] + ",";
|
|
}
|
|
}
|
|
this.txtEdit.EditValue = text;
|
|
}
|
|
else
|
|
{
|
|
this.txtEdit.EditValue = "";
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置控件提示文本</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-08 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <returns>返回控件值</returns>
|
|
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;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 文本禁编,但可以点击按钮
|
|
/// </summary>
|
|
public bool TextBoxProhibition
|
|
{
|
|
get
|
|
{
|
|
return this.ProhibitInput;
|
|
}
|
|
set
|
|
{
|
|
this.ProhibitInput = value;
|
|
this.txtEdit.Properties.ReadOnly = value;
|
|
this.lblText.ForeColor = value ? base.ReadOnlyLabelForceColor : Required ? base.RequiredLabelForceColor : base.DefaultLabelForceColor;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 只读文本颜色
|
|
/// </summary>
|
|
/// <value>The color of the read only label.</value>
|
|
public override bool ReadOnly
|
|
{
|
|
get
|
|
{
|
|
return base.ReadOnly;
|
|
}
|
|
set
|
|
{
|
|
base.ReadOnly = value;
|
|
this.txtEdit.Properties.ReadOnly = value || this.ProhibitInput;
|
|
this.lblText.ForeColor = value || this.ProhibitInput ? base.ReadOnlyLabelForceColor : Required ? base.RequiredLabelForceColor : base.DefaultLabelForceColor;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 必填文本颜色
|
|
/// </summary>
|
|
/// <value>The color of the required label.</value>
|
|
public override bool Required
|
|
{
|
|
get
|
|
{
|
|
return base.Required;
|
|
}
|
|
set
|
|
{
|
|
base.Required = value;
|
|
if (value)
|
|
{
|
|
this.lblText.ForeColor = base.RequiredLabelForceColor;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:需要单独验证是否修改</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-11-08 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <returns><c>true</c> if this instance is update; otherwise, <c>false</c>.</returns>
|
|
public override bool IsUpdate()
|
|
{
|
|
if (Model.FieldType == ControlType.LabMultiSelectValue ||
|
|
Model.FieldType == ControlType.LabMultiSelectValueNew ||
|
|
Model.FieldType == ControlType.LabMultiSelectValueParam)
|
|
{
|
|
return !this.Model.Text.Equals(this.EditValue, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
else
|
|
{
|
|
return base.IsUpdate();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置数据源</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-08 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="dataSource">数据源</param>
|
|
public void SetDataSource(DataTable dataSource)
|
|
{
|
|
_lookUpForm = new FrmLookUp();
|
|
_lookUpForm.ValueField = ValueField;
|
|
_lookUpForm.ValueMember = ValueMember;
|
|
_lookUpForm.TextField = TextField;
|
|
_lookUpForm.SourceSQL = SourceSQL;
|
|
_lookUpForm.DataSource = dataSource;
|
|
_lookUpForm.CurrentOperColumnKey = CurrentOperColumnKey;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:清空选中的值</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-08-24 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
public void ClearSelectForm()
|
|
{
|
|
_lookUpForm.ClearSelect();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:打开界面</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-20 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void btnMore_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (this.ReadOnly)
|
|
{
|
|
//只读状态,点击按钮无效
|
|
return;
|
|
}
|
|
if (_lookUpForm != null)
|
|
{
|
|
_lookUpForm.EditValue = this.EditValue;
|
|
_lookUpForm.IsType = Model.FieldType;
|
|
_lookUpForm.EditText = this.TextEdit.Text;
|
|
_lookUpForm.CurrentOperColumnKey = CurrentOperColumnKey;
|
|
string sqlValue = string.Empty;
|
|
if (this.ControlObj != null)
|
|
{
|
|
sqlValue = this.ControlObj.ReplaceControlValue(Model.SourceSql);
|
|
sqlValue = sqlValue.Replace("#", "");
|
|
_lookUpForm.DataSource = MainImpl.GetDataTableResult(sqlValue);
|
|
}
|
|
|
|
DialogResult result = _lookUpForm.ShowDialog();
|
|
if (result == DialogResult.OK)
|
|
{
|
|
string value = Model.FieldType == ControlType.LabMultiSelectValue || Model.FieldType == ControlType.LabMultiSelectValueNew || Model.FieldType == ControlType.LabCheckMultiSelectValue || Model.FieldType == ControlType.LabMultiSelectValueParam ? _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);
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 背景颜色
|
|
/// </summary>
|
|
/// <value>The color of the required label.</value>
|
|
public override Color BackgroundColor
|
|
{
|
|
get
|
|
{
|
|
return TextEdit.Properties.Appearance.BackColor;
|
|
}
|
|
set
|
|
{
|
|
TextEdit.Properties.Appearance.BackColor = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 前景颜色
|
|
/// </summary>
|
|
/// <value>The color of the required label.</value>
|
|
public override Color ForeColor
|
|
{
|
|
get
|
|
{
|
|
return TextEdit.Properties.Appearance.ForeColor;
|
|
}
|
|
set
|
|
{
|
|
TextEdit.Properties.Appearance.ForeColor = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 内容加粗
|
|
/// </summary>
|
|
/// <value>The color of the required label.</value>
|
|
public override bool ContentBold
|
|
{
|
|
get
|
|
{
|
|
return TextEdit.Properties.Appearance.Font.Bold;
|
|
}
|
|
set
|
|
{
|
|
Font oldFont = TextEdit.Properties.Appearance.Font;
|
|
TextEdit.Properties.Appearance.Font = new Font(oldFont.FontFamily, oldFont.Size, value ? FontStyle.Bold : FontStyle.Regular);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|