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); } }
internal static void SetVariable(DataPersistance dp, string ModuleName, string VarName, object Value) { AppVariable Var = new AppVariable(); Var.ModuleName = ModuleName; Var.VarName = VarName; Var.VarValue = string.Empty; if (Value == null) { Var.BinValue = null; } else { Type tp = Value.GetType(); if (tp == typeof(string) || tp == typeof(decimal) || tp == typeof(DateTime) || tp == typeof(int) || tp == typeof(Single) || tp == typeof(bool)) { Var.VarValue = BaseUtility.ConvertToString(Value); } else if (tp == typeof(Bitmap)) { Var.BinValue = Helper.ConvertImageToByteArray( (Image)Value); } else { Var.BinValue = (byte[])Value; } } Var.Save(dp, false, false); }
public void SetVariable(string VarName, object Value) { foreach (AppVariable Var in ListVar) { if (Var.VarName.Equals(VarName)) { Var.VarValue = string.Empty; if (Value == null) { Var.BinValue = null; } else { Type tp = Value.GetType(); if (tp == typeof(string) || tp == typeof(decimal) || tp == typeof(DateTime) || tp == typeof(int) || tp == typeof(Single) || tp == typeof(bool)) { Var.VarValue = BaseUtility.ConvertToString(Value); } else if (tp == typeof(Bitmap)) { Var.BinValue = Helper.ConvertImageToByteArray((Image)Value); } else { Var.BinValue = (byte[])Value; } break; } return; } } AppVariable NewVar = new AppVariable(); NewVar.ModuleName = ModuleName; NewVar.VarName = VarName; NewVar.VarValue = string.Empty; if (Value == null) { NewVar.BinValue = null; } else { Type tp = Value.GetType(); if (tp == typeof(string) || tp == typeof(decimal) || tp == typeof(DateTime) || tp == typeof(int) || tp == typeof(Single) || tp == typeof(bool)) { NewVar.VarValue = BaseUtility.ConvertToString(Value); } else if (tp == typeof(Bitmap)) { NewVar.BinValue = Helper.ConvertImageToByteArray((Image)Value); } else { NewVar.BinValue = (byte[])Value; } } ListVar.Add(NewVar); }