Exemple #1
0
        public HttpResponseBase EditStatus()
        {
            string path = Server.MapPath(xmlPath);
            SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
            SiteConfig Mail_From = _siteConfigMgr.GetConfigByName("Mail_From");
            SiteConfig Mail_Host = _siteConfigMgr.GetConfigByName("Mail_Host");
            SiteConfig Mail_Port = _siteConfigMgr.GetConfigByName("Mail_Port");
            SiteConfig Mail_UserName = _siteConfigMgr.GetConfigByName("Mail_UserName");
            SiteConfig Mail_UserPasswd = _siteConfigMgr.GetConfigByName("Mail_UserPasswd");
            string EmailFrom = Mail_From.Value;//發件人郵箱
            string SmtpHost = Mail_Host.Value;//smtp服务器
            string SmtpPort = Mail_Port.Value;//smtp服务器端口
            string EmailUserName = Mail_UserName.Value;//郵箱登陸名
            string EmailPassWord = Mail_UserPasswd.Value;//郵箱登陸密碼

            string json = string.Empty;
            EdmContentQuery query = new EdmContentQuery();
            int i = 0;
            try
            {
                if (!string.IsNullOrEmpty(Request.Params["content_id"]))
                {
                    query.content_id = Convert.ToUInt32(Request.Params["content_id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["status"]))
                {
                    query.content_status = Convert.ToUInt32(Request.Params["status"]);
                }
                _IEdmContentMgr = new EdmContentMgr(mySqlConnectionString);
                _edmContentMgr = new EdmContentMgr(mySqlConnectionString);
                ////////////
                string FromName = string.Empty;
                string EmailTile = string.Empty;
                string strTemp = string.Empty;
                string userEmail = string.Empty;
                string userName = string.Empty;
                DataTable _emaildt = _edmContentMgr.GetTestEmailById(query.content_id);
                if (_emaildt.Rows.Count > 0)
                {
                    EmailFrom = _emaildt.Rows[0]["content_from_email"].ToString();
                    FromName = _emaildt.Rows[0]["content_from_name"].ToString();

                    EmailTile = _emaildt.Rows[0]["content_title"].ToString();
                    strTemp = _emaildt.Rows[0]["content_body"].ToString();
                }
                if (query.content_status == 1)
                {
                    //發送郵件
                    DataTable _dt = _edmContentMgr.GetAllTestEmail();
                    for (int index = 0; index < _dt.Rows.Count; index++)
                    {
                        userEmail = _dt.Rows[index]["email_address"].ToString();
                        userName = _dt.Rows[index]["test_username"].ToString();

                        bool result = sendmail(EmailFrom, FromName, userEmail, userName, EmailTile, strTemp, "", SmtpHost, Convert.ToInt32(SmtpPort), EmailUserName, EmailPassWord);
                        if (result)
                            json = "{success:true}";

                    }
                }
                if (query.content_status == 3)
                {
                    //修改狀態                  
                    i = _IEdmContentMgr.EditStatus(query);
                    if (i > 0)
                    {
                        json = "{success:true}";
                    }
                }

            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:true,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }