示例#1
0
        /// <summary>
        /// 获取指定userLoginId的userlogin对象
        /// </summary>
        /// <param name="user">当前操作用户</param>
        /// <param name="userLoginId">主键值</param>
        /// <returns></returns>
        public override ResultModel Get(UserModel user, int userLoginId)
        {
            ResultModel result = new ResultModel();

            if(userLoginId<1)
            {
                result.Message = "序号不能小于1";
                return result;
            }

            List<SqlParameter> paras = new List<SqlParameter>();
            SqlParameter para = new SqlParameter("@UserLoginId",SqlDbType.Int,4);
            para.Value = userLoginId;
            paras.Add(para);

            SqlDataReader dr = null;

            try
            {
                dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringUser, CommandType.StoredProcedure, "UserLoginGet", paras.ToArray());

                UserLogin userlogin = new UserLogin();

                if (dr.Read())
                {
                    int indexUserLoginId = dr.GetOrdinal("UserLoginId");
                    userlogin.UserLoginId = Convert.ToInt32(dr[indexUserLoginId]);

                    int indexAccId = dr.GetOrdinal("AccId");
                    if(dr["AccId"] != DBNull.Value)
                    {
                    userlogin.AccId = Convert.ToInt32(dr[indexAccId]);
                    }

                    int indexLoginTime = dr.GetOrdinal("LoginTime");
                    if(dr["LoginTime"] != DBNull.Value)
                    {
                    userlogin.LoginTime = Convert.ToDateTime(dr[indexLoginTime]);
                    }

                    int indexLoginIP = dr.GetOrdinal("LoginIP");
                    if(dr["LoginIP"] != DBNull.Value)
                    {
                    userlogin.LoginIP = Convert.ToString(dr[indexLoginIP]);
                    }

                    int indexLoginMac = dr.GetOrdinal("LoginMac");
                    if(dr["LoginMac"] != DBNull.Value)
                    {
                    userlogin.LoginMac = Convert.ToString(dr[indexLoginMac]);
                    }

                    int indexBorwser = dr.GetOrdinal("Borwser");
                    if(dr["Borwser"] != DBNull.Value)
                    {
                    userlogin.Borwser = Convert.ToInt32(dr[indexBorwser]);
                    }

                    result.AffectCount = 1;
                    result.Message = "读取成功";
                    result.ResultStatus = 0;
                    result.ReturnValue = userlogin;
                }
                else
                {
                    result.Message = "读取失败或无数据";
                    result.AffectCount = 0;
                }
            }
            catch(Exception ex)
            {
                result.Message = ex.Message;
            }
            finally
            {
                if (dr != null)
                    dr.Dispose();
            }
            return result;
        }
示例#2
0
        /// <summary>
        /// 获取userlogin集合
        /// </summary>
        /// <param name="user">当前操作用户</param>
        /// <returns></returns>
        public override ResultModel Load(UserModel user)
        {
            ResultModel result = new ResultModel();
            try
            {
                DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.ConnectionStringUser,"UserLoginLoad",null,CommandType.StoredProcedure);

                List< UserLogin> userLogins = new List< UserLogin>();

                foreach(DataRow dr in dt.Rows)
                {
                    UserLogin userlogin = new UserLogin();
                    userlogin.UserLoginId = Convert.ToInt32(dr["UserLoginId"]);

                    if(dr["AccId"] != DBNull.Value)
                    {
                    userlogin.AccId = Convert.ToInt32(dr["AccId"]);
                    }
                    if(dr["LoginTime"] != DBNull.Value)
                    {
                    userlogin.LoginTime = Convert.ToDateTime(dr["LoginTime"]);
                    }
                    if(dr["LoginIP"] != DBNull.Value)
                    {
                    userlogin.LoginIP = Convert.ToString(dr["LoginIP"]);
                    }
                    if(dr["LoginMac"] != DBNull.Value)
                    {
                    userlogin.LoginMac = Convert.ToString(dr["LoginMac"]);
                    }
                    if(dr["Borwser"] != DBNull.Value)
                    {
                    userlogin.Borwser = Convert.ToInt32(dr["Borwser"]);
                    }
                    userLogins.Add(userlogin);
                }
                result.AffectCount = dt.Rows.Count;
                result.Message = "获取列表成功";
                result.ResultStatus = 0;
                result.ReturnValue = userLogins;
            }
            catch(Exception ex)
            {
                result.Message = ex.Message;
            }

            return result;
        }