Article directory
- Kingdee Cloud Starry Sky creates automatic push-down and save public services
-
- Create public method
-
- Push down data by order
- Push down data by detail row
- Call pushdown operation
- Call public method
Kingdee Cloud Starry Sky creates automatic push-down and saves public services
Create public methods
Push down data by order
/// <summary> /// Get the document conversion data package /// </summary> public DynamicObject[] GetBillObjDoPush(Context ctx, string sourceFormId, string targetFormId, List<object> sourceBillIds, string convertId = null, string billTypeId = null) {<!-- --> IConvertService convertService = Kingdee.BOS.App.ServiceHelper.GetService<IConvertService>(); var rules = convertService.GetConvertRules(ctx, sourceFormId, targetFormId); if (rules == null || rules.Count == 0) {<!-- --> throw new KDBusinessException("", string.Format("The enabled conversion rule between {0} and {1} was not found and cannot be automatically pushed down!", sourceFormId, targetFormId)); } ConvertRuleElement rule = null; if (convertId.IsNullOrEmptyOrWhiteSpace()) {<!-- --> rule = rules.FirstOrDefault(t => t.IsDefault); } else {<!-- --> rule = rules.FirstOrDefault(s => s.Id.Equals(convertId)); } if (rule == null) {<!-- --> rule = rules[0]; } List<ListSelectedRow> srcSelectedRows = new List<ListSelectedRow>(); foreach (var billId in sourceBillIds) {<!-- --> srcSelectedRows.Add(new ListSelectedRow(billId.ToString(), string.Empty, 0, sourceFormId)); } string targetBillTypeId = billTypeId == null ? string.Empty : billTypeId; long targetOrgId = 0; Dictionary<string, object> custParams = new Dictionary<string, object>(); PushArgs pushArgs = new PushArgs(rule, srcSelectedRows.ToArray()) {<!-- --> TargetBillTypeId = targetBillTypeId, TargetOrgId = targetOrgId, CustomParams = custParams }; ConvertOperationResult operationResult = convertService.Push(ctx, pushArgs, OperateOption.Create()); DynamicObject[] targetBillObjs = (from p in operationResult.TargetDataEntities select p.DataEntity).ToArray(); if (targetBillObjs.Length == 0) {<!-- --> throw new KDBusinessException("", string.Format("{0} automatically pushed down {1}, no data packet was successfully generated, the automatic push down failed!", sourceFormId, targetFormId)); } return targetBillObjs; }
Push down data by detail row
/// <summary> /// Get the document conversion data package and push down by detail row /// </summary> public DynamicObject[] GetBillObjDoPushByEntryId(Context ctx, string sourceFormId, string targetFormId, IEnumerable<ListSelectedRow> srcSelectedRows, string convertId = null, string billTypeId = null) {<!-- --> IConvertService convertService = Kingdee.BOS.App.ServiceHelper.GetService<IConvertService>(); var rules = convertService.GetConvertRules(ctx, sourceFormId, targetFormId); if (rules == null || rules.Count == 0) {<!-- --> throw new KDBusinessException("", string.Format("The enabled conversion rule between {0} and {1} was not found and cannot be automatically pushed down!", sourceFormId, targetFormId)); } ConvertRuleElement rule = null; if (convertId.IsNullOrEmptyOrWhiteSpace()) {<!-- --> rule = rules.FirstOrDefault(t => t.IsDefault); } else {<!-- --> rule = rules.FirstOrDefault(s => s.Id.Equals(convertId)); } if (rule == null) {<!-- --> rule = rules[0]; } string targetBillTypeId = billTypeId == null ? string.Empty : billTypeId; long targetOrgId = 0; Dictionary<string, object> custParams = new Dictionary<string, object>(); PushArgs pushArgs = new PushArgs(rule, srcSelectedRows.ToArray()) {<!-- --> TargetBillTypeId = targetBillTypeId, TargetOrgId = targetOrgId, CustomParams = custParams }; ConvertOperationResult operationResult = convertService.Push(ctx, pushArgs, OperateOption.Create()); DynamicObject[] targetBillObjs = (from p in operationResult.TargetDataEntities select p.DataEntity).ToArray(); if (targetBillObjs.Length == 0) {<!-- --> throw new KDBusinessException("", string.Format("{0} automatically pushed down {1}, no data packet was successfully generated, the automatic push down failed!", sourceFormId, targetFormId)); } return targetBillObjs; }
Calling pushdown operation
/// <summary> /// Push down operation processing /// </summary> public IOperationResult DoPushOper(Context ctx, DynamicObject[] targetBillObjs, string targetFormId, OperateOption option, IOperationResult billOperationResult, bool isSubmit = false, bool isAudit = false) {<!-- --> IMetaDataService metaService = Kingdee.BOS.App.ServiceHelper.GetService<IMetaDataService>(); var targetBillMeta = metaService.Load(ctx, targetFormId) as FormMetadata; OperateOption saveOption = OperateOption.Create(); saveOption.SetIgnoreWarning(true); saveOption.SetInteractionFlag(option.GetInteractionFlag()); saveOption.SetIgnoreInteractionFlag(option.GetIgnoreInteractionFlag()); try {<!-- --> var saveResult = Kingdee.K3.MFG.App.AppServiceContext.SaveService.Save(ctx, targetBillMeta.BusinessInfo, targetBillObjs, saveOption, "Save"); this.CheckOpResult(saveResult, billOperationResult, saveOption); if (isSubmit & amp; & amp; saveResult.IsSuccess) {<!-- --> saveResult = Kingdee.K3.MFG.App.AppServiceContext.SubmitService.Submit(ctx, targetBillMeta.BusinessInfo, targetBillObjs.Select(s => s["Id"]).ToArray(), "Submit", saveOption); this.CheckOpResult(saveResult, billOperationResult, saveOption); } if (isAudit & amp; & amp; saveResult.IsSuccess) {<!-- --> List<KeyValuePair<object, object>> keyValuePairs = new List<KeyValuePair<object, object>>(); targetBillObjs.ToList().ForEach(item => keyValuePairs.Add(new KeyValuePair<object, object>(item.GetPrimaryKeyValue(), item))); List<object> auditObjs = new List<object>(); auditObjs.Add("1"); auditObjs.Add(""); saveResult = Kingdee.K3.MFG.App.AppServiceContext.SetStatusService.SetBillStatus(ctx, targetBillMeta.BusinessInfo, keyValuePairs, auditObjs, "Audit", saveOption); if (this.CheckOpResult(saveResult, billOperationResult, saveOption)) return saveResult; } return saveResult; } catch (Exception ex) {<!-- --> //string aa = ex.Message; throw new KDBusinessException("", ex.Message); return null; } } /// <summary> /// Determine whether the operation result is successful. If not, throw an error directly to interrupt the process. /// </summary> /// <param name="opResult"></param> /// <returns></returns> private bool CheckOpResult(IOperationResult opResult, IOperationResult operationResult, OperateOption opOption = null, bool isShowError = false) {<!-- --> bool isSuccess = false; if (opResult.IsSuccess) {<!-- --> // Successful operation isSuccess = true; } else {<!-- --> if (opResult.InteractionContext != null & amp; & amp; opResult.InteractionContext.Option.GetInteractionFlag().Count > 0) {<!-- -->// There are interactive prompts // Outgoing interactive prompt complete information object operationResult.InteractionContext = opResult.InteractionContext; // Output the identification of this interaction, // The user will re-enter the operation after confirming to continue; // This will be used to identify whether this interaction has been confirmed to avoid repeated interactions. operationResult.Sponsor = opResult.Sponsor; if (opOption != null) {<!-- --> if(isShowError) throw new KDException("", opResult.InteractionContext.SimpleMessage); else {<!-- --> //throw new KDInteractionException(opOption, opResult.Sponsor); throw new KDException("", ((AbstractInteractionResult)opResult).InteractionContext.SimpleMessage); } } else {<!-- --> // Throw an error and terminate this operation throw new KDBusinessException("", "This operation requires the user to confirm whether to continue and is temporarily suspended"); } } else {<!-- --> // The operation fails, the reason for splicing failure, and then an interrupt is thrown opResult.MergeValidateErrors(); if (opResult.OperateResult == null) {<!-- -->// Submission failed due to unknown reasons throw new KDBusinessException("", "Automatic submission and review failed due to unknown reasons!"); } else {<!-- --> StringBuilder sb = new StringBuilder(); sb.AppendLine("Automatic submission and review failed, failure reason:"); foreach (var operateResult in opResult.OperateResult) {<!-- --> sb.AppendLine(operateResult.Message); } throw new KDBusinessException("", sb.ToString()); } } } return isSuccess; }
Call public methods
List plug-in complete code
using Kingdee.BOS; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.List; using Kingdee.BOS.Core.List.PlugIn; using Kingdee.BOS.Util; using mm.K3.App.Service.Common; using mm.K3.Core.Const; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace mm.K3.SCM.Business.PlugIn.SC {<!-- --> [Description("After-sales order-list interface"), HotUpdate] public class AfterOrderList : AbstractListPlugIn {<!-- --> public override void BarItemClick(BarItemClickEventArgs e) {<!-- --> base.BarItemClick(e); switch (e.BarItemKey.ToUpperInvariant()) {<!-- --> case "XXXX_TBPUSHREPLACE": #region Pushdown comparison XXXX_tbPushReplace #region v3.0 Context ctx = this.View.Context; string sourceFormId = FormIdConst.AS_AfterOrder;//After-sales order string targetFormId = FormIdConst.AS_Replace;//Comparison table string convertRuleKey = "AS_AfterOrderToReplace";//Conversion rules // Get the currently selected row on the list that needs to be pushed down ListSelectedRow[] selectedRows = ((IListView)this.View).SelectedRowsInfo.ToArray(); var action = new ActionCommon(); try {<!-- --> var targetBills = action.GetBillObjDoPushByEntryId(ctx, sourceFormId, targetFormId, selectedRows, convertRuleKey); var result=action.DoPushOper(ctx, targetBills, targetFormId, null, null, false, false);//Do not submit or review //var result = action.DoPushOper(ctx, targetBills, targetFormId, null, null, true, true); //Automatic submission, review if (result.IsSuccess) {<!-- --> string _msg = string.Empty; if (result.OperateResult.Count() > 0) {<!-- --> _msg + = string.Join(",", result.OperateResult.Select(s => s.Message)); } if (!_msg.IsNullOrEmptyOrWhiteSpace()) {<!-- --> this.View.ShowMessage(_msg); } } else {<!-- --> string _msg = string.Empty; if (result.ValidationErrors.Count > 0) {<!-- --> _msg + = string.Join(",", result.ValidationErrors.Select(s => s.Message)); } if (!_msg.IsNullOrEmptyOrWhiteSpace()) {<!-- --> this.View.ShowErrMessage("", _msg, MessageBoxType.Error); } } } catch (Exception ex) {<!-- --> this.View.ShowErrMessage("", "There is an exception when pushing down the comparison: " + ex.Message, MessageBoxType.Error); e.Cancel = true; return; } #endregion #endregion break; } } } }