public static class CommonUtil{/// <summary>/// 显示表单/// </summary>/// <param name="view"></param>/// <param name="panelKey"></param>/// <returns></returns>public static void ShowForm(this IDynamicFormView view, string formId, string panelKey = null, string pageId = null, Action<FormResult> callback = null, Action<DynamicFormShowParameter> showParaCallback = null){DynamicFormShowParameter showPara = new DynamicFormShowParameter();showPara.PageId = string.IsNullOrWhiteSpace(pageId) ? Guid.NewGuid().ToString() : pageId;showPara.ParentPageId = view.PageId;if (string.IsNullOrWhiteSpace(panelKey)){showPara.OpenStyle.ShowType = ShowType.Default;}else{showPara.OpenStyle.ShowType = ShowType.InContainer;showPara.OpenStyle.TagetKey = panelKey;}showPara.FormId = formId;showPara.OpenStyle.CacheId = pageId;if (showParaCallback != null){showParaCallback(showPara);}view.ShowForm(showPara, callback);}/// <summary>/// 显示列表/// </summary>/// <param name="view"></param>/// <param name="formId"></param>/// <param name="listType"></param>/// <param name="bMultiSel"></param>/// <param name="callback"></param>public static void ShowList(this IDynamicFormView view, string formId, BOSEnums.Enu_ListType listType, bool bMultiSel = true, string filter = "", Action<ListShowParameter> showPara = null, Action<FormResult> callback = null){ListShowParameter listShowPara = new ListShowParameter();listShowPara.FormId = formId;listShowPara.PageId = Guid.NewGuid().ToString();listShowPara.ParentPageId = view.PageId;listShowPara.MultiSelect = bMultiSel;listShowPara.ListType = (int)listType;if (listType == BOSEnums.Enu_ListType.SelBill){listShowPara.IsLookUp = true;}listShowPara.ListFilterParameter.Filter = listShowPara.ListFilterParameter.Filter.JoinFilterString(filter);listShowPara.IsShowUsed = true;listShowPara.IsShowApproved = false;if (showPara != null) showPara(listShowPara);view.ShowForm(listShowPara, callback);}/// <summary>/// 设置某个实体整体可用性/// </summary>/// <param name="view"></param>/// <param name="entityKey"></param>/// <param name="bEnabled"></param>public static void SetEntityEnabled(this IDynamicFormView view, string entityKey, bool bEnabled){EntityAppearance entityAp = view.LayoutInfo.GetEntityAppearance(entityKey);if (entityAp == null) return;foreach (var ap in entityAp.Layoutinfo.Controls){view.StyleManager.SetEnabled(ap, null, bEnabled);}}/// <summary>/// 设置行可用性/// </summary>/// <param name="view"></param>/// <param name="entityKey"></param>/// <param name="row"></param>/// <param name="bEnabled"></param>/// <param name="exceptFieldkeys"></param>public static void SetEntityRowEnabled(this IDynamicFormView view, string entityKey, int row, bool bEnabled, IEnumerable<string> exceptFieldkeys = null){Entity entity = view.BillBusinessInfo.GetEntity(entityKey);DynamicObject rowObj = view.Model.GetEntityDataObject(entity, row);SetEntityRowEnabled(view, entityKey, rowObj, bEnabled, exceptFieldkeys);}/// <summary>/// 设置行可用性/// </summary>/// <param name="view"></param>/// <param name="entityKey"></param>/// <param name="rowObject"></param>/// <param name="bEnabled"></param>/// <param name="exceptFieldkeys"></param>public static void SetEntityRowEnabled(this IDynamicFormView view, string entityKey, DynamicObject rowObject, bool bEnabled, IEnumerable<string> exceptFieldkeys = null){if (exceptFieldkeys == null) exceptFieldkeys = new string[] { };foreach (Field field in (from o in view.BillBusinessInfo.GetEntryEntity(entityKey).Fieldswhere !exceptFieldkeys.Contains(o.Key)select o).ToList<Field>()){view.StyleManager.SetEnabled(field, rowObject, null, bEnabled);}}/// <summary>/// 设置工具条整体可用状态/// </summary>/// <param name="view"></param>/// <param name="bEnabled">可用性</param>/// <param name="barOwnerKey">工具条拥有者标识,单据主工具条不用传值,表格工具条请传表格标识,其它独立工具条请传工具条标识</param>public static void SetBarEnabled(this IDynamicFormView view, bool bEnabled, string barOwnerKey = ""){if (string.IsNullOrWhiteSpace(barOwnerKey)){FormAppearance formAppearance = view.LayoutInfo.GetFormAppearance();if (((formAppearance.Menu != null) && !string.IsNullOrWhiteSpace(formAppearance.Menu.Id)) && (formAppearance.ShowMenu == 1)){foreach (var item in formAppearance.Menu.GetAllBarItems()){view.SetBarItemEnabled(item.Key, bEnabled, barOwnerKey);}}}else{EntryEntityAppearance appearance3 = view.LayoutInfo.GetEntryEntityAppearance(barOwnerKey);if ((appearance3 != null) && (appearance3.Menu != null)){foreach (var item in appearance3.Menu.GetAllBarItems()){view.SetBarItemEnabled(item.Key, bEnabled, barOwnerKey);}}ToolBarCtrlAppearance appearance4 = view.LayoutInfo.GetToolbarCtrlAppearances().FirstOrDefault(o => o.Key == barOwnerKey);if ((appearance4 != null) && (appearance4.Menu != null)){foreach (var item in appearance4.Menu.GetAllBarItems()){view.SetBarItemEnabled(item.Key, bEnabled, barOwnerKey);}}}}/// <summary>/// 设置按钮可用状态/// </summary>/// <param name="view"></param>/// <param name="barItemKey">按钮标识</param>/// <param name="bEnabled">可用性</param>/// <param name="barOwnerKey">工具条拥有者标识,单据主工具条不用传值,表格工具条请传表格标识,其它独立工具条请传工具条标识</param>public static void SetBarItemEnabled(this IDynamicFormView view, string barItemKey, bool bEnabled, string barOwnerKey = ""){Appearance ap = null;if (!string.IsNullOrWhiteSpace(barOwnerKey))ap = view.LayoutInfo.GetAppearance(barOwnerKey);BarItemControl barItem = null;if (ap == null){barItem = view.GetMainBarItem(barItemKey);if (barItem != null){barItem.Enabled = bEnabled;}}foreach (var entityAp in view.LayoutInfo.GetEntityAppearances()){if (entityAp is HeadEntityAppearance || entityAp is SubHeadEntityAppearance) continue;if (barOwnerKey.IsNullOrEmptyOrWhiteSpace() || entityAp.Key.EqualsIgnoreCase(barOwnerKey)){barItem = view.GetBarItem(entityAp.Key, barItemKey);if (barItem != null){barItem.Enabled = bEnabled;}}}}/// <summary>/// 设置按钮可见状态/// </summary>/// <param name="view"></param>/// <param name="barItemKey">按钮标识</param>/// <param name="bVisible">可见性</param>/// <param name="barOwnerKey">工具条拥有者标识,单据主工具条不用传值,表格工具条请传表格标识,其它独立工具条请传工具条标识</param>public static void SetBarItemVisible(this IDynamicFormView view, string barItemKey, bool bVisible, string barOwnerKey = ""){Appearance ap = null;if (!string.IsNullOrWhiteSpace(barOwnerKey))ap = view.LayoutInfo.GetAppearance(barOwnerKey);BarItemControl barItem = null;if (ap == null){barItem = view.GetMainBarItem(barItemKey);}else{barItem = view.GetBarItem(ap.Key, barItemKey);}if (barItem != null){barItem.Visible = bVisible;}}/// <summary>/// 更新可视元素宽度/// </summary>/// <param name="formState"></param>/// <param name="key"></param>/// <param name="width"></param>public static void UpdateColumnWidth(this IDynamicFormView view, ControlAppearance gridAp, string colKey, int width){IDynamicFormState formState = view.GetService<IDynamicFormState>();//SetFieldPropValue(formState, ctlAp.Key, "width", width, -1);SetColumnPropValue(formState, gridAp, colKey, "width", width);}public static void UpdateColumnHeader(this IDynamicFormView view, ControlAppearance gridAp, string colKey, string header){IDynamicFormState formState = view.GetService<IDynamicFormState>();SetColumnPropValue(formState, gridAp, colKey, "header", header);}private static void SetFieldPropValue(IDynamicFormState formState, string key, string propName, object value, int rowIndex){JSONObject obj2 = formState.GetControlProperty(key, -1, propName) as JSONObject;if (obj2 == null){obj2 = new JSONObject();}obj2[rowIndex.ToString()] = value;formState.SetControlProperty(key, rowIndex, propName, obj2);}private static void SetColumnPropValue(IDynamicFormState formState, ControlAppearance ctlAp, string colKey, string propName, object value){JSONObject obj2 = new JSONObject();obj2["key"] = colKey;obj2[propName] = value;formState.InvokeControlMethod(ctlAp, "UpdateFieldStates", new object[] { obj2 });}/// <summary>/// 移动表格分录/// </summary>/// <param name="view"></param>/// <param name="entityKey"></param>/// <param name="iSrcRowIndex"></param>/// <param name="iDstRowIndex"></param>/// <param name="callback"></param>public static void MoveEntryRow(this IDynamicFormView view, string entityKey, int iSrcRowIndex, int iDstRowIndex,Action<int,int> callback=null){EntryEntity entryEntity = view.BillBusinessInfo.GetEntryEntity(entityKey);DynamicObjectCollection dataEntities = view.Model.GetEntityDataObject(entryEntity);if (iSrcRowIndex < 0 || iSrcRowIndex >= dataEntities.Count) return;if (iDstRowIndex < 0 || iDstRowIndex >= dataEntities.Count) return;var srcRow = dataEntities[iSrcRowIndex];var dstRow = dataEntities[iDstRowIndex];            if (iSrcRowIndex > iDstRowIndex){dataEntities.RemoveAt(iSrcRowIndex);dataEntities.Insert(iDstRowIndex, srcRow);}else{dataEntities.RemoveAt(iDstRowIndex);dataEntities.Insert(iSrcRowIndex, dstRow);}EntryGrid grid = view.GetControl<EntryGrid>(entityKey);grid.ExchangeRowIndex(iSrcRowIndex, iDstRowIndex);grid.SetFocusRowIndex(iDstRowIndex);if (callback != null){callback(iSrcRowIndex, iDstRowIndex);}}#region 实现块粘贴的填充功能/// <summary>/// 处理Excel块粘贴功能/// </summary>/// <param name="view"></param>/// <param name="e"></param>/// <param name="bAllowAutoNewRows">允许自动新增行</param>/// <param name="bCanPaste">是否允许填充某字段</param>public static void PasteBlockData(this IDynamicFormView view, EntityBlockPastingEventArgs e, bool bAllowAutoNewRows = false, Func<FieldAppearance, int, bool> bCanPaste = null){if (e.BlockValue.IsNullOrEmptyOrWhiteSpace()) return;FieldAppearance startFieldAp = view.LayoutInfo.GetFieldAppearance(e.StartKey);if (startFieldAp == null || (startFieldAp.Field.Entity is EntryEntity) == false) return;EntryEntity entryEntity = (EntryEntity)startFieldAp.Field.Entity;int iTotalRows = view.Model.GetEntryRowCount(entryEntity.Key);var copyOperation = view.BillBusinessInfo.GetForm().FormOperations.FirstOrDefault(o => o.OperationId == 31 && string.Equals(o.Parmeter.OperationObjectKey, entryEntity.Key, StringComparison.InvariantCultureIgnoreCase));bool isCopyLinkEntry = false;//如果表格未配置复制行操作,则不允许自动新增行if (copyOperation == null){bAllowAutoNewRows = false;}else{isCopyLinkEntry = GetIsCopyLinkEntryParam(copyOperation.Parmeter);}string[] strBlockDataRows = e.BlockValue.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);int iRow = e.StartRow;foreach (var rowData in strBlockDataRows){if (iRow >= iTotalRows){if (bAllowAutoNewRows){view.Model.CopyEntryRow(entryEntity.Key, iRow - 1, iRow, isCopyLinkEntry);}else{break;}}string[] strItemValues = rowData.Split(new char[] { '\t' });FieldAppearance fieldAp = startFieldAp;foreach (var value in strItemValues){if (fieldAp == null) continue;object objValue = value;if (typeof(ValueType).IsAssignableFrom(fieldAp.Field.GetPropertyType())){if (value.IsNullOrEmptyOrWhiteSpace()){objValue = 0;}else{ValueTypeConverter converter = new ValueTypeConverter();if (value != null && converter.CanConvertTo(value.GetType())){objValue = converter.ConvertTo(value, fieldAp.Field.GetPropertyType());}}}if (bCanPaste == null || bCanPaste(fieldAp, iRow)){(view as IDynamicFormViewService).UpdateValue(fieldAp.Key, iRow, objValue);}fieldAp = GetNextEditFieldAp(view, fieldAp, iRow);}iRow++;}}private static FieldAppearance GetNextEditFieldAp(IDynamicFormView view, FieldAppearance fieldAp, int iRow){FieldAppearance nextFieldAp = null;if (fieldAp != null){EntryEntityAppearance entryEntityAp = view.LayoutInfo.GetEntryEntityAppearance(fieldAp.EntityKey);if (entryEntityAp != null){DynamicObject rowData = view.Model.GetEntityDataObject(entryEntityAp.Entity, iRow);int iStartFindPos = entryEntityAp.Layoutinfo.Appearances.IndexOf(fieldAp);if (iStartFindPos >= 0){for (int i = iStartFindPos + 1; i < entryEntityAp.Layoutinfo.Appearances.Count; i++){nextFieldAp = entryEntityAp.Layoutinfo.Appearances[i] as FieldAppearance;if (nextFieldAp == null) continue;//跳过不可见或不可编辑的字段if (nextFieldAp.IsLocked(view.OpenParameter.Status) == true|| nextFieldAp.IsVisible(view.OpenParameter.Status) == false) continue;//单元格锁定也不填充if (rowData != null && view.StyleManager.GetEnabled(fieldAp, rowData) == false) continue;break;}}}}return nextFieldAp;}private static bool GetIsCopyLinkEntryParam(OperationParameter operationParameter){bool flag = false;string expressValue = operationParameter.ExpressValue;if (!string.IsNullOrEmpty(expressValue)){string[] strArray = expressValue.Split(new char[] { ':' });if (strArray.Length == 2){flag = Convert.ToInt32(strArray[1]) == 1;}}return flag;} #endregion}

上述代码是一个独立的类,可以放到任何工程里用,是金蝶二开中一组常用的扩展方法,设置行,单元格,菜单等元素的可见性,可用性。

转载于:https://www.cnblogs.com/fyq891014/p/4188780.html

开放一些常见功能的工具类代码相关推荐

  1. 采用itextpdf 实现java的PDF生成与导出功能,含封装工具类代码

    引入jar包 <dependency><groupId>com.itextpdf</groupId><artifactId>itextpdf</a ...

  2. JAVA WEB之XSS防御工具类代码示例

    简述 人们经常将跨站脚本攻击(Cross Site Scripting)缩写为CSS,但这会与层叠样式表(Cascading Style Sheets,CSS)的缩写混淆.因此,有人将跨站脚本攻击缩写 ...

  3. 【Android 内存优化】Bitmap 内存缓存 ( Bitmap 内存复用 | 弱引用 | 引用队列 | 针对不同 Android 版本开发不同的 Bitmap 复用策略 | 工具类代码 )

    文章目录 一.Bitmap 复用池 二.弱引用 Bitmap 内存释放 三.从 Bitmap 复用池中获取对应可以被复用的 Bitmap 对象 1.Android 2.3.3(API 级别 10)及以 ...

  4. jdbc封装工具类代码_JDBC的使用-JDBC(3)

    光有理论,没有实践是不行的,本篇文章就是介绍JDBC如何使用. 本文知识点分布如下: 下载数据库驱动 创建项目添加驱动 通过 Statement 向表中插入数据 通过 Statement 对象修改表中 ...

  5. android开发:播放音频功能的工具类

    播放音频功能的工具类 /*** 播放声音工具类* creator: ZZF* careate date: 2018/5/25 10:36.*/public class SoundUtils {priv ...

  6. 【Android 内存优化】Bitmap 内存缓存 ( Bitmap 缓存策略 | LruCache 内存缓存 | LruCache 常用操作 | 工具类代码 )

    文章目录 一.Bitmap 内存缓存策略 二.LruCache 内存缓存 三.LruCache 常用操作 四.LruCache 工具类 五.源码及资源下载 官方参考 : Google 官方提供的 内存 ...

  7. cookie工具类 java_springboot封装JsonUtil,CookieUtil工具类代码实例

    这篇文章主要介绍了springboot封装JsonUtil,CookieUtil工具类过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 Jso ...

  8. android 属性动画实例,Android 属性动画Animator工具类代码案例

    代码分享-> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ packa ...

  9. 微信模板消息推送(内附工具类代码)

    文章目录 前言 一.添加模板消息 1.进入微信公众号后台 2.模板消息 3.填写信息 4.审核通过后 二.开发步骤 1.依赖坐标 2.实体类 1)AccessToken 2.WxTemplate模板消 ...

最新文章

  1. nero linux iso,NeroLINUX下载_NeroLINUX官方下载_NeroLINUX4.0.0.0-华军软件园
  2. spingboot使用redis连接池报错
  3. iptables日志探秘
  4. 基于java的http服务器
  5. Android实现通用的ActivityGroup(效果类似Android微博客户端主界面),...
  6. 浅谈LTE技术及实际应用方案
  7. iPhone客户端开发笔记(一)
  8. 文末有福利 | 6大理由,告诉你为什么这个大会你不能错过!
  9. C#两路list数组归并去重
  10. 汉字字符编码在线查询的网站
  11. 侙程序错误怎么找c语言,log4j 施用 - 汉字转换成拼音的种(转) - 遏止EditText弹出输入法_169IT.COM...
  12. 2月29日,四年一遇的日子!
  13. vue 使用html2canvas实现图片合成,将两张图片合成一张,并下载海报
  14. 报表同比环比sql笔记
  15. linux下twm切换gn,如何让vnc控制由默认的twm界面改为gnome?
  16. Token的组成部分
  17. keepalived+LVS;keepalived+nginx
  18. Mac 有Alt 键吗?Alt 或 Option 键在 Mac 键盘上的作用是什么
  19. 弘辽科技:拼多多再出“新招”
  20. 45 STM32 IIC主机、从机通信实例(ma51t12b触摸按键芯片)

热门文章

  1. Kafka架构设计:分布式发布订阅消息系统
  2. Console Snacks[摘自Advanced Rails Recipes]
  3. ps里面怎么插入流程图_学会这3个方法,5分钟能绘制出好看又高级的流程图
  4. 使用Runnable配合Thread创建线程
  5. json 取值判断_【收藏级】.NETCore3.1中的Json互操作解读
  6. 办公技巧:EXCEL10个常用函数介绍
  7. 后端技术:Java代码优秀案例,一定对你有提升!
  8. 硬件:断路器、接触器、继电器基础知识
  9. java 布尔表达式_java - 布尔值,条件运算符和自动装箱
  10. 梁兴珍 java_数据结构与算法_Java语言