代码拉取完成,页面将自动刷新
using Kingdee.BOS;
using Kingdee.BOS.App.Core.Utils;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.Operation;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Resource;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using Kingdee.K3.BD.BarCode.ServiceHelper;
using Kingdee.K3.BD.BarCode.Core.DataModel.Service;
using FZ.Plugins;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kingdee.BOS;
using Kingdee.BOS.App.Core.Utils;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using System.Data;
using Kingdee.K3.BD.BarCode.ServiceHelper;
using Kingdee.K3.BD.BarCode.Core.DataModel.Service;
using Kingdee.BOS.Core;
using Kingdee.BOS.KDThread;
using Kingdee.BOS.Core.Bill;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.Interaction;
using Kingdee.BOS.Core.Metadata.FormElement;
using Kingdee.BOS.Orm.Metadata.DataEntity;
using Kingdee.K3.BD.BarCode.Core;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using System.Text.RegularExpressions;
using System.ComponentModel;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.ServiceFacade.KDServiceFx;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.JSON;
/// <summary>
///
/// 宇祥 2019.04.12
/// </summary>
namespace JW.Plugins
{
[Kingdee.BOS.Util.HotUpdate]
[Description("因为现场开发拿去用了,本工程取消此插件。后工序生产报损单 编辑界面插件")]
public class HGX_SCBSD_edit : AbstractBillPlugIn
{
public override void BeforeDoOperation(BeforeDoOperationEventArgs e)
{
if (e.Operation.FormOperation.Operation.Equals("Push"))//下推,反写派工单和状态转换在标准按钮:下推里面做
{
if (this.View.Model.GetValue("FBillStatusShenXiao", 0).ToString().Equals("A"))//如果已经转换过状态证明已经反写过,这里就不处理反写,只下推就好
{
DynamicObjectCollection FEntitys = (DynamicObjectCollection)this.View.Model.DataObject.GetDynamicObjectItemValue<DynamicObjectCollection>("FEntity");
int i_fanXieErrorCount = 0;//F反写派工单异常数据,如果有一行反写异常就标记》0
foreach (DynamicObject FEntity in FEntitys.ToArray())
{
var rkkf = Convert.ToDouble(FEntity["F_PAEZ_Decimal_rkkf"].ToString());//入库宽幅
//var bskf = Convert.ToDouble(FEntity["F_PAEZ_Decimal_bskf"].ToString());//报损宽幅
var bssl = Convert.ToDouble(FEntity["F_PAEZ_Integer_bssl"].ToString());//报损数量
DynamicObjectCollection FEntity_Links = (DynamicObjectCollection)FEntity["FEntity_Link"];
foreach (var link in FEntity_Links)
{
var SourceEntryId = link["SId"].ToString();
var SourceId = link["SBillId"].ToString();
if (!editFQPGD(SourceId, SourceEntryId, rkkf, bssl))
{
i_fanXieErrorCount++;
}
break;
}
}
if (i_fanXieErrorCount > 0)
{
//反写分切派工单拆行失败就取消更新状态
this.View.Model.SetValue("FBillStatusShenXiao", "A");//未生效
this.View.Model.Save();
return;
}
else
{
//反写分切派工单拆行成功就更新状态
this.View.Model.SetValue("FBillStatusShenXiao", "B");//生效
this.View.Model.Save();
}
}
}
base.BeforeDoOperation(e);
}
public override void AfterBarItemClick(AfterBarItemClickEventArgs e)
{
base.AfterBarItemClick(e);
//if (e.BarItemKey.Equals("FSHENGXIAO"))//生效
//{
// DynamicObjectCollection FEntitys = (DynamicObjectCollection)this.View.Model.DataObject.GetDynamicObjectItemValue<DynamicObjectCollection>("FEntity");
// foreach (DynamicObject FEntity in FEntitys.ToArray())
// {
// var rkkf = Convert.ToDouble(FEntity["F_PAEZ_Decimal_rkkf"].ToString());//入库宽幅
// //var bskf = Convert.ToDouble(FEntity["F_PAEZ_Decimal_bskf"].ToString());//报损宽幅
// var bssl = Convert.ToDouble(FEntity["F_PAEZ_Integer_bssl"].ToString());//报损数量
// DynamicObjectCollection FEntity_Links = (DynamicObjectCollection)FEntity["FEntity_Link"];
// foreach (var link in FEntity_Links)
// {
// var SourceEntryId = link["SId"].ToString();
// var SourceId = link["SBillId"].ToString();
// if (!editFQPGD(SourceId, SourceEntryId, rkkf, bssl))
// {
// //反写分切派工单拆行失败就取消更新状态
// this.View.Model.SetValue("FBillStatusShenXiao", "A");
// this.View.Model.Save();
// }
// break;
// }
// }
//}
}
#region 编辑分切派工单
/// <summary>
/// 读取数据,
/// </summary>
public bool editFQPGD(string BillPkId, string sEntryId, double rkkf, double bssl)
{
// 构建一个IBillView实例,通过此实例,可以方便的填写单据各属性
IBillView billView = CreateBilllView(this.Context, "FZO_FQPGD", SessionManager.GetCurrentSession(this.Context.SessionId));
// 新建一个空白单据
//billView.CreateNewModelData();
((IBillViewService)billView).LoadData();
// 触发插件的OnLoad事件:
// 组织控制基类插件,在OnLoad事件中,对主业务组织改变是否提示选项进行初始化。
// 如果不触发OnLoad事件,会导致主业务组织赋值不成功
DynamicFormViewPlugInProxy eventProxy = billView.GetService<DynamicFormViewPlugInProxy>();
eventProxy.FireOnLoad();
// 记载指定的单据进行修改
ModifyBill(billView, BillPkId); // 本代码演示新建物料,把调用修改的代码,注释掉
// 填写单据各属性
FillPropertys(billView, BillPkId, sEntryId, rkkf, bssl);
// 保存单据
OperateOption saveOption = OperateOption.Create();
try
{
OperationResult oResult = SaveBill(billView, saveOption);
if (oResult.ValidationErrors.Count > 0)
{
this.View.ShowOperateResult(oResult.OperateResult);
return false;
}
else
return true;
}
catch (Exception e)
{
return true;
throw e;
}
finally
{
billView.CommitNetworkCtrl();
}
}
/// <summary>
/// 把预交付通知单的各属性,填写到IBillView当前所管理的交付通知单中
/// </summary>
/// <param name="billView"></param>
private void FillPropertys(IBillView billView, string BillPkId, string sEntryId, double rkkf, double bssl)
{
// 把billView转换为IDynamicFormViewService接口:
// 调用IDynamicFormViewService.UpdateValue: 会执行字段的值更新事件
// 调用 dynamicFormView.SetItemValueByNumber :不会执行值更新事件,需要继续调用:
// ((IDynamicFormView)dynamicFormView).InvokeFieldUpdateService(key, rowIndex);
IDynamicFormViewService dynamicFormView = billView as IDynamicFormViewService;
var FEntity = billView.Model.DataObject.GetDynamicObjectItemValue<DynamicObjectCollection>("CutDispatchProductEntry");
//设置表头父项编码
//dynamicFormView.BatchSetItemValueByNumber("FBillId", "STK_MISCELLANEOUS", 0);//
/********************单据体字段******************/
//if (FEntity.Count() > 1)
// billView.Model.BatchCreateNewEntryRow("FEntityToBill", FEntity.Count()); //源单明细
int rowIndex = 0;
foreach (var row in FEntity.ToArray())
{
if (row["Id"].ToString().Equals(sEntryId))
{
//先修改原来的数量
dynamicFormView.UpdateValue("FSecQty", rowIndex, Convert.ToDouble(row["FSecQty"]) - bssl);//旧行的辅助数量-报损数量
// 通过复制的方式,产生新行:确保字段值、关联关系与原行一致
DynamicObject newRowObj = (DynamicObject)row.Clone(false, true);
RelatedFlexGroupField F_PAEZ_Flex = MetaDataServiceHelper.GetFormMetaData(Context, "FZO_FQPGD").BusinessInfo.GetField("FAuxPropId") as RelatedFlexGroupField;
var tF_PAEZ_Flex = new Kingdee.BOS.Orm.DataEntity.DynamicObject(F_PAEZ_Flex.RefFormDynamicObjectType);
tF_PAEZ_Flex = (DynamicObject)newRowObj["FAuxPropId"];
tF_PAEZ_Flex["F100019"] = rkkf;//新好的宽幅为报损单的入库宽幅
newRowObj["FAuxPropId"] = tF_PAEZ_Flex;
// 把新行,插入到单据中,排在当前行之后
FEntity.Insert(rowIndex + 1, newRowObj);
dynamicFormView.UpdateValue("FSecQty", rowIndex + 1, bssl);//新行的辅助数量=报损数量
}
rowIndex++;
//break;
}
int i = 1;
foreach (var row in FEntity.ToArray())
{
row["Seq"] = i ;//重新设置所以的分录seq
i++;
}
}
/// <summary>
/// 保存交付通知单,并显示保存结果
/// </summary>
/// <param name="billView"></param>
/// <returns></returns>
private OperationResult SaveBill(IBillView billView, OperateOption saveOption)
{
OperationResult saveResultAll = new OperationResult();
OperateResult oOperateResult = new OperateResult();
// 设置FormId
Form form = billView.BillBusinessInfo.GetForm();
if (form.FormIdDynamicProperty != null)
{
form.FormIdDynamicProperty.SetValue(billView.Model.DataObject, form.Id);
}
// 调用保存操作
IOperationResult saveResult = BusinessDataServiceHelper.Save(
this.Context,
billView.BillBusinessInfo,
billView.Model.DataObject,
saveOption,
"Save");
// 显示处理结果
if (saveResult == null)
{
saveResultAll = (OperationResult)saveResult;
return saveResultAll;
}
else if (saveResult.IsSuccess == true)
{// 保存成功,直接显示
saveResultAll = (OperationResult)saveResult;
return saveResultAll;
}
else if (saveResult.InteractionContext != null
&& saveResult.InteractionContext.Option.GetInteractionFlag().Count > 0)
{// 保存失败,需要用户确认问题
InteractionUtil.DoInteraction(billView, saveResult, saveOption,
new Action<FormResult, IInteractionResult, OperateOption>((
formResult, opResult, option) =>
{
// 用户确认完毕,重新调用保存处理
this.SaveBill(billView, option);
}));
}
// 保存失败,显示错误信息
if (saveResult.IsShowMessage)
{
saveResult.MergeValidateErrors();
//baseView.ShowOperateResult(saveResult.OperateResult);
saveResultAll = (OperationResult)saveResult;
return saveResultAll;
}
saveResultAll = (OperationResult)saveResult;
return saveResultAll;
}
/// <summary>
/// 创建一个单据视图,后续将利用此视图的各种方法,设置单据字段值
/// </summary>
/// <remarks>
/// 理论上,也可以直接修改单据的数据包达成修改数据的目的
/// 但是,利用单据视图更具有优势:
/// 1. 视图会自动触发插件,这样逻辑更加完整;
/// 2. 视图会自动利用单据元数据,填写字段默认值,不用担心字段值不符合逻辑;
/// 3. 字段改动,会触发实体服务规则;
/// 而手工修改数据包的方式,所有的字段值均需要自行填写,非常麻烦
/// </remarks>
private static IBillView CreateBilllView(Context ctx, string formId, KDServiceSession Current, string pkValue = null)
{
// 读取单据的元数据
FormMetadata meta = MetaDataServiceHelper.Load(ctx, formId) as FormMetadata;
Form form = meta.BusinessInfo.GetForm();
// 创建用于引入数据的单据view
Type type = Type.GetType("Kingdee.BOS.Web.Base.BaseView,Kingdee.BOS.Web");//Import.ImportBillView
var billView = (IDynamicFormViewService)Activator.CreateInstance(type);
// 开始初始化billView:
// 创建视图加载参数对象,指定各种参数,如FormId, 视图(LayoutId)等
BillOpenParameter openParam = CreateOpenParameter(meta, ctx, Current, pkValue);
// 动态领域模型服务提供类,通过此类,构建MVC实例
var provider = form.GetFormServiceProvider();
billView.Initialize(openParam, provider);
return billView as IBillView;
}
/// <summary>
/// 创建视图加载参数对象,指定各种初始化视图时,需要指定的属性
/// </summary>
/// <param name="meta">元数据</param>
/// <returns>视图加载参数对象</returns>
private static BillOpenParameter CreateOpenParameter(FormMetadata meta, Context ctx, KDServiceSession Current, string pkValue = null)
{
Form form = meta.BusinessInfo.GetForm();
// 指定FormId, LayoutId
BillOpenParameter openParam = new BillOpenParameter(form.Id, meta.GetLayoutInfo().Id);
// 数据库上下文
openParam.Context = ctx;
// 本单据模型使用的MVC框架
openParam.ServiceName = form.FormServiceName;
// 随机产生一个不重复的PageId,作为视图的标识
openParam.PageId = Guid.NewGuid().ToString();
// 元数据
openParam.FormMetaData = meta;
// 界面状态:新增 (修改、查看)
if (pkValue == null)
{
openParam.Status = OperationStatus.ADDNEW;
}
else openParam.Status = OperationStatus.EDIT;
// 单据主键:本案例演示新建单据,不需要设置主键
openParam.PkValue = pkValue;
// 界面创建目的:普通无特殊目的 (为工作流、为下推、为复制等)
openParam.CreateFrom = CreateFrom.Default;
// 基础资料分组维度:基础资料允许添加多个分组字段,每个分组字段会有一个分组维度
// 具体分组维度Id,请参阅 form.FormGroups 属性
openParam.GroupId = "";
// 基础资料分组:如果需要为新建的基础资料指定所在分组,请设置此属性
openParam.ParentId = 0;
// 单据类型
openParam.DefaultBillTypeId = "";
// 业务流程
openParam.DefaultBusinessFlowId = "";
// 主业务组织改变时,不用弹出提示界面
openParam.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false);
openParam.SetCustomParameter("SessionManager", Current);
// 插件
List<AbstractDynamicFormPlugIn> plugs = form.CreateFormPlugIns();
openParam.SetCustomParameter(FormConst.PlugIns, plugs);
PreOpenFormEventArgs args = new PreOpenFormEventArgs(ctx, openParam);
foreach (var plug in plugs)
{// 触发插件PreOpenForm事件,供插件确认是否允许打开界面
plug.PreOpenForm(args);
}
if (args.Cancel == true)
{// 插件不允许打开界面
// 本案例不理会插件的诉求,继续....
}
// 返回
return openParam;
}
/// <summary>
/// 加载指定的单据进行修改
/// </summary>
/// <param name="billView"></param>
/// <param name="pkValue"></param>
private static void ModifyBill(IBillView billView, string pkValue)
{
billView.OpenParameter.Status = OperationStatus.EDIT;
billView.OpenParameter.CreateFrom = CreateFrom.Default;
billView.OpenParameter.PkValue = pkValue;
billView.OpenParameter.DefaultBillTypeId = string.Empty;
((IDynamicFormViewService)billView).LoadData();
}
#endregion
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。