报表发送邮件,并按客户分别发送原创
金蝶云社区-彭碰车
彭碰车
5人赞赏了该文章 162次浏览 未经作者许可,禁止转载编辑于2024年05月07日 14:49:41


using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;

using Kingdee.BOS.Core.NotePrint;

using Kingdee.BOS.JSON;

using Kingdee.BOS.Orm.DataEntity;

using Kingdee.BOS.Resource;

using Kingdee.BOS.Util;

using Kingdee.BOS.VerificationHelper;

using Kingdee.BOS.Core.Report.PlugIn;

using System.ComponentModel;

using Kingdee.BOS.Core.CommonFilter;

using System.Collections.Generic;

using System;

using System.Data;

using Kingdee.BOS.Core;

using System.IO;

using Kingdee.BOS.Core.DynamicForm;

using System.Linq;

using Kingdee.K3.FIN.Core;

using Kingdee.BOS.App;

using Kingdee.BOS.Contracts;

using Kingdee.BOS.KDThread;


namespace YOL.K3.FIN.ReportPlugIn

{

// Token: 0x0200003A RID: 58

[Description("报表邮件发送插件")]

public class SendEmail : AbstractSysReportPlugIn

{



// Token: 0x0600028E RID: 654 RVA: 0x0001FB5C File Offset: 0x0001DD5C

public override void OnInitialize(InitializeEventArgs e)

{

base.OnInitialize(e);


}



public override void BarItemClick(BarItemClickEventArgs e)

{

base.BarItemClick(e);

DynamicObject para = this.SysReportModel.FilterParameter.CustomFilter;

this.endDate = Convert.ToDateTime(para["F_YOL_Date"]).ToString("yyyy-MM-dd");

string barItemKey = e.BarItemKey;

switch (barItemKey)

{

case "tbSendMail":

LicenseVerifier.CheckViewOnlyOperation(base.Context, ResManager.LoadKDString("发送邮件", "003227000038276", (SubSystemType)4, new object[0]));

if (!AccessServiceHelper.PermissionAuthEx(base.Context, this.View.OpenParameter.SubSystemId, this.View.Model.BillBusinessInfo.GetForm().Id, "545c6fb576151f", 0L))

{

this.View.ShowMessage(ResManager.LoadKDString("没有发送邮件的权限", "003227000032890", 4, new object[0]), 0);

return;

}

if (!AccessServiceHelper.PermissionAuthEx(base.Context, this.View.OpenParameter.SubSystemId, this.View.Model.BillBusinessInfo.GetForm().Id, "8dfa91ae26774d7ea46b29e29ecb3044", 0L))


{

this.View.ShowMessage(ResManager.LoadKDString("没有打印的权限", "003192030037431", 4, new object[0]), 0);

return;

}

this.BeginSendEmail();


return;


}

}


// Token: 0x06000293 RID: 659 RVA: 0x000202B4 File Offset: 0x0001E4B4

private void BeginSendEmail()

{

//DataTable table = this.SysReportModel.DataSource;

DataTable table = this.SysReportModel.GetData(0, this.SysReportModel.GetRowCount());//获取报表数据


            if (table == null)


{

                this.View.ShowMessage(ResManager.LoadKDString("没有可发送的数据", "003227000022614", (SubSystemType)4, new object[0]), 0);

                return;

            }

            //StatementSendMailCust statementSendMail = new StatementSendMailCust(this.View);

this.GetDefaultPrintTemplateId();

            if (this.PrintTemplateId.Length <= 0)

            {

                this.View.ShowMessage(ResManager.LoadKDString("没有配置套打模板", "003192030037432", (SubSystemType)4, new object[0]), 0);

                return;

            }


this.DoSendEmail(table);

}

public void GetDefaultPrintTemplateId()

{

JSONArray jsonarray = null;

string text = string.Empty;

string text2 = "NotePrintSetup";

string id = this.View.BusinessInfo.GetForm().Id;

string text3 = " ";

string text4 = text2 + id.ToUpperInvariant().GetHashCode().ToString();

string text5 = ServiceHelper.GetService<IUserParameterService>().Load(this.View.Context, text4, this.View.Context.UserId, "");

if (string.IsNullOrWhiteSpace(text5))

{

text5 = ServiceHelper.GetService<IUserParameterService>().Load(this.View.Context, text4, -1L, "");

}

if (string.IsNullOrWhiteSpace(text5))

{

text5 = ServiceHelper.GetService<IUserParameterService>().Load(this.View.Context, text2 + id.GetHashCode().ToString(), this.View.Context.UserId, "");

}

text5 = StringUtils.FixedOrcalXMLString(text5);

if (!string.IsNullOrWhiteSpace(text5) && text5 != "<Root />")

{

jsonarray = new JSONArray(text5);

}

if (jsonarray != null)

{

foreach (object obj in jsonarray)

{

Dictionary<string, object> dictionary = (Dictionary<string, object>)obj;

object obj2;

object obj3;

if (dictionary.TryGetValue("key", out obj2) && dictionary.TryGetValue("value", out obj3))

{

if (!ObjectUtils.IsNullOrEmptyOrWhiteSpace(obj2) && (obj2.Equals(text3) || (ObjectUtils.IsNullOrEmptyOrWhiteSpace(text3) && obj2.Equals("reportNote"))) && !ObjectUtils.IsNullOrEmptyOrWhiteSpace(obj3) && !obj3.Equals("empty"))

{

text = ObjectUtils.Object2String(obj3);

break;

}

if (ObjectUtils.IsNullOrEmptyOrWhiteSpace(obj2) && !ObjectUtils.IsNullOrEmptyOrWhiteSpace(obj3) && !obj3.Equals("empty"))

{

text = ObjectUtils.Object2String(obj3);

}

}

}

}

this.PrintTemplateId = text;

}

public void DoSendEmail(DataTable dataInfo)

{

List<string> list2 = new List<string>();

List<string> list3 = new List<string>();


OperateResultCollection operateResultCollection = new OperateResultCollection();

// Dictionary<long, Dictionary<string, StatementSendMail.AmountForEmail>> dictionary = this.BuildCurAmounts(list);


var groupedData = dataInfo.AsEnumerable().GroupBy(row => row["F_CustomerNumber"]);


// string name = "";

foreach (var group in groupedData)

{

var firstRow = group.FirstOrDefault();

if (firstRow != null)

{

list3.Add(Convert.ToString(firstRow["F_Email"]));//获取邮箱

customerName = Convert.ToString(firstRow["F_CustomerName"]);

}

List<string> listBillIds = new List<string>();


Dictionary<long, string> dictionary2 = new Dictionary<long, string>();

string name = "";

string formId = this.View.BusinessInfo.GetForm().Id;

if (formId.Equals("AccountsReceivableReport")) {

name = "应收账龄明细分析表";

}


string text = "附件为"+ name + "明细,请查收";

list2 = BuildPdfs(group,name);

OperateResult operateResult = FINCommonFunc.SendMail2(this.View.Context, string.Format("{0}({1})({2})", name, customerName, DateTime.Now.ToString("yyyy-MM-dd")), text, list2, list3);


operateResult.Name = Convert.ToString(customerName);

operateResultCollection.Add(operateResult);

list3.Clear();


}

this.View.ShowOperateResult(operateResultCollection, "BOS_BatchTips");

}

private List<string> BuildPdfs(IGrouping<object, DataRow> contactInfo,string name)

{

List<string> listFiles = new List<string>();

PrintExportInfo printExportInfo = new PrintExportInfo();

List<string> list = new List<string>();

//删除后的数据生成打印模板

IDynamicFormViewService dynamicFormViewService = this.View as IDynamicFormViewService;

foreach (DataRow dynamicObject in contactInfo)

{

list.Add(Convert.ToString(dynamicObject["FIDENTITYID"]));



}

string physicalPath = PathUtils.GetPhysicalPath(KeyConst.TEMPFILEPATH, string.Format("{0}_{1}_{2}.pdf", customerName, name, endDate));

if (File.Exists(physicalPath))

{

File.Delete(physicalPath);

}

// string PageId = currentView.PageId;

dynamicFormViewService.ExportNotePrint(new PrintExportInfo

{

PageId = this.View.PageId,

FormId = this.View.BusinessInfo.GetForm().Id,

BillIds = list,

TemplateIds = new List<string> { this.PrintTemplateId },

FileType = (ExportFileType)2,//XLSX = 0,XLS = 1,PDF = 2

ExportType = 0,

FilePath = physicalPath

});

listFiles.Add(physicalPath);




return listFiles;

}

//按客户分组生成PDF

public override void OnPrepareNotePrintData(PreparePrintDataEventArgs e)

{

base.OnPrepareNotePrintData(e);

if (e.DataSourceId == "FList")

{

e.DataObjects = e.DataObjects.Where(p => p["F_CustomerName"].ToString() == customerName).ToArray();

}

}

protected string endDate;

// Token: 0x04000198 RID: 408

protected string tempTable;


protected FilterParameter filterPara;


protected string PrintTemplateId;


protected string customerName;



}

}


图标赞 5
5人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!