Beispiel #1
0
 /// <summary>
 /// 新增一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Add(Class_Group model)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("insert into [dbo].[Class_Group] ([ClassId],[Title],[Display],[Delflag],[CreateDate])");
     sql.Append(" values (@ClassId,@Title,@Display,@Delflag,@CreateDate)");
     sql.Append(" set @Id=@@IDENTITY");
     SqlParameter[] cmdParams = new SqlParameter[]{
         new SqlParameter("@Id", SqlDbType.Int, 4) { Value = model.Id, Direction = ParameterDirection.Output },
         new SqlParameter("@ClassId", SqlDbType.Int, 4) { Value = model.ClassId },
         new SqlParameter("@Title", SqlDbType.VarChar, 200) { Value = model.Title },
         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 }
     };
     int result = Convert.ToInt32(MSEntLibSqlHelper.ExecuteNonQueryBySql(sql.ToString(), cmdParams));
     model.Id = Convert.ToInt32(cmdParams[0].Value);
     return result;
 }
        public JsonResult AddClassGroupMember(string classId, string groupTitle, string accountIds)
        {
            try
            {
                var param_classId = Dianda.Common.QueryString.Decrypt(classId).ToInt();
                var gbll = new Class_GroupBLL();
                var gmbll = new Class_GroupMemberBLL();

                var groupNameCheck = new Class_GroupBLL().GetList(" Delflag=0 and ClassId=" + param_classId + " and Title='" + groupTitle.Trim() + "'", "");
                if (groupNameCheck != null && groupNameCheck.Count > 0)
                    return Json(new { Code = 0, Msg = "班级内存在此小组名称!" }, JsonRequestBehavior.AllowGet);
                var gModel = new Class_Group();
                gModel.ClassId = param_classId;
                gModel.CreateDate = DateTime.Now;
                gModel.Display = true;
                gModel.Delflag = false;
                gModel.Title = groupTitle;
                gbll.Add(gModel);

                var ids = accountIds.Split(',');
                foreach (var item in ids)
                {
                    if (!string.IsNullOrEmpty(item))
                    {
                        var gmModel = new Class_GroupMember();
                        gmModel.AccountId = item.ToInt();
                        gmModel.GroupId = gModel.Id;
                        gmModel.Delflag = false;
                        gmModel.CreateDate = DateTime.Now;
                        gmbll.Add(gmModel);
                    }
                }

                return Json(new { Code = 0, Msg = "提交成功" }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return Json(new { Code = -1, Msg = ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 根据用户获取其所在的班级和组
        /// </summary>
        /// <param name="iAccountId"></param>
        /// <returns></returns>
        public Class_Group GetClassAndGroup(int iAccountId)
        {
            string sql = @"select * from Class_Group
                        where Class_Group.Id = (select Class_GroupMember.GroupId from Class_GroupMember where Class_GroupMember.AccountId = @AccountId and Class_GroupMember.Delflag = 0)
                        and Class_Group.Delflag = 0";

            SqlParameter[] cmdParams = new SqlParameter[]{
                new SqlParameter("@AccountId", SqlDbType.Int, 4) { Value = iAccountId }
            };
            using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql, cmdParams))
            {
                if (reader.Read())
                {
                    Class_Group model = new Class_Group();
                    ConvertToModel(reader, model);
                    return model;
                }
                else
                {
                    return null;
                }
            }
        }
Beispiel #4
0
 private void ConvertToModel(IDataReader reader, Class_Group model)
 {
     if (reader["Id"] != DBNull.Value)
         model.Id = Convert.ToInt32(reader["Id"]);
     if (reader["ClassId"] != DBNull.Value)
         model.ClassId = Convert.ToInt32(reader["ClassId"]);
     if (reader["Title"] != DBNull.Value)
         model.Title = reader["Title"].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"]);
 }
Beispiel #5
0
 /// <summary>
 /// 更新一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Update(Class_Group model)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("update [dbo].[Class_Group] set ");
     sql.Append("[ClassId]=@ClassId,[Title]=@Title,[Display]=@Display,[Delflag]=@Delflag,[CreateDate]=@CreateDate");
     sql.Append(" where [Id]=@Id");
     SqlParameter[] cmdParams = new SqlParameter[] {
         new SqlParameter("@Id", SqlDbType.Int, 4) { Value = model.Id },
         new SqlParameter("@ClassId", SqlDbType.Int, 4) { Value = model.ClassId },
         new SqlParameter("@Title", SqlDbType.VarChar, 200) { Value = model.Title },
         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 }
     };
     return MSEntLibSqlHelper.ExecuteNonQueryBySql(sql.ToString(), cmdParams);
 }
Beispiel #6
0
 /// <summary>
 /// 取得一条记录
 /// </summary>
 /// <param name="id"></param>
 /// <param name="where"></param>
 /// <returns></returns>
 public Class_Group GetModel(int id, string where)
 {
     string sql = "select * from [dbo].[Class_Group] 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())
         {
             Class_Group model = new Class_Group();
             ConvertToModel(reader, model);
             return model;
         }
         else
         {
             return null;
         }
     }
 }
Beispiel #7
0
 /// <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<Class_Group> 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].[Class_Group]");
     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].[Class_Group]");
     if (!string.IsNullOrEmpty(where))
         sql.Append(" where " + where);
     sql.Append(") as T where [RowNum] between " + start + " and " + end);
     List<Class_Group> list = new List<Class_Group>();
     using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString()))
     {
         while (reader.Read())
         {
             Class_Group model = new Class_Group();
             ConvertToModel(reader, model);
             list.Add(model);
         }
     }
     return list;
 }
Beispiel #8
0
 /// <summary>
 /// 获取数据集
 /// </summary>
 /// <param name="where"></param>
 /// <param name="orderBy"></param>
 /// <returns></returns>
 public List<Class_Group> GetList(string where, string orderBy)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("select * from [dbo].[Class_Group]");
     if (!string.IsNullOrEmpty(where))
         sql.Append(" where " + where);
     if (!string.IsNullOrEmpty(orderBy))
         sql.Append(" order by " + orderBy);
     List<Class_Group> list = new List<Class_Group>();
     using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString()))
     {
         while (reader.Read())
         {
             Class_Group model = new Class_Group();
             ConvertToModel(reader, model);
             list.Add(model);
         }
     }
     return list;
 }
Beispiel #9
0
 /// <summary>
 /// 新增一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Add(Class_Group model)
 {
     return dal.Add(model) > 0;
 }
Beispiel #10
0
 /// <summary>
 /// 更新一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Update(Class_Group model)
 {
     return dal.Update(model) > 0;
 }