/// <summary>
 /// 获取数据集
 /// </summary>
 /// <param name="where"></param>
 /// <param name="orderBy"></param>
 /// <returns></returns>
 public List<Course_UnitHomeWork> GetList(string where, string orderBy)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("select * from [dbo].[Course_UnitHomeWork]");
     if (!string.IsNullOrEmpty(where))
         sql.Append(" where " + where);
     if (!string.IsNullOrEmpty(orderBy))
         sql.Append(" order by " + orderBy);
     List<Course_UnitHomeWork> list = new List<Course_UnitHomeWork>();
     using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString()))
     {
         while (reader.Read())
         {
             Course_UnitHomeWork model = new Course_UnitHomeWork();
             ConvertToModel(reader, model);
             list.Add(model);
         }
     }
     return list;
 }
 /// <summary>
 /// 新增一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Add(Course_UnitHomeWork model)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("insert into [dbo].[Course_UnitHomeWork] ([UnitContent],[ClassId],[Content],[AccountId],[AttList],[Display],[Delflag],[CreateDate],[Score],[ScoreCreater])");
     sql.Append(" values (@UnitContent,@ClassId,@Content,@AccountId,@AttList,@Display,@Delflag,@CreateDate,@Score,@ScoreCreater)");
     sql.Append(" set @Id=@@IDENTITY");
     SqlParameter[] cmdParams = new SqlParameter[]{
         new SqlParameter("@Id", SqlDbType.Int, 4) { Value = model.Id, Direction = ParameterDirection.Output },
         new SqlParameter("@UnitContent", SqlDbType.Int, 4) { Value = model.UnitContent },
         new SqlParameter("@ClassId", SqlDbType.Int, 4) { Value = model.ClassId },
         new SqlParameter("@Content", SqlDbType.VarChar, 2000) { Value = model.Content },
         new SqlParameter("@AccountId", SqlDbType.Int, 4) { Value = model.AccountId },
         new SqlParameter("@AttList", SqlDbType.VarChar, 2000) { Value = model.AttList },
         new SqlParameter("@Display", SqlDbType.Bit, 1) { Value = model.Display },
         new SqlParameter("@Delflag", SqlDbType.Bit, 1) { Value = model.Delflag },
         new SqlParameter("@CreateDate", SqlDbType.DateTime, 8) { Value = model.CreateDate },
         new SqlParameter("@Score", SqlDbType.Float, 8) { Value = model.Score },
         new SqlParameter("@ScoreCreater", SqlDbType.Int, 4) { Value = model.ScoreCreater }
     };
     int result = Convert.ToInt32(MSEntLibSqlHelper.ExecuteNonQueryBySql(sql.ToString(), cmdParams));
     model.Id = Convert.ToInt32(cmdParams[0].Value);
     return result;
 }
        public ActionResult LearnOnLineTaskShowView(int TrainingId, int UnitContent, int ClassId, int UId)
        {
            //获取活动及标题
            var Model_Course_UnitContent = this.GetCourseUnitContentActivity(TrainingId, UnitContent, ClassId, false);

            var homeWorkBll = new Course_UnitHomeWorkBLL();
            var Model_Course_UnitHomeWork = new Course_UnitHomeWork();
            var stbSqlWhere = new StringBuilder();
            var MemberBll = new Member_AccountBLL();
            var strNickName = string.Empty;

            //获取作业信
            stbSqlWhere.AppendFormat(@" UId = {0}", UId);
            Model_Course_UnitHomeWork = homeWorkBll.GetModel(UId, string.Empty);
            if (Model_Course_UnitHomeWork != null)
            {
                strNickName = MemberBll.GetModel(Model_Course_UnitHomeWork.AccountId, string.Empty).Nickname;
            }

            ViewBag.ClassId = ClassId;
            ViewBag.NickName = strNickName;
            ViewBag.UnitContent = UnitContent = Model_Course_UnitHomeWork.Id;
            ViewBag.Model_Course_UnitHomeWork = Model_Course_UnitHomeWork;

            return View();
        }
        /// <summary>
        /// [在线学习-作业] 新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult LearnOnLineTaskEdit(int UnitId, int ClassId, int TrainingId, int UnitContent, string Content, string AttList)
        {
            var stbSqlWhere = new StringBuilder();
            var HomeWorkBll = new Course_UnitHomeWorkBLL();
            var model = new Course_UnitHomeWork();
            int AccountId = Code.SiteCache.Instance.LoginInfo.UserId;
            double? dblScore = null;

            //若课程已结束禁止操作
            if (this.GetCourseIsOver(ClassId, TrainingId, AccountId))
                return Json(new { Result = false, Msg = "提交失败.当前课程已结束,不能执行该操作!" }, JsonRequestBehavior.AllowGet);
            //查看当前活动是否已打分,若已打分则禁止操作
            if (this.GetActivityScore_Task(ClassId, AccountId, UnitContent, out dblScore))
                return Json(new { Result = false, Msg = "提交失败.当前活动已打分,不能执行该操作!" }, JsonRequestBehavior.AllowGet);

            model.UnitContent = UnitContent;
            model.ClassId = ClassId;
            model.Content = Content;
            model.AccountId = AccountId;
            model.AttList = AttList;
            model.Content = Content;

            stbSqlWhere.AppendFormat(@" UnitContent = {0} AND ClassId = {1} AND AccountId = {2} AND Display = 1 AND Delflag = 0", model.UnitContent, model.ClassId, model.AccountId);
            var List_Course_UnitHomeWork = HomeWorkBll.GetList(stbSqlWhere.ToString(), string.Empty);
            if (List_Course_UnitHomeWork.Count > 0)
            {
                var ModelTmp = List_Course_UnitHomeWork[0];

                model.Id = ModelTmp.Id;
                model.Display = ModelTmp.Display;
                model.Delflag = ModelTmp.Delflag;
                model.CreateDate = DateTime.Now;
                model.Score = ModelTmp.Score;
                model.ScoreCreater = ModelTmp.ScoreCreater;

                if (HomeWorkBll.Update(model))
                {
                    //更新总体进度
                    this.UpdateOverallProgress(UnitId, ClassId, TrainingId, AccountId, UnitContent);

                    return Json(new { Result = true, Msg = "作业更新成功!" }, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return Json(new { Result = false, Msg = "作业更新失败!" }, JsonRequestBehavior.AllowGet);
                }
            }
            else
            {
                model.Delflag = false;
                model.Display = true;
                model.CreateDate = DateTime.Now;
                model.Score = null;

                if (HomeWorkBll.Add(model))
                {
                    //更新总进度
                    this.UpdateOverallProgress(UnitId, ClassId, TrainingId, AccountId, UnitContent);

                    return Json(new { Result = true, Msg = "作业新增成功!" }, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return Json(new { Result = false, Msg = "作业新增失败!" }, JsonRequestBehavior.AllowGet);
                }
            }
        }
        /// <summary>
        /// 查看当前活动是否已打分,若已打分则禁止操作
        /// </summary>
        /// <param name="iClassId"></param>
        /// <param name="iAccountId"></param>
        /// <param name="iUnitContent"></param>
        /// <param name="outScore"></param>
        /// <returns></returns>
        private bool GetActivityScore_Task(int iClassId, int iAccountId, int iUnitContent, out double? outScore)
        {
            double? dblScore = null;
            var bolResult = false;
            var Course_UnitHomeWorkbll = new Course_UnitHomeWorkBLL();
            var Model_Course_UnitHomeWork = new Course_UnitHomeWork();
            var strWhere_Activity = string.Format(@" Delflag = 0 AND ClassId = {0} AND AccountId = {1} AND UnitContent = {2}",
                               iClassId, iAccountId, iUnitContent);

            var List_Course_UnitHomeWor = Course_UnitHomeWorkbll.GetList(strWhere_Activity, string.Empty);
            if (List_Course_UnitHomeWor != null && List_Course_UnitHomeWor.Count > 0)
            {
                Model_Course_UnitHomeWork = List_Course_UnitHomeWor[0];
                if (Model_Course_UnitHomeWork.Score != null)
                {
                    bolResult = true;
                    dblScore = Model_Course_UnitHomeWork.Score;
                }
            }

            outScore = dblScore;//返回作业得分
            return bolResult;
        }
 /// <summary>
 /// 更新一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Update(Course_UnitHomeWork model)
 {
     return dal.Update(model) > 0;
 }
 /// <summary>
 /// 新增一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Add(Course_UnitHomeWork model)
 {
     return dal.Add(model) > 0;
 }
        public ActionResult LearnOnLineTaskView(int TrainingId, int UnitContent, int ClassId)
        {
            #region 作业标题
            var Model_Course_UnitContent = this.GetCourseUnitContentActivity(TrainingId, UnitContent, ClassId, false);
            #endregion

            #region 获取作业信息
            var stbSqlWhere = new StringBuilder();
            var Model_Course_UnitHomeWork = new Course_UnitHomeWork();
            int iClassId = 0, iTrainingId = 0, iAccountId = 0, iUnitContent = 0;
            int.TryParse(Convert.ToString(Request["TrainingId"]) == "" ? "0" : QueryString.Decrypt(Request["TrainingId"]), out iTrainingId);
            int.TryParse(Convert.ToString(Request["UnitContent"]) == "" ? "0" : QueryString.Decrypt(Request["UnitContent"]), out iUnitContent);
            int.TryParse(Convert.ToString(Request["ClassId"]) == "" ? "0" : QueryString.Decrypt(Request["ClassId"]), out iClassId);//获取 ClassId
            iAccountId = Code.SiteCache.Instance.LoginInfo.UserId;

            var HomeWorkBll = new Course_UnitHomeWorkBLL();
            stbSqlWhere.AppendFormat(@" UnitContent = {0} AND ClassId = {1} AND AccountId = {2} AND Display = 1 AND Delflag = 0", iUnitContent, iClassId, iAccountId);
            var List_Course_UnitHomeWork = HomeWorkBll.GetList(stbSqlWhere.ToString(), string.Empty);
            if (List_Course_UnitHomeWork.Count > 0)
            {
                Model_Course_UnitHomeWork = List_Course_UnitHomeWork[0];
            }

            ViewBag.Model_Course_UnitHomeWork = Model_Course_UnitHomeWork;
            #endregion

            return View();
        }
 /// <summary>
 /// 获取分页数据集
 /// </summary>
 /// <param name="pageSize"></param>
 /// <param name="pageIndex"></param>
 /// <param name="where"></param>
 /// <param name="orderBy"></param>
 /// <param name="recordCount"></param>
 /// <returns></returns>
 public List<Course_UnitHomeWork> GetList(int pageSize, int pageIndex, string where, string orderBy, out int recordCount)
 {
     if (string.IsNullOrEmpty(orderBy))
         throw new ArgumentNullException();
     StringBuilder sb = new StringBuilder();
     sb.Append("select count(1) from [dbo].[Course_UnitHomeWork]");
     if (!string.IsNullOrEmpty(where))
         sb.Append(" where " + where);
     recordCount = Convert.ToInt32(MSEntLibSqlHelper.ExecuteScalarBySql(sb.ToString()));
     int start = (pageIndex - 1) * pageSize + 1;
     int end = pageIndex * pageSize;
     StringBuilder sql = new StringBuilder();
     sql.Append("select * from (select *,ROW_NUMBER() over (order by " + orderBy + ") as [RowNum] from [dbo].[Course_UnitHomeWork]");
     if (!string.IsNullOrEmpty(where))
         sql.Append(" where " + where);
     sql.Append(") as T where [RowNum] between " + start + " and " + end);
     List<Course_UnitHomeWork> list = new List<Course_UnitHomeWork>();
     using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString()))
     {
         while (reader.Read())
         {
             Course_UnitHomeWork model = new Course_UnitHomeWork();
             ConvertToModel(reader, model);
             list.Add(model);
         }
     }
     return list;
 }
 private void ConvertToModel(IDataReader reader, Course_UnitHomeWork model)
 {
     if (reader["Id"] != DBNull.Value)
         model.Id = Convert.ToInt32(reader["Id"]);
     if (reader["UnitContent"] != DBNull.Value)
         model.UnitContent = Convert.ToInt32(reader["UnitContent"]);
     if (reader["ClassId"] != DBNull.Value)
         model.ClassId = Convert.ToInt32(reader["ClassId"]);
     if (reader["Content"] != DBNull.Value)
         model.Content = reader["Content"].ToString();
     if (reader["AccountId"] != DBNull.Value)
         model.AccountId = Convert.ToInt32(reader["AccountId"]);
     if (reader["AttList"] != DBNull.Value)
         model.AttList = reader["AttList"].ToString();
     if (reader["Display"] != DBNull.Value)
         model.Display = Convert.ToBoolean(reader["Display"]);
     if (reader["Delflag"] != DBNull.Value)
         model.Delflag = Convert.ToBoolean(reader["Delflag"]);
     if (reader["CreateDate"] != DBNull.Value)
         model.CreateDate = Convert.ToDateTime(reader["CreateDate"]);
     if (reader["Score"] != DBNull.Value)
         model.Score = Convert.ToDouble(reader["Score"]);
     if (reader["ScoreCreater"] != DBNull.Value)
         model.ScoreCreater = Convert.ToInt32(reader["ScoreCreater"]);
 }
 /// <summary>
 /// 更新一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Update(Course_UnitHomeWork model)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("update [dbo].[Course_UnitHomeWork] set ");
     sql.Append("[UnitContent]=@UnitContent,[ClassId]=@ClassId,[Content]=@Content,[AccountId]=@AccountId,[AttList]=@AttList,[Display]=@Display,[Delflag]=@Delflag,[CreateDate]=@CreateDate,[Score]=@Score,[ScoreCreater]=@ScoreCreater");
     sql.Append(" where [Id]=@Id");
     SqlParameter[] cmdParams = new SqlParameter[] {
         new SqlParameter("@Id", SqlDbType.Int, 4) { Value = model.Id },
         new SqlParameter("@UnitContent", SqlDbType.Int, 4) { Value = model.UnitContent },
         new SqlParameter("@ClassId", SqlDbType.Int, 4) { Value = model.ClassId },
         new SqlParameter("@Content", SqlDbType.VarChar, 2000) { Value = model.Content },
         new SqlParameter("@AccountId", SqlDbType.Int, 4) { Value = model.AccountId },
         new SqlParameter("@AttList", SqlDbType.VarChar, 2000) { Value = model.AttList },
         new SqlParameter("@Display", SqlDbType.Bit, 1) { Value = model.Display },
         new SqlParameter("@Delflag", SqlDbType.Bit, 1) { Value = model.Delflag },
         new SqlParameter("@CreateDate", SqlDbType.DateTime, 8) { Value = model.CreateDate },
         new SqlParameter("@Score", SqlDbType.Float, 8) { Value = model.Score },
         new SqlParameter("@ScoreCreater", SqlDbType.Int, 4) { Value = model.ScoreCreater }
     };
     return MSEntLibSqlHelper.ExecuteNonQueryBySql(sql.ToString(), cmdParams);
 }
 /// <summary>
 /// 取得一条记录
 /// </summary>
 /// <param name="id"></param>
 /// <param name="where"></param>
 /// <returns></returns>
 public Course_UnitHomeWork GetModel(int id, string where)
 {
     string sql = "select * from [dbo].[Course_UnitHomeWork] where [Id]=@Id";
     if (!string.IsNullOrEmpty(where))
         sql += " and " + where;
     SqlParameter[] cmdParams = new SqlParameter[]{
         new SqlParameter("@Id", SqlDbType.Int, 4) { Value = id }
     };
     using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql, cmdParams))
     {
         if (reader.Read())
         {
             Course_UnitHomeWork model = new Course_UnitHomeWork();
             ConvertToModel(reader, model);
             return model;
         }
         else
         {
             return null;
         }
     }
 }