Ejemplo n.º 1
0
        /*
         編輯的預覽按鈕和列表頁的預覽都訪問這個方法
         * 1.
         * 
         */
        public HttpResponseBase GetPreviewHtml()
        {
            string html = string.Empty;
            string replaceStr = string.Empty;
            string contentStr = string.Empty;
            string templateStr = string.Empty;
            string recommendStr = string.Empty;
            string previewStr = string.Empty;
            string editStr = string.Empty;
            try
            {
                _edmContentNewMgr = new EdmContentNewMgr(mySqlConnectionString);
                EdmContentNew query = new EdmContentNew();

                //將傳過來的html加上根據當前登入者的id獲得的推薦html替換掉content_url中的替換符
                if (!string.IsNullOrEmpty(Request.Params["content_id"]))
                {
                    query.content_id = Convert.ToInt32(Request.Params["content_id"]);
                    string content_url = _edmContentNewMgr.GetContentUrlByContentId(query.content_id);
                    if (!string.IsNullOrEmpty(content_url))
                    {
                        #region 獲取網頁內容
                        HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(content_url);
                        httpRequest.Timeout = 9000;
                        httpRequest.Method = "GET";
                        HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
                        StreamReader sr = new StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
                        contentStr = sr.ReadToEnd();
                        #endregion
                    }
                    else
                    {
                        contentStr = "";
                    }
                    
                }
                //列表頁的預覽按鈕不進這個方法
                if (!string.IsNullOrEmpty(Request.Params["template_id"]))
                {
                    query.template_id = Convert.ToInt32(Request.Params["template_id"]);
                    edmtemplatemgr = new EdmTemplateMgr(mySqlConnectionString);
                    if (edmtemplatemgr.GetStaticTemplate(query.template_id))
                    {
                        recommendStr = string.Empty;
                    }
                    else
                    {
                        recommendStr = _edmContentNewMgr.GetRecommendHtml(Convert.ToUInt32((Session["caller"] as Caller).user_id));
                    }
                }
                //獲取template_data(編輯器中的內容或者是表中的template_data)
                if (!string.IsNullOrEmpty(Request.Params["template_data"]))
                {
                    templateStr = Request.Params["template_data"];
                }
                else
                {
                    templateStr = _edmContentNewMgr.GetHtml(query);
                }
                //編輯的預覽按鈕不進這個方法
                //根據user_id獲得精準推薦
                if (!string.IsNullOrEmpty(Request.Params["static_template"]))
                {
                    if (Request.Params["static_template"] == "0")// 動態範本,精準推薦
                    {
                        recommendStr = _edmContentNewMgr.GetRecommendHtml(Convert.ToUInt32((Session["caller"] as Caller).user_id));
                    }
                    else
                    {
                        recommendStr = string.Empty;
                    }
                }
             
                //替換符
                DataTable _dt = _edmContentNewMgr.GetPraraData(1);
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    replaceStr = _dt.Rows[0][0].ToString();
                }
                else
                {
                    replaceStr = "  ";
                }
                //分隔符
                DataTable _dtEdit = _edmContentNewMgr.GetPraraData(3);
                if (_dtEdit != null && _dtEdit.Rows.Count > 0)
                {
                    editStr = _dtEdit.Rows[0][0].ToString();
                }
                else
                {
                    editStr = "  ";
                }
                    templateStr = templateStr.Replace(editStr,"") + recommendStr;
                    if (Request.Params["checked"] == "true")
                    {
                        if (!string.IsNullOrEmpty(contentStr))
                        {
                            previewStr = contentStr.Replace(replaceStr, templateStr) + subscribe_url;
                        }
                        else
                        {
                            previewStr = templateStr + subscribe_url;
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(contentStr))
                        {
                            previewStr = contentStr.Replace(replaceStr, templateStr);
                        }
                        else
                        {
                            previewStr = templateStr;
                        }
                         
                    }

            }
            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);
                previewStr = "";
            }
            this.Response.Clear();
            this.Response.Write(previewStr);
            this.Response.End();
            return this.Response;

        }
Ejemplo n.º 2
0
        //EdmTemplate 中的狀態啟用
        public HttpResponseBase UpdateStats_ET()
        {
            string json = string.Empty;
            try
            {
                edmtemplatemgr = new EdmTemplateMgr(mySqlConnectionString);
                EdmTemplateQuery query = new EdmTemplateQuery();

                if (!string.IsNullOrEmpty(Request.Params["id"]))
                {
                    query.template_id = Convert.ToInt32(Request.Params["id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["active"]))
                {
                    query.enabled = Convert.ToInt32(Request.Params["active"]);
                }
                json = edmtemplatemgr.UpdateStats_ET(query);
            }
            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:false,totalCount:0,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Ejemplo n.º 3
0
        public HttpResponseBase SaveEdmTemplateAdd() //add by yachao1120j 2015-9-22
        {
            string json = string.Empty;
            try
            {
                EdmTemplateQuery query = new EdmTemplateQuery();
                edmtemplatemgr = new EdmTemplateMgr(mySqlConnectionString);

                if (!string.IsNullOrEmpty(Request.Params["template_id"]))
                {
                    query.template_id = Convert.ToInt32(Request.Params["template_id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["template_name"]))
                {
                    query.template_name = Request.Params["template_name"];
                }
                if (!string.IsNullOrEmpty(Request.Params["edit_url"]))
                {
                    query.edit_url = Request.Params["edit_url"];
                }
                if (!string.IsNullOrEmpty(Request.Params["content_url"]))
                {
                    query.content_url = Request.Params["content_url"];
                }
                if (!string.IsNullOrEmpty(Request.Params["static_template"]))
                {
                    if (Request.Params["static_template"] == "true")
                    {
                        query.static_template = 1;
                    }
                    else
                    {
                        query.static_template = 0;
                    }
                }
                query.template_update_userid = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
                query.template_create_userid = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;


                int _dt = edmtemplatemgr.SaveEdmTemplateAdd(query);

                if (_dt > 0)
                {
                    json = "{success:true}";
                }
                else
                {
                    json = "{success:false}";
                }
            }
            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:false,totalCount:0,data:[]}";

            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return Response;

        }
Ejemplo n.º 4
0
        public HttpResponseBase GetEdmTemplateList() //add by yachao1120j 2015-9-22
        {
            string json = string.Empty;
            int totalcount = 0;
            try
            {
                EdmTemplateQuery query = new EdmTemplateQuery();
                query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");
                query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");
                edmtemplatemgr = new EdmTemplateMgr(mySqlConnectionString);
                List<EdmTemplateQuery> list = edmtemplatemgr.GetEdmTemplateList(query, out totalcount);
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                // timeConverter.DateTimeFormat = "yyyy-MM-dd ";
                json = "{success:true,totalCount:" + totalcount + ",data:" + JsonConvert.SerializeObject(list, Formatting.Indented, timeConverter) + "}";
            }
            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:false,totalCount:0,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return Response;

        }