You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

542 lines
13 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Mesnac.Controls.Base;
namespace Mesnac.Controls.Default
{
[ToolboxBitmap(typeof(System.Windows.Forms.Label))]
public partial class MCLabel : System.Windows.Forms.Label, IBaseControl
{
#region 字段定义
private bool _mcVisible = true; //保存可见性
private bool _mcEnabled = true; //保存可用性
private bool _isValid = true; //保存有效性
private bool _isEventValid = true; //保存事件有效性
private bool _bHaveAction = false;
private string _format = string.Empty;
private string _textName = null;
private string _textValue = string.Empty;
private string _xName = null;
private int? _xValue = null;
private string _yName = null;
private int? _yValue = null;
private string _widthName = null;
private int? _widthValue = null;
private string _heightName = null;
private int? _heightValue = null;
private Color _newFillColor = Color.Red;
//原背景色
private Color _oldFillColor = Color.DarkGray;
private string _fillColorName = null;
private int? _fillColorValue = null;
#endregion
#region 构造方法
public MCLabel()
{
//this.DoubleBuffered = true;
InitializeComponent();
this.AutoSize = true;
}
#endregion
#region 事件处理
protected override void OnPaint(PaintEventArgs pe)
{
// TODO: 在此处添加自定义绘制代码
// 调用基类 OnPaint
base.OnPaint(pe);
}
#endregion
#region 属性定义
#region bHaveAction
public bool bHaveAction
{
get
{
return _bHaveAction;
}
set
{
_bHaveAction = value;
}
}
#endregion
#region Text
[Description("格式化"), Category("Data")]
public string Format
{
get
{
return _format;
}
set
{
_format = value;
}
}
public string TextName
{
get
{
return _textName;
}
set
{
_textName = value;
}
}
public string TextValue
{
set
{
this._textValue = value;
if (!this.DesignMode)
{
if (string.IsNullOrWhiteSpace(this._format))
{
this.Text = this._textValue;
}
else
{
try
{
this.Text = this.ExecFormat(this._format, this._textValue);
}
catch { }
}
}
}
get
{
return this._textValue;
}
}
#endregion
#region Left
public string XName
{
get
{
return _xName;
}
set
{
_xName = value;
}
}
public int? XValue
{
set
{
this._xValue = value;
if (!this.DesignMode)
{
if (this._xValue != null)
{
this.Left = (int)this._xValue;
}
}
}
get
{
return this._xValue;
}
}
#endregion
#region Top
public string YName
{
get
{
return _yName;
}
set
{
_yName = value;
}
}
public int? YValue
{
set
{
this._yValue = value;
if (!this.DesignMode)
{
if (this._yValue != null)
{
this.Top = (int)this._yValue;
}
}
}
get
{
return this._yValue;
}
}
#endregion
#region Width
public string WidthName
{
get
{
return _widthName;
}
set
{
_widthName = value;
}
}
public int? WidthValue
{
set
{
this._widthValue = value;
if (!this.DesignMode)
{
if (this._widthValue != null)
{
this.Width = (int)this._widthValue;
}
}
}
get
{
return this._widthValue;
}
}
#endregion
#region Height
public string HeightName
{
get
{
return _heightName;
}
set
{
_heightName = value;
}
}
public int? HeightValue
{
set
{
this._heightValue = value;
if (!this.DesignMode)
{
if (this._heightValue != null && !this.DesignMode)
{
this.Height = (int)this._heightValue;
}
}
}
get
{
return this._heightValue;
}
}
#endregion
#region FillColor
[Description("背景色(2)"), Category("Appearance")]
public Color NewFillColor
{
get
{
return _newFillColor;
}
set
{
_newFillColor = value;
}
}
[Description("背景色(1)"), Category("Appearance")]
public Color OldFillColor
{
get
{
return _oldFillColor;
}
set
{
_oldFillColor = value;
}
}
public string FillColorName
{
get
{
return _fillColorName;
}
set
{
_fillColorName = value;
}
}
public int? FillColorValue
{
set
{
this._fillColorValue = value;
if (!this.DesignMode)
{
if (this._fillColorValue != null)
{
if ((int)this._fillColorValue > 0)
{
this.BackColor = this.NewFillColor;
}
else
{
this.BackColor = this.OldFillColor;
}
}
}
}
get
{
return this._fillColorValue;
}
}
#endregion
#endregion
#region 接口成员实现
public string MCKey
{
get;
set;
}
public object MCValue
{
get
{
return this.Text;
}
set
{
this.Text = value == null ? "" : value.ToString();
}
}
public IBaseControl MCRoot
{
get;
set;
}
[TypeConverter(typeof(DataSourceConverter))]
[Description("数据连接"), Category("Data")]
public string MCDataSourceID
{
get;
set;
}
public MCDataSource MCDataSource
{
get;
set;
}
[Description("是否为数据库控件"), Category("Data")]
public bool IsDbControl
{
get;
set;
}
[Description("初始化SQL"), Category("Data")]
public string InitDataSource
{
get;
set;
}
[Description("执行SQL"), Category("Data")]
public string ActionDataSource
{
get;
set;
}
[Description("绑定数据源"), Category("Data")]
public object BindDataSource
{
get;
set;
}
[Description("操作类型"), Category("Data")]
public DbOptionTypes DbOptionType
{
get;
set;
}
[Description("是否可见"), Category("Behavior")]
public bool MCVisible
{
get
{
return this._mcVisible;
}
set
{
this._mcVisible = value == null ? true : value;
if (this.Site.DesignMode)
{
this.Visible = true;
}
else
{
this.Visible = this._mcVisible;
}
}
}
[Description("是否可用"), Category("Behavior")]
public bool MCEnabled
{
get
{
return this._mcEnabled;
}
set
{
this._mcEnabled = value == null ? true : value;
if (this.Site.DesignMode)
{
this.Enabled = true;
}
else
{
this.Enabled = this._mcEnabled;
}
}
}
public bool IsValid
{
get { return _isValid; }
set { _isValid = value; }
}
public bool IsEventValid
{
get { return this._isEventValid; }
set { this._isEventValid = value; }
}
#endregion
#region 辅助方法
#region 执行格式化方法
/// <summary>
/// 执行格式化方法
/// </summary>
/// <param name="_format">格式化字符串</param>
/// <param name="strValue">要格式化的值</param>
/// <returns>返回格式化之后的字符串</returns>
public string ExecFormat(string _format, string strValue)
{
try
{
string result = "";
DateTime dateResult = DateTime.Now;
bool boolResult = false;
byte byteResult = 0;
short shortResult = 0;
int intResult = 0;
decimal decimalResult = 0;
double doubleResult = 0.0;
//日期和时间
if (strValue.IndexOf("-") > 0 || strValue.IndexOf(":") > 0)
{
if (DateTime.TryParse(strValue, out dateResult))
{
result = string.Format(_format, dateResult);
}
}
else if (strValue.IndexOf(".") > 0)
{
if (decimal.TryParse(strValue, out decimalResult))
{
result = string.Format(_format, decimalResult);
}
else if (double.TryParse(strValue, out doubleResult))
{
result = string.Format(_format, doubleResult);
}
}
else if (bool.TryParse(strValue, out boolResult))
{
result = boolResult.ToString();
}
else if (byte.TryParse(strValue, out byteResult))
{
result = byteResult.ToString();
}
else if (short.TryParse(strValue, out shortResult))
{
result = shortResult.ToString();
}
else if (int.TryParse(strValue, out intResult))
{
result = intResult.ToString();
}
else
{
result = strValue;
}
return result;
}
catch
{
return strValue;
}
}
#endregion
#endregion
}
}