Exemple #1
0
    /// <summary>
    /// 复制属性到另一个对象中(可以不同类型)。
    /// </summary>
    /// <param name="model">当前对象。</param>
    /// <param name="toModel">目标对象。</param>
    /// <param name="predicate">过滤器。</param>
    public static void CopyTo(
#if !net20
        this
#endif
        object model, object toModel, System.Predicate <System.Reflection.PropertyInfo> predicate)
    {
        Symbol.CommonException.CheckArgumentNull(model, "model");
        Symbol.CommonException.CheckArgumentNull(toModel, "toModel");

        System.Type type   = model.GetType();
        System.Type toType = toModel.GetType();

        foreach (System.Reflection.PropertyInfo propertyInfo in type.GetProperties(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
        {
            if (!propertyInfo.CanRead || propertyInfo.GetIndexParameters().Length > 0)
            {
                continue;
            }
            System.Reflection.PropertyInfo toPropertyInfo = toType.GetProperty(propertyInfo.Name, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
            if (toPropertyInfo == null || !toPropertyInfo.CanWrite)
            {
                continue;
            }
            if (predicate != null && !predicate(propertyInfo))
            {
                continue;
            }
            toPropertyInfo.SetValue(toModel, TypeExtensions.Convert(propertyInfo.GetValue(model, null), toPropertyInfo.PropertyType), null);
        }
    }
Exemple #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!UIValidtion.Create()
                .Null(txtName, "名称")
                .Len(2, 10)
                .My(p => {
                if (Program.DataStore.ExistsConsumeTypeWithName(p.LastValue, 0))
                {
                    p.Return(false)
                    .Msg("此消费方式已经存在!")
                    .LastControl.Focus();
                }
            })
                .Null(txtOrder, "顺序")
                .NumDec()
                .Result)
            {
                return;
            }

            _model = new ConsumeType()
            {
                UserId = Program.CurrentUser.Id,
                Name   = txtName.Text,
                Order  = TypeExtensions.Convert <double>(txtOrder.Text, 0D),
                IsOut  = chkIsOut.Checked,
            };
            Program.DataStore.Add(_model);
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }
Exemple #3
0
 string WrapValue(NodeValue jsonValue)
 {
     if (jsonValue == null || jsonValue.Type == NodeValueTypes.Null)
     {
         return("asc");
     }
     else if (jsonValue.Type == NodeValueTypes.Number)
     {
         return(TypeExtensions.Convert <long>(jsonValue.Value, 0) == 0 ? "asc" : "desc");
     }
     else if (jsonValue.Type == NodeValueTypes.String)
     {
         string value = (string)jsonValue.Value;
         if (string.IsNullOrEmpty(value) || value.StartsWith("asc", StringComparison.OrdinalIgnoreCase))
         {
             return("asc");
         }
         return("desc");
     }
     else if (jsonValue.Type == NodeValueTypes.Boolean)
     {
         return(((bool)jsonValue.Value) ? "desc" : "asc");
     }
     else
     {
         return("asc");
     }
 }
Exemple #4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!UIValidtion.Create()
                .Null(txtName, "名称")
                .Len(2, 10)
                .My(p => {
                if (Program.DataStore.ExistsConsumeTypeWithName(p.LastValue, _model.Id))
                {
                    p.Return(false)
                    .Msg("此消费方式已经存在!")
                    .LastControl.Focus();
                }
            })
                .Null(txtOrder, "顺序")
                .NumDec()
                .Result)
            {
                return;
            }


            _model.Name  = txtName.Text;
            _model.Order = TypeExtensions.Convert <double>(txtOrder.Text, 0D);

            Program.DataStore.Edit(_model);
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }
        string PreOffset(string orderbys)
        {
            if (string.IsNullOrEmpty(orderbys))
            {
                return(null);
            }
            string regex = "offset[\\s\\S]+(?<offset>[0-9]+)[\\s\\S]+rows[\\s\\S]+fetch[\\s\\S]+next[\\s\\S]+(?<next>[0-9]+)[\\s\\S]+rows[\\s\\S]+only[\\s\\S;]*|offset[\\s\\S]+(?<offset>[0-9]+)[\\s\\S]+rows[\\s\\S;]*";

            //string regex2 = "offset[\\s\\S]+([0-9]+)[\\s\\S]+rows[\\s\\S;]*";
            System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(orderbys, regex, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            //if (!match.Success) {
            //    match = System.Text.RegularExpressions.Regex.Match(orderbys, regex2, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            //}
            if (!match.Success)
            {
                return(orderbys);
            }
            SkipCount = TypeExtensions.Convert <int>(match.Groups["offset"].Value, 0);
            int takeCount = TypeExtensions.Convert <int>(match.Groups["next"].Value, 0);

            if (takeCount > 0)
            {
                TakeCount = takeCount;
            }
            //if (match.Groups.Count > 2) {

            //}
            return(orderbys.Replace(match.Value, ""));
        }
        /// <summary>
        /// 创建数据库连接。
        /// </summary>
        /// <param name="connectionOptions">连接参数。</param>
        /// <returns>返回数据库连接。</returns>
        public override IConnection CreateConnection(object connectionOptions)
        {
            {
                if (connectionOptions is string connectionString)
                {
                    connectionString = connectionString.Trim();
                    if (connectionString.StartsWith("{"))
                    {
                        connectionOptions = JSON.Parse(connectionString);
                        goto lb_Object;
                    }
                    return(CreateConnection(connectionString));
                }
                if (connectionOptions is ConnectionOptions connectionOptions2)
                {
                    connectionOptions = connectionOptions2.ToObject();
                    goto lb_Object;
                }
            }
lb_Object:
            System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder();
            Collections.Generic.NameValueCollection <object> values = new Collections.Generic.NameValueCollection <object>(connectionOptions);
            builder.MaxPoolSize = 1024;
            SetBuilderValue(builder, values, "host", "Data Source", p => {
                string p10 = p as string;
                if (string.IsNullOrEmpty(p10))
                {
                    return(p);
                }
                if (p10.IndexOf(':') > -1)
                {
                    return(p10.Replace(':', ','));
                }
                return(p);
            });
            SetBuilderValue(builder, values, "port", "Data Source", p => {
                string p10 = TypeExtensions.Convert <string>(p);
                if (string.IsNullOrEmpty(p10))
                {
                    return(null);
                }
                builder.DataSource += "," + p10;
                return(null);
            });

            SetBuilderValue(builder, values, "name", "Initial Catalog");
            SetBuilderValue(builder, values, "account", "User ID");
            SetBuilderValue(builder, values, "password", "Password");
            foreach (System.Collections.Generic.KeyValuePair <string, object> item in values)
            {
                //builder[item.Key] = item.Value;
                SetBuilderValue(builder, item.Key, item.Value);
            }
            if (!builder.PersistSecurityInfo && !builder.IntegratedSecurity)
            {
                builder.PersistSecurityInfo = true;
            }
            builder.MultipleActiveResultSets = true;
            return(CreateConnection(builder.ConnectionString));
        }
        /// <summary>
        /// 设置指定键对应的值。
        /// </summary>
        /// <param name="key">键,null或empty忽略。</param>
        /// <param name="value">值。</param>
        public void Set(string key, object value)
        {
            if (string.IsNullOrEmpty(key))
            {
                return;
            }
            switch (key.ToLower())
            {
            case "host":
                Host = TypeExtensions.Convert <string>(value);
                break;

            case "port":
                Port = TypeExtensions.Convert <int>(value, 0);
                break;

            case "name":
                Name = TypeExtensions.Convert <string>(value);
                break;

            case "account":
                Account = TypeExtensions.Convert <string>(value);
                break;

            case "password":
                Password = TypeExtensions.Convert <string>(value);
                break;

            default:
                _vars[key] = value;
                break;
            }
        }
Exemple #8
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //Symbol.Forms.SelectedItem<Funds> fundsItem = (Symbol.Forms.SelectedItem<Funds>)cbFundsId.SelectedItem;
            Symbol.Forms.SelectedItem <ConsumeType> consumeTypeItem = (Symbol.Forms.SelectedItem <ConsumeType>)cbConsumeTypeId.SelectedItem;
            if (!UIValidtion.Create()
                .Next(cbConsumeTypeId, p => p.SelectedIndex != -1, p => consumeTypeItem == null ? "" : consumeTypeItem.Text, "消费方式", true)
                .Next(dtByDate, p => p.Value.HasValue, p => p.Value == null ? "" : p.Value.Value.ToString(p.Format), "日期")
                .Null(txtMoney, "金额")
                .NumDec(0)
                .Null(txtRelatedPerson, "相关人")
                .Len(1, 10)
                .Result)
            {
                return;
            }

            _model = new FundsLog()
            {
                UserId    = Program.CurrentUser.Id,
                ByDate    = dtByDate.Value.Value,
                ByDateDay = dtByDate.DayNumber,
                //FundsId = fundsItem.Value.Id,
                ConsumeTypeId = consumeTypeItem.Value.Id,
                Money         = Math.Abs(TypeExtensions.Convert <decimal>(txtMoney.Text, 0M)),
                //LastMoney= fundsItem.Value.Money,
                RelatedPerson = txtRelatedPerson.Text,
                Comment       = txtComment.Text,
                IsOut         = consumeTypeItem.Value.IsOut,
            };
            Program.DataStore.Add(_model);
            //Symbol.FastWrapper.Set(_model, "FundsName", fundsItem.Value.Name);
            FastWrapper.Set(_model, "ConsumeTypeName", consumeTypeItem.Value.Name);

            DialogResult = System.Windows.Forms.DialogResult.OK;
        }
        /// <summary>
        /// 创建参数回调
        /// </summary>
        /// <param name="item">参数对象</param>
        protected override void OnCreate(CommandParameter item)
        {
            if (item.Value == null)
            {
                return;
            }
            if (item.Value.GetType() != item.RealType)
            {
                item.Value = TypeExtensions.Convert(item.Value, item.RealType);
            }

            if (item.RealType.IsArray && item.RealType.GetElementType() != typeof(byte))
            {
                item.Value = item.Value == null ? null : JSON.ToJSON(item.Value);
                return;
            }
            if (
                item.RealType == typeof(object) ||
                TypeExtensions.IsAnonymousType(item.RealType) ||
                TypeExtensions.IsInheritFrom(item.RealType, typeof(System.Collections.Generic.IDictionary <string, object>)) ||
                (item.RealType.IsClass && !TypeExtensions.IsSystemBaseType(item.RealType))
                )
            {
                item.RealType = typeof(object);
                item.Value    = item.Value == null ? null : JSON.ToJSON(item.Value);
                return;
            }
        }
        bool ParseFields(string fields)
        {
            fields = fields.Trim();
            if (string.IsNullOrEmpty(fields))
            {
                return(false);
            }
            int  i   = fields.IndexOf("top ", System.StringComparison.OrdinalIgnoreCase);
            bool top = false;

            if (i != -1)
            {
                i += "top ".Length;
                int j = fields.IndexOf(' ', i);
                if (j != -1)
                {
                    TakeCount = TypeExtensions.Convert <int>(fields.Substring(i, j - i), 0);
                    top       = true;
                    fields    = fields.Substring(j + 1);
                }
                else
                {
                    fields = fields.Substring(i);
                }
            }
            System.Collections.Generic.ICollectionExtensions.AddRange(_fields, fields.Split(','));
            return(top);
        }
        /// <summary>
        /// 绑定数据。
        /// </summary>
        /// <param name="dataContext">数据上下文对象。</param>
        /// <param name="reader">数据查询读取器。</param>
        /// <param name="entity">当前实体对象。</param>
        /// <param name="field">当前字段。</param>
        /// <param name="type">实体中字段的类型。</param>
        /// <param name="cache">缓存。</param>
        /// <returns>返回绑定的数据。</returns>
        public override object Bind(IDataContext dataContext, IDataQueryReader reader, object entity, string field, Type type, IDataBinderObjectCache cache)
        {
            bool isSingleValue = (type == typeof(string) || type.IsValueType || TypeExtensions.IsNullableType(type));

            if (isSingleValue && (string.IsNullOrEmpty(Field) || Field == "*"))
            {
                Field = "id";
            }

            using (var builder = dataContext.CreateSelect(SourceName)) {
                //PreSelectBuilder(dataContext, dataReader, entity, builder, cache);
                if (isSingleValue)
                {
                    builder.Select(Field);
                }
                var conditiion = MapObject(Condition, dataContext, entity, reader);
                builder.Query(conditiion).Sort(Sorter);
                return(CacheFunc(cache, builder, "once", type, () => {
                    object value = null;
                    if (builder.WhereCommandText.Length > 0)
                    {
                        var q = dataContext.CreateQuery(type, builder.CommandText, builder.Parameters);
                        q.DataBinderObjectCache = cache;
                        value = q.FirstOrDefault();
                    }
                    if (value == null && type.IsValueType)
                    {
                        return TypeExtensions.DefaultValue(type);
                    }
                    return TypeExtensions.Convert(value, type);
                }));
            }
        }
 /// <summary>
 /// 加载数据。
 /// </summary>
 /// <param name="data">从数据包中加载。</param>
 public void Load(Symbol.IO.Packing.TreePackage data)
 {
     _data   = data;
     _left   = TypeExtensions.Convert <int>(_data["left"], 0);
     _top    = TypeExtensions.Convert <int>(_data["top"], 0);
     _right  = TypeExtensions.Convert <int>(_data["right"], 0);
     _bottom = TypeExtensions.Convert <int>(_data["bottom"], 0);
 }
 /// <summary>
 /// 判断表是否存在。
 /// </summary>
 /// <param name="tableName">表名,不带[]等符号。</param>
 /// <param name="schemaName">架构名称,@default由实现者解析为默认值(dbo或数据库名称)</param>
 /// <returns>返回判断结果。</returns>
 public override bool TableExists(string tableName, string schemaName = "@default")
 {
     if (string.IsNullOrEmpty(tableName))
     {
         return(false);
     }
     return(TypeExtensions.Convert <bool>(ExecuteScalar("select 1 from sqlite_master where [name]=@p1", tableName), false));
 }
 public void Add(ConsumeType model)
 {
     using (var builder = _dataContext.CreateInsert("ConsumeType")) {
         builder.Fields.SetValues(model);
         builder.Fields.Remove("Id");
         model.Id = TypeExtensions.Convert <int>(_dataContext.ExecuteScalar(builder.CommandText, builder.Values), 0);
     }
 }
 public bool ExistsUserWithName(string name)
 {
     if (string.IsNullOrEmpty(name))
     {
         return(false);
     }
     return(TypeExtensions.Convert <int>(_dataContext.ExecuteScalar("select [Id] from [User] where [Name]=@p1 limit 0,1", name), 0) > 0);
 }
 public bool ExistsUserWithAccount(string account)
 {
     if (string.IsNullOrEmpty(account))
     {
         return(false);
     }
     return(TypeExtensions.Convert <int>(_dataContext.ExecuteScalar("select [Id] from [User] where [Account]=@p1 limit 0,1", account), 0) > 0);
 }
Exemple #17
0
 /// <summary>
 /// 判断表空间是否存在。
 /// </summary>
 /// <param name="name">名称,不带[]等符号。</param>
 /// <returns>返回判断结果。</returns>
 public override bool TableSpaceExists(string name)
 {
     if (string.IsNullOrEmpty(name))
     {
         return(false);
     }
     return(TypeExtensions.Convert <bool>(ExecuteScalar("select 1 from sys.database_files where [name]=@p1", name), false));
 }
        public bool register(object info)
        {
            LastMoneyResult result = invoke("/user/register/base", new {
                info,
            });

            return(result.success ? TypeExtensions.Convert <bool>(result.data, false) : false);
        }
Exemple #19
0
 T ConvertValue(object value)
 {
     if (typeof(T) == typeof(object))
     {
         return((T)value);
     }
     return(TypeExtensions.Convert <T>(value));
 }
 /// <summary>
 /// 检查指定的系统设置项是否存在
 /// </summary>
 /// <param name="settingName">设置名称</param>
 /// <returns>返回是否存在。注意:若Gouring_Setting表不存在时,直接返回false。</returns>
 public bool SettingExists(string settingName)
 {
     if (_dataContext.TableExists("Gouring_Setting"))
     {
         return(TypeExtensions.Convert <int>(_dataContext.ExecuteScalar("select [Id] from [Gouring_Setting] where [Name]=@p1", settingName), 0) > 0);
     }
     return(false);
 }
Exemple #21
0
 /// <summary>
 /// 判断函数是否存在。
 /// </summary>
 /// <param name="functionName">函数名称,不带[]等符号。</param>
 /// <param name="schemaName">架构名称,@default由实现者解析为默认值(dbo或数据库名称)</param>
 /// <returns>返回判断结果。</returns>
 public override bool FunctionExists(string functionName, string schemaName = "@default")
 {
     if (string.IsNullOrEmpty(functionName))
     {
         return(false);
     }
     return(TypeExtensions.Convert <bool>(ExecuteScalar("select 1 from sysobjects where xtype='fn' and name=@p1", functionName), false));
 }
Exemple #22
0
 /// <summary>
 /// 判断列(字段)是否存在(指定架构)。
 /// </summary>
 /// <param name="tableName">表名,不带[]等符号。</param>
 /// <param name="columnName">列(字段)名,不带[]等符号。</param>
 /// <param name="schemaName">架构名称,@default由实现者解析为默认值(dbo或数据库名称)</param>
 /// <returns></returns>
 public override bool ColumnExists(string tableName, string columnName, string schemaName = "@default")
 {
     if (string.IsNullOrEmpty(tableName) || string.IsNullOrEmpty(columnName))
     {
         return(false);
     }
     return(TypeExtensions.Convert <bool>(ExecuteScalar("select 1 from syscolumns where id=object_id(@p1) and name=@p2", tableName, columnName), false));
 }
Exemple #23
0
 /// <summary>
 /// 判断表是否存在(指定架构)。
 /// </summary>
 /// <param name="tableName">表名,不带[]等符号。</param>
 /// <param name="schemaName">架构名称,@default由实现者解析为默认值(dbo或数据库名称)</param>
 /// <returns>返回判断结果。</returns>
 public override bool TableExists(string tableName, string schemaName = "@default")
 {
     if (string.IsNullOrEmpty(tableName))
     {
         return(false);
     }
     return(TypeExtensions.Convert <bool>(ExecuteScalar("select 1 from sysobjects where id=object_id(@p1)", tableName), false));
 }
        public bool user_exists(object condition)
        {
            LastMoneyResult result = invoke("/user/exists", new {
                condition,
            });

            return(result.success ? TypeExtensions.Convert <bool>(result.data, false) : false);
        }
Exemple #25
0
 /// <summary>
 /// 获取表空间的位置
 /// </summary>
 /// <param name="name">名称,不带[]等符号。</param>
 /// <returns></returns>
 public override string GetTableSpacePath(string name)
 {
     if (string.IsNullOrEmpty(name))
     {
         return(TypeExtensions.Convert <string>(ExecuteScalar("select top 1 [physical_name] from sys.database_files")));
     }
     return(TypeExtensions.Convert <string>(ExecuteScalar("select top 1 [physical_name] from sys.database_files where [name]=@p1", name)));
 }
Exemple #26
0
 public override object Invoke(object[] args)
 {
     if (args[0] == null)
     {
         return(null);
     }
     return(TypeExtensions.Convert <DateTime?>(args[0]));
 }
Exemple #27
0
    /// <summary>
    /// 判断current的值是否包含value(逻辑操作: (current &amp; value)==value  )
    /// </summary>
    /// <param name="current">当前值</param>
    /// <param name="value">判断值</param>
    /// <returns>返回是否包含在内。</returns>
    public static bool HasFlag2(
#if !net20
        this
#endif
        Enum current, long value)
    {
        return(HasFlag2(TypeExtensions.Convert <long>(current), value));
    }
Exemple #28
0
    /// <summary>
    /// 判断current的值是否包含value(逻辑操作: (current &amp; value)==value  )
    /// </summary>
    /// <param name="current">当前值</param>
    /// <param name="value">判断值</param>
    /// <returns>返回是否包含在内。</returns>
    public static bool HasFlag2(
#if !net20
        this
#endif
        long current, Enum value)
    {
        return(HasFlag2(current, TypeExtensions.Convert <long>(value)));
    }
Exemple #29
0
    /// <summary>
    /// 将当前枚举的值,变成数组,通常用于多值的枚举。比如将 Abc.A | Abc.B 变成Abc[]{ Abc.A,Abc.B }。
    /// </summary>
    /// <typeparam name="T">任意枚举类型。</typeparam>
    /// <param name="value">当前枚举值。</param>
    /// <returns>返回一个值的数组。</returns>
    public static T[] ToValues <T>(
#if !net20
        this
#endif
        T value) where T : Enum
    {
        string[] values = value.ToString().Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
        return(TypeExtensions.Convert <T[]>(values));
    }
 /// <summary>
 /// 判断表空间是否存在。
 /// </summary>
 /// <param name="name">名称,不带[]等符号。</param>
 /// <returns>返回判断结果。</returns>
 public override bool TableSpaceExists(string name)
 {
     if (string.IsNullOrEmpty(name))
     {
         return(false);
     }
     name = Connection?.DatabaseName + "_" + name;
     return(TypeExtensions.Convert <bool>(ExecuteScalar("select 1 from pg_tablespace where spcname=@p1;", name), false));
 }