K3Cloud系統整合實現下推單據轉換呼叫
阿新 • • 發佈:2018-12-11
- //服務端外掛程式碼
- //銷售退貨單 下推 應收單 服務端程式碼(Cloud5.0)
- //新建立.net 工程
- //引用元件 Kingdee.BOS.dll、Kingdee.BOS.Core.dll、Kingdee.BOS.DataEntity.dll、Kingdee.BOS.App.dll、Kingdee.BOS.Contracts.dll
- //wanghl 2015-03-24
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.ComponentModel;
- using System.Data;
- using Kingdee.BOS.Core.DynamicForm.PlugIn;
- using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
- using Kingdee.BOS.Core.DynamicForm;
- using Kingdee.BOS.Core.Metadata.ConvertElement;
- using Kingdee.BOS.Core.List;
- using Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs;
- using Kingdee.BOS.Core.DynamicForm.Operation;
- using Kingdee.BOS.App;
- using Kingdee.BOS.Contracts;
- using Kingdee.BOS.Core.Metadata;
- using Kingdee.BOS.Orm.DataEntity;
- using Kingdee.BOS.App.Data;
- using Kingdee.BOS.Orm;
- namespace ClassLibrary.App.ServicePlugIn
- {
- /// <summary>
- /// 下推 單據轉換 測試
- /// </summary>
- [Description("服務端外掛")]
- public class CustPushTestPlugIn : AbstractOperationServicePlugIn
- {
- /// <summary>
- ///
- /// </summary>
- /// <param name="e"></param>
- public override void EndOperationTransaction(EndOperationTransactionArgs e)
- {
- base.EndOperationTransaction(e);
- //此引數是獲取由系統整合呼叫客戶端給的資料
- var parameters = this.Option.GetVariableValue<object>("Parameters");
- string getSourceSql = "select FID from T_SAL_RETURNSTOCK where FDOCUMENTSTATUS = 'C'";
- //SAL_RETURNSTOCK 銷售退貨單, AR_receivable 應收單, 180ecd4afd5d44b5be78a6efe4a7e041 標準應收單型別內碼
- IOperationResult result = Invoke("SAL_RETURNSTOCK", "AR_receivable", getSourceSql, "180ecd4afd5d44b5be78a6efe4a7e041");
- this.OperationResult.IsSuccess = result.IsSuccess;
- this.OperationResult.ValidationErrors = result.ValidationErrors;
- this.OperationResult.OperateResult = result.OperateResult;
- }
- /// <summary>
- /// 下推 單據轉換
- /// </summary>
- /// <param name="source">源單 業務物件標識</param>
- /// <param name="target">目標單 業務物件標識</param>
- /// <param name="getSourceSql">源單 查詢語句</param>
- /// <param name="sargetBillTypeId">目標單 轉換目標型別</param>
- /// <returns></returns>
- private IOperationResult Invoke(string source, string target, string getSourceSql, string sargetBillTypeId)
- {
- IOperationResult result = new OperationResult();
- //獲取單據轉換規則
- ConvertRuleElement ruleElement = ServiceHelper.GetService<IConvertService>().GetConvertRules(this.Context, source, target).FirstOrDefault();
- //如下程式碼 直接通過查詢資料庫獲取單據轉換源單資料
- ListSelectedRowCollection rows = new ListSelectedRowCollection();
- int i = 0;
- using (IDataReader reader = DBUtils.ExecuteReader(this.Context, getSourceSql))
- {
- while (reader.Read())
- {
- ListSelectedRow row = new ListSelectedRow(reader["FID"].ToString(), string.Empty, i++, source);
- rows.Add(row);
- }
- }
- PushArgs pushArgs = new PushArgs(ruleElement, rows.ToArray());
- pushArgs.TargetBillTypeId = sargetBillTypeId;
- //轉換生成目標單
- ConvertOperationResult convertResult = ServiceHelper.GetService<IConvertService>().Push(this.Context, pushArgs);
- //合併轉換操作結果
- result.MergeResult(convertResult);
- //目標單據資料集合
- DynamicObject[] destObjs = convertResult.TargetDataEntities.Select(r => r.DataEntity).ToArray();
- //根據實際情況,處理目標單據資料
- DynamicObjectCollection col_FEntityDetail = destObjs[0]["AP_PAYABLEENTRY"] as DynamicObjectCollection;
- int sum = 0;
- foreach (var item in col_FEntityDetail)
- {
- item["TaxPrice"] = 1;
- sum = sum + 1;//測試用,暫時設定 “含稅單價” 每條都是1
- }
- DynamicObjectCollection col_FEntityPlan = destObjs[0]["AP_PAYABLEPLAN"] as DynamicObjectCollection;
- int iPAYAMOUNTFOR = sum / col_FEntityPlan.Count;//“價稅合計” 總金額平均分配到每一條付款計劃 “應付金額” 欄位
- foreach (var item in col_FEntityPlan)
- {
- item["PAYAMOUNTFOR"] = iPAYAMOUNTFOR;
- }
- //設定單據頭 “價稅合計” 即【明細】分錄的“含稅單價”合計
- destObjs[0]["FALLAMOUNTFOR"] = sum;
- //目標單元資料
- FormMetadata destFormMetadata = ServiceHelper.GetService<IMetaDataService>().Load(this.Context, target) as FormMetadata;
- //儲存目標單據
- IOperationResult saveResult = ServiceHelper.GetService<ISaveService>().Save(this.Context, destFormMetadata.BusinessInfo, destObjs, OperateOption.Create());
- //合併儲存操作結果
- result.MergeResult(saveResult);
- //根據操作結果構造返回結果
- if ((result.ValidationErrors != null && result.ValidationErrors.Count > 0)
- || (result.OperateResult != null && result.OperateResult.Count > 0))
- {
- result.IsSuccess = false;
- }
- return result;
- }
- }
- }