如何优化3Cloud表格控件块中的粘贴代码逻辑?

2026-05-20 21:051阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计582个文字,预计阅读时间需要3分钟。

如何优化3Cloud表格控件块中的粘贴代码逻辑?

在EntityBlockPasting插件事件中,您可以自定义处理逻辑,并将cancel属性设置为true。以下是一个简化的代码示例,说明如何修改插件代码以适应您的需求:

javascript// 假设这是EntityBlockPasting事件的处理器function handleEntityBlockPasting(event) { // 在这里添加您的自定义逻辑 // 例如,检查某些条件 if (this.View.Busin && this.View.Busin.someProperty) { // 执行一些操作 // ...

如何优化3Cloud表格控件块中的粘贴代码逻辑?

// 如果需要取消粘贴操作,设置cancel为true event.cancel=true; }}

// 将cancel属性设置为truehandleEntityBlockPasting.prototype.cancel=true;

请根据实际情况调整上述代码,确保它符合您的插件代码结构和逻辑。注意,代码中`this.View.Busin`和`this.View.Busin.someProperty`需要替换为实际的对象和属性,以便正确执行条件检查。

大家可以在表单插件EntityBlockPasting事件中自己处理,然后将cancel设置为true。以下代码可以参考一下,插件代码中需要将其中一些属性或方法修改,例如this.BusinessInfo替换为this.View.BusinessInfo,UpdateValue替换为this.View.Model.SetValue,this.StyleManager替换为((IDynamicFormView)this.View).StyleManager

/// <summary> /// 块拷贝 /// </summary> /// <param name="startKey"></param> /// <param name="startRow"></param> /// <param name="blockValue"></param> public void EntityBlockPasting(string startKey, int startRow, string blockValue) { if (!blockValue.IsNullOrEmptyOrWhiteSpace()) { EntityBlockPastingEventArgs args = new EntityBlockPastingEventArgs(startKey, startRow, blockValue); this.EventsProxy.FireEntityBlockPasting(args); if (args.Cancel) { return; } Field fd = this.BusinessInfo.GetField(startKey); if (fd == null) return; int entityRowCount = this.Model.GetEntryRowCount(fd.EntityKey); string[] rowValues = blockValue.Split('\n'); int blockRowCount = rowValues.Length-1; if (blockRowCount > entityRowCount) { // 当前实体行数不足,补齐行数据 for (int i = entityRowCount; i < blockRowCount; i++) { this.Model.CreateNewEntryRow(fd.EntityKey); } } Dictionary<int, string> fieldKeyList = new Dictionary<int, string>(); int row = startRow; foreach (string strValue in rowValues) { if (strValue.IsNullOrEmpty()) { // 最后空行结束 return; } string[] strs = strValue.Split('\t'); int fieldCount = strs.Length; SetFieldKeyList(startKey, fd, fieldKeyList); if (fieldKeyList.Count == 0) { // 可能找不到列,则返回 return; } int index = 0; foreach (string str in strs) { string key = fieldKeyList[index]; // 未锁定状态下更新数据,锁定跳过 if (this.StyleManager.GetEnabled(this.LayoutInfo.GetFieldAppearance(key))) { this.UpdateValue(fieldKeyList[index], row, str); } index++; } row++; } } } private void SetFieldKeyList(string startKey, Field fd, Dictionary<int, string> fieldKeyList) { if (fieldKeyList.Count > 0) { return; } int start = 0; List<Field> fields = new List<Field>(); fields.AddRange(fd.Entity.Fields); fields.Sort(new Comparison<Field>((x, y) => { return x.Tabindex.CompareTo(y.Tabindex); })); foreach (Field f in fields) { if (startKey.EqualsIgnoreCase(f.Key)) { fieldKeyList[start++] = f.Key; continue; } if (start > 0) { // 可见的列才被用来粘贴 if (this.StyleManager.GetVisible(this.LayoutInfo.GetFieldAppearance(f.Key))) { fieldKeyList[start++] = f.Key; continue; } } } }

本文共计582个文字,预计阅读时间需要3分钟。

如何优化3Cloud表格控件块中的粘贴代码逻辑?

在EntityBlockPasting插件事件中,您可以自定义处理逻辑,并将cancel属性设置为true。以下是一个简化的代码示例,说明如何修改插件代码以适应您的需求:

javascript// 假设这是EntityBlockPasting事件的处理器function handleEntityBlockPasting(event) { // 在这里添加您的自定义逻辑 // 例如,检查某些条件 if (this.View.Busin && this.View.Busin.someProperty) { // 执行一些操作 // ...

如何优化3Cloud表格控件块中的粘贴代码逻辑?

// 如果需要取消粘贴操作,设置cancel为true event.cancel=true; }}

// 将cancel属性设置为truehandleEntityBlockPasting.prototype.cancel=true;

请根据实际情况调整上述代码,确保它符合您的插件代码结构和逻辑。注意,代码中`this.View.Busin`和`this.View.Busin.someProperty`需要替换为实际的对象和属性,以便正确执行条件检查。

大家可以在表单插件EntityBlockPasting事件中自己处理,然后将cancel设置为true。以下代码可以参考一下,插件代码中需要将其中一些属性或方法修改,例如this.BusinessInfo替换为this.View.BusinessInfo,UpdateValue替换为this.View.Model.SetValue,this.StyleManager替换为((IDynamicFormView)this.View).StyleManager

/// <summary> /// 块拷贝 /// </summary> /// <param name="startKey"></param> /// <param name="startRow"></param> /// <param name="blockValue"></param> public void EntityBlockPasting(string startKey, int startRow, string blockValue) { if (!blockValue.IsNullOrEmptyOrWhiteSpace()) { EntityBlockPastingEventArgs args = new EntityBlockPastingEventArgs(startKey, startRow, blockValue); this.EventsProxy.FireEntityBlockPasting(args); if (args.Cancel) { return; } Field fd = this.BusinessInfo.GetField(startKey); if (fd == null) return; int entityRowCount = this.Model.GetEntryRowCount(fd.EntityKey); string[] rowValues = blockValue.Split('\n'); int blockRowCount = rowValues.Length-1; if (blockRowCount > entityRowCount) { // 当前实体行数不足,补齐行数据 for (int i = entityRowCount; i < blockRowCount; i++) { this.Model.CreateNewEntryRow(fd.EntityKey); } } Dictionary<int, string> fieldKeyList = new Dictionary<int, string>(); int row = startRow; foreach (string strValue in rowValues) { if (strValue.IsNullOrEmpty()) { // 最后空行结束 return; } string[] strs = strValue.Split('\t'); int fieldCount = strs.Length; SetFieldKeyList(startKey, fd, fieldKeyList); if (fieldKeyList.Count == 0) { // 可能找不到列,则返回 return; } int index = 0; foreach (string str in strs) { string key = fieldKeyList[index]; // 未锁定状态下更新数据,锁定跳过 if (this.StyleManager.GetEnabled(this.LayoutInfo.GetFieldAppearance(key))) { this.UpdateValue(fieldKeyList[index], row, str); } index++; } row++; } } } private void SetFieldKeyList(string startKey, Field fd, Dictionary<int, string> fieldKeyList) { if (fieldKeyList.Count > 0) { return; } int start = 0; List<Field> fields = new List<Field>(); fields.AddRange(fd.Entity.Fields); fields.Sort(new Comparison<Field>((x, y) => { return x.Tabindex.CompareTo(y.Tabindex); })); foreach (Field f in fields) { if (startKey.EqualsIgnoreCase(f.Key)) { fieldKeyList[start++] = f.Key; continue; } if (start > 0) { // 可见的列才被用来粘贴 if (this.StyleManager.GetVisible(this.LayoutInfo.GetFieldAppearance(f.Key))) { fieldKeyList[start++] = f.Key; continue; } } } }