Esempio n. 1
0
 /// <summary>
 /// 新增UserLogin对象
 /// </summary>
 /// <param name="UserLogin">需要新增的对象</param>
 /// <returns>新插入数据的ID</returns>
 public Int64 AddUserLogin(UserLogin obj)
 {
     if(obj != null)
     {
         return Convert.ToInt32(_dal.InsertReturnID(obj));
     }
     return -1;
 }
Esempio n. 2
0
        /// <summary>
        /// 插入一条数据并返回ID
        /// </summary>
        /// <param name="UserLogin">需要插入的对象</param>
        /// <returns>新插入数据的ID</returns>
        public Object InsertReturnID(UserLogin obj)
        {
            //声明参数数组并赋值
            SqlParameter[] param = new SqlParameter[]{
                new SqlParameter("@UserID",obj.UserID),
                new SqlParameter("@Email",obj.Email),
                new SqlParameter("@LoginTime",obj.LoginTime),
                new SqlParameter("@HostName",obj.HostName),
                new SqlParameter("@HostAddress",obj.HostAddress),
                new SqlParameter("@Remark",obj.Remark),
                new SqlParameter("@Result",obj.Result)
            };

            return SqlHelper.ExecuteScalar(SqlHelper.connectionString, _SQL_INSERT_RETURNID, CommandType.Text, param);
        }
Esempio n. 3
0
        /// <summary>
        /// 插入一条数据
        /// </summary>
        /// <param name="UserLogin">需要插入的对象</param>
        /// <returns>影响行数</returns>
        public Int32 Insert(UserLogin obj)
        {
            //声明参数数组并赋值
            SqlParameter[] param = new SqlParameter[]{
                new SqlParameter("@UserID",obj.UserID),
                new SqlParameter("@Email",obj.Email),
                new SqlParameter("@LoginTime",obj.LoginTime),
                new SqlParameter("@HostName",obj.HostName),
                new SqlParameter("@HostAddress",obj.HostAddress),
                new SqlParameter("@Remark",obj.Remark),
                new SqlParameter("@Result",obj.Result)
            };

            return SqlHelper.ExecuteNonQuery(SqlHelper.connectionString, _SQL_INSERT, CommandType.Text, param);
        }
Esempio n. 4
0
        /// <summary>
        /// 将SqlDataReader对象转换成UserLogin对象
        /// </summary>
        /// <param name="dr">SqlDataReader对象</param>
        /// <returns></returns>
        private UserLogin ToObject(SqlDataReader dr)
        {
            using (dr)
            {
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        UserLogin model = new UserLogin();
                        model.ID = Convert.ToInt64(dr["ID"]);
                        model.UserID = Convert.ToInt32(dr["UserID"]);
                        model.Email = dr["Email"].ToString();
                        model.LoginTime = Convert.ToDateTime(dr["LoginTime"]);
                        model.HostName = dr["HostName"].ToString();
                        model.HostAddress = dr["HostAddress"].ToString();
                        model.Remark = dr["Remark"].ToString();
                        model.Result = Convert.ToByte(dr["Result"]);

                        return model;
                    }
                }
            }
            return null;
        }
Esempio n. 5
0
        /// <summary>
        /// 将SqlDataReader对象转换成UserLogin对象集合
        /// </summary>
        /// <param name="dr">SqlDataReader对象</param>
        /// <returns></returns>
        private List<UserLogin> ToList(SqlDataReader dr)
        {
            List<UserLogin> list = null;
            using (dr)
            {
                if (dr.HasRows)
                {
                    list = new List<UserLogin>();
                    while (dr.Read())
                    {
                        UserLogin model = new UserLogin();
                        model.ID = Convert.ToInt64(dr["ID"]);
                        model.UserID = Convert.ToInt32(dr["UserID"]);
                        model.Email = dr["Email"].ToString();
                        model.LoginTime = Convert.ToDateTime(dr["LoginTime"]);
                        model.HostName = dr["HostName"].ToString();
                        model.HostAddress = dr["HostAddress"].ToString();
                        model.Remark = dr["Remark"].ToString();
                        model.Result = Convert.ToByte(dr["Result"]);

                        list.Add(model);
                    }
                }
            }
            return list;
        }
Esempio n. 6
0
        /// <summary>
        /// 更新一条新数据。
        /// </summary>
        /// <param name="UserLogin">需要更新的对象</param>
        /// <returns>影响行数</returns>
        public Int32 Update(UserLogin obj)
        {
            //将WHERE条件组合进SQL语句
            String sqlStr = String.Format(_SQL_UPDATE, "WHERE [ID] = @ID");
            //声明参数数组并赋值
            SqlParameter[] param = new SqlParameter[]{
                new SqlParameter("@ID",obj.ID),
                new SqlParameter("@UserID",obj.UserID),
                new SqlParameter("@Email",obj.Email),
                new SqlParameter("@LoginTime",obj.LoginTime),
                new SqlParameter("@HostName",obj.HostName),
                new SqlParameter("@HostAddress",obj.HostAddress),
                new SqlParameter("@Remark",obj.Remark),
                new SqlParameter("@Result",obj.Result)
            };

            return SqlHelper.ExecuteNonQuery(SqlHelper.connectionString, sqlStr, CommandType.Text, param);
        }
Esempio n. 7
0
 /// <summary>
 /// 修改UserLogin对象
 /// </summary>
 /// <param name="UserLogin">需要修改的对象</param>
 /// <returns>影响行数</returns>
 public Int32 SetUserLogin(UserLogin obj)
 {
     if(obj != null)
     {
         return _dal.Update(obj);
     }
     return -1;
 }