| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Collections.ObjectModel; |
| | | using System.ComponentModel; |
| | | using System.Data; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using Demo.Model.Model; |
| | | using Kingdee.BOS; |
| | | using Kingdee.BOS.Core.Attachment; |
| | | using Kingdee.BOS.Core.Bill; |
| | | using Kingdee.BOS.Core.Bill.PlugIn; |
| | | using Kingdee.BOS.Core.Bill.PlugIn.Args; |
| | | using Kingdee.BOS.Core.CommonFilter; |
| | | using Kingdee.BOS.Core.DynamicForm; |
| | | using Kingdee.BOS.Core.DynamicForm.DiffCompare; |
| | | 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.BarElement; |
| | | using Kingdee.BOS.Core.Metadata.ConvertElement; |
| | | using Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs; |
| | | using Kingdee.BOS.Core.Metadata.FormElement; |
| | | using Kingdee.BOS.Core.Metadata.QueryElement; |
| | | using Kingdee.BOS.Core.Msg; |
| | | using Kingdee.BOS.Core.Permission; |
| | | using Kingdee.BOS.Log; |
| | | using Kingdee.BOS.Msg; |
| | | using Kingdee.BOS.Orm; |
| | | using Kingdee.BOS.Core.Metadata.EntityElement; |
| | | using Kingdee.BOS.Orm.DataEntity; |
| | | using Kingdee.BOS.Orm.Metadata.DataEntity; |
| | | using Kingdee.BOS.Resource; |
| | | using Kingdee.BOS.ServiceHelper; |
| | | using Kingdee.BOS.Util; |
| | | using Kingdee.K3.SCM.Business; |
| | | using Kingdee.K3.SCM.Core.SCP; |
| | | using Kingdee.K3.SCM.ServiceHelper; |
| | | using Newtonsoft.Json.Linq; |
| | | using ZD.Cloud.Logger; |
| | | using ZD.Cloud.WebApi; |
| | | |
| | | namespace Demo.BillView.PRD |
| | | { |
| | | |
| | | [Description("提料下推送货通知单")] |
| | | [Kingdee.BOS.Util.HotUpdate] |
| | | public class Pro_TlPush : AbstractBillPlugIn |
| | | { |
| | | private string InstockEntryTableNameAs; |
| | | private string ReturnEntryTableNameAs; |
| | | private string PoChangeEntryTableNameAs; |
| | | CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/"); |
| | | public override void BarItemClick(BarItemClickEventArgs e) |
| | | { |
| | | string a; |
| | | if ((a = e.BarItemKey.ToUpperInvariant()) != null) |
| | | try |
| | | { |
| | | if (a == "TBPUSH") |
| | | string a; |
| | | if ((a = e.BarItemKey.ToUpperInvariant()) != null) |
| | | { |
| | | try |
| | | if (a == "TBPUSH") |
| | | { |
| | | PermissionAuthResult permissionAuthResult = PermissionServiceHelper.FuncPermissionAuth(base.Context, new BusinessObject |
| | | // 获取父单据体 |
| | | Entity entity = this.View.BillBusinessInfo.GetEntity("FEntity");//标识 |
| | | //DynamicObjectCollection entityRows = entity.DynamicProperty.GetValue(this.Model.DataObject) as DynamicObjectCollection;//获取父单据体行集合 |
| | | DynamicObjectCollection entityRows = this.Model.GetEntityDataObject(entity);//获取父单据体行集合 |
| | | // 1和2均可 |
| | | // 取当前页面子单据体 |
| | | //Entity subEntity = this.View.BillBusinessInfo.GetEntity("FEntity");//标识 |
| | | //DynamicObjectCollection rows = this.Model.GetEntityDataObject(subEntity);//获得子单据体行集合 |
| | | //构建 model 主表 |
| | | JObject model = new JObject(); |
| | | model.Add("FBILLTYPEID", new JObject() { ["Fnumber"] = "SLD01_SYS" }); //单据类型 |
| | | model.Add("FDate", DateTime.Now.ToString("yyyy-MM-dd")); //通知日期 |
| | | model.Add("FStockOrgId", new JObject() { ["Fnumber"] = (this.Model.GetValue("FHPURCHASEORGID") as DynamicObject)?["Number"].ToString() ?? "" }); // 收料组织 |
| | | model.Add("FPurOrgId", new JObject() { ["Fnumber"] = (this.Model.GetValue("FHPURCHASEORGID") as DynamicObject)?["Number"].ToString() ?? "" }); //采购组织 |
| | | model.Add("FSupplierId", new JObject() { ["Fnumber"] = (this.Model.GetValue("FSupplierID") as DynamicObject)?["Number"].ToString() ?? "" }); //供应商 |
| | | model.Add("FOwnerTypeIdHead", "BD_OwnerOrg");// 货主类型 |
| | | model.Add("FOwnerIdHead", new JObject() { ["Fnumber"] = (this.Model.GetValue("FHPURCHASEORGID") as DynamicObject)?["Number"].ToString() ?? "" });//货主 |
| | | |
| | | |
| | | //model.Add("FPurchaserId", new JObject() { ["Fnumber"] = "" }); //采购员 |
| | | //model.Add("FReceiverId", new JObject() { ["Fnumber"] = "" }); //收料员 |
| | | //model.Add("FSupplyAddress", ""); //供货方地址 |
| | | //model.Add("FConfirmerId", new JObject() { ["FUserID"] = "" }); // 确认人 |
| | | //model.Add("FConfirmDate", "1900-01-01"); //确认日期 |
| | | //model.Add("FSupplyId", new JObject() { ["Fnumber"] = "" }); // 供货方 |
| | | //model.Add("FChargeId", new JObject() { ["Fnumber"] = "" }); // 收款方 |
| | | //model.Add("FSettleId", new JObject() { ["Fnumber"] = "" }); // 结算方 |
| | | //model.Add("FIsInsideBill", "false"); // 外部单据 |
| | | //model.Add("FScanBox", "false"); // 序列号上传 |
| | | |
| | | //子表 数据模型 |
| | | JArray Fentity = new JArray(); |
| | | foreach (var item in entityRows) |
| | | { |
| | | Id = "SCP_ReceiveBill" |
| | | }, "fce8b1aca2144beeb3c6655eaf78bc34"); |
| | | if (!permissionAuthResult.Passed) |
| | | { |
| | | string msg = ResManager.LoadKDString("没有送货通知单的新增权限", "00444293030010485", SubSystemType.SCM, new object[0]); |
| | | base.View.ShowErrMessage(msg, "", MessageBoxType.Notice); |
| | | return; |
| | | JObject FentityModel = new JObject(); |
| | | FentityModel.Add("FMaterialId", new JObject() { ["Fnumber"] = (item["FHMaterID"] as DynamicObject)?["Number"].ToString() ?? "" }); // 物料编码 |
| | | FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = (item["FUnitID"] as DynamicObject)?["Number"].ToString() ?? "" }); // 单位 |
| | | FentityModel.Add("FPreDeliveryDate", this.Model.GetValue("FHDate").ToString()); // 预计到货日期 |
| | | FentityModel.Add("FPriceUnitId", new JObject() { ["Fnumber"] = (item["FUnitID"] as DynamicObject)?["Number"].ToString() ?? "" }); // 计价单位 |
| | | FentityModel.Add("FStockUnitID", new JObject() { ["Fnumber"] = (item["FUnitID"] as DynamicObject)?["Number"].ToString() ?? "" }); // 库存单位 |
| | | FentityModel.Add("FActReceiveQty", item["FHQty"].ToString()); // 供应商送货数量 |
| | | FentityModel.Add("FOwnerTypeId", "BD_OwnerOrg");// 货主类型 |
| | | FentityModel.Add("FOwnerID", new JObject() { ["Fnumber"] = (this.Model.GetValue("FHPURCHASEORGID") as DynamicObject)?["Number"].ToString() ?? "" });//货主 |
| | | FentityModel.Add("FSrcId", item["FHPOOrderInterID"].ToString());// 源单内码 |
| | | FentityModel.Add("FSRCFORMID", "PUR_PurchaseOrder");// 源单类型 |
| | | FentityModel.Add("FSrcBillNo", item["FHPOOrderBillNo"].ToString());// 源单单号 |
| | | FentityModel.Add("FSRCENTRYID", item["FHPOOrderEntryID"].ToString());// 源单分录内码 |
| | | FentityModel.Add("FORDERBILLNO", item["FHPOOrderBillNo"].ToString());// 源单单号 |
| | | FentityModel.Add("FPOORDERENTRYID", item["FHPOOrderEntryID"].ToString());// 源单分录内码 |
| | | FentityModel.Add("FTLId", this.View.Model.DataObject["Id"].ToString());// 提料源单内码 |
| | | FentityModel.Add("FTLentryId", item["Id"].ToString());// 提料源单分录内码 |
| | | FentityModel.Add("FTLOrderNo", this.Model.GetValue("FBillNo").ToString());// 提料源单分录内码 |
| | | |
| | | JArray Fentity2 = new JArray(); |
| | | JObject FentityModel2 = new JObject(); |
| | | FentityModel2.Add("FDetailEntity_Link_FRULEID", "a8c6b6e5-a8c0-4fc1-8592-6b76c2136cf9"); |
| | | FentityModel2.Add("FDetailEntity_Link_FSTableName", "t_PUR_POOrderEntry"); |
| | | FentityModel2.Add("FDetailEntity_Link_FSBillId", item["FHPOOrderInterID"].ToString()); |
| | | FentityModel2.Add("FDetailEntity_Link_FSId", item["FHPOOrderEntryID"].ToString()); |
| | | Fentity2.Add(FentityModel2); |
| | | FentityModel.Add("FDetailEntity_Link", Fentity2); |
| | | //单据转换关联关系 |
| | | //FentityModel.Add("FAuxPropId", new JObject() { }); // 物料编码 |
| | | //FentityModel.Add("FConfirmDeliQty", 0); // 物料编码 |
| | | //FentityModel.Add("FConfirmDeliDate", "1900-01-01"); // 物料编码 |
| | | //FentityModel.Add("FConfirmInfo", ""); // 物料编码 |
| | | //FentityModel.Add("FDescription", ""); // 物料编码 |
| | | //FentityModel.Add("FBomId", new JObject() { ["Fnumber"] = "" }); // 物料编码 |
| | | //FentityModel.Add("FLot", new JObject() { ["Fnumber"] = "" }); // 物料编码 |
| | | //FentityModel.Add("FSupplierLot", ""); // 物料编码 |
| | | //FentityModel.Add("FPrice", 0); // 物料编码 |
| | | //FentityModel.Add("FTaxPrice", 0); // 物料编码 |
| | | //FentityModel.Add("FDiscountRate", 0); // 物料编码 |
| | | //FentityModel.Add("FEntryTaxRate", 0); // 物料编码 |
| | | //FentityModel.Add("FStockBaseQty", 0); // 物料编码 |
| | | //FentityModel.Add("FStockQty", 0); // 物料编码 |
| | | //FentityModel.Add("FTaxCombination", new JObject() { ["Fnumber"] = "" }); // 物料编码 |
| | | //FentityModel.Add("FPriceBaseQty", 0); // 物料编码 |
| | | //FentityModel.Add("FStockInMaxQty", 0); // 物料编码 |
| | | //FentityModel.Add("FBaseStockInMaxQty", 0); // 物料编码 |
| | | //FentityModel.Add("FCheckInComing", "false"); // 物料编码 |
| | | //FentityModel.Add("FStockID", new JObject() { ["Fnumber"] = "" }); // 物料编码 |
| | | //FentityModel.Add("FStockLocId", new JObject() { }); // 物料编码 |
| | | //FentityModel.Add("FStockStatusId", new JObject() { ["Fnumber"] = "" }); // 物料编码 |
| | | //FentityModel.Add("FProduceDate", "1900-01-01"); // 物料编码 |
| | | //FentityModel.Add("FExpiryDate", "1900-01-01"); // 物料编码 |
| | | |
| | | Fentity.Add(FentityModel); |
| | | } |
| | | DynamicObjectCollection source = this.Model.DataObject["FEntity"] as DynamicObjectCollection; |
| | | string[] selEntryIds = (from p in source |
| | | select Convert.ToString(p["id"])).ToArray<string>(); |
| | | InvokePushToRec(base.View, selEntryIds); |
| | | return; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | if (ex.InnerException != null) |
| | | model.Add("FDetailEntity", Fentity); //明细信息 |
| | | |
| | | JObject _FentityModel = new JObject(); |
| | | _FentityModel.Add("FSettleOrgId", new JObject() { ["Fnumber"] = (this.Model.GetValue("FHPURCHASEORGID") as DynamicObject)?["Number"].ToString() ?? "" }); // 结算组织 |
| | | _FentityModel.Add("FSettleCurrId", new JObject() { ["Fnumber"] = (this.Model.GetValue("FSettleCurrId") as DynamicObject)?["Number"].ToString() ?? "" }); // 结算币别 |
| | | _FentityModel.Add("FPricePoint", 0); // 定价时点 |
| | | //FPricePoint |
| | | model.Add("FinanceEntity ", _FentityModel);//财务信息 |
| | | |
| | | //model.Add("FinanceEntity ", new JObject() { |
| | | //"FSettleOrgId", new JObject() { ["Fnumber"] = (this.Model.GetValue("FHPURCHASEORGID") as DynamicObject)?["Number"].ToString() ?? "" }, |
| | | //"FSettleCurrId", new JObject() { ["Fnumber"] = (this.Model.GetValue("FSettleCurrId") as DynamicObject)?["Number"].ToString() ?? "" } |
| | | //}); |
| | | |
| | | JObject jsonRoot = new JObject() |
| | | { |
| | | base.View.ShowErrMessage(ex.InnerException.Message, "", MessageBoxType.Notice); |
| | | ["Creator"] = "", |
| | | ["NeedUpDateFields"] = new JArray(), |
| | | ["NeedReturnFields"] = new JArray(), |
| | | ["IsDeleteEntry"] = "false", |
| | | ["SubSystemId"] = "", |
| | | ["IsVerifyBaseDataField"] = "false", |
| | | //["IsAutoSubmitAndAudit"] = true,//自动调用提交和审核功能 |
| | | ["Model"] = model |
| | | }; |
| | | |
| | | var result = cloudClient.Save("PUR_ReceiveBill", jsonRoot.ToString()); |
| | | JObject saveObj = JObject.Parse(result); |
| | | string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper(); |
| | | if (saveIsSuc == "TRUE") |
| | | { |
| | | // 打开单据维护界面:以打开销售订单100001为例 |
| | | // using Kingdee.BOS.Core.Bill; |
| | | string pageId = Guid.NewGuid().ToString(); |
| | | BillShowParameter showParameter = new BillShowParameter(); |
| | | showParameter.FormId = "SCP_ReceiveBill"; |
| | | showParameter.OpenStyle.ShowType = ShowType.MainNewTabPage; |
| | | showParameter.PageId = pageId; |
| | | showParameter.Status = OperationStatus.EDIT; |
| | | // 传入需要修改的销售订单内码,演示代码直接固定写死为100001 |
| | | showParameter.PKey = saveObj["Result"]["Id"].ToString(); |
| | | this.View.ShowForm(showParameter); |
| | | } |
| | | else |
| | | { |
| | | base.View.ShowErrMessage(ex.Message, "", MessageBoxType.Notice); |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | long num = Convert.ToInt64(this.Model.DataObject["id"]); |
| | | string arg = Convert.ToString(this.Model.GetValue("fbillno")); |
| | | ScpBillTrackInfo scpBillTrackInfo = new ScpBillTrackInfo(); |
| | | scpBillTrackInfo.IsUpTrack = false; |
| | | scpBillTrackInfo.BillName = ResManager.LoadKDString("供应商协同采购订单", "00444293030009441", SubSystemType.SCM, new object[0]); |
| | | TrackItem trackItem = new TrackItem(); |
| | | trackItem.FormId = "SCP_ReceiveBill"; |
| | | trackItem.FormName = ResManager.LoadKDString("送货通知单", "00444293030009436", SubSystemType.SCM, new object[0]); |
| | | trackItem.Filter = string.Format(" FSRCFORMID='PUR_PurchaseOrder' AND FSRCID={0} ", num); |
| | | scpBillTrackInfo.TrackItems.Add(trackItem); |
| | | TrackItem trackItem2 = new TrackItem(); |
| | | trackItem2.FormId = "SCP_MRAPP"; |
| | | trackItem2.FormName = ResManager.LoadKDString("退料通知单", "00444293030010278", SubSystemType.SCM, new object[0]); |
| | | trackItem2.Filter = string.Format(" FSRCBILLTYPEID='PUR_PurchaseOrder' and FSRCBILLNO = '{0}' ", arg); |
| | | if (string.IsNullOrWhiteSpace(this.InstockEntryTableNameAs)) |
| | | { |
| | | FormMetadata formMetadata = (FormMetadata)MetaDataServiceHelper.Load(base.Context, "SCP_InStock", true); |
| | | SelectField selectField = formMetadata.BusinessInfo.GetQueryInfo().GetSelectField("FMATERIALID"); |
| | | this.InstockEntryTableNameAs = selectField.FullFieldName.Substring(0, selectField.FullFieldName.IndexOf('.')); |
| | | } |
| | | if (string.IsNullOrWhiteSpace(this.ReturnEntryTableNameAs)) |
| | | { |
| | | FormMetadata formMetadata2 = (FormMetadata)MetaDataServiceHelper.Load(base.Context, "SCP_MRB", true); |
| | | SelectField selectField2 = formMetadata2.BusinessInfo.GetQueryInfo().GetSelectField("FMATERIALID"); |
| | | this.ReturnEntryTableNameAs = selectField2.FullFieldName.Substring(0, selectField2.FullFieldName.IndexOf('.')); |
| | | } |
| | | if (string.IsNullOrWhiteSpace(this.PoChangeEntryTableNameAs)) |
| | | { |
| | | FormMetadata formMetadata3 = (FormMetadata)MetaDataServiceHelper.Load(base.Context, "SCP_POChange", true); |
| | | SelectField selectField3 = formMetadata3.BusinessInfo.GetQueryInfo().GetSelectField("FMATERIALID"); |
| | | this.PoChangeEntryTableNameAs = selectField3.FullFieldName.Substring(0, selectField3.FullFieldName.IndexOf('.')); |
| | | } |
| | | TrackItem trackItem3 = new TrackItem(); |
| | | trackItem3.FormId = "SCP_InStock"; |
| | | trackItem3.FormName = ResManager.LoadKDString("采购入库单", "00444293030010276", SubSystemType.SCM, new object[0]); |
| | | TrackItem trackItem4 = new TrackItem(); |
| | | trackItem4.FormId = "SCP_MRB"; |
| | | trackItem4.FormName = ResManager.LoadKDString("采购退料单", "00444293030010277", SubSystemType.SCM, new object[0]); |
| | | TrackItem trackItem5 = new TrackItem(); |
| | | trackItem5.FormId = "SCP_POChange"; |
| | | trackItem5.FormName = ResManager.LoadKDString("采购订单变更单", "00444293030010132", SubSystemType.SCM, new object[0]); |
| | | List<long> list = new List<long>(); |
| | | list.Add(-1L); |
| | | List<long> list2 = new List<long>(); |
| | | list2.Add(-1L); |
| | | List<long> list3 = new List<long>(); |
| | | list3.Add(-1L); |
| | | string item = Convert.ToString(base.View.Model.DataObject["id"]); |
| | | List<string> list4 = new List<string> |
| | | { |
| | | item |
| | | }; |
| | | string[] trackIds = list4.ToArray(); |
| | | List<long> linkBillEntryIds = PurchaseNewServiceHelper.GetLinkBillEntryIds(base.Context, "T_STK_INSTOCKENTRY_lk", "t_PUR_POOrderEntry", trackIds, null, true); |
| | | List<long> linkBillEntryIds2 = PurchaseNewServiceHelper.GetLinkBillEntryIds(base.Context, "T_PUR_MRBENTRY_lk", "t_PUR_POOrderEntry", trackIds, null, true); |
| | | List<long> linkBillEntryIds3 = PurchaseNewServiceHelper.GetLinkBillEntryIds(base.Context, "T_PUR_POChangeEntry_LK", "t_PUR_POOrderEntry", trackIds, null, true); |
| | | trackItem3.Filter = string.Format(" {1}.fentryid in ({0}) ", string.Join<long>(",", linkBillEntryIds), this.InstockEntryTableNameAs); |
| | | trackItem4.Filter = string.Format(" {1}.fentryid in ({0}) ", string.Join<long>(",", linkBillEntryIds2), this.ReturnEntryTableNameAs); |
| | | trackItem5.Filter = string.Format(" {1}.fentryid in ({0}) ", string.Join<long>(",", linkBillEntryIds3), this.PoChangeEntryTableNameAs); |
| | | scpBillTrackInfo.TrackItems.Add(trackItem2); |
| | | scpBillTrackInfo.TrackItems.Add(trackItem3); |
| | | scpBillTrackInfo.TrackItems.Add(trackItem4); |
| | | scpBillTrackInfo.TrackItems.Add(trackItem5); |
| | | //base.View.ShowForm(scpBillTrackInfo); |
| | | |
| | | View.ShowForm(new DynamicFormShowParameter |
| | | { |
| | | Height = 500, |
| | | Width = 1000, |
| | | FormId = "SCP_ScpBillTracker", |
| | | SyncCallBackAction = true, |
| | | ParentPageId = View.PageId, |
| | | PageId = SequentialGuid.NewGuid().ToString(), |
| | | CustomComplexParams = |
| | | { |
| | | { |
| | | "ScpBillTrackInfo", |
| | | scpBillTrackInfo |
| | | } |
| | | } |
| | | }); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | public static void InvokePushToRec(IDynamicFormView formView, string[] selEntryIds) |
| | | { |
| | | if (CheckPoHasPushRec(formView.Context, selEntryIds)) |
| | | { |
| | | formView.ShowWarnningMessage(ResManager.LoadKDString("采购订单有暂存的关联送货单据,再次生成会造成单据重复下推,是否继续生成送货通知单?", "00444293030037168", SubSystemType.SCM, new object[0]), "", MessageBoxOptions.YesNoCancel, delegate (MessageBoxResult selRst) |
| | | { |
| | | if (MessageBoxResult.Yes == selRst) |
| | | { |
| | | InnerInvokePushToRec(formView, selEntryIds); |
| | | } |
| | | }, MessageBoxType.Advise); |
| | | return; |
| | | } |
| | | InnerInvokePushToRec(formView, selEntryIds); |
| | | } |
| | | |
| | | public static bool CheckPoHasPushRec(Context ctx, string[] billEntryIds) |
| | | { |
| | | string strSql = string.Format("select 1 from T_PUR_RECEIVE TH\r\nINNER JOIN T_PUR_RECEIVEENTRY TE ON TE.FID=TH.FID\r\nINNER JOIN T_PUR_RECEIVEENTRY_LK TELK ON TE.FENTRYID=TELK.FENTRYID\r\ninner join (select /*+ cardinality(b1 {0})*/FID from TABLE(fn_StrSplit(@FID,',',1)) b1) b on TELK.FSID=b.fid \r\nwhere TH.FDOCUMENTSTATUS='Z' ", billEntryIds.Length); |
| | | int num = DBServiceHelper.ExecuteScalar<int>(ctx, strSql, 0, new List<SqlParam> |
| | | { |
| | | new SqlParam("@FID", KDDbType.udt_inttable, billEntryIds) |
| | | }.ToArray()); |
| | | return num == 1; |
| | | } |
| | | |
| | | public static void InnerInvokePushToRec(IDynamicFormView formView, string[] selEntryIds) |
| | | { |
| | | DynamicFormShowParameter dynamicFormShowParameter = new DynamicFormShowParameter(); |
| | | dynamicFormShowParameter.FormId = "SCP_PushParamFrom"; |
| | | dynamicFormShowParameter.ParentPageId = formView.PageId; |
| | | dynamicFormShowParameter.OpenStyle.ShowType = ShowType.Modal; |
| | | dynamicFormShowParameter.CustomComplexParams.Add("SrcFormId", "paez_PODemandPlan"); |
| | | dynamicFormShowParameter.CustomComplexParams.Add("TargetFormId", "PUR_ReceiveBill"); |
| | | formView.ShowForm(dynamicFormShowParameter, delegate (FormResult results) |
| | | { |
| | | if (results != null && results.ReturnData != null) |
| | | { |
| | | DynamicObject dynamicObject = results.ReturnData as DynamicObject; |
| | | string CbConvertRule = Convert.ToString(dynamicObject["CbConvertRule"]); |
| | | List<ConvertRuleElement> convertRules = ConvertServiceHelper.GetConvertRules(formView.Context, "paez_PODemandPlan", "PUR_ReceiveBill"); |
| | | ConvertRuleElement rule = convertRules.FirstOrDefault((ConvertRuleElement t) => t.Id == CbConvertRule); |
| | | PushPurOrderToRec(formView, selEntryIds, rule); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public static void PushPurOrderToRec(IDynamicFormView formView, string[] billEntryIds, ConvertRuleElement rule) |
| | | { |
| | | ConvertPolicyElement convertPolicyElement = rule.Policies[6]; |
| | | Collection<BillTypeMapElement> billTypeMaps = ((BillTypeMapPolicyElement)convertPolicyElement).BillTypeMaps; |
| | | Dictionary<string, string> dictionary = new Dictionary<string, string>(); |
| | | foreach (BillTypeMapElement billTypeMapElement in billTypeMaps) |
| | | { |
| | | if (!dictionary.ContainsKey(billTypeMapElement.SourceBillTypeId)) |
| | | { |
| | | dictionary.Add(billTypeMapElement.SourceBillTypeId, billTypeMapElement.TargetBillTypeId); |
| | | } |
| | | } |
| | | List<ScpOrderPushInfo> list = new List<ScpOrderPushInfo>(); |
| | | string strSQL = string.Format(" select tr.FentryID, t.fbilltypeid,ts.FMASTERID as fsupmasterid,t.fbillNO,TR.FID AS FBILLID \r\n from Cg_PODemandPlanBillMain t\r\n inner join T_BD_SUPPLIER ts on ts.FSUPPLIERID=t.FSUPPLIERID\r\n inner join Cg_PODemandPlanBillSub TR ON TR.FID=T.FID \r\n inner join (select /*+ cardinality(b {0})*/ fid from table(fn_StrSplit(@FID, ',',1)) b) tb on TR.fentryid=tb.fid \r\n ", billEntryIds.Length); |
| | | List<SqlParam> list2 = new List<SqlParam> |
| | | { |
| | | new SqlParam("@FID", KDDbType.udt_inttable, billEntryIds) |
| | | }; |
| | | DynamicObjectCollection dynamicObjectCollection = DBServiceHelper.ExecuteDynamicObject(formView.Context, strSQL, null, null, CommandType.Text, list2.ToArray()); |
| | | if (dynamicObjectCollection == null || dynamicObjectCollection.Count == 0) |
| | | { |
| | | throw new KDException("", ResManager.LoadKDString("受源单所选单据类型限制,不允许下推目标单!", "00444293030009439", SubSystemType.SCM, new object[0])); |
| | | } |
| | | long supplierMasterIdByUserId = SupplierServiceHelper.GetSupplierMasterIdByUserId(formView.Context, formView.Context.UserId); |
| | | string format = ResManager.LoadKDString("您没有权限操作单据{0}", "00444293030009639", SubSystemType.SCM, new object[0]); |
| | | foreach (DynamicObject dynamicObject in dynamicObjectCollection) |
| | | { |
| | | if (supplierMasterIdByUserId != Convert.ToInt64(dynamicObject["fsupmasterid"])) |
| | | { |
| | | throw new KDException("", string.Format(format, Convert.ToString(dynamicObject["fbillNO"]))); |
| | | } |
| | | list.Add(new ScpOrderPushInfo |
| | | { |
| | | EntryId = Convert.ToString(dynamicObject["FentryID"]), |
| | | BillId = Convert.ToString(dynamicObject["FBILLID"]), |
| | | BilltypeId = Convert.ToString(dynamicObject["fbilltypeid"]) |
| | | }); |
| | | } |
| | | IEnumerable<IGrouping<string, ScpOrderPushInfo>> enumerable = from g in list |
| | | group g by g.BilltypeId; |
| | | List<DynamicObject> list3 = new List<DynamicObject>(); |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | foreach (IGrouping<string, ScpOrderPushInfo> grouping in enumerable) |
| | | { |
| | | string key = grouping.Key; |
| | | List<ListSelectedRow> list4 = new List<ListSelectedRow>(); |
| | | int num = 0; |
| | | foreach (ScpOrderPushInfo scpOrderPushInfo in grouping) |
| | | { |
| | | list4.Add(new ListSelectedRow(scpOrderPushInfo.BillId, scpOrderPushInfo.EntryId, num++, "paez_PODemandPlan") |
| | | { |
| | | EntryEntityKey = "FEntity" |
| | | }); |
| | | } |
| | | ListSelectedRow[] selectedRows = list4.ToArray(); |
| | | PushArgs pushArgs = new PushArgs(rule, selectedRows); |
| | | if (dictionary.ContainsKey(key)) |
| | | { |
| | | pushArgs.TargetBillTypeId = dictionary[key]; |
| | | } |
| | | try |
| | | { |
| | | ConvertOperationResult convertOperationResult = ConvertServiceHelper.Push(formView.Context, pushArgs, false); |
| | | list3.AddRange(from p in convertOperationResult.TargetDataEntities |
| | | select p.DataEntity); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | stringBuilder.AppendLine(ex.Message); |
| | | } |
| | | } |
| | | if (list3.Count == 0) |
| | | { |
| | | if (stringBuilder.Length > 0) |
| | | { |
| | | formView.ShowErrMessage(stringBuilder.ToString(), "", MessageBoxType.Notice); |
| | | return; |
| | | } |
| | | formView.ShowErrMessage(ResManager.LoadKDString("没有可下推数据!", "00444293030009360", SubSystemType.SCM, new object[0]), "", MessageBoxType.Notice); |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | DynamicObject[] array = list3.ToArray(); |
| | | Dictionary<string, object> dictionary2 = new Dictionary<string, object>(); |
| | | dictionary2["CodeTime"] = 0; |
| | | dictionary2["UpdateMaxNum"] = 1; |
| | | FormMetadata formMetadata = (FormMetadata)MetaDataServiceHelper.Load(formView.Context, "PUR_ReceiveBill", true); |
| | | List<BillNoInfo> billNo = BusinessDataServiceHelper.GetBillNo(formView.Context, formMetadata.BusinessInfo, array, dictionary2, ""); |
| | | for (int i = 0; i < array.Count<DynamicObject>(); i++) |
| | | { |
| | | array[i]["BillNo"] = billNo[i].BillNo; |
| | | array[i]["IsInsideBill"] = true; |
| | | } |
| | | OperateOption option = OperateOption.Create(); |
| | | IOperationResult operationResult = BusinessDataServiceHelper.Draft(formView.Context, formMetadata.BusinessInfo, array, option, ""); |
| | | if (!operationResult.IsSuccess) |
| | | { |
| | | formView.ShowMessage(ResManager.LoadKDString("下推失败!", "00444293030009440", SubSystemType.SCM, new object[0]), MessageBoxType.Notice); |
| | | return; |
| | | } |
| | | if (operationResult.SuccessDataEnity.Count<DynamicObject>() == 1) |
| | | { |
| | | DynamicObject dynamicObject2 = operationResult.SuccessDataEnity.FirstOrDefault<DynamicObject>(); |
| | | formView.ShowForm(new BillShowParameter |
| | | { |
| | | FormId = "SCP_ReceiveBill", |
| | | PKey = Convert.ToString(dynamicObject2["id"]), |
| | | Status = OperationStatus.EDIT, |
| | | OpenStyle = |
| | | { |
| | | ShowType = ShowType.MainNewTabPage |
| | | }, |
| | | CustomComplexParams = |
| | | { |
| | | { |
| | | "FromScpOrderPushRecs", |
| | | true |
| | | } |
| | | } |
| | | }); |
| | | return; |
| | | } |
| | | DynamicObjectType dynamicObjectType = new DynamicObjectType("ScpRecBillDatas", null, null, DataEntityTypeFlag.Class, new object[0]); |
| | | dynamicObjectType.RegisterSimpleProperty("BillNo", typeof(string), null, false, new object[0]); |
| | | dynamicObjectType.RegisterSimpleProperty("DocumentStatus", typeof(string), null, false, new object[0]); |
| | | dynamicObjectType.RegisterSimpleProperty("BillId", typeof(long), null, false, new object[0]); |
| | | DynamicObjectCollection dynamicObjectCollection2 = new DynamicObjectCollection(dynamicObjectType, null); |
| | | foreach (DynamicObject dynamicObject3 in operationResult.SuccessDataEnity) |
| | | { |
| | | DynamicObject dynamicObject4 = new DynamicObject(dynamicObjectType); |
| | | dynamicObject4["BillNo"] = dynamicObject3["BillNo"]; |
| | | dynamicObject4["DocumentStatus"] = dynamicObject3["DocumentStatus"]; |
| | | dynamicObject4["BillId"] = dynamicObject3["id"]; |
| | | dynamicObjectCollection2.Add(dynamicObject4); |
| | | } |
| | | formView.ShowForm(new DynamicFormShowParameter |
| | | { |
| | | FormId = "SCP_GENRECRSTFORM", |
| | | PageId = SequentialGuid.NewGuid().ToString(), |
| | | OpenStyle = |
| | | { |
| | | ShowType = ShowType.MainNewTabPage |
| | | }, |
| | | CustomComplexParams = |
| | | { |
| | | { |
| | | "ScpRecBillDatas", |
| | | dynamicObjectCollection2 |
| | | LogHelper.Error(jsonRoot.ToString()); |
| | | this.View.ShowErrMessage(jsonRoot.ToString()); |
| | | } |
| | | } |
| | | }); |
| | | return; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw ex; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |