using System;
using System.Collections;
using BP.DA;
using BP.En;
namespace BP.Sys
{
///
/// 全局变量
///
public class GloVarAttr : EntityNoNameAttr
{
///
/// Val
///
public const string Val = "Val";
///
/// Note
///
public const string Note = "Note";
///
/// GroupKey
///
public const string GroupKey = "GroupKey";
///
/// 顺序号
///
public const string Idx = "Idx";
}
///
/// 全局变量
///
public class GloVar : EntityNoName
{
#region 属性
public object ValOfObject
{
get
{
return this.GetValByKey(GloVarAttr.Val);
}
set
{
this.SetValByKey(GloVarAttr.Val, value);
}
}
public string Val
{
get
{
return this.GetValStringByKey(GloVarAttr.Val);
}
set
{
this.SetValByKey(GloVarAttr.Val, value);
}
}
public float ValOfFloat
{
get
{
try
{
return this.GetValFloatByKey(GloVarAttr.Val);
}
catch
{
return 0;
throw new Exception("@" + this.Name + ", 没有设置默认值." + this.Val);
}
}
set
{
this.SetValByKey(GloVarAttr.Val, value);
}
}
public int ValOfInt
{
get
{
try
{
return this.GetValIntByKey(GloVarAttr.Val);
}
catch (Exception ex)
{
return 0;
throw new Exception("@" + this.Name + ", 没有设置默认值." + this.Val);
}
}
set
{
this.SetValByKey(GloVarAttr.Val, value);
}
}
public decimal ValOfDecimal
{
get
{
try
{
return this.GetValDecimalByKey(GloVarAttr.Val);
}
catch
{
return 0;
throw new Exception("@" + this.Name + ", 没有设置默认值." + this.Val);
}
}
set
{
this.SetValByKey(GloVarAttr.Val, value);
}
}
public bool ValOfBoolen
{
get
{
return this.GetValBooleanByKey(GloVarAttr.Val);
}
set
{
this.SetValByKey(GloVarAttr.Val, value);
}
}
///
/// note
///
public string Note
{
get
{
return this.GetValStringByKey(GloVarAttr.Note);
}
set
{
this.SetValByKey(GloVarAttr.Note, value);
}
}
public int Idx
{
get
{
return this.GetValIntByKey(GloVarAttr.Idx);
}
set
{
this.SetValByKey(GloVarAttr.Idx, value);
}
}
///
/// 分组值
///
public string GroupKey
{
get
{
return this.GetValStringByKey(GloVarAttr.GroupKey);
}
set
{
this.SetValByKey(GloVarAttr.GroupKey, value);
}
}
#endregion
#region 构造方法
///
/// 全局变量
///
public GloVar()
{
}
///
/// 全局变量
///
///
public GloVar(string no)
{
this.No = no;
this.Retrieve();
}
///
/// 键值
///
/// key
///
public GloVar(string key, object isNullAsVal)
{
try
{
this.No = key;
this.Retrieve();
}
catch
{
if (this.RetrieveFromDBSources() == 0)
{
this.Val = isNullAsVal.ToString();
this.Insert();
}
}
}
///
/// EnMap
///
public override Map EnMap
{
get
{
if (this._enMap != null)
return this._enMap;
Map map = new Map("Sys_GloVar", "全局变量");
map.AddTBStringPK(GloVarAttr.No, null, "键", true, false, 1, 50, 20);
map.AddTBString(GloVarAttr.Name, null, "名称", true, false, 0, 120, 20);
map.AddTBString(GloVarAttr.Val, null, "值", true, false, 0, 4000, 20, true);
map.AddTBString(GloVarAttr.GroupKey, null, "分组值", true, false, 0, 120, 20, true);
map.AddTBStringDoc(GloVarAttr.Note, null, "说明", true, false, true);
map.AddTBInt(GloVarAttr.Idx, 0, "顺序号", true, true);
this._enMap = map;
return this._enMap;
}
}
#endregion
#region 公共属性.
///
/// 公共假期
///
private static string _Holidays = null;
///
/// 一个月份的假期.
///
public static string Holidays
{
get
{
if (_Holidays != null)
return _Holidays;
GloVar en = new GloVar();
en.No = "Holiday";
int i = en.RetrieveFromDBSources();
if (i == 0)
_Holidays = "";
else
_Holidays = en.Val;
return _Holidays;
}
set
{
_Holidays = value;
}
}
#endregion
}
///
/// 全局变量s
///
public class GloVars : EntitiesNoName
{
#region get value by key
///
/// 设置配置文件
///
/// key
/// val
public static int SetValByKey(string key, object val)
{
GloVar en = new GloVar(key, val);
en.ValOfObject = val;
return en.Update();
}
///
/// 获取html数据
///
///
///
public static string GetValByKeyHtml(string key)
{
return DataType.ParseText2Html(GloVars.GetValByKey(key));
}
public static string GetValByKey(string key)
{
foreach (GloVar cfg in GloVars.MyGloVars)
{
if (cfg.No == key)
return cfg.Val;
}
throw new Exception("error key=" + key);
}
///
/// 得到,一个key.
///
///
///
public static string GetValByKey(string key, string isNullAs)
{
foreach (GloVar cfg in GloVars.MyGloVars)
{
if (cfg.No == key)
return cfg.Val;
}
GloVar en = new GloVar(key, isNullAs);
//GloVar en = new GloVar(key);
return en.Val;
}
public static int GetValByKeyInt(string key, int isNullAs)
{
foreach (GloVar cfg in GloVars.MyGloVars)
{
if (cfg.No == key)
return cfg.ValOfInt;
}
GloVar en = new GloVar(key, isNullAs);
//GloVar en = new GloVar(key);
return en.ValOfInt;
}
public static int GetValByKeyDecimal(string key, int isNullAs)
{
foreach (GloVar cfg in GloVars.MyGloVars)
{
if (cfg.No == key)
return cfg.ValOfInt;
}
GloVar en = new GloVar(key, isNullAs);
//GloVar en = new GloVar(key);
return en.ValOfInt;
}
public static bool GetValByKeyBoolen(string key, bool isNullAs)
{
foreach (GloVar cfg in GloVars.MyGloVars)
{
if (cfg.No == key)
return cfg.ValOfBoolen;
}
int val = 0;
if (isNullAs)
val = 1;
GloVar en = new GloVar(key, val);
return en.ValOfBoolen;
}
public static float GetValByKeyFloat(string key, float isNullAs)
{
foreach (GloVar cfg in GloVars.MyGloVars)
{
if (cfg.No == key)
return cfg.ValOfFloat;
}
GloVar en = new GloVar(key, isNullAs);
return en.ValOfFloat;
}
private static GloVars _MyGloVars = null;
public static GloVars MyGloVars
{
get
{
if (_MyGloVars == null)
{
_MyGloVars = new GloVars();
_MyGloVars.RetrieveAll();
}
return _MyGloVars;
}
}
public static void ReSetVal()
{
_MyGloVars = null;
}
#endregion
#region 风格处理.
#endregion
#region 构造
///
/// 全局变量s
///
public GloVars()
{
}
///
/// 全局变量s
///
/// s
public GloVars(string fk_mapdata)
{
if (BP.Difference.SystemConfig.IsDebug)
this.Retrieve(MapAttrAttr.FK_MapData, fk_mapdata);
else
this.RetrieveFromCash(MapAttrAttr.FK_MapData, (object)fk_mapdata);
}
///
/// 得到它的 Entity
///
public override Entity GetNewEntity
{
get
{
return new GloVar();
}
}
#endregion
#region 为了适应自动翻译成java的需要,把实体转换成List.
///
/// 转化成 java list,C#不能调用.
///
/// List
public System.Collections.Generic.IList ToJavaList()
{
return (System.Collections.Generic.IList)this;
}
///
/// 转化成list
///
/// List
public System.Collections.Generic.List Tolist()
{
System.Collections.Generic.List list = new System.Collections.Generic.List();
for (int i = 0; i < this.Count; i++)
{
list.Add((GloVar)this[i]);
}
return list;
}
#endregion 为了适应自动翻译成java的需要,把实体转换成List.
}
}