小小改了一下,使用基础资料加邮件接收人

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

小小改了一下,使用基础资料加邮件接收人

执行计划列表添加邮件接收人

using Kingdee.BOS;
using Kingdee.BOS.App.Core;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Const;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.List.PlugIn;
using Kingdee.BOS.Core.ListFilter;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Core.Permission;
using Kingdee.BOS.Core.Report;
using Kingdee.BOS.FileServer.Core.Object;
using Kingdee.BOS.FileServer.ProxyService;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Log;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.ServiceHelper.Excel;
using Kingdee.BOS.Util;
using Kingdee.BOS.Web.Core;
using Kingdee.BOS.Web.DynamicForm;
using Kingdee.BOS.Web.List;
using Kingdee.BOS.Web.Printing;
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Diagnostics;
using Kingdee.BOS.Orm;
using Kingdee.BOS.App.Data;
using System.Runtime.Remoting.Messaging;

namespace kdlst2mail
{
    /// <summary>
    /// 【执行计划】引出列表数据并发送邮件
    /// https://wenku.my7c.com/article/345938598287195392
    /// </summary>
    public class ExportListDataAndSendEmailScheduleService : IScheduleService
    {
        /// <summary>
        /// 执行计划入口函数
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="schedule"></param>
        public void Run(Context ctx, Schedule schedule)
        {
            try
            {
                // 设置组织(SELECT * FROM T_ORG_ORGANIZATIONS)
                ctx.CurrentOrganizationInfo = new OrganizationInfo
                {
                    ID = 1,
                    Name = "蓝海有限公司"
                };
                // 设置用户(SELECT * FROM T_SEC_USER)
                ctx.UserId = 100092;
                ctx.UserName = "htc";
                // 设置单据
                //var formId = "PUR_PurchaseOrder";//取界面上的表单ID控件值
                var formId = schedule.ParameterFormId;
                // 设置过滤方案(SELECT * FROM T_BAS_FILTERSCHEME WHERE FFORMID='PUR_PurchaseOrder' AND FUSERID=100008)
                //var schemeId = "62df6021e6f83e";//取界面上的参数控件值
                var schemeId = schedule.Parameters;
                var schemguid = schedule.ScheduleTypeId;
                var tolist = new List<string>();
                var cclist = new List<string>();
                var mysql = "exec get_zxjhyjlb '" + schemguid + "'";
                using (IDataReader dr = DBServiceHelper.ExecuteReader(ctx, mysql))
                {
                    while (dr.Read())
                    {
                        string result = dr.GetString(0);
                        tolist.Add(result);
                    }
                }
                // 创建列表视图
                var view = new ListViewBuilder().CreateListPrintView(ctx, formId, schemeId);
                // 生成引出数据
                var listExportService = new ListExportService(view);
                var filePath = listExportService.ExportData();
                // 发送邮件
                listExportService.SendMail(filePath,tolist,cclist);
            }
            catch (Exception ex)
            {
                Logger.Error("htc", "引出列表数据时发生异常:" + ex.Message, ex);
                throw;
            }
        }
    }

        ///其它代码查看官方链接*************

        /// <summary>
        /// 发送邮件
        /// 参考:https://wenku.my7c.com/article/131834587734451200
        /// </summary>
        public void SendMail(string filePath,List<string> tolist, List<string> cclist)
        {
            var sendMailService = new SendMailService();
            // 获取邮件服务器信息,发件人信息
            var emailInfo = sendMailService.GetEmailMessageInfoByUserId(view.Context, view.Context.UserId);
            // 设置邮件标题
            emailInfo.Subject = "采购订单列表引出数据";
            // 设置邮件内容
            emailInfo.Body = string.Format("单据名称:采购订单<br><br>导出人:{0}<br><br>导出时间:{1}", view.Context.UserName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            // 设置邮件接收人
            emailInfo.To = tolist;
            //BusinessDataServiceHelper.Load
            // 设置邮件抄送人
            emailInfo.Cc = cclist;
            // 设置邮件附件信息
            if (!string.IsNullOrWhiteSpace(filePath) && File.Exists(filePath))
            {
                emailInfo.Attachments = new List<string>();
                emailInfo.Attachments.Add(_filePath);
            }
            else
            {
                emailInfo.Body += "\r\n本次操作未查询到满足条件的数据,无引出文件。";
            }

            MailUtils.Sendmail(emailInfo);
        }
}


CREATE PROCEDURE [DBO].[GET_ZXJHYJLB] @FSCHEDULETYPEID VARCHAR(300)=''
AS
BEGIN

SELECT FEMAIL FROM T_HR_EMPINFO WITH(NOLOCK) WHERE FID IN (
SELECT F_TOLIST FROM SCO_T_HTC_ENTRY100007 WITH(NOLOCK) WHERE  FSCHEDULETYPEID=@FSCHEDULETYPEID
)

END


留意,需要使用<br>来实现换行,用&nbsp;&nbsp;来实现缩进

小小改了一下,使用基础资料加邮件接收人

执行计划列表添加邮件接收人using Kingdee.BOS;using Kingdee.BOS.App.Core;using Kingdee.BOS.Contracts;using Kingdee.BOS.Core;using Ki...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息