Exemple #1
0
        internal static TVar GetVariable <TVar>(DataPersistance dp,
                                                string ModuleName, string VarName, TVar DefaultValue)
        {
            AppVariable Var = new AppVariable();

            Var.ModuleName = ModuleName;
            Var.VarName    = VarName;

            if (!dp.LoadEntity(Var, false))
            {
                return(DefaultValue);
            }

            Type tp = typeof(TVar);

            if (tp == typeof(string) ||
                tp == typeof(decimal) ||
                tp == typeof(DateTime) ||
                tp == typeof(int) ||
                tp == typeof(Single) ||
                tp == typeof(bool))
            {
                return(BaseUtility.ConvertFromString <TVar>(
                           (string)Var.VarValue));
            }
            else if (tp == typeof(Image))
            {
                if (Var.BinValue == null)
                {
                    return((TVar)(object)null);
                }
                else
                {
                    return((TVar)(object)Helper.ConvertByteArrayToImage(
                               Var.BinValue));
                }
            }
            else
            {
                return((TVar)(object)Var.BinValue);
            }
        }
Exemple #2
0
        public static TVar GetVariable <TVar>(string ProductName,
                                              string RoleName, string UserName,
                                              string ModuleName, string VarName, TVar DefaultValue)
        {
            RoleUserVariable Var = new RoleUserVariable();

            Var.ProductName = ProductName;
            Var.RoleName    = RoleName;
            Var.UserName    = UserName;
            Var.ModuleName  = ModuleName;
            Var.VarName     = VarName;

            if (!Var.LoadEntity(false))
            {
                return(DefaultValue);
            }

            Type tp = typeof(TVar);

            if (tp == typeof(Image))
            {
                if (Var.BinValue == null)
                {
                    return((TVar)(object)null);
                }
                else
                {
                    return((TVar)(object)Helper.ConvertByteArrayToImage(Var.BinValue));
                }
            }
            else if (tp == typeof(byte[]))
            {
                return((TVar)(object)Var.BinValue);
            }
            else
            {
                return(BaseUtility.ConvertFromString <TVar>(
                           (string)Var.VarValue));
            }
        }
Exemple #3
0
 public TVar GetVariable <TVar>(string VarName, TVar DefaultValue)
 {
     foreach (AppVariable Var in ListVar)
     {
         if (Var.VarName.Equals(VarName))
         {
             Type tp = typeof(TVar);
             if (tp == typeof(string) ||
                 tp == typeof(decimal) ||
                 tp == typeof(DateTime) ||
                 tp == typeof(int) ||
                 tp == typeof(Single) ||
                 tp == typeof(bool))
             {
                 return(BaseUtility.ConvertFromString <TVar>(
                            (string)Var.VarValue));
             }
             else if (tp == typeof(Image))
             {
                 if (Var.BinValue == null)
                 {
                     return((TVar)(object)null);
                 }
                 else
                 {
                     return((TVar)(object)Helper.ConvertByteArrayToImage(Var.BinValue));
                 }
             }
             else
             {
                 return((TVar)(object)Var.BinValue);
             }
         }
     }
     return(DefaultValue);
 }