using System; using System.Data; using System.Collections; using BP.DA; using BP.En; using BP.Sys; namespace BP.Cloud.Sys { /// /// sss /// public class SysEnumMainAttr : EntityNoNameAttr { /// /// 配置的值 /// public const string CfgVal = "CfgVal"; /// /// 语言 /// public const string Lang = "Lang"; /// /// 组织结构编码 /// public const string OrgNo = "OrgNo"; /// /// 真实的编号 /// public const string EnumKey = "EnumKey"; public const string IsHaveDtl = "IsHaveDtl"; public const string AtPara = "AtPara"; } /// /// SysEnumMain /// public class SysEnumMain : EntityNoName { #region 实现基本的方方法 /// /// 配置的值 /// public string CfgVal { get { return this.GetValStrByKey(SysEnumMainAttr.CfgVal); } set { this.SetValByKey(SysEnumMainAttr.CfgVal, value); } } /// /// 语言 /// public string Lang { get { return this.GetValStrByKey(SysEnumMainAttr.Lang); } set { this.SetValByKey(SysEnumMainAttr.Lang, value); } } /// /// 枚举值 /// public string EnumKey { get { return this.GetValStrByKey(SysEnumMainAttr.EnumKey); } set { this.SetValByKey(SysEnumMainAttr.EnumKey, value); } } /// /// 枚举值 /// public string OrgNo { get { return this.GetValStrByKey(SysEnumMainAttr.OrgNo); } set { this.SetValByKey(SysEnumMainAttr.OrgNo, value); } } #endregion #region 构造方法 /// /// SysEnumMain /// public SysEnumMain() { } /// /// SysEnumMain /// /// public SysEnumMain(string no) { try { this.No = no; this.Retrieve(); } catch (Exception ex) { SysEnums ses = new SysEnums(no); if (ses.Count == 0) throw ex; this.No = no; this.Name = "未命名"; string cfgVal = ""; foreach (SysEnum item in ses) { cfgVal += "@" + item.IntKey + "=" + item.Lab; } this.CfgVal = cfgVal; this.Insert(); } } protected override bool beforeDelete() { // 检查这个类型是否被使用? MapAttrs attrs = new MapAttrs(); QueryObject qo = new QueryObject(attrs); qo.AddWhere(MapAttrAttr.UIBindKey, this.No); int i = qo.DoQuery(); if (i == 0) { //删除数据. SysEnums ses = new SysEnums(); ses.Delete(BP.Sys.SysEnumAttr.EnumKey, this.EnumKey, BP.Sys.SysEnumAttr.OrgNo, BP.Web.WebUser.OrgNo); } else { string msg = "错误:下列数据已经引用了枚举您不能删除它。"; // "错误:下列数据已经引用了枚举您不能删除它。"; foreach (MapAttr attr in attrs) msg += "\t\n" + attr.Field + "" + attr.Name + " Table = " + attr.FK_MapData; //抛出异常,阻止删除. throw new Exception(msg); } return base.beforeDelete(); } /// /// Map /// public override Map EnMap { get { if (this._enMap != null) return this._enMap; Map map = new Map("Sys_EnumMain", "枚举"); /* * 为了能够支持cloud 我们做了如下变更. * 1. 增加了OrgNo, EnumKey 字段. * 2. 如果是单机版用户,原来的业务逻辑不变化. * 3. 如果是SAAS模式, No= EnumKey+"_"+OrgNo */ map.AddTBStringPK(SysEnumMainAttr.No, null, "编号", true, false, 1, 100, 8); map.AddTBString(SysEnumMainAttr.Name, null, "名称", true, false, 0, 40, 8); map.AddTBString(SysEnumMainAttr.CfgVal, null, "配置信息", true, false, 0, 1500, 8); map.AddTBString(SysEnumMainAttr.Lang, "CH", "语言", true, false, 0, 10, 8); //枚举值. map.AddTBString(SysEnumMainAttr.EnumKey, null, "EnumKey", true, false, 0, 40, 8); map.AddTBInt(SysEnumMainAttr.IsHaveDtl, 0, "是否有子集?", true, false); //组织编号. map.AddTBString(SysEnumMainAttr.OrgNo, null, "OrgNo", true, false, 0, 100, 8); //参数. map.AddTBString(SysEnumMainAttr.AtPara, null, "AtPara", true, false, 0, 200, 8); this._enMap = map; return this._enMap; } } #endregion #region 业务操作。 public string DoInitDtls() { if (DataType.IsNullOrEmpty(this.CfgVal) == true) return "err@SysEnumMain没有cfg数据."; //首先删除原来的数据. SysEnums ses = new SysEnums(); ses.Delete(SysEnumAttr.EnumKey, this.No); //创建对象. SysEnum se = new SysEnum(); //CfgVal = @0=病假@1=事假 string[] strs = this.CfgVal.Split('@'); foreach (string str in strs) { string[] kvs = str.Split('='); se.EnumKey = this.No; se.IntKey = int.Parse(kvs[0]); se.Lab = kvs[1].Trim(); se.Lang = "CH"; se.Insert(); // se.setMyPK(this.No+"_"+se } return "执行成功."; } #endregion 业务操作。 } /// /// 纳税人集合 /// public class SysEnumMains : EntitiesNoName { /// /// SysEnumMains /// public SysEnumMains() { } /// /// 得到它的 Entity /// public override Entity GetNewEntity { get { return new SysEnumMain(); } } /// /// 查询所有枚举值,根据不同的运行平台. /// /// public override int RetrieveAll() { // 返回他组织下的数据. return this.Retrieve(SysEnumMainAttr.OrgNo, BP.Web.WebUser.OrgNo); } #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((SysEnumMain)this[i]); } return list; } #endregion 为了适应自动翻译成java的需要,把实体转换成List. } }