/// <summary> /// 提交按钮的响应 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btSubmit_Click(object sender, EventArgs e) { //用户类型 Session["Type"] = "Teacher"; //写代码不注意真是的 //Session["UserName"] = "******"; //new Model.CommentInfo,Search,Teacher,Assignment对象 Model.CommentInfo comm=new CommentInfo (); Search s = new Search(); Teacher t = new Teacher(); Assignment ass = new Assignment(); //初始化 comm.DtReleaseTime = System.DateTime.Now; int assID = Convert.ToInt32(assmtID); comm.IAssignmentId = assID; int grpID = Convert.ToInt32(groupID); comm.IGroupId = grpID; comm.StrContents = tbNewMsg.Text; //判断用户名是否为空 if (null == strUserName) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('对不起,你还未登录!')</script>"); return; } else { //判断是否是教师用户 if (Convert.ToString(type) == "Teacher") { comm.StrReleasePsnName = t.GetTeacherByUserName(Convert.ToString(strUserName)).StrTeacherName; } } //添加评论 if (ass.AddComment(comm)) { Response.Redirect("TCommunication.aspx?aid= "+comm.IAssignmentId+"&gid="+comm.IGroupId); } }
/// <summary> /// �����ҵ���� /// </summary> /// <param name="mComment">��������۵���ҵ����</param> /// <returns>�Ƿ���ӳɹ�����ӳɹ���true��ʧ����false</returns> public bool AddComment(CommentInfo mComment) { return dal.AddComment(mComment); }
/// <summary> /// 查找数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void RepeaterSearch_ItemDataBound1(object sender, RepeaterItemEventArgs e) { //注意又使用了用户控件TSMessage UserControl_TSMessage msgBox = (UserControl_TSMessage)e.Item.FindControl("TSMessage1"); //new一个CommentInfo对象并且初始化 CommentInfo comm = new CommentInfo(); comm.DtReleaseTime = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "releaseTime")); comm.ICommentId = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "Id")); comm.StrContents = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "contents")); comm.StrReleasePsnName = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "releasePsnName")); //把comm赋给AMsg msgBox.AMsg = comm; //消息数量自加 msgBox.Index = index++; }
/// <summary> /// 提交按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btSubmit_Click(object sender, EventArgs e) { Session["Type"] = "Student"; //显然不能直接用个常量啊! //Session["UserName"] = "******"; //new一个.CommentInfo对象 ,Search对象,Teacher对象,Assignment对象 Model.CommentInfo comm = new CommentInfo(); Search s = new Search(); Teacher t = new Teacher(); Assignment ass = new Assignment(); //初始化comm comm.DtReleaseTime = System.DateTime.Now; int assID = Convert.ToInt32(Request.QueryString["aID"]); int grpID =Convert.ToInt32( HiddenField2.Value); //程军添加,2010-3-5 comm.IAssignmentId = assID; //程军添加, 2010-3-5 comm.IGroupId = grpID; comm.StrContents = tbNewMsg.Text; //判断用户名是否为空 if (null == strUserName) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('对不起,你还未登录!');</script>"); return; } else { //判断用户类型,教师和学生有不同的处理 if (Convert.ToString(type) == "Teacher") { comm.StrReleasePsnName = t.GetTeacherByUserName(Convert.ToString(strUserName)).StrTeacherName; } else { comm.StrReleasePsnName = s.GetStudentByUsername(Convert.ToString(strUserName)).StrStudentName; } } //添加评论成功后 if (ass.AddComment(comm)) { //程军添加,添加评论成功后,修改“无新留言”的标志,2010-3-5 //SqlConnection myConn = CC.GetConnection(); //myConn.Open(); //string mySql = "update Assignment_Group set newMsgNum = 1 where assignmentID = " + assID + "and groupID = " + grpID; //SqlCommand myCmd = myConn.CreateCommand(); //myCmd.CommandText = mySql; //myCmd.ExecuteNonQuery(); //myConn.Close(); //程军添加,2010-3-5 Response.Redirect("SAssignmentInfo.aspx?aID= " + comm.IAssignmentId); } }
/// <summary> /// �����ҵ���� /// </summary> /// <param name="mComment">��������۵���ҵ����</param> /// <returns>�Ƿ���ӳɹ�����ӳɹ���true��ʧ����false</returns> public bool AddComment(CommentInfo mComment) { SqlParameter[] prams = { new SqlParameter("@assignmentID",mComment.IAssignmentId), new SqlParameter("@groupID",mComment.IGroupId), new SqlParameter("@releasePsnName",mComment.StrReleasePsnName), new SqlParameter("@releaseTime",mComment.DtReleaseTime), new SqlParameter("@contents",mComment.StrContents) }; bool isSuccess = false; int affectRows = SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionStringSTEduSys, CommandType.StoredProcedure, "SP_AddComment", prams); if (affectRows > 0) { isSuccess = true; } return isSuccess; }