邮件.二开案例.按列表选中行加载收件人

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

邮件.二开案例.按列表选中行加载收件人

【场景】按列表选中行加载收件人 【案例】采购申请单,使用明细的建议供应商发送邮件; 发送时使用选中行的供应商邮箱作为收件人 ```csharp using Kingdee.BOS.Core; using Kingdee.BOS.Core.Bill; using Kingdee.BOS.Core.CommonFilter; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.Enums; using Kingdee.BOS.Core.List; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Core.Metadata.EntityElement; using Kingdee.BOS.Core.Metadata.FieldElement; using Kingdee.BOS.Core.Metadata.FormElement; using Kingdee.BOS.Core.Metadata.Operation; using Kingdee.BOS.Core.SqlBuilder; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.Linq; namespace DynamicFormPlugIn.Mail { [Kingdee.BOS.Util.HotUpdate] [System.ComponentModel.Description("发送邮件,针对列表,取选中行收件人逻辑")] public class MailFormPlugIn_Extend : AbstractDynamicFormPlugIn { /* * 针对特定单据,按照选中行数据加载默认收件人 */ /// <summary> /// 指定的业务对象标识 /// </summary> string specFormId = "PUR_Requisition"; private string[] selectIds; private SendMailParameter sendMailParam; public override void OnInitialize(InitializeEventArgs e) { if (this.View.ParentFormView == null) return; //是否特定表单 if (!string.Equals(this.View.ParentFormView.BillBusinessInfo.GetForm().Id, specFormId, StringComparison.OrdinalIgnoreCase)) return; selectIds = (e.Paramter.GetCustomParameter("Ids") as string[]) ?? new string[] { }; //加载操作的发送邮件参数 var formOp = this.View.ParentFormView.BillBusinessInfo.GetForm().GetOperation("SendMail"); if (formOp == null) return; sendMailParam = formOp.Parmeter as SendMailParameter; } public override void AfterBindData(EventArgs e) { if (sendMailParam == null) return; const string mailAddress = "FMailAddress"; Entity entity = this.View.BillBusinessInfo.GetEntity(mailAddress); DynamicObjectCollection entityObjs = this.View.Model.GetEntityDataObject(entity); //<0>清掉前面加载的收件人逻辑 entityObjs.Clear(); //<1>根据既定逻辑加载自己的收件人 AppendSupplierMail(entityObjs); this.View.UpdateView(mailAddress); } private void AppendSupplierMail(DynamicObjectCollection entityObjs) { List<int> pkIds = GetBillSupplierId(); var supplilerObjs = GetSupplierById(pkIds, 1); for (int i = 0; i < supplilerObjs.Count; ++i) { DynamicObject rowObj = new DynamicObject(entityObjs.DynamicCollectionItemPropertyType); entityObjs.Add(rowObj); rowObj["FSendeeType"] = "supplier"; rowObj["FSendeeKey"] = supplilerObjs[i]["FSUPPLIERID"]; rowObj["FSendee"] = supplilerObjs[i]["FName"]; rowObj["FUser"] = supplilerObjs[i]["FCONTACT"]; rowObj["FToAddress"] = supplilerObjs[i]["FEmail"]; this.View.StyleManager.SetEnabled("FUser", rowObj, "LockFieldService", true); this.View.StyleManager.SetEnabled("FToAddress", rowObj, "LockFieldService", false); } } /// <summary> /// 获取单据关联的供应商内码 /// </summary> /// <returns></returns> private List<int> GetBillSupplierId() { List<int> result = new List<int>(); IDynamicFormView parentView = this.View.ParentFormView; if (parentView == null) return result; BaseDataField loadField = parentView.BillBusinessInfo.GetField(sendMailParam.SupplierFieldKey) as BaseDataField; Form form = parentView.BillBusinessInfo.GetForm(); string billPk = form.PkFieldName; string baseField = loadField.FieldName; QueryBuilderParemeter queryParameter = new QueryBuilderParemeter(); queryParameter.RequiresDataPermission = true; queryParameter.FormId = parentView.BillBusinessInfo.GetForm().Id; queryParameter.SelectItems = SelectorItemInfo.CreateItems(string.Format("{0},{1}", billPk, baseField)); if (parentView is IBillView) { //针对单据界面的特殊处理 queryParameter.FilterClauseWihtKey = string.Format("{0} in ('{1}')", billPk, string.Join("','", this.selectIds)); } else if(parentView is IListView) { if(loadField.Entity.EntityType != (int)Entity.ENTRY_TYPE) { queryParameter.FilterClauseWihtKey = string.Format("{0} in ('{1}')", billPk, string.Join("','", this.selectIds)); } else { //针对列表界面的特殊处理,加载选中行的供应商 IListView listView = parentView as IListView; //获取对应的实体标识 List<FilterEntity> selectEntitnes = listView.Model.FilterParameter.SelectedEntities; var selectEntity = selectEntitnes.FirstOrDefault(x => string.Equals( x.Key, loadField.EntityKey,StringComparison.OrdinalIgnoreCase)); if (selectEntity == null) { queryParameter.FilterClauseWihtKey = string.Format("{0} in ('{1}')", billPk, string.Join("','", this.selectIds)); } else { //按分录查询 string entityKey = selectEntity.Key; List<string> entityIds = new List<string>(); foreach (var selectRow in listView.SelectedRowsInfo) { string entiyId = selectRow.FieldValues[entityKey]; entityIds.Add(entiyId); } queryParameter.FilterClauseWihtKey = string.Format("{0} in ('{1}')", loadField.Entity.EntryPkFieldName, string.Join("','", entityIds)); } } } var billDaataObjs = QueryServiceHelper.GetDynamicObjectCollection(this.View.Context, queryParameter); if(billDaataObjs == null) { return result; } foreach(var billData in billDaataObjs) { int supplierId = ObjectUtils.Object2Int(billData[loadField.FieldName]); if (supplierId == 0) continue; result.Add(supplierId); } result = result.Distinct().ToList(); return result; } /// <summary> /// 根据供应商获取邮箱账号 /// </summary> /// <param name="pkIds">供应商内码集合</param> /// <param name="limit">获取数据的行数</param> /// <returns></returns> private List<DynamicObject> GetSupplierById(List<int> pkIds, int limit = -1) { if (pkIds == null || pkIds.Count <= 0) return new List<DynamicObject>(); QueryBuilderParemeter queryParameter = new QueryBuilderParemeter(); queryParameter.RequiresDataPermission = true; queryParameter.FormId = FormIdConst.BD_Supplier; queryParameter.SelectItems = SelectorItemInfo.CreateItems("FSUPPLIERID,FNAME,FCONTACT,FEMAIL,FContactIsDefault,FContactNumber"); queryParameter.FilterClauseWihtKey = string.Format("FSUPPLIERID in ({0})", string.Join(",", pkIds)); queryParameter.OrderByClauseWihtKey = "FSUPPLIERID ASC,FContactIsDefault DESC,FContactNumber ASC"; queryParameter.StartRow = 0; queryParameter.Limit = limit; queryParameter.TopRowCount = 0; var dataObjs = QueryServiceHelper.GetDynamicObjectCollection(this.Context, queryParameter); var dic = new Dictionary<string, DynamicObject>(); var dicIsDef = new Dictionary<string, bool>(); foreach (DynamicObject o in dataObjs) { string id = o[0].ToString(); if (dic.ContainsKey(id) && dicIsDef.ContainsKey(id)) { if (dicIsDef[id] == true) continue; } dic[id] = o; dicIsDef[id] = Convert.ToBoolean(o["FContactIsDefault"]); } return dic.Values.ToList(); } } } ``` 【效果】 ![20230928 1449.webp](/download/010083de3232585344fabe9bc5533c204ed8.webp)

Mark!~

邮件.二开案例.按列表选中行加载收件人

【场景】按列表选中行加载收件人【案例】采购申请单,使用明细的建议供应商发送邮件;发送时使用选中行的供应商邮箱作为收件人```csharpusi...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息