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.

494 lines
13 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using Mesnac.Controls.Base;
using System;
using Mesnac.Controls.Default;
using System.Drawing.Design;
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel.Design;
using System.Globalization;
namespace Mesnac.Controls.Compressor
{
[ToolboxBitmap(typeof(System.Windows.Forms.Button))]
public partial class DisplayButton : Mesnac.Controls.Default.Button, IPurviewControl
{
private List<DesignAction> _clickActionList = new List<DesignAction>();
private List<DesignAction> _keyDownActionList = new List<DesignAction>();
private List<DesignAction> _keyUpActionList = new List<DesignAction>();
private bool _mcVisible = true; //保存可见性
private bool _mcEnabled = true; //保存可用性
private bool _isValid = true; //保存有效性
private object _mcvalue;
private int _alarmvalue;//报警界限值
public DisplayButton()
{
InitializeComponent();
this.BackColor = buttonColor0;
}
public DisplayButton(IContainer container)
{
container.Add(this);
InitializeComponent();
this.BackColor = buttonColor0;
}
public List<DesignAction> ClickActionList
{
get
{
return this._clickActionList;
}
set
{
this._clickActionList = value;
}
}
public List<DesignAction> KeyDownActionList
{
get { return _keyDownActionList; }
set { _keyDownActionList = value; }
}
public List<DesignAction> KeyUpActionList
{
get { return _keyUpActionList; }
set { _keyUpActionList = value; }
}
//业务
public string MCKey
{
get;
set;
}
public object MCValue
{
get { return _mcvalue; }
set
{
if (value == null)
return;
_mcvalue = value;
int intVlaue = GetValue(_mcvalue);
string ColorString = "buttonColor" + intVlaue.ToString();
Type type = this.GetType();
System.Reflection.PropertyInfo propertyInfo = type.GetProperty(ColorString);
if (propertyInfo != null)
{
Color color = (Color)propertyInfo.GetValue(this,null);
this.BackColor = color;
}
}
}
/// <summary>
/// 如果是数组获取第一个字的值如果是object获取Int值
/// </summary>
/// <param name="ob"></param>
/// <returns></returns>
private int GetValue(object ob)
{
//bool isArry = false;
int IntValue = 0;
try
{
object[] value = (object[])ob;
IntValue = Convert.ToInt32(value[0]);
}
catch
{
IntValue = Convert.ToInt32(ob);
}
return IntValue;
}
#region 变化颜色
[Description("0号颜色"), Category("ChangeColor")]
public Color buttonColor0
{
get;
set;
}
[Description("1号颜色"), Category("ChangeColor")]
public Color buttonColor1
{
get;
set;
}
[Description("2号颜色"), Category("ChangeColor")]
public Color buttonColor2
{
get;
set;
}
[Description("3号颜色"), Category("ChangeColor")]
public Color buttonColor3
{
get;
set;
}
[Description("4号颜色"), Category("ChangeColor")]
public Color buttonColor4
{
get;
set;
}
[Description("5号颜色"), Category("ChangeColor")]
public Color buttonColor5
{
get;
set;
}
[Description("6号颜色"), Category("ChangeColor")]
public Color buttonColor6
{
get;
set;
}
[Description("7号颜色"), Category("ChangeColor")]
public Color buttonColor7
{
get;
set;
}
#endregion
public IBaseControl MCRoot
{
get
{
return null;
}
set
{
;
}
}
#region 数据库的屏蔽,现在用不着
[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;
}
#endregion
[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;
}
}
}
[Description("是否控制权限"), Category("Behavior")]
public bool MCPurview
{
get;
set;
}
/// <summary>
/// 报警界限值
/// </summary>
public int Alarmvalue
{
get { return _alarmvalue; }
set { _alarmvalue = value; }
}
public bool IsValid
{
get { return _isValid; }
set { _isValid = value; }
}
}
public class GenericListTypeConverter<T> : TypeConverter
{
protected readonly TypeConverter typeConverter;
public GenericListTypeConverter()
{
typeConverter = TypeDescriptor.GetConverter(typeof(T));
if (typeConverter == null)
throw new InvalidOperationException("No type converter exists for type " + typeof(T).FullName);
}
protected virtual string[] GetStringArray(string input)
{
if (!String.IsNullOrEmpty(input))
{
string[] result = input.Split(',');
Array.ForEach(result, s => s.Trim());
return result;
}
else
return new string[0];
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
//if (sourceType == typeof(string))
//{
// string[] items = GetStringArray(sourceType.ToString());
// return items.Any();
//}
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
string[] items = GetStringArray((string)value);
var result = new List<T>();
Array.ForEach(items, s =>
{
object item = typeConverter.ConvertFromInvariantString(s);
if (item != null)
{
result.Add((T)item);
}
});
return result;
}
return base.ConvertFrom(context, culture, value);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
string result = string.Empty;
if (((IList<T>)value) != null)
{
//we don't use string.Join() because it doesn't support invariant culture
for (int i = 0; i < ((IList<T>)value).Count; i++)
{
var str1 = Convert.ToString(((IList<T>)value)[i], CultureInfo.InvariantCulture);
result += str1;
//don't add comma after the last element
if (i != ((IList<T>)value).Count - 1)
result += ",";
}
}
return result;
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
//public class MyColorCollection : BaseCollection, IList
//{
// private ArrayList _innerList;
// public MyColorCollection()
// {
// _innerList = new ArrayList();
// }
// protected override ArrayList List
// {
// get
// {
// return (ArrayList)_innerList;
// }
// }
// #region IList Members
// public int Add(object value)
// {
// return this.List.Add(value);
// }
// public void Clear()
// {
// this.List.Clear();
// }
// public bool Contains(object value)
// {
// return this.List.Contains(value);
// }
// public int IndexOf(object value)
// {
// return this.List.IndexOf(value);
// }
// public void Insert(int index, object value)
// {
// this.List.Insert(index, value);
// }
// public bool IsFixedSize
// {
// get { return this.List.IsFixedSize; }
// }
// public void Remove(object value)
// {
// this.List.Remove(value);
// }
// public void RemoveAt(int index)
// {
// this.List.RemoveAt(index);
// }
// public object this[int index]
// {
// get
// {
// return List[index];
// }
// set
// {
// List[index] = value;
// }
// }
// #endregion
//}
//public class MyCollectionEditor : CollectionEditor
//{
// public MyCollectionEditor(Type type)
// : base(type)
// { }
// /// <summary>
// /// 限制一次选一个实例
// /// </summary>
// /// <returns></returns>
// protected override bool CanSelectMultipleInstances()
// {
// return false;
// }
// /// <summary>
// /// 指定创建的对象类型
// /// </summary>
// /// <returns></returns>
// protected override Type CreateCollectionItemType()
// {
// return typeof(CSFrameworkNode);
// }
// protected override object CreateInstance(Type itemType)
// {
// //创建一个实例
// CSFrameworkNode o = (CSFrameworkNode)itemType.Assembly.CreateInstance(itemType.FullName);
// IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost));
// host.Container.Add(o);//重要!自动生成组件的设计时代码!
// //或者:
// //this.Context.Container.Add(o);//重要!自动生成组件的设计时代码!
// return o;
// }
// protected override void DestroyInstance(object instance)
// {
// base.DestroyInstance(instance);//重要!自动删除组件的设计时代码!
// }
//}
}