/// <summary> /// �����ҵ /// </summary> /// <param name="mAssignment">����ӵ���ҵ����</param> /// <returns>�Ƿ���ӳɹ����ɹ��������¼��ID������-1</returns> public int AddAssignment(AssignmentInfo mAssignment, string courseName) { SqlParameter[] parms = { new SqlParameter("@title",mAssignment.StrTitle), new SqlParameter("@contents",mAssignment.StrContents), new SqlParameter("@deadline",mAssignment.DtDeadline), new SqlParameter("@teacherUserName",mAssignment.StrTeacherUserName), new SqlParameter("@courseName", courseName), new SqlParameter("@identity",SqlDbType.Int) }; parms[5].Direction = ParameterDirection.ReturnValue; int id = 0; int affectRows = SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionStringSTEduSys, CommandType.StoredProcedure, "SP_AddAssmt", parms); if (affectRows > 0) { id = Convert.ToInt32(parms[5].Value); AssignmentGroupInfo mAssignmentGroup = new AssignmentGroupInfo(); mAssignmentGroup.IAssignmentId = id; mAssignmentGroup.INewMsgNum = 0; mAssignmentGroup.IState = 0; mAssignmentGroup.StrCourseName = courseName; mAssignmentGroup.StrTeacherName = mAssignment.StrTeacherUserName; if (AddAssignmentGroup(mAssignmentGroup)) return id; else DelAssignmentByID(id); } return -1; }
/// <summary> /// �༭��ҵ /// </summary> /// <param name="mAssignment">���༭��ҵ����</param> /// <returns>�Ƿ�༭�ɹ����ɹ���true,ʧ����false</returns> public bool EditAssignmentById(AssignmentInfo mAssignment) { return dal.EditAssignmentById(mAssignment); }
/// <summary> /// �����ҵ /// </summary> /// <param name="mAssignment">����ӵ���ҵ����</param> /// <returns>�Ƿ���ӳɹ����ɹ��������¼��ID������-1</returns> public int AddAssignment(AssignmentInfo mAssignment, string courseName) { return dal.AddAssignment(mAssignment, courseName); }
/// <summary> /// ������ҵId��ȡ��ҵ /// </summary> /// <param name="iAssignmentId">��ҵId</param> /// <returns>�õ�����ҵ����</returns> public AssignmentInfo GetAssignmentById(int iAssignmentId) { SqlParameter param = new SqlParameter("@assmtID", iAssignmentId); AssignmentInfo assignment = new AssignmentInfo(); using (SqlDataReader dr = SQLHelper.ExecuteReader(SQLHelper.ConnectionStringSTEduSys, CommandType.StoredProcedure, "SP_GetAssmtByID", param)) { if (dr.Read()) { assignment.IAssignmentId = dr.GetInt32(0); assignment.StrTitle = dr.GetString(1); assignment.StrContents = dr.GetString(2); assignment.DtAssignDate = dr.GetDateTime(3); assignment.DtDeadline = dr.GetDateTime(4); } } return assignment; }
/// <summary> /// 点击“提交修改”按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btSubmitEdit_Click(object sender, EventArgs e) { //new一个Assignment对象 Assignment EditAssignment = new Assignment(); //new一个AssignmentInfo对象 AssignmentInfo EditAssignmentInfo = new AssignmentInfo(); //EditAssignmentInfo初始化 int assignmentID = Convert.ToInt32(assmtID); EditAssignmentInfo.IAssignmentId = assignmentID; EditAssignmentInfo.StrTitle = this.tbTitle.Text; EditAssignmentInfo.StrContents = this.tbInfo.Text; try { EditAssignmentInfo.DtDeadline = Convert.ToDateTime(this.tbDeadline.Text.ToString()); } catch { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('截止日期格式不对!')</script>"); return; } if (EditAssignmentInfo.StrTitle == null || EditAssignmentInfo.StrTitle == "") { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('作业主题不可为空!')</script>"); return; } if (oldTitle.Value != EditAssignmentInfo.StrTitle && new Assignment().SearchAssignmentByName(EditAssignmentInfo.StrTitle)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('作业名重名,请更换!')</script>"); } else { //胡媛媛添加,作业的提交日期的约束,2010-01-26 if (DateTime.Parse(this.tbDeadline.Text) <= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"))) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('提交截止日期非法,请重新输入!')</script>"); } //胡媛媛添加,作业的提交日期的约束,2010-01-26 else { //胡媛媛添加,保存附件,2010-5-8 if (InputFile1.HasFile) { string Path = Server.MapPath("~/SiteFile/annex"); if (Directory.Exists(Path)) //删除原来的附件 { DirectoryInfo dinfo = new DirectoryInfo(Path); FileInfo[] myfiles = dinfo.GetFiles(); foreach (FileInfo files in myfiles) { string filename = files.Name; string[] sArray = filename.Split('&'); if (sArray[0] == this.tbTitle.Text) { files.Delete(); break; } } } string Fname = this.tbTitle.Text + "&" + InputFile1.FileName; this.InputFile1.MoveTo(Path + "\\" + Fname, Brettle.Web.NeatUpload.MoveToOptions.Overwrite); } //胡媛媛添加,保存附件,2010-5-8 bool isChanged = false; if ((new Assignment().GetAssignmentById(Int32.Parse(assmtID))).DtDeadline != EditAssignmentInfo.DtDeadline) { isChanged = true; } //判断编辑作业是否成功 if (EditAssignment.EditAssignmentById(EditAssignmentInfo)) { if (isChanged) { MailMessage message = new MailMessage(); TeacherInfo teacher = new Search().GetTeacherByUsername(userName); if (teacher.Email != "" && teacher.Email != null) { message.ReplyTo = new MailAddress(teacher.Email, teacher.StrTeacherName); } message.Body = "课程名: " + course + "\n作业名: " + EditAssignmentInfo.StrTitle + "\n作业内容: " + EditAssignmentInfo.StrContents + "\n作业提交截止日期: " + EditAssignmentInfo.DtDeadline.Date + "\n自主学习平台链接: " + ConfigurationManager.AppSettings["Home"]; message.Subject = "<" + new Search().GetTeacherByUsername(userName).StrTeacherName + "> 更改了 : [" + EditAssignmentInfo.StrTitle + "] 的截止时间"; try { Search s = new Search(); List<ClassInfo> classes = s.GetClassesByTeacherAndCourse(userName, course); for (int i = 0; i < classes.Count; i++) { DataTable dt = s.GetStudentsByClass(classes[i].IClassId); for (int j = 0; j < dt.Rows.Count; j++) { if (dt.Rows[j]["email"] != null && dt.Rows[j]["email"].ToString() != "") { message.To.Add(new MailAddress(dt.Rows[j]["email"].ToString())); } } } } catch { } CommonClass.SendMail(message); } System.Web.HttpContext.Current.Response.Write("<script>alert('作业编辑成功!');window.location.href='TAssignmentList.aspx'</script>"); } else { //提交失败,提示错误 Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('还未激活任何班级,请先激活,再布置作业!')</script>"); } } } }
/// <summary> /// �༭��ҵ /// </summary> /// <param name="mAssignment">���༭��ҵ����</param> /// <returns>�Ƿ�༭�ɹ����ɹ���true,ʧ����false</returns> public bool EditAssignmentById(AssignmentInfo mAssignment) { SqlParameter[] parms = { new SqlParameter("@assmtID",mAssignment.IAssignmentId), new SqlParameter("@title",mAssignment.StrTitle), new SqlParameter("@contents",mAssignment.StrContents), new SqlParameter("@deadline",mAssignment.DtDeadline), }; bool isSuccess = false; int affectRows = SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionStringSTEduSys, CommandType.StoredProcedure, "SP_EditAssmtByID", parms); if (affectRows > 0) { isSuccess = true; } return isSuccess; }
/// <summary> /// 页面加载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { if (Session["UserName"] == null) { System.Web.HttpContext.Current.Response.Write("<script>alert('请先登录');window.location.href='../Default.aspx'</script>"); return; } if (Session["Type"].ToString() == "Student") { System.Web.HttpContext.Current.Response.Write("<script>window.location.href='../WarningPage.aspx'</script>"); return; } if (Session["Type"].ToString() == "Teacher" && Session["UserState"].ToString() != "Active") { System.Web.HttpContext.Current.Response.Write("<script>alert('帐号未激活,请激活后重试');window.location.href='../Activate.aspx'</script>"); return; } //首次加载页面的时候调用 if (!IsPostBack) { //数字的正则检查 string urlPattern = @"^\d{1,}$"; if (Request.QueryString["id"] != null) { if (Regex.IsMatch(Request.QueryString["id"], urlPattern) == true) { int AssignmentID = Convert.ToInt32(Request.QueryString["id"]); if (AssignmentID < 1) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('该作业不存在!')</script>"); } else { //保存从其它页面传过来的题目ID Session["AssignmentID"] = AssignmentID.ToString(); Assignment EditAssignment = new Assignment(); AssignmentInfo EditAssignmentInfo = new AssignmentInfo(); if ((EditAssignmentInfo = EditAssignment.GetAssignmentById(AssignmentID)) != null) { this.tbDeadline.Text = EditAssignmentInfo.DtDeadline.ToShortDateString(); //胡媛媛添加,日历控件对已经设置的截止日期进行高亮显示,2010-01-25 Calendar1.SelectedDate = EditAssignmentInfo.DtDeadline; Calendar1.VisibleDate = EditAssignmentInfo.DtDeadline; //胡媛媛添加,日历控件对已经设置的截止日期进行高亮显示,2010-01-25 this.tbInfo.Text = EditAssignmentInfo.StrContents; this.tbTitle.Text = EditAssignmentInfo.StrTitle; this.oldTitle.Value = EditAssignmentInfo.StrTitle; //胡媛媛添加,显示已经上传的附件的名字,2010-5-10 string path = Server.MapPath("~/SiteFile/annex"); if (Directory.Exists(path) == true) { DirectoryInfo di = new DirectoryInfo(path); FileInfo[] myfile = di.GetFiles(); foreach (FileInfo files in myfile) { string filename = files.Name; string[] sArray=filename.Split('&'); if (sArray[0] == this.tbTitle.Text) { Label2.Text = sArray[1]; break; } } } //胡媛媛添加,显示已经上传的附件的名字,2010-5-10 } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('该作业不存在!')</script>"); } } } } } try { course = Session["Course"].ToString(); assmtID = Int32.Parse(Session["AssignmentID"].ToString()).ToString(); userName = Session["UserName"].ToString(); } catch { Response.Redirect("../Default.aspx"); return; } }
/// <summary> /// 为RepeaterItem绑定数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void RepeaterItemDataBound(object sender, RepeaterItemEventArgs e) { //用户控件的使用 UserControl_TaListItem1 assignmentItem1 = (UserControl_TaListItem1)e.Item.FindControl("TaListItem10"); //用户控件 UserControl_TaListItem2 assignmentItem2 = (UserControl_TaListItem2)e.Item.FindControl("TaListItem20"); //new一个AssignmentInfo对象 AssignmentInfo a = new AssignmentInfo(); //初始化 a.DtAssignDate = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "assignDate")); a.DtDeadline = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "deadline")); a.IAssignmentId = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "ID")); a.StrContents = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "contents")); a.StrTitle = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "title")); //判断作业是否为空 if (assignmentItem1!=null) { assignmentItem1.A = a; assignmentItem1.Index = index++; } else { assignmentItem2.A = a; assignmentItem2.Index = index++; } }
//点击“发布”按钮 protected void btPub_Click(object sender, EventArgs e) { //new一个Assignment对象 Assignment newAssignment = new Assignment(); //new一个AssignmentInfo对象 AssignmentInfo newAssignmentInfo = new AssignmentInfo(); //对newAssignmentInfo初始化 try { newAssignmentInfo.DtDeadline = Convert.ToDateTime(this.tbDeadline.Text); } catch { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('截止日期格式不对!')</script>"); return; } //胡媛媛修改,去掉tostring();2010-01-25 // newAssignmentInfo.ITeacherID = Convert.ToInt32(Session["TeacherID"].ToString()); newAssignmentInfo.StrTeacherUserName = Session["UserName"].ToString(); //胡媛媛修改,去掉tostring();2010-01-25 newAssignmentInfo.StrContents = this.tbInfo.Text; newAssignmentInfo.StrTitle = this.tbTitle.Text; if (newAssignmentInfo.StrTitle == null || newAssignmentInfo.StrTitle == "") { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('作业主题不可为空!')</script>"); return; } if (new Assignment().SearchAssignmentByName(newAssignmentInfo.StrTitle)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('作业名重名,请更换!')</script>"); return; } else { //胡媛媛添加,作业的提交日期的约束,2010-01-26 if (DateTime.Parse(this.tbDeadline.Text) <= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"))) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('提交截止日期非法,请重新输入!')</script>"); return; } //胡媛媛添加,作业的提交日期的约束,2010-01-26 else { //胡媛媛添加,保存附件,2010-5-8 if (InputFile1.HasFile) { string Path = Server.MapPath("..//") + "SiteFile" + "\\" + "annex"; if (!Directory.Exists(Path)) { Directory.CreateDirectory(Path); } string Fname = this.tbTitle.Text + "&" + InputFile1.FileName; this.InputFile1.MoveTo(Path + "\\" + Fname, Brettle.Web.NeatUpload.MoveToOptions.Overwrite); } //胡媛媛添加,保存附件,2010-5-8 //添加作业-组对应信息 //获取ID的这个函数真是怪啊!不规范啊!见谅啊!! int assignmentID = newAssignment.AddAssignment(newAssignmentInfo, Session["Course"].ToString()); if (assignmentID > 0) { //发邮件通知所有相关学生 MailMessage message = new MailMessage(); TeacherInfo teacher = new Search().GetTeacherByUsername(userName); if (teacher.Email != "" && teacher.Email != null) { message.ReplyTo = new MailAddress(teacher.Email, teacher.StrTeacherName); } message.Body = "课程名: " + course + "\n作业名: " + newAssignmentInfo.StrTitle + "\n作业内容: " + newAssignmentInfo.StrContents + "\n作业提交截止日期: " + newAssignmentInfo.DtDeadline.Date + "\n自主学习平台链接: " + ConfigurationManager.AppSettings["Home"]; message.Subject = "<" + new Search().GetTeacherByUsername(userName).StrTeacherName + "> 发布新作业 : [" + newAssignmentInfo.StrTitle + "]"; try { Search s = new Search(); List<ClassInfo> classes = s.GetClassesByTeacherAndCourse(userName, course); for (int i = 0; i < classes.Count; i++) { DataTable dt = s.GetStudentsByClass(classes[i].IClassId); for (int j = 0; j < dt.Rows.Count; j++) { if (dt.Rows[j]["email"] != null && dt.Rows[j]["email"].ToString() != "") { message.To.Add(dt.Rows[j]["email"].ToString()); } } } } catch { } CommonClass.SendMail(message); System.Web.HttpContext.Current.Response.Write("<script>alert('作业添加成功!');window.location.href='TAssignmentList.aspx'</script>"); } else { //发布失败,提示错误 Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('还未激活任何班级,请先激活,再布置作业!')</script>"); } } } }
//加载页面 protected void Page_Load(object sender, EventArgs e) { //判断用户名是否为空 if (Session["UserName"] == null) { System.Web.HttpContext.Current.Response.Write("<script>alert('请先登录');window.location.href='../Default.aspx'</script>"); return; } //检查用户类型是否为学生类型 if (Session["Type"].ToString() == "Student") { System.Web.HttpContext.Current.Response.Write("<script>window.location.href='../WarningPage.aspx'</script>"); return; } //检查用户类型是否是教师类型并且激活 if (Session["Type"].ToString() == "Teacher" && Session["UserState"].ToString() != "Active") { System.Web.HttpContext.Current.Response.Write("<script>alert('帐号未激活,请激活后重试');window.location.href='../Activate.aspx'</script>"); return; } try { course = Session["Course"].ToString(); userName = Session["UserName"].ToString(); id = Int32.Parse(Request.QueryString["id"]).ToString(); } catch { Response.Redirect("../Default.aspx"); return; } if (!IsPostBack) { //只有测试单独这个页面功能的时候这段代码才注释 //if (Session["UserName"] == null) //{ // Response.Redirect("./Default.aspx"); // return; //} ////////////////////////////////////////////////////////////////////////////// //////////////////////由于没有教师作业列表的页面,此页面关于作业的几个label未予显示,要加的话参照SAssignmentInfo.aspx.cs ////////////////////////////////////////////////////////////////////////////////// //胡媛媛添加,检索作业的相关信息,2010-01-29 //数字的正则检查 string urlPattern = @"^\d{1,}$"; if (Request.QueryString["id"] != null) { if (Regex.IsMatch(Request.QueryString["id"], urlPattern) == true) { int AssignmentID = Convert.ToInt32(Request.QueryString["id"]); //保存从其它页面传过来的题目ID Session["AssignmentID"] = AssignmentID.ToString(); Assignment myAssignment = new Assignment(); AssignmentInfo myAssignmentInfo = new AssignmentInfo(); if ((myAssignmentInfo = myAssignment.GetAssignmentById(AssignmentID)) != null) { this.lbDeadline.Text = myAssignmentInfo.DtDeadline.ToShortDateString(); this.lbPubDate.Text = myAssignmentInfo.DtAssignDate.ToShortDateString(); this.lbAssInfo.Text = myAssignmentInfo.StrContents; this.lbTitle.Text = myAssignmentInfo.StrTitle; //胡媛媛添加,显示已经上传的附件的名字,2010-5-10 string path = Server.MapPath("~/SiteFile/annex"); if (Directory.Exists(path) == true) { DirectoryInfo di = new DirectoryInfo(path); FileInfo[] myfiles = di.GetFiles(); foreach (FileInfo file in myfiles) { string filename = file.Name; string[] sArray = filename.Split('&'); if (sArray[0] == this.lbTitle.Text) { this.lbfujian.Text = sArray[1]; break; } } } } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('该作业不存在!')</script>"); } } } //胡媛媛添加,检索作业的相关信息,2010-01-29 GridViewBind(); } }
/// <summary> /// ���ݰ༶���Ϳγ���������ҵ�б� /// </summary> /// <returns>���ظð�ÿγ̵���ҵ�б�</returns> public List<AssignmentInfo> GetAssignmentsByClassNameAndCourseName(string className, string courseName) { SqlParameter[] param = { new SqlParameter("@className", className), new SqlParameter("@courseName", courseName) }; List<AssignmentInfo> assignment = new List<AssignmentInfo>(); using (SqlDataReader dr = SQLHelper.ExecuteReader(SQLHelper.ConnectionStringSTEduSys, CommandType.StoredProcedure, "SP_GetAssignmentsByClassNameAndCourseName", param)) { while (dr.Read()) { AssignmentInfo assmt = new AssignmentInfo(); assmt.IAssignmentId = dr.GetInt32(0); assmt.StrTitle = dr.GetString(1); assmt.IGpa = dr.GetInt32(2); assignment.Add(assmt); } } return assignment; }