二开案例.表单插件.进度条
【应用场景】
通过进度条,执行长耗时的操作,避免操作超时和界面假死。
【案例演示】
采购订单,新增进度条,演示使用进度条执行批处理。
【实现步骤】
<1>编写表单插件,代码如下。
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.KDThread;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;
using System.Text;
using System.Threading;
namespace Jac.XkDemo.BOS.Business.PlugIn
{
/// <summary>
/// 【表单插件】使用进度条执行批处理
/// </summary>
[Description("【表单插件】使用进度条执行批处理"), HotUpdate]
public class CustomProgressBarFormPlugIn : AbstractDynamicFormPlugIn
{
private const string ProcessRateValue = "ProcessRateValue";
private const string barKey = "F_Jac_ProgressBar";
private const string doKey = "F_Jac_Do";
private const string logKey = "F_Jac_Remarks";
private StringBuilder logs = new StringBuilder();
private ProgressBar progressBar;
public override void OnInitialize(InitializeEventArgs e)
{
base.OnInitialize(e);
progressBar = this.View.GetControl<ProgressBar>(barKey);
progressBar.Visible = false;
}
public override void ButtonClick(ButtonClickEventArgs e)
{
base.ButtonClick(e);
if (e.Key.EqualsIgnoreCase(doKey))
{
DoSthByProgressBar();
}
}
/// <summary>
/// 更新进度
/// </summary>
/// <param name="e"></param>
public override void OnQueryProgressValue(QueryProgressValueEventArgs e)
{
base.OnQueryProgressValue(e);
if (!this.View.Session.ContainsKey(ProcessRateValue))
{
this.View.Session.Add(ProcessRateValue, 0);
}
// 更新进度条
e.Value = (int)this.View.Session[ProcessRateValue];
if (e.Value >= 100)
{
progressBar.Visible = false;
}
}
private void DoSthByProgressBar()
{
this.View.GetControl(doKey).Enabled = false;
this.View.Session[ProcessRateValue] = 0;
// 启动和显示进度条
progressBar.Visible = true;
progressBar.Start(1);
// 启动线程执行耗时操作,同时更新执行进度
logs.Clear();
MainWorker.QuequeTask(this.View.Context, () =>
{
try
{
ShowLog("批量操作开始");
var maxTaskCount = 20;
for (var x = 1; x < maxTaskCount; ++x)
{
ShowLog(string.Format("单据{0}开始创建", x));
// TODO 创建单据
Thread.Sleep(1000);
ShowLog(string.Format("单据{0}完成创建", x));
var rate = Convert.ToInt32(x * 100 / maxTaskCount);
this.View.Session[ProcessRateValue] = rate;
}
ShowLog("批量操作结束");
this.View.ShowMessage("操作已完成。");
}
catch (Exception ex)
{
ShowLog("操作失败:" + ex.Message);
this.View.ShowErrMessage(ex.Message);
}
finally
{
this.View.GetControl(doKey).Enabled = true;
this.View.Session[ProcessRateValue] = 100;
progressBar.Visible = false;
}
}, null);
}
/// <summary>
/// 显示批处理的执行日志
/// </summary>
/// <param name="log"></param>
private void ShowLog(string log)
{
logs.Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append(":").Append(log).AppendLine();
this.Model.SetValue(logKey, logs.ToString());
this.View.UpdateView(logKey);
}
}
}
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE扩展采购订单,新增页签,分割容器,进度条,按钮,多行文本,注册表单插件,保存元数据,开发完毕。
【功能验证】
<1>登录业务站点,打开采购订单新增界面,点击按钮【开始执行】,即可启动进度条。
---------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.表单插件.进度条
本文2024-09-23 03:59:44发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-162421.html