Esempio n. 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(UserEntity model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into User(");
            strSql.Append("name,psw,phone,qq,email,enable");
            strSql.Append(") values (");
            strSql.Append("@name,@psw,@phone,@qq,@email,@enable");
            strSql.Append(") ");
            strSql.Append(";select SCOPE_IDENTITY()");
            SqlParameter[] parameters = {
                        new SqlParameter("@name", SqlDbType.VarChar,50) ,
                        new SqlParameter("@psw", SqlDbType.VarChar,50) ,
                        new SqlParameter("@phone", SqlDbType.Char,11) ,
                        new SqlParameter("@qq", SqlDbType.VarChar,15) ,
                        new SqlParameter("@email", SqlDbType.VarChar,50) ,
                        new SqlParameter("@enable", SqlDbType.Bit,1)

            };

            parameters[0].Value = model.name;
            parameters[1].Value = model.psw;
            parameters[2].Value = model.phone;
            parameters[3].Value = model.qq;
            parameters[4].Value = model.email;
            parameters[5].Value = model.enable;

            DataTable dt = DBExecuteUtil.querySqlTable(strSql.ToString(), parameters);
            if (dt.Rows.Count == 0)
            {

                return 0;

            }
            else
            {

                return Convert.ToInt32(dt.Rows[0][0].ToString());

            }
        }
Esempio n. 2
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<UserEntity> DataTableToList(DataTable dt)
        {
            List<UserEntity> modelList = new List<UserEntity>();
            int rowsCount = dt.Rows.Count;
            int result;
            if (rowsCount > 0)
            {
                UserEntity model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new UserEntity();
                    if (dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    model.id = int.TryParse(dt.Rows[n]["id"].ToString(), out result) ? result : 0;
                    model.name = dt.Rows[n]["name"].ToString();
                    model.psw = dt.Rows[n]["psw"].ToString();
                    model.phone = dt.Rows[n]["phone"].ToString();
                    model.qq = dt.Rows[n]["qq"].ToString();
                    model.email = dt.Rows[n]["email"].ToString();
                    if (dt.Rows[n]["enable"].ToString() != "")
                    {
                        if ((dt.Rows[n]["enable"].ToString() == "1") || (dt.Rows[n]["enable"].ToString().ToLower() == "true"))
                        {
                            model.enable = true;
                        }
                        else
                        {
                            model.enable = false;
                        }
                    }

                    modelList.Add(model);
                }
            }
            return modelList;
        }
Esempio n. 3
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(UserEntity model)
 {
     return dal.Add(model);
 }
Esempio n. 4
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(UserEntity model)
 {
     return dal.Update(model);
 }
Esempio n. 5
0
 /// <summary>
 /// 获得分页数据
 /// </summary>
 /// <param name="pageIndex"></param>
 /// <param name="pageSize"></param>
 /// <param name="model"></param>
 /// <returns></returns>
 public DataTable GetPage(int pageIndex, int pageSize, UserEntity model, out int count)
 {
     return dal.GetPage(pageIndex, pageSize, model, out count);
 }
Esempio n. 6
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(UserEntity model)
        {
            StringBuilder strSql = new StringBuilder();
            List<SqlParameter> parameters = new List<SqlParameter>();
            strSql.Append("update User set ");

            if (!string.IsNullOrEmpty(model.name))
            {
                strSql.Append(" name = @name , ");
                parameters.Add(new SqlParameter("@name", model.name));
            }
            if (!string.IsNullOrEmpty(model.psw))
            {
                strSql.Append(" psw = @psw , ");
                parameters.Add(new SqlParameter("@psw", model.psw));
            }
            if (!string.IsNullOrEmpty(model.phone))
            {
                strSql.Append(" phone = @phone , ");
                parameters.Add(new SqlParameter("@phone", model.phone));
            }
            if (!string.IsNullOrEmpty(model.qq))
            {
                strSql.Append(" qq = @qq , ");
                parameters.Add(new SqlParameter("@qq", model.qq));
            }
            if (!string.IsNullOrEmpty(model.email))
            {
                strSql.Append(" email = @email , ");
                parameters.Add(new SqlParameter("@email", model.email));
            }
            strSql.Append(" enable = @enable , ");
            parameters.Add(new SqlParameter("@enable", model.enable));
            strSql = strSql.Remove(strSql.Length - 2, 2);
            strSql.Append(" where id=@id ");
            parameters.Add(new SqlParameter("@id", model.id));
            int rows = DBExecuteUtil.ExecuteSqlWithParams(strSql.ToString(), parameters.ToArray());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Esempio n. 7
0
 /// <summary>
 /// 获取分页数据
 /// </summary>
 /// <returns></returns>
 public DataTable GetPage(int pageIndex, int pageSize, UserEntity model, out int count)
 {
     count = 0;
     SqlParameter[] items = new SqlParameter[]{
         new SqlParameter("pageIndex",pageIndex),
         new SqlParameter("pageSize",pageSize),
         new SqlParameter("count",count)
     };
     items[2].Direction = ParameterDirection.Output;
     var dt = DBStoreProUtil.queryProTable4Params("proc_User_Pagedata", items);
     count = int.Parse(items[2].Value.ToString());
     return dt;
 }
Esempio n. 8
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public UserEntity GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id, name, psw, phone, qq, email, enable  ");
            strSql.Append("  from User ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int,4)
            };
            parameters[0].Value = id;

            UserEntity model = new UserEntity();
            DataTable dt = DBExecuteUtil.querySqlTable(strSql.ToString(), parameters);

            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(dt.Rows[0]["id"].ToString());
                }
                model.name = dt.Rows[0]["name"].ToString();
                model.psw = dt.Rows[0]["psw"].ToString();
                model.phone = dt.Rows[0]["phone"].ToString();
                model.qq = dt.Rows[0]["qq"].ToString();
                model.email = dt.Rows[0]["email"].ToString();
                if (dt.Rows[0]["enable"].ToString() != "")
                {
                    if ((dt.Rows[0]["enable"].ToString() == "1") || (dt.Rows[0]["enable"].ToString().ToLower() == "true"))
                    {
                        model.enable = true;
                    }
                    else
                    {
                        model.enable = false;
                    }
                }

                return model;
            }
            else
            {
                return null;
            }
        }