예제 #1
0
파일: Email.cs 프로젝트: san90279/UK_OAS
 public static string GetUrl(FLInstance flInstance, object[] clientInfo, string userID, IFLBaseActivity nextFLActivity, FLNavigatorMode mode)
 {
     string webUrl = flInstance.GetWebUrl();
     if (webUrl != null && webUrl != "0" && webUrl.IndexOf("/MainPage_Flow.aspx") > 0)
     {
         var databaseType = Srvtools.DbConnectionSet.GetDbConn((string)((object[])clientInfo[0])[2]).DbType.ToString().Replace("ct", string.Empty);
         webUrl = webUrl.Substring(0, webUrl.IndexOf("/MainPage_Flow.aspx")) + "/MainPage_Flow.aspx";
         var key = Srvtools.PublicKey.GetEncryptKey(userID, Global.GetUserName(userID, clientInfo), (string)((object[])clientInfo[0])[2], (string)((object[])clientInfo[0])[6], databaseType, (string)((object[])clientInfo[0])[5]);
         var listID = flInstance.FLInstanceId.ToString();
         IEventWaiting currentFLActivity = (IEventWaiting)flInstance.CurrentFLActivity;
         string flowPath = (currentFLActivity == null ? string.Empty : currentFLActivity.Name) + ";" + nextFLActivity.Name;
         var param = EncryptParameters(string.Format("{{\"listID\":\"{0}\", \"flowPath\":\"{1}\", \"mode\":\"{2}\"}}", listID, flowPath, mode), key);
         return string.Format("href='{0}?key={1}&param={2}'", webUrl, HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(param));
     }
     else
     {
         return string.Empty;
     }
 }
예제 #2
0
파일: Email.cs 프로젝트: san90279/UK_OAS
        /// <summary>
        /// 发送Email
        /// </summary>
        /// <param name="flInstance">流程</param>
        /// <param name="flInstanceParms">流程参数</param>
        /// <param name="keyValues">宿主筛选条件</param>
        /// <param name="roleId">角色Id</param>
        /// <param name="flActivity">Activity</param>
        /// <param name="clientInfo">ClientInfo</param>
        public static void SendTo2(FLInstance flInstance, object[] flInstanceParms, object[] keyValues, string roleId, FLActivity flActivity, object[] clientInfo)
        {
            List<string> sendToes = new List<string>();

            string tableName = ((IFLRootActivity)flInstance.RootFLActivity).TableName;
            string flowDesc = ((IFLRootActivity)flInstance.RootFLActivity).Description;
            string sUserId = ((object[])clientInfo[0])[1].ToString();
            string sUserName = Global.GetUserName(sUserId, clientInfo);

            var setting = EmailSetting.LoadSetting(clientInfo);

            var active = setting.Activie;
            if (!active)
            {
                return;
            }

            var sendFrom = setting.SendFrom;
            var password = setting.Password;
            var smtp = setting.SMTP;
            var enableSSL = setting.EnableSSL;
            var port = setting.Port;

            if (!(flActivity is IEventWaiting) && !(flActivity is IFLNotifyActivity))
            {
                return;
            }

            bool sm = false;
            if (flActivity is IEventWaiting)
            {
                sm = ((IEventWaiting)flActivity).SendEmail;
            }
            else if (flActivity is IFLNotifyActivity)
            {
                sm = ((IFLNotifyActivity)flActivity).SendEmail;
            }

            if (sm)
            {
                FLActivity nextFLActivity = flActivity;
                int plusApprove = 0;
                if (nextFLActivity is IFLStandActivity)
                {
                    plusApprove = Convert.ToInt32(((IFLStandActivity)nextFLActivity).PlusApprove);
                }
                else if (nextFLActivity is IFLApproveActivity)
                {
                    plusApprove = Convert.ToInt32(((IFLApproveActivity)nextFLActivity).PlusApprove);
                }
                else if (nextFLActivity is IFLApproveBranchActivity)
                {
                    FLActivity approve = flInstance.RootFLActivity.GetFLActivityByName(((IFLApproveBranchActivity)nextFLActivity).ParentActivity);
                    plusApprove = Convert.ToInt32(((IFLApproveActivity)approve).PlusApprove);
                }

                string users = string.Empty;
                string email = string.Empty;
                List<string> roleIds = new List<string>();
                List<string> userIds = new List<string>();
                SendToKind sk = SendToKind.Applicate;
                string sr = string.Empty;
                string su = string.Empty;
                string sf = string.Empty;
                string fn = string.Empty;
                string wfn = string.Empty;
                NavigatorMode nm = NavigatorMode.Normal;
                FLNavigatorMode fnm = FLNavigatorMode.Notify;
                if (flActivity is IEventWaiting)
                {
                    sk = ((IEventWaiting)flActivity).SendToKind;
                    sr = ((IEventWaiting)flActivity).SendToRole;
                    su = ((IEventWaiting)flActivity).SendToUser;
                    sf = ((IEventWaiting)flActivity).SendToField;
                    wfn = string.IsNullOrEmpty(((IEventWaiting)flActivity).WebFormName)
                        ? ((IFLRootActivity)flInstance.RootFLActivity).WebFormName
                        : ((IEventWaiting)flActivity).WebFormName;
                    nm = ((IEventWaiting)flActivity).NavigatorMode;
                    fnm = ((IEventWaiting)flActivity).FLNavigatorMode;
                }
                else if (flActivity is IFLNotifyActivity)
                {
                    sk = ((IFLNotifyActivity)flActivity).SendToKind;
                    sr = ((IFLNotifyActivity)flActivity).SendToRole;
                    su = ((IFLNotifyActivity)flActivity).SendToUser;
                    sf = ((IFLNotifyActivity)flActivity).SendToField;
                    wfn = string.IsNullOrEmpty(((IFLNotifyActivity)flActivity).WebFormName)
                                 ? ((IFLRootActivity)flInstance.RootFLActivity).WebFormName
                                 : ((IFLNotifyActivity)flActivity).WebFormName;
                    nm = ((IFLNotifyActivity)flActivity).NavigatorMode;
                    fnm = ((IFLNotifyActivity)flActivity).FLNavigatorMode;
                }
                //ccm   2012/11/07-------------------------------------------------------------------------------------------------------------------------------------
                if (flInstance.IsPlusApprove)
                {
                    string q = flInstanceParms[8].ToString();
                    string[] qq = q.Split(";".ToCharArray());
                    foreach (string r in qq)
                    {
                        if (!string.IsNullOrEmpty(r))
                        {
                            if (r.StartsWith("U:"))
                            {
                                userIds.Add(r.Substring(2));
                            }
                            else
                            {
                                roleIds.Add(r);
                            }
                        }
                    }
                }
                //-------------------------------------------------------------------------------------------------------------------------------------
                else if (sk == SendToKind.Applicate)
                {
                    userIds.Add(flInstance.Creator);
                }
                else
                {
                    string orgKind = ((IFLRootActivity)flInstance.RootFLActivity).OrgKind;
                    if (sk == SendToKind.Role)
                    {
                        string q = sr;
                        string[] qq = q.Split(";".ToCharArray());

                        //roleId = qq[0].Trim();
                        roleIds.Add(qq[0].Trim());
                    }
                    else if (sk == SendToKind.ApplicateManager)
                    {
                        if (!string.IsNullOrEmpty(flInstance.CreateRole))
                        {
                            //roleId = Global.GetManagerRoleId(flInstance.CreateRole, orgKind, clientInfo);
                            roleIds.Add(Global.GetManagerRoleId(flInstance.R, orgKind, clientInfo));
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(flInstance.CreateRole))
                            {
                                roleIds.Add(Global.GetManagerRoleId(flInstance.CreateRole, orgKind, clientInfo));
                            }
                            else
                            {
                                List<string> roles = Global.GetRoleIdsByUserId(flInstance.Creator, clientInfo);
                                if (roles.Count > 0)
                                {
                                    roleIds.Add(Global.GetManagerRoleId(roles[0], orgKind, clientInfo));
                                }
                            }
                        }
                    }
                    else if (sk == SendToKind.Manager)
                    {
                        if (flInstance.FLDirection == FLDirection.GoToBack)
                        {
                            // roleId = ((IEventWaitingExecute)nextFLActivity).RoleId;
                            roleIds.Add(((IEventWaitingExecute)nextFLActivity).RoleId);
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(flInstance.R))
                            {
                                // roleId = Global.GetManagerRoleId(flInstanceParms[5].ToString(), orgKind, clientInfo);
                                roleIds.Add(Global.GetManagerRoleId(flInstanceParms[5].ToString(), orgKind, clientInfo));
                            }
                            else
                            {
                                roleIds.Add(Global.GetManagerRoleId(flInstance.R, orgKind, clientInfo));
                            }
                        }
                    }
                    else if (sk == SendToKind.RefRole)
                    {
                        if (nextFLActivity is FLStandActivity && ((ISupportFLDetailsActivity)nextFLActivity).SendToId2 != string.Empty)
                        {
                            // roleId = ((ISupportFLDetailsActivity)nextFLActivity).SendToId2;
                            roleIds.Add(((ISupportFLDetailsActivity)nextFLActivity).SendToId2);
                        }
                        else
                        {
                            // roleId = Global.GetRoleIdByRefRole(sf, tableName, keyValues[1].ToString(), clientInfo);
                            roleIds.Add(Global.GetRoleIdByRefRole(flInstance, sf, tableName, keyValues[1].ToString(), clientInfo));
                        }
                    }
                    else if (sk == SendToKind.RefManager)
                    {
                        if (flInstance.FLDirection == FLDirection.GoToBack)
                        {
                            // roleId = ((IEventWaitingExecute)nextFLActivity).RoleId;
                            roleIds.Add(((IEventWaitingExecute)nextFLActivity).RoleId);
                        }
                        else
                        {
                            if (nextFLActivity is IFLApproveBranchActivity && !string.IsNullOrEmpty(flInstance.R))
                            {
                                // roleId = Global.GetManagerRoleId(flInstanceParms[5].ToString(), orgKind, clientInfo);
                                roleIds.Add(Global.GetManagerRoleId(flInstance.R, orgKind, clientInfo));
                            }
                            else
                            {
                                string sendToField = sf;
                                string values = keyValues[1].ToString();

                                string s = Global.GetRoleIdByRefRole(flInstance, sendToField, tableName, values, clientInfo);
                                // roleId = Global.GetManagerRoleId(s.ToString(), orgKind, clientInfo);
                                roleIds.Add(Global.GetManagerRoleId(s.ToString(), orgKind, clientInfo));
                            }
                        }
                    }
                    else if (sk == SendToKind.RefUser)
                    {
                        string id = Global.GetRoleIdByRefRole(flInstance, sf, tableName, keyValues[1].ToString(), clientInfo, true);

                        if (!string.IsNullOrEmpty(id))
                        {
                            string[] listusers = id.Split(';');
                            foreach (string user in listusers)
                            {
                                if (user.Trim().Length > 0)
                                {
                                    userIds.Add(user);
                                }
                            }
                        }
                    }
                    else if (sk == SendToKind.User)
                    {
                        string[] listusers = su.Split(';');
                        foreach (string user in listusers)
                        {
                            if (user.Trim().Length > 0)
                            {
                                userIds.Add(user);
                            }
                        }
                    }
                    else
                    {
                        //roleId = flInstanceParms[5].ToString();
                        roleIds.Add(flInstanceParms[5].ToString());
                    }
                }
                List<string> tempIds = new List<string>();
                foreach (string r in roleIds)
                {
                    string[] rr = r.Split(":".ToCharArray());
                    if (rr.Length > 1)
                    {
                        tempIds.Add(rr[1]);
                    }

                    List<string> userofrole = Global.GetUsersIdsByRoleId(r, clientInfo);
                    if (userofrole.Count > 0)
                    {
                        string agent = Global.GetAgent(r, userofrole[0], flInstance.RootFLActivity.Description, clientInfo);
                        if (!string.IsNullOrEmpty(agent))
                        {
                            object parAgent = Global.GetPARAGENT(flInstance.RootFLActivity.Description, agent, clientInfo);
                            if (parAgent != null && Convert.ToBoolean(parAgent))
                            {
                                tempIds.AddRange(userofrole);
                            }
                            tempIds.Add(agent);
                        }
                        else
                        {
                            tempIds.AddRange(userofrole);
                        }
                    }
                }
                foreach (string u in tempIds)
                {
                    if (userIds.Contains(u))
                        continue;

                    userIds.Add(u);
                }
                Dictionary<string, string> userEmails = new Dictionary<string, string>();
                foreach (string userId in userIds)
                {
                    if (users.Length != 0)
                    {
                        users += ",";
                    }
                    users += userId;

                    email = Global.GetUserEmail(userId, clientInfo);
                    if (email != null && email != string.Empty)
                    {
                        AddEmail(sendToes, email);
                        userEmails[userId] = email;
                    }
                }

                if (sendToes.Count == 0)
                {
                    return;
                }

                string body = string.Empty;

                if(setting.BodyActivityDescription)
                {
                    body += "<span>" + nextFLActivity.Description + "</span>";
                }

                body += "<TABLE BORDER=1>";

                if (setting.BodySender)
                {
                    body += "<TR>";
                    body += "<TD WIDTH=150>";
                    body += SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLRuntime", "InstanceManager", _sender);
                    body += "</TD>";
                    body += "<TD  COLSPAN=7>";
                    body += string.Format("[{0}]{1}", sUserId, sUserName);
                    body += "</TD>";
                    body += "</TR>";
                }

                if (setting.BodyFlowName)
                {
                    body += "<TR>";
                    body += "<TD>";
                    body += SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLRuntime", "InstanceManager", _flowName);
                    body += "</TD>";
                    body += "<TD  COLSPAN=7>";
                    body += string.IsNullOrEmpty(flowDesc) ? "&nbsp;" : flowDesc;
                    body += "</TD>";
                    body += "</TR>";
                }

                if (setting.BodyActivityName)
                {
                    body += "<TR>";
                    body += "<TD>";
                    body += SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLRuntime", "InstanceManager", _activityName);
                    body += "</TD>";
                    body += "<TD  COLSPAN=7>";
                    body += nextFLActivity.Name;
                    body += "</TD>";
                    body += "</TR>";
                }

                string presenationCT = null;
                if (setting.BodyContent)
                {
                    string presentFields = ((IFLRootActivity)flInstance.RootFLActivity).PresentFields;
                    string keys = keyValues[0].ToString();
                    string presenation = keyValues[1].ToString();
                    presenationCT = Global.GetFormPresentCT(flInstance, keys, presenation, presentFields, clientInfo);

                    body += GetPresentation(presenationCT);
                    body += GetBodyHtml(flInstance, keyValues, clientInfo);
                }

                if (setting.BodyDescription)
                {
                    string remark = flInstanceParms[4].ToString();
                    //意見內容有換行會報錯
                    remark = InitRemark(remark);
                    body += "<TR>";
                    body += "<TD>";
                    body += SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLRuntime", "InstanceManager", _description);
                    body += "</TD>";
                    body += "<TD  COLSPAN=7>";
                    body += string.IsNullOrEmpty(remark) ? "&nbsp;" : remark;
                    body += "</TD>";
                    body += "</TR>";
                }

                if (setting.BodyDatetime)
                {
                    body += "<TR>";
                    body += "<TD>";
                    body += SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLRuntime", "InstanceManager", _dateTime);
                    body += "</TD>";
                    body += "<TD  COLSPAN=7>";
                    body += DateTime.Now.ToString();
                    body += "</TD>";
                    body += "</TR>";
                }

                if (setting.BodyHyperlink)
                {
                    string webUrl = flInstance.GetWebUrl();
                    if (webUrl != null && webUrl != "0" && !string.IsNullOrEmpty(wfn))
                    {
                        if (webUrl.IndexOf("/MainPage_Flow.aspx") > 0)
                        {
                            //在下面替换
                        }
                        else
                        {
                            List<object> objs = new List<object>();
                            if (wfn.IndexOf(".web", StringComparison.OrdinalIgnoreCase) == 0 && wfn.Length > 4)
                            {
                                wfn = wfn.Substring(4);
                            }
                            string[] webFormNames = wfn.Split('.');
                            if (webFormNames.Length >= 2)
                            {
                                objs.Add(HttpUtility.UrlEncode(webFormNames[0]));
                                objs.Add(HttpUtility.UrlEncode(webFormNames[1]) + ".aspx");
                                objs.Add(HttpUtility.UrlEncode(flInstance.FLInstanceId.ToString()));
                                objs.Add(HttpUtility.UrlEncode((flInstance.CurrentFLActivity == null ? string.Empty : flInstance.CurrentFLActivity.Name) + ";" + nextFLActivity.Name));
                                objs.Add(HttpUtility.UrlEncode(keyValues[1].ToString()));
                                objs.Add(HttpUtility.UrlEncode(((int)nm).ToString()));
                                objs.Add(HttpUtility.UrlEncode(((int)fnm).ToString()));
                                objs.Add(HttpUtility.UrlEncode(users));
                                objs.Add(plusApprove);
                                objs.Add(plusApprove == 1 ? "A" : "");
                                objs.Add(roleId);
                                objs.Add(GetMultiStepReturn(flInstance, nextFLActivity) ? "1" : "0");
                                objs.Add(flInstanceParms.Length >= 10 ? HttpUtility.UrlEncode(flInstanceParms[9].ToString()) : string.Empty);

                                if (webUrl != null && webUrl != string.Empty)
                                {
                                    webUrl = string.Format(webUrl, objs.ToArray());

                                    if (setting.AutoLogin)
                                    {
                                        webUrl += "&AutoLogin=true";
                                    }
                                }
                            }
                        }

                        body += "<TR>";
                        body += "<TD>";
                        body += SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLRuntime", "InstanceManager", _hyperLink);
                        body += "</TD>";
                        body += "<TD  COLSPAN=7>";
                        body += "<a href='" + webUrl + "' target='_blank'>" + SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLRuntime", "InstanceManager", _hyperLink2) + "</a>";
                        body += "</TD>";
                        body += "</TR>";
                    }
                }

                if (setting.BodyComment)
                {
                    body += GetComments(flInstance.FLInstanceId.ToString(), clientInfo);
                }

                body += "</TABLE>";

                //---------------------------------------------------------------

                string subject = SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLRuntime", "InstanceManager", _overTime);

                if (setting.SubjectFlowName)
                {
                    subject += flowDesc + "-";
                }

                if (setting.SubjectActivityName)
                {
                    subject += nextFLActivity.Name;
                }

                if (setting.SubjectDescription)
                {
                    string remark = flInstanceParms[4].ToString();
                    //意見內容有換行會報錯
                    remark = remark.Replace("\r\n", " ");
                    if (subject.Length != 0)
                    {
                        subject += ",";
                    }

                    subject += remark;
                }

                if (setting.SubjectSender)
                {
                    if (subject.Length != 0)
                    {
                        subject += ",";
                    }

                    subject += sUserId;
                    subject += "(" + sUserName + ")";
                }

                if (setting.SubjectContent)
                {
                    if (subject.Length != 0)
                    {
                        subject += ",";
                    }
                    if (string.IsNullOrEmpty(presenationCT))
                    {
                        string presentFields = ((IFLRootActivity)flInstance.RootFLActivity).PresentFields;
                        string keys = keyValues[0].ToString();
                        string presenation = keyValues[1].ToString();
                        presenationCT = Global.GetFormPresentCT(flInstance, keys, presenation, presentFields, clientInfo);
                    }
                    subject += presenationCT;
                }

                if (subject.Length == 0 && body.Length == 0)
                {
                    return;
                }

                foreach (var userEmail in userEmails)
                {
                    var client = CreateSmtpClient(smtp, sendFrom, password, enableSSL, port);

                    MailMessage message = new MailMessage();
                    message.SubjectEncoding = Encoding.UTF8;
                    message.Priority = MailPriority.High;
                    message.BodyEncoding = Encoding.UTF8;
                    message.From = new MailAddress(sendFrom, "Workflow", System.Text.Encoding.UTF8);
                    message.To.Add(new MailAddress(userEmail.Value, userEmail.Value, Encoding.UTF8));
                    message.IsBodyHtml = true;
                    message.Subject = subject;
                    if (nextFLActivity is IEventWaiting)
                    {
                        message.Body = body.Replace("href='" + flInstance.GetWebUrl() + "'", GetUrl(flInstance, clientInfo, userEmail.Key, nextFLActivity as IEventWaiting, fnm))
                            + GetButtons(flInstance, clientInfo, setting, userEmail.Key, nextFLActivity as IEventWaiting);
                    }
                    else
                    {
                        message.Body = body.Replace("href='" + flInstance.GetWebUrl() + "'", GetUrl(flInstance, clientInfo, userEmail.Key, nextFLActivity as IFLBaseActivity, fnm));
                    }
                    //_message = message;

                    Thread thread = new Thread(new ParameterizedThreadStart(SendMail));
                    DateTime d1 = DateTime.Now;
                    thread.Start(new object[] { client, message });
                    DateTime d2 = DateTime.Now;
                    Thread.Sleep(200);
                }
            }
        }
예제 #3
0
파일: Email.cs 프로젝트: san90279/UK_OAS
        private static string GetButtons(FLInstance flInstance, object[] clientInfo, EmailSetting setting, string userID, IEventWaiting nextFLActivity)
        {
            var buttons = new StringBuilder();
            string webUrl = flInstance.GetWebUrl();
            if (webUrl != null && webUrl != "0" && webUrl.IndexOf("/MainPage_Flow.aspx") > 0)
            {
                var databaseType = Srvtools.DbConnectionSet.GetDbConn((string)((object[])clientInfo[0])[2]).DbType.ToString().Replace("ct", string.Empty);
                webUrl = webUrl.Substring(0, webUrl.IndexOf("/MainPage_Flow.aspx")) + "/FlowEmail.aspx";
                var key = Srvtools.PublicKey.GetEncryptKey(userID, Global.GetUserName(userID, clientInfo), (string)((object[])clientInfo[0])[2], (string)((object[])clientInfo[0])[6], databaseType, (string)((object[])clientInfo[0])[5]);

                buttons.Append("<br/>");
                var listID = flInstance.FLInstanceId.ToString();
                IEventWaiting currentFLActivity = (IEventWaiting)flInstance.CurrentFLActivity;
                string flowPath = (currentFLActivity == null ? string.Empty : currentFLActivity.Name) + ";" + nextFLActivity.Name;
                var titles = SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLClientControls", "FLNavigator", "NavText").Split(';');
                if (setting.ButtonApprove)
                {
                    var param = EncryptParameters(string.Format("{{\"listID\":\"{0}\", \"type\":\"{1}\", \"flowPath\":\"{2}\"}}", listID, "approve", flowPath), key);
                    buttons.Append(string.Format("<a href='{0}?key={1}&param={2}' style='margin:15px 15px 15px 5px'  target='_blank'>{3}</a>", webUrl, HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(param), titles[17]));
                }
                if (setting.ButtonReturn)
                {
                    var param = EncryptParameters(string.Format("{{\"listID\":\"{0}\", \"type\":\"{1}\", \"flowPath\":\"{2}\"}}", listID, "return", flowPath), key);
                    buttons.Append(string.Format("<a href='{0}?key={1}&param={2}' style='margin:15px'  target='_blank'>{3}</a>", webUrl, HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(param), titles[18]));
                }
                if (setting.ButtonReject)
                {
                    if (nextFLActivity.FLNavigatorMode == FLNavigatorMode.Submit)
                    {
                        var param = EncryptParameters(string.Format("{{\"listID\":\"{0}\", \"type\":\"{1}\", \"flowPath\":\"{2}\"}}", listID, "reject", flowPath), key);
                        buttons.Append(string.Format("<a href='{0}?key={1}&param={2}' style='margin:15px'  target='_blank'>{3}</a>", webUrl, HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(param), titles[19]));
                    }
                }
            }

            return buttons.ToString();
        }
예제 #4
0
파일: Email.cs 프로젝트: san90279/UK_OAS
        /// <summary>
        /// 发送Email
        /// </summary>
        /// <param name="flInstance">流程</param>
        /// <param name="flInstanceParms">流程参数</param>
        /// <param name="keyValues">宿主筛选条件</param>
        /// <param name="roleId">角色Id</param>
        /// <param name="flActivity">Activity</param>
        /// <param name="clientInfo">ClientInfo</param>
        public static void SendTo3(FLInstance flInstance, object[] flInstanceParms, object[] keyValues, FLActivity flActivity, object[] clientInfo)
        {
            List<string> sendToes = new List<string>();

            string tableName = ((IFLRootActivity)flInstance.RootFLActivity).TableName;
            string flowDesc = ((IFLRootActivity)flInstance.RootFLActivity).Description;
            string sUserId = ((object[])clientInfo[0])[1].ToString();
            string sUserName = Global.GetUserName(sUserId, clientInfo);

            var setting = EmailSetting.LoadSetting(clientInfo);

            var active = setting.Activie;
            if (!active)
            {
                return;
            }

            var sendFrom = setting.SendFrom;
            var password = setting.Password;
            var smtp = setting.SMTP;
            var enableSSL = setting.EnableSSL;
            var port = setting.Port;

            FLActivity nextFLActivity = flActivity;
            int plusApprove = 0;
            if (nextFLActivity is IFLStandActivity)
            {
                plusApprove = Convert.ToInt32(((IFLStandActivity)nextFLActivity).PlusApprove);
            }
            else if (nextFLActivity is IFLApproveActivity)
            {
                plusApprove = Convert.ToInt32(((IFLApproveActivity)nextFLActivity).PlusApprove);
            }
            else if (nextFLActivity is IFLApproveBranchActivity)
            {
                FLActivity approve = flInstance.RootFLActivity.GetFLActivityByName(((IFLApproveBranchActivity)nextFLActivity).ParentActivity);
                plusApprove = Convert.ToInt32(((IFLApproveActivity)approve).PlusApprove);
            }

            string users = string.Empty;
            string email = string.Empty;
            SendToKind sk = SendToKind.Applicate;
            string sr = string.Empty;
            string sf = string.Empty;
            string fn = string.Empty;
            string wfn = string.Empty;
            NavigatorMode nm = NavigatorMode.Normal;
            FLNavigatorMode fnm = FLNavigatorMode.Notify;
            if (flActivity is IEventWaiting)
            {
                sk = ((IEventWaiting)flActivity).SendToKind;
                sr = ((IEventWaiting)flActivity).SendToRole;
                sf = ((IEventWaiting)flActivity).SendToField;
                wfn = string.IsNullOrEmpty(((IEventWaiting)flActivity).WebFormName)
                    ? ((IFLRootActivity)flInstance.RootFLActivity).WebFormName
                    : ((IEventWaiting)flActivity).WebFormName;
                nm = ((IEventWaiting)flActivity).NavigatorMode;
                //fnm = ((IEventWaiting)flActivity).FLNavigatorMode;
            }
            else if (flActivity is IFLNotifyActivity)
            {
                sk = ((IFLNotifyActivity)flActivity).SendToKind;
                sr = ((IFLNotifyActivity)flActivity).SendToRole;
                sf = ((IFLNotifyActivity)flActivity).SendToField;
                wfn = string.IsNullOrEmpty(((IFLNotifyActivity)flActivity).WebFormName)
                             ? ((IFLRootActivity)flInstance.RootFLActivity).WebFormName
                             : ((IFLNotifyActivity)flActivity).WebFormName;
                nm = ((IFLNotifyActivity)flActivity).NavigatorMode;
                //fnm = ((IFLNotifyActivity)flActivity).FLNavigatorMode;
            }

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

            string s = flInstanceParms[8].ToString();
            string[] ss = s.Split(';');
            foreach (string id in ss)
            {
                if (string.IsNullOrEmpty(id))
                    continue;

                string[] ss1 = id.Split(':');
                if (ss1.Length <= 1)
                {
                    List<string> userofrole = Global.GetUsersIdsByRoleId(ss1[0], clientInfo);
                    if (userofrole.Count > 0)
                    {
                        string agent = Global.GetAgent(ss1[0], userofrole[0], flInstance.RootFLActivity.Description, clientInfo);
                        if (!string.IsNullOrEmpty(agent))
                        {
                            object parAgent = Global.GetPARAGENT(flInstance.RootFLActivity.Description, agent, clientInfo);
                            if (parAgent != null && Convert.ToBoolean(parAgent))
                            {
                                userIds.AddRange(userofrole);
                            }
                            userIds.Add(agent);
                        }
                        else
                        {
                            userIds.AddRange(userofrole);
                        }
                    }
                }
                else
                {
                    userIds.Add(ss1[0]);
                }
            }
            Dictionary<string, string> userEmails = new Dictionary<string, string>();
            foreach (string userId in userIds)
            {
                if (users.Length != 0)
                {
                    users += ",";
                }
                users += userId;

                email = Global.GetUserEmail(userId, clientInfo);
                if (email != null && email != string.Empty)
                {
                    AddEmail(sendToes, email);
                    userEmails[userId] = email;
                }
            }

            if (sendToes.Count == 0)
            {
                return;
            }
            string body = string.Empty;
            if (setting.BodyActivityDescription)
            {
                body += "<span>" + nextFLActivity.Description + "</span>";
            }

            body += "<TABLE BORDER=1>";

            if (setting.BodySender)
            {
                body += "<TR>";
                body += "<TD WIDTH=150>";
                body += SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLRuntime", "InstanceManager", _sender);
                body += "</TD>";
                body += "<TD  COLSPAN=7>";
                body += string.Format("[{0}]{1}", sUserId, sUserName);
                body += "</TD>";
                body += "</TR>";
            }

            if (setting.BodyFlowName)
            {
                body += "<TR>";
                body += "<TD>";
                body += SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLRuntime", "InstanceManager", _flowName);
                body += "</TD>";
                body += "<TD  COLSPAN=7>";
                body += string.IsNullOrEmpty(flowDesc) ? "&nbsp;" : flowDesc;
                body += "</TD>";
                body += "</TR>";
            }

            if (setting.BodyActivityName)
            {
                body += "<TR>";
                body += "<TD>";
                body += SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLRuntime", "InstanceManager", _activityName);
                body += "</TD>";
                body += "<TD  COLSPAN=7>";
                body += nextFLActivity.Name;
                body += "</TD>";
                body += "</TR>";
            }

            string presenationCT = null;
            if (setting.BodyContent)
            {
                string presentFields = ((IFLRootActivity)flInstance.RootFLActivity).PresentFields;
                string keys = keyValues[0].ToString();
                string presenation = keyValues[1].ToString();
                presenationCT = Global.GetFormPresentCT(flInstance, keys, presenation, presentFields, clientInfo);

                body += GetPresentation(presenationCT);
                body += GetBodyHtml(flInstance, keyValues, clientInfo);
            }

            if (setting.BodyDescription)
            {
                string remark = flInstance.IsReturn == true ? "Return(system)" : (flInstanceParms[4] == null ? string.Empty : flInstanceParms[4].ToString());
                //意見內容有換行會報錯
                remark = InitRemark(remark);
                body += "<TR>";
                body += "<TD>";
                body += SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLRuntime", "InstanceManager", _description);
                body += "</TD>";
                body += "<TD  COLSPAN=7>";
                body += string.IsNullOrEmpty(remark) ? "&nbsp;" : remark;
                body += "</TD>";
                body += "</TR>";
            }

            if (setting.BodyDatetime)
            {
                body += "<TR>";
                body += "<TD>";
                body += SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLRuntime", "InstanceManager", _dateTime);
                body += "</TD>";
                body += "<TD  COLSPAN=7>";
                body += DateTime.Now.ToString();
                body += "</TD>";
                body += "</TR>";
            }

            if (setting.BodyHyperlink)
            {
                string webUrl = flInstance.GetWebUrl();
                if (webUrl != null && webUrl != "0" && !string.IsNullOrEmpty(wfn))
                {
                    if (webUrl.IndexOf("/MainPage_Flow.aspx") > 0)
                    {
                        //在下面替换
                    }
                    else
                    {
                        List<object> objs = new List<object>();
                        if (wfn.IndexOf(".web", StringComparison.OrdinalIgnoreCase) == 0 && wfn.Length > 4)
                        {
                            wfn = wfn.Substring(4);
                        }
                        string[] webFormNames = wfn.Split('.');
                        if (webFormNames.Length >= 2)
                        {
                            objs.Add(HttpUtility.UrlEncode(webFormNames[0]));
                            objs.Add(HttpUtility.UrlEncode(webFormNames[1]) + ".aspx");
                            objs.Add(HttpUtility.UrlEncode(flInstance.FLInstanceId.ToString()));
                            objs.Add(HttpUtility.UrlEncode((flInstance.CurrentFLActivity == null ? string.Empty : flInstance.CurrentFLActivity.Name) + ";" + nextFLActivity.Name));
                            objs.Add(HttpUtility.UrlEncode(keyValues[1].ToString()));
                            objs.Add(HttpUtility.UrlEncode(((int)nm).ToString()));
                            objs.Add(HttpUtility.UrlEncode(((int)fnm).ToString()));
                            objs.Add(HttpUtility.UrlEncode(users));
                            objs.Add(plusApprove);
                            objs.Add(plusApprove == 1 ? "A" : "");
                            objs.Add(string.Empty);//roleid
                            objs.Add("0");
                            objs.Add(flInstanceParms.Length >= 10 ? HttpUtility.UrlEncode(flInstanceParms[9].ToString()) : string.Empty);

                            if (webUrl != null && webUrl != string.Empty)
                            {
                                webUrl = string.Format(webUrl, objs.ToArray());

                                if (setting.AutoLogin)
                                {
                                    webUrl += "&AutoLogin=true";
                                }
                            }
                        }
                    }

                    body += "<TR>";
                    body += "<TD>";
                    body += SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLRuntime", "InstanceManager", _hyperLink);
                    body += "</TD>";
                    body += "<TD  COLSPAN=7>";
                    body += "<a href='" + webUrl + "' target='_blank'>" + SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(clientInfo[0]))[0]), "FLRuntime", "InstanceManager", _hyperLink2) + "</a>";
                    body += "</TD>";
                    body += "</TR>";
                }
            }

            if (setting.BodyComment)
            {
                body += GetComments(flInstance.FLInstanceId.ToString(), clientInfo);
            }

            body += "</TABLE>";

            //---------------------------------------------------------------

            string subject = GetSubjectHtml(flInstance, new FLNotifyActivity(), clientInfo);
            if (setting.SubjectFlowName)
            {
                subject += flowDesc + "-";
            }

            if (setting.SubjectActivityName)
            {
                subject += nextFLActivity.Name;
            }

            if (setting.SubjectDescription)
            {
                string remark = "";
                if (subject.Length != 0)
                {
                    subject += ",";
                }

                subject += remark;
            }

            if (setting.SubjectSender)
            {
                if (subject.Length != 0)
                {
                    subject += ",";
                }

                subject += sUserId;
                subject += "(" + sUserName + ")";
            }

            if (setting.SubjectContent)
            {
                if (subject.Length != 0)
                {
                    subject += ",";
                }
                if (string.IsNullOrEmpty(presenationCT))
                {
                    string presentFields = ((IFLRootActivity)flInstance.RootFLActivity).PresentFields;
                    string keys = keyValues[0].ToString();
                    string presenation = keyValues[1].ToString();
                    presenationCT = Global.GetFormPresentCT(flInstance, keys, presenation, presentFields, clientInfo);
                }
                subject += presenationCT;
            }

            if (subject.Length == 0 && body.Length == 0)
            {
                return;
            }

            foreach (var userEmail in userEmails)
            {
                var client = CreateSmtpClient(smtp, sendFrom, password, enableSSL, port);

                MailMessage message = new MailMessage();
                message.SubjectEncoding = Encoding.UTF8;
                message.BodyEncoding = Encoding.UTF8;
                message.From = new MailAddress(sendFrom, "Workflow", System.Text.Encoding.UTF8);
                message.To.Add(new MailAddress(userEmail.Value, userEmail.Value, Encoding.UTF8));
                message.IsBodyHtml = true;
                message.Subject = subject;
                message.Body = body.Replace("href='" + flInstance.GetWebUrl() + "'", GetUrl(flInstance, clientInfo, userEmail.Key, nextFLActivity as IFLBaseActivity, fnm));
                //_message = message;

                Thread thread = new Thread(new ParameterizedThreadStart(SendMail));
                DateTime d1 = DateTime.Now;
                thread.Start(new object[] { client, message });
                DateTime d2 = DateTime.Now;
                Thread.Sleep(200);
            }
        }