WPF颜色特性标签Color

/*----------------------------------------------------------------
 * 作    者 :姜  彦 
 * 项目名称 :EMRCPOE.Presentation.Common.Attributes
 * 类 名 称 :ColorAttribute 
 * 命名空间 :EMRCPOE.Presentation.Common.Attributes
 * CLR 版本 :4.0.30319.42000
 * 创建时间 :2019/11/6 16:00:10
 * 当前版本 :1.0.0.0
 * WeChatQQ :771078740
 * My Email :jiangyan2008.521@gmail.com 
 *            jiangyan2008.521@qq.com  
 * 描述说明 :色值特性 
 * 
 * 修改历史 : 
 * 
*******************************************************************
 * Copyright @ JiangYan 2019. All rights reserved.
*******************************************************************
------------------------------------------------------------------*/

using EMRCPOE.Presentation.Common.BaseModel;
using EMRCPOE.Presentation.Common.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace EMRCPOE.Presentation.Common.Attributes
{
    /// <summary>
    /// 色值特性
    /// </summary>
    public class ColorAttribute:Attribute
    {
        #region Construction

        /// <summary>
        /// 色值特性
        /// </summary>
        /// <param name="colorValue">通用WPF色值</param>
        public ColorAttribute(Color colorValue)
        {
            this._color = new SolidColorBrush(colorValue);
        }
        /// <summary>
        /// 色值特性
        /// </summary>
        /// <param name="colorValue">十六进制色值字符串</param>
        public ColorAttribute(string colorValue)
        {
            this._color=new SolidColorBrush((Color)ColorConverter.ConvertFromString(colorValue));
        }

        #endregion        

        #region Property

        private SolidColorBrush _color;

        /// <summary>
        /// 色值
        /// </summary>
        public SolidColorBrush Color
        {
            get { return _color; }
            set { _color = value; }
        }

        #endregion Property               
    }

    public static class ColorAttributeEx
    {
        /// <summary>
        /// 获取色值特性值
        /// </summary>
        /// <typeparam name="T">泛型对象</typeparam>
        /// <param name="obj">泛型单个对象</param>
        /// <param name="expr">Lambda表达式</param>
        /// <returns></returns>
        public static SolidColorBrush Color<T>(this T obj, Expression<Func<T, object>> expr)
        {
            var strColorValue = string.Empty;
            if (expr.Body is UnaryExpression)
            {
                var body = (MemberExpression)((UnaryExpression)expr.Body).Operand;
                var attr = body.Member.CustomAttributes.FirstOrDefault(t => t.AttributeType == typeof(ColorAttribute));
                if (attr == null)
                    strColorValue = body.Member.Name;
                else
                    strColorValue = attr.ConstructorArguments.FirstOrDefault().Value.ToString();
            }
            else if (expr.Body is MemberExpression)
            {
                var body = expr.Body as MemberExpression;
                var attr = body.Member.CustomAttributes.FirstOrDefault(t => t.AttributeType == typeof(ColorAttribute));
                if (attr == null)
                    strColorValue = body.Member.Name;
                else
                    strColorValue = attr.ConstructorArguments.FirstOrDefault().Value.ToString();
            }
            else if (expr.Body is ParameterExpression)
            {

                var body = expr.Body as ParameterExpression;
                var attr = body.Type.CustomAttributes.FirstOrDefault(t => t.AttributeType == typeof(ColorAttribute));
                if (attr == null)
                    strColorValue = body.Type.Name;
                else
                    strColorValue = attr.ConstructorArguments.FirstOrDefault().Value.ToString();
            }
            return new SolidColorBrush((Color)ColorConverter.ConvertFromString(strColorValue));
        }

        /// <summary>
        /// 获取色值特性值
        /// </summary>
        /// <typeparam name="T">枚举类型</typeparam>
        /// <param name="obj">枚举值</param>
        /// <returns>特性的说明</returns>
        public static SolidColorBrush Color<T>(this T obj)
        {
            var type = obj.GetType();
            FieldInfo field = type.GetField(System.Enum.GetName(type, obj));
            ColorAttribute descAttr = Attribute.GetCustomAttribute(field, typeof(ColorAttribute)) as ColorAttribute;
            if (descAttr == null)
            {
                return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));
            }

            return descAttr.Color;
        }
    }

    #region 医嘱状态管理
    /// <summary>
    /// 表示医嘱状态事件数据的类,并提供用于不包含事件数据的事件的值
    /// </summary>
    public class OrderStatusEventArgs : EventArgs
    {
        /// <summary>
        /// 医嘱时间类构造函数
        /// </summary>
        /// <param name="previousOrderStatus">前一个状态</param>
        /// <param name="currentOrderStatus">当前状态</param>
        /// <param name="nextOrderStatus">下一个状态</param>
        public OrderStatusEventArgs(OrderStatusEnum previousOrderStatus, OrderStatusEnum currentOrderStatus, OrderStatusEnum nextOrderStatus)
        {
            this._previousOrderStatus = previousOrderStatus;
            this._currentOrderStatus = currentOrderStatus;
            this._nextOrderStatus = nextOrderStatus;
        }

        /// <summary>
        /// 医嘱时间类构造函数
        /// </summary>
        /// <param name="previousOrderStatus">前一个状态</param>
        /// <param name="currentOrderStatus">当前状态</param>      
        public OrderStatusEventArgs(OrderStatusEnum previousOrderStatus, OrderStatusEnum currentOrderStatus)
        {
            this._previousOrderStatus = previousOrderStatus;
            this._currentOrderStatus = currentOrderStatus;
        }

        private OrderStatusEnum _previousOrderStatus;
        /// <summary>
        /// 前一个医嘱状态
        /// </summary>
        public OrderStatusEnum PreviousOrderStatus
        {
            get { return _previousOrderStatus; }
            set { _previousOrderStatus = value; }
        }

        private OrderStatusEnum _currentOrderStatus;
        /// <summary>
        /// 当前医嘱状态
        /// </summary>
        public OrderStatusEnum CurrentOrderStatus
        {
            get { return _currentOrderStatus; }
            set { _currentOrderStatus = value; }
        }

        private OrderStatusEnum _nextOrderStatus;
        /// <summary>
        /// 下一个医嘱状态
        /// </summary>
        public OrderStatusEnum NextOrderStatus
        {
            get { return _nextOrderStatus; }
            set { _nextOrderStatus = value; }
        }

    }

    /// <summary>
    /// 医嘱状态管理类
    /// </summary>
    public class OrderStatusManager : Singleton<OrderStatusManager>
    {
        #region Property

        private OrderStatusEnum _orderStatus;

        /// <summary>
        /// 医嘱状态
        /// </summary>
        public OrderStatusEnum OrderStatus
        {
            get { return _orderStatus; }
            set
            {
                OrderStatusChanged(this, new OrderStatusEventArgs(_orderStatus, value));
                _orderStatus = value;
            }
        }

        #endregion

        #region Event

        /// <summary>
        /// 医嘱状态监控委托
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">医嘱状态事件数据</param>
        public delegate void MonitoredEventHandler(object sender, OrderStatusEventArgs e);

        /// <summary>
        /// 医嘱监控事件
        /// </summary>
        public event MonitoredEventHandler Monitored;

        /// <summary>
        /// 医嘱状态监控事件触发
        /// </summary>
        /// <param name="e"></param>
        public void Invoke(object sender, OrderStatusEventArgs e)
        {
            if (Monitored != null)
                Monitored(sender, e);
        }

        #endregion

        #region Function

        /// <summary>
        /// 医嘱状态改变
        /// </summary>
        /// <param name="e"></param>
        private void OrderStatusChanged(object sender, OrderStatusEventArgs e)
        {
            Invoke(this, e);
        }

        #endregion
    }
    #endregion
}

/*----------------------------------------------------------------
 * 备    注 :
 * 
 * 
 * 
*******************************************************************
 * Copyright @ JiangYan 2019. All rights reserved.
*******************************************************************
------------------------------------------------------------------*/

 

posted @ 2019-12-13 19:41  <--青青子衿-->  阅读(857)  评论(0编辑  收藏  举报
// /**/ // 在页脚Html代码 引入 // function btn_donateClick() { var DivPopup = document.getElementById('Div_popup'); var DivMasklayer = document.getElementById('div_masklayer'); DivMasklayer.style.display = 'block'; DivPopup.style.display = 'block'; var h = Div_popup.clientHeight; with (Div_popup.style) { marginTop = -h / 2 + 'px'; } } function MasklayerClick() { var masklayer = document.getElementById('div_masklayer'); var divImg = document.getElementById("Div_popup"); masklayer.style.display = "none"; divImg.style.display = "none"; } setTimeout( function () { document.getElementById('div_masklayer').onclick = MasklayerClick; document.getElementById('btn_donate').onclick = btn_donateClick; var a_gzw = document.getElementById("guanzhuwo"); a_gzw.href = "javascript:void(0);"; $("#guanzhuwo").attr("onclick","follow('33513f9f-ba13-e011-ac81-842b2b196315');"); }, 900);