protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["courseNo"] == null||!CommonUtility.SafeCheckByParams<string>(Request["schoolworkNotifyId"], ref schoolworkNotifyId))
        {
            Javascript.GoHistory(-1, Page);
            return;
        }

        if (!IsPostBack)
        {
            DalOperationAboutCourses dalOperationAboutCourses = new DalOperationAboutCourses();
            schoolWorkNotify = dalOperationAboutCourses.GetSchoolworkNotifyById(schoolworkNotifyId);
            this.txtTitle.Text = schoolWorkNotify.schoolWorkNotifyTitle;
            this.Textarea1.Value = schoolWorkNotify.schoolWorkNotifyContent;
            datepicker.Value = schoolWorkNotify.deadline.ToString("yyyy-MM-dd HH:mm:ss");
            if (schoolWorkNotify.isOnline)
                this.ddltOnline.SelectedValue = "true";
            else
                this.ddltOnline.SelectedValue = "false";

            hidAttachmentId.Value = schoolWorkNotify.attachmentIds;
            if (schoolWorkNotify.attachmentIds.Length > 0)
            {
                DalOperationAttachments dalOperationAttachments = new DalOperationAttachments();
                ltlAttachment.Text = dalOperationAttachments.GetAttachmentsList(schoolWorkNotify.attachmentIds, ref iframeCount, true,string.Empty);
            }
        }
    }
    protected void btnEditSchoolworkNotify_Click(object sender, EventArgs e)
    {
        if (txtTitle.Text.Trim().Length != 0 && Textarea1.Value.ToString().Trim().Length != 0)
        {
            DateTime deadline_t = Convert.ToDateTime(datepicker.Value);

            SchoolWorkNotify schoolWorkNotify = new SchoolWorkNotify
            {
                courseNo = Request["courseNo"],
                schoolWorkNotifyTitle = CommonUtility.JavascriptStringFilter(txtTitle.Text),
                schoolWorkNotifyContent = Textarea1.Value,
                deadline = deadline_t,
                updateTime = DateTime.Now,
                attachmentIds = hidAttachmentId.Value,
                schoolWorkNotifyId = schoolworkNotifyId,
                isOnline = Convert.ToBoolean(ddltOnline.SelectedValue)

            };

            DalOperationAboutCourses doac = new DalOperationAboutCourses();
            doac.UpdateSchoolworkNotify(schoolWorkNotify);
            Javascript.RefreshParentWindow("修改成功!", "CInfoSchoolworkNotify.aspx?courseNo=" + schoolWorkNotify.courseNo+"&classID="+Server.UrlEncode(Server.UrlDecode(Request["classID"]))+"&termtag="+Request["termtag"].Trim(), Page);
        }
        else
        {
            Javascript.Alert("标题和内容不能为空!", Page);
        }
    }
        /// <summary>
        /// 修改/更新作业通知
        /// </summary>
        /// <param name="schoolworkNotify">作业实体</param>
        public void UpdateSchoolworkNotify(SchoolWorkNotify schoolworkNotify)
        {
            try
            {
                string sql = "UPDATE [USTA].[dbo].[usta_SchoolWorkNotify] SET [schoolWorkNotifyTitle] = @schoolWorkNotifyTitle,[schoolWorkNotifyContent] = @schoolWorkNotifyContent,[updateTime] =@updateTime,[deadline] =@deadline ,[courseNo] = @courseNo,[isOnline] = @isOnline,[attachmentIds] = @attachmentIds WHERE schoolWorkNotifyId=@schoolWorkNotifyId";

                SqlParameter[] parameters = {
                    new SqlParameter("@schoolWorkNotifyId", SqlDbType.Int,4),
                    new SqlParameter("@schoolWorkNotifyTitle", SqlDbType.NChar,50),
                    new SqlParameter("@schoolWorkNotifyContent", SqlDbType.NText),
                    new SqlParameter("@updateTime", SqlDbType.DateTime),
                    new SqlParameter("@deadline", SqlDbType.DateTime),
                    new SqlParameter("@courseNo", SqlDbType.NChar,20),
                    new SqlParameter("@isOnline", SqlDbType.Bit,1),
                    new SqlParameter("@attachmentIds", SqlDbType.NVarChar,200)};
                parameters[0].Value = schoolworkNotify.schoolWorkNotifyId;
                parameters[1].Value = schoolworkNotify.schoolWorkNotifyTitle;
                parameters[2].Value = schoolworkNotify.schoolWorkNotifyContent;
                parameters[3].Value = schoolworkNotify.updateTime;
                parameters[4].Value = schoolworkNotify.deadline;
                parameters[5].Value = schoolworkNotify.courseNo;
                parameters[6].Value = schoolworkNotify.isOnline;
                parameters[7].Value = schoolworkNotify.attachmentIds;
                SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, parameters);
            }
            catch (Exception ex)
            {
                MongoDBLog.LogRecord(ex);
                CommonUtility.RedirectUrl();
            }
            finally
            {
                conn.Close();
            }
        }
 /// <summary>
 /// 获得作业通知的具体项目
 /// </summary>
 /// <param name="schoolworkNotifyId">作业主键</param>
 /// <returns>作业实体</returns>
 public SchoolWorkNotify GetSchoolworkNotifyById(int schoolworkNotifyId)
 {
     SchoolWorkNotify schoolWorkNotify = null;
     string sql = "SELECT [schoolWorkNotifyId],[schoolWorkNotifyTitle],[schoolWorkNotifyContent],[updateTime],[deadline],[courseNo],[isOnline],[attachmentIds] FROM [USTA].[dbo].[usta_SchoolWorkNotify] WHERE schoolWorkNotifyId=@schoolWorkNotifyId";
     SqlParameter[] parameters = new SqlParameter[1]{
          new SqlParameter("@schoolWorkNotifyId",schoolworkNotifyId)
     };
     SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.Text, sql, parameters);
     while (dr.Read())
     {
         schoolWorkNotify = new SchoolWorkNotify
         {
             schoolWorkNotifyId = int.Parse(dr["schoolWorkNotifyId"].ToString()),
             schoolWorkNotifyTitle = dr["schoolWorkNotifyTitle"].ToString().Trim(),
             schoolWorkNotifyContent = dr["schoolWorkNotifyContent"].ToString().Trim(),
             updateTime = Convert.ToDateTime(dr["updateTime"].ToString()),
             deadline = Convert.ToDateTime(dr["deadline"].ToString()),
             courseNo = dr["courseNo"].ToString(),
             isOnline = Boolean.Parse(dr["isOnline"].ToString()),
             attachmentIds = dr["attachmentIds"].ToString()
         };
     }
     return schoolWorkNotify;
 }
        /// <summary>
        /// 添加作业通知
        /// </summary>
        /// <param name="schoolworkNotify">课程作业实体</param>
        /// <returns>作业实体</returns>
        public SchoolWorkNotify AddSchoolworkNotify(SchoolWorkNotify schoolworkNotify)
        {
            try
            {
                using (SqlCommand cmd = new SqlCommand("spSchoolWorkNotifyAdd", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Connection = conn;

                    conn.Open();
                    cmd.Parameters.Add(new SqlParameter("@schoolWorkNotifyTitle", schoolworkNotify.schoolWorkNotifyTitle));
                    cmd.Parameters.Add(new SqlParameter("@schoolWorkNotifyContent", schoolworkNotify.schoolWorkNotifyContent));
                    cmd.Parameters.Add(new SqlParameter("@updateTime", schoolworkNotify.updateTime));
                    cmd.Parameters.Add(new SqlParameter("@deadline", schoolworkNotify.deadline));
                    cmd.Parameters.Add(new SqlParameter("@isOnline", schoolworkNotify.isOnline));
                    cmd.Parameters.Add(new SqlParameter("@attachmentIds", schoolworkNotify.attachmentIds));
                    cmd.Parameters.Add(new SqlParameter("@courseNo", schoolworkNotify.courseNo));
                    cmd.Parameters.Add(new SqlParameter("@classId", schoolworkNotify.classID));
                    cmd.Parameters.Add(new SqlParameter("@termtag", schoolworkNotify.termTag));
                    cmd.Parameters.Add(new SqlParameter("@schoolWorkNotifyId", 0));
                    cmd.Parameters["@schoolWorkNotifyId"].Direction = ParameterDirection.Output;
                    cmd.ExecuteNonQuery();
                    schoolworkNotify.schoolWorkNotifyId = int.Parse(cmd.Parameters["@schoolWorkNotifyId"].Value.ToString());
                }
            }
            catch (Exception ex)
            {
                MongoDBLog.LogRecord(ex);
                CommonUtility.RedirectUrl();
            }
            finally
            {
                conn.Close();
            }
            return schoolworkNotify;
        }
    protected void btnAddSchoolworkNotify_Click(object sender, EventArgs e)
    {
        if (txtTitle.Text.Trim().Length != 0)
        {
            UserCookiesInfo UserCookiesInfo = BllOperationAboutUser.GetUserCookiesInfo();
            DateTime deadline_t = Convert.ToDateTime(datepicker.Value);
            if (deadline_t.CompareTo(DateTime.Now) > 0)
            {
                SchoolWorkNotify SchoolWorkNotify = new SchoolWorkNotify
                {
                    schoolWorkNotifyTitle=CommonUtility.JavascriptStringFilter(txtTitle.Text),
                    updateTime=DateTime.Now,
                    schoolWorkNotifyContent = Textarea1.Value,
                    deadline=deadline_t,
                    courseNo = Request["courseNo"],
                    isOnline = Convert.ToBoolean(ddltOnline.SelectedValue),
                    attachmentIds = hidAttachmentId.Value,
                    classID=Server.UrlDecode(Request["classID"].Trim()),
                    termTag=Request["termtag"].Trim()

                };

                using (TransactionScope scope = new TransactionScope())
                {

                    try
                    {
                        //添加课程作业并返回作业的自增长主键
                        DalOperationAboutCourses dalOperationAboutCourses = new DalOperationAboutCourses();
                        SchoolWorkNotify = dalOperationAboutCourses.AddSchoolworkNotify(SchoolWorkNotify);

                        //添加了课程作业以后,往作业提交表中添加记录
                        DalOperationAboutSchoolWorks dalOperationAboutSchoolworks = new DalOperationAboutSchoolWorks();

                        //查询出选课学生记录
                        DataTable dt = dalOperationAboutCourses.FindStudentInfoByCourseNo(Request["courseNo"].ToString().Trim(),Server.UrlDecode(Request["classID"]),Request["termtag"]).Tables[0];
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            SchoolWorks schoolwork = new SchoolWorks
                            {
                                updateTime = DateTime.Now,
                                schoolWorkNofityId = SchoolWorkNotify.schoolWorkNotifyId,
                                studentNo = dt.Rows[i]["studentNo"].ToString().Trim(),
                                isCheck = false,
                                isExcellent = false,
                                remark = "",
                                checkTime = DateTime.Now,
                                excellentTime = DateTime.Now,
                                attachmentId = "0"

                            };
                            dalOperationAboutSchoolworks.AddSchoolWork(schoolwork);
                        }
                        scope.Complete();
                    }
                    catch (Exception ex)
                    {
                        MongoDBLog.LogRecord(ex);
                        CommonUtility.RedirectUrl();
                    }
                }
                Javascript.RefreshParentWindow(Page);
            }
            else
            {
                Javascript.Alert("截止时间不能在当前时间之前", Page);
            }
        }
        else
        {
            Javascript.Alert("标题不能为空!", Page);
        }
    }