枚举常用方法示例
1、可扩展枚举配置方法
在对应UI项目WebPart类的Extend文件 AfterCreateChildControls()方法中增加以下代码
针对卡片容器中的控件设置可扩展枚举代码
//参数1为当前界面,参数2为文本显示控件名,参数3为下拉输入控件名
UFIDA.U9.UI.PDHelper.UDC.Refresh(this, this.lblCust_DemandType31, this.Cust_DemandType31);
针对表格容器中的栏位设置可扩展枚举代码
// 参数1为对应的表格控件容器,参数2为枚举类型字段名
UFIDA.U9.UI.PDHelper.UDC.Refresh(this.DataGrid***, "***");
2、如何获取枚举名称
场景-数据库:
获取枚举名称:select dbo.F_GetEnumName('UFIDA.U9.MO.Enums.MOStateEnum',2,'zh-cn')
select [dbo].SN_FN_GetEnumName(1002006072100009,'UFIDA.U9.CBO.SCM.Enums.FreeTypeEnum',1)
获取枚举编码:select dbo.sqlF_Sys_GetEnumCode('UFIDA.U9.CBO.Enums.DemandCodeEnum',枚举值(0,1,2…))
场景-打印:
使用函数GetEnumName;举例:GetEnumName('UFIDA.U9.Base.Doc.BusinessTypeEnum',UFIDA::U9::MO::Issue::IssueDoc.IssueDocType.BusinessType)。第一个参数为数据字段Classview查询出的枚举名称,第二个参数为枚举值(1,2,3这种)
场景-代码:
枚举类.EnumRes.GetResource(枚举项编码-Code)));
枚举类.EnumRes.GetResourceByValue(枚举项值Value)));
3、有枚举项编码/名称/ID值,如何获取枚举Value值
ExtEnumValue extEnum = ExtEnumValue.Find(string.Format("ExtEnumType.Code='{0}' and Code='{1}'", “UFIDA.U9.CBO.Enums.DemandCodeEnum","01"));//参数1为枚举类全名,参数2为枚举项编码值
int enumValue=extEnum.Value;
4、报表参数-枚举如何配置
根据枚举全名(数据字段查找实体下枚举全名)查找出枚举ID,
declare @FN varchar(550),
@ClsID bigint,
@UID varchar(50)
select @FN='UFIDA.U9.MO.Enums.MOStateEnum' --此处只需填入你要更新的枚举FullName,示例为标准产品的业务员类型枚举
select @ClsID=Local_ID,@UID=ID from UBF_MD_Class where FullName = @FN and ClassType=3
SELECT @UID
在报表参数中,选择参照类型为Enumerator,枚举ID输入以上查询出的枚举ID,输入UBF中的枚举ID输入框中,点击加载即可
5、新建枚举后,界面不显示枚举项如何解决?
原因:由于新建枚举后,枚举类及枚举项未同步枚举表及枚举值表,因此需要手工同步(打补丁方式可以忽略此问题,会自动同步)
解决方案:执行以下脚本,替换找@FN参数值,修改为对应的枚举类命名即可
--同步单个枚举
declare @FN varchar(550), @ClsID bigint, @UID varchar(50) select @FN='枚举全名称,到BE模型中去复制'
--此处只需填入你要更新的枚举FullName,示例为标准产品的业务员类型枚举
select @ClsID=Local_ID,@UID=ID from UBF_MD_Class where FullName = '枚举全名称,到BE模型中去复制' and ClassType=3 select @ClsID,@UID
--先删除已有的数据
delete from UBF_Sys_ExtEnumType_Trl where ID=@ClsID or ID in (select ID from ubf_sys_extenumtype where UID=@UID)
delete from ubf_sys_extenumtype where ID=@ClsID or UID=@UID delete from UBF_Sys_ExtEnumValue_Trl
where ID in (select ID from ubf_sys_extenumvalue where ExtEnumType=@ClsID or ExtEnumTypeUID=@UID)
delete from ubf_sys_extenumvalue where ExtEnumType=@ClsID or ExtEnumTypeUID=@UID
--下面为插入最新数据
insert into ubf_sys_extenumtype select local_id as id,'20150601','admin','20150601','admin',0,fullname as code,isextend,id as uid,0 from ubf_md_class
where Local_ID = @ClsID insert into ubf_sys_extenumtype_trl select a.local_id as id,'zh-CN',b.[displayname] as [name],b.[Description] from ubf_md_class a
left join ubf_RES_resourcevalue b on cast(a.[iD] as varchar(50)) = cast(b.resourcename as varchar(50)) where Local_ID = @ClsID
insert into ubf_sys_extenumvalue select a.local_id as id,'20150601','admin','20150601','admin',0,a.[Local_Class_ID] as ExtEnumType , a.[name] as code,
a.defaultvalue as evalue,issystem,md_class_id as ExtEnumTypeUID from ubf_md_attribute as a
inner join ubf_md_class as b on cast(a.md_class_id as varchar(50))=cast(b.id as varchar(50)) where b.Local_ID = @ClsID
insert into ubf_sys_extenumvalue_trl select a.local_id as id,'zh-CN',c.[displayname] as [name] from ubf_md_attribute as a
inner join ubf_md_class as b on cast(a.md_class_id as varchar(50))=cast(b.id as varchar(50))
left join ubf_RES_resourcevalue c on cast(a.[ID] as varchar(50)) = cast(c.resourcename as varchar(50)) where b.Local_ID = @ClsID
枚举常用方法示例
本文2024-08-20 17:53:30发表“u9cloud知识”栏目。
本文链接:https://wenku.my7c.com/article/yonyou-u9cloud-1177.html