protected void btn_Submit_Click(object sender, EventArgs e) { DataEntities ent = new DataEntities(); if (UserAction.HasPostRight(ddl_Class.SelectedValue.ToInt32()) == false) { Js.AlertAndGoback("对不起,对于本栏目您没有提问的权限!如有疑问,请联系管理员"); ent.Dispose(); return; } User u=UserAction.opuser; int rclass = WS.RequestInt("ddl_Class", WS.RequestInt("class")); string content = WS.RequestString("txt_Content").TrimDbDangerousChar().Trim().HtmlDeCode(); string title = WS.RequestString("txt_Title").TrimDbDangerousChar().Trim(); if (rclass < 0) { Js.AlertAndGoback("栏目不能为空"); return; } if (content.IsNullOrEmpty()) { Js.AlertAndGoback("提问内容不能为空"); return; } if (title.IsNullOrEmpty()) { Js.AlertAndGoback("标题不能为空"); return; } Question qs = new Question(); qs.AskTime = DateTime.Now; qs.ClassID = rclass; qs.ClickCount = 0; qs.Content = content; qs.Title = title; qs.UserID = u.ID; qs.UserName = u.UserName; qs.ZtID = 0; ent.AddToQuestion(qs); ent.SaveChanges(); CreatePage.CreateContentPage(qs, qs.GetClass()); CreatePage.CreateListPage(qs.GetClass(), 1); string url = BasePage.GetQuestionUrl(qs, qs.GetClass()); ent.Dispose(); Js.AlertAndChangUrl("提问发布成功!", url); }
public string ReplaceContent(string TempString, Question n, Class c) { return ReplaceContent(new TemplateList() { TimeFormat = "yyyy-MM-dd HH:mm:ss", CutTitle = 0 }, TempString, n, c); }
/// <summary> /// 生成内容页--图片 /// </summary> /// <param name="album"></param> /// <param name="cls"></param> public string CreateContentPage(Question qs, Class cls) { DataEntities ent = new DataEntities(); TemplateContent temp = GetContentTemplate(cls); string Content = temp.Content; Content = ReplacePublicTemplate(Content); Content = ReplacePublicTemplate(Content); Content = ReplacePublicTemplate(Content); Content = ReplaceSystemSetting(Content); #region 替换内容 Content = Content.Replace("[!--class.id--]", cls.ID.ToString()); Content = Content.Replace("[!--class.name--]", cls.ClassName); Content = ReplaceContent(Content, qs, cls); List<Answer> ans = (from l in ent.Answer where l.QuestionID == qs.ID select l).ToList(); StringBuilder sb = new StringBuilder(); string list_tmp = GetTempateString(1, TempType.问答回答列表); foreach (Answer an in ans) { string row = list_tmp.Replace("[!--answer.agree--]", an.Agree.ToS()); row = row.Replace("[!--answer.answertime--]", an.AnswerTime.ToString()); row = row.Replace("[!--answer.content--]", an.Content); row = row.Replace("[!--answer.id--]", an.ID.ToS()); row = row.Replace("[!--answer.questionid--]", an.QuestionID.ToS()); row = row.Replace("[!--answer.userid--]", an.UserID.ToS()); row = row.Replace("[!--answer.username--]", an.UserName); sb.AppendLine(row); } Content = Content.Replace("[!--answer.list--]", sb.ToS()); #endregion Content = ReplaceTagContent(Content); #region 上一篇 下一篇 链接 Question news_pre = BasePage.GetPreQuestion(qs, cls); Question news_next = BasePage.GetNextQuestion(qs, cls); //上一篇 string pre_link = "<a href=\"javascript:void(0)\">没有了</a>"; if (news_pre != null) { pre_link = string.Format("<a href=\"{0}\" title=\"{1}\">{2}</a>", BasePage.GetQuestionUrl(news_pre, cls), news_pre.Title, news_pre.Title.CutString(20)); } Content = Content.Replace("[!--news.prelink--]", pre_link); //下一篇 string next_link = "<a href=\"javascript:void(0)\">没有了</a>"; if (news_next != null) { next_link = string.Format("<a href=\"{0}\" title=\"{1}\">{2}</a>", BasePage.GetQuestionUrl(news_next, cls), news_next.Title, news_next.Title.CutString(20)); } Content = Content.Replace("[!--news.nextlink--]", next_link); #endregion //替换导航条 Content = Content.Replace("[!--newsnav--]", BuildClassNavString(cls)); ent.Dispose(); return Content; }
/// <summary> /// 替换问答 /// </summary> /// <param name="TempString"></param> /// <param name="n"></param> /// <returns></returns> public string ReplaceContent(TemplateList temp, string TempString, Question q, Class c) { using (DataEntities ent = new DataEntities()) { string str_lst = TempString; str_lst = str_lst.Replace("[!--question.url--]", BasePage.GetQuestionUrl(q, c));//问题地址 str_lst = str_lst.Replace("[!--question.asktime--]", q.AskTime.ToDateTime().ToString(temp.TimeFormat)); str_lst = str_lst.Replace("[!--question.classid--]", q.ClassID.ToS()); str_lst = str_lst.Replace("[!--question.clickcount--]", q.ClickCount.ToS()); str_lst = str_lst.Replace("[!--question.content--]", q.Content); str_lst = str_lst.Replace("[!--question.id--]", q.ID.ToS()); str_lst = str_lst.Replace("[!--question.title--]", q.Title); str_lst = str_lst.Replace("[!--question.ftitle--]", temp.CutTitle > 0 ? q.Title.CutString(temp.CutTitle.ToInt32()) : q.Title); str_lst = str_lst.Replace("[!--question.userid--]", q.UserID.ToS()); str_lst = str_lst.Replace("[!--question.username--]", q.UserName); str_lst = str_lst.Replace("[!--question.ztid--]", q.ZtID.ToS()); str_lst = str_lst.Replace("[!--question.answercount--]", (from l in ent.Answer where l.QuestionID == q.ID select l).Count().ToS()); return str_lst; } }