开放一些常见功能的工具类代码
来源:互联网 发布:js控制div显示和隐藏 编辑:程序博客网 时间:2024/05/26 19:16
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).Fields where !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 }上述代码是一个独立的类,可以放到任何工程里用,是金蝶二开中一组常用的扩展方法,设置行,单元格,菜单等元素的可见性,可用性。
0 0
- 开放一些常见功能的工具类代码
- 常见的一些代码
- 一些注册表监控工具默认监控的一些常见项及其功能
- java-API类的一些不常见功能
- android常见的一些工具类的方法
- 【sublime代码编辑工具】 sublime 代码编辑软件的一些常用功能和快捷键
- 时间工具类,一些常见的时间实现方法
- 常见的一些功能测试用例
- 常见的一些功能测试用例
- 一些常见的web小功能
- 配置管理的功能和常见工具
- “开放”的一些感想
- linux下的一些工具功能总结
- 一些常见又好用的代码
- 一些常见的JS表单验证代码
- 国内常见的一些代码托管平台
- 我的开放代码
- Android代码中自己写的一些工具类(整理)
- 目标--connect world,ZMQ源码详细解析 之 进程内通信流程
- 动态表单 - 加载与关闭
- 31HTTP Telnet
- go pprof
- Linux内核源码学习之 内核编译
- 开放一些常见功能的工具类代码
- ACdream原创群赛(18)题解6题
- Python 批量获取Google+用户动态 (分页)
- 在ubuntu14.04上安装sogoupinyin
- SRAM与SDRAM的区别
- Linux3.6.9下AD7490的SPI通信驱动设计
- 博客开张小记
- 动态表单实现客户端二次过滤及字段汇总统计
- leetcode 之 Scramble String