BOS套打二次开发原创
11人赞赏了该文章
2,329次浏览
编辑于2019年08月09日 21:33:20
总结:套打单据头与单据体是分开赋值的。第一步:BOS套打设计器进行模板设计 第二步:新建工程进行编码 代码示例 using Kingdee.BOS.App.Data; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel; using Kingdee.BOS.Core.List.PlugIn; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Orm.Metadata.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HUALI.K3.SCM.PUR.Business.ServicePlugln { [Description("行车表套打")] [Kingdee.BOS.Util.HotUpdate] public class ServiceDiagramPrintData : AbstractListPlugIn { /// <summary> /// 行车表套打前准备数据 /// </summary> /// <param name="e"></param> public override void OnPrepareNotePrintData(PreparePrintDataEventArgs e) { //根据套打模板ID确认取数方式{行车表套打} ///行车表套打36d142ac-8691-4954-8ebc-1edf1c7955a5 if (e.NotePrintTplId == "36d142ac-8691-4954-8ebc-1edf1c7955a5")//打印模板,套打模板ID { if (e.DataSourceId.Equals("FLineEntity", StringComparison.OrdinalIgnoreCase)) ///单据体标识 { //单据头套打数据准备 DynamicObjectType olddt = ObjectUtils.CreateCopy(e.DynamicObjectType) as DynamicObjectType; DynamicObjectType dt = e.DynamicObjectType; // 使用新的模型,创建新的数据包 DynamicObject newObj = new DynamicObject(dt); //当前选中行行号 int[] selectedIndexsR = this.View.GetControl<EntryGrid>("FLineEntity").GetSelectedRows(); // 基于原始模型,把原始数据包中的值,复制到新的数据包中 //e.DataObjects[0] DynamicObject[] BillHradObject = e.DataObjects; foreach (var index in selectedIndexsR) { foreach (var prop in olddt.Properties) { prop.SetValue(newObj, prop.GetValue(e.DataObjects[index])); } } e.DataObjects = new DynamicObject[] { newObj }; e.DynamicObjectType = dt; } if (e.DataSourceId.Equals("FSubEntity", StringComparison.OrdinalIgnoreCase)) ///单据体标识 { //单据体套打数据准备 int indexLine = 0;//存储线路信息当前存储行 // 基于套打要求的ORM数据模型,构建数据包,取单据体的字段值 // 特别注意:e.DynamicObjectType,仅包含了套打会用到的单据体字段 List<DynamicObject> notePrintEntryRows = new List<DynamicObject>(); //当前选中行行号(线路信息) int[] selectedIndexsR = this.View.GetControl<EntryGrid>("FLineEntity").GetSelectedRows(); indexLine = selectedIndexsR[0] + 1; DynamicObject[] BillHradObject = e.DataObjects; //获取集合中的数据包 DynamicObject BillHradDate = BillHradObject[0]; if (BillHradDate != null) { String FID = BillHradDate["FID"].ToString(); string sql = @"/*dialect*/ select distinct car.FDELIVERYORGID,cus.FDELIVERYADDRESS,trans.FTOTALQTY, trans.FCUSTOMER,trans.FDetailID,trans.FEntryID ,trans.Fseq " + " from T_BOS_TransEntry trans "+ " left join T_BOS_LineEntry line "+ " on trans.FEntryID=line.FEntryID "+ " left join t_BOS_CusEntry cus "+ " on trans.fdetailID=cus.fdetailID "+ " left join T_BOS_SaleRowCar car " + " on line.FID=car.FID "+ " where line.FID='" +FID+ "' and line.Fseq='" + indexLine + "'"; var sqlData = DBUtils.ExecuteDynamicObject(this.Context, sql.ToString()); if (sqlData.Count > 0) { foreach (var Data in sqlData) { String FCUSTOMER = Data["FCUSTOMER"].ToString(); //客户内码 String FTOTALQTY = Data["FTOTALQTY"].ToString(); //总重量 string FDetailID= Data["FDetailID"].ToString(); //FDetailID String FEntryID = Data["FEntryID"].ToString(); //FEntryID String Fseq = Data["Fseq"].ToString(); //总重量 string FDELIVERYORGID = Data["FDELIVERYORGID"].ToString(); //FDELIVERYORGID string FDELIVERYADDRESS = Data["FDELIVERYADDRESS"].ToString(); //FDELIVERYADDRESS FormMetadata formMetadata = MetaDataServiceHelper.Load(this.Context, "BD_CUSTOMER") as FormMetadata; DynamicObject dynamicObject = BusinessDataServiceHelper.LoadSingle( this.Context, FCUSTOMER, formMetadata.BusinessInfo.GetDynamicObjectType()); DynamicObjectCollection dynamicObjects = dynamicObject["BD_CUSTCONTACT"] as DynamicObjectCollection; DynamicObject obj = null; if (dynamicObjects.Count>0) { obj = dynamicObjects[0]; } DynamicObject notePrintEntryRow = new DynamicObject(e.DynamicObjectType); notePrintEntryRow["FCustomer_FNumber"] = dynamicObject["Number"];//客户编码 notePrintEntryRow["FTotalQty"] =Convert.ToDecimal(FTOTALQTY); // 总重 notePrintEntryRow["FID"] = FID; //单据ID notePrintEntryRow["FCustomer_Id"] = Convert.ToInt32(FCUSTOMER); //客户ID notePrintEntryRow["FDetailID"] = Convert.ToInt32(FDetailID); //FDetailID notePrintEntryRow["FSubEntity_Fseq"] = Convert.ToInt32(Fseq); //FSubEntity_Fseq notePrintEntryRow["FEntryID"] = Convert.ToInt32(FEntryID); //FEntryID notePrintEntryRow["FLineEntity_Fseq"] = Convert.ToInt32(FEntryID); //FLineEntity_Fseq notePrintEntryRow["FDeliveryOrgID"] = Convert.ToInt32(FDELIVERYORGID); //FDeliveryOrgID notePrintEntryRow["FCustomer_Ref"] = dynamicObject; //FCustomer_Ref notePrintEntryRow["FCustomer_FName"] = dynamicObject["Name"]; //FCustomer_FName if (!ObjectUtils.IsNullOrEmptyOrWhiteSpace(obj)) { notePrintEntryRow["FCustomer_FMOBILE"] = obj["MOBILE"]; //物料备注1 notePrintEntryRow["FCustomer_FEMail"] = obj["EMail"]; //物料备注1 notePrintEntryRow["FCustomer_FTTel"] = obj["TTel"]; //联系电话 } else { notePrintEntryRow["FCustomer_FMOBILE"] = ""; //物料备注1 notePrintEntryRow["FCustomer_FEMail"] = ""; //物料备注1 notePrintEntryRow["FCustomer_FTTel"] = ""; //联系电话 } notePrintEntryRows.Add(notePrintEntryRow); } } } e.DataObjects = notePrintEntryRows.ToArray(); } } ///备货单套打 ///测试账套af7fbf03-69d8-4511-b58e-0b5579879b01 ///本地ID 6679a05d-808f-4a43-93c6-25ff4d6f3c8f if (e.NotePrintTplId == "af7fbf03-69d8-4511-b58e-0b5579879b01") { //单据头(套打模板的)套打数据准备af7fbf03-69d8-4511-b58e-0b5579879b01 if (e.DataSourceId.Equals("FLineEntity", StringComparison.OrdinalIgnoreCase)) ///单据体标识 { DynamicObjectType olddt = ObjectUtils.CreateCopy(e.DynamicObjectType) as DynamicObjectType; DynamicObjectType dt = e.DynamicObjectType; // 使用新的模型,创建新的数据包 DynamicObject newObj = new DynamicObject(dt); //当前选中行行号 int[] selectedIndexsR = this.View.GetControl<EntryGrid>("FLineEntity").GetSelectedRows(); // 基于原始模型,把原始数据包中的值,复制到新的数据包中 //e.DataObjects[0] DynamicObject[] BillHradObject = e.DataObjects; foreach (var index in selectedIndexsR) { foreach (var prop in olddt.Properties) { prop.SetValue(newObj, prop.GetValue(e.DataObjects[index])); } } e.DataObjects = new DynamicObject[] { newObj }; e.DynamicObjectType = dt; } //单据体套打数据准备 if (e.DataSourceId.Equals("FEntity", StringComparison.OrdinalIgnoreCase)) { int indexLine = 0;//存储线路信息当前存储行 // 基于套打要求的ORM数据模型,构建数据包,取单据体的字段值 // 特别注意:e.DynamicObjectType,仅包含了套打会用到的单据体字段 List<DynamicObject> notePrintEntryRows = new List<DynamicObject>(); //当前选中行行号(线路信息) int[] selectedIndexsR = this.View.GetControl<EntryGrid>("FLineEntity").GetSelectedRows(); indexLine = selectedIndexsR[0] + 1; DynamicObject[] BillHradObject = e.DataObjects; //获取集合中的数据包 DynamicObject BillHradDate = BillHradObject[0]; DynamicObjectType dt = e.DynamicObjectType; //动态字段注册 dt.RegisterSimpleProperty("FOutAmount", typeof(object), attributes: new SimplePropertyAttribute() { Alias = "FOutAmount" });//出货数 dt.RegisterSimpleProperty("FPackSpecification", typeof(object), attributes: new SimplePropertyAttribute() { Alias = "FPackSpecification" });//包装规格 dt.RegisterSimpleProperty("FAoument", typeof(object), attributes: new SimplePropertyAttribute() { Alias = "FAoument" });//数量 dt.RegisterSimpleProperty("FFlotNumber", typeof(object), attributes: new SimplePropertyAttribute() { Alias = "FFlotNumber" });//取单号 dt.RegisterSimpleProperty("FBoxAoument", typeof(object), attributes: new SimplePropertyAttribute() { Alias = "FBoxAoument" });//箱数 dt.RegisterSimpleProperty("FStockLoc", typeof(object), attributes: new SimplePropertyAttribute() { Alias = "FStockLoc" });//储位 dt.RegisterSimpleProperty("FCustName1", typeof(object), attributes: new SimplePropertyAttribute() { Alias = "FCustName1" });//客户名称 dt.RegisterSimpleProperty("F_Tnote1", typeof(object), attributes: new SimplePropertyAttribute() { Alias = "F_Tnote1" });//送货备注 dt.RegisterSimpleProperty("FOrderBIllNo", typeof(object), attributes: new SimplePropertyAttribute() { Alias = "FOrderBIllNo" });//销售订单编号 dt.RegisterSimpleProperty("FMaterialID1", typeof(object), attributes: new SimplePropertyAttribute() { Alias = "FMaterialID1" });//物料名称 dt.RegisterSimpleProperty("FPZM", typeof(object), attributes: new SimplePropertyAttribute() { Alias = "FPZM" });//配置码 //通过数据包获取订单编号:根据订单编号获取子项工单的数据 if (BillHradDate != null) { String FID = BillHradDate["FID"].ToString(); string sql = string.Format(@"/*dialect*/ exec PrintData '{0}','{1}'", FID, indexLine); var sqlData = DBUtils.ExecuteDynamicObject(this.Context, sql.ToString()); if (sqlData.Count > 0) { foreach (var data in sqlData) { string FCUSTOMER = data["FCUSTOMER"].ToString();//客户编码 FormMetadata formMetadata = MetaDataServiceHelper.Load(this.Context, "BD_CUSTOMER") as FormMetadata; DynamicObject dynamicObject = BusinessDataServiceHelper.LoadSingle( this.Context, FCUSTOMER, formMetadata.BusinessInfo.GetDynamicObjectType());//获取客户对象 string F_Tnote = data["F_Tnote"].ToString();//送货备注 string FDELIVERYNOTICE = data["FSOBILLNO"].ToString();//销售订单编号 string FPRODUCTID = data["FPRODUCTID"].ToString();//物料ID FormMetadata formMetadataP = MetaDataServiceHelper.Load(this.Context, "BD_MATERIAL") as FormMetadata; DynamicObject dynamicObjectP = BusinessDataServiceHelper.LoadSingle( this.Context, FPRODUCTID, formMetadataP.BusinessInfo.GetDynamicObjectType());//获取物料对象 Decimal FNOWQTY = (Decimal)data["FNOWQTY"];//本次送货数量 string FStockLocId = (string)data["FNAME"];//仓位名称 string FAUXPROPID = data["FAUXFLEX"].ToString();//辅助属性ID string FLOT =data["FLOT_Text"].ToString();//批号 Decimal FBARVOLUMENUMBER = Convert.ToDecimal(data["FBarVolumeNumber"]); //条卷数 string FEntryID = data["FEntryID"].ToString();//分录ID string Fseq = data["Fseq"].ToString();//行号 Decimal BARCODEMAINCount = Convert.ToDecimal(data["Amount"]);//箱数 Decimal FQTY = (Decimal)data["FQTY"];//一箱数量 FormMetadata formMetadataFAUX = null; DynamicObject dynamicObjectFAUX = null; Decimal FNewQTY = 0; DynamicObject notePrintEntryRow = new DynamicObject(dt); if (!"0".Equals(FAUXPROPID)) { formMetadataFAUX = MetaDataServiceHelper.Load(this.Context, "BD_FLEXSITEMDETAILV") as FormMetadata; dynamicObjectFAUX = BusinessDataServiceHelper.LoadSingle( this.Context, FAUXPROPID, formMetadataFAUX.BusinessInfo.GetDynamicObjectType()); if (!ObjectUtils.IsNullOrEmptyOrWhiteSpace(dynamicObjectFAUX["F100002"])) { FNewQTY = FNOWQTY / Convert.ToDecimal(dynamicObjectFAUX["F100002"]) * 1000; notePrintEntryRow["FOutAmount"] = Math.Ceiling(FNewQTY).ToString();//本次出货数 } if (ObjectUtils.IsNullOrEmptyOrWhiteSpace(dynamicObjectFAUX["F100001"]) || FBARVOLUMENUMBER==0) { notePrintEntryRow["FPackSpecification"] = "";//包装规格 } else { notePrintEntryRow["FPackSpecification"] = ((string)dynamicObjectFAUX["F100001"]).TrimEnd('0') + "/" + FBARVOLUMENUMBER + "R";//包装规格 } notePrintEntryRow["FPZM"] = ((string)dynamicObjectFAUX["F100002"]).TrimEnd('0') + "*" + ((string)dynamicObjectFAUX["F100001"]).TrimEnd('0');//配置码 } else { notePrintEntryRow["FOutAmount"] = Math.Ceiling(FNOWQTY);//本次出货数 } notePrintEntryRow["FOrderBIllNo"] = FDELIVERYNOTICE; //销售订单号 notePrintEntryRow["F_Tnote1"] = F_Tnote;//送货备注 notePrintEntryRow["FAoument"] = Math.Ceiling(FQTY * BARCODEMAINCount);//数量 if (!"".Equals(FLOT)) { string FFlotNumber = FLOT.Split('_').ToArray()[0]; if (!FDELIVERYNOTICE.Equals(FFlotNumber)) { notePrintEntryRow["FFlotNumber"] = FFlotNumber;//批号 } } notePrintEntryRow["FFlotNumber"] = ""; notePrintEntryRow["FBoxAoument"] = Convert.ToInt32(BARCODEMAINCount);//箱数 notePrintEntryRow["FStockLoc"] = FStockLocId;//仓位 notePrintEntryRow["FMaterialID1"] = dynamicObjectP["Name"];//物料名称 notePrintEntryRow["FCustName1"] = dynamicObject["Name"];//客户名称 notePrintEntryRows.Add(notePrintEntryRow); } } } e.DynamicObjectType = dt; e.DataObjects = notePrintEntryRows.ToArray(); } } } } } 第三步:挂载表单插件 |
赞 11
11人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!