开放一些常见功能的工具类代码

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/290754.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ios之第一个图形化界面

1、创建ios项目 1、create Xcode ->simpleViewApplication -> input Program name 2、在控制器里面加入代码 我们在viewControl.m里面加上UILabel控件&#xff0c;这个控件和Android 里面的TextView类似&#xff0c;具体代码如下// // ViewController.m // SecondHello…

Memcached简介

在Web服务开发中&#xff0c;服务端缓存是服务实现中所常常采用的一种提高服务性能的方法。其通过记录某部分计算结果来尝试避免再次执行得到该结果所需要的复杂计算&#xff0c;从而提高了服务的运行效率。 除了能够提高服务的运行效率之外&#xff0c;服务端缓存还常常用来提…

JAVA设计模式之门面模式(外观模式)

医院的例子 现代的软件系统都是比较复杂的&#xff0c;设计师处理复杂系统的一个常见方法便是将其“分而治之”&#xff0c;把一个系统划分为几个较小的子系统。如果把医院作为一个子系统&#xff0c;按照部门职能&#xff0c;这个系统可以划分为挂号、门诊、划价、化验、收费、…

里程碑 .Net7再更新,从此彻底碾压Java!

.NET 7 Preview1发布了&#xff0c;没时间实操&#xff1f;先快来看看.NET7的七项重大改进&#xff01;1、不再支持.NET 7应用程序、运行时和SDK的多级查找&#xff08;MLL&#xff09;2、PATH停止向.NET 7运行时和SDK添加32位.NET3、默认情况下&#xff0c; dotnet build/publ…

软件架构知识体系

2019独角兽企业重金招聘Python工程师标准>>> 由于[GOF95]是论述软件模式的著作的第一本&#xff0c;也是OO设计理论著作中最流行的一本&#xff0c;因此有些人常常使用设计模式&#xff08;Design Pattern&#xff09;一词来指所有直接处理软件的架构、设计、程序实…

C语言之最好理解的通过函数指针作为参数实现回调函数

1、函数指针回调解释 回调函数就是一个通过函数指针调用的函数。如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用来调用其所指向的函数时,我们就说这是回调函数 2、代码实现 #include <stdio.h>int sub(int a, int b);int sub1(int a, int b, in…

asp.net 的page 基类页面 做一些判断 可以定义一个基类页面 继承Page类 然后重写OnPreLoad事件...

public class BasePage:Page protected override void OnPreLoad(EventArgs e){ base.OnPreLoad(e); .................. } 这样 就可以在基类页面 统一做一些判断了 转载于:https://www.cnblogs.com/maijin/p/4681871.html

C#不要再使用Npoi啦,使用MiniExcel操作Excel文件更快更高效!

1.简介MiniExcel简单、高效避免OOM的.NET处理Excel查、写、填充数据工具。目前主流框架如Npoi 需要将数据全载入到内存方便操作&#xff0c;但这会导致内存消耗问题。MiniExcel 尝试以 Stream 角度写底层算法逻辑&#xff0c;能让原本1000多MB占用降低到几MB&#xff0c;避免内…

#、%和$符号在OGNL表达式中的作用

#、%和$符号在OGNL表达式中经常出现&#xff0c;而这三种符号也是开发者不容易掌握和理解的部分。在这里笔者简单介绍它们的相应用途。1&#xff0e;#符号的用途一般有三种。 1)访问非根对象属性&#xff0c;例如示例中的#session.msg表达式&#xff0c;由于Struts 2中值栈被…

Android之获取证书文件(pfx格式)的公钥和私钥

1、把pfx证书文件放入sdcard adb push ***.pfx /sdcard/ 2、解析获取公钥和私钥 //证书解析 String path = Environment.getExternalStorageDirectory().getPath() + "/sim_shield.pfx";public static Map<String, byte[]> parsePfx(String pfxPath, String…

go和python切片的不同

2019独角兽企业重金招聘Python工程师标准>>> go有切片slice类型&#xff0c;python有列表和元组&#xff0c;这两种语言都有切片操作。 但是它们的切片操作是完全不同的。 首先说第一个&#xff0c;go的切片&#xff0c;其成员是相同类型的&#xff0c;python的列…

编程算法 - 切割排序 代码(C)

切割排序 代码(C)本文地址: http://blog.csdn.net/caroline_wendy排序切割, 把一个数组分为, 大于k\小于k\等于k的三个部分.能够使用高速排序的Partition函数, 进行处理, 把大于k的放在左边, 小于k的放在右边.使用一个变量记录中间的位置, 则时间复杂度为O(3n/2).代码:/** main…

【C#/.NET】.NET6中全局异常处理

微信公众号&#xff1a;趣编程ACE关注可了解每日一更的.NET日常实战开发技巧&#xff0c;欢迎公众号留言开发 获取源码;.NET6中全局异常处理异常处理是我们在程序开发中不可或缺的一环&#xff0c;下文我将会结合程序Sample讲解如何在.NET6中有效处理异常。Try-Ctach 块包裹自定…

JAVA学习笔记--初识容器类库

一、前言 JAVA中一切皆为对象&#xff0c;因而&#xff0c;持有对象显得尤为重要。 在JAVA中&#xff0c;我们可以通过创建一个对象的引用的方式来持有对象&#xff1a; HoldingObject holding; 也可以创建一个对象数组来持有一组特定类型的对象&#xff1a; HoldingObject hol…

如何保证执行异步方法时不会遗漏 await 关键字

前言在.NET Core 中已经广泛使用异步编程&#xff0c;代码中充斥着大量的 async 和 await 关键字。但有时候&#xff0c;调用一个异步方法时可能会忘了写 await。这会造成什么问题呢&#xff1f;问题重现示例代码如下&#xff1a;[HttpGet] public async Task<IEnumerable&l…

Andorid之打包出现Proguard returned with erro code 1.See console解决办法

1、错误 我们进行签名操作的时候&#xff0c;提示下面错误 Proguard returned with erro code 1.See console 然后在console里面提示这个 you should check if you need to specify additional program jars 2、原因 找不到引用包导致 2、解决办法 我们可以在proguard-projec…

CCF-CSP认证201312-1(出现次数最多的数)

CCF-CSP认证201312-1&#xff08;出现次数最多的数&#xff09; 问题描述   给定n个正整数&#xff0c;找出它们中出现次数最多的数。如果这样的数有多个&#xff0c;请输出其中最小的一个。 输入格式   输入的第一行只有一个正整数n(1 ≤ n ≤ 1000)&#xff0c;表示数字…

Java的原始数据类型一共就8个

Java的原始数据类型一共就8个&#xff0c;分别是&#xff1a;byte、short、int、long、boolean、char、float、double。注意这些是大小写敏感的&#xff0c;而Boolean是boolean的封装类(wrapper class)。 在java中一个类只能有一个直接父类&#xff0c;但是可以实现多个接口&a…

Avalonia跨平台入门第十二篇之动画效果

在前面分享的几篇中咱已经玩耍了Popup、ListBox多选、Grid动态分、RadioButton模板、控件的拖放效果、控件的置顶和置底、控件的锁定、自定义Window样式;今天趁着空闲时间接着去摸索简单的动画效果,毕竟有点动画的东西还是挺有意思的;最终实现的效果如下图:使用了Margin实现左右…

python之解析最简单的xml

1、person.xm文件如下 2、用xml.etree.ElementTree解析person.xml的实现 3、效果如下 4、总结 python里面的list []相当于java里面的list&#xff0c;然后可以改变其中的值。