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
{///
/// 高级按钮文本框
///
public partial class AdvButtonText : UserControl
{
//public bool ChangeTextLeft
///
///标签标题;
///
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; }
}
///
/// 标题
///
[Category("扩展功能"), Description("文本底色")]
public Color TextBackColor
{
get { return textEdit.BackColor; }
set
{
textEdit.BackColor = value;
}
}
///
/// 数据值
///
[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;
}
}
}
///
/// 数据值
///
[Category("扩展功能"), Description("文本框内容")]
public string EditValue
{
get { return textEdit.Text; }
set
{
//这个如果不设置会引起列变化事件。
if (textEdit.Text == value)
return;
textEdit.Text = value;
}
}
///
/// 备注字段
///
[Category("扩展功能"), Description("备注内容")]
public string Remark
{
get { return lbRemark.Text; }
set
{
//这个如果不设置会引起列变化事件。
if (lbRemark.Text == value)
return;
lbRemark.Text = value;
}
}
///
/// 是否验证
///
private Boolean isValidated = true;
///
/// 是否验证
///
[Category("扩展功能"), Description("是否验证")]
public Boolean IsValidated
{
get { return isValidated; }
set { isValidated = value; }
}
///
/// 显示类型
///
private ShowStyle textType = ShowStyle.BeRemark;
///
/// 控件类型,分别:非备注模式,备注模式,文本框模式
///
/// The type of the text.
[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;
}
}
///
/// 风格
///
[Category("扩展功能"), Description("风格")]
public IStyleController StyleController
{
get { return textEdit.StyleController; }
set { textEdit.StyleController = value; }
}
///
/// 获取或设置一个值,该值指示控件是否可以对用户交互作出响应。
///
///
///
/// 如果控件可以对用户交互作出响应,则为 true;否则为 false。默认为 true。
///
public new bool Enabled
{
get { return textEdit.Enabled; }
set
{
textEdit.Enabled = value;
btnButton.Enabled = value;
lbRemark.Enabled = value;
}
}
///
/// DC编号
///
private string datacatalogID;
///
/// 数据目录编号DC
///
/// The datacatalog ID.
[Category("扩展功能"), Description("数据目录编号,如ADMDAA-01")]
public string DatacatalogID
{
get { return datacatalogID; }
set { datacatalogID = value; }
}
private string textField = string.Empty;
///
/// 文本字段
///
[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;
///
/// 备注字段名
///
[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;
///
/// 备注绑定字段
///
[Category("扩展功能"), Description("对应当前数据表中的字段。")]
public string RemarkBindField
{
get
{
if (_RemarkBindField == null)
return string.Empty;
else
return _RemarkBindField.Trim();
}
set { _RemarkBindField = value; }
}
///
/// 映射关系
///
private string otherMapping;
///
/// 设置或获取其他映射关系
///
/// The mapping.
[Category("扩展功能"), Description("其他关系字段映射关系统(用分号隔开):[控件.Text]=DAA001;[控件.Text]=DAA002")]
public string OtherMapping
{
get
{
if (otherMapping == null)
return string.Empty;
else
return otherMapping.Trim();
}
set { otherMapping = value; }
}
///
/// 条件筛选
///
private string filter;
///
/// 获取或设置筛选条件
///
/// The filter.
[Category("扩展功能"), Description("筛选条件(也可写固定条件).字段编号=[控件.属性] 如:DAA004='8032'AND DAA005=[控件2.Text]")]
public string Filter
{
get { return filter; }
set { filter = value; }
}
///
/// 文体大小
///
[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();
}
}
///
/// 字体大小,此属性不要使用了,请使用Font。
///
[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();
}
}
///
/// 字体大小
///
[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();
}
}
///
/// 字体大小
///
[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();
}
}
///
/// 背景颜色
///
//[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();
// }
//}
/////
///// 文本框宽度
/////
//[Category("扩展功能"), Description("前景颜色")]
//public new int Width
//{
// get { return textEdit.Width; }
// set
// {
// if (textEdit.Width != value)
// {
// textEdit.Width = value;
// }
// this.Refresh();
// }
//}
///
/// 实体类
///
private object _SearchEntity;
///
/// 数据实体类
///
[Category("扩展功能"), Description("数据实体类")]
public object SearchEntity
{
get { return _SearchEntity; }
set { _SearchEntity = value; }
}
///
/// 引发 事件。
///
/// 包含事件数据的 。
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);
}
///
/// 按钮点击事件
///
[Category("扩展功能"), Description("按钮点选事件")]
public event EventHandler ButtonClick;
///
/// 验证文本事件
///
[Category("扩展功能"), Description("文本框验证事件")]
public event EventHandler TextValidated;
///
/// 文本框数据变更事件
///
[Category("扩展功能"), Description("文本框数据变更事件")]
public event EventHandler ButtonDataChanged;
///
/// 构造函数
///
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);
}
///
/// 进入文本框时的文本
///
public string strOldText = "";
///
/// 控件进入时,记录原本的文本
///
/// The source of the event.
/// The instance containing the event data.
void textEdit_Enter(object sender, EventArgs e)
{
if (ReadOnly == false)
strOldText = textEdit.Text;
}
///
/// 设置文本框获得焦点
///
public void GetFocus()
{
textEdit.Focus();
}
void lbCaption_TextChanged(object sender, EventArgs e)
{
if (lbCaption.Text.Trim() == "")
textEdit.Location = new Point(0, 1);
}
///
/// 按钮点击事件
///
/// The source of the event.
/// The instance containing the event data.
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;
// }
//}
///
/// 包装激活数据绑定变更
///
///
///
internal void FireButtonDataChanged(object sender, EventArgs e)
{
if (ButtonDataChanged != null)
ButtonDataChanged(sender, e);
}
///
/// 文本框验证事件
///
/// The source of the event.
/// The instance containing the event data.
private void textEdit_Validated(object sender, EventArgs e)
{
if (TextValidated != null && strOldText != textEdit.Text && ReadOnly == false)
{
try
{
TextValidated(this, e);
}
catch
{
return;
}
strOldText = "";
}
}
}
///
/// 显示样式
///
public enum ShowStyle
{
///
/// 非备注模式
///
NoRemark,
///
/// 有备注模式
///
BeRemark,
///
/// 只有文本按钮模式
///
BeText
}
}