using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Drawing;
|
using System.Data;
|
using System.Text;
|
using System.Windows.Forms;
|
using DevExpress.XtraEditors;
|
using GSBase.BaseFrom;
|
|
namespace GSBase.Control
|
{/// <summary>
|
/// 高级按钮文本框
|
/// </summary>
|
public partial class AdvButtonText : UserControl
|
{
|
//public bool ChangeTextLeft
|
/// <summary>
|
///标签标题;
|
/// </summary>
|
public SelectQueryDlg SelectItemDlg;
|
[Category("扩展功能"), Description("标题内容"), DefaultValue("Caption")]
|
public string Caption
|
{
|
get { return lbCaption.Text; }
|
set
|
{
|
if (lbCaption.Text != value)
|
{
|
//int oldwith = lbCaption.Size.Width;
|
lbCaption.Text = value;
|
//int newwith = lbCaption.Size.Width;
|
|
//textEdit.Location = new Point(textEdit.Location.X + (newwith - oldwith), textEdit.Location.Y);
|
//btnButton.Location = new Point(btnButton.Location.X + (newwith - oldwith), btnButton.Location.Y);
|
//lbRemark.Location = new Point(lbRemark.Location.X + (newwith - oldwith), lbRemark.Location.Y);
|
}
|
// this.Refresh();
|
}
|
}
|
private string captionT;
|
public string CaptionT
|
{
|
get { return captionT; }
|
set { captionT = value; }
|
}
|
|
/// <summary>
|
/// 标题
|
/// </summary>
|
[Category("扩展功能"), Description("文本底色")]
|
public Color TextBackColor
|
{
|
get { return textEdit.BackColor; }
|
set
|
{
|
textEdit.BackColor = value;
|
}
|
|
}
|
|
/// <summary>
|
/// 数据值
|
/// </summary>
|
[Category("扩展功能"), Description("只读模式")]
|
public bool ReadOnly
|
{
|
get { return !btnButton.Enabled; }
|
set
|
{
|
string s = this.Name;
|
btnButton.Enabled = !value;
|
textEdit.Properties.ReadOnly = value;
|
if (value && textEdit.BackColor == Color.White)
|
{
|
textEdit.Properties.AppearanceReadOnly.BackColor = Color.FromArgb(255, 247, 245, 241); //Color.WhiteSmoke;//
|
textEdit.Properties.AppearanceReadOnly.Options.UseBackColor = true;
|
}
|
}
|
}
|
/// <summary>
|
/// 数据值
|
/// </summary>
|
[Category("扩展功能"), Description("文本框内容")]
|
public string EditValue
|
{
|
get { return textEdit.Text; }
|
set
|
{
|
//这个如果不设置会引起列变化事件。
|
if (textEdit.Text == value)
|
return;
|
textEdit.Text = value;
|
}
|
}
|
|
/// <summary>
|
/// 备注字段
|
/// </summary>
|
[Category("扩展功能"), Description("备注内容")]
|
public string Remark
|
{
|
get { return lbRemark.Text; }
|
set
|
{
|
//这个如果不设置会引起列变化事件。
|
if (lbRemark.Text == value)
|
return;
|
|
lbRemark.Text = value;
|
}
|
}
|
/// <summary>
|
/// 是否验证
|
/// </summary>
|
private Boolean isValidated = true;
|
|
/// <summary>
|
/// 是否验证
|
/// </summary>
|
[Category("扩展功能"), Description("是否验证")]
|
public Boolean IsValidated
|
{
|
get { return isValidated; }
|
set { isValidated = value; }
|
}
|
|
/// <summary>
|
/// 显示类型
|
/// </summary>
|
private ShowStyle textType = ShowStyle.BeRemark;
|
|
/// <summary>
|
/// 控件类型,分别:非备注模式,备注模式,文本框模式
|
/// </summary>
|
/// <value>The type of the text.</value>
|
[Category("扩展功能"), Description("控件类型,分别:非备注模式,备注模式,文本框模式")]
|
public ShowStyle TextType
|
{
|
get { return textType; }
|
set
|
{
|
if (textType != value)
|
{
|
switch (value)
|
{
|
case ShowStyle.BeRemark:
|
lbRemark.Visible = true;
|
lbRemark.Text = "Remark";
|
btnButton.Visible = true;
|
break;
|
case ShowStyle.NoRemark:
|
lbRemark.Visible = false;
|
lbRemark.Text = "";
|
btnButton.Visible = true;
|
break;
|
case ShowStyle.BeText:
|
lbRemark.Visible = false;
|
lbRemark.Text = "";
|
btnButton.Visible = false;
|
break;
|
default:
|
MessageBox.Show("输入无效的值");
|
break;
|
}
|
}
|
textType = value;
|
}
|
}
|
|
/// <summary>
|
/// 风格
|
/// </summary>
|
[Category("扩展功能"), Description("风格")]
|
public IStyleController StyleController
|
{
|
get { return textEdit.StyleController; }
|
set { textEdit.StyleController = value; }
|
}
|
|
/// <summary>
|
/// 获取或设置一个值,该值指示控件是否可以对用户交互作出响应。
|
/// </summary>
|
/// <value></value>
|
/// <returns>
|
/// 如果控件可以对用户交互作出响应,则为 true;否则为 false。默认为 true。</returns>
|
/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
|
public new bool Enabled
|
{
|
get { return textEdit.Enabled; }
|
set
|
{
|
textEdit.Enabled = value;
|
btnButton.Enabled = value;
|
lbRemark.Enabled = value;
|
}
|
}
|
|
/// <summary>
|
/// DC编号
|
/// </summary>
|
private string datacatalogID;
|
|
/// <summary>
|
/// 数据目录编号DC
|
/// </summary>
|
/// <value>The datacatalog ID.</value>
|
[Category("扩展功能"), Description("数据目录编号,如ADMDAA-01")]
|
public string DatacatalogID
|
{
|
get { return datacatalogID; }
|
set { datacatalogID = value; }
|
}
|
|
private string textField = string.Empty;
|
|
/// <summary>
|
/// 文本字段
|
/// </summary>
|
[Category("扩展功能"), Description("控件文本框对应的DC中字段,如DAA002")]
|
public string TextField
|
{
|
get
|
{
|
|
if (textField == null)
|
return string.Empty;
|
else
|
return textField.Trim();
|
}
|
set { textField = value; }
|
}
|
|
private string remarkField = string.Empty;
|
|
/// <summary>
|
/// 备注字段名
|
/// </summary>
|
[Category("扩展功能"), Description("对应DC中的字段,例如选择单别时会带出单据简称。如DAA002")]
|
public string RemarkField
|
{
|
get
|
{
|
if (remarkField == null)
|
return string.Empty;
|
else
|
return remarkField.Trim();
|
}
|
set { remarkField = value; }
|
}
|
|
private string _RemarkBindField = string.Empty;
|
/// <summary>
|
/// 备注绑定字段
|
/// </summary>
|
[Category("扩展功能"), Description("对应当前数据表中的字段。")]
|
public string RemarkBindField
|
{
|
get
|
{
|
if (_RemarkBindField == null)
|
return string.Empty;
|
else
|
return _RemarkBindField.Trim();
|
}
|
set { _RemarkBindField = value; }
|
}
|
|
/// <summary>
|
/// 映射关系
|
/// </summary>
|
private string otherMapping;
|
|
/// <summary>
|
/// 设置或获取其他映射关系
|
/// </summary>
|
/// <value>The mapping.</value>
|
[Category("扩展功能"), Description("其他关系字段映射关系统(用分号隔开):[控件.Text]=DAA001;[控件.Text]=DAA002")]
|
public string OtherMapping
|
{
|
get
|
{
|
if (otherMapping == null)
|
return string.Empty;
|
else
|
return otherMapping.Trim();
|
}
|
set { otherMapping = value; }
|
}
|
|
/// <summary>
|
/// 条件筛选
|
/// </summary>
|
private string filter;
|
|
/// <summary>
|
/// 获取或设置筛选条件
|
/// </summary>
|
/// <value>The filter.</value>
|
[Category("扩展功能"), Description("筛选条件(也可写固定条件).字段编号=[控件.属性] 如:DAA004='8032'AND DAA005=[控件2.Text]")]
|
public string Filter
|
{
|
get { return filter; }
|
set { filter = value; }
|
}
|
|
/// <summary>
|
/// 文体大小
|
/// </summary>
|
[Category("扩展功能"), Description("文本框大小")]
|
public Size TextSize
|
{
|
get { return textEdit.Size; }
|
set
|
{
|
if (textEdit.Size != value)
|
{
|
int oldwith = textEdit.Size.Width;
|
textEdit.Size = value;
|
int newwith = textEdit.Size.Width;
|
|
btnButton.Location = new Point(btnButton.Location.X + (newwith - oldwith), btnButton.Location.Y);
|
lbRemark.Location = new Point(lbRemark.Location.X + (newwith - oldwith), lbRemark.Location.Y);
|
}
|
this.Refresh();
|
}
|
}
|
|
/// <summary>
|
/// 字体大小,此属性不要使用了,请使用Font。
|
/// </summary>
|
[Category("扩展功能"), Description("字体")]
|
public Font TextFont
|
{
|
get { return textEdit.Font; }
|
set
|
{
|
if (textEdit.Font != value)
|
{
|
textEdit.Font = value;
|
lbRemark.Font = value;
|
lbCaption.Font = value;
|
}
|
this.Refresh();
|
}
|
}
|
|
/// <summary>
|
/// 字体大小
|
/// </summary>
|
[Category("扩展功能"), Description("字体")]
|
public override Font Font
|
{
|
get { return textEdit.Font; }
|
set
|
{
|
if (textEdit.Font != value)
|
{
|
textEdit.Font = value;
|
lbRemark.Font = value;
|
lbCaption.Font = value;
|
}
|
this.Refresh();
|
}
|
}
|
|
|
/// <summary>
|
/// 字体大小
|
/// </summary>
|
[Category("扩展功能"), Description("前景颜色")]
|
public override Color ForeColor
|
{
|
get { return textEdit.ForeColor; }
|
set
|
{
|
if (textEdit.ForeColor != value)
|
{
|
textEdit.ForeColor = value;
|
lbRemark.ForeColor = value;
|
lbCaption.ForeColor = value;
|
}
|
this.Refresh();
|
}
|
}
|
|
/// <summary>
|
/// 背景颜色
|
/// </summary>
|
//[Category("扩展功能"), Description("背景颜色")]
|
//public override Color BackColor
|
//{
|
// get { return this.BackColor; }
|
// set
|
// {
|
// if (textEdit.BackColor != value)
|
// {
|
// this.BackColor = value;
|
// //textEdit.BackColor = value;
|
// //lbRemark.BackColor = value;
|
// //lbCaption.BackColor = value;
|
// }
|
// this.Refresh();
|
// }
|
//}
|
|
|
///// <summary>
|
///// 文本框宽度
|
///// </summary>
|
//[Category("扩展功能"), Description("前景颜色")]
|
//public new int Width
|
//{
|
// get { return textEdit.Width; }
|
// set
|
// {
|
// if (textEdit.Width != value)
|
// {
|
// textEdit.Width = value;
|
// }
|
// this.Refresh();
|
// }
|
//}
|
|
|
/// <summary>
|
/// 实体类
|
/// </summary>
|
private object _SearchEntity;
|
|
/// <summary>
|
/// 数据实体类
|
/// </summary>
|
[Category("扩展功能"), Description("数据实体类")]
|
public object SearchEntity
|
{
|
get { return _SearchEntity; }
|
set { _SearchEntity = value; }
|
}
|
|
/// <summary>
|
/// 引发 <see cref="E:System.Windows.Forms.Control.Paint"></see> 事件。
|
/// </summary>
|
/// <param name="e">包含事件数据的 <see cref="T:System.Windows.Forms.PaintEventArgs"></see>。</param>
|
protected override void OnPaint(PaintEventArgs e)
|
{
|
//标题的列宽
|
int with = lbCaption.Size.Width + 3;
|
textEdit.Location = new Point(with, textEdit.Location.Y);
|
//文本列宽+标题的列宽
|
with = textEdit.Size.Width + with + 1;
|
btnButton.Location = new Point(with, btnButton.Location.Y);
|
//文本列宽+标题的列宽+按钮列宽
|
with = btnButton.Size.Width + with + 1;
|
lbRemark.Location = new Point(with, lbRemark.Location.Y);
|
base.OnPaint(e);
|
}
|
|
/// <summary>
|
/// 按钮点击事件
|
/// </summary>
|
[Category("扩展功能"), Description("按钮点选事件")]
|
public event EventHandler ButtonClick;
|
|
/// <summary>
|
/// 验证文本事件
|
/// </summary>
|
[Category("扩展功能"), Description("文本框验证事件")]
|
public event EventHandler TextValidated;
|
|
/// <summary>
|
/// 文本框数据变更事件
|
/// </summary>
|
[Category("扩展功能"), Description("文本框数据变更事件")]
|
public event EventHandler ButtonDataChanged;
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
public AdvButtonText()
|
{
|
InitializeComponent();
|
|
|
//this.BackColor = Color.FromArgb(255, 247, 245, 241);
|
//lbCaption.BackColor = Color.FromArgb(255, 247, 245, 241);
|
//lbRemark.BackColor = Color.FromArgb(255, 247, 245, 241);
|
//this.Refresh();
|
////textEdit.Properties.AppearanceReadOnly.BackColor = Color.FromArgb(255, 247, 245, 241); //Color.WhiteSmoke;//
|
////textEdit.Properties.AppearanceReadOnly.Options.UseBackColor = true;
|
////lbRemark.BackColor =Color.Transparent;
|
////.BackColor = Color.Cyan;//Color.FromArgb(255, 247, 245, 241);
|
btnButton.Click += new EventHandler(btnButton_Click);
|
textEdit.Validated += new EventHandler(textEdit_Validated);
|
lbCaption.TextChanged += new EventHandler(lbCaption_TextChanged);
|
textEdit.Enter += new EventHandler(textEdit_Enter);
|
|
}
|
|
/// <summary>
|
/// 进入文本框时的文本
|
/// </summary>
|
public string strOldText = "";
|
|
/// <summary>
|
/// 控件进入时,记录原本的文本
|
/// </summary>
|
/// <param name="sender">The source of the event.</param>
|
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
|
void textEdit_Enter(object sender, EventArgs e)
|
{
|
if (ReadOnly == false)
|
strOldText = textEdit.Text;
|
}
|
|
/// <summary>
|
/// 设置文本框获得焦点
|
/// </summary>
|
public void GetFocus()
|
{
|
textEdit.Focus();
|
}
|
|
void lbCaption_TextChanged(object sender, EventArgs e)
|
{
|
if (lbCaption.Text.Trim() == "")
|
textEdit.Location = new Point(0, 1);
|
}
|
|
/// <summary>
|
/// 按钮点击事件
|
/// </summary>
|
/// <param name="sender">The source of the event.</param>
|
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
|
public void btnButton_Click(object sender, EventArgs e)
|
{
|
DataRow[] RowList = new DataRow[1];
|
if (ButtonClick != null && ReadOnly == false)
|
{
|
//DataRow SelectRow = GetQueryRowArray(this.datacatalogID, this.filter);
|
//RowList[0]= SelectRow;
|
ButtonClick(this, e);
|
}
|
}
|
|
//private DataRow GetQueryRowArray(object dataCatalogID, object strFilter)
|
//{
|
// return GetQueryRow(dataCatalogID, strFilter, "");
|
//}
|
|
//private DataRow GetQueryRow(object dataCatalogID, object strFilter, string v)
|
//{
|
// SelectItemDlg.QueryType = SelectClickType.SingleRow;
|
// SelectItemDlg.Query = this;
|
// SelectItemDlg.SelfTitle = strTitle;
|
// //设置窗口标题
|
// if (SelectItemDlg.GetResultData(DataCatalogID, strFilter, out Error, _isUseCache) == true)
|
// {
|
// if (SelectItemDlg.ShowDialog() == DialogResult.OK)
|
// return (SelectItemDlg.ReturnRow == null) ? null : SelectItemDlg.ReturnRow;
|
// else
|
// return null;
|
// }
|
// else
|
// {
|
// //WriteLog(Error);
|
// return null;
|
// }
|
//}
|
|
//private DataRow GetQueryRow(string DataCatalogID, string strFilter)
|
//{
|
// return GetQueryRow(DataCatalogID, strFilter, "");
|
//}
|
//string _bindableDataCatalogId = "";
|
//string _bindableFilter = "";
|
//private DataRow GetQueryRow(string dataCatalogID, string strFilter, string strTitle)
|
//{
|
// #region 添加以备翻页复用(2018-1-5 G98118)
|
// _bindableDataCatalogId = dataCatalogID;
|
// _bindableFilter = strFilter;
|
// #endregion
|
|
// // SelectItemDlg.QueryType = SelectClickType.RowArray; //单行改为多行
|
// SelectItemDlg.QueryType = SelectClickType.SingleRow;
|
// SelectItemDlg.Query = this;
|
// SelectItemDlg.SelfTitle = strTitle;
|
// //设置窗口标题
|
// if (SelectItemDlg.GetResultData(DataCatalogID, strFilter, out Error, _isUseCache) == true)
|
// {
|
// if (SelectItemDlg.ShowDialog() == DialogResult.OK)
|
// return (SelectItemDlg.ReturnRow == null) ? null : SelectItemDlg.ReturnRow;
|
// else
|
// return null;
|
// }
|
// else
|
// {
|
// //WriteLog(Error);
|
// return null;
|
// }
|
//}
|
|
/// <summary>
|
/// 包装激活数据绑定变更
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
internal void FireButtonDataChanged(object sender, EventArgs e)
|
{
|
if (ButtonDataChanged != null)
|
ButtonDataChanged(sender, e);
|
}
|
|
/// <summary>
|
/// 文本框验证事件
|
/// </summary>
|
/// <param name="sender">The source of the event.</param>
|
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
|
private void textEdit_Validated(object sender, EventArgs e)
|
{
|
if (TextValidated != null && strOldText != textEdit.Text && ReadOnly == false)
|
{
|
try
|
{
|
TextValidated(this, e);
|
}
|
catch
|
{
|
return;
|
}
|
strOldText = "";
|
}
|
}
|
|
}
|
|
/// <summary>
|
/// 显示样式
|
/// </summary>
|
public enum ShowStyle
|
{
|
/// <summary>
|
/// 非备注模式
|
/// </summary>
|
NoRemark,
|
/// <summary>
|
/// 有备注模式
|
/// </summary>
|
BeRemark,
|
/// <summary>
|
/// 只有文本按钮模式
|
/// </summary>
|
BeText
|
}
|
|
|
}
|