二开案例.表单插件.进度条

【应用场景】
通过进度条,执行长耗时的操作,避免操作超时和界面假死。
【案例演示】
采购订单,新增进度条,演示使用进度条执行批处理。

【实现步骤】
<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;
二开案例.表单插件.进度条
声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。



