Esempio n. 1
0
        public override bool Equals(object obj)
        {
            if (!Value.HasValue)
            {
                return(obj == null);
            }

            if (obj == null)
            {
                return(!Value.HasValue);
            }

            if (obj is string)
            {
                int?number = CustomTypeHelper.DeserializeNullableInt((string)obj);

                return(Value == number);
            }
            else if (obj is double number)
            {
                return(Value == number);
            }
            else if (obj is XNullableInt)
            {
                return(Value == (XNullableInt)obj);
            }
            else
            {
                return(Value == Convert.ToDouble(obj));
            }
        }
Esempio n. 2
0
        static void Context_Loaded(object sender, RoutedEventArgs e)
        {
            FrameworkElement ui = (FrameworkElement)sender;

            ui.Loaded -= Context_Loaded;
            CustomTypeHelper go = (CustomTypeHelper)GetContext(ui);

            go.Init(ui);
        }
Esempio n. 3
0
        //把属性设置放入对象中
        private static void UIDataContextChanged(FrameworkElement ui)
        {
            PropertySetter ps = (PropertySetter)GetProp(ui);

            if (ui.DataContext != null)
            {
                //把属性设置放入对象中
                CustomTypeHelper go = (CustomTypeHelper)ui.DataContext;
                go.Add(ps);
            }
            //设置PropertySetter自己的DataContext为UI的DataContext
            ps.DataContext = ui.DataContext;
        }
Esempio n. 4
0
        //对列表中的对象按条件进行过滤,条件是编译好的程序
        public static string ToWhere(object list)
        {
            IEnumerable <object> enumer = (IEnumerable <object>)list;
            StringBuilder        sb     = new StringBuilder();

            foreach (var obj in enumer)
            {
                CustomTypeHelper cth       = (CustomTypeHelper)obj;
                string           field     = cth.GetPropertyValue("code").ToString();
                string           fieldtype = (string)cth.GetPropertyValue("fieldtype");
                PropertyInfo     pi        = cth.GetProperty("f_changehou");
                object           val       = cth.GetPropertyValue("f_changehou");
                if (val == null)
                {
                    continue;
                }
                //如果有自定义类型
                else if (fieldtype != null && fieldtype.Equals("oracledate"))
                {
                    sb.Append(",").Append(field).Append(" = ").Append("to_date('" + val.ToString() + "','yyyy-mm-dd')");
                }

                else if (pi.PropertyType == typeof(int) || pi.PropertyType == typeof(long) || pi.PropertyType == typeof(double) ||
                         pi.PropertyType == typeof(decimal))
                {
                    sb.Append(",").Append(field).Append(" = ").Append(val);
                }

                else if (pi.PropertyType == typeof(string))
                {
                    string v = "'" + val.ToString() + "'";
                    sb.Append(",").Append(field).Append(" = ").Append(v);
                }
                else
                {
                    throw new Exception("类型" + val.GetType() + "未知");
                }
            }
            if (sb.Length == 0)
            {
                return("");
            }
            return(sb.Remove(0, 1).ToString());
        }
Esempio n. 5
0
        public override bool Equals(object obj)
        {
            if (obj is string)
            {
                double number = CustomTypeHelper.DeserializeDouble((string)obj);

                return(Value == number);
            }
            else if (obj is double number)
            {
                return(Value == number);
            }
            else if (obj is XDouble)
            {
                return(Value == (XDouble)obj);
            }
            else
            {
                return(Value == Convert.ToDouble(obj));
            }
        }
Esempio n. 6
0
        public void ReadXml(XmlReader reader)
        {
            string rawValue = reader.ReadElementContentAsString();

            Value = CustomTypeHelper.DeserializeDouble(rawValue);
        }
Esempio n. 7
0
 public XDouble(string value)
 {
     Value = CustomTypeHelper.DeserializeDouble(value);
 }
Esempio n. 8
0
        public void ReadXml(XmlReader reader)
        {
            string rawValue = reader.ReadElementContentAsString();

            Value = CustomTypeHelper.ConvertToBoolean(rawValue, falseIfUnknown: false);
        }
Esempio n. 9
0
        public object ProvideValue(IServiceProvider serviceProvider)
        {
            var target =
                (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget));

            //没有source,默认为数据上下文
            if (Source == null && target is FrameworkElement)
            {
                Source = (target as FrameworkElement).DataContext;
            }
            Binding b = new Binding();

            b.Source = Source;
            if (Path != null)
            {
                b.Path = new PropertyPath(Path);
            }
            //模式默认为双向
            b.Mode = Mode;
            //默认转换器为空串转空值转换器
            b.Converter                   = new EmptyStringConverter();
            b.ConverterParameter          = filter;
            b.ValidatesOnExceptions       = true;
            b.ValidatesOnNotifyDataErrors = true;
            b.ValidatesOnDataErrors       = true;
            b.NotifyOnValidationError     = true;

            //如果目标对象是TextBox,且设置了,当TextBox的Text发生改变时,触发绑定
            if ((target.TargetObject is TextBox) && change)
            {
                TextBox txt = target.TargetObject as TextBox;
                txt.TextChanged += (o, e) =>
                {
                    TextBox text = o as TextBox;
                    var     bindingExpression = text.GetBindingExpression(TextBox.TextProperty);
                    if (filter != null && text.Text != null)
                    {
                        string result = (string)text.Text;
                        //用每一个过滤字符替换value中的内容为空串
                        foreach (char ch in filter)
                        {
                            result = result.Replace("" + ch, "");
                        }
                        text.Text = result;
                    }
                    if (bindingExpression != null)
                    {
                        bindingExpression.UpdateSource();
                    }
                };
            }
            //如果目标对象是PasswordBox,且设置了,当PasswordBox的Password发生改变时,触发绑定
            if ((target.TargetObject is PasswordBox) && change)
            {
                PasswordBox txt = target.TargetObject as PasswordBox;
                txt.PasswordChanged += (o, e) =>
                {
                    PasswordBox text = o as PasswordBox;
                    var         bindingExpression = text.GetBindingExpression(PasswordBox.PasswordProperty);
                    if (filter != null && text.Password != null)
                    {
                        string result = (string)text.Password;
                        //用每一个过滤字符替换value中的内容为空串
                        foreach (char ch in filter)
                        {
                            result = result.Replace("" + ch, "");
                        }
                        text.Password = result;
                    }
                    if (bindingExpression != null)
                    {
                        bindingExpression.UpdateSource();
                    }
                };
            }

            //注册错误通知事件,绑定发生错误(例如类型错误),通知对象
            FrameworkElement fe = (FrameworkElement)target.TargetObject;

            fe.BindingValidationError += (o, e) =>
            {
                if (e.Action.Equals(System.Windows.Controls.ValidationErrorEventAction.Added))
                {
                    CustomTypeHelper ct = (CustomTypeHelper)fe.DataContext;
                    if (ct != null)
                    {
                        ct.OnError(this.Path, e.Error.ErrorContent.ToString());
                    }
                }
            };
            return(b);
        }
Esempio n. 10
0
 public XNullableInt(string value)
 {
     Value = CustomTypeHelper.DeserializeNullableInt(value);
 }
Esempio n. 11
0
 public static void SetContext(FrameworkElement ui, CustomTypeHelper value)
 {
     ui.SetValue(ContextProperty, value);
 }