using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class xuewanyu : System.Web.UI.Page { public static DataRow ClassInfo; public static DataTable DiscussInfo; public static DataTable Discuss; public static string DiscussCount; static string ClassId = null; static string ClassTypeId = null; public static DataTable ClassList; protected void Page_Load(object sender, EventArgs e) { this.LinkButton2.Visible = false; try { ClassId = Request.QueryString["ClassId"].ToString(); string getClassList = "select * from class as class left join classTYpe as classtype on class.Classtypeid =classtype. classid where class.classtypeid = " + ClassInfo[1].ToString(); GetClassList(getClassList); string sqlstr = " select * from Class where classid = " + ClassId; ClassInfo = new common().ExcuteReader(sqlstr).Tables[0].Rows[0]; BindDiscussAndSort(); } catch { ClassId = null; try { ClassTypeId = Request.QueryString["ClassTypeId"].ToString(); string getClassList = "select * from Class where ClassTypeId = " + ClassTypeId + " order by edittime desc "; GetClassList(getClassList); ClassInfo = ClassList.Rows[ClassList.Rows.Count - 1]; BindDiscussAndSort(); } catch { ClassTypeId = null; Methods1.Methods1.MsgBox("对不起,该课程下没有安排课时,敬请期待!", "default.aspx"); Response.End(); } } } public string GetHuiFuByDiscussId(string DiscussParentID) { string GetHuiFuByDiscussId = "select Discuss from Discuss where ParentId = " + DiscussParentID; return new common().ExcuteReader(GetHuiFuByDiscussId).Tables[0].Rows[0][0].ToString(); } protected void BindDiscussAndSort() { string SelectDiscussByClassId = "select top 5 (select count(*) from Discuss where ClassId = " + ClassInfo["ClassId"].ToString() + ") as [count],* from Discuss where ClassId=" + ClassInfo[0].ToString() + " order by Discuss_Time desc "; Discuss = new common().ExcuteReader(SelectDiscussByClassId).Tables[0]; } #region private void getClassInfo(string ClassId) { string sqlstr = " select * from Class where ClassId = " + ClassId; ClassInfo = new common().ExcuteReader(sqlstr).Tables[0].Rows[0]; } private void GetClassList(string ClassTypeIDorClassID) { ClassList = new common().ExcuteReader(ClassTypeIDorClassID).Tables[0]; this.Repeater1.DataSource = ClassList; this.Repeater1.DataBind(); } public string GetClassTypeByClassId(string ClassTypeId) { string SelectTypeById = " select ClassName from ClassType where ClassId = " + ClassInfo[1].ToString(); string result = new common().ExcuteReader(SelectTypeById).Tables[0].Rows[0][0].ToString(); return result; } #endregion #region protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "Link") { Response.Redirect("LearnClass.aspx?ClassId=" + e.CommandArgument); } } protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { string DiscussName; string Discuss; string DiscussTime = DateTime.Now.ToShortDateString(); if (!string.IsNullOrEmpty(txtName.Text.ToString())) { DiscussName = txtName.Text.ToString(); } else { DiscussName = "匿名浏览-"; } Discuss = this.txtDiscuss.Text.Trim(); string InsertDiscuss = " insert into Discuss(ClassId,Discuss,Discusser,Discuss_Time,ParentId)values('" + ClassInfo[0].ToString() + "','" + Discuss + "','" + DiscussName + "','" + DiscussTime + "',0)"; bool b = new common().ExcuteNoneQuery(InsertDiscuss, null); if (b) { Methods1.Methods1.MsgBox("留言成功!", Request.Url.ToString()); } else { Methods1.Methods1.Alert(this, "留言失败!感谢支持,我们会尽快修正这个错误"); } } protected void LinkButton1_Click(object sender, EventArgs e) { this.LinkButton2.Visible = true; this.LinkButton1.Visible = false; string SelectDiscussByClassId = "select (select count(*) from Discuss where ClassId = " + ClassInfo["ClassId"].ToString() + ") as [count],* from Discuss where ClassId=" + ClassInfo["ClassId"].ToString() + " order by Discuss_Time desc "; Discuss = new common().ExcuteReader(SelectDiscussByClassId).Tables[0]; } protected void LinkButton2_Click(object sender, EventArgs e) { this.LinkButton2.Visible = false; this.LinkButton1.Visible = true; string SelectDiscussByClassId = "select top 5 (select count(*) from Discuss where ClassId = " + ClassInfo["ClassId"].ToString() + ") as [count],* from Discuss where ClassId=" + ClassInfo["ClassId"].ToString() + " order by Discuss_Time desc "; Discuss = new common().ExcuteReader(SelectDiscussByClassId).Tables[0]; } #endregion }