コード例 #1
0
ファイル: BaseBLL.cs プロジェクト: pigeon79/SMErp
        int IBaseBLL.Delete(ND_USER user, IDictionary keys, IDictionary values)
        {
            object key = ClassHelper.ChangeType(keys[KeyName], Ctx.Info.KeyMembers[0].MemberType);
            var    obj = DbEntry.GetObject <T>(key);

            return(ExecuteDelete(user, obj));
        }
コード例 #2
0
        int IExcuteableDataSource.Delete(IDictionary keys, IDictionary values)
        {
            object key = ClassHelper.ChangeType(keys[KeyName], Ctx.Info.KeyMembers[0].MemberType);
            var    obj = DbEntry.GetObject <T>(key);

            return(ExecuteDelete(obj));
        }
コード例 #3
0
ファイル: ControllerHelper.cs プロジェクト: zyj0021/DbEntry
        public static object ChangeType(object value, Type t)
        {
            if (t.IsEnum)
            {
                return(Enum.Parse(t, value.ToString()));
            }
            if (t == typeof(bool))
            {
                if (value == null)
                {
                    return(false);
                }
                switch (value.ToString().ToLower())
                {
                case "on":
                case "true":
                case "1":
                    return(true);

                case "off":
                case "false":
                case "0":
                    return(false);

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            return(ClassHelper.ChangeType(value, t));
        }
コード例 #4
0
ファイル: ClassHelperTest.cs プロジェクト: zyj0021/DbEntry
        public void TestChangeType()
        {
            const string v  = "7:30:30";
            object       iv = ClassHelper.ChangeType(v, typeof(Time));

            Assert.AreEqual("07:30:30", iv.ToString());
        }
コード例 #5
0
        protected T GetRequestObject()
        {
            string sid = Page.Request["Id"];

            if (!string.IsNullOrEmpty(sid))
            {
                object id = ClassHelper.ChangeType(sid, Ctx.Info.KeyMembers[0].MemberType);
                var    o  = DbEntry.GetObject <T>(id);
                if (o == null)
                {
                    throw new DataException("The record doesn't exist.");
                }
                ViewState["Id"] = id;
                var ctx = ModelContext.GetInstance(typeof(T));
                if (ctx.Info.LockVersion != null)
                {
                    var lv = (int)ctx.Info.LockVersion.GetValue(o);
                    if (Page.IsPostBack)
                    {
                        if (lv != ObjectLockVersion)
                        {
                            throw new DataException("The version of record was changed.");
                        }
                    }
                    else
                    {
                        ObjectLockVersion = lv;
                    }
                }
                return(o);
            }
            return(default(T));
        }
コード例 #6
0
 protected object ChangeType(string s, Type t)
 {
     if (t.IsValueType && string.IsNullOrEmpty(s))
     {
         return(Util.GetEmptyValue(t));
     }
     return(ClassHelper.ChangeType(s, t));
 }
コード例 #7
0
ファイル: TypeBinder.cs プロジェクト: zyj0021/DbEntry
        private object ProcessSimpleNullableType(string name, Type type)
        {
            var value = HttpContextHandler.Instance[name];

            if (value.IsNullOrEmpty())
            {
                return(null);
            }
            return(ClassHelper.ChangeType(value, type));
        }
コード例 #8
0
 private static object GetObject(object o, Type t)
 {
     if (o == DBNull.Value || t == o.GetType())
     {
         return(o);
     }
     if (t.IsGenericType)
     {
         return(ClassHelper.ChangeType(o, t.GetGenericArguments()[0]));
     }
     return(ClassHelper.ChangeType(o, t));
 }
コード例 #9
0
ファイル: ConfigHelperBase.cs プロジェクト: zyj0021/DbEntry
        public object GetValue(string key, object defaultValue)
        {
            string s = GetString(key);

            if (s == null)
            {
                return(defaultValue);
            }
            Type t = defaultValue.GetType();

            if (t.IsSubclassOf(typeof(Enum)))
            {
                return(Enum.Parse(t, s));
            }
            return(ClassHelper.ChangeType(s, t));
        }
コード例 #10
0
    private static object GetValue(Dictionary <string, string> map, string key, object defaultValue)
    {
        string s = GetString(map, key);

        if (s == null)
        {
            return(defaultValue);
        }
        Type t = defaultValue.GetType();

        if (t.IsSubclassOf(typeof(Enum)))
        {
            return(Enum.Parse(t, s));
        }
        return(ClassHelper.ChangeType(s, t));
    }
コード例 #11
0
ファイル: PageHelper.cs プロジェクト: leohsu91/DbEntry
 private static object GetObject(object obj, ModelContext ctx, Page p, string parseErrorText)
 {
     EnumControls(p, ctx.Info, delegate(MemberHandler h, WebControl c)
     {
         string v = GetValue(c);
         if (h.MemberType.IsEnum)
         {
             var n = (int)Enum.Parse(h.MemberType, v);
             h.SetValue(obj, n);
         }
         else
         {
             if (string.IsNullOrEmpty(v))
             {
                 if (h.Is.AllowNull)
                 {
                     h.SetValue(obj, null);
                 }
                 else
                 {
                     if (h.MemberType == typeof(string))
                     {
                         h.SetValue(obj, "");
                     }
                     else if (!h.Is.CreatedOn && !h.Is.SavedOn)
                     {
                         throw new WebControlException(c, string.Format(parseErrorText, h.ShowString, ""));
                     }
                 }
             }
             else
             {
                 try
                 {
                     object iv = ClassHelper.ChangeType(v, h.MemberType);
                     h.SetValue(obj, iv);
                 }
                 catch (Exception ex)
                 {
                     throw new WebControlException(c, string.Format(parseErrorText, h.ShowString, ex.Message));
                 }
             }
         }
     });
     return(obj);
 }
コード例 #12
0
ファイル: DbEntryDataSource.cs プロジェクト: pigeon79/SMErp
        protected virtual T CreateObject(IDictionary keys, IDictionary values)
        {
            T      obj;
            object key = null;

            if (keys != null)
            {
                key = ClassHelper.ChangeType(keys[KeyName], Ctx.Info.KeyMembers[0].MemberType);
            }
            if (key == null || key.Equals(Ctx.Info.KeyMembers[0].UnsavedValue))
            {
                obj = (T)Ctx.NewObject();
            }
            else
            {
                obj = DbEntry.GetObject <T>(key);
            }
            foreach (MemberHandler mh in Ctx.Info.SimpleMembers)
            {
                string name = mh.MemberInfo.IsProperty ? mh.MemberInfo.Name : mh.Name;
                if (name != KeyName)
                {
                    if (values.Contains(name))
                    {
                        object ov = values[name];
                        object mo;
                        if (ov != null)
                        {
                            mo = ClassHelper.ChangeType(ov.ToString(), mh.MemberType);
                        }
                        else
                        {
                            mo = !mh.Is.AllowNull ? "" : null;
                        }
                        object ho = mh.GetValue(obj);
                        if (!Util.AreEqual(ho, mo))
                        {
                            mh.SetValue(obj, mo);
                        }
                    }
                }
            }
            return(obj);
        }
コード例 #13
0
 internal static object GetValue(string s, bool allowEmpty, string name, Type type)
 {
     if (string.IsNullOrEmpty(s))
     {
         if (!allowEmpty)
         {
             throw new WebException(string.Format("The Parameter {0} can't be empty", name));
         }
         if (type.IsValueType)
         {
             if (type.IsGenericType)
             {
                 return(null);
             }
             return(Util.GetEmptyValue(type));
         }
     }
     return(ClassHelper.ChangeType(s, type));
 }
コード例 #14
0
ファイル: TypeBinder.cs プロジェクト: zyj0021/DbEntry
 private static void UpdateSimpleMembers(object obj, ModelContext ctx)
 {
     foreach (var field in ctx.Info.SimpleMembers)
     {
         if (!field.Is.Key)
         {
             var value = HttpContextHandler.Instance[field.MemberInfo.Name];
             if (value != null || field.MemberType == typeof(bool))
             {
                 if (value == "" && field.Is.AllowNull)
                 {
                     field.SetValue(obj, null);
                 }
                 else
                 {
                     field.SetValue(obj, ClassHelper.ChangeType(value, field.MemberType));
                 }
             }
         }
     }
 }
コード例 #15
0
ファイル: DbColumnInfo.cs プロジェクト: sfltd/DbEntry
        public DbColumnInfo(DataRow dr)
        {
            Type t   = typeof(DbColumnInfo);
            var  fis = t.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);

            foreach (FieldInfo fi in fis)
            {
                Util.CatchAll(
                    delegate {
                    object o = dr[fi.Name];
                    if (o == DBNull.Value)
                    {
                        o = null;
                    }
                    if (o != null && fi.FieldType != typeof(Type) && o.GetType() != fi.FieldType)
                    {
                        o = ClassHelper.ChangeType(o, fi.FieldType);
                    }
                    fi.SetValue(this, o);
                });
            }
        }
コード例 #16
0
ファイル: TypeBinder.cs プロジェクト: zyj0021/DbEntry
        protected virtual object ProcessOtherType(string name, Type type)
        {
            var obj = ClassHelper.CreateInstance(type);

            foreach (var info in type.GetFields(BindingFlags.Instance | BindingFlags.Public))
            {
                var value = HttpContextHandler.Instance[info.Name];
                if (!value.IsNullOrEmpty())
                {
                    var av = ClassHelper.ChangeType(value, info.FieldType);
                    info.SetValue(obj, av);
                }
            }
            foreach (var info in type.GetProperties())
            {
                var value = HttpContextHandler.Instance[info.Name];
                if (!value.IsNullOrEmpty())
                {
                    var av = ClassHelper.ChangeType(value, info.PropertyType);
                    info.SetValue(obj, av, null);
                }
            }
            return(obj);
        }
コード例 #17
0
ファイル: TypeBinder.cs プロジェクト: zyj0021/DbEntry
        protected virtual object ProcessSimpleType(string name, Type type)
        {
            var value = HttpContextHandler.Instance[name];

            return(ClassHelper.ChangeType(value, type));
        }
コード例 #18
0
ファイル: ClassHelperTest.cs プロジェクト: zyj0021/DbEntry
        public void TestChangeType2()
        {
            var n = ClassHelper.ChangeType(null, typeof(DateTime?));

            Assert.IsNull(n);
        }