Example #1
0
        private void SendEmail(List <TaskWork> taskList)
        {
            foreach (TaskWork task in taskList)
            {
                if (task == null)
                {
                    return;
                }

                var action             = Mcdonalds.AM.Services.Common.ActionLogType.None;
                var notificationModule = new Mcdonalds.AM.Services.Common.MailHelper.NotificationModule();
                var emailMessage       = MailHelper.BuildEmailMessage(task, ref action, ref notificationModule);
                if (emailMessage == null)
                {
                    return;
                }
                EmailServiceReference.EmailSendingResultType result = null;
                if (action == Mcdonalds.AM.Services.Common.ActionLogType.Approve)
                {
                    result = MailHelper.SendApprovalEmail(emailMessage);
                }
                else
                {
                    result = MailHelper.SendCommentsEmail(emailMessage);
                }
            }
        }
        /// <summary>
        /// 添加审批邮件的Comments
        /// </summary>
        /// <param name="comments"></param>
        /// <param name="refTableId"></param>
        /// <param name="procInstID"></param>
        /// <param name="projectId"></param>
        private void AddComments(WorkflowStepInfo comments, Guid refTableId, string refTableName, int?procInstID, string projectId, string flowCode, string templateCode)
        {
            //获取操作人信息
            var            user           = Employee.GetSimpleEmployeeByCode(comments.OperatorID);
            ProjectComment projectcomment = new ProjectComment();

            projectcomment.RefTableId    = refTableId;
            projectcomment.RefTableName  = refTableName;
            projectcomment.TitleNameENUS = user.PositionENUS;
            projectcomment.TitleNameZHCN = user.PositionZHCN;
            projectcomment.TitleCode     = string.Empty;
            projectcomment.Status        = ProjectCommentStatus.Submit;

            projectcomment.CreateTime        = DateTime.Now;
            projectcomment.CreateUserAccount = user.Code;

            projectcomment.UserAccount        = user.Code;
            projectcomment.UserNameENUS       = user.NameENUS;
            projectcomment.UserNameZHCN       = user.NameZHCN;
            projectcomment.CreateUserNameZHCN = user.NameZHCN;
            if (procInstID > 0)
            {
                projectcomment.ProcInstID = procInstID;
            }
            projectcomment.Id = Guid.NewGuid();
            if (!string.IsNullOrEmpty(comments.Comments) && !comments.Comments.Equals(Constants.EmptyComments))
            {
                projectcomment.Content = comments.Comments.Trim();
            }
            projectcomment.Action = "Comments";
            projectcomment.Status = ProjectCommentStatus.Submit;

            projectcomment.SourceCode     = flowCode;
            projectcomment.SourceNameENUS = flowCode;
            projectcomment.SourceNameZHCN = flowCode;
            projectcomment.Add();

            //using (var db = new McdAMEntities())
            //{
            //    db.ProjectComment.Add(projectcomment);
            //    db.SaveChanges();
            //}
            //邮件通知邮件干系人
            string emails = string.Empty;

            EmailServiceReference.EmailMessage emailMessage = new EmailServiceReference.EmailMessage();
            var notificationModule = new Mcdonalds.AM.Services.Common.MailHelper.NotificationModule();

            if (comments != null && !string.IsNullOrEmpty(comments.SN) && !string.IsNullOrEmpty(comments.OperatorID))
            {
                emailMessage = MailHelper.BuildEmailMessage(comments.SN, ActionLogType.Comments, ref notificationModule);
                emails       = MailHelper.GetWorkflowRelationUserEmails(projectId, comments.WorkflowName, notificationModule, true);
            }
            //获取邮件的提醒人
            //var relationEmails = MailHelper.GetNotifyUserEmails(projectId, comments.WorkflowName, comments.OperatorID);
            //if (!string.IsNullOrEmpty(relationEmails))
            //{
            //    emails += relationEmails;
            //}
            emailMessage.To           = emails;
            emailMessage.TemplateCode = templateCode;
            MailHelper.SendCommentsEmail(emailMessage);
        }